]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-2.6.32.51-201201021326.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.51-201201021326.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index e1efc40..47f0daf 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -1,15 +1,19 @@
6 *.a
7 *.aux
8 *.bin
9 +*.cis
10 *.cpio
11 *.csp
12 +*.dbg
13 *.dsp
14 *.dvi
15 *.elf
16 *.eps
17 *.fw
18 +*.gcno
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -38,8 +42,10 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *_MODULES
32 +*_reg_safe.h
33 *_vga16.c
34 *~
35 *.9
36 @@ -49,11 +55,16 @@
37 53c700_d.h
38 CVS
39 ChangeSet
40 +GPATH
41 +GRTAGS
42 +GSYMS
43 +GTAGS
44 Image
45 Kerntypes
46 Module.markers
47 Module.symvers
48 PENDING
49 +PERF*
50 SCCS
51 System.map*
52 TAGS
53 @@ -76,7 +87,11 @@ btfixupprep
54 build
55 bvmlinux
56 bzImage*
57 +capability_names.h
58 +capflags.c
59 classlist.h*
60 +clut_vga16.c
61 +common-cmds.h
62 comp*.log
63 compile.h*
64 conf
65 @@ -84,6 +99,8 @@ config
66 config-*
67 config_data.h*
68 config_data.gz*
69 +config.c
70 +config.tmp
71 conmakehash
72 consolemap_deftbl.c*
73 cpustr.h
74 @@ -97,19 +114,23 @@ elfconfig.h*
75 fixdep
76 fore200e_mkfirm
77 fore200e_pca_fw.c*
78 +gate.lds
79 gconf
80 gen-devlist
81 gen_crc32table
82 gen_init_cpio
83 genksyms
84 *_gray256.c
85 +hash
86 +hid-example
87 ihex2fw
88 ikconfig.h*
89 initramfs_data.cpio
90 +initramfs_data.cpio.bz2
91 initramfs_data.cpio.gz
92 initramfs_list
93 kallsyms
94 -kconfig
95 +kern_constants.h
96 keywords.c
97 ksym.c*
98 ksym.h*
99 @@ -127,13 +148,16 @@ machtypes.h
100 map
101 maui_boot.h
102 mconf
103 +mdp
104 miboot*
105 mk_elfconfig
106 mkboot
107 mkbugboot
108 mkcpustr
109 mkdep
110 +mkpiggy
111 mkprep
112 +mkregtable
113 mktables
114 mktree
115 modpost
116 @@ -149,6 +173,7 @@ patches*
117 pca200e.bin
118 pca200e_ecd.bin2
119 piggy.gz
120 +piggy.S
121 piggyback
122 pnmtologo
123 ppc_defs.h*
124 @@ -157,12 +182,15 @@ qconf
125 raid6altivec*.c
126 raid6int*.c
127 raid6tables.c
128 +regdb.c
129 relocs
130 +rlim_names.h
131 series
132 setup
133 setup.bin
134 setup.elf
135 sImage
136 +slabinfo
137 sm_tbl*
138 split-include
139 syscalltab.h
140 @@ -171,6 +199,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 @@ -186,14 +215,20 @@ version.h*
149 vmlinux
150 vmlinux-*
151 vmlinux.aout
152 +vmlinux.bin.all
153 +vmlinux.bin.bz2
154 vmlinux.lds
155 +vmlinux.relocs
156 +voffset.h
157 vsyscall.lds
158 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 +zoffset.h
169 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
170 index c840e7d..f4c451c 100644
171 --- a/Documentation/kernel-parameters.txt
172 +++ b/Documentation/kernel-parameters.txt
173 @@ -1837,6 +1837,13 @@ and is between 256 and 4096 characters. It is defined in the file
174 the specified number of seconds. This is to be used if
175 your oopses keep scrolling off the screen.
176
177 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
178 + virtualization environments that don't cope well with the
179 + expand down segment used by UDEREF on X86-32 or the frequent
180 + page table updates on X86-64.
181 +
182 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
183 +
184 pcbit= [HW,ISDN]
185
186 pcd. [PARIDE]
187 diff --git a/Makefile b/Makefile
188 index 1c640ea..b545bdc 100644
189 --- a/Makefile
190 +++ b/Makefile
191 @@ -221,8 +221,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
192
193 HOSTCC = gcc
194 HOSTCXX = g++
195 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
196 -HOSTCXXFLAGS = -O2
197 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
198 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
199 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
200
201 # Decide whether to build built-in, modular, or both.
202 # Normally, just do built-in.
203 @@ -376,8 +377,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
204 # Rules shared between *config targets and build targets
205
206 # Basic helpers built in scripts/
207 -PHONY += scripts_basic
208 -scripts_basic:
209 +PHONY += scripts_basic gcc-plugins
210 +scripts_basic: gcc-plugins
211 $(Q)$(MAKE) $(build)=scripts/basic
212
213 # To avoid any implicit rule to kick in, define an empty command.
214 @@ -403,7 +404,7 @@ endif
215 # of make so .config is not included in this case either (for *config).
216
217 no-dot-config-targets := clean mrproper distclean \
218 - cscope TAGS tags help %docs check% \
219 + cscope gtags TAGS tags help %docs check% \
220 include/linux/version.h headers_% \
221 kernelrelease kernelversion
222
223 @@ -526,6 +527,42 @@ else
224 KBUILD_CFLAGS += -O2
225 endif
226
227 +ifndef DISABLE_PAX_PLUGINS
228 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
229 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
230 +CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
231 +endif
232 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
233 +STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
234 +STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
235 +endif
236 +ifdef CONFIG_KALLOCSTAT_PLUGIN
237 +KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
238 +endif
239 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
240 +KERNEXEC_PLUGIN := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
241 +KERNEXEC_PLUGIN += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD)
242 +endif
243 +ifdef CONFIG_CHECKER_PLUGIN
244 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
245 +CHECKER_PLUGIN := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
246 +endif
247 +endif
248 +GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN) $(KERNEXEC_PLUGIN) $(CHECKER_PLUGIN)
249 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
250 +gcc-plugins:
251 + $(Q)$(MAKE) $(build)=tools/gcc
252 +else
253 +gcc-plugins:
254 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
255 + $(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.))
256 +else
257 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
258 +endif
259 + $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
260 +endif
261 +endif
262 +
263 include $(srctree)/arch/$(SRCARCH)/Makefile
264
265 ifneq ($(CONFIG_FRAME_WARN),0)
266 @@ -647,7 +684,7 @@ export mod_strip_cmd
267
268
269 ifeq ($(KBUILD_EXTMOD),)
270 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
271 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
272
273 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
274 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
275 @@ -868,6 +905,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
276
277 # The actual objects are generated when descending,
278 # make sure no implicit rule kicks in
279 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
280 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
281
282 # Handle descending into subdirectories listed in $(vmlinux-dirs)
283 @@ -877,7 +915,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
284 # Error messages still appears in the original language
285
286 PHONY += $(vmlinux-dirs)
287 -$(vmlinux-dirs): prepare scripts
288 +$(vmlinux-dirs): gcc-plugins prepare scripts
289 $(Q)$(MAKE) $(build)=$@
290
291 # Build the kernel release string
292 @@ -986,6 +1024,7 @@ prepare0: archprepare FORCE
293 $(Q)$(MAKE) $(build)=. missing-syscalls
294
295 # All the preparing..
296 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
297 prepare: prepare0
298
299 # The asm symlink changes when $(ARCH) changes.
300 @@ -1127,6 +1166,7 @@ all: modules
301 # using awk while concatenating to the final file.
302
303 PHONY += modules
304 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
305 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
306 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
307 @$(kecho) ' Building modules, stage 2.';
308 @@ -1136,7 +1176,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
309
310 # Target to prepare building external modules
311 PHONY += modules_prepare
312 -modules_prepare: prepare scripts
313 +modules_prepare: gcc-plugins prepare scripts
314
315 # Target to install modules
316 PHONY += modules_install
317 @@ -1201,7 +1241,7 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
318 include/linux/autoconf.h include/linux/version.h \
319 include/linux/utsrelease.h \
320 include/linux/bounds.h include/asm*/asm-offsets.h \
321 - Module.symvers Module.markers tags TAGS cscope*
322 + Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
323
324 # clean - Delete most, but leave enough to build external modules
325 #
326 @@ -1245,7 +1285,7 @@ distclean: mrproper
327 @find $(srctree) $(RCS_FIND_IGNORE) \
328 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
329 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
330 - -o -name '.*.rej' -o -size 0 \
331 + -o -name '.*.rej' -o -name '*.so' -o -size 0 \
332 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
333 -type f -print | xargs rm -f
334
335 @@ -1292,6 +1332,7 @@ help:
336 @echo ' modules_prepare - Set up for building external modules'
337 @echo ' tags/TAGS - Generate tags file for editors'
338 @echo ' cscope - Generate cscope index'
339 + @echo ' gtags - Generate GNU GLOBAL index'
340 @echo ' kernelrelease - Output the release version string'
341 @echo ' kernelversion - Output the version stored in Makefile'
342 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
343 @@ -1393,6 +1434,7 @@ PHONY += $(module-dirs) modules
344 $(module-dirs): crmodverdir $(objtree)/Module.symvers
345 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
346
347 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
348 modules: $(module-dirs)
349 @$(kecho) ' Building modules, stage 2.';
350 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
351 @@ -1448,7 +1490,7 @@ endif # KBUILD_EXTMOD
352 quiet_cmd_tags = GEN $@
353 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
354
355 -tags TAGS cscope: FORCE
356 +tags TAGS cscope gtags: FORCE
357 $(call cmd,tags)
358
359 # Scripts to check various things for consistency
360 @@ -1513,17 +1555,19 @@ else
361 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
362 endif
363
364 -%.s: %.c prepare scripts FORCE
365 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
366 +%.s: %.c gcc-plugins prepare scripts FORCE
367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
368 %.i: %.c prepare scripts FORCE
369 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
370 -%.o: %.c prepare scripts FORCE
371 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
372 +%.o: %.c gcc-plugins prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 %.lst: %.c prepare scripts FORCE
375 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
376 -%.s: %.S prepare scripts FORCE
377 +%.s: %.S gcc-plugins prepare scripts FORCE
378 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
379 -%.o: %.S prepare scripts FORCE
380 +%.o: %.S gcc-plugins prepare scripts FORCE
381 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
382 %.symtypes: %.c prepare scripts FORCE
383 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
384 @@ -1533,11 +1577,13 @@ endif
385 $(cmd_crmodverdir)
386 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
387 $(build)=$(build-dir)
388 -%/: prepare scripts FORCE
389 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
390 +%/: gcc-plugins prepare scripts FORCE
391 $(cmd_crmodverdir)
392 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
393 $(build)=$(build-dir)
394 -%.ko: prepare scripts FORCE
395 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
396 +%.ko: gcc-plugins prepare scripts FORCE
397 $(cmd_crmodverdir)
398 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
399 $(build)=$(build-dir) $(@:.ko=.o)
400 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
401 index 5c75c1b..c82f878 100644
402 --- a/arch/alpha/include/asm/elf.h
403 +++ b/arch/alpha/include/asm/elf.h
404 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
405
406 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
407
408 +#ifdef CONFIG_PAX_ASLR
409 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
410 +
411 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
412 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
413 +#endif
414 +
415 /* $0 is set by ld.so to a pointer to a function which might be
416 registered using atexit. This provides a mean for the dynamic
417 linker to call DT_FINI functions for shared libraries that have
418 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
419 index 3f0c59f..cf1e100 100644
420 --- a/arch/alpha/include/asm/pgtable.h
421 +++ b/arch/alpha/include/asm/pgtable.h
422 @@ -101,6 +101,17 @@ struct vm_area_struct;
423 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
424 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
425 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
426 +
427 +#ifdef CONFIG_PAX_PAGEEXEC
428 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
429 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
430 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
431 +#else
432 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
433 +# define PAGE_COPY_NOEXEC PAGE_COPY
434 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
435 +#endif
436 +
437 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
438
439 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
440 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
441 index ebc3c89..20cfa63 100644
442 --- a/arch/alpha/kernel/module.c
443 +++ b/arch/alpha/kernel/module.c
444 @@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
445
446 /* The small sections were sorted to the end of the segment.
447 The following should definitely cover them. */
448 - gp = (u64)me->module_core + me->core_size - 0x8000;
449 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
450 got = sechdrs[me->arch.gotsecindex].sh_addr;
451
452 for (i = 0; i < n; i++) {
453 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
454 index a94e49c..d71dd44 100644
455 --- a/arch/alpha/kernel/osf_sys.c
456 +++ b/arch/alpha/kernel/osf_sys.c
457 @@ -1172,7 +1172,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
458 /* At this point: (!vma || addr < vma->vm_end). */
459 if (limit - len < addr)
460 return -ENOMEM;
461 - if (!vma || addr + len <= vma->vm_start)
462 + if (check_heap_stack_gap(vma, addr, len))
463 return addr;
464 addr = vma->vm_end;
465 vma = vma->vm_next;
466 @@ -1208,6 +1208,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
467 merely specific addresses, but regions of memory -- perhaps
468 this feature should be incorporated into all ports? */
469
470 +#ifdef CONFIG_PAX_RANDMMAP
471 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
472 +#endif
473 +
474 if (addr) {
475 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
476 if (addr != (unsigned long) -ENOMEM)
477 @@ -1215,8 +1219,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
478 }
479
480 /* Next, try allocating at TASK_UNMAPPED_BASE. */
481 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
482 - len, limit);
483 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
484 +
485 if (addr != (unsigned long) -ENOMEM)
486 return addr;
487
488 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
489 index 00a31de..2ded0f2 100644
490 --- a/arch/alpha/mm/fault.c
491 +++ b/arch/alpha/mm/fault.c
492 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
493 __reload_thread(pcb);
494 }
495
496 +#ifdef CONFIG_PAX_PAGEEXEC
497 +/*
498 + * PaX: decide what to do with offenders (regs->pc = fault address)
499 + *
500 + * returns 1 when task should be killed
501 + * 2 when patched PLT trampoline was detected
502 + * 3 when unpatched PLT trampoline was detected
503 + */
504 +static int pax_handle_fetch_fault(struct pt_regs *regs)
505 +{
506 +
507 +#ifdef CONFIG_PAX_EMUPLT
508 + int err;
509 +
510 + do { /* PaX: patched PLT emulation #1 */
511 + unsigned int ldah, ldq, jmp;
512 +
513 + err = get_user(ldah, (unsigned int *)regs->pc);
514 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
515 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
516 +
517 + if (err)
518 + break;
519 +
520 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
521 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
522 + jmp == 0x6BFB0000U)
523 + {
524 + unsigned long r27, addr;
525 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
526 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
527 +
528 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
529 + err = get_user(r27, (unsigned long *)addr);
530 + if (err)
531 + break;
532 +
533 + regs->r27 = r27;
534 + regs->pc = r27;
535 + return 2;
536 + }
537 + } while (0);
538 +
539 + do { /* PaX: patched PLT emulation #2 */
540 + unsigned int ldah, lda, br;
541 +
542 + err = get_user(ldah, (unsigned int *)regs->pc);
543 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
544 + err |= get_user(br, (unsigned int *)(regs->pc+8));
545 +
546 + if (err)
547 + break;
548 +
549 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
550 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
551 + (br & 0xFFE00000U) == 0xC3E00000U)
552 + {
553 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
554 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
555 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
556 +
557 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
558 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
559 + return 2;
560 + }
561 + } while (0);
562 +
563 + do { /* PaX: unpatched PLT emulation */
564 + unsigned int br;
565 +
566 + err = get_user(br, (unsigned int *)regs->pc);
567 +
568 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
569 + unsigned int br2, ldq, nop, jmp;
570 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
571 +
572 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
573 + err = get_user(br2, (unsigned int *)addr);
574 + err |= get_user(ldq, (unsigned int *)(addr+4));
575 + err |= get_user(nop, (unsigned int *)(addr+8));
576 + err |= get_user(jmp, (unsigned int *)(addr+12));
577 + err |= get_user(resolver, (unsigned long *)(addr+16));
578 +
579 + if (err)
580 + break;
581 +
582 + if (br2 == 0xC3600000U &&
583 + ldq == 0xA77B000CU &&
584 + nop == 0x47FF041FU &&
585 + jmp == 0x6B7B0000U)
586 + {
587 + regs->r28 = regs->pc+4;
588 + regs->r27 = addr+16;
589 + regs->pc = resolver;
590 + return 3;
591 + }
592 + }
593 + } while (0);
594 +#endif
595 +
596 + return 1;
597 +}
598 +
599 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
600 +{
601 + unsigned long i;
602 +
603 + printk(KERN_ERR "PAX: bytes at PC: ");
604 + for (i = 0; i < 5; i++) {
605 + unsigned int c;
606 + if (get_user(c, (unsigned int *)pc+i))
607 + printk(KERN_CONT "???????? ");
608 + else
609 + printk(KERN_CONT "%08x ", c);
610 + }
611 + printk("\n");
612 +}
613 +#endif
614
615 /*
616 * This routine handles page faults. It determines the address,
617 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
618 good_area:
619 si_code = SEGV_ACCERR;
620 if (cause < 0) {
621 - if (!(vma->vm_flags & VM_EXEC))
622 + if (!(vma->vm_flags & VM_EXEC)) {
623 +
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
626 + goto bad_area;
627 +
628 + up_read(&mm->mmap_sem);
629 + switch (pax_handle_fetch_fault(regs)) {
630 +
631 +#ifdef CONFIG_PAX_EMUPLT
632 + case 2:
633 + case 3:
634 + return;
635 +#endif
636 +
637 + }
638 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
639 + do_group_exit(SIGKILL);
640 +#else
641 goto bad_area;
642 +#endif
643 +
644 + }
645 } else if (!cause) {
646 /* Allow reads even for write-only mappings */
647 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
648 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
649 index 6aac3f5..265536b 100644
650 --- a/arch/arm/include/asm/elf.h
651 +++ b/arch/arm/include/asm/elf.h
652 @@ -109,7 +109,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
653 the loader. We need to make sure that it is out of the way of the program
654 that it will "exec", and that there is sufficient room for the brk. */
655
656 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
657 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
658 +
659 +#ifdef CONFIG_PAX_ASLR
660 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
661 +
662 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
663 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
664 +#endif
665
666 /* When the program starts, a1 contains a pointer to a function to be
667 registered with atexit, as per the SVR4 ABI. A value of 0 means we
668 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
669 index c019949..388fdd1 100644
670 --- a/arch/arm/include/asm/kmap_types.h
671 +++ b/arch/arm/include/asm/kmap_types.h
672 @@ -19,6 +19,7 @@ enum km_type {
673 KM_SOFTIRQ0,
674 KM_SOFTIRQ1,
675 KM_L2_CACHE,
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 1d6bd40..fba0cb9 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 0e62770..e2c2cd6 100644
741 --- a/arch/arm/kernel/armksyms.c
742 +++ b/arch/arm/kernel/armksyms.c
743 @@ -118,8 +118,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/kgdb.c b/arch/arm/kernel/kgdb.c
755 index ba8ccfe..2dc34dc 100644
756 --- a/arch/arm/kernel/kgdb.c
757 +++ b/arch/arm/kernel/kgdb.c
758 @@ -190,7 +190,7 @@ void kgdb_arch_exit(void)
759 * and we handle the normal undef case within the do_undefinstr
760 * handler.
761 */
762 -struct kgdb_arch arch_kgdb_ops = {
763 +const struct kgdb_arch arch_kgdb_ops = {
764 #ifndef __ARMEB__
765 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
766 #else /* ! __ARMEB__ */
767 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
768 index 3f361a7..6e806e1 100644
769 --- a/arch/arm/kernel/traps.c
770 +++ b/arch/arm/kernel/traps.c
771 @@ -247,6 +247,8 @@ static void __die(const char *str, int err, struct thread_info *thread, struct p
772
773 DEFINE_SPINLOCK(die_lock);
774
775 +extern void gr_handle_kernel_exploit(void);
776 +
777 /*
778 * This function is protected against re-entrancy.
779 */
780 @@ -271,6 +273,8 @@ NORET_TYPE void die(const char *str, struct pt_regs *regs, int err)
781 if (panic_on_oops)
782 panic("Fatal exception");
783
784 + gr_handle_kernel_exploit();
785 +
786 do_exit(SIGSEGV);
787 }
788
789 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
790 index e4fe124..0fc246b 100644
791 --- a/arch/arm/lib/copy_from_user.S
792 +++ b/arch/arm/lib/copy_from_user.S
793 @@ -16,7 +16,7 @@
794 /*
795 * Prototype:
796 *
797 - * size_t __copy_from_user(void *to, const void *from, size_t n)
798 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
799 *
800 * Purpose:
801 *
802 @@ -84,11 +84,11 @@
803
804 .text
805
806 -ENTRY(__copy_from_user)
807 +ENTRY(___copy_from_user)
808
809 #include "copy_template.S"
810
811 -ENDPROC(__copy_from_user)
812 +ENDPROC(___copy_from_user)
813
814 .section .fixup,"ax"
815 .align 0
816 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
817 index 1a71e15..ac7b258 100644
818 --- a/arch/arm/lib/copy_to_user.S
819 +++ b/arch/arm/lib/copy_to_user.S
820 @@ -16,7 +16,7 @@
821 /*
822 * Prototype:
823 *
824 - * size_t __copy_to_user(void *to, const void *from, size_t n)
825 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
826 *
827 * Purpose:
828 *
829 @@ -88,11 +88,11 @@
830 .text
831
832 ENTRY(__copy_to_user_std)
833 -WEAK(__copy_to_user)
834 +WEAK(___copy_to_user)
835
836 #include "copy_template.S"
837
838 -ENDPROC(__copy_to_user)
839 +ENDPROC(___copy_to_user)
840
841 .section .fixup,"ax"
842 .align 0
843 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
844 index ffdd274..91017b6 100644
845 --- a/arch/arm/lib/uaccess.S
846 +++ b/arch/arm/lib/uaccess.S
847 @@ -19,7 +19,7 @@
848
849 #define PAGE_SHIFT 12
850
851 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
852 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
853 * Purpose : copy a block to user memory from kernel memory
854 * Params : to - user memory
855 * : from - kernel memory
856 @@ -39,7 +39,7 @@ USER( strgtbt r3, [r0], #1) @ May fault
857 sub r2, r2, ip
858 b .Lc2u_dest_aligned
859
860 -ENTRY(__copy_to_user)
861 +ENTRY(___copy_to_user)
862 stmfd sp!, {r2, r4 - r7, lr}
863 cmp r2, #4
864 blt .Lc2u_not_enough
865 @@ -277,14 +277,14 @@ USER( strgebt r3, [r0], #1) @ May fault
866 ldrgtb r3, [r1], #0
867 USER( strgtbt r3, [r0], #1) @ May fault
868 b .Lc2u_finished
869 -ENDPROC(__copy_to_user)
870 +ENDPROC(___copy_to_user)
871
872 .section .fixup,"ax"
873 .align 0
874 9001: ldmfd sp!, {r0, r4 - r7, pc}
875 .previous
876
877 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
878 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
879 * Purpose : copy a block from user memory to kernel memory
880 * Params : to - kernel memory
881 * : from - user memory
882 @@ -303,7 +303,7 @@ USER( ldrgtbt r3, [r1], #1) @ May fault
883 sub r2, r2, ip
884 b .Lcfu_dest_aligned
885
886 -ENTRY(__copy_from_user)
887 +ENTRY(___copy_from_user)
888 stmfd sp!, {r0, r2, r4 - r7, lr}
889 cmp r2, #4
890 blt .Lcfu_not_enough
891 @@ -543,7 +543,7 @@ USER( ldrgebt r3, [r1], #1) @ May fault
892 USER( ldrgtbt r3, [r1], #1) @ May fault
893 strgtb r3, [r0], #1
894 b .Lcfu_finished
895 -ENDPROC(__copy_from_user)
896 +ENDPROC(___copy_from_user)
897
898 .section .fixup,"ax"
899 .align 0
900 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
901 index 6b967ff..67d5b2b 100644
902 --- a/arch/arm/lib/uaccess_with_memcpy.c
903 +++ b/arch/arm/lib/uaccess_with_memcpy.c
904 @@ -97,7 +97,7 @@ out:
905 }
906
907 unsigned long
908 -__copy_to_user(void __user *to, const void *from, unsigned long n)
909 +___copy_to_user(void __user *to, const void *from, unsigned long n)
910 {
911 /*
912 * This test is stubbed out of the main function above to keep
913 diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
914 index 4028724..beec230 100644
915 --- a/arch/arm/mach-at91/pm.c
916 +++ b/arch/arm/mach-at91/pm.c
917 @@ -348,7 +348,7 @@ static void at91_pm_end(void)
918 }
919
920
921 -static struct platform_suspend_ops at91_pm_ops ={
922 +static const struct platform_suspend_ops at91_pm_ops ={
923 .valid = at91_pm_valid_state,
924 .begin = at91_pm_begin,
925 .enter = at91_pm_enter,
926 diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
927 index 5218943..0a34552 100644
928 --- a/arch/arm/mach-omap1/pm.c
929 +++ b/arch/arm/mach-omap1/pm.c
930 @@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq = {
931
932
933
934 -static struct platform_suspend_ops omap_pm_ops ={
935 +static const struct platform_suspend_ops omap_pm_ops ={
936 .prepare = omap_pm_prepare,
937 .enter = omap_pm_enter,
938 .finish = omap_pm_finish,
939 diff --git a/arch/arm/mach-omap2/pm24xx.c b/arch/arm/mach-omap2/pm24xx.c
940 index bff5c4e..d4c649b 100644
941 --- a/arch/arm/mach-omap2/pm24xx.c
942 +++ b/arch/arm/mach-omap2/pm24xx.c
943 @@ -326,7 +326,7 @@ static void omap2_pm_finish(void)
944 enable_hlt();
945 }
946
947 -static struct platform_suspend_ops omap_pm_ops = {
948 +static const struct platform_suspend_ops omap_pm_ops = {
949 .prepare = omap2_pm_prepare,
950 .enter = omap2_pm_enter,
951 .finish = omap2_pm_finish,
952 diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
953 index 8946319..7d3e661 100644
954 --- a/arch/arm/mach-omap2/pm34xx.c
955 +++ b/arch/arm/mach-omap2/pm34xx.c
956 @@ -401,7 +401,7 @@ static void omap3_pm_end(void)
957 return;
958 }
959
960 -static struct platform_suspend_ops omap_pm_ops = {
961 +static const struct platform_suspend_ops omap_pm_ops = {
962 .begin = omap3_pm_begin,
963 .end = omap3_pm_end,
964 .prepare = omap3_pm_prepare,
965 diff --git a/arch/arm/mach-pnx4008/pm.c b/arch/arm/mach-pnx4008/pm.c
966 index b3d8d53..6e68ebc 100644
967 --- a/arch/arm/mach-pnx4008/pm.c
968 +++ b/arch/arm/mach-pnx4008/pm.c
969 @@ -116,7 +116,7 @@ static int pnx4008_pm_valid(suspend_state_t state)
970 (state == PM_SUSPEND_MEM);
971 }
972
973 -static struct platform_suspend_ops pnx4008_pm_ops = {
974 +static const struct platform_suspend_ops pnx4008_pm_ops = {
975 .enter = pnx4008_pm_enter,
976 .valid = pnx4008_pm_valid,
977 };
978 diff --git a/arch/arm/mach-pxa/pm.c b/arch/arm/mach-pxa/pm.c
979 index 7693355..9beb00a 100644
980 --- a/arch/arm/mach-pxa/pm.c
981 +++ b/arch/arm/mach-pxa/pm.c
982 @@ -95,7 +95,7 @@ void pxa_pm_finish(void)
983 pxa_cpu_pm_fns->finish();
984 }
985
986 -static struct platform_suspend_ops pxa_pm_ops = {
987 +static const struct platform_suspend_ops pxa_pm_ops = {
988 .valid = pxa_pm_valid,
989 .enter = pxa_pm_enter,
990 .prepare = pxa_pm_prepare,
991 diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
992 index 629e05d..06be589 100644
993 --- a/arch/arm/mach-pxa/sharpsl_pm.c
994 +++ b/arch/arm/mach-pxa/sharpsl_pm.c
995 @@ -891,7 +891,7 @@ static void sharpsl_apm_get_power_status(struct apm_power_info *info)
996 }
997
998 #ifdef CONFIG_PM
999 -static struct platform_suspend_ops sharpsl_pm_ops = {
1000 +static const struct platform_suspend_ops sharpsl_pm_ops = {
1001 .prepare = pxa_pm_prepare,
1002 .finish = pxa_pm_finish,
1003 .enter = corgi_pxa_pm_enter,
1004 diff --git a/arch/arm/mach-sa1100/pm.c b/arch/arm/mach-sa1100/pm.c
1005 index c83fdc8..ab9fc44 100644
1006 --- a/arch/arm/mach-sa1100/pm.c
1007 +++ b/arch/arm/mach-sa1100/pm.c
1008 @@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
1009 return virt_to_phys(sp);
1010 }
1011
1012 -static struct platform_suspend_ops sa11x0_pm_ops = {
1013 +static const struct platform_suspend_ops sa11x0_pm_ops = {
1014 .enter = sa11x0_pm_enter,
1015 .valid = suspend_valid_only_mem,
1016 };
1017 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1018 index 3191cd6..c0739db 100644
1019 --- a/arch/arm/mm/fault.c
1020 +++ b/arch/arm/mm/fault.c
1021 @@ -166,6 +166,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1022 }
1023 #endif
1024
1025 +#ifdef CONFIG_PAX_PAGEEXEC
1026 + if (fsr & FSR_LNX_PF) {
1027 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1028 + do_group_exit(SIGKILL);
1029 + }
1030 +#endif
1031 +
1032 tsk->thread.address = addr;
1033 tsk->thread.error_code = fsr;
1034 tsk->thread.trap_no = 14;
1035 @@ -357,6 +364,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1036 }
1037 #endif /* CONFIG_MMU */
1038
1039 +#ifdef CONFIG_PAX_PAGEEXEC
1040 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1041 +{
1042 + long i;
1043 +
1044 + printk(KERN_ERR "PAX: bytes at PC: ");
1045 + for (i = 0; i < 20; i++) {
1046 + unsigned char c;
1047 + if (get_user(c, (__force unsigned char __user *)pc+i))
1048 + printk(KERN_CONT "?? ");
1049 + else
1050 + printk(KERN_CONT "%02x ", c);
1051 + }
1052 + printk("\n");
1053 +
1054 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1055 + for (i = -1; i < 20; i++) {
1056 + unsigned long c;
1057 + if (get_user(c, (__force unsigned long __user *)sp+i))
1058 + printk(KERN_CONT "???????? ");
1059 + else
1060 + printk(KERN_CONT "%08lx ", c);
1061 + }
1062 + printk("\n");
1063 +}
1064 +#endif
1065 +
1066 /*
1067 * First Level Translation Fault Handler
1068 *
1069 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1070 index f5abc51..7ec524c 100644
1071 --- a/arch/arm/mm/mmap.c
1072 +++ b/arch/arm/mm/mmap.c
1073 @@ -63,6 +63,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1074 if (len > TASK_SIZE)
1075 return -ENOMEM;
1076
1077 +#ifdef CONFIG_PAX_RANDMMAP
1078 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1079 +#endif
1080 +
1081 if (addr) {
1082 if (do_align)
1083 addr = COLOUR_ALIGN(addr, pgoff);
1084 @@ -70,15 +74,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1085 addr = PAGE_ALIGN(addr);
1086
1087 vma = find_vma(mm, addr);
1088 - if (TASK_SIZE - len >= addr &&
1089 - (!vma || addr + len <= vma->vm_start))
1090 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1091 return addr;
1092 }
1093 if (len > mm->cached_hole_size) {
1094 - start_addr = addr = mm->free_area_cache;
1095 + start_addr = addr = mm->free_area_cache;
1096 } else {
1097 - start_addr = addr = TASK_UNMAPPED_BASE;
1098 - mm->cached_hole_size = 0;
1099 + start_addr = addr = mm->mmap_base;
1100 + mm->cached_hole_size = 0;
1101 }
1102
1103 full_search:
1104 @@ -94,14 +97,14 @@ full_search:
1105 * Start a new search - just in case we missed
1106 * some holes.
1107 */
1108 - if (start_addr != TASK_UNMAPPED_BASE) {
1109 - start_addr = addr = TASK_UNMAPPED_BASE;
1110 + if (start_addr != mm->mmap_base) {
1111 + start_addr = addr = mm->mmap_base;
1112 mm->cached_hole_size = 0;
1113 goto full_search;
1114 }
1115 return -ENOMEM;
1116 }
1117 - if (!vma || addr + len <= vma->vm_start) {
1118 + if (check_heap_stack_gap(vma, addr, len)) {
1119 /*
1120 * Remember the place where we stopped the search:
1121 */
1122 diff --git a/arch/arm/plat-s3c/pm.c b/arch/arm/plat-s3c/pm.c
1123 index 8d97db2..b66cfa5 100644
1124 --- a/arch/arm/plat-s3c/pm.c
1125 +++ b/arch/arm/plat-s3c/pm.c
1126 @@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
1127 s3c_pm_check_cleanup();
1128 }
1129
1130 -static struct platform_suspend_ops s3c_pm_ops = {
1131 +static const struct platform_suspend_ops s3c_pm_ops = {
1132 .enter = s3c_pm_enter,
1133 .prepare = s3c_pm_prepare,
1134 .finish = s3c_pm_finish,
1135 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1136 index d5d1d41..856e2ed 100644
1137 --- a/arch/avr32/include/asm/elf.h
1138 +++ b/arch/avr32/include/asm/elf.h
1139 @@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1140 the loader. We need to make sure that it is out of the way of the program
1141 that it will "exec", and that there is sufficient room for the brk. */
1142
1143 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1144 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1145
1146 +#ifdef CONFIG_PAX_ASLR
1147 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1148 +
1149 +#define PAX_DELTA_MMAP_LEN 15
1150 +#define PAX_DELTA_STACK_LEN 15
1151 +#endif
1152
1153 /* This yields a mask that user programs can use to figure out what
1154 instruction set this CPU supports. This could be done in user space,
1155 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1156 index b7f5c68..556135c 100644
1157 --- a/arch/avr32/include/asm/kmap_types.h
1158 +++ b/arch/avr32/include/asm/kmap_types.h
1159 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1160 D(11) KM_IRQ1,
1161 D(12) KM_SOFTIRQ0,
1162 D(13) KM_SOFTIRQ1,
1163 -D(14) KM_TYPE_NR
1164 +D(14) KM_CLEARPAGE,
1165 +D(15) KM_TYPE_NR
1166 };
1167
1168 #undef D
1169 diff --git a/arch/avr32/mach-at32ap/pm.c b/arch/avr32/mach-at32ap/pm.c
1170 index f021edf..32d680e 100644
1171 --- a/arch/avr32/mach-at32ap/pm.c
1172 +++ b/arch/avr32/mach-at32ap/pm.c
1173 @@ -176,7 +176,7 @@ out:
1174 return 0;
1175 }
1176
1177 -static struct platform_suspend_ops avr32_pm_ops = {
1178 +static const struct platform_suspend_ops avr32_pm_ops = {
1179 .valid = avr32_pm_valid_state,
1180 .enter = avr32_pm_enter,
1181 };
1182 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1183 index b61d86d..e292c7f 100644
1184 --- a/arch/avr32/mm/fault.c
1185 +++ b/arch/avr32/mm/fault.c
1186 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1187
1188 int exception_trace = 1;
1189
1190 +#ifdef CONFIG_PAX_PAGEEXEC
1191 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1192 +{
1193 + unsigned long i;
1194 +
1195 + printk(KERN_ERR "PAX: bytes at PC: ");
1196 + for (i = 0; i < 20; i++) {
1197 + unsigned char c;
1198 + if (get_user(c, (unsigned char *)pc+i))
1199 + printk(KERN_CONT "???????? ");
1200 + else
1201 + printk(KERN_CONT "%02x ", c);
1202 + }
1203 + printk("\n");
1204 +}
1205 +#endif
1206 +
1207 /*
1208 * This routine handles page faults. It determines the address and the
1209 * problem, and then passes it off to one of the appropriate routines.
1210 @@ -157,6 +174,16 @@ bad_area:
1211 up_read(&mm->mmap_sem);
1212
1213 if (user_mode(regs)) {
1214 +
1215 +#ifdef CONFIG_PAX_PAGEEXEC
1216 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1217 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1218 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1219 + do_group_exit(SIGKILL);
1220 + }
1221 + }
1222 +#endif
1223 +
1224 if (exception_trace && printk_ratelimit())
1225 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1226 "sp %08lx ecr %lu\n",
1227 diff --git a/arch/blackfin/kernel/kgdb.c b/arch/blackfin/kernel/kgdb.c
1228 index cce79d0..c406c85 100644
1229 --- a/arch/blackfin/kernel/kgdb.c
1230 +++ b/arch/blackfin/kernel/kgdb.c
1231 @@ -428,7 +428,7 @@ int kgdb_arch_handle_exception(int vector, int signo,
1232 return -1; /* this means that we do not want to exit from the handler */
1233 }
1234
1235 -struct kgdb_arch arch_kgdb_ops = {
1236 +const struct kgdb_arch arch_kgdb_ops = {
1237 .gdb_bpt_instr = {0xa1},
1238 #ifdef CONFIG_SMP
1239 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
1240 diff --git a/arch/blackfin/mach-common/pm.c b/arch/blackfin/mach-common/pm.c
1241 index 8837be4..b2fb413 100644
1242 --- a/arch/blackfin/mach-common/pm.c
1243 +++ b/arch/blackfin/mach-common/pm.c
1244 @@ -255,7 +255,7 @@ static int bfin_pm_enter(suspend_state_t state)
1245 return 0;
1246 }
1247
1248 -struct platform_suspend_ops bfin_pm_ops = {
1249 +const struct platform_suspend_ops bfin_pm_ops = {
1250 .enter = bfin_pm_enter,
1251 .valid = bfin_pm_valid,
1252 };
1253 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1254 index f8e16b2..c73ff79 100644
1255 --- a/arch/frv/include/asm/kmap_types.h
1256 +++ b/arch/frv/include/asm/kmap_types.h
1257 @@ -23,6 +23,7 @@ enum km_type {
1258 KM_IRQ1,
1259 KM_SOFTIRQ0,
1260 KM_SOFTIRQ1,
1261 + KM_CLEARPAGE,
1262 KM_TYPE_NR
1263 };
1264
1265 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1266 index 385fd30..6c3d97e 100644
1267 --- a/arch/frv/mm/elf-fdpic.c
1268 +++ b/arch/frv/mm/elf-fdpic.c
1269 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1270 if (addr) {
1271 addr = PAGE_ALIGN(addr);
1272 vma = find_vma(current->mm, addr);
1273 - if (TASK_SIZE - len >= addr &&
1274 - (!vma || addr + len <= vma->vm_start))
1275 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1276 goto success;
1277 }
1278
1279 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1280 for (; vma; vma = vma->vm_next) {
1281 if (addr > limit)
1282 break;
1283 - if (addr + len <= vma->vm_start)
1284 + if (check_heap_stack_gap(vma, addr, len))
1285 goto success;
1286 addr = vma->vm_end;
1287 }
1288 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1289 for (; vma; vma = vma->vm_next) {
1290 if (addr > limit)
1291 break;
1292 - if (addr + len <= vma->vm_start)
1293 + if (check_heap_stack_gap(vma, addr, len))
1294 goto success;
1295 addr = vma->vm_end;
1296 }
1297 diff --git a/arch/ia64/hp/common/hwsw_iommu.c b/arch/ia64/hp/common/hwsw_iommu.c
1298 index e4a80d8..11a7ea1 100644
1299 --- a/arch/ia64/hp/common/hwsw_iommu.c
1300 +++ b/arch/ia64/hp/common/hwsw_iommu.c
1301 @@ -17,7 +17,7 @@
1302 #include <linux/swiotlb.h>
1303 #include <asm/machvec.h>
1304
1305 -extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1306 +extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1307
1308 /* swiotlb declarations & definitions: */
1309 extern int swiotlb_late_init_with_default_size (size_t size);
1310 @@ -33,7 +33,7 @@ static inline int use_swiotlb(struct device *dev)
1311 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1312 }
1313
1314 -struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1315 +const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1316 {
1317 if (use_swiotlb(dev))
1318 return &swiotlb_dma_ops;
1319 diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
1320 index 01ae69b..35752fd 100644
1321 --- a/arch/ia64/hp/common/sba_iommu.c
1322 +++ b/arch/ia64/hp/common/sba_iommu.c
1323 @@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_driver = {
1324 },
1325 };
1326
1327 -extern struct dma_map_ops swiotlb_dma_ops;
1328 +extern const struct dma_map_ops swiotlb_dma_ops;
1329
1330 static int __init
1331 sba_init(void)
1332 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1333
1334 __setup("sbapagesize=",sba_page_override);
1335
1336 -struct dma_map_ops sba_dma_ops = {
1337 +const struct dma_map_ops sba_dma_ops = {
1338 .alloc_coherent = sba_alloc_coherent,
1339 .free_coherent = sba_free_coherent,
1340 .map_page = sba_map_page,
1341 diff --git a/arch/ia64/ia32/binfmt_elf32.c b/arch/ia64/ia32/binfmt_elf32.c
1342 index c69552b..c7122f4 100644
1343 --- a/arch/ia64/ia32/binfmt_elf32.c
1344 +++ b/arch/ia64/ia32/binfmt_elf32.c
1345 @@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_top);
1346
1347 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
1348
1349 +#ifdef CONFIG_PAX_ASLR
1350 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1351 +
1352 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1353 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1354 +#endif
1355 +
1356 /* Ugly but avoids duplication */
1357 #include "../../../fs/binfmt_elf.c"
1358
1359 diff --git a/arch/ia64/ia32/ia32priv.h b/arch/ia64/ia32/ia32priv.h
1360 index 0f15349..26b3429 100644
1361 --- a/arch/ia64/ia32/ia32priv.h
1362 +++ b/arch/ia64/ia32/ia32priv.h
1363 @@ -296,7 +296,14 @@ typedef struct compat_siginfo {
1364 #define ELF_DATA ELFDATA2LSB
1365 #define ELF_ARCH EM_386
1366
1367 -#define IA32_STACK_TOP IA32_PAGE_OFFSET
1368 +#ifdef CONFIG_PAX_RANDUSTACK
1369 +#define __IA32_DELTA_STACK (current->mm->delta_stack)
1370 +#else
1371 +#define __IA32_DELTA_STACK 0UL
1372 +#endif
1373 +
1374 +#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
1375 +
1376 #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
1377 #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
1378
1379 diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
1380 index 8d3c79c..71b3af6 100644
1381 --- a/arch/ia64/include/asm/dma-mapping.h
1382 +++ b/arch/ia64/include/asm/dma-mapping.h
1383 @@ -12,7 +12,7 @@
1384
1385 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
1386
1387 -extern struct dma_map_ops *dma_ops;
1388 +extern const struct dma_map_ops *dma_ops;
1389 extern struct ia64_machine_vector ia64_mv;
1390 extern void set_iommu_machvec(void);
1391
1392 @@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
1393 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1394 dma_addr_t *daddr, gfp_t gfp)
1395 {
1396 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1397 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1398 void *caddr;
1399
1400 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1401 @@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1402 static inline void dma_free_coherent(struct device *dev, size_t size,
1403 void *caddr, dma_addr_t daddr)
1404 {
1405 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1406 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1407 debug_dma_free_coherent(dev, size, caddr, daddr);
1408 ops->free_coherent(dev, size, caddr, daddr);
1409 }
1410 @@ -49,13 +49,13 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
1411
1412 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1413 {
1414 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1415 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1416 return ops->mapping_error(dev, daddr);
1417 }
1418
1419 static inline int dma_supported(struct device *dev, u64 mask)
1420 {
1421 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1422 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1423 return ops->dma_supported(dev, mask);
1424 }
1425
1426 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1427 index 86eddee..b116bb4 100644
1428 --- a/arch/ia64/include/asm/elf.h
1429 +++ b/arch/ia64/include/asm/elf.h
1430 @@ -43,6 +43,13 @@
1431 */
1432 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1433
1434 +#ifdef CONFIG_PAX_ASLR
1435 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1436 +
1437 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1438 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1439 +#endif
1440 +
1441 #define PT_IA_64_UNWIND 0x70000001
1442
1443 /* IA-64 relocations: */
1444 diff --git a/arch/ia64/include/asm/machvec.h b/arch/ia64/include/asm/machvec.h
1445 index 367d299..9ad4279 100644
1446 --- a/arch/ia64/include/asm/machvec.h
1447 +++ b/arch/ia64/include/asm/machvec.h
1448 @@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event_t(void);
1449 /* DMA-mapping interface: */
1450 typedef void ia64_mv_dma_init (void);
1451 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1452 -typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1453 +typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1454
1455 /*
1456 * WARNING: The legacy I/O space is _architected_. Platforms are
1457 @@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(const char *cmdline);
1458 # endif /* CONFIG_IA64_GENERIC */
1459
1460 extern void swiotlb_dma_init(void);
1461 -extern struct dma_map_ops *dma_get_ops(struct device *);
1462 +extern const struct dma_map_ops *dma_get_ops(struct device *);
1463
1464 /*
1465 * Define default versions so we can extend machvec for new platforms without having
1466 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1467 index 8840a69..cdb63d9 100644
1468 --- a/arch/ia64/include/asm/pgtable.h
1469 +++ b/arch/ia64/include/asm/pgtable.h
1470 @@ -12,7 +12,7 @@
1471 * David Mosberger-Tang <davidm@hpl.hp.com>
1472 */
1473
1474 -
1475 +#include <linux/const.h>
1476 #include <asm/mman.h>
1477 #include <asm/page.h>
1478 #include <asm/processor.h>
1479 @@ -143,6 +143,17 @@
1480 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1481 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1482 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1483 +
1484 +#ifdef CONFIG_PAX_PAGEEXEC
1485 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1486 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1487 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1488 +#else
1489 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1490 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1491 +# define PAGE_COPY_NOEXEC PAGE_COPY
1492 +#endif
1493 +
1494 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1495 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1496 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1497 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1498 index 239ecdc..f94170e 100644
1499 --- a/arch/ia64/include/asm/spinlock.h
1500 +++ b/arch/ia64/include/asm/spinlock.h
1501 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(raw_spinlock_t *lock)
1502 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1503
1504 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1505 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1506 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1507 }
1508
1509 static __always_inline void __ticket_spin_unlock_wait(raw_spinlock_t *lock)
1510 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1511 index 449c8c0..432a3d2 100644
1512 --- a/arch/ia64/include/asm/uaccess.h
1513 +++ b/arch/ia64/include/asm/uaccess.h
1514 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1515 const void *__cu_from = (from); \
1516 long __cu_len = (n); \
1517 \
1518 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1519 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1520 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1521 __cu_len; \
1522 })
1523 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1524 long __cu_len = (n); \
1525 \
1526 __chk_user_ptr(__cu_from); \
1527 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1528 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1529 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1530 __cu_len; \
1531 })
1532 diff --git a/arch/ia64/kernel/dma-mapping.c b/arch/ia64/kernel/dma-mapping.c
1533 index f2c1600..969398a 100644
1534 --- a/arch/ia64/kernel/dma-mapping.c
1535 +++ b/arch/ia64/kernel/dma-mapping.c
1536 @@ -3,7 +3,7 @@
1537 /* Set this to 1 if there is a HW IOMMU in the system */
1538 int iommu_detected __read_mostly;
1539
1540 -struct dma_map_ops *dma_ops;
1541 +const struct dma_map_ops *dma_ops;
1542 EXPORT_SYMBOL(dma_ops);
1543
1544 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1545 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1546 }
1547 fs_initcall(dma_init);
1548
1549 -struct dma_map_ops *dma_get_ops(struct device *dev)
1550 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1551 {
1552 return dma_ops;
1553 }
1554 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1555 index 1481b0a..e7d38ff 100644
1556 --- a/arch/ia64/kernel/module.c
1557 +++ b/arch/ia64/kernel/module.c
1558 @@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1559 void
1560 module_free (struct module *mod, void *module_region)
1561 {
1562 - if (mod && mod->arch.init_unw_table &&
1563 - module_region == mod->module_init) {
1564 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1565 unw_remove_unwind_table(mod->arch.init_unw_table);
1566 mod->arch.init_unw_table = NULL;
1567 }
1568 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
1569 }
1570
1571 static inline int
1572 +in_init_rx (const struct module *mod, uint64_t addr)
1573 +{
1574 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1575 +}
1576 +
1577 +static inline int
1578 +in_init_rw (const struct module *mod, uint64_t addr)
1579 +{
1580 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1581 +}
1582 +
1583 +static inline int
1584 in_init (const struct module *mod, uint64_t addr)
1585 {
1586 - return addr - (uint64_t) mod->module_init < mod->init_size;
1587 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1588 +}
1589 +
1590 +static inline int
1591 +in_core_rx (const struct module *mod, uint64_t addr)
1592 +{
1593 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1594 +}
1595 +
1596 +static inline int
1597 +in_core_rw (const struct module *mod, uint64_t addr)
1598 +{
1599 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1600 }
1601
1602 static inline int
1603 in_core (const struct module *mod, uint64_t addr)
1604 {
1605 - return addr - (uint64_t) mod->module_core < mod->core_size;
1606 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1607 }
1608
1609 static inline int
1610 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
1611 break;
1612
1613 case RV_BDREL:
1614 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1615 + if (in_init_rx(mod, val))
1616 + val -= (uint64_t) mod->module_init_rx;
1617 + else if (in_init_rw(mod, val))
1618 + val -= (uint64_t) mod->module_init_rw;
1619 + else if (in_core_rx(mod, val))
1620 + val -= (uint64_t) mod->module_core_rx;
1621 + else if (in_core_rw(mod, val))
1622 + val -= (uint64_t) mod->module_core_rw;
1623 break;
1624
1625 case RV_LTV:
1626 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
1627 * addresses have been selected...
1628 */
1629 uint64_t gp;
1630 - if (mod->core_size > MAX_LTOFF)
1631 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1632 /*
1633 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1634 * at the end of the module.
1635 */
1636 - gp = mod->core_size - MAX_LTOFF / 2;
1637 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1638 else
1639 - gp = mod->core_size / 2;
1640 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1641 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1642 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1643 mod->arch.gp = gp;
1644 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1645 }
1646 diff --git a/arch/ia64/kernel/pci-dma.c b/arch/ia64/kernel/pci-dma.c
1647 index f6b1ff0..de773fb 100644
1648 --- a/arch/ia64/kernel/pci-dma.c
1649 +++ b/arch/ia64/kernel/pci-dma.c
1650 @@ -43,7 +43,7 @@ struct device fallback_dev = {
1651 .dma_mask = &fallback_dev.coherent_dma_mask,
1652 };
1653
1654 -extern struct dma_map_ops intel_dma_ops;
1655 +extern const struct dma_map_ops intel_dma_ops;
1656
1657 static int __init pci_iommu_init(void)
1658 {
1659 @@ -96,15 +96,34 @@ int iommu_dma_supported(struct device *dev, u64 mask)
1660 }
1661 EXPORT_SYMBOL(iommu_dma_supported);
1662
1663 +extern void *intel_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags);
1664 +extern void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
1665 +extern int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1666 +extern void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1667 +extern dma_addr_t intel_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1668 +extern void intel_unmap_page(struct device *dev, dma_addr_t dev_addr, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1669 +extern int intel_mapping_error(struct device *dev, dma_addr_t dma_addr);
1670 +
1671 +static const struct dma_map_ops intel_iommu_dma_ops = {
1672 + /* from drivers/pci/intel-iommu.c:intel_dma_ops */
1673 + .alloc_coherent = intel_alloc_coherent,
1674 + .free_coherent = intel_free_coherent,
1675 + .map_sg = intel_map_sg,
1676 + .unmap_sg = intel_unmap_sg,
1677 + .map_page = intel_map_page,
1678 + .unmap_page = intel_unmap_page,
1679 + .mapping_error = intel_mapping_error,
1680 +
1681 + .sync_single_for_cpu = machvec_dma_sync_single,
1682 + .sync_sg_for_cpu = machvec_dma_sync_sg,
1683 + .sync_single_for_device = machvec_dma_sync_single,
1684 + .sync_sg_for_device = machvec_dma_sync_sg,
1685 + .dma_supported = iommu_dma_supported,
1686 +};
1687 +
1688 void __init pci_iommu_alloc(void)
1689 {
1690 - dma_ops = &intel_dma_ops;
1691 -
1692 - dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
1693 - dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
1694 - dma_ops->sync_single_for_device = machvec_dma_sync_single;
1695 - dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
1696 - dma_ops->dma_supported = iommu_dma_supported;
1697 + dma_ops = &intel_iommu_dma_ops;
1698
1699 /*
1700 * The order of these functions is important for
1701 diff --git a/arch/ia64/kernel/pci-swiotlb.c b/arch/ia64/kernel/pci-swiotlb.c
1702 index 285aae8..61dbab6 100644
1703 --- a/arch/ia64/kernel/pci-swiotlb.c
1704 +++ b/arch/ia64/kernel/pci-swiotlb.c
1705 @@ -21,7 +21,7 @@ static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
1706 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1707 }
1708
1709 -struct dma_map_ops swiotlb_dma_ops = {
1710 +const struct dma_map_ops swiotlb_dma_ops = {
1711 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1712 .free_coherent = swiotlb_free_coherent,
1713 .map_page = swiotlb_map_page,
1714 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1715 index 609d500..7dde2a8 100644
1716 --- a/arch/ia64/kernel/sys_ia64.c
1717 +++ b/arch/ia64/kernel/sys_ia64.c
1718 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1719 if (REGION_NUMBER(addr) == RGN_HPAGE)
1720 addr = 0;
1721 #endif
1722 +
1723 +#ifdef CONFIG_PAX_RANDMMAP
1724 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1725 + addr = mm->free_area_cache;
1726 + else
1727 +#endif
1728 +
1729 if (!addr)
1730 addr = mm->free_area_cache;
1731
1732 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1733 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1734 /* At this point: (!vma || addr < vma->vm_end). */
1735 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1736 - if (start_addr != TASK_UNMAPPED_BASE) {
1737 + if (start_addr != mm->mmap_base) {
1738 /* Start a new search --- just in case we missed some holes. */
1739 - addr = TASK_UNMAPPED_BASE;
1740 + addr = mm->mmap_base;
1741 goto full_search;
1742 }
1743 return -ENOMEM;
1744 }
1745 - if (!vma || addr + len <= vma->vm_start) {
1746 + if (check_heap_stack_gap(vma, addr, len)) {
1747 /* Remember the address where we stopped this search: */
1748 mm->free_area_cache = addr + len;
1749 return addr;
1750 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
1751 index 8f06035..b3a5818 100644
1752 --- a/arch/ia64/kernel/topology.c
1753 +++ b/arch/ia64/kernel/topology.c
1754 @@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject * kobj, struct attribute * attr, char *
1755 return ret;
1756 }
1757
1758 -static struct sysfs_ops cache_sysfs_ops = {
1759 +static const struct sysfs_ops cache_sysfs_ops = {
1760 .show = cache_show
1761 };
1762
1763 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1764 index 0a0c77b..8e55a81 100644
1765 --- a/arch/ia64/kernel/vmlinux.lds.S
1766 +++ b/arch/ia64/kernel/vmlinux.lds.S
1767 @@ -190,7 +190,7 @@ SECTIONS
1768 /* Per-cpu data: */
1769 . = ALIGN(PERCPU_PAGE_SIZE);
1770 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1771 - __phys_per_cpu_start = __per_cpu_load;
1772 + __phys_per_cpu_start = per_cpu_load;
1773 . = __phys_per_cpu_start + PERCPU_PAGE_SIZE; /* ensure percpu data fits
1774 * into percpu page size
1775 */
1776 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1777 index 19261a9..1611b7a 100644
1778 --- a/arch/ia64/mm/fault.c
1779 +++ b/arch/ia64/mm/fault.c
1780 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
1781 return pte_present(pte);
1782 }
1783
1784 +#ifdef CONFIG_PAX_PAGEEXEC
1785 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1786 +{
1787 + unsigned long i;
1788 +
1789 + printk(KERN_ERR "PAX: bytes at PC: ");
1790 + for (i = 0; i < 8; i++) {
1791 + unsigned int c;
1792 + if (get_user(c, (unsigned int *)pc+i))
1793 + printk(KERN_CONT "???????? ");
1794 + else
1795 + printk(KERN_CONT "%08x ", c);
1796 + }
1797 + printk("\n");
1798 +}
1799 +#endif
1800 +
1801 void __kprobes
1802 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1803 {
1804 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
1805 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1806 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1807
1808 - if ((vma->vm_flags & mask) != mask)
1809 + if ((vma->vm_flags & mask) != mask) {
1810 +
1811 +#ifdef CONFIG_PAX_PAGEEXEC
1812 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1813 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1814 + goto bad_area;
1815 +
1816 + up_read(&mm->mmap_sem);
1817 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1818 + do_group_exit(SIGKILL);
1819 + }
1820 +#endif
1821 +
1822 goto bad_area;
1823
1824 + }
1825 +
1826 survive:
1827 /*
1828 * If for any reason at all we couldn't handle the fault, make
1829 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1830 index b0f6157..a082bbc 100644
1831 --- a/arch/ia64/mm/hugetlbpage.c
1832 +++ b/arch/ia64/mm/hugetlbpage.c
1833 @@ -172,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
1834 /* At this point: (!vmm || addr < vmm->vm_end). */
1835 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1836 return -ENOMEM;
1837 - if (!vmm || (addr + len) <= vmm->vm_start)
1838 + if (check_heap_stack_gap(vmm, addr, len))
1839 return addr;
1840 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1841 }
1842 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1843 index 1857766..05cc6a3 100644
1844 --- a/arch/ia64/mm/init.c
1845 +++ b/arch/ia64/mm/init.c
1846 @@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1847 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1848 vma->vm_end = vma->vm_start + PAGE_SIZE;
1849 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1850 +
1851 +#ifdef CONFIG_PAX_PAGEEXEC
1852 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1853 + vma->vm_flags &= ~VM_EXEC;
1854 +
1855 +#ifdef CONFIG_PAX_MPROTECT
1856 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1857 + vma->vm_flags &= ~VM_MAYEXEC;
1858 +#endif
1859 +
1860 + }
1861 +#endif
1862 +
1863 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1864 down_write(&current->mm->mmap_sem);
1865 if (insert_vm_struct(current->mm, vma)) {
1866 diff --git a/arch/ia64/sn/pci/pci_dma.c b/arch/ia64/sn/pci/pci_dma.c
1867 index 98b6849..8046766 100644
1868 --- a/arch/ia64/sn/pci/pci_dma.c
1869 +++ b/arch/ia64/sn/pci/pci_dma.c
1870 @@ -464,7 +464,7 @@ int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
1871 return ret;
1872 }
1873
1874 -static struct dma_map_ops sn_dma_ops = {
1875 +static const struct dma_map_ops sn_dma_ops = {
1876 .alloc_coherent = sn_dma_alloc_coherent,
1877 .free_coherent = sn_dma_free_coherent,
1878 .map_page = sn_dma_map_page,
1879 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1880 index 82abd15..d95ae5d 100644
1881 --- a/arch/m32r/lib/usercopy.c
1882 +++ b/arch/m32r/lib/usercopy.c
1883 @@ -14,6 +14,9 @@
1884 unsigned long
1885 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1886 {
1887 + if ((long)n < 0)
1888 + return n;
1889 +
1890 prefetch(from);
1891 if (access_ok(VERIFY_WRITE, to, n))
1892 __copy_user(to,from,n);
1893 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1894 unsigned long
1895 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1896 {
1897 + if ((long)n < 0)
1898 + return n;
1899 +
1900 prefetchw(to);
1901 if (access_ok(VERIFY_READ, from, n))
1902 __copy_user_zeroing(to,from,n);
1903 diff --git a/arch/mips/Makefile b/arch/mips/Makefile
1904 index 77f5021..2b1db8a 100644
1905 --- a/arch/mips/Makefile
1906 +++ b/arch/mips/Makefile
1907 @@ -51,6 +51,8 @@ endif
1908 cflags-y := -ffunction-sections
1909 cflags-y += $(call cc-option, -mno-check-zero-division)
1910
1911 +cflags-y += -Wno-sign-compare -Wno-extra
1912 +
1913 ifdef CONFIG_32BIT
1914 ld-emul = $(32bit-emul)
1915 vmlinux-32 = vmlinux
1916 diff --git a/arch/mips/alchemy/devboards/pm.c b/arch/mips/alchemy/devboards/pm.c
1917 index 632f986..fd0378d 100644
1918 --- a/arch/mips/alchemy/devboards/pm.c
1919 +++ b/arch/mips/alchemy/devboards/pm.c
1920 @@ -78,7 +78,7 @@ static void db1x_pm_end(void)
1921
1922 }
1923
1924 -static struct platform_suspend_ops db1x_pm_ops = {
1925 +static const struct platform_suspend_ops db1x_pm_ops = {
1926 .valid = suspend_valid_only_mem,
1927 .begin = db1x_pm_begin,
1928 .enter = db1x_pm_enter,
1929 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1930 index 7990694..4e93acf 100644
1931 --- a/arch/mips/include/asm/elf.h
1932 +++ b/arch/mips/include/asm/elf.h
1933 @@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *);
1934 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1935 #endif
1936
1937 +#ifdef CONFIG_PAX_ASLR
1938 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1939 +
1940 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1941 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1942 +#endif
1943 +
1944 #endif /* _ASM_ELF_H */
1945 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1946 index f266295..627cfff 100644
1947 --- a/arch/mips/include/asm/page.h
1948 +++ b/arch/mips/include/asm/page.h
1949 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
1950 #ifdef CONFIG_CPU_MIPS32
1951 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1952 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1953 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1954 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1955 #else
1956 typedef struct { unsigned long long pte; } pte_t;
1957 #define pte_val(x) ((x).pte)
1958 diff --git a/arch/mips/include/asm/reboot.h b/arch/mips/include/asm/reboot.h
1959 index e48c0bf..f3acf65 100644
1960 --- a/arch/mips/include/asm/reboot.h
1961 +++ b/arch/mips/include/asm/reboot.h
1962 @@ -9,7 +9,7 @@
1963 #ifndef _ASM_REBOOT_H
1964 #define _ASM_REBOOT_H
1965
1966 -extern void (*_machine_restart)(char *command);
1967 -extern void (*_machine_halt)(void);
1968 +extern void (*__noreturn _machine_restart)(char *command);
1969 +extern void (*__noreturn _machine_halt)(void);
1970
1971 #endif /* _ASM_REBOOT_H */
1972 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1973 index 83b5509..9fa24a23 100644
1974 --- a/arch/mips/include/asm/system.h
1975 +++ b/arch/mips/include/asm/system.h
1976 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1977 */
1978 #define __ARCH_WANT_UNLOCKED_CTXSW
1979
1980 -extern unsigned long arch_align_stack(unsigned long sp);
1981 +#define arch_align_stack(x) ((x) & ~0xfUL)
1982
1983 #endif /* _ASM_SYSTEM_H */
1984 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1985 index 9fdd8bc..fcf9d68 100644
1986 --- a/arch/mips/kernel/binfmt_elfn32.c
1987 +++ b/arch/mips/kernel/binfmt_elfn32.c
1988 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1989 #undef ELF_ET_DYN_BASE
1990 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1991
1992 +#ifdef CONFIG_PAX_ASLR
1993 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1994 +
1995 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1996 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1997 +#endif
1998 +
1999 #include <asm/processor.h>
2000 #include <linux/module.h>
2001 #include <linux/elfcore.h>
2002 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2003 index ff44823..cf0b48a 100644
2004 --- a/arch/mips/kernel/binfmt_elfo32.c
2005 +++ b/arch/mips/kernel/binfmt_elfo32.c
2006 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2007 #undef ELF_ET_DYN_BASE
2008 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2009
2010 +#ifdef CONFIG_PAX_ASLR
2011 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2012 +
2013 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2014 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2015 +#endif
2016 +
2017 #include <asm/processor.h>
2018
2019 /*
2020 diff --git a/arch/mips/kernel/kgdb.c b/arch/mips/kernel/kgdb.c
2021 index 50c9bb8..efdd5f8 100644
2022 --- a/arch/mips/kernel/kgdb.c
2023 +++ b/arch/mips/kernel/kgdb.c
2024 @@ -245,6 +245,7 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
2025 return -1;
2026 }
2027
2028 +/* cannot be const */
2029 struct kgdb_arch arch_kgdb_ops;
2030
2031 /*
2032 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2033 index f3d73e1..bb3f57a 100644
2034 --- a/arch/mips/kernel/process.c
2035 +++ b/arch/mips/kernel/process.c
2036 @@ -470,15 +470,3 @@ unsigned long get_wchan(struct task_struct *task)
2037 out:
2038 return pc;
2039 }
2040 -
2041 -/*
2042 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2043 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2044 - */
2045 -unsigned long arch_align_stack(unsigned long sp)
2046 -{
2047 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2048 - sp -= get_random_int() & ~PAGE_MASK;
2049 -
2050 - return sp & ALMASK;
2051 -}
2052 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
2053 index 060563a..7fbf310 100644
2054 --- a/arch/mips/kernel/reset.c
2055 +++ b/arch/mips/kernel/reset.c
2056 @@ -19,8 +19,8 @@
2057 * So handle all using function pointers to machine specific
2058 * functions.
2059 */
2060 -void (*_machine_restart)(char *command);
2061 -void (*_machine_halt)(void);
2062 +void (*__noreturn _machine_restart)(char *command);
2063 +void (*__noreturn _machine_halt)(void);
2064 void (*pm_power_off)(void);
2065
2066 EXPORT_SYMBOL(pm_power_off);
2067 @@ -29,16 +29,19 @@ void machine_restart(char *command)
2068 {
2069 if (_machine_restart)
2070 _machine_restart(command);
2071 + BUG();
2072 }
2073
2074 void machine_halt(void)
2075 {
2076 if (_machine_halt)
2077 _machine_halt();
2078 + BUG();
2079 }
2080
2081 void machine_power_off(void)
2082 {
2083 if (pm_power_off)
2084 pm_power_off();
2085 + BUG();
2086 }
2087 diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
2088 index 3f7f466..3abe0b5 100644
2089 --- a/arch/mips/kernel/syscall.c
2090 +++ b/arch/mips/kernel/syscall.c
2091 @@ -102,17 +102,21 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2092 do_color_align = 0;
2093 if (filp || (flags & MAP_SHARED))
2094 do_color_align = 1;
2095 +
2096 +#ifdef CONFIG_PAX_RANDMMAP
2097 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2098 +#endif
2099 +
2100 if (addr) {
2101 if (do_color_align)
2102 addr = COLOUR_ALIGN(addr, pgoff);
2103 else
2104 addr = PAGE_ALIGN(addr);
2105 vmm = find_vma(current->mm, addr);
2106 - if (task_size - len >= addr &&
2107 - (!vmm || addr + len <= vmm->vm_start))
2108 + if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2109 return addr;
2110 }
2111 - addr = TASK_UNMAPPED_BASE;
2112 + addr = current->mm->mmap_base;
2113 if (do_color_align)
2114 addr = COLOUR_ALIGN(addr, pgoff);
2115 else
2116 @@ -122,7 +126,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2117 /* At this point: (!vmm || addr < vmm->vm_end). */
2118 if (task_size - len < addr)
2119 return -ENOMEM;
2120 - if (!vmm || addr + len <= vmm->vm_start)
2121 + if (check_heap_stack_gap(vmm, addr, len))
2122 return addr;
2123 addr = vmm->vm_end;
2124 if (do_color_align)
2125 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2126 index e97a7a2..f18f5b0 100644
2127 --- a/arch/mips/mm/fault.c
2128 +++ b/arch/mips/mm/fault.c
2129 @@ -26,6 +26,23 @@
2130 #include <asm/ptrace.h>
2131 #include <asm/highmem.h> /* For VMALLOC_END */
2132
2133 +#ifdef CONFIG_PAX_PAGEEXEC
2134 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2135 +{
2136 + unsigned long i;
2137 +
2138 + printk(KERN_ERR "PAX: bytes at PC: ");
2139 + for (i = 0; i < 5; i++) {
2140 + unsigned int c;
2141 + if (get_user(c, (unsigned int *)pc+i))
2142 + printk(KERN_CONT "???????? ");
2143 + else
2144 + printk(KERN_CONT "%08x ", c);
2145 + }
2146 + printk("\n");
2147 +}
2148 +#endif
2149 +
2150 /*
2151 * This routine handles page faults. It determines the address,
2152 * and the problem, and then passes it off to one of the appropriate
2153 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2154 index 9c802eb..0592e41 100644
2155 --- a/arch/parisc/include/asm/elf.h
2156 +++ b/arch/parisc/include/asm/elf.h
2157 @@ -343,6 +343,13 @@ struct pt_regs; /* forward declaration... */
2158
2159 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2160
2161 +#ifdef CONFIG_PAX_ASLR
2162 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2163 +
2164 +#define PAX_DELTA_MMAP_LEN 16
2165 +#define PAX_DELTA_STACK_LEN 16
2166 +#endif
2167 +
2168 /* This yields a mask that user programs can use to figure out what
2169 instruction set this CPU supports. This could be done in user space,
2170 but it's not easy, and we've already done it here. */
2171 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2172 index a27d2e2..18fd845 100644
2173 --- a/arch/parisc/include/asm/pgtable.h
2174 +++ b/arch/parisc/include/asm/pgtable.h
2175 @@ -207,6 +207,17 @@
2176 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2177 #define PAGE_COPY PAGE_EXECREAD
2178 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2179 +
2180 +#ifdef CONFIG_PAX_PAGEEXEC
2181 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2182 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2183 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2184 +#else
2185 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2186 +# define PAGE_COPY_NOEXEC PAGE_COPY
2187 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2188 +#endif
2189 +
2190 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2191 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2192 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2193 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
2194 index 2120746..8d70a5e 100644
2195 --- a/arch/parisc/kernel/module.c
2196 +++ b/arch/parisc/kernel/module.c
2197 @@ -95,16 +95,38 @@
2198
2199 /* three functions to determine where in the module core
2200 * or init pieces the location is */
2201 +static inline int in_init_rx(struct module *me, void *loc)
2202 +{
2203 + return (loc >= me->module_init_rx &&
2204 + loc < (me->module_init_rx + me->init_size_rx));
2205 +}
2206 +
2207 +static inline int in_init_rw(struct module *me, void *loc)
2208 +{
2209 + return (loc >= me->module_init_rw &&
2210 + loc < (me->module_init_rw + me->init_size_rw));
2211 +}
2212 +
2213 static inline int in_init(struct module *me, void *loc)
2214 {
2215 - return (loc >= me->module_init &&
2216 - loc <= (me->module_init + me->init_size));
2217 + return in_init_rx(me, loc) || in_init_rw(me, loc);
2218 +}
2219 +
2220 +static inline int in_core_rx(struct module *me, void *loc)
2221 +{
2222 + return (loc >= me->module_core_rx &&
2223 + loc < (me->module_core_rx + me->core_size_rx));
2224 +}
2225 +
2226 +static inline int in_core_rw(struct module *me, void *loc)
2227 +{
2228 + return (loc >= me->module_core_rw &&
2229 + loc < (me->module_core_rw + me->core_size_rw));
2230 }
2231
2232 static inline int in_core(struct module *me, void *loc)
2233 {
2234 - return (loc >= me->module_core &&
2235 - loc <= (me->module_core + me->core_size));
2236 + return in_core_rx(me, loc) || in_core_rw(me, loc);
2237 }
2238
2239 static inline int in_local(struct module *me, void *loc)
2240 @@ -364,13 +386,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
2241 }
2242
2243 /* align things a bit */
2244 - me->core_size = ALIGN(me->core_size, 16);
2245 - me->arch.got_offset = me->core_size;
2246 - me->core_size += gots * sizeof(struct got_entry);
2247 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2248 + me->arch.got_offset = me->core_size_rw;
2249 + me->core_size_rw += gots * sizeof(struct got_entry);
2250
2251 - me->core_size = ALIGN(me->core_size, 16);
2252 - me->arch.fdesc_offset = me->core_size;
2253 - me->core_size += fdescs * sizeof(Elf_Fdesc);
2254 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2255 + me->arch.fdesc_offset = me->core_size_rw;
2256 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2257
2258 me->arch.got_max = gots;
2259 me->arch.fdesc_max = fdescs;
2260 @@ -388,7 +410,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
2261
2262 BUG_ON(value == 0);
2263
2264 - got = me->module_core + me->arch.got_offset;
2265 + got = me->module_core_rw + me->arch.got_offset;
2266 for (i = 0; got[i].addr; i++)
2267 if (got[i].addr == value)
2268 goto out;
2269 @@ -406,7 +428,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
2270 #ifdef CONFIG_64BIT
2271 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2272 {
2273 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2274 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2275
2276 if (!value) {
2277 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2278 @@ -424,7 +446,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2279
2280 /* Create new one */
2281 fdesc->addr = value;
2282 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2283 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2284 return (Elf_Addr)fdesc;
2285 }
2286 #endif /* CONFIG_64BIT */
2287 @@ -848,7 +870,7 @@ register_unwind_table(struct module *me,
2288
2289 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2290 end = table + sechdrs[me->arch.unwind_section].sh_size;
2291 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2292 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2293
2294 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2295 me->arch.unwind_section, table, end, gp);
2296 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
2297 index 9147391..f3d949a 100644
2298 --- a/arch/parisc/kernel/sys_parisc.c
2299 +++ b/arch/parisc/kernel/sys_parisc.c
2300 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
2301 /* At this point: (!vma || addr < vma->vm_end). */
2302 if (TASK_SIZE - len < addr)
2303 return -ENOMEM;
2304 - if (!vma || addr + len <= vma->vm_start)
2305 + if (check_heap_stack_gap(vma, addr, len))
2306 return addr;
2307 addr = vma->vm_end;
2308 }
2309 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
2310 /* At this point: (!vma || addr < vma->vm_end). */
2311 if (TASK_SIZE - len < addr)
2312 return -ENOMEM;
2313 - if (!vma || addr + len <= vma->vm_start)
2314 + if (check_heap_stack_gap(vma, addr, len))
2315 return addr;
2316 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2317 if (addr < vma->vm_end) /* handle wraparound */
2318 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2319 if (flags & MAP_FIXED)
2320 return addr;
2321 if (!addr)
2322 - addr = TASK_UNMAPPED_BASE;
2323 + addr = current->mm->mmap_base;
2324
2325 if (filp) {
2326 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2327 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
2328 index 8b58bf0..7afff03 100644
2329 --- a/arch/parisc/kernel/traps.c
2330 +++ b/arch/parisc/kernel/traps.c
2331 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
2332
2333 down_read(&current->mm->mmap_sem);
2334 vma = find_vma(current->mm,regs->iaoq[0]);
2335 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2336 - && (vma->vm_flags & VM_EXEC)) {
2337 -
2338 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2339 fault_address = regs->iaoq[0];
2340 fault_space = regs->iasq[0];
2341
2342 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
2343 index c6afbfc..c5839f6 100644
2344 --- a/arch/parisc/mm/fault.c
2345 +++ b/arch/parisc/mm/fault.c
2346 @@ -15,6 +15,7 @@
2347 #include <linux/sched.h>
2348 #include <linux/interrupt.h>
2349 #include <linux/module.h>
2350 +#include <linux/unistd.h>
2351
2352 #include <asm/uaccess.h>
2353 #include <asm/traps.h>
2354 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
2355 static unsigned long
2356 parisc_acctyp(unsigned long code, unsigned int inst)
2357 {
2358 - if (code == 6 || code == 16)
2359 + if (code == 6 || code == 7 || code == 16)
2360 return VM_EXEC;
2361
2362 switch (inst & 0xf0000000) {
2363 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
2364 }
2365 #endif
2366
2367 +#ifdef CONFIG_PAX_PAGEEXEC
2368 +/*
2369 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2370 + *
2371 + * returns 1 when task should be killed
2372 + * 2 when rt_sigreturn trampoline was detected
2373 + * 3 when unpatched PLT trampoline was detected
2374 + */
2375 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2376 +{
2377 +
2378 +#ifdef CONFIG_PAX_EMUPLT
2379 + int err;
2380 +
2381 + do { /* PaX: unpatched PLT emulation */
2382 + unsigned int bl, depwi;
2383 +
2384 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2385 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2386 +
2387 + if (err)
2388 + break;
2389 +
2390 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2391 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2392 +
2393 + err = get_user(ldw, (unsigned int *)addr);
2394 + err |= get_user(bv, (unsigned int *)(addr+4));
2395 + err |= get_user(ldw2, (unsigned int *)(addr+8));
2396 +
2397 + if (err)
2398 + break;
2399 +
2400 + if (ldw == 0x0E801096U &&
2401 + bv == 0xEAC0C000U &&
2402 + ldw2 == 0x0E881095U)
2403 + {
2404 + unsigned int resolver, map;
2405 +
2406 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2407 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2408 + if (err)
2409 + break;
2410 +
2411 + regs->gr[20] = instruction_pointer(regs)+8;
2412 + regs->gr[21] = map;
2413 + regs->gr[22] = resolver;
2414 + regs->iaoq[0] = resolver | 3UL;
2415 + regs->iaoq[1] = regs->iaoq[0] + 4;
2416 + return 3;
2417 + }
2418 + }
2419 + } while (0);
2420 +#endif
2421 +
2422 +#ifdef CONFIG_PAX_EMUTRAMP
2423 +
2424 +#ifndef CONFIG_PAX_EMUSIGRT
2425 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2426 + return 1;
2427 +#endif
2428 +
2429 + do { /* PaX: rt_sigreturn emulation */
2430 + unsigned int ldi1, ldi2, bel, nop;
2431 +
2432 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2433 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2434 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2435 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2436 +
2437 + if (err)
2438 + break;
2439 +
2440 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2441 + ldi2 == 0x3414015AU &&
2442 + bel == 0xE4008200U &&
2443 + nop == 0x08000240U)
2444 + {
2445 + regs->gr[25] = (ldi1 & 2) >> 1;
2446 + regs->gr[20] = __NR_rt_sigreturn;
2447 + regs->gr[31] = regs->iaoq[1] + 16;
2448 + regs->sr[0] = regs->iasq[1];
2449 + regs->iaoq[0] = 0x100UL;
2450 + regs->iaoq[1] = regs->iaoq[0] + 4;
2451 + regs->iasq[0] = regs->sr[2];
2452 + regs->iasq[1] = regs->sr[2];
2453 + return 2;
2454 + }
2455 + } while (0);
2456 +#endif
2457 +
2458 + return 1;
2459 +}
2460 +
2461 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2462 +{
2463 + unsigned long i;
2464 +
2465 + printk(KERN_ERR "PAX: bytes at PC: ");
2466 + for (i = 0; i < 5; i++) {
2467 + unsigned int c;
2468 + if (get_user(c, (unsigned int *)pc+i))
2469 + printk(KERN_CONT "???????? ");
2470 + else
2471 + printk(KERN_CONT "%08x ", c);
2472 + }
2473 + printk("\n");
2474 +}
2475 +#endif
2476 +
2477 int fixup_exception(struct pt_regs *regs)
2478 {
2479 const struct exception_table_entry *fix;
2480 @@ -192,8 +303,33 @@ good_area:
2481
2482 acc_type = parisc_acctyp(code,regs->iir);
2483
2484 - if ((vma->vm_flags & acc_type) != acc_type)
2485 + if ((vma->vm_flags & acc_type) != acc_type) {
2486 +
2487 +#ifdef CONFIG_PAX_PAGEEXEC
2488 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2489 + (address & ~3UL) == instruction_pointer(regs))
2490 + {
2491 + up_read(&mm->mmap_sem);
2492 + switch (pax_handle_fetch_fault(regs)) {
2493 +
2494 +#ifdef CONFIG_PAX_EMUPLT
2495 + case 3:
2496 + return;
2497 +#endif
2498 +
2499 +#ifdef CONFIG_PAX_EMUTRAMP
2500 + case 2:
2501 + return;
2502 +#endif
2503 +
2504 + }
2505 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2506 + do_group_exit(SIGKILL);
2507 + }
2508 +#endif
2509 +
2510 goto bad_area;
2511 + }
2512
2513 /*
2514 * If for any reason at all we couldn't handle the fault, make
2515 diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
2516 index c107b74..409dc0f 100644
2517 --- a/arch/powerpc/Makefile
2518 +++ b/arch/powerpc/Makefile
2519 @@ -74,6 +74,8 @@ KBUILD_AFLAGS += -Iarch/$(ARCH)
2520 KBUILD_CFLAGS += -msoft-float -pipe -Iarch/$(ARCH) $(CFLAGS-y)
2521 CPP = $(CC) -E $(KBUILD_CFLAGS)
2522
2523 +cflags-y += -Wno-sign-compare -Wno-extra
2524 +
2525 CHECKFLAGS += -m$(CONFIG_WORD_SIZE) -D__powerpc__ -D__powerpc$(CONFIG_WORD_SIZE)__
2526
2527 ifeq ($(CONFIG_PPC64),y)
2528 diff --git a/arch/powerpc/include/asm/device.h b/arch/powerpc/include/asm/device.h
2529 index 6d94d27..50d4cad 100644
2530 --- a/arch/powerpc/include/asm/device.h
2531 +++ b/arch/powerpc/include/asm/device.h
2532 @@ -14,7 +14,7 @@ struct dev_archdata {
2533 struct device_node *of_node;
2534
2535 /* DMA operations on that device */
2536 - struct dma_map_ops *dma_ops;
2537 + const struct dma_map_ops *dma_ops;
2538
2539 /*
2540 * When an iommu is in use, dma_data is used as a ptr to the base of the
2541 diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
2542 index e281dae..2b8a784 100644
2543 --- a/arch/powerpc/include/asm/dma-mapping.h
2544 +++ b/arch/powerpc/include/asm/dma-mapping.h
2545 @@ -69,9 +69,9 @@ static inline unsigned long device_to_mask(struct device *dev)
2546 #ifdef CONFIG_PPC64
2547 extern struct dma_map_ops dma_iommu_ops;
2548 #endif
2549 -extern struct dma_map_ops dma_direct_ops;
2550 +extern const struct dma_map_ops dma_direct_ops;
2551
2552 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2553 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2554 {
2555 /* We don't handle the NULL dev case for ISA for now. We could
2556 * do it via an out of line call but it is not needed for now. The
2557 @@ -84,7 +84,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2558 return dev->archdata.dma_ops;
2559 }
2560
2561 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
2562 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
2563 {
2564 dev->archdata.dma_ops = ops;
2565 }
2566 @@ -118,7 +118,7 @@ static inline void set_dma_offset(struct device *dev, dma_addr_t off)
2567
2568 static inline int dma_supported(struct device *dev, u64 mask)
2569 {
2570 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2571 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2572
2573 if (unlikely(dma_ops == NULL))
2574 return 0;
2575 @@ -132,7 +132,7 @@ static inline int dma_supported(struct device *dev, u64 mask)
2576
2577 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2578 {
2579 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2580 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2581
2582 if (unlikely(dma_ops == NULL))
2583 return -EIO;
2584 @@ -147,7 +147,7 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2585 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2586 dma_addr_t *dma_handle, gfp_t flag)
2587 {
2588 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2589 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2590 void *cpu_addr;
2591
2592 BUG_ON(!dma_ops);
2593 @@ -162,7 +162,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2594 static inline void dma_free_coherent(struct device *dev, size_t size,
2595 void *cpu_addr, dma_addr_t dma_handle)
2596 {
2597 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2598 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2599
2600 BUG_ON(!dma_ops);
2601
2602 @@ -173,7 +173,7 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
2603
2604 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2605 {
2606 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2607 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2608
2609 if (dma_ops->mapping_error)
2610 return dma_ops->mapping_error(dev, dma_addr);
2611 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2612 index 5698502..5db093c 100644
2613 --- a/arch/powerpc/include/asm/elf.h
2614 +++ b/arch/powerpc/include/asm/elf.h
2615 @@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
2616 the loader. We need to make sure that it is out of the way of the program
2617 that it will "exec", and that there is sufficient room for the brk. */
2618
2619 -extern unsigned long randomize_et_dyn(unsigned long base);
2620 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2621 +#define ELF_ET_DYN_BASE (0x20000000)
2622 +
2623 +#ifdef CONFIG_PAX_ASLR
2624 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2625 +
2626 +#ifdef __powerpc64__
2627 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2628 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2629 +#else
2630 +#define PAX_DELTA_MMAP_LEN 15
2631 +#define PAX_DELTA_STACK_LEN 15
2632 +#endif
2633 +#endif
2634
2635 /*
2636 * Our registers are always unsigned longs, whether we're a 32 bit
2637 @@ -275,9 +286,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2638 (0x7ff >> (PAGE_SHIFT - 12)) : \
2639 (0x3ffff >> (PAGE_SHIFT - 12)))
2640
2641 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2642 -#define arch_randomize_brk arch_randomize_brk
2643 -
2644 #endif /* __KERNEL__ */
2645
2646 /*
2647 diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
2648 index edfc980..1766f59 100644
2649 --- a/arch/powerpc/include/asm/iommu.h
2650 +++ b/arch/powerpc/include/asm/iommu.h
2651 @@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(void);
2652 extern void iommu_init_early_dart(void);
2653 extern void iommu_init_early_pasemi(void);
2654
2655 +/* dma-iommu.c */
2656 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2657 +
2658 #ifdef CONFIG_PCI
2659 extern void pci_iommu_init(void);
2660 extern void pci_direct_iommu_init(void);
2661 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2662 index 9163695..5a00112 100644
2663 --- a/arch/powerpc/include/asm/kmap_types.h
2664 +++ b/arch/powerpc/include/asm/kmap_types.h
2665 @@ -26,6 +26,7 @@ enum km_type {
2666 KM_SOFTIRQ1,
2667 KM_PPC_SYNC_PAGE,
2668 KM_PPC_SYNC_ICACHE,
2669 + KM_CLEARPAGE,
2670 KM_TYPE_NR
2671 };
2672
2673 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2674 index ff24254..fe45b21 100644
2675 --- a/arch/powerpc/include/asm/page.h
2676 +++ b/arch/powerpc/include/asm/page.h
2677 @@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
2678 * and needs to be executable. This means the whole heap ends
2679 * up being executable.
2680 */
2681 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2682 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2683 +#define VM_DATA_DEFAULT_FLAGS32 \
2684 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2685 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2686
2687 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2688 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2689 @@ -145,6 +146,9 @@ extern phys_addr_t kernstart_addr;
2690 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2691 #endif
2692
2693 +#define ktla_ktva(addr) (addr)
2694 +#define ktva_ktla(addr) (addr)
2695 +
2696 #ifndef __ASSEMBLY__
2697
2698 #undef STRICT_MM_TYPECHECKS
2699 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2700 index 3f17b83..1f9e766 100644
2701 --- a/arch/powerpc/include/asm/page_64.h
2702 +++ b/arch/powerpc/include/asm/page_64.h
2703 @@ -180,15 +180,18 @@ do { \
2704 * stack by default, so in the absense of a PT_GNU_STACK program header
2705 * we turn execute permission off.
2706 */
2707 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2708 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2709 +#define VM_STACK_DEFAULT_FLAGS32 \
2710 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2711 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2712
2713 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2714 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2715
2716 +#ifndef CONFIG_PAX_PAGEEXEC
2717 #define VM_STACK_DEFAULT_FLAGS \
2718 (test_thread_flag(TIF_32BIT) ? \
2719 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2720 +#endif
2721
2722 #include <asm-generic/getorder.h>
2723
2724 diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
2725 index b5ea626..4030822 100644
2726 --- a/arch/powerpc/include/asm/pci.h
2727 +++ b/arch/powerpc/include/asm/pci.h
2728 @@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
2729 }
2730
2731 #ifdef CONFIG_PCI
2732 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
2733 -extern struct dma_map_ops *get_pci_dma_ops(void);
2734 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
2735 +extern const struct dma_map_ops *get_pci_dma_ops(void);
2736 #else /* CONFIG_PCI */
2737 #define set_pci_dma_ops(d)
2738 #define get_pci_dma_ops() NULL
2739 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2740 index 2a5da06..d65bea2 100644
2741 --- a/arch/powerpc/include/asm/pgtable.h
2742 +++ b/arch/powerpc/include/asm/pgtable.h
2743 @@ -2,6 +2,7 @@
2744 #define _ASM_POWERPC_PGTABLE_H
2745 #ifdef __KERNEL__
2746
2747 +#include <linux/const.h>
2748 #ifndef __ASSEMBLY__
2749 #include <asm/processor.h> /* For TASK_SIZE */
2750 #include <asm/mmu.h>
2751 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2752 index 4aad413..85d86bf 100644
2753 --- a/arch/powerpc/include/asm/pte-hash32.h
2754 +++ b/arch/powerpc/include/asm/pte-hash32.h
2755 @@ -21,6 +21,7 @@
2756 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2757 #define _PAGE_USER 0x004 /* usermode access allowed */
2758 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2759 +#define _PAGE_EXEC _PAGE_GUARDED
2760 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2761 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2762 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2763 diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
2764 index 8c34149..78f425a 100644
2765 --- a/arch/powerpc/include/asm/ptrace.h
2766 +++ b/arch/powerpc/include/asm/ptrace.h
2767 @@ -103,7 +103,7 @@ extern unsigned long profile_pc(struct pt_regs *regs);
2768 } while(0)
2769
2770 struct task_struct;
2771 -extern unsigned long ptrace_get_reg(struct task_struct *task, int regno);
2772 +extern unsigned long ptrace_get_reg(struct task_struct *task, unsigned int regno);
2773 extern int ptrace_put_reg(struct task_struct *task, int regno,
2774 unsigned long data);
2775
2776 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2777 index 32a7c30..be3a8bb 100644
2778 --- a/arch/powerpc/include/asm/reg.h
2779 +++ b/arch/powerpc/include/asm/reg.h
2780 @@ -191,6 +191,7 @@
2781 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2782 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2783 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2784 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2785 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2786 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2787 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2788 diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
2789 index 8979d4c..d2fd0d3 100644
2790 --- a/arch/powerpc/include/asm/swiotlb.h
2791 +++ b/arch/powerpc/include/asm/swiotlb.h
2792 @@ -13,7 +13,7 @@
2793
2794 #include <linux/swiotlb.h>
2795
2796 -extern struct dma_map_ops swiotlb_dma_ops;
2797 +extern const struct dma_map_ops swiotlb_dma_ops;
2798
2799 static inline void dma_mark_clean(void *addr, size_t size) {}
2800
2801 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2802 index 094a12a..877a60a 100644
2803 --- a/arch/powerpc/include/asm/system.h
2804 +++ b/arch/powerpc/include/asm/system.h
2805 @@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
2806 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2807 #endif
2808
2809 -extern unsigned long arch_align_stack(unsigned long sp);
2810 +#define arch_align_stack(x) ((x) & ~0xfUL)
2811
2812 /* Used in very early kernel initialization. */
2813 extern unsigned long reloc_offset(void);
2814 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2815 index bd0fb84..a42a14b 100644
2816 --- a/arch/powerpc/include/asm/uaccess.h
2817 +++ b/arch/powerpc/include/asm/uaccess.h
2818 @@ -13,6 +13,8 @@
2819 #define VERIFY_READ 0
2820 #define VERIFY_WRITE 1
2821
2822 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2823 +
2824 /*
2825 * The fs value determines whether argument validity checking should be
2826 * performed or not. If get_fs() == USER_DS, checking is performed, with
2827 @@ -327,52 +329,6 @@ do { \
2828 extern unsigned long __copy_tofrom_user(void __user *to,
2829 const void __user *from, unsigned long size);
2830
2831 -#ifndef __powerpc64__
2832 -
2833 -static inline unsigned long copy_from_user(void *to,
2834 - const void __user *from, unsigned long n)
2835 -{
2836 - unsigned long over;
2837 -
2838 - if (access_ok(VERIFY_READ, from, n))
2839 - return __copy_tofrom_user((__force void __user *)to, from, n);
2840 - if ((unsigned long)from < TASK_SIZE) {
2841 - over = (unsigned long)from + n - TASK_SIZE;
2842 - return __copy_tofrom_user((__force void __user *)to, from,
2843 - n - over) + over;
2844 - }
2845 - return n;
2846 -}
2847 -
2848 -static inline unsigned long copy_to_user(void __user *to,
2849 - const void *from, unsigned long n)
2850 -{
2851 - unsigned long over;
2852 -
2853 - if (access_ok(VERIFY_WRITE, to, n))
2854 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2855 - if ((unsigned long)to < TASK_SIZE) {
2856 - over = (unsigned long)to + n - TASK_SIZE;
2857 - return __copy_tofrom_user(to, (__force void __user *)from,
2858 - n - over) + over;
2859 - }
2860 - return n;
2861 -}
2862 -
2863 -#else /* __powerpc64__ */
2864 -
2865 -#define __copy_in_user(to, from, size) \
2866 - __copy_tofrom_user((to), (from), (size))
2867 -
2868 -extern unsigned long copy_from_user(void *to, const void __user *from,
2869 - unsigned long n);
2870 -extern unsigned long copy_to_user(void __user *to, const void *from,
2871 - unsigned long n);
2872 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2873 - unsigned long n);
2874 -
2875 -#endif /* __powerpc64__ */
2876 -
2877 static inline unsigned long __copy_from_user_inatomic(void *to,
2878 const void __user *from, unsigned long n)
2879 {
2880 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
2881 if (ret == 0)
2882 return 0;
2883 }
2884 +
2885 + if (!__builtin_constant_p(n))
2886 + check_object_size(to, n, false);
2887 +
2888 return __copy_tofrom_user((__force void __user *)to, from, n);
2889 }
2890
2891 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
2892 if (ret == 0)
2893 return 0;
2894 }
2895 +
2896 + if (!__builtin_constant_p(n))
2897 + check_object_size(from, n, true);
2898 +
2899 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2900 }
2901
2902 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
2903 return __copy_to_user_inatomic(to, from, size);
2904 }
2905
2906 +#ifndef __powerpc64__
2907 +
2908 +static inline unsigned long __must_check copy_from_user(void *to,
2909 + const void __user *from, unsigned long n)
2910 +{
2911 + unsigned long over;
2912 +
2913 + if ((long)n < 0)
2914 + return n;
2915 +
2916 + if (access_ok(VERIFY_READ, from, n)) {
2917 + if (!__builtin_constant_p(n))
2918 + check_object_size(to, n, false);
2919 + return __copy_tofrom_user((__force void __user *)to, from, n);
2920 + }
2921 + if ((unsigned long)from < TASK_SIZE) {
2922 + over = (unsigned long)from + n - TASK_SIZE;
2923 + if (!__builtin_constant_p(n - over))
2924 + check_object_size(to, n - over, false);
2925 + return __copy_tofrom_user((__force void __user *)to, from,
2926 + n - over) + over;
2927 + }
2928 + return n;
2929 +}
2930 +
2931 +static inline unsigned long __must_check copy_to_user(void __user *to,
2932 + const void *from, unsigned long n)
2933 +{
2934 + unsigned long over;
2935 +
2936 + if ((long)n < 0)
2937 + return n;
2938 +
2939 + if (access_ok(VERIFY_WRITE, to, n)) {
2940 + if (!__builtin_constant_p(n))
2941 + check_object_size(from, n, true);
2942 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2943 + }
2944 + if ((unsigned long)to < TASK_SIZE) {
2945 + over = (unsigned long)to + n - TASK_SIZE;
2946 + if (!__builtin_constant_p(n))
2947 + check_object_size(from, n - over, true);
2948 + return __copy_tofrom_user(to, (__force void __user *)from,
2949 + n - over) + over;
2950 + }
2951 + return n;
2952 +}
2953 +
2954 +#else /* __powerpc64__ */
2955 +
2956 +#define __copy_in_user(to, from, size) \
2957 + __copy_tofrom_user((to), (from), (size))
2958 +
2959 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2960 +{
2961 + if ((long)n < 0 || n > INT_MAX)
2962 + return n;
2963 +
2964 + if (!__builtin_constant_p(n))
2965 + check_object_size(to, n, false);
2966 +
2967 + if (likely(access_ok(VERIFY_READ, from, n)))
2968 + n = __copy_from_user(to, from, n);
2969 + else
2970 + memset(to, 0, n);
2971 + return n;
2972 +}
2973 +
2974 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2975 +{
2976 + if ((long)n < 0 || n > INT_MAX)
2977 + return n;
2978 +
2979 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2980 + if (!__builtin_constant_p(n))
2981 + check_object_size(from, n, true);
2982 + n = __copy_to_user(to, from, n);
2983 + }
2984 + return n;
2985 +}
2986 +
2987 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2988 + unsigned long n);
2989 +
2990 +#endif /* __powerpc64__ */
2991 +
2992 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2993
2994 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2995 diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
2996 index bb37b1d..01fe9ce 100644
2997 --- a/arch/powerpc/kernel/cacheinfo.c
2998 +++ b/arch/powerpc/kernel/cacheinfo.c
2999 @@ -642,7 +642,7 @@ static struct kobj_attribute *cache_index_opt_attrs[] = {
3000 &cache_assoc_attr,
3001 };
3002
3003 -static struct sysfs_ops cache_index_ops = {
3004 +static const struct sysfs_ops cache_index_ops = {
3005 .show = cache_index_show,
3006 };
3007
3008 diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
3009 index 37771a5..648530c 100644
3010 --- a/arch/powerpc/kernel/dma-iommu.c
3011 +++ b/arch/powerpc/kernel/dma-iommu.c
3012 @@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct device *dev, struct scatterlist *sglist,
3013 }
3014
3015 /* We support DMA to/from any memory page via the iommu */
3016 -static int dma_iommu_dma_supported(struct device *dev, u64 mask)
3017 +int dma_iommu_dma_supported(struct device *dev, u64 mask)
3018 {
3019 struct iommu_table *tbl = get_iommu_table_base(dev);
3020
3021 diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
3022 index e96cbbd..bdd6d41 100644
3023 --- a/arch/powerpc/kernel/dma-swiotlb.c
3024 +++ b/arch/powerpc/kernel/dma-swiotlb.c
3025 @@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
3026 * map_page, and unmap_page on highmem, use normal dma_ops
3027 * for everything else.
3028 */
3029 -struct dma_map_ops swiotlb_dma_ops = {
3030 +const struct dma_map_ops swiotlb_dma_ops = {
3031 .alloc_coherent = dma_direct_alloc_coherent,
3032 .free_coherent = dma_direct_free_coherent,
3033 .map_sg = swiotlb_map_sg_attrs,
3034 diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
3035 index 6215062..ebea59c 100644
3036 --- a/arch/powerpc/kernel/dma.c
3037 +++ b/arch/powerpc/kernel/dma.c
3038 @@ -134,7 +134,7 @@ static inline void dma_direct_sync_single_range(struct device *dev,
3039 }
3040 #endif
3041
3042 -struct dma_map_ops dma_direct_ops = {
3043 +const struct dma_map_ops dma_direct_ops = {
3044 .alloc_coherent = dma_direct_alloc_coherent,
3045 .free_coherent = dma_direct_free_coherent,
3046 .map_sg = dma_direct_map_sg,
3047 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3048 index 24dcc0e..a300455 100644
3049 --- a/arch/powerpc/kernel/exceptions-64e.S
3050 +++ b/arch/powerpc/kernel/exceptions-64e.S
3051 @@ -455,6 +455,7 @@ storage_fault_common:
3052 std r14,_DAR(r1)
3053 std r15,_DSISR(r1)
3054 addi r3,r1,STACK_FRAME_OVERHEAD
3055 + bl .save_nvgprs
3056 mr r4,r14
3057 mr r5,r15
3058 ld r14,PACA_EXGEN+EX_R14(r13)
3059 @@ -464,8 +465,7 @@ storage_fault_common:
3060 cmpdi r3,0
3061 bne- 1f
3062 b .ret_from_except_lite
3063 -1: bl .save_nvgprs
3064 - mr r5,r3
3065 +1: mr r5,r3
3066 addi r3,r1,STACK_FRAME_OVERHEAD
3067 ld r4,_DAR(r1)
3068 bl .bad_page_fault
3069 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3070 index 1808876..9fd206a 100644
3071 --- a/arch/powerpc/kernel/exceptions-64s.S
3072 +++ b/arch/powerpc/kernel/exceptions-64s.S
3073 @@ -818,10 +818,10 @@ handle_page_fault:
3074 11: ld r4,_DAR(r1)
3075 ld r5,_DSISR(r1)
3076 addi r3,r1,STACK_FRAME_OVERHEAD
3077 + bl .save_nvgprs
3078 bl .do_page_fault
3079 cmpdi r3,0
3080 beq+ 13f
3081 - bl .save_nvgprs
3082 mr r5,r3
3083 addi r3,r1,STACK_FRAME_OVERHEAD
3084 lwz r4,_DAR(r1)
3085 diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
3086 index a4c8b38..1b09ad9 100644
3087 --- a/arch/powerpc/kernel/ibmebus.c
3088 +++ b/arch/powerpc/kernel/ibmebus.c
3089 @@ -127,7 +127,7 @@ static int ibmebus_dma_supported(struct device *dev, u64 mask)
3090 return 1;
3091 }
3092
3093 -static struct dma_map_ops ibmebus_dma_ops = {
3094 +static const struct dma_map_ops ibmebus_dma_ops = {
3095 .alloc_coherent = ibmebus_alloc_coherent,
3096 .free_coherent = ibmebus_free_coherent,
3097 .map_sg = ibmebus_map_sg,
3098 diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
3099 index 641c74b..8339ad7 100644
3100 --- a/arch/powerpc/kernel/kgdb.c
3101 +++ b/arch/powerpc/kernel/kgdb.c
3102 @@ -126,7 +126,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)
3103 if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
3104 return 0;
3105
3106 - if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
3107 + if (*(u32 *) (regs->nip) == *(const u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
3108 regs->nip += 4;
3109
3110 return 1;
3111 @@ -353,7 +353,7 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
3112 /*
3113 * Global data
3114 */
3115 -struct kgdb_arch arch_kgdb_ops = {
3116 +const struct kgdb_arch arch_kgdb_ops = {
3117 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
3118 };
3119
3120 diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
3121 index 477c663..4f50234 100644
3122 --- a/arch/powerpc/kernel/module.c
3123 +++ b/arch/powerpc/kernel/module.c
3124 @@ -31,11 +31,24 @@
3125
3126 LIST_HEAD(module_bug_list);
3127
3128 +#ifdef CONFIG_PAX_KERNEXEC
3129 void *module_alloc(unsigned long size)
3130 {
3131 if (size == 0)
3132 return NULL;
3133
3134 + return vmalloc(size);
3135 +}
3136 +
3137 +void *module_alloc_exec(unsigned long size)
3138 +#else
3139 +void *module_alloc(unsigned long size)
3140 +#endif
3141 +
3142 +{
3143 + if (size == 0)
3144 + return NULL;
3145 +
3146 return vmalloc_exec(size);
3147 }
3148
3149 @@ -45,6 +58,13 @@ void module_free(struct module *mod, void *module_region)
3150 vfree(module_region);
3151 }
3152
3153 +#ifdef CONFIG_PAX_KERNEXEC
3154 +void module_free_exec(struct module *mod, void *module_region)
3155 +{
3156 + module_free(mod, module_region);
3157 +}
3158 +#endif
3159 +
3160 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3161 const Elf_Shdr *sechdrs,
3162 const char *name)
3163 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3164 index f832773..0507238 100644
3165 --- a/arch/powerpc/kernel/module_32.c
3166 +++ b/arch/powerpc/kernel/module_32.c
3167 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3168 me->arch.core_plt_section = i;
3169 }
3170 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3171 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3172 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3173 return -ENOEXEC;
3174 }
3175
3176 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *location,
3177
3178 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3179 /* Init, or core PLT? */
3180 - if (location >= mod->module_core
3181 - && location < mod->module_core + mod->core_size)
3182 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3183 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3184 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3185 - else
3186 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3187 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3188 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3189 + else {
3190 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3191 + return ~0UL;
3192 + }
3193
3194 /* Find this entry, or if that fails, the next avail. entry */
3195 while (entry->jump[0]) {
3196 diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
3197 index cadbed6..b9bbb00 100644
3198 --- a/arch/powerpc/kernel/pci-common.c
3199 +++ b/arch/powerpc/kernel/pci-common.c
3200 @@ -50,14 +50,14 @@ resource_size_t isa_mem_base;
3201 unsigned int ppc_pci_flags = 0;
3202
3203
3204 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3205 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3206
3207 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3208 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3209 {
3210 pci_dma_ops = dma_ops;
3211 }
3212
3213 -struct dma_map_ops *get_pci_dma_ops(void)
3214 +const struct dma_map_ops *get_pci_dma_ops(void)
3215 {
3216 return pci_dma_ops;
3217 }
3218 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3219 index 7b816da..8d5c277 100644
3220 --- a/arch/powerpc/kernel/process.c
3221 +++ b/arch/powerpc/kernel/process.c
3222 @@ -539,8 +539,8 @@ void show_regs(struct pt_regs * regs)
3223 * Lookup NIP late so we have the best change of getting the
3224 * above info out without failing
3225 */
3226 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3227 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3228 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3229 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3230 #endif
3231 show_stack(current, (unsigned long *) regs->gpr[1]);
3232 if (!user_mode(regs))
3233 @@ -1034,10 +1034,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3234 newsp = stack[0];
3235 ip = stack[STACK_FRAME_LR_SAVE];
3236 if (!firstframe || ip != lr) {
3237 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3238 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3239 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3240 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3241 - printk(" (%pS)",
3242 + printk(" (%pA)",
3243 (void *)current->ret_stack[curr_frame].ret);
3244 curr_frame--;
3245 }
3246 @@ -1057,7 +1057,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3247 struct pt_regs *regs = (struct pt_regs *)
3248 (sp + STACK_FRAME_OVERHEAD);
3249 lr = regs->link;
3250 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3251 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3252 regs->trap, (void *)regs->nip, (void *)lr);
3253 firstframe = 1;
3254 }
3255 @@ -1134,58 +1134,3 @@ void thread_info_cache_init(void)
3256 }
3257
3258 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3259 -
3260 -unsigned long arch_align_stack(unsigned long sp)
3261 -{
3262 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3263 - sp -= get_random_int() & ~PAGE_MASK;
3264 - return sp & ~0xf;
3265 -}
3266 -
3267 -static inline unsigned long brk_rnd(void)
3268 -{
3269 - unsigned long rnd = 0;
3270 -
3271 - /* 8MB for 32bit, 1GB for 64bit */
3272 - if (is_32bit_task())
3273 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3274 - else
3275 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3276 -
3277 - return rnd << PAGE_SHIFT;
3278 -}
3279 -
3280 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3281 -{
3282 - unsigned long base = mm->brk;
3283 - unsigned long ret;
3284 -
3285 -#ifdef CONFIG_PPC_STD_MMU_64
3286 - /*
3287 - * If we are using 1TB segments and we are allowed to randomise
3288 - * the heap, we can put it above 1TB so it is backed by a 1TB
3289 - * segment. Otherwise the heap will be in the bottom 1TB
3290 - * which always uses 256MB segments and this may result in a
3291 - * performance penalty.
3292 - */
3293 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3294 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3295 -#endif
3296 -
3297 - ret = PAGE_ALIGN(base + brk_rnd());
3298 -
3299 - if (ret < mm->brk)
3300 - return mm->brk;
3301 -
3302 - return ret;
3303 -}
3304 -
3305 -unsigned long randomize_et_dyn(unsigned long base)
3306 -{
3307 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3308 -
3309 - if (ret < base)
3310 - return base;
3311 -
3312 - return ret;
3313 -}
3314 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
3315 index ef14988..856c4bc 100644
3316 --- a/arch/powerpc/kernel/ptrace.c
3317 +++ b/arch/powerpc/kernel/ptrace.c
3318 @@ -86,7 +86,7 @@ static int set_user_trap(struct task_struct *task, unsigned long trap)
3319 /*
3320 * Get contents of register REGNO in task TASK.
3321 */
3322 -unsigned long ptrace_get_reg(struct task_struct *task, int regno)
3323 +unsigned long ptrace_get_reg(struct task_struct *task, unsigned int regno)
3324 {
3325 if (task->thread.regs == NULL)
3326 return -EIO;
3327 @@ -894,7 +894,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
3328
3329 CHECK_FULL_REGS(child->thread.regs);
3330 if (index < PT_FPR0) {
3331 - tmp = ptrace_get_reg(child, (int) index);
3332 + tmp = ptrace_get_reg(child, index);
3333 } else {
3334 flush_fp_to_thread(child);
3335 tmp = ((unsigned long *)child->thread.fpr)
3336 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3337 index d670429..2bc59b2 100644
3338 --- a/arch/powerpc/kernel/signal_32.c
3339 +++ b/arch/powerpc/kernel/signal_32.c
3340 @@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3341 /* Save user registers on the stack */
3342 frame = &rt_sf->uc.uc_mcontext;
3343 addr = frame;
3344 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3345 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3346 if (save_user_regs(regs, frame, 0, 1))
3347 goto badframe;
3348 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3349 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3350 index 2fe6fc6..ada0d96 100644
3351 --- a/arch/powerpc/kernel/signal_64.c
3352 +++ b/arch/powerpc/kernel/signal_64.c
3353 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3354 current->thread.fpscr.val = 0;
3355
3356 /* Set up to return from userspace. */
3357 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3358 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3359 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3360 } else {
3361 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3362 diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
3363 index b97c2d6..dd01a6a 100644
3364 --- a/arch/powerpc/kernel/sys_ppc32.c
3365 +++ b/arch/powerpc/kernel/sys_ppc32.c
3366 @@ -563,10 +563,10 @@ asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
3367 if (oldlenp) {
3368 if (!error) {
3369 if (get_user(oldlen, oldlenp) ||
3370 - put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
3371 + put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
3372 + copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
3373 error = -EFAULT;
3374 }
3375 - copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
3376 }
3377 return error;
3378 }
3379 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3380 index 6f0ae1a..e4b6a56 100644
3381 --- a/arch/powerpc/kernel/traps.c
3382 +++ b/arch/powerpc/kernel/traps.c
3383 @@ -99,6 +99,8 @@ static void pmac_backlight_unblank(void)
3384 static inline void pmac_backlight_unblank(void) { }
3385 #endif
3386
3387 +extern void gr_handle_kernel_exploit(void);
3388 +
3389 int die(const char *str, struct pt_regs *regs, long err)
3390 {
3391 static struct {
3392 @@ -168,6 +170,8 @@ int die(const char *str, struct pt_regs *regs, long err)
3393 if (panic_on_oops)
3394 panic("Fatal exception");
3395
3396 + gr_handle_kernel_exploit();
3397 +
3398 oops_exit();
3399 do_exit(err);
3400
3401 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3402 index 137dc22..fe57a79 100644
3403 --- a/arch/powerpc/kernel/vdso.c
3404 +++ b/arch/powerpc/kernel/vdso.c
3405 @@ -36,6 +36,7 @@
3406 #include <asm/firmware.h>
3407 #include <asm/vdso.h>
3408 #include <asm/vdso_datapage.h>
3409 +#include <asm/mman.h>
3410
3411 #include "setup.h"
3412
3413 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3414 vdso_base = VDSO32_MBASE;
3415 #endif
3416
3417 - current->mm->context.vdso_base = 0;
3418 + current->mm->context.vdso_base = ~0UL;
3419
3420 /* vDSO has a problem and was disabled, just don't "enable" it for the
3421 * process
3422 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3423 vdso_base = get_unmapped_area(NULL, vdso_base,
3424 (vdso_pages << PAGE_SHIFT) +
3425 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3426 - 0, 0);
3427 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3428 if (IS_ERR_VALUE(vdso_base)) {
3429 rc = vdso_base;
3430 goto fail_mmapsem;
3431 diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
3432 index 77f6421..829564a 100644
3433 --- a/arch/powerpc/kernel/vio.c
3434 +++ b/arch/powerpc/kernel/vio.c
3435 @@ -601,11 +601,12 @@ static void vio_dma_iommu_unmap_sg(struct device *dev,
3436 vio_cmo_dealloc(viodev, alloc_size);
3437 }
3438
3439 -struct dma_map_ops vio_dma_mapping_ops = {
3440 +static const struct dma_map_ops vio_dma_mapping_ops = {
3441 .alloc_coherent = vio_dma_iommu_alloc_coherent,
3442 .free_coherent = vio_dma_iommu_free_coherent,
3443 .map_sg = vio_dma_iommu_map_sg,
3444 .unmap_sg = vio_dma_iommu_unmap_sg,
3445 + .dma_supported = dma_iommu_dma_supported,
3446 .map_page = vio_dma_iommu_map_page,
3447 .unmap_page = vio_dma_iommu_unmap_page,
3448
3449 @@ -857,7 +858,6 @@ static void vio_cmo_bus_remove(struct vio_dev *viodev)
3450
3451 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
3452 {
3453 - vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
3454 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
3455 }
3456
3457 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3458 index 5eea6f3..5d10396 100644
3459 --- a/arch/powerpc/lib/usercopy_64.c
3460 +++ b/arch/powerpc/lib/usercopy_64.c
3461 @@ -9,22 +9,6 @@
3462 #include <linux/module.h>
3463 #include <asm/uaccess.h>
3464
3465 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3466 -{
3467 - if (likely(access_ok(VERIFY_READ, from, n)))
3468 - n = __copy_from_user(to, from, n);
3469 - else
3470 - memset(to, 0, n);
3471 - return n;
3472 -}
3473 -
3474 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3475 -{
3476 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3477 - n = __copy_to_user(to, from, n);
3478 - return n;
3479 -}
3480 -
3481 unsigned long copy_in_user(void __user *to, const void __user *from,
3482 unsigned long n)
3483 {
3484 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
3485 return n;
3486 }
3487
3488 -EXPORT_SYMBOL(copy_from_user);
3489 -EXPORT_SYMBOL(copy_to_user);
3490 EXPORT_SYMBOL(copy_in_user);
3491
3492 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
3493 index e7dae82..877ce0d 100644
3494 --- a/arch/powerpc/mm/fault.c
3495 +++ b/arch/powerpc/mm/fault.c
3496 @@ -30,6 +30,10 @@
3497 #include <linux/kprobes.h>
3498 #include <linux/kdebug.h>
3499 #include <linux/perf_event.h>
3500 +#include <linux/slab.h>
3501 +#include <linux/pagemap.h>
3502 +#include <linux/compiler.h>
3503 +#include <linux/unistd.h>
3504
3505 #include <asm/firmware.h>
3506 #include <asm/page.h>
3507 @@ -40,6 +44,7 @@
3508 #include <asm/uaccess.h>
3509 #include <asm/tlbflush.h>
3510 #include <asm/siginfo.h>
3511 +#include <asm/ptrace.h>
3512
3513
3514 #ifdef CONFIG_KPROBES
3515 @@ -64,6 +69,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
3516 }
3517 #endif
3518
3519 +#ifdef CONFIG_PAX_PAGEEXEC
3520 +/*
3521 + * PaX: decide what to do with offenders (regs->nip = fault address)
3522 + *
3523 + * returns 1 when task should be killed
3524 + */
3525 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3526 +{
3527 + return 1;
3528 +}
3529 +
3530 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3531 +{
3532 + unsigned long i;
3533 +
3534 + printk(KERN_ERR "PAX: bytes at PC: ");
3535 + for (i = 0; i < 5; i++) {
3536 + unsigned int c;
3537 + if (get_user(c, (unsigned int __user *)pc+i))
3538 + printk(KERN_CONT "???????? ");
3539 + else
3540 + printk(KERN_CONT "%08x ", c);
3541 + }
3542 + printk("\n");
3543 +}
3544 +#endif
3545 +
3546 /*
3547 * Check whether the instruction at regs->nip is a store using
3548 * an update addressing form which will update r1.
3549 @@ -134,7 +166,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
3550 * indicate errors in DSISR but can validly be set in SRR1.
3551 */
3552 if (trap == 0x400)
3553 - error_code &= 0x48200000;
3554 + error_code &= 0x58200000;
3555 else
3556 is_write = error_code & DSISR_ISSTORE;
3557 #else
3558 @@ -250,7 +282,7 @@ good_area:
3559 * "undefined". Of those that can be set, this is the only
3560 * one which seems bad.
3561 */
3562 - if (error_code & 0x10000000)
3563 + if (error_code & DSISR_GUARDED)
3564 /* Guarded storage error. */
3565 goto bad_area;
3566 #endif /* CONFIG_8xx */
3567 @@ -265,7 +297,7 @@ good_area:
3568 * processors use the same I/D cache coherency mechanism
3569 * as embedded.
3570 */
3571 - if (error_code & DSISR_PROTFAULT)
3572 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3573 goto bad_area;
3574 #endif /* CONFIG_PPC_STD_MMU */
3575
3576 @@ -335,6 +367,23 @@ bad_area:
3577 bad_area_nosemaphore:
3578 /* User mode accesses cause a SIGSEGV */
3579 if (user_mode(regs)) {
3580 +
3581 +#ifdef CONFIG_PAX_PAGEEXEC
3582 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3583 +#ifdef CONFIG_PPC_STD_MMU
3584 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
3585 +#else
3586 + if (is_exec && regs->nip == address) {
3587 +#endif
3588 + switch (pax_handle_fetch_fault(regs)) {
3589 + }
3590 +
3591 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3592 + do_group_exit(SIGKILL);
3593 + }
3594 + }
3595 +#endif
3596 +
3597 _exception(SIGSEGV, regs, code, address);
3598 return 0;
3599 }
3600 diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
3601 index 5973631..ad617af 100644
3602 --- a/arch/powerpc/mm/mem.c
3603 +++ b/arch/powerpc/mm/mem.c
3604 @@ -250,7 +250,7 @@ static int __init mark_nonram_nosave(void)
3605 {
3606 unsigned long lmb_next_region_start_pfn,
3607 lmb_region_max_pfn;
3608 - int i;
3609 + unsigned int i;
3610
3611 for (i = 0; i < lmb.memory.cnt - 1; i++) {
3612 lmb_region_max_pfn =
3613 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
3614 index 0d957a4..26d968f 100644
3615 --- a/arch/powerpc/mm/mmap_64.c
3616 +++ b/arch/powerpc/mm/mmap_64.c
3617 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3618 */
3619 if (mmap_is_legacy()) {
3620 mm->mmap_base = TASK_UNMAPPED_BASE;
3621 +
3622 +#ifdef CONFIG_PAX_RANDMMAP
3623 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3624 + mm->mmap_base += mm->delta_mmap;
3625 +#endif
3626 +
3627 mm->get_unmapped_area = arch_get_unmapped_area;
3628 mm->unmap_area = arch_unmap_area;
3629 } else {
3630 mm->mmap_base = mmap_base();
3631 +
3632 +#ifdef CONFIG_PAX_RANDMMAP
3633 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3634 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3635 +#endif
3636 +
3637 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3638 mm->unmap_area = arch_unmap_area_topdown;
3639 }
3640 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
3641 index ba51948..23009d9 100644
3642 --- a/arch/powerpc/mm/slice.c
3643 +++ b/arch/powerpc/mm/slice.c
3644 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
3645 if ((mm->task_size - len) < addr)
3646 return 0;
3647 vma = find_vma(mm, addr);
3648 - return (!vma || (addr + len) <= vma->vm_start);
3649 + return check_heap_stack_gap(vma, addr, len);
3650 }
3651
3652 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3653 @@ -256,7 +256,7 @@ full_search:
3654 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3655 continue;
3656 }
3657 - if (!vma || addr + len <= vma->vm_start) {
3658 + if (check_heap_stack_gap(vma, addr, len)) {
3659 /*
3660 * Remember the place where we stopped the search:
3661 */
3662 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3663 }
3664 }
3665
3666 - addr = mm->mmap_base;
3667 - while (addr > len) {
3668 + if (mm->mmap_base < len)
3669 + addr = -ENOMEM;
3670 + else
3671 + addr = mm->mmap_base - len;
3672 +
3673 + while (!IS_ERR_VALUE(addr)) {
3674 /* Go down by chunk size */
3675 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3676 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
3677
3678 /* Check for hit with different page size */
3679 mask = slice_range_to_mask(addr, len);
3680 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3681 * return with success:
3682 */
3683 vma = find_vma(mm, addr);
3684 - if (!vma || (addr + len) <= vma->vm_start) {
3685 + if (check_heap_stack_gap(vma, addr, len)) {
3686 /* remember the address as a hint for next time */
3687 if (use_cache)
3688 mm->free_area_cache = addr;
3689 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3690 mm->cached_hole_size = vma->vm_start - addr;
3691
3692 /* try just below the current vma->vm_start */
3693 - addr = vma->vm_start;
3694 + addr = skip_heap_stack_gap(vma, len);
3695 }
3696
3697 /*
3698 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
3699 if (fixed && addr > (mm->task_size - len))
3700 return -EINVAL;
3701
3702 +#ifdef CONFIG_PAX_RANDMMAP
3703 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3704 + addr = 0;
3705 +#endif
3706 +
3707 /* If hint, make sure it matches our alignment restrictions */
3708 if (!fixed && addr) {
3709 addr = _ALIGN_UP(addr, 1ul << pshift);
3710 diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platforms/52xx/lite5200_pm.c
3711 index b5c753d..8f01abe 100644
3712 --- a/arch/powerpc/platforms/52xx/lite5200_pm.c
3713 +++ b/arch/powerpc/platforms/52xx/lite5200_pm.c
3714 @@ -235,7 +235,7 @@ static void lite5200_pm_end(void)
3715 lite5200_pm_target_state = PM_SUSPEND_ON;
3716 }
3717
3718 -static struct platform_suspend_ops lite5200_pm_ops = {
3719 +static const struct platform_suspend_ops lite5200_pm_ops = {
3720 .valid = lite5200_pm_valid,
3721 .begin = lite5200_pm_begin,
3722 .prepare = lite5200_pm_prepare,
3723 diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pm.c b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3724 index a55b0b6..478c18e 100644
3725 --- a/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3726 +++ b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3727 @@ -180,7 +180,7 @@ void mpc52xx_pm_finish(void)
3728 iounmap(mbar);
3729 }
3730
3731 -static struct platform_suspend_ops mpc52xx_pm_ops = {
3732 +static const struct platform_suspend_ops mpc52xx_pm_ops = {
3733 .valid = mpc52xx_pm_valid,
3734 .prepare = mpc52xx_pm_prepare,
3735 .enter = mpc52xx_pm_enter,
3736 diff --git a/arch/powerpc/platforms/83xx/suspend.c b/arch/powerpc/platforms/83xx/suspend.c
3737 index 08e65fc..643d3ac 100644
3738 --- a/arch/powerpc/platforms/83xx/suspend.c
3739 +++ b/arch/powerpc/platforms/83xx/suspend.c
3740 @@ -273,7 +273,7 @@ static int mpc83xx_is_pci_agent(void)
3741 return ret;
3742 }
3743
3744 -static struct platform_suspend_ops mpc83xx_suspend_ops = {
3745 +static const struct platform_suspend_ops mpc83xx_suspend_ops = {
3746 .valid = mpc83xx_suspend_valid,
3747 .begin = mpc83xx_suspend_begin,
3748 .enter = mpc83xx_suspend_enter,
3749 diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
3750 index ca5bfdf..1602e09 100644
3751 --- a/arch/powerpc/platforms/cell/iommu.c
3752 +++ b/arch/powerpc/platforms/cell/iommu.c
3753 @@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struct device *dev, u64 mask)
3754
3755 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3756
3757 -struct dma_map_ops dma_iommu_fixed_ops = {
3758 +const struct dma_map_ops dma_iommu_fixed_ops = {
3759 .alloc_coherent = dma_fixed_alloc_coherent,
3760 .free_coherent = dma_fixed_free_coherent,
3761 .map_sg = dma_fixed_map_sg,
3762 diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
3763 index e34b305..20e48ec 100644
3764 --- a/arch/powerpc/platforms/ps3/system-bus.c
3765 +++ b/arch/powerpc/platforms/ps3/system-bus.c
3766 @@ -694,7 +694,7 @@ static int ps3_dma_supported(struct device *_dev, u64 mask)
3767 return mask >= DMA_BIT_MASK(32);
3768 }
3769
3770 -static struct dma_map_ops ps3_sb_dma_ops = {
3771 +static const struct dma_map_ops ps3_sb_dma_ops = {
3772 .alloc_coherent = ps3_alloc_coherent,
3773 .free_coherent = ps3_free_coherent,
3774 .map_sg = ps3_sb_map_sg,
3775 @@ -704,7 +704,7 @@ static struct dma_map_ops ps3_sb_dma_ops = {
3776 .unmap_page = ps3_unmap_page,
3777 };
3778
3779 -static struct dma_map_ops ps3_ioc0_dma_ops = {
3780 +static const struct dma_map_ops ps3_ioc0_dma_ops = {
3781 .alloc_coherent = ps3_alloc_coherent,
3782 .free_coherent = ps3_free_coherent,
3783 .map_sg = ps3_ioc0_map_sg,
3784 diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
3785 index f0e6f28..60d53ed 100644
3786 --- a/arch/powerpc/platforms/pseries/Kconfig
3787 +++ b/arch/powerpc/platforms/pseries/Kconfig
3788 @@ -2,6 +2,8 @@ config PPC_PSERIES
3789 depends on PPC64 && PPC_BOOK3S
3790 bool "IBM pSeries & new (POWER5-based) iSeries"
3791 select MPIC
3792 + select PCI_MSI
3793 + select XICS
3794 select PPC_I8259
3795 select PPC_RTAS
3796 select RTAS_ERROR_LOGGING
3797 diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
3798 index 43c0aca..42c045b 100644
3799 --- a/arch/s390/Kconfig
3800 +++ b/arch/s390/Kconfig
3801 @@ -194,28 +194,26 @@ config AUDIT_ARCH
3802
3803 config S390_SWITCH_AMODE
3804 bool "Switch kernel/user addressing modes"
3805 + default y
3806 help
3807 This option allows to switch the addressing modes of kernel and user
3808 - space. The kernel parameter switch_amode=on will enable this feature,
3809 - default is disabled. Enabling this (via kernel parameter) on machines
3810 - earlier than IBM System z9-109 EC/BC will reduce system performance.
3811 + space. Enabling this on machines earlier than IBM System z9-109 EC/BC
3812 + will reduce system performance.
3813
3814 Note that this option will also be selected by selecting the execute
3815 - protection option below. Enabling the execute protection via the
3816 - noexec kernel parameter will also switch the addressing modes,
3817 - independent of the switch_amode kernel parameter.
3818 + protection option below. Enabling the execute protection will also
3819 + switch the addressing modes, independent of this option.
3820
3821
3822 config S390_EXEC_PROTECT
3823 bool "Data execute protection"
3824 + default y
3825 select S390_SWITCH_AMODE
3826 help
3827 This option allows to enable a buffer overflow protection for user
3828 space programs and it also selects the addressing mode option above.
3829 - The kernel parameter noexec=on will enable this feature and also
3830 - switch the addressing modes, default is disabled. Enabling this (via
3831 - kernel parameter) on machines earlier than IBM System z9-109 EC/BC
3832 - will reduce system performance.
3833 + Enabling this on machines earlier than IBM System z9-109 EC/BC will
3834 + reduce system performance.
3835
3836 comment "Code generation options"
3837
3838 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
3839 index e885442..5e6c303 100644
3840 --- a/arch/s390/include/asm/elf.h
3841 +++ b/arch/s390/include/asm/elf.h
3842 @@ -164,6 +164,13 @@ extern unsigned int vdso_enabled;
3843 that it will "exec", and that there is sufficient room for the brk. */
3844 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3845
3846 +#ifdef CONFIG_PAX_ASLR
3847 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3848 +
3849 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3850 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3851 +#endif
3852 +
3853 /* This yields a mask that user programs can use to figure out what
3854 instruction set this CPU supports. */
3855
3856 diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
3857 index e37478e..9ce0e9f 100644
3858 --- a/arch/s390/include/asm/setup.h
3859 +++ b/arch/s390/include/asm/setup.h
3860 @@ -50,13 +50,13 @@ extern unsigned long memory_end;
3861 void detect_memory_layout(struct mem_chunk chunk[]);
3862
3863 #ifdef CONFIG_S390_SWITCH_AMODE
3864 -extern unsigned int switch_amode;
3865 +#define switch_amode (1)
3866 #else
3867 #define switch_amode (0)
3868 #endif
3869
3870 #ifdef CONFIG_S390_EXEC_PROTECT
3871 -extern unsigned int s390_noexec;
3872 +#define s390_noexec (1)
3873 #else
3874 #define s390_noexec (0)
3875 #endif
3876 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
3877 index 8377e91..e28e6f1 100644
3878 --- a/arch/s390/include/asm/uaccess.h
3879 +++ b/arch/s390/include/asm/uaccess.h
3880 @@ -232,6 +232,10 @@ static inline unsigned long __must_check
3881 copy_to_user(void __user *to, const void *from, unsigned long n)
3882 {
3883 might_fault();
3884 +
3885 + if ((long)n < 0)
3886 + return n;
3887 +
3888 if (access_ok(VERIFY_WRITE, to, n))
3889 n = __copy_to_user(to, from, n);
3890 return n;
3891 @@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
3892 static inline unsigned long __must_check
3893 __copy_from_user(void *to, const void __user *from, unsigned long n)
3894 {
3895 + if ((long)n < 0)
3896 + return n;
3897 +
3898 if (__builtin_constant_p(n) && (n <= 256))
3899 return uaccess.copy_from_user_small(n, from, to);
3900 else
3901 @@ -283,6 +290,10 @@ static inline unsigned long __must_check
3902 copy_from_user(void *to, const void __user *from, unsigned long n)
3903 {
3904 might_fault();
3905 +
3906 + if ((long)n < 0)
3907 + return n;
3908 +
3909 if (access_ok(VERIFY_READ, from, n))
3910 n = __copy_from_user(to, from, n);
3911 else
3912 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
3913 index 639380a..72e3c02 100644
3914 --- a/arch/s390/kernel/module.c
3915 +++ b/arch/s390/kernel/module.c
3916 @@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
3917
3918 /* Increase core size by size of got & plt and set start
3919 offsets for got and plt. */
3920 - me->core_size = ALIGN(me->core_size, 4);
3921 - me->arch.got_offset = me->core_size;
3922 - me->core_size += me->arch.got_size;
3923 - me->arch.plt_offset = me->core_size;
3924 - me->core_size += me->arch.plt_size;
3925 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3926 + me->arch.got_offset = me->core_size_rw;
3927 + me->core_size_rw += me->arch.got_size;
3928 + me->arch.plt_offset = me->core_size_rx;
3929 + me->core_size_rx += me->arch.plt_size;
3930 return 0;
3931 }
3932
3933 @@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3934 if (info->got_initialized == 0) {
3935 Elf_Addr *gotent;
3936
3937 - gotent = me->module_core + me->arch.got_offset +
3938 + gotent = me->module_core_rw + me->arch.got_offset +
3939 info->got_offset;
3940 *gotent = val;
3941 info->got_initialized = 1;
3942 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3943 else if (r_type == R_390_GOTENT ||
3944 r_type == R_390_GOTPLTENT)
3945 *(unsigned int *) loc =
3946 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3947 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3948 else if (r_type == R_390_GOT64 ||
3949 r_type == R_390_GOTPLT64)
3950 *(unsigned long *) loc = val;
3951 @@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3952 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3953 if (info->plt_initialized == 0) {
3954 unsigned int *ip;
3955 - ip = me->module_core + me->arch.plt_offset +
3956 + ip = me->module_core_rx + me->arch.plt_offset +
3957 info->plt_offset;
3958 #ifndef CONFIG_64BIT
3959 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3960 @@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3961 val - loc + 0xffffUL < 0x1ffffeUL) ||
3962 (r_type == R_390_PLT32DBL &&
3963 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3964 - val = (Elf_Addr) me->module_core +
3965 + val = (Elf_Addr) me->module_core_rx +
3966 me->arch.plt_offset +
3967 info->plt_offset;
3968 val += rela->r_addend - loc;
3969 @@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3970 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3971 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3972 val = val + rela->r_addend -
3973 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3974 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3975 if (r_type == R_390_GOTOFF16)
3976 *(unsigned short *) loc = val;
3977 else if (r_type == R_390_GOTOFF32)
3978 @@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3979 break;
3980 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3981 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3982 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3983 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3984 rela->r_addend - loc;
3985 if (r_type == R_390_GOTPC)
3986 *(unsigned int *) loc = val;
3987 diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
3988 index 061479f..dbfb08c 100644
3989 --- a/arch/s390/kernel/setup.c
3990 +++ b/arch/s390/kernel/setup.c
3991 @@ -306,9 +306,6 @@ static int __init early_parse_mem(char *p)
3992 early_param("mem", early_parse_mem);
3993
3994 #ifdef CONFIG_S390_SWITCH_AMODE
3995 -unsigned int switch_amode = 0;
3996 -EXPORT_SYMBOL_GPL(switch_amode);
3997 -
3998 static int set_amode_and_uaccess(unsigned long user_amode,
3999 unsigned long user32_amode)
4000 {
4001 @@ -334,17 +331,6 @@ static int set_amode_and_uaccess(unsigned long user_amode,
4002 return 0;
4003 }
4004 }
4005 -
4006 -/*
4007 - * Switch kernel/user addressing modes?
4008 - */
4009 -static int __init early_parse_switch_amode(char *p)
4010 -{
4011 - switch_amode = 1;
4012 - return 0;
4013 -}
4014 -early_param("switch_amode", early_parse_switch_amode);
4015 -
4016 #else /* CONFIG_S390_SWITCH_AMODE */
4017 static inline int set_amode_and_uaccess(unsigned long user_amode,
4018 unsigned long user32_amode)
4019 @@ -353,24 +339,6 @@ static inline int set_amode_and_uaccess(unsigned long user_amode,
4020 }
4021 #endif /* CONFIG_S390_SWITCH_AMODE */
4022
4023 -#ifdef CONFIG_S390_EXEC_PROTECT
4024 -unsigned int s390_noexec = 0;
4025 -EXPORT_SYMBOL_GPL(s390_noexec);
4026 -
4027 -/*
4028 - * Enable execute protection?
4029 - */
4030 -static int __init early_parse_noexec(char *p)
4031 -{
4032 - if (!strncmp(p, "off", 3))
4033 - return 0;
4034 - switch_amode = 1;
4035 - s390_noexec = 1;
4036 - return 0;
4037 -}
4038 -early_param("noexec", early_parse_noexec);
4039 -#endif /* CONFIG_S390_EXEC_PROTECT */
4040 -
4041 static void setup_addressing_mode(void)
4042 {
4043 if (s390_noexec) {
4044 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4045 index f4558cc..e461f37 100644
4046 --- a/arch/s390/mm/mmap.c
4047 +++ b/arch/s390/mm/mmap.c
4048 @@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4049 */
4050 if (mmap_is_legacy()) {
4051 mm->mmap_base = TASK_UNMAPPED_BASE;
4052 +
4053 +#ifdef CONFIG_PAX_RANDMMAP
4054 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4055 + mm->mmap_base += mm->delta_mmap;
4056 +#endif
4057 +
4058 mm->get_unmapped_area = arch_get_unmapped_area;
4059 mm->unmap_area = arch_unmap_area;
4060 } else {
4061 mm->mmap_base = mmap_base();
4062 +
4063 +#ifdef CONFIG_PAX_RANDMMAP
4064 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4065 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4066 +#endif
4067 +
4068 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4069 mm->unmap_area = arch_unmap_area_topdown;
4070 }
4071 @@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4072 */
4073 if (mmap_is_legacy()) {
4074 mm->mmap_base = TASK_UNMAPPED_BASE;
4075 +
4076 +#ifdef CONFIG_PAX_RANDMMAP
4077 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4078 + mm->mmap_base += mm->delta_mmap;
4079 +#endif
4080 +
4081 mm->get_unmapped_area = s390_get_unmapped_area;
4082 mm->unmap_area = arch_unmap_area;
4083 } else {
4084 mm->mmap_base = mmap_base();
4085 +
4086 +#ifdef CONFIG_PAX_RANDMMAP
4087 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4088 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4089 +#endif
4090 +
4091 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4092 mm->unmap_area = arch_unmap_area_topdown;
4093 }
4094 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4095 index 589d5c7..669e274 100644
4096 --- a/arch/score/include/asm/system.h
4097 +++ b/arch/score/include/asm/system.h
4098 @@ -17,7 +17,7 @@ do { \
4099 #define finish_arch_switch(prev) do {} while (0)
4100
4101 typedef void (*vi_handler_t)(void);
4102 -extern unsigned long arch_align_stack(unsigned long sp);
4103 +#define arch_align_stack(x) (x)
4104
4105 #define mb() barrier()
4106 #define rmb() barrier()
4107 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4108 index 25d0803..d6c8e36 100644
4109 --- a/arch/score/kernel/process.c
4110 +++ b/arch/score/kernel/process.c
4111 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4112
4113 return task_pt_regs(task)->cp0_epc;
4114 }
4115 -
4116 -unsigned long arch_align_stack(unsigned long sp)
4117 -{
4118 - return sp;
4119 -}
4120 diff --git a/arch/sh/boards/mach-hp6xx/pm.c b/arch/sh/boards/mach-hp6xx/pm.c
4121 index d936c1a..304a252 100644
4122 --- a/arch/sh/boards/mach-hp6xx/pm.c
4123 +++ b/arch/sh/boards/mach-hp6xx/pm.c
4124 @@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_t state)
4125 return 0;
4126 }
4127
4128 -static struct platform_suspend_ops hp6x0_pm_ops = {
4129 +static const struct platform_suspend_ops hp6x0_pm_ops = {
4130 .enter = hp6x0_pm_enter,
4131 .valid = suspend_valid_only_mem,
4132 };
4133 diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
4134 index 8a8a993..7b3079b 100644
4135 --- a/arch/sh/kernel/cpu/sh4/sq.c
4136 +++ b/arch/sh/kernel/cpu/sh4/sq.c
4137 @@ -327,7 +327,7 @@ static struct attribute *sq_sysfs_attrs[] = {
4138 NULL,
4139 };
4140
4141 -static struct sysfs_ops sq_sysfs_ops = {
4142 +static const struct sysfs_ops sq_sysfs_ops = {
4143 .show = sq_sysfs_show,
4144 .store = sq_sysfs_store,
4145 };
4146 diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c
4147 index ee3c2aa..c49cee6 100644
4148 --- a/arch/sh/kernel/cpu/shmobile/pm.c
4149 +++ b/arch/sh/kernel/cpu/shmobile/pm.c
4150 @@ -58,7 +58,7 @@ static int sh_pm_enter(suspend_state_t state)
4151 return 0;
4152 }
4153
4154 -static struct platform_suspend_ops sh_pm_ops = {
4155 +static const struct platform_suspend_ops sh_pm_ops = {
4156 .enter = sh_pm_enter,
4157 .valid = suspend_valid_only_mem,
4158 };
4159 diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
4160 index 3e532d0..9faa306 100644
4161 --- a/arch/sh/kernel/kgdb.c
4162 +++ b/arch/sh/kernel/kgdb.c
4163 @@ -271,7 +271,7 @@ void kgdb_arch_exit(void)
4164 {
4165 }
4166
4167 -struct kgdb_arch arch_kgdb_ops = {
4168 +const struct kgdb_arch arch_kgdb_ops = {
4169 /* Breakpoint instruction: trapa #0x3c */
4170 #ifdef CONFIG_CPU_LITTLE_ENDIAN
4171 .gdb_bpt_instr = { 0x3c, 0xc3 },
4172 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4173 index afeb710..d1d1289 100644
4174 --- a/arch/sh/mm/mmap.c
4175 +++ b/arch/sh/mm/mmap.c
4176 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4177 addr = PAGE_ALIGN(addr);
4178
4179 vma = find_vma(mm, addr);
4180 - if (TASK_SIZE - len >= addr &&
4181 - (!vma || addr + len <= vma->vm_start))
4182 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4183 return addr;
4184 }
4185
4186 @@ -106,7 +105,7 @@ full_search:
4187 }
4188 return -ENOMEM;
4189 }
4190 - if (likely(!vma || addr + len <= vma->vm_start)) {
4191 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4192 /*
4193 * Remember the place where we stopped the search:
4194 */
4195 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4196 addr = PAGE_ALIGN(addr);
4197
4198 vma = find_vma(mm, addr);
4199 - if (TASK_SIZE - len >= addr &&
4200 - (!vma || addr + len <= vma->vm_start))
4201 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4202 return addr;
4203 }
4204
4205 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4206 /* make sure it can fit in the remaining address space */
4207 if (likely(addr > len)) {
4208 vma = find_vma(mm, addr-len);
4209 - if (!vma || addr <= vma->vm_start) {
4210 + if (check_heap_stack_gap(vma, addr - len, len)) {
4211 /* remember the address as a hint for next time */
4212 return (mm->free_area_cache = addr-len);
4213 }
4214 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4215 if (unlikely(mm->mmap_base < len))
4216 goto bottomup;
4217
4218 - addr = mm->mmap_base-len;
4219 - if (do_colour_align)
4220 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4221 + addr = mm->mmap_base - len;
4222
4223 do {
4224 + if (do_colour_align)
4225 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4226 /*
4227 * Lookup failure means no vma is above this address,
4228 * else if new region fits below vma->vm_start,
4229 * return with success:
4230 */
4231 vma = find_vma(mm, addr);
4232 - if (likely(!vma || addr+len <= vma->vm_start)) {
4233 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4234 /* remember the address as a hint for next time */
4235 return (mm->free_area_cache = addr);
4236 }
4237 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4238 mm->cached_hole_size = vma->vm_start - addr;
4239
4240 /* try just below the current vma->vm_start */
4241 - addr = vma->vm_start-len;
4242 - if (do_colour_align)
4243 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4244 - } while (likely(len < vma->vm_start));
4245 + addr = skip_heap_stack_gap(vma, len);
4246 + } while (!IS_ERR_VALUE(addr));
4247
4248 bottomup:
4249 /*
4250 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4251 index 113225b..7fd04e7 100644
4252 --- a/arch/sparc/Makefile
4253 +++ b/arch/sparc/Makefile
4254 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4255 # Export what is needed by arch/sparc/boot/Makefile
4256 export VMLINUX_INIT VMLINUX_MAIN
4257 VMLINUX_INIT := $(head-y) $(init-y)
4258 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4259 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4260 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4261 VMLINUX_MAIN += $(drivers-y) $(net-y)
4262
4263 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4264 index f5cc06f..f858d47 100644
4265 --- a/arch/sparc/include/asm/atomic_64.h
4266 +++ b/arch/sparc/include/asm/atomic_64.h
4267 @@ -14,18 +14,40 @@
4268 #define ATOMIC64_INIT(i) { (i) }
4269
4270 #define atomic_read(v) ((v)->counter)
4271 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4272 +{
4273 + return v->counter;
4274 +}
4275 #define atomic64_read(v) ((v)->counter)
4276 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4277 +{
4278 + return v->counter;
4279 +}
4280
4281 #define atomic_set(v, i) (((v)->counter) = i)
4282 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4283 +{
4284 + v->counter = i;
4285 +}
4286 #define atomic64_set(v, i) (((v)->counter) = i)
4287 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4288 +{
4289 + v->counter = i;
4290 +}
4291
4292 extern void atomic_add(int, atomic_t *);
4293 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4294 extern void atomic64_add(long, atomic64_t *);
4295 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4296 extern void atomic_sub(int, atomic_t *);
4297 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4298 extern void atomic64_sub(long, atomic64_t *);
4299 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4300
4301 extern int atomic_add_ret(int, atomic_t *);
4302 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4303 extern long atomic64_add_ret(long, atomic64_t *);
4304 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4305 extern int atomic_sub_ret(int, atomic_t *);
4306 extern long atomic64_sub_ret(long, atomic64_t *);
4307
4308 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4309 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4310
4311 #define atomic_inc_return(v) atomic_add_ret(1, v)
4312 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4313 +{
4314 + return atomic_add_ret_unchecked(1, v);
4315 +}
4316 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4317 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4318 +{
4319 + return atomic64_add_ret_unchecked(1, v);
4320 +}
4321
4322 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4323 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4324
4325 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4326 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4327 +{
4328 + return atomic_add_ret_unchecked(i, v);
4329 +}
4330 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4331 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4332 +{
4333 + return atomic64_add_ret_unchecked(i, v);
4334 +}
4335
4336 /*
4337 * atomic_inc_and_test - increment and test
4338 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4339 * other cases.
4340 */
4341 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4342 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4343 +{
4344 + return atomic_inc_return_unchecked(v) == 0;
4345 +}
4346 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4347
4348 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4349 @@ -59,30 +101,65 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4350 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4351
4352 #define atomic_inc(v) atomic_add(1, v)
4353 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4354 +{
4355 + atomic_add_unchecked(1, v);
4356 +}
4357 #define atomic64_inc(v) atomic64_add(1, v)
4358 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4359 +{
4360 + atomic64_add_unchecked(1, v);
4361 +}
4362
4363 #define atomic_dec(v) atomic_sub(1, v)
4364 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4365 +{
4366 + atomic_sub_unchecked(1, v);
4367 +}
4368 #define atomic64_dec(v) atomic64_sub(1, v)
4369 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4370 +{
4371 + atomic64_sub_unchecked(1, v);
4372 +}
4373
4374 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4375 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4376
4377 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4378 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4379 +{
4380 + return cmpxchg(&v->counter, old, new);
4381 +}
4382 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4383 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4384 +{
4385 + return xchg(&v->counter, new);
4386 +}
4387
4388 static inline int atomic_add_unless(atomic_t *v, int a, int u)
4389 {
4390 - int c, old;
4391 + int c, old, new;
4392 c = atomic_read(v);
4393 for (;;) {
4394 - if (unlikely(c == (u)))
4395 + if (unlikely(c == u))
4396 break;
4397 - old = atomic_cmpxchg((v), c, c + (a));
4398 +
4399 + asm volatile("addcc %2, %0, %0\n"
4400 +
4401 +#ifdef CONFIG_PAX_REFCOUNT
4402 + "tvs %%icc, 6\n"
4403 +#endif
4404 +
4405 + : "=r" (new)
4406 + : "0" (c), "ir" (a)
4407 + : "cc");
4408 +
4409 + old = atomic_cmpxchg(v, c, new);
4410 if (likely(old == c))
4411 break;
4412 c = old;
4413 }
4414 - return c != (u);
4415 + return c != u;
4416 }
4417
4418 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
4419 @@ -90,20 +167,35 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
4420 #define atomic64_cmpxchg(v, o, n) \
4421 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4422 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4423 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4424 +{
4425 + return xchg(&v->counter, new);
4426 +}
4427
4428 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4429 {
4430 - long c, old;
4431 + long c, old, new;
4432 c = atomic64_read(v);
4433 for (;;) {
4434 - if (unlikely(c == (u)))
4435 + if (unlikely(c == u))
4436 break;
4437 - old = atomic64_cmpxchg((v), c, c + (a));
4438 +
4439 + asm volatile("addcc %2, %0, %0\n"
4440 +
4441 +#ifdef CONFIG_PAX_REFCOUNT
4442 + "tvs %%xcc, 6\n"
4443 +#endif
4444 +
4445 + : "=r" (new)
4446 + : "0" (c), "ir" (a)
4447 + : "cc");
4448 +
4449 + old = atomic64_cmpxchg(v, c, new);
4450 if (likely(old == c))
4451 break;
4452 c = old;
4453 }
4454 - return c != (u);
4455 + return c != u;
4456 }
4457
4458 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4459 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4460 index 41f85ae..fb54d5e 100644
4461 --- a/arch/sparc/include/asm/cache.h
4462 +++ b/arch/sparc/include/asm/cache.h
4463 @@ -8,7 +8,7 @@
4464 #define _SPARC_CACHE_H
4465
4466 #define L1_CACHE_SHIFT 5
4467 -#define L1_CACHE_BYTES 32
4468 +#define L1_CACHE_BYTES 32UL
4469 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
4470
4471 #ifdef CONFIG_SPARC32
4472 diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h
4473 index 5a8c308..38def92 100644
4474 --- a/arch/sparc/include/asm/dma-mapping.h
4475 +++ b/arch/sparc/include/asm/dma-mapping.h
4476 @@ -14,10 +14,10 @@ extern int dma_set_mask(struct device *dev, u64 dma_mask);
4477 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
4478 #define dma_is_consistent(d, h) (1)
4479
4480 -extern struct dma_map_ops *dma_ops, pci32_dma_ops;
4481 +extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
4482 extern struct bus_type pci_bus_type;
4483
4484 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4485 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
4486 {
4487 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
4488 if (dev->bus == &pci_bus_type)
4489 @@ -31,7 +31,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4490 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4491 dma_addr_t *dma_handle, gfp_t flag)
4492 {
4493 - struct dma_map_ops *ops = get_dma_ops(dev);
4494 + const struct dma_map_ops *ops = get_dma_ops(dev);
4495 void *cpu_addr;
4496
4497 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
4498 @@ -42,7 +42,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4499 static inline void dma_free_coherent(struct device *dev, size_t size,
4500 void *cpu_addr, dma_addr_t dma_handle)
4501 {
4502 - struct dma_map_ops *ops = get_dma_ops(dev);
4503 + const struct dma_map_ops *ops = get_dma_ops(dev);
4504
4505 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
4506 ops->free_coherent(dev, size, cpu_addr, dma_handle);
4507 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4508 index 381a1b5..b97e3ff 100644
4509 --- a/arch/sparc/include/asm/elf_32.h
4510 +++ b/arch/sparc/include/asm/elf_32.h
4511 @@ -116,6 +116,13 @@ typedef struct {
4512
4513 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4514
4515 +#ifdef CONFIG_PAX_ASLR
4516 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4517 +
4518 +#define PAX_DELTA_MMAP_LEN 16
4519 +#define PAX_DELTA_STACK_LEN 16
4520 +#endif
4521 +
4522 /* This yields a mask that user programs can use to figure out what
4523 instruction set this cpu supports. This can NOT be done in userspace
4524 on Sparc. */
4525 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4526 index 9968085..c2106ef 100644
4527 --- a/arch/sparc/include/asm/elf_64.h
4528 +++ b/arch/sparc/include/asm/elf_64.h
4529 @@ -163,6 +163,12 @@ typedef struct {
4530 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4531 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4532
4533 +#ifdef CONFIG_PAX_ASLR
4534 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4535 +
4536 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4537 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4538 +#endif
4539
4540 /* This yields a mask that user programs can use to figure out what
4541 instruction set this cpu supports. */
4542 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4543 index e0cabe7..efd60f1 100644
4544 --- a/arch/sparc/include/asm/pgtable_32.h
4545 +++ b/arch/sparc/include/asm/pgtable_32.h
4546 @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4547 BTFIXUPDEF_INT(page_none)
4548 BTFIXUPDEF_INT(page_copy)
4549 BTFIXUPDEF_INT(page_readonly)
4550 +
4551 +#ifdef CONFIG_PAX_PAGEEXEC
4552 +BTFIXUPDEF_INT(page_shared_noexec)
4553 +BTFIXUPDEF_INT(page_copy_noexec)
4554 +BTFIXUPDEF_INT(page_readonly_noexec)
4555 +#endif
4556 +
4557 BTFIXUPDEF_INT(page_kernel)
4558
4559 #define PMD_SHIFT SUN4C_PMD_SHIFT
4560 @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
4561 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4562 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4563
4564 +#ifdef CONFIG_PAX_PAGEEXEC
4565 +extern pgprot_t PAGE_SHARED_NOEXEC;
4566 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4567 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4568 +#else
4569 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4570 +# define PAGE_COPY_NOEXEC PAGE_COPY
4571 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4572 +#endif
4573 +
4574 extern unsigned long page_kernel;
4575
4576 #ifdef MODULE
4577 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4578 index 1407c07..7e10231 100644
4579 --- a/arch/sparc/include/asm/pgtsrmmu.h
4580 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4581 @@ -115,6 +115,13 @@
4582 SRMMU_EXEC | SRMMU_REF)
4583 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4584 SRMMU_EXEC | SRMMU_REF)
4585 +
4586 +#ifdef CONFIG_PAX_PAGEEXEC
4587 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4588 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4589 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4590 +#endif
4591 +
4592 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4593 SRMMU_DIRTY | SRMMU_REF)
4594
4595 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4596 index 43e5147..47622a1 100644
4597 --- a/arch/sparc/include/asm/spinlock_64.h
4598 +++ b/arch/sparc/include/asm/spinlock_64.h
4599 @@ -92,14 +92,19 @@ static inline void __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long fla
4600
4601 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4602
4603 -static void inline arch_read_lock(raw_rwlock_t *lock)
4604 +static inline void arch_read_lock(raw_rwlock_t *lock)
4605 {
4606 unsigned long tmp1, tmp2;
4607
4608 __asm__ __volatile__ (
4609 "1: ldsw [%2], %0\n"
4610 " brlz,pn %0, 2f\n"
4611 -"4: add %0, 1, %1\n"
4612 +"4: addcc %0, 1, %1\n"
4613 +
4614 +#ifdef CONFIG_PAX_REFCOUNT
4615 +" tvs %%icc, 6\n"
4616 +#endif
4617 +
4618 " cas [%2], %0, %1\n"
4619 " cmp %0, %1\n"
4620 " bne,pn %%icc, 1b\n"
4621 @@ -112,10 +117,10 @@ static void inline arch_read_lock(raw_rwlock_t *lock)
4622 " .previous"
4623 : "=&r" (tmp1), "=&r" (tmp2)
4624 : "r" (lock)
4625 - : "memory");
4626 + : "memory", "cc");
4627 }
4628
4629 -static int inline arch_read_trylock(raw_rwlock_t *lock)
4630 +static inline int arch_read_trylock(raw_rwlock_t *lock)
4631 {
4632 int tmp1, tmp2;
4633
4634 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(raw_rwlock_t *lock)
4635 "1: ldsw [%2], %0\n"
4636 " brlz,a,pn %0, 2f\n"
4637 " mov 0, %0\n"
4638 -" add %0, 1, %1\n"
4639 +" addcc %0, 1, %1\n"
4640 +
4641 +#ifdef CONFIG_PAX_REFCOUNT
4642 +" tvs %%icc, 6\n"
4643 +#endif
4644 +
4645 " cas [%2], %0, %1\n"
4646 " cmp %0, %1\n"
4647 " bne,pn %%icc, 1b\n"
4648 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(raw_rwlock_t *lock)
4649 return tmp1;
4650 }
4651
4652 -static void inline arch_read_unlock(raw_rwlock_t *lock)
4653 +static inline void arch_read_unlock(raw_rwlock_t *lock)
4654 {
4655 unsigned long tmp1, tmp2;
4656
4657 __asm__ __volatile__(
4658 "1: lduw [%2], %0\n"
4659 -" sub %0, 1, %1\n"
4660 +" subcc %0, 1, %1\n"
4661 +
4662 +#ifdef CONFIG_PAX_REFCOUNT
4663 +" tvs %%icc, 6\n"
4664 +#endif
4665 +
4666 " cas [%2], %0, %1\n"
4667 " cmp %0, %1\n"
4668 " bne,pn %%xcc, 1b\n"
4669 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(raw_rwlock_t *lock)
4670 : "memory");
4671 }
4672
4673 -static void inline arch_write_lock(raw_rwlock_t *lock)
4674 +static inline void arch_write_lock(raw_rwlock_t *lock)
4675 {
4676 unsigned long mask, tmp1, tmp2;
4677
4678 @@ -177,7 +192,7 @@ static void inline arch_write_lock(raw_rwlock_t *lock)
4679 : "memory");
4680 }
4681
4682 -static void inline arch_write_unlock(raw_rwlock_t *lock)
4683 +static inline void arch_write_unlock(raw_rwlock_t *lock)
4684 {
4685 __asm__ __volatile__(
4686 " stw %%g0, [%0]"
4687 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(raw_rwlock_t *lock)
4688 : "memory");
4689 }
4690
4691 -static int inline arch_write_trylock(raw_rwlock_t *lock)
4692 +static inline int arch_write_trylock(raw_rwlock_t *lock)
4693 {
4694 unsigned long mask, tmp1, tmp2, result;
4695
4696 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
4697 index 844d73a..f787fb9 100644
4698 --- a/arch/sparc/include/asm/thread_info_32.h
4699 +++ b/arch/sparc/include/asm/thread_info_32.h
4700 @@ -50,6 +50,8 @@ struct thread_info {
4701 unsigned long w_saved;
4702
4703 struct restart_block restart_block;
4704 +
4705 + unsigned long lowest_stack;
4706 };
4707
4708 /*
4709 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
4710 index f78ad9a..9f55fc7 100644
4711 --- a/arch/sparc/include/asm/thread_info_64.h
4712 +++ b/arch/sparc/include/asm/thread_info_64.h
4713 @@ -68,6 +68,8 @@ struct thread_info {
4714 struct pt_regs *kern_una_regs;
4715 unsigned int kern_una_insn;
4716
4717 + unsigned long lowest_stack;
4718 +
4719 unsigned long fpregs[0] __attribute__ ((aligned(64)));
4720 };
4721
4722 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
4723 index e88fbe5..96b0ce5 100644
4724 --- a/arch/sparc/include/asm/uaccess.h
4725 +++ b/arch/sparc/include/asm/uaccess.h
4726 @@ -1,5 +1,13 @@
4727 #ifndef ___ASM_SPARC_UACCESS_H
4728 #define ___ASM_SPARC_UACCESS_H
4729 +
4730 +#ifdef __KERNEL__
4731 +#ifndef __ASSEMBLY__
4732 +#include <linux/types.h>
4733 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4734 +#endif
4735 +#endif
4736 +
4737 #if defined(__sparc__) && defined(__arch64__)
4738 #include <asm/uaccess_64.h>
4739 #else
4740 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
4741 index 8303ac4..07f333d 100644
4742 --- a/arch/sparc/include/asm/uaccess_32.h
4743 +++ b/arch/sparc/include/asm/uaccess_32.h
4744 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
4745
4746 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4747 {
4748 - if (n && __access_ok((unsigned long) to, n))
4749 + if ((long)n < 0)
4750 + return n;
4751 +
4752 + if (n && __access_ok((unsigned long) to, n)) {
4753 + if (!__builtin_constant_p(n))
4754 + check_object_size(from, n, true);
4755 return __copy_user(to, (__force void __user *) from, n);
4756 - else
4757 + } else
4758 return n;
4759 }
4760
4761 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4762 {
4763 + if ((long)n < 0)
4764 + return n;
4765 +
4766 + if (!__builtin_constant_p(n))
4767 + check_object_size(from, n, true);
4768 +
4769 return __copy_user(to, (__force void __user *) from, n);
4770 }
4771
4772 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4773 {
4774 - if (n && __access_ok((unsigned long) from, n))
4775 + if ((long)n < 0)
4776 + return n;
4777 +
4778 + if (n && __access_ok((unsigned long) from, n)) {
4779 + if (!__builtin_constant_p(n))
4780 + check_object_size(to, n, false);
4781 return __copy_user((__force void __user *) to, from, n);
4782 - else
4783 + } else
4784 return n;
4785 }
4786
4787 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4788 {
4789 + if ((long)n < 0)
4790 + return n;
4791 +
4792 return __copy_user((__force void __user *) to, from, n);
4793 }
4794
4795 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
4796 index 9ea271e..7b8a271 100644
4797 --- a/arch/sparc/include/asm/uaccess_64.h
4798 +++ b/arch/sparc/include/asm/uaccess_64.h
4799 @@ -9,6 +9,7 @@
4800 #include <linux/compiler.h>
4801 #include <linux/string.h>
4802 #include <linux/thread_info.h>
4803 +#include <linux/kernel.h>
4804 #include <asm/asi.h>
4805 #include <asm/system.h>
4806 #include <asm/spitfire.h>
4807 @@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
4808 static inline unsigned long __must_check
4809 copy_from_user(void *to, const void __user *from, unsigned long size)
4810 {
4811 - unsigned long ret = ___copy_from_user(to, from, size);
4812 + unsigned long ret;
4813
4814 + if ((long)size < 0 || size > INT_MAX)
4815 + return size;
4816 +
4817 + if (!__builtin_constant_p(size))
4818 + check_object_size(to, size, false);
4819 +
4820 + ret = ___copy_from_user(to, from, size);
4821 if (unlikely(ret))
4822 ret = copy_from_user_fixup(to, from, size);
4823 return ret;
4824 @@ -228,8 +236,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
4825 static inline unsigned long __must_check
4826 copy_to_user(void __user *to, const void *from, unsigned long size)
4827 {
4828 - unsigned long ret = ___copy_to_user(to, from, size);
4829 + unsigned long ret;
4830
4831 + if ((long)size < 0 || size > INT_MAX)
4832 + return size;
4833 +
4834 + if (!__builtin_constant_p(size))
4835 + check_object_size(from, size, true);
4836 +
4837 + ret = ___copy_to_user(to, from, size);
4838 if (unlikely(ret))
4839 ret = copy_to_user_fixup(to, from, size);
4840 return ret;
4841 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
4842 index 2782681..77ded84 100644
4843 --- a/arch/sparc/kernel/Makefile
4844 +++ b/arch/sparc/kernel/Makefile
4845 @@ -3,7 +3,7 @@
4846 #
4847
4848 asflags-y := -ansi
4849 -ccflags-y := -Werror
4850 +#ccflags-y := -Werror
4851
4852 extra-y := head_$(BITS).o
4853 extra-y += init_task.o
4854 diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
4855 index 7690cc2..ece64c9 100644
4856 --- a/arch/sparc/kernel/iommu.c
4857 +++ b/arch/sparc/kernel/iommu.c
4858 @@ -826,7 +826,7 @@ static void dma_4u_sync_sg_for_cpu(struct device *dev,
4859 spin_unlock_irqrestore(&iommu->lock, flags);
4860 }
4861
4862 -static struct dma_map_ops sun4u_dma_ops = {
4863 +static const struct dma_map_ops sun4u_dma_ops = {
4864 .alloc_coherent = dma_4u_alloc_coherent,
4865 .free_coherent = dma_4u_free_coherent,
4866 .map_page = dma_4u_map_page,
4867 @@ -837,7 +837,7 @@ static struct dma_map_ops sun4u_dma_ops = {
4868 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
4869 };
4870
4871 -struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4872 +const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4873 EXPORT_SYMBOL(dma_ops);
4874
4875 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
4876 diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
4877 index 9f61fd8..bd048db 100644
4878 --- a/arch/sparc/kernel/ioport.c
4879 +++ b/arch/sparc/kernel/ioport.c
4880 @@ -392,7 +392,7 @@ static void sbus_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
4881 BUG();
4882 }
4883
4884 -struct dma_map_ops sbus_dma_ops = {
4885 +const struct dma_map_ops sbus_dma_ops = {
4886 .alloc_coherent = sbus_alloc_coherent,
4887 .free_coherent = sbus_free_coherent,
4888 .map_page = sbus_map_page,
4889 @@ -403,7 +403,7 @@ struct dma_map_ops sbus_dma_ops = {
4890 .sync_sg_for_device = sbus_sync_sg_for_device,
4891 };
4892
4893 -struct dma_map_ops *dma_ops = &sbus_dma_ops;
4894 +const struct dma_map_ops *dma_ops = &sbus_dma_ops;
4895 EXPORT_SYMBOL(dma_ops);
4896
4897 static int __init sparc_register_ioport(void)
4898 @@ -640,7 +640,7 @@ static void pci32_sync_sg_for_device(struct device *device, struct scatterlist *
4899 }
4900 }
4901
4902 -struct dma_map_ops pci32_dma_ops = {
4903 +const struct dma_map_ops pci32_dma_ops = {
4904 .alloc_coherent = pci32_alloc_coherent,
4905 .free_coherent = pci32_free_coherent,
4906 .map_page = pci32_map_page,
4907 diff --git a/arch/sparc/kernel/kgdb_32.c b/arch/sparc/kernel/kgdb_32.c
4908 index 04df4ed..55c4b6e 100644
4909 --- a/arch/sparc/kernel/kgdb_32.c
4910 +++ b/arch/sparc/kernel/kgdb_32.c
4911 @@ -158,7 +158,7 @@ void kgdb_arch_exit(void)
4912 {
4913 }
4914
4915 -struct kgdb_arch arch_kgdb_ops = {
4916 +const struct kgdb_arch arch_kgdb_ops = {
4917 /* Breakpoint instruction: ta 0x7d */
4918 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
4919 };
4920 diff --git a/arch/sparc/kernel/kgdb_64.c b/arch/sparc/kernel/kgdb_64.c
4921 index f5a0fd4..d886f71 100644
4922 --- a/arch/sparc/kernel/kgdb_64.c
4923 +++ b/arch/sparc/kernel/kgdb_64.c
4924 @@ -180,7 +180,7 @@ void kgdb_arch_exit(void)
4925 {
4926 }
4927
4928 -struct kgdb_arch arch_kgdb_ops = {
4929 +const struct kgdb_arch arch_kgdb_ops = {
4930 /* Breakpoint instruction: ta 0x72 */
4931 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
4932 };
4933 diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
4934 index 23c33ff..d137fbd 100644
4935 --- a/arch/sparc/kernel/pci_sun4v.c
4936 +++ b/arch/sparc/kernel/pci_sun4v.c
4937 @@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
4938 spin_unlock_irqrestore(&iommu->lock, flags);
4939 }
4940
4941 -static struct dma_map_ops sun4v_dma_ops = {
4942 +static const struct dma_map_ops sun4v_dma_ops = {
4943 .alloc_coherent = dma_4v_alloc_coherent,
4944 .free_coherent = dma_4v_free_coherent,
4945 .map_page = dma_4v_map_page,
4946 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
4947 index c49865b..b41a81b 100644
4948 --- a/arch/sparc/kernel/process_32.c
4949 +++ b/arch/sparc/kernel/process_32.c
4950 @@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4951 rw->ins[4], rw->ins[5],
4952 rw->ins[6],
4953 rw->ins[7]);
4954 - printk("%pS\n", (void *) rw->ins[7]);
4955 + printk("%pA\n", (void *) rw->ins[7]);
4956 rw = (struct reg_window32 *) rw->ins[6];
4957 }
4958 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4959 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4960
4961 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4962 r->psr, r->pc, r->npc, r->y, print_tainted());
4963 - printk("PC: <%pS>\n", (void *) r->pc);
4964 + printk("PC: <%pA>\n", (void *) r->pc);
4965 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4966 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4967 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4968 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4969 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4970 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4971 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4972 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4973
4974 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4975 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4976 @@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4977 rw = (struct reg_window32 *) fp;
4978 pc = rw->ins[7];
4979 printk("[%08lx : ", pc);
4980 - printk("%pS ] ", (void *) pc);
4981 + printk("%pA ] ", (void *) pc);
4982 fp = rw->ins[6];
4983 } while (++count < 16);
4984 printk("\n");
4985 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
4986 index cb70476..3d0c191 100644
4987 --- a/arch/sparc/kernel/process_64.c
4988 +++ b/arch/sparc/kernel/process_64.c
4989 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
4990 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4991 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4992 if (regs->tstate & TSTATE_PRIV)
4993 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4994 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4995 }
4996
4997 void show_regs(struct pt_regs *regs)
4998 {
4999 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5000 regs->tpc, regs->tnpc, regs->y, print_tainted());
5001 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5002 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5003 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5004 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5005 regs->u_regs[3]);
5006 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5007 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5008 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5009 regs->u_regs[15]);
5010 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5011 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5012 show_regwindow(regs);
5013 }
5014
5015 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5016 ((tp && tp->task) ? tp->task->pid : -1));
5017
5018 if (gp->tstate & TSTATE_PRIV) {
5019 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5020 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5021 (void *) gp->tpc,
5022 (void *) gp->o7,
5023 (void *) gp->i7,
5024 diff --git a/arch/sparc/kernel/sigutil_64.c b/arch/sparc/kernel/sigutil_64.c
5025 index 6edc4e5..06a69b4 100644
5026 --- a/arch/sparc/kernel/sigutil_64.c
5027 +++ b/arch/sparc/kernel/sigutil_64.c
5028 @@ -2,6 +2,7 @@
5029 #include <linux/types.h>
5030 #include <linux/thread_info.h>
5031 #include <linux/uaccess.h>
5032 +#include <linux/errno.h>
5033
5034 #include <asm/sigcontext.h>
5035 #include <asm/fpumacro.h>
5036 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5037 index 3a82e65..ce0a53a 100644
5038 --- a/arch/sparc/kernel/sys_sparc_32.c
5039 +++ b/arch/sparc/kernel/sys_sparc_32.c
5040 @@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5041 if (ARCH_SUN4C && len > 0x20000000)
5042 return -ENOMEM;
5043 if (!addr)
5044 - addr = TASK_UNMAPPED_BASE;
5045 + addr = current->mm->mmap_base;
5046
5047 if (flags & MAP_SHARED)
5048 addr = COLOUR_ALIGN(addr);
5049 @@ -72,7 +72,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5050 }
5051 if (TASK_SIZE - PAGE_SIZE - len < addr)
5052 return -ENOMEM;
5053 - if (!vmm || addr + len <= vmm->vm_start)
5054 + if (check_heap_stack_gap(vmm, addr, len))
5055 return addr;
5056 addr = vmm->vm_end;
5057 if (flags & MAP_SHARED)
5058 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5059 index cfa0e19..98972ac 100644
5060 --- a/arch/sparc/kernel/sys_sparc_64.c
5061 +++ b/arch/sparc/kernel/sys_sparc_64.c
5062 @@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5063 /* We do not accept a shared mapping if it would violate
5064 * cache aliasing constraints.
5065 */
5066 - if ((flags & MAP_SHARED) &&
5067 + if ((filp || (flags & MAP_SHARED)) &&
5068 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5069 return -EINVAL;
5070 return addr;
5071 @@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5072 if (filp || (flags & MAP_SHARED))
5073 do_color_align = 1;
5074
5075 +#ifdef CONFIG_PAX_RANDMMAP
5076 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5077 +#endif
5078 +
5079 if (addr) {
5080 if (do_color_align)
5081 addr = COLOUR_ALIGN(addr, pgoff);
5082 @@ -147,15 +151,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5083 addr = PAGE_ALIGN(addr);
5084
5085 vma = find_vma(mm, addr);
5086 - if (task_size - len >= addr &&
5087 - (!vma || addr + len <= vma->vm_start))
5088 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5089 return addr;
5090 }
5091
5092 if (len > mm->cached_hole_size) {
5093 - start_addr = addr = mm->free_area_cache;
5094 + start_addr = addr = mm->free_area_cache;
5095 } else {
5096 - start_addr = addr = TASK_UNMAPPED_BASE;
5097 + start_addr = addr = mm->mmap_base;
5098 mm->cached_hole_size = 0;
5099 }
5100
5101 @@ -175,14 +178,14 @@ full_search:
5102 vma = find_vma(mm, VA_EXCLUDE_END);
5103 }
5104 if (unlikely(task_size < addr)) {
5105 - if (start_addr != TASK_UNMAPPED_BASE) {
5106 - start_addr = addr = TASK_UNMAPPED_BASE;
5107 + if (start_addr != mm->mmap_base) {
5108 + start_addr = addr = mm->mmap_base;
5109 mm->cached_hole_size = 0;
5110 goto full_search;
5111 }
5112 return -ENOMEM;
5113 }
5114 - if (likely(!vma || addr + len <= vma->vm_start)) {
5115 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5116 /*
5117 * Remember the place where we stopped the search:
5118 */
5119 @@ -216,7 +219,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5120 /* We do not accept a shared mapping if it would violate
5121 * cache aliasing constraints.
5122 */
5123 - if ((flags & MAP_SHARED) &&
5124 + if ((filp || (flags & MAP_SHARED)) &&
5125 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5126 return -EINVAL;
5127 return addr;
5128 @@ -237,8 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5129 addr = PAGE_ALIGN(addr);
5130
5131 vma = find_vma(mm, addr);
5132 - if (task_size - len >= addr &&
5133 - (!vma || addr + len <= vma->vm_start))
5134 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5135 return addr;
5136 }
5137
5138 @@ -259,7 +261,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5139 /* make sure it can fit in the remaining address space */
5140 if (likely(addr > len)) {
5141 vma = find_vma(mm, addr-len);
5142 - if (!vma || addr <= vma->vm_start) {
5143 + if (check_heap_stack_gap(vma, addr - len, len)) {
5144 /* remember the address as a hint for next time */
5145 return (mm->free_area_cache = addr-len);
5146 }
5147 @@ -268,18 +270,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5148 if (unlikely(mm->mmap_base < len))
5149 goto bottomup;
5150
5151 - addr = mm->mmap_base-len;
5152 - if (do_color_align)
5153 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5154 + addr = mm->mmap_base - len;
5155
5156 do {
5157 + if (do_color_align)
5158 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5159 /*
5160 * Lookup failure means no vma is above this address,
5161 * else if new region fits below vma->vm_start,
5162 * return with success:
5163 */
5164 vma = find_vma(mm, addr);
5165 - if (likely(!vma || addr+len <= vma->vm_start)) {
5166 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5167 /* remember the address as a hint for next time */
5168 return (mm->free_area_cache = addr);
5169 }
5170 @@ -289,10 +291,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5171 mm->cached_hole_size = vma->vm_start - addr;
5172
5173 /* try just below the current vma->vm_start */
5174 - addr = vma->vm_start-len;
5175 - if (do_color_align)
5176 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5177 - } while (likely(len < vma->vm_start));
5178 + addr = skip_heap_stack_gap(vma, len);
5179 + } while (!IS_ERR_VALUE(addr));
5180
5181 bottomup:
5182 /*
5183 @@ -384,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5184 current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
5185 sysctl_legacy_va_layout) {
5186 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5187 +
5188 +#ifdef CONFIG_PAX_RANDMMAP
5189 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5190 + mm->mmap_base += mm->delta_mmap;
5191 +#endif
5192 +
5193 mm->get_unmapped_area = arch_get_unmapped_area;
5194 mm->unmap_area = arch_unmap_area;
5195 } else {
5196 @@ -398,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5197 gap = (task_size / 6 * 5);
5198
5199 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5200 +
5201 +#ifdef CONFIG_PAX_RANDMMAP
5202 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5203 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5204 +#endif
5205 +
5206 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5207 mm->unmap_area = arch_unmap_area_topdown;
5208 }
5209 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5210 index c0490c7..84959d1 100644
5211 --- a/arch/sparc/kernel/traps_32.c
5212 +++ b/arch/sparc/kernel/traps_32.c
5213 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
5214 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5215 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5216
5217 +extern void gr_handle_kernel_exploit(void);
5218 +
5219 void die_if_kernel(char *str, struct pt_regs *regs)
5220 {
5221 static int die_counter;
5222 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5223 count++ < 30 &&
5224 (((unsigned long) rw) >= PAGE_OFFSET) &&
5225 !(((unsigned long) rw) & 0x7)) {
5226 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5227 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5228 (void *) rw->ins[7]);
5229 rw = (struct reg_window32 *)rw->ins[6];
5230 }
5231 }
5232 printk("Instruction DUMP:");
5233 instruction_dump ((unsigned long *) regs->pc);
5234 - if(regs->psr & PSR_PS)
5235 + if(regs->psr & PSR_PS) {
5236 + gr_handle_kernel_exploit();
5237 do_exit(SIGKILL);
5238 + }
5239 do_exit(SIGSEGV);
5240 }
5241
5242 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5243 index 10f7bb9..cdb6793 100644
5244 --- a/arch/sparc/kernel/traps_64.c
5245 +++ b/arch/sparc/kernel/traps_64.c
5246 @@ -73,7 +73,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5247 i + 1,
5248 p->trapstack[i].tstate, p->trapstack[i].tpc,
5249 p->trapstack[i].tnpc, p->trapstack[i].tt);
5250 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5251 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5252 }
5253 }
5254
5255 @@ -93,6 +93,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5256
5257 lvl -= 0x100;
5258 if (regs->tstate & TSTATE_PRIV) {
5259 +
5260 +#ifdef CONFIG_PAX_REFCOUNT
5261 + if (lvl == 6)
5262 + pax_report_refcount_overflow(regs);
5263 +#endif
5264 +
5265 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5266 die_if_kernel(buffer, regs);
5267 }
5268 @@ -111,11 +117,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5269 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5270 {
5271 char buffer[32];
5272 -
5273 +
5274 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5275 0, lvl, SIGTRAP) == NOTIFY_STOP)
5276 return;
5277
5278 +#ifdef CONFIG_PAX_REFCOUNT
5279 + if (lvl == 6)
5280 + pax_report_refcount_overflow(regs);
5281 +#endif
5282 +
5283 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5284
5285 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5286 @@ -1139,7 +1150,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5287 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5288 printk("%s" "ERROR(%d): ",
5289 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5290 - printk("TPC<%pS>\n", (void *) regs->tpc);
5291 + printk("TPC<%pA>\n", (void *) regs->tpc);
5292 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5293 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5294 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5295 @@ -1746,7 +1757,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5296 smp_processor_id(),
5297 (type & 0x1) ? 'I' : 'D',
5298 regs->tpc);
5299 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5300 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5301 panic("Irrecoverable Cheetah+ parity error.");
5302 }
5303
5304 @@ -1754,7 +1765,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5305 smp_processor_id(),
5306 (type & 0x1) ? 'I' : 'D',
5307 regs->tpc);
5308 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5309 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5310 }
5311
5312 struct sun4v_error_entry {
5313 @@ -1961,9 +1972,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5314
5315 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5316 regs->tpc, tl);
5317 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5318 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5319 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5320 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5321 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5322 (void *) regs->u_regs[UREG_I7]);
5323 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5324 "pte[%lx] error[%lx]\n",
5325 @@ -1985,9 +1996,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5326
5327 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5328 regs->tpc, tl);
5329 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5330 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5331 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5332 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5333 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5334 (void *) regs->u_regs[UREG_I7]);
5335 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5336 "pte[%lx] error[%lx]\n",
5337 @@ -2191,7 +2202,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5338 fp = (unsigned long)sf->fp + STACK_BIAS;
5339 }
5340
5341 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5342 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5343 } while (++count < 16);
5344 }
5345
5346 @@ -2233,6 +2244,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5347 return (struct reg_window *) (fp + STACK_BIAS);
5348 }
5349
5350 +extern void gr_handle_kernel_exploit(void);
5351 +
5352 void die_if_kernel(char *str, struct pt_regs *regs)
5353 {
5354 static int die_counter;
5355 @@ -2260,7 +2273,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5356 while (rw &&
5357 count++ < 30&&
5358 is_kernel_stack(current, rw)) {
5359 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5360 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5361 (void *) rw->ins[7]);
5362
5363 rw = kernel_stack_up(rw);
5364 @@ -2273,8 +2286,11 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5365 }
5366 user_instruction_dump ((unsigned int __user *) regs->tpc);
5367 }
5368 - if (regs->tstate & TSTATE_PRIV)
5369 + if (regs->tstate & TSTATE_PRIV) {
5370 + gr_handle_kernel_exploit();
5371 do_exit(SIGKILL);
5372 + }
5373 +
5374 do_exit(SIGSEGV);
5375 }
5376 EXPORT_SYMBOL(die_if_kernel);
5377 diff --git a/arch/sparc/kernel/una_asm_64.S b/arch/sparc/kernel/una_asm_64.S
5378 index be183fe..1c8d332 100644
5379 --- a/arch/sparc/kernel/una_asm_64.S
5380 +++ b/arch/sparc/kernel/una_asm_64.S
5381 @@ -127,7 +127,7 @@ do_int_load:
5382 wr %o5, 0x0, %asi
5383 retl
5384 mov 0, %o0
5385 - .size __do_int_load, .-__do_int_load
5386 + .size do_int_load, .-do_int_load
5387
5388 .section __ex_table,"a"
5389 .word 4b, __retl_efault
5390 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5391 index 3792099..2af17d8 100644
5392 --- a/arch/sparc/kernel/unaligned_64.c
5393 +++ b/arch/sparc/kernel/unaligned_64.c
5394 @@ -288,7 +288,7 @@ static void log_unaligned(struct pt_regs *regs)
5395 if (count < 5) {
5396 last_time = jiffies;
5397 count++;
5398 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5399 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5400 regs->tpc, (void *) regs->tpc);
5401 }
5402 }
5403 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5404 index e75faf0..24f12f9 100644
5405 --- a/arch/sparc/lib/Makefile
5406 +++ b/arch/sparc/lib/Makefile
5407 @@ -2,7 +2,7 @@
5408 #
5409
5410 asflags-y := -ansi -DST_DIV0=0x02
5411 -ccflags-y := -Werror
5412 +#ccflags-y := -Werror
5413
5414 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5415 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5416 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5417 index 0268210..f0291ca 100644
5418 --- a/arch/sparc/lib/atomic_64.S
5419 +++ b/arch/sparc/lib/atomic_64.S
5420 @@ -18,7 +18,12 @@
5421 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5422 BACKOFF_SETUP(%o2)
5423 1: lduw [%o1], %g1
5424 - add %g1, %o0, %g7
5425 + addcc %g1, %o0, %g7
5426 +
5427 +#ifdef CONFIG_PAX_REFCOUNT
5428 + tvs %icc, 6
5429 +#endif
5430 +
5431 cas [%o1], %g1, %g7
5432 cmp %g1, %g7
5433 bne,pn %icc, 2f
5434 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5435 2: BACKOFF_SPIN(%o2, %o3, 1b)
5436 .size atomic_add, .-atomic_add
5437
5438 + .globl atomic_add_unchecked
5439 + .type atomic_add_unchecked,#function
5440 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5441 + BACKOFF_SETUP(%o2)
5442 +1: lduw [%o1], %g1
5443 + add %g1, %o0, %g7
5444 + cas [%o1], %g1, %g7
5445 + cmp %g1, %g7
5446 + bne,pn %icc, 2f
5447 + nop
5448 + retl
5449 + nop
5450 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5451 + .size atomic_add_unchecked, .-atomic_add_unchecked
5452 +
5453 .globl atomic_sub
5454 .type atomic_sub,#function
5455 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5456 BACKOFF_SETUP(%o2)
5457 1: lduw [%o1], %g1
5458 - sub %g1, %o0, %g7
5459 + subcc %g1, %o0, %g7
5460 +
5461 +#ifdef CONFIG_PAX_REFCOUNT
5462 + tvs %icc, 6
5463 +#endif
5464 +
5465 cas [%o1], %g1, %g7
5466 cmp %g1, %g7
5467 bne,pn %icc, 2f
5468 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5469 2: BACKOFF_SPIN(%o2, %o3, 1b)
5470 .size atomic_sub, .-atomic_sub
5471
5472 + .globl atomic_sub_unchecked
5473 + .type atomic_sub_unchecked,#function
5474 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5475 + BACKOFF_SETUP(%o2)
5476 +1: lduw [%o1], %g1
5477 + sub %g1, %o0, %g7
5478 + cas [%o1], %g1, %g7
5479 + cmp %g1, %g7
5480 + bne,pn %icc, 2f
5481 + nop
5482 + retl
5483 + nop
5484 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5485 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5486 +
5487 .globl atomic_add_ret
5488 .type atomic_add_ret,#function
5489 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5490 BACKOFF_SETUP(%o2)
5491 1: lduw [%o1], %g1
5492 - add %g1, %o0, %g7
5493 + addcc %g1, %o0, %g7
5494 +
5495 +#ifdef CONFIG_PAX_REFCOUNT
5496 + tvs %icc, 6
5497 +#endif
5498 +
5499 cas [%o1], %g1, %g7
5500 cmp %g1, %g7
5501 bne,pn %icc, 2f
5502 @@ -59,12 +104,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5503 2: BACKOFF_SPIN(%o2, %o3, 1b)
5504 .size atomic_add_ret, .-atomic_add_ret
5505
5506 + .globl atomic_add_ret_unchecked
5507 + .type atomic_add_ret_unchecked,#function
5508 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5509 + BACKOFF_SETUP(%o2)
5510 +1: lduw [%o1], %g1
5511 + addcc %g1, %o0, %g7
5512 + cas [%o1], %g1, %g7
5513 + cmp %g1, %g7
5514 + bne,pn %icc, 2f
5515 + add %g7, %o0, %g7
5516 + sra %g7, 0, %o0
5517 + retl
5518 + nop
5519 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5520 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5521 +
5522 .globl atomic_sub_ret
5523 .type atomic_sub_ret,#function
5524 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5525 BACKOFF_SETUP(%o2)
5526 1: lduw [%o1], %g1
5527 - sub %g1, %o0, %g7
5528 + subcc %g1, %o0, %g7
5529 +
5530 +#ifdef CONFIG_PAX_REFCOUNT
5531 + tvs %icc, 6
5532 +#endif
5533 +
5534 cas [%o1], %g1, %g7
5535 cmp %g1, %g7
5536 bne,pn %icc, 2f
5537 @@ -80,7 +146,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5538 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5539 BACKOFF_SETUP(%o2)
5540 1: ldx [%o1], %g1
5541 - add %g1, %o0, %g7
5542 + addcc %g1, %o0, %g7
5543 +
5544 +#ifdef CONFIG_PAX_REFCOUNT
5545 + tvs %xcc, 6
5546 +#endif
5547 +
5548 casx [%o1], %g1, %g7
5549 cmp %g1, %g7
5550 bne,pn %xcc, 2f
5551 @@ -90,12 +161,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5552 2: BACKOFF_SPIN(%o2, %o3, 1b)
5553 .size atomic64_add, .-atomic64_add
5554
5555 + .globl atomic64_add_unchecked
5556 + .type atomic64_add_unchecked,#function
5557 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5558 + BACKOFF_SETUP(%o2)
5559 +1: ldx [%o1], %g1
5560 + addcc %g1, %o0, %g7
5561 + casx [%o1], %g1, %g7
5562 + cmp %g1, %g7
5563 + bne,pn %xcc, 2f
5564 + nop
5565 + retl
5566 + nop
5567 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5568 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5569 +
5570 .globl atomic64_sub
5571 .type atomic64_sub,#function
5572 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5573 BACKOFF_SETUP(%o2)
5574 1: ldx [%o1], %g1
5575 - sub %g1, %o0, %g7
5576 + subcc %g1, %o0, %g7
5577 +
5578 +#ifdef CONFIG_PAX_REFCOUNT
5579 + tvs %xcc, 6
5580 +#endif
5581 +
5582 casx [%o1], %g1, %g7
5583 cmp %g1, %g7
5584 bne,pn %xcc, 2f
5585 @@ -105,12 +196,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5586 2: BACKOFF_SPIN(%o2, %o3, 1b)
5587 .size atomic64_sub, .-atomic64_sub
5588
5589 + .globl atomic64_sub_unchecked
5590 + .type atomic64_sub_unchecked,#function
5591 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5592 + BACKOFF_SETUP(%o2)
5593 +1: ldx [%o1], %g1
5594 + subcc %g1, %o0, %g7
5595 + casx [%o1], %g1, %g7
5596 + cmp %g1, %g7
5597 + bne,pn %xcc, 2f
5598 + nop
5599 + retl
5600 + nop
5601 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5602 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5603 +
5604 .globl atomic64_add_ret
5605 .type atomic64_add_ret,#function
5606 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5607 BACKOFF_SETUP(%o2)
5608 1: ldx [%o1], %g1
5609 - add %g1, %o0, %g7
5610 + addcc %g1, %o0, %g7
5611 +
5612 +#ifdef CONFIG_PAX_REFCOUNT
5613 + tvs %xcc, 6
5614 +#endif
5615 +
5616 casx [%o1], %g1, %g7
5617 cmp %g1, %g7
5618 bne,pn %xcc, 2f
5619 @@ -121,12 +232,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5620 2: BACKOFF_SPIN(%o2, %o3, 1b)
5621 .size atomic64_add_ret, .-atomic64_add_ret
5622
5623 + .globl atomic64_add_ret_unchecked
5624 + .type atomic64_add_ret_unchecked,#function
5625 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5626 + BACKOFF_SETUP(%o2)
5627 +1: ldx [%o1], %g1
5628 + addcc %g1, %o0, %g7
5629 + casx [%o1], %g1, %g7
5630 + cmp %g1, %g7
5631 + bne,pn %xcc, 2f
5632 + add %g7, %o0, %g7
5633 + mov %g7, %o0
5634 + retl
5635 + nop
5636 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5637 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5638 +
5639 .globl atomic64_sub_ret
5640 .type atomic64_sub_ret,#function
5641 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5642 BACKOFF_SETUP(%o2)
5643 1: ldx [%o1], %g1
5644 - sub %g1, %o0, %g7
5645 + subcc %g1, %o0, %g7
5646 +
5647 +#ifdef CONFIG_PAX_REFCOUNT
5648 + tvs %xcc, 6
5649 +#endif
5650 +
5651 casx [%o1], %g1, %g7
5652 cmp %g1, %g7
5653 bne,pn %xcc, 2f
5654 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5655 index 704b126..2e79d76 100644
5656 --- a/arch/sparc/lib/ksyms.c
5657 +++ b/arch/sparc/lib/ksyms.c
5658 @@ -144,12 +144,18 @@ EXPORT_SYMBOL(__downgrade_write);
5659
5660 /* Atomic counter implementation. */
5661 EXPORT_SYMBOL(atomic_add);
5662 +EXPORT_SYMBOL(atomic_add_unchecked);
5663 EXPORT_SYMBOL(atomic_add_ret);
5664 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5665 EXPORT_SYMBOL(atomic_sub);
5666 +EXPORT_SYMBOL(atomic_sub_unchecked);
5667 EXPORT_SYMBOL(atomic_sub_ret);
5668 EXPORT_SYMBOL(atomic64_add);
5669 +EXPORT_SYMBOL(atomic64_add_unchecked);
5670 EXPORT_SYMBOL(atomic64_add_ret);
5671 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5672 EXPORT_SYMBOL(atomic64_sub);
5673 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5674 EXPORT_SYMBOL(atomic64_sub_ret);
5675
5676 /* Atomic bit operations. */
5677 diff --git a/arch/sparc/lib/rwsem_64.S b/arch/sparc/lib/rwsem_64.S
5678 index 91a7d29..ce75c29 100644
5679 --- a/arch/sparc/lib/rwsem_64.S
5680 +++ b/arch/sparc/lib/rwsem_64.S
5681 @@ -11,7 +11,12 @@
5682 .globl __down_read
5683 __down_read:
5684 1: lduw [%o0], %g1
5685 - add %g1, 1, %g7
5686 + addcc %g1, 1, %g7
5687 +
5688 +#ifdef CONFIG_PAX_REFCOUNT
5689 + tvs %icc, 6
5690 +#endif
5691 +
5692 cas [%o0], %g1, %g7
5693 cmp %g1, %g7
5694 bne,pn %icc, 1b
5695 @@ -33,7 +38,12 @@ __down_read:
5696 .globl __down_read_trylock
5697 __down_read_trylock:
5698 1: lduw [%o0], %g1
5699 - add %g1, 1, %g7
5700 + addcc %g1, 1, %g7
5701 +
5702 +#ifdef CONFIG_PAX_REFCOUNT
5703 + tvs %icc, 6
5704 +#endif
5705 +
5706 cmp %g7, 0
5707 bl,pn %icc, 2f
5708 mov 0, %o1
5709 @@ -51,7 +61,12 @@ __down_write:
5710 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5711 1:
5712 lduw [%o0], %g3
5713 - add %g3, %g1, %g7
5714 + addcc %g3, %g1, %g7
5715 +
5716 +#ifdef CONFIG_PAX_REFCOUNT
5717 + tvs %icc, 6
5718 +#endif
5719 +
5720 cas [%o0], %g3, %g7
5721 cmp %g3, %g7
5722 bne,pn %icc, 1b
5723 @@ -77,7 +92,12 @@ __down_write_trylock:
5724 cmp %g3, 0
5725 bne,pn %icc, 2f
5726 mov 0, %o1
5727 - add %g3, %g1, %g7
5728 + addcc %g3, %g1, %g7
5729 +
5730 +#ifdef CONFIG_PAX_REFCOUNT
5731 + tvs %icc, 6
5732 +#endif
5733 +
5734 cas [%o0], %g3, %g7
5735 cmp %g3, %g7
5736 bne,pn %icc, 1b
5737 @@ -90,7 +110,12 @@ __down_write_trylock:
5738 __up_read:
5739 1:
5740 lduw [%o0], %g1
5741 - sub %g1, 1, %g7
5742 + subcc %g1, 1, %g7
5743 +
5744 +#ifdef CONFIG_PAX_REFCOUNT
5745 + tvs %icc, 6
5746 +#endif
5747 +
5748 cas [%o0], %g1, %g7
5749 cmp %g1, %g7
5750 bne,pn %icc, 1b
5751 @@ -118,7 +143,12 @@ __up_write:
5752 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5753 1:
5754 lduw [%o0], %g3
5755 - sub %g3, %g1, %g7
5756 + subcc %g3, %g1, %g7
5757 +
5758 +#ifdef CONFIG_PAX_REFCOUNT
5759 + tvs %icc, 6
5760 +#endif
5761 +
5762 cas [%o0], %g3, %g7
5763 cmp %g3, %g7
5764 bne,pn %icc, 1b
5765 @@ -143,7 +173,12 @@ __downgrade_write:
5766 or %g1, %lo(RWSEM_WAITING_BIAS), %g1
5767 1:
5768 lduw [%o0], %g3
5769 - sub %g3, %g1, %g7
5770 + subcc %g3, %g1, %g7
5771 +
5772 +#ifdef CONFIG_PAX_REFCOUNT
5773 + tvs %icc, 6
5774 +#endif
5775 +
5776 cas [%o0], %g3, %g7
5777 cmp %g3, %g7
5778 bne,pn %icc, 1b
5779 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5780 index 79836a7..62f47a2 100644
5781 --- a/arch/sparc/mm/Makefile
5782 +++ b/arch/sparc/mm/Makefile
5783 @@ -2,7 +2,7 @@
5784 #
5785
5786 asflags-y := -ansi
5787 -ccflags-y := -Werror
5788 +#ccflags-y := -Werror
5789
5790 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5791 obj-y += fault_$(BITS).o
5792 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5793 index b99f81c..3453e93 100644
5794 --- a/arch/sparc/mm/fault_32.c
5795 +++ b/arch/sparc/mm/fault_32.c
5796 @@ -21,6 +21,9 @@
5797 #include <linux/interrupt.h>
5798 #include <linux/module.h>
5799 #include <linux/kdebug.h>
5800 +#include <linux/slab.h>
5801 +#include <linux/pagemap.h>
5802 +#include <linux/compiler.h>
5803
5804 #include <asm/system.h>
5805 #include <asm/page.h>
5806 @@ -167,6 +170,267 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5807 return safe_compute_effective_address(regs, insn);
5808 }
5809
5810 +#ifdef CONFIG_PAX_PAGEEXEC
5811 +#ifdef CONFIG_PAX_DLRESOLVE
5812 +static void pax_emuplt_close(struct vm_area_struct *vma)
5813 +{
5814 + vma->vm_mm->call_dl_resolve = 0UL;
5815 +}
5816 +
5817 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5818 +{
5819 + unsigned int *kaddr;
5820 +
5821 + vmf->page = alloc_page(GFP_HIGHUSER);
5822 + if (!vmf->page)
5823 + return VM_FAULT_OOM;
5824 +
5825 + kaddr = kmap(vmf->page);
5826 + memset(kaddr, 0, PAGE_SIZE);
5827 + kaddr[0] = 0x9DE3BFA8U; /* save */
5828 + flush_dcache_page(vmf->page);
5829 + kunmap(vmf->page);
5830 + return VM_FAULT_MAJOR;
5831 +}
5832 +
5833 +static const struct vm_operations_struct pax_vm_ops = {
5834 + .close = pax_emuplt_close,
5835 + .fault = pax_emuplt_fault
5836 +};
5837 +
5838 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5839 +{
5840 + int ret;
5841 +
5842 + vma->vm_mm = current->mm;
5843 + vma->vm_start = addr;
5844 + vma->vm_end = addr + PAGE_SIZE;
5845 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5846 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5847 + vma->vm_ops = &pax_vm_ops;
5848 +
5849 + ret = insert_vm_struct(current->mm, vma);
5850 + if (ret)
5851 + return ret;
5852 +
5853 + ++current->mm->total_vm;
5854 + return 0;
5855 +}
5856 +#endif
5857 +
5858 +/*
5859 + * PaX: decide what to do with offenders (regs->pc = fault address)
5860 + *
5861 + * returns 1 when task should be killed
5862 + * 2 when patched PLT trampoline was detected
5863 + * 3 when unpatched PLT trampoline was detected
5864 + */
5865 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5866 +{
5867 +
5868 +#ifdef CONFIG_PAX_EMUPLT
5869 + int err;
5870 +
5871 + do { /* PaX: patched PLT emulation #1 */
5872 + unsigned int sethi1, sethi2, jmpl;
5873 +
5874 + err = get_user(sethi1, (unsigned int *)regs->pc);
5875 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5876 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5877 +
5878 + if (err)
5879 + break;
5880 +
5881 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5882 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5883 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5884 + {
5885 + unsigned int addr;
5886 +
5887 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5888 + addr = regs->u_regs[UREG_G1];
5889 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5890 + regs->pc = addr;
5891 + regs->npc = addr+4;
5892 + return 2;
5893 + }
5894 + } while (0);
5895 +
5896 + { /* PaX: patched PLT emulation #2 */
5897 + unsigned int ba;
5898 +
5899 + err = get_user(ba, (unsigned int *)regs->pc);
5900 +
5901 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5902 + unsigned int addr;
5903 +
5904 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5905 + regs->pc = addr;
5906 + regs->npc = addr+4;
5907 + return 2;
5908 + }
5909 + }
5910 +
5911 + do { /* PaX: patched PLT emulation #3 */
5912 + unsigned int sethi, jmpl, nop;
5913 +
5914 + err = get_user(sethi, (unsigned int *)regs->pc);
5915 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5916 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5917 +
5918 + if (err)
5919 + break;
5920 +
5921 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5922 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5923 + nop == 0x01000000U)
5924 + {
5925 + unsigned int addr;
5926 +
5927 + addr = (sethi & 0x003FFFFFU) << 10;
5928 + regs->u_regs[UREG_G1] = addr;
5929 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5930 + regs->pc = addr;
5931 + regs->npc = addr+4;
5932 + return 2;
5933 + }
5934 + } while (0);
5935 +
5936 + do { /* PaX: unpatched PLT emulation step 1 */
5937 + unsigned int sethi, ba, nop;
5938 +
5939 + err = get_user(sethi, (unsigned int *)regs->pc);
5940 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
5941 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5942 +
5943 + if (err)
5944 + break;
5945 +
5946 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5947 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5948 + nop == 0x01000000U)
5949 + {
5950 + unsigned int addr, save, call;
5951 +
5952 + if ((ba & 0xFFC00000U) == 0x30800000U)
5953 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5954 + else
5955 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5956 +
5957 + err = get_user(save, (unsigned int *)addr);
5958 + err |= get_user(call, (unsigned int *)(addr+4));
5959 + err |= get_user(nop, (unsigned int *)(addr+8));
5960 + if (err)
5961 + break;
5962 +
5963 +#ifdef CONFIG_PAX_DLRESOLVE
5964 + if (save == 0x9DE3BFA8U &&
5965 + (call & 0xC0000000U) == 0x40000000U &&
5966 + nop == 0x01000000U)
5967 + {
5968 + struct vm_area_struct *vma;
5969 + unsigned long call_dl_resolve;
5970 +
5971 + down_read(&current->mm->mmap_sem);
5972 + call_dl_resolve = current->mm->call_dl_resolve;
5973 + up_read(&current->mm->mmap_sem);
5974 + if (likely(call_dl_resolve))
5975 + goto emulate;
5976 +
5977 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5978 +
5979 + down_write(&current->mm->mmap_sem);
5980 + if (current->mm->call_dl_resolve) {
5981 + call_dl_resolve = current->mm->call_dl_resolve;
5982 + up_write(&current->mm->mmap_sem);
5983 + if (vma)
5984 + kmem_cache_free(vm_area_cachep, vma);
5985 + goto emulate;
5986 + }
5987 +
5988 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5989 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5990 + up_write(&current->mm->mmap_sem);
5991 + if (vma)
5992 + kmem_cache_free(vm_area_cachep, vma);
5993 + return 1;
5994 + }
5995 +
5996 + if (pax_insert_vma(vma, call_dl_resolve)) {
5997 + up_write(&current->mm->mmap_sem);
5998 + kmem_cache_free(vm_area_cachep, vma);
5999 + return 1;
6000 + }
6001 +
6002 + current->mm->call_dl_resolve = call_dl_resolve;
6003 + up_write(&current->mm->mmap_sem);
6004 +
6005 +emulate:
6006 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6007 + regs->pc = call_dl_resolve;
6008 + regs->npc = addr+4;
6009 + return 3;
6010 + }
6011 +#endif
6012 +
6013 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6014 + if ((save & 0xFFC00000U) == 0x05000000U &&
6015 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6016 + nop == 0x01000000U)
6017 + {
6018 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6019 + regs->u_regs[UREG_G2] = addr + 4;
6020 + addr = (save & 0x003FFFFFU) << 10;
6021 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6022 + regs->pc = addr;
6023 + regs->npc = addr+4;
6024 + return 3;
6025 + }
6026 + }
6027 + } while (0);
6028 +
6029 + do { /* PaX: unpatched PLT emulation step 2 */
6030 + unsigned int save, call, nop;
6031 +
6032 + err = get_user(save, (unsigned int *)(regs->pc-4));
6033 + err |= get_user(call, (unsigned int *)regs->pc);
6034 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6035 + if (err)
6036 + break;
6037 +
6038 + if (save == 0x9DE3BFA8U &&
6039 + (call & 0xC0000000U) == 0x40000000U &&
6040 + nop == 0x01000000U)
6041 + {
6042 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6043 +
6044 + regs->u_regs[UREG_RETPC] = regs->pc;
6045 + regs->pc = dl_resolve;
6046 + regs->npc = dl_resolve+4;
6047 + return 3;
6048 + }
6049 + } while (0);
6050 +#endif
6051 +
6052 + return 1;
6053 +}
6054 +
6055 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6056 +{
6057 + unsigned long i;
6058 +
6059 + printk(KERN_ERR "PAX: bytes at PC: ");
6060 + for (i = 0; i < 8; i++) {
6061 + unsigned int c;
6062 + if (get_user(c, (unsigned int *)pc+i))
6063 + printk(KERN_CONT "???????? ");
6064 + else
6065 + printk(KERN_CONT "%08x ", c);
6066 + }
6067 + printk("\n");
6068 +}
6069 +#endif
6070 +
6071 asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
6072 unsigned long address)
6073 {
6074 @@ -231,6 +495,24 @@ good_area:
6075 if(!(vma->vm_flags & VM_WRITE))
6076 goto bad_area;
6077 } else {
6078 +
6079 +#ifdef CONFIG_PAX_PAGEEXEC
6080 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6081 + up_read(&mm->mmap_sem);
6082 + switch (pax_handle_fetch_fault(regs)) {
6083 +
6084 +#ifdef CONFIG_PAX_EMUPLT
6085 + case 2:
6086 + case 3:
6087 + return;
6088 +#endif
6089 +
6090 + }
6091 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6092 + do_group_exit(SIGKILL);
6093 + }
6094 +#endif
6095 +
6096 /* Allow reads even for write-only mappings */
6097 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6098 goto bad_area;
6099 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6100 index 43b0da9..a0b78f9 100644
6101 --- a/arch/sparc/mm/fault_64.c
6102 +++ b/arch/sparc/mm/fault_64.c
6103 @@ -20,6 +20,9 @@
6104 #include <linux/kprobes.h>
6105 #include <linux/kdebug.h>
6106 #include <linux/percpu.h>
6107 +#include <linux/slab.h>
6108 +#include <linux/pagemap.h>
6109 +#include <linux/compiler.h>
6110
6111 #include <asm/page.h>
6112 #include <asm/pgtable.h>
6113 @@ -78,7 +81,7 @@ static void bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6114 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6115 regs->tpc);
6116 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6117 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6118 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6119 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6120 dump_stack();
6121 unhandled_fault(regs->tpc, current, regs);
6122 @@ -249,6 +252,456 @@ static void noinline bogus_32bit_fault_address(struct pt_regs *regs,
6123 show_regs(regs);
6124 }
6125
6126 +#ifdef CONFIG_PAX_PAGEEXEC
6127 +#ifdef CONFIG_PAX_DLRESOLVE
6128 +static void pax_emuplt_close(struct vm_area_struct *vma)
6129 +{
6130 + vma->vm_mm->call_dl_resolve = 0UL;
6131 +}
6132 +
6133 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6134 +{
6135 + unsigned int *kaddr;
6136 +
6137 + vmf->page = alloc_page(GFP_HIGHUSER);
6138 + if (!vmf->page)
6139 + return VM_FAULT_OOM;
6140 +
6141 + kaddr = kmap(vmf->page);
6142 + memset(kaddr, 0, PAGE_SIZE);
6143 + kaddr[0] = 0x9DE3BFA8U; /* save */
6144 + flush_dcache_page(vmf->page);
6145 + kunmap(vmf->page);
6146 + return VM_FAULT_MAJOR;
6147 +}
6148 +
6149 +static const struct vm_operations_struct pax_vm_ops = {
6150 + .close = pax_emuplt_close,
6151 + .fault = pax_emuplt_fault
6152 +};
6153 +
6154 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6155 +{
6156 + int ret;
6157 +
6158 + vma->vm_mm = current->mm;
6159 + vma->vm_start = addr;
6160 + vma->vm_end = addr + PAGE_SIZE;
6161 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6162 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6163 + vma->vm_ops = &pax_vm_ops;
6164 +
6165 + ret = insert_vm_struct(current->mm, vma);
6166 + if (ret)
6167 + return ret;
6168 +
6169 + ++current->mm->total_vm;
6170 + return 0;
6171 +}
6172 +#endif
6173 +
6174 +/*
6175 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6176 + *
6177 + * returns 1 when task should be killed
6178 + * 2 when patched PLT trampoline was detected
6179 + * 3 when unpatched PLT trampoline was detected
6180 + */
6181 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6182 +{
6183 +
6184 +#ifdef CONFIG_PAX_EMUPLT
6185 + int err;
6186 +
6187 + do { /* PaX: patched PLT emulation #1 */
6188 + unsigned int sethi1, sethi2, jmpl;
6189 +
6190 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6191 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6192 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6193 +
6194 + if (err)
6195 + break;
6196 +
6197 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6198 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6199 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6200 + {
6201 + unsigned long addr;
6202 +
6203 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6204 + addr = regs->u_regs[UREG_G1];
6205 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6206 +
6207 + if (test_thread_flag(TIF_32BIT))
6208 + addr &= 0xFFFFFFFFUL;
6209 +
6210 + regs->tpc = addr;
6211 + regs->tnpc = addr+4;
6212 + return 2;
6213 + }
6214 + } while (0);
6215 +
6216 + { /* PaX: patched PLT emulation #2 */
6217 + unsigned int ba;
6218 +
6219 + err = get_user(ba, (unsigned int *)regs->tpc);
6220 +
6221 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6222 + unsigned long addr;
6223 +
6224 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6225 +
6226 + if (test_thread_flag(TIF_32BIT))
6227 + addr &= 0xFFFFFFFFUL;
6228 +
6229 + regs->tpc = addr;
6230 + regs->tnpc = addr+4;
6231 + return 2;
6232 + }
6233 + }
6234 +
6235 + do { /* PaX: patched PLT emulation #3 */
6236 + unsigned int sethi, jmpl, nop;
6237 +
6238 + err = get_user(sethi, (unsigned int *)regs->tpc);
6239 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6240 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6241 +
6242 + if (err)
6243 + break;
6244 +
6245 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6246 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6247 + nop == 0x01000000U)
6248 + {
6249 + unsigned long addr;
6250 +
6251 + addr = (sethi & 0x003FFFFFU) << 10;
6252 + regs->u_regs[UREG_G1] = addr;
6253 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6254 +
6255 + if (test_thread_flag(TIF_32BIT))
6256 + addr &= 0xFFFFFFFFUL;
6257 +
6258 + regs->tpc = addr;
6259 + regs->tnpc = addr+4;
6260 + return 2;
6261 + }
6262 + } while (0);
6263 +
6264 + do { /* PaX: patched PLT emulation #4 */
6265 + unsigned int sethi, mov1, call, mov2;
6266 +
6267 + err = get_user(sethi, (unsigned int *)regs->tpc);
6268 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6269 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6270 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6271 +
6272 + if (err)
6273 + break;
6274 +
6275 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6276 + mov1 == 0x8210000FU &&
6277 + (call & 0xC0000000U) == 0x40000000U &&
6278 + mov2 == 0x9E100001U)
6279 + {
6280 + unsigned long addr;
6281 +
6282 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6283 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6284 +
6285 + if (test_thread_flag(TIF_32BIT))
6286 + addr &= 0xFFFFFFFFUL;
6287 +
6288 + regs->tpc = addr;
6289 + regs->tnpc = addr+4;
6290 + return 2;
6291 + }
6292 + } while (0);
6293 +
6294 + do { /* PaX: patched PLT emulation #5 */
6295 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6296 +
6297 + err = get_user(sethi, (unsigned int *)regs->tpc);
6298 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6299 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6300 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6301 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6302 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6303 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6304 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6305 +
6306 + if (err)
6307 + break;
6308 +
6309 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6310 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6311 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6312 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6313 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6314 + sllx == 0x83287020U &&
6315 + jmpl == 0x81C04005U &&
6316 + nop == 0x01000000U)
6317 + {
6318 + unsigned long addr;
6319 +
6320 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6321 + regs->u_regs[UREG_G1] <<= 32;
6322 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6323 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6324 + regs->tpc = addr;
6325 + regs->tnpc = addr+4;
6326 + return 2;
6327 + }
6328 + } while (0);
6329 +
6330 + do { /* PaX: patched PLT emulation #6 */
6331 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6332 +
6333 + err = get_user(sethi, (unsigned int *)regs->tpc);
6334 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6335 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6336 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6337 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6338 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6339 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6340 +
6341 + if (err)
6342 + break;
6343 +
6344 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6345 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6346 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6347 + sllx == 0x83287020U &&
6348 + (or & 0xFFFFE000U) == 0x8A116000U &&
6349 + jmpl == 0x81C04005U &&
6350 + nop == 0x01000000U)
6351 + {
6352 + unsigned long addr;
6353 +
6354 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6355 + regs->u_regs[UREG_G1] <<= 32;
6356 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6357 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6358 + regs->tpc = addr;
6359 + regs->tnpc = addr+4;
6360 + return 2;
6361 + }
6362 + } while (0);
6363 +
6364 + do { /* PaX: unpatched PLT emulation step 1 */
6365 + unsigned int sethi, ba, nop;
6366 +
6367 + err = get_user(sethi, (unsigned int *)regs->tpc);
6368 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6369 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6370 +
6371 + if (err)
6372 + break;
6373 +
6374 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6375 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6376 + nop == 0x01000000U)
6377 + {
6378 + unsigned long addr;
6379 + unsigned int save, call;
6380 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6381 +
6382 + if ((ba & 0xFFC00000U) == 0x30800000U)
6383 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6384 + else
6385 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6386 +
6387 + if (test_thread_flag(TIF_32BIT))
6388 + addr &= 0xFFFFFFFFUL;
6389 +
6390 + err = get_user(save, (unsigned int *)addr);
6391 + err |= get_user(call, (unsigned int *)(addr+4));
6392 + err |= get_user(nop, (unsigned int *)(addr+8));
6393 + if (err)
6394 + break;
6395 +
6396 +#ifdef CONFIG_PAX_DLRESOLVE
6397 + if (save == 0x9DE3BFA8U &&
6398 + (call & 0xC0000000U) == 0x40000000U &&
6399 + nop == 0x01000000U)
6400 + {
6401 + struct vm_area_struct *vma;
6402 + unsigned long call_dl_resolve;
6403 +
6404 + down_read(&current->mm->mmap_sem);
6405 + call_dl_resolve = current->mm->call_dl_resolve;
6406 + up_read(&current->mm->mmap_sem);
6407 + if (likely(call_dl_resolve))
6408 + goto emulate;
6409 +
6410 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6411 +
6412 + down_write(&current->mm->mmap_sem);
6413 + if (current->mm->call_dl_resolve) {
6414 + call_dl_resolve = current->mm->call_dl_resolve;
6415 + up_write(&current->mm->mmap_sem);
6416 + if (vma)
6417 + kmem_cache_free(vm_area_cachep, vma);
6418 + goto emulate;
6419 + }
6420 +
6421 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6422 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6423 + up_write(&current->mm->mmap_sem);
6424 + if (vma)
6425 + kmem_cache_free(vm_area_cachep, vma);
6426 + return 1;
6427 + }
6428 +
6429 + if (pax_insert_vma(vma, call_dl_resolve)) {
6430 + up_write(&current->mm->mmap_sem);
6431 + kmem_cache_free(vm_area_cachep, vma);
6432 + return 1;
6433 + }
6434 +
6435 + current->mm->call_dl_resolve = call_dl_resolve;
6436 + up_write(&current->mm->mmap_sem);
6437 +
6438 +emulate:
6439 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6440 + regs->tpc = call_dl_resolve;
6441 + regs->tnpc = addr+4;
6442 + return 3;
6443 + }
6444 +#endif
6445 +
6446 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6447 + if ((save & 0xFFC00000U) == 0x05000000U &&
6448 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6449 + nop == 0x01000000U)
6450 + {
6451 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6452 + regs->u_regs[UREG_G2] = addr + 4;
6453 + addr = (save & 0x003FFFFFU) << 10;
6454 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6455 +
6456 + if (test_thread_flag(TIF_32BIT))
6457 + addr &= 0xFFFFFFFFUL;
6458 +
6459 + regs->tpc = addr;
6460 + regs->tnpc = addr+4;
6461 + return 3;
6462 + }
6463 +
6464 + /* PaX: 64-bit PLT stub */
6465 + err = get_user(sethi1, (unsigned int *)addr);
6466 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6467 + err |= get_user(or1, (unsigned int *)(addr+8));
6468 + err |= get_user(or2, (unsigned int *)(addr+12));
6469 + err |= get_user(sllx, (unsigned int *)(addr+16));
6470 + err |= get_user(add, (unsigned int *)(addr+20));
6471 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6472 + err |= get_user(nop, (unsigned int *)(addr+28));
6473 + if (err)
6474 + break;
6475 +
6476 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6477 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6478 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6479 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6480 + sllx == 0x89293020U &&
6481 + add == 0x8A010005U &&
6482 + jmpl == 0x89C14000U &&
6483 + nop == 0x01000000U)
6484 + {
6485 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6486 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6487 + regs->u_regs[UREG_G4] <<= 32;
6488 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6489 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6490 + regs->u_regs[UREG_G4] = addr + 24;
6491 + addr = regs->u_regs[UREG_G5];
6492 + regs->tpc = addr;
6493 + regs->tnpc = addr+4;
6494 + return 3;
6495 + }
6496 + }
6497 + } while (0);
6498 +
6499 +#ifdef CONFIG_PAX_DLRESOLVE
6500 + do { /* PaX: unpatched PLT emulation step 2 */
6501 + unsigned int save, call, nop;
6502 +
6503 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6504 + err |= get_user(call, (unsigned int *)regs->tpc);
6505 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6506 + if (err)
6507 + break;
6508 +
6509 + if (save == 0x9DE3BFA8U &&
6510 + (call & 0xC0000000U) == 0x40000000U &&
6511 + nop == 0x01000000U)
6512 + {
6513 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6514 +
6515 + if (test_thread_flag(TIF_32BIT))
6516 + dl_resolve &= 0xFFFFFFFFUL;
6517 +
6518 + regs->u_regs[UREG_RETPC] = regs->tpc;
6519 + regs->tpc = dl_resolve;
6520 + regs->tnpc = dl_resolve+4;
6521 + return 3;
6522 + }
6523 + } while (0);
6524 +#endif
6525 +
6526 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6527 + unsigned int sethi, ba, nop;
6528 +
6529 + err = get_user(sethi, (unsigned int *)regs->tpc);
6530 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6531 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6532 +
6533 + if (err)
6534 + break;
6535 +
6536 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6537 + (ba & 0xFFF00000U) == 0x30600000U &&
6538 + nop == 0x01000000U)
6539 + {
6540 + unsigned long addr;
6541 +
6542 + addr = (sethi & 0x003FFFFFU) << 10;
6543 + regs->u_regs[UREG_G1] = addr;
6544 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6545 +
6546 + if (test_thread_flag(TIF_32BIT))
6547 + addr &= 0xFFFFFFFFUL;
6548 +
6549 + regs->tpc = addr;
6550 + regs->tnpc = addr+4;
6551 + return 2;
6552 + }
6553 + } while (0);
6554 +
6555 +#endif
6556 +
6557 + return 1;
6558 +}
6559 +
6560 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6561 +{
6562 + unsigned long i;
6563 +
6564 + printk(KERN_ERR "PAX: bytes at PC: ");
6565 + for (i = 0; i < 8; i++) {
6566 + unsigned int c;
6567 + if (get_user(c, (unsigned int *)pc+i))
6568 + printk(KERN_CONT "???????? ");
6569 + else
6570 + printk(KERN_CONT "%08x ", c);
6571 + }
6572 + printk("\n");
6573 +}
6574 +#endif
6575 +
6576 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6577 {
6578 struct mm_struct *mm = current->mm;
6579 @@ -315,6 +768,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6580 if (!vma)
6581 goto bad_area;
6582
6583 +#ifdef CONFIG_PAX_PAGEEXEC
6584 + /* PaX: detect ITLB misses on non-exec pages */
6585 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6586 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6587 + {
6588 + if (address != regs->tpc)
6589 + goto good_area;
6590 +
6591 + up_read(&mm->mmap_sem);
6592 + switch (pax_handle_fetch_fault(regs)) {
6593 +
6594 +#ifdef CONFIG_PAX_EMUPLT
6595 + case 2:
6596 + case 3:
6597 + return;
6598 +#endif
6599 +
6600 + }
6601 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6602 + do_group_exit(SIGKILL);
6603 + }
6604 +#endif
6605 +
6606 /* Pure DTLB misses do not tell us whether the fault causing
6607 * load/store/atomic was a write or not, it only says that there
6608 * was no match. So in such a case we (carefully) read the
6609 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6610 index f27d103..1b06377 100644
6611 --- a/arch/sparc/mm/hugetlbpage.c
6612 +++ b/arch/sparc/mm/hugetlbpage.c
6613 @@ -69,7 +69,7 @@ full_search:
6614 }
6615 return -ENOMEM;
6616 }
6617 - if (likely(!vma || addr + len <= vma->vm_start)) {
6618 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6619 /*
6620 * Remember the place where we stopped the search:
6621 */
6622 @@ -108,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6623 /* make sure it can fit in the remaining address space */
6624 if (likely(addr > len)) {
6625 vma = find_vma(mm, addr-len);
6626 - if (!vma || addr <= vma->vm_start) {
6627 + if (check_heap_stack_gap(vma, addr - len, len)) {
6628 /* remember the address as a hint for next time */
6629 return (mm->free_area_cache = addr-len);
6630 }
6631 @@ -117,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6632 if (unlikely(mm->mmap_base < len))
6633 goto bottomup;
6634
6635 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6636 + addr = mm->mmap_base - len;
6637
6638 do {
6639 + addr &= HPAGE_MASK;
6640 /*
6641 * Lookup failure means no vma is above this address,
6642 * else if new region fits below vma->vm_start,
6643 * return with success:
6644 */
6645 vma = find_vma(mm, addr);
6646 - if (likely(!vma || addr+len <= vma->vm_start)) {
6647 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6648 /* remember the address as a hint for next time */
6649 return (mm->free_area_cache = addr);
6650 }
6651 @@ -136,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6652 mm->cached_hole_size = vma->vm_start - addr;
6653
6654 /* try just below the current vma->vm_start */
6655 - addr = (vma->vm_start-len) & HPAGE_MASK;
6656 - } while (likely(len < vma->vm_start));
6657 + addr = skip_heap_stack_gap(vma, len);
6658 + } while (!IS_ERR_VALUE(addr));
6659
6660 bottomup:
6661 /*
6662 @@ -183,8 +184,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6663 if (addr) {
6664 addr = ALIGN(addr, HPAGE_SIZE);
6665 vma = find_vma(mm, addr);
6666 - if (task_size - len >= addr &&
6667 - (!vma || addr + len <= vma->vm_start))
6668 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6669 return addr;
6670 }
6671 if (mm->get_unmapped_area == arch_get_unmapped_area)
6672 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6673 index dc7c3b1..34c0070 100644
6674 --- a/arch/sparc/mm/init_32.c
6675 +++ b/arch/sparc/mm/init_32.c
6676 @@ -317,6 +317,9 @@ extern void device_scan(void);
6677 pgprot_t PAGE_SHARED __read_mostly;
6678 EXPORT_SYMBOL(PAGE_SHARED);
6679
6680 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6681 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6682 +
6683 void __init paging_init(void)
6684 {
6685 switch(sparc_cpu_model) {
6686 @@ -345,17 +348,17 @@ void __init paging_init(void)
6687
6688 /* Initialize the protection map with non-constant, MMU dependent values. */
6689 protection_map[0] = PAGE_NONE;
6690 - protection_map[1] = PAGE_READONLY;
6691 - protection_map[2] = PAGE_COPY;
6692 - protection_map[3] = PAGE_COPY;
6693 + protection_map[1] = PAGE_READONLY_NOEXEC;
6694 + protection_map[2] = PAGE_COPY_NOEXEC;
6695 + protection_map[3] = PAGE_COPY_NOEXEC;
6696 protection_map[4] = PAGE_READONLY;
6697 protection_map[5] = PAGE_READONLY;
6698 protection_map[6] = PAGE_COPY;
6699 protection_map[7] = PAGE_COPY;
6700 protection_map[8] = PAGE_NONE;
6701 - protection_map[9] = PAGE_READONLY;
6702 - protection_map[10] = PAGE_SHARED;
6703 - protection_map[11] = PAGE_SHARED;
6704 + protection_map[9] = PAGE_READONLY_NOEXEC;
6705 + protection_map[10] = PAGE_SHARED_NOEXEC;
6706 + protection_map[11] = PAGE_SHARED_NOEXEC;
6707 protection_map[12] = PAGE_READONLY;
6708 protection_map[13] = PAGE_READONLY;
6709 protection_map[14] = PAGE_SHARED;
6710 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6711 index 509b1ff..bfd7118 100644
6712 --- a/arch/sparc/mm/srmmu.c
6713 +++ b/arch/sparc/mm/srmmu.c
6714 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6715 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6716 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6717 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6718 +
6719 +#ifdef CONFIG_PAX_PAGEEXEC
6720 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6721 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6722 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6723 +#endif
6724 +
6725 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6726 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6727
6728 diff --git a/arch/um/Makefile b/arch/um/Makefile
6729 index fc633db..5e1a1c2 100644
6730 --- a/arch/um/Makefile
6731 +++ b/arch/um/Makefile
6732 @@ -49,6 +49,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6733 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6734 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64
6735
6736 +ifdef CONSTIFY_PLUGIN
6737 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6738 +endif
6739 +
6740 include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
6741
6742 #This will adjust *FLAGS accordingly to the platform.
6743 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6744 index 6c03acd..a5e0215 100644
6745 --- a/arch/um/include/asm/kmap_types.h
6746 +++ b/arch/um/include/asm/kmap_types.h
6747 @@ -23,6 +23,7 @@ enum km_type {
6748 KM_IRQ1,
6749 KM_SOFTIRQ0,
6750 KM_SOFTIRQ1,
6751 + KM_CLEARPAGE,
6752 KM_TYPE_NR
6753 };
6754
6755 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6756 index 4cc9b6c..02e5029 100644
6757 --- a/arch/um/include/asm/page.h
6758 +++ b/arch/um/include/asm/page.h
6759 @@ -14,6 +14,9 @@
6760 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6761 #define PAGE_MASK (~(PAGE_SIZE-1))
6762
6763 +#define ktla_ktva(addr) (addr)
6764 +#define ktva_ktla(addr) (addr)
6765 +
6766 #ifndef __ASSEMBLY__
6767
6768 struct page;
6769 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6770 index 4a28a15..654dc2a 100644
6771 --- a/arch/um/kernel/process.c
6772 +++ b/arch/um/kernel/process.c
6773 @@ -393,22 +393,6 @@ int singlestepping(void * t)
6774 return 2;
6775 }
6776
6777 -/*
6778 - * Only x86 and x86_64 have an arch_align_stack().
6779 - * All other arches have "#define arch_align_stack(x) (x)"
6780 - * in their asm/system.h
6781 - * As this is included in UML from asm-um/system-generic.h,
6782 - * we can use it to behave as the subarch does.
6783 - */
6784 -#ifndef arch_align_stack
6785 -unsigned long arch_align_stack(unsigned long sp)
6786 -{
6787 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6788 - sp -= get_random_int() % 8192;
6789 - return sp & ~0xf;
6790 -}
6791 -#endif
6792 -
6793 unsigned long get_wchan(struct task_struct *p)
6794 {
6795 unsigned long stack_page, sp, ip;
6796 diff --git a/arch/um/sys-i386/shared/sysdep/system.h b/arch/um/sys-i386/shared/sysdep/system.h
6797 index d1b93c4..ae1b7fd 100644
6798 --- a/arch/um/sys-i386/shared/sysdep/system.h
6799 +++ b/arch/um/sys-i386/shared/sysdep/system.h
6800 @@ -17,7 +17,7 @@
6801 # define AT_VECTOR_SIZE_ARCH 1
6802 #endif
6803
6804 -extern unsigned long arch_align_stack(unsigned long sp);
6805 +#define arch_align_stack(x) ((x) & ~0xfUL)
6806
6807 void default_idle(void);
6808
6809 diff --git a/arch/um/sys-i386/syscalls.c b/arch/um/sys-i386/syscalls.c
6810 index 857ca0b..9a2669d 100644
6811 --- a/arch/um/sys-i386/syscalls.c
6812 +++ b/arch/um/sys-i386/syscalls.c
6813 @@ -11,6 +11,21 @@
6814 #include "asm/uaccess.h"
6815 #include "asm/unistd.h"
6816
6817 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6818 +{
6819 + unsigned long pax_task_size = TASK_SIZE;
6820 +
6821 +#ifdef CONFIG_PAX_SEGMEXEC
6822 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6823 + pax_task_size = SEGMEXEC_TASK_SIZE;
6824 +#endif
6825 +
6826 + if (len > pax_task_size || addr > pax_task_size - len)
6827 + return -EINVAL;
6828 +
6829 + return 0;
6830 +}
6831 +
6832 /*
6833 * Perform the select(nd, in, out, ex, tv) and mmap() system
6834 * calls. Linux/i386 didn't use to be able to handle more than
6835 diff --git a/arch/um/sys-x86_64/shared/sysdep/system.h b/arch/um/sys-x86_64/shared/sysdep/system.h
6836 index d1b93c4..ae1b7fd 100644
6837 --- a/arch/um/sys-x86_64/shared/sysdep/system.h
6838 +++ b/arch/um/sys-x86_64/shared/sysdep/system.h
6839 @@ -17,7 +17,7 @@
6840 # define AT_VECTOR_SIZE_ARCH 1
6841 #endif
6842
6843 -extern unsigned long arch_align_stack(unsigned long sp);
6844 +#define arch_align_stack(x) ((x) & ~0xfUL)
6845
6846 void default_idle(void);
6847
6848 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
6849 index 73ae02a..f932de5 100644
6850 --- a/arch/x86/Kconfig
6851 +++ b/arch/x86/Kconfig
6852 @@ -223,7 +223,7 @@ config X86_TRAMPOLINE
6853
6854 config X86_32_LAZY_GS
6855 def_bool y
6856 - depends on X86_32 && !CC_STACKPROTECTOR
6857 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
6858
6859 config KTIME_SCALAR
6860 def_bool X86_32
6861 @@ -1008,7 +1008,7 @@ choice
6862
6863 config NOHIGHMEM
6864 bool "off"
6865 - depends on !X86_NUMAQ
6866 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6867 ---help---
6868 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
6869 However, the address space of 32-bit x86 processors is only 4
6870 @@ -1045,7 +1045,7 @@ config NOHIGHMEM
6871
6872 config HIGHMEM4G
6873 bool "4GB"
6874 - depends on !X86_NUMAQ
6875 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6876 ---help---
6877 Select this if you have a 32-bit processor and between 1 and 4
6878 gigabytes of physical RAM.
6879 @@ -1099,7 +1099,7 @@ config PAGE_OFFSET
6880 hex
6881 default 0xB0000000 if VMSPLIT_3G_OPT
6882 default 0x80000000 if VMSPLIT_2G
6883 - default 0x78000000 if VMSPLIT_2G_OPT
6884 + default 0x70000000 if VMSPLIT_2G_OPT
6885 default 0x40000000 if VMSPLIT_1G
6886 default 0xC0000000
6887 depends on X86_32
6888 @@ -1460,6 +1460,7 @@ config SECCOMP
6889
6890 config CC_STACKPROTECTOR
6891 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
6892 + depends on X86_64 || !PAX_MEMORY_UDEREF
6893 ---help---
6894 This option turns on the -fstack-protector GCC feature. This
6895 feature puts, at the beginning of functions, a canary value on
6896 @@ -1517,6 +1518,7 @@ config KEXEC_JUMP
6897 config PHYSICAL_START
6898 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
6899 default "0x1000000"
6900 + range 0x400000 0x40000000
6901 ---help---
6902 This gives the physical address where the kernel is loaded.
6903
6904 @@ -1581,6 +1583,7 @@ config PHYSICAL_ALIGN
6905 hex
6906 prompt "Alignment value to which kernel should be aligned" if X86_32
6907 default "0x1000000"
6908 + range 0x400000 0x1000000 if PAX_KERNEXEC
6909 range 0x2000 0x1000000
6910 ---help---
6911 This value puts the alignment restrictions on physical address
6912 @@ -1612,9 +1615,10 @@ config HOTPLUG_CPU
6913 Say N if you want to disable CPU hotplug.
6914
6915 config COMPAT_VDSO
6916 - def_bool y
6917 + def_bool n
6918 prompt "Compat VDSO support"
6919 depends on X86_32 || IA32_EMULATION
6920 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
6921 ---help---
6922 Map the 32-bit VDSO to the predictable old-style address too.
6923 ---help---
6924 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
6925 index 0e566103..1a6b57e 100644
6926 --- a/arch/x86/Kconfig.cpu
6927 +++ b/arch/x86/Kconfig.cpu
6928 @@ -340,7 +340,7 @@ config X86_PPRO_FENCE
6929
6930 config X86_F00F_BUG
6931 def_bool y
6932 - depends on M586MMX || M586TSC || M586 || M486 || M386
6933 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
6934
6935 config X86_WP_WORKS_OK
6936 def_bool y
6937 @@ -360,7 +360,7 @@ config X86_POPAD_OK
6938
6939 config X86_ALIGNMENT_16
6940 def_bool y
6941 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6942 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6943
6944 config X86_INTEL_USERCOPY
6945 def_bool y
6946 @@ -406,7 +406,7 @@ config X86_CMPXCHG64
6947 # generates cmov.
6948 config X86_CMOV
6949 def_bool y
6950 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
6951 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
6952
6953 config X86_MINIMUM_CPU_FAMILY
6954 int
6955 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
6956 index d105f29..c928727 100644
6957 --- a/arch/x86/Kconfig.debug
6958 +++ b/arch/x86/Kconfig.debug
6959 @@ -99,7 +99,7 @@ config X86_PTDUMP
6960 config DEBUG_RODATA
6961 bool "Write protect kernel read-only data structures"
6962 default y
6963 - depends on DEBUG_KERNEL
6964 + depends on DEBUG_KERNEL && BROKEN
6965 ---help---
6966 Mark the kernel read-only data as write-protected in the pagetables,
6967 in order to catch accidental (and incorrect) writes to such const
6968 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
6969 index d2d24c9..0f21f8d 100644
6970 --- a/arch/x86/Makefile
6971 +++ b/arch/x86/Makefile
6972 @@ -44,6 +44,7 @@ ifeq ($(CONFIG_X86_32),y)
6973 else
6974 BITS := 64
6975 UTS_MACHINE := x86_64
6976 + biarch := $(call cc-option,-m64)
6977 CHECKFLAGS += -D__x86_64__ -m64
6978
6979 KBUILD_AFLAGS += -m64
6980 @@ -189,3 +190,12 @@ define archhelp
6981 echo ' FDARGS="..." arguments for the booted kernel'
6982 echo ' FDINITRD=file initrd for the booted kernel'
6983 endef
6984 +
6985 +define OLD_LD
6986 +
6987 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
6988 +*** Please upgrade your binutils to 2.18 or newer
6989 +endef
6990 +
6991 +archprepare:
6992 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
6993 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
6994 index ec749c2..bbb5319 100644
6995 --- a/arch/x86/boot/Makefile
6996 +++ b/arch/x86/boot/Makefile
6997 @@ -69,6 +69,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
6998 $(call cc-option, -fno-stack-protector) \
6999 $(call cc-option, -mpreferred-stack-boundary=2)
7000 KBUILD_CFLAGS += $(call cc-option, -m32)
7001 +ifdef CONSTIFY_PLUGIN
7002 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7003 +endif
7004 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7005 GCOV_PROFILE := n
7006
7007 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7008 index 878e4b9..20537ab 100644
7009 --- a/arch/x86/boot/bitops.h
7010 +++ b/arch/x86/boot/bitops.h
7011 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7012 u8 v;
7013 const u32 *p = (const u32 *)addr;
7014
7015 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7016 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7017 return v;
7018 }
7019
7020 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7021
7022 static inline void set_bit(int nr, void *addr)
7023 {
7024 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7025 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7026 }
7027
7028 #endif /* BOOT_BITOPS_H */
7029 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7030 index 98239d2..f40214c 100644
7031 --- a/arch/x86/boot/boot.h
7032 +++ b/arch/x86/boot/boot.h
7033 @@ -82,7 +82,7 @@ static inline void io_delay(void)
7034 static inline u16 ds(void)
7035 {
7036 u16 seg;
7037 - asm("movw %%ds,%0" : "=rm" (seg));
7038 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7039 return seg;
7040 }
7041
7042 @@ -178,7 +178,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7043 static inline int memcmp(const void *s1, const void *s2, size_t len)
7044 {
7045 u8 diff;
7046 - asm("repe; cmpsb; setnz %0"
7047 + asm volatile("repe; cmpsb; setnz %0"
7048 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7049 return diff;
7050 }
7051 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7052 index f8ed065..5bf5ff3 100644
7053 --- a/arch/x86/boot/compressed/Makefile
7054 +++ b/arch/x86/boot/compressed/Makefile
7055 @@ -13,6 +13,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7056 KBUILD_CFLAGS += $(cflags-y)
7057 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7058 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7059 +ifdef CONSTIFY_PLUGIN
7060 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7061 +endif
7062
7063 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7064 GCOV_PROFILE := n
7065 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7066 index f543b70..b60fba8 100644
7067 --- a/arch/x86/boot/compressed/head_32.S
7068 +++ b/arch/x86/boot/compressed/head_32.S
7069 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7070 notl %eax
7071 andl %eax, %ebx
7072 #else
7073 - movl $LOAD_PHYSICAL_ADDR, %ebx
7074 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7075 #endif
7076
7077 /* Target address to relocate to for decompression */
7078 @@ -149,7 +149,7 @@ relocated:
7079 * and where it was actually loaded.
7080 */
7081 movl %ebp, %ebx
7082 - subl $LOAD_PHYSICAL_ADDR, %ebx
7083 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7084 jz 2f /* Nothing to be done if loaded at compiled addr. */
7085 /*
7086 * Process relocations.
7087 @@ -157,8 +157,7 @@ relocated:
7088
7089 1: subl $4, %edi
7090 movl (%edi), %ecx
7091 - testl %ecx, %ecx
7092 - jz 2f
7093 + jecxz 2f
7094 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7095 jmp 1b
7096 2:
7097 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7098 index 077e1b6..2c6b13b 100644
7099 --- a/arch/x86/boot/compressed/head_64.S
7100 +++ b/arch/x86/boot/compressed/head_64.S
7101 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7102 notl %eax
7103 andl %eax, %ebx
7104 #else
7105 - movl $LOAD_PHYSICAL_ADDR, %ebx
7106 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7107 #endif
7108
7109 /* Target address to relocate to for decompression */
7110 @@ -183,7 +183,7 @@ no_longmode:
7111 hlt
7112 jmp 1b
7113
7114 -#include "../../kernel/verify_cpu_64.S"
7115 +#include "../../kernel/verify_cpu.S"
7116
7117 /*
7118 * Be careful here startup_64 needs to be at a predictable
7119 @@ -234,7 +234,7 @@ ENTRY(startup_64)
7120 notq %rax
7121 andq %rax, %rbp
7122 #else
7123 - movq $LOAD_PHYSICAL_ADDR, %rbp
7124 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7125 #endif
7126
7127 /* Target address to relocate to for decompression */
7128 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7129 index 842b2a3..f00178b 100644
7130 --- a/arch/x86/boot/compressed/misc.c
7131 +++ b/arch/x86/boot/compressed/misc.c
7132 @@ -288,7 +288,7 @@ static void parse_elf(void *output)
7133 case PT_LOAD:
7134 #ifdef CONFIG_RELOCATABLE
7135 dest = output;
7136 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7137 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7138 #else
7139 dest = (void *)(phdr->p_paddr);
7140 #endif
7141 @@ -335,7 +335,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7142 error("Destination address too large");
7143 #endif
7144 #ifndef CONFIG_RELOCATABLE
7145 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7146 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7147 error("Wrong destination address");
7148 #endif
7149
7150 diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
7151 index bcbd36c..b1754af 100644
7152 --- a/arch/x86/boot/compressed/mkpiggy.c
7153 +++ b/arch/x86/boot/compressed/mkpiggy.c
7154 @@ -74,7 +74,7 @@ int main(int argc, char *argv[])
7155
7156 offs = (olen > ilen) ? olen - ilen : 0;
7157 offs += olen >> 12; /* Add 8 bytes for each 32K block */
7158 - offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
7159 + offs += 64*1024; /* Add 64K bytes slack */
7160 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
7161
7162 printf(".section \".rodata.compressed\",\"a\",@progbits\n");
7163 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7164 index bbeb0c3..f5167ab 100644
7165 --- a/arch/x86/boot/compressed/relocs.c
7166 +++ b/arch/x86/boot/compressed/relocs.c
7167 @@ -10,8 +10,11 @@
7168 #define USE_BSD
7169 #include <endian.h>
7170
7171 +#include "../../../../include/linux/autoconf.h"
7172 +
7173 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7174 static Elf32_Ehdr ehdr;
7175 +static Elf32_Phdr *phdr;
7176 static unsigned long reloc_count, reloc_idx;
7177 static unsigned long *relocs;
7178
7179 @@ -37,7 +40,7 @@ static const char* safe_abs_relocs[] = {
7180
7181 static int is_safe_abs_reloc(const char* sym_name)
7182 {
7183 - int i;
7184 + unsigned int i;
7185
7186 for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
7187 if (!strcmp(sym_name, safe_abs_relocs[i]))
7188 @@ -245,9 +248,39 @@ static void read_ehdr(FILE *fp)
7189 }
7190 }
7191
7192 +static void read_phdrs(FILE *fp)
7193 +{
7194 + unsigned int i;
7195 +
7196 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7197 + if (!phdr) {
7198 + die("Unable to allocate %d program headers\n",
7199 + ehdr.e_phnum);
7200 + }
7201 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7202 + die("Seek to %d failed: %s\n",
7203 + ehdr.e_phoff, strerror(errno));
7204 + }
7205 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7206 + die("Cannot read ELF program headers: %s\n",
7207 + strerror(errno));
7208 + }
7209 + for(i = 0; i < ehdr.e_phnum; i++) {
7210 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7211 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7212 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7213 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7214 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7215 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7216 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7217 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7218 + }
7219 +
7220 +}
7221 +
7222 static void read_shdrs(FILE *fp)
7223 {
7224 - int i;
7225 + unsigned int i;
7226 Elf32_Shdr shdr;
7227
7228 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7229 @@ -282,7 +315,7 @@ static void read_shdrs(FILE *fp)
7230
7231 static void read_strtabs(FILE *fp)
7232 {
7233 - int i;
7234 + unsigned int i;
7235 for (i = 0; i < ehdr.e_shnum; i++) {
7236 struct section *sec = &secs[i];
7237 if (sec->shdr.sh_type != SHT_STRTAB) {
7238 @@ -307,7 +340,7 @@ static void read_strtabs(FILE *fp)
7239
7240 static void read_symtabs(FILE *fp)
7241 {
7242 - int i,j;
7243 + unsigned int i,j;
7244 for (i = 0; i < ehdr.e_shnum; i++) {
7245 struct section *sec = &secs[i];
7246 if (sec->shdr.sh_type != SHT_SYMTAB) {
7247 @@ -340,7 +373,9 @@ static void read_symtabs(FILE *fp)
7248
7249 static void read_relocs(FILE *fp)
7250 {
7251 - int i,j;
7252 + unsigned int i,j;
7253 + uint32_t base;
7254 +
7255 for (i = 0; i < ehdr.e_shnum; i++) {
7256 struct section *sec = &secs[i];
7257 if (sec->shdr.sh_type != SHT_REL) {
7258 @@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
7259 die("Cannot read symbol table: %s\n",
7260 strerror(errno));
7261 }
7262 + base = 0;
7263 + for (j = 0; j < ehdr.e_phnum; j++) {
7264 + if (phdr[j].p_type != PT_LOAD )
7265 + continue;
7266 + 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)
7267 + continue;
7268 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7269 + break;
7270 + }
7271 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7272 Elf32_Rel *rel = &sec->reltab[j];
7273 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7274 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7275 rel->r_info = elf32_to_cpu(rel->r_info);
7276 }
7277 }
7278 @@ -371,14 +415,14 @@ static void read_relocs(FILE *fp)
7279
7280 static void print_absolute_symbols(void)
7281 {
7282 - int i;
7283 + unsigned int i;
7284 printf("Absolute symbols\n");
7285 printf(" Num: Value Size Type Bind Visibility Name\n");
7286 for (i = 0; i < ehdr.e_shnum; i++) {
7287 struct section *sec = &secs[i];
7288 char *sym_strtab;
7289 Elf32_Sym *sh_symtab;
7290 - int j;
7291 + unsigned int j;
7292
7293 if (sec->shdr.sh_type != SHT_SYMTAB) {
7294 continue;
7295 @@ -406,14 +450,14 @@ static void print_absolute_symbols(void)
7296
7297 static void print_absolute_relocs(void)
7298 {
7299 - int i, printed = 0;
7300 + unsigned int i, printed = 0;
7301
7302 for (i = 0; i < ehdr.e_shnum; i++) {
7303 struct section *sec = &secs[i];
7304 struct section *sec_applies, *sec_symtab;
7305 char *sym_strtab;
7306 Elf32_Sym *sh_symtab;
7307 - int j;
7308 + unsigned int j;
7309 if (sec->shdr.sh_type != SHT_REL) {
7310 continue;
7311 }
7312 @@ -474,13 +518,13 @@ static void print_absolute_relocs(void)
7313
7314 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7315 {
7316 - int i;
7317 + unsigned int i;
7318 /* Walk through the relocations */
7319 for (i = 0; i < ehdr.e_shnum; i++) {
7320 char *sym_strtab;
7321 Elf32_Sym *sh_symtab;
7322 struct section *sec_applies, *sec_symtab;
7323 - int j;
7324 + unsigned int j;
7325 struct section *sec = &secs[i];
7326
7327 if (sec->shdr.sh_type != SHT_REL) {
7328 @@ -504,6 +548,21 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7329 if (sym->st_shndx == SHN_ABS) {
7330 continue;
7331 }
7332 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7333 + if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7334 + continue;
7335 +
7336 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7337 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7338 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7339 + continue;
7340 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7341 + continue;
7342 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7343 + continue;
7344 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7345 + continue;
7346 +#endif
7347 if (r_type == R_386_NONE || r_type == R_386_PC32) {
7348 /*
7349 * NONE can be ignored and and PC relative
7350 @@ -541,7 +600,7 @@ static int cmp_relocs(const void *va, const void *vb)
7351
7352 static void emit_relocs(int as_text)
7353 {
7354 - int i;
7355 + unsigned int i;
7356 /* Count how many relocations I have and allocate space for them. */
7357 reloc_count = 0;
7358 walk_relocs(count_reloc);
7359 @@ -634,6 +693,7 @@ int main(int argc, char **argv)
7360 fname, strerror(errno));
7361 }
7362 read_ehdr(fp);
7363 + read_phdrs(fp);
7364 read_shdrs(fp);
7365 read_strtabs(fp);
7366 read_symtabs(fp);
7367 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7368 index 4d3ff03..e4972ff 100644
7369 --- a/arch/x86/boot/cpucheck.c
7370 +++ b/arch/x86/boot/cpucheck.c
7371 @@ -74,7 +74,7 @@ static int has_fpu(void)
7372 u16 fcw = -1, fsw = -1;
7373 u32 cr0;
7374
7375 - asm("movl %%cr0,%0" : "=r" (cr0));
7376 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7377 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7378 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7379 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7380 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7381 {
7382 u32 f0, f1;
7383
7384 - asm("pushfl ; "
7385 + asm volatile("pushfl ; "
7386 "pushfl ; "
7387 "popl %0 ; "
7388 "movl %0,%1 ; "
7389 @@ -115,7 +115,7 @@ static void get_flags(void)
7390 set_bit(X86_FEATURE_FPU, cpu.flags);
7391
7392 if (has_eflag(X86_EFLAGS_ID)) {
7393 - asm("cpuid"
7394 + asm volatile("cpuid"
7395 : "=a" (max_intel_level),
7396 "=b" (cpu_vendor[0]),
7397 "=d" (cpu_vendor[1]),
7398 @@ -124,7 +124,7 @@ static void get_flags(void)
7399
7400 if (max_intel_level >= 0x00000001 &&
7401 max_intel_level <= 0x0000ffff) {
7402 - asm("cpuid"
7403 + asm volatile("cpuid"
7404 : "=a" (tfms),
7405 "=c" (cpu.flags[4]),
7406 "=d" (cpu.flags[0])
7407 @@ -136,7 +136,7 @@ static void get_flags(void)
7408 cpu.model += ((tfms >> 16) & 0xf) << 4;
7409 }
7410
7411 - asm("cpuid"
7412 + asm volatile("cpuid"
7413 : "=a" (max_amd_level)
7414 : "a" (0x80000000)
7415 : "ebx", "ecx", "edx");
7416 @@ -144,7 +144,7 @@ static void get_flags(void)
7417 if (max_amd_level >= 0x80000001 &&
7418 max_amd_level <= 0x8000ffff) {
7419 u32 eax = 0x80000001;
7420 - asm("cpuid"
7421 + asm volatile("cpuid"
7422 : "+a" (eax),
7423 "=c" (cpu.flags[6]),
7424 "=d" (cpu.flags[1])
7425 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7426 u32 ecx = MSR_K7_HWCR;
7427 u32 eax, edx;
7428
7429 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7430 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7431 eax &= ~(1 << 15);
7432 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7433 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7434
7435 get_flags(); /* Make sure it really did something */
7436 err = check_flags();
7437 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7438 u32 ecx = MSR_VIA_FCR;
7439 u32 eax, edx;
7440
7441 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7442 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7443 eax |= (1<<1)|(1<<7);
7444 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7445 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7446
7447 set_bit(X86_FEATURE_CX8, cpu.flags);
7448 err = check_flags();
7449 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7450 u32 eax, edx;
7451 u32 level = 1;
7452
7453 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7454 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7455 - asm("cpuid"
7456 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7457 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7458 + asm volatile("cpuid"
7459 : "+a" (level), "=d" (cpu.flags[0])
7460 : : "ecx", "ebx");
7461 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7462 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7463
7464 err = check_flags();
7465 }
7466 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7467 index b31cc54..8d69237 100644
7468 --- a/arch/x86/boot/header.S
7469 +++ b/arch/x86/boot/header.S
7470 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7471 # single linked list of
7472 # struct setup_data
7473
7474 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7475 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7476
7477 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7478 #define VO_INIT_SIZE (VO__end - VO__text)
7479 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7480 index cae3feb..ff8ff2a 100644
7481 --- a/arch/x86/boot/memory.c
7482 +++ b/arch/x86/boot/memory.c
7483 @@ -19,7 +19,7 @@
7484
7485 static int detect_memory_e820(void)
7486 {
7487 - int count = 0;
7488 + unsigned int count = 0;
7489 struct biosregs ireg, oreg;
7490 struct e820entry *desc = boot_params.e820_map;
7491 static struct e820entry buf; /* static so it is zeroed */
7492 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7493 index 11e8c6e..fdbb1ed 100644
7494 --- a/arch/x86/boot/video-vesa.c
7495 +++ b/arch/x86/boot/video-vesa.c
7496 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7497
7498 boot_params.screen_info.vesapm_seg = oreg.es;
7499 boot_params.screen_info.vesapm_off = oreg.di;
7500 + boot_params.screen_info.vesapm_size = oreg.cx;
7501 }
7502
7503 /*
7504 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7505 index d42da38..787cdf3 100644
7506 --- a/arch/x86/boot/video.c
7507 +++ b/arch/x86/boot/video.c
7508 @@ -90,7 +90,7 @@ static void store_mode_params(void)
7509 static unsigned int get_entry(void)
7510 {
7511 char entry_buf[4];
7512 - int i, len = 0;
7513 + unsigned int i, len = 0;
7514 int key;
7515 unsigned int v;
7516
7517 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7518 index 5b577d5..3c1fed4 100644
7519 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7520 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7521 @@ -8,6 +8,8 @@
7522 * including this sentence is retained in full.
7523 */
7524
7525 +#include <asm/alternative-asm.h>
7526 +
7527 .extern crypto_ft_tab
7528 .extern crypto_it_tab
7529 .extern crypto_fl_tab
7530 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7531 je B192; \
7532 leaq 32(r9),r9;
7533
7534 +#define ret pax_force_retaddr 0, 1; ret
7535 +
7536 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7537 movq r1,r2; \
7538 movq r3,r4; \
7539 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7540 index eb0566e..e3ebad8 100644
7541 --- a/arch/x86/crypto/aesni-intel_asm.S
7542 +++ b/arch/x86/crypto/aesni-intel_asm.S
7543 @@ -16,6 +16,7 @@
7544 */
7545
7546 #include <linux/linkage.h>
7547 +#include <asm/alternative-asm.h>
7548
7549 .text
7550
7551 @@ -52,6 +53,7 @@ _key_expansion_256a:
7552 pxor %xmm1, %xmm0
7553 movaps %xmm0, (%rcx)
7554 add $0x10, %rcx
7555 + pax_force_retaddr_bts
7556 ret
7557
7558 _key_expansion_192a:
7559 @@ -75,6 +77,7 @@ _key_expansion_192a:
7560 shufps $0b01001110, %xmm2, %xmm1
7561 movaps %xmm1, 16(%rcx)
7562 add $0x20, %rcx
7563 + pax_force_retaddr_bts
7564 ret
7565
7566 _key_expansion_192b:
7567 @@ -93,6 +96,7 @@ _key_expansion_192b:
7568
7569 movaps %xmm0, (%rcx)
7570 add $0x10, %rcx
7571 + pax_force_retaddr_bts
7572 ret
7573
7574 _key_expansion_256b:
7575 @@ -104,6 +108,7 @@ _key_expansion_256b:
7576 pxor %xmm1, %xmm2
7577 movaps %xmm2, (%rcx)
7578 add $0x10, %rcx
7579 + pax_force_retaddr_bts
7580 ret
7581
7582 /*
7583 @@ -239,7 +244,9 @@ ENTRY(aesni_set_key)
7584 cmp %rcx, %rdi
7585 jb .Ldec_key_loop
7586 xor %rax, %rax
7587 + pax_force_retaddr 0, 1
7588 ret
7589 +ENDPROC(aesni_set_key)
7590
7591 /*
7592 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7593 @@ -249,7 +256,9 @@ ENTRY(aesni_enc)
7594 movups (INP), STATE # input
7595 call _aesni_enc1
7596 movups STATE, (OUTP) # output
7597 + pax_force_retaddr 0, 1
7598 ret
7599 +ENDPROC(aesni_enc)
7600
7601 /*
7602 * _aesni_enc1: internal ABI
7603 @@ -319,6 +328,7 @@ _aesni_enc1:
7604 movaps 0x70(TKEYP), KEY
7605 # aesenclast KEY, STATE # last round
7606 .byte 0x66, 0x0f, 0x38, 0xdd, 0xc2
7607 + pax_force_retaddr_bts
7608 ret
7609
7610 /*
7611 @@ -482,6 +492,7 @@ _aesni_enc4:
7612 .byte 0x66, 0x0f, 0x38, 0xdd, 0xea
7613 # aesenclast KEY, STATE4
7614 .byte 0x66, 0x0f, 0x38, 0xdd, 0xf2
7615 + pax_force_retaddr_bts
7616 ret
7617
7618 /*
7619 @@ -493,7 +504,9 @@ ENTRY(aesni_dec)
7620 movups (INP), STATE # input
7621 call _aesni_dec1
7622 movups STATE, (OUTP) #output
7623 + pax_force_retaddr 0, 1
7624 ret
7625 +ENDPROC(aesni_dec)
7626
7627 /*
7628 * _aesni_dec1: internal ABI
7629 @@ -563,6 +576,7 @@ _aesni_dec1:
7630 movaps 0x70(TKEYP), KEY
7631 # aesdeclast KEY, STATE # last round
7632 .byte 0x66, 0x0f, 0x38, 0xdf, 0xc2
7633 + pax_force_retaddr_bts
7634 ret
7635
7636 /*
7637 @@ -726,6 +740,7 @@ _aesni_dec4:
7638 .byte 0x66, 0x0f, 0x38, 0xdf, 0xea
7639 # aesdeclast KEY, STATE4
7640 .byte 0x66, 0x0f, 0x38, 0xdf, 0xf2
7641 + pax_force_retaddr_bts
7642 ret
7643
7644 /*
7645 @@ -769,7 +784,9 @@ ENTRY(aesni_ecb_enc)
7646 cmp $16, LEN
7647 jge .Lecb_enc_loop1
7648 .Lecb_enc_ret:
7649 + pax_force_retaddr 0, 1
7650 ret
7651 +ENDPROC(aesni_ecb_enc)
7652
7653 /*
7654 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7655 @@ -813,7 +830,9 @@ ENTRY(aesni_ecb_dec)
7656 cmp $16, LEN
7657 jge .Lecb_dec_loop1
7658 .Lecb_dec_ret:
7659 + pax_force_retaddr 0, 1
7660 ret
7661 +ENDPROC(aesni_ecb_dec)
7662
7663 /*
7664 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7665 @@ -837,7 +856,9 @@ ENTRY(aesni_cbc_enc)
7666 jge .Lcbc_enc_loop
7667 movups STATE, (IVP)
7668 .Lcbc_enc_ret:
7669 + pax_force_retaddr 0, 1
7670 ret
7671 +ENDPROC(aesni_cbc_enc)
7672
7673 /*
7674 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7675 @@ -894,4 +915,6 @@ ENTRY(aesni_cbc_dec)
7676 .Lcbc_dec_ret:
7677 movups IV, (IVP)
7678 .Lcbc_dec_just_ret:
7679 + pax_force_retaddr 0, 1
7680 ret
7681 +ENDPROC(aesni_cbc_dec)
7682 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7683 index 6214a9b..1f4fc9a 100644
7684 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7685 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7686 @@ -1,3 +1,5 @@
7687 +#include <asm/alternative-asm.h>
7688 +
7689 # enter ECRYPT_encrypt_bytes
7690 .text
7691 .p2align 5
7692 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7693 add %r11,%rsp
7694 mov %rdi,%rax
7695 mov %rsi,%rdx
7696 + pax_force_retaddr 0, 1
7697 ret
7698 # bytesatleast65:
7699 ._bytesatleast65:
7700 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7701 add %r11,%rsp
7702 mov %rdi,%rax
7703 mov %rsi,%rdx
7704 + pax_force_retaddr
7705 ret
7706 # enter ECRYPT_ivsetup
7707 .text
7708 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7709 add %r11,%rsp
7710 mov %rdi,%rax
7711 mov %rsi,%rdx
7712 + pax_force_retaddr
7713 ret
7714 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
7715 index 35974a5..5662ae2 100644
7716 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
7717 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
7718 @@ -21,6 +21,7 @@
7719 .text
7720
7721 #include <asm/asm-offsets.h>
7722 +#include <asm/alternative-asm.h>
7723
7724 #define a_offset 0
7725 #define b_offset 4
7726 @@ -269,6 +270,7 @@ twofish_enc_blk:
7727
7728 popq R1
7729 movq $1,%rax
7730 + pax_force_retaddr 0, 1
7731 ret
7732
7733 twofish_dec_blk:
7734 @@ -321,4 +323,5 @@ twofish_dec_blk:
7735
7736 popq R1
7737 movq $1,%rax
7738 + pax_force_retaddr 0, 1
7739 ret
7740 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
7741 index 14531ab..a89a0c0 100644
7742 --- a/arch/x86/ia32/ia32_aout.c
7743 +++ b/arch/x86/ia32/ia32_aout.c
7744 @@ -169,6 +169,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
7745 unsigned long dump_start, dump_size;
7746 struct user32 dump;
7747
7748 + memset(&dump, 0, sizeof(dump));
7749 +
7750 fs = get_fs();
7751 set_fs(KERNEL_DS);
7752 has_dumped = 1;
7753 @@ -218,12 +220,6 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
7754 dump_size = dump.u_ssize << PAGE_SHIFT;
7755 DUMP_WRITE(dump_start, dump_size);
7756 }
7757 - /*
7758 - * Finally dump the task struct. Not be used by gdb, but
7759 - * could be useful
7760 - */
7761 - set_fs(KERNEL_DS);
7762 - DUMP_WRITE(current, sizeof(*current));
7763 end_coredump:
7764 set_fs(fs);
7765 return has_dumped;
7766 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
7767 index 588a7aa..a3468b0 100644
7768 --- a/arch/x86/ia32/ia32_signal.c
7769 +++ b/arch/x86/ia32/ia32_signal.c
7770 @@ -167,7 +167,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
7771 }
7772 seg = get_fs();
7773 set_fs(KERNEL_DS);
7774 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
7775 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
7776 set_fs(seg);
7777 if (ret >= 0 && uoss_ptr) {
7778 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
7779 @@ -374,7 +374,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
7780 */
7781 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7782 size_t frame_size,
7783 - void **fpstate)
7784 + void __user **fpstate)
7785 {
7786 unsigned long sp;
7787
7788 @@ -395,7 +395,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7789
7790 if (used_math()) {
7791 sp = sp - sig_xstate_ia32_size;
7792 - *fpstate = (struct _fpstate_ia32 *) sp;
7793 + *fpstate = (struct _fpstate_ia32 __user *) sp;
7794 if (save_i387_xstate_ia32(*fpstate) < 0)
7795 return (void __user *) -1L;
7796 }
7797 @@ -403,7 +403,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7798 sp -= frame_size;
7799 /* Align the stack pointer according to the i386 ABI,
7800 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
7801 - sp = ((sp + 4) & -16ul) - 4;
7802 + sp = ((sp - 12) & -16ul) - 4;
7803 return (void __user *) sp;
7804 }
7805
7806 @@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
7807 * These are actually not used anymore, but left because some
7808 * gdb versions depend on them as a marker.
7809 */
7810 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7811 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7812 } put_user_catch(err);
7813
7814 if (err)
7815 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
7816 0xb8,
7817 __NR_ia32_rt_sigreturn,
7818 0x80cd,
7819 - 0,
7820 + 0
7821 };
7822
7823 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
7824 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
7825
7826 if (ka->sa.sa_flags & SA_RESTORER)
7827 restorer = ka->sa.sa_restorer;
7828 + else if (current->mm->context.vdso)
7829 + /* Return stub is in 32bit vsyscall page */
7830 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
7831 else
7832 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
7833 - rt_sigreturn);
7834 + restorer = &frame->retcode;
7835 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
7836
7837 /*
7838 * Not actually used anymore, but left because some gdb
7839 * versions need it.
7840 */
7841 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7842 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7843 } put_user_catch(err);
7844
7845 if (err)
7846 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
7847 index 4edd8eb..07ac7fd 100644
7848 --- a/arch/x86/ia32/ia32entry.S
7849 +++ b/arch/x86/ia32/ia32entry.S
7850 @@ -13,7 +13,9 @@
7851 #include <asm/thread_info.h>
7852 #include <asm/segment.h>
7853 #include <asm/irqflags.h>
7854 +#include <asm/pgtable.h>
7855 #include <linux/linkage.h>
7856 +#include <asm/alternative-asm.h>
7857
7858 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7859 #include <linux/elf-em.h>
7860 @@ -93,6 +95,30 @@ ENTRY(native_irq_enable_sysexit)
7861 ENDPROC(native_irq_enable_sysexit)
7862 #endif
7863
7864 + .macro pax_enter_kernel_user
7865 + pax_set_fptr_mask
7866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7867 + call pax_enter_kernel_user
7868 +#endif
7869 + .endm
7870 +
7871 + .macro pax_exit_kernel_user
7872 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7873 + call pax_exit_kernel_user
7874 +#endif
7875 +#ifdef CONFIG_PAX_RANDKSTACK
7876 + pushq %rax
7877 + call pax_randomize_kstack
7878 + popq %rax
7879 +#endif
7880 + .endm
7881 +
7882 +.macro pax_erase_kstack
7883 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7884 + call pax_erase_kstack
7885 +#endif
7886 +.endm
7887 +
7888 /*
7889 * 32bit SYSENTER instruction entry.
7890 *
7891 @@ -119,12 +145,6 @@ ENTRY(ia32_sysenter_target)
7892 CFI_REGISTER rsp,rbp
7893 SWAPGS_UNSAFE_STACK
7894 movq PER_CPU_VAR(kernel_stack), %rsp
7895 - addq $(KERNEL_STACK_OFFSET),%rsp
7896 - /*
7897 - * No need to follow this irqs on/off section: the syscall
7898 - * disabled irqs, here we enable it straight after entry:
7899 - */
7900 - ENABLE_INTERRUPTS(CLBR_NONE)
7901 movl %ebp,%ebp /* zero extension */
7902 pushq $__USER32_DS
7903 CFI_ADJUST_CFA_OFFSET 8
7904 @@ -135,28 +155,41 @@ ENTRY(ia32_sysenter_target)
7905 pushfq
7906 CFI_ADJUST_CFA_OFFSET 8
7907 /*CFI_REL_OFFSET rflags,0*/
7908 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
7909 - CFI_REGISTER rip,r10
7910 + GET_THREAD_INFO(%r11)
7911 + movl TI_sysenter_return(%r11), %r11d
7912 + CFI_REGISTER rip,r11
7913 pushq $__USER32_CS
7914 CFI_ADJUST_CFA_OFFSET 8
7915 /*CFI_REL_OFFSET cs,0*/
7916 movl %eax, %eax
7917 - pushq %r10
7918 + pushq %r11
7919 CFI_ADJUST_CFA_OFFSET 8
7920 CFI_REL_OFFSET rip,0
7921 pushq %rax
7922 CFI_ADJUST_CFA_OFFSET 8
7923 cld
7924 SAVE_ARGS 0,0,1
7925 + pax_enter_kernel_user
7926 + /*
7927 + * No need to follow this irqs on/off section: the syscall
7928 + * disabled irqs, here we enable it straight after entry:
7929 + */
7930 + ENABLE_INTERRUPTS(CLBR_NONE)
7931 /* no need to do an access_ok check here because rbp has been
7932 32bit zero extended */
7933 +
7934 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7935 + mov $PAX_USER_SHADOW_BASE,%r11
7936 + add %r11,%rbp
7937 +#endif
7938 +
7939 1: movl (%rbp),%ebp
7940 .section __ex_table,"a"
7941 .quad 1b,ia32_badarg
7942 .previous
7943 - GET_THREAD_INFO(%r10)
7944 - orl $TS_COMPAT,TI_status(%r10)
7945 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7946 + GET_THREAD_INFO(%r11)
7947 + orl $TS_COMPAT,TI_status(%r11)
7948 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7949 CFI_REMEMBER_STATE
7950 jnz sysenter_tracesys
7951 cmpq $(IA32_NR_syscalls-1),%rax
7952 @@ -166,13 +199,15 @@ sysenter_do_call:
7953 sysenter_dispatch:
7954 call *ia32_sys_call_table(,%rax,8)
7955 movq %rax,RAX-ARGOFFSET(%rsp)
7956 - GET_THREAD_INFO(%r10)
7957 + GET_THREAD_INFO(%r11)
7958 DISABLE_INTERRUPTS(CLBR_NONE)
7959 TRACE_IRQS_OFF
7960 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7961 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
7962 jnz sysexit_audit
7963 sysexit_from_sys_call:
7964 - andl $~TS_COMPAT,TI_status(%r10)
7965 + pax_exit_kernel_user
7966 + pax_erase_kstack
7967 + andl $~TS_COMPAT,TI_status(%r11)
7968 /* clear IF, that popfq doesn't enable interrupts early */
7969 andl $~0x200,EFLAGS-R11(%rsp)
7970 movl RIP-R11(%rsp),%edx /* User %eip */
7971 @@ -200,6 +235,9 @@ sysexit_from_sys_call:
7972 movl %eax,%esi /* 2nd arg: syscall number */
7973 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
7974 call audit_syscall_entry
7975 +
7976 + pax_erase_kstack
7977 +
7978 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
7979 cmpq $(IA32_NR_syscalls-1),%rax
7980 ja ia32_badsys
7981 @@ -211,7 +249,7 @@ sysexit_from_sys_call:
7982 .endm
7983
7984 .macro auditsys_exit exit
7985 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7986 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7987 jnz ia32_ret_from_sys_call
7988 TRACE_IRQS_ON
7989 sti
7990 @@ -221,12 +259,12 @@ sysexit_from_sys_call:
7991 movzbl %al,%edi /* zero-extend that into %edi */
7992 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
7993 call audit_syscall_exit
7994 - GET_THREAD_INFO(%r10)
7995 + GET_THREAD_INFO(%r11)
7996 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
7997 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
7998 cli
7999 TRACE_IRQS_OFF
8000 - testl %edi,TI_flags(%r10)
8001 + testl %edi,TI_flags(%r11)
8002 jz \exit
8003 CLEAR_RREGS -ARGOFFSET
8004 jmp int_with_check
8005 @@ -244,7 +282,7 @@ sysexit_audit:
8006
8007 sysenter_tracesys:
8008 #ifdef CONFIG_AUDITSYSCALL
8009 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8010 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8011 jz sysenter_auditsys
8012 #endif
8013 SAVE_REST
8014 @@ -252,6 +290,9 @@ sysenter_tracesys:
8015 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8016 movq %rsp,%rdi /* &pt_regs -> arg1 */
8017 call syscall_trace_enter
8018 +
8019 + pax_erase_kstack
8020 +
8021 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8022 RESTORE_REST
8023 cmpq $(IA32_NR_syscalls-1),%rax
8024 @@ -283,19 +324,20 @@ ENDPROC(ia32_sysenter_target)
8025 ENTRY(ia32_cstar_target)
8026 CFI_STARTPROC32 simple
8027 CFI_SIGNAL_FRAME
8028 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8029 + CFI_DEF_CFA rsp,0
8030 CFI_REGISTER rip,rcx
8031 /*CFI_REGISTER rflags,r11*/
8032 SWAPGS_UNSAFE_STACK
8033 movl %esp,%r8d
8034 CFI_REGISTER rsp,r8
8035 movq PER_CPU_VAR(kernel_stack),%rsp
8036 + SAVE_ARGS 8*6,1,1
8037 + pax_enter_kernel_user
8038 /*
8039 * No need to follow this irqs on/off section: the syscall
8040 * disabled irqs and here we enable it straight after entry:
8041 */
8042 ENABLE_INTERRUPTS(CLBR_NONE)
8043 - SAVE_ARGS 8,1,1
8044 movl %eax,%eax /* zero extension */
8045 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8046 movq %rcx,RIP-ARGOFFSET(%rsp)
8047 @@ -311,13 +353,19 @@ ENTRY(ia32_cstar_target)
8048 /* no need to do an access_ok check here because r8 has been
8049 32bit zero extended */
8050 /* hardware stack frame is complete now */
8051 +
8052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8053 + mov $PAX_USER_SHADOW_BASE,%r11
8054 + add %r11,%r8
8055 +#endif
8056 +
8057 1: movl (%r8),%r9d
8058 .section __ex_table,"a"
8059 .quad 1b,ia32_badarg
8060 .previous
8061 - GET_THREAD_INFO(%r10)
8062 - orl $TS_COMPAT,TI_status(%r10)
8063 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8064 + GET_THREAD_INFO(%r11)
8065 + orl $TS_COMPAT,TI_status(%r11)
8066 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8067 CFI_REMEMBER_STATE
8068 jnz cstar_tracesys
8069 cmpq $IA32_NR_syscalls-1,%rax
8070 @@ -327,13 +375,15 @@ cstar_do_call:
8071 cstar_dispatch:
8072 call *ia32_sys_call_table(,%rax,8)
8073 movq %rax,RAX-ARGOFFSET(%rsp)
8074 - GET_THREAD_INFO(%r10)
8075 + GET_THREAD_INFO(%r11)
8076 DISABLE_INTERRUPTS(CLBR_NONE)
8077 TRACE_IRQS_OFF
8078 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8079 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8080 jnz sysretl_audit
8081 sysretl_from_sys_call:
8082 - andl $~TS_COMPAT,TI_status(%r10)
8083 + pax_exit_kernel_user
8084 + pax_erase_kstack
8085 + andl $~TS_COMPAT,TI_status(%r11)
8086 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8087 movl RIP-ARGOFFSET(%rsp),%ecx
8088 CFI_REGISTER rip,rcx
8089 @@ -361,7 +411,7 @@ sysretl_audit:
8090
8091 cstar_tracesys:
8092 #ifdef CONFIG_AUDITSYSCALL
8093 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8094 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8095 jz cstar_auditsys
8096 #endif
8097 xchgl %r9d,%ebp
8098 @@ -370,6 +420,9 @@ cstar_tracesys:
8099 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8100 movq %rsp,%rdi /* &pt_regs -> arg1 */
8101 call syscall_trace_enter
8102 +
8103 + pax_erase_kstack
8104 +
8105 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8106 RESTORE_REST
8107 xchgl %ebp,%r9d
8108 @@ -415,11 +468,6 @@ ENTRY(ia32_syscall)
8109 CFI_REL_OFFSET rip,RIP-RIP
8110 PARAVIRT_ADJUST_EXCEPTION_FRAME
8111 SWAPGS
8112 - /*
8113 - * No need to follow this irqs on/off section: the syscall
8114 - * disabled irqs and here we enable it straight after entry:
8115 - */
8116 - ENABLE_INTERRUPTS(CLBR_NONE)
8117 movl %eax,%eax
8118 pushq %rax
8119 CFI_ADJUST_CFA_OFFSET 8
8120 @@ -427,9 +475,15 @@ ENTRY(ia32_syscall)
8121 /* note the registers are not zero extended to the sf.
8122 this could be a problem. */
8123 SAVE_ARGS 0,0,1
8124 - GET_THREAD_INFO(%r10)
8125 - orl $TS_COMPAT,TI_status(%r10)
8126 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8127 + pax_enter_kernel_user
8128 + /*
8129 + * No need to follow this irqs on/off section: the syscall
8130 + * disabled irqs and here we enable it straight after entry:
8131 + */
8132 + ENABLE_INTERRUPTS(CLBR_NONE)
8133 + GET_THREAD_INFO(%r11)
8134 + orl $TS_COMPAT,TI_status(%r11)
8135 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8136 jnz ia32_tracesys
8137 cmpq $(IA32_NR_syscalls-1),%rax
8138 ja ia32_badsys
8139 @@ -448,6 +502,9 @@ ia32_tracesys:
8140 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8141 movq %rsp,%rdi /* &pt_regs -> arg1 */
8142 call syscall_trace_enter
8143 +
8144 + pax_erase_kstack
8145 +
8146 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8147 RESTORE_REST
8148 cmpq $(IA32_NR_syscalls-1),%rax
8149 @@ -462,6 +519,7 @@ ia32_badsys:
8150
8151 quiet_ni_syscall:
8152 movq $-ENOSYS,%rax
8153 + pax_force_retaddr
8154 ret
8155 CFI_ENDPROC
8156
8157 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8158 index 016218c..47ccbdd 100644
8159 --- a/arch/x86/ia32/sys_ia32.c
8160 +++ b/arch/x86/ia32/sys_ia32.c
8161 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8162 */
8163 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8164 {
8165 - typeof(ubuf->st_uid) uid = 0;
8166 - typeof(ubuf->st_gid) gid = 0;
8167 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8168 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8169 SET_UID(uid, stat->uid);
8170 SET_GID(gid, stat->gid);
8171 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8172 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8173 }
8174 set_fs(KERNEL_DS);
8175 ret = sys_rt_sigprocmask(how,
8176 - set ? (sigset_t __user *)&s : NULL,
8177 - oset ? (sigset_t __user *)&s : NULL,
8178 + set ? (sigset_t __force_user *)&s : NULL,
8179 + oset ? (sigset_t __force_user *)&s : NULL,
8180 sigsetsize);
8181 set_fs(old_fs);
8182 if (ret)
8183 @@ -371,7 +371,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8184 mm_segment_t old_fs = get_fs();
8185
8186 set_fs(KERNEL_DS);
8187 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8188 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8189 set_fs(old_fs);
8190 if (put_compat_timespec(&t, interval))
8191 return -EFAULT;
8192 @@ -387,7 +387,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8193 mm_segment_t old_fs = get_fs();
8194
8195 set_fs(KERNEL_DS);
8196 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8197 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8198 set_fs(old_fs);
8199 if (!ret) {
8200 switch (_NSIG_WORDS) {
8201 @@ -412,7 +412,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8202 if (copy_siginfo_from_user32(&info, uinfo))
8203 return -EFAULT;
8204 set_fs(KERNEL_DS);
8205 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8206 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8207 set_fs(old_fs);
8208 return ret;
8209 }
8210 @@ -513,7 +513,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8211 return -EFAULT;
8212
8213 set_fs(KERNEL_DS);
8214 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8215 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8216 count);
8217 set_fs(old_fs);
8218
8219 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8220 index e2077d3..e134a5e 100644
8221 --- a/arch/x86/include/asm/alternative-asm.h
8222 +++ b/arch/x86/include/asm/alternative-asm.h
8223 @@ -19,4 +19,43 @@
8224 .endm
8225 #endif
8226
8227 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
8228 + .macro pax_force_retaddr_bts rip=0
8229 + btsq $63,\rip(%rsp)
8230 + .endm
8231 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8232 + .macro pax_force_retaddr rip=0, reload=0
8233 + btsq $63,\rip(%rsp)
8234 + .endm
8235 + .macro pax_force_fptr ptr
8236 + btsq $63,\ptr
8237 + .endm
8238 + .macro pax_set_fptr_mask
8239 + .endm
8240 +#endif
8241 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8242 + .macro pax_force_retaddr rip=0, reload=0
8243 + .if \reload
8244 + pax_set_fptr_mask
8245 + .endif
8246 + orq %r10,\rip(%rsp)
8247 + .endm
8248 + .macro pax_force_fptr ptr
8249 + orq %r10,\ptr
8250 + .endm
8251 + .macro pax_set_fptr_mask
8252 + movabs $0x8000000000000000,%r10
8253 + .endm
8254 +#endif
8255 +#else
8256 + .macro pax_force_retaddr rip=0, reload=0
8257 + .endm
8258 + .macro pax_force_fptr ptr
8259 + .endm
8260 + .macro pax_force_retaddr_bts rip=0
8261 + .endm
8262 + .macro pax_set_fptr_mask
8263 + .endm
8264 +#endif
8265 +
8266 #endif /* __ASSEMBLY__ */
8267 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8268 index c240efc..fdfadf3 100644
8269 --- a/arch/x86/include/asm/alternative.h
8270 +++ b/arch/x86/include/asm/alternative.h
8271 @@ -85,7 +85,7 @@ static inline void alternatives_smp_switch(int smp) {}
8272 " .byte 662b-661b\n" /* sourcelen */ \
8273 " .byte 664f-663f\n" /* replacementlen */ \
8274 ".previous\n" \
8275 - ".section .altinstr_replacement, \"ax\"\n" \
8276 + ".section .altinstr_replacement, \"a\"\n" \
8277 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8278 ".previous"
8279
8280 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8281 index 474d80d..1f97d58 100644
8282 --- a/arch/x86/include/asm/apic.h
8283 +++ b/arch/x86/include/asm/apic.h
8284 @@ -46,7 +46,7 @@ static inline void generic_apic_probe(void)
8285
8286 #ifdef CONFIG_X86_LOCAL_APIC
8287
8288 -extern unsigned int apic_verbosity;
8289 +extern int apic_verbosity;
8290 extern int local_apic_timer_c2_ok;
8291
8292 extern int disable_apic;
8293 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8294 index 20370c6..a2eb9b0 100644
8295 --- a/arch/x86/include/asm/apm.h
8296 +++ b/arch/x86/include/asm/apm.h
8297 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8298 __asm__ __volatile__(APM_DO_ZERO_SEGS
8299 "pushl %%edi\n\t"
8300 "pushl %%ebp\n\t"
8301 - "lcall *%%cs:apm_bios_entry\n\t"
8302 + "lcall *%%ss:apm_bios_entry\n\t"
8303 "setc %%al\n\t"
8304 "popl %%ebp\n\t"
8305 "popl %%edi\n\t"
8306 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8307 __asm__ __volatile__(APM_DO_ZERO_SEGS
8308 "pushl %%edi\n\t"
8309 "pushl %%ebp\n\t"
8310 - "lcall *%%cs:apm_bios_entry\n\t"
8311 + "lcall *%%ss:apm_bios_entry\n\t"
8312 "setc %%bl\n\t"
8313 "popl %%ebp\n\t"
8314 "popl %%edi\n\t"
8315 diff --git a/arch/x86/include/asm/atomic_32.h b/arch/x86/include/asm/atomic_32.h
8316 index dc5a667..fbed878 100644
8317 --- a/arch/x86/include/asm/atomic_32.h
8318 +++ b/arch/x86/include/asm/atomic_32.h
8319 @@ -25,6 +25,17 @@ static inline int atomic_read(const atomic_t *v)
8320 }
8321
8322 /**
8323 + * atomic_read_unchecked - read atomic variable
8324 + * @v: pointer of type atomic_unchecked_t
8325 + *
8326 + * Atomically reads the value of @v.
8327 + */
8328 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8329 +{
8330 + return v->counter;
8331 +}
8332 +
8333 +/**
8334 * atomic_set - set atomic variable
8335 * @v: pointer of type atomic_t
8336 * @i: required value
8337 @@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *v, int i)
8338 }
8339
8340 /**
8341 + * atomic_set_unchecked - set atomic variable
8342 + * @v: pointer of type atomic_unchecked_t
8343 + * @i: required value
8344 + *
8345 + * Atomically sets the value of @v to @i.
8346 + */
8347 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8348 +{
8349 + v->counter = i;
8350 +}
8351 +
8352 +/**
8353 * atomic_add - add integer to atomic variable
8354 * @i: integer value to add
8355 * @v: pointer of type atomic_t
8356 @@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *v, int i)
8357 */
8358 static inline void atomic_add(int i, atomic_t *v)
8359 {
8360 - asm volatile(LOCK_PREFIX "addl %1,%0"
8361 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8362 +
8363 +#ifdef CONFIG_PAX_REFCOUNT
8364 + "jno 0f\n"
8365 + LOCK_PREFIX "subl %1,%0\n"
8366 + "int $4\n0:\n"
8367 + _ASM_EXTABLE(0b, 0b)
8368 +#endif
8369 +
8370 + : "+m" (v->counter)
8371 + : "ir" (i));
8372 +}
8373 +
8374 +/**
8375 + * atomic_add_unchecked - add integer to atomic variable
8376 + * @i: integer value to add
8377 + * @v: pointer of type atomic_unchecked_t
8378 + *
8379 + * Atomically adds @i to @v.
8380 + */
8381 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8382 +{
8383 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8384 : "+m" (v->counter)
8385 : "ir" (i));
8386 }
8387 @@ -59,7 +104,29 @@ static inline void atomic_add(int i, atomic_t *v)
8388 */
8389 static inline void atomic_sub(int i, atomic_t *v)
8390 {
8391 - asm volatile(LOCK_PREFIX "subl %1,%0"
8392 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8393 +
8394 +#ifdef CONFIG_PAX_REFCOUNT
8395 + "jno 0f\n"
8396 + LOCK_PREFIX "addl %1,%0\n"
8397 + "int $4\n0:\n"
8398 + _ASM_EXTABLE(0b, 0b)
8399 +#endif
8400 +
8401 + : "+m" (v->counter)
8402 + : "ir" (i));
8403 +}
8404 +
8405 +/**
8406 + * atomic_sub_unchecked - subtract integer from atomic variable
8407 + * @i: integer value to subtract
8408 + * @v: pointer of type atomic_unchecked_t
8409 + *
8410 + * Atomically subtracts @i from @v.
8411 + */
8412 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8413 +{
8414 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8415 : "+m" (v->counter)
8416 : "ir" (i));
8417 }
8418 @@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8419 {
8420 unsigned char c;
8421
8422 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8423 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8424 +
8425 +#ifdef CONFIG_PAX_REFCOUNT
8426 + "jno 0f\n"
8427 + LOCK_PREFIX "addl %2,%0\n"
8428 + "int $4\n0:\n"
8429 + _ASM_EXTABLE(0b, 0b)
8430 +#endif
8431 +
8432 + "sete %1\n"
8433 : "+m" (v->counter), "=qm" (c)
8434 : "ir" (i) : "memory");
8435 return c;
8436 @@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8437 */
8438 static inline void atomic_inc(atomic_t *v)
8439 {
8440 - asm volatile(LOCK_PREFIX "incl %0"
8441 + asm volatile(LOCK_PREFIX "incl %0\n"
8442 +
8443 +#ifdef CONFIG_PAX_REFCOUNT
8444 + "jno 0f\n"
8445 + LOCK_PREFIX "decl %0\n"
8446 + "int $4\n0:\n"
8447 + _ASM_EXTABLE(0b, 0b)
8448 +#endif
8449 +
8450 + : "+m" (v->counter));
8451 +}
8452 +
8453 +/**
8454 + * atomic_inc_unchecked - increment atomic variable
8455 + * @v: pointer of type atomic_unchecked_t
8456 + *
8457 + * Atomically increments @v by 1.
8458 + */
8459 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8460 +{
8461 + asm volatile(LOCK_PREFIX "incl %0\n"
8462 : "+m" (v->counter));
8463 }
8464
8465 @@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *v)
8466 */
8467 static inline void atomic_dec(atomic_t *v)
8468 {
8469 - asm volatile(LOCK_PREFIX "decl %0"
8470 + asm volatile(LOCK_PREFIX "decl %0\n"
8471 +
8472 +#ifdef CONFIG_PAX_REFCOUNT
8473 + "jno 0f\n"
8474 + LOCK_PREFIX "incl %0\n"
8475 + "int $4\n0:\n"
8476 + _ASM_EXTABLE(0b, 0b)
8477 +#endif
8478 +
8479 + : "+m" (v->counter));
8480 +}
8481 +
8482 +/**
8483 + * atomic_dec_unchecked - decrement atomic variable
8484 + * @v: pointer of type atomic_unchecked_t
8485 + *
8486 + * Atomically decrements @v by 1.
8487 + */
8488 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8489 +{
8490 + asm volatile(LOCK_PREFIX "decl %0\n"
8491 : "+m" (v->counter));
8492 }
8493
8494 @@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8495 {
8496 unsigned char c;
8497
8498 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8499 + asm volatile(LOCK_PREFIX "decl %0\n"
8500 +
8501 +#ifdef CONFIG_PAX_REFCOUNT
8502 + "jno 0f\n"
8503 + LOCK_PREFIX "incl %0\n"
8504 + "int $4\n0:\n"
8505 + _ASM_EXTABLE(0b, 0b)
8506 +#endif
8507 +
8508 + "sete %1\n"
8509 : "+m" (v->counter), "=qm" (c)
8510 : : "memory");
8511 return c != 0;
8512 @@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8513 {
8514 unsigned char c;
8515
8516 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8517 + asm volatile(LOCK_PREFIX "incl %0\n"
8518 +
8519 +#ifdef CONFIG_PAX_REFCOUNT
8520 + "jno 0f\n"
8521 + LOCK_PREFIX "decl %0\n"
8522 + "into\n0:\n"
8523 + _ASM_EXTABLE(0b, 0b)
8524 +#endif
8525 +
8526 + "sete %1\n"
8527 + : "+m" (v->counter), "=qm" (c)
8528 + : : "memory");
8529 + return c != 0;
8530 +}
8531 +
8532 +/**
8533 + * atomic_inc_and_test_unchecked - increment and test
8534 + * @v: pointer of type atomic_unchecked_t
8535 + *
8536 + * Atomically increments @v by 1
8537 + * and returns true if the result is zero, or false for all
8538 + * other cases.
8539 + */
8540 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8541 +{
8542 + unsigned char c;
8543 +
8544 + asm volatile(LOCK_PREFIX "incl %0\n"
8545 + "sete %1\n"
8546 : "+m" (v->counter), "=qm" (c)
8547 : : "memory");
8548 return c != 0;
8549 @@ -156,7 +309,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8550 {
8551 unsigned char c;
8552
8553 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8554 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8555 +
8556 +#ifdef CONFIG_PAX_REFCOUNT
8557 + "jno 0f\n"
8558 + LOCK_PREFIX "subl %2,%0\n"
8559 + "int $4\n0:\n"
8560 + _ASM_EXTABLE(0b, 0b)
8561 +#endif
8562 +
8563 + "sets %1\n"
8564 : "+m" (v->counter), "=qm" (c)
8565 : "ir" (i) : "memory");
8566 return c;
8567 @@ -179,6 +341,46 @@ static inline int atomic_add_return(int i, atomic_t *v)
8568 #endif
8569 /* Modern 486+ processor */
8570 __i = i;
8571 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8572 +
8573 +#ifdef CONFIG_PAX_REFCOUNT
8574 + "jno 0f\n"
8575 + "movl %0, %1\n"
8576 + "int $4\n0:\n"
8577 + _ASM_EXTABLE(0b, 0b)
8578 +#endif
8579 +
8580 + : "+r" (i), "+m" (v->counter)
8581 + : : "memory");
8582 + return i + __i;
8583 +
8584 +#ifdef CONFIG_M386
8585 +no_xadd: /* Legacy 386 processor */
8586 + local_irq_save(flags);
8587 + __i = atomic_read(v);
8588 + atomic_set(v, i + __i);
8589 + local_irq_restore(flags);
8590 + return i + __i;
8591 +#endif
8592 +}
8593 +
8594 +/**
8595 + * atomic_add_return_unchecked - add integer and return
8596 + * @v: pointer of type atomic_unchecked_t
8597 + * @i: integer value to add
8598 + *
8599 + * Atomically adds @i to @v and returns @i + @v
8600 + */
8601 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8602 +{
8603 + int __i;
8604 +#ifdef CONFIG_M386
8605 + unsigned long flags;
8606 + if (unlikely(boot_cpu_data.x86 <= 3))
8607 + goto no_xadd;
8608 +#endif
8609 + /* Modern 486+ processor */
8610 + __i = i;
8611 asm volatile(LOCK_PREFIX "xaddl %0, %1"
8612 : "+r" (i), "+m" (v->counter)
8613 : : "memory");
8614 @@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8615 return cmpxchg(&v->counter, old, new);
8616 }
8617
8618 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8619 +{
8620 + return cmpxchg(&v->counter, old, new);
8621 +}
8622 +
8623 static inline int atomic_xchg(atomic_t *v, int new)
8624 {
8625 return xchg(&v->counter, new);
8626 }
8627
8628 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8629 +{
8630 + return xchg(&v->counter, new);
8631 +}
8632 +
8633 /**
8634 * atomic_add_unless - add unless the number is already a given value
8635 * @v: pointer of type atomic_t
8636 @@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *v, int new)
8637 */
8638 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8639 {
8640 - int c, old;
8641 + int c, old, new;
8642 c = atomic_read(v);
8643 for (;;) {
8644 - if (unlikely(c == (u)))
8645 + if (unlikely(c == u))
8646 break;
8647 - old = atomic_cmpxchg((v), c, c + (a));
8648 +
8649 + asm volatile("addl %2,%0\n"
8650 +
8651 +#ifdef CONFIG_PAX_REFCOUNT
8652 + "jno 0f\n"
8653 + "subl %2,%0\n"
8654 + "int $4\n0:\n"
8655 + _ASM_EXTABLE(0b, 0b)
8656 +#endif
8657 +
8658 + : "=r" (new)
8659 + : "0" (c), "ir" (a));
8660 +
8661 + old = atomic_cmpxchg(v, c, new);
8662 if (likely(old == c))
8663 break;
8664 c = old;
8665 }
8666 - return c != (u);
8667 + return c != u;
8668 }
8669
8670 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8671
8672 #define atomic_inc_return(v) (atomic_add_return(1, v))
8673 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8674 +{
8675 + return atomic_add_return_unchecked(1, v);
8676 +}
8677 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8678
8679 /* These are x86-specific, used by some header files */
8680 @@ -266,9 +495,18 @@ typedef struct {
8681 u64 __aligned(8) counter;
8682 } atomic64_t;
8683
8684 +#ifdef CONFIG_PAX_REFCOUNT
8685 +typedef struct {
8686 + u64 __aligned(8) counter;
8687 +} atomic64_unchecked_t;
8688 +#else
8689 +typedef atomic64_t atomic64_unchecked_t;
8690 +#endif
8691 +
8692 #define ATOMIC64_INIT(val) { (val) }
8693
8694 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8695 +extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
8696
8697 /**
8698 * atomic64_xchg - xchg atomic64 variable
8699 @@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8700 * the old value.
8701 */
8702 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8703 +extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8704
8705 /**
8706 * atomic64_set - set atomic64 variable
8707 @@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8708 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
8709
8710 /**
8711 + * atomic64_unchecked_set - set atomic64 variable
8712 + * @ptr: pointer to type atomic64_unchecked_t
8713 + * @new_val: value to assign
8714 + *
8715 + * Atomically sets the value of @ptr to @new_val.
8716 + */
8717 +extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8718 +
8719 +/**
8720 * atomic64_read - read atomic64 variable
8721 * @ptr: pointer to type atomic64_t
8722 *
8723 @@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64_t *ptr)
8724 return res;
8725 }
8726
8727 -extern u64 atomic64_read(atomic64_t *ptr);
8728 +/**
8729 + * atomic64_read_unchecked - read atomic64 variable
8730 + * @ptr: pointer to type atomic64_unchecked_t
8731 + *
8732 + * Atomically reads the value of @ptr and returns it.
8733 + */
8734 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
8735 +{
8736 + u64 res;
8737 +
8738 + /*
8739 + * Note, we inline this atomic64_unchecked_t primitive because
8740 + * it only clobbers EAX/EDX and leaves the others
8741 + * untouched. We also (somewhat subtly) rely on the
8742 + * fact that cmpxchg8b returns the current 64-bit value
8743 + * of the memory location we are touching:
8744 + */
8745 + asm volatile(
8746 + "mov %%ebx, %%eax\n\t"
8747 + "mov %%ecx, %%edx\n\t"
8748 + LOCK_PREFIX "cmpxchg8b %1\n"
8749 + : "=&A" (res)
8750 + : "m" (*ptr)
8751 + );
8752 +
8753 + return res;
8754 +}
8755
8756 /**
8757 * atomic64_add_return - add and return
8758 @@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr);
8759 * Other variants with different arithmetic operators:
8760 */
8761 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
8762 +extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8763 extern u64 atomic64_inc_return(atomic64_t *ptr);
8764 +extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
8765 extern u64 atomic64_dec_return(atomic64_t *ptr);
8766 +extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
8767
8768 /**
8769 * atomic64_add - add integer to atomic64 variable
8770 @@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_t *ptr);
8771 extern void atomic64_add(u64 delta, atomic64_t *ptr);
8772
8773 /**
8774 + * atomic64_add_unchecked - add integer to atomic64 variable
8775 + * @delta: integer value to add
8776 + * @ptr: pointer to type atomic64_unchecked_t
8777 + *
8778 + * Atomically adds @delta to @ptr.
8779 + */
8780 +extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8781 +
8782 +/**
8783 * atomic64_sub - subtract the atomic64 variable
8784 * @delta: integer value to subtract
8785 * @ptr: pointer to type atomic64_t
8786 @@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atomic64_t *ptr);
8787 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
8788
8789 /**
8790 + * atomic64_sub_unchecked - subtract the atomic64 variable
8791 + * @delta: integer value to subtract
8792 + * @ptr: pointer to type atomic64_unchecked_t
8793 + *
8794 + * Atomically subtracts @delta from @ptr.
8795 + */
8796 +extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8797 +
8798 +/**
8799 * atomic64_sub_and_test - subtract value from variable and test result
8800 * @delta: integer value to subtract
8801 * @ptr: pointer to type atomic64_t
8802 @@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr);
8803 extern void atomic64_inc(atomic64_t *ptr);
8804
8805 /**
8806 + * atomic64_inc_unchecked - increment atomic64 variable
8807 + * @ptr: pointer to type atomic64_unchecked_t
8808 + *
8809 + * Atomically increments @ptr by 1.
8810 + */
8811 +extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
8812 +
8813 +/**
8814 * atomic64_dec - decrement atomic64 variable
8815 * @ptr: pointer to type atomic64_t
8816 *
8817 @@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr);
8818 extern void atomic64_dec(atomic64_t *ptr);
8819
8820 /**
8821 + * atomic64_dec_unchecked - decrement atomic64 variable
8822 + * @ptr: pointer to type atomic64_unchecked_t
8823 + *
8824 + * Atomically decrements @ptr by 1.
8825 + */
8826 +extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
8827 +
8828 +/**
8829 * atomic64_dec_and_test - decrement and test
8830 * @ptr: pointer to type atomic64_t
8831 *
8832 diff --git a/arch/x86/include/asm/atomic_64.h b/arch/x86/include/asm/atomic_64.h
8833 index d605dc2..fafd7bd 100644
8834 --- a/arch/x86/include/asm/atomic_64.h
8835 +++ b/arch/x86/include/asm/atomic_64.h
8836 @@ -24,6 +24,17 @@ static inline int atomic_read(const atomic_t *v)
8837 }
8838
8839 /**
8840 + * atomic_read_unchecked - read atomic variable
8841 + * @v: pointer of type atomic_unchecked_t
8842 + *
8843 + * Atomically reads the value of @v.
8844 + */
8845 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8846 +{
8847 + return v->counter;
8848 +}
8849 +
8850 +/**
8851 * atomic_set - set atomic variable
8852 * @v: pointer of type atomic_t
8853 * @i: required value
8854 @@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *v, int i)
8855 }
8856
8857 /**
8858 + * atomic_set_unchecked - set atomic variable
8859 + * @v: pointer of type atomic_unchecked_t
8860 + * @i: required value
8861 + *
8862 + * Atomically sets the value of @v to @i.
8863 + */
8864 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8865 +{
8866 + v->counter = i;
8867 +}
8868 +
8869 +/**
8870 * atomic_add - add integer to atomic variable
8871 * @i: integer value to add
8872 * @v: pointer of type atomic_t
8873 @@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *v, int i)
8874 */
8875 static inline void atomic_add(int i, atomic_t *v)
8876 {
8877 - asm volatile(LOCK_PREFIX "addl %1,%0"
8878 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8879 +
8880 +#ifdef CONFIG_PAX_REFCOUNT
8881 + "jno 0f\n"
8882 + LOCK_PREFIX "subl %1,%0\n"
8883 + "int $4\n0:\n"
8884 + _ASM_EXTABLE(0b, 0b)
8885 +#endif
8886 +
8887 + : "=m" (v->counter)
8888 + : "ir" (i), "m" (v->counter));
8889 +}
8890 +
8891 +/**
8892 + * atomic_add_unchecked - add integer to atomic variable
8893 + * @i: integer value to add
8894 + * @v: pointer of type atomic_unchecked_t
8895 + *
8896 + * Atomically adds @i to @v.
8897 + */
8898 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8899 +{
8900 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8901 : "=m" (v->counter)
8902 : "ir" (i), "m" (v->counter));
8903 }
8904 @@ -58,7 +103,29 @@ static inline void atomic_add(int i, atomic_t *v)
8905 */
8906 static inline void atomic_sub(int i, atomic_t *v)
8907 {
8908 - asm volatile(LOCK_PREFIX "subl %1,%0"
8909 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8910 +
8911 +#ifdef CONFIG_PAX_REFCOUNT
8912 + "jno 0f\n"
8913 + LOCK_PREFIX "addl %1,%0\n"
8914 + "int $4\n0:\n"
8915 + _ASM_EXTABLE(0b, 0b)
8916 +#endif
8917 +
8918 + : "=m" (v->counter)
8919 + : "ir" (i), "m" (v->counter));
8920 +}
8921 +
8922 +/**
8923 + * atomic_sub_unchecked - subtract the atomic variable
8924 + * @i: integer value to subtract
8925 + * @v: pointer of type atomic_unchecked_t
8926 + *
8927 + * Atomically subtracts @i from @v.
8928 + */
8929 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8930 +{
8931 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8932 : "=m" (v->counter)
8933 : "ir" (i), "m" (v->counter));
8934 }
8935 @@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8936 {
8937 unsigned char c;
8938
8939 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8940 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8941 +
8942 +#ifdef CONFIG_PAX_REFCOUNT
8943 + "jno 0f\n"
8944 + LOCK_PREFIX "addl %2,%0\n"
8945 + "int $4\n0:\n"
8946 + _ASM_EXTABLE(0b, 0b)
8947 +#endif
8948 +
8949 + "sete %1\n"
8950 : "=m" (v->counter), "=qm" (c)
8951 : "ir" (i), "m" (v->counter) : "memory");
8952 return c;
8953 @@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8954 */
8955 static inline void atomic_inc(atomic_t *v)
8956 {
8957 - asm volatile(LOCK_PREFIX "incl %0"
8958 + asm volatile(LOCK_PREFIX "incl %0\n"
8959 +
8960 +#ifdef CONFIG_PAX_REFCOUNT
8961 + "jno 0f\n"
8962 + LOCK_PREFIX "decl %0\n"
8963 + "int $4\n0:\n"
8964 + _ASM_EXTABLE(0b, 0b)
8965 +#endif
8966 +
8967 + : "=m" (v->counter)
8968 + : "m" (v->counter));
8969 +}
8970 +
8971 +/**
8972 + * atomic_inc_unchecked - increment atomic variable
8973 + * @v: pointer of type atomic_unchecked_t
8974 + *
8975 + * Atomically increments @v by 1.
8976 + */
8977 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8978 +{
8979 + asm volatile(LOCK_PREFIX "incl %0\n"
8980 : "=m" (v->counter)
8981 : "m" (v->counter));
8982 }
8983 @@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *v)
8984 */
8985 static inline void atomic_dec(atomic_t *v)
8986 {
8987 - asm volatile(LOCK_PREFIX "decl %0"
8988 + asm volatile(LOCK_PREFIX "decl %0\n"
8989 +
8990 +#ifdef CONFIG_PAX_REFCOUNT
8991 + "jno 0f\n"
8992 + LOCK_PREFIX "incl %0\n"
8993 + "int $4\n0:\n"
8994 + _ASM_EXTABLE(0b, 0b)
8995 +#endif
8996 +
8997 + : "=m" (v->counter)
8998 + : "m" (v->counter));
8999 +}
9000 +
9001 +/**
9002 + * atomic_dec_unchecked - decrement atomic variable
9003 + * @v: pointer of type atomic_unchecked_t
9004 + *
9005 + * Atomically decrements @v by 1.
9006 + */
9007 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9008 +{
9009 + asm volatile(LOCK_PREFIX "decl %0\n"
9010 : "=m" (v->counter)
9011 : "m" (v->counter));
9012 }
9013 @@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9014 {
9015 unsigned char c;
9016
9017 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9018 + asm volatile(LOCK_PREFIX "decl %0\n"
9019 +
9020 +#ifdef CONFIG_PAX_REFCOUNT
9021 + "jno 0f\n"
9022 + LOCK_PREFIX "incl %0\n"
9023 + "int $4\n0:\n"
9024 + _ASM_EXTABLE(0b, 0b)
9025 +#endif
9026 +
9027 + "sete %1\n"
9028 : "=m" (v->counter), "=qm" (c)
9029 : "m" (v->counter) : "memory");
9030 return c != 0;
9031 @@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9032 {
9033 unsigned char c;
9034
9035 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9036 + asm volatile(LOCK_PREFIX "incl %0\n"
9037 +
9038 +#ifdef CONFIG_PAX_REFCOUNT
9039 + "jno 0f\n"
9040 + LOCK_PREFIX "decl %0\n"
9041 + "int $4\n0:\n"
9042 + _ASM_EXTABLE(0b, 0b)
9043 +#endif
9044 +
9045 + "sete %1\n"
9046 + : "=m" (v->counter), "=qm" (c)
9047 + : "m" (v->counter) : "memory");
9048 + return c != 0;
9049 +}
9050 +
9051 +/**
9052 + * atomic_inc_and_test_unchecked - increment and test
9053 + * @v: pointer of type atomic_unchecked_t
9054 + *
9055 + * Atomically increments @v by 1
9056 + * and returns true if the result is zero, or false for all
9057 + * other cases.
9058 + */
9059 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9060 +{
9061 + unsigned char c;
9062 +
9063 + asm volatile(LOCK_PREFIX "incl %0\n"
9064 + "sete %1\n"
9065 : "=m" (v->counter), "=qm" (c)
9066 : "m" (v->counter) : "memory");
9067 return c != 0;
9068 @@ -157,7 +312,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9069 {
9070 unsigned char c;
9071
9072 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9073 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9074 +
9075 +#ifdef CONFIG_PAX_REFCOUNT
9076 + "jno 0f\n"
9077 + LOCK_PREFIX "subl %2,%0\n"
9078 + "int $4\n0:\n"
9079 + _ASM_EXTABLE(0b, 0b)
9080 +#endif
9081 +
9082 + "sets %1\n"
9083 : "=m" (v->counter), "=qm" (c)
9084 : "ir" (i), "m" (v->counter) : "memory");
9085 return c;
9086 @@ -173,7 +337,31 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9087 static inline int atomic_add_return(int i, atomic_t *v)
9088 {
9089 int __i = i;
9090 - asm volatile(LOCK_PREFIX "xaddl %0, %1"
9091 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9092 +
9093 +#ifdef CONFIG_PAX_REFCOUNT
9094 + "jno 0f\n"
9095 + "movl %0, %1\n"
9096 + "int $4\n0:\n"
9097 + _ASM_EXTABLE(0b, 0b)
9098 +#endif
9099 +
9100 + : "+r" (i), "+m" (v->counter)
9101 + : : "memory");
9102 + return i + __i;
9103 +}
9104 +
9105 +/**
9106 + * atomic_add_return_unchecked - add and return
9107 + * @i: integer value to add
9108 + * @v: pointer of type atomic_unchecked_t
9109 + *
9110 + * Atomically adds @i to @v and returns @i + @v
9111 + */
9112 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9113 +{
9114 + int __i = i;
9115 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9116 : "+r" (i), "+m" (v->counter)
9117 : : "memory");
9118 return i + __i;
9119 @@ -185,6 +373,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9120 }
9121
9122 #define atomic_inc_return(v) (atomic_add_return(1, v))
9123 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9124 +{
9125 + return atomic_add_return_unchecked(1, v);
9126 +}
9127 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9128
9129 /* The 64-bit atomic type */
9130 @@ -204,6 +396,18 @@ static inline long atomic64_read(const atomic64_t *v)
9131 }
9132
9133 /**
9134 + * atomic64_read_unchecked - read atomic64 variable
9135 + * @v: pointer of type atomic64_unchecked_t
9136 + *
9137 + * Atomically reads the value of @v.
9138 + * Doesn't imply a read memory barrier.
9139 + */
9140 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9141 +{
9142 + return v->counter;
9143 +}
9144 +
9145 +/**
9146 * atomic64_set - set atomic64 variable
9147 * @v: pointer to type atomic64_t
9148 * @i: required value
9149 @@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9150 }
9151
9152 /**
9153 + * atomic64_set_unchecked - set atomic64 variable
9154 + * @v: pointer to type atomic64_unchecked_t
9155 + * @i: required value
9156 + *
9157 + * Atomically sets the value of @v to @i.
9158 + */
9159 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9160 +{
9161 + v->counter = i;
9162 +}
9163 +
9164 +/**
9165 * atomic64_add - add integer to atomic64 variable
9166 * @i: integer value to add
9167 * @v: pointer to type atomic64_t
9168 @@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9169 */
9170 static inline void atomic64_add(long i, atomic64_t *v)
9171 {
9172 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9173 +
9174 +#ifdef CONFIG_PAX_REFCOUNT
9175 + "jno 0f\n"
9176 + LOCK_PREFIX "subq %1,%0\n"
9177 + "int $4\n0:\n"
9178 + _ASM_EXTABLE(0b, 0b)
9179 +#endif
9180 +
9181 + : "=m" (v->counter)
9182 + : "er" (i), "m" (v->counter));
9183 +}
9184 +
9185 +/**
9186 + * atomic64_add_unchecked - add integer to atomic64 variable
9187 + * @i: integer value to add
9188 + * @v: pointer to type atomic64_unchecked_t
9189 + *
9190 + * Atomically adds @i to @v.
9191 + */
9192 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9193 +{
9194 asm volatile(LOCK_PREFIX "addq %1,%0"
9195 : "=m" (v->counter)
9196 : "er" (i), "m" (v->counter));
9197 @@ -238,7 +476,15 @@ static inline void atomic64_add(long i, atomic64_t *v)
9198 */
9199 static inline void atomic64_sub(long i, atomic64_t *v)
9200 {
9201 - asm volatile(LOCK_PREFIX "subq %1,%0"
9202 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9203 +
9204 +#ifdef CONFIG_PAX_REFCOUNT
9205 + "jno 0f\n"
9206 + LOCK_PREFIX "addq %1,%0\n"
9207 + "int $4\n0:\n"
9208 + _ASM_EXTABLE(0b, 0b)
9209 +#endif
9210 +
9211 : "=m" (v->counter)
9212 : "er" (i), "m" (v->counter));
9213 }
9214 @@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9215 {
9216 unsigned char c;
9217
9218 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9219 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9220 +
9221 +#ifdef CONFIG_PAX_REFCOUNT
9222 + "jno 0f\n"
9223 + LOCK_PREFIX "addq %2,%0\n"
9224 + "int $4\n0:\n"
9225 + _ASM_EXTABLE(0b, 0b)
9226 +#endif
9227 +
9228 + "sete %1\n"
9229 : "=m" (v->counter), "=qm" (c)
9230 : "er" (i), "m" (v->counter) : "memory");
9231 return c;
9232 @@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9233 */
9234 static inline void atomic64_inc(atomic64_t *v)
9235 {
9236 + asm volatile(LOCK_PREFIX "incq %0\n"
9237 +
9238 +#ifdef CONFIG_PAX_REFCOUNT
9239 + "jno 0f\n"
9240 + LOCK_PREFIX "decq %0\n"
9241 + "int $4\n0:\n"
9242 + _ASM_EXTABLE(0b, 0b)
9243 +#endif
9244 +
9245 + : "=m" (v->counter)
9246 + : "m" (v->counter));
9247 +}
9248 +
9249 +/**
9250 + * atomic64_inc_unchecked - increment atomic64 variable
9251 + * @v: pointer to type atomic64_unchecked_t
9252 + *
9253 + * Atomically increments @v by 1.
9254 + */
9255 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9256 +{
9257 asm volatile(LOCK_PREFIX "incq %0"
9258 : "=m" (v->counter)
9259 : "m" (v->counter));
9260 @@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64_t *v)
9261 */
9262 static inline void atomic64_dec(atomic64_t *v)
9263 {
9264 - asm volatile(LOCK_PREFIX "decq %0"
9265 + asm volatile(LOCK_PREFIX "decq %0\n"
9266 +
9267 +#ifdef CONFIG_PAX_REFCOUNT
9268 + "jno 0f\n"
9269 + LOCK_PREFIX "incq %0\n"
9270 + "int $4\n0:\n"
9271 + _ASM_EXTABLE(0b, 0b)
9272 +#endif
9273 +
9274 + : "=m" (v->counter)
9275 + : "m" (v->counter));
9276 +}
9277 +
9278 +/**
9279 + * atomic64_dec_unchecked - decrement atomic64 variable
9280 + * @v: pointer to type atomic64_t
9281 + *
9282 + * Atomically decrements @v by 1.
9283 + */
9284 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9285 +{
9286 + asm volatile(LOCK_PREFIX "decq %0\n"
9287 : "=m" (v->counter)
9288 : "m" (v->counter));
9289 }
9290 @@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9291 {
9292 unsigned char c;
9293
9294 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9295 + asm volatile(LOCK_PREFIX "decq %0\n"
9296 +
9297 +#ifdef CONFIG_PAX_REFCOUNT
9298 + "jno 0f\n"
9299 + LOCK_PREFIX "incq %0\n"
9300 + "int $4\n0:\n"
9301 + _ASM_EXTABLE(0b, 0b)
9302 +#endif
9303 +
9304 + "sete %1\n"
9305 : "=m" (v->counter), "=qm" (c)
9306 : "m" (v->counter) : "memory");
9307 return c != 0;
9308 @@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9309 {
9310 unsigned char c;
9311
9312 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9313 + asm volatile(LOCK_PREFIX "incq %0\n"
9314 +
9315 +#ifdef CONFIG_PAX_REFCOUNT
9316 + "jno 0f\n"
9317 + LOCK_PREFIX "decq %0\n"
9318 + "int $4\n0:\n"
9319 + _ASM_EXTABLE(0b, 0b)
9320 +#endif
9321 +
9322 + "sete %1\n"
9323 : "=m" (v->counter), "=qm" (c)
9324 : "m" (v->counter) : "memory");
9325 return c != 0;
9326 @@ -337,7 +652,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9327 {
9328 unsigned char c;
9329
9330 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9331 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9332 +
9333 +#ifdef CONFIG_PAX_REFCOUNT
9334 + "jno 0f\n"
9335 + LOCK_PREFIX "subq %2,%0\n"
9336 + "int $4\n0:\n"
9337 + _ASM_EXTABLE(0b, 0b)
9338 +#endif
9339 +
9340 + "sets %1\n"
9341 : "=m" (v->counter), "=qm" (c)
9342 : "er" (i), "m" (v->counter) : "memory");
9343 return c;
9344 @@ -353,7 +677,31 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9345 static inline long atomic64_add_return(long i, atomic64_t *v)
9346 {
9347 long __i = i;
9348 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
9349 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
9350 +
9351 +#ifdef CONFIG_PAX_REFCOUNT
9352 + "jno 0f\n"
9353 + "movq %0, %1\n"
9354 + "int $4\n0:\n"
9355 + _ASM_EXTABLE(0b, 0b)
9356 +#endif
9357 +
9358 + : "+r" (i), "+m" (v->counter)
9359 + : : "memory");
9360 + return i + __i;
9361 +}
9362 +
9363 +/**
9364 + * atomic64_add_return_unchecked - add and return
9365 + * @i: integer value to add
9366 + * @v: pointer to type atomic64_unchecked_t
9367 + *
9368 + * Atomically adds @i to @v and returns @i + @v
9369 + */
9370 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9371 +{
9372 + long __i = i;
9373 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
9374 : "+r" (i), "+m" (v->counter)
9375 : : "memory");
9376 return i + __i;
9377 @@ -365,6 +713,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9378 }
9379
9380 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9381 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9382 +{
9383 + return atomic64_add_return_unchecked(1, v);
9384 +}
9385 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9386
9387 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9388 @@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9389 return cmpxchg(&v->counter, old, new);
9390 }
9391
9392 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9393 +{
9394 + return cmpxchg(&v->counter, old, new);
9395 +}
9396 +
9397 static inline long atomic64_xchg(atomic64_t *v, long new)
9398 {
9399 return xchg(&v->counter, new);
9400 }
9401
9402 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9403 +{
9404 + return xchg(&v->counter, new);
9405 +}
9406 +
9407 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
9408 {
9409 return cmpxchg(&v->counter, old, new);
9410 }
9411
9412 +static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9413 +{
9414 + return cmpxchg(&v->counter, old, new);
9415 +}
9416 +
9417 static inline long atomic_xchg(atomic_t *v, int new)
9418 {
9419 return xchg(&v->counter, new);
9420 }
9421
9422 +static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9423 +{
9424 + return xchg(&v->counter, new);
9425 +}
9426 +
9427 /**
9428 * atomic_add_unless - add unless the number is a given value
9429 * @v: pointer of type atomic_t
9430 @@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t *v, int new)
9431 */
9432 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9433 {
9434 - int c, old;
9435 + int c, old, new;
9436 c = atomic_read(v);
9437 for (;;) {
9438 - if (unlikely(c == (u)))
9439 + if (unlikely(c == u))
9440 break;
9441 - old = atomic_cmpxchg((v), c, c + (a));
9442 +
9443 + asm volatile("addl %2,%0\n"
9444 +
9445 +#ifdef CONFIG_PAX_REFCOUNT
9446 + "jno 0f\n"
9447 + "subl %2,%0\n"
9448 + "int $4\n0:\n"
9449 + _ASM_EXTABLE(0b, 0b)
9450 +#endif
9451 +
9452 + : "=r" (new)
9453 + : "0" (c), "ir" (a));
9454 +
9455 + old = atomic_cmpxchg(v, c, new);
9456 if (likely(old == c))
9457 break;
9458 c = old;
9459 }
9460 - return c != (u);
9461 + return c != u;
9462 }
9463
9464 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9465 @@ -424,17 +809,30 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
9466 */
9467 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9468 {
9469 - long c, old;
9470 + long c, old, new;
9471 c = atomic64_read(v);
9472 for (;;) {
9473 - if (unlikely(c == (u)))
9474 + if (unlikely(c == u))
9475 break;
9476 - old = atomic64_cmpxchg((v), c, c + (a));
9477 +
9478 + asm volatile("addq %2,%0\n"
9479 +
9480 +#ifdef CONFIG_PAX_REFCOUNT
9481 + "jno 0f\n"
9482 + "subq %2,%0\n"
9483 + "int $4\n0:\n"
9484 + _ASM_EXTABLE(0b, 0b)
9485 +#endif
9486 +
9487 + : "=r" (new)
9488 + : "0" (c), "er" (a));
9489 +
9490 + old = atomic64_cmpxchg(v, c, new);
9491 if (likely(old == c))
9492 break;
9493 c = old;
9494 }
9495 - return c != (u);
9496 + return c != u;
9497 }
9498
9499 /**
9500 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9501 index 02b47a6..d5c4b15 100644
9502 --- a/arch/x86/include/asm/bitops.h
9503 +++ b/arch/x86/include/asm/bitops.h
9504 @@ -38,7 +38,7 @@
9505 * a mask operation on a byte.
9506 */
9507 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9508 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9509 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9510 #define CONST_MASK(nr) (1 << ((nr) & 7))
9511
9512 /**
9513 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9514 index 7a10659..8bbf355 100644
9515 --- a/arch/x86/include/asm/boot.h
9516 +++ b/arch/x86/include/asm/boot.h
9517 @@ -11,10 +11,15 @@
9518 #include <asm/pgtable_types.h>
9519
9520 /* Physical address where kernel should be loaded. */
9521 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9522 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9523 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9524 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9525
9526 +#ifndef __ASSEMBLY__
9527 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9528 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9529 +#endif
9530 +
9531 /* Minimum kernel alignment, as a power of two */
9532 #ifdef CONFIG_X86_64
9533 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9534 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9535 index 549860d..7d45f68 100644
9536 --- a/arch/x86/include/asm/cache.h
9537 +++ b/arch/x86/include/asm/cache.h
9538 @@ -5,9 +5,10 @@
9539
9540 /* L1 cache line size */
9541 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9542 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9543 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9544
9545 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
9546 +#define __read_only __attribute__((__section__(".data.read_only")))
9547
9548 #ifdef CONFIG_X86_VSMP
9549 /* vSMP Internode cacheline shift */
9550 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9551 index b54f6af..5b376a6 100644
9552 --- a/arch/x86/include/asm/cacheflush.h
9553 +++ b/arch/x86/include/asm/cacheflush.h
9554 @@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
9555 static inline unsigned long get_page_memtype(struct page *pg)
9556 {
9557 if (!PageUncached(pg) && !PageWC(pg))
9558 - return -1;
9559 + return ~0UL;
9560 else if (!PageUncached(pg) && PageWC(pg))
9561 return _PAGE_CACHE_WC;
9562 else if (PageUncached(pg) && !PageWC(pg))
9563 @@ -85,7 +85,7 @@ static inline void set_page_memtype(struct page *pg, unsigned long memtype)
9564 SetPageWC(pg);
9565 break;
9566 default:
9567 - case -1:
9568 + case ~0UL:
9569 ClearPageUncached(pg);
9570 ClearPageWC(pg);
9571 break;
9572 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
9573 index 0e63c9a..ab8d972 100644
9574 --- a/arch/x86/include/asm/calling.h
9575 +++ b/arch/x86/include/asm/calling.h
9576 @@ -52,32 +52,32 @@ For 32-bit we have the following conventions - kernel is built with
9577 * for assembly code:
9578 */
9579
9580 -#define R15 0
9581 -#define R14 8
9582 -#define R13 16
9583 -#define R12 24
9584 -#define RBP 32
9585 -#define RBX 40
9586 +#define R15 (0)
9587 +#define R14 (8)
9588 +#define R13 (16)
9589 +#define R12 (24)
9590 +#define RBP (32)
9591 +#define RBX (40)
9592
9593 /* arguments: interrupts/non tracing syscalls only save up to here: */
9594 -#define R11 48
9595 -#define R10 56
9596 -#define R9 64
9597 -#define R8 72
9598 -#define RAX 80
9599 -#define RCX 88
9600 -#define RDX 96
9601 -#define RSI 104
9602 -#define RDI 112
9603 -#define ORIG_RAX 120 /* + error_code */
9604 +#define R11 (48)
9605 +#define R10 (56)
9606 +#define R9 (64)
9607 +#define R8 (72)
9608 +#define RAX (80)
9609 +#define RCX (88)
9610 +#define RDX (96)
9611 +#define RSI (104)
9612 +#define RDI (112)
9613 +#define ORIG_RAX (120) /* + error_code */
9614 /* end of arguments */
9615
9616 /* cpu exception frame or undefined in case of fast syscall: */
9617 -#define RIP 128
9618 -#define CS 136
9619 -#define EFLAGS 144
9620 -#define RSP 152
9621 -#define SS 160
9622 +#define RIP (128)
9623 +#define CS (136)
9624 +#define EFLAGS (144)
9625 +#define RSP (152)
9626 +#define SS (160)
9627
9628 #define ARGOFFSET R11
9629 #define SWFRAME ORIG_RAX
9630 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9631 index 46fc474..b02b0f9 100644
9632 --- a/arch/x86/include/asm/checksum_32.h
9633 +++ b/arch/x86/include/asm/checksum_32.h
9634 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9635 int len, __wsum sum,
9636 int *src_err_ptr, int *dst_err_ptr);
9637
9638 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9639 + int len, __wsum sum,
9640 + int *src_err_ptr, int *dst_err_ptr);
9641 +
9642 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9643 + int len, __wsum sum,
9644 + int *src_err_ptr, int *dst_err_ptr);
9645 +
9646 /*
9647 * Note: when you get a NULL pointer exception here this means someone
9648 * passed in an incorrect kernel address to one of these functions.
9649 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9650 int *err_ptr)
9651 {
9652 might_sleep();
9653 - return csum_partial_copy_generic((__force void *)src, dst,
9654 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9655 len, sum, err_ptr, NULL);
9656 }
9657
9658 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9659 {
9660 might_sleep();
9661 if (access_ok(VERIFY_WRITE, dst, len))
9662 - return csum_partial_copy_generic(src, (__force void *)dst,
9663 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9664 len, sum, NULL, err_ptr);
9665
9666 if (len)
9667 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9668 index 617bd56..7b047a1 100644
9669 --- a/arch/x86/include/asm/desc.h
9670 +++ b/arch/x86/include/asm/desc.h
9671 @@ -4,6 +4,7 @@
9672 #include <asm/desc_defs.h>
9673 #include <asm/ldt.h>
9674 #include <asm/mmu.h>
9675 +#include <asm/pgtable.h>
9676 #include <linux/smp.h>
9677
9678 static inline void fill_ldt(struct desc_struct *desc,
9679 @@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_struct *desc,
9680 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9681 desc->type = (info->read_exec_only ^ 1) << 1;
9682 desc->type |= info->contents << 2;
9683 + desc->type |= info->seg_not_present ^ 1;
9684 desc->s = 1;
9685 desc->dpl = 0x3;
9686 desc->p = info->seg_not_present ^ 1;
9687 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_struct *desc,
9688 }
9689
9690 extern struct desc_ptr idt_descr;
9691 -extern gate_desc idt_table[];
9692 -
9693 -struct gdt_page {
9694 - struct desc_struct gdt[GDT_ENTRIES];
9695 -} __attribute__((aligned(PAGE_SIZE)));
9696 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9697 +extern gate_desc idt_table[256];
9698
9699 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9700 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9701 {
9702 - return per_cpu(gdt_page, cpu).gdt;
9703 + return cpu_gdt_table[cpu];
9704 }
9705
9706 #ifdef CONFIG_X86_64
9707 @@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9708 unsigned long base, unsigned dpl, unsigned flags,
9709 unsigned short seg)
9710 {
9711 - gate->a = (seg << 16) | (base & 0xffff);
9712 - gate->b = (base & 0xffff0000) |
9713 - (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9714 + gate->gate.offset_low = base;
9715 + gate->gate.seg = seg;
9716 + gate->gate.reserved = 0;
9717 + gate->gate.type = type;
9718 + gate->gate.s = 0;
9719 + gate->gate.dpl = dpl;
9720 + gate->gate.p = 1;
9721 + gate->gate.offset_high = base >> 16;
9722 }
9723
9724 #endif
9725 @@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9726 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9727 const gate_desc *gate)
9728 {
9729 + pax_open_kernel();
9730 memcpy(&idt[entry], gate, sizeof(*gate));
9731 + pax_close_kernel();
9732 }
9733
9734 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9735 const void *desc)
9736 {
9737 + pax_open_kernel();
9738 memcpy(&ldt[entry], desc, 8);
9739 + pax_close_kernel();
9740 }
9741
9742 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9743 @@ -139,7 +146,10 @@ static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9744 size = sizeof(struct desc_struct);
9745 break;
9746 }
9747 +
9748 + pax_open_kernel();
9749 memcpy(&gdt[entry], desc, size);
9750 + pax_close_kernel();
9751 }
9752
9753 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9754 @@ -211,7 +221,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9755
9756 static inline void native_load_tr_desc(void)
9757 {
9758 + pax_open_kernel();
9759 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9760 + pax_close_kernel();
9761 }
9762
9763 static inline void native_load_gdt(const struct desc_ptr *dtr)
9764 @@ -246,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9765 unsigned int i;
9766 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9767
9768 + pax_open_kernel();
9769 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9770 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9771 + pax_close_kernel();
9772 }
9773
9774 #define _LDT_empty(info) \
9775 @@ -309,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9776 desc->limit = (limit >> 16) & 0xf;
9777 }
9778
9779 -static inline void _set_gate(int gate, unsigned type, void *addr,
9780 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9781 unsigned dpl, unsigned ist, unsigned seg)
9782 {
9783 gate_desc s;
9784 @@ -327,7 +341,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9785 * Pentium F0 0F bugfix can have resulted in the mapped
9786 * IDT being write-protected.
9787 */
9788 -static inline void set_intr_gate(unsigned int n, void *addr)
9789 +static inline void set_intr_gate(unsigned int n, const void *addr)
9790 {
9791 BUG_ON((unsigned)n > 0xFF);
9792 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9793 @@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9794 /*
9795 * This routine sets up an interrupt gate at directory privilege level 3.
9796 */
9797 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9798 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9799 {
9800 BUG_ON((unsigned)n > 0xFF);
9801 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9802 }
9803
9804 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9805 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9806 {
9807 BUG_ON((unsigned)n > 0xFF);
9808 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9809 }
9810
9811 -static inline void set_trap_gate(unsigned int n, void *addr)
9812 +static inline void set_trap_gate(unsigned int n, const void *addr)
9813 {
9814 BUG_ON((unsigned)n > 0xFF);
9815 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9816 @@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9817 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9818 {
9819 BUG_ON((unsigned)n > 0xFF);
9820 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9821 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9822 }
9823
9824 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9825 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9826 {
9827 BUG_ON((unsigned)n > 0xFF);
9828 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9829 }
9830
9831 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9832 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9833 {
9834 BUG_ON((unsigned)n > 0xFF);
9835 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9836 }
9837
9838 +#ifdef CONFIG_X86_32
9839 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9840 +{
9841 + struct desc_struct d;
9842 +
9843 + if (likely(limit))
9844 + limit = (limit - 1UL) >> PAGE_SHIFT;
9845 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9846 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9847 +}
9848 +#endif
9849 +
9850 #endif /* _ASM_X86_DESC_H */
9851 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9852 index 9d66848..6b4a691 100644
9853 --- a/arch/x86/include/asm/desc_defs.h
9854 +++ b/arch/x86/include/asm/desc_defs.h
9855 @@ -31,6 +31,12 @@ struct desc_struct {
9856 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9857 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9858 };
9859 + struct {
9860 + u16 offset_low;
9861 + u16 seg;
9862 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9863 + unsigned offset_high: 16;
9864 + } gate;
9865 };
9866 } __attribute__((packed));
9867
9868 diff --git a/arch/x86/include/asm/device.h b/arch/x86/include/asm/device.h
9869 index cee34e9..a7c3fa2 100644
9870 --- a/arch/x86/include/asm/device.h
9871 +++ b/arch/x86/include/asm/device.h
9872 @@ -6,7 +6,7 @@ struct dev_archdata {
9873 void *acpi_handle;
9874 #endif
9875 #ifdef CONFIG_X86_64
9876 -struct dma_map_ops *dma_ops;
9877 + const struct dma_map_ops *dma_ops;
9878 #endif
9879 #ifdef CONFIG_DMAR
9880 void *iommu; /* hook for IOMMU specific extension */
9881 diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
9882 index 6a25d5d..786b202 100644
9883 --- a/arch/x86/include/asm/dma-mapping.h
9884 +++ b/arch/x86/include/asm/dma-mapping.h
9885 @@ -25,9 +25,9 @@ extern int iommu_merge;
9886 extern struct device x86_dma_fallback_dev;
9887 extern int panic_on_overflow;
9888
9889 -extern struct dma_map_ops *dma_ops;
9890 +extern const struct dma_map_ops *dma_ops;
9891
9892 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9893 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9894 {
9895 #ifdef CONFIG_X86_32
9896 return dma_ops;
9897 @@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9898 /* Make sure we keep the same behaviour */
9899 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9900 {
9901 - struct dma_map_ops *ops = get_dma_ops(dev);
9902 + const struct dma_map_ops *ops = get_dma_ops(dev);
9903 if (ops->mapping_error)
9904 return ops->mapping_error(dev, dma_addr);
9905
9906 @@ -122,7 +122,7 @@ static inline void *
9907 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9908 gfp_t gfp)
9909 {
9910 - struct dma_map_ops *ops = get_dma_ops(dev);
9911 + const struct dma_map_ops *ops = get_dma_ops(dev);
9912 void *memory;
9913
9914 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9915 @@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9916 static inline void dma_free_coherent(struct device *dev, size_t size,
9917 void *vaddr, dma_addr_t bus)
9918 {
9919 - struct dma_map_ops *ops = get_dma_ops(dev);
9920 + const struct dma_map_ops *ops = get_dma_ops(dev);
9921
9922 WARN_ON(irqs_disabled()); /* for portability */
9923
9924 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9925 index 40b4e61..40d8133 100644
9926 --- a/arch/x86/include/asm/e820.h
9927 +++ b/arch/x86/include/asm/e820.h
9928 @@ -133,7 +133,7 @@ extern char *default_machine_specific_memory_setup(void);
9929 #define ISA_END_ADDRESS 0x100000
9930 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
9931
9932 -#define BIOS_BEGIN 0x000a0000
9933 +#define BIOS_BEGIN 0x000c0000
9934 #define BIOS_END 0x00100000
9935
9936 #ifdef __KERNEL__
9937 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9938 index 8ac9d9a..0a6c96e 100644
9939 --- a/arch/x86/include/asm/elf.h
9940 +++ b/arch/x86/include/asm/elf.h
9941 @@ -257,7 +257,25 @@ extern int force_personality32;
9942 the loader. We need to make sure that it is out of the way of the program
9943 that it will "exec", and that there is sufficient room for the brk. */
9944
9945 +#ifdef CONFIG_PAX_SEGMEXEC
9946 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9947 +#else
9948 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9949 +#endif
9950 +
9951 +#ifdef CONFIG_PAX_ASLR
9952 +#ifdef CONFIG_X86_32
9953 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9954 +
9955 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9956 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9957 +#else
9958 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9959 +
9960 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9961 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9962 +#endif
9963 +#endif
9964
9965 /* This yields a mask that user programs can use to figure out what
9966 instruction set this CPU supports. This could be done in user space,
9967 @@ -310,9 +328,7 @@ do { \
9968
9969 #define ARCH_DLINFO \
9970 do { \
9971 - if (vdso_enabled) \
9972 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9973 - (unsigned long)current->mm->context.vdso); \
9974 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9975 } while (0)
9976
9977 #define AT_SYSINFO 32
9978 @@ -323,7 +339,7 @@ do { \
9979
9980 #endif /* !CONFIG_X86_32 */
9981
9982 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9983 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9984
9985 #define VDSO_ENTRY \
9986 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9987 @@ -337,7 +353,4 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
9988 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9989 #define compat_arch_setup_additional_pages syscall32_setup_pages
9990
9991 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9992 -#define arch_randomize_brk arch_randomize_brk
9993 -
9994 #endif /* _ASM_X86_ELF_H */
9995 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
9996 index cc70c1c..d96d011 100644
9997 --- a/arch/x86/include/asm/emergency-restart.h
9998 +++ b/arch/x86/include/asm/emergency-restart.h
9999 @@ -15,6 +15,6 @@ enum reboot_type {
10000
10001 extern enum reboot_type reboot_type;
10002
10003 -extern void machine_emergency_restart(void);
10004 +extern void machine_emergency_restart(void) __noreturn;
10005
10006 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10007 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10008 index 1f11ce4..7caabd1 100644
10009 --- a/arch/x86/include/asm/futex.h
10010 +++ b/arch/x86/include/asm/futex.h
10011 @@ -12,16 +12,18 @@
10012 #include <asm/system.h>
10013
10014 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10015 + typecheck(u32 __user *, uaddr); \
10016 asm volatile("1:\t" insn "\n" \
10017 "2:\t.section .fixup,\"ax\"\n" \
10018 "3:\tmov\t%3, %1\n" \
10019 "\tjmp\t2b\n" \
10020 "\t.previous\n" \
10021 _ASM_EXTABLE(1b, 3b) \
10022 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10023 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10024 : "i" (-EFAULT), "0" (oparg), "1" (0))
10025
10026 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10027 + typecheck(u32 __user *, uaddr); \
10028 asm volatile("1:\tmovl %2, %0\n" \
10029 "\tmovl\t%0, %3\n" \
10030 "\t" insn "\n" \
10031 @@ -34,10 +36,10 @@
10032 _ASM_EXTABLE(1b, 4b) \
10033 _ASM_EXTABLE(2b, 4b) \
10034 : "=&a" (oldval), "=&r" (ret), \
10035 - "+m" (*uaddr), "=&r" (tem) \
10036 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10037 : "r" (oparg), "i" (-EFAULT), "1" (0))
10038
10039 -static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10040 +static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10041 {
10042 int op = (encoded_op >> 28) & 7;
10043 int cmp = (encoded_op >> 24) & 15;
10044 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10045
10046 switch (op) {
10047 case FUTEX_OP_SET:
10048 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10049 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10050 break;
10051 case FUTEX_OP_ADD:
10052 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10053 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10054 uaddr, oparg);
10055 break;
10056 case FUTEX_OP_OR:
10057 @@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10058 return ret;
10059 }
10060
10061 -static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
10062 +static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
10063 int newval)
10064 {
10065
10066 @@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
10067 return -ENOSYS;
10068 #endif
10069
10070 - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
10071 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10072 return -EFAULT;
10073
10074 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
10075 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
10076 "2:\t.section .fixup, \"ax\"\n"
10077 "3:\tmov %2, %0\n"
10078 "\tjmp 2b\n"
10079 "\t.previous\n"
10080 _ASM_EXTABLE(1b, 3b)
10081 - : "=a" (oldval), "+m" (*uaddr)
10082 + : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
10083 : "i" (-EFAULT), "r" (newval), "0" (oldval)
10084 : "memory"
10085 );
10086 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10087 index ba180d9..3bad351 100644
10088 --- a/arch/x86/include/asm/hw_irq.h
10089 +++ b/arch/x86/include/asm/hw_irq.h
10090 @@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
10091 extern void enable_IO_APIC(void);
10092
10093 /* Statistics */
10094 -extern atomic_t irq_err_count;
10095 -extern atomic_t irq_mis_count;
10096 +extern atomic_unchecked_t irq_err_count;
10097 +extern atomic_unchecked_t irq_mis_count;
10098
10099 /* EISA */
10100 extern void eisa_set_level_irq(unsigned int irq);
10101 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10102 index 0b20bbb..4cb1396 100644
10103 --- a/arch/x86/include/asm/i387.h
10104 +++ b/arch/x86/include/asm/i387.h
10105 @@ -60,6 +60,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10106 {
10107 int err;
10108
10109 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10110 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10111 + fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
10112 +#endif
10113 +
10114 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
10115 "2:\n"
10116 ".section .fixup,\"ax\"\n"
10117 @@ -105,6 +110,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10118 {
10119 int err;
10120
10121 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10122 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10123 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10124 +#endif
10125 +
10126 asm volatile("1: rex64/fxsave (%[fx])\n\t"
10127 "2:\n"
10128 ".section .fixup,\"ax\"\n"
10129 @@ -195,13 +205,8 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10130 }
10131
10132 /* We need a safe address that is cheap to find and that is already
10133 - in L1 during context switch. The best choices are unfortunately
10134 - different for UP and SMP */
10135 -#ifdef CONFIG_SMP
10136 -#define safe_address (__per_cpu_offset[0])
10137 -#else
10138 -#define safe_address (kstat_cpu(0).cpustat.user)
10139 -#endif
10140 + in L1 during context switch. */
10141 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
10142
10143 /*
10144 * These must be called with preempt disabled
10145 @@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void)
10146 struct thread_info *me = current_thread_info();
10147 preempt_disable();
10148 if (me->status & TS_USEDFPU)
10149 - __save_init_fpu(me->task);
10150 + __save_init_fpu(current);
10151 else
10152 clts();
10153 }
10154 diff --git a/arch/x86/include/asm/io_32.h b/arch/x86/include/asm/io_32.h
10155 index a299900..15c5410 100644
10156 --- a/arch/x86/include/asm/io_32.h
10157 +++ b/arch/x86/include/asm/io_32.h
10158 @@ -3,6 +3,7 @@
10159
10160 #include <linux/string.h>
10161 #include <linux/compiler.h>
10162 +#include <asm/processor.h>
10163
10164 /*
10165 * This file contains the definitions for the x86 IO instructions
10166 @@ -42,6 +43,17 @@
10167
10168 #ifdef __KERNEL__
10169
10170 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10171 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10172 +{
10173 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10174 +}
10175 +
10176 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10177 +{
10178 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10179 +}
10180 +
10181 #include <asm-generic/iomap.h>
10182
10183 #include <linux/vmalloc.h>
10184 diff --git a/arch/x86/include/asm/io_64.h b/arch/x86/include/asm/io_64.h
10185 index 2440678..c158b88 100644
10186 --- a/arch/x86/include/asm/io_64.h
10187 +++ b/arch/x86/include/asm/io_64.h
10188 @@ -140,6 +140,17 @@ __OUTS(l)
10189
10190 #include <linux/vmalloc.h>
10191
10192 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10193 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10194 +{
10195 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10196 +}
10197 +
10198 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10199 +{
10200 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10201 +}
10202 +
10203 #include <asm-generic/iomap.h>
10204
10205 void __memcpy_fromio(void *, unsigned long, unsigned);
10206 diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
10207 index fd6d21b..8b13915 100644
10208 --- a/arch/x86/include/asm/iommu.h
10209 +++ b/arch/x86/include/asm/iommu.h
10210 @@ -3,7 +3,7 @@
10211
10212 extern void pci_iommu_shutdown(void);
10213 extern void no_iommu_init(void);
10214 -extern struct dma_map_ops nommu_dma_ops;
10215 +extern const struct dma_map_ops nommu_dma_ops;
10216 extern int force_iommu, no_iommu;
10217 extern int iommu_detected;
10218 extern int iommu_pass_through;
10219 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10220 index 9e2b952..557206e 100644
10221 --- a/arch/x86/include/asm/irqflags.h
10222 +++ b/arch/x86/include/asm/irqflags.h
10223 @@ -142,6 +142,11 @@ static inline unsigned long __raw_local_irq_save(void)
10224 sti; \
10225 sysexit
10226
10227 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10228 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10229 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10230 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10231 +
10232 #else
10233 #define INTERRUPT_RETURN iret
10234 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10235 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10236 index 4fe681d..bb6d40c 100644
10237 --- a/arch/x86/include/asm/kprobes.h
10238 +++ b/arch/x86/include/asm/kprobes.h
10239 @@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
10240 #define BREAKPOINT_INSTRUCTION 0xcc
10241 #define RELATIVEJUMP_INSTRUCTION 0xe9
10242 #define MAX_INSN_SIZE 16
10243 -#define MAX_STACK_SIZE 64
10244 -#define MIN_STACK_SIZE(ADDR) \
10245 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10246 - THREAD_SIZE - (unsigned long)(ADDR))) \
10247 - ? (MAX_STACK_SIZE) \
10248 - : (((unsigned long)current_thread_info()) + \
10249 - THREAD_SIZE - (unsigned long)(ADDR)))
10250 +#define MAX_STACK_SIZE 64UL
10251 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10252
10253 #define flush_insn_slot(p) do { } while (0)
10254
10255 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10256 index 08bc2ff..2e88d1f 100644
10257 --- a/arch/x86/include/asm/kvm_host.h
10258 +++ b/arch/x86/include/asm/kvm_host.h
10259 @@ -534,9 +534,9 @@ struct kvm_x86_ops {
10260 bool (*gb_page_enable)(void);
10261
10262 const struct trace_print_flags *exit_reasons_str;
10263 -};
10264 +} __do_const;
10265
10266 -extern struct kvm_x86_ops *kvm_x86_ops;
10267 +extern const struct kvm_x86_ops *kvm_x86_ops;
10268
10269 int kvm_mmu_module_init(void);
10270 void kvm_mmu_module_exit(void);
10271 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10272 index 47b9b6f..815aaa1 100644
10273 --- a/arch/x86/include/asm/local.h
10274 +++ b/arch/x86/include/asm/local.h
10275 @@ -18,26 +18,58 @@ typedef struct {
10276
10277 static inline void local_inc(local_t *l)
10278 {
10279 - asm volatile(_ASM_INC "%0"
10280 + asm volatile(_ASM_INC "%0\n"
10281 +
10282 +#ifdef CONFIG_PAX_REFCOUNT
10283 + "jno 0f\n"
10284 + _ASM_DEC "%0\n"
10285 + "int $4\n0:\n"
10286 + _ASM_EXTABLE(0b, 0b)
10287 +#endif
10288 +
10289 : "+m" (l->a.counter));
10290 }
10291
10292 static inline void local_dec(local_t *l)
10293 {
10294 - asm volatile(_ASM_DEC "%0"
10295 + asm volatile(_ASM_DEC "%0\n"
10296 +
10297 +#ifdef CONFIG_PAX_REFCOUNT
10298 + "jno 0f\n"
10299 + _ASM_INC "%0\n"
10300 + "int $4\n0:\n"
10301 + _ASM_EXTABLE(0b, 0b)
10302 +#endif
10303 +
10304 : "+m" (l->a.counter));
10305 }
10306
10307 static inline void local_add(long i, local_t *l)
10308 {
10309 - asm volatile(_ASM_ADD "%1,%0"
10310 + asm volatile(_ASM_ADD "%1,%0\n"
10311 +
10312 +#ifdef CONFIG_PAX_REFCOUNT
10313 + "jno 0f\n"
10314 + _ASM_SUB "%1,%0\n"
10315 + "int $4\n0:\n"
10316 + _ASM_EXTABLE(0b, 0b)
10317 +#endif
10318 +
10319 : "+m" (l->a.counter)
10320 : "ir" (i));
10321 }
10322
10323 static inline void local_sub(long i, local_t *l)
10324 {
10325 - asm volatile(_ASM_SUB "%1,%0"
10326 + asm volatile(_ASM_SUB "%1,%0\n"
10327 +
10328 +#ifdef CONFIG_PAX_REFCOUNT
10329 + "jno 0f\n"
10330 + _ASM_ADD "%1,%0\n"
10331 + "int $4\n0:\n"
10332 + _ASM_EXTABLE(0b, 0b)
10333 +#endif
10334 +
10335 : "+m" (l->a.counter)
10336 : "ir" (i));
10337 }
10338 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10339 {
10340 unsigned char c;
10341
10342 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10343 + asm volatile(_ASM_SUB "%2,%0\n"
10344 +
10345 +#ifdef CONFIG_PAX_REFCOUNT
10346 + "jno 0f\n"
10347 + _ASM_ADD "%2,%0\n"
10348 + "int $4\n0:\n"
10349 + _ASM_EXTABLE(0b, 0b)
10350 +#endif
10351 +
10352 + "sete %1\n"
10353 : "+m" (l->a.counter), "=qm" (c)
10354 : "ir" (i) : "memory");
10355 return c;
10356 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10357 {
10358 unsigned char c;
10359
10360 - asm volatile(_ASM_DEC "%0; sete %1"
10361 + asm volatile(_ASM_DEC "%0\n"
10362 +
10363 +#ifdef CONFIG_PAX_REFCOUNT
10364 + "jno 0f\n"
10365 + _ASM_INC "%0\n"
10366 + "int $4\n0:\n"
10367 + _ASM_EXTABLE(0b, 0b)
10368 +#endif
10369 +
10370 + "sete %1\n"
10371 : "+m" (l->a.counter), "=qm" (c)
10372 : : "memory");
10373 return c != 0;
10374 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10375 {
10376 unsigned char c;
10377
10378 - asm volatile(_ASM_INC "%0; sete %1"
10379 + asm volatile(_ASM_INC "%0\n"
10380 +
10381 +#ifdef CONFIG_PAX_REFCOUNT
10382 + "jno 0f\n"
10383 + _ASM_DEC "%0\n"
10384 + "int $4\n0:\n"
10385 + _ASM_EXTABLE(0b, 0b)
10386 +#endif
10387 +
10388 + "sete %1\n"
10389 : "+m" (l->a.counter), "=qm" (c)
10390 : : "memory");
10391 return c != 0;
10392 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10393 {
10394 unsigned char c;
10395
10396 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10397 + asm volatile(_ASM_ADD "%2,%0\n"
10398 +
10399 +#ifdef CONFIG_PAX_REFCOUNT
10400 + "jno 0f\n"
10401 + _ASM_SUB "%2,%0\n"
10402 + "int $4\n0:\n"
10403 + _ASM_EXTABLE(0b, 0b)
10404 +#endif
10405 +
10406 + "sets %1\n"
10407 : "+m" (l->a.counter), "=qm" (c)
10408 : "ir" (i) : "memory");
10409 return c;
10410 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10411 #endif
10412 /* Modern 486+ processor */
10413 __i = i;
10414 - asm volatile(_ASM_XADD "%0, %1;"
10415 + asm volatile(_ASM_XADD "%0, %1\n"
10416 +
10417 +#ifdef CONFIG_PAX_REFCOUNT
10418 + "jno 0f\n"
10419 + _ASM_MOV "%0,%1\n"
10420 + "int $4\n0:\n"
10421 + _ASM_EXTABLE(0b, 0b)
10422 +#endif
10423 +
10424 : "+r" (i), "+m" (l->a.counter)
10425 : : "memory");
10426 return i + __i;
10427 diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
10428 index ef51b50..514ba37 100644
10429 --- a/arch/x86/include/asm/microcode.h
10430 +++ b/arch/x86/include/asm/microcode.h
10431 @@ -12,13 +12,13 @@ struct device;
10432 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
10433
10434 struct microcode_ops {
10435 - enum ucode_state (*request_microcode_user) (int cpu,
10436 + enum ucode_state (* const request_microcode_user) (int cpu,
10437 const void __user *buf, size_t size);
10438
10439 - enum ucode_state (*request_microcode_fw) (int cpu,
10440 + enum ucode_state (* const request_microcode_fw) (int cpu,
10441 struct device *device);
10442
10443 - void (*microcode_fini_cpu) (int cpu);
10444 + void (* const microcode_fini_cpu) (int cpu);
10445
10446 /*
10447 * The generic 'microcode_core' part guarantees that
10448 @@ -38,18 +38,18 @@ struct ucode_cpu_info {
10449 extern struct ucode_cpu_info ucode_cpu_info[];
10450
10451 #ifdef CONFIG_MICROCODE_INTEL
10452 -extern struct microcode_ops * __init init_intel_microcode(void);
10453 +extern const struct microcode_ops * __init init_intel_microcode(void);
10454 #else
10455 -static inline struct microcode_ops * __init init_intel_microcode(void)
10456 +static inline const struct microcode_ops * __init init_intel_microcode(void)
10457 {
10458 return NULL;
10459 }
10460 #endif /* CONFIG_MICROCODE_INTEL */
10461
10462 #ifdef CONFIG_MICROCODE_AMD
10463 -extern struct microcode_ops * __init init_amd_microcode(void);
10464 +extern const struct microcode_ops * __init init_amd_microcode(void);
10465 #else
10466 -static inline struct microcode_ops * __init init_amd_microcode(void)
10467 +static inline const struct microcode_ops * __init init_amd_microcode(void)
10468 {
10469 return NULL;
10470 }
10471 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10472 index 593e51d..fa69c9a 100644
10473 --- a/arch/x86/include/asm/mman.h
10474 +++ b/arch/x86/include/asm/mman.h
10475 @@ -5,4 +5,14 @@
10476
10477 #include <asm-generic/mman.h>
10478
10479 +#ifdef __KERNEL__
10480 +#ifndef __ASSEMBLY__
10481 +#ifdef CONFIG_X86_32
10482 +#define arch_mmap_check i386_mmap_check
10483 +int i386_mmap_check(unsigned long addr, unsigned long len,
10484 + unsigned long flags);
10485 +#endif
10486 +#endif
10487 +#endif
10488 +
10489 #endif /* _ASM_X86_MMAN_H */
10490 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10491 index 80a1dee..239c67d 100644
10492 --- a/arch/x86/include/asm/mmu.h
10493 +++ b/arch/x86/include/asm/mmu.h
10494 @@ -9,10 +9,23 @@
10495 * we put the segment information here.
10496 */
10497 typedef struct {
10498 - void *ldt;
10499 + struct desc_struct *ldt;
10500 int size;
10501 struct mutex lock;
10502 - void *vdso;
10503 + unsigned long vdso;
10504 +
10505 +#ifdef CONFIG_X86_32
10506 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10507 + unsigned long user_cs_base;
10508 + unsigned long user_cs_limit;
10509 +
10510 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10511 + cpumask_t cpu_user_cs_mask;
10512 +#endif
10513 +
10514 +#endif
10515 +#endif
10516 +
10517 } mm_context_t;
10518
10519 #ifdef CONFIG_SMP
10520 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10521 index 8b5393e..8143173 100644
10522 --- a/arch/x86/include/asm/mmu_context.h
10523 +++ b/arch/x86/include/asm/mmu_context.h
10524 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10525
10526 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10527 {
10528 +
10529 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10530 + unsigned int i;
10531 + pgd_t *pgd;
10532 +
10533 + pax_open_kernel();
10534 + pgd = get_cpu_pgd(smp_processor_id());
10535 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10536 + set_pgd_batched(pgd+i, native_make_pgd(0));
10537 + pax_close_kernel();
10538 +#endif
10539 +
10540 #ifdef CONFIG_SMP
10541 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10542 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10543 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10544 struct task_struct *tsk)
10545 {
10546 unsigned cpu = smp_processor_id();
10547 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)) && defined(CONFIG_SMP)
10548 + int tlbstate = TLBSTATE_OK;
10549 +#endif
10550
10551 if (likely(prev != next)) {
10552 #ifdef CONFIG_SMP
10553 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10554 + tlbstate = percpu_read(cpu_tlbstate.state);
10555 +#endif
10556 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10557 percpu_write(cpu_tlbstate.active_mm, next);
10558 #endif
10559 cpumask_set_cpu(cpu, mm_cpumask(next));
10560
10561 /* Re-load page tables */
10562 +#ifdef CONFIG_PAX_PER_CPU_PGD
10563 + pax_open_kernel();
10564 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10565 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10566 + pax_close_kernel();
10567 + load_cr3(get_cpu_pgd(cpu));
10568 +#else
10569 load_cr3(next->pgd);
10570 +#endif
10571
10572 /* stop flush ipis for the previous mm */
10573 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10574 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10575 */
10576 if (unlikely(prev->context.ldt != next->context.ldt))
10577 load_LDT_nolock(&next->context);
10578 - }
10579 +
10580 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10581 + if (!nx_enabled) {
10582 + smp_mb__before_clear_bit();
10583 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10584 + smp_mb__after_clear_bit();
10585 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10586 + }
10587 +#endif
10588 +
10589 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10590 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10591 + prev->context.user_cs_limit != next->context.user_cs_limit))
10592 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10593 #ifdef CONFIG_SMP
10594 + else if (unlikely(tlbstate != TLBSTATE_OK))
10595 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10596 +#endif
10597 +#endif
10598 +
10599 + }
10600 else {
10601 +
10602 +#ifdef CONFIG_PAX_PER_CPU_PGD
10603 + pax_open_kernel();
10604 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10605 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10606 + pax_close_kernel();
10607 + load_cr3(get_cpu_pgd(cpu));
10608 +#endif
10609 +
10610 +#ifdef CONFIG_SMP
10611 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10612 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10613
10614 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10615 * tlb flush IPI delivery. We must reload CR3
10616 * to make sure to use no freed page tables.
10617 */
10618 +
10619 +#ifndef CONFIG_PAX_PER_CPU_PGD
10620 load_cr3(next->pgd);
10621 +#endif
10622 +
10623 load_LDT_nolock(&next->context);
10624 +
10625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10626 + if (!nx_enabled)
10627 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10628 +#endif
10629 +
10630 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10631 +#ifdef CONFIG_PAX_PAGEEXEC
10632 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
10633 +#endif
10634 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10635 +#endif
10636 +
10637 }
10638 +#endif
10639 }
10640 -#endif
10641 }
10642
10643 #define activate_mm(prev, next) \
10644 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10645 index 3e2ce58..caaf478 100644
10646 --- a/arch/x86/include/asm/module.h
10647 +++ b/arch/x86/include/asm/module.h
10648 @@ -5,6 +5,7 @@
10649
10650 #ifdef CONFIG_X86_64
10651 /* X86_64 does not define MODULE_PROC_FAMILY */
10652 +#define MODULE_PROC_FAMILY ""
10653 #elif defined CONFIG_M386
10654 #define MODULE_PROC_FAMILY "386 "
10655 #elif defined CONFIG_M486
10656 @@ -59,13 +60,26 @@
10657 #error unknown processor family
10658 #endif
10659
10660 -#ifdef CONFIG_X86_32
10661 -# ifdef CONFIG_4KSTACKS
10662 -# define MODULE_STACKSIZE "4KSTACKS "
10663 -# else
10664 -# define MODULE_STACKSIZE ""
10665 -# endif
10666 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
10667 +#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
10668 +#define MODULE_STACKSIZE "4KSTACKS "
10669 +#else
10670 +#define MODULE_STACKSIZE ""
10671 #endif
10672
10673 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10674 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10675 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10676 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10677 +#else
10678 +#define MODULE_PAX_KERNEXEC ""
10679 +#endif
10680 +
10681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10682 +#define MODULE_PAX_UDEREF "UDEREF "
10683 +#else
10684 +#define MODULE_PAX_UDEREF ""
10685 +#endif
10686 +
10687 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10688 +
10689 #endif /* _ASM_X86_MODULE_H */
10690 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10691 index 7639dbf..e08a58c 100644
10692 --- a/arch/x86/include/asm/page_64_types.h
10693 +++ b/arch/x86/include/asm/page_64_types.h
10694 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10695
10696 /* duplicated to the one in bootmem.h */
10697 extern unsigned long max_pfn;
10698 -extern unsigned long phys_base;
10699 +extern const unsigned long phys_base;
10700
10701 extern unsigned long __phys_addr(unsigned long);
10702 #define __phys_reloc_hide(x) (x)
10703 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10704 index efb3899..ef30687 100644
10705 --- a/arch/x86/include/asm/paravirt.h
10706 +++ b/arch/x86/include/asm/paravirt.h
10707 @@ -648,6 +648,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10708 val);
10709 }
10710
10711 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10712 +{
10713 + pgdval_t val = native_pgd_val(pgd);
10714 +
10715 + if (sizeof(pgdval_t) > sizeof(long))
10716 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10717 + val, (u64)val >> 32);
10718 + else
10719 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10720 + val);
10721 +}
10722 +
10723 static inline void pgd_clear(pgd_t *pgdp)
10724 {
10725 set_pgd(pgdp, __pgd(0));
10726 @@ -729,6 +741,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10727 pv_mmu_ops.set_fixmap(idx, phys, flags);
10728 }
10729
10730 +#ifdef CONFIG_PAX_KERNEXEC
10731 +static inline unsigned long pax_open_kernel(void)
10732 +{
10733 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10734 +}
10735 +
10736 +static inline unsigned long pax_close_kernel(void)
10737 +{
10738 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10739 +}
10740 +#else
10741 +static inline unsigned long pax_open_kernel(void) { return 0; }
10742 +static inline unsigned long pax_close_kernel(void) { return 0; }
10743 +#endif
10744 +
10745 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10746
10747 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
10748 @@ -945,7 +972,7 @@ extern void default_banner(void);
10749
10750 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10751 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10752 -#define PARA_INDIRECT(addr) *%cs:addr
10753 +#define PARA_INDIRECT(addr) *%ss:addr
10754 #endif
10755
10756 #define INTERRUPT_RETURN \
10757 @@ -1022,6 +1049,21 @@ extern void default_banner(void);
10758 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10759 CLBR_NONE, \
10760 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10761 +
10762 +#define GET_CR0_INTO_RDI \
10763 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10764 + mov %rax,%rdi
10765 +
10766 +#define SET_RDI_INTO_CR0 \
10767 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10768 +
10769 +#define GET_CR3_INTO_RDI \
10770 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10771 + mov %rax,%rdi
10772 +
10773 +#define SET_RDI_INTO_CR3 \
10774 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10775 +
10776 #endif /* CONFIG_X86_32 */
10777
10778 #endif /* __ASSEMBLY__ */
10779 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10780 index 9357473..aeb2de5 100644
10781 --- a/arch/x86/include/asm/paravirt_types.h
10782 +++ b/arch/x86/include/asm/paravirt_types.h
10783 @@ -78,19 +78,19 @@ struct pv_init_ops {
10784 */
10785 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10786 unsigned long addr, unsigned len);
10787 -};
10788 +} __no_const;
10789
10790
10791 struct pv_lazy_ops {
10792 /* Set deferred update mode, used for batching operations. */
10793 void (*enter)(void);
10794 void (*leave)(void);
10795 -};
10796 +} __no_const;
10797
10798 struct pv_time_ops {
10799 unsigned long long (*sched_clock)(void);
10800 unsigned long (*get_tsc_khz)(void);
10801 -};
10802 +} __no_const;
10803
10804 struct pv_cpu_ops {
10805 /* hooks for various privileged instructions */
10806 @@ -186,7 +186,7 @@ struct pv_cpu_ops {
10807
10808 void (*start_context_switch)(struct task_struct *prev);
10809 void (*end_context_switch)(struct task_struct *next);
10810 -};
10811 +} __no_const;
10812
10813 struct pv_irq_ops {
10814 /*
10815 @@ -217,7 +217,7 @@ struct pv_apic_ops {
10816 unsigned long start_eip,
10817 unsigned long start_esp);
10818 #endif
10819 -};
10820 +} __no_const;
10821
10822 struct pv_mmu_ops {
10823 unsigned long (*read_cr2)(void);
10824 @@ -301,6 +301,7 @@ struct pv_mmu_ops {
10825 struct paravirt_callee_save make_pud;
10826
10827 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10828 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10829 #endif /* PAGETABLE_LEVELS == 4 */
10830 #endif /* PAGETABLE_LEVELS >= 3 */
10831
10832 @@ -316,6 +317,12 @@ struct pv_mmu_ops {
10833 an mfn. We can tell which is which from the index. */
10834 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10835 phys_addr_t phys, pgprot_t flags);
10836 +
10837 +#ifdef CONFIG_PAX_KERNEXEC
10838 + unsigned long (*pax_open_kernel)(void);
10839 + unsigned long (*pax_close_kernel)(void);
10840 +#endif
10841 +
10842 };
10843
10844 struct raw_spinlock;
10845 @@ -326,7 +333,7 @@ struct pv_lock_ops {
10846 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
10847 int (*spin_trylock)(struct raw_spinlock *lock);
10848 void (*spin_unlock)(struct raw_spinlock *lock);
10849 -};
10850 +} __no_const;
10851
10852 /* This contains all the paravirt structures: we get a convenient
10853 * number for each function using the offset which we use to indicate
10854 diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
10855 index b399988..3f47c38 100644
10856 --- a/arch/x86/include/asm/pci_x86.h
10857 +++ b/arch/x86/include/asm/pci_x86.h
10858 @@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct pci_dev *dev);
10859 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10860
10861 struct pci_raw_ops {
10862 - int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10863 + int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10864 int reg, int len, u32 *val);
10865 - int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10866 + int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10867 int reg, int len, u32 val);
10868 };
10869
10870 -extern struct pci_raw_ops *raw_pci_ops;
10871 -extern struct pci_raw_ops *raw_pci_ext_ops;
10872 +extern const struct pci_raw_ops *raw_pci_ops;
10873 +extern const struct pci_raw_ops *raw_pci_ext_ops;
10874
10875 -extern struct pci_raw_ops pci_direct_conf1;
10876 +extern const struct pci_raw_ops pci_direct_conf1;
10877 extern bool port_cf9_safe;
10878
10879 /* arch_initcall level */
10880 diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
10881 index b65a36d..50345a4 100644
10882 --- a/arch/x86/include/asm/percpu.h
10883 +++ b/arch/x86/include/asm/percpu.h
10884 @@ -78,6 +78,7 @@ do { \
10885 if (0) { \
10886 T__ tmp__; \
10887 tmp__ = (val); \
10888 + (void)tmp__; \
10889 } \
10890 switch (sizeof(var)) { \
10891 case 1: \
10892 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10893 index 271de94..ef944d6 100644
10894 --- a/arch/x86/include/asm/pgalloc.h
10895 +++ b/arch/x86/include/asm/pgalloc.h
10896 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10897 pmd_t *pmd, pte_t *pte)
10898 {
10899 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10900 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10901 +}
10902 +
10903 +static inline void pmd_populate_user(struct mm_struct *mm,
10904 + pmd_t *pmd, pte_t *pte)
10905 +{
10906 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10907 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10908 }
10909
10910 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10911 index 2334982..70bc412 100644
10912 --- a/arch/x86/include/asm/pgtable-2level.h
10913 +++ b/arch/x86/include/asm/pgtable-2level.h
10914 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10915
10916 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10917 {
10918 + pax_open_kernel();
10919 *pmdp = pmd;
10920 + pax_close_kernel();
10921 }
10922
10923 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10924 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10925 index 33927d2..ccde329 100644
10926 --- a/arch/x86/include/asm/pgtable-3level.h
10927 +++ b/arch/x86/include/asm/pgtable-3level.h
10928 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10929
10930 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10931 {
10932 + pax_open_kernel();
10933 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10934 + pax_close_kernel();
10935 }
10936
10937 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10938 {
10939 + pax_open_kernel();
10940 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10941 + pax_close_kernel();
10942 }
10943
10944 /*
10945 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10946 index af6fd36..867ff74 100644
10947 --- a/arch/x86/include/asm/pgtable.h
10948 +++ b/arch/x86/include/asm/pgtable.h
10949 @@ -39,6 +39,7 @@ extern struct list_head pgd_list;
10950
10951 #ifndef __PAGETABLE_PUD_FOLDED
10952 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10953 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10954 #define pgd_clear(pgd) native_pgd_clear(pgd)
10955 #endif
10956
10957 @@ -74,12 +75,51 @@ extern struct list_head pgd_list;
10958
10959 #define arch_end_context_switch(prev) do {} while(0)
10960
10961 +#define pax_open_kernel() native_pax_open_kernel()
10962 +#define pax_close_kernel() native_pax_close_kernel()
10963 #endif /* CONFIG_PARAVIRT */
10964
10965 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10966 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10967 +
10968 +#ifdef CONFIG_PAX_KERNEXEC
10969 +static inline unsigned long native_pax_open_kernel(void)
10970 +{
10971 + unsigned long cr0;
10972 +
10973 + preempt_disable();
10974 + barrier();
10975 + cr0 = read_cr0() ^ X86_CR0_WP;
10976 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10977 + write_cr0(cr0);
10978 + return cr0 ^ X86_CR0_WP;
10979 +}
10980 +
10981 +static inline unsigned long native_pax_close_kernel(void)
10982 +{
10983 + unsigned long cr0;
10984 +
10985 + cr0 = read_cr0() ^ X86_CR0_WP;
10986 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10987 + write_cr0(cr0);
10988 + barrier();
10989 + preempt_enable_no_resched();
10990 + return cr0 ^ X86_CR0_WP;
10991 +}
10992 +#else
10993 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10994 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10995 +#endif
10996 +
10997 /*
10998 * The following only work if pte_present() is true.
10999 * Undefined behaviour if not..
11000 */
11001 +static inline int pte_user(pte_t pte)
11002 +{
11003 + return pte_val(pte) & _PAGE_USER;
11004 +}
11005 +
11006 static inline int pte_dirty(pte_t pte)
11007 {
11008 return pte_flags(pte) & _PAGE_DIRTY;
11009 @@ -167,9 +207,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11010 return pte_clear_flags(pte, _PAGE_RW);
11011 }
11012
11013 +static inline pte_t pte_mkread(pte_t pte)
11014 +{
11015 + return __pte(pte_val(pte) | _PAGE_USER);
11016 +}
11017 +
11018 static inline pte_t pte_mkexec(pte_t pte)
11019 {
11020 - return pte_clear_flags(pte, _PAGE_NX);
11021 +#ifdef CONFIG_X86_PAE
11022 + if (__supported_pte_mask & _PAGE_NX)
11023 + return pte_clear_flags(pte, _PAGE_NX);
11024 + else
11025 +#endif
11026 + return pte_set_flags(pte, _PAGE_USER);
11027 +}
11028 +
11029 +static inline pte_t pte_exprotect(pte_t pte)
11030 +{
11031 +#ifdef CONFIG_X86_PAE
11032 + if (__supported_pte_mask & _PAGE_NX)
11033 + return pte_set_flags(pte, _PAGE_NX);
11034 + else
11035 +#endif
11036 + return pte_clear_flags(pte, _PAGE_USER);
11037 }
11038
11039 static inline pte_t pte_mkdirty(pte_t pte)
11040 @@ -302,6 +362,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11041 #endif
11042
11043 #ifndef __ASSEMBLY__
11044 +
11045 +#ifdef CONFIG_PAX_PER_CPU_PGD
11046 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11047 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11048 +{
11049 + return cpu_pgd[cpu];
11050 +}
11051 +#endif
11052 +
11053 #include <linux/mm_types.h>
11054
11055 static inline int pte_none(pte_t pte)
11056 @@ -472,7 +541,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11057
11058 static inline int pgd_bad(pgd_t pgd)
11059 {
11060 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11061 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11062 }
11063
11064 static inline int pgd_none(pgd_t pgd)
11065 @@ -495,7 +564,12 @@ static inline int pgd_none(pgd_t pgd)
11066 * pgd_offset() returns a (pgd_t *)
11067 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11068 */
11069 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11070 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11071 +
11072 +#ifdef CONFIG_PAX_PER_CPU_PGD
11073 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11074 +#endif
11075 +
11076 /*
11077 * a shortcut which implies the use of the kernel's pgd, instead
11078 * of a process's
11079 @@ -506,6 +580,20 @@ static inline int pgd_none(pgd_t pgd)
11080 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11081 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11082
11083 +#ifdef CONFIG_X86_32
11084 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11085 +#else
11086 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11087 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11088 +
11089 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11090 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11091 +#else
11092 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11093 +#endif
11094 +
11095 +#endif
11096 +
11097 #ifndef __ASSEMBLY__
11098
11099 extern int direct_gbpages;
11100 @@ -611,11 +699,23 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
11101 * dst and src can be on the same page, but the range must not overlap,
11102 * and must not cross a page boundary.
11103 */
11104 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11105 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11106 {
11107 - memcpy(dst, src, count * sizeof(pgd_t));
11108 + pax_open_kernel();
11109 + while (count--)
11110 + *dst++ = *src++;
11111 + pax_close_kernel();
11112 }
11113
11114 +#ifdef CONFIG_PAX_PER_CPU_PGD
11115 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11116 +#endif
11117 +
11118 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11119 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11120 +#else
11121 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11122 +#endif
11123
11124 #include <asm-generic/pgtable.h>
11125 #endif /* __ASSEMBLY__ */
11126 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11127 index 750f1bf..971e839 100644
11128 --- a/arch/x86/include/asm/pgtable_32.h
11129 +++ b/arch/x86/include/asm/pgtable_32.h
11130 @@ -26,9 +26,6 @@
11131 struct mm_struct;
11132 struct vm_area_struct;
11133
11134 -extern pgd_t swapper_pg_dir[1024];
11135 -extern pgd_t trampoline_pg_dir[1024];
11136 -
11137 static inline void pgtable_cache_init(void) { }
11138 static inline void check_pgt_cache(void) { }
11139 void paging_init(void);
11140 @@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11141 # include <asm/pgtable-2level.h>
11142 #endif
11143
11144 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11145 +extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
11146 +#ifdef CONFIG_X86_PAE
11147 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11148 +#endif
11149 +
11150 #if defined(CONFIG_HIGHPTE)
11151 #define __KM_PTE \
11152 (in_nmi() ? KM_NMI_PTE : \
11153 @@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11154 /* Clear a kernel PTE and flush it from the TLB */
11155 #define kpte_clear_flush(ptep, vaddr) \
11156 do { \
11157 + pax_open_kernel(); \
11158 pte_clear(&init_mm, (vaddr), (ptep)); \
11159 + pax_close_kernel(); \
11160 __flush_tlb_one((vaddr)); \
11161 } while (0)
11162
11163 @@ -85,6 +90,9 @@ do { \
11164
11165 #endif /* !__ASSEMBLY__ */
11166
11167 +#define HAVE_ARCH_UNMAPPED_AREA
11168 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11169 +
11170 /*
11171 * kern_addr_valid() is (1) for FLATMEM and (0) for
11172 * SPARSEMEM and DISCONTIGMEM
11173 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11174 index 5e67c15..12d5c47 100644
11175 --- a/arch/x86/include/asm/pgtable_32_types.h
11176 +++ b/arch/x86/include/asm/pgtable_32_types.h
11177 @@ -8,7 +8,7 @@
11178 */
11179 #ifdef CONFIG_X86_PAE
11180 # include <asm/pgtable-3level_types.h>
11181 -# define PMD_SIZE (1UL << PMD_SHIFT)
11182 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11183 # define PMD_MASK (~(PMD_SIZE - 1))
11184 #else
11185 # include <asm/pgtable-2level_types.h>
11186 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11187 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11188 #endif
11189
11190 +#ifdef CONFIG_PAX_KERNEXEC
11191 +#ifndef __ASSEMBLY__
11192 +extern unsigned char MODULES_EXEC_VADDR[];
11193 +extern unsigned char MODULES_EXEC_END[];
11194 +#endif
11195 +#include <asm/boot.h>
11196 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11197 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11198 +#else
11199 +#define ktla_ktva(addr) (addr)
11200 +#define ktva_ktla(addr) (addr)
11201 +#endif
11202 +
11203 #define MODULES_VADDR VMALLOC_START
11204 #define MODULES_END VMALLOC_END
11205 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11206 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11207 index c57a301..6b414ff 100644
11208 --- a/arch/x86/include/asm/pgtable_64.h
11209 +++ b/arch/x86/include/asm/pgtable_64.h
11210 @@ -16,10 +16,14 @@
11211
11212 extern pud_t level3_kernel_pgt[512];
11213 extern pud_t level3_ident_pgt[512];
11214 +extern pud_t level3_vmalloc_start_pgt[512];
11215 +extern pud_t level3_vmalloc_end_pgt[512];
11216 +extern pud_t level3_vmemmap_pgt[512];
11217 +extern pud_t level2_vmemmap_pgt[512];
11218 extern pmd_t level2_kernel_pgt[512];
11219 extern pmd_t level2_fixmap_pgt[512];
11220 -extern pmd_t level2_ident_pgt[512];
11221 -extern pgd_t init_level4_pgt[];
11222 +extern pmd_t level2_ident_pgt[512*2];
11223 +extern pgd_t init_level4_pgt[512];
11224
11225 #define swapper_pg_dir init_level4_pgt
11226
11227 @@ -74,7 +78,9 @@ static inline pte_t native_ptep_get_and_clear(pte_t *xp)
11228
11229 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11230 {
11231 + pax_open_kernel();
11232 *pmdp = pmd;
11233 + pax_close_kernel();
11234 }
11235
11236 static inline void native_pmd_clear(pmd_t *pmd)
11237 @@ -94,6 +100,13 @@ static inline void native_pud_clear(pud_t *pud)
11238
11239 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11240 {
11241 + pax_open_kernel();
11242 + *pgdp = pgd;
11243 + pax_close_kernel();
11244 +}
11245 +
11246 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11247 +{
11248 *pgdp = pgd;
11249 }
11250
11251 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11252 index 766ea16..5b96cb3 100644
11253 --- a/arch/x86/include/asm/pgtable_64_types.h
11254 +++ b/arch/x86/include/asm/pgtable_64_types.h
11255 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11256 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11257 #define MODULES_END _AC(0xffffffffff000000, UL)
11258 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11259 +#define MODULES_EXEC_VADDR MODULES_VADDR
11260 +#define MODULES_EXEC_END MODULES_END
11261 +
11262 +#define ktla_ktva(addr) (addr)
11263 +#define ktva_ktla(addr) (addr)
11264
11265 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11266 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11267 index d1f4a76..2f46ba1 100644
11268 --- a/arch/x86/include/asm/pgtable_types.h
11269 +++ b/arch/x86/include/asm/pgtable_types.h
11270 @@ -16,12 +16,11 @@
11271 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11272 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11273 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11274 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11275 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11276 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11277 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11278 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11279 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11280 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11281 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11282 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11283
11284 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11285 @@ -39,7 +38,6 @@
11286 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11287 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11288 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11289 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11290 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11291 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11292 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11293 @@ -55,8 +53,10 @@
11294
11295 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11296 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11297 -#else
11298 +#elif defined(CONFIG_KMEMCHECK)
11299 #define _PAGE_NX (_AT(pteval_t, 0))
11300 +#else
11301 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11302 #endif
11303
11304 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11305 @@ -93,6 +93,9 @@
11306 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11307 _PAGE_ACCESSED)
11308
11309 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11310 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11311 +
11312 #define __PAGE_KERNEL_EXEC \
11313 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11314 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11315 @@ -103,8 +106,8 @@
11316 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11317 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11318 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11319 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11320 -#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
11321 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11322 +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
11323 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11324 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
11325 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
11326 @@ -163,8 +166,8 @@
11327 * bits are combined, this will alow user to access the high address mapped
11328 * VDSO in the presence of CONFIG_COMPAT_VDSO
11329 */
11330 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11331 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11332 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11333 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11334 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11335 #endif
11336
11337 @@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11338 {
11339 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11340 }
11341 +#endif
11342
11343 +#if PAGETABLE_LEVELS == 3
11344 +#include <asm-generic/pgtable-nopud.h>
11345 +#endif
11346 +
11347 +#if PAGETABLE_LEVELS == 2
11348 +#include <asm-generic/pgtable-nopmd.h>
11349 +#endif
11350 +
11351 +#ifndef __ASSEMBLY__
11352 #if PAGETABLE_LEVELS > 3
11353 typedef struct { pudval_t pud; } pud_t;
11354
11355 @@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11356 return pud.pud;
11357 }
11358 #else
11359 -#include <asm-generic/pgtable-nopud.h>
11360 -
11361 static inline pudval_t native_pud_val(pud_t pud)
11362 {
11363 return native_pgd_val(pud.pgd);
11364 @@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11365 return pmd.pmd;
11366 }
11367 #else
11368 -#include <asm-generic/pgtable-nopmd.h>
11369 -
11370 static inline pmdval_t native_pmd_val(pmd_t pmd)
11371 {
11372 return native_pgd_val(pmd.pud.pgd);
11373 @@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
11374
11375 extern pteval_t __supported_pte_mask;
11376 extern void set_nx(void);
11377 +
11378 +#ifdef CONFIG_X86_32
11379 +#ifdef CONFIG_X86_PAE
11380 extern int nx_enabled;
11381 +#else
11382 +#define nx_enabled (0)
11383 +#endif
11384 +#else
11385 +#define nx_enabled (1)
11386 +#endif
11387
11388 #define pgprot_writecombine pgprot_writecombine
11389 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11390 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11391 index fa04dea..5f823fc 100644
11392 --- a/arch/x86/include/asm/processor.h
11393 +++ b/arch/x86/include/asm/processor.h
11394 @@ -272,7 +272,7 @@ struct tss_struct {
11395
11396 } ____cacheline_aligned;
11397
11398 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11399 +extern struct tss_struct init_tss[NR_CPUS];
11400
11401 /*
11402 * Save the original ist values for checking stack pointers during debugging
11403 @@ -911,11 +911,18 @@ static inline void spin_lock_prefetch(const void *x)
11404 */
11405 #define TASK_SIZE PAGE_OFFSET
11406 #define TASK_SIZE_MAX TASK_SIZE
11407 +
11408 +#ifdef CONFIG_PAX_SEGMEXEC
11409 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11410 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11411 +#else
11412 #define STACK_TOP TASK_SIZE
11413 -#define STACK_TOP_MAX STACK_TOP
11414 +#endif
11415 +
11416 +#define STACK_TOP_MAX TASK_SIZE
11417
11418 #define INIT_THREAD { \
11419 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11420 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11421 .vm86_info = NULL, \
11422 .sysenter_cs = __KERNEL_CS, \
11423 .io_bitmap_ptr = NULL, \
11424 @@ -929,7 +936,7 @@ static inline void spin_lock_prefetch(const void *x)
11425 */
11426 #define INIT_TSS { \
11427 .x86_tss = { \
11428 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11429 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11430 .ss0 = __KERNEL_DS, \
11431 .ss1 = __KERNEL_CS, \
11432 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11433 @@ -940,11 +947,7 @@ static inline void spin_lock_prefetch(const void *x)
11434 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11435
11436 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11437 -#define KSTK_TOP(info) \
11438 -({ \
11439 - unsigned long *__ptr = (unsigned long *)(info); \
11440 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11441 -})
11442 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11443
11444 /*
11445 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11446 @@ -959,7 +962,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11447 #define task_pt_regs(task) \
11448 ({ \
11449 struct pt_regs *__regs__; \
11450 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11451 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11452 __regs__ - 1; \
11453 })
11454
11455 @@ -969,13 +972,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11456 /*
11457 * User space process size. 47bits minus one guard page.
11458 */
11459 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11460 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11461
11462 /* This decides where the kernel will search for a free chunk of vm
11463 * space during mmap's.
11464 */
11465 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11466 - 0xc0000000 : 0xFFFFe000)
11467 + 0xc0000000 : 0xFFFFf000)
11468
11469 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11470 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11471 @@ -986,11 +989,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11472 #define STACK_TOP_MAX TASK_SIZE_MAX
11473
11474 #define INIT_THREAD { \
11475 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11476 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11477 }
11478
11479 #define INIT_TSS { \
11480 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11481 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11482 }
11483
11484 /*
11485 @@ -1012,6 +1015,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11486 */
11487 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11488
11489 +#ifdef CONFIG_PAX_SEGMEXEC
11490 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11491 +#endif
11492 +
11493 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11494
11495 /* Get/set a process' ability to use the timestamp counter instruction */
11496 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11497 index 0f0d908..f2e3da2 100644
11498 --- a/arch/x86/include/asm/ptrace.h
11499 +++ b/arch/x86/include/asm/ptrace.h
11500 @@ -151,28 +151,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11501 }
11502
11503 /*
11504 - * user_mode_vm(regs) determines whether a register set came from user mode.
11505 + * user_mode(regs) determines whether a register set came from user mode.
11506 * This is true if V8086 mode was enabled OR if the register set was from
11507 * protected mode with RPL-3 CS value. This tricky test checks that with
11508 * one comparison. Many places in the kernel can bypass this full check
11509 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11510 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11511 + * be used.
11512 */
11513 -static inline int user_mode(struct pt_regs *regs)
11514 +static inline int user_mode_novm(struct pt_regs *regs)
11515 {
11516 #ifdef CONFIG_X86_32
11517 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11518 #else
11519 - return !!(regs->cs & 3);
11520 + return !!(regs->cs & SEGMENT_RPL_MASK);
11521 #endif
11522 }
11523
11524 -static inline int user_mode_vm(struct pt_regs *regs)
11525 +static inline int user_mode(struct pt_regs *regs)
11526 {
11527 #ifdef CONFIG_X86_32
11528 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11529 USER_RPL;
11530 #else
11531 - return user_mode(regs);
11532 + return user_mode_novm(regs);
11533 #endif
11534 }
11535
11536 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11537 index 562d4fd..6e39df1 100644
11538 --- a/arch/x86/include/asm/reboot.h
11539 +++ b/arch/x86/include/asm/reboot.h
11540 @@ -6,19 +6,19 @@
11541 struct pt_regs;
11542
11543 struct machine_ops {
11544 - void (*restart)(char *cmd);
11545 - void (*halt)(void);
11546 - void (*power_off)(void);
11547 + void (* __noreturn restart)(char *cmd);
11548 + void (* __noreturn halt)(void);
11549 + void (* __noreturn power_off)(void);
11550 void (*shutdown)(void);
11551 void (*crash_shutdown)(struct pt_regs *);
11552 - void (*emergency_restart)(void);
11553 -};
11554 + void (* __noreturn emergency_restart)(void);
11555 +} __no_const;
11556
11557 extern struct machine_ops machine_ops;
11558
11559 void native_machine_crash_shutdown(struct pt_regs *regs);
11560 void native_machine_shutdown(void);
11561 -void machine_real_restart(const unsigned char *code, int length);
11562 +void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
11563
11564 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
11565 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
11566 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11567 index 606ede1..dbfff37 100644
11568 --- a/arch/x86/include/asm/rwsem.h
11569 +++ b/arch/x86/include/asm/rwsem.h
11570 @@ -118,6 +118,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11571 {
11572 asm volatile("# beginning down_read\n\t"
11573 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11574 +
11575 +#ifdef CONFIG_PAX_REFCOUNT
11576 + "jno 0f\n"
11577 + LOCK_PREFIX _ASM_DEC "(%1)\n\t"
11578 + "int $4\n0:\n"
11579 + _ASM_EXTABLE(0b, 0b)
11580 +#endif
11581 +
11582 /* adds 0x00000001, returns the old value */
11583 " jns 1f\n"
11584 " call call_rwsem_down_read_failed\n"
11585 @@ -139,6 +147,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11586 "1:\n\t"
11587 " mov %1,%2\n\t"
11588 " add %3,%2\n\t"
11589 +
11590 +#ifdef CONFIG_PAX_REFCOUNT
11591 + "jno 0f\n"
11592 + "sub %3,%2\n"
11593 + "int $4\n0:\n"
11594 + _ASM_EXTABLE(0b, 0b)
11595 +#endif
11596 +
11597 " jle 2f\n\t"
11598 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11599 " jnz 1b\n\t"
11600 @@ -160,6 +176,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11601 tmp = RWSEM_ACTIVE_WRITE_BIAS;
11602 asm volatile("# beginning down_write\n\t"
11603 LOCK_PREFIX " xadd %1,(%2)\n\t"
11604 +
11605 +#ifdef CONFIG_PAX_REFCOUNT
11606 + "jno 0f\n"
11607 + "mov %1,(%2)\n"
11608 + "int $4\n0:\n"
11609 + _ASM_EXTABLE(0b, 0b)
11610 +#endif
11611 +
11612 /* subtract 0x0000ffff, returns the old value */
11613 " test %1,%1\n\t"
11614 /* was the count 0 before? */
11615 @@ -198,6 +222,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11616 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
11617 asm volatile("# beginning __up_read\n\t"
11618 LOCK_PREFIX " xadd %1,(%2)\n\t"
11619 +
11620 +#ifdef CONFIG_PAX_REFCOUNT
11621 + "jno 0f\n"
11622 + "mov %1,(%2)\n"
11623 + "int $4\n0:\n"
11624 + _ASM_EXTABLE(0b, 0b)
11625 +#endif
11626 +
11627 /* subtracts 1, returns the old value */
11628 " jns 1f\n\t"
11629 " call call_rwsem_wake\n"
11630 @@ -216,6 +248,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11631 rwsem_count_t tmp;
11632 asm volatile("# beginning __up_write\n\t"
11633 LOCK_PREFIX " xadd %1,(%2)\n\t"
11634 +
11635 +#ifdef CONFIG_PAX_REFCOUNT
11636 + "jno 0f\n"
11637 + "mov %1,(%2)\n"
11638 + "int $4\n0:\n"
11639 + _ASM_EXTABLE(0b, 0b)
11640 +#endif
11641 +
11642 /* tries to transition
11643 0xffff0001 -> 0x00000000 */
11644 " jz 1f\n"
11645 @@ -234,6 +274,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11646 {
11647 asm volatile("# beginning __downgrade_write\n\t"
11648 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11649 +
11650 +#ifdef CONFIG_PAX_REFCOUNT
11651 + "jno 0f\n"
11652 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11653 + "int $4\n0:\n"
11654 + _ASM_EXTABLE(0b, 0b)
11655 +#endif
11656 +
11657 /*
11658 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11659 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11660 @@ -253,7 +301,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11661 static inline void rwsem_atomic_add(rwsem_count_t delta,
11662 struct rw_semaphore *sem)
11663 {
11664 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11665 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11666 +
11667 +#ifdef CONFIG_PAX_REFCOUNT
11668 + "jno 0f\n"
11669 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11670 + "int $4\n0:\n"
11671 + _ASM_EXTABLE(0b, 0b)
11672 +#endif
11673 +
11674 : "+m" (sem->count)
11675 : "er" (delta));
11676 }
11677 @@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic_update(rwsem_count_t delta,
11678 {
11679 rwsem_count_t tmp = delta;
11680
11681 - asm volatile(LOCK_PREFIX "xadd %0,%1"
11682 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11683 +
11684 +#ifdef CONFIG_PAX_REFCOUNT
11685 + "jno 0f\n"
11686 + "mov %0,%1\n"
11687 + "int $4\n0:\n"
11688 + _ASM_EXTABLE(0b, 0b)
11689 +#endif
11690 +
11691 : "+r" (tmp), "+m" (sem->count)
11692 : : "memory");
11693
11694 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11695 index 14e0ed8..7f7dd5e 100644
11696 --- a/arch/x86/include/asm/segment.h
11697 +++ b/arch/x86/include/asm/segment.h
11698 @@ -62,10 +62,15 @@
11699 * 26 - ESPFIX small SS
11700 * 27 - per-cpu [ offset to per-cpu data area ]
11701 * 28 - stack_canary-20 [ for stack protector ]
11702 - * 29 - unused
11703 - * 30 - unused
11704 + * 29 - PCI BIOS CS
11705 + * 30 - PCI BIOS DS
11706 * 31 - TSS for double fault handler
11707 */
11708 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11709 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11710 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11711 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11712 +
11713 #define GDT_ENTRY_TLS_MIN 6
11714 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11715
11716 @@ -77,6 +82,8 @@
11717
11718 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
11719
11720 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11721 +
11722 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
11723
11724 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
11725 @@ -88,7 +95,7 @@
11726 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
11727 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
11728
11729 -#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11730 +#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11731 #ifdef CONFIG_SMP
11732 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
11733 #else
11734 @@ -102,6 +109,12 @@
11735 #define __KERNEL_STACK_CANARY 0
11736 #endif
11737
11738 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
11739 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11740 +
11741 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
11742 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11743 +
11744 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11745
11746 /*
11747 @@ -139,7 +152,7 @@
11748 */
11749
11750 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11751 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11752 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11753
11754
11755 #else
11756 @@ -163,6 +176,8 @@
11757 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11758 #define __USER32_DS __USER_DS
11759
11760 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11761 +
11762 #define GDT_ENTRY_TSS 8 /* needs two entries */
11763 #define GDT_ENTRY_LDT 10 /* needs two entries */
11764 #define GDT_ENTRY_TLS_MIN 12
11765 @@ -183,6 +198,7 @@
11766 #endif
11767
11768 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
11769 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
11770 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
11771 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
11772 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
11773 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11774 index 4c2f63c..5685db2 100644
11775 --- a/arch/x86/include/asm/smp.h
11776 +++ b/arch/x86/include/asm/smp.h
11777 @@ -24,7 +24,7 @@ extern unsigned int num_processors;
11778 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
11779 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11780 DECLARE_PER_CPU(u16, cpu_llc_id);
11781 -DECLARE_PER_CPU(int, cpu_number);
11782 +DECLARE_PER_CPU(unsigned int, cpu_number);
11783
11784 static inline struct cpumask *cpu_sibling_mask(int cpu)
11785 {
11786 @@ -40,10 +40,7 @@ DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
11787 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
11788
11789 /* Static state in head.S used to set up a CPU */
11790 -extern struct {
11791 - void *sp;
11792 - unsigned short ss;
11793 -} stack_start;
11794 +extern unsigned long stack_start; /* Initial stack pointer address */
11795
11796 struct smp_ops {
11797 void (*smp_prepare_boot_cpu)(void);
11798 @@ -60,7 +57,7 @@ struct smp_ops {
11799
11800 void (*send_call_func_ipi)(const struct cpumask *mask);
11801 void (*send_call_func_single_ipi)(int cpu);
11802 -};
11803 +} __no_const;
11804
11805 /* Globals due to paravirt */
11806 extern void set_cpu_sibling_map(int cpu);
11807 @@ -175,14 +172,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11808 extern int safe_smp_processor_id(void);
11809
11810 #elif defined(CONFIG_X86_64_SMP)
11811 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11812 -
11813 -#define stack_smp_processor_id() \
11814 -({ \
11815 - struct thread_info *ti; \
11816 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11817 - ti->cpu; \
11818 -})
11819 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11820 +#define stack_smp_processor_id() raw_smp_processor_id()
11821 #define safe_smp_processor_id() smp_processor_id()
11822
11823 #endif
11824 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11825 index 4e77853..4359783 100644
11826 --- a/arch/x86/include/asm/spinlock.h
11827 +++ b/arch/x86/include/asm/spinlock.h
11828 @@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(raw_rwlock_t *lock)
11829 static inline void __raw_read_lock(raw_rwlock_t *rw)
11830 {
11831 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11832 +
11833 +#ifdef CONFIG_PAX_REFCOUNT
11834 + "jno 0f\n"
11835 + LOCK_PREFIX " addl $1,(%0)\n"
11836 + "int $4\n0:\n"
11837 + _ASM_EXTABLE(0b, 0b)
11838 +#endif
11839 +
11840 "jns 1f\n"
11841 "call __read_lock_failed\n\t"
11842 "1:\n"
11843 @@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_rwlock_t *rw)
11844 static inline void __raw_write_lock(raw_rwlock_t *rw)
11845 {
11846 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11847 +
11848 +#ifdef CONFIG_PAX_REFCOUNT
11849 + "jno 0f\n"
11850 + LOCK_PREFIX " addl %1,(%0)\n"
11851 + "int $4\n0:\n"
11852 + _ASM_EXTABLE(0b, 0b)
11853 +#endif
11854 +
11855 "jz 1f\n"
11856 "call __write_lock_failed\n\t"
11857 "1:\n"
11858 @@ -286,12 +302,29 @@ static inline int __raw_write_trylock(raw_rwlock_t *lock)
11859
11860 static inline void __raw_read_unlock(raw_rwlock_t *rw)
11861 {
11862 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11863 + asm volatile(LOCK_PREFIX "incl %0\n"
11864 +
11865 +#ifdef CONFIG_PAX_REFCOUNT
11866 + "jno 0f\n"
11867 + LOCK_PREFIX "decl %0\n"
11868 + "int $4\n0:\n"
11869 + _ASM_EXTABLE(0b, 0b)
11870 +#endif
11871 +
11872 + :"+m" (rw->lock) : : "memory");
11873 }
11874
11875 static inline void __raw_write_unlock(raw_rwlock_t *rw)
11876 {
11877 - asm volatile(LOCK_PREFIX "addl %1, %0"
11878 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
11879 +
11880 +#ifdef CONFIG_PAX_REFCOUNT
11881 + "jno 0f\n"
11882 + LOCK_PREFIX "subl %1, %0\n"
11883 + "int $4\n0:\n"
11884 + _ASM_EXTABLE(0b, 0b)
11885 +#endif
11886 +
11887 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11888 }
11889
11890 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11891 index 1575177..cb23f52 100644
11892 --- a/arch/x86/include/asm/stackprotector.h
11893 +++ b/arch/x86/include/asm/stackprotector.h
11894 @@ -48,7 +48,7 @@
11895 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11896 */
11897 #define GDT_STACK_CANARY_INIT \
11898 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11899 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11900
11901 /*
11902 * Initialize the stackprotector canary value.
11903 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11904
11905 static inline void load_stack_canary_segment(void)
11906 {
11907 -#ifdef CONFIG_X86_32
11908 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11909 asm volatile ("mov %0, %%gs" : : "r" (0));
11910 #endif
11911 }
11912 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11913 index e0fbf29..858ef4a 100644
11914 --- a/arch/x86/include/asm/system.h
11915 +++ b/arch/x86/include/asm/system.h
11916 @@ -132,7 +132,7 @@ do { \
11917 "thread_return:\n\t" \
11918 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11919 __switch_canary \
11920 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11921 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11922 "movq %%rax,%%rdi\n\t" \
11923 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11924 "jnz ret_from_fork\n\t" \
11925 @@ -143,7 +143,7 @@ do { \
11926 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11927 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11928 [_tif_fork] "i" (_TIF_FORK), \
11929 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11930 + [thread_info] "m" (per_cpu_var(current_tinfo)), \
11931 [current_task] "m" (per_cpu_var(current_task)) \
11932 __switch_canary_iparam \
11933 : "memory", "cc" __EXTRA_CLOBBER)
11934 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11935 {
11936 unsigned long __limit;
11937 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11938 - return __limit + 1;
11939 + return __limit;
11940 }
11941
11942 static inline void native_clts(void)
11943 @@ -340,12 +340,12 @@ void enable_hlt(void);
11944
11945 void cpu_idle_wait(void);
11946
11947 -extern unsigned long arch_align_stack(unsigned long sp);
11948 +#define arch_align_stack(x) ((x) & ~0xfUL)
11949 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11950
11951 void default_idle(void);
11952
11953 -void stop_this_cpu(void *dummy);
11954 +void stop_this_cpu(void *dummy) __noreturn;
11955
11956 /*
11957 * Force strict CPU ordering.
11958 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11959 index 19c3ce4..8962535 100644
11960 --- a/arch/x86/include/asm/thread_info.h
11961 +++ b/arch/x86/include/asm/thread_info.h
11962 @@ -10,6 +10,7 @@
11963 #include <linux/compiler.h>
11964 #include <asm/page.h>
11965 #include <asm/types.h>
11966 +#include <asm/percpu.h>
11967
11968 /*
11969 * low level task data that entry.S needs immediate access to
11970 @@ -24,7 +25,6 @@ struct exec_domain;
11971 #include <asm/atomic.h>
11972
11973 struct thread_info {
11974 - struct task_struct *task; /* main task structure */
11975 struct exec_domain *exec_domain; /* execution domain */
11976 __u32 flags; /* low level flags */
11977 __u32 status; /* thread synchronous flags */
11978 @@ -34,18 +34,12 @@ struct thread_info {
11979 mm_segment_t addr_limit;
11980 struct restart_block restart_block;
11981 void __user *sysenter_return;
11982 -#ifdef CONFIG_X86_32
11983 - unsigned long previous_esp; /* ESP of the previous stack in
11984 - case of nested (IRQ) stacks
11985 - */
11986 - __u8 supervisor_stack[0];
11987 -#endif
11988 + unsigned long lowest_stack;
11989 int uaccess_err;
11990 };
11991
11992 -#define INIT_THREAD_INFO(tsk) \
11993 +#define INIT_THREAD_INFO \
11994 { \
11995 - .task = &tsk, \
11996 .exec_domain = &default_exec_domain, \
11997 .flags = 0, \
11998 .cpu = 0, \
11999 @@ -56,7 +50,7 @@ struct thread_info {
12000 }, \
12001 }
12002
12003 -#define init_thread_info (init_thread_union.thread_info)
12004 +#define init_thread_info (init_thread_union.stack)
12005 #define init_stack (init_thread_union.stack)
12006
12007 #else /* !__ASSEMBLY__ */
12008 @@ -163,45 +157,40 @@ struct thread_info {
12009 #define alloc_thread_info(tsk) \
12010 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
12011
12012 -#ifdef CONFIG_X86_32
12013 -
12014 -#define STACK_WARN (THREAD_SIZE/8)
12015 -/*
12016 - * macros/functions for gaining access to the thread information structure
12017 - *
12018 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12019 - */
12020 -#ifndef __ASSEMBLY__
12021 -
12022 -
12023 -/* how to get the current stack pointer from C */
12024 -register unsigned long current_stack_pointer asm("esp") __used;
12025 -
12026 -/* how to get the thread information struct from C */
12027 -static inline struct thread_info *current_thread_info(void)
12028 -{
12029 - return (struct thread_info *)
12030 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12031 -}
12032 -
12033 -#else /* !__ASSEMBLY__ */
12034 -
12035 +#ifdef __ASSEMBLY__
12036 /* how to get the thread information struct from ASM */
12037 #define GET_THREAD_INFO(reg) \
12038 - movl $-THREAD_SIZE, reg; \
12039 - andl %esp, reg
12040 + mov PER_CPU_VAR(current_tinfo), reg
12041
12042 /* use this one if reg already contains %esp */
12043 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12044 - andl $-THREAD_SIZE, reg
12045 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12046 +#else
12047 +/* how to get the thread information struct from C */
12048 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12049 +
12050 +static __always_inline struct thread_info *current_thread_info(void)
12051 +{
12052 + return percpu_read_stable(current_tinfo);
12053 +}
12054 +#endif
12055 +
12056 +#ifdef CONFIG_X86_32
12057 +
12058 +#define STACK_WARN (THREAD_SIZE/8)
12059 +/*
12060 + * macros/functions for gaining access to the thread information structure
12061 + *
12062 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12063 + */
12064 +#ifndef __ASSEMBLY__
12065 +
12066 +/* how to get the current stack pointer from C */
12067 +register unsigned long current_stack_pointer asm("esp") __used;
12068
12069 #endif
12070
12071 #else /* X86_32 */
12072
12073 -#include <asm/percpu.h>
12074 -#define KERNEL_STACK_OFFSET (5*8)
12075 -
12076 /*
12077 * macros/functions for gaining access to the thread information structure
12078 * preempt_count needs to be 1 initially, until the scheduler is functional.
12079 @@ -209,21 +198,8 @@ static inline struct thread_info *current_thread_info(void)
12080 #ifndef __ASSEMBLY__
12081 DECLARE_PER_CPU(unsigned long, kernel_stack);
12082
12083 -static inline struct thread_info *current_thread_info(void)
12084 -{
12085 - struct thread_info *ti;
12086 - ti = (void *)(percpu_read_stable(kernel_stack) +
12087 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12088 - return ti;
12089 -}
12090 -
12091 -#else /* !__ASSEMBLY__ */
12092 -
12093 -/* how to get the thread information struct from ASM */
12094 -#define GET_THREAD_INFO(reg) \
12095 - movq PER_CPU_VAR(kernel_stack),reg ; \
12096 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12097 -
12098 +/* how to get the current stack pointer from C */
12099 +register unsigned long current_stack_pointer asm("rsp") __used;
12100 #endif
12101
12102 #endif /* !X86_32 */
12103 @@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
12104 extern void free_thread_info(struct thread_info *ti);
12105 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12106 #define arch_task_cache_init arch_task_cache_init
12107 +
12108 +#define __HAVE_THREAD_FUNCTIONS
12109 +#define task_thread_info(task) (&(task)->tinfo)
12110 +#define task_stack_page(task) ((task)->stack)
12111 +#define setup_thread_stack(p, org) do {} while (0)
12112 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12113 +
12114 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12115 +extern struct task_struct *alloc_task_struct(void);
12116 +extern void free_task_struct(struct task_struct *);
12117 +
12118 #endif
12119 #endif /* _ASM_X86_THREAD_INFO_H */
12120 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12121 index 61c5874..8a046e9 100644
12122 --- a/arch/x86/include/asm/uaccess.h
12123 +++ b/arch/x86/include/asm/uaccess.h
12124 @@ -8,12 +8,15 @@
12125 #include <linux/thread_info.h>
12126 #include <linux/prefetch.h>
12127 #include <linux/string.h>
12128 +#include <linux/sched.h>
12129 #include <asm/asm.h>
12130 #include <asm/page.h>
12131
12132 #define VERIFY_READ 0
12133 #define VERIFY_WRITE 1
12134
12135 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12136 +
12137 /*
12138 * The fs value determines whether argument validity checking should be
12139 * performed or not. If get_fs() == USER_DS, checking is performed, with
12140 @@ -29,7 +32,12 @@
12141
12142 #define get_ds() (KERNEL_DS)
12143 #define get_fs() (current_thread_info()->addr_limit)
12144 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12145 +void __set_fs(mm_segment_t x);
12146 +void set_fs(mm_segment_t x);
12147 +#else
12148 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12149 +#endif
12150
12151 #define segment_eq(a, b) ((a).seg == (b).seg)
12152
12153 @@ -77,7 +85,33 @@
12154 * checks that the pointer is in the user space range - after calling
12155 * this function, memory access functions may still return -EFAULT.
12156 */
12157 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12158 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12159 +#define access_ok(type, addr, size) \
12160 +({ \
12161 + long __size = size; \
12162 + unsigned long __addr = (unsigned long)addr; \
12163 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12164 + unsigned long __end_ao = __addr + __size - 1; \
12165 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12166 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12167 + while(__addr_ao <= __end_ao) { \
12168 + char __c_ao; \
12169 + __addr_ao += PAGE_SIZE; \
12170 + if (__size > PAGE_SIZE) \
12171 + cond_resched(); \
12172 + if (__get_user(__c_ao, (char __user *)__addr)) \
12173 + break; \
12174 + if (type != VERIFY_WRITE) { \
12175 + __addr = __addr_ao; \
12176 + continue; \
12177 + } \
12178 + if (__put_user(__c_ao, (char __user *)__addr)) \
12179 + break; \
12180 + __addr = __addr_ao; \
12181 + } \
12182 + } \
12183 + __ret_ao; \
12184 +})
12185
12186 /*
12187 * The exception table consists of pairs of addresses: the first is the
12188 @@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12189 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12190 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12191
12192 -
12193 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12194 +#define __copyuser_seg "gs;"
12195 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12196 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12197 +#else
12198 +#define __copyuser_seg
12199 +#define __COPYUSER_SET_ES
12200 +#define __COPYUSER_RESTORE_ES
12201 +#endif
12202
12203 #ifdef CONFIG_X86_32
12204 #define __put_user_asm_u64(x, addr, err, errret) \
12205 - asm volatile("1: movl %%eax,0(%2)\n" \
12206 - "2: movl %%edx,4(%2)\n" \
12207 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12208 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12209 "3:\n" \
12210 ".section .fixup,\"ax\"\n" \
12211 "4: movl %3,%0\n" \
12212 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12213 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12214
12215 #define __put_user_asm_ex_u64(x, addr) \
12216 - asm volatile("1: movl %%eax,0(%1)\n" \
12217 - "2: movl %%edx,4(%1)\n" \
12218 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12219 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12220 "3:\n" \
12221 _ASM_EXTABLE(1b, 2b - 1b) \
12222 _ASM_EXTABLE(2b, 3b - 2b) \
12223 @@ -253,7 +295,7 @@ extern void __put_user_8(void);
12224 __typeof__(*(ptr)) __pu_val; \
12225 __chk_user_ptr(ptr); \
12226 might_fault(); \
12227 - __pu_val = x; \
12228 + __pu_val = (x); \
12229 switch (sizeof(*(ptr))) { \
12230 case 1: \
12231 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12232 @@ -374,7 +416,7 @@ do { \
12233 } while (0)
12234
12235 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12236 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12237 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12238 "2:\n" \
12239 ".section .fixup,\"ax\"\n" \
12240 "3: mov %3,%0\n" \
12241 @@ -382,7 +424,7 @@ do { \
12242 " jmp 2b\n" \
12243 ".previous\n" \
12244 _ASM_EXTABLE(1b, 3b) \
12245 - : "=r" (err), ltype(x) \
12246 + : "=r" (err), ltype (x) \
12247 : "m" (__m(addr)), "i" (errret), "0" (err))
12248
12249 #define __get_user_size_ex(x, ptr, size) \
12250 @@ -407,7 +449,7 @@ do { \
12251 } while (0)
12252
12253 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12254 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12255 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12256 "2:\n" \
12257 _ASM_EXTABLE(1b, 2b - 1b) \
12258 : ltype(x) : "m" (__m(addr)))
12259 @@ -424,13 +466,24 @@ do { \
12260 int __gu_err; \
12261 unsigned long __gu_val; \
12262 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12263 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12264 + (x) = (__typeof__(*(ptr)))__gu_val; \
12265 __gu_err; \
12266 })
12267
12268 /* FIXME: this hack is definitely wrong -AK */
12269 struct __large_struct { unsigned long buf[100]; };
12270 -#define __m(x) (*(struct __large_struct __user *)(x))
12271 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12272 +#define ____m(x) \
12273 +({ \
12274 + unsigned long ____x = (unsigned long)(x); \
12275 + if (____x < PAX_USER_SHADOW_BASE) \
12276 + ____x += PAX_USER_SHADOW_BASE; \
12277 + (void __user *)____x; \
12278 +})
12279 +#else
12280 +#define ____m(x) (x)
12281 +#endif
12282 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12283
12284 /*
12285 * Tell gcc we read from memory instead of writing: this is because
12286 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long buf[100]; };
12287 * aliasing issues.
12288 */
12289 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12290 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12291 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12292 "2:\n" \
12293 ".section .fixup,\"ax\"\n" \
12294 "3: mov %3,%0\n" \
12295 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long buf[100]; };
12296 ".previous\n" \
12297 _ASM_EXTABLE(1b, 3b) \
12298 : "=r"(err) \
12299 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12300 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12301
12302 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12303 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12304 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12305 "2:\n" \
12306 _ASM_EXTABLE(1b, 2b - 1b) \
12307 : : ltype(x), "m" (__m(addr)))
12308 @@ -488,8 +541,12 @@ struct __large_struct { unsigned long buf[100]; };
12309 * On error, the variable @x is set to zero.
12310 */
12311
12312 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12313 +#define __get_user(x, ptr) get_user((x), (ptr))
12314 +#else
12315 #define __get_user(x, ptr) \
12316 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12317 +#endif
12318
12319 /**
12320 * __put_user: - Write a simple value into user space, with less checking.
12321 @@ -511,8 +568,12 @@ struct __large_struct { unsigned long buf[100]; };
12322 * Returns zero on success, or -EFAULT on error.
12323 */
12324
12325 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12326 +#define __put_user(x, ptr) put_user((x), (ptr))
12327 +#else
12328 #define __put_user(x, ptr) \
12329 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12330 +#endif
12331
12332 #define __get_user_unaligned __get_user
12333 #define __put_user_unaligned __put_user
12334 @@ -530,7 +591,7 @@ struct __large_struct { unsigned long buf[100]; };
12335 #define get_user_ex(x, ptr) do { \
12336 unsigned long __gue_val; \
12337 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12338 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12339 + (x) = (__typeof__(*(ptr)))__gue_val; \
12340 } while (0)
12341
12342 #ifdef CONFIG_X86_WP_WORKS_OK
12343 @@ -567,6 +628,7 @@ extern struct movsl_mask {
12344
12345 #define ARCH_HAS_NOCACHE_UACCESS 1
12346
12347 +#define ARCH_HAS_SORT_EXTABLE
12348 #ifdef CONFIG_X86_32
12349 # include "uaccess_32.h"
12350 #else
12351 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12352 index 632fb44..e30e334 100644
12353 --- a/arch/x86/include/asm/uaccess_32.h
12354 +++ b/arch/x86/include/asm/uaccess_32.h
12355 @@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12356 static __always_inline unsigned long __must_check
12357 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12358 {
12359 + pax_track_stack();
12360 +
12361 + if ((long)n < 0)
12362 + return n;
12363 +
12364 if (__builtin_constant_p(n)) {
12365 unsigned long ret;
12366
12367 @@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12368 return ret;
12369 }
12370 }
12371 + if (!__builtin_constant_p(n))
12372 + check_object_size(from, n, true);
12373 return __copy_to_user_ll(to, from, n);
12374 }
12375
12376 @@ -83,12 +90,16 @@ static __always_inline unsigned long __must_check
12377 __copy_to_user(void __user *to, const void *from, unsigned long n)
12378 {
12379 might_fault();
12380 +
12381 return __copy_to_user_inatomic(to, from, n);
12382 }
12383
12384 static __always_inline unsigned long
12385 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12386 {
12387 + if ((long)n < 0)
12388 + return n;
12389 +
12390 /* Avoid zeroing the tail if the copy fails..
12391 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12392 * but as the zeroing behaviour is only significant when n is not
12393 @@ -138,6 +149,12 @@ static __always_inline unsigned long
12394 __copy_from_user(void *to, const void __user *from, unsigned long n)
12395 {
12396 might_fault();
12397 +
12398 + pax_track_stack();
12399 +
12400 + if ((long)n < 0)
12401 + return n;
12402 +
12403 if (__builtin_constant_p(n)) {
12404 unsigned long ret;
12405
12406 @@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12407 return ret;
12408 }
12409 }
12410 + if (!__builtin_constant_p(n))
12411 + check_object_size(to, n, false);
12412 return __copy_from_user_ll(to, from, n);
12413 }
12414
12415 @@ -160,6 +179,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12416 const void __user *from, unsigned long n)
12417 {
12418 might_fault();
12419 +
12420 + if ((long)n < 0)
12421 + return n;
12422 +
12423 if (__builtin_constant_p(n)) {
12424 unsigned long ret;
12425
12426 @@ -182,14 +205,62 @@ static __always_inline unsigned long
12427 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12428 unsigned long n)
12429 {
12430 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12431 + if ((long)n < 0)
12432 + return n;
12433 +
12434 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12435 +}
12436 +
12437 +/**
12438 + * copy_to_user: - Copy a block of data into user space.
12439 + * @to: Destination address, in user space.
12440 + * @from: Source address, in kernel space.
12441 + * @n: Number of bytes to copy.
12442 + *
12443 + * Context: User context only. This function may sleep.
12444 + *
12445 + * Copy data from kernel space to user space.
12446 + *
12447 + * Returns number of bytes that could not be copied.
12448 + * On success, this will be zero.
12449 + */
12450 +static __always_inline unsigned long __must_check
12451 +copy_to_user(void __user *to, const void *from, unsigned long n)
12452 +{
12453 + if (access_ok(VERIFY_WRITE, to, n))
12454 + n = __copy_to_user(to, from, n);
12455 + return n;
12456 +}
12457 +
12458 +/**
12459 + * copy_from_user: - Copy a block of data from user space.
12460 + * @to: Destination address, in kernel space.
12461 + * @from: Source address, in user space.
12462 + * @n: Number of bytes to copy.
12463 + *
12464 + * Context: User context only. This function may sleep.
12465 + *
12466 + * Copy data from user space to kernel space.
12467 + *
12468 + * Returns number of bytes that could not be copied.
12469 + * On success, this will be zero.
12470 + *
12471 + * If some data could not be copied, this function will pad the copied
12472 + * data to the requested size using zero bytes.
12473 + */
12474 +static __always_inline unsigned long __must_check
12475 +copy_from_user(void *to, const void __user *from, unsigned long n)
12476 +{
12477 + if (access_ok(VERIFY_READ, from, n))
12478 + n = __copy_from_user(to, from, n);
12479 + else if ((long)n > 0) {
12480 + if (!__builtin_constant_p(n))
12481 + check_object_size(to, n, false);
12482 + memset(to, 0, n);
12483 + }
12484 + return n;
12485 }
12486
12487 -unsigned long __must_check copy_to_user(void __user *to,
12488 - const void *from, unsigned long n);
12489 -unsigned long __must_check copy_from_user(void *to,
12490 - const void __user *from,
12491 - unsigned long n);
12492 long __must_check strncpy_from_user(char *dst, const char __user *src,
12493 long count);
12494 long __must_check __strncpy_from_user(char *dst,
12495 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12496 index db24b21..f595ae7 100644
12497 --- a/arch/x86/include/asm/uaccess_64.h
12498 +++ b/arch/x86/include/asm/uaccess_64.h
12499 @@ -9,6 +9,9 @@
12500 #include <linux/prefetch.h>
12501 #include <linux/lockdep.h>
12502 #include <asm/page.h>
12503 +#include <asm/pgtable.h>
12504 +
12505 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12506
12507 /*
12508 * Copy To/From Userspace
12509 @@ -16,116 +19,205 @@
12510
12511 /* Handles exceptions in both to and from, but doesn't do access_ok */
12512 __must_check unsigned long
12513 -copy_user_generic(void *to, const void *from, unsigned len);
12514 +copy_user_generic(void *to, const void *from, unsigned long len);
12515
12516 __must_check unsigned long
12517 -copy_to_user(void __user *to, const void *from, unsigned len);
12518 -__must_check unsigned long
12519 -copy_from_user(void *to, const void __user *from, unsigned len);
12520 -__must_check unsigned long
12521 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12522 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
12523
12524 static __always_inline __must_check
12525 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12526 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12527 {
12528 - int ret = 0;
12529 + unsigned ret = 0;
12530
12531 might_fault();
12532 - if (!__builtin_constant_p(size))
12533 - return copy_user_generic(dst, (__force void *)src, size);
12534 +
12535 + if (size > INT_MAX)
12536 + return size;
12537 +
12538 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12539 + if (!__access_ok(VERIFY_READ, src, size))
12540 + return size;
12541 +#endif
12542 +
12543 + if (!__builtin_constant_p(size)) {
12544 + check_object_size(dst, size, false);
12545 +
12546 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12547 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12548 + src += PAX_USER_SHADOW_BASE;
12549 +#endif
12550 +
12551 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12552 + }
12553 switch (size) {
12554 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12555 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12556 ret, "b", "b", "=q", 1);
12557 return ret;
12558 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12559 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12560 ret, "w", "w", "=r", 2);
12561 return ret;
12562 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12563 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12564 ret, "l", "k", "=r", 4);
12565 return ret;
12566 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12567 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12568 ret, "q", "", "=r", 8);
12569 return ret;
12570 case 10:
12571 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12572 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12573 ret, "q", "", "=r", 10);
12574 if (unlikely(ret))
12575 return ret;
12576 __get_user_asm(*(u16 *)(8 + (char *)dst),
12577 - (u16 __user *)(8 + (char __user *)src),
12578 + (const u16 __user *)(8 + (const char __user *)src),
12579 ret, "w", "w", "=r", 2);
12580 return ret;
12581 case 16:
12582 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12583 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12584 ret, "q", "", "=r", 16);
12585 if (unlikely(ret))
12586 return ret;
12587 __get_user_asm(*(u64 *)(8 + (char *)dst),
12588 - (u64 __user *)(8 + (char __user *)src),
12589 + (const u64 __user *)(8 + (const char __user *)src),
12590 ret, "q", "", "=r", 8);
12591 return ret;
12592 default:
12593 - return copy_user_generic(dst, (__force void *)src, size);
12594 +
12595 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12596 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12597 + src += PAX_USER_SHADOW_BASE;
12598 +#endif
12599 +
12600 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12601 }
12602 }
12603
12604 static __always_inline __must_check
12605 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12606 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12607 {
12608 - int ret = 0;
12609 + unsigned ret = 0;
12610
12611 might_fault();
12612 - if (!__builtin_constant_p(size))
12613 - return copy_user_generic((__force void *)dst, src, size);
12614 +
12615 + pax_track_stack();
12616 +
12617 + if (size > INT_MAX)
12618 + return size;
12619 +
12620 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12621 + if (!__access_ok(VERIFY_WRITE, dst, size))
12622 + return size;
12623 +#endif
12624 +
12625 + if (!__builtin_constant_p(size)) {
12626 + check_object_size(src, size, true);
12627 +
12628 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12629 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12630 + dst += PAX_USER_SHADOW_BASE;
12631 +#endif
12632 +
12633 + return copy_user_generic((__force_kernel void *)dst, src, size);
12634 + }
12635 switch (size) {
12636 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12637 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12638 ret, "b", "b", "iq", 1);
12639 return ret;
12640 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12641 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12642 ret, "w", "w", "ir", 2);
12643 return ret;
12644 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12645 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12646 ret, "l", "k", "ir", 4);
12647 return ret;
12648 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12649 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12650 ret, "q", "", "er", 8);
12651 return ret;
12652 case 10:
12653 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12654 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12655 ret, "q", "", "er", 10);
12656 if (unlikely(ret))
12657 return ret;
12658 asm("":::"memory");
12659 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12660 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12661 ret, "w", "w", "ir", 2);
12662 return ret;
12663 case 16:
12664 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12665 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12666 ret, "q", "", "er", 16);
12667 if (unlikely(ret))
12668 return ret;
12669 asm("":::"memory");
12670 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12671 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12672 ret, "q", "", "er", 8);
12673 return ret;
12674 default:
12675 - return copy_user_generic((__force void *)dst, src, size);
12676 +
12677 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12678 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12679 + dst += PAX_USER_SHADOW_BASE;
12680 +#endif
12681 +
12682 + return copy_user_generic((__force_kernel void *)dst, src, size);
12683 + }
12684 +}
12685 +
12686 +static __always_inline __must_check
12687 +unsigned long copy_to_user(void __user *to, const void *from, unsigned long len)
12688 +{
12689 + if (access_ok(VERIFY_WRITE, to, len))
12690 + len = __copy_to_user(to, from, len);
12691 + return len;
12692 +}
12693 +
12694 +static __always_inline __must_check
12695 +unsigned long copy_from_user(void *to, const void __user *from, unsigned long len)
12696 +{
12697 + might_fault();
12698 +
12699 + if (access_ok(VERIFY_READ, from, len))
12700 + len = __copy_from_user(to, from, len);
12701 + else if (len < INT_MAX) {
12702 + if (!__builtin_constant_p(len))
12703 + check_object_size(to, len, false);
12704 + memset(to, 0, len);
12705 }
12706 + return len;
12707 }
12708
12709 static __always_inline __must_check
12710 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12711 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12712 {
12713 - int ret = 0;
12714 + unsigned ret = 0;
12715
12716 might_fault();
12717 - if (!__builtin_constant_p(size))
12718 - return copy_user_generic((__force void *)dst,
12719 - (__force void *)src, size);
12720 +
12721 + pax_track_stack();
12722 +
12723 + if (size > INT_MAX)
12724 + return size;
12725 +
12726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12727 + if (!__access_ok(VERIFY_READ, src, size))
12728 + return size;
12729 + if (!__access_ok(VERIFY_WRITE, dst, size))
12730 + return size;
12731 +#endif
12732 +
12733 + if (!__builtin_constant_p(size)) {
12734 +
12735 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12736 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12737 + src += PAX_USER_SHADOW_BASE;
12738 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12739 + dst += PAX_USER_SHADOW_BASE;
12740 +#endif
12741 +
12742 + return copy_user_generic((__force_kernel void *)dst,
12743 + (__force_kernel const void *)src, size);
12744 + }
12745 switch (size) {
12746 case 1: {
12747 u8 tmp;
12748 - __get_user_asm(tmp, (u8 __user *)src,
12749 + __get_user_asm(tmp, (const u8 __user *)src,
12750 ret, "b", "b", "=q", 1);
12751 if (likely(!ret))
12752 __put_user_asm(tmp, (u8 __user *)dst,
12753 @@ -134,7 +226,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12754 }
12755 case 2: {
12756 u16 tmp;
12757 - __get_user_asm(tmp, (u16 __user *)src,
12758 + __get_user_asm(tmp, (const u16 __user *)src,
12759 ret, "w", "w", "=r", 2);
12760 if (likely(!ret))
12761 __put_user_asm(tmp, (u16 __user *)dst,
12762 @@ -144,7 +236,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12763
12764 case 4: {
12765 u32 tmp;
12766 - __get_user_asm(tmp, (u32 __user *)src,
12767 + __get_user_asm(tmp, (const u32 __user *)src,
12768 ret, "l", "k", "=r", 4);
12769 if (likely(!ret))
12770 __put_user_asm(tmp, (u32 __user *)dst,
12771 @@ -153,7 +245,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12772 }
12773 case 8: {
12774 u64 tmp;
12775 - __get_user_asm(tmp, (u64 __user *)src,
12776 + __get_user_asm(tmp, (const u64 __user *)src,
12777 ret, "q", "", "=r", 8);
12778 if (likely(!ret))
12779 __put_user_asm(tmp, (u64 __user *)dst,
12780 @@ -161,8 +253,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12781 return ret;
12782 }
12783 default:
12784 - return copy_user_generic((__force void *)dst,
12785 - (__force void *)src, size);
12786 +
12787 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12788 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12789 + src += PAX_USER_SHADOW_BASE;
12790 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12791 + dst += PAX_USER_SHADOW_BASE;
12792 +#endif
12793 +
12794 + return copy_user_generic((__force_kernel void *)dst,
12795 + (__force_kernel const void *)src, size);
12796 }
12797 }
12798
12799 @@ -176,33 +276,75 @@ __must_check long strlen_user(const char __user *str);
12800 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12801 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12802
12803 -__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
12804 - unsigned size);
12805 +static __must_check __always_inline unsigned long
12806 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12807 +{
12808 + pax_track_stack();
12809 +
12810 + if (size > INT_MAX)
12811 + return size;
12812 +
12813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12814 + if (!__access_ok(VERIFY_READ, src, size))
12815 + return size;
12816
12817 -static __must_check __always_inline int
12818 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12819 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12820 + src += PAX_USER_SHADOW_BASE;
12821 +#endif
12822 +
12823 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12824 +}
12825 +
12826 +static __must_check __always_inline unsigned long
12827 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12828 {
12829 - return copy_user_generic((__force void *)dst, src, size);
12830 + if (size > INT_MAX)
12831 + return size;
12832 +
12833 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12834 + if (!__access_ok(VERIFY_WRITE, dst, size))
12835 + return size;
12836 +
12837 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12838 + dst += PAX_USER_SHADOW_BASE;
12839 +#endif
12840 +
12841 + return copy_user_generic((__force_kernel void *)dst, src, size);
12842 }
12843
12844 -extern long __copy_user_nocache(void *dst, const void __user *src,
12845 - unsigned size, int zerorest);
12846 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12847 + unsigned long size, int zerorest);
12848
12849 -static inline int
12850 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12851 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12852 {
12853 might_sleep();
12854 +
12855 + if (size > INT_MAX)
12856 + return size;
12857 +
12858 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12859 + if (!__access_ok(VERIFY_READ, src, size))
12860 + return size;
12861 +#endif
12862 +
12863 return __copy_user_nocache(dst, src, size, 1);
12864 }
12865
12866 -static inline int
12867 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12868 - unsigned size)
12869 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12870 + unsigned long size)
12871 {
12872 + if (size > INT_MAX)
12873 + return size;
12874 +
12875 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12876 + if (!__access_ok(VERIFY_READ, src, size))
12877 + return size;
12878 +#endif
12879 +
12880 return __copy_user_nocache(dst, src, size, 0);
12881 }
12882
12883 -unsigned long
12884 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12885 +extern unsigned long
12886 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12887
12888 #endif /* _ASM_X86_UACCESS_64_H */
12889 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12890 index 9064052..786cfbc 100644
12891 --- a/arch/x86/include/asm/vdso.h
12892 +++ b/arch/x86/include/asm/vdso.h
12893 @@ -25,7 +25,7 @@ extern const char VDSO32_PRELINK[];
12894 #define VDSO32_SYMBOL(base, name) \
12895 ({ \
12896 extern const char VDSO32_##name[]; \
12897 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12898 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12899 })
12900 #endif
12901
12902 diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
12903 index 3d61e20..9507180 100644
12904 --- a/arch/x86/include/asm/vgtod.h
12905 +++ b/arch/x86/include/asm/vgtod.h
12906 @@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12907 int sysctl_enabled;
12908 struct timezone sys_tz;
12909 struct { /* extract of a clocksource struct */
12910 + char name[8];
12911 cycle_t (*vread)(void);
12912 cycle_t cycle_last;
12913 cycle_t mask;
12914 diff --git a/arch/x86/include/asm/vmi.h b/arch/x86/include/asm/vmi.h
12915 index 61e08c0..b0da582 100644
12916 --- a/arch/x86/include/asm/vmi.h
12917 +++ b/arch/x86/include/asm/vmi.h
12918 @@ -191,6 +191,7 @@ struct vrom_header {
12919 u8 reserved[96]; /* Reserved for headers */
12920 char vmi_init[8]; /* VMI_Init jump point */
12921 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
12922 + char rom_data[8048]; /* rest of the option ROM */
12923 } __attribute__((packed));
12924
12925 struct pnp_header {
12926 diff --git a/arch/x86/include/asm/vmi_time.h b/arch/x86/include/asm/vmi_time.h
12927 index c6e0bee..fcb9f74 100644
12928 --- a/arch/x86/include/asm/vmi_time.h
12929 +++ b/arch/x86/include/asm/vmi_time.h
12930 @@ -43,7 +43,7 @@ extern struct vmi_timer_ops {
12931 int (*wallclock_updated)(void);
12932 void (*set_alarm)(u32 flags, u64 expiry, u64 period);
12933 void (*cancel_alarm)(u32 flags);
12934 -} vmi_timer_ops;
12935 +} __no_const vmi_timer_ops;
12936
12937 /* Prototypes */
12938 extern void __init vmi_time_init(void);
12939 diff --git a/arch/x86/include/asm/vsyscall.h b/arch/x86/include/asm/vsyscall.h
12940 index d0983d2..1f7c9e9 100644
12941 --- a/arch/x86/include/asm/vsyscall.h
12942 +++ b/arch/x86/include/asm/vsyscall.h
12943 @@ -15,9 +15,10 @@ enum vsyscall_num {
12944
12945 #ifdef __KERNEL__
12946 #include <linux/seqlock.h>
12947 +#include <linux/getcpu.h>
12948 +#include <linux/time.h>
12949
12950 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12951 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12952
12953 /* Definitions for CONFIG_GENERIC_TIME definitions */
12954 #define __section_vsyscall_gtod_data __attribute__ \
12955 @@ -31,7 +32,6 @@ enum vsyscall_num {
12956 #define VGETCPU_LSL 2
12957
12958 extern int __vgetcpu_mode;
12959 -extern volatile unsigned long __jiffies;
12960
12961 /* kernel space (writeable) */
12962 extern int vgetcpu_mode;
12963 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12964
12965 extern void map_vsyscall(void);
12966
12967 +extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12968 +extern time_t vtime(time_t *t);
12969 +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12970 #endif /* __KERNEL__ */
12971
12972 #endif /* _ASM_X86_VSYSCALL_H */
12973 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
12974 index 2c756fd..3377e37 100644
12975 --- a/arch/x86/include/asm/x86_init.h
12976 +++ b/arch/x86/include/asm/x86_init.h
12977 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
12978 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
12979 void (*find_smp_config)(unsigned int reserve);
12980 void (*get_smp_config)(unsigned int early);
12981 -};
12982 +} __no_const;
12983
12984 /**
12985 * struct x86_init_resources - platform specific resource related ops
12986 @@ -42,7 +42,7 @@ struct x86_init_resources {
12987 void (*probe_roms)(void);
12988 void (*reserve_resources)(void);
12989 char *(*memory_setup)(void);
12990 -};
12991 +} __no_const;
12992
12993 /**
12994 * struct x86_init_irqs - platform specific interrupt setup
12995 @@ -55,7 +55,7 @@ struct x86_init_irqs {
12996 void (*pre_vector_init)(void);
12997 void (*intr_init)(void);
12998 void (*trap_init)(void);
12999 -};
13000 +} __no_const;
13001
13002 /**
13003 * struct x86_init_oem - oem platform specific customizing functions
13004 @@ -65,7 +65,7 @@ struct x86_init_irqs {
13005 struct x86_init_oem {
13006 void (*arch_setup)(void);
13007 void (*banner)(void);
13008 -};
13009 +} __no_const;
13010
13011 /**
13012 * struct x86_init_paging - platform specific paging functions
13013 @@ -75,7 +75,7 @@ struct x86_init_oem {
13014 struct x86_init_paging {
13015 void (*pagetable_setup_start)(pgd_t *base);
13016 void (*pagetable_setup_done)(pgd_t *base);
13017 -};
13018 +} __no_const;
13019
13020 /**
13021 * struct x86_init_timers - platform specific timer setup
13022 @@ -88,7 +88,7 @@ struct x86_init_timers {
13023 void (*setup_percpu_clockev)(void);
13024 void (*tsc_pre_init)(void);
13025 void (*timer_init)(void);
13026 -};
13027 +} __no_const;
13028
13029 /**
13030 * struct x86_init_ops - functions for platform specific setup
13031 @@ -101,7 +101,7 @@ struct x86_init_ops {
13032 struct x86_init_oem oem;
13033 struct x86_init_paging paging;
13034 struct x86_init_timers timers;
13035 -};
13036 +} __no_const;
13037
13038 /**
13039 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13040 @@ -109,7 +109,7 @@ struct x86_init_ops {
13041 */
13042 struct x86_cpuinit_ops {
13043 void (*setup_percpu_clockev)(void);
13044 -};
13045 +} __no_const;
13046
13047 /**
13048 * struct x86_platform_ops - platform specific runtime functions
13049 @@ -121,7 +121,7 @@ struct x86_platform_ops {
13050 unsigned long (*calibrate_tsc)(void);
13051 unsigned long (*get_wallclock)(void);
13052 int (*set_wallclock)(unsigned long nowtime);
13053 -};
13054 +} __no_const;
13055
13056 extern struct x86_init_ops x86_init;
13057 extern struct x86_cpuinit_ops x86_cpuinit;
13058 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13059 index 727acc1..554f3eb 100644
13060 --- a/arch/x86/include/asm/xsave.h
13061 +++ b/arch/x86/include/asm/xsave.h
13062 @@ -56,6 +56,12 @@ static inline int xrstor_checking(struct xsave_struct *fx)
13063 static inline int xsave_user(struct xsave_struct __user *buf)
13064 {
13065 int err;
13066 +
13067 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13068 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13069 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13070 +#endif
13071 +
13072 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13073 "2:\n"
13074 ".section .fixup,\"ax\"\n"
13075 @@ -78,10 +84,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13076 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13077 {
13078 int err;
13079 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13080 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13081 u32 lmask = mask;
13082 u32 hmask = mask >> 32;
13083
13084 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13085 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13086 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13087 +#endif
13088 +
13089 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13090 "2:\n"
13091 ".section .fixup,\"ax\"\n"
13092 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13093 index 6a564ac..9b1340c 100644
13094 --- a/arch/x86/kernel/acpi/realmode/Makefile
13095 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13096 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13097 $(call cc-option, -fno-stack-protector) \
13098 $(call cc-option, -mpreferred-stack-boundary=2)
13099 KBUILD_CFLAGS += $(call cc-option, -m32)
13100 +ifdef CONSTIFY_PLUGIN
13101 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13102 +endif
13103 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13104 GCOV_PROFILE := n
13105
13106 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13107 index 580b4e2..d4129e4 100644
13108 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13109 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13110 @@ -91,6 +91,9 @@ _start:
13111 /* Do any other stuff... */
13112
13113 #ifndef CONFIG_64BIT
13114 + /* Recheck NX bit overrides (64bit path does this in trampoline) */
13115 + call verify_cpu
13116 +
13117 /* This could also be done in C code... */
13118 movl pmode_cr3, %eax
13119 movl %eax, %cr3
13120 @@ -104,7 +107,7 @@ _start:
13121 movl %eax, %ecx
13122 orl %edx, %ecx
13123 jz 1f
13124 - movl $0xc0000080, %ecx
13125 + mov $MSR_EFER, %ecx
13126 wrmsr
13127 1:
13128
13129 @@ -114,6 +117,7 @@ _start:
13130 movl pmode_cr0, %eax
13131 movl %eax, %cr0
13132 jmp pmode_return
13133 +# include "../../verify_cpu.S"
13134 #else
13135 pushw $0
13136 pushw trampoline_segment
13137 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13138 index ca93638..7042f24 100644
13139 --- a/arch/x86/kernel/acpi/sleep.c
13140 +++ b/arch/x86/kernel/acpi/sleep.c
13141 @@ -11,11 +11,12 @@
13142 #include <linux/cpumask.h>
13143 #include <asm/segment.h>
13144 #include <asm/desc.h>
13145 +#include <asm/e820.h>
13146
13147 #include "realmode/wakeup.h"
13148 #include "sleep.h"
13149
13150 -unsigned long acpi_wakeup_address;
13151 +unsigned long acpi_wakeup_address = 0x2000;
13152 unsigned long acpi_realmode_flags;
13153
13154 /* address in low memory of the wakeup routine. */
13155 @@ -98,9 +99,13 @@ int acpi_save_state_mem(void)
13156 #else /* CONFIG_64BIT */
13157 header->trampoline_segment = setup_trampoline() >> 4;
13158 #ifdef CONFIG_SMP
13159 - stack_start.sp = temp_stack + sizeof(temp_stack);
13160 + stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13161 +
13162 + pax_open_kernel();
13163 early_gdt_descr.address =
13164 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13165 + pax_close_kernel();
13166 +
13167 initial_gs = per_cpu_offset(smp_processor_id());
13168 #endif
13169 initial_code = (unsigned long)wakeup_long64;
13170 @@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
13171 return;
13172 }
13173
13174 - acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
13175 -
13176 - if (!acpi_realmode) {
13177 - printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
13178 - return;
13179 - }
13180 -
13181 - acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
13182 + reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
13183 + acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
13184 }
13185
13186
13187 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13188 index 8ded418..079961e 100644
13189 --- a/arch/x86/kernel/acpi/wakeup_32.S
13190 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13191 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13192 # and restore the stack ... but you need gdt for this to work
13193 movl saved_context_esp, %esp
13194
13195 - movl %cs:saved_magic, %eax
13196 - cmpl $0x12345678, %eax
13197 + cmpl $0x12345678, saved_magic
13198 jne bogus_magic
13199
13200 # jump to place where we left off
13201 - movl saved_eip, %eax
13202 - jmp *%eax
13203 + jmp *(saved_eip)
13204
13205 bogus_magic:
13206 jmp bogus_magic
13207 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13208 index de7353c..075da5f 100644
13209 --- a/arch/x86/kernel/alternative.c
13210 +++ b/arch/x86/kernel/alternative.c
13211 @@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13212
13213 BUG_ON(p->len > MAX_PATCH_LEN);
13214 /* prep the buffer with the original instructions */
13215 - memcpy(insnbuf, p->instr, p->len);
13216 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13217 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13218 (unsigned long)p->instr, p->len);
13219
13220 @@ -475,7 +475,7 @@ void __init alternative_instructions(void)
13221 if (smp_alt_once)
13222 free_init_pages("SMP alternatives",
13223 (unsigned long)__smp_locks,
13224 - (unsigned long)__smp_locks_end);
13225 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13226
13227 restart_nmi();
13228 }
13229 @@ -492,13 +492,17 @@ void __init alternative_instructions(void)
13230 * instructions. And on the local CPU you need to be protected again NMI or MCE
13231 * handlers seeing an inconsistent instruction while you patch.
13232 */
13233 -static void *__init_or_module text_poke_early(void *addr, const void *opcode,
13234 +static void *__kprobes text_poke_early(void *addr, const void *opcode,
13235 size_t len)
13236 {
13237 unsigned long flags;
13238 local_irq_save(flags);
13239 - memcpy(addr, opcode, len);
13240 +
13241 + pax_open_kernel();
13242 + memcpy(ktla_ktva(addr), opcode, len);
13243 sync_core();
13244 + pax_close_kernel();
13245 +
13246 local_irq_restore(flags);
13247 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13248 that causes hangs on some VIA CPUs. */
13249 @@ -520,35 +524,21 @@ static void *__init_or_module text_poke_early(void *addr, const void *opcode,
13250 */
13251 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13252 {
13253 - unsigned long flags;
13254 - char *vaddr;
13255 + unsigned char *vaddr = ktla_ktva(addr);
13256 struct page *pages[2];
13257 - int i;
13258 + size_t i;
13259
13260 if (!core_kernel_text((unsigned long)addr)) {
13261 - pages[0] = vmalloc_to_page(addr);
13262 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13263 + pages[0] = vmalloc_to_page(vaddr);
13264 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13265 } else {
13266 - pages[0] = virt_to_page(addr);
13267 + pages[0] = virt_to_page(vaddr);
13268 WARN_ON(!PageReserved(pages[0]));
13269 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13270 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13271 }
13272 BUG_ON(!pages[0]);
13273 - local_irq_save(flags);
13274 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13275 - if (pages[1])
13276 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13277 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13278 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13279 - clear_fixmap(FIX_TEXT_POKE0);
13280 - if (pages[1])
13281 - clear_fixmap(FIX_TEXT_POKE1);
13282 - local_flush_tlb();
13283 - sync_core();
13284 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13285 - that causes hangs on some VIA CPUs. */
13286 + text_poke_early(addr, opcode, len);
13287 for (i = 0; i < len; i++)
13288 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13289 - local_irq_restore(flags);
13290 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13291 return addr;
13292 }
13293 diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
13294 index 3a44b75..1601800 100644
13295 --- a/arch/x86/kernel/amd_iommu.c
13296 +++ b/arch/x86/kernel/amd_iommu.c
13297 @@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(void)
13298 }
13299 }
13300
13301 -static struct dma_map_ops amd_iommu_dma_ops = {
13302 +static const struct dma_map_ops amd_iommu_dma_ops = {
13303 .alloc_coherent = alloc_coherent,
13304 .free_coherent = free_coherent,
13305 .map_page = map_page,
13306 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13307 index 1d2d670..8e3f477 100644
13308 --- a/arch/x86/kernel/apic/apic.c
13309 +++ b/arch/x86/kernel/apic/apic.c
13310 @@ -170,7 +170,7 @@ int first_system_vector = 0xfe;
13311 /*
13312 * Debug level, exported for io_apic.c
13313 */
13314 -unsigned int apic_verbosity;
13315 +int apic_verbosity;
13316
13317 int pic_mode;
13318
13319 @@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13320 apic_write(APIC_ESR, 0);
13321 v1 = apic_read(APIC_ESR);
13322 ack_APIC_irq();
13323 - atomic_inc(&irq_err_count);
13324 + atomic_inc_unchecked(&irq_err_count);
13325
13326 /*
13327 * Here is what the APIC error bits mean:
13328 @@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(void)
13329 u16 *bios_cpu_apicid;
13330 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
13331
13332 + pax_track_stack();
13333 +
13334 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
13335 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
13336
13337 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13338 index 8928d97..f799cea 100644
13339 --- a/arch/x86/kernel/apic/io_apic.c
13340 +++ b/arch/x86/kernel/apic/io_apic.c
13341 @@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapic_entries(void)
13342 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
13343 GFP_ATOMIC);
13344 if (!ioapic_entries)
13345 - return 0;
13346 + return NULL;
13347
13348 for (apic = 0; apic < nr_ioapics; apic++) {
13349 ioapic_entries[apic] =
13350 @@ -733,7 +733,7 @@ nomem:
13351 kfree(ioapic_entries[apic]);
13352 kfree(ioapic_entries);
13353
13354 - return 0;
13355 + return NULL;
13356 }
13357
13358 /*
13359 @@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13360 }
13361 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13362
13363 -void lock_vector_lock(void)
13364 +void lock_vector_lock(void) __acquires(vector_lock)
13365 {
13366 /* Used to the online set of cpus does not change
13367 * during assign_irq_vector.
13368 @@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
13369 spin_lock(&vector_lock);
13370 }
13371
13372 -void unlock_vector_lock(void)
13373 +void unlock_vector_lock(void) __releases(vector_lock)
13374 {
13375 spin_unlock(&vector_lock);
13376 }
13377 @@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int irq)
13378 ack_APIC_irq();
13379 }
13380
13381 -atomic_t irq_mis_count;
13382 +atomic_unchecked_t irq_mis_count;
13383
13384 static void ack_apic_level(unsigned int irq)
13385 {
13386 @@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int irq)
13387
13388 /* Tail end of version 0x11 I/O APIC bug workaround */
13389 if (!(v & (1 << (i & 0x1f)))) {
13390 - atomic_inc(&irq_mis_count);
13391 + atomic_inc_unchecked(&irq_mis_count);
13392 spin_lock(&ioapic_lock);
13393 __mask_and_edge_IO_APIC_irq(cfg);
13394 __unmask_and_level_IO_APIC_irq(cfg);
13395 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13396 index 151ace6..f317474 100644
13397 --- a/arch/x86/kernel/apm_32.c
13398 +++ b/arch/x86/kernel/apm_32.c
13399 @@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
13400 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13401 * even though they are called in protected mode.
13402 */
13403 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13404 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13405 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13406
13407 static const char driver_version[] = "1.16ac"; /* no spaces */
13408 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13409 BUG_ON(cpu != 0);
13410 gdt = get_cpu_gdt_table(cpu);
13411 save_desc_40 = gdt[0x40 / 8];
13412 +
13413 + pax_open_kernel();
13414 gdt[0x40 / 8] = bad_bios_desc;
13415 + pax_close_kernel();
13416
13417 apm_irq_save(flags);
13418 APM_DO_SAVE_SEGS;
13419 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13420 &call->esi);
13421 APM_DO_RESTORE_SEGS;
13422 apm_irq_restore(flags);
13423 +
13424 + pax_open_kernel();
13425 gdt[0x40 / 8] = save_desc_40;
13426 + pax_close_kernel();
13427 +
13428 put_cpu();
13429
13430 return call->eax & 0xff;
13431 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13432 BUG_ON(cpu != 0);
13433 gdt = get_cpu_gdt_table(cpu);
13434 save_desc_40 = gdt[0x40 / 8];
13435 +
13436 + pax_open_kernel();
13437 gdt[0x40 / 8] = bad_bios_desc;
13438 + pax_close_kernel();
13439
13440 apm_irq_save(flags);
13441 APM_DO_SAVE_SEGS;
13442 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13443 &call->eax);
13444 APM_DO_RESTORE_SEGS;
13445 apm_irq_restore(flags);
13446 +
13447 + pax_open_kernel();
13448 gdt[0x40 / 8] = save_desc_40;
13449 + pax_close_kernel();
13450 +
13451 put_cpu();
13452 return error;
13453 }
13454 @@ -975,7 +989,7 @@ recalc:
13455
13456 static void apm_power_off(void)
13457 {
13458 - unsigned char po_bios_call[] = {
13459 + const unsigned char po_bios_call[] = {
13460 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
13461 0x8e, 0xd0, /* movw ax,ss */
13462 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
13463 @@ -2357,12 +2371,15 @@ static int __init apm_init(void)
13464 * code to that CPU.
13465 */
13466 gdt = get_cpu_gdt_table(0);
13467 +
13468 + pax_open_kernel();
13469 set_desc_base(&gdt[APM_CS >> 3],
13470 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13471 set_desc_base(&gdt[APM_CS_16 >> 3],
13472 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13473 set_desc_base(&gdt[APM_DS >> 3],
13474 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13475 + pax_close_kernel();
13476
13477 proc_create("apm", 0, NULL, &apm_file_ops);
13478
13479 diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
13480 index dfdbf64..9b2b6ce 100644
13481 --- a/arch/x86/kernel/asm-offsets_32.c
13482 +++ b/arch/x86/kernel/asm-offsets_32.c
13483 @@ -51,7 +51,6 @@ void foo(void)
13484 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
13485 BLANK();
13486
13487 - OFFSET(TI_task, thread_info, task);
13488 OFFSET(TI_exec_domain, thread_info, exec_domain);
13489 OFFSET(TI_flags, thread_info, flags);
13490 OFFSET(TI_status, thread_info, status);
13491 @@ -60,6 +59,8 @@ void foo(void)
13492 OFFSET(TI_restart_block, thread_info, restart_block);
13493 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
13494 OFFSET(TI_cpu, thread_info, cpu);
13495 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13496 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13497 BLANK();
13498
13499 OFFSET(GDS_size, desc_ptr, size);
13500 @@ -99,6 +100,7 @@ void foo(void)
13501
13502 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13503 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13504 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13505 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
13506 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
13507 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
13508 @@ -115,6 +117,11 @@ void foo(void)
13509 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
13510 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13511 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13512 +
13513 +#ifdef CONFIG_PAX_KERNEXEC
13514 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13515 +#endif
13516 +
13517 #endif
13518
13519 #ifdef CONFIG_XEN
13520 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13521 index 4a6aeed..371de20 100644
13522 --- a/arch/x86/kernel/asm-offsets_64.c
13523 +++ b/arch/x86/kernel/asm-offsets_64.c
13524 @@ -44,6 +44,8 @@ int main(void)
13525 ENTRY(addr_limit);
13526 ENTRY(preempt_count);
13527 ENTRY(status);
13528 + ENTRY(lowest_stack);
13529 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13530 #ifdef CONFIG_IA32_EMULATION
13531 ENTRY(sysenter_return);
13532 #endif
13533 @@ -63,6 +65,18 @@ int main(void)
13534 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13535 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
13536 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13537 +
13538 +#ifdef CONFIG_PAX_KERNEXEC
13539 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13540 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13541 +#endif
13542 +
13543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13544 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13545 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13546 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13547 +#endif
13548 +
13549 #endif
13550
13551
13552 @@ -115,6 +129,7 @@ int main(void)
13553 ENTRY(cr8);
13554 BLANK();
13555 #undef ENTRY
13556 + DEFINE(TSS_size, sizeof(struct tss_struct));
13557 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
13558 BLANK();
13559 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
13560 @@ -130,6 +145,7 @@ int main(void)
13561
13562 BLANK();
13563 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13564 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13565 #ifdef CONFIG_XEN
13566 BLANK();
13567 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13568 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13569 index ff502cc..dc5133e 100644
13570 --- a/arch/x86/kernel/cpu/Makefile
13571 +++ b/arch/x86/kernel/cpu/Makefile
13572 @@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
13573 CFLAGS_REMOVE_common.o = -pg
13574 endif
13575
13576 -# Make sure load_percpu_segment has no stackprotector
13577 -nostackp := $(call cc-option, -fno-stack-protector)
13578 -CFLAGS_common.o := $(nostackp)
13579 -
13580 obj-y := intel_cacheinfo.o addon_cpuid_features.o
13581 obj-y += proc.o capflags.o powerflags.o common.o
13582 obj-y += vmware.o hypervisor.o sched.o
13583 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13584 index 6e082dc..a0b5f36 100644
13585 --- a/arch/x86/kernel/cpu/amd.c
13586 +++ b/arch/x86/kernel/cpu/amd.c
13587 @@ -602,7 +602,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13588 unsigned int size)
13589 {
13590 /* AMD errata T13 (order #21922) */
13591 - if ((c->x86 == 6)) {
13592 + if (c->x86 == 6) {
13593 /* Duron Rev A0 */
13594 if (c->x86_model == 3 && c->x86_mask == 0)
13595 size = 64;
13596 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13597 index 4e34d10..a53b130a 100644
13598 --- a/arch/x86/kernel/cpu/common.c
13599 +++ b/arch/x86/kernel/cpu/common.c
13600 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13601
13602 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13603
13604 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13605 -#ifdef CONFIG_X86_64
13606 - /*
13607 - * We need valid kernel segments for data and code in long mode too
13608 - * IRET will check the segment types kkeil 2000/10/28
13609 - * Also sysret mandates a special GDT layout
13610 - *
13611 - * TLS descriptors are currently at a different place compared to i386.
13612 - * Hopefully nobody expects them at a fixed place (Wine?)
13613 - */
13614 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13615 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13616 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13617 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13618 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13619 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13620 -#else
13621 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13622 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13623 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13624 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13625 - /*
13626 - * Segments used for calling PnP BIOS have byte granularity.
13627 - * They code segments and data segments have fixed 64k limits,
13628 - * the transfer segment sizes are set at run time.
13629 - */
13630 - /* 32-bit code */
13631 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13632 - /* 16-bit code */
13633 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13634 - /* 16-bit data */
13635 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13636 - /* 16-bit data */
13637 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13638 - /* 16-bit data */
13639 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13640 - /*
13641 - * The APM segments have byte granularity and their bases
13642 - * are set at run time. All have 64k limits.
13643 - */
13644 - /* 32-bit code */
13645 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13646 - /* 16-bit code */
13647 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13648 - /* data */
13649 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13650 -
13651 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13652 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13653 - GDT_STACK_CANARY_INIT
13654 -#endif
13655 -} };
13656 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13657 -
13658 static int __init x86_xsave_setup(char *s)
13659 {
13660 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13661 @@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
13662 {
13663 struct desc_ptr gdt_descr;
13664
13665 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13666 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13667 gdt_descr.size = GDT_SIZE - 1;
13668 load_gdt(&gdt_descr);
13669 /* Reload the per-cpu base */
13670 @@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13671 /* Filter out anything that depends on CPUID levels we don't have */
13672 filter_cpuid_features(c, true);
13673
13674 +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
13675 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13676 +#endif
13677 +
13678 /* If the model name is still unset, do table lookup. */
13679 if (!c->x86_model_id[0]) {
13680 const char *p;
13681 @@ -980,6 +930,9 @@ static __init int setup_disablecpuid(char *arg)
13682 }
13683 __setup("clearcpuid=", setup_disablecpuid);
13684
13685 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13686 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13687 +
13688 #ifdef CONFIG_X86_64
13689 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13690
13691 @@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13692 EXPORT_PER_CPU_SYMBOL(current_task);
13693
13694 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13695 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13696 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13697 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13698
13699 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13700 @@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13701 {
13702 memset(regs, 0, sizeof(struct pt_regs));
13703 regs->fs = __KERNEL_PERCPU;
13704 - regs->gs = __KERNEL_STACK_CANARY;
13705 + savesegment(gs, regs->gs);
13706
13707 return regs;
13708 }
13709 @@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
13710 int i;
13711
13712 cpu = stack_smp_processor_id();
13713 - t = &per_cpu(init_tss, cpu);
13714 + t = init_tss + cpu;
13715 orig_ist = &per_cpu(orig_ist, cpu);
13716
13717 #ifdef CONFIG_NUMA
13718 @@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
13719 switch_to_new_gdt(cpu);
13720 loadsegment(fs, 0);
13721
13722 - load_idt((const struct desc_ptr *)&idt_descr);
13723 + load_idt(&idt_descr);
13724
13725 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13726 syscall_init();
13727 @@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
13728 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13729 barrier();
13730
13731 - check_efer();
13732 if (cpu != 0)
13733 enable_x2apic();
13734
13735 @@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
13736 {
13737 int cpu = smp_processor_id();
13738 struct task_struct *curr = current;
13739 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13740 + struct tss_struct *t = init_tss + cpu;
13741 struct thread_struct *thread = &curr->thread;
13742
13743 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13744 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13745 index 6a77cca..4f4fca0 100644
13746 --- a/arch/x86/kernel/cpu/intel.c
13747 +++ b/arch/x86/kernel/cpu/intel.c
13748 @@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13749 * Update the IDT descriptor and reload the IDT so that
13750 * it uses the read-only mapped virtual address.
13751 */
13752 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13753 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13754 load_idt(&idt_descr);
13755 }
13756 #endif
13757 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
13758 index 417990f..96dc36b 100644
13759 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
13760 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
13761 @@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
13762 return ret;
13763 }
13764
13765 -static struct sysfs_ops sysfs_ops = {
13766 +static const struct sysfs_ops sysfs_ops = {
13767 .show = show,
13768 .store = store,
13769 };
13770 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13771 index 472763d..9831e11 100644
13772 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13773 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13774 @@ -211,7 +211,9 @@ static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13775 static int inject_init(void)
13776 {
13777 printk(KERN_INFO "Machine check injector initialized\n");
13778 - mce_chrdev_ops.write = mce_write;
13779 + pax_open_kernel();
13780 + *(void **)&mce_chrdev_ops.write = mce_write;
13781 + pax_close_kernel();
13782 register_die_notifier(&mce_raise_nb);
13783 return 0;
13784 }
13785 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13786 index 0f16a2b..21740f5 100644
13787 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13788 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13789 @@ -43,6 +43,7 @@
13790 #include <asm/ipi.h>
13791 #include <asm/mce.h>
13792 #include <asm/msr.h>
13793 +#include <asm/local.h>
13794
13795 #include "mce-internal.h"
13796
13797 @@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
13798 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13799 m->cs, m->ip);
13800
13801 - if (m->cs == __KERNEL_CS)
13802 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13803 print_symbol("{%s}", m->ip);
13804 pr_cont("\n");
13805 }
13806 @@ -221,10 +222,10 @@ static void print_mce_tail(void)
13807
13808 #define PANIC_TIMEOUT 5 /* 5 seconds */
13809
13810 -static atomic_t mce_paniced;
13811 +static atomic_unchecked_t mce_paniced;
13812
13813 static int fake_panic;
13814 -static atomic_t mce_fake_paniced;
13815 +static atomic_unchecked_t mce_fake_paniced;
13816
13817 /* Panic in progress. Enable interrupts and wait for final IPI */
13818 static void wait_for_panic(void)
13819 @@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13820 /*
13821 * Make sure only one CPU runs in machine check panic
13822 */
13823 - if (atomic_inc_return(&mce_paniced) > 1)
13824 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13825 wait_for_panic();
13826 barrier();
13827
13828 @@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13829 console_verbose();
13830 } else {
13831 /* Don't log too much for fake panic */
13832 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13833 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13834 return;
13835 }
13836 print_mce_head();
13837 @@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
13838 * might have been modified by someone else.
13839 */
13840 rmb();
13841 - if (atomic_read(&mce_paniced))
13842 + if (atomic_read_unchecked(&mce_paniced))
13843 wait_for_panic();
13844 if (!monarch_timeout)
13845 goto out;
13846 @@ -1394,7 +1395,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13847 }
13848
13849 /* Call the installed machine check handler for this CPU setup. */
13850 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13851 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13852 unexpected_machine_check;
13853
13854 /*
13855 @@ -1416,7 +1417,9 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
13856 return;
13857 }
13858
13859 + pax_open_kernel();
13860 machine_check_vector = do_machine_check;
13861 + pax_close_kernel();
13862
13863 mce_init();
13864 mce_cpu_features(c);
13865 @@ -1429,14 +1432,14 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
13866 */
13867
13868 static DEFINE_SPINLOCK(mce_state_lock);
13869 -static int open_count; /* #times opened */
13870 +static local_t open_count; /* #times opened */
13871 static int open_exclu; /* already open exclusive? */
13872
13873 static int mce_open(struct inode *inode, struct file *file)
13874 {
13875 spin_lock(&mce_state_lock);
13876
13877 - if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13878 + if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13879 spin_unlock(&mce_state_lock);
13880
13881 return -EBUSY;
13882 @@ -1444,7 +1447,7 @@ static int mce_open(struct inode *inode, struct file *file)
13883
13884 if (file->f_flags & O_EXCL)
13885 open_exclu = 1;
13886 - open_count++;
13887 + local_inc(&open_count);
13888
13889 spin_unlock(&mce_state_lock);
13890
13891 @@ -1455,7 +1458,7 @@ static int mce_release(struct inode *inode, struct file *file)
13892 {
13893 spin_lock(&mce_state_lock);
13894
13895 - open_count--;
13896 + local_dec(&open_count);
13897 open_exclu = 0;
13898
13899 spin_unlock(&mce_state_lock);
13900 @@ -2082,7 +2085,7 @@ struct dentry *mce_get_debugfs_dir(void)
13901 static void mce_reset(void)
13902 {
13903 cpu_missing = 0;
13904 - atomic_set(&mce_fake_paniced, 0);
13905 + atomic_set_unchecked(&mce_fake_paniced, 0);
13906 atomic_set(&mce_executing, 0);
13907 atomic_set(&mce_callin, 0);
13908 atomic_set(&global_nwo, 0);
13909 diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13910 index ef3cd31..9d2f6ab 100644
13911 --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
13912 +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13913 @@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
13914 return ret;
13915 }
13916
13917 -static struct sysfs_ops threshold_ops = {
13918 +static const struct sysfs_ops threshold_ops = {
13919 .show = show,
13920 .store = store,
13921 };
13922 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13923 index 5c0e653..1e82c7c 100644
13924 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13925 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13926 @@ -50,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13927 if (!cpu_has(c, X86_FEATURE_MCE))
13928 return;
13929
13930 + pax_open_kernel();
13931 machine_check_vector = pentium_machine_check;
13932 + pax_close_kernel();
13933 /* Make sure the vector pointer is visible before we enable MCEs: */
13934 wmb();
13935
13936 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13937 index 54060f5..e6ba93d 100644
13938 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13939 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13940 @@ -24,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13941 {
13942 u32 lo, hi;
13943
13944 + pax_open_kernel();
13945 machine_check_vector = winchip_machine_check;
13946 + pax_close_kernel();
13947 /* Make sure the vector pointer is visible before we enable MCEs: */
13948 wmb();
13949
13950 diff --git a/arch/x86/kernel/cpu/mtrr/amd.c b/arch/x86/kernel/cpu/mtrr/amd.c
13951 index 33af141..92ba9cd 100644
13952 --- a/arch/x86/kernel/cpu/mtrr/amd.c
13953 +++ b/arch/x86/kernel/cpu/mtrr/amd.c
13954 @@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base, unsigned long size, unsigned int type)
13955 return 0;
13956 }
13957
13958 -static struct mtrr_ops amd_mtrr_ops = {
13959 +static const struct mtrr_ops amd_mtrr_ops = {
13960 .vendor = X86_VENDOR_AMD,
13961 .set = amd_set_mtrr,
13962 .get = amd_get_mtrr,
13963 diff --git a/arch/x86/kernel/cpu/mtrr/centaur.c b/arch/x86/kernel/cpu/mtrr/centaur.c
13964 index de89f14..316fe3e 100644
13965 --- a/arch/x86/kernel/cpu/mtrr/centaur.c
13966 +++ b/arch/x86/kernel/cpu/mtrr/centaur.c
13967 @@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long base, unsigned long size, unsigned int t
13968 return 0;
13969 }
13970
13971 -static struct mtrr_ops centaur_mtrr_ops = {
13972 +static const struct mtrr_ops centaur_mtrr_ops = {
13973 .vendor = X86_VENDOR_CENTAUR,
13974 .set = centaur_set_mcr,
13975 .get = centaur_get_mcr,
13976 diff --git a/arch/x86/kernel/cpu/mtrr/cyrix.c b/arch/x86/kernel/cpu/mtrr/cyrix.c
13977 index 228d982..68a3343 100644
13978 --- a/arch/x86/kernel/cpu/mtrr/cyrix.c
13979 +++ b/arch/x86/kernel/cpu/mtrr/cyrix.c
13980 @@ -265,7 +265,7 @@ static void cyrix_set_all(void)
13981 post_set();
13982 }
13983
13984 -static struct mtrr_ops cyrix_mtrr_ops = {
13985 +static const struct mtrr_ops cyrix_mtrr_ops = {
13986 .vendor = X86_VENDOR_CYRIX,
13987 .set_all = cyrix_set_all,
13988 .set = cyrix_set_arr,
13989 diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
13990 index 55da0c5..4d75584 100644
13991 --- a/arch/x86/kernel/cpu/mtrr/generic.c
13992 +++ b/arch/x86/kernel/cpu/mtrr/generic.c
13993 @@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
13994 /*
13995 * Generic structure...
13996 */
13997 -struct mtrr_ops generic_mtrr_ops = {
13998 +const struct mtrr_ops generic_mtrr_ops = {
13999 .use_intel_if = 1,
14000 .set_all = generic_set_all,
14001 .get = generic_get_mtrr,
14002 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14003 index fd60f09..c94ef52 100644
14004 --- a/arch/x86/kernel/cpu/mtrr/main.c
14005 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14006 @@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
14007 u64 size_or_mask, size_and_mask;
14008 static bool mtrr_aps_delayed_init;
14009
14010 -static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14011 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14012
14013 -struct mtrr_ops *mtrr_if;
14014 +const struct mtrr_ops *mtrr_if;
14015
14016 static void set_mtrr(unsigned int reg, unsigned long base,
14017 unsigned long size, mtrr_type type);
14018
14019 -void set_mtrr_ops(struct mtrr_ops *ops)
14020 +void set_mtrr_ops(const struct mtrr_ops *ops)
14021 {
14022 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
14023 mtrr_ops[ops->vendor] = ops;
14024 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14025 index a501dee..816c719 100644
14026 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14027 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14028 @@ -25,14 +25,14 @@ struct mtrr_ops {
14029 int (*validate_add_page)(unsigned long base, unsigned long size,
14030 unsigned int type);
14031 int (*have_wrcomb)(void);
14032 -};
14033 +} __do_const;
14034
14035 extern int generic_get_free_region(unsigned long base, unsigned long size,
14036 int replace_reg);
14037 extern int generic_validate_add_page(unsigned long base, unsigned long size,
14038 unsigned int type);
14039
14040 -extern struct mtrr_ops generic_mtrr_ops;
14041 +extern const struct mtrr_ops generic_mtrr_ops;
14042
14043 extern int positive_have_wrcomb(void);
14044
14045 @@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int index,
14046 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
14047 void get_mtrr_state(void);
14048
14049 -extern void set_mtrr_ops(struct mtrr_ops *ops);
14050 +extern void set_mtrr_ops(const struct mtrr_ops *ops);
14051
14052 extern u64 size_or_mask, size_and_mask;
14053 -extern struct mtrr_ops *mtrr_if;
14054 +extern const struct mtrr_ops *mtrr_if;
14055
14056 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
14057 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
14058 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14059 index 0ff02ca..fc49a60 100644
14060 --- a/arch/x86/kernel/cpu/perf_event.c
14061 +++ b/arch/x86/kernel/cpu/perf_event.c
14062 @@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event *event,
14063 * count to the generic event atomically:
14064 */
14065 again:
14066 - prev_raw_count = atomic64_read(&hwc->prev_count);
14067 + prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
14068 rdmsrl(hwc->event_base + idx, new_raw_count);
14069
14070 - if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
14071 + if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
14072 new_raw_count) != prev_raw_count)
14073 goto again;
14074
14075 @@ -741,7 +741,7 @@ again:
14076 delta = (new_raw_count << shift) - (prev_raw_count << shift);
14077 delta >>= shift;
14078
14079 - atomic64_add(delta, &event->count);
14080 + atomic64_add_unchecked(delta, &event->count);
14081 atomic64_sub(delta, &hwc->period_left);
14082
14083 return new_raw_count;
14084 @@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_event *event,
14085 * The hw event starts counting from this event offset,
14086 * mark it to be able to extra future deltas:
14087 */
14088 - atomic64_set(&hwc->prev_count, (u64)-left);
14089 + atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
14090
14091 err = checking_wrmsrl(hwc->event_base + idx,
14092 (u64)(-left) & x86_pmu.event_mask);
14093 @@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry)
14094 break;
14095
14096 callchain_store(entry, frame.return_address);
14097 - fp = frame.next_frame;
14098 + fp = (__force const void __user *)frame.next_frame;
14099 }
14100 }
14101
14102 diff --git a/arch/x86/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c
14103 index 898df97..9e82503 100644
14104 --- a/arch/x86/kernel/cpu/perfctr-watchdog.c
14105 +++ b/arch/x86/kernel/cpu/perfctr-watchdog.c
14106 @@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
14107
14108 /* Interface defining a CPU specific perfctr watchdog */
14109 struct wd_ops {
14110 - int (*reserve)(void);
14111 - void (*unreserve)(void);
14112 - int (*setup)(unsigned nmi_hz);
14113 - void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
14114 - void (*stop)(void);
14115 + int (* const reserve)(void);
14116 + void (* const unreserve)(void);
14117 + int (* const setup)(unsigned nmi_hz);
14118 + void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
14119 + void (* const stop)(void);
14120 unsigned perfctr;
14121 unsigned evntsel;
14122 u64 checkbit;
14123 @@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
14124 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
14125 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
14126
14127 +/* cannot be const */
14128 static struct wd_ops intel_arch_wd_ops;
14129
14130 static int setup_intel_arch_watchdog(unsigned nmi_hz)
14131 @@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(unsigned nmi_hz)
14132 return 1;
14133 }
14134
14135 +/* cannot be const */
14136 static struct wd_ops intel_arch_wd_ops __read_mostly = {
14137 .reserve = single_msr_reserve,
14138 .unreserve = single_msr_unreserve,
14139 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14140 index ff95824..2ffdcb5 100644
14141 --- a/arch/x86/kernel/crash.c
14142 +++ b/arch/x86/kernel/crash.c
14143 @@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu, struct die_args *args)
14144 regs = args->regs;
14145
14146 #ifdef CONFIG_X86_32
14147 - if (!user_mode_vm(regs)) {
14148 + if (!user_mode(regs)) {
14149 crash_fixup_ss_esp(&fixed_regs, regs);
14150 regs = &fixed_regs;
14151 }
14152 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14153 index 37250fe..bf2ec74 100644
14154 --- a/arch/x86/kernel/doublefault_32.c
14155 +++ b/arch/x86/kernel/doublefault_32.c
14156 @@ -11,7 +11,7 @@
14157
14158 #define DOUBLEFAULT_STACKSIZE (1024)
14159 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14160 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14161 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14162
14163 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14164
14165 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14166 unsigned long gdt, tss;
14167
14168 store_gdt(&gdt_desc);
14169 - gdt = gdt_desc.address;
14170 + gdt = (unsigned long)gdt_desc.address;
14171
14172 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14173
14174 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14175 /* 0x2 bit is always set */
14176 .flags = X86_EFLAGS_SF | 0x2,
14177 .sp = STACK_START,
14178 - .es = __USER_DS,
14179 + .es = __KERNEL_DS,
14180 .cs = __KERNEL_CS,
14181 .ss = __KERNEL_DS,
14182 - .ds = __USER_DS,
14183 + .ds = __KERNEL_DS,
14184 .fs = __KERNEL_PERCPU,
14185
14186 .__cr3 = __pa_nodebug(swapper_pg_dir),
14187 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14188 index 2d8a371..4fa6ae6 100644
14189 --- a/arch/x86/kernel/dumpstack.c
14190 +++ b/arch/x86/kernel/dumpstack.c
14191 @@ -2,6 +2,9 @@
14192 * Copyright (C) 1991, 1992 Linus Torvalds
14193 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14194 */
14195 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14196 +#define __INCLUDED_BY_HIDESYM 1
14197 +#endif
14198 #include <linux/kallsyms.h>
14199 #include <linux/kprobes.h>
14200 #include <linux/uaccess.h>
14201 @@ -28,7 +31,7 @@ static int die_counter;
14202
14203 void printk_address(unsigned long address, int reliable)
14204 {
14205 - printk(" [<%p>] %s%pS\n", (void *) address,
14206 + printk(" [<%p>] %s%pA\n", (void *) address,
14207 reliable ? "" : "? ", (void *) address);
14208 }
14209
14210 @@ -36,9 +39,8 @@ void printk_address(unsigned long address, int reliable)
14211 static void
14212 print_ftrace_graph_addr(unsigned long addr, void *data,
14213 const struct stacktrace_ops *ops,
14214 - struct thread_info *tinfo, int *graph)
14215 + struct task_struct *task, int *graph)
14216 {
14217 - struct task_struct *task = tinfo->task;
14218 unsigned long ret_addr;
14219 int index = task->curr_ret_stack;
14220
14221 @@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14222 static inline void
14223 print_ftrace_graph_addr(unsigned long addr, void *data,
14224 const struct stacktrace_ops *ops,
14225 - struct thread_info *tinfo, int *graph)
14226 + struct task_struct *task, int *graph)
14227 { }
14228 #endif
14229
14230 @@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14231 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14232 */
14233
14234 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14235 - void *p, unsigned int size, void *end)
14236 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14237 {
14238 - void *t = tinfo;
14239 if (end) {
14240 if (p < end && p >= (end-THREAD_SIZE))
14241 return 1;
14242 @@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14243 }
14244
14245 unsigned long
14246 -print_context_stack(struct thread_info *tinfo,
14247 +print_context_stack(struct task_struct *task, void *stack_start,
14248 unsigned long *stack, unsigned long bp,
14249 const struct stacktrace_ops *ops, void *data,
14250 unsigned long *end, int *graph)
14251 {
14252 struct stack_frame *frame = (struct stack_frame *)bp;
14253
14254 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14255 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14256 unsigned long addr;
14257
14258 addr = *stack;
14259 @@ -103,7 +103,7 @@ print_context_stack(struct thread_info *tinfo,
14260 } else {
14261 ops->address(data, addr, 0);
14262 }
14263 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14264 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14265 }
14266 stack++;
14267 }
14268 @@ -180,7 +180,7 @@ void dump_stack(void)
14269 #endif
14270
14271 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14272 - current->pid, current->comm, print_tainted(),
14273 + task_pid_nr(current), current->comm, print_tainted(),
14274 init_utsname()->release,
14275 (int)strcspn(init_utsname()->version, " "),
14276 init_utsname()->version);
14277 @@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
14278 return flags;
14279 }
14280
14281 +extern void gr_handle_kernel_exploit(void);
14282 +
14283 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14284 {
14285 if (regs && kexec_should_crash(current))
14286 @@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14287 panic("Fatal exception in interrupt");
14288 if (panic_on_oops)
14289 panic("Fatal exception");
14290 - do_exit(signr);
14291 +
14292 + gr_handle_kernel_exploit();
14293 +
14294 + do_group_exit(signr);
14295 }
14296
14297 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14298 @@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14299 unsigned long flags = oops_begin();
14300 int sig = SIGSEGV;
14301
14302 - if (!user_mode_vm(regs))
14303 + if (!user_mode(regs))
14304 report_bug(regs->ip, regs);
14305
14306 if (__die(str, regs, err))
14307 diff --git a/arch/x86/kernel/dumpstack.h b/arch/x86/kernel/dumpstack.h
14308 index 81086c2..13e8b17 100644
14309 --- a/arch/x86/kernel/dumpstack.h
14310 +++ b/arch/x86/kernel/dumpstack.h
14311 @@ -15,7 +15,7 @@
14312 #endif
14313
14314 extern unsigned long
14315 -print_context_stack(struct thread_info *tinfo,
14316 +print_context_stack(struct task_struct *task, void *stack_start,
14317 unsigned long *stack, unsigned long bp,
14318 const struct stacktrace_ops *ops, void *data,
14319 unsigned long *end, int *graph);
14320 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14321 index f7dd2a7..504f53b 100644
14322 --- a/arch/x86/kernel/dumpstack_32.c
14323 +++ b/arch/x86/kernel/dumpstack_32.c
14324 @@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14325 #endif
14326
14327 for (;;) {
14328 - struct thread_info *context;
14329 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14330 + bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14331
14332 - context = (struct thread_info *)
14333 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14334 - bp = print_context_stack(context, stack, bp, ops,
14335 - data, NULL, &graph);
14336 -
14337 - stack = (unsigned long *)context->previous_esp;
14338 - if (!stack)
14339 + if (stack_start == task_stack_page(task))
14340 break;
14341 + stack = *(unsigned long **)stack_start;
14342 if (ops->stack(data, "IRQ") < 0)
14343 break;
14344 touch_nmi_watchdog();
14345 @@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs)
14346 * When in-kernel, we also print out the stack and code at the
14347 * time of the fault..
14348 */
14349 - if (!user_mode_vm(regs)) {
14350 + if (!user_mode(regs)) {
14351 unsigned int code_prologue = code_bytes * 43 / 64;
14352 unsigned int code_len = code_bytes;
14353 unsigned char c;
14354 u8 *ip;
14355 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14356
14357 printk(KERN_EMERG "Stack:\n");
14358 show_stack_log_lvl(NULL, regs, &regs->sp,
14359 @@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs)
14360
14361 printk(KERN_EMERG "Code: ");
14362
14363 - ip = (u8 *)regs->ip - code_prologue;
14364 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14365 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14366 /* try starting at IP */
14367 - ip = (u8 *)regs->ip;
14368 + ip = (u8 *)regs->ip + cs_base;
14369 code_len = code_len - code_prologue + 1;
14370 }
14371 for (i = 0; i < code_len; i++, ip++) {
14372 @@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs)
14373 printk(" Bad EIP value.");
14374 break;
14375 }
14376 - if (ip == (u8 *)regs->ip)
14377 + if (ip == (u8 *)regs->ip + cs_base)
14378 printk("<%02x> ", c);
14379 else
14380 printk("%02x ", c);
14381 @@ -145,10 +142,23 @@ void show_registers(struct pt_regs *regs)
14382 printk("\n");
14383 }
14384
14385 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14386 +void pax_check_alloca(unsigned long size)
14387 +{
14388 + unsigned long sp = (unsigned long)&sp, stack_left;
14389 +
14390 + /* all kernel stacks are of the same size */
14391 + stack_left = sp & (THREAD_SIZE - 1);
14392 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14393 +}
14394 +EXPORT_SYMBOL(pax_check_alloca);
14395 +#endif
14396 +
14397 int is_valid_bugaddr(unsigned long ip)
14398 {
14399 unsigned short ud2;
14400
14401 + ip = ktla_ktva(ip);
14402 if (ip < PAGE_OFFSET)
14403 return 0;
14404 if (probe_kernel_address((unsigned short *)ip, ud2))
14405 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14406 index a071e6b..36cd585 100644
14407 --- a/arch/x86/kernel/dumpstack_64.c
14408 +++ b/arch/x86/kernel/dumpstack_64.c
14409 @@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14410 unsigned long *irq_stack_end =
14411 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14412 unsigned used = 0;
14413 - struct thread_info *tinfo;
14414 int graph = 0;
14415 + void *stack_start;
14416
14417 if (!task)
14418 task = current;
14419 @@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14420 * current stack address. If the stacks consist of nested
14421 * exceptions
14422 */
14423 - tinfo = task_thread_info(task);
14424 for (;;) {
14425 char *id;
14426 unsigned long *estack_end;
14427 +
14428 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14429 &used, &id);
14430
14431 @@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14432 if (ops->stack(data, id) < 0)
14433 break;
14434
14435 - bp = print_context_stack(tinfo, stack, bp, ops,
14436 + bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14437 data, estack_end, &graph);
14438 ops->stack(data, "<EOE>");
14439 /*
14440 @@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14441 if (stack >= irq_stack && stack < irq_stack_end) {
14442 if (ops->stack(data, "IRQ") < 0)
14443 break;
14444 - bp = print_context_stack(tinfo, stack, bp,
14445 + bp = print_context_stack(task, irq_stack, stack, bp,
14446 ops, data, irq_stack_end, &graph);
14447 /*
14448 * We link to the next stack (which would be
14449 @@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14450 /*
14451 * This handles the process stack:
14452 */
14453 - bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14454 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14455 + bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14456 put_cpu();
14457 }
14458 EXPORT_SYMBOL(dump_trace);
14459 @@ -304,3 +305,50 @@ int is_valid_bugaddr(unsigned long ip)
14460 return ud2 == 0x0b0f;
14461 }
14462
14463 +
14464 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14465 +void pax_check_alloca(unsigned long size)
14466 +{
14467 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14468 + unsigned cpu, used;
14469 + char *id;
14470 +
14471 + /* check the process stack first */
14472 + stack_start = (unsigned long)task_stack_page(current);
14473 + stack_end = stack_start + THREAD_SIZE;
14474 + if (likely(stack_start <= sp && sp < stack_end)) {
14475 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14476 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14477 + return;
14478 + }
14479 +
14480 + cpu = get_cpu();
14481 +
14482 + /* check the irq stacks */
14483 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14484 + stack_start = stack_end - IRQ_STACK_SIZE;
14485 + if (stack_start <= sp && sp < stack_end) {
14486 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14487 + put_cpu();
14488 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14489 + return;
14490 + }
14491 +
14492 + /* check the exception stacks */
14493 + used = 0;
14494 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14495 + stack_start = stack_end - EXCEPTION_STKSZ;
14496 + if (stack_end && stack_start <= sp && sp < stack_end) {
14497 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14498 + put_cpu();
14499 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14500 + return;
14501 + }
14502 +
14503 + put_cpu();
14504 +
14505 + /* unknown stack */
14506 + BUG();
14507 +}
14508 +EXPORT_SYMBOL(pax_check_alloca);
14509 +#endif
14510 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
14511 index a89739a..95e0c48 100644
14512 --- a/arch/x86/kernel/e820.c
14513 +++ b/arch/x86/kernel/e820.c
14514 @@ -733,7 +733,7 @@ struct early_res {
14515 };
14516 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
14517 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
14518 - {}
14519 + { 0, 0, {0}, 0 }
14520 };
14521
14522 static int __init find_overlapped_early(u64 start, u64 end)
14523 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14524 index b9c830c..1e41a96 100644
14525 --- a/arch/x86/kernel/early_printk.c
14526 +++ b/arch/x86/kernel/early_printk.c
14527 @@ -7,6 +7,7 @@
14528 #include <linux/pci_regs.h>
14529 #include <linux/pci_ids.h>
14530 #include <linux/errno.h>
14531 +#include <linux/sched.h>
14532 #include <asm/io.h>
14533 #include <asm/processor.h>
14534 #include <asm/fcntl.h>
14535 @@ -170,6 +171,8 @@ asmlinkage void early_printk(const char *fmt, ...)
14536 int n;
14537 va_list ap;
14538
14539 + pax_track_stack();
14540 +
14541 va_start(ap, fmt);
14542 n = vscnprintf(buf, sizeof(buf), fmt, ap);
14543 early_console->write(early_console, buf, n);
14544 diff --git a/arch/x86/kernel/efi_32.c b/arch/x86/kernel/efi_32.c
14545 index 5cab48e..b025f9b 100644
14546 --- a/arch/x86/kernel/efi_32.c
14547 +++ b/arch/x86/kernel/efi_32.c
14548 @@ -38,70 +38,56 @@
14549 */
14550
14551 static unsigned long efi_rt_eflags;
14552 -static pgd_t efi_bak_pg_dir_pointer[2];
14553 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
14554
14555 -void efi_call_phys_prelog(void)
14556 +void __init efi_call_phys_prelog(void)
14557 {
14558 - unsigned long cr4;
14559 - unsigned long temp;
14560 struct desc_ptr gdt_descr;
14561
14562 +#ifdef CONFIG_PAX_KERNEXEC
14563 + struct desc_struct d;
14564 +#endif
14565 +
14566 local_irq_save(efi_rt_eflags);
14567
14568 - /*
14569 - * If I don't have PAE, I should just duplicate two entries in page
14570 - * directory. If I have PAE, I just need to duplicate one entry in
14571 - * page directory.
14572 - */
14573 - cr4 = read_cr4_safe();
14574 -
14575 - if (cr4 & X86_CR4_PAE) {
14576 - efi_bak_pg_dir_pointer[0].pgd =
14577 - swapper_pg_dir[pgd_index(0)].pgd;
14578 - swapper_pg_dir[0].pgd =
14579 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
14580 - } else {
14581 - efi_bak_pg_dir_pointer[0].pgd =
14582 - swapper_pg_dir[pgd_index(0)].pgd;
14583 - efi_bak_pg_dir_pointer[1].pgd =
14584 - swapper_pg_dir[pgd_index(0x400000)].pgd;
14585 - swapper_pg_dir[pgd_index(0)].pgd =
14586 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
14587 - temp = PAGE_OFFSET + 0x400000;
14588 - swapper_pg_dir[pgd_index(0x400000)].pgd =
14589 - swapper_pg_dir[pgd_index(temp)].pgd;
14590 - }
14591 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
14592 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
14593 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
14594
14595 /*
14596 * After the lock is released, the original page table is restored.
14597 */
14598 __flush_tlb_all();
14599
14600 +#ifdef CONFIG_PAX_KERNEXEC
14601 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
14602 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
14603 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
14604 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
14605 +#endif
14606 +
14607 gdt_descr.address = __pa(get_cpu_gdt_table(0));
14608 gdt_descr.size = GDT_SIZE - 1;
14609 load_gdt(&gdt_descr);
14610 }
14611
14612 -void efi_call_phys_epilog(void)
14613 +void __init efi_call_phys_epilog(void)
14614 {
14615 - unsigned long cr4;
14616 struct desc_ptr gdt_descr;
14617
14618 +#ifdef CONFIG_PAX_KERNEXEC
14619 + struct desc_struct d;
14620 +
14621 + memset(&d, 0, sizeof d);
14622 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
14623 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
14624 +#endif
14625 +
14626 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
14627 gdt_descr.size = GDT_SIZE - 1;
14628 load_gdt(&gdt_descr);
14629
14630 - cr4 = read_cr4_safe();
14631 -
14632 - if (cr4 & X86_CR4_PAE) {
14633 - swapper_pg_dir[pgd_index(0)].pgd =
14634 - efi_bak_pg_dir_pointer[0].pgd;
14635 - } else {
14636 - swapper_pg_dir[pgd_index(0)].pgd =
14637 - efi_bak_pg_dir_pointer[0].pgd;
14638 - swapper_pg_dir[pgd_index(0x400000)].pgd =
14639 - efi_bak_pg_dir_pointer[1].pgd;
14640 - }
14641 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
14642
14643 /*
14644 * After the lock is released, the original page table is restored.
14645 diff --git a/arch/x86/kernel/efi_stub_32.S b/arch/x86/kernel/efi_stub_32.S
14646 index fbe66e6..c5c0dd2 100644
14647 --- a/arch/x86/kernel/efi_stub_32.S
14648 +++ b/arch/x86/kernel/efi_stub_32.S
14649 @@ -6,7 +6,9 @@
14650 */
14651
14652 #include <linux/linkage.h>
14653 +#include <linux/init.h>
14654 #include <asm/page_types.h>
14655 +#include <asm/segment.h>
14656
14657 /*
14658 * efi_call_phys(void *, ...) is a function with variable parameters.
14659 @@ -20,7 +22,7 @@
14660 * service functions will comply with gcc calling convention, too.
14661 */
14662
14663 -.text
14664 +__INIT
14665 ENTRY(efi_call_phys)
14666 /*
14667 * 0. The function can only be called in Linux kernel. So CS has been
14668 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
14669 * The mapping of lower virtual memory has been created in prelog and
14670 * epilog.
14671 */
14672 - movl $1f, %edx
14673 - subl $__PAGE_OFFSET, %edx
14674 - jmp *%edx
14675 + movl $(__KERNEXEC_EFI_DS), %edx
14676 + mov %edx, %ds
14677 + mov %edx, %es
14678 + mov %edx, %ss
14679 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
14680 1:
14681
14682 /*
14683 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
14684 * parameter 2, ..., param n. To make things easy, we save the return
14685 * address of efi_call_phys in a global variable.
14686 */
14687 - popl %edx
14688 - movl %edx, saved_return_addr
14689 - /* get the function pointer into ECX*/
14690 - popl %ecx
14691 - movl %ecx, efi_rt_function_ptr
14692 - movl $2f, %edx
14693 - subl $__PAGE_OFFSET, %edx
14694 - pushl %edx
14695 + popl (saved_return_addr)
14696 + popl (efi_rt_function_ptr)
14697
14698 /*
14699 * 3. Clear PG bit in %CR0.
14700 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
14701 /*
14702 * 5. Call the physical function.
14703 */
14704 - jmp *%ecx
14705 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
14706
14707 -2:
14708 /*
14709 * 6. After EFI runtime service returns, control will return to
14710 * following instruction. We'd better readjust stack pointer first.
14711 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
14712 movl %cr0, %edx
14713 orl $0x80000000, %edx
14714 movl %edx, %cr0
14715 - jmp 1f
14716 -1:
14717 +
14718 /*
14719 * 8. Now restore the virtual mode from flat mode by
14720 * adding EIP with PAGE_OFFSET.
14721 */
14722 - movl $1f, %edx
14723 - jmp *%edx
14724 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
14725 1:
14726 + movl $(__KERNEL_DS), %edx
14727 + mov %edx, %ds
14728 + mov %edx, %es
14729 + mov %edx, %ss
14730
14731 /*
14732 * 9. Balance the stack. And because EAX contain the return value,
14733 * we'd better not clobber it.
14734 */
14735 - leal efi_rt_function_ptr, %edx
14736 - movl (%edx), %ecx
14737 - pushl %ecx
14738 + pushl (efi_rt_function_ptr)
14739
14740 /*
14741 - * 10. Push the saved return address onto the stack and return.
14742 + * 10. Return to the saved return address.
14743 */
14744 - leal saved_return_addr, %edx
14745 - movl (%edx), %ecx
14746 - pushl %ecx
14747 - ret
14748 + jmpl *(saved_return_addr)
14749 ENDPROC(efi_call_phys)
14750 .previous
14751
14752 -.data
14753 +__INITDATA
14754 saved_return_addr:
14755 .long 0
14756 efi_rt_function_ptr:
14757 diff --git a/arch/x86/kernel/efi_stub_64.S b/arch/x86/kernel/efi_stub_64.S
14758 index 4c07cca..2c8427d 100644
14759 --- a/arch/x86/kernel/efi_stub_64.S
14760 +++ b/arch/x86/kernel/efi_stub_64.S
14761 @@ -7,6 +7,7 @@
14762 */
14763
14764 #include <linux/linkage.h>
14765 +#include <asm/alternative-asm.h>
14766
14767 #define SAVE_XMM \
14768 mov %rsp, %rax; \
14769 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
14770 call *%rdi
14771 addq $32, %rsp
14772 RESTORE_XMM
14773 + pax_force_retaddr 0, 1
14774 ret
14775 ENDPROC(efi_call0)
14776
14777 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
14778 call *%rdi
14779 addq $32, %rsp
14780 RESTORE_XMM
14781 + pax_force_retaddr 0, 1
14782 ret
14783 ENDPROC(efi_call1)
14784
14785 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
14786 call *%rdi
14787 addq $32, %rsp
14788 RESTORE_XMM
14789 + pax_force_retaddr 0, 1
14790 ret
14791 ENDPROC(efi_call2)
14792
14793 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
14794 call *%rdi
14795 addq $32, %rsp
14796 RESTORE_XMM
14797 + pax_force_retaddr 0, 1
14798 ret
14799 ENDPROC(efi_call3)
14800
14801 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
14802 call *%rdi
14803 addq $32, %rsp
14804 RESTORE_XMM
14805 + pax_force_retaddr 0, 1
14806 ret
14807 ENDPROC(efi_call4)
14808
14809 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
14810 call *%rdi
14811 addq $48, %rsp
14812 RESTORE_XMM
14813 + pax_force_retaddr 0, 1
14814 ret
14815 ENDPROC(efi_call5)
14816
14817 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
14818 call *%rdi
14819 addq $48, %rsp
14820 RESTORE_XMM
14821 + pax_force_retaddr 0, 1
14822 ret
14823 ENDPROC(efi_call6)
14824 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14825 index c097e7d..c689cf4 100644
14826 --- a/arch/x86/kernel/entry_32.S
14827 +++ b/arch/x86/kernel/entry_32.S
14828 @@ -185,13 +185,146 @@
14829 /*CFI_REL_OFFSET gs, PT_GS*/
14830 .endm
14831 .macro SET_KERNEL_GS reg
14832 +
14833 +#ifdef CONFIG_CC_STACKPROTECTOR
14834 movl $(__KERNEL_STACK_CANARY), \reg
14835 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14836 + movl $(__USER_DS), \reg
14837 +#else
14838 + xorl \reg, \reg
14839 +#endif
14840 +
14841 movl \reg, %gs
14842 .endm
14843
14844 #endif /* CONFIG_X86_32_LAZY_GS */
14845
14846 -.macro SAVE_ALL
14847 +.macro pax_enter_kernel
14848 +#ifdef CONFIG_PAX_KERNEXEC
14849 + call pax_enter_kernel
14850 +#endif
14851 +.endm
14852 +
14853 +.macro pax_exit_kernel
14854 +#ifdef CONFIG_PAX_KERNEXEC
14855 + call pax_exit_kernel
14856 +#endif
14857 +.endm
14858 +
14859 +#ifdef CONFIG_PAX_KERNEXEC
14860 +ENTRY(pax_enter_kernel)
14861 +#ifdef CONFIG_PARAVIRT
14862 + pushl %eax
14863 + pushl %ecx
14864 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14865 + mov %eax, %esi
14866 +#else
14867 + mov %cr0, %esi
14868 +#endif
14869 + bts $16, %esi
14870 + jnc 1f
14871 + mov %cs, %esi
14872 + cmp $__KERNEL_CS, %esi
14873 + jz 3f
14874 + ljmp $__KERNEL_CS, $3f
14875 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14876 +2:
14877 +#ifdef CONFIG_PARAVIRT
14878 + mov %esi, %eax
14879 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14880 +#else
14881 + mov %esi, %cr0
14882 +#endif
14883 +3:
14884 +#ifdef CONFIG_PARAVIRT
14885 + popl %ecx
14886 + popl %eax
14887 +#endif
14888 + ret
14889 +ENDPROC(pax_enter_kernel)
14890 +
14891 +ENTRY(pax_exit_kernel)
14892 +#ifdef CONFIG_PARAVIRT
14893 + pushl %eax
14894 + pushl %ecx
14895 +#endif
14896 + mov %cs, %esi
14897 + cmp $__KERNEXEC_KERNEL_CS, %esi
14898 + jnz 2f
14899 +#ifdef CONFIG_PARAVIRT
14900 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14901 + mov %eax, %esi
14902 +#else
14903 + mov %cr0, %esi
14904 +#endif
14905 + btr $16, %esi
14906 + ljmp $__KERNEL_CS, $1f
14907 +1:
14908 +#ifdef CONFIG_PARAVIRT
14909 + mov %esi, %eax
14910 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14911 +#else
14912 + mov %esi, %cr0
14913 +#endif
14914 +2:
14915 +#ifdef CONFIG_PARAVIRT
14916 + popl %ecx
14917 + popl %eax
14918 +#endif
14919 + ret
14920 +ENDPROC(pax_exit_kernel)
14921 +#endif
14922 +
14923 +.macro pax_erase_kstack
14924 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14925 + call pax_erase_kstack
14926 +#endif
14927 +.endm
14928 +
14929 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14930 +/*
14931 + * ebp: thread_info
14932 + * ecx, edx: can be clobbered
14933 + */
14934 +ENTRY(pax_erase_kstack)
14935 + pushl %edi
14936 + pushl %eax
14937 +
14938 + mov TI_lowest_stack(%ebp), %edi
14939 + mov $-0xBEEF, %eax
14940 + std
14941 +
14942 +1: mov %edi, %ecx
14943 + and $THREAD_SIZE_asm - 1, %ecx
14944 + shr $2, %ecx
14945 + repne scasl
14946 + jecxz 2f
14947 +
14948 + cmp $2*16, %ecx
14949 + jc 2f
14950 +
14951 + mov $2*16, %ecx
14952 + repe scasl
14953 + jecxz 2f
14954 + jne 1b
14955 +
14956 +2: cld
14957 + mov %esp, %ecx
14958 + sub %edi, %ecx
14959 + shr $2, %ecx
14960 + rep stosl
14961 +
14962 + mov TI_task_thread_sp0(%ebp), %edi
14963 + sub $128, %edi
14964 + mov %edi, TI_lowest_stack(%ebp)
14965 +
14966 + popl %eax
14967 + popl %edi
14968 + ret
14969 +ENDPROC(pax_erase_kstack)
14970 +#endif
14971 +
14972 +.macro __SAVE_ALL _DS
14973 cld
14974 PUSH_GS
14975 pushl %fs
14976 @@ -224,7 +357,7 @@
14977 pushl %ebx
14978 CFI_ADJUST_CFA_OFFSET 4
14979 CFI_REL_OFFSET ebx, 0
14980 - movl $(__USER_DS), %edx
14981 + movl $\_DS, %edx
14982 movl %edx, %ds
14983 movl %edx, %es
14984 movl $(__KERNEL_PERCPU), %edx
14985 @@ -232,6 +365,15 @@
14986 SET_KERNEL_GS %edx
14987 .endm
14988
14989 +.macro SAVE_ALL
14990 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14991 + __SAVE_ALL __KERNEL_DS
14992 + pax_enter_kernel
14993 +#else
14994 + __SAVE_ALL __USER_DS
14995 +#endif
14996 +.endm
14997 +
14998 .macro RESTORE_INT_REGS
14999 popl %ebx
15000 CFI_ADJUST_CFA_OFFSET -4
15001 @@ -331,7 +473,7 @@ ENTRY(ret_from_fork)
15002 CFI_ADJUST_CFA_OFFSET -4
15003 jmp syscall_exit
15004 CFI_ENDPROC
15005 -END(ret_from_fork)
15006 +ENDPROC(ret_from_fork)
15007
15008 /*
15009 * Return to user mode is not as complex as all this looks,
15010 @@ -352,7 +494,15 @@ check_userspace:
15011 movb PT_CS(%esp), %al
15012 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
15013 cmpl $USER_RPL, %eax
15014 +
15015 +#ifdef CONFIG_PAX_KERNEXEC
15016 + jae resume_userspace
15017 +
15018 + PAX_EXIT_KERNEL
15019 + jmp resume_kernel
15020 +#else
15021 jb resume_kernel # not returning to v8086 or userspace
15022 +#endif
15023
15024 ENTRY(resume_userspace)
15025 LOCKDEP_SYS_EXIT
15026 @@ -364,8 +514,8 @@ ENTRY(resume_userspace)
15027 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15028 # int/exception return?
15029 jne work_pending
15030 - jmp restore_all
15031 -END(ret_from_exception)
15032 + jmp restore_all_pax
15033 +ENDPROC(ret_from_exception)
15034
15035 #ifdef CONFIG_PREEMPT
15036 ENTRY(resume_kernel)
15037 @@ -380,7 +530,7 @@ need_resched:
15038 jz restore_all
15039 call preempt_schedule_irq
15040 jmp need_resched
15041 -END(resume_kernel)
15042 +ENDPROC(resume_kernel)
15043 #endif
15044 CFI_ENDPROC
15045
15046 @@ -414,25 +564,36 @@ sysenter_past_esp:
15047 /*CFI_REL_OFFSET cs, 0*/
15048 /*
15049 * Push current_thread_info()->sysenter_return to the stack.
15050 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15051 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15052 */
15053 - pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
15054 + pushl $0
15055 CFI_ADJUST_CFA_OFFSET 4
15056 CFI_REL_OFFSET eip, 0
15057
15058 pushl %eax
15059 CFI_ADJUST_CFA_OFFSET 4
15060 SAVE_ALL
15061 + GET_THREAD_INFO(%ebp)
15062 + movl TI_sysenter_return(%ebp),%ebp
15063 + movl %ebp,PT_EIP(%esp)
15064 ENABLE_INTERRUPTS(CLBR_NONE)
15065
15066 /*
15067 * Load the potential sixth argument from user stack.
15068 * Careful about security.
15069 */
15070 + movl PT_OLDESP(%esp),%ebp
15071 +
15072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15073 + mov PT_OLDSS(%esp),%ds
15074 +1: movl %ds:(%ebp),%ebp
15075 + push %ss
15076 + pop %ds
15077 +#else
15078 cmpl $__PAGE_OFFSET-3,%ebp
15079 jae syscall_fault
15080 1: movl (%ebp),%ebp
15081 +#endif
15082 +
15083 movl %ebp,PT_EBP(%esp)
15084 .section __ex_table,"a"
15085 .align 4
15086 @@ -455,12 +616,24 @@ sysenter_do_call:
15087 testl $_TIF_ALLWORK_MASK, %ecx
15088 jne sysexit_audit
15089 sysenter_exit:
15090 +
15091 +#ifdef CONFIG_PAX_RANDKSTACK
15092 + pushl_cfi %eax
15093 + movl %esp, %eax
15094 + call pax_randomize_kstack
15095 + popl_cfi %eax
15096 +#endif
15097 +
15098 + pax_erase_kstack
15099 +
15100 /* if something modifies registers it must also disable sysexit */
15101 movl PT_EIP(%esp), %edx
15102 movl PT_OLDESP(%esp), %ecx
15103 xorl %ebp,%ebp
15104 TRACE_IRQS_ON
15105 1: mov PT_FS(%esp), %fs
15106 +2: mov PT_DS(%esp), %ds
15107 +3: mov PT_ES(%esp), %es
15108 PTGS_TO_GS
15109 ENABLE_INTERRUPTS_SYSEXIT
15110
15111 @@ -477,6 +650,9 @@ sysenter_audit:
15112 movl %eax,%edx /* 2nd arg: syscall number */
15113 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15114 call audit_syscall_entry
15115 +
15116 + pax_erase_kstack
15117 +
15118 pushl %ebx
15119 CFI_ADJUST_CFA_OFFSET 4
15120 movl PT_EAX(%esp),%eax /* reload syscall number */
15121 @@ -504,11 +680,17 @@ sysexit_audit:
15122
15123 CFI_ENDPROC
15124 .pushsection .fixup,"ax"
15125 -2: movl $0,PT_FS(%esp)
15126 +4: movl $0,PT_FS(%esp)
15127 + jmp 1b
15128 +5: movl $0,PT_DS(%esp)
15129 + jmp 1b
15130 +6: movl $0,PT_ES(%esp)
15131 jmp 1b
15132 .section __ex_table,"a"
15133 .align 4
15134 - .long 1b,2b
15135 + .long 1b,4b
15136 + .long 2b,5b
15137 + .long 3b,6b
15138 .popsection
15139 PTGS_TO_GS_EX
15140 ENDPROC(ia32_sysenter_target)
15141 @@ -538,6 +720,15 @@ syscall_exit:
15142 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15143 jne syscall_exit_work
15144
15145 +restore_all_pax:
15146 +
15147 +#ifdef CONFIG_PAX_RANDKSTACK
15148 + movl %esp, %eax
15149 + call pax_randomize_kstack
15150 +#endif
15151 +
15152 + pax_erase_kstack
15153 +
15154 restore_all:
15155 TRACE_IRQS_IRET
15156 restore_all_notrace:
15157 @@ -602,10 +793,29 @@ ldt_ss:
15158 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15159 mov %dx, %ax /* eax: new kernel esp */
15160 sub %eax, %edx /* offset (low word is 0) */
15161 - PER_CPU(gdt_page, %ebx)
15162 +#ifdef CONFIG_SMP
15163 + movl PER_CPU_VAR(cpu_number), %ebx
15164 + shll $PAGE_SHIFT_asm, %ebx
15165 + addl $cpu_gdt_table, %ebx
15166 +#else
15167 + movl $cpu_gdt_table, %ebx
15168 +#endif
15169 shr $16, %edx
15170 +
15171 +#ifdef CONFIG_PAX_KERNEXEC
15172 + mov %cr0, %esi
15173 + btr $16, %esi
15174 + mov %esi, %cr0
15175 +#endif
15176 +
15177 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
15178 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
15179 +
15180 +#ifdef CONFIG_PAX_KERNEXEC
15181 + bts $16, %esi
15182 + mov %esi, %cr0
15183 +#endif
15184 +
15185 pushl $__ESPFIX_SS
15186 CFI_ADJUST_CFA_OFFSET 4
15187 push %eax /* new kernel esp */
15188 @@ -636,36 +846,30 @@ work_resched:
15189 movl TI_flags(%ebp), %ecx
15190 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15191 # than syscall tracing?
15192 - jz restore_all
15193 + jz restore_all_pax
15194 testb $_TIF_NEED_RESCHED, %cl
15195 jnz work_resched
15196
15197 work_notifysig: # deal with pending signals and
15198 # notify-resume requests
15199 + movl %esp, %eax
15200 #ifdef CONFIG_VM86
15201 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15202 - movl %esp, %eax
15203 - jne work_notifysig_v86 # returning to kernel-space or
15204 + jz 1f # returning to kernel-space or
15205 # vm86-space
15206 - xorl %edx, %edx
15207 - call do_notify_resume
15208 - jmp resume_userspace_sig
15209
15210 - ALIGN
15211 -work_notifysig_v86:
15212 pushl %ecx # save ti_flags for do_notify_resume
15213 CFI_ADJUST_CFA_OFFSET 4
15214 call save_v86_state # %eax contains pt_regs pointer
15215 popl %ecx
15216 CFI_ADJUST_CFA_OFFSET -4
15217 movl %eax, %esp
15218 -#else
15219 - movl %esp, %eax
15220 +1:
15221 #endif
15222 xorl %edx, %edx
15223 call do_notify_resume
15224 jmp resume_userspace_sig
15225 -END(work_pending)
15226 +ENDPROC(work_pending)
15227
15228 # perform syscall exit tracing
15229 ALIGN
15230 @@ -673,11 +877,14 @@ syscall_trace_entry:
15231 movl $-ENOSYS,PT_EAX(%esp)
15232 movl %esp, %eax
15233 call syscall_trace_enter
15234 +
15235 + pax_erase_kstack
15236 +
15237 /* What it returned is what we'll actually use. */
15238 cmpl $(nr_syscalls), %eax
15239 jnae syscall_call
15240 jmp syscall_exit
15241 -END(syscall_trace_entry)
15242 +ENDPROC(syscall_trace_entry)
15243
15244 # perform syscall exit tracing
15245 ALIGN
15246 @@ -690,20 +897,24 @@ syscall_exit_work:
15247 movl %esp, %eax
15248 call syscall_trace_leave
15249 jmp resume_userspace
15250 -END(syscall_exit_work)
15251 +ENDPROC(syscall_exit_work)
15252 CFI_ENDPROC
15253
15254 RING0_INT_FRAME # can't unwind into user space anyway
15255 syscall_fault:
15256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15257 + push %ss
15258 + pop %ds
15259 +#endif
15260 GET_THREAD_INFO(%ebp)
15261 movl $-EFAULT,PT_EAX(%esp)
15262 jmp resume_userspace
15263 -END(syscall_fault)
15264 +ENDPROC(syscall_fault)
15265
15266 syscall_badsys:
15267 movl $-ENOSYS,PT_EAX(%esp)
15268 jmp resume_userspace
15269 -END(syscall_badsys)
15270 +ENDPROC(syscall_badsys)
15271 CFI_ENDPROC
15272
15273 /*
15274 @@ -726,6 +937,33 @@ PTREGSCALL(rt_sigreturn)
15275 PTREGSCALL(vm86)
15276 PTREGSCALL(vm86old)
15277
15278 + ALIGN;
15279 +ENTRY(kernel_execve)
15280 + push %ebp
15281 + sub $PT_OLDSS+4,%esp
15282 + push %edi
15283 + push %ecx
15284 + push %eax
15285 + lea 3*4(%esp),%edi
15286 + mov $PT_OLDSS/4+1,%ecx
15287 + xorl %eax,%eax
15288 + rep stosl
15289 + pop %eax
15290 + pop %ecx
15291 + pop %edi
15292 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15293 + mov %eax,PT_EBX(%esp)
15294 + mov %edx,PT_ECX(%esp)
15295 + mov %ecx,PT_EDX(%esp)
15296 + mov %esp,%eax
15297 + call sys_execve
15298 + GET_THREAD_INFO(%ebp)
15299 + test %eax,%eax
15300 + jz syscall_exit
15301 + add $PT_OLDSS+4,%esp
15302 + pop %ebp
15303 + ret
15304 +
15305 .macro FIXUP_ESPFIX_STACK
15306 /*
15307 * Switch back for ESPFIX stack to the normal zerobased stack
15308 @@ -735,7 +973,13 @@ PTREGSCALL(vm86old)
15309 * normal stack and adjusts ESP with the matching offset.
15310 */
15311 /* fixup the stack */
15312 - PER_CPU(gdt_page, %ebx)
15313 +#ifdef CONFIG_SMP
15314 + movl PER_CPU_VAR(cpu_number), %ebx
15315 + shll $PAGE_SHIFT_asm, %ebx
15316 + addl $cpu_gdt_table, %ebx
15317 +#else
15318 + movl $cpu_gdt_table, %ebx
15319 +#endif
15320 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
15321 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
15322 shl $16, %eax
15323 @@ -793,7 +1037,7 @@ vector=vector+1
15324 .endr
15325 2: jmp common_interrupt
15326 .endr
15327 -END(irq_entries_start)
15328 +ENDPROC(irq_entries_start)
15329
15330 .previous
15331 END(interrupt)
15332 @@ -840,7 +1084,7 @@ ENTRY(coprocessor_error)
15333 CFI_ADJUST_CFA_OFFSET 4
15334 jmp error_code
15335 CFI_ENDPROC
15336 -END(coprocessor_error)
15337 +ENDPROC(coprocessor_error)
15338
15339 ENTRY(simd_coprocessor_error)
15340 RING0_INT_FRAME
15341 @@ -850,7 +1094,7 @@ ENTRY(simd_coprocessor_error)
15342 CFI_ADJUST_CFA_OFFSET 4
15343 jmp error_code
15344 CFI_ENDPROC
15345 -END(simd_coprocessor_error)
15346 +ENDPROC(simd_coprocessor_error)
15347
15348 ENTRY(device_not_available)
15349 RING0_INT_FRAME
15350 @@ -860,7 +1104,7 @@ ENTRY(device_not_available)
15351 CFI_ADJUST_CFA_OFFSET 4
15352 jmp error_code
15353 CFI_ENDPROC
15354 -END(device_not_available)
15355 +ENDPROC(device_not_available)
15356
15357 #ifdef CONFIG_PARAVIRT
15358 ENTRY(native_iret)
15359 @@ -869,12 +1113,12 @@ ENTRY(native_iret)
15360 .align 4
15361 .long native_iret, iret_exc
15362 .previous
15363 -END(native_iret)
15364 +ENDPROC(native_iret)
15365
15366 ENTRY(native_irq_enable_sysexit)
15367 sti
15368 sysexit
15369 -END(native_irq_enable_sysexit)
15370 +ENDPROC(native_irq_enable_sysexit)
15371 #endif
15372
15373 ENTRY(overflow)
15374 @@ -885,7 +1129,7 @@ ENTRY(overflow)
15375 CFI_ADJUST_CFA_OFFSET 4
15376 jmp error_code
15377 CFI_ENDPROC
15378 -END(overflow)
15379 +ENDPROC(overflow)
15380
15381 ENTRY(bounds)
15382 RING0_INT_FRAME
15383 @@ -895,7 +1139,7 @@ ENTRY(bounds)
15384 CFI_ADJUST_CFA_OFFSET 4
15385 jmp error_code
15386 CFI_ENDPROC
15387 -END(bounds)
15388 +ENDPROC(bounds)
15389
15390 ENTRY(invalid_op)
15391 RING0_INT_FRAME
15392 @@ -905,7 +1149,7 @@ ENTRY(invalid_op)
15393 CFI_ADJUST_CFA_OFFSET 4
15394 jmp error_code
15395 CFI_ENDPROC
15396 -END(invalid_op)
15397 +ENDPROC(invalid_op)
15398
15399 ENTRY(coprocessor_segment_overrun)
15400 RING0_INT_FRAME
15401 @@ -915,7 +1159,7 @@ ENTRY(coprocessor_segment_overrun)
15402 CFI_ADJUST_CFA_OFFSET 4
15403 jmp error_code
15404 CFI_ENDPROC
15405 -END(coprocessor_segment_overrun)
15406 +ENDPROC(coprocessor_segment_overrun)
15407
15408 ENTRY(invalid_TSS)
15409 RING0_EC_FRAME
15410 @@ -923,7 +1167,7 @@ ENTRY(invalid_TSS)
15411 CFI_ADJUST_CFA_OFFSET 4
15412 jmp error_code
15413 CFI_ENDPROC
15414 -END(invalid_TSS)
15415 +ENDPROC(invalid_TSS)
15416
15417 ENTRY(segment_not_present)
15418 RING0_EC_FRAME
15419 @@ -931,7 +1175,7 @@ ENTRY(segment_not_present)
15420 CFI_ADJUST_CFA_OFFSET 4
15421 jmp error_code
15422 CFI_ENDPROC
15423 -END(segment_not_present)
15424 +ENDPROC(segment_not_present)
15425
15426 ENTRY(stack_segment)
15427 RING0_EC_FRAME
15428 @@ -939,7 +1183,7 @@ ENTRY(stack_segment)
15429 CFI_ADJUST_CFA_OFFSET 4
15430 jmp error_code
15431 CFI_ENDPROC
15432 -END(stack_segment)
15433 +ENDPROC(stack_segment)
15434
15435 ENTRY(alignment_check)
15436 RING0_EC_FRAME
15437 @@ -947,7 +1191,7 @@ ENTRY(alignment_check)
15438 CFI_ADJUST_CFA_OFFSET 4
15439 jmp error_code
15440 CFI_ENDPROC
15441 -END(alignment_check)
15442 +ENDPROC(alignment_check)
15443
15444 ENTRY(divide_error)
15445 RING0_INT_FRAME
15446 @@ -957,7 +1201,7 @@ ENTRY(divide_error)
15447 CFI_ADJUST_CFA_OFFSET 4
15448 jmp error_code
15449 CFI_ENDPROC
15450 -END(divide_error)
15451 +ENDPROC(divide_error)
15452
15453 #ifdef CONFIG_X86_MCE
15454 ENTRY(machine_check)
15455 @@ -968,7 +1212,7 @@ ENTRY(machine_check)
15456 CFI_ADJUST_CFA_OFFSET 4
15457 jmp error_code
15458 CFI_ENDPROC
15459 -END(machine_check)
15460 +ENDPROC(machine_check)
15461 #endif
15462
15463 ENTRY(spurious_interrupt_bug)
15464 @@ -979,7 +1223,7 @@ ENTRY(spurious_interrupt_bug)
15465 CFI_ADJUST_CFA_OFFSET 4
15466 jmp error_code
15467 CFI_ENDPROC
15468 -END(spurious_interrupt_bug)
15469 +ENDPROC(spurious_interrupt_bug)
15470
15471 ENTRY(kernel_thread_helper)
15472 pushl $0 # fake return address for unwinder
15473 @@ -1095,7 +1339,7 @@ ENDPROC(xen_failsafe_callback)
15474
15475 ENTRY(mcount)
15476 ret
15477 -END(mcount)
15478 +ENDPROC(mcount)
15479
15480 ENTRY(ftrace_caller)
15481 cmpl $0, function_trace_stop
15482 @@ -1124,7 +1368,7 @@ ftrace_graph_call:
15483 .globl ftrace_stub
15484 ftrace_stub:
15485 ret
15486 -END(ftrace_caller)
15487 +ENDPROC(ftrace_caller)
15488
15489 #else /* ! CONFIG_DYNAMIC_FTRACE */
15490
15491 @@ -1160,7 +1404,7 @@ trace:
15492 popl %ecx
15493 popl %eax
15494 jmp ftrace_stub
15495 -END(mcount)
15496 +ENDPROC(mcount)
15497 #endif /* CONFIG_DYNAMIC_FTRACE */
15498 #endif /* CONFIG_FUNCTION_TRACER */
15499
15500 @@ -1181,7 +1425,7 @@ ENTRY(ftrace_graph_caller)
15501 popl %ecx
15502 popl %eax
15503 ret
15504 -END(ftrace_graph_caller)
15505 +ENDPROC(ftrace_graph_caller)
15506
15507 .globl return_to_handler
15508 return_to_handler:
15509 @@ -1198,7 +1442,6 @@ return_to_handler:
15510 ret
15511 #endif
15512
15513 -.section .rodata,"a"
15514 #include "syscall_table_32.S"
15515
15516 syscall_table_size=(.-sys_call_table)
15517 @@ -1255,15 +1498,18 @@ error_code:
15518 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15519 REG_TO_PTGS %ecx
15520 SET_KERNEL_GS %ecx
15521 - movl $(__USER_DS), %ecx
15522 + movl $(__KERNEL_DS), %ecx
15523 movl %ecx, %ds
15524 movl %ecx, %es
15525 +
15526 + pax_enter_kernel
15527 +
15528 TRACE_IRQS_OFF
15529 movl %esp,%eax # pt_regs pointer
15530 call *%edi
15531 jmp ret_from_exception
15532 CFI_ENDPROC
15533 -END(page_fault)
15534 +ENDPROC(page_fault)
15535
15536 /*
15537 * Debug traps and NMI can happen at the one SYSENTER instruction
15538 @@ -1309,7 +1555,7 @@ debug_stack_correct:
15539 call do_debug
15540 jmp ret_from_exception
15541 CFI_ENDPROC
15542 -END(debug)
15543 +ENDPROC(debug)
15544
15545 /*
15546 * NMI is doubly nasty. It can happen _while_ we're handling
15547 @@ -1351,6 +1597,9 @@ nmi_stack_correct:
15548 xorl %edx,%edx # zero error code
15549 movl %esp,%eax # pt_regs pointer
15550 call do_nmi
15551 +
15552 + pax_exit_kernel
15553 +
15554 jmp restore_all_notrace
15555 CFI_ENDPROC
15556
15557 @@ -1391,12 +1640,15 @@ nmi_espfix_stack:
15558 FIXUP_ESPFIX_STACK # %eax == %esp
15559 xorl %edx,%edx # zero error code
15560 call do_nmi
15561 +
15562 + pax_exit_kernel
15563 +
15564 RESTORE_REGS
15565 lss 12+4(%esp), %esp # back to espfix stack
15566 CFI_ADJUST_CFA_OFFSET -24
15567 jmp irq_return
15568 CFI_ENDPROC
15569 -END(nmi)
15570 +ENDPROC(nmi)
15571
15572 ENTRY(int3)
15573 RING0_INT_FRAME
15574 @@ -1409,7 +1661,7 @@ ENTRY(int3)
15575 call do_int3
15576 jmp ret_from_exception
15577 CFI_ENDPROC
15578 -END(int3)
15579 +ENDPROC(int3)
15580
15581 ENTRY(general_protection)
15582 RING0_EC_FRAME
15583 @@ -1417,7 +1669,7 @@ ENTRY(general_protection)
15584 CFI_ADJUST_CFA_OFFSET 4
15585 jmp error_code
15586 CFI_ENDPROC
15587 -END(general_protection)
15588 +ENDPROC(general_protection)
15589
15590 /*
15591 * End of kprobes section
15592 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15593 index 34a56a9..a98c643 100644
15594 --- a/arch/x86/kernel/entry_64.S
15595 +++ b/arch/x86/kernel/entry_64.S
15596 @@ -53,6 +53,8 @@
15597 #include <asm/paravirt.h>
15598 #include <asm/ftrace.h>
15599 #include <asm/percpu.h>
15600 +#include <asm/pgtable.h>
15601 +#include <asm/alternative-asm.h>
15602
15603 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15604 #include <linux/elf-em.h>
15605 @@ -64,8 +66,9 @@
15606 #ifdef CONFIG_FUNCTION_TRACER
15607 #ifdef CONFIG_DYNAMIC_FTRACE
15608 ENTRY(mcount)
15609 + pax_force_retaddr
15610 retq
15611 -END(mcount)
15612 +ENDPROC(mcount)
15613
15614 ENTRY(ftrace_caller)
15615 cmpl $0, function_trace_stop
15616 @@ -88,8 +91,9 @@ GLOBAL(ftrace_graph_call)
15617 #endif
15618
15619 GLOBAL(ftrace_stub)
15620 + pax_force_retaddr
15621 retq
15622 -END(ftrace_caller)
15623 +ENDPROC(ftrace_caller)
15624
15625 #else /* ! CONFIG_DYNAMIC_FTRACE */
15626 ENTRY(mcount)
15627 @@ -108,6 +112,7 @@ ENTRY(mcount)
15628 #endif
15629
15630 GLOBAL(ftrace_stub)
15631 + pax_force_retaddr
15632 retq
15633
15634 trace:
15635 @@ -117,12 +122,13 @@ trace:
15636 movq 8(%rbp), %rsi
15637 subq $MCOUNT_INSN_SIZE, %rdi
15638
15639 + pax_force_fptr ftrace_trace_function
15640 call *ftrace_trace_function
15641
15642 MCOUNT_RESTORE_FRAME
15643
15644 jmp ftrace_stub
15645 -END(mcount)
15646 +ENDPROC(mcount)
15647 #endif /* CONFIG_DYNAMIC_FTRACE */
15648 #endif /* CONFIG_FUNCTION_TRACER */
15649
15650 @@ -142,8 +148,9 @@ ENTRY(ftrace_graph_caller)
15651
15652 MCOUNT_RESTORE_FRAME
15653
15654 + pax_force_retaddr
15655 retq
15656 -END(ftrace_graph_caller)
15657 +ENDPROC(ftrace_graph_caller)
15658
15659 GLOBAL(return_to_handler)
15660 subq $24, %rsp
15661 @@ -159,6 +166,7 @@ GLOBAL(return_to_handler)
15662 movq 8(%rsp), %rdx
15663 movq (%rsp), %rax
15664 addq $16, %rsp
15665 + pax_force_retaddr
15666 retq
15667 #endif
15668
15669 @@ -174,6 +182,282 @@ ENTRY(native_usergs_sysret64)
15670 ENDPROC(native_usergs_sysret64)
15671 #endif /* CONFIG_PARAVIRT */
15672
15673 + .macro ljmpq sel, off
15674 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15675 + .byte 0x48; ljmp *1234f(%rip)
15676 + .pushsection .rodata
15677 + .align 16
15678 + 1234: .quad \off; .word \sel
15679 + .popsection
15680 +#else
15681 + pushq $\sel
15682 + pushq $\off
15683 + lretq
15684 +#endif
15685 + .endm
15686 +
15687 + .macro pax_enter_kernel
15688 + pax_set_fptr_mask
15689 +#ifdef CONFIG_PAX_KERNEXEC
15690 + call pax_enter_kernel
15691 +#endif
15692 + .endm
15693 +
15694 + .macro pax_exit_kernel
15695 +#ifdef CONFIG_PAX_KERNEXEC
15696 + call pax_exit_kernel
15697 +#endif
15698 + .endm
15699 +
15700 +#ifdef CONFIG_PAX_KERNEXEC
15701 +ENTRY(pax_enter_kernel)
15702 + pushq %rdi
15703 +
15704 +#ifdef CONFIG_PARAVIRT
15705 + PV_SAVE_REGS(CLBR_RDI)
15706 +#endif
15707 +
15708 + GET_CR0_INTO_RDI
15709 + bts $16,%rdi
15710 + jnc 3f
15711 + mov %cs,%edi
15712 + cmp $__KERNEL_CS,%edi
15713 + jnz 2f
15714 +1:
15715 +
15716 +#ifdef CONFIG_PARAVIRT
15717 + PV_RESTORE_REGS(CLBR_RDI)
15718 +#endif
15719 +
15720 + popq %rdi
15721 + pax_force_retaddr
15722 + retq
15723 +
15724 +2: ljmpq __KERNEL_CS,1f
15725 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15726 +4: SET_RDI_INTO_CR0
15727 + jmp 1b
15728 +ENDPROC(pax_enter_kernel)
15729 +
15730 +ENTRY(pax_exit_kernel)
15731 + pushq %rdi
15732 +
15733 +#ifdef CONFIG_PARAVIRT
15734 + PV_SAVE_REGS(CLBR_RDI)
15735 +#endif
15736 +
15737 + mov %cs,%rdi
15738 + cmp $__KERNEXEC_KERNEL_CS,%edi
15739 + jz 2f
15740 +1:
15741 +
15742 +#ifdef CONFIG_PARAVIRT
15743 + PV_RESTORE_REGS(CLBR_RDI);
15744 +#endif
15745 +
15746 + popq %rdi
15747 + pax_force_retaddr
15748 + retq
15749 +
15750 +2: GET_CR0_INTO_RDI
15751 + btr $16,%rdi
15752 + ljmpq __KERNEL_CS,3f
15753 +3: SET_RDI_INTO_CR0
15754 + jmp 1b
15755 +#ifdef CONFIG_PARAVIRT
15756 + PV_RESTORE_REGS(CLBR_RDI);
15757 +#endif
15758 +
15759 + popq %rdi
15760 + pax_force_retaddr
15761 + retq
15762 +ENDPROC(pax_exit_kernel)
15763 +#endif
15764 +
15765 + .macro pax_enter_kernel_user
15766 + pax_set_fptr_mask
15767 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15768 + call pax_enter_kernel_user
15769 +#endif
15770 + .endm
15771 +
15772 + .macro pax_exit_kernel_user
15773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15774 + call pax_exit_kernel_user
15775 +#endif
15776 +#ifdef CONFIG_PAX_RANDKSTACK
15777 + push %rax
15778 + call pax_randomize_kstack
15779 + pop %rax
15780 +#endif
15781 + .endm
15782 +
15783 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15784 +ENTRY(pax_enter_kernel_user)
15785 + pushq %rdi
15786 + pushq %rbx
15787 +
15788 +#ifdef CONFIG_PARAVIRT
15789 + PV_SAVE_REGS(CLBR_RDI)
15790 +#endif
15791 +
15792 + GET_CR3_INTO_RDI
15793 + mov %rdi,%rbx
15794 + add $__START_KERNEL_map,%rbx
15795 + sub phys_base(%rip),%rbx
15796 +
15797 +#ifdef CONFIG_PARAVIRT
15798 + pushq %rdi
15799 + cmpl $0, pv_info+PARAVIRT_enabled
15800 + jz 1f
15801 + i = 0
15802 + .rept USER_PGD_PTRS
15803 + mov i*8(%rbx),%rsi
15804 + mov $0,%sil
15805 + lea i*8(%rbx),%rdi
15806 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15807 + i = i + 1
15808 + .endr
15809 + jmp 2f
15810 +1:
15811 +#endif
15812 +
15813 + i = 0
15814 + .rept USER_PGD_PTRS
15815 + movb $0,i*8(%rbx)
15816 + i = i + 1
15817 + .endr
15818 +
15819 +#ifdef CONFIG_PARAVIRT
15820 +2: popq %rdi
15821 +#endif
15822 + SET_RDI_INTO_CR3
15823 +
15824 +#ifdef CONFIG_PAX_KERNEXEC
15825 + GET_CR0_INTO_RDI
15826 + bts $16,%rdi
15827 + SET_RDI_INTO_CR0
15828 +#endif
15829 +
15830 +#ifdef CONFIG_PARAVIRT
15831 + PV_RESTORE_REGS(CLBR_RDI)
15832 +#endif
15833 +
15834 + popq %rbx
15835 + popq %rdi
15836 + pax_force_retaddr
15837 + retq
15838 +ENDPROC(pax_enter_kernel_user)
15839 +
15840 +ENTRY(pax_exit_kernel_user)
15841 + push %rdi
15842 +
15843 +#ifdef CONFIG_PARAVIRT
15844 + pushq %rbx
15845 + PV_SAVE_REGS(CLBR_RDI)
15846 +#endif
15847 +
15848 +#ifdef CONFIG_PAX_KERNEXEC
15849 + GET_CR0_INTO_RDI
15850 + btr $16,%rdi
15851 + SET_RDI_INTO_CR0
15852 +#endif
15853 +
15854 + GET_CR3_INTO_RDI
15855 + add $__START_KERNEL_map,%rdi
15856 + sub phys_base(%rip),%rdi
15857 +
15858 +#ifdef CONFIG_PARAVIRT
15859 + cmpl $0, pv_info+PARAVIRT_enabled
15860 + jz 1f
15861 + mov %rdi,%rbx
15862 + i = 0
15863 + .rept USER_PGD_PTRS
15864 + mov i*8(%rbx),%rsi
15865 + mov $0x67,%sil
15866 + lea i*8(%rbx),%rdi
15867 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15868 + i = i + 1
15869 + .endr
15870 + jmp 2f
15871 +1:
15872 +#endif
15873 +
15874 + i = 0
15875 + .rept USER_PGD_PTRS
15876 + movb $0x67,i*8(%rdi)
15877 + i = i + 1
15878 + .endr
15879 +
15880 +#ifdef CONFIG_PARAVIRT
15881 +2: PV_RESTORE_REGS(CLBR_RDI)
15882 + popq %rbx
15883 +#endif
15884 +
15885 + popq %rdi
15886 + pax_force_retaddr
15887 + retq
15888 +ENDPROC(pax_exit_kernel_user)
15889 +#endif
15890 +
15891 +.macro pax_erase_kstack
15892 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15893 + call pax_erase_kstack
15894 +#endif
15895 +.endm
15896 +
15897 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15898 +/*
15899 + * r11: thread_info
15900 + * rcx, rdx: can be clobbered
15901 + */
15902 +ENTRY(pax_erase_kstack)
15903 + pushq %rdi
15904 + pushq %rax
15905 + pushq %r11
15906 +
15907 + GET_THREAD_INFO(%r11)
15908 + mov TI_lowest_stack(%r11), %rdi
15909 + mov $-0xBEEF, %rax
15910 + std
15911 +
15912 +1: mov %edi, %ecx
15913 + and $THREAD_SIZE_asm - 1, %ecx
15914 + shr $3, %ecx
15915 + repne scasq
15916 + jecxz 2f
15917 +
15918 + cmp $2*8, %ecx
15919 + jc 2f
15920 +
15921 + mov $2*8, %ecx
15922 + repe scasq
15923 + jecxz 2f
15924 + jne 1b
15925 +
15926 +2: cld
15927 + mov %esp, %ecx
15928 + sub %edi, %ecx
15929 +
15930 + cmp $THREAD_SIZE_asm, %rcx
15931 + jb 3f
15932 + ud2
15933 +3:
15934 +
15935 + shr $3, %ecx
15936 + rep stosq
15937 +
15938 + mov TI_task_thread_sp0(%r11), %rdi
15939 + sub $256, %rdi
15940 + mov %rdi, TI_lowest_stack(%r11)
15941 +
15942 + popq %r11
15943 + popq %rax
15944 + popq %rdi
15945 + pax_force_retaddr
15946 + ret
15947 +ENDPROC(pax_erase_kstack)
15948 +#endif
15949
15950 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15951 #ifdef CONFIG_TRACE_IRQFLAGS
15952 @@ -233,8 +517,8 @@ ENDPROC(native_usergs_sysret64)
15953 .endm
15954
15955 .macro UNFAKE_STACK_FRAME
15956 - addq $8*6, %rsp
15957 - CFI_ADJUST_CFA_OFFSET -(6*8)
15958 + addq $8*6 + ARG_SKIP, %rsp
15959 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15960 .endm
15961
15962 /*
15963 @@ -317,7 +601,7 @@ ENTRY(save_args)
15964 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
15965 movq_cfi rbp, 8 /* push %rbp */
15966 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
15967 - testl $3, CS(%rdi)
15968 + testb $3, CS(%rdi)
15969 je 1f
15970 SWAPGS
15971 /*
15972 @@ -337,9 +621,10 @@ ENTRY(save_args)
15973 * We entered an interrupt context - irqs are off:
15974 */
15975 2: TRACE_IRQS_OFF
15976 + pax_force_retaddr
15977 ret
15978 CFI_ENDPROC
15979 -END(save_args)
15980 +ENDPROC(save_args)
15981
15982 ENTRY(save_rest)
15983 PARTIAL_FRAME 1 REST_SKIP+8
15984 @@ -352,9 +637,10 @@ ENTRY(save_rest)
15985 movq_cfi r15, R15+16
15986 movq %r11, 8(%rsp) /* return address */
15987 FIXUP_TOP_OF_STACK %r11, 16
15988 + pax_force_retaddr
15989 ret
15990 CFI_ENDPROC
15991 -END(save_rest)
15992 +ENDPROC(save_rest)
15993
15994 /* save complete stack frame */
15995 .pushsection .kprobes.text, "ax"
15996 @@ -383,9 +669,10 @@ ENTRY(save_paranoid)
15997 js 1f /* negative -> in kernel */
15998 SWAPGS
15999 xorl %ebx,%ebx
16000 -1: ret
16001 +1: pax_force_retaddr_bts
16002 + ret
16003 CFI_ENDPROC
16004 -END(save_paranoid)
16005 +ENDPROC(save_paranoid)
16006 .popsection
16007
16008 /*
16009 @@ -409,7 +696,7 @@ ENTRY(ret_from_fork)
16010
16011 RESTORE_REST
16012
16013 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16014 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16015 je int_ret_from_sys_call
16016
16017 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16018 @@ -419,7 +706,7 @@ ENTRY(ret_from_fork)
16019 jmp ret_from_sys_call # go to the SYSRET fastpath
16020
16021 CFI_ENDPROC
16022 -END(ret_from_fork)
16023 +ENDPROC(ret_from_fork)
16024
16025 /*
16026 * System call entry. Upto 6 arguments in registers are supported.
16027 @@ -455,7 +742,7 @@ END(ret_from_fork)
16028 ENTRY(system_call)
16029 CFI_STARTPROC simple
16030 CFI_SIGNAL_FRAME
16031 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16032 + CFI_DEF_CFA rsp,0
16033 CFI_REGISTER rip,rcx
16034 /*CFI_REGISTER rflags,r11*/
16035 SWAPGS_UNSAFE_STACK
16036 @@ -468,12 +755,13 @@ ENTRY(system_call_after_swapgs)
16037
16038 movq %rsp,PER_CPU_VAR(old_rsp)
16039 movq PER_CPU_VAR(kernel_stack),%rsp
16040 + SAVE_ARGS 8*6,1
16041 + pax_enter_kernel_user
16042 /*
16043 * No need to follow this irqs off/on section - it's straight
16044 * and short:
16045 */
16046 ENABLE_INTERRUPTS(CLBR_NONE)
16047 - SAVE_ARGS 8,1
16048 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16049 movq %rcx,RIP-ARGOFFSET(%rsp)
16050 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16051 @@ -483,7 +771,7 @@ ENTRY(system_call_after_swapgs)
16052 system_call_fastpath:
16053 cmpq $__NR_syscall_max,%rax
16054 ja badsys
16055 - movq %r10,%rcx
16056 + movq R10-ARGOFFSET(%rsp),%rcx
16057 call *sys_call_table(,%rax,8) # XXX: rip relative
16058 movq %rax,RAX-ARGOFFSET(%rsp)
16059 /*
16060 @@ -502,6 +790,8 @@ sysret_check:
16061 andl %edi,%edx
16062 jnz sysret_careful
16063 CFI_REMEMBER_STATE
16064 + pax_exit_kernel_user
16065 + pax_erase_kstack
16066 /*
16067 * sysretq will re-enable interrupts:
16068 */
16069 @@ -555,14 +845,18 @@ badsys:
16070 * jump back to the normal fast path.
16071 */
16072 auditsys:
16073 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16074 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16075 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16076 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16077 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16078 movq %rax,%rsi /* 2nd arg: syscall number */
16079 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16080 call audit_syscall_entry
16081 +
16082 + pax_erase_kstack
16083 +
16084 LOAD_ARGS 0 /* reload call-clobbered registers */
16085 + pax_set_fptr_mask
16086 jmp system_call_fastpath
16087
16088 /*
16089 @@ -592,16 +886,20 @@ tracesys:
16090 FIXUP_TOP_OF_STACK %rdi
16091 movq %rsp,%rdi
16092 call syscall_trace_enter
16093 +
16094 + pax_erase_kstack
16095 +
16096 /*
16097 * Reload arg registers from stack in case ptrace changed them.
16098 * We don't reload %rax because syscall_trace_enter() returned
16099 * the value it wants us to use in the table lookup.
16100 */
16101 LOAD_ARGS ARGOFFSET, 1
16102 + pax_set_fptr_mask
16103 RESTORE_REST
16104 cmpq $__NR_syscall_max,%rax
16105 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16106 - movq %r10,%rcx /* fixup for C */
16107 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16108 call *sys_call_table(,%rax,8)
16109 movq %rax,RAX-ARGOFFSET(%rsp)
16110 /* Use IRET because user could have changed frame */
16111 @@ -613,7 +911,7 @@ tracesys:
16112 GLOBAL(int_ret_from_sys_call)
16113 DISABLE_INTERRUPTS(CLBR_NONE)
16114 TRACE_IRQS_OFF
16115 - testl $3,CS-ARGOFFSET(%rsp)
16116 + testb $3,CS-ARGOFFSET(%rsp)
16117 je retint_restore_args
16118 movl $_TIF_ALLWORK_MASK,%edi
16119 /* edi: mask to check */
16120 @@ -674,7 +972,7 @@ int_restore_rest:
16121 TRACE_IRQS_OFF
16122 jmp int_with_check
16123 CFI_ENDPROC
16124 -END(system_call)
16125 +ENDPROC(system_call)
16126
16127 /*
16128 * Certain special system calls that need to save a complete full stack frame.
16129 @@ -690,7 +988,7 @@ ENTRY(\label)
16130 call \func
16131 jmp ptregscall_common
16132 CFI_ENDPROC
16133 -END(\label)
16134 +ENDPROC(\label)
16135 .endm
16136
16137 PTREGSCALL stub_clone, sys_clone, %r8
16138 @@ -708,9 +1006,10 @@ ENTRY(ptregscall_common)
16139 movq_cfi_restore R12+8, r12
16140 movq_cfi_restore RBP+8, rbp
16141 movq_cfi_restore RBX+8, rbx
16142 + pax_force_retaddr
16143 ret $REST_SKIP /* pop extended registers */
16144 CFI_ENDPROC
16145 -END(ptregscall_common)
16146 +ENDPROC(ptregscall_common)
16147
16148 ENTRY(stub_execve)
16149 CFI_STARTPROC
16150 @@ -726,7 +1025,7 @@ ENTRY(stub_execve)
16151 RESTORE_REST
16152 jmp int_ret_from_sys_call
16153 CFI_ENDPROC
16154 -END(stub_execve)
16155 +ENDPROC(stub_execve)
16156
16157 /*
16158 * sigreturn is special because it needs to restore all registers on return.
16159 @@ -744,7 +1043,7 @@ ENTRY(stub_rt_sigreturn)
16160 RESTORE_REST
16161 jmp int_ret_from_sys_call
16162 CFI_ENDPROC
16163 -END(stub_rt_sigreturn)
16164 +ENDPROC(stub_rt_sigreturn)
16165
16166 /*
16167 * Build the entry stubs and pointer table with some assembler magic.
16168 @@ -780,7 +1079,7 @@ vector=vector+1
16169 2: jmp common_interrupt
16170 .endr
16171 CFI_ENDPROC
16172 -END(irq_entries_start)
16173 +ENDPROC(irq_entries_start)
16174
16175 .previous
16176 END(interrupt)
16177 @@ -800,6 +1099,16 @@ END(interrupt)
16178 CFI_ADJUST_CFA_OFFSET 10*8
16179 call save_args
16180 PARTIAL_FRAME 0
16181 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16182 + testb $3, CS(%rdi)
16183 + jnz 1f
16184 + pax_enter_kernel
16185 + jmp 2f
16186 +1: pax_enter_kernel_user
16187 +2:
16188 +#else
16189 + pax_enter_kernel
16190 +#endif
16191 call \func
16192 .endm
16193
16194 @@ -822,7 +1131,7 @@ ret_from_intr:
16195 CFI_ADJUST_CFA_OFFSET -8
16196 exit_intr:
16197 GET_THREAD_INFO(%rcx)
16198 - testl $3,CS-ARGOFFSET(%rsp)
16199 + testb $3,CS-ARGOFFSET(%rsp)
16200 je retint_kernel
16201
16202 /* Interrupt came from user space */
16203 @@ -844,12 +1153,16 @@ retint_swapgs: /* return to user-space */
16204 * The iretq could re-enable interrupts:
16205 */
16206 DISABLE_INTERRUPTS(CLBR_ANY)
16207 + pax_exit_kernel_user
16208 + pax_erase_kstack
16209 TRACE_IRQS_IRETQ
16210 SWAPGS
16211 jmp restore_args
16212
16213 retint_restore_args: /* return to kernel space */
16214 DISABLE_INTERRUPTS(CLBR_ANY)
16215 + pax_exit_kernel
16216 + pax_force_retaddr RIP-ARGOFFSET
16217 /*
16218 * The iretq could re-enable interrupts:
16219 */
16220 @@ -940,7 +1253,7 @@ ENTRY(retint_kernel)
16221 #endif
16222
16223 CFI_ENDPROC
16224 -END(common_interrupt)
16225 +ENDPROC(common_interrupt)
16226
16227 /*
16228 * APIC interrupts.
16229 @@ -953,7 +1266,7 @@ ENTRY(\sym)
16230 interrupt \do_sym
16231 jmp ret_from_intr
16232 CFI_ENDPROC
16233 -END(\sym)
16234 +ENDPROC(\sym)
16235 .endm
16236
16237 #ifdef CONFIG_SMP
16238 @@ -1032,12 +1345,22 @@ ENTRY(\sym)
16239 CFI_ADJUST_CFA_OFFSET 15*8
16240 call error_entry
16241 DEFAULT_FRAME 0
16242 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16243 + testb $3, CS(%rsp)
16244 + jnz 1f
16245 + pax_enter_kernel
16246 + jmp 2f
16247 +1: pax_enter_kernel_user
16248 +2:
16249 +#else
16250 + pax_enter_kernel
16251 +#endif
16252 movq %rsp,%rdi /* pt_regs pointer */
16253 xorl %esi,%esi /* no error code */
16254 call \do_sym
16255 jmp error_exit /* %ebx: no swapgs flag */
16256 CFI_ENDPROC
16257 -END(\sym)
16258 +ENDPROC(\sym)
16259 .endm
16260
16261 .macro paranoidzeroentry sym do_sym
16262 @@ -1049,12 +1372,22 @@ ENTRY(\sym)
16263 subq $15*8, %rsp
16264 call save_paranoid
16265 TRACE_IRQS_OFF
16266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16267 + testb $3, CS(%rsp)
16268 + jnz 1f
16269 + pax_enter_kernel
16270 + jmp 2f
16271 +1: pax_enter_kernel_user
16272 +2:
16273 +#else
16274 + pax_enter_kernel
16275 +#endif
16276 movq %rsp,%rdi /* pt_regs pointer */
16277 xorl %esi,%esi /* no error code */
16278 call \do_sym
16279 jmp paranoid_exit /* %ebx: no swapgs flag */
16280 CFI_ENDPROC
16281 -END(\sym)
16282 +ENDPROC(\sym)
16283 .endm
16284
16285 .macro paranoidzeroentry_ist sym do_sym ist
16286 @@ -1066,15 +1399,30 @@ ENTRY(\sym)
16287 subq $15*8, %rsp
16288 call save_paranoid
16289 TRACE_IRQS_OFF
16290 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16291 + testb $3, CS(%rsp)
16292 + jnz 1f
16293 + pax_enter_kernel
16294 + jmp 2f
16295 +1: pax_enter_kernel_user
16296 +2:
16297 +#else
16298 + pax_enter_kernel
16299 +#endif
16300 movq %rsp,%rdi /* pt_regs pointer */
16301 xorl %esi,%esi /* no error code */
16302 - PER_CPU(init_tss, %rbp)
16303 +#ifdef CONFIG_SMP
16304 + imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
16305 + lea init_tss(%rbp), %rbp
16306 +#else
16307 + lea init_tss(%rip), %rbp
16308 +#endif
16309 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
16310 call \do_sym
16311 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
16312 jmp paranoid_exit /* %ebx: no swapgs flag */
16313 CFI_ENDPROC
16314 -END(\sym)
16315 +ENDPROC(\sym)
16316 .endm
16317
16318 .macro errorentry sym do_sym
16319 @@ -1085,13 +1433,23 @@ ENTRY(\sym)
16320 CFI_ADJUST_CFA_OFFSET 15*8
16321 call error_entry
16322 DEFAULT_FRAME 0
16323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16324 + testb $3, CS(%rsp)
16325 + jnz 1f
16326 + pax_enter_kernel
16327 + jmp 2f
16328 +1: pax_enter_kernel_user
16329 +2:
16330 +#else
16331 + pax_enter_kernel
16332 +#endif
16333 movq %rsp,%rdi /* pt_regs pointer */
16334 movq ORIG_RAX(%rsp),%rsi /* get error code */
16335 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16336 call \do_sym
16337 jmp error_exit /* %ebx: no swapgs flag */
16338 CFI_ENDPROC
16339 -END(\sym)
16340 +ENDPROC(\sym)
16341 .endm
16342
16343 /* error code is on the stack already */
16344 @@ -1104,13 +1462,23 @@ ENTRY(\sym)
16345 call save_paranoid
16346 DEFAULT_FRAME 0
16347 TRACE_IRQS_OFF
16348 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16349 + testb $3, CS(%rsp)
16350 + jnz 1f
16351 + pax_enter_kernel
16352 + jmp 2f
16353 +1: pax_enter_kernel_user
16354 +2:
16355 +#else
16356 + pax_enter_kernel
16357 +#endif
16358 movq %rsp,%rdi /* pt_regs pointer */
16359 movq ORIG_RAX(%rsp),%rsi /* get error code */
16360 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16361 call \do_sym
16362 jmp paranoid_exit /* %ebx: no swapgs flag */
16363 CFI_ENDPROC
16364 -END(\sym)
16365 +ENDPROC(\sym)
16366 .endm
16367
16368 zeroentry divide_error do_divide_error
16369 @@ -1141,9 +1509,10 @@ gs_change:
16370 SWAPGS
16371 popf
16372 CFI_ADJUST_CFA_OFFSET -8
16373 + pax_force_retaddr
16374 ret
16375 CFI_ENDPROC
16376 -END(native_load_gs_index)
16377 +ENDPROC(native_load_gs_index)
16378
16379 .section __ex_table,"a"
16380 .align 8
16381 @@ -1193,11 +1562,12 @@ ENTRY(kernel_thread)
16382 * of hacks for example to fork off the per-CPU idle tasks.
16383 * [Hopefully no generic code relies on the reschedule -AK]
16384 */
16385 - RESTORE_ALL
16386 + RESTORE_REST
16387 UNFAKE_STACK_FRAME
16388 + pax_force_retaddr
16389 ret
16390 CFI_ENDPROC
16391 -END(kernel_thread)
16392 +ENDPROC(kernel_thread)
16393
16394 ENTRY(child_rip)
16395 pushq $0 # fake return address
16396 @@ -1208,13 +1578,14 @@ ENTRY(child_rip)
16397 */
16398 movq %rdi, %rax
16399 movq %rsi, %rdi
16400 + pax_force_fptr %rax
16401 call *%rax
16402 # exit
16403 mov %eax, %edi
16404 call do_exit
16405 ud2 # padding for call trace
16406 CFI_ENDPROC
16407 -END(child_rip)
16408 +ENDPROC(child_rip)
16409
16410 /*
16411 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16412 @@ -1241,11 +1612,11 @@ ENTRY(kernel_execve)
16413 RESTORE_REST
16414 testq %rax,%rax
16415 je int_ret_from_sys_call
16416 - RESTORE_ARGS
16417 UNFAKE_STACK_FRAME
16418 + pax_force_retaddr
16419 ret
16420 CFI_ENDPROC
16421 -END(kernel_execve)
16422 +ENDPROC(kernel_execve)
16423
16424 /* Call softirq on interrupt stack. Interrupts are off. */
16425 ENTRY(call_softirq)
16426 @@ -1263,9 +1634,10 @@ ENTRY(call_softirq)
16427 CFI_DEF_CFA_REGISTER rsp
16428 CFI_ADJUST_CFA_OFFSET -8
16429 decl PER_CPU_VAR(irq_count)
16430 + pax_force_retaddr
16431 ret
16432 CFI_ENDPROC
16433 -END(call_softirq)
16434 +ENDPROC(call_softirq)
16435
16436 #ifdef CONFIG_XEN
16437 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16438 @@ -1303,7 +1675,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16439 decl PER_CPU_VAR(irq_count)
16440 jmp error_exit
16441 CFI_ENDPROC
16442 -END(xen_do_hypervisor_callback)
16443 +ENDPROC(xen_do_hypervisor_callback)
16444
16445 /*
16446 * Hypervisor uses this for application faults while it executes.
16447 @@ -1362,7 +1734,7 @@ ENTRY(xen_failsafe_callback)
16448 SAVE_ALL
16449 jmp error_exit
16450 CFI_ENDPROC
16451 -END(xen_failsafe_callback)
16452 +ENDPROC(xen_failsafe_callback)
16453
16454 #endif /* CONFIG_XEN */
16455
16456 @@ -1405,16 +1777,31 @@ ENTRY(paranoid_exit)
16457 TRACE_IRQS_OFF
16458 testl %ebx,%ebx /* swapgs needed? */
16459 jnz paranoid_restore
16460 - testl $3,CS(%rsp)
16461 + testb $3,CS(%rsp)
16462 jnz paranoid_userspace
16463 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16464 + pax_exit_kernel
16465 + TRACE_IRQS_IRETQ 0
16466 + SWAPGS_UNSAFE_STACK
16467 + RESTORE_ALL 8
16468 + pax_force_retaddr_bts
16469 + jmp irq_return
16470 +#endif
16471 paranoid_swapgs:
16472 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16473 + pax_exit_kernel_user
16474 +#else
16475 + pax_exit_kernel
16476 +#endif
16477 TRACE_IRQS_IRETQ 0
16478 SWAPGS_UNSAFE_STACK
16479 RESTORE_ALL 8
16480 jmp irq_return
16481 paranoid_restore:
16482 + pax_exit_kernel
16483 TRACE_IRQS_IRETQ 0
16484 RESTORE_ALL 8
16485 + pax_force_retaddr_bts
16486 jmp irq_return
16487 paranoid_userspace:
16488 GET_THREAD_INFO(%rcx)
16489 @@ -1443,7 +1830,7 @@ paranoid_schedule:
16490 TRACE_IRQS_OFF
16491 jmp paranoid_userspace
16492 CFI_ENDPROC
16493 -END(paranoid_exit)
16494 +ENDPROC(paranoid_exit)
16495
16496 /*
16497 * Exception entry point. This expects an error code/orig_rax on the stack.
16498 @@ -1470,12 +1857,13 @@ ENTRY(error_entry)
16499 movq_cfi r14, R14+8
16500 movq_cfi r15, R15+8
16501 xorl %ebx,%ebx
16502 - testl $3,CS+8(%rsp)
16503 + testb $3,CS+8(%rsp)
16504 je error_kernelspace
16505 error_swapgs:
16506 SWAPGS
16507 error_sti:
16508 TRACE_IRQS_OFF
16509 + pax_force_retaddr_bts
16510 ret
16511 CFI_ENDPROC
16512
16513 @@ -1497,7 +1885,7 @@ error_kernelspace:
16514 cmpq $gs_change,RIP+8(%rsp)
16515 je error_swapgs
16516 jmp error_sti
16517 -END(error_entry)
16518 +ENDPROC(error_entry)
16519
16520
16521 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16522 @@ -1517,7 +1905,7 @@ ENTRY(error_exit)
16523 jnz retint_careful
16524 jmp retint_swapgs
16525 CFI_ENDPROC
16526 -END(error_exit)
16527 +ENDPROC(error_exit)
16528
16529
16530 /* runs on exception stack */
16531 @@ -1529,6 +1917,16 @@ ENTRY(nmi)
16532 CFI_ADJUST_CFA_OFFSET 15*8
16533 call save_paranoid
16534 DEFAULT_FRAME 0
16535 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16536 + testb $3, CS(%rsp)
16537 + jnz 1f
16538 + pax_enter_kernel
16539 + jmp 2f
16540 +1: pax_enter_kernel_user
16541 +2:
16542 +#else
16543 + pax_enter_kernel
16544 +#endif
16545 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16546 movq %rsp,%rdi
16547 movq $-1,%rsi
16548 @@ -1539,12 +1937,28 @@ ENTRY(nmi)
16549 DISABLE_INTERRUPTS(CLBR_NONE)
16550 testl %ebx,%ebx /* swapgs needed? */
16551 jnz nmi_restore
16552 - testl $3,CS(%rsp)
16553 + testb $3,CS(%rsp)
16554 jnz nmi_userspace
16555 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16556 + pax_exit_kernel
16557 + SWAPGS_UNSAFE_STACK
16558 + RESTORE_ALL 8
16559 + pax_force_retaddr_bts
16560 + jmp irq_return
16561 +#endif
16562 nmi_swapgs:
16563 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16564 + pax_exit_kernel_user
16565 +#else
16566 + pax_exit_kernel
16567 +#endif
16568 SWAPGS_UNSAFE_STACK
16569 + RESTORE_ALL 8
16570 + jmp irq_return
16571 nmi_restore:
16572 + pax_exit_kernel
16573 RESTORE_ALL 8
16574 + pax_force_retaddr_bts
16575 jmp irq_return
16576 nmi_userspace:
16577 GET_THREAD_INFO(%rcx)
16578 @@ -1573,14 +1987,14 @@ nmi_schedule:
16579 jmp paranoid_exit
16580 CFI_ENDPROC
16581 #endif
16582 -END(nmi)
16583 +ENDPROC(nmi)
16584
16585 ENTRY(ignore_sysret)
16586 CFI_STARTPROC
16587 mov $-ENOSYS,%eax
16588 sysret
16589 CFI_ENDPROC
16590 -END(ignore_sysret)
16591 +ENDPROC(ignore_sysret)
16592
16593 /*
16594 * End of kprobes section
16595 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16596 index 9dbb527..7b3615a 100644
16597 --- a/arch/x86/kernel/ftrace.c
16598 +++ b/arch/x86/kernel/ftrace.c
16599 @@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16600 static void *mod_code_newcode; /* holds the text to write to the IP */
16601
16602 static unsigned nmi_wait_count;
16603 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16604 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16605
16606 int ftrace_arch_read_dyn_info(char *buf, int size)
16607 {
16608 @@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16609
16610 r = snprintf(buf, size, "%u %u",
16611 nmi_wait_count,
16612 - atomic_read(&nmi_update_count));
16613 + atomic_read_unchecked(&nmi_update_count));
16614 return r;
16615 }
16616
16617 @@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
16618 {
16619 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16620 smp_rmb();
16621 + pax_open_kernel();
16622 ftrace_mod_code();
16623 - atomic_inc(&nmi_update_count);
16624 + pax_close_kernel();
16625 + atomic_inc_unchecked(&nmi_update_count);
16626 }
16627 /* Must have previous changes seen before executions */
16628 smp_mb();
16629 @@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, void *new_code)
16630
16631
16632
16633 -static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
16634 +static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
16635
16636 static unsigned char *ftrace_nop_replace(void)
16637 {
16638 @@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
16639 {
16640 unsigned char replaced[MCOUNT_INSN_SIZE];
16641
16642 + ip = ktla_ktva(ip);
16643 +
16644 /*
16645 * Note: Due to modules and __init, code can
16646 * disappear and change, we need to protect against faulting
16647 @@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16648 unsigned char old[MCOUNT_INSN_SIZE], *new;
16649 int ret;
16650
16651 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16652 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16653 new = ftrace_call_replace(ip, (unsigned long)func);
16654 ret = ftrace_modify_code(ip, old, new);
16655
16656 @@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *data)
16657 switch (faulted) {
16658 case 0:
16659 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
16660 - memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
16661 + memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
16662 break;
16663 case 1:
16664 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
16665 - memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
16666 + memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
16667 break;
16668 case 2:
16669 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
16670 - memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
16671 + memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
16672 break;
16673 }
16674
16675 @@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16676 {
16677 unsigned char code[MCOUNT_INSN_SIZE];
16678
16679 + ip = ktla_ktva(ip);
16680 +
16681 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16682 return -EFAULT;
16683
16684 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16685 index 4f8e250..df24706 100644
16686 --- a/arch/x86/kernel/head32.c
16687 +++ b/arch/x86/kernel/head32.c
16688 @@ -16,6 +16,7 @@
16689 #include <asm/apic.h>
16690 #include <asm/io_apic.h>
16691 #include <asm/bios_ebda.h>
16692 +#include <asm/boot.h>
16693
16694 static void __init i386_default_early_setup(void)
16695 {
16696 @@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
16697 {
16698 reserve_trampoline_memory();
16699
16700 - reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16701 + reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16702
16703 #ifdef CONFIG_BLK_DEV_INITRD
16704 /* Reserve INITRD */
16705 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16706 index 34c3308..6fc4e76 100644
16707 --- a/arch/x86/kernel/head_32.S
16708 +++ b/arch/x86/kernel/head_32.S
16709 @@ -19,10 +19,17 @@
16710 #include <asm/setup.h>
16711 #include <asm/processor-flags.h>
16712 #include <asm/percpu.h>
16713 +#include <asm/msr-index.h>
16714
16715 /* Physical address */
16716 #define pa(X) ((X) - __PAGE_OFFSET)
16717
16718 +#ifdef CONFIG_PAX_KERNEXEC
16719 +#define ta(X) (X)
16720 +#else
16721 +#define ta(X) ((X) - __PAGE_OFFSET)
16722 +#endif
16723 +
16724 /*
16725 * References to members of the new_cpu_data structure.
16726 */
16727 @@ -52,11 +59,7 @@
16728 * and small than max_low_pfn, otherwise will waste some page table entries
16729 */
16730
16731 -#if PTRS_PER_PMD > 1
16732 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16733 -#else
16734 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16735 -#endif
16736 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16737
16738 /* Enough space to fit pagetables for the low memory linear map */
16739 MAPPING_BEYOND_END = \
16740 @@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE_asm
16741 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16742
16743 /*
16744 + * Real beginning of normal "text" segment
16745 + */
16746 +ENTRY(stext)
16747 +ENTRY(_stext)
16748 +
16749 +/*
16750 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16751 * %esi points to the real-mode code as a 32-bit pointer.
16752 * CS and DS must be 4 GB flat segments, but we don't depend on
16753 @@ -80,7 +89,16 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16754 * can.
16755 */
16756 __HEAD
16757 +
16758 +#ifdef CONFIG_PAX_KERNEXEC
16759 + jmp startup_32
16760 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16761 +.fill PAGE_SIZE-5,1,0xcc
16762 +#endif
16763 +
16764 ENTRY(startup_32)
16765 + movl pa(stack_start),%ecx
16766 +
16767 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
16768 us to not reload segments */
16769 testb $(1<<6), BP_loadflags(%esi)
16770 @@ -95,7 +113,60 @@ ENTRY(startup_32)
16771 movl %eax,%es
16772 movl %eax,%fs
16773 movl %eax,%gs
16774 + movl %eax,%ss
16775 2:
16776 + leal -__PAGE_OFFSET(%ecx),%esp
16777 +
16778 +#ifdef CONFIG_SMP
16779 + movl $pa(cpu_gdt_table),%edi
16780 + movl $__per_cpu_load,%eax
16781 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16782 + rorl $16,%eax
16783 + movb %al,__KERNEL_PERCPU + 4(%edi)
16784 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16785 + movl $__per_cpu_end - 1,%eax
16786 + subl $__per_cpu_start,%eax
16787 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16788 +#endif
16789 +
16790 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16791 + movl $NR_CPUS,%ecx
16792 + movl $pa(cpu_gdt_table),%edi
16793 +1:
16794 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16795 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16796 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16797 + addl $PAGE_SIZE_asm,%edi
16798 + loop 1b
16799 +#endif
16800 +
16801 +#ifdef CONFIG_PAX_KERNEXEC
16802 + movl $pa(boot_gdt),%edi
16803 + movl $__LOAD_PHYSICAL_ADDR,%eax
16804 + movw %ax,__BOOT_CS + 2(%edi)
16805 + rorl $16,%eax
16806 + movb %al,__BOOT_CS + 4(%edi)
16807 + movb %ah,__BOOT_CS + 7(%edi)
16808 + rorl $16,%eax
16809 +
16810 + ljmp $(__BOOT_CS),$1f
16811 +1:
16812 +
16813 + movl $NR_CPUS,%ecx
16814 + movl $pa(cpu_gdt_table),%edi
16815 + addl $__PAGE_OFFSET,%eax
16816 +1:
16817 + movw %ax,__KERNEL_CS + 2(%edi)
16818 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16819 + rorl $16,%eax
16820 + movb %al,__KERNEL_CS + 4(%edi)
16821 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16822 + movb %ah,__KERNEL_CS + 7(%edi)
16823 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16824 + rorl $16,%eax
16825 + addl $PAGE_SIZE_asm,%edi
16826 + loop 1b
16827 +#endif
16828
16829 /*
16830 * Clear BSS first so that there are no surprises...
16831 @@ -140,9 +211,7 @@ ENTRY(startup_32)
16832 cmpl $num_subarch_entries, %eax
16833 jae bad_subarch
16834
16835 - movl pa(subarch_entries)(,%eax,4), %eax
16836 - subl $__PAGE_OFFSET, %eax
16837 - jmp *%eax
16838 + jmp *pa(subarch_entries)(,%eax,4)
16839
16840 bad_subarch:
16841 WEAK(lguest_entry)
16842 @@ -154,10 +223,10 @@ WEAK(xen_entry)
16843 __INITDATA
16844
16845 subarch_entries:
16846 - .long default_entry /* normal x86/PC */
16847 - .long lguest_entry /* lguest hypervisor */
16848 - .long xen_entry /* Xen hypervisor */
16849 - .long default_entry /* Moorestown MID */
16850 + .long ta(default_entry) /* normal x86/PC */
16851 + .long ta(lguest_entry) /* lguest hypervisor */
16852 + .long ta(xen_entry) /* Xen hypervisor */
16853 + .long ta(default_entry) /* Moorestown MID */
16854 num_subarch_entries = (. - subarch_entries) / 4
16855 .previous
16856 #endif /* CONFIG_PARAVIRT */
16857 @@ -218,8 +287,11 @@ default_entry:
16858 movl %eax, pa(max_pfn_mapped)
16859
16860 /* Do early initialization of the fixmap area */
16861 - movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
16862 - movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16863 +#ifdef CONFIG_COMPAT_VDSO
16864 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16865 +#else
16866 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16867 +#endif
16868 #else /* Not PAE */
16869
16870 page_pde_offset = (__PAGE_OFFSET >> 20);
16871 @@ -249,8 +321,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16872 movl %eax, pa(max_pfn_mapped)
16873
16874 /* Do early initialization of the fixmap area */
16875 - movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
16876 - movl %eax,pa(swapper_pg_dir+0xffc)
16877 +#ifdef CONFIG_COMPAT_VDSO
16878 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
16879 +#else
16880 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
16881 +#endif
16882 #endif
16883 jmp 3f
16884 /*
16885 @@ -272,6 +347,9 @@ ENTRY(startup_32_smp)
16886 movl %eax,%es
16887 movl %eax,%fs
16888 movl %eax,%gs
16889 + movl pa(stack_start),%ecx
16890 + movl %eax,%ss
16891 + leal -__PAGE_OFFSET(%ecx),%esp
16892 #endif /* CONFIG_SMP */
16893 3:
16894
16895 @@ -297,6 +375,7 @@ ENTRY(startup_32_smp)
16896 orl %edx,%eax
16897 movl %eax,%cr4
16898
16899 +#ifdef CONFIG_X86_PAE
16900 btl $5, %eax # check if PAE is enabled
16901 jnc 6f
16902
16903 @@ -305,6 +384,10 @@ ENTRY(startup_32_smp)
16904 cpuid
16905 cmpl $0x80000000, %eax
16906 jbe 6f
16907 +
16908 + /* Clear bogus XD_DISABLE bits */
16909 + call verify_cpu
16910 +
16911 mov $0x80000001, %eax
16912 cpuid
16913 /* Execute Disable bit supported? */
16914 @@ -312,13 +395,17 @@ ENTRY(startup_32_smp)
16915 jnc 6f
16916
16917 /* Setup EFER (Extended Feature Enable Register) */
16918 - movl $0xc0000080, %ecx
16919 + movl $MSR_EFER, %ecx
16920 rdmsr
16921
16922 btsl $11, %eax
16923 /* Make changes effective */
16924 wrmsr
16925
16926 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16927 + movl $1,pa(nx_enabled)
16928 +#endif
16929 +
16930 6:
16931
16932 /*
16933 @@ -331,8 +418,8 @@ ENTRY(startup_32_smp)
16934 movl %eax,%cr0 /* ..and set paging (PG) bit */
16935 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
16936 1:
16937 - /* Set up the stack pointer */
16938 - lss stack_start,%esp
16939 + /* Shift the stack pointer to a virtual address */
16940 + addl $__PAGE_OFFSET, %esp
16941
16942 /*
16943 * Initialize eflags. Some BIOS's leave bits like NT set. This would
16944 @@ -344,9 +431,7 @@ ENTRY(startup_32_smp)
16945
16946 #ifdef CONFIG_SMP
16947 cmpb $0, ready
16948 - jz 1f /* Initial CPU cleans BSS */
16949 - jmp checkCPUtype
16950 -1:
16951 + jnz checkCPUtype
16952 #endif /* CONFIG_SMP */
16953
16954 /*
16955 @@ -424,7 +509,7 @@ is386: movl $2,%ecx # set MP
16956 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16957 movl %eax,%ss # after changing gdt.
16958
16959 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16960 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16961 movl %eax,%ds
16962 movl %eax,%es
16963
16964 @@ -438,15 +523,22 @@ is386: movl $2,%ecx # set MP
16965 */
16966 cmpb $0,ready
16967 jne 1f
16968 - movl $per_cpu__gdt_page,%eax
16969 + movl $cpu_gdt_table,%eax
16970 movl $per_cpu__stack_canary,%ecx
16971 +#ifdef CONFIG_SMP
16972 + addl $__per_cpu_load,%ecx
16973 +#endif
16974 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16975 shrl $16, %ecx
16976 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16977 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16978 1:
16979 -#endif
16980 movl $(__KERNEL_STACK_CANARY),%eax
16981 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16982 + movl $(__USER_DS),%eax
16983 +#else
16984 + xorl %eax,%eax
16985 +#endif
16986 movl %eax,%gs
16987
16988 xorl %eax,%eax # Clear LDT
16989 @@ -454,14 +546,7 @@ is386: movl $2,%ecx # set MP
16990
16991 cld # gcc2 wants the direction flag cleared at all times
16992 pushl $0 # fake return address for unwinder
16993 -#ifdef CONFIG_SMP
16994 - movb ready, %cl
16995 movb $1, ready
16996 - cmpb $0,%cl # the first CPU calls start_kernel
16997 - je 1f
16998 - movl (stack_start), %esp
16999 -1:
17000 -#endif /* CONFIG_SMP */
17001 jmp *(initial_code)
17002
17003 /*
17004 @@ -546,22 +631,22 @@ early_page_fault:
17005 jmp early_fault
17006
17007 early_fault:
17008 - cld
17009 #ifdef CONFIG_PRINTK
17010 + cmpl $1,%ss:early_recursion_flag
17011 + je hlt_loop
17012 + incl %ss:early_recursion_flag
17013 + cld
17014 pusha
17015 movl $(__KERNEL_DS),%eax
17016 movl %eax,%ds
17017 movl %eax,%es
17018 - cmpl $2,early_recursion_flag
17019 - je hlt_loop
17020 - incl early_recursion_flag
17021 movl %cr2,%eax
17022 pushl %eax
17023 pushl %edx /* trapno */
17024 pushl $fault_msg
17025 call printk
17026 +; call dump_stack
17027 #endif
17028 - call dump_stack
17029 hlt_loop:
17030 hlt
17031 jmp hlt_loop
17032 @@ -569,8 +654,11 @@ hlt_loop:
17033 /* This is the default interrupt "handler" :-) */
17034 ALIGN
17035 ignore_int:
17036 - cld
17037 #ifdef CONFIG_PRINTK
17038 + cmpl $2,%ss:early_recursion_flag
17039 + je hlt_loop
17040 + incl %ss:early_recursion_flag
17041 + cld
17042 pushl %eax
17043 pushl %ecx
17044 pushl %edx
17045 @@ -579,9 +667,6 @@ ignore_int:
17046 movl $(__KERNEL_DS),%eax
17047 movl %eax,%ds
17048 movl %eax,%es
17049 - cmpl $2,early_recursion_flag
17050 - je hlt_loop
17051 - incl early_recursion_flag
17052 pushl 16(%esp)
17053 pushl 24(%esp)
17054 pushl 32(%esp)
17055 @@ -600,6 +685,8 @@ ignore_int:
17056 #endif
17057 iret
17058
17059 +#include "verify_cpu.S"
17060 +
17061 __REFDATA
17062 .align 4
17063 ENTRY(initial_code)
17064 @@ -610,31 +697,47 @@ ENTRY(initial_page_table)
17065 /*
17066 * BSS section
17067 */
17068 -__PAGE_ALIGNED_BSS
17069 - .align PAGE_SIZE_asm
17070 #ifdef CONFIG_X86_PAE
17071 +.section .swapper_pg_pmd,"a",@progbits
17072 swapper_pg_pmd:
17073 .fill 1024*KPMDS,4,0
17074 #else
17075 +.section .swapper_pg_dir,"a",@progbits
17076 ENTRY(swapper_pg_dir)
17077 .fill 1024,4,0
17078 #endif
17079 +.section .swapper_pg_fixmap,"a",@progbits
17080 swapper_pg_fixmap:
17081 .fill 1024,4,0
17082 #ifdef CONFIG_X86_TRAMPOLINE
17083 +.section .trampoline_pg_dir,"a",@progbits
17084 ENTRY(trampoline_pg_dir)
17085 +#ifdef CONFIG_X86_PAE
17086 + .fill 4,8,0
17087 +#else
17088 .fill 1024,4,0
17089 #endif
17090 +#endif
17091 +
17092 +.section .empty_zero_page,"a",@progbits
17093 ENTRY(empty_zero_page)
17094 .fill 4096,1,0
17095
17096 /*
17097 + * The IDT has to be page-aligned to simplify the Pentium
17098 + * F0 0F bug workaround.. We have a special link segment
17099 + * for this.
17100 + */
17101 +.section .idt,"a",@progbits
17102 +ENTRY(idt_table)
17103 + .fill 256,8,0
17104 +
17105 +/*
17106 * This starts the data section.
17107 */
17108 #ifdef CONFIG_X86_PAE
17109 -__PAGE_ALIGNED_DATA
17110 - /* Page-aligned for the benefit of paravirt? */
17111 - .align PAGE_SIZE_asm
17112 +.section .swapper_pg_dir,"a",@progbits
17113 +
17114 ENTRY(swapper_pg_dir)
17115 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17116 # if KPMDS == 3
17117 @@ -653,15 +756,24 @@ ENTRY(swapper_pg_dir)
17118 # error "Kernel PMDs should be 1, 2 or 3"
17119 # endif
17120 .align PAGE_SIZE_asm /* needs to be page-sized too */
17121 +
17122 +#ifdef CONFIG_PAX_PER_CPU_PGD
17123 +ENTRY(cpu_pgd)
17124 + .rept NR_CPUS
17125 + .fill 4,8,0
17126 + .endr
17127 +#endif
17128 +
17129 #endif
17130
17131 .data
17132 +.balign 4
17133 ENTRY(stack_start)
17134 - .long init_thread_union+THREAD_SIZE
17135 - .long __BOOT_DS
17136 + .long init_thread_union+THREAD_SIZE-8
17137
17138 ready: .byte 0
17139
17140 +.section .rodata,"a",@progbits
17141 early_recursion_flag:
17142 .long 0
17143
17144 @@ -697,7 +809,7 @@ fault_msg:
17145 .word 0 # 32 bit align gdt_desc.address
17146 boot_gdt_descr:
17147 .word __BOOT_DS+7
17148 - .long boot_gdt - __PAGE_OFFSET
17149 + .long pa(boot_gdt)
17150
17151 .word 0 # 32-bit align idt_desc.address
17152 idt_descr:
17153 @@ -708,7 +820,7 @@ idt_descr:
17154 .word 0 # 32 bit align gdt_desc.address
17155 ENTRY(early_gdt_descr)
17156 .word GDT_ENTRIES*8-1
17157 - .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
17158 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17159
17160 /*
17161 * The boot_gdt must mirror the equivalent in setup.S and is
17162 @@ -717,5 +829,65 @@ ENTRY(early_gdt_descr)
17163 .align L1_CACHE_BYTES
17164 ENTRY(boot_gdt)
17165 .fill GDT_ENTRY_BOOT_CS,8,0
17166 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17167 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17168 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17169 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17170 +
17171 + .align PAGE_SIZE_asm
17172 +ENTRY(cpu_gdt_table)
17173 + .rept NR_CPUS
17174 + .quad 0x0000000000000000 /* NULL descriptor */
17175 + .quad 0x0000000000000000 /* 0x0b reserved */
17176 + .quad 0x0000000000000000 /* 0x13 reserved */
17177 + .quad 0x0000000000000000 /* 0x1b reserved */
17178 +
17179 +#ifdef CONFIG_PAX_KERNEXEC
17180 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17181 +#else
17182 + .quad 0x0000000000000000 /* 0x20 unused */
17183 +#endif
17184 +
17185 + .quad 0x0000000000000000 /* 0x28 unused */
17186 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17187 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17188 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17189 + .quad 0x0000000000000000 /* 0x4b reserved */
17190 + .quad 0x0000000000000000 /* 0x53 reserved */
17191 + .quad 0x0000000000000000 /* 0x5b reserved */
17192 +
17193 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17194 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17195 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17196 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17197 +
17198 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17199 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17200 +
17201 + /*
17202 + * Segments used for calling PnP BIOS have byte granularity.
17203 + * The code segments and data segments have fixed 64k limits,
17204 + * the transfer segment sizes are set at run time.
17205 + */
17206 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17207 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17208 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17209 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17210 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17211 +
17212 + /*
17213 + * The APM segments have byte granularity and their bases
17214 + * are set at run time. All have 64k limits.
17215 + */
17216 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17217 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17218 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17219 +
17220 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17221 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17222 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17223 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17224 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17225 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17226 +
17227 + /* Be sure this is zeroed to avoid false validations in Xen */
17228 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17229 + .endr
17230 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17231 index 780cd92..758b2a6 100644
17232 --- a/arch/x86/kernel/head_64.S
17233 +++ b/arch/x86/kernel/head_64.S
17234 @@ -19,6 +19,8 @@
17235 #include <asm/cache.h>
17236 #include <asm/processor-flags.h>
17237 #include <asm/percpu.h>
17238 +#include <asm/cpufeature.h>
17239 +#include <asm/alternative-asm.h>
17240
17241 #ifdef CONFIG_PARAVIRT
17242 #include <asm/asm-offsets.h>
17243 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17244 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17245 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17246 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17247 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17248 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17249 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17250 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17251 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17252 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17253
17254 .text
17255 __HEAD
17256 @@ -85,35 +93,23 @@ startup_64:
17257 */
17258 addq %rbp, init_level4_pgt + 0(%rip)
17259 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17260 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17261 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17262 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17263 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17264
17265 addq %rbp, level3_ident_pgt + 0(%rip)
17266 +#ifndef CONFIG_XEN
17267 + addq %rbp, level3_ident_pgt + 8(%rip)
17268 +#endif
17269
17270 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17271 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17272 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17273 +
17274 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17275 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17276
17277 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17278 -
17279 - /* Add an Identity mapping if I am above 1G */
17280 - leaq _text(%rip), %rdi
17281 - andq $PMD_PAGE_MASK, %rdi
17282 -
17283 - movq %rdi, %rax
17284 - shrq $PUD_SHIFT, %rax
17285 - andq $(PTRS_PER_PUD - 1), %rax
17286 - jz ident_complete
17287 -
17288 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17289 - leaq level3_ident_pgt(%rip), %rbx
17290 - movq %rdx, 0(%rbx, %rax, 8)
17291 -
17292 - movq %rdi, %rax
17293 - shrq $PMD_SHIFT, %rax
17294 - andq $(PTRS_PER_PMD - 1), %rax
17295 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17296 - leaq level2_spare_pgt(%rip), %rbx
17297 - movq %rdx, 0(%rbx, %rax, 8)
17298 -ident_complete:
17299 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17300
17301 /*
17302 * Fixup the kernel text+data virtual addresses. Note that
17303 @@ -161,8 +157,8 @@ ENTRY(secondary_startup_64)
17304 * after the boot processor executes this code.
17305 */
17306
17307 - /* Enable PAE mode and PGE */
17308 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17309 + /* Enable PAE mode and PSE/PGE */
17310 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17311 movq %rax, %cr4
17312
17313 /* Setup early boot stage 4 level pagetables. */
17314 @@ -184,9 +180,16 @@ ENTRY(secondary_startup_64)
17315 movl $MSR_EFER, %ecx
17316 rdmsr
17317 btsl $_EFER_SCE, %eax /* Enable System Call */
17318 - btl $20,%edi /* No Execute supported? */
17319 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17320 jnc 1f
17321 btsl $_EFER_NX, %eax
17322 + leaq init_level4_pgt(%rip), %rdi
17323 +#ifndef CONFIG_EFI
17324 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17325 +#endif
17326 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17327 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17328 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17329 1: wrmsr /* Make changes effective */
17330
17331 /* Setup cr0 */
17332 @@ -249,6 +252,7 @@ ENTRY(secondary_startup_64)
17333 * jump. In addition we need to ensure %cs is set so we make this
17334 * a far return.
17335 */
17336 + pax_set_fptr_mask
17337 movq initial_code(%rip),%rax
17338 pushq $0 # fake return address to stop unwinder
17339 pushq $__KERNEL_CS # set correct cs
17340 @@ -262,16 +266,16 @@ ENTRY(secondary_startup_64)
17341 .quad x86_64_start_kernel
17342 ENTRY(initial_gs)
17343 .quad INIT_PER_CPU_VAR(irq_stack_union)
17344 - __FINITDATA
17345
17346 ENTRY(stack_start)
17347 .quad init_thread_union+THREAD_SIZE-8
17348 .word 0
17349 + __FINITDATA
17350
17351 bad_address:
17352 jmp bad_address
17353
17354 - .section ".init.text","ax"
17355 + __INIT
17356 #ifdef CONFIG_EARLY_PRINTK
17357 .globl early_idt_handlers
17358 early_idt_handlers:
17359 @@ -316,18 +320,23 @@ ENTRY(early_idt_handler)
17360 #endif /* EARLY_PRINTK */
17361 1: hlt
17362 jmp 1b
17363 + .previous
17364
17365 #ifdef CONFIG_EARLY_PRINTK
17366 + __INITDATA
17367 early_recursion_flag:
17368 .long 0
17369 + .previous
17370
17371 + .section .rodata,"a",@progbits
17372 early_idt_msg:
17373 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17374 early_idt_ripmsg:
17375 .asciz "RIP %s\n"
17376 + .previous
17377 #endif /* CONFIG_EARLY_PRINTK */
17378 - .previous
17379
17380 + .section .rodata,"a",@progbits
17381 #define NEXT_PAGE(name) \
17382 .balign PAGE_SIZE; \
17383 ENTRY(name)
17384 @@ -350,13 +359,41 @@ NEXT_PAGE(init_level4_pgt)
17385 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17386 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17387 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17388 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17389 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17390 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17391 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17392 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17393 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17394 .org init_level4_pgt + L4_START_KERNEL*8, 0
17395 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17396 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17397
17398 +#ifdef CONFIG_PAX_PER_CPU_PGD
17399 +NEXT_PAGE(cpu_pgd)
17400 + .rept NR_CPUS
17401 + .fill 512,8,0
17402 + .endr
17403 +#endif
17404 +
17405 NEXT_PAGE(level3_ident_pgt)
17406 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17407 +#ifdef CONFIG_XEN
17408 .fill 511,8,0
17409 +#else
17410 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17411 + .fill 510,8,0
17412 +#endif
17413 +
17414 +NEXT_PAGE(level3_vmalloc_start_pgt)
17415 + .fill 512,8,0
17416 +
17417 +NEXT_PAGE(level3_vmalloc_end_pgt)
17418 + .fill 512,8,0
17419 +
17420 +NEXT_PAGE(level3_vmemmap_pgt)
17421 + .fill L3_VMEMMAP_START,8,0
17422 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17423
17424 NEXT_PAGE(level3_kernel_pgt)
17425 .fill L3_START_KERNEL,8,0
17426 @@ -364,20 +401,23 @@ NEXT_PAGE(level3_kernel_pgt)
17427 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17428 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17429
17430 +NEXT_PAGE(level2_vmemmap_pgt)
17431 + .fill 512,8,0
17432 +
17433 NEXT_PAGE(level2_fixmap_pgt)
17434 - .fill 506,8,0
17435 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17436 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17437 - .fill 5,8,0
17438 + .fill 507,8,0
17439 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17440 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17441 + .fill 4,8,0
17442
17443 -NEXT_PAGE(level1_fixmap_pgt)
17444 +NEXT_PAGE(level1_vsyscall_pgt)
17445 .fill 512,8,0
17446
17447 -NEXT_PAGE(level2_ident_pgt)
17448 - /* Since I easily can, map the first 1G.
17449 + /* Since I easily can, map the first 2G.
17450 * Don't set NX because code runs from these pages.
17451 */
17452 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17453 +NEXT_PAGE(level2_ident_pgt)
17454 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17455
17456 NEXT_PAGE(level2_kernel_pgt)
17457 /*
17458 @@ -390,33 +430,55 @@ NEXT_PAGE(level2_kernel_pgt)
17459 * If you want to increase this then increase MODULES_VADDR
17460 * too.)
17461 */
17462 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17463 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17464 -
17465 -NEXT_PAGE(level2_spare_pgt)
17466 - .fill 512, 8, 0
17467 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17468
17469 #undef PMDS
17470 #undef NEXT_PAGE
17471
17472 - .data
17473 + .align PAGE_SIZE
17474 +ENTRY(cpu_gdt_table)
17475 + .rept NR_CPUS
17476 + .quad 0x0000000000000000 /* NULL descriptor */
17477 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17478 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17479 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17480 + .quad 0x00cffb000000ffff /* __USER32_CS */
17481 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17482 + .quad 0x00affb000000ffff /* __USER_CS */
17483 +
17484 +#ifdef CONFIG_PAX_KERNEXEC
17485 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17486 +#else
17487 + .quad 0x0 /* unused */
17488 +#endif
17489 +
17490 + .quad 0,0 /* TSS */
17491 + .quad 0,0 /* LDT */
17492 + .quad 0,0,0 /* three TLS descriptors */
17493 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17494 + /* asm/segment.h:GDT_ENTRIES must match this */
17495 +
17496 + /* zero the remaining page */
17497 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17498 + .endr
17499 +
17500 .align 16
17501 .globl early_gdt_descr
17502 early_gdt_descr:
17503 .word GDT_ENTRIES*8-1
17504 early_gdt_descr_base:
17505 - .quad INIT_PER_CPU_VAR(gdt_page)
17506 + .quad cpu_gdt_table
17507
17508 ENTRY(phys_base)
17509 /* This must match the first entry in level2_kernel_pgt */
17510 .quad 0x0000000000000000
17511
17512 #include "../../x86/xen/xen-head.S"
17513 -
17514 - .section .bss, "aw", @nobits
17515 +
17516 + .section .rodata,"a",@progbits
17517 .align L1_CACHE_BYTES
17518 ENTRY(idt_table)
17519 - .skip IDT_ENTRIES * 16
17520 + .fill 512,8,0
17521
17522 __PAGE_ALIGNED_BSS
17523 .align PAGE_SIZE
17524 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17525 index 9c3bd4a..e1d9b35 100644
17526 --- a/arch/x86/kernel/i386_ksyms_32.c
17527 +++ b/arch/x86/kernel/i386_ksyms_32.c
17528 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17529 EXPORT_SYMBOL(cmpxchg8b_emu);
17530 #endif
17531
17532 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17533 +
17534 /* Networking helper routines. */
17535 EXPORT_SYMBOL(csum_partial_copy_generic);
17536 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17537 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17538
17539 EXPORT_SYMBOL(__get_user_1);
17540 EXPORT_SYMBOL(__get_user_2);
17541 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17542
17543 EXPORT_SYMBOL(csum_partial);
17544 EXPORT_SYMBOL(empty_zero_page);
17545 +
17546 +#ifdef CONFIG_PAX_KERNEXEC
17547 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17548 +#endif
17549 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17550 index df89102..a244320 100644
17551 --- a/arch/x86/kernel/i8259.c
17552 +++ b/arch/x86/kernel/i8259.c
17553 @@ -208,7 +208,7 @@ spurious_8259A_irq:
17554 "spurious 8259A interrupt: IRQ%d.\n", irq);
17555 spurious_irq_mask |= irqmask;
17556 }
17557 - atomic_inc(&irq_err_count);
17558 + atomic_inc_unchecked(&irq_err_count);
17559 /*
17560 * Theoretically we do not have to handle this IRQ,
17561 * but in Linux this does not cause problems and is
17562 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17563 index 3a54dcb..1c22348 100644
17564 --- a/arch/x86/kernel/init_task.c
17565 +++ b/arch/x86/kernel/init_task.c
17566 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17567 * way process stacks are handled. This is done by having a special
17568 * "init_task" linker map entry..
17569 */
17570 -union thread_union init_thread_union __init_task_data =
17571 - { INIT_THREAD_INFO(init_task) };
17572 +union thread_union init_thread_union __init_task_data;
17573
17574 /*
17575 * Initial task structure.
17576 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17577 * section. Since TSS's are completely CPU-local, we want them
17578 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17579 */
17580 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17581 -
17582 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17583 +EXPORT_SYMBOL(init_tss);
17584 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17585 index 99c4d30..74c84e9 100644
17586 --- a/arch/x86/kernel/ioport.c
17587 +++ b/arch/x86/kernel/ioport.c
17588 @@ -6,6 +6,7 @@
17589 #include <linux/sched.h>
17590 #include <linux/kernel.h>
17591 #include <linux/capability.h>
17592 +#include <linux/security.h>
17593 #include <linux/errno.h>
17594 #include <linux/types.h>
17595 #include <linux/ioport.h>
17596 @@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17597
17598 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17599 return -EINVAL;
17600 +#ifdef CONFIG_GRKERNSEC_IO
17601 + if (turn_on && grsec_disable_privio) {
17602 + gr_handle_ioperm();
17603 + return -EPERM;
17604 + }
17605 +#endif
17606 if (turn_on && !capable(CAP_SYS_RAWIO))
17607 return -EPERM;
17608
17609 @@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17610 * because the ->io_bitmap_max value must match the bitmap
17611 * contents:
17612 */
17613 - tss = &per_cpu(init_tss, get_cpu());
17614 + tss = init_tss + get_cpu();
17615
17616 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
17617
17618 @@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, struct pt_regs *regs)
17619 return -EINVAL;
17620 /* Trying to gain more privileges? */
17621 if (level > old) {
17622 +#ifdef CONFIG_GRKERNSEC_IO
17623 + if (grsec_disable_privio) {
17624 + gr_handle_iopl();
17625 + return -EPERM;
17626 + }
17627 +#endif
17628 if (!capable(CAP_SYS_RAWIO))
17629 return -EPERM;
17630 }
17631 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17632 index 04bbd52..83a07d9 100644
17633 --- a/arch/x86/kernel/irq.c
17634 +++ b/arch/x86/kernel/irq.c
17635 @@ -15,7 +15,7 @@
17636 #include <asm/mce.h>
17637 #include <asm/hw_irq.h>
17638
17639 -atomic_t irq_err_count;
17640 +atomic_unchecked_t irq_err_count;
17641
17642 /* Function pointer for generic interrupt vector handling */
17643 void (*generic_interrupt_extension)(void) = NULL;
17644 @@ -114,9 +114,9 @@ static int show_other_interrupts(struct seq_file *p, int prec)
17645 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17646 seq_printf(p, " Machine check polls\n");
17647 #endif
17648 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17649 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17650 #if defined(CONFIG_X86_IO_APIC)
17651 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17652 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17653 #endif
17654 return 0;
17655 }
17656 @@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17657
17658 u64 arch_irq_stat(void)
17659 {
17660 - u64 sum = atomic_read(&irq_err_count);
17661 + u64 sum = atomic_read_unchecked(&irq_err_count);
17662
17663 #ifdef CONFIG_X86_IO_APIC
17664 - sum += atomic_read(&irq_mis_count);
17665 + sum += atomic_read_unchecked(&irq_mis_count);
17666 #endif
17667 return sum;
17668 }
17669 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17670 index 7d35d0f..03f1d52 100644
17671 --- a/arch/x86/kernel/irq_32.c
17672 +++ b/arch/x86/kernel/irq_32.c
17673 @@ -35,7 +35,7 @@ static int check_stack_overflow(void)
17674 __asm__ __volatile__("andl %%esp,%0" :
17675 "=r" (sp) : "0" (THREAD_SIZE - 1));
17676
17677 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17678 + return sp < STACK_WARN;
17679 }
17680
17681 static void print_stack_overflow(void)
17682 @@ -54,9 +54,9 @@ static inline void print_stack_overflow(void) { }
17683 * per-CPU IRQ handling contexts (thread information and stack)
17684 */
17685 union irq_ctx {
17686 - struct thread_info tinfo;
17687 - u32 stack[THREAD_SIZE/sizeof(u32)];
17688 -} __attribute__((aligned(PAGE_SIZE)));
17689 + unsigned long previous_esp;
17690 + u32 stack[THREAD_SIZE/sizeof(u32)];
17691 +} __attribute__((aligned(THREAD_SIZE)));
17692
17693 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17694 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
17695 @@ -78,10 +78,9 @@ static void call_on_stack(void *func, void *stack)
17696 static inline int
17697 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17698 {
17699 - union irq_ctx *curctx, *irqctx;
17700 + union irq_ctx *irqctx;
17701 u32 *isp, arg1, arg2;
17702
17703 - curctx = (union irq_ctx *) current_thread_info();
17704 irqctx = __get_cpu_var(hardirq_ctx);
17705
17706 /*
17707 @@ -90,21 +89,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17708 * handler) we can't do that and just have to keep using the
17709 * current stack (which is the irq stack already after all)
17710 */
17711 - if (unlikely(curctx == irqctx))
17712 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17713 return 0;
17714
17715 /* build the stack frame on the IRQ stack */
17716 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17717 - irqctx->tinfo.task = curctx->tinfo.task;
17718 - irqctx->tinfo.previous_esp = current_stack_pointer;
17719 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17720 + irqctx->previous_esp = current_stack_pointer;
17721
17722 - /*
17723 - * Copy the softirq bits in preempt_count so that the
17724 - * softirq checks work in the hardirq context.
17725 - */
17726 - irqctx->tinfo.preempt_count =
17727 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17728 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17729 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17730 + __set_fs(MAKE_MM_SEG(0));
17731 +#endif
17732
17733 if (unlikely(overflow))
17734 call_on_stack(print_stack_overflow, isp);
17735 @@ -116,6 +110,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17736 : "0" (irq), "1" (desc), "2" (isp),
17737 "D" (desc->handle_irq)
17738 : "memory", "cc", "ecx");
17739 +
17740 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17741 + __set_fs(current_thread_info()->addr_limit);
17742 +#endif
17743 +
17744 return 1;
17745 }
17746
17747 @@ -124,28 +123,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17748 */
17749 void __cpuinit irq_ctx_init(int cpu)
17750 {
17751 - union irq_ctx *irqctx;
17752 -
17753 if (per_cpu(hardirq_ctx, cpu))
17754 return;
17755
17756 - irqctx = &per_cpu(hardirq_stack, cpu);
17757 - irqctx->tinfo.task = NULL;
17758 - irqctx->tinfo.exec_domain = NULL;
17759 - irqctx->tinfo.cpu = cpu;
17760 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17761 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17762 -
17763 - per_cpu(hardirq_ctx, cpu) = irqctx;
17764 -
17765 - irqctx = &per_cpu(softirq_stack, cpu);
17766 - irqctx->tinfo.task = NULL;
17767 - irqctx->tinfo.exec_domain = NULL;
17768 - irqctx->tinfo.cpu = cpu;
17769 - irqctx->tinfo.preempt_count = 0;
17770 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17771 -
17772 - per_cpu(softirq_ctx, cpu) = irqctx;
17773 + per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
17774 + per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
17775
17776 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17777 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17778 @@ -159,7 +141,6 @@ void irq_ctx_exit(int cpu)
17779 asmlinkage void do_softirq(void)
17780 {
17781 unsigned long flags;
17782 - struct thread_info *curctx;
17783 union irq_ctx *irqctx;
17784 u32 *isp;
17785
17786 @@ -169,15 +150,22 @@ asmlinkage void do_softirq(void)
17787 local_irq_save(flags);
17788
17789 if (local_softirq_pending()) {
17790 - curctx = current_thread_info();
17791 irqctx = __get_cpu_var(softirq_ctx);
17792 - irqctx->tinfo.task = curctx->task;
17793 - irqctx->tinfo.previous_esp = current_stack_pointer;
17794 + irqctx->previous_esp = current_stack_pointer;
17795
17796 /* build the stack frame on the softirq stack */
17797 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17798 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17799 +
17800 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17801 + __set_fs(MAKE_MM_SEG(0));
17802 +#endif
17803
17804 call_on_stack(__do_softirq, isp);
17805 +
17806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17807 + __set_fs(current_thread_info()->addr_limit);
17808 +#endif
17809 +
17810 /*
17811 * Shouldnt happen, we returned above if in_interrupt():
17812 */
17813 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17814 index 8d82a77..0baf312 100644
17815 --- a/arch/x86/kernel/kgdb.c
17816 +++ b/arch/x86/kernel/kgdb.c
17817 @@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17818
17819 /* clear the trace bit */
17820 linux_regs->flags &= ~X86_EFLAGS_TF;
17821 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17822 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17823
17824 /* set the trace bit if we're stepping */
17825 if (remcomInBuffer[0] == 's') {
17826 linux_regs->flags |= X86_EFLAGS_TF;
17827 kgdb_single_step = 1;
17828 - atomic_set(&kgdb_cpu_doing_single_step,
17829 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17830 raw_smp_processor_id());
17831 }
17832
17833 @@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17834 break;
17835
17836 case DIE_DEBUG:
17837 - if (atomic_read(&kgdb_cpu_doing_single_step) ==
17838 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
17839 raw_smp_processor_id()) {
17840 if (user_mode(regs))
17841 return single_step_cont(regs, args);
17842 @@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
17843 return instruction_pointer(regs);
17844 }
17845
17846 -struct kgdb_arch arch_kgdb_ops = {
17847 +const struct kgdb_arch arch_kgdb_ops = {
17848 /* Breakpoint instruction: */
17849 .gdb_bpt_instr = { 0xcc },
17850 .flags = KGDB_HW_BREAKPOINT,
17851 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17852 index 7a67820..8d15b75 100644
17853 --- a/arch/x86/kernel/kprobes.c
17854 +++ b/arch/x86/kernel/kprobes.c
17855 @@ -168,9 +168,13 @@ static void __kprobes set_jmp_op(void *from, void *to)
17856 char op;
17857 s32 raddr;
17858 } __attribute__((packed)) * jop;
17859 - jop = (struct __arch_jmp_op *)from;
17860 +
17861 + jop = (struct __arch_jmp_op *)(ktla_ktva(from));
17862 +
17863 + pax_open_kernel();
17864 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
17865 jop->op = RELATIVEJUMP_INSTRUCTION;
17866 + pax_close_kernel();
17867 }
17868
17869 /*
17870 @@ -195,7 +199,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17871 kprobe_opcode_t opcode;
17872 kprobe_opcode_t *orig_opcodes = opcodes;
17873
17874 - if (search_exception_tables((unsigned long)opcodes))
17875 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17876 return 0; /* Page fault may occur on this address. */
17877
17878 retry:
17879 @@ -339,7 +343,9 @@ static void __kprobes fix_riprel(struct kprobe *p)
17880 disp = (u8 *) p->addr + *((s32 *) insn) -
17881 (u8 *) p->ainsn.insn;
17882 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
17883 + pax_open_kernel();
17884 *(s32 *)insn = (s32) disp;
17885 + pax_close_kernel();
17886 }
17887 }
17888 #endif
17889 @@ -347,16 +353,18 @@ static void __kprobes fix_riprel(struct kprobe *p)
17890
17891 static void __kprobes arch_copy_kprobe(struct kprobe *p)
17892 {
17893 - memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
17894 + pax_open_kernel();
17895 + memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
17896 + pax_close_kernel();
17897
17898 fix_riprel(p);
17899
17900 - if (can_boost(p->addr))
17901 + if (can_boost(ktla_ktva(p->addr)))
17902 p->ainsn.boostable = 0;
17903 else
17904 p->ainsn.boostable = -1;
17905
17906 - p->opcode = *p->addr;
17907 + p->opcode = *(ktla_ktva(p->addr));
17908 }
17909
17910 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17911 @@ -434,7 +442,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
17912 if (p->opcode == BREAKPOINT_INSTRUCTION)
17913 regs->ip = (unsigned long)p->addr;
17914 else
17915 - regs->ip = (unsigned long)p->ainsn.insn;
17916 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17917 }
17918
17919 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
17920 @@ -455,7 +463,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17921 if (p->ainsn.boostable == 1 && !p->post_handler) {
17922 /* Boost up -- we can execute copied instructions directly */
17923 reset_current_kprobe();
17924 - regs->ip = (unsigned long)p->ainsn.insn;
17925 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17926 preempt_enable_no_resched();
17927 return;
17928 }
17929 @@ -525,7 +533,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17930 struct kprobe_ctlblk *kcb;
17931
17932 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
17933 - if (*addr != BREAKPOINT_INSTRUCTION) {
17934 + if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17935 /*
17936 * The breakpoint instruction was removed right
17937 * after we hit it. Another cpu has removed
17938 @@ -637,6 +645,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17939 /* Skip orig_ax, ip, cs */
17940 " addq $24, %rsp\n"
17941 " popfq\n"
17942 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
17943 + " btsq $63,(%rsp)\n"
17944 +#endif
17945 #else
17946 " pushf\n"
17947 /*
17948 @@ -777,7 +788,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17949 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17950 {
17951 unsigned long *tos = stack_addr(regs);
17952 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17953 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17954 unsigned long orig_ip = (unsigned long)p->addr;
17955 kprobe_opcode_t *insn = p->ainsn.insn;
17956
17957 @@ -960,7 +971,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17958 struct die_args *args = data;
17959 int ret = NOTIFY_DONE;
17960
17961 - if (args->regs && user_mode_vm(args->regs))
17962 + if (args->regs && user_mode(args->regs))
17963 return ret;
17964
17965 switch (val) {
17966 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17967 index 63b0ec8..6d92227 100644
17968 --- a/arch/x86/kernel/kvm.c
17969 +++ b/arch/x86/kernel/kvm.c
17970 @@ -216,6 +216,7 @@ static void __init paravirt_ops_setup(void)
17971 pv_mmu_ops.set_pud = kvm_set_pud;
17972 #if PAGETABLE_LEVELS == 4
17973 pv_mmu_ops.set_pgd = kvm_set_pgd;
17974 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
17975 #endif
17976 #endif
17977 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
17978 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17979 index ec6ef60..ab2c824 100644
17980 --- a/arch/x86/kernel/ldt.c
17981 +++ b/arch/x86/kernel/ldt.c
17982 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17983 if (reload) {
17984 #ifdef CONFIG_SMP
17985 preempt_disable();
17986 - load_LDT(pc);
17987 + load_LDT_nolock(pc);
17988 if (!cpumask_equal(mm_cpumask(current->mm),
17989 cpumask_of(smp_processor_id())))
17990 smp_call_function(flush_ldt, current->mm, 1);
17991 preempt_enable();
17992 #else
17993 - load_LDT(pc);
17994 + load_LDT_nolock(pc);
17995 #endif
17996 }
17997 if (oldsize) {
17998 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17999 return err;
18000
18001 for (i = 0; i < old->size; i++)
18002 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18003 + write_ldt_entry(new->ldt, i, old->ldt + i);
18004 return 0;
18005 }
18006
18007 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18008 retval = copy_ldt(&mm->context, &old_mm->context);
18009 mutex_unlock(&old_mm->context.lock);
18010 }
18011 +
18012 + if (tsk == current) {
18013 + mm->context.vdso = 0;
18014 +
18015 +#ifdef CONFIG_X86_32
18016 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18017 + mm->context.user_cs_base = 0UL;
18018 + mm->context.user_cs_limit = ~0UL;
18019 +
18020 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18021 + cpus_clear(mm->context.cpu_user_cs_mask);
18022 +#endif
18023 +
18024 +#endif
18025 +#endif
18026 +
18027 + }
18028 +
18029 return retval;
18030 }
18031
18032 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18033 }
18034 }
18035
18036 +#ifdef CONFIG_PAX_SEGMEXEC
18037 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18038 + error = -EINVAL;
18039 + goto out_unlock;
18040 + }
18041 +#endif
18042 +
18043 fill_ldt(&ldt, &ldt_info);
18044 if (oldmode)
18045 ldt.avl = 0;
18046 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18047 index c1c429d..f02eaf9 100644
18048 --- a/arch/x86/kernel/machine_kexec_32.c
18049 +++ b/arch/x86/kernel/machine_kexec_32.c
18050 @@ -26,7 +26,7 @@
18051 #include <asm/system.h>
18052 #include <asm/cacheflush.h>
18053
18054 -static void set_idt(void *newidt, __u16 limit)
18055 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18056 {
18057 struct desc_ptr curidt;
18058
18059 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18060 }
18061
18062
18063 -static void set_gdt(void *newgdt, __u16 limit)
18064 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18065 {
18066 struct desc_ptr curgdt;
18067
18068 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
18069 }
18070
18071 control_page = page_address(image->control_code_page);
18072 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18073 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18074
18075 relocate_kernel_ptr = control_page;
18076 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18077 diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
18078 index 1e47679..e73449d 100644
18079 --- a/arch/x86/kernel/microcode_amd.c
18080 +++ b/arch/x86/kernel/microcode_amd.c
18081 @@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int cpu)
18082 uci->mc = NULL;
18083 }
18084
18085 -static struct microcode_ops microcode_amd_ops = {
18086 +static const struct microcode_ops microcode_amd_ops = {
18087 .request_microcode_user = request_microcode_user,
18088 .request_microcode_fw = request_microcode_fw,
18089 .collect_cpu_info = collect_cpu_info_amd,
18090 @@ -372,7 +372,7 @@ static struct microcode_ops microcode_amd_ops = {
18091 .microcode_fini_cpu = microcode_fini_cpu_amd,
18092 };
18093
18094 -struct microcode_ops * __init init_amd_microcode(void)
18095 +const struct microcode_ops * __init init_amd_microcode(void)
18096 {
18097 return &microcode_amd_ops;
18098 }
18099 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
18100 index 378e9a8..b5a6ea9 100644
18101 --- a/arch/x86/kernel/microcode_core.c
18102 +++ b/arch/x86/kernel/microcode_core.c
18103 @@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
18104
18105 #define MICROCODE_VERSION "2.00"
18106
18107 -static struct microcode_ops *microcode_ops;
18108 +static const struct microcode_ops *microcode_ops;
18109
18110 /*
18111 * Synchronization.
18112 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18113 index 0d334dd..14cedaf 100644
18114 --- a/arch/x86/kernel/microcode_intel.c
18115 +++ b/arch/x86/kernel/microcode_intel.c
18116 @@ -443,13 +443,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18117
18118 static int get_ucode_user(void *to, const void *from, size_t n)
18119 {
18120 - return copy_from_user(to, from, n);
18121 + return copy_from_user(to, (const void __force_user *)from, n);
18122 }
18123
18124 static enum ucode_state
18125 request_microcode_user(int cpu, const void __user *buf, size_t size)
18126 {
18127 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18128 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18129 }
18130
18131 static void microcode_fini_cpu(int cpu)
18132 @@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
18133 uci->mc = NULL;
18134 }
18135
18136 -static struct microcode_ops microcode_intel_ops = {
18137 +static const struct microcode_ops microcode_intel_ops = {
18138 .request_microcode_user = request_microcode_user,
18139 .request_microcode_fw = request_microcode_fw,
18140 .collect_cpu_info = collect_cpu_info,
18141 @@ -468,7 +468,7 @@ static struct microcode_ops microcode_intel_ops = {
18142 .microcode_fini_cpu = microcode_fini_cpu,
18143 };
18144
18145 -struct microcode_ops * __init init_intel_microcode(void)
18146 +const struct microcode_ops * __init init_intel_microcode(void)
18147 {
18148 return &microcode_intel_ops;
18149 }
18150 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18151 index 89f386f..9028f51 100644
18152 --- a/arch/x86/kernel/module.c
18153 +++ b/arch/x86/kernel/module.c
18154 @@ -34,7 +34,7 @@
18155 #define DEBUGP(fmt...)
18156 #endif
18157
18158 -void *module_alloc(unsigned long size)
18159 +static void *__module_alloc(unsigned long size, pgprot_t prot)
18160 {
18161 struct vm_struct *area;
18162
18163 @@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
18164 if (!area)
18165 return NULL;
18166
18167 - return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
18168 - PAGE_KERNEL_EXEC);
18169 + return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
18170 +}
18171 +
18172 +void *module_alloc(unsigned long size)
18173 +{
18174 +
18175 +#ifdef CONFIG_PAX_KERNEXEC
18176 + return __module_alloc(size, PAGE_KERNEL);
18177 +#else
18178 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18179 +#endif
18180 +
18181 }
18182
18183 /* Free memory returned from module_alloc */
18184 @@ -58,6 +68,40 @@ void module_free(struct module *mod, void *module_region)
18185 vfree(module_region);
18186 }
18187
18188 +#ifdef CONFIG_PAX_KERNEXEC
18189 +#ifdef CONFIG_X86_32
18190 +void *module_alloc_exec(unsigned long size)
18191 +{
18192 + struct vm_struct *area;
18193 +
18194 + if (size == 0)
18195 + return NULL;
18196 +
18197 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18198 + return area ? area->addr : NULL;
18199 +}
18200 +EXPORT_SYMBOL(module_alloc_exec);
18201 +
18202 +void module_free_exec(struct module *mod, void *module_region)
18203 +{
18204 + vunmap(module_region);
18205 +}
18206 +EXPORT_SYMBOL(module_free_exec);
18207 +#else
18208 +void module_free_exec(struct module *mod, void *module_region)
18209 +{
18210 + module_free(mod, module_region);
18211 +}
18212 +EXPORT_SYMBOL(module_free_exec);
18213 +
18214 +void *module_alloc_exec(unsigned long size)
18215 +{
18216 + return __module_alloc(size, PAGE_KERNEL_RX);
18217 +}
18218 +EXPORT_SYMBOL(module_alloc_exec);
18219 +#endif
18220 +#endif
18221 +
18222 /* We don't need anything special. */
18223 int module_frob_arch_sections(Elf_Ehdr *hdr,
18224 Elf_Shdr *sechdrs,
18225 @@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18226 unsigned int i;
18227 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18228 Elf32_Sym *sym;
18229 - uint32_t *location;
18230 + uint32_t *plocation, location;
18231
18232 DEBUGP("Applying relocate section %u to %u\n", relsec,
18233 sechdrs[relsec].sh_info);
18234 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18235 /* This is where to make the change */
18236 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18237 - + rel[i].r_offset;
18238 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18239 + location = (uint32_t)plocation;
18240 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18241 + plocation = ktla_ktva((void *)plocation);
18242 /* This is the symbol it is referring to. Note that all
18243 undefined symbols have been resolved. */
18244 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18245 @@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18246 switch (ELF32_R_TYPE(rel[i].r_info)) {
18247 case R_386_32:
18248 /* We add the value into the location given */
18249 - *location += sym->st_value;
18250 + pax_open_kernel();
18251 + *plocation += sym->st_value;
18252 + pax_close_kernel();
18253 break;
18254 case R_386_PC32:
18255 /* Add the value, subtract its postition */
18256 - *location += sym->st_value - (uint32_t)location;
18257 + pax_open_kernel();
18258 + *plocation += sym->st_value - location;
18259 + pax_close_kernel();
18260 break;
18261 default:
18262 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18263 @@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18264 case R_X86_64_NONE:
18265 break;
18266 case R_X86_64_64:
18267 + pax_open_kernel();
18268 *(u64 *)loc = val;
18269 + pax_close_kernel();
18270 break;
18271 case R_X86_64_32:
18272 + pax_open_kernel();
18273 *(u32 *)loc = val;
18274 + pax_close_kernel();
18275 if (val != *(u32 *)loc)
18276 goto overflow;
18277 break;
18278 case R_X86_64_32S:
18279 + pax_open_kernel();
18280 *(s32 *)loc = val;
18281 + pax_close_kernel();
18282 if ((s64)val != *(s32 *)loc)
18283 goto overflow;
18284 break;
18285 case R_X86_64_PC32:
18286 val -= (u64)loc;
18287 + pax_open_kernel();
18288 *(u32 *)loc = val;
18289 + pax_close_kernel();
18290 +
18291 #if 0
18292 if ((s64)val != *(s32 *)loc)
18293 goto overflow;
18294 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18295 index 3a7c5a4..9191528 100644
18296 --- a/arch/x86/kernel/paravirt-spinlocks.c
18297 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18298 @@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
18299 __raw_spin_lock(lock);
18300 }
18301
18302 -struct pv_lock_ops pv_lock_ops = {
18303 +struct pv_lock_ops pv_lock_ops __read_only = {
18304 #ifdef CONFIG_SMP
18305 .spin_is_locked = __ticket_spin_is_locked,
18306 .spin_is_contended = __ticket_spin_is_contended,
18307 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18308 index 1b1739d..dea6077 100644
18309 --- a/arch/x86/kernel/paravirt.c
18310 +++ b/arch/x86/kernel/paravirt.c
18311 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18312 {
18313 return x;
18314 }
18315 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18316 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18317 +#endif
18318
18319 void __init default_banner(void)
18320 {
18321 @@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
18322 * corresponding structure. */
18323 static void *get_call_destination(u8 type)
18324 {
18325 - struct paravirt_patch_template tmpl = {
18326 + const struct paravirt_patch_template tmpl = {
18327 .pv_init_ops = pv_init_ops,
18328 .pv_time_ops = pv_time_ops,
18329 .pv_cpu_ops = pv_cpu_ops,
18330 @@ -133,6 +136,8 @@ static void *get_call_destination(u8 type)
18331 .pv_lock_ops = pv_lock_ops,
18332 #endif
18333 };
18334 +
18335 + pax_track_stack();
18336 return *((void **)&tmpl + type);
18337 }
18338
18339 @@ -145,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18340 if (opfunc == NULL)
18341 /* If there's no function, patch it with a ud2a (BUG) */
18342 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18343 - else if (opfunc == _paravirt_nop)
18344 + else if (opfunc == (void *)_paravirt_nop)
18345 /* If the operation is a nop, then nop the callsite */
18346 ret = paravirt_patch_nop();
18347
18348 /* identity functions just return their single argument */
18349 - else if (opfunc == _paravirt_ident_32)
18350 + else if (opfunc == (void *)_paravirt_ident_32)
18351 ret = paravirt_patch_ident_32(insnbuf, len);
18352 - else if (opfunc == _paravirt_ident_64)
18353 + else if (opfunc == (void *)_paravirt_ident_64)
18354 ret = paravirt_patch_ident_64(insnbuf, len);
18355 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18356 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18357 + ret = paravirt_patch_ident_64(insnbuf, len);
18358 +#endif
18359
18360 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18361 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18362 @@ -178,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18363 if (insn_len > len || start == NULL)
18364 insn_len = len;
18365 else
18366 - memcpy(insnbuf, start, insn_len);
18367 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18368
18369 return insn_len;
18370 }
18371 @@ -294,22 +303,22 @@ void arch_flush_lazy_mmu_mode(void)
18372 preempt_enable();
18373 }
18374
18375 -struct pv_info pv_info = {
18376 +struct pv_info pv_info __read_only = {
18377 .name = "bare hardware",
18378 .paravirt_enabled = 0,
18379 .kernel_rpl = 0,
18380 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
18381 };
18382
18383 -struct pv_init_ops pv_init_ops = {
18384 +struct pv_init_ops pv_init_ops __read_only = {
18385 .patch = native_patch,
18386 };
18387
18388 -struct pv_time_ops pv_time_ops = {
18389 +struct pv_time_ops pv_time_ops __read_only = {
18390 .sched_clock = native_sched_clock,
18391 };
18392
18393 -struct pv_irq_ops pv_irq_ops = {
18394 +struct pv_irq_ops pv_irq_ops __read_only = {
18395 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18396 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18397 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18398 @@ -321,7 +330,7 @@ struct pv_irq_ops pv_irq_ops = {
18399 #endif
18400 };
18401
18402 -struct pv_cpu_ops pv_cpu_ops = {
18403 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18404 .cpuid = native_cpuid,
18405 .get_debugreg = native_get_debugreg,
18406 .set_debugreg = native_set_debugreg,
18407 @@ -382,21 +391,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18408 .end_context_switch = paravirt_nop,
18409 };
18410
18411 -struct pv_apic_ops pv_apic_ops = {
18412 +struct pv_apic_ops pv_apic_ops __read_only = {
18413 #ifdef CONFIG_X86_LOCAL_APIC
18414 .startup_ipi_hook = paravirt_nop,
18415 #endif
18416 };
18417
18418 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18419 +#ifdef CONFIG_X86_32
18420 +#ifdef CONFIG_X86_PAE
18421 +/* 64-bit pagetable entries */
18422 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18423 +#else
18424 /* 32-bit pagetable entries */
18425 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18426 +#endif
18427 #else
18428 /* 64-bit pagetable entries */
18429 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18430 #endif
18431
18432 -struct pv_mmu_ops pv_mmu_ops = {
18433 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18434
18435 .read_cr2 = native_read_cr2,
18436 .write_cr2 = native_write_cr2,
18437 @@ -448,6 +462,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18438 .make_pud = PTE_IDENT,
18439
18440 .set_pgd = native_set_pgd,
18441 + .set_pgd_batched = native_set_pgd_batched,
18442 #endif
18443 #endif /* PAGETABLE_LEVELS >= 3 */
18444
18445 @@ -467,6 +482,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18446 },
18447
18448 .set_fixmap = native_set_fixmap,
18449 +
18450 +#ifdef CONFIG_PAX_KERNEXEC
18451 + .pax_open_kernel = native_pax_open_kernel,
18452 + .pax_close_kernel = native_pax_close_kernel,
18453 +#endif
18454 +
18455 };
18456
18457 EXPORT_SYMBOL_GPL(pv_time_ops);
18458 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
18459 index 1a2d4b1..6a0dd55 100644
18460 --- a/arch/x86/kernel/pci-calgary_64.c
18461 +++ b/arch/x86/kernel/pci-calgary_64.c
18462 @@ -477,7 +477,7 @@ static void calgary_free_coherent(struct device *dev, size_t size,
18463 free_pages((unsigned long)vaddr, get_order(size));
18464 }
18465
18466 -static struct dma_map_ops calgary_dma_ops = {
18467 +static const struct dma_map_ops calgary_dma_ops = {
18468 .alloc_coherent = calgary_alloc_coherent,
18469 .free_coherent = calgary_free_coherent,
18470 .map_sg = calgary_map_sg,
18471 diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
18472 index 6ac3931..42b4414 100644
18473 --- a/arch/x86/kernel/pci-dma.c
18474 +++ b/arch/x86/kernel/pci-dma.c
18475 @@ -14,7 +14,7 @@
18476
18477 static int forbid_dac __read_mostly;
18478
18479 -struct dma_map_ops *dma_ops;
18480 +const struct dma_map_ops *dma_ops;
18481 EXPORT_SYMBOL(dma_ops);
18482
18483 static int iommu_sac_force __read_mostly;
18484 @@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
18485
18486 int dma_supported(struct device *dev, u64 mask)
18487 {
18488 - struct dma_map_ops *ops = get_dma_ops(dev);
18489 + const struct dma_map_ops *ops = get_dma_ops(dev);
18490
18491 #ifdef CONFIG_PCI
18492 if (mask > 0xffffffff && forbid_dac > 0) {
18493 diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
18494 index 1c76691..e3632db 100644
18495 --- a/arch/x86/kernel/pci-gart_64.c
18496 +++ b/arch/x86/kernel/pci-gart_64.c
18497 @@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
18498 return -1;
18499 }
18500
18501 -static struct dma_map_ops gart_dma_ops = {
18502 +static const struct dma_map_ops gart_dma_ops = {
18503 .map_sg = gart_map_sg,
18504 .unmap_sg = gart_unmap_sg,
18505 .map_page = gart_map_page,
18506 diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
18507 index a3933d4..c898869 100644
18508 --- a/arch/x86/kernel/pci-nommu.c
18509 +++ b/arch/x86/kernel/pci-nommu.c
18510 @@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(struct device *dev,
18511 flush_write_buffers();
18512 }
18513
18514 -struct dma_map_ops nommu_dma_ops = {
18515 +const struct dma_map_ops nommu_dma_ops = {
18516 .alloc_coherent = dma_generic_alloc_coherent,
18517 .free_coherent = nommu_free_coherent,
18518 .map_sg = nommu_map_sg,
18519 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
18520 index aaa6b78..4de1881 100644
18521 --- a/arch/x86/kernel/pci-swiotlb.c
18522 +++ b/arch/x86/kernel/pci-swiotlb.c
18523 @@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
18524 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
18525 }
18526
18527 -static struct dma_map_ops swiotlb_dma_ops = {
18528 +static const struct dma_map_ops swiotlb_dma_ops = {
18529 .mapping_error = swiotlb_dma_mapping_error,
18530 .alloc_coherent = x86_swiotlb_alloc_coherent,
18531 .free_coherent = swiotlb_free_coherent,
18532 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18533 index fc6c84d..0312ca2 100644
18534 --- a/arch/x86/kernel/process.c
18535 +++ b/arch/x86/kernel/process.c
18536 @@ -51,16 +51,33 @@ void free_thread_xstate(struct task_struct *tsk)
18537
18538 void free_thread_info(struct thread_info *ti)
18539 {
18540 - free_thread_xstate(ti->task);
18541 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
18542 }
18543
18544 +static struct kmem_cache *task_struct_cachep;
18545 +
18546 void arch_task_cache_init(void)
18547 {
18548 - task_xstate_cachep =
18549 - kmem_cache_create("task_xstate", xstate_size,
18550 + /* create a slab on which task_structs can be allocated */
18551 + task_struct_cachep =
18552 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18553 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18554 +
18555 + task_xstate_cachep =
18556 + kmem_cache_create("task_xstate", xstate_size,
18557 __alignof__(union thread_xstate),
18558 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18559 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18560 +}
18561 +
18562 +struct task_struct *alloc_task_struct(void)
18563 +{
18564 + return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
18565 +}
18566 +
18567 +void free_task_struct(struct task_struct *task)
18568 +{
18569 + free_thread_xstate(task);
18570 + kmem_cache_free(task_struct_cachep, task);
18571 }
18572
18573 /*
18574 @@ -73,7 +90,7 @@ void exit_thread(void)
18575 unsigned long *bp = t->io_bitmap_ptr;
18576
18577 if (bp) {
18578 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18579 + struct tss_struct *tss = init_tss + get_cpu();
18580
18581 t->io_bitmap_ptr = NULL;
18582 clear_thread_flag(TIF_IO_BITMAP);
18583 @@ -93,6 +110,9 @@ void flush_thread(void)
18584
18585 clear_tsk_thread_flag(tsk, TIF_DEBUG);
18586
18587 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18588 + loadsegment(gs, 0);
18589 +#endif
18590 tsk->thread.debugreg0 = 0;
18591 tsk->thread.debugreg1 = 0;
18592 tsk->thread.debugreg2 = 0;
18593 @@ -307,7 +327,7 @@ void default_idle(void)
18594 EXPORT_SYMBOL(default_idle);
18595 #endif
18596
18597 -void stop_this_cpu(void *dummy)
18598 +__noreturn void stop_this_cpu(void *dummy)
18599 {
18600 local_irq_disable();
18601 /*
18602 @@ -568,16 +588,38 @@ static int __init idle_setup(char *str)
18603 }
18604 early_param("idle", idle_setup);
18605
18606 -unsigned long arch_align_stack(unsigned long sp)
18607 +#ifdef CONFIG_PAX_RANDKSTACK
18608 +void pax_randomize_kstack(struct pt_regs *regs)
18609 {
18610 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18611 - sp -= get_random_int() % 8192;
18612 - return sp & ~0xf;
18613 -}
18614 + struct thread_struct *thread = &current->thread;
18615 + unsigned long time;
18616
18617 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18618 -{
18619 - unsigned long range_end = mm->brk + 0x02000000;
18620 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18621 + if (!randomize_va_space)
18622 + return;
18623 +
18624 + if (v8086_mode(regs))
18625 + return;
18626 +
18627 + rdtscl(time);
18628 +
18629 + /* P4 seems to return a 0 LSB, ignore it */
18630 +#ifdef CONFIG_MPENTIUM4
18631 + time &= 0x3EUL;
18632 + time <<= 2;
18633 +#elif defined(CONFIG_X86_64)
18634 + time &= 0xFUL;
18635 + time <<= 4;
18636 +#else
18637 + time &= 0x1FUL;
18638 + time <<= 3;
18639 +#endif
18640 +
18641 + thread->sp0 ^= time;
18642 + load_sp0(init_tss + smp_processor_id(), thread);
18643 +
18644 +#ifdef CONFIG_X86_64
18645 + percpu_write(kernel_stack, thread->sp0);
18646 +#endif
18647 }
18648 +#endif
18649
18650 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18651 index c40c432..6e1df72 100644
18652 --- a/arch/x86/kernel/process_32.c
18653 +++ b/arch/x86/kernel/process_32.c
18654 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18655 unsigned long thread_saved_pc(struct task_struct *tsk)
18656 {
18657 return ((unsigned long *)tsk->thread.sp)[3];
18658 +//XXX return tsk->thread.eip;
18659 }
18660
18661 #ifndef CONFIG_SMP
18662 @@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, int all)
18663 unsigned short ss, gs;
18664 const char *board;
18665
18666 - if (user_mode_vm(regs)) {
18667 + if (user_mode(regs)) {
18668 sp = regs->sp;
18669 ss = regs->ss & 0xffff;
18670 - gs = get_user_gs(regs);
18671 } else {
18672 sp = (unsigned long) (&regs->sp);
18673 savesegment(ss, ss);
18674 - savesegment(gs, gs);
18675 }
18676 + gs = get_user_gs(regs);
18677
18678 printk("\n");
18679
18680 @@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18681 regs.bx = (unsigned long) fn;
18682 regs.dx = (unsigned long) arg;
18683
18684 - regs.ds = __USER_DS;
18685 - regs.es = __USER_DS;
18686 + regs.ds = __KERNEL_DS;
18687 + regs.es = __KERNEL_DS;
18688 regs.fs = __KERNEL_PERCPU;
18689 - regs.gs = __KERNEL_STACK_CANARY;
18690 + savesegment(gs, regs.gs);
18691 regs.orig_ax = -1;
18692 regs.ip = (unsigned long) kernel_thread_helper;
18693 regs.cs = __KERNEL_CS | get_kernel_rpl();
18694 @@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18695 struct task_struct *tsk;
18696 int err;
18697
18698 - childregs = task_pt_regs(p);
18699 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18700 *childregs = *regs;
18701 childregs->ax = 0;
18702 childregs->sp = sp;
18703
18704 p->thread.sp = (unsigned long) childregs;
18705 p->thread.sp0 = (unsigned long) (childregs+1);
18706 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18707
18708 p->thread.ip = (unsigned long) ret_from_fork;
18709
18710 @@ -345,7 +346,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18711 struct thread_struct *prev = &prev_p->thread,
18712 *next = &next_p->thread;
18713 int cpu = smp_processor_id();
18714 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18715 + struct tss_struct *tss = init_tss + cpu;
18716 bool preload_fpu;
18717
18718 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18719 @@ -380,6 +381,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18720 */
18721 lazy_save_gs(prev->gs);
18722
18723 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18724 + __set_fs(task_thread_info(next_p)->addr_limit);
18725 +#endif
18726 +
18727 /*
18728 * Load the per-thread Thread-Local Storage descriptor.
18729 */
18730 @@ -415,6 +420,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18731 */
18732 arch_end_context_switch(next_p);
18733
18734 + percpu_write(current_task, next_p);
18735 + percpu_write(current_tinfo, &next_p->tinfo);
18736 +
18737 if (preload_fpu)
18738 __math_state_restore();
18739
18740 @@ -424,8 +432,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18741 if (prev->gs | next->gs)
18742 lazy_load_gs(next->gs);
18743
18744 - percpu_write(current_task, next_p);
18745 -
18746 return prev_p;
18747 }
18748
18749 @@ -495,4 +501,3 @@ unsigned long get_wchan(struct task_struct *p)
18750 } while (count++ < 16);
18751 return 0;
18752 }
18753 -
18754 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18755 index 39493bc..196816d 100644
18756 --- a/arch/x86/kernel/process_64.c
18757 +++ b/arch/x86/kernel/process_64.c
18758 @@ -91,7 +91,7 @@ static void __exit_idle(void)
18759 void exit_idle(void)
18760 {
18761 /* idle loop has pid 0 */
18762 - if (current->pid)
18763 + if (task_pid_nr(current))
18764 return;
18765 __exit_idle();
18766 }
18767 @@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, int all)
18768 if (!board)
18769 board = "";
18770 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
18771 - current->pid, current->comm, print_tainted(),
18772 + task_pid_nr(current), current->comm, print_tainted(),
18773 init_utsname()->release,
18774 (int)strcspn(init_utsname()->version, " "),
18775 init_utsname()->version, board);
18776 @@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18777 struct pt_regs *childregs;
18778 struct task_struct *me = current;
18779
18780 - childregs = ((struct pt_regs *)
18781 - (THREAD_SIZE + task_stack_page(p))) - 1;
18782 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18783 *childregs = *regs;
18784
18785 childregs->ax = 0;
18786 @@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18787 p->thread.sp = (unsigned long) childregs;
18788 p->thread.sp0 = (unsigned long) (childregs+1);
18789 p->thread.usersp = me->thread.usersp;
18790 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18791
18792 set_tsk_thread_flag(p, TIF_FORK);
18793
18794 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18795 struct thread_struct *prev = &prev_p->thread;
18796 struct thread_struct *next = &next_p->thread;
18797 int cpu = smp_processor_id();
18798 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18799 + struct tss_struct *tss = init_tss + cpu;
18800 unsigned fsindex, gsindex;
18801 bool preload_fpu;
18802
18803 @@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18804 prev->usersp = percpu_read(old_rsp);
18805 percpu_write(old_rsp, next->usersp);
18806 percpu_write(current_task, next_p);
18807 + percpu_write(current_tinfo, &next_p->tinfo);
18808
18809 - percpu_write(kernel_stack,
18810 - (unsigned long)task_stack_page(next_p) +
18811 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18812 + percpu_write(kernel_stack, next->sp0);
18813
18814 /*
18815 * Now maybe reload the debug registers and handle I/O bitmaps
18816 @@ -559,12 +558,11 @@ unsigned long get_wchan(struct task_struct *p)
18817 if (!p || p == current || p->state == TASK_RUNNING)
18818 return 0;
18819 stack = (unsigned long)task_stack_page(p);
18820 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18821 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18822 return 0;
18823 fp = *(u64 *)(p->thread.sp);
18824 do {
18825 - if (fp < (unsigned long)stack ||
18826 - fp >= (unsigned long)stack+THREAD_SIZE)
18827 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18828 return 0;
18829 ip = *(u64 *)(fp+8);
18830 if (!in_sched_functions(ip))
18831 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18832 index c06acdd..3f5fff5 100644
18833 --- a/arch/x86/kernel/ptrace.c
18834 +++ b/arch/x86/kernel/ptrace.c
18835 @@ -925,7 +925,7 @@ static const struct user_regset_view user_x86_32_view; /* Initialized below. */
18836 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18837 {
18838 int ret;
18839 - unsigned long __user *datap = (unsigned long __user *)data;
18840 + unsigned long __user *datap = (__force unsigned long __user *)data;
18841
18842 switch (request) {
18843 /* read the word at location addr in the USER area. */
18844 @@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18845 if (addr < 0)
18846 return -EIO;
18847 ret = do_get_thread_area(child, addr,
18848 - (struct user_desc __user *) data);
18849 + (__force struct user_desc __user *) data);
18850 break;
18851
18852 case PTRACE_SET_THREAD_AREA:
18853 if (addr < 0)
18854 return -EIO;
18855 ret = do_set_thread_area(child, addr,
18856 - (struct user_desc __user *) data, 0);
18857 + (__force struct user_desc __user *) data, 0);
18858 break;
18859 #endif
18860
18861 @@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18862 #ifdef CONFIG_X86_PTRACE_BTS
18863 case PTRACE_BTS_CONFIG:
18864 ret = ptrace_bts_config
18865 - (child, data, (struct ptrace_bts_config __user *)addr);
18866 + (child, data, (__force struct ptrace_bts_config __user *)addr);
18867 break;
18868
18869 case PTRACE_BTS_STATUS:
18870 ret = ptrace_bts_status
18871 - (child, data, (struct ptrace_bts_config __user *)addr);
18872 + (child, data, (__force struct ptrace_bts_config __user *)addr);
18873 break;
18874
18875 case PTRACE_BTS_SIZE:
18876 @@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18877
18878 case PTRACE_BTS_GET:
18879 ret = ptrace_bts_read_record
18880 - (child, data, (struct bts_struct __user *) addr);
18881 + (child, data, (__force struct bts_struct __user *) addr);
18882 break;
18883
18884 case PTRACE_BTS_CLEAR:
18885 @@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18886
18887 case PTRACE_BTS_DRAIN:
18888 ret = ptrace_bts_drain
18889 - (child, data, (struct bts_struct __user *) addr);
18890 + (child, data, (__force struct bts_struct __user *) addr);
18891 break;
18892 #endif /* CONFIG_X86_PTRACE_BTS */
18893
18894 @@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18895 info.si_code = si_code;
18896
18897 /* User-mode ip? */
18898 - info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
18899 + info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
18900
18901 /* Send us the fake SIGTRAP */
18902 force_sig_info(SIGTRAP, &info, tsk);
18903 @@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18904 * We must return the syscall number to actually look up in the table.
18905 * This can be -1L to skip running any syscall at all.
18906 */
18907 -asmregparm long syscall_trace_enter(struct pt_regs *regs)
18908 +long syscall_trace_enter(struct pt_regs *regs)
18909 {
18910 long ret = 0;
18911
18912 @@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
18913 return ret ?: regs->orig_ax;
18914 }
18915
18916 -asmregparm void syscall_trace_leave(struct pt_regs *regs)
18917 +void syscall_trace_leave(struct pt_regs *regs)
18918 {
18919 if (unlikely(current->audit_context))
18920 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
18921 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18922 index cf98100..e76e03d 100644
18923 --- a/arch/x86/kernel/reboot.c
18924 +++ b/arch/x86/kernel/reboot.c
18925 @@ -33,7 +33,7 @@ void (*pm_power_off)(void);
18926 EXPORT_SYMBOL(pm_power_off);
18927
18928 static const struct desc_ptr no_idt = {};
18929 -static int reboot_mode;
18930 +static unsigned short reboot_mode;
18931 enum reboot_type reboot_type = BOOT_KBD;
18932 int reboot_force;
18933
18934 @@ -292,12 +292,12 @@ core_initcall(reboot_init);
18935 controller to pulse the CPU reset line, which is more thorough, but
18936 doesn't work with at least one type of 486 motherboard. It is easy
18937 to stop this code working; hence the copious comments. */
18938 -static const unsigned long long
18939 -real_mode_gdt_entries [3] =
18940 +static struct desc_struct
18941 +real_mode_gdt_entries [3] __read_only =
18942 {
18943 - 0x0000000000000000ULL, /* Null descriptor */
18944 - 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
18945 - 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
18946 + GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
18947 + GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
18948 + GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
18949 };
18950
18951 static const struct desc_ptr
18952 @@ -346,7 +346,7 @@ static const unsigned char jump_to_bios [] =
18953 * specified by the code and length parameters.
18954 * We assume that length will aways be less that 100!
18955 */
18956 -void machine_real_restart(const unsigned char *code, int length)
18957 +__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
18958 {
18959 local_irq_disable();
18960
18961 @@ -366,8 +366,8 @@ void machine_real_restart(const unsigned char *code, int length)
18962 /* Remap the kernel at virtual address zero, as well as offset zero
18963 from the kernel segment. This assumes the kernel segment starts at
18964 virtual address PAGE_OFFSET. */
18965 - memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18966 - sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
18967 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18968 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
18969
18970 /*
18971 * Use `swapper_pg_dir' as our page directory.
18972 @@ -379,16 +379,15 @@ void machine_real_restart(const unsigned char *code, int length)
18973 boot)". This seems like a fairly standard thing that gets set by
18974 REBOOT.COM programs, and the previous reset routine did this
18975 too. */
18976 - *((unsigned short *)0x472) = reboot_mode;
18977 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18978
18979 /* For the switch to real mode, copy some code to low memory. It has
18980 to be in the first 64k because it is running in 16-bit mode, and it
18981 has to have the same physical and virtual address, because it turns
18982 off paging. Copy it near the end of the first page, out of the way
18983 of BIOS variables. */
18984 - memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
18985 - real_mode_switch, sizeof (real_mode_switch));
18986 - memcpy((void *)(0x1000 - 100), code, length);
18987 + memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
18988 + memcpy(__va(0x1000 - 100), code, length);
18989
18990 /* Set up the IDT for real mode. */
18991 load_idt(&real_mode_idt);
18992 @@ -416,6 +415,7 @@ void machine_real_restart(const unsigned char *code, int length)
18993 __asm__ __volatile__ ("ljmp $0x0008,%0"
18994 :
18995 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
18996 + do { } while (1);
18997 }
18998 #ifdef CONFIG_APM_MODULE
18999 EXPORT_SYMBOL(machine_real_restart);
19000 @@ -544,7 +544,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19001 {
19002 }
19003
19004 -static void native_machine_emergency_restart(void)
19005 +__noreturn static void native_machine_emergency_restart(void)
19006 {
19007 int i;
19008
19009 @@ -659,13 +659,13 @@ void native_machine_shutdown(void)
19010 #endif
19011 }
19012
19013 -static void __machine_emergency_restart(int emergency)
19014 +static __noreturn void __machine_emergency_restart(int emergency)
19015 {
19016 reboot_emergency = emergency;
19017 machine_ops.emergency_restart();
19018 }
19019
19020 -static void native_machine_restart(char *__unused)
19021 +static __noreturn void native_machine_restart(char *__unused)
19022 {
19023 printk("machine restart\n");
19024
19025 @@ -674,7 +674,7 @@ static void native_machine_restart(char *__unused)
19026 __machine_emergency_restart(0);
19027 }
19028
19029 -static void native_machine_halt(void)
19030 +static __noreturn void native_machine_halt(void)
19031 {
19032 /* stop other cpus and apics */
19033 machine_shutdown();
19034 @@ -685,7 +685,7 @@ static void native_machine_halt(void)
19035 stop_this_cpu(NULL);
19036 }
19037
19038 -static void native_machine_power_off(void)
19039 +__noreturn static void native_machine_power_off(void)
19040 {
19041 if (pm_power_off) {
19042 if (!reboot_force)
19043 @@ -694,6 +694,7 @@ static void native_machine_power_off(void)
19044 }
19045 /* a fallback in case there is no PM info available */
19046 tboot_shutdown(TB_SHUTDOWN_HALT);
19047 + do { } while (1);
19048 }
19049
19050 struct machine_ops machine_ops = {
19051 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19052 index 7a6f3b3..976a959 100644
19053 --- a/arch/x86/kernel/relocate_kernel_64.S
19054 +++ b/arch/x86/kernel/relocate_kernel_64.S
19055 @@ -11,6 +11,7 @@
19056 #include <asm/kexec.h>
19057 #include <asm/processor-flags.h>
19058 #include <asm/pgtable_types.h>
19059 +#include <asm/alternative-asm.h>
19060
19061 /*
19062 * Must be relocatable PIC code callable as a C function
19063 @@ -167,6 +168,7 @@ identity_mapped:
19064 xorq %r14, %r14
19065 xorq %r15, %r15
19066
19067 + pax_force_retaddr 0, 1
19068 ret
19069
19070 1:
19071 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19072 index 5449a26..0b6c759 100644
19073 --- a/arch/x86/kernel/setup.c
19074 +++ b/arch/x86/kernel/setup.c
19075 @@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
19076
19077 if (!boot_params.hdr.root_flags)
19078 root_mountflags &= ~MS_RDONLY;
19079 - init_mm.start_code = (unsigned long) _text;
19080 - init_mm.end_code = (unsigned long) _etext;
19081 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19082 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19083 init_mm.end_data = (unsigned long) _edata;
19084 init_mm.brk = _brk_end;
19085
19086 - code_resource.start = virt_to_phys(_text);
19087 - code_resource.end = virt_to_phys(_etext)-1;
19088 - data_resource.start = virt_to_phys(_etext);
19089 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19090 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19091 + data_resource.start = virt_to_phys(_sdata);
19092 data_resource.end = virt_to_phys(_edata)-1;
19093 bss_resource.start = virt_to_phys(&__bss_start);
19094 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19095 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19096 index d559af9..524c6ad 100644
19097 --- a/arch/x86/kernel/setup_percpu.c
19098 +++ b/arch/x86/kernel/setup_percpu.c
19099 @@ -25,19 +25,17 @@
19100 # define DBG(x...)
19101 #endif
19102
19103 -DEFINE_PER_CPU(int, cpu_number);
19104 +#ifdef CONFIG_SMP
19105 +DEFINE_PER_CPU(unsigned int, cpu_number);
19106 EXPORT_PER_CPU_SYMBOL(cpu_number);
19107 +#endif
19108
19109 -#ifdef CONFIG_X86_64
19110 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19111 -#else
19112 -#define BOOT_PERCPU_OFFSET 0
19113 -#endif
19114
19115 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19116 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19117
19118 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19119 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19120 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19121 };
19122 EXPORT_SYMBOL(__per_cpu_offset);
19123 @@ -159,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
19124 {
19125 #ifdef CONFIG_X86_32
19126 struct desc_struct gdt;
19127 + unsigned long base = per_cpu_offset(cpu);
19128
19129 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19130 - 0x2 | DESCTYPE_S, 0x8);
19131 - gdt.s = 1;
19132 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19133 + 0x83 | DESCTYPE_S, 0xC);
19134 write_gdt_entry(get_cpu_gdt_table(cpu),
19135 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19136 #endif
19137 @@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
19138 /* alrighty, percpu areas up and running */
19139 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19140 for_each_possible_cpu(cpu) {
19141 +#ifdef CONFIG_CC_STACKPROTECTOR
19142 +#ifdef CONFIG_X86_32
19143 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19144 +#endif
19145 +#endif
19146 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19147 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19148 per_cpu(cpu_number, cpu) = cpu;
19149 @@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
19150 early_per_cpu_map(x86_cpu_to_node_map, cpu);
19151 #endif
19152 #endif
19153 +#ifdef CONFIG_CC_STACKPROTECTOR
19154 +#ifdef CONFIG_X86_32
19155 + if (!cpu)
19156 + per_cpu(stack_canary.canary, cpu) = canary;
19157 +#endif
19158 +#endif
19159 /*
19160 * Up to this point, the boot CPU has been using .data.init
19161 * area. Reload any changed state for the boot CPU.
19162 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19163 index 6a44a76..a9287a1 100644
19164 --- a/arch/x86/kernel/signal.c
19165 +++ b/arch/x86/kernel/signal.c
19166 @@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsigned long sp)
19167 * Align the stack pointer according to the i386 ABI,
19168 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19169 */
19170 - sp = ((sp + 4) & -16ul) - 4;
19171 + sp = ((sp - 12) & -16ul) - 4;
19172 #else /* !CONFIG_X86_32 */
19173 sp = round_down(sp, 16) - 8;
19174 #endif
19175 @@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19176 * Return an always-bogus address instead so we will die with SIGSEGV.
19177 */
19178 if (onsigstack && !likely(on_sig_stack(sp)))
19179 - return (void __user *)-1L;
19180 + return (__force void __user *)-1L;
19181
19182 /* save i387 state */
19183 if (used_math() && save_i387_xstate(*fpstate) < 0)
19184 - return (void __user *)-1L;
19185 + return (__force void __user *)-1L;
19186
19187 return (void __user *)sp;
19188 }
19189 @@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19190 }
19191
19192 if (current->mm->context.vdso)
19193 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19194 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19195 else
19196 - restorer = &frame->retcode;
19197 + restorer = (void __user *)&frame->retcode;
19198 if (ka->sa.sa_flags & SA_RESTORER)
19199 restorer = ka->sa.sa_restorer;
19200
19201 @@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19202 * reasons and because gdb uses it as a signature to notice
19203 * signal handler stack frames.
19204 */
19205 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19206 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19207
19208 if (err)
19209 return -EFAULT;
19210 @@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19211 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19212
19213 /* Set up to return from userspace. */
19214 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19215 + if (current->mm->context.vdso)
19216 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19217 + else
19218 + restorer = (void __user *)&frame->retcode;
19219 if (ka->sa.sa_flags & SA_RESTORER)
19220 restorer = ka->sa.sa_restorer;
19221 put_user_ex(restorer, &frame->pretcode);
19222 @@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19223 * reasons and because gdb uses it as a signature to notice
19224 * signal handler stack frames.
19225 */
19226 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19227 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19228 } put_user_catch(err);
19229
19230 if (err)
19231 @@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *regs)
19232 int signr;
19233 sigset_t *oldset;
19234
19235 + pax_track_stack();
19236 +
19237 /*
19238 * We want the common case to go fast, which is why we may in certain
19239 * cases get here from kernel mode. Just return without doing anything
19240 @@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *regs)
19241 * X86_32: vm86 regs switched out by assembly code before reaching
19242 * here, so testing against kernel CS suffices.
19243 */
19244 - if (!user_mode(regs))
19245 + if (!user_mode_novm(regs))
19246 return;
19247
19248 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
19249 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19250 index 7e8e905..64d5c32 100644
19251 --- a/arch/x86/kernel/smpboot.c
19252 +++ b/arch/x86/kernel/smpboot.c
19253 @@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
19254 */
19255 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
19256
19257 -void cpu_hotplug_driver_lock()
19258 +void cpu_hotplug_driver_lock(void)
19259 {
19260 - mutex_lock(&x86_cpu_hotplug_driver_mutex);
19261 + mutex_lock(&x86_cpu_hotplug_driver_mutex);
19262 }
19263
19264 -void cpu_hotplug_driver_unlock()
19265 +void cpu_hotplug_driver_unlock(void)
19266 {
19267 - mutex_unlock(&x86_cpu_hotplug_driver_mutex);
19268 + mutex_unlock(&x86_cpu_hotplug_driver_mutex);
19269 }
19270
19271 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
19272 @@ -625,7 +625,7 @@ wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
19273 * target processor state.
19274 */
19275 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
19276 - (unsigned long)stack_start.sp);
19277 + stack_start);
19278
19279 /*
19280 * Run STARTUP IPI loop.
19281 @@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19282 set_idle_for_cpu(cpu, c_idle.idle);
19283 do_rest:
19284 per_cpu(current_task, cpu) = c_idle.idle;
19285 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19286 #ifdef CONFIG_X86_32
19287 /* Stack for startup_32 can be just as for start_secondary onwards */
19288 irq_ctx_init(cpu);
19289 @@ -750,13 +751,15 @@ do_rest:
19290 #else
19291 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19292 initial_gs = per_cpu_offset(cpu);
19293 - per_cpu(kernel_stack, cpu) =
19294 - (unsigned long)task_stack_page(c_idle.idle) -
19295 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19296 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19297 #endif
19298 +
19299 + pax_open_kernel();
19300 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19301 + pax_close_kernel();
19302 +
19303 initial_code = (unsigned long)start_secondary;
19304 - stack_start.sp = (void *) c_idle.idle->thread.sp;
19305 + stack_start = c_idle.idle->thread.sp;
19306
19307 /* start_ip had better be page-aligned! */
19308 start_ip = setup_trampoline();
19309 @@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19310
19311 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19312
19313 +#ifdef CONFIG_PAX_PER_CPU_PGD
19314 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19315 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19316 + KERNEL_PGD_PTRS);
19317 +#endif
19318 +
19319 err = do_boot_cpu(apicid, cpu);
19320
19321 if (err) {
19322 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19323 index 3149032..14f1053 100644
19324 --- a/arch/x86/kernel/step.c
19325 +++ b/arch/x86/kernel/step.c
19326 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19327 struct desc_struct *desc;
19328 unsigned long base;
19329
19330 - seg &= ~7UL;
19331 + seg >>= 3;
19332
19333 mutex_lock(&child->mm->context.lock);
19334 - if (unlikely((seg >> 3) >= child->mm->context.size))
19335 + if (unlikely(seg >= child->mm->context.size))
19336 addr = -1L; /* bogus selector, access would fault */
19337 else {
19338 desc = child->mm->context.ldt + seg;
19339 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19340 addr += base;
19341 }
19342 mutex_unlock(&child->mm->context.lock);
19343 - }
19344 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19345 + addr = ktla_ktva(addr);
19346
19347 return addr;
19348 }
19349 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19350 unsigned char opcode[15];
19351 unsigned long addr = convert_ip_to_linear(child, regs);
19352
19353 + if (addr == -EINVAL)
19354 + return 0;
19355 +
19356 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19357 for (i = 0; i < copied; i++) {
19358 switch (opcode[i]) {
19359 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19360
19361 #ifdef CONFIG_X86_64
19362 case 0x40 ... 0x4f:
19363 - if (regs->cs != __USER_CS)
19364 + if ((regs->cs & 0xffff) != __USER_CS)
19365 /* 32-bit mode: register increment */
19366 return 0;
19367 /* 64-bit mode: REX prefix */
19368 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19369 index dee1ff7..a397f7f 100644
19370 --- a/arch/x86/kernel/sys_i386_32.c
19371 +++ b/arch/x86/kernel/sys_i386_32.c
19372 @@ -24,6 +24,21 @@
19373
19374 #include <asm/syscalls.h>
19375
19376 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19377 +{
19378 + unsigned long pax_task_size = TASK_SIZE;
19379 +
19380 +#ifdef CONFIG_PAX_SEGMEXEC
19381 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19382 + pax_task_size = SEGMEXEC_TASK_SIZE;
19383 +#endif
19384 +
19385 + if (len > pax_task_size || addr > pax_task_size - len)
19386 + return -EINVAL;
19387 +
19388 + return 0;
19389 +}
19390 +
19391 /*
19392 * Perform the select(nd, in, out, ex, tv) and mmap() system
19393 * calls. Linux/i386 didn't use to be able to handle more than
19394 @@ -58,6 +73,212 @@ out:
19395 return err;
19396 }
19397
19398 +unsigned long
19399 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19400 + unsigned long len, unsigned long pgoff, unsigned long flags)
19401 +{
19402 + struct mm_struct *mm = current->mm;
19403 + struct vm_area_struct *vma;
19404 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19405 +
19406 +#ifdef CONFIG_PAX_SEGMEXEC
19407 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19408 + pax_task_size = SEGMEXEC_TASK_SIZE;
19409 +#endif
19410 +
19411 + pax_task_size -= PAGE_SIZE;
19412 +
19413 + if (len > pax_task_size)
19414 + return -ENOMEM;
19415 +
19416 + if (flags & MAP_FIXED)
19417 + return addr;
19418 +
19419 +#ifdef CONFIG_PAX_RANDMMAP
19420 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19421 +#endif
19422 +
19423 + if (addr) {
19424 + addr = PAGE_ALIGN(addr);
19425 + if (pax_task_size - len >= addr) {
19426 + vma = find_vma(mm, addr);
19427 + if (check_heap_stack_gap(vma, addr, len))
19428 + return addr;
19429 + }
19430 + }
19431 + if (len > mm->cached_hole_size) {
19432 + start_addr = addr = mm->free_area_cache;
19433 + } else {
19434 + start_addr = addr = mm->mmap_base;
19435 + mm->cached_hole_size = 0;
19436 + }
19437 +
19438 +#ifdef CONFIG_PAX_PAGEEXEC
19439 + if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19440 + start_addr = 0x00110000UL;
19441 +
19442 +#ifdef CONFIG_PAX_RANDMMAP
19443 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19444 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19445 +#endif
19446 +
19447 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19448 + start_addr = addr = mm->mmap_base;
19449 + else
19450 + addr = start_addr;
19451 + }
19452 +#endif
19453 +
19454 +full_search:
19455 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19456 + /* At this point: (!vma || addr < vma->vm_end). */
19457 + if (pax_task_size - len < addr) {
19458 + /*
19459 + * Start a new search - just in case we missed
19460 + * some holes.
19461 + */
19462 + if (start_addr != mm->mmap_base) {
19463 + start_addr = addr = mm->mmap_base;
19464 + mm->cached_hole_size = 0;
19465 + goto full_search;
19466 + }
19467 + return -ENOMEM;
19468 + }
19469 + if (check_heap_stack_gap(vma, addr, len))
19470 + break;
19471 + if (addr + mm->cached_hole_size < vma->vm_start)
19472 + mm->cached_hole_size = vma->vm_start - addr;
19473 + addr = vma->vm_end;
19474 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19475 + start_addr = addr = mm->mmap_base;
19476 + mm->cached_hole_size = 0;
19477 + goto full_search;
19478 + }
19479 + }
19480 +
19481 + /*
19482 + * Remember the place where we stopped the search:
19483 + */
19484 + mm->free_area_cache = addr + len;
19485 + return addr;
19486 +}
19487 +
19488 +unsigned long
19489 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19490 + const unsigned long len, const unsigned long pgoff,
19491 + const unsigned long flags)
19492 +{
19493 + struct vm_area_struct *vma;
19494 + struct mm_struct *mm = current->mm;
19495 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19496 +
19497 +#ifdef CONFIG_PAX_SEGMEXEC
19498 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19499 + pax_task_size = SEGMEXEC_TASK_SIZE;
19500 +#endif
19501 +
19502 + pax_task_size -= PAGE_SIZE;
19503 +
19504 + /* requested length too big for entire address space */
19505 + if (len > pax_task_size)
19506 + return -ENOMEM;
19507 +
19508 + if (flags & MAP_FIXED)
19509 + return addr;
19510 +
19511 +#ifdef CONFIG_PAX_PAGEEXEC
19512 + if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19513 + goto bottomup;
19514 +#endif
19515 +
19516 +#ifdef CONFIG_PAX_RANDMMAP
19517 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19518 +#endif
19519 +
19520 + /* requesting a specific address */
19521 + if (addr) {
19522 + addr = PAGE_ALIGN(addr);
19523 + if (pax_task_size - len >= addr) {
19524 + vma = find_vma(mm, addr);
19525 + if (check_heap_stack_gap(vma, addr, len))
19526 + return addr;
19527 + }
19528 + }
19529 +
19530 + /* check if free_area_cache is useful for us */
19531 + if (len <= mm->cached_hole_size) {
19532 + mm->cached_hole_size = 0;
19533 + mm->free_area_cache = mm->mmap_base;
19534 + }
19535 +
19536 + /* either no address requested or can't fit in requested address hole */
19537 + addr = mm->free_area_cache;
19538 +
19539 + /* make sure it can fit in the remaining address space */
19540 + if (addr > len) {
19541 + vma = find_vma(mm, addr-len);
19542 + if (check_heap_stack_gap(vma, addr - len, len))
19543 + /* remember the address as a hint for next time */
19544 + return (mm->free_area_cache = addr-len);
19545 + }
19546 +
19547 + if (mm->mmap_base < len)
19548 + goto bottomup;
19549 +
19550 + addr = mm->mmap_base-len;
19551 +
19552 + do {
19553 + /*
19554 + * Lookup failure means no vma is above this address,
19555 + * else if new region fits below vma->vm_start,
19556 + * return with success:
19557 + */
19558 + vma = find_vma(mm, addr);
19559 + if (check_heap_stack_gap(vma, addr, len))
19560 + /* remember the address as a hint for next time */
19561 + return (mm->free_area_cache = addr);
19562 +
19563 + /* remember the largest hole we saw so far */
19564 + if (addr + mm->cached_hole_size < vma->vm_start)
19565 + mm->cached_hole_size = vma->vm_start - addr;
19566 +
19567 + /* try just below the current vma->vm_start */
19568 + addr = skip_heap_stack_gap(vma, len);
19569 + } while (!IS_ERR_VALUE(addr));
19570 +
19571 +bottomup:
19572 + /*
19573 + * A failed mmap() very likely causes application failure,
19574 + * so fall back to the bottom-up function here. This scenario
19575 + * can happen with large stack limits and large mmap()
19576 + * allocations.
19577 + */
19578 +
19579 +#ifdef CONFIG_PAX_SEGMEXEC
19580 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19581 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19582 + else
19583 +#endif
19584 +
19585 + mm->mmap_base = TASK_UNMAPPED_BASE;
19586 +
19587 +#ifdef CONFIG_PAX_RANDMMAP
19588 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19589 + mm->mmap_base += mm->delta_mmap;
19590 +#endif
19591 +
19592 + mm->free_area_cache = mm->mmap_base;
19593 + mm->cached_hole_size = ~0UL;
19594 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19595 + /*
19596 + * Restore the topdown base:
19597 + */
19598 + mm->mmap_base = base;
19599 + mm->free_area_cache = base;
19600 + mm->cached_hole_size = ~0UL;
19601 +
19602 + return addr;
19603 +}
19604
19605 struct sel_arg_struct {
19606 unsigned long n;
19607 @@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int first, int second,
19608 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
19609 case SEMTIMEDOP:
19610 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
19611 - (const struct timespec __user *)fifth);
19612 + (__force const struct timespec __user *)fifth);
19613
19614 case SEMGET:
19615 return sys_semget(first, second, third);
19616 @@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int first, int second,
19617 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
19618 if (ret)
19619 return ret;
19620 - return put_user(raddr, (ulong __user *) third);
19621 + return put_user(raddr, (__force ulong __user *) third);
19622 }
19623 case 1: /* iBCS2 emulator entry point */
19624 if (!segment_eq(get_fs(), get_ds()))
19625 @@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldold_utsname __user *name)
19626
19627 return error;
19628 }
19629 -
19630 -
19631 -/*
19632 - * Do a system call from kernel instead of calling sys_execve so we
19633 - * end up with proper pt_regs.
19634 - */
19635 -int kernel_execve(const char *filename, char *const argv[], char *const envp[])
19636 -{
19637 - long __res;
19638 - asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
19639 - : "=a" (__res)
19640 - : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
19641 - return __res;
19642 -}
19643 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19644 index 8aa2057..b604bc1 100644
19645 --- a/arch/x86/kernel/sys_x86_64.c
19646 +++ b/arch/x86/kernel/sys_x86_64.c
19647 @@ -32,8 +32,8 @@ out:
19648 return error;
19649 }
19650
19651 -static void find_start_end(unsigned long flags, unsigned long *begin,
19652 - unsigned long *end)
19653 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19654 + unsigned long *begin, unsigned long *end)
19655 {
19656 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19657 unsigned long new_begin;
19658 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19659 *begin = new_begin;
19660 }
19661 } else {
19662 - *begin = TASK_UNMAPPED_BASE;
19663 + *begin = mm->mmap_base;
19664 *end = TASK_SIZE;
19665 }
19666 }
19667 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19668 if (flags & MAP_FIXED)
19669 return addr;
19670
19671 - find_start_end(flags, &begin, &end);
19672 + find_start_end(mm, flags, &begin, &end);
19673
19674 if (len > end)
19675 return -ENOMEM;
19676
19677 +#ifdef CONFIG_PAX_RANDMMAP
19678 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19679 +#endif
19680 +
19681 if (addr) {
19682 addr = PAGE_ALIGN(addr);
19683 vma = find_vma(mm, addr);
19684 - if (end - len >= addr &&
19685 - (!vma || addr + len <= vma->vm_start))
19686 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19687 return addr;
19688 }
19689 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19690 @@ -106,7 +109,7 @@ full_search:
19691 }
19692 return -ENOMEM;
19693 }
19694 - if (!vma || addr + len <= vma->vm_start) {
19695 + if (check_heap_stack_gap(vma, addr, len)) {
19696 /*
19697 * Remember the place where we stopped the search:
19698 */
19699 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19700 {
19701 struct vm_area_struct *vma;
19702 struct mm_struct *mm = current->mm;
19703 - unsigned long addr = addr0;
19704 + unsigned long base = mm->mmap_base, addr = addr0;
19705
19706 /* requested length too big for entire address space */
19707 if (len > TASK_SIZE)
19708 @@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19709 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19710 goto bottomup;
19711
19712 +#ifdef CONFIG_PAX_RANDMMAP
19713 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19714 +#endif
19715 +
19716 /* requesting a specific address */
19717 if (addr) {
19718 addr = PAGE_ALIGN(addr);
19719 - vma = find_vma(mm, addr);
19720 - if (TASK_SIZE - len >= addr &&
19721 - (!vma || addr + len <= vma->vm_start))
19722 - return addr;
19723 + if (TASK_SIZE - len >= addr) {
19724 + vma = find_vma(mm, addr);
19725 + if (check_heap_stack_gap(vma, addr, len))
19726 + return addr;
19727 + }
19728 }
19729
19730 /* check if free_area_cache is useful for us */
19731 @@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19732 /* make sure it can fit in the remaining address space */
19733 if (addr > len) {
19734 vma = find_vma(mm, addr-len);
19735 - if (!vma || addr <= vma->vm_start)
19736 + if (check_heap_stack_gap(vma, addr - len, len))
19737 /* remember the address as a hint for next time */
19738 return mm->free_area_cache = addr-len;
19739 }
19740 @@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19741 * return with success:
19742 */
19743 vma = find_vma(mm, addr);
19744 - if (!vma || addr+len <= vma->vm_start)
19745 + if (check_heap_stack_gap(vma, addr, len))
19746 /* remember the address as a hint for next time */
19747 return mm->free_area_cache = addr;
19748
19749 @@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19750 mm->cached_hole_size = vma->vm_start - addr;
19751
19752 /* try just below the current vma->vm_start */
19753 - addr = vma->vm_start-len;
19754 - } while (len < vma->vm_start);
19755 + addr = skip_heap_stack_gap(vma, len);
19756 + } while (!IS_ERR_VALUE(addr));
19757
19758 bottomup:
19759 /*
19760 @@ -198,13 +206,21 @@ bottomup:
19761 * can happen with large stack limits and large mmap()
19762 * allocations.
19763 */
19764 + mm->mmap_base = TASK_UNMAPPED_BASE;
19765 +
19766 +#ifdef CONFIG_PAX_RANDMMAP
19767 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19768 + mm->mmap_base += mm->delta_mmap;
19769 +#endif
19770 +
19771 + mm->free_area_cache = mm->mmap_base;
19772 mm->cached_hole_size = ~0UL;
19773 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19774 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19775 /*
19776 * Restore the topdown base:
19777 */
19778 - mm->free_area_cache = mm->mmap_base;
19779 + mm->mmap_base = base;
19780 + mm->free_area_cache = base;
19781 mm->cached_hole_size = ~0UL;
19782
19783 return addr;
19784 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
19785 index 76d70a4..4c94a44 100644
19786 --- a/arch/x86/kernel/syscall_table_32.S
19787 +++ b/arch/x86/kernel/syscall_table_32.S
19788 @@ -1,3 +1,4 @@
19789 +.section .rodata,"a",@progbits
19790 ENTRY(sys_call_table)
19791 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
19792 .long sys_exit
19793 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19794 index 46b8277..3349d55 100644
19795 --- a/arch/x86/kernel/tboot.c
19796 +++ b/arch/x86/kernel/tboot.c
19797 @@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
19798
19799 void tboot_shutdown(u32 shutdown_type)
19800 {
19801 - void (*shutdown)(void);
19802 + void (* __noreturn shutdown)(void);
19803
19804 if (!tboot_enabled())
19805 return;
19806 @@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
19807
19808 switch_to_tboot_pt();
19809
19810 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19811 + shutdown = (void *)tboot->shutdown_entry;
19812 shutdown();
19813
19814 /* should not reach here */
19815 @@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19816 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19817 }
19818
19819 -static atomic_t ap_wfs_count;
19820 +static atomic_unchecked_t ap_wfs_count;
19821
19822 static int tboot_wait_for_aps(int num_aps)
19823 {
19824 @@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19825 {
19826 switch (action) {
19827 case CPU_DYING:
19828 - atomic_inc(&ap_wfs_count);
19829 + atomic_inc_unchecked(&ap_wfs_count);
19830 if (num_online_cpus() == 1)
19831 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19832 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19833 return NOTIFY_BAD;
19834 break;
19835 }
19836 @@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
19837
19838 tboot_create_trampoline();
19839
19840 - atomic_set(&ap_wfs_count, 0);
19841 + atomic_set_unchecked(&ap_wfs_count, 0);
19842 register_hotcpu_notifier(&tboot_cpu_notifier);
19843 return 0;
19844 }
19845 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19846 index be25734..87fe232 100644
19847 --- a/arch/x86/kernel/time.c
19848 +++ b/arch/x86/kernel/time.c
19849 @@ -26,17 +26,13 @@
19850 int timer_ack;
19851 #endif
19852
19853 -#ifdef CONFIG_X86_64
19854 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
19855 -#endif
19856 -
19857 unsigned long profile_pc(struct pt_regs *regs)
19858 {
19859 unsigned long pc = instruction_pointer(regs);
19860
19861 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19862 + if (!user_mode(regs) && in_lock_functions(pc)) {
19863 #ifdef CONFIG_FRAME_POINTER
19864 - return *(unsigned long *)(regs->bp + sizeof(long));
19865 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19866 #else
19867 unsigned long *sp =
19868 (unsigned long *)kernel_stack_pointer(regs);
19869 @@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19870 * or above a saved flags. Eflags has bits 22-31 zero,
19871 * kernel addresses don't.
19872 */
19873 +
19874 +#ifdef CONFIG_PAX_KERNEXEC
19875 + return ktla_ktva(sp[0]);
19876 +#else
19877 if (sp[0] >> 22)
19878 return sp[0];
19879 if (sp[1] >> 22)
19880 return sp[1];
19881 #endif
19882 +
19883 +#endif
19884 }
19885 return pc;
19886 }
19887 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19888 index 6bb7b85..dd853e1 100644
19889 --- a/arch/x86/kernel/tls.c
19890 +++ b/arch/x86/kernel/tls.c
19891 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19892 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19893 return -EINVAL;
19894
19895 +#ifdef CONFIG_PAX_SEGMEXEC
19896 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19897 + return -EINVAL;
19898 +#endif
19899 +
19900 set_tls_desc(p, idx, &info, 1);
19901
19902 return 0;
19903 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19904 index 8508237..229b664 100644
19905 --- a/arch/x86/kernel/trampoline_32.S
19906 +++ b/arch/x86/kernel/trampoline_32.S
19907 @@ -32,6 +32,12 @@
19908 #include <asm/segment.h>
19909 #include <asm/page_types.h>
19910
19911 +#ifdef CONFIG_PAX_KERNEXEC
19912 +#define ta(X) (X)
19913 +#else
19914 +#define ta(X) ((X) - __PAGE_OFFSET)
19915 +#endif
19916 +
19917 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
19918 __CPUINITRODATA
19919 .code16
19920 @@ -60,7 +66,7 @@ r_base = .
19921 inc %ax # protected mode (PE) bit
19922 lmsw %ax # into protected mode
19923 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19924 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19925 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19926
19927 # These need to be in the same 64K segment as the above;
19928 # hence we don't use the boot_gdt_descr defined in head.S
19929 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19930 index 3af2dff..ba8aa49 100644
19931 --- a/arch/x86/kernel/trampoline_64.S
19932 +++ b/arch/x86/kernel/trampoline_64.S
19933 @@ -91,7 +91,7 @@ startup_32:
19934 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19935 movl %eax, %ds
19936
19937 - movl $X86_CR4_PAE, %eax
19938 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19939 movl %eax, %cr4 # Enable PAE mode
19940
19941 # Setup trampoline 4 level pagetables
19942 @@ -127,7 +127,7 @@ startup_64:
19943 no_longmode:
19944 hlt
19945 jmp no_longmode
19946 -#include "verify_cpu_64.S"
19947 +#include "verify_cpu.S"
19948
19949 # Careful these need to be in the same 64K segment as the above;
19950 tidt:
19951 @@ -138,7 +138,7 @@ tidt:
19952 # so the kernel can live anywhere
19953 .balign 4
19954 tgdt:
19955 - .short tgdt_end - tgdt # gdt limit
19956 + .short tgdt_end - tgdt - 1 # gdt limit
19957 .long tgdt - r_base
19958 .short 0
19959 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19960 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19961 index 7e37dce..ec3f8e5 100644
19962 --- a/arch/x86/kernel/traps.c
19963 +++ b/arch/x86/kernel/traps.c
19964 @@ -69,12 +69,6 @@ asmlinkage int system_call(void);
19965
19966 /* Do we ignore FPU interrupts ? */
19967 char ignore_fpu_irq;
19968 -
19969 -/*
19970 - * The IDT has to be page-aligned to simplify the Pentium
19971 - * F0 0F bug workaround.
19972 - */
19973 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19974 #endif
19975
19976 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19977 @@ -112,19 +106,19 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19978 static inline void
19979 die_if_kernel(const char *str, struct pt_regs *regs, long err)
19980 {
19981 - if (!user_mode_vm(regs))
19982 + if (!user_mode(regs))
19983 die(str, regs, err);
19984 }
19985 #endif
19986
19987 static void __kprobes
19988 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19989 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19990 long error_code, siginfo_t *info)
19991 {
19992 struct task_struct *tsk = current;
19993
19994 #ifdef CONFIG_X86_32
19995 - if (regs->flags & X86_VM_MASK) {
19996 + if (v8086_mode(regs)) {
19997 /*
19998 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19999 * On nmi (interrupt 2), do_trap should not be called.
20000 @@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20001 }
20002 #endif
20003
20004 - if (!user_mode(regs))
20005 + if (!user_mode_novm(regs))
20006 goto kernel_trap;
20007
20008 #ifdef CONFIG_X86_32
20009 @@ -158,7 +152,7 @@ trap_signal:
20010 printk_ratelimit()) {
20011 printk(KERN_INFO
20012 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20013 - tsk->comm, tsk->pid, str,
20014 + tsk->comm, task_pid_nr(tsk), str,
20015 regs->ip, regs->sp, error_code);
20016 print_vma_addr(" in ", regs->ip);
20017 printk("\n");
20018 @@ -175,8 +169,20 @@ kernel_trap:
20019 if (!fixup_exception(regs)) {
20020 tsk->thread.error_code = error_code;
20021 tsk->thread.trap_no = trapnr;
20022 +
20023 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20024 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20025 + str = "PAX: suspicious stack segment fault";
20026 +#endif
20027 +
20028 die(str, regs, error_code);
20029 }
20030 +
20031 +#ifdef CONFIG_PAX_REFCOUNT
20032 + if (trapnr == 4)
20033 + pax_report_refcount_overflow(regs);
20034 +#endif
20035 +
20036 return;
20037
20038 #ifdef CONFIG_X86_32
20039 @@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
20040 conditional_sti(regs);
20041
20042 #ifdef CONFIG_X86_32
20043 - if (regs->flags & X86_VM_MASK)
20044 + if (v8086_mode(regs))
20045 goto gp_in_vm86;
20046 #endif
20047
20048 tsk = current;
20049 - if (!user_mode(regs))
20050 + if (!user_mode_novm(regs))
20051 goto gp_in_kernel;
20052
20053 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20054 + if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20055 + struct mm_struct *mm = tsk->mm;
20056 + unsigned long limit;
20057 +
20058 + down_write(&mm->mmap_sem);
20059 + limit = mm->context.user_cs_limit;
20060 + if (limit < TASK_SIZE) {
20061 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20062 + up_write(&mm->mmap_sem);
20063 + return;
20064 + }
20065 + up_write(&mm->mmap_sem);
20066 + }
20067 +#endif
20068 +
20069 tsk->thread.error_code = error_code;
20070 tsk->thread.trap_no = 13;
20071
20072 @@ -305,6 +327,13 @@ gp_in_kernel:
20073 if (notify_die(DIE_GPF, "general protection fault", regs,
20074 error_code, 13, SIGSEGV) == NOTIFY_STOP)
20075 return;
20076 +
20077 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20078 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20079 + die("PAX: suspicious general protection fault", regs, error_code);
20080 + else
20081 +#endif
20082 +
20083 die("general protection fault", regs, error_code);
20084 }
20085
20086 @@ -435,6 +464,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
20087 dotraplinkage notrace __kprobes void
20088 do_nmi(struct pt_regs *regs, long error_code)
20089 {
20090 +
20091 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20092 + if (!user_mode(regs)) {
20093 + unsigned long cs = regs->cs & 0xFFFF;
20094 + unsigned long ip = ktva_ktla(regs->ip);
20095 +
20096 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
20097 + regs->ip = ip;
20098 + }
20099 +#endif
20100 +
20101 nmi_enter();
20102
20103 inc_irq_stat(__nmi_count);
20104 @@ -558,7 +598,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20105 }
20106
20107 #ifdef CONFIG_X86_32
20108 - if (regs->flags & X86_VM_MASK)
20109 + if (v8086_mode(regs))
20110 goto debug_vm86;
20111 #endif
20112
20113 @@ -570,7 +610,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20114 * kernel space (but re-enable TF when returning to user mode).
20115 */
20116 if (condition & DR_STEP) {
20117 - if (!user_mode(regs))
20118 + if (!user_mode_novm(regs))
20119 goto clear_TF_reenable;
20120 }
20121
20122 @@ -757,7 +797,7 @@ do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
20123 * Handle strange cache flush from user space exception
20124 * in all other cases. This is undocumented behaviour.
20125 */
20126 - if (regs->flags & X86_VM_MASK) {
20127 + if (v8086_mode(regs)) {
20128 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
20129 return;
20130 }
20131 @@ -798,7 +838,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
20132 void __math_state_restore(void)
20133 {
20134 struct thread_info *thread = current_thread_info();
20135 - struct task_struct *tsk = thread->task;
20136 + struct task_struct *tsk = current;
20137
20138 /*
20139 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
20140 @@ -825,8 +865,7 @@ void __math_state_restore(void)
20141 */
20142 asmlinkage void math_state_restore(void)
20143 {
20144 - struct thread_info *thread = current_thread_info();
20145 - struct task_struct *tsk = thread->task;
20146 + struct task_struct *tsk = current;
20147
20148 if (!tsk_used_math(tsk)) {
20149 local_irq_enable();
20150 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20151 new file mode 100644
20152 index 0000000..50c5edd
20153 --- /dev/null
20154 +++ b/arch/x86/kernel/verify_cpu.S
20155 @@ -0,0 +1,140 @@
20156 +/*
20157 + *
20158 + * verify_cpu.S - Code for cpu long mode and SSE verification. This
20159 + * code has been borrowed from boot/setup.S and was introduced by
20160 + * Andi Kleen.
20161 + *
20162 + * Copyright (c) 2007 Andi Kleen (ak@suse.de)
20163 + * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
20164 + * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
20165 + * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com)
20166 + *
20167 + * This source code is licensed under the GNU General Public License,
20168 + * Version 2. See the file COPYING for more details.
20169 + *
20170 + * This is a common code for verification whether CPU supports
20171 + * long mode and SSE or not. It is not called directly instead this
20172 + * file is included at various places and compiled in that context.
20173 + * This file is expected to run in 32bit code. Currently:
20174 + *
20175 + * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20176 + * arch/x86/kernel/trampoline_64.S: secondary processor verification
20177 + * arch/x86/kernel/head_32.S: processor startup
20178 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20179 + *
20180 + * verify_cpu, returns the status of longmode and SSE in register %eax.
20181 + * 0: Success 1: Failure
20182 + *
20183 + * On Intel, the XD_DISABLE flag will be cleared as a side-effect.
20184 + *
20185 + * The caller needs to check for the error code and take the action
20186 + * appropriately. Either display a message or halt.
20187 + */
20188 +
20189 +#include <asm/cpufeature.h>
20190 +#include <asm/msr-index.h>
20191 +
20192 +verify_cpu:
20193 + pushfl # Save caller passed flags
20194 + pushl $0 # Kill any dangerous flags
20195 + popfl
20196 +
20197 + pushfl # standard way to check for cpuid
20198 + popl %eax
20199 + movl %eax,%ebx
20200 + xorl $0x200000,%eax
20201 + pushl %eax
20202 + popfl
20203 + pushfl
20204 + popl %eax
20205 + cmpl %eax,%ebx
20206 + jz verify_cpu_no_longmode # cpu has no cpuid
20207 +
20208 + movl $0x0,%eax # See if cpuid 1 is implemented
20209 + cpuid
20210 + cmpl $0x1,%eax
20211 + jb verify_cpu_no_longmode # no cpuid 1
20212 +
20213 + xor %di,%di
20214 + cmpl $0x68747541,%ebx # AuthenticAMD
20215 + jnz verify_cpu_noamd
20216 + cmpl $0x69746e65,%edx
20217 + jnz verify_cpu_noamd
20218 + cmpl $0x444d4163,%ecx
20219 + jnz verify_cpu_noamd
20220 + mov $1,%di # cpu is from AMD
20221 + jmp verify_cpu_check
20222 +
20223 +verify_cpu_noamd:
20224 + cmpl $0x756e6547,%ebx # GenuineIntel?
20225 + jnz verify_cpu_check
20226 + cmpl $0x49656e69,%edx
20227 + jnz verify_cpu_check
20228 + cmpl $0x6c65746e,%ecx
20229 + jnz verify_cpu_check
20230 +
20231 + # only call IA32_MISC_ENABLE when:
20232 + # family > 6 || (family == 6 && model >= 0xd)
20233 + movl $0x1, %eax # check CPU family and model
20234 + cpuid
20235 + movl %eax, %ecx
20236 +
20237 + andl $0x0ff00f00, %eax # mask family and extended family
20238 + shrl $8, %eax
20239 + cmpl $6, %eax
20240 + ja verify_cpu_clear_xd # family > 6, ok
20241 + jb verify_cpu_check # family < 6, skip
20242 +
20243 + andl $0x000f00f0, %ecx # mask model and extended model
20244 + shrl $4, %ecx
20245 + cmpl $0xd, %ecx
20246 + jb verify_cpu_check # family == 6, model < 0xd, skip
20247 +
20248 +verify_cpu_clear_xd:
20249 + movl $MSR_IA32_MISC_ENABLE, %ecx
20250 + rdmsr
20251 + btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE
20252 + jnc verify_cpu_check # only write MSR if bit was changed
20253 + wrmsr
20254 +
20255 +verify_cpu_check:
20256 + movl $0x1,%eax # Does the cpu have what it takes
20257 + cpuid
20258 + andl $REQUIRED_MASK0,%edx
20259 + xorl $REQUIRED_MASK0,%edx
20260 + jnz verify_cpu_no_longmode
20261 +
20262 + movl $0x80000000,%eax # See if extended cpuid is implemented
20263 + cpuid
20264 + cmpl $0x80000001,%eax
20265 + jb verify_cpu_no_longmode # no extended cpuid
20266 +
20267 + movl $0x80000001,%eax # Does the cpu have what it takes
20268 + cpuid
20269 + andl $REQUIRED_MASK1,%edx
20270 + xorl $REQUIRED_MASK1,%edx
20271 + jnz verify_cpu_no_longmode
20272 +
20273 +verify_cpu_sse_test:
20274 + movl $1,%eax
20275 + cpuid
20276 + andl $SSE_MASK,%edx
20277 + cmpl $SSE_MASK,%edx
20278 + je verify_cpu_sse_ok
20279 + test %di,%di
20280 + jz verify_cpu_no_longmode # only try to force SSE on AMD
20281 + movl $MSR_K7_HWCR,%ecx
20282 + rdmsr
20283 + btr $15,%eax # enable SSE
20284 + wrmsr
20285 + xor %di,%di # don't loop
20286 + jmp verify_cpu_sse_test # try again
20287 +
20288 +verify_cpu_no_longmode:
20289 + popfl # Restore caller passed flags
20290 + movl $1,%eax
20291 + ret
20292 +verify_cpu_sse_ok:
20293 + popfl # Restore caller passed flags
20294 + xorl %eax, %eax
20295 + ret
20296 diff --git a/arch/x86/kernel/verify_cpu_64.S b/arch/x86/kernel/verify_cpu_64.S
20297 deleted file mode 100644
20298 index 45b6f8a..0000000
20299 --- a/arch/x86/kernel/verify_cpu_64.S
20300 +++ /dev/null
20301 @@ -1,105 +0,0 @@
20302 -/*
20303 - *
20304 - * verify_cpu.S - Code for cpu long mode and SSE verification. This
20305 - * code has been borrowed from boot/setup.S and was introduced by
20306 - * Andi Kleen.
20307 - *
20308 - * Copyright (c) 2007 Andi Kleen (ak@suse.de)
20309 - * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
20310 - * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
20311 - *
20312 - * This source code is licensed under the GNU General Public License,
20313 - * Version 2. See the file COPYING for more details.
20314 - *
20315 - * This is a common code for verification whether CPU supports
20316 - * long mode and SSE or not. It is not called directly instead this
20317 - * file is included at various places and compiled in that context.
20318 - * Following are the current usage.
20319 - *
20320 - * This file is included by both 16bit and 32bit code.
20321 - *
20322 - * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
20323 - * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
20324 - * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
20325 - * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
20326 - *
20327 - * verify_cpu, returns the status of cpu check in register %eax.
20328 - * 0: Success 1: Failure
20329 - *
20330 - * The caller needs to check for the error code and take the action
20331 - * appropriately. Either display a message or halt.
20332 - */
20333 -
20334 -#include <asm/cpufeature.h>
20335 -
20336 -verify_cpu:
20337 - pushfl # Save caller passed flags
20338 - pushl $0 # Kill any dangerous flags
20339 - popfl
20340 -
20341 - pushfl # standard way to check for cpuid
20342 - popl %eax
20343 - movl %eax,%ebx
20344 - xorl $0x200000,%eax
20345 - pushl %eax
20346 - popfl
20347 - pushfl
20348 - popl %eax
20349 - cmpl %eax,%ebx
20350 - jz verify_cpu_no_longmode # cpu has no cpuid
20351 -
20352 - movl $0x0,%eax # See if cpuid 1 is implemented
20353 - cpuid
20354 - cmpl $0x1,%eax
20355 - jb verify_cpu_no_longmode # no cpuid 1
20356 -
20357 - xor %di,%di
20358 - cmpl $0x68747541,%ebx # AuthenticAMD
20359 - jnz verify_cpu_noamd
20360 - cmpl $0x69746e65,%edx
20361 - jnz verify_cpu_noamd
20362 - cmpl $0x444d4163,%ecx
20363 - jnz verify_cpu_noamd
20364 - mov $1,%di # cpu is from AMD
20365 -
20366 -verify_cpu_noamd:
20367 - movl $0x1,%eax # Does the cpu have what it takes
20368 - cpuid
20369 - andl $REQUIRED_MASK0,%edx
20370 - xorl $REQUIRED_MASK0,%edx
20371 - jnz verify_cpu_no_longmode
20372 -
20373 - movl $0x80000000,%eax # See if extended cpuid is implemented
20374 - cpuid
20375 - cmpl $0x80000001,%eax
20376 - jb verify_cpu_no_longmode # no extended cpuid
20377 -
20378 - movl $0x80000001,%eax # Does the cpu have what it takes
20379 - cpuid
20380 - andl $REQUIRED_MASK1,%edx
20381 - xorl $REQUIRED_MASK1,%edx
20382 - jnz verify_cpu_no_longmode
20383 -
20384 -verify_cpu_sse_test:
20385 - movl $1,%eax
20386 - cpuid
20387 - andl $SSE_MASK,%edx
20388 - cmpl $SSE_MASK,%edx
20389 - je verify_cpu_sse_ok
20390 - test %di,%di
20391 - jz verify_cpu_no_longmode # only try to force SSE on AMD
20392 - movl $0xc0010015,%ecx # HWCR
20393 - rdmsr
20394 - btr $15,%eax # enable SSE
20395 - wrmsr
20396 - xor %di,%di # don't loop
20397 - jmp verify_cpu_sse_test # try again
20398 -
20399 -verify_cpu_no_longmode:
20400 - popfl # Restore caller passed flags
20401 - movl $1,%eax
20402 - ret
20403 -verify_cpu_sse_ok:
20404 - popfl # Restore caller passed flags
20405 - xorl %eax, %eax
20406 - ret
20407 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20408 index 9c4e625..c992817 100644
20409 --- a/arch/x86/kernel/vm86_32.c
20410 +++ b/arch/x86/kernel/vm86_32.c
20411 @@ -41,6 +41,7 @@
20412 #include <linux/ptrace.h>
20413 #include <linux/audit.h>
20414 #include <linux/stddef.h>
20415 +#include <linux/grsecurity.h>
20416
20417 #include <asm/uaccess.h>
20418 #include <asm/io.h>
20419 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20420 do_exit(SIGSEGV);
20421 }
20422
20423 - tss = &per_cpu(init_tss, get_cpu());
20424 + tss = init_tss + get_cpu();
20425 current->thread.sp0 = current->thread.saved_sp0;
20426 current->thread.sysenter_cs = __KERNEL_CS;
20427 load_sp0(tss, &current->thread);
20428 @@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
20429 struct task_struct *tsk;
20430 int tmp, ret = -EPERM;
20431
20432 +#ifdef CONFIG_GRKERNSEC_VM86
20433 + if (!capable(CAP_SYS_RAWIO)) {
20434 + gr_handle_vm86();
20435 + goto out;
20436 + }
20437 +#endif
20438 +
20439 tsk = current;
20440 if (tsk->thread.saved_sp0)
20441 goto out;
20442 @@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
20443 int tmp, ret;
20444 struct vm86plus_struct __user *v86;
20445
20446 +#ifdef CONFIG_GRKERNSEC_VM86
20447 + if (!capable(CAP_SYS_RAWIO)) {
20448 + gr_handle_vm86();
20449 + ret = -EPERM;
20450 + goto out;
20451 + }
20452 +#endif
20453 +
20454 tsk = current;
20455 switch (regs->bx) {
20456 case VM86_REQUEST_IRQ:
20457 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20458 tsk->thread.saved_fs = info->regs32->fs;
20459 tsk->thread.saved_gs = get_user_gs(info->regs32);
20460
20461 - tss = &per_cpu(init_tss, get_cpu());
20462 + tss = init_tss + get_cpu();
20463 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20464 if (cpu_has_sep)
20465 tsk->thread.sysenter_cs = 0;
20466 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20467 goto cannot_handle;
20468 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20469 goto cannot_handle;
20470 - intr_ptr = (unsigned long __user *) (i << 2);
20471 + intr_ptr = (__force unsigned long __user *) (i << 2);
20472 if (get_user(segoffs, intr_ptr))
20473 goto cannot_handle;
20474 if ((segoffs >> 16) == BIOSSEG)
20475 diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c
20476 index d430e4c..831f817 100644
20477 --- a/arch/x86/kernel/vmi_32.c
20478 +++ b/arch/x86/kernel/vmi_32.c
20479 @@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1))) (VROMFUNC)(void);
20480 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
20481
20482 #define call_vrom_func(rom,func) \
20483 - (((VROMFUNC *)(rom->func))())
20484 + (((VROMFUNC *)(ktva_ktla(rom.func)))())
20485
20486 #define call_vrom_long_func(rom,func,arg) \
20487 - (((VROMLONGFUNC *)(rom->func)) (arg))
20488 +({\
20489 + u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
20490 + struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
20491 + __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
20492 + __reloc;\
20493 +})
20494
20495 -static struct vrom_header *vmi_rom;
20496 +static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
20497 static int disable_pge;
20498 static int disable_pse;
20499 static int disable_sep;
20500 @@ -76,10 +81,10 @@ static struct {
20501 void (*set_initial_ap_state)(int, int);
20502 void (*halt)(void);
20503 void (*set_lazy_mode)(int mode);
20504 -} vmi_ops;
20505 +} __no_const vmi_ops __read_only;
20506
20507 /* Cached VMI operations */
20508 -struct vmi_timer_ops vmi_timer_ops;
20509 +struct vmi_timer_ops vmi_timer_ops __read_only;
20510
20511 /*
20512 * VMI patching routines.
20513 @@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
20514 static inline void patch_offset(void *insnbuf,
20515 unsigned long ip, unsigned long dest)
20516 {
20517 - *(unsigned long *)(insnbuf+1) = dest-ip-5;
20518 + *(unsigned long *)(insnbuf+1) = dest-ip-5;
20519 }
20520
20521 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
20522 @@ -102,6 +107,7 @@ static unsigned patch_internal(int call, unsigned len, void *insnbuf,
20523 {
20524 u64 reloc;
20525 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
20526 +
20527 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
20528 switch(rel->type) {
20529 case VMI_RELOCATION_CALL_REL:
20530 @@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud_t pudval)
20531
20532 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
20533 {
20534 - const pte_t pte = { .pte = 0 };
20535 + const pte_t pte = __pte(0ULL);
20536 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
20537 }
20538
20539 static void vmi_pmd_clear(pmd_t *pmd)
20540 {
20541 - const pte_t pte = { .pte = 0 };
20542 + const pte_t pte = __pte(0ULL);
20543 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
20544 }
20545 #endif
20546 @@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, unsigned long start_eip,
20547 ap.ss = __KERNEL_DS;
20548 ap.esp = (unsigned long) start_esp;
20549
20550 - ap.ds = __USER_DS;
20551 - ap.es = __USER_DS;
20552 + ap.ds = __KERNEL_DS;
20553 + ap.es = __KERNEL_DS;
20554 ap.fs = __KERNEL_PERCPU;
20555 - ap.gs = __KERNEL_STACK_CANARY;
20556 + savesegment(gs, ap.gs);
20557
20558 ap.eflags = 0;
20559
20560 @@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
20561 paravirt_leave_lazy_mmu();
20562 }
20563
20564 +#ifdef CONFIG_PAX_KERNEXEC
20565 +static unsigned long vmi_pax_open_kernel(void)
20566 +{
20567 + return 0;
20568 +}
20569 +
20570 +static unsigned long vmi_pax_close_kernel(void)
20571 +{
20572 + return 0;
20573 +}
20574 +#endif
20575 +
20576 static inline int __init check_vmi_rom(struct vrom_header *rom)
20577 {
20578 struct pci_header *pci;
20579 @@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(struct vrom_header *rom)
20580 return 0;
20581 if (rom->vrom_signature != VMI_SIGNATURE)
20582 return 0;
20583 + if (rom->rom_length * 512 > sizeof(*rom)) {
20584 + printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
20585 + return 0;
20586 + }
20587 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
20588 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
20589 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
20590 @@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(void)
20591 struct vrom_header *romstart;
20592 romstart = (struct vrom_header *)isa_bus_to_virt(base);
20593 if (check_vmi_rom(romstart)) {
20594 - vmi_rom = romstart;
20595 + vmi_rom = *romstart;
20596 return 1;
20597 }
20598 }
20599 @@ -836,6 +858,11 @@ static inline int __init activate_vmi(void)
20600
20601 para_fill(pv_irq_ops.safe_halt, Halt);
20602
20603 +#ifdef CONFIG_PAX_KERNEXEC
20604 + pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
20605 + pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
20606 +#endif
20607 +
20608 /*
20609 * Alternative instruction rewriting doesn't happen soon enough
20610 * to convert VMI_IRET to a call instead of a jump; so we have
20611 @@ -853,16 +880,16 @@ static inline int __init activate_vmi(void)
20612
20613 void __init vmi_init(void)
20614 {
20615 - if (!vmi_rom)
20616 + if (!vmi_rom.rom_signature)
20617 probe_vmi_rom();
20618 else
20619 - check_vmi_rom(vmi_rom);
20620 + check_vmi_rom(&vmi_rom);
20621
20622 /* In case probing for or validating the ROM failed, basil */
20623 - if (!vmi_rom)
20624 + if (!vmi_rom.rom_signature)
20625 return;
20626
20627 - reserve_top_address(-vmi_rom->virtual_top);
20628 + reserve_top_address(-vmi_rom.virtual_top);
20629
20630 #ifdef CONFIG_X86_IO_APIC
20631 /* This is virtual hardware; timer routing is wired correctly */
20632 @@ -874,7 +901,7 @@ void __init vmi_activate(void)
20633 {
20634 unsigned long flags;
20635
20636 - if (!vmi_rom)
20637 + if (!vmi_rom.rom_signature)
20638 return;
20639
20640 local_irq_save(flags);
20641 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20642 index 3c68fe2..12c8280 100644
20643 --- a/arch/x86/kernel/vmlinux.lds.S
20644 +++ b/arch/x86/kernel/vmlinux.lds.S
20645 @@ -26,6 +26,13 @@
20646 #include <asm/page_types.h>
20647 #include <asm/cache.h>
20648 #include <asm/boot.h>
20649 +#include <asm/segment.h>
20650 +
20651 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20652 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20653 +#else
20654 +#define __KERNEL_TEXT_OFFSET 0
20655 +#endif
20656
20657 #undef i386 /* in case the preprocessor is a 32bit one */
20658
20659 @@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
20660 #ifdef CONFIG_X86_32
20661 OUTPUT_ARCH(i386)
20662 ENTRY(phys_startup_32)
20663 -jiffies = jiffies_64;
20664 #else
20665 OUTPUT_ARCH(i386:x86-64)
20666 ENTRY(phys_startup_64)
20667 -jiffies_64 = jiffies;
20668 #endif
20669
20670 PHDRS {
20671 text PT_LOAD FLAGS(5); /* R_E */
20672 - data PT_LOAD FLAGS(7); /* RWE */
20673 +#ifdef CONFIG_X86_32
20674 + module PT_LOAD FLAGS(5); /* R_E */
20675 +#endif
20676 +#ifdef CONFIG_XEN
20677 + rodata PT_LOAD FLAGS(5); /* R_E */
20678 +#else
20679 + rodata PT_LOAD FLAGS(4); /* R__ */
20680 +#endif
20681 + data PT_LOAD FLAGS(6); /* RW_ */
20682 #ifdef CONFIG_X86_64
20683 user PT_LOAD FLAGS(5); /* R_E */
20684 +#endif
20685 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20686 #ifdef CONFIG_SMP
20687 percpu PT_LOAD FLAGS(6); /* RW_ */
20688 #endif
20689 + text.init PT_LOAD FLAGS(5); /* R_E */
20690 + text.exit PT_LOAD FLAGS(5); /* R_E */
20691 init PT_LOAD FLAGS(7); /* RWE */
20692 -#endif
20693 note PT_NOTE FLAGS(0); /* ___ */
20694 }
20695
20696 SECTIONS
20697 {
20698 #ifdef CONFIG_X86_32
20699 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20700 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20701 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20702 #else
20703 - . = __START_KERNEL;
20704 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20705 + . = __START_KERNEL;
20706 #endif
20707
20708 /* Text and read-only data */
20709 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20710 - _text = .;
20711 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20712 /* bootstrapping code */
20713 +#ifdef CONFIG_X86_32
20714 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20715 +#else
20716 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20717 +#endif
20718 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20719 + _text = .;
20720 HEAD_TEXT
20721 #ifdef CONFIG_X86_32
20722 . = ALIGN(PAGE_SIZE);
20723 @@ -82,28 +102,71 @@ SECTIONS
20724 IRQENTRY_TEXT
20725 *(.fixup)
20726 *(.gnu.warning)
20727 - /* End of text section */
20728 - _etext = .;
20729 } :text = 0x9090
20730
20731 - NOTES :text :note
20732 + . += __KERNEL_TEXT_OFFSET;
20733
20734 - EXCEPTION_TABLE(16) :text = 0x9090
20735 +#ifdef CONFIG_X86_32
20736 + . = ALIGN(PAGE_SIZE);
20737 + .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
20738 + *(.vmi.rom)
20739 + } :module
20740 +
20741 + . = ALIGN(PAGE_SIZE);
20742 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20743 +
20744 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20745 + MODULES_EXEC_VADDR = .;
20746 + BYTE(0)
20747 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20748 + . = ALIGN(HPAGE_SIZE);
20749 + MODULES_EXEC_END = . - 1;
20750 +#endif
20751 +
20752 + } :module
20753 +#endif
20754 +
20755 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20756 + /* End of text section */
20757 + _etext = . - __KERNEL_TEXT_OFFSET;
20758 + }
20759 +
20760 +#ifdef CONFIG_X86_32
20761 + . = ALIGN(PAGE_SIZE);
20762 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20763 + *(.idt)
20764 + . = ALIGN(PAGE_SIZE);
20765 + *(.empty_zero_page)
20766 + *(.swapper_pg_fixmap)
20767 + *(.swapper_pg_pmd)
20768 + *(.swapper_pg_dir)
20769 + *(.trampoline_pg_dir)
20770 + } :rodata
20771 +#endif
20772 +
20773 + . = ALIGN(PAGE_SIZE);
20774 + NOTES :rodata :note
20775 +
20776 + EXCEPTION_TABLE(16) :rodata
20777
20778 RO_DATA(PAGE_SIZE)
20779
20780 /* Data */
20781 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20782 +
20783 +#ifdef CONFIG_PAX_KERNEXEC
20784 + . = ALIGN(HPAGE_SIZE);
20785 +#else
20786 + . = ALIGN(PAGE_SIZE);
20787 +#endif
20788 +
20789 /* Start of data section */
20790 _sdata = .;
20791
20792 /* init_task */
20793 INIT_TASK_DATA(THREAD_SIZE)
20794
20795 -#ifdef CONFIG_X86_32
20796 - /* 32 bit has nosave before _edata */
20797 NOSAVE_DATA
20798 -#endif
20799
20800 PAGE_ALIGNED_DATA(PAGE_SIZE)
20801
20802 @@ -112,6 +175,8 @@ SECTIONS
20803 DATA_DATA
20804 CONSTRUCTORS
20805
20806 + jiffies = jiffies_64;
20807 +
20808 /* rarely changed data like cpu maps */
20809 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
20810
20811 @@ -166,12 +231,6 @@ SECTIONS
20812 }
20813 vgetcpu_mode = VVIRT(.vgetcpu_mode);
20814
20815 - . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
20816 - .jiffies : AT(VLOAD(.jiffies)) {
20817 - *(.jiffies)
20818 - }
20819 - jiffies = VVIRT(.jiffies);
20820 -
20821 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
20822 *(.vsyscall_3)
20823 }
20824 @@ -187,12 +246,19 @@ SECTIONS
20825 #endif /* CONFIG_X86_64 */
20826
20827 /* Init code and data - will be freed after init */
20828 - . = ALIGN(PAGE_SIZE);
20829 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20830 + BYTE(0)
20831 +
20832 +#ifdef CONFIG_PAX_KERNEXEC
20833 + . = ALIGN(HPAGE_SIZE);
20834 +#else
20835 + . = ALIGN(PAGE_SIZE);
20836 +#endif
20837 +
20838 __init_begin = .; /* paired with __init_end */
20839 - }
20840 + } :init.begin
20841
20842 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20843 +#ifdef CONFIG_SMP
20844 /*
20845 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20846 * output PHDR, so the next output section - .init.text - should
20847 @@ -201,12 +267,27 @@ SECTIONS
20848 PERCPU_VADDR(0, :percpu)
20849 #endif
20850
20851 - INIT_TEXT_SECTION(PAGE_SIZE)
20852 -#ifdef CONFIG_X86_64
20853 - :init
20854 -#endif
20855 + . = ALIGN(PAGE_SIZE);
20856 + init_begin = .;
20857 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20858 + VMLINUX_SYMBOL(_sinittext) = .;
20859 + INIT_TEXT
20860 + VMLINUX_SYMBOL(_einittext) = .;
20861 + . = ALIGN(PAGE_SIZE);
20862 + } :text.init
20863
20864 - INIT_DATA_SECTION(16)
20865 + /*
20866 + * .exit.text is discard at runtime, not link time, to deal with
20867 + * references from .altinstructions and .eh_frame
20868 + */
20869 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20870 + EXIT_TEXT
20871 + . = ALIGN(16);
20872 + } :text.exit
20873 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20874 +
20875 + . = ALIGN(PAGE_SIZE);
20876 + INIT_DATA_SECTION(16) :init
20877
20878 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20879 __x86_cpu_dev_start = .;
20880 @@ -232,19 +313,11 @@ SECTIONS
20881 *(.altinstr_replacement)
20882 }
20883
20884 - /*
20885 - * .exit.text is discard at runtime, not link time, to deal with
20886 - * references from .altinstructions and .eh_frame
20887 - */
20888 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20889 - EXIT_TEXT
20890 - }
20891 -
20892 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20893 EXIT_DATA
20894 }
20895
20896 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20897 +#ifndef CONFIG_SMP
20898 PERCPU(PAGE_SIZE)
20899 #endif
20900
20901 @@ -267,12 +340,6 @@ SECTIONS
20902 . = ALIGN(PAGE_SIZE);
20903 }
20904
20905 -#ifdef CONFIG_X86_64
20906 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20907 - NOSAVE_DATA
20908 - }
20909 -#endif
20910 -
20911 /* BSS */
20912 . = ALIGN(PAGE_SIZE);
20913 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20914 @@ -288,6 +355,7 @@ SECTIONS
20915 __brk_base = .;
20916 . += 64 * 1024; /* 64k alignment slop space */
20917 *(.brk_reservation) /* areas brk users have reserved */
20918 + . = ALIGN(HPAGE_SIZE);
20919 __brk_limit = .;
20920 }
20921
20922 @@ -316,13 +384,12 @@ SECTIONS
20923 * for the boot processor.
20924 */
20925 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
20926 -INIT_PER_CPU(gdt_page);
20927 INIT_PER_CPU(irq_stack_union);
20928
20929 /*
20930 * Build-time check on the image size:
20931 */
20932 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20933 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20934 "kernel image bigger than KERNEL_IMAGE_SIZE");
20935
20936 #ifdef CONFIG_SMP
20937 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20938 index 62f39d7..3bc46a1 100644
20939 --- a/arch/x86/kernel/vsyscall_64.c
20940 +++ b/arch/x86/kernel/vsyscall_64.c
20941 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wall_time, struct clocksource *clock,
20942
20943 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
20944 /* copy vsyscall data */
20945 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
20946 vsyscall_gtod_data.clock.vread = clock->vread;
20947 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
20948 vsyscall_gtod_data.clock.mask = clock->mask;
20949 @@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
20950 We do this here because otherwise user space would do it on
20951 its own in a likely inferior way (no access to jiffies).
20952 If you don't like it pass NULL. */
20953 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
20954 + if (tcache && tcache->blob[0] == (j = jiffies)) {
20955 p = tcache->blob[1];
20956 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
20957 /* Load per CPU data from RDTSCP */
20958 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20959 index 3909e3b..5433a97 100644
20960 --- a/arch/x86/kernel/x8664_ksyms_64.c
20961 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20962 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
20963
20964 EXPORT_SYMBOL(copy_user_generic);
20965 EXPORT_SYMBOL(__copy_user_nocache);
20966 -EXPORT_SYMBOL(copy_from_user);
20967 -EXPORT_SYMBOL(copy_to_user);
20968 EXPORT_SYMBOL(__copy_from_user_inatomic);
20969
20970 EXPORT_SYMBOL(copy_page);
20971 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20972 index c5ee17e..d63218f 100644
20973 --- a/arch/x86/kernel/xsave.c
20974 +++ b/arch/x86/kernel/xsave.c
20975 @@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20976 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20977 return -1;
20978
20979 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20980 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20981 fx_sw_user->extended_size -
20982 FP_XSTATE_MAGIC2_SIZE));
20983 /*
20984 @@ -196,7 +196,7 @@ fx_only:
20985 * the other extended state.
20986 */
20987 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20988 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20989 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20990 }
20991
20992 /*
20993 @@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf)
20994 if (task_thread_info(tsk)->status & TS_XSAVE)
20995 err = restore_user_xstate(buf);
20996 else
20997 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20998 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
20999 buf);
21000 if (unlikely(err)) {
21001 /*
21002 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21003 index 1350e43..a94b011 100644
21004 --- a/arch/x86/kvm/emulate.c
21005 +++ b/arch/x86/kvm/emulate.c
21006 @@ -81,8 +81,8 @@
21007 #define Src2CL (1<<29)
21008 #define Src2ImmByte (2<<29)
21009 #define Src2One (3<<29)
21010 -#define Src2Imm16 (4<<29)
21011 -#define Src2Mask (7<<29)
21012 +#define Src2Imm16 (4U<<29)
21013 +#define Src2Mask (7U<<29)
21014
21015 enum {
21016 Group1_80, Group1_81, Group1_82, Group1_83,
21017 @@ -411,6 +411,7 @@ static u32 group2_table[] = {
21018
21019 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
21020 do { \
21021 + unsigned long _tmp; \
21022 __asm__ __volatile__ ( \
21023 _PRE_EFLAGS("0", "4", "2") \
21024 _op _suffix " %"_x"3,%1; " \
21025 @@ -424,8 +425,6 @@ static u32 group2_table[] = {
21026 /* Raw emulation: instruction has two explicit operands. */
21027 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
21028 do { \
21029 - unsigned long _tmp; \
21030 - \
21031 switch ((_dst).bytes) { \
21032 case 2: \
21033 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
21034 @@ -441,7 +440,6 @@ static u32 group2_table[] = {
21035
21036 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21037 do { \
21038 - unsigned long _tmp; \
21039 switch ((_dst).bytes) { \
21040 case 1: \
21041 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
21042 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21043 index 8dfeaaa..4daa395 100644
21044 --- a/arch/x86/kvm/lapic.c
21045 +++ b/arch/x86/kvm/lapic.c
21046 @@ -52,7 +52,7 @@
21047 #define APIC_BUS_CYCLE_NS 1
21048
21049 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21050 -#define apic_debug(fmt, arg...)
21051 +#define apic_debug(fmt, arg...) do {} while (0)
21052
21053 #define APIC_LVT_NUM 6
21054 /* 14 is the version for Xeon and Pentium 8.4.8*/
21055 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21056 index 3bc2707..dd157e2 100644
21057 --- a/arch/x86/kvm/paging_tmpl.h
21058 +++ b/arch/x86/kvm/paging_tmpl.h
21059 @@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
21060 int level = PT_PAGE_TABLE_LEVEL;
21061 unsigned long mmu_seq;
21062
21063 + pax_track_stack();
21064 +
21065 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
21066 kvm_mmu_audit(vcpu, "pre page fault");
21067
21068 @@ -461,6 +463,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
21069 kvm_mmu_free_some_pages(vcpu);
21070 sptep = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault,
21071 level, &write_pt, pfn);
21072 + (void)sptep;
21073 pgprintk("%s: shadow pte %p %llx ptwrite %d\n", __func__,
21074 sptep, *sptep, write_pt);
21075
21076 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21077 index 7c6e63e..c5d92c1 100644
21078 --- a/arch/x86/kvm/svm.c
21079 +++ b/arch/x86/kvm/svm.c
21080 @@ -2486,7 +2486,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21081 int cpu = raw_smp_processor_id();
21082
21083 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
21084 +
21085 + pax_open_kernel();
21086 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
21087 + pax_close_kernel();
21088 +
21089 load_TR_desc();
21090 }
21091
21092 @@ -2947,7 +2951,7 @@ static bool svm_gb_page_enable(void)
21093 return true;
21094 }
21095
21096 -static struct kvm_x86_ops svm_x86_ops = {
21097 +static const struct kvm_x86_ops svm_x86_ops = {
21098 .cpu_has_kvm_support = has_svm,
21099 .disabled_by_bios = is_disabled,
21100 .hardware_setup = svm_hardware_setup,
21101 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21102 index e6d925f..e7a4af8 100644
21103 --- a/arch/x86/kvm/vmx.c
21104 +++ b/arch/x86/kvm/vmx.c
21105 @@ -570,7 +570,11 @@ static void reload_tss(void)
21106
21107 kvm_get_gdt(&gdt);
21108 descs = (void *)gdt.base;
21109 +
21110 + pax_open_kernel();
21111 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21112 + pax_close_kernel();
21113 +
21114 load_TR_desc();
21115 }
21116
21117 @@ -1410,8 +1414,11 @@ static __init int hardware_setup(void)
21118 if (!cpu_has_vmx_flexpriority())
21119 flexpriority_enabled = 0;
21120
21121 - if (!cpu_has_vmx_tpr_shadow())
21122 - kvm_x86_ops->update_cr8_intercept = NULL;
21123 + if (!cpu_has_vmx_tpr_shadow()) {
21124 + pax_open_kernel();
21125 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21126 + pax_close_kernel();
21127 + }
21128
21129 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21130 kvm_disable_largepages();
21131 @@ -2362,7 +2369,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
21132 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
21133
21134 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
21135 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
21136 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
21137 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
21138 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
21139 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
21140 @@ -3718,6 +3725,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21141 "jmp .Lkvm_vmx_return \n\t"
21142 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
21143 ".Lkvm_vmx_return: "
21144 +
21145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21146 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
21147 + ".Lkvm_vmx_return2: "
21148 +#endif
21149 +
21150 /* Save guest registers, load host registers, keep flags */
21151 "xchg %0, (%%"R"sp) \n\t"
21152 "mov %%"R"ax, %c[rax](%0) \n\t"
21153 @@ -3764,8 +3777,13 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21154 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
21155 #endif
21156 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
21157 +
21158 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21159 + ,[cs]"i"(__KERNEL_CS)
21160 +#endif
21161 +
21162 : "cc", "memory"
21163 - , R"bx", R"di", R"si"
21164 + , R"ax", R"bx", R"di", R"si"
21165 #ifdef CONFIG_X86_64
21166 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
21167 #endif
21168 @@ -3782,7 +3800,16 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21169 if (vmx->rmode.irq.pending)
21170 fixup_rmode_irq(vmx);
21171
21172 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
21173 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
21174 +
21175 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21176 + loadsegment(fs, __KERNEL_PERCPU);
21177 +#endif
21178 +
21179 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21180 + __set_fs(current_thread_info()->addr_limit);
21181 +#endif
21182 +
21183 vmx->launched = 1;
21184
21185 vmx_complete_interrupts(vmx);
21186 @@ -3957,7 +3984,7 @@ static bool vmx_gb_page_enable(void)
21187 return false;
21188 }
21189
21190 -static struct kvm_x86_ops vmx_x86_ops = {
21191 +static const struct kvm_x86_ops vmx_x86_ops = {
21192 .cpu_has_kvm_support = cpu_has_kvm_support,
21193 .disabled_by_bios = vmx_disabled_by_bios,
21194 .hardware_setup = hardware_setup,
21195 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21196 index df1cefb..5e882ad 100644
21197 --- a/arch/x86/kvm/x86.c
21198 +++ b/arch/x86/kvm/x86.c
21199 @@ -82,7 +82,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu);
21200 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
21201 struct kvm_cpuid_entry2 __user *entries);
21202
21203 -struct kvm_x86_ops *kvm_x86_ops;
21204 +const struct kvm_x86_ops *kvm_x86_ops;
21205 EXPORT_SYMBOL_GPL(kvm_x86_ops);
21206
21207 int ignore_msrs = 0;
21208 @@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21209 struct kvm_cpuid2 *cpuid,
21210 struct kvm_cpuid_entry2 __user *entries)
21211 {
21212 - int r;
21213 + int r, i;
21214
21215 r = -E2BIG;
21216 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21217 goto out;
21218 r = -EFAULT;
21219 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21220 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21221 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21222 goto out;
21223 + for (i = 0; i < cpuid->nent; ++i) {
21224 + struct kvm_cpuid_entry2 cpuid_entry;
21225 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21226 + goto out;
21227 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21228 + }
21229 vcpu->arch.cpuid_nent = cpuid->nent;
21230 kvm_apic_set_version(vcpu);
21231 return 0;
21232 @@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21233 struct kvm_cpuid2 *cpuid,
21234 struct kvm_cpuid_entry2 __user *entries)
21235 {
21236 - int r;
21237 + int r, i;
21238
21239 vcpu_load(vcpu);
21240 r = -E2BIG;
21241 if (cpuid->nent < vcpu->arch.cpuid_nent)
21242 goto out;
21243 r = -EFAULT;
21244 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21245 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21246 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21247 goto out;
21248 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21249 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21250 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21251 + goto out;
21252 + }
21253 return 0;
21254
21255 out:
21256 @@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
21257 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
21258 struct kvm_interrupt *irq)
21259 {
21260 - if (irq->irq < 0 || irq->irq >= 256)
21261 + if (irq->irq >= 256)
21262 return -EINVAL;
21263 if (irqchip_in_kernel(vcpu->kvm))
21264 return -ENXIO;
21265 @@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cpufreq_notifier_block = {
21266 .notifier_call = kvmclock_cpufreq_notifier
21267 };
21268
21269 -int kvm_arch_init(void *opaque)
21270 +int kvm_arch_init(const void *opaque)
21271 {
21272 int r, cpu;
21273 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
21274 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
21275
21276 if (kvm_x86_ops) {
21277 printk(KERN_ERR "kvm: already loaded the other module\n");
21278 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21279 index 7e59dc1..b88c98f 100644
21280 --- a/arch/x86/lguest/boot.c
21281 +++ b/arch/x86/lguest/boot.c
21282 @@ -1172,9 +1172,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
21283 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
21284 * Launcher to reboot us.
21285 */
21286 -static void lguest_restart(char *reason)
21287 +static __noreturn void lguest_restart(char *reason)
21288 {
21289 kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART);
21290 + BUG();
21291 }
21292
21293 /*G:050
21294 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
21295 index 824fa0b..c619e96 100644
21296 --- a/arch/x86/lib/atomic64_32.c
21297 +++ b/arch/x86/lib/atomic64_32.c
21298 @@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val)
21299 }
21300 EXPORT_SYMBOL(atomic64_cmpxchg);
21301
21302 +u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
21303 +{
21304 + return cmpxchg8b(&ptr->counter, old_val, new_val);
21305 +}
21306 +EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
21307 +
21308 /**
21309 * atomic64_xchg - xchg atomic64 variable
21310 * @ptr: pointer to type atomic64_t
21311 @@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 new_val)
21312 EXPORT_SYMBOL(atomic64_xchg);
21313
21314 /**
21315 + * atomic64_xchg_unchecked - xchg atomic64 variable
21316 + * @ptr: pointer to type atomic64_unchecked_t
21317 + * @new_val: value to assign
21318 + *
21319 + * Atomically xchgs the value of @ptr to @new_val and returns
21320 + * the old value.
21321 + */
21322 +u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
21323 +{
21324 + /*
21325 + * Try first with a (possibly incorrect) assumption about
21326 + * what we have there. We'll do two loops most likely,
21327 + * but we'll get an ownership MESI transaction straight away
21328 + * instead of a read transaction followed by a
21329 + * flush-for-ownership transaction:
21330 + */
21331 + u64 old_val, real_val = 0;
21332 +
21333 + do {
21334 + old_val = real_val;
21335 +
21336 + real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
21337 +
21338 + } while (real_val != old_val);
21339 +
21340 + return old_val;
21341 +}
21342 +EXPORT_SYMBOL(atomic64_xchg_unchecked);
21343 +
21344 +/**
21345 * atomic64_set - set atomic64 variable
21346 * @ptr: pointer to type atomic64_t
21347 * @new_val: value to assign
21348 @@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 new_val)
21349 EXPORT_SYMBOL(atomic64_set);
21350
21351 /**
21352 -EXPORT_SYMBOL(atomic64_read);
21353 + * atomic64_unchecked_set - set atomic64 variable
21354 + * @ptr: pointer to type atomic64_unchecked_t
21355 + * @new_val: value to assign
21356 + *
21357 + * Atomically sets the value of @ptr to @new_val.
21358 + */
21359 +void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
21360 +{
21361 + atomic64_xchg_unchecked(ptr, new_val);
21362 +}
21363 +EXPORT_SYMBOL(atomic64_set_unchecked);
21364 +
21365 +/**
21366 * atomic64_add_return - add and return
21367 * @delta: integer value to add
21368 * @ptr: pointer to type atomic64_t
21369 @@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 delta, atomic64_t *ptr)
21370 }
21371 EXPORT_SYMBOL(atomic64_add_return);
21372
21373 +/**
21374 + * atomic64_add_return_unchecked - add and return
21375 + * @delta: integer value to add
21376 + * @ptr: pointer to type atomic64_unchecked_t
21377 + *
21378 + * Atomically adds @delta to @ptr and returns @delta + *@ptr
21379 + */
21380 +noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21381 +{
21382 + /*
21383 + * Try first with a (possibly incorrect) assumption about
21384 + * what we have there. We'll do two loops most likely,
21385 + * but we'll get an ownership MESI transaction straight away
21386 + * instead of a read transaction followed by a
21387 + * flush-for-ownership transaction:
21388 + */
21389 + u64 old_val, new_val, real_val = 0;
21390 +
21391 + do {
21392 + old_val = real_val;
21393 + new_val = old_val + delta;
21394 +
21395 + real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
21396 +
21397 + } while (real_val != old_val);
21398 +
21399 + return new_val;
21400 +}
21401 +EXPORT_SYMBOL(atomic64_add_return_unchecked);
21402 +
21403 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
21404 {
21405 return atomic64_add_return(-delta, ptr);
21406 }
21407 EXPORT_SYMBOL(atomic64_sub_return);
21408
21409 +u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21410 +{
21411 + return atomic64_add_return_unchecked(-delta, ptr);
21412 +}
21413 +EXPORT_SYMBOL(atomic64_sub_return_unchecked);
21414 +
21415 u64 atomic64_inc_return(atomic64_t *ptr)
21416 {
21417 return atomic64_add_return(1, ptr);
21418 }
21419 EXPORT_SYMBOL(atomic64_inc_return);
21420
21421 +u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
21422 +{
21423 + return atomic64_add_return_unchecked(1, ptr);
21424 +}
21425 +EXPORT_SYMBOL(atomic64_inc_return_unchecked);
21426 +
21427 u64 atomic64_dec_return(atomic64_t *ptr)
21428 {
21429 return atomic64_sub_return(1, ptr);
21430 }
21431 EXPORT_SYMBOL(atomic64_dec_return);
21432
21433 +u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
21434 +{
21435 + return atomic64_sub_return_unchecked(1, ptr);
21436 +}
21437 +EXPORT_SYMBOL(atomic64_dec_return_unchecked);
21438 +
21439 /**
21440 * atomic64_add - add integer to atomic64 variable
21441 * @delta: integer value to add
21442 @@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t *ptr)
21443 EXPORT_SYMBOL(atomic64_add);
21444
21445 /**
21446 + * atomic64_add_unchecked - add integer to atomic64 variable
21447 + * @delta: integer value to add
21448 + * @ptr: pointer to type atomic64_unchecked_t
21449 + *
21450 + * Atomically adds @delta to @ptr.
21451 + */
21452 +void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21453 +{
21454 + atomic64_add_return_unchecked(delta, ptr);
21455 +}
21456 +EXPORT_SYMBOL(atomic64_add_unchecked);
21457 +
21458 +/**
21459 * atomic64_sub - subtract the atomic64 variable
21460 * @delta: integer value to subtract
21461 * @ptr: pointer to type atomic64_t
21462 @@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t *ptr)
21463 EXPORT_SYMBOL(atomic64_sub);
21464
21465 /**
21466 + * atomic64_sub_unchecked - subtract the atomic64 variable
21467 + * @delta: integer value to subtract
21468 + * @ptr: pointer to type atomic64_unchecked_t
21469 + *
21470 + * Atomically subtracts @delta from @ptr.
21471 + */
21472 +void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21473 +{
21474 + atomic64_add_unchecked(-delta, ptr);
21475 +}
21476 +EXPORT_SYMBOL(atomic64_sub_unchecked);
21477 +
21478 +/**
21479 * atomic64_sub_and_test - subtract value from variable and test result
21480 * @delta: integer value to subtract
21481 * @ptr: pointer to type atomic64_t
21482 @@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
21483 EXPORT_SYMBOL(atomic64_inc);
21484
21485 /**
21486 + * atomic64_inc_unchecked - increment atomic64 variable
21487 + * @ptr: pointer to type atomic64_unchecked_t
21488 + *
21489 + * Atomically increments @ptr by 1.
21490 + */
21491 +void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
21492 +{
21493 + atomic64_add_unchecked(1, ptr);
21494 +}
21495 +EXPORT_SYMBOL(atomic64_inc_unchecked);
21496 +
21497 +/**
21498 * atomic64_dec - decrement atomic64 variable
21499 * @ptr: pointer to type atomic64_t
21500 *
21501 @@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
21502 EXPORT_SYMBOL(atomic64_dec);
21503
21504 /**
21505 + * atomic64_dec_unchecked - decrement atomic64 variable
21506 + * @ptr: pointer to type atomic64_unchecked_t
21507 + *
21508 + * Atomically decrements @ptr by 1.
21509 + */
21510 +void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
21511 +{
21512 + atomic64_sub_unchecked(1, ptr);
21513 +}
21514 +EXPORT_SYMBOL(atomic64_dec_unchecked);
21515 +
21516 +/**
21517 * atomic64_dec_and_test - decrement and test
21518 * @ptr: pointer to type atomic64_t
21519 *
21520 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21521 index adbccd0..98f96c8 100644
21522 --- a/arch/x86/lib/checksum_32.S
21523 +++ b/arch/x86/lib/checksum_32.S
21524 @@ -28,7 +28,8 @@
21525 #include <linux/linkage.h>
21526 #include <asm/dwarf2.h>
21527 #include <asm/errno.h>
21528 -
21529 +#include <asm/segment.h>
21530 +
21531 /*
21532 * computes a partial checksum, e.g. for TCP/UDP fragments
21533 */
21534 @@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21535
21536 #define ARGBASE 16
21537 #define FP 12
21538 -
21539 -ENTRY(csum_partial_copy_generic)
21540 +
21541 +ENTRY(csum_partial_copy_generic_to_user)
21542 CFI_STARTPROC
21543 +
21544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21545 + pushl %gs
21546 + CFI_ADJUST_CFA_OFFSET 4
21547 + popl %es
21548 + CFI_ADJUST_CFA_OFFSET -4
21549 + jmp csum_partial_copy_generic
21550 +#endif
21551 +
21552 +ENTRY(csum_partial_copy_generic_from_user)
21553 +
21554 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21555 + pushl %gs
21556 + CFI_ADJUST_CFA_OFFSET 4
21557 + popl %ds
21558 + CFI_ADJUST_CFA_OFFSET -4
21559 +#endif
21560 +
21561 +ENTRY(csum_partial_copy_generic)
21562 subl $4,%esp
21563 CFI_ADJUST_CFA_OFFSET 4
21564 pushl %edi
21565 @@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
21566 jmp 4f
21567 SRC(1: movw (%esi), %bx )
21568 addl $2, %esi
21569 -DST( movw %bx, (%edi) )
21570 +DST( movw %bx, %es:(%edi) )
21571 addl $2, %edi
21572 addw %bx, %ax
21573 adcl $0, %eax
21574 @@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
21575 SRC(1: movl (%esi), %ebx )
21576 SRC( movl 4(%esi), %edx )
21577 adcl %ebx, %eax
21578 -DST( movl %ebx, (%edi) )
21579 +DST( movl %ebx, %es:(%edi) )
21580 adcl %edx, %eax
21581 -DST( movl %edx, 4(%edi) )
21582 +DST( movl %edx, %es:4(%edi) )
21583
21584 SRC( movl 8(%esi), %ebx )
21585 SRC( movl 12(%esi), %edx )
21586 adcl %ebx, %eax
21587 -DST( movl %ebx, 8(%edi) )
21588 +DST( movl %ebx, %es:8(%edi) )
21589 adcl %edx, %eax
21590 -DST( movl %edx, 12(%edi) )
21591 +DST( movl %edx, %es:12(%edi) )
21592
21593 SRC( movl 16(%esi), %ebx )
21594 SRC( movl 20(%esi), %edx )
21595 adcl %ebx, %eax
21596 -DST( movl %ebx, 16(%edi) )
21597 +DST( movl %ebx, %es:16(%edi) )
21598 adcl %edx, %eax
21599 -DST( movl %edx, 20(%edi) )
21600 +DST( movl %edx, %es:20(%edi) )
21601
21602 SRC( movl 24(%esi), %ebx )
21603 SRC( movl 28(%esi), %edx )
21604 adcl %ebx, %eax
21605 -DST( movl %ebx, 24(%edi) )
21606 +DST( movl %ebx, %es:24(%edi) )
21607 adcl %edx, %eax
21608 -DST( movl %edx, 28(%edi) )
21609 +DST( movl %edx, %es:28(%edi) )
21610
21611 lea 32(%esi), %esi
21612 lea 32(%edi), %edi
21613 @@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
21614 shrl $2, %edx # This clears CF
21615 SRC(3: movl (%esi), %ebx )
21616 adcl %ebx, %eax
21617 -DST( movl %ebx, (%edi) )
21618 +DST( movl %ebx, %es:(%edi) )
21619 lea 4(%esi), %esi
21620 lea 4(%edi), %edi
21621 dec %edx
21622 @@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
21623 jb 5f
21624 SRC( movw (%esi), %cx )
21625 leal 2(%esi), %esi
21626 -DST( movw %cx, (%edi) )
21627 +DST( movw %cx, %es:(%edi) )
21628 leal 2(%edi), %edi
21629 je 6f
21630 shll $16,%ecx
21631 SRC(5: movb (%esi), %cl )
21632 -DST( movb %cl, (%edi) )
21633 +DST( movb %cl, %es:(%edi) )
21634 6: addl %ecx, %eax
21635 adcl $0, %eax
21636 7:
21637 @@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
21638
21639 6001:
21640 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21641 - movl $-EFAULT, (%ebx)
21642 + movl $-EFAULT, %ss:(%ebx)
21643
21644 # zero the complete destination - computing the rest
21645 # is too much work
21646 @@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
21647
21648 6002:
21649 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21650 - movl $-EFAULT,(%ebx)
21651 + movl $-EFAULT,%ss:(%ebx)
21652 jmp 5000b
21653
21654 .previous
21655
21656 + pushl %ss
21657 + CFI_ADJUST_CFA_OFFSET 4
21658 + popl %ds
21659 + CFI_ADJUST_CFA_OFFSET -4
21660 + pushl %ss
21661 + CFI_ADJUST_CFA_OFFSET 4
21662 + popl %es
21663 + CFI_ADJUST_CFA_OFFSET -4
21664 popl %ebx
21665 CFI_ADJUST_CFA_OFFSET -4
21666 CFI_RESTORE ebx
21667 @@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
21668 CFI_ADJUST_CFA_OFFSET -4
21669 ret
21670 CFI_ENDPROC
21671 -ENDPROC(csum_partial_copy_generic)
21672 +ENDPROC(csum_partial_copy_generic_to_user)
21673
21674 #else
21675
21676 /* Version for PentiumII/PPro */
21677
21678 #define ROUND1(x) \
21679 + nop; nop; nop; \
21680 SRC(movl x(%esi), %ebx ) ; \
21681 addl %ebx, %eax ; \
21682 - DST(movl %ebx, x(%edi) ) ;
21683 + DST(movl %ebx, %es:x(%edi)) ;
21684
21685 #define ROUND(x) \
21686 + nop; nop; nop; \
21687 SRC(movl x(%esi), %ebx ) ; \
21688 adcl %ebx, %eax ; \
21689 - DST(movl %ebx, x(%edi) ) ;
21690 + DST(movl %ebx, %es:x(%edi)) ;
21691
21692 #define ARGBASE 12
21693 -
21694 -ENTRY(csum_partial_copy_generic)
21695 +
21696 +ENTRY(csum_partial_copy_generic_to_user)
21697 CFI_STARTPROC
21698 +
21699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21700 + pushl %gs
21701 + CFI_ADJUST_CFA_OFFSET 4
21702 + popl %es
21703 + CFI_ADJUST_CFA_OFFSET -4
21704 + jmp csum_partial_copy_generic
21705 +#endif
21706 +
21707 +ENTRY(csum_partial_copy_generic_from_user)
21708 +
21709 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21710 + pushl %gs
21711 + CFI_ADJUST_CFA_OFFSET 4
21712 + popl %ds
21713 + CFI_ADJUST_CFA_OFFSET -4
21714 +#endif
21715 +
21716 +ENTRY(csum_partial_copy_generic)
21717 pushl %ebx
21718 CFI_ADJUST_CFA_OFFSET 4
21719 CFI_REL_OFFSET ebx, 0
21720 @@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
21721 subl %ebx, %edi
21722 lea -1(%esi),%edx
21723 andl $-32,%edx
21724 - lea 3f(%ebx,%ebx), %ebx
21725 + lea 3f(%ebx,%ebx,2), %ebx
21726 testl %esi, %esi
21727 jmp *%ebx
21728 1: addl $64,%esi
21729 @@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
21730 jb 5f
21731 SRC( movw (%esi), %dx )
21732 leal 2(%esi), %esi
21733 -DST( movw %dx, (%edi) )
21734 +DST( movw %dx, %es:(%edi) )
21735 leal 2(%edi), %edi
21736 je 6f
21737 shll $16,%edx
21738 5:
21739 SRC( movb (%esi), %dl )
21740 -DST( movb %dl, (%edi) )
21741 +DST( movb %dl, %es:(%edi) )
21742 6: addl %edx, %eax
21743 adcl $0, %eax
21744 7:
21745 .section .fixup, "ax"
21746 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21747 - movl $-EFAULT, (%ebx)
21748 + movl $-EFAULT, %ss:(%ebx)
21749 # zero the complete destination (computing the rest is too much work)
21750 movl ARGBASE+8(%esp),%edi # dst
21751 movl ARGBASE+12(%esp),%ecx # len
21752 @@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
21753 rep; stosb
21754 jmp 7b
21755 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21756 - movl $-EFAULT, (%ebx)
21757 + movl $-EFAULT, %ss:(%ebx)
21758 jmp 7b
21759 .previous
21760
21761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21762 + pushl %ss
21763 + CFI_ADJUST_CFA_OFFSET 4
21764 + popl %ds
21765 + CFI_ADJUST_CFA_OFFSET -4
21766 + pushl %ss
21767 + CFI_ADJUST_CFA_OFFSET 4
21768 + popl %es
21769 + CFI_ADJUST_CFA_OFFSET -4
21770 +#endif
21771 +
21772 popl %esi
21773 CFI_ADJUST_CFA_OFFSET -4
21774 CFI_RESTORE esi
21775 @@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
21776 CFI_RESTORE ebx
21777 ret
21778 CFI_ENDPROC
21779 -ENDPROC(csum_partial_copy_generic)
21780 +ENDPROC(csum_partial_copy_generic_to_user)
21781
21782 #undef ROUND
21783 #undef ROUND1
21784 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21785 index ebeafcc..1e3a402 100644
21786 --- a/arch/x86/lib/clear_page_64.S
21787 +++ b/arch/x86/lib/clear_page_64.S
21788 @@ -1,5 +1,6 @@
21789 #include <linux/linkage.h>
21790 #include <asm/dwarf2.h>
21791 +#include <asm/alternative-asm.h>
21792
21793 /*
21794 * Zero a page.
21795 @@ -10,6 +11,7 @@ ENTRY(clear_page_c)
21796 movl $4096/8,%ecx
21797 xorl %eax,%eax
21798 rep stosq
21799 + pax_force_retaddr
21800 ret
21801 CFI_ENDPROC
21802 ENDPROC(clear_page_c)
21803 @@ -33,6 +35,7 @@ ENTRY(clear_page)
21804 leaq 64(%rdi),%rdi
21805 jnz .Lloop
21806 nop
21807 + pax_force_retaddr
21808 ret
21809 CFI_ENDPROC
21810 .Lclear_page_end:
21811 @@ -43,7 +46,7 @@ ENDPROC(clear_page)
21812
21813 #include <asm/cpufeature.h>
21814
21815 - .section .altinstr_replacement,"ax"
21816 + .section .altinstr_replacement,"a"
21817 1: .byte 0xeb /* jmp <disp8> */
21818 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21819 2:
21820 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21821 index 727a5d4..333818a 100644
21822 --- a/arch/x86/lib/copy_page_64.S
21823 +++ b/arch/x86/lib/copy_page_64.S
21824 @@ -2,12 +2,14 @@
21825
21826 #include <linux/linkage.h>
21827 #include <asm/dwarf2.h>
21828 +#include <asm/alternative-asm.h>
21829
21830 ALIGN
21831 copy_page_c:
21832 CFI_STARTPROC
21833 movl $4096/8,%ecx
21834 rep movsq
21835 + pax_force_retaddr
21836 ret
21837 CFI_ENDPROC
21838 ENDPROC(copy_page_c)
21839 @@ -38,7 +40,7 @@ ENTRY(copy_page)
21840 movq 16 (%rsi), %rdx
21841 movq 24 (%rsi), %r8
21842 movq 32 (%rsi), %r9
21843 - movq 40 (%rsi), %r10
21844 + movq 40 (%rsi), %r13
21845 movq 48 (%rsi), %r11
21846 movq 56 (%rsi), %r12
21847
21848 @@ -49,7 +51,7 @@ ENTRY(copy_page)
21849 movq %rdx, 16 (%rdi)
21850 movq %r8, 24 (%rdi)
21851 movq %r9, 32 (%rdi)
21852 - movq %r10, 40 (%rdi)
21853 + movq %r13, 40 (%rdi)
21854 movq %r11, 48 (%rdi)
21855 movq %r12, 56 (%rdi)
21856
21857 @@ -68,7 +70,7 @@ ENTRY(copy_page)
21858 movq 16 (%rsi), %rdx
21859 movq 24 (%rsi), %r8
21860 movq 32 (%rsi), %r9
21861 - movq 40 (%rsi), %r10
21862 + movq 40 (%rsi), %r13
21863 movq 48 (%rsi), %r11
21864 movq 56 (%rsi), %r12
21865
21866 @@ -77,7 +79,7 @@ ENTRY(copy_page)
21867 movq %rdx, 16 (%rdi)
21868 movq %r8, 24 (%rdi)
21869 movq %r9, 32 (%rdi)
21870 - movq %r10, 40 (%rdi)
21871 + movq %r13, 40 (%rdi)
21872 movq %r11, 48 (%rdi)
21873 movq %r12, 56 (%rdi)
21874
21875 @@ -94,6 +96,7 @@ ENTRY(copy_page)
21876 CFI_RESTORE r13
21877 addq $3*8,%rsp
21878 CFI_ADJUST_CFA_OFFSET -3*8
21879 + pax_force_retaddr
21880 ret
21881 .Lcopy_page_end:
21882 CFI_ENDPROC
21883 @@ -104,7 +107,7 @@ ENDPROC(copy_page)
21884
21885 #include <asm/cpufeature.h>
21886
21887 - .section .altinstr_replacement,"ax"
21888 + .section .altinstr_replacement,"a"
21889 1: .byte 0xeb /* jmp <disp8> */
21890 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21891 2:
21892 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21893 index af8debd..40c75f3 100644
21894 --- a/arch/x86/lib/copy_user_64.S
21895 +++ b/arch/x86/lib/copy_user_64.S
21896 @@ -15,13 +15,15 @@
21897 #include <asm/asm-offsets.h>
21898 #include <asm/thread_info.h>
21899 #include <asm/cpufeature.h>
21900 +#include <asm/pgtable.h>
21901 +#include <asm/alternative-asm.h>
21902
21903 .macro ALTERNATIVE_JUMP feature,orig,alt
21904 0:
21905 .byte 0xe9 /* 32bit jump */
21906 .long \orig-1f /* by default jump to orig */
21907 1:
21908 - .section .altinstr_replacement,"ax"
21909 + .section .altinstr_replacement,"a"
21910 2: .byte 0xe9 /* near jump with 32bit immediate */
21911 .long \alt-1b /* offset */ /* or alternatively to alt */
21912 .previous
21913 @@ -64,55 +66,26 @@
21914 #endif
21915 .endm
21916
21917 -/* Standard copy_to_user with segment limit checking */
21918 -ENTRY(copy_to_user)
21919 - CFI_STARTPROC
21920 - GET_THREAD_INFO(%rax)
21921 - movq %rdi,%rcx
21922 - addq %rdx,%rcx
21923 - jc bad_to_user
21924 - cmpq TI_addr_limit(%rax),%rcx
21925 - ja bad_to_user
21926 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21927 - CFI_ENDPROC
21928 -ENDPROC(copy_to_user)
21929 -
21930 -/* Standard copy_from_user with segment limit checking */
21931 -ENTRY(copy_from_user)
21932 - CFI_STARTPROC
21933 - GET_THREAD_INFO(%rax)
21934 - movq %rsi,%rcx
21935 - addq %rdx,%rcx
21936 - jc bad_from_user
21937 - cmpq TI_addr_limit(%rax),%rcx
21938 - ja bad_from_user
21939 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21940 - CFI_ENDPROC
21941 -ENDPROC(copy_from_user)
21942 -
21943 ENTRY(copy_user_generic)
21944 CFI_STARTPROC
21945 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21946 CFI_ENDPROC
21947 ENDPROC(copy_user_generic)
21948
21949 -ENTRY(__copy_from_user_inatomic)
21950 - CFI_STARTPROC
21951 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21952 - CFI_ENDPROC
21953 -ENDPROC(__copy_from_user_inatomic)
21954 -
21955 .section .fixup,"ax"
21956 /* must zero dest */
21957 ENTRY(bad_from_user)
21958 bad_from_user:
21959 CFI_STARTPROC
21960 + testl %edx,%edx
21961 + js bad_to_user
21962 movl %edx,%ecx
21963 xorl %eax,%eax
21964 rep
21965 stosb
21966 bad_to_user:
21967 movl %edx,%eax
21968 + pax_force_retaddr
21969 ret
21970 CFI_ENDPROC
21971 ENDPROC(bad_from_user)
21972 @@ -142,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21973 jz 17f
21974 1: movq (%rsi),%r8
21975 2: movq 1*8(%rsi),%r9
21976 -3: movq 2*8(%rsi),%r10
21977 +3: movq 2*8(%rsi),%rax
21978 4: movq 3*8(%rsi),%r11
21979 5: movq %r8,(%rdi)
21980 6: movq %r9,1*8(%rdi)
21981 -7: movq %r10,2*8(%rdi)
21982 +7: movq %rax,2*8(%rdi)
21983 8: movq %r11,3*8(%rdi)
21984 9: movq 4*8(%rsi),%r8
21985 10: movq 5*8(%rsi),%r9
21986 -11: movq 6*8(%rsi),%r10
21987 +11: movq 6*8(%rsi),%rax
21988 12: movq 7*8(%rsi),%r11
21989 13: movq %r8,4*8(%rdi)
21990 14: movq %r9,5*8(%rdi)
21991 -15: movq %r10,6*8(%rdi)
21992 +15: movq %rax,6*8(%rdi)
21993 16: movq %r11,7*8(%rdi)
21994 leaq 64(%rsi),%rsi
21995 leaq 64(%rdi),%rdi
21996 @@ -180,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21997 decl %ecx
21998 jnz 21b
21999 23: xor %eax,%eax
22000 + pax_force_retaddr
22001 ret
22002
22003 .section .fixup,"ax"
22004 @@ -252,6 +226,7 @@ ENTRY(copy_user_generic_string)
22005 3: rep
22006 movsb
22007 4: xorl %eax,%eax
22008 + pax_force_retaddr
22009 ret
22010
22011 .section .fixup,"ax"
22012 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22013 index cb0c112..e3a6895 100644
22014 --- a/arch/x86/lib/copy_user_nocache_64.S
22015 +++ b/arch/x86/lib/copy_user_nocache_64.S
22016 @@ -8,12 +8,14 @@
22017
22018 #include <linux/linkage.h>
22019 #include <asm/dwarf2.h>
22020 +#include <asm/alternative-asm.h>
22021
22022 #define FIX_ALIGNMENT 1
22023
22024 #include <asm/current.h>
22025 #include <asm/asm-offsets.h>
22026 #include <asm/thread_info.h>
22027 +#include <asm/pgtable.h>
22028
22029 .macro ALIGN_DESTINATION
22030 #ifdef FIX_ALIGNMENT
22031 @@ -50,6 +52,15 @@
22032 */
22033 ENTRY(__copy_user_nocache)
22034 CFI_STARTPROC
22035 +
22036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22037 + mov $PAX_USER_SHADOW_BASE,%rcx
22038 + cmp %rcx,%rsi
22039 + jae 1f
22040 + add %rcx,%rsi
22041 +1:
22042 +#endif
22043 +
22044 cmpl $8,%edx
22045 jb 20f /* less then 8 bytes, go to byte copy loop */
22046 ALIGN_DESTINATION
22047 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
22048 jz 17f
22049 1: movq (%rsi),%r8
22050 2: movq 1*8(%rsi),%r9
22051 -3: movq 2*8(%rsi),%r10
22052 +3: movq 2*8(%rsi),%rax
22053 4: movq 3*8(%rsi),%r11
22054 5: movnti %r8,(%rdi)
22055 6: movnti %r9,1*8(%rdi)
22056 -7: movnti %r10,2*8(%rdi)
22057 +7: movnti %rax,2*8(%rdi)
22058 8: movnti %r11,3*8(%rdi)
22059 9: movq 4*8(%rsi),%r8
22060 10: movq 5*8(%rsi),%r9
22061 -11: movq 6*8(%rsi),%r10
22062 +11: movq 6*8(%rsi),%rax
22063 12: movq 7*8(%rsi),%r11
22064 13: movnti %r8,4*8(%rdi)
22065 14: movnti %r9,5*8(%rdi)
22066 -15: movnti %r10,6*8(%rdi)
22067 +15: movnti %rax,6*8(%rdi)
22068 16: movnti %r11,7*8(%rdi)
22069 leaq 64(%rsi),%rsi
22070 leaq 64(%rdi),%rdi
22071 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
22072 jnz 21b
22073 23: xorl %eax,%eax
22074 sfence
22075 + pax_force_retaddr
22076 ret
22077
22078 .section .fixup,"ax"
22079 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22080 index f0dba36..48cb4d6 100644
22081 --- a/arch/x86/lib/csum-copy_64.S
22082 +++ b/arch/x86/lib/csum-copy_64.S
22083 @@ -8,6 +8,7 @@
22084 #include <linux/linkage.h>
22085 #include <asm/dwarf2.h>
22086 #include <asm/errno.h>
22087 +#include <asm/alternative-asm.h>
22088
22089 /*
22090 * Checksum copy with exception handling.
22091 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
22092 CFI_RESTORE rbp
22093 addq $7*8,%rsp
22094 CFI_ADJUST_CFA_OFFSET -7*8
22095 + pax_force_retaddr 0, 1
22096 ret
22097 CFI_RESTORE_STATE
22098
22099 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22100 index 459b58a..9570bc7 100644
22101 --- a/arch/x86/lib/csum-wrappers_64.c
22102 +++ b/arch/x86/lib/csum-wrappers_64.c
22103 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
22104 len -= 2;
22105 }
22106 }
22107 - isum = csum_partial_copy_generic((__force const void *)src,
22108 +
22109 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22110 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22111 + src += PAX_USER_SHADOW_BASE;
22112 +#endif
22113 +
22114 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
22115 dst, len, isum, errp, NULL);
22116 if (unlikely(*errp))
22117 goto out_err;
22118 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
22119 }
22120
22121 *errp = 0;
22122 - return csum_partial_copy_generic(src, (void __force *)dst,
22123 +
22124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22125 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
22126 + dst += PAX_USER_SHADOW_BASE;
22127 +#endif
22128 +
22129 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
22130 len, isum, NULL, errp);
22131 }
22132 EXPORT_SYMBOL(csum_partial_copy_to_user);
22133 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22134 index 51f1504..ddac4c1 100644
22135 --- a/arch/x86/lib/getuser.S
22136 +++ b/arch/x86/lib/getuser.S
22137 @@ -33,15 +33,38 @@
22138 #include <asm/asm-offsets.h>
22139 #include <asm/thread_info.h>
22140 #include <asm/asm.h>
22141 +#include <asm/segment.h>
22142 +#include <asm/pgtable.h>
22143 +#include <asm/alternative-asm.h>
22144 +
22145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22146 +#define __copyuser_seg gs;
22147 +#else
22148 +#define __copyuser_seg
22149 +#endif
22150
22151 .text
22152 ENTRY(__get_user_1)
22153 CFI_STARTPROC
22154 +
22155 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22156 GET_THREAD_INFO(%_ASM_DX)
22157 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22158 jae bad_get_user
22159 -1: movzb (%_ASM_AX),%edx
22160 +
22161 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22162 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22163 + cmp %_ASM_DX,%_ASM_AX
22164 + jae 1234f
22165 + add %_ASM_DX,%_ASM_AX
22166 +1234:
22167 +#endif
22168 +
22169 +#endif
22170 +
22171 +1: __copyuser_seg movzb (%_ASM_AX),%edx
22172 xor %eax,%eax
22173 + pax_force_retaddr
22174 ret
22175 CFI_ENDPROC
22176 ENDPROC(__get_user_1)
22177 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
22178 ENTRY(__get_user_2)
22179 CFI_STARTPROC
22180 add $1,%_ASM_AX
22181 +
22182 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22183 jc bad_get_user
22184 GET_THREAD_INFO(%_ASM_DX)
22185 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22186 jae bad_get_user
22187 -2: movzwl -1(%_ASM_AX),%edx
22188 +
22189 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22190 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22191 + cmp %_ASM_DX,%_ASM_AX
22192 + jae 1234f
22193 + add %_ASM_DX,%_ASM_AX
22194 +1234:
22195 +#endif
22196 +
22197 +#endif
22198 +
22199 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22200 xor %eax,%eax
22201 + pax_force_retaddr
22202 ret
22203 CFI_ENDPROC
22204 ENDPROC(__get_user_2)
22205 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
22206 ENTRY(__get_user_4)
22207 CFI_STARTPROC
22208 add $3,%_ASM_AX
22209 +
22210 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22211 jc bad_get_user
22212 GET_THREAD_INFO(%_ASM_DX)
22213 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22214 jae bad_get_user
22215 -3: mov -3(%_ASM_AX),%edx
22216 +
22217 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22218 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22219 + cmp %_ASM_DX,%_ASM_AX
22220 + jae 1234f
22221 + add %_ASM_DX,%_ASM_AX
22222 +1234:
22223 +#endif
22224 +
22225 +#endif
22226 +
22227 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
22228 xor %eax,%eax
22229 + pax_force_retaddr
22230 ret
22231 CFI_ENDPROC
22232 ENDPROC(__get_user_4)
22233 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22234 GET_THREAD_INFO(%_ASM_DX)
22235 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22236 jae bad_get_user
22237 +
22238 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22239 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22240 + cmp %_ASM_DX,%_ASM_AX
22241 + jae 1234f
22242 + add %_ASM_DX,%_ASM_AX
22243 +1234:
22244 +#endif
22245 +
22246 4: movq -7(%_ASM_AX),%_ASM_DX
22247 xor %eax,%eax
22248 + pax_force_retaddr
22249 ret
22250 CFI_ENDPROC
22251 ENDPROC(__get_user_8)
22252 @@ -91,6 +152,7 @@ bad_get_user:
22253 CFI_STARTPROC
22254 xor %edx,%edx
22255 mov $(-EFAULT),%_ASM_AX
22256 + pax_force_retaddr
22257 ret
22258 CFI_ENDPROC
22259 END(bad_get_user)
22260 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22261 index 05a95e7..326f2fa 100644
22262 --- a/arch/x86/lib/iomap_copy_64.S
22263 +++ b/arch/x86/lib/iomap_copy_64.S
22264 @@ -17,6 +17,7 @@
22265
22266 #include <linux/linkage.h>
22267 #include <asm/dwarf2.h>
22268 +#include <asm/alternative-asm.h>
22269
22270 /*
22271 * override generic version in lib/iomap_copy.c
22272 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22273 CFI_STARTPROC
22274 movl %edx,%ecx
22275 rep movsd
22276 + pax_force_retaddr
22277 ret
22278 CFI_ENDPROC
22279 ENDPROC(__iowrite32_copy)
22280 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22281 index ad5441e..610e351 100644
22282 --- a/arch/x86/lib/memcpy_64.S
22283 +++ b/arch/x86/lib/memcpy_64.S
22284 @@ -4,6 +4,7 @@
22285
22286 #include <asm/cpufeature.h>
22287 #include <asm/dwarf2.h>
22288 +#include <asm/alternative-asm.h>
22289
22290 /*
22291 * memcpy - Copy a memory block.
22292 @@ -34,6 +35,7 @@ memcpy_c:
22293 rep movsq
22294 movl %edx, %ecx
22295 rep movsb
22296 + pax_force_retaddr
22297 ret
22298 CFI_ENDPROC
22299 ENDPROC(memcpy_c)
22300 @@ -118,6 +120,7 @@ ENTRY(memcpy)
22301 jnz .Lloop_1
22302
22303 .Lend:
22304 + pax_force_retaddr 0, 1
22305 ret
22306 CFI_ENDPROC
22307 ENDPROC(memcpy)
22308 @@ -128,7 +131,7 @@ ENDPROC(__memcpy)
22309 * It is also a lot simpler. Use this when possible:
22310 */
22311
22312 - .section .altinstr_replacement, "ax"
22313 + .section .altinstr_replacement, "a"
22314 1: .byte 0xeb /* jmp <disp8> */
22315 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
22316 2:
22317 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22318 index 2c59481..7e9ba4e 100644
22319 --- a/arch/x86/lib/memset_64.S
22320 +++ b/arch/x86/lib/memset_64.S
22321 @@ -2,6 +2,7 @@
22322
22323 #include <linux/linkage.h>
22324 #include <asm/dwarf2.h>
22325 +#include <asm/alternative-asm.h>
22326
22327 /*
22328 * ISO C memset - set a memory block to a byte value.
22329 @@ -28,6 +29,7 @@ memset_c:
22330 movl %r8d,%ecx
22331 rep stosb
22332 movq %r9,%rax
22333 + pax_force_retaddr
22334 ret
22335 CFI_ENDPROC
22336 ENDPROC(memset_c)
22337 @@ -35,13 +37,13 @@ ENDPROC(memset_c)
22338 ENTRY(memset)
22339 ENTRY(__memset)
22340 CFI_STARTPROC
22341 - movq %rdi,%r10
22342 movq %rdx,%r11
22343
22344 /* expand byte value */
22345 movzbl %sil,%ecx
22346 movabs $0x0101010101010101,%rax
22347 mul %rcx /* with rax, clobbers rdx */
22348 + movq %rdi,%rdx
22349
22350 /* align dst */
22351 movl %edi,%r9d
22352 @@ -95,7 +97,8 @@ ENTRY(__memset)
22353 jnz .Lloop_1
22354
22355 .Lende:
22356 - movq %r10,%rax
22357 + movq %rdx,%rax
22358 + pax_force_retaddr
22359 ret
22360
22361 CFI_RESTORE_STATE
22362 @@ -118,7 +121,7 @@ ENDPROC(__memset)
22363
22364 #include <asm/cpufeature.h>
22365
22366 - .section .altinstr_replacement,"ax"
22367 + .section .altinstr_replacement,"a"
22368 1: .byte 0xeb /* jmp <disp8> */
22369 .byte (memset_c - memset) - (2f - 1b) /* offset */
22370 2:
22371 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22372 index c9f2d9b..e7fd2c0 100644
22373 --- a/arch/x86/lib/mmx_32.c
22374 +++ b/arch/x86/lib/mmx_32.c
22375 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22376 {
22377 void *p;
22378 int i;
22379 + unsigned long cr0;
22380
22381 if (unlikely(in_interrupt()))
22382 return __memcpy(to, from, len);
22383 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22384 kernel_fpu_begin();
22385
22386 __asm__ __volatile__ (
22387 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22388 - " prefetch 64(%0)\n"
22389 - " prefetch 128(%0)\n"
22390 - " prefetch 192(%0)\n"
22391 - " prefetch 256(%0)\n"
22392 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22393 + " prefetch 64(%1)\n"
22394 + " prefetch 128(%1)\n"
22395 + " prefetch 192(%1)\n"
22396 + " prefetch 256(%1)\n"
22397 "2: \n"
22398 ".section .fixup, \"ax\"\n"
22399 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22400 + "3: \n"
22401 +
22402 +#ifdef CONFIG_PAX_KERNEXEC
22403 + " movl %%cr0, %0\n"
22404 + " movl %0, %%eax\n"
22405 + " andl $0xFFFEFFFF, %%eax\n"
22406 + " movl %%eax, %%cr0\n"
22407 +#endif
22408 +
22409 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22410 +
22411 +#ifdef CONFIG_PAX_KERNEXEC
22412 + " movl %0, %%cr0\n"
22413 +#endif
22414 +
22415 " jmp 2b\n"
22416 ".previous\n"
22417 _ASM_EXTABLE(1b, 3b)
22418 - : : "r" (from));
22419 + : "=&r" (cr0) : "r" (from) : "ax");
22420
22421 for ( ; i > 5; i--) {
22422 __asm__ __volatile__ (
22423 - "1: prefetch 320(%0)\n"
22424 - "2: movq (%0), %%mm0\n"
22425 - " movq 8(%0), %%mm1\n"
22426 - " movq 16(%0), %%mm2\n"
22427 - " movq 24(%0), %%mm3\n"
22428 - " movq %%mm0, (%1)\n"
22429 - " movq %%mm1, 8(%1)\n"
22430 - " movq %%mm2, 16(%1)\n"
22431 - " movq %%mm3, 24(%1)\n"
22432 - " movq 32(%0), %%mm0\n"
22433 - " movq 40(%0), %%mm1\n"
22434 - " movq 48(%0), %%mm2\n"
22435 - " movq 56(%0), %%mm3\n"
22436 - " movq %%mm0, 32(%1)\n"
22437 - " movq %%mm1, 40(%1)\n"
22438 - " movq %%mm2, 48(%1)\n"
22439 - " movq %%mm3, 56(%1)\n"
22440 + "1: prefetch 320(%1)\n"
22441 + "2: movq (%1), %%mm0\n"
22442 + " movq 8(%1), %%mm1\n"
22443 + " movq 16(%1), %%mm2\n"
22444 + " movq 24(%1), %%mm3\n"
22445 + " movq %%mm0, (%2)\n"
22446 + " movq %%mm1, 8(%2)\n"
22447 + " movq %%mm2, 16(%2)\n"
22448 + " movq %%mm3, 24(%2)\n"
22449 + " movq 32(%1), %%mm0\n"
22450 + " movq 40(%1), %%mm1\n"
22451 + " movq 48(%1), %%mm2\n"
22452 + " movq 56(%1), %%mm3\n"
22453 + " movq %%mm0, 32(%2)\n"
22454 + " movq %%mm1, 40(%2)\n"
22455 + " movq %%mm2, 48(%2)\n"
22456 + " movq %%mm3, 56(%2)\n"
22457 ".section .fixup, \"ax\"\n"
22458 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22459 + "3:\n"
22460 +
22461 +#ifdef CONFIG_PAX_KERNEXEC
22462 + " movl %%cr0, %0\n"
22463 + " movl %0, %%eax\n"
22464 + " andl $0xFFFEFFFF, %%eax\n"
22465 + " movl %%eax, %%cr0\n"
22466 +#endif
22467 +
22468 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22469 +
22470 +#ifdef CONFIG_PAX_KERNEXEC
22471 + " movl %0, %%cr0\n"
22472 +#endif
22473 +
22474 " jmp 2b\n"
22475 ".previous\n"
22476 _ASM_EXTABLE(1b, 3b)
22477 - : : "r" (from), "r" (to) : "memory");
22478 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22479
22480 from += 64;
22481 to += 64;
22482 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22483 static void fast_copy_page(void *to, void *from)
22484 {
22485 int i;
22486 + unsigned long cr0;
22487
22488 kernel_fpu_begin();
22489
22490 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22491 * but that is for later. -AV
22492 */
22493 __asm__ __volatile__(
22494 - "1: prefetch (%0)\n"
22495 - " prefetch 64(%0)\n"
22496 - " prefetch 128(%0)\n"
22497 - " prefetch 192(%0)\n"
22498 - " prefetch 256(%0)\n"
22499 + "1: prefetch (%1)\n"
22500 + " prefetch 64(%1)\n"
22501 + " prefetch 128(%1)\n"
22502 + " prefetch 192(%1)\n"
22503 + " prefetch 256(%1)\n"
22504 "2: \n"
22505 ".section .fixup, \"ax\"\n"
22506 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22507 + "3: \n"
22508 +
22509 +#ifdef CONFIG_PAX_KERNEXEC
22510 + " movl %%cr0, %0\n"
22511 + " movl %0, %%eax\n"
22512 + " andl $0xFFFEFFFF, %%eax\n"
22513 + " movl %%eax, %%cr0\n"
22514 +#endif
22515 +
22516 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22517 +
22518 +#ifdef CONFIG_PAX_KERNEXEC
22519 + " movl %0, %%cr0\n"
22520 +#endif
22521 +
22522 " jmp 2b\n"
22523 ".previous\n"
22524 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22525 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22526
22527 for (i = 0; i < (4096-320)/64; i++) {
22528 __asm__ __volatile__ (
22529 - "1: prefetch 320(%0)\n"
22530 - "2: movq (%0), %%mm0\n"
22531 - " movntq %%mm0, (%1)\n"
22532 - " movq 8(%0), %%mm1\n"
22533 - " movntq %%mm1, 8(%1)\n"
22534 - " movq 16(%0), %%mm2\n"
22535 - " movntq %%mm2, 16(%1)\n"
22536 - " movq 24(%0), %%mm3\n"
22537 - " movntq %%mm3, 24(%1)\n"
22538 - " movq 32(%0), %%mm4\n"
22539 - " movntq %%mm4, 32(%1)\n"
22540 - " movq 40(%0), %%mm5\n"
22541 - " movntq %%mm5, 40(%1)\n"
22542 - " movq 48(%0), %%mm6\n"
22543 - " movntq %%mm6, 48(%1)\n"
22544 - " movq 56(%0), %%mm7\n"
22545 - " movntq %%mm7, 56(%1)\n"
22546 + "1: prefetch 320(%1)\n"
22547 + "2: movq (%1), %%mm0\n"
22548 + " movntq %%mm0, (%2)\n"
22549 + " movq 8(%1), %%mm1\n"
22550 + " movntq %%mm1, 8(%2)\n"
22551 + " movq 16(%1), %%mm2\n"
22552 + " movntq %%mm2, 16(%2)\n"
22553 + " movq 24(%1), %%mm3\n"
22554 + " movntq %%mm3, 24(%2)\n"
22555 + " movq 32(%1), %%mm4\n"
22556 + " movntq %%mm4, 32(%2)\n"
22557 + " movq 40(%1), %%mm5\n"
22558 + " movntq %%mm5, 40(%2)\n"
22559 + " movq 48(%1), %%mm6\n"
22560 + " movntq %%mm6, 48(%2)\n"
22561 + " movq 56(%1), %%mm7\n"
22562 + " movntq %%mm7, 56(%2)\n"
22563 ".section .fixup, \"ax\"\n"
22564 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22565 + "3:\n"
22566 +
22567 +#ifdef CONFIG_PAX_KERNEXEC
22568 + " movl %%cr0, %0\n"
22569 + " movl %0, %%eax\n"
22570 + " andl $0xFFFEFFFF, %%eax\n"
22571 + " movl %%eax, %%cr0\n"
22572 +#endif
22573 +
22574 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22575 +
22576 +#ifdef CONFIG_PAX_KERNEXEC
22577 + " movl %0, %%cr0\n"
22578 +#endif
22579 +
22580 " jmp 2b\n"
22581 ".previous\n"
22582 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22583 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22584
22585 from += 64;
22586 to += 64;
22587 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22588 static void fast_copy_page(void *to, void *from)
22589 {
22590 int i;
22591 + unsigned long cr0;
22592
22593 kernel_fpu_begin();
22594
22595 __asm__ __volatile__ (
22596 - "1: prefetch (%0)\n"
22597 - " prefetch 64(%0)\n"
22598 - " prefetch 128(%0)\n"
22599 - " prefetch 192(%0)\n"
22600 - " prefetch 256(%0)\n"
22601 + "1: prefetch (%1)\n"
22602 + " prefetch 64(%1)\n"
22603 + " prefetch 128(%1)\n"
22604 + " prefetch 192(%1)\n"
22605 + " prefetch 256(%1)\n"
22606 "2: \n"
22607 ".section .fixup, \"ax\"\n"
22608 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22609 + "3: \n"
22610 +
22611 +#ifdef CONFIG_PAX_KERNEXEC
22612 + " movl %%cr0, %0\n"
22613 + " movl %0, %%eax\n"
22614 + " andl $0xFFFEFFFF, %%eax\n"
22615 + " movl %%eax, %%cr0\n"
22616 +#endif
22617 +
22618 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22619 +
22620 +#ifdef CONFIG_PAX_KERNEXEC
22621 + " movl %0, %%cr0\n"
22622 +#endif
22623 +
22624 " jmp 2b\n"
22625 ".previous\n"
22626 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22627 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22628
22629 for (i = 0; i < 4096/64; i++) {
22630 __asm__ __volatile__ (
22631 - "1: prefetch 320(%0)\n"
22632 - "2: movq (%0), %%mm0\n"
22633 - " movq 8(%0), %%mm1\n"
22634 - " movq 16(%0), %%mm2\n"
22635 - " movq 24(%0), %%mm3\n"
22636 - " movq %%mm0, (%1)\n"
22637 - " movq %%mm1, 8(%1)\n"
22638 - " movq %%mm2, 16(%1)\n"
22639 - " movq %%mm3, 24(%1)\n"
22640 - " movq 32(%0), %%mm0\n"
22641 - " movq 40(%0), %%mm1\n"
22642 - " movq 48(%0), %%mm2\n"
22643 - " movq 56(%0), %%mm3\n"
22644 - " movq %%mm0, 32(%1)\n"
22645 - " movq %%mm1, 40(%1)\n"
22646 - " movq %%mm2, 48(%1)\n"
22647 - " movq %%mm3, 56(%1)\n"
22648 + "1: prefetch 320(%1)\n"
22649 + "2: movq (%1), %%mm0\n"
22650 + " movq 8(%1), %%mm1\n"
22651 + " movq 16(%1), %%mm2\n"
22652 + " movq 24(%1), %%mm3\n"
22653 + " movq %%mm0, (%2)\n"
22654 + " movq %%mm1, 8(%2)\n"
22655 + " movq %%mm2, 16(%2)\n"
22656 + " movq %%mm3, 24(%2)\n"
22657 + " movq 32(%1), %%mm0\n"
22658 + " movq 40(%1), %%mm1\n"
22659 + " movq 48(%1), %%mm2\n"
22660 + " movq 56(%1), %%mm3\n"
22661 + " movq %%mm0, 32(%2)\n"
22662 + " movq %%mm1, 40(%2)\n"
22663 + " movq %%mm2, 48(%2)\n"
22664 + " movq %%mm3, 56(%2)\n"
22665 ".section .fixup, \"ax\"\n"
22666 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22667 + "3:\n"
22668 +
22669 +#ifdef CONFIG_PAX_KERNEXEC
22670 + " movl %%cr0, %0\n"
22671 + " movl %0, %%eax\n"
22672 + " andl $0xFFFEFFFF, %%eax\n"
22673 + " movl %%eax, %%cr0\n"
22674 +#endif
22675 +
22676 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22677 +
22678 +#ifdef CONFIG_PAX_KERNEXEC
22679 + " movl %0, %%cr0\n"
22680 +#endif
22681 +
22682 " jmp 2b\n"
22683 ".previous\n"
22684 _ASM_EXTABLE(1b, 3b)
22685 - : : "r" (from), "r" (to) : "memory");
22686 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22687
22688 from += 64;
22689 to += 64;
22690 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22691 index 69fa106..adda88b 100644
22692 --- a/arch/x86/lib/msr-reg.S
22693 +++ b/arch/x86/lib/msr-reg.S
22694 @@ -3,6 +3,7 @@
22695 #include <asm/dwarf2.h>
22696 #include <asm/asm.h>
22697 #include <asm/msr.h>
22698 +#include <asm/alternative-asm.h>
22699
22700 #ifdef CONFIG_X86_64
22701 /*
22702 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22703 CFI_STARTPROC
22704 pushq_cfi %rbx
22705 pushq_cfi %rbp
22706 - movq %rdi, %r10 /* Save pointer */
22707 + movq %rdi, %r9 /* Save pointer */
22708 xorl %r11d, %r11d /* Return value */
22709 movl (%rdi), %eax
22710 movl 4(%rdi), %ecx
22711 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22712 movl 28(%rdi), %edi
22713 CFI_REMEMBER_STATE
22714 1: \op
22715 -2: movl %eax, (%r10)
22716 +2: movl %eax, (%r9)
22717 movl %r11d, %eax /* Return value */
22718 - movl %ecx, 4(%r10)
22719 - movl %edx, 8(%r10)
22720 - movl %ebx, 12(%r10)
22721 - movl %ebp, 20(%r10)
22722 - movl %esi, 24(%r10)
22723 - movl %edi, 28(%r10)
22724 + movl %ecx, 4(%r9)
22725 + movl %edx, 8(%r9)
22726 + movl %ebx, 12(%r9)
22727 + movl %ebp, 20(%r9)
22728 + movl %esi, 24(%r9)
22729 + movl %edi, 28(%r9)
22730 popq_cfi %rbp
22731 popq_cfi %rbx
22732 + pax_force_retaddr
22733 ret
22734 3:
22735 CFI_RESTORE_STATE
22736 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22737 index 36b0d15..d381858 100644
22738 --- a/arch/x86/lib/putuser.S
22739 +++ b/arch/x86/lib/putuser.S
22740 @@ -15,7 +15,9 @@
22741 #include <asm/thread_info.h>
22742 #include <asm/errno.h>
22743 #include <asm/asm.h>
22744 -
22745 +#include <asm/segment.h>
22746 +#include <asm/pgtable.h>
22747 +#include <asm/alternative-asm.h>
22748
22749 /*
22750 * __put_user_X
22751 @@ -29,52 +31,119 @@
22752 * as they get called from within inline assembly.
22753 */
22754
22755 -#define ENTER CFI_STARTPROC ; \
22756 - GET_THREAD_INFO(%_ASM_BX)
22757 -#define EXIT ret ; \
22758 +#define ENTER CFI_STARTPROC
22759 +#define EXIT pax_force_retaddr; ret ; \
22760 CFI_ENDPROC
22761
22762 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22763 +#define _DEST %_ASM_CX,%_ASM_BX
22764 +#else
22765 +#define _DEST %_ASM_CX
22766 +#endif
22767 +
22768 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22769 +#define __copyuser_seg gs;
22770 +#else
22771 +#define __copyuser_seg
22772 +#endif
22773 +
22774 .text
22775 ENTRY(__put_user_1)
22776 ENTER
22777 +
22778 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22779 + GET_THREAD_INFO(%_ASM_BX)
22780 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22781 jae bad_put_user
22782 -1: movb %al,(%_ASM_CX)
22783 +
22784 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22785 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22786 + cmp %_ASM_BX,%_ASM_CX
22787 + jb 1234f
22788 + xor %ebx,%ebx
22789 +1234:
22790 +#endif
22791 +
22792 +#endif
22793 +
22794 +1: __copyuser_seg movb %al,(_DEST)
22795 xor %eax,%eax
22796 EXIT
22797 ENDPROC(__put_user_1)
22798
22799 ENTRY(__put_user_2)
22800 ENTER
22801 +
22802 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22803 + GET_THREAD_INFO(%_ASM_BX)
22804 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22805 sub $1,%_ASM_BX
22806 cmp %_ASM_BX,%_ASM_CX
22807 jae bad_put_user
22808 -2: movw %ax,(%_ASM_CX)
22809 +
22810 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22811 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22812 + cmp %_ASM_BX,%_ASM_CX
22813 + jb 1234f
22814 + xor %ebx,%ebx
22815 +1234:
22816 +#endif
22817 +
22818 +#endif
22819 +
22820 +2: __copyuser_seg movw %ax,(_DEST)
22821 xor %eax,%eax
22822 EXIT
22823 ENDPROC(__put_user_2)
22824
22825 ENTRY(__put_user_4)
22826 ENTER
22827 +
22828 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22829 + GET_THREAD_INFO(%_ASM_BX)
22830 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22831 sub $3,%_ASM_BX
22832 cmp %_ASM_BX,%_ASM_CX
22833 jae bad_put_user
22834 -3: movl %eax,(%_ASM_CX)
22835 +
22836 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22837 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22838 + cmp %_ASM_BX,%_ASM_CX
22839 + jb 1234f
22840 + xor %ebx,%ebx
22841 +1234:
22842 +#endif
22843 +
22844 +#endif
22845 +
22846 +3: __copyuser_seg movl %eax,(_DEST)
22847 xor %eax,%eax
22848 EXIT
22849 ENDPROC(__put_user_4)
22850
22851 ENTRY(__put_user_8)
22852 ENTER
22853 +
22854 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22855 + GET_THREAD_INFO(%_ASM_BX)
22856 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22857 sub $7,%_ASM_BX
22858 cmp %_ASM_BX,%_ASM_CX
22859 jae bad_put_user
22860 -4: mov %_ASM_AX,(%_ASM_CX)
22861 +
22862 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22863 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22864 + cmp %_ASM_BX,%_ASM_CX
22865 + jb 1234f
22866 + xor %ebx,%ebx
22867 +1234:
22868 +#endif
22869 +
22870 +#endif
22871 +
22872 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22873 #ifdef CONFIG_X86_32
22874 -5: movl %edx,4(%_ASM_CX)
22875 +5: __copyuser_seg movl %edx,4(_DEST)
22876 #endif
22877 xor %eax,%eax
22878 EXIT
22879 diff --git a/arch/x86/lib/rwlock_64.S b/arch/x86/lib/rwlock_64.S
22880 index 05ea55f..6345b9a 100644
22881 --- a/arch/x86/lib/rwlock_64.S
22882 +++ b/arch/x86/lib/rwlock_64.S
22883 @@ -2,6 +2,7 @@
22884
22885 #include <linux/linkage.h>
22886 #include <asm/rwlock.h>
22887 +#include <asm/asm.h>
22888 #include <asm/alternative-asm.h>
22889 #include <asm/dwarf2.h>
22890
22891 @@ -10,13 +11,34 @@ ENTRY(__write_lock_failed)
22892 CFI_STARTPROC
22893 LOCK_PREFIX
22894 addl $RW_LOCK_BIAS,(%rdi)
22895 +
22896 +#ifdef CONFIG_PAX_REFCOUNT
22897 + jno 1234f
22898 + LOCK_PREFIX
22899 + subl $RW_LOCK_BIAS,(%rdi)
22900 + int $4
22901 +1234:
22902 + _ASM_EXTABLE(1234b, 1234b)
22903 +#endif
22904 +
22905 1: rep
22906 nop
22907 cmpl $RW_LOCK_BIAS,(%rdi)
22908 jne 1b
22909 LOCK_PREFIX
22910 subl $RW_LOCK_BIAS,(%rdi)
22911 +
22912 +#ifdef CONFIG_PAX_REFCOUNT
22913 + jno 1234f
22914 + LOCK_PREFIX
22915 + addl $RW_LOCK_BIAS,(%rdi)
22916 + int $4
22917 +1234:
22918 + _ASM_EXTABLE(1234b, 1234b)
22919 +#endif
22920 +
22921 jnz __write_lock_failed
22922 + pax_force_retaddr
22923 ret
22924 CFI_ENDPROC
22925 END(__write_lock_failed)
22926 @@ -26,13 +48,34 @@ ENTRY(__read_lock_failed)
22927 CFI_STARTPROC
22928 LOCK_PREFIX
22929 incl (%rdi)
22930 +
22931 +#ifdef CONFIG_PAX_REFCOUNT
22932 + jno 1234f
22933 + LOCK_PREFIX
22934 + decl (%rdi)
22935 + int $4
22936 +1234:
22937 + _ASM_EXTABLE(1234b, 1234b)
22938 +#endif
22939 +
22940 1: rep
22941 nop
22942 cmpl $1,(%rdi)
22943 js 1b
22944 LOCK_PREFIX
22945 decl (%rdi)
22946 +
22947 +#ifdef CONFIG_PAX_REFCOUNT
22948 + jno 1234f
22949 + LOCK_PREFIX
22950 + incl (%rdi)
22951 + int $4
22952 +1234:
22953 + _ASM_EXTABLE(1234b, 1234b)
22954 +#endif
22955 +
22956 js __read_lock_failed
22957 + pax_force_retaddr
22958 ret
22959 CFI_ENDPROC
22960 END(__read_lock_failed)
22961 diff --git a/arch/x86/lib/rwsem_64.S b/arch/x86/lib/rwsem_64.S
22962 index 15acecf..f768b10 100644
22963 --- a/arch/x86/lib/rwsem_64.S
22964 +++ b/arch/x86/lib/rwsem_64.S
22965 @@ -48,6 +48,7 @@ ENTRY(call_rwsem_down_read_failed)
22966 call rwsem_down_read_failed
22967 popq %rdx
22968 restore_common_regs
22969 + pax_force_retaddr
22970 ret
22971 ENDPROC(call_rwsem_down_read_failed)
22972
22973 @@ -56,6 +57,7 @@ ENTRY(call_rwsem_down_write_failed)
22974 movq %rax,%rdi
22975 call rwsem_down_write_failed
22976 restore_common_regs
22977 + pax_force_retaddr
22978 ret
22979 ENDPROC(call_rwsem_down_write_failed)
22980
22981 @@ -66,7 +68,8 @@ ENTRY(call_rwsem_wake)
22982 movq %rax,%rdi
22983 call rwsem_wake
22984 restore_common_regs
22985 -1: ret
22986 +1: pax_force_retaddr
22987 + ret
22988 ENDPROC(call_rwsem_wake)
22989
22990 /* Fix up special calling conventions */
22991 @@ -77,5 +80,6 @@ ENTRY(call_rwsem_downgrade_wake)
22992 call rwsem_downgrade_wake
22993 popq %rdx
22994 restore_common_regs
22995 + pax_force_retaddr
22996 ret
22997 ENDPROC(call_rwsem_downgrade_wake)
22998 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22999 index bf9a7d5..fb06ab5 100644
23000 --- a/arch/x86/lib/thunk_64.S
23001 +++ b/arch/x86/lib/thunk_64.S
23002 @@ -10,7 +10,8 @@
23003 #include <asm/dwarf2.h>
23004 #include <asm/calling.h>
23005 #include <asm/rwlock.h>
23006 -
23007 + #include <asm/alternative-asm.h>
23008 +
23009 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23010 .macro thunk name,func
23011 .globl \name
23012 @@ -70,6 +71,7 @@
23013 SAVE_ARGS
23014 restore:
23015 RESTORE_ARGS
23016 + pax_force_retaddr
23017 ret
23018 CFI_ENDPROC
23019
23020 @@ -77,5 +79,6 @@ restore:
23021 SAVE_ARGS
23022 restore_norax:
23023 RESTORE_ARGS 1
23024 + pax_force_retaddr
23025 ret
23026 CFI_ENDPROC
23027 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23028 index 1f118d4..ec4a953 100644
23029 --- a/arch/x86/lib/usercopy_32.c
23030 +++ b/arch/x86/lib/usercopy_32.c
23031 @@ -43,7 +43,7 @@ do { \
23032 __asm__ __volatile__( \
23033 " testl %1,%1\n" \
23034 " jz 2f\n" \
23035 - "0: lodsb\n" \
23036 + "0: "__copyuser_seg"lodsb\n" \
23037 " stosb\n" \
23038 " testb %%al,%%al\n" \
23039 " jz 1f\n" \
23040 @@ -128,10 +128,12 @@ do { \
23041 int __d0; \
23042 might_fault(); \
23043 __asm__ __volatile__( \
23044 + __COPYUSER_SET_ES \
23045 "0: rep; stosl\n" \
23046 " movl %2,%0\n" \
23047 "1: rep; stosb\n" \
23048 "2:\n" \
23049 + __COPYUSER_RESTORE_ES \
23050 ".section .fixup,\"ax\"\n" \
23051 "3: lea 0(%2,%0,4),%0\n" \
23052 " jmp 2b\n" \
23053 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
23054 might_fault();
23055
23056 __asm__ __volatile__(
23057 + __COPYUSER_SET_ES
23058 " testl %0, %0\n"
23059 " jz 3f\n"
23060 " andl %0,%%ecx\n"
23061 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
23062 " subl %%ecx,%0\n"
23063 " addl %0,%%eax\n"
23064 "1:\n"
23065 + __COPYUSER_RESTORE_ES
23066 ".section .fixup,\"ax\"\n"
23067 "2: xorl %%eax,%%eax\n"
23068 " jmp 1b\n"
23069 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
23070
23071 #ifdef CONFIG_X86_INTEL_USERCOPY
23072 static unsigned long
23073 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
23074 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23075 {
23076 int d0, d1;
23077 __asm__ __volatile__(
23078 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23079 " .align 2,0x90\n"
23080 "3: movl 0(%4), %%eax\n"
23081 "4: movl 4(%4), %%edx\n"
23082 - "5: movl %%eax, 0(%3)\n"
23083 - "6: movl %%edx, 4(%3)\n"
23084 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23085 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23086 "7: movl 8(%4), %%eax\n"
23087 "8: movl 12(%4),%%edx\n"
23088 - "9: movl %%eax, 8(%3)\n"
23089 - "10: movl %%edx, 12(%3)\n"
23090 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23091 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23092 "11: movl 16(%4), %%eax\n"
23093 "12: movl 20(%4), %%edx\n"
23094 - "13: movl %%eax, 16(%3)\n"
23095 - "14: movl %%edx, 20(%3)\n"
23096 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23097 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23098 "15: movl 24(%4), %%eax\n"
23099 "16: movl 28(%4), %%edx\n"
23100 - "17: movl %%eax, 24(%3)\n"
23101 - "18: movl %%edx, 28(%3)\n"
23102 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23103 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23104 "19: movl 32(%4), %%eax\n"
23105 "20: movl 36(%4), %%edx\n"
23106 - "21: movl %%eax, 32(%3)\n"
23107 - "22: movl %%edx, 36(%3)\n"
23108 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23109 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23110 "23: movl 40(%4), %%eax\n"
23111 "24: movl 44(%4), %%edx\n"
23112 - "25: movl %%eax, 40(%3)\n"
23113 - "26: movl %%edx, 44(%3)\n"
23114 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23115 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23116 "27: movl 48(%4), %%eax\n"
23117 "28: movl 52(%4), %%edx\n"
23118 - "29: movl %%eax, 48(%3)\n"
23119 - "30: movl %%edx, 52(%3)\n"
23120 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23121 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23122 "31: movl 56(%4), %%eax\n"
23123 "32: movl 60(%4), %%edx\n"
23124 - "33: movl %%eax, 56(%3)\n"
23125 - "34: movl %%edx, 60(%3)\n"
23126 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23127 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23128 " addl $-64, %0\n"
23129 " addl $64, %4\n"
23130 " addl $64, %3\n"
23131 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23132 " shrl $2, %0\n"
23133 " andl $3, %%eax\n"
23134 " cld\n"
23135 + __COPYUSER_SET_ES
23136 "99: rep; movsl\n"
23137 "36: movl %%eax, %0\n"
23138 "37: rep; movsb\n"
23139 "100:\n"
23140 + __COPYUSER_RESTORE_ES
23141 + ".section .fixup,\"ax\"\n"
23142 + "101: lea 0(%%eax,%0,4),%0\n"
23143 + " jmp 100b\n"
23144 + ".previous\n"
23145 + ".section __ex_table,\"a\"\n"
23146 + " .align 4\n"
23147 + " .long 1b,100b\n"
23148 + " .long 2b,100b\n"
23149 + " .long 3b,100b\n"
23150 + " .long 4b,100b\n"
23151 + " .long 5b,100b\n"
23152 + " .long 6b,100b\n"
23153 + " .long 7b,100b\n"
23154 + " .long 8b,100b\n"
23155 + " .long 9b,100b\n"
23156 + " .long 10b,100b\n"
23157 + " .long 11b,100b\n"
23158 + " .long 12b,100b\n"
23159 + " .long 13b,100b\n"
23160 + " .long 14b,100b\n"
23161 + " .long 15b,100b\n"
23162 + " .long 16b,100b\n"
23163 + " .long 17b,100b\n"
23164 + " .long 18b,100b\n"
23165 + " .long 19b,100b\n"
23166 + " .long 20b,100b\n"
23167 + " .long 21b,100b\n"
23168 + " .long 22b,100b\n"
23169 + " .long 23b,100b\n"
23170 + " .long 24b,100b\n"
23171 + " .long 25b,100b\n"
23172 + " .long 26b,100b\n"
23173 + " .long 27b,100b\n"
23174 + " .long 28b,100b\n"
23175 + " .long 29b,100b\n"
23176 + " .long 30b,100b\n"
23177 + " .long 31b,100b\n"
23178 + " .long 32b,100b\n"
23179 + " .long 33b,100b\n"
23180 + " .long 34b,100b\n"
23181 + " .long 35b,100b\n"
23182 + " .long 36b,100b\n"
23183 + " .long 37b,100b\n"
23184 + " .long 99b,101b\n"
23185 + ".previous"
23186 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23187 + : "1"(to), "2"(from), "0"(size)
23188 + : "eax", "edx", "memory");
23189 + return size;
23190 +}
23191 +
23192 +static unsigned long
23193 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23194 +{
23195 + int d0, d1;
23196 + __asm__ __volatile__(
23197 + " .align 2,0x90\n"
23198 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23199 + " cmpl $67, %0\n"
23200 + " jbe 3f\n"
23201 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23202 + " .align 2,0x90\n"
23203 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23204 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23205 + "5: movl %%eax, 0(%3)\n"
23206 + "6: movl %%edx, 4(%3)\n"
23207 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23208 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23209 + "9: movl %%eax, 8(%3)\n"
23210 + "10: movl %%edx, 12(%3)\n"
23211 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23212 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23213 + "13: movl %%eax, 16(%3)\n"
23214 + "14: movl %%edx, 20(%3)\n"
23215 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23216 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23217 + "17: movl %%eax, 24(%3)\n"
23218 + "18: movl %%edx, 28(%3)\n"
23219 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23220 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23221 + "21: movl %%eax, 32(%3)\n"
23222 + "22: movl %%edx, 36(%3)\n"
23223 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23224 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23225 + "25: movl %%eax, 40(%3)\n"
23226 + "26: movl %%edx, 44(%3)\n"
23227 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23228 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23229 + "29: movl %%eax, 48(%3)\n"
23230 + "30: movl %%edx, 52(%3)\n"
23231 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23232 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23233 + "33: movl %%eax, 56(%3)\n"
23234 + "34: movl %%edx, 60(%3)\n"
23235 + " addl $-64, %0\n"
23236 + " addl $64, %4\n"
23237 + " addl $64, %3\n"
23238 + " cmpl $63, %0\n"
23239 + " ja 1b\n"
23240 + "35: movl %0, %%eax\n"
23241 + " shrl $2, %0\n"
23242 + " andl $3, %%eax\n"
23243 + " cld\n"
23244 + "99: rep; "__copyuser_seg" movsl\n"
23245 + "36: movl %%eax, %0\n"
23246 + "37: rep; "__copyuser_seg" movsb\n"
23247 + "100:\n"
23248 ".section .fixup,\"ax\"\n"
23249 "101: lea 0(%%eax,%0,4),%0\n"
23250 " jmp 100b\n"
23251 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23252 int d0, d1;
23253 __asm__ __volatile__(
23254 " .align 2,0x90\n"
23255 - "0: movl 32(%4), %%eax\n"
23256 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23257 " cmpl $67, %0\n"
23258 " jbe 2f\n"
23259 - "1: movl 64(%4), %%eax\n"
23260 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23261 " .align 2,0x90\n"
23262 - "2: movl 0(%4), %%eax\n"
23263 - "21: movl 4(%4), %%edx\n"
23264 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23265 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23266 " movl %%eax, 0(%3)\n"
23267 " movl %%edx, 4(%3)\n"
23268 - "3: movl 8(%4), %%eax\n"
23269 - "31: movl 12(%4),%%edx\n"
23270 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23271 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23272 " movl %%eax, 8(%3)\n"
23273 " movl %%edx, 12(%3)\n"
23274 - "4: movl 16(%4), %%eax\n"
23275 - "41: movl 20(%4), %%edx\n"
23276 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23277 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23278 " movl %%eax, 16(%3)\n"
23279 " movl %%edx, 20(%3)\n"
23280 - "10: movl 24(%4), %%eax\n"
23281 - "51: movl 28(%4), %%edx\n"
23282 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23283 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23284 " movl %%eax, 24(%3)\n"
23285 " movl %%edx, 28(%3)\n"
23286 - "11: movl 32(%4), %%eax\n"
23287 - "61: movl 36(%4), %%edx\n"
23288 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23289 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23290 " movl %%eax, 32(%3)\n"
23291 " movl %%edx, 36(%3)\n"
23292 - "12: movl 40(%4), %%eax\n"
23293 - "71: movl 44(%4), %%edx\n"
23294 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23295 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23296 " movl %%eax, 40(%3)\n"
23297 " movl %%edx, 44(%3)\n"
23298 - "13: movl 48(%4), %%eax\n"
23299 - "81: movl 52(%4), %%edx\n"
23300 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23301 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23302 " movl %%eax, 48(%3)\n"
23303 " movl %%edx, 52(%3)\n"
23304 - "14: movl 56(%4), %%eax\n"
23305 - "91: movl 60(%4), %%edx\n"
23306 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23307 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23308 " movl %%eax, 56(%3)\n"
23309 " movl %%edx, 60(%3)\n"
23310 " addl $-64, %0\n"
23311 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23312 " shrl $2, %0\n"
23313 " andl $3, %%eax\n"
23314 " cld\n"
23315 - "6: rep; movsl\n"
23316 + "6: rep; "__copyuser_seg" movsl\n"
23317 " movl %%eax,%0\n"
23318 - "7: rep; movsb\n"
23319 + "7: rep; "__copyuser_seg" movsb\n"
23320 "8:\n"
23321 ".section .fixup,\"ax\"\n"
23322 "9: lea 0(%%eax,%0,4),%0\n"
23323 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23324
23325 __asm__ __volatile__(
23326 " .align 2,0x90\n"
23327 - "0: movl 32(%4), %%eax\n"
23328 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23329 " cmpl $67, %0\n"
23330 " jbe 2f\n"
23331 - "1: movl 64(%4), %%eax\n"
23332 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23333 " .align 2,0x90\n"
23334 - "2: movl 0(%4), %%eax\n"
23335 - "21: movl 4(%4), %%edx\n"
23336 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23337 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23338 " movnti %%eax, 0(%3)\n"
23339 " movnti %%edx, 4(%3)\n"
23340 - "3: movl 8(%4), %%eax\n"
23341 - "31: movl 12(%4),%%edx\n"
23342 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23343 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23344 " movnti %%eax, 8(%3)\n"
23345 " movnti %%edx, 12(%3)\n"
23346 - "4: movl 16(%4), %%eax\n"
23347 - "41: movl 20(%4), %%edx\n"
23348 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23349 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23350 " movnti %%eax, 16(%3)\n"
23351 " movnti %%edx, 20(%3)\n"
23352 - "10: movl 24(%4), %%eax\n"
23353 - "51: movl 28(%4), %%edx\n"
23354 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23355 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23356 " movnti %%eax, 24(%3)\n"
23357 " movnti %%edx, 28(%3)\n"
23358 - "11: movl 32(%4), %%eax\n"
23359 - "61: movl 36(%4), %%edx\n"
23360 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23361 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23362 " movnti %%eax, 32(%3)\n"
23363 " movnti %%edx, 36(%3)\n"
23364 - "12: movl 40(%4), %%eax\n"
23365 - "71: movl 44(%4), %%edx\n"
23366 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23367 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23368 " movnti %%eax, 40(%3)\n"
23369 " movnti %%edx, 44(%3)\n"
23370 - "13: movl 48(%4), %%eax\n"
23371 - "81: movl 52(%4), %%edx\n"
23372 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23373 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23374 " movnti %%eax, 48(%3)\n"
23375 " movnti %%edx, 52(%3)\n"
23376 - "14: movl 56(%4), %%eax\n"
23377 - "91: movl 60(%4), %%edx\n"
23378 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23379 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23380 " movnti %%eax, 56(%3)\n"
23381 " movnti %%edx, 60(%3)\n"
23382 " addl $-64, %0\n"
23383 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23384 " shrl $2, %0\n"
23385 " andl $3, %%eax\n"
23386 " cld\n"
23387 - "6: rep; movsl\n"
23388 + "6: rep; "__copyuser_seg" movsl\n"
23389 " movl %%eax,%0\n"
23390 - "7: rep; movsb\n"
23391 + "7: rep; "__copyuser_seg" movsb\n"
23392 "8:\n"
23393 ".section .fixup,\"ax\"\n"
23394 "9: lea 0(%%eax,%0,4),%0\n"
23395 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
23396
23397 __asm__ __volatile__(
23398 " .align 2,0x90\n"
23399 - "0: movl 32(%4), %%eax\n"
23400 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23401 " cmpl $67, %0\n"
23402 " jbe 2f\n"
23403 - "1: movl 64(%4), %%eax\n"
23404 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23405 " .align 2,0x90\n"
23406 - "2: movl 0(%4), %%eax\n"
23407 - "21: movl 4(%4), %%edx\n"
23408 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23409 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23410 " movnti %%eax, 0(%3)\n"
23411 " movnti %%edx, 4(%3)\n"
23412 - "3: movl 8(%4), %%eax\n"
23413 - "31: movl 12(%4),%%edx\n"
23414 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23415 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23416 " movnti %%eax, 8(%3)\n"
23417 " movnti %%edx, 12(%3)\n"
23418 - "4: movl 16(%4), %%eax\n"
23419 - "41: movl 20(%4), %%edx\n"
23420 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23421 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23422 " movnti %%eax, 16(%3)\n"
23423 " movnti %%edx, 20(%3)\n"
23424 - "10: movl 24(%4), %%eax\n"
23425 - "51: movl 28(%4), %%edx\n"
23426 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23427 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23428 " movnti %%eax, 24(%3)\n"
23429 " movnti %%edx, 28(%3)\n"
23430 - "11: movl 32(%4), %%eax\n"
23431 - "61: movl 36(%4), %%edx\n"
23432 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23433 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23434 " movnti %%eax, 32(%3)\n"
23435 " movnti %%edx, 36(%3)\n"
23436 - "12: movl 40(%4), %%eax\n"
23437 - "71: movl 44(%4), %%edx\n"
23438 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23439 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23440 " movnti %%eax, 40(%3)\n"
23441 " movnti %%edx, 44(%3)\n"
23442 - "13: movl 48(%4), %%eax\n"
23443 - "81: movl 52(%4), %%edx\n"
23444 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23445 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23446 " movnti %%eax, 48(%3)\n"
23447 " movnti %%edx, 52(%3)\n"
23448 - "14: movl 56(%4), %%eax\n"
23449 - "91: movl 60(%4), %%edx\n"
23450 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23451 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23452 " movnti %%eax, 56(%3)\n"
23453 " movnti %%edx, 60(%3)\n"
23454 " addl $-64, %0\n"
23455 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23456 " shrl $2, %0\n"
23457 " andl $3, %%eax\n"
23458 " cld\n"
23459 - "6: rep; movsl\n"
23460 + "6: rep; "__copyuser_seg" movsl\n"
23461 " movl %%eax,%0\n"
23462 - "7: rep; movsb\n"
23463 + "7: rep; "__copyuser_seg" movsb\n"
23464 "8:\n"
23465 ".section .fixup,\"ax\"\n"
23466 "9: lea 0(%%eax,%0,4),%0\n"
23467 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23468 */
23469 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23470 unsigned long size);
23471 -unsigned long __copy_user_intel(void __user *to, const void *from,
23472 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23473 + unsigned long size);
23474 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23475 unsigned long size);
23476 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23477 const void __user *from, unsigned long size);
23478 #endif /* CONFIG_X86_INTEL_USERCOPY */
23479
23480 /* Generic arbitrary sized copy. */
23481 -#define __copy_user(to, from, size) \
23482 +#define __copy_user(to, from, size, prefix, set, restore) \
23483 do { \
23484 int __d0, __d1, __d2; \
23485 __asm__ __volatile__( \
23486 + set \
23487 " cmp $7,%0\n" \
23488 " jbe 1f\n" \
23489 " movl %1,%0\n" \
23490 " negl %0\n" \
23491 " andl $7,%0\n" \
23492 " subl %0,%3\n" \
23493 - "4: rep; movsb\n" \
23494 + "4: rep; "prefix"movsb\n" \
23495 " movl %3,%0\n" \
23496 " shrl $2,%0\n" \
23497 " andl $3,%3\n" \
23498 " .align 2,0x90\n" \
23499 - "0: rep; movsl\n" \
23500 + "0: rep; "prefix"movsl\n" \
23501 " movl %3,%0\n" \
23502 - "1: rep; movsb\n" \
23503 + "1: rep; "prefix"movsb\n" \
23504 "2:\n" \
23505 + restore \
23506 ".section .fixup,\"ax\"\n" \
23507 "5: addl %3,%0\n" \
23508 " jmp 2b\n" \
23509 @@ -682,14 +799,14 @@ do { \
23510 " negl %0\n" \
23511 " andl $7,%0\n" \
23512 " subl %0,%3\n" \
23513 - "4: rep; movsb\n" \
23514 + "4: rep; "__copyuser_seg"movsb\n" \
23515 " movl %3,%0\n" \
23516 " shrl $2,%0\n" \
23517 " andl $3,%3\n" \
23518 " .align 2,0x90\n" \
23519 - "0: rep; movsl\n" \
23520 + "0: rep; "__copyuser_seg"movsl\n" \
23521 " movl %3,%0\n" \
23522 - "1: rep; movsb\n" \
23523 + "1: rep; "__copyuser_seg"movsb\n" \
23524 "2:\n" \
23525 ".section .fixup,\"ax\"\n" \
23526 "5: addl %3,%0\n" \
23527 @@ -775,9 +892,9 @@ survive:
23528 }
23529 #endif
23530 if (movsl_is_ok(to, from, n))
23531 - __copy_user(to, from, n);
23532 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23533 else
23534 - n = __copy_user_intel(to, from, n);
23535 + n = __generic_copy_to_user_intel(to, from, n);
23536 return n;
23537 }
23538 EXPORT_SYMBOL(__copy_to_user_ll);
23539 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23540 unsigned long n)
23541 {
23542 if (movsl_is_ok(to, from, n))
23543 - __copy_user(to, from, n);
23544 + __copy_user(to, from, n, __copyuser_seg, "", "");
23545 else
23546 - n = __copy_user_intel((void __user *)to,
23547 - (const void *)from, n);
23548 + n = __generic_copy_from_user_intel(to, from, n);
23549 return n;
23550 }
23551 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23552 @@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23553 if (n > 64 && cpu_has_xmm2)
23554 n = __copy_user_intel_nocache(to, from, n);
23555 else
23556 - __copy_user(to, from, n);
23557 + __copy_user(to, from, n, __copyuser_seg, "", "");
23558 #else
23559 - __copy_user(to, from, n);
23560 + __copy_user(to, from, n, __copyuser_seg, "", "");
23561 #endif
23562 return n;
23563 }
23564 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23565
23566 -/**
23567 - * copy_to_user: - Copy a block of data into user space.
23568 - * @to: Destination address, in user space.
23569 - * @from: Source address, in kernel space.
23570 - * @n: Number of bytes to copy.
23571 - *
23572 - * Context: User context only. This function may sleep.
23573 - *
23574 - * Copy data from kernel space to user space.
23575 - *
23576 - * Returns number of bytes that could not be copied.
23577 - * On success, this will be zero.
23578 - */
23579 -unsigned long
23580 -copy_to_user(void __user *to, const void *from, unsigned long n)
23581 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23582 +void __set_fs(mm_segment_t x)
23583 {
23584 - if (access_ok(VERIFY_WRITE, to, n))
23585 - n = __copy_to_user(to, from, n);
23586 - return n;
23587 + switch (x.seg) {
23588 + case 0:
23589 + loadsegment(gs, 0);
23590 + break;
23591 + case TASK_SIZE_MAX:
23592 + loadsegment(gs, __USER_DS);
23593 + break;
23594 + case -1UL:
23595 + loadsegment(gs, __KERNEL_DS);
23596 + break;
23597 + default:
23598 + BUG();
23599 + }
23600 + return;
23601 }
23602 -EXPORT_SYMBOL(copy_to_user);
23603 +EXPORT_SYMBOL(__set_fs);
23604
23605 -/**
23606 - * copy_from_user: - Copy a block of data from user space.
23607 - * @to: Destination address, in kernel space.
23608 - * @from: Source address, in user space.
23609 - * @n: Number of bytes to copy.
23610 - *
23611 - * Context: User context only. This function may sleep.
23612 - *
23613 - * Copy data from user space to kernel space.
23614 - *
23615 - * Returns number of bytes that could not be copied.
23616 - * On success, this will be zero.
23617 - *
23618 - * If some data could not be copied, this function will pad the copied
23619 - * data to the requested size using zero bytes.
23620 - */
23621 -unsigned long
23622 -copy_from_user(void *to, const void __user *from, unsigned long n)
23623 +void set_fs(mm_segment_t x)
23624 {
23625 - if (access_ok(VERIFY_READ, from, n))
23626 - n = __copy_from_user(to, from, n);
23627 - else
23628 - memset(to, 0, n);
23629 - return n;
23630 + current_thread_info()->addr_limit = x;
23631 + __set_fs(x);
23632 }
23633 -EXPORT_SYMBOL(copy_from_user);
23634 +EXPORT_SYMBOL(set_fs);
23635 +#endif
23636 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23637 index b7c2849..8633ad8 100644
23638 --- a/arch/x86/lib/usercopy_64.c
23639 +++ b/arch/x86/lib/usercopy_64.c
23640 @@ -42,6 +42,12 @@ long
23641 __strncpy_from_user(char *dst, const char __user *src, long count)
23642 {
23643 long res;
23644 +
23645 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23646 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23647 + src += PAX_USER_SHADOW_BASE;
23648 +#endif
23649 +
23650 __do_strncpy_from_user(dst, src, count, res);
23651 return res;
23652 }
23653 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23654 {
23655 long __d0;
23656 might_fault();
23657 +
23658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23659 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23660 + addr += PAX_USER_SHADOW_BASE;
23661 +#endif
23662 +
23663 /* no memory constraint because it doesn't change any memory gcc knows
23664 about */
23665 asm volatile(
23666 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23667 }
23668 EXPORT_SYMBOL(strlen_user);
23669
23670 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23671 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23672 {
23673 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23674 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23675 - }
23676 - return len;
23677 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23678 +
23679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23680 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23681 + to += PAX_USER_SHADOW_BASE;
23682 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23683 + from += PAX_USER_SHADOW_BASE;
23684 +#endif
23685 +
23686 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23687 + }
23688 + return len;
23689 }
23690 EXPORT_SYMBOL(copy_in_user);
23691
23692 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23693 * it is not necessary to optimize tail handling.
23694 */
23695 unsigned long
23696 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23697 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23698 {
23699 char c;
23700 unsigned zero_len;
23701 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23702 index 61b41ca..5fef66a 100644
23703 --- a/arch/x86/mm/extable.c
23704 +++ b/arch/x86/mm/extable.c
23705 @@ -1,14 +1,71 @@
23706 #include <linux/module.h>
23707 #include <linux/spinlock.h>
23708 +#include <linux/sort.h>
23709 #include <asm/uaccess.h>
23710 +#include <asm/pgtable.h>
23711
23712 +/*
23713 + * The exception table needs to be sorted so that the binary
23714 + * search that we use to find entries in it works properly.
23715 + * This is used both for the kernel exception table and for
23716 + * the exception tables of modules that get loaded.
23717 + */
23718 +static int cmp_ex(const void *a, const void *b)
23719 +{
23720 + const struct exception_table_entry *x = a, *y = b;
23721 +
23722 + /* avoid overflow */
23723 + if (x->insn > y->insn)
23724 + return 1;
23725 + if (x->insn < y->insn)
23726 + return -1;
23727 + return 0;
23728 +}
23729 +
23730 +static void swap_ex(void *a, void *b, int size)
23731 +{
23732 + struct exception_table_entry t, *x = a, *y = b;
23733 +
23734 + t = *x;
23735 +
23736 + pax_open_kernel();
23737 + *x = *y;
23738 + *y = t;
23739 + pax_close_kernel();
23740 +}
23741 +
23742 +void sort_extable(struct exception_table_entry *start,
23743 + struct exception_table_entry *finish)
23744 +{
23745 + sort(start, finish - start, sizeof(struct exception_table_entry),
23746 + cmp_ex, swap_ex);
23747 +}
23748 +
23749 +#ifdef CONFIG_MODULES
23750 +/*
23751 + * If the exception table is sorted, any referring to the module init
23752 + * will be at the beginning or the end.
23753 + */
23754 +void trim_init_extable(struct module *m)
23755 +{
23756 + /*trim the beginning*/
23757 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
23758 + m->extable++;
23759 + m->num_exentries--;
23760 + }
23761 + /*trim the end*/
23762 + while (m->num_exentries &&
23763 + within_module_init(m->extable[m->num_exentries-1].insn, m))
23764 + m->num_exentries--;
23765 +}
23766 +#endif /* CONFIG_MODULES */
23767
23768 int fixup_exception(struct pt_regs *regs)
23769 {
23770 const struct exception_table_entry *fixup;
23771
23772 #ifdef CONFIG_PNPBIOS
23773 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23774 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23775 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23776 extern u32 pnp_bios_is_utter_crap;
23777 pnp_bios_is_utter_crap = 1;
23778 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23779 index 8ac0d76..3f191dc 100644
23780 --- a/arch/x86/mm/fault.c
23781 +++ b/arch/x86/mm/fault.c
23782 @@ -11,10 +11,19 @@
23783 #include <linux/kprobes.h> /* __kprobes, ... */
23784 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
23785 #include <linux/perf_event.h> /* perf_sw_event */
23786 +#include <linux/unistd.h>
23787 +#include <linux/compiler.h>
23788
23789 #include <asm/traps.h> /* dotraplinkage, ... */
23790 #include <asm/pgalloc.h> /* pgd_*(), ... */
23791 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23792 +#include <asm/vsyscall.h>
23793 +#include <asm/tlbflush.h>
23794 +
23795 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23796 +#include <asm/stacktrace.h>
23797 +#include "../kernel/dumpstack.h"
23798 +#endif
23799
23800 /*
23801 * Page fault error code bits:
23802 @@ -51,7 +60,7 @@ static inline int notify_page_fault(struct pt_regs *regs)
23803 int ret = 0;
23804
23805 /* kprobe_running() needs smp_processor_id() */
23806 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23807 + if (kprobes_built_in() && !user_mode(regs)) {
23808 preempt_disable();
23809 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23810 ret = 1;
23811 @@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23812 return !instr_lo || (instr_lo>>1) == 1;
23813 case 0x00:
23814 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23815 - if (probe_kernel_address(instr, opcode))
23816 + if (user_mode(regs)) {
23817 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23818 + return 0;
23819 + } else if (probe_kernel_address(instr, opcode))
23820 return 0;
23821
23822 *prefetch = (instr_lo == 0xF) &&
23823 @@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23824 while (instr < max_instr) {
23825 unsigned char opcode;
23826
23827 - if (probe_kernel_address(instr, opcode))
23828 + if (user_mode(regs)) {
23829 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23830 + break;
23831 + } else if (probe_kernel_address(instr, opcode))
23832 break;
23833
23834 instr++;
23835 @@ -172,6 +187,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23836 force_sig_info(si_signo, &info, tsk);
23837 }
23838
23839 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23840 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23841 +#endif
23842 +
23843 +#ifdef CONFIG_PAX_EMUTRAMP
23844 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23845 +#endif
23846 +
23847 +#ifdef CONFIG_PAX_PAGEEXEC
23848 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23849 +{
23850 + pgd_t *pgd;
23851 + pud_t *pud;
23852 + pmd_t *pmd;
23853 +
23854 + pgd = pgd_offset(mm, address);
23855 + if (!pgd_present(*pgd))
23856 + return NULL;
23857 + pud = pud_offset(pgd, address);
23858 + if (!pud_present(*pud))
23859 + return NULL;
23860 + pmd = pmd_offset(pud, address);
23861 + if (!pmd_present(*pmd))
23862 + return NULL;
23863 + return pmd;
23864 +}
23865 +#endif
23866 +
23867 DEFINE_SPINLOCK(pgd_lock);
23868 LIST_HEAD(pgd_list);
23869
23870 @@ -224,11 +267,24 @@ void vmalloc_sync_all(void)
23871 address += PMD_SIZE) {
23872
23873 unsigned long flags;
23874 +
23875 +#ifdef CONFIG_PAX_PER_CPU_PGD
23876 + unsigned long cpu;
23877 +#else
23878 struct page *page;
23879 +#endif
23880
23881 spin_lock_irqsave(&pgd_lock, flags);
23882 +
23883 +#ifdef CONFIG_PAX_PER_CPU_PGD
23884 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23885 + pgd_t *pgd = get_cpu_pgd(cpu);
23886 +#else
23887 list_for_each_entry(page, &pgd_list, lru) {
23888 - if (!vmalloc_sync_one(page_address(page), address))
23889 + pgd_t *pgd = page_address(page);
23890 +#endif
23891 +
23892 + if (!vmalloc_sync_one(pgd, address))
23893 break;
23894 }
23895 spin_unlock_irqrestore(&pgd_lock, flags);
23896 @@ -258,6 +314,11 @@ static noinline int vmalloc_fault(unsigned long address)
23897 * an interrupt in the middle of a task switch..
23898 */
23899 pgd_paddr = read_cr3();
23900 +
23901 +#ifdef CONFIG_PAX_PER_CPU_PGD
23902 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23903 +#endif
23904 +
23905 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23906 if (!pmd_k)
23907 return -1;
23908 @@ -332,15 +393,27 @@ void vmalloc_sync_all(void)
23909
23910 const pgd_t *pgd_ref = pgd_offset_k(address);
23911 unsigned long flags;
23912 +
23913 +#ifdef CONFIG_PAX_PER_CPU_PGD
23914 + unsigned long cpu;
23915 +#else
23916 struct page *page;
23917 +#endif
23918
23919 if (pgd_none(*pgd_ref))
23920 continue;
23921
23922 spin_lock_irqsave(&pgd_lock, flags);
23923 +
23924 +#ifdef CONFIG_PAX_PER_CPU_PGD
23925 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23926 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
23927 +#else
23928 list_for_each_entry(page, &pgd_list, lru) {
23929 pgd_t *pgd;
23930 pgd = (pgd_t *)page_address(page) + pgd_index(address);
23931 +#endif
23932 +
23933 if (pgd_none(*pgd))
23934 set_pgd(pgd, *pgd_ref);
23935 else
23936 @@ -373,7 +446,14 @@ static noinline int vmalloc_fault(unsigned long address)
23937 * happen within a race in page table update. In the later
23938 * case just flush:
23939 */
23940 +
23941 +#ifdef CONFIG_PAX_PER_CPU_PGD
23942 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23943 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23944 +#else
23945 pgd = pgd_offset(current->active_mm, address);
23946 +#endif
23947 +
23948 pgd_ref = pgd_offset_k(address);
23949 if (pgd_none(*pgd_ref))
23950 return -1;
23951 @@ -535,7 +615,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23952 static int is_errata100(struct pt_regs *regs, unsigned long address)
23953 {
23954 #ifdef CONFIG_X86_64
23955 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23956 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23957 return 1;
23958 #endif
23959 return 0;
23960 @@ -562,7 +642,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23961 }
23962
23963 static const char nx_warning[] = KERN_CRIT
23964 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23965 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23966
23967 static void
23968 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23969 @@ -571,15 +651,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23970 if (!oops_may_print())
23971 return;
23972
23973 - if (error_code & PF_INSTR) {
23974 + if (nx_enabled && (error_code & PF_INSTR)) {
23975 unsigned int level;
23976
23977 pte_t *pte = lookup_address(address, &level);
23978
23979 if (pte && pte_present(*pte) && !pte_exec(*pte))
23980 - printk(nx_warning, current_uid());
23981 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23982 }
23983
23984 +#ifdef CONFIG_PAX_KERNEXEC
23985 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23986 + if (current->signal->curr_ip)
23987 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23988 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23989 + else
23990 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23991 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23992 + }
23993 +#endif
23994 +
23995 printk(KERN_ALERT "BUG: unable to handle kernel ");
23996 if (address < PAGE_SIZE)
23997 printk(KERN_CONT "NULL pointer dereference");
23998 @@ -705,6 +796,23 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23999 {
24000 struct task_struct *tsk = current;
24001
24002 +#ifdef CONFIG_X86_64
24003 + struct mm_struct *mm = tsk->mm;
24004 +
24005 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
24006 + if (regs->ip == (unsigned long)vgettimeofday) {
24007 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
24008 + return;
24009 + } else if (regs->ip == (unsigned long)vtime) {
24010 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
24011 + return;
24012 + } else if (regs->ip == (unsigned long)vgetcpu) {
24013 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
24014 + return;
24015 + }
24016 + }
24017 +#endif
24018 +
24019 /* User mode accesses just cause a SIGSEGV */
24020 if (error_code & PF_USER) {
24021 /*
24022 @@ -722,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24023 if (is_errata100(regs, address))
24024 return;
24025
24026 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24027 + if (pax_is_fetch_fault(regs, error_code, address)) {
24028 +
24029 +#ifdef CONFIG_PAX_EMUTRAMP
24030 + switch (pax_handle_fetch_fault(regs)) {
24031 + case 2:
24032 + return;
24033 + }
24034 +#endif
24035 +
24036 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24037 + do_group_exit(SIGKILL);
24038 + }
24039 +#endif
24040 +
24041 if (unlikely(show_unhandled_signals))
24042 show_signal_msg(regs, error_code, address, tsk);
24043
24044 @@ -818,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24045 if (fault & VM_FAULT_HWPOISON) {
24046 printk(KERN_ERR
24047 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24048 - tsk->comm, tsk->pid, address);
24049 + tsk->comm, task_pid_nr(tsk), address);
24050 code = BUS_MCEERR_AR;
24051 }
24052 #endif
24053 @@ -857,6 +980,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24054 return 1;
24055 }
24056
24057 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24058 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24059 +{
24060 + pte_t *pte;
24061 + pmd_t *pmd;
24062 + spinlock_t *ptl;
24063 + unsigned char pte_mask;
24064 +
24065 + if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24066 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
24067 + return 0;
24068 +
24069 + /* PaX: it's our fault, let's handle it if we can */
24070 +
24071 + /* PaX: take a look at read faults before acquiring any locks */
24072 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24073 + /* instruction fetch attempt from a protected page in user mode */
24074 + up_read(&mm->mmap_sem);
24075 +
24076 +#ifdef CONFIG_PAX_EMUTRAMP
24077 + switch (pax_handle_fetch_fault(regs)) {
24078 + case 2:
24079 + return 1;
24080 + }
24081 +#endif
24082 +
24083 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24084 + do_group_exit(SIGKILL);
24085 + }
24086 +
24087 + pmd = pax_get_pmd(mm, address);
24088 + if (unlikely(!pmd))
24089 + return 0;
24090 +
24091 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24092 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24093 + pte_unmap_unlock(pte, ptl);
24094 + return 0;
24095 + }
24096 +
24097 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24098 + /* write attempt to a protected page in user mode */
24099 + pte_unmap_unlock(pte, ptl);
24100 + return 0;
24101 + }
24102 +
24103 +#ifdef CONFIG_SMP
24104 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24105 +#else
24106 + if (likely(address > get_limit(regs->cs)))
24107 +#endif
24108 + {
24109 + set_pte(pte, pte_mkread(*pte));
24110 + __flush_tlb_one(address);
24111 + pte_unmap_unlock(pte, ptl);
24112 + up_read(&mm->mmap_sem);
24113 + return 1;
24114 + }
24115 +
24116 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24117 +
24118 + /*
24119 + * PaX: fill DTLB with user rights and retry
24120 + */
24121 + __asm__ __volatile__ (
24122 + "orb %2,(%1)\n"
24123 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24124 +/*
24125 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24126 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24127 + * page fault when examined during a TLB load attempt. this is true not only
24128 + * for PTEs holding a non-present entry but also present entries that will
24129 + * raise a page fault (such as those set up by PaX, or the copy-on-write
24130 + * mechanism). in effect it means that we do *not* need to flush the TLBs
24131 + * for our target pages since their PTEs are simply not in the TLBs at all.
24132 +
24133 + * the best thing in omitting it is that we gain around 15-20% speed in the
24134 + * fast path of the page fault handler and can get rid of tracing since we
24135 + * can no longer flush unintended entries.
24136 + */
24137 + "invlpg (%0)\n"
24138 +#endif
24139 + __copyuser_seg"testb $0,(%0)\n"
24140 + "xorb %3,(%1)\n"
24141 + :
24142 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24143 + : "memory", "cc");
24144 + pte_unmap_unlock(pte, ptl);
24145 + up_read(&mm->mmap_sem);
24146 + return 1;
24147 +}
24148 +#endif
24149 +
24150 /*
24151 * Handle a spurious fault caused by a stale TLB entry.
24152 *
24153 @@ -923,6 +1139,9 @@ int show_unhandled_signals = 1;
24154 static inline int
24155 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
24156 {
24157 + if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24158 + return 1;
24159 +
24160 if (write) {
24161 /* write, present and write, not present: */
24162 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24163 @@ -956,16 +1175,30 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24164 {
24165 struct vm_area_struct *vma;
24166 struct task_struct *tsk;
24167 - unsigned long address;
24168 struct mm_struct *mm;
24169 int write;
24170 int fault;
24171
24172 - tsk = current;
24173 - mm = tsk->mm;
24174 -
24175 /* Get the faulting address: */
24176 - address = read_cr2();
24177 + unsigned long address = read_cr2();
24178 +
24179 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24180 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24181 + if (!search_exception_tables(regs->ip)) {
24182 + bad_area_nosemaphore(regs, error_code, address);
24183 + return;
24184 + }
24185 + if (address < PAX_USER_SHADOW_BASE) {
24186 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24187 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
24188 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24189 + } else
24190 + address -= PAX_USER_SHADOW_BASE;
24191 + }
24192 +#endif
24193 +
24194 + tsk = current;
24195 + mm = tsk->mm;
24196
24197 /*
24198 * Detect and handle instructions that would cause a page fault for
24199 @@ -1026,7 +1259,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24200 * User-mode registers count as a user access even for any
24201 * potential system fault or CPU buglet:
24202 */
24203 - if (user_mode_vm(regs)) {
24204 + if (user_mode(regs)) {
24205 local_irq_enable();
24206 error_code |= PF_USER;
24207 } else {
24208 @@ -1080,6 +1313,11 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24209 might_sleep();
24210 }
24211
24212 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24213 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24214 + return;
24215 +#endif
24216 +
24217 vma = find_vma(mm, address);
24218 if (unlikely(!vma)) {
24219 bad_area(regs, error_code, address);
24220 @@ -1091,18 +1329,24 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24221 bad_area(regs, error_code, address);
24222 return;
24223 }
24224 - if (error_code & PF_USER) {
24225 - /*
24226 - * Accessing the stack below %sp is always a bug.
24227 - * The large cushion allows instructions like enter
24228 - * and pusha to work. ("enter $65535, $31" pushes
24229 - * 32 pointers and then decrements %sp by 65535.)
24230 - */
24231 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24232 - bad_area(regs, error_code, address);
24233 - return;
24234 - }
24235 + /*
24236 + * Accessing the stack below %sp is always a bug.
24237 + * The large cushion allows instructions like enter
24238 + * and pusha to work. ("enter $65535, $31" pushes
24239 + * 32 pointers and then decrements %sp by 65535.)
24240 + */
24241 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24242 + bad_area(regs, error_code, address);
24243 + return;
24244 }
24245 +
24246 +#ifdef CONFIG_PAX_SEGMEXEC
24247 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24248 + bad_area(regs, error_code, address);
24249 + return;
24250 + }
24251 +#endif
24252 +
24253 if (unlikely(expand_stack(vma, address))) {
24254 bad_area(regs, error_code, address);
24255 return;
24256 @@ -1146,3 +1390,240 @@ good_area:
24257
24258 up_read(&mm->mmap_sem);
24259 }
24260 +
24261 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24262 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24263 +{
24264 + struct mm_struct *mm = current->mm;
24265 + unsigned long ip = regs->ip;
24266 +
24267 + if (v8086_mode(regs))
24268 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24269 +
24270 +#ifdef CONFIG_PAX_PAGEEXEC
24271 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24272 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24273 + return true;
24274 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24275 + return true;
24276 + return false;
24277 + }
24278 +#endif
24279 +
24280 +#ifdef CONFIG_PAX_SEGMEXEC
24281 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24282 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24283 + return true;
24284 + return false;
24285 + }
24286 +#endif
24287 +
24288 + return false;
24289 +}
24290 +#endif
24291 +
24292 +#ifdef CONFIG_PAX_EMUTRAMP
24293 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24294 +{
24295 + int err;
24296 +
24297 + do { /* PaX: gcc trampoline emulation #1 */
24298 + unsigned char mov1, mov2;
24299 + unsigned short jmp;
24300 + unsigned int addr1, addr2;
24301 +
24302 +#ifdef CONFIG_X86_64
24303 + if ((regs->ip + 11) >> 32)
24304 + break;
24305 +#endif
24306 +
24307 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24308 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24309 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24310 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24311 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24312 +
24313 + if (err)
24314 + break;
24315 +
24316 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24317 + regs->cx = addr1;
24318 + regs->ax = addr2;
24319 + regs->ip = addr2;
24320 + return 2;
24321 + }
24322 + } while (0);
24323 +
24324 + do { /* PaX: gcc trampoline emulation #2 */
24325 + unsigned char mov, jmp;
24326 + unsigned int addr1, addr2;
24327 +
24328 +#ifdef CONFIG_X86_64
24329 + if ((regs->ip + 9) >> 32)
24330 + break;
24331 +#endif
24332 +
24333 + err = get_user(mov, (unsigned char __user *)regs->ip);
24334 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24335 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24336 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24337 +
24338 + if (err)
24339 + break;
24340 +
24341 + if (mov == 0xB9 && jmp == 0xE9) {
24342 + regs->cx = addr1;
24343 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24344 + return 2;
24345 + }
24346 + } while (0);
24347 +
24348 + return 1; /* PaX in action */
24349 +}
24350 +
24351 +#ifdef CONFIG_X86_64
24352 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24353 +{
24354 + int err;
24355 +
24356 + do { /* PaX: gcc trampoline emulation #1 */
24357 + unsigned short mov1, mov2, jmp1;
24358 + unsigned char jmp2;
24359 + unsigned int addr1;
24360 + unsigned long addr2;
24361 +
24362 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24363 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24364 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24365 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24366 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24367 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24368 +
24369 + if (err)
24370 + break;
24371 +
24372 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24373 + regs->r11 = addr1;
24374 + regs->r10 = addr2;
24375 + regs->ip = addr1;
24376 + return 2;
24377 + }
24378 + } while (0);
24379 +
24380 + do { /* PaX: gcc trampoline emulation #2 */
24381 + unsigned short mov1, mov2, jmp1;
24382 + unsigned char jmp2;
24383 + unsigned long addr1, addr2;
24384 +
24385 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24386 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24387 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24388 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24389 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24390 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24391 +
24392 + if (err)
24393 + break;
24394 +
24395 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24396 + regs->r11 = addr1;
24397 + regs->r10 = addr2;
24398 + regs->ip = addr1;
24399 + return 2;
24400 + }
24401 + } while (0);
24402 +
24403 + return 1; /* PaX in action */
24404 +}
24405 +#endif
24406 +
24407 +/*
24408 + * PaX: decide what to do with offenders (regs->ip = fault address)
24409 + *
24410 + * returns 1 when task should be killed
24411 + * 2 when gcc trampoline was detected
24412 + */
24413 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24414 +{
24415 + if (v8086_mode(regs))
24416 + return 1;
24417 +
24418 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24419 + return 1;
24420 +
24421 +#ifdef CONFIG_X86_32
24422 + return pax_handle_fetch_fault_32(regs);
24423 +#else
24424 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24425 + return pax_handle_fetch_fault_32(regs);
24426 + else
24427 + return pax_handle_fetch_fault_64(regs);
24428 +#endif
24429 +}
24430 +#endif
24431 +
24432 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24433 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24434 +{
24435 + long i;
24436 +
24437 + printk(KERN_ERR "PAX: bytes at PC: ");
24438 + for (i = 0; i < 20; i++) {
24439 + unsigned char c;
24440 + if (get_user(c, (unsigned char __force_user *)pc+i))
24441 + printk(KERN_CONT "?? ");
24442 + else
24443 + printk(KERN_CONT "%02x ", c);
24444 + }
24445 + printk("\n");
24446 +
24447 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24448 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24449 + unsigned long c;
24450 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24451 +#ifdef CONFIG_X86_32
24452 + printk(KERN_CONT "???????? ");
24453 +#else
24454 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24455 + printk(KERN_CONT "???????? ???????? ");
24456 + else
24457 + printk(KERN_CONT "???????????????? ");
24458 +#endif
24459 + } else {
24460 +#ifdef CONFIG_X86_64
24461 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24462 + printk(KERN_CONT "%08x ", (unsigned int)c);
24463 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24464 + } else
24465 +#endif
24466 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24467 + }
24468 + }
24469 + printk("\n");
24470 +}
24471 +#endif
24472 +
24473 +/**
24474 + * probe_kernel_write(): safely attempt to write to a location
24475 + * @dst: address to write to
24476 + * @src: pointer to the data that shall be written
24477 + * @size: size of the data chunk
24478 + *
24479 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24480 + * happens, handle that and return -EFAULT.
24481 + */
24482 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24483 +{
24484 + long ret;
24485 + mm_segment_t old_fs = get_fs();
24486 +
24487 + set_fs(KERNEL_DS);
24488 + pagefault_disable();
24489 + pax_open_kernel();
24490 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24491 + pax_close_kernel();
24492 + pagefault_enable();
24493 + set_fs(old_fs);
24494 +
24495 + return ret ? -EFAULT : 0;
24496 +}
24497 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24498 index 71da1bc..7a16bf4 100644
24499 --- a/arch/x86/mm/gup.c
24500 +++ b/arch/x86/mm/gup.c
24501 @@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24502 addr = start;
24503 len = (unsigned long) nr_pages << PAGE_SHIFT;
24504 end = start + len;
24505 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24506 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24507 (void __user *)start, len)))
24508 return 0;
24509
24510 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24511 index 63a6ba6..79abd7a 100644
24512 --- a/arch/x86/mm/highmem_32.c
24513 +++ b/arch/x86/mm/highmem_32.c
24514 @@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
24515 idx = type + KM_TYPE_NR*smp_processor_id();
24516 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24517 BUG_ON(!pte_none(*(kmap_pte-idx)));
24518 +
24519 + pax_open_kernel();
24520 set_pte(kmap_pte-idx, mk_pte(page, prot));
24521 + pax_close_kernel();
24522
24523 return (void *)vaddr;
24524 }
24525 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24526 index f46c340..6ff9a26 100644
24527 --- a/arch/x86/mm/hugetlbpage.c
24528 +++ b/arch/x86/mm/hugetlbpage.c
24529 @@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24530 struct hstate *h = hstate_file(file);
24531 struct mm_struct *mm = current->mm;
24532 struct vm_area_struct *vma;
24533 - unsigned long start_addr;
24534 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24535 +
24536 +#ifdef CONFIG_PAX_SEGMEXEC
24537 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24538 + pax_task_size = SEGMEXEC_TASK_SIZE;
24539 +#endif
24540 +
24541 + pax_task_size -= PAGE_SIZE;
24542
24543 if (len > mm->cached_hole_size) {
24544 - start_addr = mm->free_area_cache;
24545 + start_addr = mm->free_area_cache;
24546 } else {
24547 - start_addr = TASK_UNMAPPED_BASE;
24548 - mm->cached_hole_size = 0;
24549 + start_addr = mm->mmap_base;
24550 + mm->cached_hole_size = 0;
24551 }
24552
24553 full_search:
24554 @@ -281,26 +288,27 @@ full_search:
24555
24556 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24557 /* At this point: (!vma || addr < vma->vm_end). */
24558 - if (TASK_SIZE - len < addr) {
24559 + if (pax_task_size - len < addr) {
24560 /*
24561 * Start a new search - just in case we missed
24562 * some holes.
24563 */
24564 - if (start_addr != TASK_UNMAPPED_BASE) {
24565 - start_addr = TASK_UNMAPPED_BASE;
24566 + if (start_addr != mm->mmap_base) {
24567 + start_addr = mm->mmap_base;
24568 mm->cached_hole_size = 0;
24569 goto full_search;
24570 }
24571 return -ENOMEM;
24572 }
24573 - if (!vma || addr + len <= vma->vm_start) {
24574 - mm->free_area_cache = addr + len;
24575 - return addr;
24576 - }
24577 + if (check_heap_stack_gap(vma, addr, len))
24578 + break;
24579 if (addr + mm->cached_hole_size < vma->vm_start)
24580 mm->cached_hole_size = vma->vm_start - addr;
24581 addr = ALIGN(vma->vm_end, huge_page_size(h));
24582 }
24583 +
24584 + mm->free_area_cache = addr + len;
24585 + return addr;
24586 }
24587
24588 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24589 @@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24590 {
24591 struct hstate *h = hstate_file(file);
24592 struct mm_struct *mm = current->mm;
24593 - struct vm_area_struct *vma, *prev_vma;
24594 - unsigned long base = mm->mmap_base, addr = addr0;
24595 + struct vm_area_struct *vma;
24596 + unsigned long base = mm->mmap_base, addr;
24597 unsigned long largest_hole = mm->cached_hole_size;
24598 - int first_time = 1;
24599
24600 /* don't allow allocations above current base */
24601 if (mm->free_area_cache > base)
24602 @@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24603 largest_hole = 0;
24604 mm->free_area_cache = base;
24605 }
24606 -try_again:
24607 +
24608 /* make sure it can fit in the remaining address space */
24609 if (mm->free_area_cache < len)
24610 goto fail;
24611
24612 /* either no address requested or cant fit in requested address hole */
24613 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24614 + addr = (mm->free_area_cache - len);
24615 do {
24616 + addr &= huge_page_mask(h);
24617 + vma = find_vma(mm, addr);
24618 /*
24619 * Lookup failure means no vma is above this address,
24620 * i.e. return with success:
24621 - */
24622 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
24623 - return addr;
24624 -
24625 - /*
24626 * new region fits between prev_vma->vm_end and
24627 * vma->vm_start, use it:
24628 */
24629 - if (addr + len <= vma->vm_start &&
24630 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24631 + if (check_heap_stack_gap(vma, addr, len)) {
24632 /* remember the address as a hint for next time */
24633 - mm->cached_hole_size = largest_hole;
24634 - return (mm->free_area_cache = addr);
24635 - } else {
24636 - /* pull free_area_cache down to the first hole */
24637 - if (mm->free_area_cache == vma->vm_end) {
24638 - mm->free_area_cache = vma->vm_start;
24639 - mm->cached_hole_size = largest_hole;
24640 - }
24641 + mm->cached_hole_size = largest_hole;
24642 + return (mm->free_area_cache = addr);
24643 + }
24644 + /* pull free_area_cache down to the first hole */
24645 + if (mm->free_area_cache == vma->vm_end) {
24646 + mm->free_area_cache = vma->vm_start;
24647 + mm->cached_hole_size = largest_hole;
24648 }
24649
24650 /* remember the largest hole we saw so far */
24651 if (addr + largest_hole < vma->vm_start)
24652 - largest_hole = vma->vm_start - addr;
24653 + largest_hole = vma->vm_start - addr;
24654
24655 /* try just below the current vma->vm_start */
24656 - addr = (vma->vm_start - len) & huge_page_mask(h);
24657 - } while (len <= vma->vm_start);
24658 + addr = skip_heap_stack_gap(vma, len);
24659 + } while (!IS_ERR_VALUE(addr));
24660
24661 fail:
24662 /*
24663 - * if hint left us with no space for the requested
24664 - * mapping then try again:
24665 - */
24666 - if (first_time) {
24667 - mm->free_area_cache = base;
24668 - largest_hole = 0;
24669 - first_time = 0;
24670 - goto try_again;
24671 - }
24672 - /*
24673 * A failed mmap() very likely causes application failure,
24674 * so fall back to the bottom-up function here. This scenario
24675 * can happen with large stack limits and large mmap()
24676 * allocations.
24677 */
24678 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24679 +
24680 +#ifdef CONFIG_PAX_SEGMEXEC
24681 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24682 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24683 + else
24684 +#endif
24685 +
24686 + mm->mmap_base = TASK_UNMAPPED_BASE;
24687 +
24688 +#ifdef CONFIG_PAX_RANDMMAP
24689 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24690 + mm->mmap_base += mm->delta_mmap;
24691 +#endif
24692 +
24693 + mm->free_area_cache = mm->mmap_base;
24694 mm->cached_hole_size = ~0UL;
24695 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24696 len, pgoff, flags);
24697 @@ -387,6 +393,7 @@ fail:
24698 /*
24699 * Restore the topdown base:
24700 */
24701 + mm->mmap_base = base;
24702 mm->free_area_cache = base;
24703 mm->cached_hole_size = ~0UL;
24704
24705 @@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24706 struct hstate *h = hstate_file(file);
24707 struct mm_struct *mm = current->mm;
24708 struct vm_area_struct *vma;
24709 + unsigned long pax_task_size = TASK_SIZE;
24710
24711 if (len & ~huge_page_mask(h))
24712 return -EINVAL;
24713 - if (len > TASK_SIZE)
24714 +
24715 +#ifdef CONFIG_PAX_SEGMEXEC
24716 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24717 + pax_task_size = SEGMEXEC_TASK_SIZE;
24718 +#endif
24719 +
24720 + pax_task_size -= PAGE_SIZE;
24721 +
24722 + if (len > pax_task_size)
24723 return -ENOMEM;
24724
24725 if (flags & MAP_FIXED) {
24726 @@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24727 if (addr) {
24728 addr = ALIGN(addr, huge_page_size(h));
24729 vma = find_vma(mm, addr);
24730 - if (TASK_SIZE - len >= addr &&
24731 - (!vma || addr + len <= vma->vm_start))
24732 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24733 return addr;
24734 }
24735 if (mm->get_unmapped_area == arch_get_unmapped_area)
24736 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24737 index 73ffd55..ad78676 100644
24738 --- a/arch/x86/mm/init.c
24739 +++ b/arch/x86/mm/init.c
24740 @@ -69,11 +69,7 @@ static void __init find_early_table_space(unsigned long end, int use_pse,
24741 * cause a hotspot and fill up ZONE_DMA. The page tables
24742 * need roughly 0.5KB per GB.
24743 */
24744 -#ifdef CONFIG_X86_32
24745 - start = 0x7000;
24746 -#else
24747 - start = 0x8000;
24748 -#endif
24749 + start = 0x100000;
24750 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
24751 tables, PAGE_SIZE);
24752 if (e820_table_start == -1UL)
24753 @@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24754 #endif
24755
24756 set_nx();
24757 - if (nx_enabled)
24758 + if (nx_enabled && cpu_has_nx)
24759 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
24760
24761 /* Enable PSE if available */
24762 @@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24763 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24764 * mmio resources as well as potential bios/acpi data regions.
24765 */
24766 +
24767 int devmem_is_allowed(unsigned long pagenr)
24768 {
24769 +#ifdef CONFIG_GRKERNSEC_KMEM
24770 + /* allow BDA */
24771 + if (!pagenr)
24772 + return 1;
24773 + /* allow EBDA */
24774 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24775 + return 1;
24776 + /* allow ISA/video mem */
24777 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24778 + return 1;
24779 + /* throw out everything else below 1MB */
24780 + if (pagenr <= 256)
24781 + return 0;
24782 +#else
24783 if (pagenr <= 256)
24784 return 1;
24785 +#endif
24786 +
24787 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24788 return 0;
24789 if (!page_is_ram(pagenr))
24790 @@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24791
24792 void free_initmem(void)
24793 {
24794 +
24795 +#ifdef CONFIG_PAX_KERNEXEC
24796 +#ifdef CONFIG_X86_32
24797 + /* PaX: limit KERNEL_CS to actual size */
24798 + unsigned long addr, limit;
24799 + struct desc_struct d;
24800 + int cpu;
24801 +
24802 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24803 + limit = (limit - 1UL) >> PAGE_SHIFT;
24804 +
24805 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24806 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
24807 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24808 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24809 + }
24810 +
24811 + /* PaX: make KERNEL_CS read-only */
24812 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24813 + if (!paravirt_enabled())
24814 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24815 +/*
24816 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24817 + pgd = pgd_offset_k(addr);
24818 + pud = pud_offset(pgd, addr);
24819 + pmd = pmd_offset(pud, addr);
24820 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24821 + }
24822 +*/
24823 +#ifdef CONFIG_X86_PAE
24824 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24825 +/*
24826 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24827 + pgd = pgd_offset_k(addr);
24828 + pud = pud_offset(pgd, addr);
24829 + pmd = pmd_offset(pud, addr);
24830 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24831 + }
24832 +*/
24833 +#endif
24834 +
24835 +#ifdef CONFIG_MODULES
24836 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24837 +#endif
24838 +
24839 +#else
24840 + pgd_t *pgd;
24841 + pud_t *pud;
24842 + pmd_t *pmd;
24843 + unsigned long addr, end;
24844 +
24845 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24846 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24847 + pgd = pgd_offset_k(addr);
24848 + pud = pud_offset(pgd, addr);
24849 + pmd = pmd_offset(pud, addr);
24850 + if (!pmd_present(*pmd))
24851 + continue;
24852 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24853 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24854 + else
24855 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24856 + }
24857 +
24858 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24859 + end = addr + KERNEL_IMAGE_SIZE;
24860 + for (; addr < end; addr += PMD_SIZE) {
24861 + pgd = pgd_offset_k(addr);
24862 + pud = pud_offset(pgd, addr);
24863 + pmd = pmd_offset(pud, addr);
24864 + if (!pmd_present(*pmd))
24865 + continue;
24866 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24867 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24868 + }
24869 +#endif
24870 +
24871 + flush_tlb_all();
24872 +#endif
24873 +
24874 free_init_pages("unused kernel memory",
24875 (unsigned long)(&__init_begin),
24876 (unsigned long)(&__init_end));
24877 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24878 index 30938c1..bda3d5d 100644
24879 --- a/arch/x86/mm/init_32.c
24880 +++ b/arch/x86/mm/init_32.c
24881 @@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
24882 }
24883
24884 /*
24885 - * Creates a middle page table and puts a pointer to it in the
24886 - * given global directory entry. This only returns the gd entry
24887 - * in non-PAE compilation mode, since the middle layer is folded.
24888 - */
24889 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24890 -{
24891 - pud_t *pud;
24892 - pmd_t *pmd_table;
24893 -
24894 -#ifdef CONFIG_X86_PAE
24895 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24896 - if (after_bootmem)
24897 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24898 - else
24899 - pmd_table = (pmd_t *)alloc_low_page();
24900 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24901 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24902 - pud = pud_offset(pgd, 0);
24903 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24904 -
24905 - return pmd_table;
24906 - }
24907 -#endif
24908 - pud = pud_offset(pgd, 0);
24909 - pmd_table = pmd_offset(pud, 0);
24910 -
24911 - return pmd_table;
24912 -}
24913 -
24914 -/*
24915 * Create a page table and place a pointer to it in a middle page
24916 * directory entry:
24917 */
24918 @@ -121,13 +91,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24919 page_table = (pte_t *)alloc_low_page();
24920
24921 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24922 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24923 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24924 +#else
24925 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24926 +#endif
24927 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24928 }
24929
24930 return pte_offset_kernel(pmd, 0);
24931 }
24932
24933 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24934 +{
24935 + pud_t *pud;
24936 + pmd_t *pmd_table;
24937 +
24938 + pud = pud_offset(pgd, 0);
24939 + pmd_table = pmd_offset(pud, 0);
24940 +
24941 + return pmd_table;
24942 +}
24943 +
24944 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24945 {
24946 int pgd_idx = pgd_index(vaddr);
24947 @@ -201,6 +186,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24948 int pgd_idx, pmd_idx;
24949 unsigned long vaddr;
24950 pgd_t *pgd;
24951 + pud_t *pud;
24952 pmd_t *pmd;
24953 pte_t *pte = NULL;
24954
24955 @@ -210,8 +196,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24956 pgd = pgd_base + pgd_idx;
24957
24958 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24959 - pmd = one_md_table_init(pgd);
24960 - pmd = pmd + pmd_index(vaddr);
24961 + pud = pud_offset(pgd, vaddr);
24962 + pmd = pmd_offset(pud, vaddr);
24963 +
24964 +#ifdef CONFIG_X86_PAE
24965 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24966 +#endif
24967 +
24968 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24969 pmd++, pmd_idx++) {
24970 pte = page_table_kmap_check(one_page_table_init(pmd),
24971 @@ -223,11 +214,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24972 }
24973 }
24974
24975 -static inline int is_kernel_text(unsigned long addr)
24976 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24977 {
24978 - if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
24979 - return 1;
24980 - return 0;
24981 + if ((start > ktla_ktva((unsigned long)_etext) ||
24982 + end <= ktla_ktva((unsigned long)_stext)) &&
24983 + (start > ktla_ktva((unsigned long)_einittext) ||
24984 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24985 +
24986 +#ifdef CONFIG_ACPI_SLEEP
24987 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24988 +#endif
24989 +
24990 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24991 + return 0;
24992 + return 1;
24993 }
24994
24995 /*
24996 @@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned long start,
24997 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
24998 unsigned long start_pfn, end_pfn;
24999 pgd_t *pgd_base = swapper_pg_dir;
25000 - int pgd_idx, pmd_idx, pte_ofs;
25001 + unsigned int pgd_idx, pmd_idx, pte_ofs;
25002 unsigned long pfn;
25003 pgd_t *pgd;
25004 + pud_t *pud;
25005 pmd_t *pmd;
25006 pte_t *pte;
25007 unsigned pages_2m, pages_4k;
25008 @@ -278,8 +279,13 @@ repeat:
25009 pfn = start_pfn;
25010 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25011 pgd = pgd_base + pgd_idx;
25012 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25013 - pmd = one_md_table_init(pgd);
25014 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25015 + pud = pud_offset(pgd, 0);
25016 + pmd = pmd_offset(pud, 0);
25017 +
25018 +#ifdef CONFIG_X86_PAE
25019 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25020 +#endif
25021
25022 if (pfn >= end_pfn)
25023 continue;
25024 @@ -291,14 +297,13 @@ repeat:
25025 #endif
25026 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25027 pmd++, pmd_idx++) {
25028 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25029 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25030
25031 /*
25032 * Map with big pages if possible, otherwise
25033 * create normal page tables:
25034 */
25035 if (use_pse) {
25036 - unsigned int addr2;
25037 pgprot_t prot = PAGE_KERNEL_LARGE;
25038 /*
25039 * first pass will use the same initial
25040 @@ -308,11 +313,7 @@ repeat:
25041 __pgprot(PTE_IDENT_ATTR |
25042 _PAGE_PSE);
25043
25044 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25045 - PAGE_OFFSET + PAGE_SIZE-1;
25046 -
25047 - if (is_kernel_text(addr) ||
25048 - is_kernel_text(addr2))
25049 + if (is_kernel_text(address, address + PMD_SIZE))
25050 prot = PAGE_KERNEL_LARGE_EXEC;
25051
25052 pages_2m++;
25053 @@ -329,7 +330,7 @@ repeat:
25054 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25055 pte += pte_ofs;
25056 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25057 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25058 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25059 pgprot_t prot = PAGE_KERNEL;
25060 /*
25061 * first pass will use the same initial
25062 @@ -337,7 +338,7 @@ repeat:
25063 */
25064 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25065
25066 - if (is_kernel_text(addr))
25067 + if (is_kernel_text(address, address + PAGE_SIZE))
25068 prot = PAGE_KERNEL_EXEC;
25069
25070 pages_4k++;
25071 @@ -489,7 +490,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25072
25073 pud = pud_offset(pgd, va);
25074 pmd = pmd_offset(pud, va);
25075 - if (!pmd_present(*pmd))
25076 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25077 break;
25078
25079 pte = pte_offset_kernel(pmd, va);
25080 @@ -541,9 +542,7 @@ void __init early_ioremap_page_table_range_init(void)
25081
25082 static void __init pagetable_init(void)
25083 {
25084 - pgd_t *pgd_base = swapper_pg_dir;
25085 -
25086 - permanent_kmaps_init(pgd_base);
25087 + permanent_kmaps_init(swapper_pg_dir);
25088 }
25089
25090 #ifdef CONFIG_ACPI_SLEEP
25091 @@ -551,12 +550,12 @@ static void __init pagetable_init(void)
25092 * ACPI suspend needs this for resume, because things like the intel-agp
25093 * driver might have split up a kernel 4MB mapping.
25094 */
25095 -char swsusp_pg_dir[PAGE_SIZE]
25096 +pgd_t swsusp_pg_dir[PTRS_PER_PGD]
25097 __attribute__ ((aligned(PAGE_SIZE)));
25098
25099 static inline void save_pg_dir(void)
25100 {
25101 - memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
25102 + clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
25103 }
25104 #else /* !CONFIG_ACPI_SLEEP */
25105 static inline void save_pg_dir(void)
25106 @@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
25107 flush_tlb_all();
25108 }
25109
25110 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25111 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25112 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25113
25114 /* user-defined highmem size */
25115 @@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void)
25116 * Initialize the boot-time allocator (with low memory only):
25117 */
25118 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
25119 - bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
25120 + bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
25121 PAGE_SIZE);
25122 if (bootmap == -1L)
25123 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
25124 @@ -864,6 +863,12 @@ void __init mem_init(void)
25125
25126 pci_iommu_alloc();
25127
25128 +#ifdef CONFIG_PAX_PER_CPU_PGD
25129 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25130 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25131 + KERNEL_PGD_PTRS);
25132 +#endif
25133 +
25134 #ifdef CONFIG_FLATMEM
25135 BUG_ON(!mem_map);
25136 #endif
25137 @@ -881,7 +886,7 @@ void __init mem_init(void)
25138 set_highmem_pages_init();
25139
25140 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25141 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25142 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25143 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25144
25145 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25146 @@ -923,10 +928,10 @@ void __init mem_init(void)
25147 ((unsigned long)&__init_end -
25148 (unsigned long)&__init_begin) >> 10,
25149
25150 - (unsigned long)&_etext, (unsigned long)&_edata,
25151 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25152 + (unsigned long)&_sdata, (unsigned long)&_edata,
25153 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25154
25155 - (unsigned long)&_text, (unsigned long)&_etext,
25156 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25157 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25158
25159 /*
25160 @@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
25161 if (!kernel_set_to_readonly)
25162 return;
25163
25164 + start = ktla_ktva(start);
25165 pr_debug("Set kernel text: %lx - %lx for read write\n",
25166 start, start+size);
25167
25168 @@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
25169 if (!kernel_set_to_readonly)
25170 return;
25171
25172 + start = ktla_ktva(start);
25173 pr_debug("Set kernel text: %lx - %lx for read only\n",
25174 start, start+size);
25175
25176 @@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
25177 unsigned long start = PFN_ALIGN(_text);
25178 unsigned long size = PFN_ALIGN(_etext) - start;
25179
25180 + start = ktla_ktva(start);
25181 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25182 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25183 size >> 10);
25184 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25185 index 7d095ad..25d2549 100644
25186 --- a/arch/x86/mm/init_64.c
25187 +++ b/arch/x86/mm/init_64.c
25188 @@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25189 pmd = fill_pmd(pud, vaddr);
25190 pte = fill_pte(pmd, vaddr);
25191
25192 + pax_open_kernel();
25193 set_pte(pte, new_pte);
25194 + pax_close_kernel();
25195
25196 /*
25197 * It's enough to flush this one mapping.
25198 @@ -223,14 +225,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25199 pgd = pgd_offset_k((unsigned long)__va(phys));
25200 if (pgd_none(*pgd)) {
25201 pud = (pud_t *) spp_getpage();
25202 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25203 - _PAGE_USER));
25204 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25205 }
25206 pud = pud_offset(pgd, (unsigned long)__va(phys));
25207 if (pud_none(*pud)) {
25208 pmd = (pmd_t *) spp_getpage();
25209 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25210 - _PAGE_USER));
25211 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25212 }
25213 pmd = pmd_offset(pud, phys);
25214 BUG_ON(!pmd_none(*pmd));
25215 @@ -675,6 +675,12 @@ void __init mem_init(void)
25216
25217 pci_iommu_alloc();
25218
25219 +#ifdef CONFIG_PAX_PER_CPU_PGD
25220 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25221 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25222 + KERNEL_PGD_PTRS);
25223 +#endif
25224 +
25225 /* clear_bss() already clear the empty_zero_page */
25226
25227 reservedpages = 0;
25228 @@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
25229 static struct vm_area_struct gate_vma = {
25230 .vm_start = VSYSCALL_START,
25231 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25232 - .vm_page_prot = PAGE_READONLY_EXEC,
25233 - .vm_flags = VM_READ | VM_EXEC
25234 + .vm_page_prot = PAGE_READONLY,
25235 + .vm_flags = VM_READ
25236 };
25237
25238 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
25239 @@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long addr)
25240
25241 const char *arch_vma_name(struct vm_area_struct *vma)
25242 {
25243 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25244 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25245 return "[vdso]";
25246 if (vma == &gate_vma)
25247 return "[vsyscall]";
25248 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25249 index 84e236c..69bd3f6 100644
25250 --- a/arch/x86/mm/iomap_32.c
25251 +++ b/arch/x86/mm/iomap_32.c
25252 @@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
25253 debug_kmap_atomic(type);
25254 idx = type + KM_TYPE_NR * smp_processor_id();
25255 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25256 +
25257 + pax_open_kernel();
25258 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25259 + pax_close_kernel();
25260 +
25261 arch_flush_lazy_mmu_mode();
25262
25263 return (void *)vaddr;
25264 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25265 index 2feb9bd..3646202 100644
25266 --- a/arch/x86/mm/ioremap.c
25267 +++ b/arch/x86/mm/ioremap.c
25268 @@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
25269 * Second special case: Some BIOSen report the PC BIOS
25270 * area (640->1Mb) as ram even though it is not.
25271 */
25272 - if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
25273 - pagenr < (BIOS_END >> PAGE_SHIFT))
25274 + if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
25275 + pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
25276 return 0;
25277
25278 for (i = 0; i < e820.nr_map; i++) {
25279 @@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25280 /*
25281 * Don't allow anybody to remap normal RAM that we're using..
25282 */
25283 - for (pfn = phys_addr >> PAGE_SHIFT;
25284 - (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
25285 - pfn++) {
25286 -
25287 + for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
25288 int is_ram = page_is_ram(pfn);
25289
25290 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25291 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25292 return NULL;
25293 WARN_ON_ONCE(is_ram);
25294 }
25295 @@ -407,7 +404,7 @@ static int __init early_ioremap_debug_setup(char *str)
25296 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25297
25298 static __initdata int after_paging_init;
25299 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25300 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25301
25302 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25303 {
25304 @@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
25305 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25306
25307 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25308 - memset(bm_pte, 0, sizeof(bm_pte));
25309 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25310 + pmd_populate_user(&init_mm, pmd, bm_pte);
25311
25312 /*
25313 * The boot-ioremap range spans multiple pmds, for which
25314 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25315 index 8cc1833..1abbc5b 100644
25316 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25317 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25318 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25319 * memory (e.g. tracked pages)? For now, we need this to avoid
25320 * invoking kmemcheck for PnP BIOS calls.
25321 */
25322 - if (regs->flags & X86_VM_MASK)
25323 + if (v8086_mode(regs))
25324 return false;
25325 - if (regs->cs != __KERNEL_CS)
25326 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25327 return false;
25328
25329 pte = kmemcheck_pte_lookup(address);
25330 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25331 index c8191de..2975082 100644
25332 --- a/arch/x86/mm/mmap.c
25333 +++ b/arch/x86/mm/mmap.c
25334 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size(void)
25335 * Leave an at least ~128 MB hole with possible stack randomization.
25336 */
25337 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25338 -#define MAX_GAP (TASK_SIZE/6*5)
25339 +#define MAX_GAP (pax_task_size/6*5)
25340
25341 /*
25342 * True on X86_32 or when emulating IA32 on X86_64
25343 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
25344 return rnd << PAGE_SHIFT;
25345 }
25346
25347 -static unsigned long mmap_base(void)
25348 +static unsigned long mmap_base(struct mm_struct *mm)
25349 {
25350 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
25351 + unsigned long pax_task_size = TASK_SIZE;
25352 +
25353 +#ifdef CONFIG_PAX_SEGMEXEC
25354 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25355 + pax_task_size = SEGMEXEC_TASK_SIZE;
25356 +#endif
25357
25358 if (gap < MIN_GAP)
25359 gap = MIN_GAP;
25360 else if (gap > MAX_GAP)
25361 gap = MAX_GAP;
25362
25363 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25364 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25365 }
25366
25367 /*
25368 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25369 * does, but not when emulating X86_32
25370 */
25371 -static unsigned long mmap_legacy_base(void)
25372 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25373 {
25374 - if (mmap_is_ia32())
25375 + if (mmap_is_ia32()) {
25376 +
25377 +#ifdef CONFIG_PAX_SEGMEXEC
25378 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25379 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25380 + else
25381 +#endif
25382 +
25383 return TASK_UNMAPPED_BASE;
25384 - else
25385 + } else
25386 return TASK_UNMAPPED_BASE + mmap_rnd();
25387 }
25388
25389 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(void)
25390 void arch_pick_mmap_layout(struct mm_struct *mm)
25391 {
25392 if (mmap_is_legacy()) {
25393 - mm->mmap_base = mmap_legacy_base();
25394 + mm->mmap_base = mmap_legacy_base(mm);
25395 +
25396 +#ifdef CONFIG_PAX_RANDMMAP
25397 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25398 + mm->mmap_base += mm->delta_mmap;
25399 +#endif
25400 +
25401 mm->get_unmapped_area = arch_get_unmapped_area;
25402 mm->unmap_area = arch_unmap_area;
25403 } else {
25404 - mm->mmap_base = mmap_base();
25405 + mm->mmap_base = mmap_base(mm);
25406 +
25407 +#ifdef CONFIG_PAX_RANDMMAP
25408 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25409 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25410 +#endif
25411 +
25412 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25413 mm->unmap_area = arch_unmap_area_topdown;
25414 }
25415 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25416 index 132772a..b961f11 100644
25417 --- a/arch/x86/mm/mmio-mod.c
25418 +++ b/arch/x86/mm/mmio-mod.c
25419 @@ -193,7 +193,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25420 break;
25421 default:
25422 {
25423 - unsigned char *ip = (unsigned char *)instptr;
25424 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25425 my_trace->opcode = MMIO_UNKNOWN_OP;
25426 my_trace->width = 0;
25427 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25428 @@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25429 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25430 void __iomem *addr)
25431 {
25432 - static atomic_t next_id;
25433 + static atomic_unchecked_t next_id;
25434 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25435 /* These are page-unaligned. */
25436 struct mmiotrace_map map = {
25437 @@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25438 .private = trace
25439 },
25440 .phys = offset,
25441 - .id = atomic_inc_return(&next_id)
25442 + .id = atomic_inc_return_unchecked(&next_id)
25443 };
25444 map.map_id = trace->id;
25445
25446 diff --git a/arch/x86/mm/numa_32.c b/arch/x86/mm/numa_32.c
25447 index d253006..e56dd6a 100644
25448 --- a/arch/x86/mm/numa_32.c
25449 +++ b/arch/x86/mm/numa_32.c
25450 @@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int nid, unsigned long start_pfn,
25451 }
25452 #endif
25453
25454 -extern unsigned long find_max_low_pfn(void);
25455 extern unsigned long highend_pfn, highstart_pfn;
25456
25457 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
25458 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25459 index e1d1069..2251ff3 100644
25460 --- a/arch/x86/mm/pageattr-test.c
25461 +++ b/arch/x86/mm/pageattr-test.c
25462 @@ -36,7 +36,7 @@ enum {
25463
25464 static int pte_testbit(pte_t pte)
25465 {
25466 - return pte_flags(pte) & _PAGE_UNUSED1;
25467 + return pte_flags(pte) & _PAGE_CPA_TEST;
25468 }
25469
25470 struct split_state {
25471 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25472 index dd38bfb..8c12306 100644
25473 --- a/arch/x86/mm/pageattr.c
25474 +++ b/arch/x86/mm/pageattr.c
25475 @@ -261,16 +261,17 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25476 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
25477 */
25478 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25479 - pgprot_val(forbidden) |= _PAGE_NX;
25480 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25481
25482 /*
25483 * The kernel text needs to be executable for obvious reasons
25484 * Does not cover __inittext since that is gone later on. On
25485 * 64bit we do not enforce !NX on the low mapping
25486 */
25487 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25488 - pgprot_val(forbidden) |= _PAGE_NX;
25489 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25490 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25491
25492 +#ifdef CONFIG_DEBUG_RODATA
25493 /*
25494 * The .rodata section needs to be read-only. Using the pfn
25495 * catches all aliases.
25496 @@ -278,6 +279,14 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25497 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25498 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25499 pgprot_val(forbidden) |= _PAGE_RW;
25500 +#endif
25501 +
25502 +#ifdef CONFIG_PAX_KERNEXEC
25503 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25504 + pgprot_val(forbidden) |= _PAGE_RW;
25505 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25506 + }
25507 +#endif
25508
25509 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25510
25511 @@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25512 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25513 {
25514 /* change init_mm */
25515 + pax_open_kernel();
25516 set_pte_atomic(kpte, pte);
25517 +
25518 #ifdef CONFIG_X86_32
25519 if (!SHARED_KERNEL_PMD) {
25520 +
25521 +#ifdef CONFIG_PAX_PER_CPU_PGD
25522 + unsigned long cpu;
25523 +#else
25524 struct page *page;
25525 +#endif
25526
25527 +#ifdef CONFIG_PAX_PER_CPU_PGD
25528 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
25529 + pgd_t *pgd = get_cpu_pgd(cpu);
25530 +#else
25531 list_for_each_entry(page, &pgd_list, lru) {
25532 - pgd_t *pgd;
25533 + pgd_t *pgd = (pgd_t *)page_address(page);
25534 +#endif
25535 +
25536 pud_t *pud;
25537 pmd_t *pmd;
25538
25539 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25540 + pgd += pgd_index(address);
25541 pud = pud_offset(pgd, address);
25542 pmd = pmd_offset(pud, address);
25543 set_pte_atomic((pte_t *)pmd, pte);
25544 }
25545 }
25546 #endif
25547 + pax_close_kernel();
25548 }
25549
25550 static int
25551 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25552 index e78cd0e..de0a817 100644
25553 --- a/arch/x86/mm/pat.c
25554 +++ b/arch/x86/mm/pat.c
25555 @@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct memtype *entry, unsigned long *type)
25556
25557 conflict:
25558 printk(KERN_INFO "%s:%d conflicting memory types "
25559 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
25560 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
25561 new->end, cattr_name(new->type), cattr_name(entry->type));
25562 return -EBUSY;
25563 }
25564 @@ -559,7 +559,7 @@ unlock_ret:
25565
25566 if (err) {
25567 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25568 - current->comm, current->pid, start, end);
25569 + current->comm, task_pid_nr(current), start, end);
25570 }
25571
25572 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
25573 @@ -689,8 +689,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25574 while (cursor < to) {
25575 if (!devmem_is_allowed(pfn)) {
25576 printk(KERN_INFO
25577 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25578 - current->comm, from, to);
25579 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25580 + current->comm, from, to, cursor);
25581 return 0;
25582 }
25583 cursor += PAGE_SIZE;
25584 @@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25585 printk(KERN_INFO
25586 "%s:%d ioremap_change_attr failed %s "
25587 "for %Lx-%Lx\n",
25588 - current->comm, current->pid,
25589 + current->comm, task_pid_nr(current),
25590 cattr_name(flags),
25591 base, (unsigned long long)(base + size));
25592 return -EINVAL;
25593 @@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25594 free_memtype(paddr, paddr + size);
25595 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25596 " for %Lx-%Lx, got %s\n",
25597 - current->comm, current->pid,
25598 + current->comm, task_pid_nr(current),
25599 cattr_name(want_flags),
25600 (unsigned long long)paddr,
25601 (unsigned long long)(paddr + size),
25602 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25603 index df3d5c8..c2223e1 100644
25604 --- a/arch/x86/mm/pf_in.c
25605 +++ b/arch/x86/mm/pf_in.c
25606 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25607 int i;
25608 enum reason_type rv = OTHERS;
25609
25610 - p = (unsigned char *)ins_addr;
25611 + p = (unsigned char *)ktla_ktva(ins_addr);
25612 p += skip_prefix(p, &prf);
25613 p += get_opcode(p, &opcode);
25614
25615 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25616 struct prefix_bits prf;
25617 int i;
25618
25619 - p = (unsigned char *)ins_addr;
25620 + p = (unsigned char *)ktla_ktva(ins_addr);
25621 p += skip_prefix(p, &prf);
25622 p += get_opcode(p, &opcode);
25623
25624 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25625 struct prefix_bits prf;
25626 int i;
25627
25628 - p = (unsigned char *)ins_addr;
25629 + p = (unsigned char *)ktla_ktva(ins_addr);
25630 p += skip_prefix(p, &prf);
25631 p += get_opcode(p, &opcode);
25632
25633 @@ -417,7 +417,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25634 int i;
25635 unsigned long rv;
25636
25637 - p = (unsigned char *)ins_addr;
25638 + p = (unsigned char *)ktla_ktva(ins_addr);
25639 p += skip_prefix(p, &prf);
25640 p += get_opcode(p, &opcode);
25641 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25642 @@ -472,7 +472,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25643 int i;
25644 unsigned long rv;
25645
25646 - p = (unsigned char *)ins_addr;
25647 + p = (unsigned char *)ktla_ktva(ins_addr);
25648 p += skip_prefix(p, &prf);
25649 p += get_opcode(p, &opcode);
25650 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25651 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25652 index e0e6fad..6b90017 100644
25653 --- a/arch/x86/mm/pgtable.c
25654 +++ b/arch/x86/mm/pgtable.c
25655 @@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *pgd)
25656 list_del(&page->lru);
25657 }
25658
25659 -#define UNSHARED_PTRS_PER_PGD \
25660 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25661 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25662 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25663
25664 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25665 +{
25666 + while (count--)
25667 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25668 +}
25669 +#endif
25670 +
25671 +#ifdef CONFIG_PAX_PER_CPU_PGD
25672 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25673 +{
25674 + while (count--)
25675 +
25676 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25677 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
25678 +#else
25679 + *dst++ = *src++;
25680 +#endif
25681 +
25682 +}
25683 +#endif
25684 +
25685 +#ifdef CONFIG_X86_64
25686 +#define pxd_t pud_t
25687 +#define pyd_t pgd_t
25688 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25689 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25690 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25691 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
25692 +#define PYD_SIZE PGDIR_SIZE
25693 +#else
25694 +#define pxd_t pmd_t
25695 +#define pyd_t pud_t
25696 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25697 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25698 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25699 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
25700 +#define PYD_SIZE PUD_SIZE
25701 +#endif
25702 +
25703 +#ifdef CONFIG_PAX_PER_CPU_PGD
25704 +static inline void pgd_ctor(pgd_t *pgd) {}
25705 +static inline void pgd_dtor(pgd_t *pgd) {}
25706 +#else
25707 static void pgd_ctor(pgd_t *pgd)
25708 {
25709 /* If the pgd points to a shared pagetable level (either the
25710 @@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
25711 pgd_list_del(pgd);
25712 spin_unlock_irqrestore(&pgd_lock, flags);
25713 }
25714 +#endif
25715
25716 /*
25717 * List of all pgd's needed for non-PAE so it can invalidate entries
25718 @@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
25719 * -- wli
25720 */
25721
25722 -#ifdef CONFIG_X86_PAE
25723 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25724 /*
25725 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25726 * updating the top-level pagetable entries to guarantee the
25727 @@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
25728 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25729 * and initialize the kernel pmds here.
25730 */
25731 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25732 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25733
25734 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25735 {
25736 @@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25737 */
25738 flush_tlb_mm(mm);
25739 }
25740 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25741 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25742 #else /* !CONFIG_X86_PAE */
25743
25744 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25745 -#define PREALLOCATED_PMDS 0
25746 +#define PREALLOCATED_PXDS 0
25747
25748 #endif /* CONFIG_X86_PAE */
25749
25750 -static void free_pmds(pmd_t *pmds[])
25751 +static void free_pxds(pxd_t *pxds[])
25752 {
25753 int i;
25754
25755 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25756 - if (pmds[i])
25757 - free_page((unsigned long)pmds[i]);
25758 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25759 + if (pxds[i])
25760 + free_page((unsigned long)pxds[i]);
25761 }
25762
25763 -static int preallocate_pmds(pmd_t *pmds[])
25764 +static int preallocate_pxds(pxd_t *pxds[])
25765 {
25766 int i;
25767 bool failed = false;
25768
25769 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25770 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25771 - if (pmd == NULL)
25772 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25773 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25774 + if (pxd == NULL)
25775 failed = true;
25776 - pmds[i] = pmd;
25777 + pxds[i] = pxd;
25778 }
25779
25780 if (failed) {
25781 - free_pmds(pmds);
25782 + free_pxds(pxds);
25783 return -ENOMEM;
25784 }
25785
25786 @@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[])
25787 * preallocate which never got a corresponding vma will need to be
25788 * freed manually.
25789 */
25790 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25791 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25792 {
25793 int i;
25794
25795 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25796 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25797 pgd_t pgd = pgdp[i];
25798
25799 if (pgd_val(pgd) != 0) {
25800 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25801 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25802
25803 - pgdp[i] = native_make_pgd(0);
25804 + set_pgd(pgdp + i, native_make_pgd(0));
25805
25806 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25807 - pmd_free(mm, pmd);
25808 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25809 + pxd_free(mm, pxd);
25810 }
25811 }
25812 }
25813
25814 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25815 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25816 {
25817 - pud_t *pud;
25818 + pyd_t *pyd;
25819 unsigned long addr;
25820 int i;
25821
25822 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25823 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25824 return;
25825
25826 - pud = pud_offset(pgd, 0);
25827 +#ifdef CONFIG_X86_64
25828 + pyd = pyd_offset(mm, 0L);
25829 +#else
25830 + pyd = pyd_offset(pgd, 0L);
25831 +#endif
25832
25833 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25834 - i++, pud++, addr += PUD_SIZE) {
25835 - pmd_t *pmd = pmds[i];
25836 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25837 + i++, pyd++, addr += PYD_SIZE) {
25838 + pxd_t *pxd = pxds[i];
25839
25840 if (i >= KERNEL_PGD_BOUNDARY)
25841 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25842 - sizeof(pmd_t) * PTRS_PER_PMD);
25843 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25844 + sizeof(pxd_t) * PTRS_PER_PMD);
25845
25846 - pud_populate(mm, pud, pmd);
25847 + pyd_populate(mm, pyd, pxd);
25848 }
25849 }
25850
25851 pgd_t *pgd_alloc(struct mm_struct *mm)
25852 {
25853 pgd_t *pgd;
25854 - pmd_t *pmds[PREALLOCATED_PMDS];
25855 + pxd_t *pxds[PREALLOCATED_PXDS];
25856 +
25857 unsigned long flags;
25858
25859 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25860 @@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25861
25862 mm->pgd = pgd;
25863
25864 - if (preallocate_pmds(pmds) != 0)
25865 + if (preallocate_pxds(pxds) != 0)
25866 goto out_free_pgd;
25867
25868 if (paravirt_pgd_alloc(mm) != 0)
25869 - goto out_free_pmds;
25870 + goto out_free_pxds;
25871
25872 /*
25873 * Make sure that pre-populating the pmds is atomic with
25874 @@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25875 spin_lock_irqsave(&pgd_lock, flags);
25876
25877 pgd_ctor(pgd);
25878 - pgd_prepopulate_pmd(mm, pgd, pmds);
25879 + pgd_prepopulate_pxd(mm, pgd, pxds);
25880
25881 spin_unlock_irqrestore(&pgd_lock, flags);
25882
25883 return pgd;
25884
25885 -out_free_pmds:
25886 - free_pmds(pmds);
25887 +out_free_pxds:
25888 + free_pxds(pxds);
25889 out_free_pgd:
25890 free_page((unsigned long)pgd);
25891 out:
25892 @@ -287,7 +338,7 @@ out:
25893
25894 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25895 {
25896 - pgd_mop_up_pmds(mm, pgd);
25897 + pgd_mop_up_pxds(mm, pgd);
25898 pgd_dtor(pgd);
25899 paravirt_pgd_free(mm, pgd);
25900 free_page((unsigned long)pgd);
25901 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25902 index 46c8834..fcab43d 100644
25903 --- a/arch/x86/mm/pgtable_32.c
25904 +++ b/arch/x86/mm/pgtable_32.c
25905 @@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25906 return;
25907 }
25908 pte = pte_offset_kernel(pmd, vaddr);
25909 +
25910 + pax_open_kernel();
25911 if (pte_val(pteval))
25912 set_pte_at(&init_mm, vaddr, pte, pteval);
25913 else
25914 pte_clear(&init_mm, vaddr, pte);
25915 + pax_close_kernel();
25916
25917 /*
25918 * It's enough to flush this one mapping.
25919 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25920 index 513d8ed..978c161 100644
25921 --- a/arch/x86/mm/setup_nx.c
25922 +++ b/arch/x86/mm/setup_nx.c
25923 @@ -4,11 +4,10 @@
25924
25925 #include <asm/pgtable.h>
25926
25927 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25928 int nx_enabled;
25929
25930 -#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25931 -static int disable_nx __cpuinitdata;
25932 -
25933 +#ifndef CONFIG_PAX_PAGEEXEC
25934 /*
25935 * noexec = on|off
25936 *
25937 @@ -22,32 +21,26 @@ static int __init noexec_setup(char *str)
25938 if (!str)
25939 return -EINVAL;
25940 if (!strncmp(str, "on", 2)) {
25941 - __supported_pte_mask |= _PAGE_NX;
25942 - disable_nx = 0;
25943 + nx_enabled = 1;
25944 } else if (!strncmp(str, "off", 3)) {
25945 - disable_nx = 1;
25946 - __supported_pte_mask &= ~_PAGE_NX;
25947 + nx_enabled = 0;
25948 }
25949 return 0;
25950 }
25951 early_param("noexec", noexec_setup);
25952 #endif
25953 +#endif
25954
25955 #ifdef CONFIG_X86_PAE
25956 void __init set_nx(void)
25957 {
25958 - unsigned int v[4], l, h;
25959 + if (!nx_enabled && cpu_has_nx) {
25960 + unsigned l, h;
25961
25962 - if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
25963 - cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
25964 -
25965 - if ((v[3] & (1 << 20)) && !disable_nx) {
25966 - rdmsr(MSR_EFER, l, h);
25967 - l |= EFER_NX;
25968 - wrmsr(MSR_EFER, l, h);
25969 - nx_enabled = 1;
25970 - __supported_pte_mask |= _PAGE_NX;
25971 - }
25972 + __supported_pte_mask &= ~_PAGE_NX;
25973 + rdmsr(MSR_EFER, l, h);
25974 + l &= ~EFER_NX;
25975 + wrmsr(MSR_EFER, l, h);
25976 }
25977 }
25978 #else
25979 @@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
25980 unsigned long efer;
25981
25982 rdmsrl(MSR_EFER, efer);
25983 - if (!(efer & EFER_NX) || disable_nx)
25984 + if (!(efer & EFER_NX) || !nx_enabled)
25985 __supported_pte_mask &= ~_PAGE_NX;
25986 }
25987 #endif
25988 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25989 index 36fe08e..b123d3a 100644
25990 --- a/arch/x86/mm/tlb.c
25991 +++ b/arch/x86/mm/tlb.c
25992 @@ -61,7 +61,11 @@ void leave_mm(int cpu)
25993 BUG();
25994 cpumask_clear_cpu(cpu,
25995 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25996 +
25997 +#ifndef CONFIG_PAX_PER_CPU_PGD
25998 load_cr3(swapper_pg_dir);
25999 +#endif
26000 +
26001 }
26002 EXPORT_SYMBOL_GPL(leave_mm);
26003
26004 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26005 index 829edf0..672adb3 100644
26006 --- a/arch/x86/oprofile/backtrace.c
26007 +++ b/arch/x86/oprofile/backtrace.c
26008 @@ -115,7 +115,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26009 {
26010 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
26011
26012 - if (!user_mode_vm(regs)) {
26013 + if (!user_mode(regs)) {
26014 unsigned long stack = kernel_stack_pointer(regs);
26015 if (depth)
26016 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26017 diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
26018 index e6a160a..36deff6 100644
26019 --- a/arch/x86/oprofile/op_model_p4.c
26020 +++ b/arch/x86/oprofile/op_model_p4.c
26021 @@ -50,7 +50,7 @@ static inline void setup_num_counters(void)
26022 #endif
26023 }
26024
26025 -static int inline addr_increment(void)
26026 +static inline int addr_increment(void)
26027 {
26028 #ifdef CONFIG_SMP
26029 return smp_num_siblings == 2 ? 2 : 1;
26030 diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
26031 index 1331fcf..03901b2 100644
26032 --- a/arch/x86/pci/common.c
26033 +++ b/arch/x86/pci/common.c
26034 @@ -31,8 +31,8 @@ int noioapicreroute = 1;
26035 int pcibios_last_bus = -1;
26036 unsigned long pirq_table_addr;
26037 struct pci_bus *pci_root_bus;
26038 -struct pci_raw_ops *raw_pci_ops;
26039 -struct pci_raw_ops *raw_pci_ext_ops;
26040 +const struct pci_raw_ops *raw_pci_ops;
26041 +const struct pci_raw_ops *raw_pci_ext_ops;
26042
26043 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
26044 int reg, int len, u32 *val)
26045 diff --git a/arch/x86/pci/direct.c b/arch/x86/pci/direct.c
26046 index 347d882..4baf6b6 100644
26047 --- a/arch/x86/pci/direct.c
26048 +++ b/arch/x86/pci/direct.c
26049 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
26050
26051 #undef PCI_CONF1_ADDRESS
26052
26053 -struct pci_raw_ops pci_direct_conf1 = {
26054 +const struct pci_raw_ops pci_direct_conf1 = {
26055 .read = pci_conf1_read,
26056 .write = pci_conf1_write,
26057 };
26058 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
26059
26060 #undef PCI_CONF2_ADDRESS
26061
26062 -struct pci_raw_ops pci_direct_conf2 = {
26063 +const struct pci_raw_ops pci_direct_conf2 = {
26064 .read = pci_conf2_read,
26065 .write = pci_conf2_write,
26066 };
26067 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
26068 * This should be close to trivial, but it isn't, because there are buggy
26069 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
26070 */
26071 -static int __init pci_sanity_check(struct pci_raw_ops *o)
26072 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
26073 {
26074 u32 x = 0;
26075 int year, devfn;
26076 diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c
26077 index f10a7e9..0425342 100644
26078 --- a/arch/x86/pci/mmconfig_32.c
26079 +++ b/arch/x86/pci/mmconfig_32.c
26080 @@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26081 return 0;
26082 }
26083
26084 -static struct pci_raw_ops pci_mmcfg = {
26085 +static const struct pci_raw_ops pci_mmcfg = {
26086 .read = pci_mmcfg_read,
26087 .write = pci_mmcfg_write,
26088 };
26089 diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c
26090 index 94349f8..41600a7 100644
26091 --- a/arch/x86/pci/mmconfig_64.c
26092 +++ b/arch/x86/pci/mmconfig_64.c
26093 @@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26094 return 0;
26095 }
26096
26097 -static struct pci_raw_ops pci_mmcfg = {
26098 +static const struct pci_raw_ops pci_mmcfg = {
26099 .read = pci_mmcfg_read,
26100 .write = pci_mmcfg_write,
26101 };
26102 diff --git a/arch/x86/pci/numaq_32.c b/arch/x86/pci/numaq_32.c
26103 index 8eb295e..86bd657 100644
26104 --- a/arch/x86/pci/numaq_32.c
26105 +++ b/arch/x86/pci/numaq_32.c
26106 @@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
26107
26108 #undef PCI_CONF1_MQ_ADDRESS
26109
26110 -static struct pci_raw_ops pci_direct_conf1_mq = {
26111 +static const struct pci_raw_ops pci_direct_conf1_mq = {
26112 .read = pci_conf1_mq_read,
26113 .write = pci_conf1_mq_write
26114 };
26115 diff --git a/arch/x86/pci/olpc.c b/arch/x86/pci/olpc.c
26116 index b889d82..5a58a0a 100644
26117 --- a/arch/x86/pci/olpc.c
26118 +++ b/arch/x86/pci/olpc.c
26119 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int seg, unsigned int bus,
26120 return 0;
26121 }
26122
26123 -static struct pci_raw_ops pci_olpc_conf = {
26124 +static const struct pci_raw_ops pci_olpc_conf = {
26125 .read = pci_olpc_read,
26126 .write = pci_olpc_write,
26127 };
26128 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26129 index 1c975cc..ffd0536 100644
26130 --- a/arch/x86/pci/pcbios.c
26131 +++ b/arch/x86/pci/pcbios.c
26132 @@ -56,50 +56,93 @@ union bios32 {
26133 static struct {
26134 unsigned long address;
26135 unsigned short segment;
26136 -} bios32_indirect = { 0, __KERNEL_CS };
26137 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26138
26139 /*
26140 * Returns the entry point for the given service, NULL on error
26141 */
26142
26143 -static unsigned long bios32_service(unsigned long service)
26144 +static unsigned long __devinit bios32_service(unsigned long service)
26145 {
26146 unsigned char return_code; /* %al */
26147 unsigned long address; /* %ebx */
26148 unsigned long length; /* %ecx */
26149 unsigned long entry; /* %edx */
26150 unsigned long flags;
26151 + struct desc_struct d, *gdt;
26152
26153 local_irq_save(flags);
26154 - __asm__("lcall *(%%edi); cld"
26155 +
26156 + gdt = get_cpu_gdt_table(smp_processor_id());
26157 +
26158 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26159 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26160 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26161 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26162 +
26163 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26164 : "=a" (return_code),
26165 "=b" (address),
26166 "=c" (length),
26167 "=d" (entry)
26168 : "0" (service),
26169 "1" (0),
26170 - "D" (&bios32_indirect));
26171 + "D" (&bios32_indirect),
26172 + "r"(__PCIBIOS_DS)
26173 + : "memory");
26174 +
26175 + pax_open_kernel();
26176 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26177 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26178 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26179 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26180 + pax_close_kernel();
26181 +
26182 local_irq_restore(flags);
26183
26184 switch (return_code) {
26185 - case 0:
26186 - return address + entry;
26187 - case 0x80: /* Not present */
26188 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26189 - return 0;
26190 - default: /* Shouldn't happen */
26191 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26192 - service, return_code);
26193 + case 0: {
26194 + int cpu;
26195 + unsigned char flags;
26196 +
26197 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26198 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26199 + printk(KERN_WARNING "bios32_service: not valid\n");
26200 return 0;
26201 + }
26202 + address = address + PAGE_OFFSET;
26203 + length += 16UL; /* some BIOSs underreport this... */
26204 + flags = 4;
26205 + if (length >= 64*1024*1024) {
26206 + length >>= PAGE_SHIFT;
26207 + flags |= 8;
26208 + }
26209 +
26210 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
26211 + gdt = get_cpu_gdt_table(cpu);
26212 + pack_descriptor(&d, address, length, 0x9b, flags);
26213 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26214 + pack_descriptor(&d, address, length, 0x93, flags);
26215 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26216 + }
26217 + return entry;
26218 + }
26219 + case 0x80: /* Not present */
26220 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26221 + return 0;
26222 + default: /* Shouldn't happen */
26223 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26224 + service, return_code);
26225 + return 0;
26226 }
26227 }
26228
26229 static struct {
26230 unsigned long address;
26231 unsigned short segment;
26232 -} pci_indirect = { 0, __KERNEL_CS };
26233 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26234
26235 -static int pci_bios_present;
26236 +static int pci_bios_present __read_only;
26237
26238 static int __devinit check_pcibios(void)
26239 {
26240 @@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
26241 unsigned long flags, pcibios_entry;
26242
26243 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26244 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26245 + pci_indirect.address = pcibios_entry;
26246
26247 local_irq_save(flags);
26248 - __asm__(
26249 - "lcall *(%%edi); cld\n\t"
26250 + __asm__("movw %w6, %%ds\n\t"
26251 + "lcall *%%ss:(%%edi); cld\n\t"
26252 + "push %%ss\n\t"
26253 + "pop %%ds\n\t"
26254 "jc 1f\n\t"
26255 "xor %%ah, %%ah\n"
26256 "1:"
26257 @@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
26258 "=b" (ebx),
26259 "=c" (ecx)
26260 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26261 - "D" (&pci_indirect)
26262 + "D" (&pci_indirect),
26263 + "r" (__PCIBIOS_DS)
26264 : "memory");
26265 local_irq_restore(flags);
26266
26267 @@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26268
26269 switch (len) {
26270 case 1:
26271 - __asm__("lcall *(%%esi); cld\n\t"
26272 + __asm__("movw %w6, %%ds\n\t"
26273 + "lcall *%%ss:(%%esi); cld\n\t"
26274 + "push %%ss\n\t"
26275 + "pop %%ds\n\t"
26276 "jc 1f\n\t"
26277 "xor %%ah, %%ah\n"
26278 "1:"
26279 @@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26280 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26281 "b" (bx),
26282 "D" ((long)reg),
26283 - "S" (&pci_indirect));
26284 + "S" (&pci_indirect),
26285 + "r" (__PCIBIOS_DS));
26286 /*
26287 * Zero-extend the result beyond 8 bits, do not trust the
26288 * BIOS having done it:
26289 @@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26290 *value &= 0xff;
26291 break;
26292 case 2:
26293 - __asm__("lcall *(%%esi); cld\n\t"
26294 + __asm__("movw %w6, %%ds\n\t"
26295 + "lcall *%%ss:(%%esi); cld\n\t"
26296 + "push %%ss\n\t"
26297 + "pop %%ds\n\t"
26298 "jc 1f\n\t"
26299 "xor %%ah, %%ah\n"
26300 "1:"
26301 @@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26302 : "1" (PCIBIOS_READ_CONFIG_WORD),
26303 "b" (bx),
26304 "D" ((long)reg),
26305 - "S" (&pci_indirect));
26306 + "S" (&pci_indirect),
26307 + "r" (__PCIBIOS_DS));
26308 /*
26309 * Zero-extend the result beyond 16 bits, do not trust the
26310 * BIOS having done it:
26311 @@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26312 *value &= 0xffff;
26313 break;
26314 case 4:
26315 - __asm__("lcall *(%%esi); cld\n\t"
26316 + __asm__("movw %w6, %%ds\n\t"
26317 + "lcall *%%ss:(%%esi); cld\n\t"
26318 + "push %%ss\n\t"
26319 + "pop %%ds\n\t"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323 @@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26324 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26325 "b" (bx),
26326 "D" ((long)reg),
26327 - "S" (&pci_indirect));
26328 + "S" (&pci_indirect),
26329 + "r" (__PCIBIOS_DS));
26330 break;
26331 }
26332
26333 @@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26334
26335 switch (len) {
26336 case 1:
26337 - __asm__("lcall *(%%esi); cld\n\t"
26338 + __asm__("movw %w6, %%ds\n\t"
26339 + "lcall *%%ss:(%%esi); cld\n\t"
26340 + "push %%ss\n\t"
26341 + "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345 @@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26346 "c" (value),
26347 "b" (bx),
26348 "D" ((long)reg),
26349 - "S" (&pci_indirect));
26350 + "S" (&pci_indirect),
26351 + "r" (__PCIBIOS_DS));
26352 break;
26353 case 2:
26354 - __asm__("lcall *(%%esi); cld\n\t"
26355 + __asm__("movw %w6, %%ds\n\t"
26356 + "lcall *%%ss:(%%esi); cld\n\t"
26357 + "push %%ss\n\t"
26358 + "pop %%ds\n\t"
26359 "jc 1f\n\t"
26360 "xor %%ah, %%ah\n"
26361 "1:"
26362 @@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26363 "c" (value),
26364 "b" (bx),
26365 "D" ((long)reg),
26366 - "S" (&pci_indirect));
26367 + "S" (&pci_indirect),
26368 + "r" (__PCIBIOS_DS));
26369 break;
26370 case 4:
26371 - __asm__("lcall *(%%esi); cld\n\t"
26372 + __asm__("movw %w6, %%ds\n\t"
26373 + "lcall *%%ss:(%%esi); cld\n\t"
26374 + "push %%ss\n\t"
26375 + "pop %%ds\n\t"
26376 "jc 1f\n\t"
26377 "xor %%ah, %%ah\n"
26378 "1:"
26379 @@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26380 "c" (value),
26381 "b" (bx),
26382 "D" ((long)reg),
26383 - "S" (&pci_indirect));
26384 + "S" (&pci_indirect),
26385 + "r" (__PCIBIOS_DS));
26386 break;
26387 }
26388
26389 @@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26390 * Function table for BIOS32 access
26391 */
26392
26393 -static struct pci_raw_ops pci_bios_access = {
26394 +static const struct pci_raw_ops pci_bios_access = {
26395 .read = pci_bios_read,
26396 .write = pci_bios_write
26397 };
26398 @@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_access = {
26399 * Try to find PCI BIOS.
26400 */
26401
26402 -static struct pci_raw_ops * __devinit pci_find_bios(void)
26403 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
26404 {
26405 union bios32 *check;
26406 unsigned char sum;
26407 @@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26408
26409 DBG("PCI: Fetching IRQ routing table... ");
26410 __asm__("push %%es\n\t"
26411 + "movw %w8, %%ds\n\t"
26412 "push %%ds\n\t"
26413 "pop %%es\n\t"
26414 - "lcall *(%%esi); cld\n\t"
26415 + "lcall *%%ss:(%%esi); cld\n\t"
26416 "pop %%es\n\t"
26417 + "push %%ss\n\t"
26418 + "pop %%ds\n"
26419 "jc 1f\n\t"
26420 "xor %%ah, %%ah\n"
26421 "1:"
26422 @@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26423 "1" (0),
26424 "D" ((long) &opt),
26425 "S" (&pci_indirect),
26426 - "m" (opt)
26427 + "m" (opt),
26428 + "r" (__PCIBIOS_DS)
26429 : "memory");
26430 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26431 if (ret & 0xff00)
26432 @@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26433 {
26434 int ret;
26435
26436 - __asm__("lcall *(%%esi); cld\n\t"
26437 + __asm__("movw %w5, %%ds\n\t"
26438 + "lcall *%%ss:(%%esi); cld\n\t"
26439 + "push %%ss\n\t"
26440 + "pop %%ds\n"
26441 "jc 1f\n\t"
26442 "xor %%ah, %%ah\n"
26443 "1:"
26444 @@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26445 : "0" (PCIBIOS_SET_PCI_HW_INT),
26446 "b" ((dev->bus->number << 8) | dev->devfn),
26447 "c" ((irq << 8) | (pin + 10)),
26448 - "S" (&pci_indirect));
26449 + "S" (&pci_indirect),
26450 + "r" (__PCIBIOS_DS));
26451 return !(ret & 0xff00);
26452 }
26453 EXPORT_SYMBOL(pcibios_set_irq_routing);
26454 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26455 index fa0f651..9d8f3d9 100644
26456 --- a/arch/x86/power/cpu.c
26457 +++ b/arch/x86/power/cpu.c
26458 @@ -129,7 +129,7 @@ static void do_fpu_end(void)
26459 static void fix_processor_context(void)
26460 {
26461 int cpu = smp_processor_id();
26462 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26463 + struct tss_struct *t = init_tss + cpu;
26464
26465 set_tss_desc(cpu, t); /*
26466 * This just modifies memory; should not be
26467 @@ -139,7 +139,9 @@ static void fix_processor_context(void)
26468 */
26469
26470 #ifdef CONFIG_X86_64
26471 + pax_open_kernel();
26472 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26473 + pax_close_kernel();
26474
26475 syscall_init(); /* This sets MSR_*STAR and related */
26476 #endif
26477 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26478 index dd78ef6..f9d928d 100644
26479 --- a/arch/x86/vdso/Makefile
26480 +++ b/arch/x86/vdso/Makefile
26481 @@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
26482 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
26483 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
26484
26485 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26486 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26487 GCOV_PROFILE := n
26488
26489 #
26490 diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
26491 index ee55754..0013b2e 100644
26492 --- a/arch/x86/vdso/vclock_gettime.c
26493 +++ b/arch/x86/vdso/vclock_gettime.c
26494 @@ -22,24 +22,48 @@
26495 #include <asm/hpet.h>
26496 #include <asm/unistd.h>
26497 #include <asm/io.h>
26498 +#include <asm/fixmap.h>
26499 #include "vextern.h"
26500
26501 #define gtod vdso_vsyscall_gtod_data
26502
26503 +notrace noinline long __vdso_fallback_time(long *t)
26504 +{
26505 + long secs;
26506 + asm volatile("syscall"
26507 + : "=a" (secs)
26508 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
26509 + return secs;
26510 +}
26511 +
26512 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
26513 {
26514 long ret;
26515 asm("syscall" : "=a" (ret) :
26516 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
26517 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
26518 return ret;
26519 }
26520
26521 +notrace static inline cycle_t __vdso_vread_hpet(void)
26522 +{
26523 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
26524 +}
26525 +
26526 +notrace static inline cycle_t __vdso_vread_tsc(void)
26527 +{
26528 + cycle_t ret = (cycle_t)vget_cycles();
26529 +
26530 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
26531 +}
26532 +
26533 notrace static inline long vgetns(void)
26534 {
26535 long v;
26536 - cycles_t (*vread)(void);
26537 - vread = gtod->clock.vread;
26538 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
26539 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
26540 + v = __vdso_vread_tsc();
26541 + else
26542 + v = __vdso_vread_hpet();
26543 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
26544 return (v * gtod->clock.mult) >> gtod->clock.shift;
26545 }
26546
26547 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic_coarse(struct timespec *ts)
26548
26549 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26550 {
26551 - if (likely(gtod->sysctl_enabled))
26552 + if (likely(gtod->sysctl_enabled &&
26553 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26554 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26555 switch (clock) {
26556 case CLOCK_REALTIME:
26557 if (likely(gtod->clock.vread))
26558 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26559 int clock_gettime(clockid_t, struct timespec *)
26560 __attribute__((weak, alias("__vdso_clock_gettime")));
26561
26562 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
26563 +{
26564 + long ret;
26565 + asm("syscall" : "=a" (ret) :
26566 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
26567 + return ret;
26568 +}
26569 +
26570 notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26571 {
26572 - long ret;
26573 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
26574 + if (likely(gtod->sysctl_enabled &&
26575 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26576 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26577 + {
26578 if (likely(tv != NULL)) {
26579 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
26580 offsetof(struct timespec, tv_nsec) ||
26581 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26582 }
26583 return 0;
26584 }
26585 - asm("syscall" : "=a" (ret) :
26586 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
26587 - return ret;
26588 + return __vdso_fallback_gettimeofday(tv, tz);
26589 }
26590 int gettimeofday(struct timeval *, struct timezone *)
26591 __attribute__((weak, alias("__vdso_gettimeofday")));
26592 diff --git a/arch/x86/vdso/vdso.lds.S b/arch/x86/vdso/vdso.lds.S
26593 index 4e5dd3b..00ba15e 100644
26594 --- a/arch/x86/vdso/vdso.lds.S
26595 +++ b/arch/x86/vdso/vdso.lds.S
26596 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
26597 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
26598 #include "vextern.h"
26599 #undef VEXTERN
26600 +
26601 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
26602 +VEXTERN(fallback_gettimeofday)
26603 +VEXTERN(fallback_time)
26604 +VEXTERN(getcpu)
26605 +#undef VEXTERN
26606 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26607 index 58bc00f..d53fb48 100644
26608 --- a/arch/x86/vdso/vdso32-setup.c
26609 +++ b/arch/x86/vdso/vdso32-setup.c
26610 @@ -25,6 +25,7 @@
26611 #include <asm/tlbflush.h>
26612 #include <asm/vdso.h>
26613 #include <asm/proto.h>
26614 +#include <asm/mman.h>
26615
26616 enum {
26617 VDSO_DISABLED = 0,
26618 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26619 void enable_sep_cpu(void)
26620 {
26621 int cpu = get_cpu();
26622 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26623 + struct tss_struct *tss = init_tss + cpu;
26624
26625 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26626 put_cpu();
26627 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26628 gate_vma.vm_start = FIXADDR_USER_START;
26629 gate_vma.vm_end = FIXADDR_USER_END;
26630 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26631 - gate_vma.vm_page_prot = __P101;
26632 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26633 /*
26634 * Make sure the vDSO gets into every core dump.
26635 * Dumping its contents makes post-mortem fully interpretable later
26636 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26637 if (compat)
26638 addr = VDSO_HIGH_BASE;
26639 else {
26640 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26641 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26642 if (IS_ERR_VALUE(addr)) {
26643 ret = addr;
26644 goto up_fail;
26645 }
26646 }
26647
26648 - current->mm->context.vdso = (void *)addr;
26649 + current->mm->context.vdso = addr;
26650
26651 if (compat_uses_vma || !compat) {
26652 /*
26653 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26654 }
26655
26656 current_thread_info()->sysenter_return =
26657 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26658 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26659
26660 up_fail:
26661 if (ret)
26662 - current->mm->context.vdso = NULL;
26663 + current->mm->context.vdso = 0;
26664
26665 up_write(&mm->mmap_sem);
26666
26667 @@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
26668
26669 const char *arch_vma_name(struct vm_area_struct *vma)
26670 {
26671 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26672 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26673 return "[vdso]";
26674 +
26675 +#ifdef CONFIG_PAX_SEGMEXEC
26676 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26677 + return "[vdso]";
26678 +#endif
26679 +
26680 return NULL;
26681 }
26682
26683 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
26684 struct mm_struct *mm = tsk->mm;
26685
26686 /* Check to see if this task was created in compat vdso mode */
26687 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26688 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26689 return &gate_vma;
26690 return NULL;
26691 }
26692 diff --git a/arch/x86/vdso/vextern.h b/arch/x86/vdso/vextern.h
26693 index 1683ba2..48d07f3 100644
26694 --- a/arch/x86/vdso/vextern.h
26695 +++ b/arch/x86/vdso/vextern.h
26696 @@ -11,6 +11,5 @@
26697 put into vextern.h and be referenced as a pointer with vdso prefix.
26698 The main kernel later fills in the values. */
26699
26700 -VEXTERN(jiffies)
26701 VEXTERN(vgetcpu_mode)
26702 VEXTERN(vsyscall_gtod_data)
26703 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26704 index 21e1aeb..2c0b3c4 100644
26705 --- a/arch/x86/vdso/vma.c
26706 +++ b/arch/x86/vdso/vma.c
26707 @@ -17,8 +17,6 @@
26708 #include "vextern.h" /* Just for VMAGIC. */
26709 #undef VEXTERN
26710
26711 -unsigned int __read_mostly vdso_enabled = 1;
26712 -
26713 extern char vdso_start[], vdso_end[];
26714 extern unsigned short vdso_sync_cpuid;
26715
26716 @@ -27,10 +25,8 @@ static unsigned vdso_size;
26717
26718 static inline void *var_ref(void *p, char *name)
26719 {
26720 - if (*(void **)p != (void *)VMAGIC) {
26721 - printk("VDSO: variable %s broken\n", name);
26722 - vdso_enabled = 0;
26723 - }
26724 + if (*(void **)p != (void *)VMAGIC)
26725 + panic("VDSO: variable %s broken\n", name);
26726 return p;
26727 }
26728
26729 @@ -57,21 +53,18 @@ static int __init init_vdso_vars(void)
26730 if (!vbase)
26731 goto oom;
26732
26733 - if (memcmp(vbase, "\177ELF", 4)) {
26734 - printk("VDSO: I'm broken; not ELF\n");
26735 - vdso_enabled = 0;
26736 - }
26737 + if (memcmp(vbase, ELFMAG, SELFMAG))
26738 + panic("VDSO: I'm broken; not ELF\n");
26739
26740 #define VEXTERN(x) \
26741 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
26742 #include "vextern.h"
26743 #undef VEXTERN
26744 + vunmap(vbase);
26745 return 0;
26746
26747 oom:
26748 - printk("Cannot allocate vdso\n");
26749 - vdso_enabled = 0;
26750 - return -ENOMEM;
26751 + panic("Cannot allocate vdso\n");
26752 }
26753 __initcall(init_vdso_vars);
26754
26755 @@ -102,13 +95,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26756 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26757 {
26758 struct mm_struct *mm = current->mm;
26759 - unsigned long addr;
26760 + unsigned long addr = 0;
26761 int ret;
26762
26763 - if (!vdso_enabled)
26764 - return 0;
26765 -
26766 down_write(&mm->mmap_sem);
26767 +
26768 +#ifdef CONFIG_PAX_RANDMMAP
26769 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26770 +#endif
26771 +
26772 addr = vdso_addr(mm->start_stack, vdso_size);
26773 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26774 if (IS_ERR_VALUE(addr)) {
26775 @@ -116,7 +111,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26776 goto up_fail;
26777 }
26778
26779 - current->mm->context.vdso = (void *)addr;
26780 + current->mm->context.vdso = addr;
26781
26782 ret = install_special_mapping(mm, addr, vdso_size,
26783 VM_READ|VM_EXEC|
26784 @@ -124,7 +119,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26785 VM_ALWAYSDUMP,
26786 vdso_pages);
26787 if (ret) {
26788 - current->mm->context.vdso = NULL;
26789 + current->mm->context.vdso = 0;
26790 goto up_fail;
26791 }
26792
26793 @@ -132,10 +127,3 @@ up_fail:
26794 up_write(&mm->mmap_sem);
26795 return ret;
26796 }
26797 -
26798 -static __init int vdso_setup(char *s)
26799 -{
26800 - vdso_enabled = simple_strtoul(s, NULL, 0);
26801 - return 0;
26802 -}
26803 -__setup("vdso=", vdso_setup);
26804 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26805 index 0087b00..eecb34f 100644
26806 --- a/arch/x86/xen/enlighten.c
26807 +++ b/arch/x86/xen/enlighten.c
26808 @@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26809
26810 struct shared_info xen_dummy_shared_info;
26811
26812 -void *xen_initial_gdt;
26813 -
26814 /*
26815 * Point at some empty memory to start with. We map the real shared_info
26816 * page as soon as fixmap is up and running.
26817 @@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g)
26818
26819 preempt_disable();
26820
26821 - start = __get_cpu_var(idt_desc).address;
26822 + start = (unsigned long)__get_cpu_var(idt_desc).address;
26823 end = start + __get_cpu_var(idt_desc).size + 1;
26824
26825 xen_mc_flush();
26826 @@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic_ops __initdata = {
26827 #endif
26828 };
26829
26830 -static void xen_reboot(int reason)
26831 +static __noreturn void xen_reboot(int reason)
26832 {
26833 struct sched_shutdown r = { .reason = reason };
26834
26835 @@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
26836 BUG();
26837 }
26838
26839 -static void xen_restart(char *msg)
26840 +static __noreturn void xen_restart(char *msg)
26841 {
26842 xen_reboot(SHUTDOWN_reboot);
26843 }
26844
26845 -static void xen_emergency_restart(void)
26846 +static __noreturn void xen_emergency_restart(void)
26847 {
26848 xen_reboot(SHUTDOWN_reboot);
26849 }
26850
26851 -static void xen_machine_halt(void)
26852 +static __noreturn void xen_machine_halt(void)
26853 {
26854 xen_reboot(SHUTDOWN_poweroff);
26855 }
26856 @@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(void)
26857 */
26858 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26859
26860 -#ifdef CONFIG_X86_64
26861 /* Work out if we support NX */
26862 - check_efer();
26863 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26864 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26865 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26866 + unsigned l, h;
26867 +
26868 +#ifdef CONFIG_X86_PAE
26869 + nx_enabled = 1;
26870 +#endif
26871 + __supported_pte_mask |= _PAGE_NX;
26872 + rdmsr(MSR_EFER, l, h);
26873 + l |= EFER_NX;
26874 + wrmsr(MSR_EFER, l, h);
26875 + }
26876 #endif
26877
26878 xen_setup_features();
26879 @@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(void)
26880
26881 machine_ops = xen_machine_ops;
26882
26883 - /*
26884 - * The only reliable way to retain the initial address of the
26885 - * percpu gdt_page is to remember it here, so we can go and
26886 - * mark it RW later, when the initial percpu area is freed.
26887 - */
26888 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26889 -
26890 xen_smp_init();
26891
26892 pgd = (pgd_t *)xen_start_info->pt_base;
26893 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26894 index 3f90a2c..2c2ad84 100644
26895 --- a/arch/x86/xen/mmu.c
26896 +++ b/arch/x86/xen/mmu.c
26897 @@ -1719,6 +1719,9 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26898 convert_pfn_mfn(init_level4_pgt);
26899 convert_pfn_mfn(level3_ident_pgt);
26900 convert_pfn_mfn(level3_kernel_pgt);
26901 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26902 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26903 + convert_pfn_mfn(level3_vmemmap_pgt);
26904
26905 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26906 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26907 @@ -1737,7 +1740,11 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26908 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26909 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26910 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26911 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26912 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26913 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26914 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26915 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26916 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26917 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26918
26919 @@ -1860,6 +1867,7 @@ static __init void xen_post_allocator_init(void)
26920 pv_mmu_ops.set_pud = xen_set_pud;
26921 #if PAGETABLE_LEVELS == 4
26922 pv_mmu_ops.set_pgd = xen_set_pgd;
26923 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26924 #endif
26925
26926 /* This will work as long as patching hasn't happened yet
26927 @@ -1946,6 +1954,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
26928 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26929 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26930 .set_pgd = xen_set_pgd_hyper,
26931 + .set_pgd_batched = xen_set_pgd_hyper,
26932
26933 .alloc_pud = xen_alloc_pmd_init,
26934 .release_pud = xen_release_pmd_init,
26935 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26936 index a96204a..fca9b8e 100644
26937 --- a/arch/x86/xen/smp.c
26938 +++ b/arch/x86/xen/smp.c
26939 @@ -168,11 +168,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26940 {
26941 BUG_ON(smp_processor_id() != 0);
26942 native_smp_prepare_boot_cpu();
26943 -
26944 - /* We've switched to the "real" per-cpu gdt, so make sure the
26945 - old memory can be recycled */
26946 - make_lowmem_page_readwrite(xen_initial_gdt);
26947 -
26948 xen_setup_vcpu_info_placement();
26949 }
26950
26951 @@ -241,12 +236,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26952 gdt = get_cpu_gdt_table(cpu);
26953
26954 ctxt->flags = VGCF_IN_KERNEL;
26955 - ctxt->user_regs.ds = __USER_DS;
26956 - ctxt->user_regs.es = __USER_DS;
26957 + ctxt->user_regs.ds = __KERNEL_DS;
26958 + ctxt->user_regs.es = __KERNEL_DS;
26959 ctxt->user_regs.ss = __KERNEL_DS;
26960 #ifdef CONFIG_X86_32
26961 ctxt->user_regs.fs = __KERNEL_PERCPU;
26962 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26963 + savesegment(gs, ctxt->user_regs.gs);
26964 #else
26965 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26966 #endif
26967 @@ -297,13 +292,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26968 int rc;
26969
26970 per_cpu(current_task, cpu) = idle;
26971 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26972 #ifdef CONFIG_X86_32
26973 irq_ctx_init(cpu);
26974 #else
26975 clear_tsk_thread_flag(idle, TIF_FORK);
26976 - per_cpu(kernel_stack, cpu) =
26977 - (unsigned long)task_stack_page(idle) -
26978 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26979 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26980 #endif
26981 xen_setup_runstate_info(cpu);
26982 xen_setup_timer(cpu);
26983 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26984 index 9a95a9c..4f39e774 100644
26985 --- a/arch/x86/xen/xen-asm_32.S
26986 +++ b/arch/x86/xen/xen-asm_32.S
26987 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26988 ESP_OFFSET=4 # bytes pushed onto stack
26989
26990 /*
26991 - * Store vcpu_info pointer for easy access. Do it this way to
26992 - * avoid having to reload %fs
26993 + * Store vcpu_info pointer for easy access.
26994 */
26995 #ifdef CONFIG_SMP
26996 - GET_THREAD_INFO(%eax)
26997 - movl TI_cpu(%eax), %eax
26998 - movl __per_cpu_offset(,%eax,4), %eax
26999 - mov per_cpu__xen_vcpu(%eax), %eax
27000 + push %fs
27001 + mov $(__KERNEL_PERCPU), %eax
27002 + mov %eax, %fs
27003 + mov PER_CPU_VAR(xen_vcpu), %eax
27004 + pop %fs
27005 #else
27006 movl per_cpu__xen_vcpu, %eax
27007 #endif
27008 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27009 index 1a5ff24..a187d40 100644
27010 --- a/arch/x86/xen/xen-head.S
27011 +++ b/arch/x86/xen/xen-head.S
27012 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27013 #ifdef CONFIG_X86_32
27014 mov %esi,xen_start_info
27015 mov $init_thread_union+THREAD_SIZE,%esp
27016 +#ifdef CONFIG_SMP
27017 + movl $cpu_gdt_table,%edi
27018 + movl $__per_cpu_load,%eax
27019 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27020 + rorl $16,%eax
27021 + movb %al,__KERNEL_PERCPU + 4(%edi)
27022 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27023 + movl $__per_cpu_end - 1,%eax
27024 + subl $__per_cpu_start,%eax
27025 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27026 +#endif
27027 #else
27028 mov %rsi,xen_start_info
27029 mov $init_thread_union+THREAD_SIZE,%rsp
27030 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27031 index f9153a3..51eab3d 100644
27032 --- a/arch/x86/xen/xen-ops.h
27033 +++ b/arch/x86/xen/xen-ops.h
27034 @@ -10,8 +10,6 @@
27035 extern const char xen_hypervisor_callback[];
27036 extern const char xen_failsafe_callback[];
27037
27038 -extern void *xen_initial_gdt;
27039 -
27040 struct trap_info;
27041 void xen_copy_trap_info(struct trap_info *traps);
27042
27043 diff --git a/block/blk-integrity.c b/block/blk-integrity.c
27044 index 15c6308..96e83c2 100644
27045 --- a/block/blk-integrity.c
27046 +++ b/block/blk-integrity.c
27047 @@ -278,7 +278,7 @@ static struct attribute *integrity_attrs[] = {
27048 NULL,
27049 };
27050
27051 -static struct sysfs_ops integrity_ops = {
27052 +static const struct sysfs_ops integrity_ops = {
27053 .show = &integrity_attr_show,
27054 .store = &integrity_attr_store,
27055 };
27056 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27057 index ca56420..f2fc409 100644
27058 --- a/block/blk-iopoll.c
27059 +++ b/block/blk-iopoll.c
27060 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27061 }
27062 EXPORT_SYMBOL(blk_iopoll_complete);
27063
27064 -static void blk_iopoll_softirq(struct softirq_action *h)
27065 +static void blk_iopoll_softirq(void)
27066 {
27067 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27068 int rearm = 0, budget = blk_iopoll_budget;
27069 diff --git a/block/blk-map.c b/block/blk-map.c
27070 index 30a7e51..0aeec6a 100644
27071 --- a/block/blk-map.c
27072 +++ b/block/blk-map.c
27073 @@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
27074 * direct dma. else, set up kernel bounce buffers
27075 */
27076 uaddr = (unsigned long) ubuf;
27077 - if (blk_rq_aligned(q, ubuf, len) && !map_data)
27078 + if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
27079 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
27080 else
27081 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
27082 @@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
27083 for (i = 0; i < iov_count; i++) {
27084 unsigned long uaddr = (unsigned long)iov[i].iov_base;
27085
27086 + if (!iov[i].iov_len)
27087 + return -EINVAL;
27088 +
27089 if (uaddr & queue_dma_alignment(q)) {
27090 unaligned = 1;
27091 break;
27092 }
27093 - if (!iov[i].iov_len)
27094 - return -EINVAL;
27095 }
27096
27097 if (unaligned || (q->dma_pad_mask & len) || map_data)
27098 @@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27099 if (!len || !kbuf)
27100 return -EINVAL;
27101
27102 - do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
27103 + do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
27104 if (do_copy)
27105 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27106 else
27107 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27108 index ee9c216..58d410a 100644
27109 --- a/block/blk-softirq.c
27110 +++ b/block/blk-softirq.c
27111 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27112 * Softirq action handler - move entries to local list and loop over them
27113 * while passing them to the queue registered handler.
27114 */
27115 -static void blk_done_softirq(struct softirq_action *h)
27116 +static void blk_done_softirq(void)
27117 {
27118 struct list_head *cpu_list, local_list;
27119
27120 diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
27121 index bb9c5ea..5330d48 100644
27122 --- a/block/blk-sysfs.c
27123 +++ b/block/blk-sysfs.c
27124 @@ -414,7 +414,7 @@ static void blk_release_queue(struct kobject *kobj)
27125 kmem_cache_free(blk_requestq_cachep, q);
27126 }
27127
27128 -static struct sysfs_ops queue_sysfs_ops = {
27129 +static const struct sysfs_ops queue_sysfs_ops = {
27130 .show = queue_attr_show,
27131 .store = queue_attr_store,
27132 };
27133 diff --git a/block/bsg.c b/block/bsg.c
27134 index 7154a7a..08ac2f0 100644
27135 --- a/block/bsg.c
27136 +++ b/block/bsg.c
27137 @@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27138 struct sg_io_v4 *hdr, struct bsg_device *bd,
27139 fmode_t has_write_perm)
27140 {
27141 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27142 + unsigned char *cmdptr;
27143 +
27144 if (hdr->request_len > BLK_MAX_CDB) {
27145 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27146 if (!rq->cmd)
27147 return -ENOMEM;
27148 - }
27149 + cmdptr = rq->cmd;
27150 + } else
27151 + cmdptr = tmpcmd;
27152
27153 - if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
27154 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27155 hdr->request_len))
27156 return -EFAULT;
27157
27158 + if (cmdptr != rq->cmd)
27159 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27160 +
27161 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27162 if (blk_verify_command(rq->cmd, has_write_perm))
27163 return -EPERM;
27164 @@ -282,7 +290,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27165 rq->next_rq = next_rq;
27166 next_rq->cmd_type = rq->cmd_type;
27167
27168 - dxferp = (void*)(unsigned long)hdr->din_xferp;
27169 + dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27170 ret = blk_rq_map_user(q, next_rq, NULL, dxferp,
27171 hdr->din_xfer_len, GFP_KERNEL);
27172 if (ret)
27173 @@ -291,10 +299,10 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27174
27175 if (hdr->dout_xfer_len) {
27176 dxfer_len = hdr->dout_xfer_len;
27177 - dxferp = (void*)(unsigned long)hdr->dout_xferp;
27178 + dxferp = (void __user *)(unsigned long)hdr->dout_xferp;
27179 } else if (hdr->din_xfer_len) {
27180 dxfer_len = hdr->din_xfer_len;
27181 - dxferp = (void*)(unsigned long)hdr->din_xferp;
27182 + dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27183 } else
27184 dxfer_len = 0;
27185
27186 @@ -436,7 +444,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
27187 int len = min_t(unsigned int, hdr->max_response_len,
27188 rq->sense_len);
27189
27190 - ret = copy_to_user((void*)(unsigned long)hdr->response,
27191 + ret = copy_to_user((void __user *)(unsigned long)hdr->response,
27192 rq->sense, len);
27193 if (!ret)
27194 hdr->response_len = len;
27195 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27196 index 9bd086c..ca1fc22 100644
27197 --- a/block/compat_ioctl.c
27198 +++ b/block/compat_ioctl.c
27199 @@ -354,7 +354,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27200 err |= __get_user(f->spec1, &uf->spec1);
27201 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27202 err |= __get_user(name, &uf->name);
27203 - f->name = compat_ptr(name);
27204 + f->name = (void __force_kernel *)compat_ptr(name);
27205 if (err) {
27206 err = -EFAULT;
27207 goto out;
27208 diff --git a/block/elevator.c b/block/elevator.c
27209 index a847046..75a1746 100644
27210 --- a/block/elevator.c
27211 +++ b/block/elevator.c
27212 @@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
27213 return error;
27214 }
27215
27216 -static struct sysfs_ops elv_sysfs_ops = {
27217 +static const struct sysfs_ops elv_sysfs_ops = {
27218 .show = elv_attr_show,
27219 .store = elv_attr_store,
27220 };
27221 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27222 index 1d5a780..0e2fb8c 100644
27223 --- a/block/scsi_ioctl.c
27224 +++ b/block/scsi_ioctl.c
27225 @@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
27226 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27227 struct sg_io_hdr *hdr, fmode_t mode)
27228 {
27229 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27230 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27231 + unsigned char *cmdptr;
27232 +
27233 + if (rq->cmd != rq->__cmd)
27234 + cmdptr = rq->cmd;
27235 + else
27236 + cmdptr = tmpcmd;
27237 +
27238 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27239 return -EFAULT;
27240 +
27241 + if (cmdptr != rq->cmd)
27242 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27243 +
27244 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27245 return -EPERM;
27246
27247 @@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27248 int err;
27249 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27250 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27251 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27252 + unsigned char *cmdptr;
27253
27254 if (!sic)
27255 return -EINVAL;
27256 @@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27257 */
27258 err = -EFAULT;
27259 rq->cmd_len = cmdlen;
27260 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27261 +
27262 + if (rq->cmd != rq->__cmd)
27263 + cmdptr = rq->cmd;
27264 + else
27265 + cmdptr = tmpcmd;
27266 +
27267 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27268 goto error;
27269
27270 + if (rq->cmd != cmdptr)
27271 + memcpy(rq->cmd, cmdptr, cmdlen);
27272 +
27273 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27274 goto error;
27275
27276 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27277 index 3533582..f143117 100644
27278 --- a/crypto/cryptd.c
27279 +++ b/crypto/cryptd.c
27280 @@ -50,7 +50,7 @@ struct cryptd_blkcipher_ctx {
27281
27282 struct cryptd_blkcipher_request_ctx {
27283 crypto_completion_t complete;
27284 -};
27285 +} __no_const;
27286
27287 struct cryptd_hash_ctx {
27288 struct crypto_shash *child;
27289 diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c
27290 index a90d260..7a9765e 100644
27291 --- a/crypto/gf128mul.c
27292 +++ b/crypto/gf128mul.c
27293 @@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128 *b)
27294 for (i = 0; i < 7; ++i)
27295 gf128mul_x_lle(&p[i + 1], &p[i]);
27296
27297 - memset(r, 0, sizeof(r));
27298 + memset(r, 0, sizeof(*r));
27299 for (i = 0;;) {
27300 u8 ch = ((u8 *)b)[15 - i];
27301
27302 @@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128 *b)
27303 for (i = 0; i < 7; ++i)
27304 gf128mul_x_bbe(&p[i + 1], &p[i]);
27305
27306 - memset(r, 0, sizeof(r));
27307 + memset(r, 0, sizeof(*r));
27308 for (i = 0;;) {
27309 u8 ch = ((u8 *)b)[i];
27310
27311 diff --git a/crypto/serpent.c b/crypto/serpent.c
27312 index b651a55..023297d 100644
27313 --- a/crypto/serpent.c
27314 +++ b/crypto/serpent.c
27315 @@ -21,6 +21,7 @@
27316 #include <asm/byteorder.h>
27317 #include <linux/crypto.h>
27318 #include <linux/types.h>
27319 +#include <linux/sched.h>
27320
27321 /* Key is padded to the maximum of 256 bits before round key generation.
27322 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
27323 @@ -224,6 +225,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
27324 u32 r0,r1,r2,r3,r4;
27325 int i;
27326
27327 + pax_track_stack();
27328 +
27329 /* Copy key, add padding */
27330
27331 for (i = 0; i < keylen; ++i)
27332 diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
27333 index 0d2cdb8..d8de48d 100644
27334 --- a/drivers/acpi/acpi_pad.c
27335 +++ b/drivers/acpi/acpi_pad.c
27336 @@ -30,7 +30,7 @@
27337 #include <acpi/acpi_bus.h>
27338 #include <acpi/acpi_drivers.h>
27339
27340 -#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
27341 +#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
27342 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
27343 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
27344 static DEFINE_MUTEX(isolated_cpus_lock);
27345 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27346 index 3f4602b..2e41d36 100644
27347 --- a/drivers/acpi/battery.c
27348 +++ b/drivers/acpi/battery.c
27349 @@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
27350 }
27351
27352 static struct battery_file {
27353 - struct file_operations ops;
27354 + const struct file_operations ops;
27355 mode_t mode;
27356 const char *name;
27357 } acpi_battery_file[] = {
27358 diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
27359 index 7338b6a..82f0257 100644
27360 --- a/drivers/acpi/dock.c
27361 +++ b/drivers/acpi/dock.c
27362 @@ -77,7 +77,7 @@ struct dock_dependent_device {
27363 struct list_head list;
27364 struct list_head hotplug_list;
27365 acpi_handle handle;
27366 - struct acpi_dock_ops *ops;
27367 + const struct acpi_dock_ops *ops;
27368 void *context;
27369 };
27370
27371 @@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
27372 * the dock driver after _DCK is executed.
27373 */
27374 int
27375 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
27376 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
27377 void *context)
27378 {
27379 struct dock_dependent_device *dd;
27380 diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
27381 index 7c1c59e..2993595 100644
27382 --- a/drivers/acpi/osl.c
27383 +++ b/drivers/acpi/osl.c
27384 @@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
27385 void __iomem *virt_addr;
27386
27387 virt_addr = ioremap(phys_addr, width);
27388 + if (!virt_addr)
27389 + return AE_NO_MEMORY;
27390 if (!value)
27391 value = &dummy;
27392
27393 @@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
27394 void __iomem *virt_addr;
27395
27396 virt_addr = ioremap(phys_addr, width);
27397 + if (!virt_addr)
27398 + return AE_NO_MEMORY;
27399
27400 switch (width) {
27401 case 8:
27402 diff --git a/drivers/acpi/power_meter.c b/drivers/acpi/power_meter.c
27403 index c216062..eec10d2 100644
27404 --- a/drivers/acpi/power_meter.c
27405 +++ b/drivers/acpi/power_meter.c
27406 @@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
27407 return res;
27408
27409 temp /= 1000;
27410 - if (temp < 0)
27411 - return -EINVAL;
27412
27413 mutex_lock(&resource->lock);
27414 resource->trip[attr->index - 7] = temp;
27415 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27416 index d0d25e2..961643d 100644
27417 --- a/drivers/acpi/proc.c
27418 +++ b/drivers/acpi/proc.c
27419 @@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct file *file,
27420 size_t count, loff_t * ppos)
27421 {
27422 struct list_head *node, *next;
27423 - char strbuf[5];
27424 - char str[5] = "";
27425 - unsigned int len = count;
27426 + char strbuf[5] = {0};
27427 struct acpi_device *found_dev = NULL;
27428
27429 - if (len > 4)
27430 - len = 4;
27431 - if (len < 0)
27432 - return -EFAULT;
27433 + if (count > 4)
27434 + count = 4;
27435
27436 - if (copy_from_user(strbuf, buffer, len))
27437 + if (copy_from_user(strbuf, buffer, count))
27438 return -EFAULT;
27439 - strbuf[len] = '\0';
27440 - sscanf(strbuf, "%s", str);
27441 + strbuf[count] = '\0';
27442
27443 mutex_lock(&acpi_device_lock);
27444 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27445 @@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct file *file,
27446 if (!dev->wakeup.flags.valid)
27447 continue;
27448
27449 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27450 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27451 dev->wakeup.state.enabled =
27452 dev->wakeup.state.enabled ? 0 : 1;
27453 found_dev = dev;
27454 diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
27455 index 7102474..de8ad22 100644
27456 --- a/drivers/acpi/processor_core.c
27457 +++ b/drivers/acpi/processor_core.c
27458 @@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27459 return 0;
27460 }
27461
27462 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27463 + BUG_ON(pr->id >= nr_cpu_ids);
27464
27465 /*
27466 * Buggy BIOS check
27467 diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
27468 index d933980..5761f13 100644
27469 --- a/drivers/acpi/sbshc.c
27470 +++ b/drivers/acpi/sbshc.c
27471 @@ -17,7 +17,7 @@
27472
27473 #define PREFIX "ACPI: "
27474
27475 -#define ACPI_SMB_HC_CLASS "smbus_host_controller"
27476 +#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
27477 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
27478
27479 struct acpi_smb_hc {
27480 diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
27481 index 0458094..6978e7b 100644
27482 --- a/drivers/acpi/sleep.c
27483 +++ b/drivers/acpi/sleep.c
27484 @@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
27485 }
27486 }
27487
27488 -static struct platform_suspend_ops acpi_suspend_ops = {
27489 +static const struct platform_suspend_ops acpi_suspend_ops = {
27490 .valid = acpi_suspend_state_valid,
27491 .begin = acpi_suspend_begin,
27492 .prepare_late = acpi_pm_prepare,
27493 @@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
27494 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27495 * been requested.
27496 */
27497 -static struct platform_suspend_ops acpi_suspend_ops_old = {
27498 +static const struct platform_suspend_ops acpi_suspend_ops_old = {
27499 .valid = acpi_suspend_state_valid,
27500 .begin = acpi_suspend_begin_old,
27501 .prepare_late = acpi_pm_disable_gpes,
27502 @@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
27503 acpi_enable_all_runtime_gpes();
27504 }
27505
27506 -static struct platform_hibernation_ops acpi_hibernation_ops = {
27507 +static const struct platform_hibernation_ops acpi_hibernation_ops = {
27508 .begin = acpi_hibernation_begin,
27509 .end = acpi_pm_end,
27510 .pre_snapshot = acpi_hibernation_pre_snapshot,
27511 @@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
27512 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27513 * been requested.
27514 */
27515 -static struct platform_hibernation_ops acpi_hibernation_ops_old = {
27516 +static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
27517 .begin = acpi_hibernation_begin_old,
27518 .end = acpi_pm_end,
27519 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
27520 diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
27521 index 05dff63..b662ab7 100644
27522 --- a/drivers/acpi/video.c
27523 +++ b/drivers/acpi/video.c
27524 @@ -359,7 +359,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
27525 vd->brightness->levels[request_level]);
27526 }
27527
27528 -static struct backlight_ops acpi_backlight_ops = {
27529 +static const struct backlight_ops acpi_backlight_ops = {
27530 .get_brightness = acpi_video_get_brightness,
27531 .update_status = acpi_video_set_brightness,
27532 };
27533 diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
27534 index 6787aab..23ffb0e 100644
27535 --- a/drivers/ata/ahci.c
27536 +++ b/drivers/ata/ahci.c
27537 @@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sht = {
27538 .sdev_attrs = ahci_sdev_attrs,
27539 };
27540
27541 -static struct ata_port_operations ahci_ops = {
27542 +static const struct ata_port_operations ahci_ops = {
27543 .inherits = &sata_pmp_port_ops,
27544
27545 .qc_defer = sata_pmp_qc_defer_cmd_switch,
27546 @@ -424,17 +424,17 @@ static struct ata_port_operations ahci_ops = {
27547 .port_stop = ahci_port_stop,
27548 };
27549
27550 -static struct ata_port_operations ahci_vt8251_ops = {
27551 +static const struct ata_port_operations ahci_vt8251_ops = {
27552 .inherits = &ahci_ops,
27553 .hardreset = ahci_vt8251_hardreset,
27554 };
27555
27556 -static struct ata_port_operations ahci_p5wdh_ops = {
27557 +static const struct ata_port_operations ahci_p5wdh_ops = {
27558 .inherits = &ahci_ops,
27559 .hardreset = ahci_p5wdh_hardreset,
27560 };
27561
27562 -static struct ata_port_operations ahci_sb600_ops = {
27563 +static const struct ata_port_operations ahci_sb600_ops = {
27564 .inherits = &ahci_ops,
27565 .softreset = ahci_sb600_softreset,
27566 .pmp_softreset = ahci_sb600_softreset,
27567 diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
27568 index 99e7196..4968c77 100644
27569 --- a/drivers/ata/ata_generic.c
27570 +++ b/drivers/ata/ata_generic.c
27571 @@ -104,7 +104,7 @@ static struct scsi_host_template generic_sht = {
27572 ATA_BMDMA_SHT(DRV_NAME),
27573 };
27574
27575 -static struct ata_port_operations generic_port_ops = {
27576 +static const struct ata_port_operations generic_port_ops = {
27577 .inherits = &ata_bmdma_port_ops,
27578 .cable_detect = ata_cable_unknown,
27579 .set_mode = generic_set_mode,
27580 diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
27581 index c33591d..000c121 100644
27582 --- a/drivers/ata/ata_piix.c
27583 +++ b/drivers/ata/ata_piix.c
27584 @@ -318,7 +318,7 @@ static struct scsi_host_template piix_sht = {
27585 ATA_BMDMA_SHT(DRV_NAME),
27586 };
27587
27588 -static struct ata_port_operations piix_pata_ops = {
27589 +static const struct ata_port_operations piix_pata_ops = {
27590 .inherits = &ata_bmdma32_port_ops,
27591 .cable_detect = ata_cable_40wire,
27592 .set_piomode = piix_set_piomode,
27593 @@ -326,22 +326,22 @@ static struct ata_port_operations piix_pata_ops = {
27594 .prereset = piix_pata_prereset,
27595 };
27596
27597 -static struct ata_port_operations piix_vmw_ops = {
27598 +static const struct ata_port_operations piix_vmw_ops = {
27599 .inherits = &piix_pata_ops,
27600 .bmdma_status = piix_vmw_bmdma_status,
27601 };
27602
27603 -static struct ata_port_operations ich_pata_ops = {
27604 +static const struct ata_port_operations ich_pata_ops = {
27605 .inherits = &piix_pata_ops,
27606 .cable_detect = ich_pata_cable_detect,
27607 .set_dmamode = ich_set_dmamode,
27608 };
27609
27610 -static struct ata_port_operations piix_sata_ops = {
27611 +static const struct ata_port_operations piix_sata_ops = {
27612 .inherits = &ata_bmdma_port_ops,
27613 };
27614
27615 -static struct ata_port_operations piix_sidpr_sata_ops = {
27616 +static const struct ata_port_operations piix_sidpr_sata_ops = {
27617 .inherits = &piix_sata_ops,
27618 .hardreset = sata_std_hardreset,
27619 .scr_read = piix_sidpr_scr_read,
27620 diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
27621 index b0882cd..c295d65 100644
27622 --- a/drivers/ata/libata-acpi.c
27623 +++ b/drivers/ata/libata-acpi.c
27624 @@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_handle handle, u32 event, void *data)
27625 ata_acpi_uevent(dev->link->ap, dev, event);
27626 }
27627
27628 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27629 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27630 .handler = ata_acpi_dev_notify_dock,
27631 .uevent = ata_acpi_dev_uevent,
27632 };
27633
27634 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27635 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27636 .handler = ata_acpi_ap_notify_dock,
27637 .uevent = ata_acpi_ap_uevent,
27638 };
27639 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27640 index d4f7f99..94f603e 100644
27641 --- a/drivers/ata/libata-core.c
27642 +++ b/drivers/ata/libata-core.c
27643 @@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27644 struct ata_port *ap;
27645 unsigned int tag;
27646
27647 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27648 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27649 ap = qc->ap;
27650
27651 qc->flags = 0;
27652 @@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27653 struct ata_port *ap;
27654 struct ata_link *link;
27655
27656 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27657 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27658 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27659 ap = qc->ap;
27660 link = qc->dev->link;
27661 @@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device *gendev, void *res)
27662 * LOCKING:
27663 * None.
27664 */
27665 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
27666 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
27667 {
27668 static DEFINE_SPINLOCK(lock);
27669 const struct ata_port_operations *cur;
27670 @@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27671 return;
27672
27673 spin_lock(&lock);
27674 + pax_open_kernel();
27675
27676 for (cur = ops->inherits; cur; cur = cur->inherits) {
27677 void **inherit = (void **)cur;
27678 @@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27679 if (IS_ERR(*pp))
27680 *pp = NULL;
27681
27682 - ops->inherits = NULL;
27683 + *(struct ata_port_operations **)&ops->inherits = NULL;
27684
27685 + pax_close_kernel();
27686 spin_unlock(&lock);
27687 }
27688
27689 @@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host)
27690 */
27691 /* KILLME - the only user left is ipr */
27692 void ata_host_init(struct ata_host *host, struct device *dev,
27693 - unsigned long flags, struct ata_port_operations *ops)
27694 + unsigned long flags, const struct ata_port_operations *ops)
27695 {
27696 spin_lock_init(&host->lock);
27697 host->dev = dev;
27698 @@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(struct ata_port *ap)
27699 /* truly dummy */
27700 }
27701
27702 -struct ata_port_operations ata_dummy_port_ops = {
27703 +const struct ata_port_operations ata_dummy_port_ops = {
27704 .qc_prep = ata_noop_qc_prep,
27705 .qc_issue = ata_dummy_qc_issue,
27706 .error_handler = ata_dummy_error_handler,
27707 diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
27708 index e5bdb9b..45a8e72 100644
27709 --- a/drivers/ata/libata-eh.c
27710 +++ b/drivers/ata/libata-eh.c
27711 @@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
27712 {
27713 struct ata_link *link;
27714
27715 + pax_track_stack();
27716 +
27717 ata_for_each_link(link, ap, HOST_FIRST)
27718 ata_eh_link_report(link);
27719 }
27720 @@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
27721 */
27722 void ata_std_error_handler(struct ata_port *ap)
27723 {
27724 - struct ata_port_operations *ops = ap->ops;
27725 + const struct ata_port_operations *ops = ap->ops;
27726 ata_reset_fn_t hardreset = ops->hardreset;
27727
27728 /* ignore built-in hardreset if SCR access is not available */
27729 diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
27730 index 51f0ffb..19ce3e3 100644
27731 --- a/drivers/ata/libata-pmp.c
27732 +++ b/drivers/ata/libata-pmp.c
27733 @@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
27734 */
27735 static int sata_pmp_eh_recover(struct ata_port *ap)
27736 {
27737 - struct ata_port_operations *ops = ap->ops;
27738 + const struct ata_port_operations *ops = ap->ops;
27739 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
27740 struct ata_link *pmp_link = &ap->link;
27741 struct ata_device *pmp_dev = pmp_link->device;
27742 diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
27743 index d8f35fe..288180a 100644
27744 --- a/drivers/ata/pata_acpi.c
27745 +++ b/drivers/ata/pata_acpi.c
27746 @@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_sht = {
27747 ATA_BMDMA_SHT(DRV_NAME),
27748 };
27749
27750 -static struct ata_port_operations pacpi_ops = {
27751 +static const struct ata_port_operations pacpi_ops = {
27752 .inherits = &ata_bmdma_port_ops,
27753 .qc_issue = pacpi_qc_issue,
27754 .cable_detect = pacpi_cable_detect,
27755 diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
27756 index 9434114..1f2f364 100644
27757 --- a/drivers/ata/pata_ali.c
27758 +++ b/drivers/ata/pata_ali.c
27759 @@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht = {
27760 * Port operations for PIO only ALi
27761 */
27762
27763 -static struct ata_port_operations ali_early_port_ops = {
27764 +static const struct ata_port_operations ali_early_port_ops = {
27765 .inherits = &ata_sff_port_ops,
27766 .cable_detect = ata_cable_40wire,
27767 .set_piomode = ali_set_piomode,
27768 @@ -382,7 +382,7 @@ static const struct ata_port_operations ali_dma_base_ops = {
27769 * Port operations for DMA capable ALi without cable
27770 * detect
27771 */
27772 -static struct ata_port_operations ali_20_port_ops = {
27773 +static const struct ata_port_operations ali_20_port_ops = {
27774 .inherits = &ali_dma_base_ops,
27775 .cable_detect = ata_cable_40wire,
27776 .mode_filter = ali_20_filter,
27777 @@ -393,7 +393,7 @@ static struct ata_port_operations ali_20_port_ops = {
27778 /*
27779 * Port operations for DMA capable ALi with cable detect
27780 */
27781 -static struct ata_port_operations ali_c2_port_ops = {
27782 +static const struct ata_port_operations ali_c2_port_ops = {
27783 .inherits = &ali_dma_base_ops,
27784 .check_atapi_dma = ali_check_atapi_dma,
27785 .cable_detect = ali_c2_cable_detect,
27786 @@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2_port_ops = {
27787 /*
27788 * Port operations for DMA capable ALi with cable detect
27789 */
27790 -static struct ata_port_operations ali_c4_port_ops = {
27791 +static const struct ata_port_operations ali_c4_port_ops = {
27792 .inherits = &ali_dma_base_ops,
27793 .check_atapi_dma = ali_check_atapi_dma,
27794 .cable_detect = ali_c2_cable_detect,
27795 @@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4_port_ops = {
27796 /*
27797 * Port operations for DMA capable ALi with cable detect and LBA48
27798 */
27799 -static struct ata_port_operations ali_c5_port_ops = {
27800 +static const struct ata_port_operations ali_c5_port_ops = {
27801 .inherits = &ali_dma_base_ops,
27802 .check_atapi_dma = ali_check_atapi_dma,
27803 .dev_config = ali_warn_atapi_dma,
27804 diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
27805 index 567f3f7..c8ee0da 100644
27806 --- a/drivers/ata/pata_amd.c
27807 +++ b/drivers/ata/pata_amd.c
27808 @@ -397,28 +397,28 @@ static const struct ata_port_operations amd_base_port_ops = {
27809 .prereset = amd_pre_reset,
27810 };
27811
27812 -static struct ata_port_operations amd33_port_ops = {
27813 +static const struct ata_port_operations amd33_port_ops = {
27814 .inherits = &amd_base_port_ops,
27815 .cable_detect = ata_cable_40wire,
27816 .set_piomode = amd33_set_piomode,
27817 .set_dmamode = amd33_set_dmamode,
27818 };
27819
27820 -static struct ata_port_operations amd66_port_ops = {
27821 +static const struct ata_port_operations amd66_port_ops = {
27822 .inherits = &amd_base_port_ops,
27823 .cable_detect = ata_cable_unknown,
27824 .set_piomode = amd66_set_piomode,
27825 .set_dmamode = amd66_set_dmamode,
27826 };
27827
27828 -static struct ata_port_operations amd100_port_ops = {
27829 +static const struct ata_port_operations amd100_port_ops = {
27830 .inherits = &amd_base_port_ops,
27831 .cable_detect = ata_cable_unknown,
27832 .set_piomode = amd100_set_piomode,
27833 .set_dmamode = amd100_set_dmamode,
27834 };
27835
27836 -static struct ata_port_operations amd133_port_ops = {
27837 +static const struct ata_port_operations amd133_port_ops = {
27838 .inherits = &amd_base_port_ops,
27839 .cable_detect = amd_cable_detect,
27840 .set_piomode = amd133_set_piomode,
27841 @@ -433,13 +433,13 @@ static const struct ata_port_operations nv_base_port_ops = {
27842 .host_stop = nv_host_stop,
27843 };
27844
27845 -static struct ata_port_operations nv100_port_ops = {
27846 +static const struct ata_port_operations nv100_port_ops = {
27847 .inherits = &nv_base_port_ops,
27848 .set_piomode = nv100_set_piomode,
27849 .set_dmamode = nv100_set_dmamode,
27850 };
27851
27852 -static struct ata_port_operations nv133_port_ops = {
27853 +static const struct ata_port_operations nv133_port_ops = {
27854 .inherits = &nv_base_port_ops,
27855 .set_piomode = nv133_set_piomode,
27856 .set_dmamode = nv133_set_dmamode,
27857 diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
27858 index d332cfd..4b7eaae 100644
27859 --- a/drivers/ata/pata_artop.c
27860 +++ b/drivers/ata/pata_artop.c
27861 @@ -311,7 +311,7 @@ static struct scsi_host_template artop_sht = {
27862 ATA_BMDMA_SHT(DRV_NAME),
27863 };
27864
27865 -static struct ata_port_operations artop6210_ops = {
27866 +static const struct ata_port_operations artop6210_ops = {
27867 .inherits = &ata_bmdma_port_ops,
27868 .cable_detect = ata_cable_40wire,
27869 .set_piomode = artop6210_set_piomode,
27870 @@ -320,7 +320,7 @@ static struct ata_port_operations artop6210_ops = {
27871 .qc_defer = artop6210_qc_defer,
27872 };
27873
27874 -static struct ata_port_operations artop6260_ops = {
27875 +static const struct ata_port_operations artop6260_ops = {
27876 .inherits = &ata_bmdma_port_ops,
27877 .cable_detect = artop6260_cable_detect,
27878 .set_piomode = artop6260_set_piomode,
27879 diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
27880 index 5c129f9..7bb7ccb 100644
27881 --- a/drivers/ata/pata_at32.c
27882 +++ b/drivers/ata/pata_at32.c
27883 @@ -172,7 +172,7 @@ static struct scsi_host_template at32_sht = {
27884 ATA_PIO_SHT(DRV_NAME),
27885 };
27886
27887 -static struct ata_port_operations at32_port_ops = {
27888 +static const struct ata_port_operations at32_port_ops = {
27889 .inherits = &ata_sff_port_ops,
27890 .cable_detect = ata_cable_40wire,
27891 .set_piomode = pata_at32_set_piomode,
27892 diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
27893 index 41c94b1..829006d 100644
27894 --- a/drivers/ata/pata_at91.c
27895 +++ b/drivers/ata/pata_at91.c
27896 @@ -195,7 +195,7 @@ static struct scsi_host_template pata_at91_sht = {
27897 ATA_PIO_SHT(DRV_NAME),
27898 };
27899
27900 -static struct ata_port_operations pata_at91_port_ops = {
27901 +static const struct ata_port_operations pata_at91_port_ops = {
27902 .inherits = &ata_sff_port_ops,
27903
27904 .sff_data_xfer = pata_at91_data_xfer_noirq,
27905 diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
27906 index ae4454d..d391eb4 100644
27907 --- a/drivers/ata/pata_atiixp.c
27908 +++ b/drivers/ata/pata_atiixp.c
27909 @@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_sht = {
27910 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27911 };
27912
27913 -static struct ata_port_operations atiixp_port_ops = {
27914 +static const struct ata_port_operations atiixp_port_ops = {
27915 .inherits = &ata_bmdma_port_ops,
27916
27917 .qc_prep = ata_sff_dumb_qc_prep,
27918 diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c
27919 index 6fe7ded..2a425dc 100644
27920 --- a/drivers/ata/pata_atp867x.c
27921 +++ b/drivers/ata/pata_atp867x.c
27922 @@ -274,7 +274,7 @@ static struct scsi_host_template atp867x_sht = {
27923 ATA_BMDMA_SHT(DRV_NAME),
27924 };
27925
27926 -static struct ata_port_operations atp867x_ops = {
27927 +static const struct ata_port_operations atp867x_ops = {
27928 .inherits = &ata_bmdma_port_ops,
27929 .cable_detect = atp867x_cable_detect,
27930 .set_piomode = atp867x_set_piomode,
27931 diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
27932 index c4b47a3..b27a367 100644
27933 --- a/drivers/ata/pata_bf54x.c
27934 +++ b/drivers/ata/pata_bf54x.c
27935 @@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sht = {
27936 .dma_boundary = ATA_DMA_BOUNDARY,
27937 };
27938
27939 -static struct ata_port_operations bfin_pata_ops = {
27940 +static const struct ata_port_operations bfin_pata_ops = {
27941 .inherits = &ata_sff_port_ops,
27942
27943 .set_piomode = bfin_set_piomode,
27944 diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
27945 index 5acf9fa..84248be 100644
27946 --- a/drivers/ata/pata_cmd640.c
27947 +++ b/drivers/ata/pata_cmd640.c
27948 @@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_sht = {
27949 ATA_BMDMA_SHT(DRV_NAME),
27950 };
27951
27952 -static struct ata_port_operations cmd640_port_ops = {
27953 +static const struct ata_port_operations cmd640_port_ops = {
27954 .inherits = &ata_bmdma_port_ops,
27955 /* In theory xfer_noirq is not needed once we kill the prefetcher */
27956 .sff_data_xfer = ata_sff_data_xfer_noirq,
27957 diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
27958 index ccd2694..c869c3d 100644
27959 --- a/drivers/ata/pata_cmd64x.c
27960 +++ b/drivers/ata/pata_cmd64x.c
27961 @@ -271,18 +271,18 @@ static const struct ata_port_operations cmd64x_base_ops = {
27962 .set_dmamode = cmd64x_set_dmamode,
27963 };
27964
27965 -static struct ata_port_operations cmd64x_port_ops = {
27966 +static const struct ata_port_operations cmd64x_port_ops = {
27967 .inherits = &cmd64x_base_ops,
27968 .cable_detect = ata_cable_40wire,
27969 };
27970
27971 -static struct ata_port_operations cmd646r1_port_ops = {
27972 +static const struct ata_port_operations cmd646r1_port_ops = {
27973 .inherits = &cmd64x_base_ops,
27974 .bmdma_stop = cmd646r1_bmdma_stop,
27975 .cable_detect = ata_cable_40wire,
27976 };
27977
27978 -static struct ata_port_operations cmd648_port_ops = {
27979 +static const struct ata_port_operations cmd648_port_ops = {
27980 .inherits = &cmd64x_base_ops,
27981 .bmdma_stop = cmd648_bmdma_stop,
27982 .cable_detect = cmd648_cable_detect,
27983 diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
27984 index 0df83cf..d7595b0 100644
27985 --- a/drivers/ata/pata_cs5520.c
27986 +++ b/drivers/ata/pata_cs5520.c
27987 @@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_sht = {
27988 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27989 };
27990
27991 -static struct ata_port_operations cs5520_port_ops = {
27992 +static const struct ata_port_operations cs5520_port_ops = {
27993 .inherits = &ata_bmdma_port_ops,
27994 .qc_prep = ata_sff_dumb_qc_prep,
27995 .cable_detect = ata_cable_40wire,
27996 diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
27997 index c974b05..6d26b11 100644
27998 --- a/drivers/ata/pata_cs5530.c
27999 +++ b/drivers/ata/pata_cs5530.c
28000 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_sht = {
28001 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28002 };
28003
28004 -static struct ata_port_operations cs5530_port_ops = {
28005 +static const struct ata_port_operations cs5530_port_ops = {
28006 .inherits = &ata_bmdma_port_ops,
28007
28008 .qc_prep = ata_sff_dumb_qc_prep,
28009 diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
28010 index 403f561..aacd26b 100644
28011 --- a/drivers/ata/pata_cs5535.c
28012 +++ b/drivers/ata/pata_cs5535.c
28013 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_sht = {
28014 ATA_BMDMA_SHT(DRV_NAME),
28015 };
28016
28017 -static struct ata_port_operations cs5535_port_ops = {
28018 +static const struct ata_port_operations cs5535_port_ops = {
28019 .inherits = &ata_bmdma_port_ops,
28020 .cable_detect = cs5535_cable_detect,
28021 .set_piomode = cs5535_set_piomode,
28022 diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
28023 index 6da4cb4..de24a25 100644
28024 --- a/drivers/ata/pata_cs5536.c
28025 +++ b/drivers/ata/pata_cs5536.c
28026 @@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_sht = {
28027 ATA_BMDMA_SHT(DRV_NAME),
28028 };
28029
28030 -static struct ata_port_operations cs5536_port_ops = {
28031 +static const struct ata_port_operations cs5536_port_ops = {
28032 .inherits = &ata_bmdma_port_ops,
28033 .cable_detect = cs5536_cable_detect,
28034 .set_piomode = cs5536_set_piomode,
28035 diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
28036 index 8fb040b..b16a9c9 100644
28037 --- a/drivers/ata/pata_cypress.c
28038 +++ b/drivers/ata/pata_cypress.c
28039 @@ -113,7 +113,7 @@ static struct scsi_host_template cy82c693_sht = {
28040 ATA_BMDMA_SHT(DRV_NAME),
28041 };
28042
28043 -static struct ata_port_operations cy82c693_port_ops = {
28044 +static const struct ata_port_operations cy82c693_port_ops = {
28045 .inherits = &ata_bmdma_port_ops,
28046 .cable_detect = ata_cable_40wire,
28047 .set_piomode = cy82c693_set_piomode,
28048 diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
28049 index 2a6412f..555ee11 100644
28050 --- a/drivers/ata/pata_efar.c
28051 +++ b/drivers/ata/pata_efar.c
28052 @@ -222,7 +222,7 @@ static struct scsi_host_template efar_sht = {
28053 ATA_BMDMA_SHT(DRV_NAME),
28054 };
28055
28056 -static struct ata_port_operations efar_ops = {
28057 +static const struct ata_port_operations efar_ops = {
28058 .inherits = &ata_bmdma_port_ops,
28059 .cable_detect = efar_cable_detect,
28060 .set_piomode = efar_set_piomode,
28061 diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
28062 index b9d8836..0b92030 100644
28063 --- a/drivers/ata/pata_hpt366.c
28064 +++ b/drivers/ata/pata_hpt366.c
28065 @@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_sht = {
28066 * Configuration for HPT366/68
28067 */
28068
28069 -static struct ata_port_operations hpt366_port_ops = {
28070 +static const struct ata_port_operations hpt366_port_ops = {
28071 .inherits = &ata_bmdma_port_ops,
28072 .cable_detect = hpt36x_cable_detect,
28073 .mode_filter = hpt366_filter,
28074 diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
28075 index 5af7f19..00c4980 100644
28076 --- a/drivers/ata/pata_hpt37x.c
28077 +++ b/drivers/ata/pata_hpt37x.c
28078 @@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_sht = {
28079 * Configuration for HPT370
28080 */
28081
28082 -static struct ata_port_operations hpt370_port_ops = {
28083 +static const struct ata_port_operations hpt370_port_ops = {
28084 .inherits = &ata_bmdma_port_ops,
28085
28086 .bmdma_stop = hpt370_bmdma_stop,
28087 @@ -591,7 +591,7 @@ static struct ata_port_operations hpt370_port_ops = {
28088 * Configuration for HPT370A. Close to 370 but less filters
28089 */
28090
28091 -static struct ata_port_operations hpt370a_port_ops = {
28092 +static const struct ata_port_operations hpt370a_port_ops = {
28093 .inherits = &hpt370_port_ops,
28094 .mode_filter = hpt370a_filter,
28095 };
28096 @@ -601,7 +601,7 @@ static struct ata_port_operations hpt370a_port_ops = {
28097 * and DMA mode setting functionality.
28098 */
28099
28100 -static struct ata_port_operations hpt372_port_ops = {
28101 +static const struct ata_port_operations hpt372_port_ops = {
28102 .inherits = &ata_bmdma_port_ops,
28103
28104 .bmdma_stop = hpt37x_bmdma_stop,
28105 @@ -616,7 +616,7 @@ static struct ata_port_operations hpt372_port_ops = {
28106 * but we have a different cable detection procedure for function 1.
28107 */
28108
28109 -static struct ata_port_operations hpt374_fn1_port_ops = {
28110 +static const struct ata_port_operations hpt374_fn1_port_ops = {
28111 .inherits = &hpt372_port_ops,
28112 .prereset = hpt374_fn1_pre_reset,
28113 };
28114 diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
28115 index 100f227..2e39382 100644
28116 --- a/drivers/ata/pata_hpt3x2n.c
28117 +++ b/drivers/ata/pata_hpt3x2n.c
28118 @@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n_sht = {
28119 * Configuration for HPT3x2n.
28120 */
28121
28122 -static struct ata_port_operations hpt3x2n_port_ops = {
28123 +static const struct ata_port_operations hpt3x2n_port_ops = {
28124 .inherits = &ata_bmdma_port_ops,
28125
28126 .bmdma_stop = hpt3x2n_bmdma_stop,
28127 diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
28128 index 7e31025..6fca8f4 100644
28129 --- a/drivers/ata/pata_hpt3x3.c
28130 +++ b/drivers/ata/pata_hpt3x3.c
28131 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_sht = {
28132 ATA_BMDMA_SHT(DRV_NAME),
28133 };
28134
28135 -static struct ata_port_operations hpt3x3_port_ops = {
28136 +static const struct ata_port_operations hpt3x3_port_ops = {
28137 .inherits = &ata_bmdma_port_ops,
28138 .cable_detect = ata_cable_40wire,
28139 .set_piomode = hpt3x3_set_piomode,
28140 diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
28141 index b663b7f..9a26c2a 100644
28142 --- a/drivers/ata/pata_icside.c
28143 +++ b/drivers/ata/pata_icside.c
28144 @@ -319,7 +319,7 @@ static void pata_icside_postreset(struct ata_link *link, unsigned int *classes)
28145 }
28146 }
28147
28148 -static struct ata_port_operations pata_icside_port_ops = {
28149 +static const struct ata_port_operations pata_icside_port_ops = {
28150 .inherits = &ata_sff_port_ops,
28151 /* no need to build any PRD tables for DMA */
28152 .qc_prep = ata_noop_qc_prep,
28153 diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
28154 index 4bceb88..457dfb6 100644
28155 --- a/drivers/ata/pata_isapnp.c
28156 +++ b/drivers/ata/pata_isapnp.c
28157 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_sht = {
28158 ATA_PIO_SHT(DRV_NAME),
28159 };
28160
28161 -static struct ata_port_operations isapnp_port_ops = {
28162 +static const struct ata_port_operations isapnp_port_ops = {
28163 .inherits = &ata_sff_port_ops,
28164 .cable_detect = ata_cable_40wire,
28165 };
28166
28167 -static struct ata_port_operations isapnp_noalt_port_ops = {
28168 +static const struct ata_port_operations isapnp_noalt_port_ops = {
28169 .inherits = &ata_sff_port_ops,
28170 .cable_detect = ata_cable_40wire,
28171 /* No altstatus so we don't want to use the lost interrupt poll */
28172 diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
28173 index f156da8..24976e2 100644
28174 --- a/drivers/ata/pata_it8213.c
28175 +++ b/drivers/ata/pata_it8213.c
28176 @@ -234,7 +234,7 @@ static struct scsi_host_template it8213_sht = {
28177 };
28178
28179
28180 -static struct ata_port_operations it8213_ops = {
28181 +static const struct ata_port_operations it8213_ops = {
28182 .inherits = &ata_bmdma_port_ops,
28183 .cable_detect = it8213_cable_detect,
28184 .set_piomode = it8213_set_piomode,
28185 diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
28186 index 188bc2f..ca9e785 100644
28187 --- a/drivers/ata/pata_it821x.c
28188 +++ b/drivers/ata/pata_it821x.c
28189 @@ -800,7 +800,7 @@ static struct scsi_host_template it821x_sht = {
28190 ATA_BMDMA_SHT(DRV_NAME),
28191 };
28192
28193 -static struct ata_port_operations it821x_smart_port_ops = {
28194 +static const struct ata_port_operations it821x_smart_port_ops = {
28195 .inherits = &ata_bmdma_port_ops,
28196
28197 .check_atapi_dma= it821x_check_atapi_dma,
28198 @@ -814,7 +814,7 @@ static struct ata_port_operations it821x_smart_port_ops = {
28199 .port_start = it821x_port_start,
28200 };
28201
28202 -static struct ata_port_operations it821x_passthru_port_ops = {
28203 +static const struct ata_port_operations it821x_passthru_port_ops = {
28204 .inherits = &ata_bmdma_port_ops,
28205
28206 .check_atapi_dma= it821x_check_atapi_dma,
28207 @@ -830,7 +830,7 @@ static struct ata_port_operations it821x_passthru_port_ops = {
28208 .port_start = it821x_port_start,
28209 };
28210
28211 -static struct ata_port_operations it821x_rdc_port_ops = {
28212 +static const struct ata_port_operations it821x_rdc_port_ops = {
28213 .inherits = &ata_bmdma_port_ops,
28214
28215 .check_atapi_dma= it821x_check_atapi_dma,
28216 diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
28217 index ba54b08..4b952b7 100644
28218 --- a/drivers/ata/pata_ixp4xx_cf.c
28219 +++ b/drivers/ata/pata_ixp4xx_cf.c
28220 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_sht = {
28221 ATA_PIO_SHT(DRV_NAME),
28222 };
28223
28224 -static struct ata_port_operations ixp4xx_port_ops = {
28225 +static const struct ata_port_operations ixp4xx_port_ops = {
28226 .inherits = &ata_sff_port_ops,
28227 .sff_data_xfer = ixp4xx_mmio_data_xfer,
28228 .cable_detect = ata_cable_40wire,
28229 diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
28230 index 3a1474a..434b0ff 100644
28231 --- a/drivers/ata/pata_jmicron.c
28232 +++ b/drivers/ata/pata_jmicron.c
28233 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron_sht = {
28234 ATA_BMDMA_SHT(DRV_NAME),
28235 };
28236
28237 -static struct ata_port_operations jmicron_ops = {
28238 +static const struct ata_port_operations jmicron_ops = {
28239 .inherits = &ata_bmdma_port_ops,
28240 .prereset = jmicron_pre_reset,
28241 };
28242 diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
28243 index 6932e56..220e71d 100644
28244 --- a/drivers/ata/pata_legacy.c
28245 +++ b/drivers/ata/pata_legacy.c
28246 @@ -106,7 +106,7 @@ struct legacy_probe {
28247
28248 struct legacy_controller {
28249 const char *name;
28250 - struct ata_port_operations *ops;
28251 + const struct ata_port_operations *ops;
28252 unsigned int pio_mask;
28253 unsigned int flags;
28254 unsigned int pflags;
28255 @@ -223,12 +223,12 @@ static const struct ata_port_operations legacy_base_port_ops = {
28256 * pio_mask as well.
28257 */
28258
28259 -static struct ata_port_operations simple_port_ops = {
28260 +static const struct ata_port_operations simple_port_ops = {
28261 .inherits = &legacy_base_port_ops,
28262 .sff_data_xfer = ata_sff_data_xfer_noirq,
28263 };
28264
28265 -static struct ata_port_operations legacy_port_ops = {
28266 +static const struct ata_port_operations legacy_port_ops = {
28267 .inherits = &legacy_base_port_ops,
28268 .sff_data_xfer = ata_sff_data_xfer_noirq,
28269 .set_mode = legacy_set_mode,
28270 @@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
28271 return buflen;
28272 }
28273
28274 -static struct ata_port_operations pdc20230_port_ops = {
28275 +static const struct ata_port_operations pdc20230_port_ops = {
28276 .inherits = &legacy_base_port_ops,
28277 .set_piomode = pdc20230_set_piomode,
28278 .sff_data_xfer = pdc_data_xfer_vlb,
28279 @@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
28280 ioread8(ap->ioaddr.status_addr);
28281 }
28282
28283 -static struct ata_port_operations ht6560a_port_ops = {
28284 +static const struct ata_port_operations ht6560a_port_ops = {
28285 .inherits = &legacy_base_port_ops,
28286 .set_piomode = ht6560a_set_piomode,
28287 };
28288 @@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
28289 ioread8(ap->ioaddr.status_addr);
28290 }
28291
28292 -static struct ata_port_operations ht6560b_port_ops = {
28293 +static const struct ata_port_operations ht6560b_port_ops = {
28294 .inherits = &legacy_base_port_ops,
28295 .set_piomode = ht6560b_set_piomode,
28296 };
28297 @@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(struct ata_port *ap,
28298 }
28299
28300
28301 -static struct ata_port_operations opti82c611a_port_ops = {
28302 +static const struct ata_port_operations opti82c611a_port_ops = {
28303 .inherits = &legacy_base_port_ops,
28304 .set_piomode = opti82c611a_set_piomode,
28305 };
28306 @@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(struct ata_queued_cmd *qc)
28307 return ata_sff_qc_issue(qc);
28308 }
28309
28310 -static struct ata_port_operations opti82c46x_port_ops = {
28311 +static const struct ata_port_operations opti82c46x_port_ops = {
28312 .inherits = &legacy_base_port_ops,
28313 .set_piomode = opti82c46x_set_piomode,
28314 .qc_issue = opti82c46x_qc_issue,
28315 @@ -771,20 +771,20 @@ static int qdi_port(struct platform_device *dev,
28316 return 0;
28317 }
28318
28319 -static struct ata_port_operations qdi6500_port_ops = {
28320 +static const struct ata_port_operations qdi6500_port_ops = {
28321 .inherits = &legacy_base_port_ops,
28322 .set_piomode = qdi6500_set_piomode,
28323 .qc_issue = qdi_qc_issue,
28324 .sff_data_xfer = vlb32_data_xfer,
28325 };
28326
28327 -static struct ata_port_operations qdi6580_port_ops = {
28328 +static const struct ata_port_operations qdi6580_port_ops = {
28329 .inherits = &legacy_base_port_ops,
28330 .set_piomode = qdi6580_set_piomode,
28331 .sff_data_xfer = vlb32_data_xfer,
28332 };
28333
28334 -static struct ata_port_operations qdi6580dp_port_ops = {
28335 +static const struct ata_port_operations qdi6580dp_port_ops = {
28336 .inherits = &legacy_base_port_ops,
28337 .set_piomode = qdi6580dp_set_piomode,
28338 .sff_data_xfer = vlb32_data_xfer,
28339 @@ -855,7 +855,7 @@ static int winbond_port(struct platform_device *dev,
28340 return 0;
28341 }
28342
28343 -static struct ata_port_operations winbond_port_ops = {
28344 +static const struct ata_port_operations winbond_port_ops = {
28345 .inherits = &legacy_base_port_ops,
28346 .set_piomode = winbond_set_piomode,
28347 .sff_data_xfer = vlb32_data_xfer,
28348 @@ -978,7 +978,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
28349 int pio_modes = controller->pio_mask;
28350 unsigned long io = probe->port;
28351 u32 mask = (1 << probe->slot);
28352 - struct ata_port_operations *ops = controller->ops;
28353 + const struct ata_port_operations *ops = controller->ops;
28354 struct legacy_data *ld = &legacy_data[probe->slot];
28355 struct ata_host *host = NULL;
28356 struct ata_port *ap;
28357 diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
28358 index 2096fb7..4d090fc 100644
28359 --- a/drivers/ata/pata_marvell.c
28360 +++ b/drivers/ata/pata_marvell.c
28361 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell_sht = {
28362 ATA_BMDMA_SHT(DRV_NAME),
28363 };
28364
28365 -static struct ata_port_operations marvell_ops = {
28366 +static const struct ata_port_operations marvell_ops = {
28367 .inherits = &ata_bmdma_port_ops,
28368 .cable_detect = marvell_cable_detect,
28369 .prereset = marvell_pre_reset,
28370 diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
28371 index 99d41be..7d56aa8 100644
28372 --- a/drivers/ata/pata_mpc52xx.c
28373 +++ b/drivers/ata/pata_mpc52xx.c
28374 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx_ata_sht = {
28375 ATA_PIO_SHT(DRV_NAME),
28376 };
28377
28378 -static struct ata_port_operations mpc52xx_ata_port_ops = {
28379 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
28380 .inherits = &ata_bmdma_port_ops,
28381 .sff_dev_select = mpc52xx_ata_dev_select,
28382 .set_piomode = mpc52xx_ata_set_piomode,
28383 diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
28384 index b21f002..0a27e7f 100644
28385 --- a/drivers/ata/pata_mpiix.c
28386 +++ b/drivers/ata/pata_mpiix.c
28387 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_sht = {
28388 ATA_PIO_SHT(DRV_NAME),
28389 };
28390
28391 -static struct ata_port_operations mpiix_port_ops = {
28392 +static const struct ata_port_operations mpiix_port_ops = {
28393 .inherits = &ata_sff_port_ops,
28394 .qc_issue = mpiix_qc_issue,
28395 .cable_detect = ata_cable_40wire,
28396 diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
28397 index f0d52f7..89c3be3 100644
28398 --- a/drivers/ata/pata_netcell.c
28399 +++ b/drivers/ata/pata_netcell.c
28400 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell_sht = {
28401 ATA_BMDMA_SHT(DRV_NAME),
28402 };
28403
28404 -static struct ata_port_operations netcell_ops = {
28405 +static const struct ata_port_operations netcell_ops = {
28406 .inherits = &ata_bmdma_port_ops,
28407 .cable_detect = ata_cable_80wire,
28408 .read_id = netcell_read_id,
28409 diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
28410 index dd53a66..a3f4317 100644
28411 --- a/drivers/ata/pata_ninja32.c
28412 +++ b/drivers/ata/pata_ninja32.c
28413 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32_sht = {
28414 ATA_BMDMA_SHT(DRV_NAME),
28415 };
28416
28417 -static struct ata_port_operations ninja32_port_ops = {
28418 +static const struct ata_port_operations ninja32_port_ops = {
28419 .inherits = &ata_bmdma_port_ops,
28420 .sff_dev_select = ninja32_dev_select,
28421 .cable_detect = ata_cable_40wire,
28422 diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
28423 index ca53fac..9aa93ef 100644
28424 --- a/drivers/ata/pata_ns87410.c
28425 +++ b/drivers/ata/pata_ns87410.c
28426 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410_sht = {
28427 ATA_PIO_SHT(DRV_NAME),
28428 };
28429
28430 -static struct ata_port_operations ns87410_port_ops = {
28431 +static const struct ata_port_operations ns87410_port_ops = {
28432 .inherits = &ata_sff_port_ops,
28433 .qc_issue = ns87410_qc_issue,
28434 .cable_detect = ata_cable_40wire,
28435 diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
28436 index 773b159..55f454e 100644
28437 --- a/drivers/ata/pata_ns87415.c
28438 +++ b/drivers/ata/pata_ns87415.c
28439 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct ata_port *ap)
28440 }
28441 #endif /* 87560 SuperIO Support */
28442
28443 -static struct ata_port_operations ns87415_pata_ops = {
28444 +static const struct ata_port_operations ns87415_pata_ops = {
28445 .inherits = &ata_bmdma_port_ops,
28446
28447 .check_atapi_dma = ns87415_check_atapi_dma,
28448 @@ -313,7 +313,7 @@ static struct ata_port_operations ns87415_pata_ops = {
28449 };
28450
28451 #if defined(CONFIG_SUPERIO)
28452 -static struct ata_port_operations ns87560_pata_ops = {
28453 +static const struct ata_port_operations ns87560_pata_ops = {
28454 .inherits = &ns87415_pata_ops,
28455 .sff_tf_read = ns87560_tf_read,
28456 .sff_check_status = ns87560_check_status,
28457 diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
28458 index d6f6956..639295b 100644
28459 --- a/drivers/ata/pata_octeon_cf.c
28460 +++ b/drivers/ata/pata_octeon_cf.c
28461 @@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(struct ata_queued_cmd *qc)
28462 return 0;
28463 }
28464
28465 +/* cannot be const */
28466 static struct ata_port_operations octeon_cf_ops = {
28467 .inherits = &ata_sff_port_ops,
28468 .check_atapi_dma = octeon_cf_check_atapi_dma,
28469 diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
28470 index 84ac503..adee1cd 100644
28471 --- a/drivers/ata/pata_oldpiix.c
28472 +++ b/drivers/ata/pata_oldpiix.c
28473 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix_sht = {
28474 ATA_BMDMA_SHT(DRV_NAME),
28475 };
28476
28477 -static struct ata_port_operations oldpiix_pata_ops = {
28478 +static const struct ata_port_operations oldpiix_pata_ops = {
28479 .inherits = &ata_bmdma_port_ops,
28480 .qc_issue = oldpiix_qc_issue,
28481 .cable_detect = ata_cable_40wire,
28482 diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
28483 index 99eddda..3a4c0aa 100644
28484 --- a/drivers/ata/pata_opti.c
28485 +++ b/drivers/ata/pata_opti.c
28486 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sht = {
28487 ATA_PIO_SHT(DRV_NAME),
28488 };
28489
28490 -static struct ata_port_operations opti_port_ops = {
28491 +static const struct ata_port_operations opti_port_ops = {
28492 .inherits = &ata_sff_port_ops,
28493 .cable_detect = ata_cable_40wire,
28494 .set_piomode = opti_set_piomode,
28495 diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
28496 index 86885a4..8e9968d 100644
28497 --- a/drivers/ata/pata_optidma.c
28498 +++ b/drivers/ata/pata_optidma.c
28499 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma_sht = {
28500 ATA_BMDMA_SHT(DRV_NAME),
28501 };
28502
28503 -static struct ata_port_operations optidma_port_ops = {
28504 +static const struct ata_port_operations optidma_port_ops = {
28505 .inherits = &ata_bmdma_port_ops,
28506 .cable_detect = ata_cable_40wire,
28507 .set_piomode = optidma_set_pio_mode,
28508 @@ -346,7 +346,7 @@ static struct ata_port_operations optidma_port_ops = {
28509 .prereset = optidma_pre_reset,
28510 };
28511
28512 -static struct ata_port_operations optiplus_port_ops = {
28513 +static const struct ata_port_operations optiplus_port_ops = {
28514 .inherits = &optidma_port_ops,
28515 .set_piomode = optiplus_set_pio_mode,
28516 .set_dmamode = optiplus_set_dma_mode,
28517 diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c
28518 index 11fb4cc..1a14022 100644
28519 --- a/drivers/ata/pata_palmld.c
28520 +++ b/drivers/ata/pata_palmld.c
28521 @@ -37,7 +37,7 @@ static struct scsi_host_template palmld_sht = {
28522 ATA_PIO_SHT(DRV_NAME),
28523 };
28524
28525 -static struct ata_port_operations palmld_port_ops = {
28526 +static const struct ata_port_operations palmld_port_ops = {
28527 .inherits = &ata_sff_port_ops,
28528 .sff_data_xfer = ata_sff_data_xfer_noirq,
28529 .cable_detect = ata_cable_40wire,
28530 diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
28531 index dc99e26..7f4b1e4 100644
28532 --- a/drivers/ata/pata_pcmcia.c
28533 +++ b/drivers/ata/pata_pcmcia.c
28534 @@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_sht = {
28535 ATA_PIO_SHT(DRV_NAME),
28536 };
28537
28538 -static struct ata_port_operations pcmcia_port_ops = {
28539 +static const struct ata_port_operations pcmcia_port_ops = {
28540 .inherits = &ata_sff_port_ops,
28541 .sff_data_xfer = ata_sff_data_xfer_noirq,
28542 .cable_detect = ata_cable_40wire,
28543 .set_mode = pcmcia_set_mode,
28544 };
28545
28546 -static struct ata_port_operations pcmcia_8bit_port_ops = {
28547 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
28548 .inherits = &ata_sff_port_ops,
28549 .sff_data_xfer = ata_data_xfer_8bit,
28550 .cable_detect = ata_cable_40wire,
28551 @@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
28552 unsigned long io_base, ctl_base;
28553 void __iomem *io_addr, *ctl_addr;
28554 int n_ports = 1;
28555 - struct ata_port_operations *ops = &pcmcia_port_ops;
28556 + const struct ata_port_operations *ops = &pcmcia_port_ops;
28557
28558 info = kzalloc(sizeof(*info), GFP_KERNEL);
28559 if (info == NULL)
28560 diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
28561 index ca5cad0..3a1f125 100644
28562 --- a/drivers/ata/pata_pdc2027x.c
28563 +++ b/drivers/ata/pata_pdc2027x.c
28564 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027x_sht = {
28565 ATA_BMDMA_SHT(DRV_NAME),
28566 };
28567
28568 -static struct ata_port_operations pdc2027x_pata100_ops = {
28569 +static const struct ata_port_operations pdc2027x_pata100_ops = {
28570 .inherits = &ata_bmdma_port_ops,
28571 .check_atapi_dma = pdc2027x_check_atapi_dma,
28572 .cable_detect = pdc2027x_cable_detect,
28573 .prereset = pdc2027x_prereset,
28574 };
28575
28576 -static struct ata_port_operations pdc2027x_pata133_ops = {
28577 +static const struct ata_port_operations pdc2027x_pata133_ops = {
28578 .inherits = &pdc2027x_pata100_ops,
28579 .mode_filter = pdc2027x_mode_filter,
28580 .set_piomode = pdc2027x_set_piomode,
28581 diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
28582 index 2911120..4bf62aa 100644
28583 --- a/drivers/ata/pata_pdc202xx_old.c
28584 +++ b/drivers/ata/pata_pdc202xx_old.c
28585 @@ -274,7 +274,7 @@ static struct scsi_host_template pdc202xx_sht = {
28586 ATA_BMDMA_SHT(DRV_NAME),
28587 };
28588
28589 -static struct ata_port_operations pdc2024x_port_ops = {
28590 +static const struct ata_port_operations pdc2024x_port_ops = {
28591 .inherits = &ata_bmdma_port_ops,
28592
28593 .cable_detect = ata_cable_40wire,
28594 @@ -284,7 +284,7 @@ static struct ata_port_operations pdc2024x_port_ops = {
28595 .sff_exec_command = pdc202xx_exec_command,
28596 };
28597
28598 -static struct ata_port_operations pdc2026x_port_ops = {
28599 +static const struct ata_port_operations pdc2026x_port_ops = {
28600 .inherits = &pdc2024x_port_ops,
28601
28602 .check_atapi_dma = pdc2026x_check_atapi_dma,
28603 diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
28604 index 3f6ebc6..a18c358 100644
28605 --- a/drivers/ata/pata_platform.c
28606 +++ b/drivers/ata/pata_platform.c
28607 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_platform_sht = {
28608 ATA_PIO_SHT(DRV_NAME),
28609 };
28610
28611 -static struct ata_port_operations pata_platform_port_ops = {
28612 +static const struct ata_port_operations pata_platform_port_ops = {
28613 .inherits = &ata_sff_port_ops,
28614 .sff_data_xfer = ata_sff_data_xfer_noirq,
28615 .cable_detect = ata_cable_unknown,
28616 diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
28617 index 45879dc..165a9f9 100644
28618 --- a/drivers/ata/pata_qdi.c
28619 +++ b/drivers/ata/pata_qdi.c
28620 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht = {
28621 ATA_PIO_SHT(DRV_NAME),
28622 };
28623
28624 -static struct ata_port_operations qdi6500_port_ops = {
28625 +static const struct ata_port_operations qdi6500_port_ops = {
28626 .inherits = &ata_sff_port_ops,
28627 .qc_issue = qdi_qc_issue,
28628 .sff_data_xfer = qdi_data_xfer,
28629 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi6500_port_ops = {
28630 .set_piomode = qdi6500_set_piomode,
28631 };
28632
28633 -static struct ata_port_operations qdi6580_port_ops = {
28634 +static const struct ata_port_operations qdi6580_port_ops = {
28635 .inherits = &qdi6500_port_ops,
28636 .set_piomode = qdi6580_set_piomode,
28637 };
28638 diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
28639 index 4401b33..716c5cc 100644
28640 --- a/drivers/ata/pata_radisys.c
28641 +++ b/drivers/ata/pata_radisys.c
28642 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys_sht = {
28643 ATA_BMDMA_SHT(DRV_NAME),
28644 };
28645
28646 -static struct ata_port_operations radisys_pata_ops = {
28647 +static const struct ata_port_operations radisys_pata_ops = {
28648 .inherits = &ata_bmdma_port_ops,
28649 .qc_issue = radisys_qc_issue,
28650 .cable_detect = ata_cable_unknown,
28651 diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
28652 index 45f1e10..fab6bca 100644
28653 --- a/drivers/ata/pata_rb532_cf.c
28654 +++ b/drivers/ata/pata_rb532_cf.c
28655 @@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
28656 return IRQ_HANDLED;
28657 }
28658
28659 -static struct ata_port_operations rb532_pata_port_ops = {
28660 +static const struct ata_port_operations rb532_pata_port_ops = {
28661 .inherits = &ata_sff_port_ops,
28662 .sff_data_xfer = ata_sff_data_xfer32,
28663 };
28664 diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c
28665 index c843a1e..b5853c3 100644
28666 --- a/drivers/ata/pata_rdc.c
28667 +++ b/drivers/ata/pata_rdc.c
28668 @@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
28669 pci_write_config_byte(dev, 0x48, udma_enable);
28670 }
28671
28672 -static struct ata_port_operations rdc_pata_ops = {
28673 +static const struct ata_port_operations rdc_pata_ops = {
28674 .inherits = &ata_bmdma32_port_ops,
28675 .cable_detect = rdc_pata_cable_detect,
28676 .set_piomode = rdc_set_piomode,
28677 diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
28678 index a5e4dfe..080c8c9 100644
28679 --- a/drivers/ata/pata_rz1000.c
28680 +++ b/drivers/ata/pata_rz1000.c
28681 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_sht = {
28682 ATA_PIO_SHT(DRV_NAME),
28683 };
28684
28685 -static struct ata_port_operations rz1000_port_ops = {
28686 +static const struct ata_port_operations rz1000_port_ops = {
28687 .inherits = &ata_sff_port_ops,
28688 .cable_detect = ata_cable_40wire,
28689 .set_mode = rz1000_set_mode,
28690 diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
28691 index 3bbed83..e309daf 100644
28692 --- a/drivers/ata/pata_sc1200.c
28693 +++ b/drivers/ata/pata_sc1200.c
28694 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_sht = {
28695 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28696 };
28697
28698 -static struct ata_port_operations sc1200_port_ops = {
28699 +static const struct ata_port_operations sc1200_port_ops = {
28700 .inherits = &ata_bmdma_port_ops,
28701 .qc_prep = ata_sff_dumb_qc_prep,
28702 .qc_issue = sc1200_qc_issue,
28703 diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
28704 index 4257d6b..4c1d9d5 100644
28705 --- a/drivers/ata/pata_scc.c
28706 +++ b/drivers/ata/pata_scc.c
28707 @@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht = {
28708 ATA_BMDMA_SHT(DRV_NAME),
28709 };
28710
28711 -static struct ata_port_operations scc_pata_ops = {
28712 +static const struct ata_port_operations scc_pata_ops = {
28713 .inherits = &ata_bmdma_port_ops,
28714
28715 .set_piomode = scc_set_piomode,
28716 diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
28717 index 99cceb4..e2e0a87 100644
28718 --- a/drivers/ata/pata_sch.c
28719 +++ b/drivers/ata/pata_sch.c
28720 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht = {
28721 ATA_BMDMA_SHT(DRV_NAME),
28722 };
28723
28724 -static struct ata_port_operations sch_pata_ops = {
28725 +static const struct ata_port_operations sch_pata_ops = {
28726 .inherits = &ata_bmdma_port_ops,
28727 .cable_detect = ata_cable_unknown,
28728 .set_piomode = sch_set_piomode,
28729 diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
28730 index beaed12..39969f1 100644
28731 --- a/drivers/ata/pata_serverworks.c
28732 +++ b/drivers/ata/pata_serverworks.c
28733 @@ -299,7 +299,7 @@ static struct scsi_host_template serverworks_sht = {
28734 ATA_BMDMA_SHT(DRV_NAME),
28735 };
28736
28737 -static struct ata_port_operations serverworks_osb4_port_ops = {
28738 +static const struct ata_port_operations serverworks_osb4_port_ops = {
28739 .inherits = &ata_bmdma_port_ops,
28740 .cable_detect = serverworks_cable_detect,
28741 .mode_filter = serverworks_osb4_filter,
28742 @@ -307,7 +307,7 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
28743 .set_dmamode = serverworks_set_dmamode,
28744 };
28745
28746 -static struct ata_port_operations serverworks_csb_port_ops = {
28747 +static const struct ata_port_operations serverworks_csb_port_ops = {
28748 .inherits = &serverworks_osb4_port_ops,
28749 .mode_filter = serverworks_csb_filter,
28750 };
28751 diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
28752 index a2ace48..0463b44 100644
28753 --- a/drivers/ata/pata_sil680.c
28754 +++ b/drivers/ata/pata_sil680.c
28755 @@ -194,7 +194,7 @@ static struct scsi_host_template sil680_sht = {
28756 ATA_BMDMA_SHT(DRV_NAME),
28757 };
28758
28759 -static struct ata_port_operations sil680_port_ops = {
28760 +static const struct ata_port_operations sil680_port_ops = {
28761 .inherits = &ata_bmdma32_port_ops,
28762 .cable_detect = sil680_cable_detect,
28763 .set_piomode = sil680_set_piomode,
28764 diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
28765 index 488e77b..b3724d5 100644
28766 --- a/drivers/ata/pata_sis.c
28767 +++ b/drivers/ata/pata_sis.c
28768 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht = {
28769 ATA_BMDMA_SHT(DRV_NAME),
28770 };
28771
28772 -static struct ata_port_operations sis_133_for_sata_ops = {
28773 +static const struct ata_port_operations sis_133_for_sata_ops = {
28774 .inherits = &ata_bmdma_port_ops,
28775 .set_piomode = sis_133_set_piomode,
28776 .set_dmamode = sis_133_set_dmamode,
28777 .cable_detect = sis_133_cable_detect,
28778 };
28779
28780 -static struct ata_port_operations sis_base_ops = {
28781 +static const struct ata_port_operations sis_base_ops = {
28782 .inherits = &ata_bmdma_port_ops,
28783 .prereset = sis_pre_reset,
28784 };
28785
28786 -static struct ata_port_operations sis_133_ops = {
28787 +static const struct ata_port_operations sis_133_ops = {
28788 .inherits = &sis_base_ops,
28789 .set_piomode = sis_133_set_piomode,
28790 .set_dmamode = sis_133_set_dmamode,
28791 .cable_detect = sis_133_cable_detect,
28792 };
28793
28794 -static struct ata_port_operations sis_133_early_ops = {
28795 +static const struct ata_port_operations sis_133_early_ops = {
28796 .inherits = &sis_base_ops,
28797 .set_piomode = sis_100_set_piomode,
28798 .set_dmamode = sis_133_early_set_dmamode,
28799 .cable_detect = sis_66_cable_detect,
28800 };
28801
28802 -static struct ata_port_operations sis_100_ops = {
28803 +static const struct ata_port_operations sis_100_ops = {
28804 .inherits = &sis_base_ops,
28805 .set_piomode = sis_100_set_piomode,
28806 .set_dmamode = sis_100_set_dmamode,
28807 .cable_detect = sis_66_cable_detect,
28808 };
28809
28810 -static struct ata_port_operations sis_66_ops = {
28811 +static const struct ata_port_operations sis_66_ops = {
28812 .inherits = &sis_base_ops,
28813 .set_piomode = sis_old_set_piomode,
28814 .set_dmamode = sis_66_set_dmamode,
28815 .cable_detect = sis_66_cable_detect,
28816 };
28817
28818 -static struct ata_port_operations sis_old_ops = {
28819 +static const struct ata_port_operations sis_old_ops = {
28820 .inherits = &sis_base_ops,
28821 .set_piomode = sis_old_set_piomode,
28822 .set_dmamode = sis_old_set_dmamode,
28823 diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
28824 index 29f733c..43e9ca0 100644
28825 --- a/drivers/ata/pata_sl82c105.c
28826 +++ b/drivers/ata/pata_sl82c105.c
28827 @@ -231,7 +231,7 @@ static struct scsi_host_template sl82c105_sht = {
28828 ATA_BMDMA_SHT(DRV_NAME),
28829 };
28830
28831 -static struct ata_port_operations sl82c105_port_ops = {
28832 +static const struct ata_port_operations sl82c105_port_ops = {
28833 .inherits = &ata_bmdma_port_ops,
28834 .qc_defer = sl82c105_qc_defer,
28835 .bmdma_start = sl82c105_bmdma_start,
28836 diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
28837 index f1f13ff..df39e99 100644
28838 --- a/drivers/ata/pata_triflex.c
28839 +++ b/drivers/ata/pata_triflex.c
28840 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex_sht = {
28841 ATA_BMDMA_SHT(DRV_NAME),
28842 };
28843
28844 -static struct ata_port_operations triflex_port_ops = {
28845 +static const struct ata_port_operations triflex_port_ops = {
28846 .inherits = &ata_bmdma_port_ops,
28847 .bmdma_start = triflex_bmdma_start,
28848 .bmdma_stop = triflex_bmdma_stop,
28849 diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
28850 index 1d73b8d..98a4b29 100644
28851 --- a/drivers/ata/pata_via.c
28852 +++ b/drivers/ata/pata_via.c
28853 @@ -419,7 +419,7 @@ static struct scsi_host_template via_sht = {
28854 ATA_BMDMA_SHT(DRV_NAME),
28855 };
28856
28857 -static struct ata_port_operations via_port_ops = {
28858 +static const struct ata_port_operations via_port_ops = {
28859 .inherits = &ata_bmdma_port_ops,
28860 .cable_detect = via_cable_detect,
28861 .set_piomode = via_set_piomode,
28862 @@ -429,7 +429,7 @@ static struct ata_port_operations via_port_ops = {
28863 .port_start = via_port_start,
28864 };
28865
28866 -static struct ata_port_operations via_port_ops_noirq = {
28867 +static const struct ata_port_operations via_port_ops_noirq = {
28868 .inherits = &via_port_ops,
28869 .sff_data_xfer = ata_sff_data_xfer_noirq,
28870 };
28871 diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
28872 index 6d8619b..ad511c4 100644
28873 --- a/drivers/ata/pata_winbond.c
28874 +++ b/drivers/ata/pata_winbond.c
28875 @@ -125,7 +125,7 @@ static struct scsi_host_template winbond_sht = {
28876 ATA_PIO_SHT(DRV_NAME),
28877 };
28878
28879 -static struct ata_port_operations winbond_port_ops = {
28880 +static const struct ata_port_operations winbond_port_ops = {
28881 .inherits = &ata_sff_port_ops,
28882 .sff_data_xfer = winbond_data_xfer,
28883 .cable_detect = ata_cable_40wire,
28884 diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
28885 index 6c65b07..f996ec7 100644
28886 --- a/drivers/ata/pdc_adma.c
28887 +++ b/drivers/ata/pdc_adma.c
28888 @@ -145,7 +145,7 @@ static struct scsi_host_template adma_ata_sht = {
28889 .dma_boundary = ADMA_DMA_BOUNDARY,
28890 };
28891
28892 -static struct ata_port_operations adma_ata_ops = {
28893 +static const struct ata_port_operations adma_ata_ops = {
28894 .inherits = &ata_sff_port_ops,
28895
28896 .lost_interrupt = ATA_OP_NULL,
28897 diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
28898 index 172b57e..c49bc1e 100644
28899 --- a/drivers/ata/sata_fsl.c
28900 +++ b/drivers/ata/sata_fsl.c
28901 @@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fsl_sht = {
28902 .dma_boundary = ATA_DMA_BOUNDARY,
28903 };
28904
28905 -static struct ata_port_operations sata_fsl_ops = {
28906 +static const struct ata_port_operations sata_fsl_ops = {
28907 .inherits = &sata_pmp_port_ops,
28908
28909 .qc_defer = ata_std_qc_defer,
28910 diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
28911 index 4406902..60603ef 100644
28912 --- a/drivers/ata/sata_inic162x.c
28913 +++ b/drivers/ata/sata_inic162x.c
28914 @@ -721,7 +721,7 @@ static int inic_port_start(struct ata_port *ap)
28915 return 0;
28916 }
28917
28918 -static struct ata_port_operations inic_port_ops = {
28919 +static const struct ata_port_operations inic_port_ops = {
28920 .inherits = &sata_port_ops,
28921
28922 .check_atapi_dma = inic_check_atapi_dma,
28923 diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
28924 index cf41126..8107be6 100644
28925 --- a/drivers/ata/sata_mv.c
28926 +++ b/drivers/ata/sata_mv.c
28927 @@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht = {
28928 .dma_boundary = MV_DMA_BOUNDARY,
28929 };
28930
28931 -static struct ata_port_operations mv5_ops = {
28932 +static const struct ata_port_operations mv5_ops = {
28933 .inherits = &ata_sff_port_ops,
28934
28935 .lost_interrupt = ATA_OP_NULL,
28936 @@ -678,7 +678,7 @@ static struct ata_port_operations mv5_ops = {
28937 .port_stop = mv_port_stop,
28938 };
28939
28940 -static struct ata_port_operations mv6_ops = {
28941 +static const struct ata_port_operations mv6_ops = {
28942 .inherits = &mv5_ops,
28943 .dev_config = mv6_dev_config,
28944 .scr_read = mv_scr_read,
28945 @@ -698,7 +698,7 @@ static struct ata_port_operations mv6_ops = {
28946 .bmdma_status = mv_bmdma_status,
28947 };
28948
28949 -static struct ata_port_operations mv_iie_ops = {
28950 +static const struct ata_port_operations mv_iie_ops = {
28951 .inherits = &mv6_ops,
28952 .dev_config = ATA_OP_NULL,
28953 .qc_prep = mv_qc_prep_iie,
28954 diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
28955 index ae2297c..d5c9c33 100644
28956 --- a/drivers/ata/sata_nv.c
28957 +++ b/drivers/ata/sata_nv.c
28958 @@ -464,7 +464,7 @@ static struct scsi_host_template nv_swncq_sht = {
28959 * cases. Define nv_hardreset() which only kicks in for post-boot
28960 * probing and use it for all variants.
28961 */
28962 -static struct ata_port_operations nv_generic_ops = {
28963 +static const struct ata_port_operations nv_generic_ops = {
28964 .inherits = &ata_bmdma_port_ops,
28965 .lost_interrupt = ATA_OP_NULL,
28966 .scr_read = nv_scr_read,
28967 @@ -472,20 +472,20 @@ static struct ata_port_operations nv_generic_ops = {
28968 .hardreset = nv_hardreset,
28969 };
28970
28971 -static struct ata_port_operations nv_nf2_ops = {
28972 +static const struct ata_port_operations nv_nf2_ops = {
28973 .inherits = &nv_generic_ops,
28974 .freeze = nv_nf2_freeze,
28975 .thaw = nv_nf2_thaw,
28976 };
28977
28978 -static struct ata_port_operations nv_ck804_ops = {
28979 +static const struct ata_port_operations nv_ck804_ops = {
28980 .inherits = &nv_generic_ops,
28981 .freeze = nv_ck804_freeze,
28982 .thaw = nv_ck804_thaw,
28983 .host_stop = nv_ck804_host_stop,
28984 };
28985
28986 -static struct ata_port_operations nv_adma_ops = {
28987 +static const struct ata_port_operations nv_adma_ops = {
28988 .inherits = &nv_ck804_ops,
28989
28990 .check_atapi_dma = nv_adma_check_atapi_dma,
28991 @@ -509,7 +509,7 @@ static struct ata_port_operations nv_adma_ops = {
28992 .host_stop = nv_adma_host_stop,
28993 };
28994
28995 -static struct ata_port_operations nv_swncq_ops = {
28996 +static const struct ata_port_operations nv_swncq_ops = {
28997 .inherits = &nv_generic_ops,
28998
28999 .qc_defer = ata_std_qc_defer,
29000 diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
29001 index 07d8d00..6cc70bb 100644
29002 --- a/drivers/ata/sata_promise.c
29003 +++ b/drivers/ata/sata_promise.c
29004 @@ -195,7 +195,7 @@ static const struct ata_port_operations pdc_common_ops = {
29005 .error_handler = pdc_error_handler,
29006 };
29007
29008 -static struct ata_port_operations pdc_sata_ops = {
29009 +static const struct ata_port_operations pdc_sata_ops = {
29010 .inherits = &pdc_common_ops,
29011 .cable_detect = pdc_sata_cable_detect,
29012 .freeze = pdc_sata_freeze,
29013 @@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sata_ops = {
29014
29015 /* First-generation chips need a more restrictive ->check_atapi_dma op,
29016 and ->freeze/thaw that ignore the hotplug controls. */
29017 -static struct ata_port_operations pdc_old_sata_ops = {
29018 +static const struct ata_port_operations pdc_old_sata_ops = {
29019 .inherits = &pdc_sata_ops,
29020 .freeze = pdc_freeze,
29021 .thaw = pdc_thaw,
29022 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
29023 };
29024
29025 -static struct ata_port_operations pdc_pata_ops = {
29026 +static const struct ata_port_operations pdc_pata_ops = {
29027 .inherits = &pdc_common_ops,
29028 .cable_detect = pdc_pata_cable_detect,
29029 .freeze = pdc_freeze,
29030 diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
29031 index 326c0cf..36ecebe 100644
29032 --- a/drivers/ata/sata_qstor.c
29033 +++ b/drivers/ata/sata_qstor.c
29034 @@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_sht = {
29035 .dma_boundary = QS_DMA_BOUNDARY,
29036 };
29037
29038 -static struct ata_port_operations qs_ata_ops = {
29039 +static const struct ata_port_operations qs_ata_ops = {
29040 .inherits = &ata_sff_port_ops,
29041
29042 .check_atapi_dma = qs_check_atapi_dma,
29043 diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
29044 index 3cb69d5..0871d3c 100644
29045 --- a/drivers/ata/sata_sil.c
29046 +++ b/drivers/ata/sata_sil.c
29047 @@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht = {
29048 .sg_tablesize = ATA_MAX_PRD
29049 };
29050
29051 -static struct ata_port_operations sil_ops = {
29052 +static const struct ata_port_operations sil_ops = {
29053 .inherits = &ata_bmdma32_port_ops,
29054 .dev_config = sil_dev_config,
29055 .set_mode = sil_set_mode,
29056 diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
29057 index e6946fc..eddb794 100644
29058 --- a/drivers/ata/sata_sil24.c
29059 +++ b/drivers/ata/sata_sil24.c
29060 @@ -388,7 +388,7 @@ static struct scsi_host_template sil24_sht = {
29061 .dma_boundary = ATA_DMA_BOUNDARY,
29062 };
29063
29064 -static struct ata_port_operations sil24_ops = {
29065 +static const struct ata_port_operations sil24_ops = {
29066 .inherits = &sata_pmp_port_ops,
29067
29068 .qc_defer = sil24_qc_defer,
29069 diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
29070 index f8a91bf..9cb06b6 100644
29071 --- a/drivers/ata/sata_sis.c
29072 +++ b/drivers/ata/sata_sis.c
29073 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht = {
29074 ATA_BMDMA_SHT(DRV_NAME),
29075 };
29076
29077 -static struct ata_port_operations sis_ops = {
29078 +static const struct ata_port_operations sis_ops = {
29079 .inherits = &ata_bmdma_port_ops,
29080 .scr_read = sis_scr_read,
29081 .scr_write = sis_scr_write,
29082 diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
29083 index 7257f2d..d04c6f5 100644
29084 --- a/drivers/ata/sata_svw.c
29085 +++ b/drivers/ata/sata_svw.c
29086 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata_sht = {
29087 };
29088
29089
29090 -static struct ata_port_operations k2_sata_ops = {
29091 +static const struct ata_port_operations k2_sata_ops = {
29092 .inherits = &ata_bmdma_port_ops,
29093 .sff_tf_load = k2_sata_tf_load,
29094 .sff_tf_read = k2_sata_tf_read,
29095 diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
29096 index bbcf970..cd0df0d 100644
29097 --- a/drivers/ata/sata_sx4.c
29098 +++ b/drivers/ata/sata_sx4.c
29099 @@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sata_sht = {
29100 };
29101
29102 /* TODO: inherit from base port_ops after converting to new EH */
29103 -static struct ata_port_operations pdc_20621_ops = {
29104 +static const struct ata_port_operations pdc_20621_ops = {
29105 .inherits = &ata_sff_port_ops,
29106
29107 .check_atapi_dma = pdc_check_atapi_dma,
29108 diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
29109 index e5bff47..089d859 100644
29110 --- a/drivers/ata/sata_uli.c
29111 +++ b/drivers/ata/sata_uli.c
29112 @@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht = {
29113 ATA_BMDMA_SHT(DRV_NAME),
29114 };
29115
29116 -static struct ata_port_operations uli_ops = {
29117 +static const struct ata_port_operations uli_ops = {
29118 .inherits = &ata_bmdma_port_ops,
29119 .scr_read = uli_scr_read,
29120 .scr_write = uli_scr_write,
29121 diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
29122 index f5dcca7..77b94eb 100644
29123 --- a/drivers/ata/sata_via.c
29124 +++ b/drivers/ata/sata_via.c
29125 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sht = {
29126 ATA_BMDMA_SHT(DRV_NAME),
29127 };
29128
29129 -static struct ata_port_operations svia_base_ops = {
29130 +static const struct ata_port_operations svia_base_ops = {
29131 .inherits = &ata_bmdma_port_ops,
29132 .sff_tf_load = svia_tf_load,
29133 };
29134
29135 -static struct ata_port_operations vt6420_sata_ops = {
29136 +static const struct ata_port_operations vt6420_sata_ops = {
29137 .inherits = &svia_base_ops,
29138 .freeze = svia_noop_freeze,
29139 .prereset = vt6420_prereset,
29140 .bmdma_start = vt6420_bmdma_start,
29141 };
29142
29143 -static struct ata_port_operations vt6421_pata_ops = {
29144 +static const struct ata_port_operations vt6421_pata_ops = {
29145 .inherits = &svia_base_ops,
29146 .cable_detect = vt6421_pata_cable_detect,
29147 .set_piomode = vt6421_set_pio_mode,
29148 .set_dmamode = vt6421_set_dma_mode,
29149 };
29150
29151 -static struct ata_port_operations vt6421_sata_ops = {
29152 +static const struct ata_port_operations vt6421_sata_ops = {
29153 .inherits = &svia_base_ops,
29154 .scr_read = svia_scr_read,
29155 .scr_write = svia_scr_write,
29156 };
29157
29158 -static struct ata_port_operations vt8251_ops = {
29159 +static const struct ata_port_operations vt8251_ops = {
29160 .inherits = &svia_base_ops,
29161 .hardreset = sata_std_hardreset,
29162 .scr_read = vt8251_scr_read,
29163 diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
29164 index 8b2a278..51e65d3 100644
29165 --- a/drivers/ata/sata_vsc.c
29166 +++ b/drivers/ata/sata_vsc.c
29167 @@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sata_sht = {
29168 };
29169
29170
29171 -static struct ata_port_operations vsc_sata_ops = {
29172 +static const struct ata_port_operations vsc_sata_ops = {
29173 .inherits = &ata_bmdma_port_ops,
29174 /* The IRQ handling is not quite standard SFF behaviour so we
29175 cannot use the default lost interrupt handler */
29176 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29177 index 5effec6..7e4019a 100644
29178 --- a/drivers/atm/adummy.c
29179 +++ b/drivers/atm/adummy.c
29180 @@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29181 vcc->pop(vcc, skb);
29182 else
29183 dev_kfree_skb_any(skb);
29184 - atomic_inc(&vcc->stats->tx);
29185 + atomic_inc_unchecked(&vcc->stats->tx);
29186
29187 return 0;
29188 }
29189 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29190 index 66e1813..26a27c6 100644
29191 --- a/drivers/atm/ambassador.c
29192 +++ b/drivers/atm/ambassador.c
29193 @@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29194 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29195
29196 // VC layer stats
29197 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29198 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29199
29200 // free the descriptor
29201 kfree (tx_descr);
29202 @@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29203 dump_skb ("<<<", vc, skb);
29204
29205 // VC layer stats
29206 - atomic_inc(&atm_vcc->stats->rx);
29207 + atomic_inc_unchecked(&atm_vcc->stats->rx);
29208 __net_timestamp(skb);
29209 // end of our responsability
29210 atm_vcc->push (atm_vcc, skb);
29211 @@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29212 } else {
29213 PRINTK (KERN_INFO, "dropped over-size frame");
29214 // should we count this?
29215 - atomic_inc(&atm_vcc->stats->rx_drop);
29216 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29217 }
29218
29219 } else {
29220 @@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29221 }
29222
29223 if (check_area (skb->data, skb->len)) {
29224 - atomic_inc(&atm_vcc->stats->tx_err);
29225 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29226 return -ENOMEM; // ?
29227 }
29228
29229 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29230 index 02ad83d..6daffeb 100644
29231 --- a/drivers/atm/atmtcp.c
29232 +++ b/drivers/atm/atmtcp.c
29233 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29234 if (vcc->pop) vcc->pop(vcc,skb);
29235 else dev_kfree_skb(skb);
29236 if (dev_data) return 0;
29237 - atomic_inc(&vcc->stats->tx_err);
29238 + atomic_inc_unchecked(&vcc->stats->tx_err);
29239 return -ENOLINK;
29240 }
29241 size = skb->len+sizeof(struct atmtcp_hdr);
29242 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29243 if (!new_skb) {
29244 if (vcc->pop) vcc->pop(vcc,skb);
29245 else dev_kfree_skb(skb);
29246 - atomic_inc(&vcc->stats->tx_err);
29247 + atomic_inc_unchecked(&vcc->stats->tx_err);
29248 return -ENOBUFS;
29249 }
29250 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29251 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29252 if (vcc->pop) vcc->pop(vcc,skb);
29253 else dev_kfree_skb(skb);
29254 out_vcc->push(out_vcc,new_skb);
29255 - atomic_inc(&vcc->stats->tx);
29256 - atomic_inc(&out_vcc->stats->rx);
29257 + atomic_inc_unchecked(&vcc->stats->tx);
29258 + atomic_inc_unchecked(&out_vcc->stats->rx);
29259 return 0;
29260 }
29261
29262 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29263 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29264 read_unlock(&vcc_sklist_lock);
29265 if (!out_vcc) {
29266 - atomic_inc(&vcc->stats->tx_err);
29267 + atomic_inc_unchecked(&vcc->stats->tx_err);
29268 goto done;
29269 }
29270 skb_pull(skb,sizeof(struct atmtcp_hdr));
29271 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29272 __net_timestamp(new_skb);
29273 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29274 out_vcc->push(out_vcc,new_skb);
29275 - atomic_inc(&vcc->stats->tx);
29276 - atomic_inc(&out_vcc->stats->rx);
29277 + atomic_inc_unchecked(&vcc->stats->tx);
29278 + atomic_inc_unchecked(&out_vcc->stats->rx);
29279 done:
29280 if (vcc->pop) vcc->pop(vcc,skb);
29281 else dev_kfree_skb(skb);
29282 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29283 index 0c30261..3da356e 100644
29284 --- a/drivers/atm/eni.c
29285 +++ b/drivers/atm/eni.c
29286 @@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29287 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29288 vcc->dev->number);
29289 length = 0;
29290 - atomic_inc(&vcc->stats->rx_err);
29291 + atomic_inc_unchecked(&vcc->stats->rx_err);
29292 }
29293 else {
29294 length = ATM_CELL_SIZE-1; /* no HEC */
29295 @@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29296 size);
29297 }
29298 eff = length = 0;
29299 - atomic_inc(&vcc->stats->rx_err);
29300 + atomic_inc_unchecked(&vcc->stats->rx_err);
29301 }
29302 else {
29303 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29304 @@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29305 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29306 vcc->dev->number,vcc->vci,length,size << 2,descr);
29307 length = eff = 0;
29308 - atomic_inc(&vcc->stats->rx_err);
29309 + atomic_inc_unchecked(&vcc->stats->rx_err);
29310 }
29311 }
29312 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29313 @@ -770,7 +770,7 @@ rx_dequeued++;
29314 vcc->push(vcc,skb);
29315 pushed++;
29316 }
29317 - atomic_inc(&vcc->stats->rx);
29318 + atomic_inc_unchecked(&vcc->stats->rx);
29319 }
29320 wake_up(&eni_dev->rx_wait);
29321 }
29322 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29323 PCI_DMA_TODEVICE);
29324 if (vcc->pop) vcc->pop(vcc,skb);
29325 else dev_kfree_skb_irq(skb);
29326 - atomic_inc(&vcc->stats->tx);
29327 + atomic_inc_unchecked(&vcc->stats->tx);
29328 wake_up(&eni_dev->tx_wait);
29329 dma_complete++;
29330 }
29331 @@ -1570,7 +1570,7 @@ tx_complete++;
29332 /*--------------------------------- entries ---------------------------------*/
29333
29334
29335 -static const char *media_name[] __devinitdata = {
29336 +static const char *media_name[] __devinitconst = {
29337 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
29338 "UTP", "05?", "06?", "07?", /* 4- 7 */
29339 "TAXI","09?", "10?", "11?", /* 8-11 */
29340 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29341 index cd5049a..a51209f 100644
29342 --- a/drivers/atm/firestream.c
29343 +++ b/drivers/atm/firestream.c
29344 @@ -748,7 +748,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29345 }
29346 }
29347
29348 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29349 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29350
29351 fs_dprintk (FS_DEBUG_TXMEM, "i");
29352 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29353 @@ -815,7 +815,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29354 #endif
29355 skb_put (skb, qe->p1 & 0xffff);
29356 ATM_SKB(skb)->vcc = atm_vcc;
29357 - atomic_inc(&atm_vcc->stats->rx);
29358 + atomic_inc_unchecked(&atm_vcc->stats->rx);
29359 __net_timestamp(skb);
29360 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29361 atm_vcc->push (atm_vcc, skb);
29362 @@ -836,12 +836,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29363 kfree (pe);
29364 }
29365 if (atm_vcc)
29366 - atomic_inc(&atm_vcc->stats->rx_drop);
29367 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29368 break;
29369 case 0x1f: /* Reassembly abort: no buffers. */
29370 /* Silently increment error counter. */
29371 if (atm_vcc)
29372 - atomic_inc(&atm_vcc->stats->rx_drop);
29373 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29374 break;
29375 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29376 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29377 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29378 index f766cc4..a34002e 100644
29379 --- a/drivers/atm/fore200e.c
29380 +++ b/drivers/atm/fore200e.c
29381 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29382 #endif
29383 /* check error condition */
29384 if (*entry->status & STATUS_ERROR)
29385 - atomic_inc(&vcc->stats->tx_err);
29386 + atomic_inc_unchecked(&vcc->stats->tx_err);
29387 else
29388 - atomic_inc(&vcc->stats->tx);
29389 + atomic_inc_unchecked(&vcc->stats->tx);
29390 }
29391 }
29392
29393 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29394 if (skb == NULL) {
29395 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29396
29397 - atomic_inc(&vcc->stats->rx_drop);
29398 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29399 return -ENOMEM;
29400 }
29401
29402 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29403
29404 dev_kfree_skb_any(skb);
29405
29406 - atomic_inc(&vcc->stats->rx_drop);
29407 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29408 return -ENOMEM;
29409 }
29410
29411 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29412
29413 vcc->push(vcc, skb);
29414 - atomic_inc(&vcc->stats->rx);
29415 + atomic_inc_unchecked(&vcc->stats->rx);
29416
29417 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29418
29419 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29420 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29421 fore200e->atm_dev->number,
29422 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29423 - atomic_inc(&vcc->stats->rx_err);
29424 + atomic_inc_unchecked(&vcc->stats->rx_err);
29425 }
29426 }
29427
29428 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29429 goto retry_here;
29430 }
29431
29432 - atomic_inc(&vcc->stats->tx_err);
29433 + atomic_inc_unchecked(&vcc->stats->tx_err);
29434
29435 fore200e->tx_sat++;
29436 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29437 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29438 index 7066703..2b130de 100644
29439 --- a/drivers/atm/he.c
29440 +++ b/drivers/atm/he.c
29441 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29442
29443 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29444 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29445 - atomic_inc(&vcc->stats->rx_drop);
29446 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29447 goto return_host_buffers;
29448 }
29449
29450 @@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29451 RBRQ_LEN_ERR(he_dev->rbrq_head)
29452 ? "LEN_ERR" : "",
29453 vcc->vpi, vcc->vci);
29454 - atomic_inc(&vcc->stats->rx_err);
29455 + atomic_inc_unchecked(&vcc->stats->rx_err);
29456 goto return_host_buffers;
29457 }
29458
29459 @@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29460 vcc->push(vcc, skb);
29461 spin_lock(&he_dev->global_lock);
29462
29463 - atomic_inc(&vcc->stats->rx);
29464 + atomic_inc_unchecked(&vcc->stats->rx);
29465
29466 return_host_buffers:
29467 ++pdus_assembled;
29468 @@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
29469 tpd->vcc->pop(tpd->vcc, tpd->skb);
29470 else
29471 dev_kfree_skb_any(tpd->skb);
29472 - atomic_inc(&tpd->vcc->stats->tx_err);
29473 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
29474 }
29475 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
29476 return;
29477 @@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29478 vcc->pop(vcc, skb);
29479 else
29480 dev_kfree_skb_any(skb);
29481 - atomic_inc(&vcc->stats->tx_err);
29482 + atomic_inc_unchecked(&vcc->stats->tx_err);
29483 return -EINVAL;
29484 }
29485
29486 @@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29487 vcc->pop(vcc, skb);
29488 else
29489 dev_kfree_skb_any(skb);
29490 - atomic_inc(&vcc->stats->tx_err);
29491 + atomic_inc_unchecked(&vcc->stats->tx_err);
29492 return -EINVAL;
29493 }
29494 #endif
29495 @@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29496 vcc->pop(vcc, skb);
29497 else
29498 dev_kfree_skb_any(skb);
29499 - atomic_inc(&vcc->stats->tx_err);
29500 + atomic_inc_unchecked(&vcc->stats->tx_err);
29501 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29502 return -ENOMEM;
29503 }
29504 @@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29505 vcc->pop(vcc, skb);
29506 else
29507 dev_kfree_skb_any(skb);
29508 - atomic_inc(&vcc->stats->tx_err);
29509 + atomic_inc_unchecked(&vcc->stats->tx_err);
29510 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29511 return -ENOMEM;
29512 }
29513 @@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29514 __enqueue_tpd(he_dev, tpd, cid);
29515 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29516
29517 - atomic_inc(&vcc->stats->tx);
29518 + atomic_inc_unchecked(&vcc->stats->tx);
29519
29520 return 0;
29521 }
29522 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
29523 index 4e49021..01b1512 100644
29524 --- a/drivers/atm/horizon.c
29525 +++ b/drivers/atm/horizon.c
29526 @@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
29527 {
29528 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
29529 // VC layer stats
29530 - atomic_inc(&vcc->stats->rx);
29531 + atomic_inc_unchecked(&vcc->stats->rx);
29532 __net_timestamp(skb);
29533 // end of our responsability
29534 vcc->push (vcc, skb);
29535 @@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
29536 dev->tx_iovec = NULL;
29537
29538 // VC layer stats
29539 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29540 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29541
29542 // free the skb
29543 hrz_kfree_skb (skb);
29544 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
29545 index e33ae00..9deb4ab 100644
29546 --- a/drivers/atm/idt77252.c
29547 +++ b/drivers/atm/idt77252.c
29548 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
29549 else
29550 dev_kfree_skb(skb);
29551
29552 - atomic_inc(&vcc->stats->tx);
29553 + atomic_inc_unchecked(&vcc->stats->tx);
29554 }
29555
29556 atomic_dec(&scq->used);
29557 @@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29558 if ((sb = dev_alloc_skb(64)) == NULL) {
29559 printk("%s: Can't allocate buffers for aal0.\n",
29560 card->name);
29561 - atomic_add(i, &vcc->stats->rx_drop);
29562 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
29563 break;
29564 }
29565 if (!atm_charge(vcc, sb->truesize)) {
29566 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
29567 card->name);
29568 - atomic_add(i - 1, &vcc->stats->rx_drop);
29569 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
29570 dev_kfree_skb(sb);
29571 break;
29572 }
29573 @@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29574 ATM_SKB(sb)->vcc = vcc;
29575 __net_timestamp(sb);
29576 vcc->push(vcc, sb);
29577 - atomic_inc(&vcc->stats->rx);
29578 + atomic_inc_unchecked(&vcc->stats->rx);
29579
29580 cell += ATM_CELL_PAYLOAD;
29581 }
29582 @@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29583 "(CDC: %08x)\n",
29584 card->name, len, rpp->len, readl(SAR_REG_CDC));
29585 recycle_rx_pool_skb(card, rpp);
29586 - atomic_inc(&vcc->stats->rx_err);
29587 + atomic_inc_unchecked(&vcc->stats->rx_err);
29588 return;
29589 }
29590 if (stat & SAR_RSQE_CRC) {
29591 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
29592 recycle_rx_pool_skb(card, rpp);
29593 - atomic_inc(&vcc->stats->rx_err);
29594 + atomic_inc_unchecked(&vcc->stats->rx_err);
29595 return;
29596 }
29597 if (skb_queue_len(&rpp->queue) > 1) {
29598 @@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29599 RXPRINTK("%s: Can't alloc RX skb.\n",
29600 card->name);
29601 recycle_rx_pool_skb(card, rpp);
29602 - atomic_inc(&vcc->stats->rx_err);
29603 + atomic_inc_unchecked(&vcc->stats->rx_err);
29604 return;
29605 }
29606 if (!atm_charge(vcc, skb->truesize)) {
29607 @@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29608 __net_timestamp(skb);
29609
29610 vcc->push(vcc, skb);
29611 - atomic_inc(&vcc->stats->rx);
29612 + atomic_inc_unchecked(&vcc->stats->rx);
29613
29614 return;
29615 }
29616 @@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29617 __net_timestamp(skb);
29618
29619 vcc->push(vcc, skb);
29620 - atomic_inc(&vcc->stats->rx);
29621 + atomic_inc_unchecked(&vcc->stats->rx);
29622
29623 if (skb->truesize > SAR_FB_SIZE_3)
29624 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
29625 @@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
29626 if (vcc->qos.aal != ATM_AAL0) {
29627 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
29628 card->name, vpi, vci);
29629 - atomic_inc(&vcc->stats->rx_drop);
29630 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29631 goto drop;
29632 }
29633
29634 if ((sb = dev_alloc_skb(64)) == NULL) {
29635 printk("%s: Can't allocate buffers for AAL0.\n",
29636 card->name);
29637 - atomic_inc(&vcc->stats->rx_err);
29638 + atomic_inc_unchecked(&vcc->stats->rx_err);
29639 goto drop;
29640 }
29641
29642 @@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
29643 ATM_SKB(sb)->vcc = vcc;
29644 __net_timestamp(sb);
29645 vcc->push(vcc, sb);
29646 - atomic_inc(&vcc->stats->rx);
29647 + atomic_inc_unchecked(&vcc->stats->rx);
29648
29649 drop:
29650 skb_pull(queue, 64);
29651 @@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29652
29653 if (vc == NULL) {
29654 printk("%s: NULL connection in send().\n", card->name);
29655 - atomic_inc(&vcc->stats->tx_err);
29656 + atomic_inc_unchecked(&vcc->stats->tx_err);
29657 dev_kfree_skb(skb);
29658 return -EINVAL;
29659 }
29660 if (!test_bit(VCF_TX, &vc->flags)) {
29661 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
29662 - atomic_inc(&vcc->stats->tx_err);
29663 + atomic_inc_unchecked(&vcc->stats->tx_err);
29664 dev_kfree_skb(skb);
29665 return -EINVAL;
29666 }
29667 @@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29668 break;
29669 default:
29670 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
29671 - atomic_inc(&vcc->stats->tx_err);
29672 + atomic_inc_unchecked(&vcc->stats->tx_err);
29673 dev_kfree_skb(skb);
29674 return -EINVAL;
29675 }
29676
29677 if (skb_shinfo(skb)->nr_frags != 0) {
29678 printk("%s: No scatter-gather yet.\n", card->name);
29679 - atomic_inc(&vcc->stats->tx_err);
29680 + atomic_inc_unchecked(&vcc->stats->tx_err);
29681 dev_kfree_skb(skb);
29682 return -EINVAL;
29683 }
29684 @@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29685
29686 err = queue_skb(card, vc, skb, oam);
29687 if (err) {
29688 - atomic_inc(&vcc->stats->tx_err);
29689 + atomic_inc_unchecked(&vcc->stats->tx_err);
29690 dev_kfree_skb(skb);
29691 return err;
29692 }
29693 @@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
29694 skb = dev_alloc_skb(64);
29695 if (!skb) {
29696 printk("%s: Out of memory in send_oam().\n", card->name);
29697 - atomic_inc(&vcc->stats->tx_err);
29698 + atomic_inc_unchecked(&vcc->stats->tx_err);
29699 return -ENOMEM;
29700 }
29701 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
29702 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
29703 index b2c1b37..faa672b 100644
29704 --- a/drivers/atm/iphase.c
29705 +++ b/drivers/atm/iphase.c
29706 @@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
29707 status = (u_short) (buf_desc_ptr->desc_mode);
29708 if (status & (RX_CER | RX_PTE | RX_OFL))
29709 {
29710 - atomic_inc(&vcc->stats->rx_err);
29711 + atomic_inc_unchecked(&vcc->stats->rx_err);
29712 IF_ERR(printk("IA: bad packet, dropping it");)
29713 if (status & RX_CER) {
29714 IF_ERR(printk(" cause: packet CRC error\n");)
29715 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
29716 len = dma_addr - buf_addr;
29717 if (len > iadev->rx_buf_sz) {
29718 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
29719 - atomic_inc(&vcc->stats->rx_err);
29720 + atomic_inc_unchecked(&vcc->stats->rx_err);
29721 goto out_free_desc;
29722 }
29723
29724 @@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29725 ia_vcc = INPH_IA_VCC(vcc);
29726 if (ia_vcc == NULL)
29727 {
29728 - atomic_inc(&vcc->stats->rx_err);
29729 + atomic_inc_unchecked(&vcc->stats->rx_err);
29730 dev_kfree_skb_any(skb);
29731 atm_return(vcc, atm_guess_pdu2truesize(len));
29732 goto INCR_DLE;
29733 @@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29734 if ((length > iadev->rx_buf_sz) || (length >
29735 (skb->len - sizeof(struct cpcs_trailer))))
29736 {
29737 - atomic_inc(&vcc->stats->rx_err);
29738 + atomic_inc_unchecked(&vcc->stats->rx_err);
29739 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
29740 length, skb->len);)
29741 dev_kfree_skb_any(skb);
29742 @@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29743
29744 IF_RX(printk("rx_dle_intr: skb push");)
29745 vcc->push(vcc,skb);
29746 - atomic_inc(&vcc->stats->rx);
29747 + atomic_inc_unchecked(&vcc->stats->rx);
29748 iadev->rx_pkt_cnt++;
29749 }
29750 INCR_DLE:
29751 @@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
29752 {
29753 struct k_sonet_stats *stats;
29754 stats = &PRIV(_ia_dev[board])->sonet_stats;
29755 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
29756 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
29757 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
29758 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
29759 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
29760 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
29761 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
29762 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
29763 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
29764 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
29765 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
29766 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
29767 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
29768 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
29769 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
29770 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
29771 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
29772 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
29773 }
29774 ia_cmds.status = 0;
29775 break;
29776 @@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29777 if ((desc == 0) || (desc > iadev->num_tx_desc))
29778 {
29779 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
29780 - atomic_inc(&vcc->stats->tx);
29781 + atomic_inc_unchecked(&vcc->stats->tx);
29782 if (vcc->pop)
29783 vcc->pop(vcc, skb);
29784 else
29785 @@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29786 ATM_DESC(skb) = vcc->vci;
29787 skb_queue_tail(&iadev->tx_dma_q, skb);
29788
29789 - atomic_inc(&vcc->stats->tx);
29790 + atomic_inc_unchecked(&vcc->stats->tx);
29791 iadev->tx_pkt_cnt++;
29792 /* Increment transaction counter */
29793 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29794
29795 #if 0
29796 /* add flow control logic */
29797 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29798 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29799 if (iavcc->vc_desc_cnt > 10) {
29800 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29801 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29802 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29803 index cf97c34..8d30655 100644
29804 --- a/drivers/atm/lanai.c
29805 +++ b/drivers/atm/lanai.c
29806 @@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29807 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29808 lanai_endtx(lanai, lvcc);
29809 lanai_free_skb(lvcc->tx.atmvcc, skb);
29810 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29811 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29812 }
29813
29814 /* Try to fill the buffer - don't call unless there is backlog */
29815 @@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29816 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29817 __net_timestamp(skb);
29818 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29819 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29820 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29821 out:
29822 lvcc->rx.buf.ptr = end;
29823 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29824 @@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29825 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29826 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29827 lanai->stats.service_rxnotaal5++;
29828 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29829 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29830 return 0;
29831 }
29832 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29833 @@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29834 int bytes;
29835 read_unlock(&vcc_sklist_lock);
29836 DPRINTK("got trashed rx pdu on vci %d\n", vci);
29837 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29838 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29839 lvcc->stats.x.aal5.service_trash++;
29840 bytes = (SERVICE_GET_END(s) * 16) -
29841 (((unsigned long) lvcc->rx.buf.ptr) -
29842 @@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29843 }
29844 if (s & SERVICE_STREAM) {
29845 read_unlock(&vcc_sklist_lock);
29846 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29847 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29848 lvcc->stats.x.aal5.service_stream++;
29849 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29850 "PDU on VCI %d!\n", lanai->number, vci);
29851 @@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29852 return 0;
29853 }
29854 DPRINTK("got rx crc error on vci %d\n", vci);
29855 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29856 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29857 lvcc->stats.x.aal5.service_rxcrc++;
29858 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29859 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29860 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29861 index 3da804b..d3b0eed 100644
29862 --- a/drivers/atm/nicstar.c
29863 +++ b/drivers/atm/nicstar.c
29864 @@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29865 if ((vc = (vc_map *) vcc->dev_data) == NULL)
29866 {
29867 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
29868 - atomic_inc(&vcc->stats->tx_err);
29869 + atomic_inc_unchecked(&vcc->stats->tx_err);
29870 dev_kfree_skb_any(skb);
29871 return -EINVAL;
29872 }
29873 @@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29874 if (!vc->tx)
29875 {
29876 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
29877 - atomic_inc(&vcc->stats->tx_err);
29878 + atomic_inc_unchecked(&vcc->stats->tx_err);
29879 dev_kfree_skb_any(skb);
29880 return -EINVAL;
29881 }
29882 @@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29883 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
29884 {
29885 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
29886 - atomic_inc(&vcc->stats->tx_err);
29887 + atomic_inc_unchecked(&vcc->stats->tx_err);
29888 dev_kfree_skb_any(skb);
29889 return -EINVAL;
29890 }
29891 @@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29892 if (skb_shinfo(skb)->nr_frags != 0)
29893 {
29894 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29895 - atomic_inc(&vcc->stats->tx_err);
29896 + atomic_inc_unchecked(&vcc->stats->tx_err);
29897 dev_kfree_skb_any(skb);
29898 return -EINVAL;
29899 }
29900 @@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29901
29902 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
29903 {
29904 - atomic_inc(&vcc->stats->tx_err);
29905 + atomic_inc_unchecked(&vcc->stats->tx_err);
29906 dev_kfree_skb_any(skb);
29907 return -EIO;
29908 }
29909 - atomic_inc(&vcc->stats->tx);
29910 + atomic_inc_unchecked(&vcc->stats->tx);
29911
29912 return 0;
29913 }
29914 @@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29915 {
29916 printk("nicstar%d: Can't allocate buffers for aal0.\n",
29917 card->index);
29918 - atomic_add(i,&vcc->stats->rx_drop);
29919 + atomic_add_unchecked(i,&vcc->stats->rx_drop);
29920 break;
29921 }
29922 if (!atm_charge(vcc, sb->truesize))
29923 {
29924 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
29925 card->index);
29926 - atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
29927 + atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
29928 dev_kfree_skb_any(sb);
29929 break;
29930 }
29931 @@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29932 ATM_SKB(sb)->vcc = vcc;
29933 __net_timestamp(sb);
29934 vcc->push(vcc, sb);
29935 - atomic_inc(&vcc->stats->rx);
29936 + atomic_inc_unchecked(&vcc->stats->rx);
29937 cell += ATM_CELL_PAYLOAD;
29938 }
29939
29940 @@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29941 if (iovb == NULL)
29942 {
29943 printk("nicstar%d: Out of iovec buffers.\n", card->index);
29944 - atomic_inc(&vcc->stats->rx_drop);
29945 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29946 recycle_rx_buf(card, skb);
29947 return;
29948 }
29949 @@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29950 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
29951 {
29952 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29953 - atomic_inc(&vcc->stats->rx_err);
29954 + atomic_inc_unchecked(&vcc->stats->rx_err);
29955 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
29956 NS_SKB(iovb)->iovcnt = 0;
29957 iovb->len = 0;
29958 @@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29959 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
29960 card->index);
29961 which_list(card, skb);
29962 - atomic_inc(&vcc->stats->rx_err);
29963 + atomic_inc_unchecked(&vcc->stats->rx_err);
29964 recycle_rx_buf(card, skb);
29965 vc->rx_iov = NULL;
29966 recycle_iov_buf(card, iovb);
29967 @@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29968 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
29969 card->index);
29970 which_list(card, skb);
29971 - atomic_inc(&vcc->stats->rx_err);
29972 + atomic_inc_unchecked(&vcc->stats->rx_err);
29973 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
29974 NS_SKB(iovb)->iovcnt);
29975 vc->rx_iov = NULL;
29976 @@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29977 printk(" - PDU size mismatch.\n");
29978 else
29979 printk(".\n");
29980 - atomic_inc(&vcc->stats->rx_err);
29981 + atomic_inc_unchecked(&vcc->stats->rx_err);
29982 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
29983 NS_SKB(iovb)->iovcnt);
29984 vc->rx_iov = NULL;
29985 @@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29986 if (!atm_charge(vcc, skb->truesize))
29987 {
29988 push_rxbufs(card, skb);
29989 - atomic_inc(&vcc->stats->rx_drop);
29990 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29991 }
29992 else
29993 {
29994 @@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29995 ATM_SKB(skb)->vcc = vcc;
29996 __net_timestamp(skb);
29997 vcc->push(vcc, skb);
29998 - atomic_inc(&vcc->stats->rx);
29999 + atomic_inc_unchecked(&vcc->stats->rx);
30000 }
30001 }
30002 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
30003 @@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30004 if (!atm_charge(vcc, sb->truesize))
30005 {
30006 push_rxbufs(card, sb);
30007 - atomic_inc(&vcc->stats->rx_drop);
30008 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30009 }
30010 else
30011 {
30012 @@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30013 ATM_SKB(sb)->vcc = vcc;
30014 __net_timestamp(sb);
30015 vcc->push(vcc, sb);
30016 - atomic_inc(&vcc->stats->rx);
30017 + atomic_inc_unchecked(&vcc->stats->rx);
30018 }
30019
30020 push_rxbufs(card, skb);
30021 @@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30022 if (!atm_charge(vcc, skb->truesize))
30023 {
30024 push_rxbufs(card, skb);
30025 - atomic_inc(&vcc->stats->rx_drop);
30026 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30027 }
30028 else
30029 {
30030 @@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30031 ATM_SKB(skb)->vcc = vcc;
30032 __net_timestamp(skb);
30033 vcc->push(vcc, skb);
30034 - atomic_inc(&vcc->stats->rx);
30035 + atomic_inc_unchecked(&vcc->stats->rx);
30036 }
30037
30038 push_rxbufs(card, sb);
30039 @@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30040 if (hb == NULL)
30041 {
30042 printk("nicstar%d: Out of huge buffers.\n", card->index);
30043 - atomic_inc(&vcc->stats->rx_drop);
30044 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30045 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30046 NS_SKB(iovb)->iovcnt);
30047 vc->rx_iov = NULL;
30048 @@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30049 }
30050 else
30051 dev_kfree_skb_any(hb);
30052 - atomic_inc(&vcc->stats->rx_drop);
30053 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30054 }
30055 else
30056 {
30057 @@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30058 #endif /* NS_USE_DESTRUCTORS */
30059 __net_timestamp(hb);
30060 vcc->push(vcc, hb);
30061 - atomic_inc(&vcc->stats->rx);
30062 + atomic_inc_unchecked(&vcc->stats->rx);
30063 }
30064 }
30065
30066 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30067 index 84c93ff..e6ed269 100644
30068 --- a/drivers/atm/solos-pci.c
30069 +++ b/drivers/atm/solos-pci.c
30070 @@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
30071 }
30072 atm_charge(vcc, skb->truesize);
30073 vcc->push(vcc, skb);
30074 - atomic_inc(&vcc->stats->rx);
30075 + atomic_inc_unchecked(&vcc->stats->rx);
30076 break;
30077
30078 case PKT_STATUS:
30079 @@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *buf)
30080 char msg[500];
30081 char item[10];
30082
30083 + pax_track_stack();
30084 +
30085 len = buf->len;
30086 for (i = 0; i < len; i++){
30087 if(i % 8 == 0)
30088 @@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30089 vcc = SKB_CB(oldskb)->vcc;
30090
30091 if (vcc) {
30092 - atomic_inc(&vcc->stats->tx);
30093 + atomic_inc_unchecked(&vcc->stats->tx);
30094 solos_pop(vcc, oldskb);
30095 } else
30096 dev_kfree_skb_irq(oldskb);
30097 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30098 index 6dd3f59..ee377f3 100644
30099 --- a/drivers/atm/suni.c
30100 +++ b/drivers/atm/suni.c
30101 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30102
30103
30104 #define ADD_LIMITED(s,v) \
30105 - atomic_add((v),&stats->s); \
30106 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30107 + atomic_add_unchecked((v),&stats->s); \
30108 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30109
30110
30111 static void suni_hz(unsigned long from_timer)
30112 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30113 index fc8cb07..4a80e53 100644
30114 --- a/drivers/atm/uPD98402.c
30115 +++ b/drivers/atm/uPD98402.c
30116 @@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30117 struct sonet_stats tmp;
30118 int error = 0;
30119
30120 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30121 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30122 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30123 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30124 if (zero && !error) {
30125 @@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30126
30127
30128 #define ADD_LIMITED(s,v) \
30129 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30130 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30131 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30132 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30133 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30134 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30135
30136
30137 static void stat_event(struct atm_dev *dev)
30138 @@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev *dev)
30139 if (reason & uPD98402_INT_PFM) stat_event(dev);
30140 if (reason & uPD98402_INT_PCO) {
30141 (void) GET(PCOCR); /* clear interrupt cause */
30142 - atomic_add(GET(HECCT),
30143 + atomic_add_unchecked(GET(HECCT),
30144 &PRIV(dev)->sonet_stats.uncorr_hcs);
30145 }
30146 if ((reason & uPD98402_INT_RFO) &&
30147 @@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev *dev)
30148 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30149 uPD98402_INT_LOS),PIMR); /* enable them */
30150 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30151 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30152 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30153 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30154 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30155 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30156 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30157 return 0;
30158 }
30159
30160 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30161 index 2e9635b..32927b4 100644
30162 --- a/drivers/atm/zatm.c
30163 +++ b/drivers/atm/zatm.c
30164 @@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30165 }
30166 if (!size) {
30167 dev_kfree_skb_irq(skb);
30168 - if (vcc) atomic_inc(&vcc->stats->rx_err);
30169 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30170 continue;
30171 }
30172 if (!atm_charge(vcc,skb->truesize)) {
30173 @@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30174 skb->len = size;
30175 ATM_SKB(skb)->vcc = vcc;
30176 vcc->push(vcc,skb);
30177 - atomic_inc(&vcc->stats->rx);
30178 + atomic_inc_unchecked(&vcc->stats->rx);
30179 }
30180 zout(pos & 0xffff,MTA(mbx));
30181 #if 0 /* probably a stupid idea */
30182 @@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30183 skb_queue_head(&zatm_vcc->backlog,skb);
30184 break;
30185 }
30186 - atomic_inc(&vcc->stats->tx);
30187 + atomic_inc_unchecked(&vcc->stats->tx);
30188 wake_up(&zatm_vcc->tx_wait);
30189 }
30190
30191 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
30192 index 63c143e..fece183 100644
30193 --- a/drivers/base/bus.c
30194 +++ b/drivers/base/bus.c
30195 @@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
30196 return ret;
30197 }
30198
30199 -static struct sysfs_ops driver_sysfs_ops = {
30200 +static const struct sysfs_ops driver_sysfs_ops = {
30201 .show = drv_attr_show,
30202 .store = drv_attr_store,
30203 };
30204 @@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
30205 return ret;
30206 }
30207
30208 -static struct sysfs_ops bus_sysfs_ops = {
30209 +static const struct sysfs_ops bus_sysfs_ops = {
30210 .show = bus_attr_show,
30211 .store = bus_attr_store,
30212 };
30213 @@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
30214 return 0;
30215 }
30216
30217 -static struct kset_uevent_ops bus_uevent_ops = {
30218 +static const struct kset_uevent_ops bus_uevent_ops = {
30219 .filter = bus_uevent_filter,
30220 };
30221
30222 diff --git a/drivers/base/class.c b/drivers/base/class.c
30223 index 6e2c3b0..cb61871 100644
30224 --- a/drivers/base/class.c
30225 +++ b/drivers/base/class.c
30226 @@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj)
30227 kfree(cp);
30228 }
30229
30230 -static struct sysfs_ops class_sysfs_ops = {
30231 +static const struct sysfs_ops class_sysfs_ops = {
30232 .show = class_attr_show,
30233 .store = class_attr_store,
30234 };
30235 diff --git a/drivers/base/core.c b/drivers/base/core.c
30236 index f33d768..a9358d0 100644
30237 --- a/drivers/base/core.c
30238 +++ b/drivers/base/core.c
30239 @@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
30240 return ret;
30241 }
30242
30243 -static struct sysfs_ops dev_sysfs_ops = {
30244 +static const struct sysfs_ops dev_sysfs_ops = {
30245 .show = dev_attr_show,
30246 .store = dev_attr_store,
30247 };
30248 @@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
30249 return retval;
30250 }
30251
30252 -static struct kset_uevent_ops device_uevent_ops = {
30253 +static const struct kset_uevent_ops device_uevent_ops = {
30254 .filter = dev_uevent_filter,
30255 .name = dev_uevent_name,
30256 .uevent = dev_uevent,
30257 diff --git a/drivers/base/memory.c b/drivers/base/memory.c
30258 index 989429c..2272b00 100644
30259 --- a/drivers/base/memory.c
30260 +++ b/drivers/base/memory.c
30261 @@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
30262 return retval;
30263 }
30264
30265 -static struct kset_uevent_ops memory_uevent_ops = {
30266 +static const struct kset_uevent_ops memory_uevent_ops = {
30267 .name = memory_uevent_name,
30268 .uevent = memory_uevent,
30269 };
30270 diff --git a/drivers/base/sys.c b/drivers/base/sys.c
30271 index 3f202f7..61c4a6f 100644
30272 --- a/drivers/base/sys.c
30273 +++ b/drivers/base/sys.c
30274 @@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr,
30275 return -EIO;
30276 }
30277
30278 -static struct sysfs_ops sysfs_ops = {
30279 +static const struct sysfs_ops sysfs_ops = {
30280 .show = sysdev_show,
30281 .store = sysdev_store,
30282 };
30283 @@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
30284 return -EIO;
30285 }
30286
30287 -static struct sysfs_ops sysfs_class_ops = {
30288 +static const struct sysfs_ops sysfs_class_ops = {
30289 .show = sysdev_class_show,
30290 .store = sysdev_class_store,
30291 };
30292 diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
30293 index eb4fa19..1954777 100644
30294 --- a/drivers/block/DAC960.c
30295 +++ b/drivers/block/DAC960.c
30296 @@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
30297 unsigned long flags;
30298 int Channel, TargetID;
30299
30300 + pax_track_stack();
30301 +
30302 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
30303 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
30304 sizeof(DAC960_SCSI_Inquiry_T) +
30305 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30306 index ca9c548..ca6899c 100644
30307 --- a/drivers/block/cciss.c
30308 +++ b/drivers/block/cciss.c
30309 @@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30310 int err;
30311 u32 cp;
30312
30313 + memset(&arg64, 0, sizeof(arg64));
30314 +
30315 err = 0;
30316 err |=
30317 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30318 @@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ctlr)
30319 /* Wait (up to 20 seconds) for a command to complete */
30320
30321 for (i = 20 * HZ; i > 0; i--) {
30322 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
30323 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
30324 if (done == FIFO_EMPTY)
30325 schedule_timeout_uninterruptible(1);
30326 else
30327 @@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
30328 resend_cmd1:
30329
30330 /* Disable interrupt on the board. */
30331 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
30332 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
30333
30334 /* Make sure there is room in the command FIFO */
30335 /* Actually it should be completely empty at this time */
30336 @@ -2884,13 +2886,13 @@ resend_cmd1:
30337 /* tape side of the driver. */
30338 for (i = 200000; i > 0; i--) {
30339 /* if fifo isn't full go */
30340 - if (!(h->access.fifo_full(h)))
30341 + if (!(h->access->fifo_full(h)))
30342 break;
30343 udelay(10);
30344 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
30345 " waiting!\n", h->ctlr);
30346 }
30347 - h->access.submit_command(h, c); /* Send the cmd */
30348 + h->access->submit_command(h, c); /* Send the cmd */
30349 do {
30350 complete = pollcomplete(h->ctlr);
30351
30352 @@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
30353 while (!hlist_empty(&h->reqQ)) {
30354 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
30355 /* can't do anything if fifo is full */
30356 - if ((h->access.fifo_full(h))) {
30357 + if ((h->access->fifo_full(h))) {
30358 printk(KERN_WARNING "cciss: fifo full\n");
30359 break;
30360 }
30361 @@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
30362 h->Qdepth--;
30363
30364 /* Tell the controller execute command */
30365 - h->access.submit_command(h, c);
30366 + h->access->submit_command(h, c);
30367
30368 /* Put job onto the completed Q */
30369 addQ(&h->cmpQ, c);
30370 @@ -3393,17 +3395,17 @@ startio:
30371
30372 static inline unsigned long get_next_completion(ctlr_info_t *h)
30373 {
30374 - return h->access.command_completed(h);
30375 + return h->access->command_completed(h);
30376 }
30377
30378 static inline int interrupt_pending(ctlr_info_t *h)
30379 {
30380 - return h->access.intr_pending(h);
30381 + return h->access->intr_pending(h);
30382 }
30383
30384 static inline long interrupt_not_for_us(ctlr_info_t *h)
30385 {
30386 - return (((h->access.intr_pending(h) == 0) ||
30387 + return (((h->access->intr_pending(h) == 0) ||
30388 (h->interrupts_enabled == 0)));
30389 }
30390
30391 @@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
30392 */
30393 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
30394 c->product_name = products[prod_index].product_name;
30395 - c->access = *(products[prod_index].access);
30396 + c->access = products[prod_index].access;
30397 c->nr_cmds = c->max_commands - 4;
30398 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
30399 (readb(&c->cfgtable->Signature[1]) != 'I') ||
30400 @@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30401 }
30402
30403 /* make sure the board interrupts are off */
30404 - hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
30405 + hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
30406 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
30407 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
30408 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
30409 @@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30410 cciss_scsi_setup(i);
30411
30412 /* Turn the interrupts on so we can service requests */
30413 - hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
30414 + hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
30415
30416 /* Get the firmware version */
30417 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30418 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30419 index 04d6bf8..36e712d 100644
30420 --- a/drivers/block/cciss.h
30421 +++ b/drivers/block/cciss.h
30422 @@ -90,7 +90,7 @@ struct ctlr_info
30423 // information about each logical volume
30424 drive_info_struct *drv[CISS_MAX_LUN];
30425
30426 - struct access_method access;
30427 + struct access_method *access;
30428
30429 /* queue and queue Info */
30430 struct hlist_head reqQ;
30431 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30432 index 6422651..bb1bdef 100644
30433 --- a/drivers/block/cpqarray.c
30434 +++ b/drivers/block/cpqarray.c
30435 @@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30436 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30437 goto Enomem4;
30438 }
30439 - hba[i]->access.set_intr_mask(hba[i], 0);
30440 + hba[i]->access->set_intr_mask(hba[i], 0);
30441 if (request_irq(hba[i]->intr, do_ida_intr,
30442 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30443 {
30444 @@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30445 add_timer(&hba[i]->timer);
30446
30447 /* Enable IRQ now that spinlock and rate limit timer are set up */
30448 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30449 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30450
30451 for(j=0; j<NWD; j++) {
30452 struct gendisk *disk = ida_gendisk[i][j];
30453 @@ -695,7 +695,7 @@ DBGINFO(
30454 for(i=0; i<NR_PRODUCTS; i++) {
30455 if (board_id == products[i].board_id) {
30456 c->product_name = products[i].product_name;
30457 - c->access = *(products[i].access);
30458 + c->access = products[i].access;
30459 break;
30460 }
30461 }
30462 @@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(void)
30463 hba[ctlr]->intr = intr;
30464 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30465 hba[ctlr]->product_name = products[j].product_name;
30466 - hba[ctlr]->access = *(products[j].access);
30467 + hba[ctlr]->access = products[j].access;
30468 hba[ctlr]->ctlr = ctlr;
30469 hba[ctlr]->board_id = board_id;
30470 hba[ctlr]->pci_dev = NULL; /* not PCI */
30471 @@ -896,6 +896,8 @@ static void do_ida_request(struct request_queue *q)
30472 struct scatterlist tmp_sg[SG_MAX];
30473 int i, dir, seg;
30474
30475 + pax_track_stack();
30476 +
30477 if (blk_queue_plugged(q))
30478 goto startio;
30479
30480 @@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
30481
30482 while((c = h->reqQ) != NULL) {
30483 /* Can't do anything if we're busy */
30484 - if (h->access.fifo_full(h) == 0)
30485 + if (h->access->fifo_full(h) == 0)
30486 return;
30487
30488 /* Get the first entry from the request Q */
30489 @@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
30490 h->Qdepth--;
30491
30492 /* Tell the controller to do our bidding */
30493 - h->access.submit_command(h, c);
30494 + h->access->submit_command(h, c);
30495
30496 /* Get onto the completion Q */
30497 addQ(&h->cmpQ, c);
30498 @@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30499 unsigned long flags;
30500 __u32 a,a1;
30501
30502 - istat = h->access.intr_pending(h);
30503 + istat = h->access->intr_pending(h);
30504 /* Is this interrupt for us? */
30505 if (istat == 0)
30506 return IRQ_NONE;
30507 @@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30508 */
30509 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30510 if (istat & FIFO_NOT_EMPTY) {
30511 - while((a = h->access.command_completed(h))) {
30512 + while((a = h->access->command_completed(h))) {
30513 a1 = a; a &= ~3;
30514 if ((c = h->cmpQ) == NULL)
30515 {
30516 @@ -1434,11 +1436,11 @@ static int sendcmd(
30517 /*
30518 * Disable interrupt
30519 */
30520 - info_p->access.set_intr_mask(info_p, 0);
30521 + info_p->access->set_intr_mask(info_p, 0);
30522 /* Make sure there is room in the command FIFO */
30523 /* Actually it should be completely empty at this time. */
30524 for (i = 200000; i > 0; i--) {
30525 - temp = info_p->access.fifo_full(info_p);
30526 + temp = info_p->access->fifo_full(info_p);
30527 if (temp != 0) {
30528 break;
30529 }
30530 @@ -1451,7 +1453,7 @@ DBG(
30531 /*
30532 * Send the cmd
30533 */
30534 - info_p->access.submit_command(info_p, c);
30535 + info_p->access->submit_command(info_p, c);
30536 complete = pollcomplete(ctlr);
30537
30538 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
30539 @@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t *host)
30540 * we check the new geometry. Then turn interrupts back on when
30541 * we're done.
30542 */
30543 - host->access.set_intr_mask(host, 0);
30544 + host->access->set_intr_mask(host, 0);
30545 getgeometry(ctlr);
30546 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
30547 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
30548
30549 for(i=0; i<NWD; i++) {
30550 struct gendisk *disk = ida_gendisk[ctlr][i];
30551 @@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
30552 /* Wait (up to 2 seconds) for a command to complete */
30553
30554 for (i = 200000; i > 0; i--) {
30555 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
30556 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
30557 if (done == 0) {
30558 udelay(10); /* a short fixed delay */
30559 } else
30560 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
30561 index be73e9d..7fbf140 100644
30562 --- a/drivers/block/cpqarray.h
30563 +++ b/drivers/block/cpqarray.h
30564 @@ -99,7 +99,7 @@ struct ctlr_info {
30565 drv_info_t drv[NWD];
30566 struct proc_dir_entry *proc;
30567
30568 - struct access_method access;
30569 + struct access_method *access;
30570
30571 cmdlist_t *reqQ;
30572 cmdlist_t *cmpQ;
30573 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
30574 index 8ec2d70..2804b30 100644
30575 --- a/drivers/block/loop.c
30576 +++ b/drivers/block/loop.c
30577 @@ -282,7 +282,7 @@ static int __do_lo_send_write(struct file *file,
30578 mm_segment_t old_fs = get_fs();
30579
30580 set_fs(get_ds());
30581 - bw = file->f_op->write(file, buf, len, &pos);
30582 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
30583 set_fs(old_fs);
30584 if (likely(bw == len))
30585 return 0;
30586 diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
30587 index 26ada47..083c480 100644
30588 --- a/drivers/block/nbd.c
30589 +++ b/drivers/block/nbd.c
30590 @@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
30591 struct kvec iov;
30592 sigset_t blocked, oldset;
30593
30594 + pax_track_stack();
30595 +
30596 if (unlikely(!sock)) {
30597 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
30598 lo->disk->disk_name, (send ? "send" : "recv"));
30599 @@ -569,6 +571,8 @@ static void do_nbd_request(struct request_queue *q)
30600 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
30601 unsigned int cmd, unsigned long arg)
30602 {
30603 + pax_track_stack();
30604 +
30605 switch (cmd) {
30606 case NBD_DISCONNECT: {
30607 struct request sreq;
30608 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
30609 index a5d585d..d087be3 100644
30610 --- a/drivers/block/pktcdvd.c
30611 +++ b/drivers/block/pktcdvd.c
30612 @@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
30613 return len;
30614 }
30615
30616 -static struct sysfs_ops kobj_pkt_ops = {
30617 +static const struct sysfs_ops kobj_pkt_ops = {
30618 .show = kobj_pkt_show,
30619 .store = kobj_pkt_store
30620 };
30621 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
30622 index 6aad99e..89cd142 100644
30623 --- a/drivers/char/Kconfig
30624 +++ b/drivers/char/Kconfig
30625 @@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
30626
30627 config DEVKMEM
30628 bool "/dev/kmem virtual device support"
30629 - default y
30630 + default n
30631 + depends on !GRKERNSEC_KMEM
30632 help
30633 Say Y here if you want to support the /dev/kmem device. The
30634 /dev/kmem device is rarely used, but can be used for certain
30635 @@ -1114,6 +1115,7 @@ config DEVPORT
30636 bool
30637 depends on !M68K
30638 depends on ISA || PCI
30639 + depends on !GRKERNSEC_KMEM
30640 default y
30641
30642 source "drivers/s390/char/Kconfig"
30643 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
30644 index a96f319..a778a5b 100644
30645 --- a/drivers/char/agp/frontend.c
30646 +++ b/drivers/char/agp/frontend.c
30647 @@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
30648 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
30649 return -EFAULT;
30650
30651 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
30652 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
30653 return -EFAULT;
30654
30655 client = agp_find_client_by_pid(reserve.pid);
30656 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
30657 index d8cff90..9628e70 100644
30658 --- a/drivers/char/briq_panel.c
30659 +++ b/drivers/char/briq_panel.c
30660 @@ -10,6 +10,7 @@
30661 #include <linux/types.h>
30662 #include <linux/errno.h>
30663 #include <linux/tty.h>
30664 +#include <linux/mutex.h>
30665 #include <linux/timer.h>
30666 #include <linux/kernel.h>
30667 #include <linux/wait.h>
30668 @@ -36,6 +37,7 @@ static int vfd_is_open;
30669 static unsigned char vfd[40];
30670 static int vfd_cursor;
30671 static unsigned char ledpb, led;
30672 +static DEFINE_MUTEX(vfd_mutex);
30673
30674 static void update_vfd(void)
30675 {
30676 @@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30677 if (!vfd_is_open)
30678 return -EBUSY;
30679
30680 + mutex_lock(&vfd_mutex);
30681 for (;;) {
30682 char c;
30683 if (!indx)
30684 break;
30685 - if (get_user(c, buf))
30686 + if (get_user(c, buf)) {
30687 + mutex_unlock(&vfd_mutex);
30688 return -EFAULT;
30689 + }
30690 if (esc) {
30691 set_led(c);
30692 esc = 0;
30693 @@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30694 buf++;
30695 }
30696 update_vfd();
30697 + mutex_unlock(&vfd_mutex);
30698
30699 return len;
30700 }
30701 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
30702 index 31e7c91..161afc0 100644
30703 --- a/drivers/char/genrtc.c
30704 +++ b/drivers/char/genrtc.c
30705 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
30706 switch (cmd) {
30707
30708 case RTC_PLL_GET:
30709 + memset(&pll, 0, sizeof(pll));
30710 if (get_rtc_pll(&pll))
30711 return -EINVAL;
30712 else
30713 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
30714 index 006466d..a2bb21c 100644
30715 --- a/drivers/char/hpet.c
30716 +++ b/drivers/char/hpet.c
30717 @@ -430,7 +430,7 @@ static int hpet_release(struct inode *inode, struct file *file)
30718 return 0;
30719 }
30720
30721 -static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
30722 +static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
30723
30724 static int
30725 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
30726 @@ -565,7 +565,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
30727 }
30728
30729 static int
30730 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30731 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
30732 {
30733 struct hpet_timer __iomem *timer;
30734 struct hpet __iomem *hpet;
30735 @@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30736 {
30737 struct hpet_info info;
30738
30739 + memset(&info, 0, sizeof(info));
30740 +
30741 if (devp->hd_ireqfreq)
30742 info.hi_ireqfreq =
30743 hpet_time_div(hpetp, devp->hd_ireqfreq);
30744 - else
30745 - info.hi_ireqfreq = 0;
30746 info.hi_flags =
30747 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
30748 info.hi_hpet = hpetp->hp_which;
30749 diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c
30750 index 0afc8b8..6913fc3 100644
30751 --- a/drivers/char/hvc_beat.c
30752 +++ b/drivers/char/hvc_beat.c
30753 @@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
30754 return cnt;
30755 }
30756
30757 -static struct hv_ops hvc_beat_get_put_ops = {
30758 +static const struct hv_ops hvc_beat_get_put_ops = {
30759 .get_chars = hvc_beat_get_chars,
30760 .put_chars = hvc_beat_put_chars,
30761 };
30762 diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
30763 index 98097f2..407dddc 100644
30764 --- a/drivers/char/hvc_console.c
30765 +++ b/drivers/char/hvc_console.c
30766 @@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
30767 * console interfaces but can still be used as a tty device. This has to be
30768 * static because kmalloc will not work during early console init.
30769 */
30770 -static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30771 +static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30772 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
30773 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
30774
30775 @@ -249,7 +249,7 @@ static void destroy_hvc_struct(struct kref *kref)
30776 * vty adapters do NOT get an hvc_instantiate() callback since they
30777 * appear after early console init.
30778 */
30779 -int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
30780 +int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
30781 {
30782 struct hvc_struct *hp;
30783
30784 @@ -758,7 +758,7 @@ static const struct tty_operations hvc_ops = {
30785 };
30786
30787 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
30788 - struct hv_ops *ops, int outbuf_size)
30789 + const struct hv_ops *ops, int outbuf_size)
30790 {
30791 struct hvc_struct *hp;
30792 int i;
30793 diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
30794 index 10950ca..ed176c3 100644
30795 --- a/drivers/char/hvc_console.h
30796 +++ b/drivers/char/hvc_console.h
30797 @@ -55,7 +55,7 @@ struct hvc_struct {
30798 int outbuf_size;
30799 int n_outbuf;
30800 uint32_t vtermno;
30801 - struct hv_ops *ops;
30802 + const struct hv_ops *ops;
30803 int irq_requested;
30804 int data;
30805 struct winsize ws;
30806 @@ -76,11 +76,11 @@ struct hv_ops {
30807 };
30808
30809 /* Register a vterm and a slot index for use as a console (console_init) */
30810 -extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
30811 +extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
30812
30813 /* register a vterm for hvc tty operation (module_init or hotplug add) */
30814 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
30815 - struct hv_ops *ops, int outbuf_size);
30816 + const struct hv_ops *ops, int outbuf_size);
30817 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
30818 extern int hvc_remove(struct hvc_struct *hp);
30819
30820 diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
30821 index 936d05b..fd02426 100644
30822 --- a/drivers/char/hvc_iseries.c
30823 +++ b/drivers/char/hvc_iseries.c
30824 @@ -197,7 +197,7 @@ done:
30825 return sent;
30826 }
30827
30828 -static struct hv_ops hvc_get_put_ops = {
30829 +static const struct hv_ops hvc_get_put_ops = {
30830 .get_chars = get_chars,
30831 .put_chars = put_chars,
30832 .notifier_add = notifier_add_irq,
30833 diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
30834 index b0e168f..69cda2a 100644
30835 --- a/drivers/char/hvc_iucv.c
30836 +++ b/drivers/char/hvc_iucv.c
30837 @@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
30838
30839
30840 /* HVC operations */
30841 -static struct hv_ops hvc_iucv_ops = {
30842 +static const struct hv_ops hvc_iucv_ops = {
30843 .get_chars = hvc_iucv_get_chars,
30844 .put_chars = hvc_iucv_put_chars,
30845 .notifier_add = hvc_iucv_notifier_add,
30846 diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
30847 index 88590d0..61c4a61 100644
30848 --- a/drivers/char/hvc_rtas.c
30849 +++ b/drivers/char/hvc_rtas.c
30850 @@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
30851 return i;
30852 }
30853
30854 -static struct hv_ops hvc_rtas_get_put_ops = {
30855 +static const struct hv_ops hvc_rtas_get_put_ops = {
30856 .get_chars = hvc_rtas_read_console,
30857 .put_chars = hvc_rtas_write_console,
30858 };
30859 diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
30860 index bd63ba8..b0957e6 100644
30861 --- a/drivers/char/hvc_udbg.c
30862 +++ b/drivers/char/hvc_udbg.c
30863 @@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
30864 return i;
30865 }
30866
30867 -static struct hv_ops hvc_udbg_ops = {
30868 +static const struct hv_ops hvc_udbg_ops = {
30869 .get_chars = hvc_udbg_get,
30870 .put_chars = hvc_udbg_put,
30871 };
30872 diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
30873 index 10be343..27370e9 100644
30874 --- a/drivers/char/hvc_vio.c
30875 +++ b/drivers/char/hvc_vio.c
30876 @@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
30877 return got;
30878 }
30879
30880 -static struct hv_ops hvc_get_put_ops = {
30881 +static const struct hv_ops hvc_get_put_ops = {
30882 .get_chars = filtered_get_chars,
30883 .put_chars = hvc_put_chars,
30884 .notifier_add = notifier_add_irq,
30885 diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
30886 index a6ee32b..94f8c26 100644
30887 --- a/drivers/char/hvc_xen.c
30888 +++ b/drivers/char/hvc_xen.c
30889 @@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
30890 return recv;
30891 }
30892
30893 -static struct hv_ops hvc_ops = {
30894 +static const struct hv_ops hvc_ops = {
30895 .get_chars = read_console,
30896 .put_chars = write_console,
30897 .notifier_add = notifier_add_irq,
30898 diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
30899 index 266b858..f3ee0bb 100644
30900 --- a/drivers/char/hvcs.c
30901 +++ b/drivers/char/hvcs.c
30902 @@ -82,6 +82,7 @@
30903 #include <asm/hvcserver.h>
30904 #include <asm/uaccess.h>
30905 #include <asm/vio.h>
30906 +#include <asm/local.h>
30907
30908 /*
30909 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
30910 @@ -269,7 +270,7 @@ struct hvcs_struct {
30911 unsigned int index;
30912
30913 struct tty_struct *tty;
30914 - int open_count;
30915 + local_t open_count;
30916
30917 /*
30918 * Used to tell the driver kernel_thread what operations need to take
30919 @@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
30920
30921 spin_lock_irqsave(&hvcsd->lock, flags);
30922
30923 - if (hvcsd->open_count > 0) {
30924 + if (local_read(&hvcsd->open_count) > 0) {
30925 spin_unlock_irqrestore(&hvcsd->lock, flags);
30926 printk(KERN_INFO "HVCS: vterm state unchanged. "
30927 "The hvcs device node is still in use.\n");
30928 @@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
30929 if ((retval = hvcs_partner_connect(hvcsd)))
30930 goto error_release;
30931
30932 - hvcsd->open_count = 1;
30933 + local_set(&hvcsd->open_count, 1);
30934 hvcsd->tty = tty;
30935 tty->driver_data = hvcsd;
30936
30937 @@ -1169,7 +1170,7 @@ fast_open:
30938
30939 spin_lock_irqsave(&hvcsd->lock, flags);
30940 kref_get(&hvcsd->kref);
30941 - hvcsd->open_count++;
30942 + local_inc(&hvcsd->open_count);
30943 hvcsd->todo_mask |= HVCS_SCHED_READ;
30944 spin_unlock_irqrestore(&hvcsd->lock, flags);
30945
30946 @@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
30947 hvcsd = tty->driver_data;
30948
30949 spin_lock_irqsave(&hvcsd->lock, flags);
30950 - if (--hvcsd->open_count == 0) {
30951 + if (local_dec_and_test(&hvcsd->open_count)) {
30952
30953 vio_disable_interrupts(hvcsd->vdev);
30954
30955 @@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
30956 free_irq(irq, hvcsd);
30957 kref_put(&hvcsd->kref, destroy_hvcs_struct);
30958 return;
30959 - } else if (hvcsd->open_count < 0) {
30960 + } else if (local_read(&hvcsd->open_count) < 0) {
30961 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
30962 " is missmanaged.\n",
30963 - hvcsd->vdev->unit_address, hvcsd->open_count);
30964 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
30965 }
30966
30967 spin_unlock_irqrestore(&hvcsd->lock, flags);
30968 @@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struct * tty)
30969
30970 spin_lock_irqsave(&hvcsd->lock, flags);
30971 /* Preserve this so that we know how many kref refs to put */
30972 - temp_open_count = hvcsd->open_count;
30973 + temp_open_count = local_read(&hvcsd->open_count);
30974
30975 /*
30976 * Don't kref put inside the spinlock because the destruction
30977 @@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struct * tty)
30978 hvcsd->tty->driver_data = NULL;
30979 hvcsd->tty = NULL;
30980
30981 - hvcsd->open_count = 0;
30982 + local_set(&hvcsd->open_count, 0);
30983
30984 /* This will drop any buffered data on the floor which is OK in a hangup
30985 * scenario. */
30986 @@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct *tty,
30987 * the middle of a write operation? This is a crummy place to do this
30988 * but we want to keep it all in the spinlock.
30989 */
30990 - if (hvcsd->open_count <= 0) {
30991 + if (local_read(&hvcsd->open_count) <= 0) {
30992 spin_unlock_irqrestore(&hvcsd->lock, flags);
30993 return -ENODEV;
30994 }
30995 @@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_struct *tty)
30996 {
30997 struct hvcs_struct *hvcsd = tty->driver_data;
30998
30999 - if (!hvcsd || hvcsd->open_count <= 0)
31000 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
31001 return 0;
31002
31003 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
31004 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31005 index ec5e3f8..02455ba 100644
31006 --- a/drivers/char/ipmi/ipmi_msghandler.c
31007 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31008 @@ -414,7 +414,7 @@ struct ipmi_smi {
31009 struct proc_dir_entry *proc_dir;
31010 char proc_dir_name[10];
31011
31012 - atomic_t stats[IPMI_NUM_STATS];
31013 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31014
31015 /*
31016 * run_to_completion duplicate of smb_info, smi_info
31017 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31018
31019
31020 #define ipmi_inc_stat(intf, stat) \
31021 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31022 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31023 #define ipmi_get_stat(intf, stat) \
31024 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31025 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31026
31027 static int is_lan_addr(struct ipmi_addr *addr)
31028 {
31029 @@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31030 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31031 init_waitqueue_head(&intf->waitq);
31032 for (i = 0; i < IPMI_NUM_STATS; i++)
31033 - atomic_set(&intf->stats[i], 0);
31034 + atomic_set_unchecked(&intf->stats[i], 0);
31035
31036 intf->proc_dir = NULL;
31037
31038 @@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
31039 struct ipmi_smi_msg smi_msg;
31040 struct ipmi_recv_msg recv_msg;
31041
31042 + pax_track_stack();
31043 +
31044 si = (struct ipmi_system_interface_addr *) &addr;
31045 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
31046 si->channel = IPMI_BMC_CHANNEL;
31047 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31048 index abae8c9..8021979 100644
31049 --- a/drivers/char/ipmi/ipmi_si_intf.c
31050 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31051 @@ -277,7 +277,7 @@ struct smi_info {
31052 unsigned char slave_addr;
31053
31054 /* Counters and things for the proc filesystem. */
31055 - atomic_t stats[SI_NUM_STATS];
31056 + atomic_unchecked_t stats[SI_NUM_STATS];
31057
31058 struct task_struct *thread;
31059
31060 @@ -285,9 +285,9 @@ struct smi_info {
31061 };
31062
31063 #define smi_inc_stat(smi, stat) \
31064 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31065 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31066 #define smi_get_stat(smi, stat) \
31067 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31068 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31069
31070 #define SI_MAX_PARMS 4
31071
31072 @@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info *new_smi)
31073 atomic_set(&new_smi->req_events, 0);
31074 new_smi->run_to_completion = 0;
31075 for (i = 0; i < SI_NUM_STATS; i++)
31076 - atomic_set(&new_smi->stats[i], 0);
31077 + atomic_set_unchecked(&new_smi->stats[i], 0);
31078
31079 new_smi->interrupt_disabled = 0;
31080 atomic_set(&new_smi->stop_operation, 0);
31081 diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
31082 index 402838f..55e2200 100644
31083 --- a/drivers/char/istallion.c
31084 +++ b/drivers/char/istallion.c
31085 @@ -187,7 +187,6 @@ static struct ktermios stli_deftermios = {
31086 * re-used for each stats call.
31087 */
31088 static comstats_t stli_comstats;
31089 -static combrd_t stli_brdstats;
31090 static struct asystats stli_cdkstats;
31091
31092 /*****************************************************************************/
31093 @@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
31094 {
31095 struct stlibrd *brdp;
31096 unsigned int i;
31097 + combrd_t stli_brdstats;
31098
31099 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
31100 return -EFAULT;
31101 @@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stliport __user *arg)
31102 struct stliport stli_dummyport;
31103 struct stliport *portp;
31104
31105 + pax_track_stack();
31106 +
31107 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
31108 return -EFAULT;
31109 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
31110 @@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stlibrd __user *arg)
31111 struct stlibrd stli_dummybrd;
31112 struct stlibrd *brdp;
31113
31114 + pax_track_stack();
31115 +
31116 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
31117 return -EFAULT;
31118 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
31119 diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
31120 index 950837c..e55a288 100644
31121 --- a/drivers/char/keyboard.c
31122 +++ b/drivers/char/keyboard.c
31123 @@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
31124 kbd->kbdmode == VC_MEDIUMRAW) &&
31125 value != KVAL(K_SAK))
31126 return; /* SAK is allowed even in raw mode */
31127 +
31128 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
31129 + {
31130 + void *func = fn_handler[value];
31131 + if (func == fn_show_state || func == fn_show_ptregs ||
31132 + func == fn_show_mem)
31133 + return;
31134 + }
31135 +#endif
31136 +
31137 fn_handler[value](vc);
31138 }
31139
31140 @@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_ids[] = {
31141 .evbit = { BIT_MASK(EV_SND) },
31142 },
31143
31144 - { }, /* Terminating entry */
31145 + { 0 }, /* Terminating entry */
31146 };
31147
31148 MODULE_DEVICE_TABLE(input, kbd_ids);
31149 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
31150 index 87c67b4..230527a 100644
31151 --- a/drivers/char/mbcs.c
31152 +++ b/drivers/char/mbcs.c
31153 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
31154 return 0;
31155 }
31156
31157 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
31158 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
31159 {
31160 .part_num = MBCS_PART_NUM,
31161 .mfg_num = MBCS_MFG_NUM,
31162 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31163 index 1270f64..8495f49 100644
31164 --- a/drivers/char/mem.c
31165 +++ b/drivers/char/mem.c
31166 @@ -18,6 +18,7 @@
31167 #include <linux/raw.h>
31168 #include <linux/tty.h>
31169 #include <linux/capability.h>
31170 +#include <linux/security.h>
31171 #include <linux/ptrace.h>
31172 #include <linux/device.h>
31173 #include <linux/highmem.h>
31174 @@ -35,6 +36,10 @@
31175 # include <linux/efi.h>
31176 #endif
31177
31178 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31179 +extern struct file_operations grsec_fops;
31180 +#endif
31181 +
31182 static inline unsigned long size_inside_page(unsigned long start,
31183 unsigned long size)
31184 {
31185 @@ -102,9 +107,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31186
31187 while (cursor < to) {
31188 if (!devmem_is_allowed(pfn)) {
31189 +#ifdef CONFIG_GRKERNSEC_KMEM
31190 + gr_handle_mem_readwrite(from, to);
31191 +#else
31192 printk(KERN_INFO
31193 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31194 current->comm, from, to);
31195 +#endif
31196 return 0;
31197 }
31198 cursor += PAGE_SIZE;
31199 @@ -112,6 +121,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31200 }
31201 return 1;
31202 }
31203 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31204 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31205 +{
31206 + return 0;
31207 +}
31208 #else
31209 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31210 {
31211 @@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31212 #endif
31213
31214 while (count > 0) {
31215 + char *temp;
31216 +
31217 /*
31218 * Handle first page in case it's not aligned
31219 */
31220 @@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31221 if (!ptr)
31222 return -EFAULT;
31223
31224 - if (copy_to_user(buf, ptr, sz)) {
31225 +#ifdef CONFIG_PAX_USERCOPY
31226 + temp = kmalloc(sz, GFP_KERNEL);
31227 + if (!temp) {
31228 + unxlate_dev_mem_ptr(p, ptr);
31229 + return -ENOMEM;
31230 + }
31231 + memcpy(temp, ptr, sz);
31232 +#else
31233 + temp = ptr;
31234 +#endif
31235 +
31236 + if (copy_to_user(buf, temp, sz)) {
31237 +
31238 +#ifdef CONFIG_PAX_USERCOPY
31239 + kfree(temp);
31240 +#endif
31241 +
31242 unxlate_dev_mem_ptr(p, ptr);
31243 return -EFAULT;
31244 }
31245
31246 +#ifdef CONFIG_PAX_USERCOPY
31247 + kfree(temp);
31248 +#endif
31249 +
31250 unxlate_dev_mem_ptr(p, ptr);
31251
31252 buf += sz;
31253 @@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31254 size_t count, loff_t *ppos)
31255 {
31256 unsigned long p = *ppos;
31257 - ssize_t low_count, read, sz;
31258 + ssize_t low_count, read, sz, err = 0;
31259 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31260 - int err = 0;
31261
31262 read = 0;
31263 if (p < (unsigned long) high_memory) {
31264 @@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31265 }
31266 #endif
31267 while (low_count > 0) {
31268 + char *temp;
31269 +
31270 sz = size_inside_page(p, low_count);
31271
31272 /*
31273 @@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31274 */
31275 kbuf = xlate_dev_kmem_ptr((char *)p);
31276
31277 - if (copy_to_user(buf, kbuf, sz))
31278 +#ifdef CONFIG_PAX_USERCOPY
31279 + temp = kmalloc(sz, GFP_KERNEL);
31280 + if (!temp)
31281 + return -ENOMEM;
31282 + memcpy(temp, kbuf, sz);
31283 +#else
31284 + temp = kbuf;
31285 +#endif
31286 +
31287 + err = copy_to_user(buf, temp, sz);
31288 +
31289 +#ifdef CONFIG_PAX_USERCOPY
31290 + kfree(temp);
31291 +#endif
31292 +
31293 + if (err)
31294 return -EFAULT;
31295 buf += sz;
31296 p += sz;
31297 @@ -889,6 +941,9 @@ static const struct memdev {
31298 #ifdef CONFIG_CRASH_DUMP
31299 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31300 #endif
31301 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31302 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31303 +#endif
31304 };
31305
31306 static int memory_open(struct inode *inode, struct file *filp)
31307 diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
31308 index 674b3ab..a8d1970 100644
31309 --- a/drivers/char/pcmcia/ipwireless/tty.c
31310 +++ b/drivers/char/pcmcia/ipwireless/tty.c
31311 @@ -29,6 +29,7 @@
31312 #include <linux/tty_driver.h>
31313 #include <linux/tty_flip.h>
31314 #include <linux/uaccess.h>
31315 +#include <asm/local.h>
31316
31317 #include "tty.h"
31318 #include "network.h"
31319 @@ -51,7 +52,7 @@ struct ipw_tty {
31320 int tty_type;
31321 struct ipw_network *network;
31322 struct tty_struct *linux_tty;
31323 - int open_count;
31324 + local_t open_count;
31325 unsigned int control_lines;
31326 struct mutex ipw_tty_mutex;
31327 int tx_bytes_queued;
31328 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31329 mutex_unlock(&tty->ipw_tty_mutex);
31330 return -ENODEV;
31331 }
31332 - if (tty->open_count == 0)
31333 + if (local_read(&tty->open_count) == 0)
31334 tty->tx_bytes_queued = 0;
31335
31336 - tty->open_count++;
31337 + local_inc(&tty->open_count);
31338
31339 tty->linux_tty = linux_tty;
31340 linux_tty->driver_data = tty;
31341 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31342
31343 static void do_ipw_close(struct ipw_tty *tty)
31344 {
31345 - tty->open_count--;
31346 -
31347 - if (tty->open_count == 0) {
31348 + if (local_dec_return(&tty->open_count) == 0) {
31349 struct tty_struct *linux_tty = tty->linux_tty;
31350
31351 if (linux_tty != NULL) {
31352 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
31353 return;
31354
31355 mutex_lock(&tty->ipw_tty_mutex);
31356 - if (tty->open_count == 0) {
31357 + if (local_read(&tty->open_count) == 0) {
31358 mutex_unlock(&tty->ipw_tty_mutex);
31359 return;
31360 }
31361 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
31362 return;
31363 }
31364
31365 - if (!tty->open_count) {
31366 + if (!local_read(&tty->open_count)) {
31367 mutex_unlock(&tty->ipw_tty_mutex);
31368 return;
31369 }
31370 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
31371 return -ENODEV;
31372
31373 mutex_lock(&tty->ipw_tty_mutex);
31374 - if (!tty->open_count) {
31375 + if (!local_read(&tty->open_count)) {
31376 mutex_unlock(&tty->ipw_tty_mutex);
31377 return -EINVAL;
31378 }
31379 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
31380 if (!tty)
31381 return -ENODEV;
31382
31383 - if (!tty->open_count)
31384 + if (!local_read(&tty->open_count))
31385 return -EINVAL;
31386
31387 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
31388 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
31389 if (!tty)
31390 return 0;
31391
31392 - if (!tty->open_count)
31393 + if (!local_read(&tty->open_count))
31394 return 0;
31395
31396 return tty->tx_bytes_queued;
31397 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
31398 if (!tty)
31399 return -ENODEV;
31400
31401 - if (!tty->open_count)
31402 + if (!local_read(&tty->open_count))
31403 return -EINVAL;
31404
31405 return get_control_lines(tty);
31406 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
31407 if (!tty)
31408 return -ENODEV;
31409
31410 - if (!tty->open_count)
31411 + if (!local_read(&tty->open_count))
31412 return -EINVAL;
31413
31414 return set_control_lines(tty, set, clear);
31415 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
31416 if (!tty)
31417 return -ENODEV;
31418
31419 - if (!tty->open_count)
31420 + if (!local_read(&tty->open_count))
31421 return -EINVAL;
31422
31423 /* FIXME: Exactly how is the tty object locked here .. */
31424 @@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
31425 against a parallel ioctl etc */
31426 mutex_lock(&ttyj->ipw_tty_mutex);
31427 }
31428 - while (ttyj->open_count)
31429 + while (local_read(&ttyj->open_count))
31430 do_ipw_close(ttyj);
31431 ipwireless_disassociate_network_ttys(network,
31432 ttyj->channel_idx);
31433 diff --git a/drivers/char/pty.c b/drivers/char/pty.c
31434 index 62f282e..e45c45c 100644
31435 --- a/drivers/char/pty.c
31436 +++ b/drivers/char/pty.c
31437 @@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
31438 register_sysctl_table(pty_root_table);
31439
31440 /* Now create the /dev/ptmx special device */
31441 + pax_open_kernel();
31442 tty_default_fops(&ptmx_fops);
31443 - ptmx_fops.open = ptmx_open;
31444 + *(void **)&ptmx_fops.open = ptmx_open;
31445 + pax_close_kernel();
31446
31447 cdev_init(&ptmx_cdev, &ptmx_fops);
31448 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
31449 diff --git a/drivers/char/random.c b/drivers/char/random.c
31450 index 3a19e2d..6ed09d3 100644
31451 --- a/drivers/char/random.c
31452 +++ b/drivers/char/random.c
31453 @@ -254,8 +254,13 @@
31454 /*
31455 * Configuration information
31456 */
31457 +#ifdef CONFIG_GRKERNSEC_RANDNET
31458 +#define INPUT_POOL_WORDS 512
31459 +#define OUTPUT_POOL_WORDS 128
31460 +#else
31461 #define INPUT_POOL_WORDS 128
31462 #define OUTPUT_POOL_WORDS 32
31463 +#endif
31464 #define SEC_XFER_SIZE 512
31465
31466 /*
31467 @@ -292,10 +297,17 @@ static struct poolinfo {
31468 int poolwords;
31469 int tap1, tap2, tap3, tap4, tap5;
31470 } poolinfo_table[] = {
31471 +#ifdef CONFIG_GRKERNSEC_RANDNET
31472 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31473 + { 512, 411, 308, 208, 104, 1 },
31474 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31475 + { 128, 103, 76, 51, 25, 1 },
31476 +#else
31477 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31478 { 128, 103, 76, 51, 25, 1 },
31479 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31480 { 32, 26, 20, 14, 7, 1 },
31481 +#endif
31482 #if 0
31483 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31484 { 2048, 1638, 1231, 819, 411, 1 },
31485 @@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31486 #include <linux/sysctl.h>
31487
31488 static int min_read_thresh = 8, min_write_thresh;
31489 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
31490 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31491 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31492 static char sysctl_bootid[16];
31493
31494 diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
31495 index 0e29a23..0efc2c2 100644
31496 --- a/drivers/char/rocket.c
31497 +++ b/drivers/char/rocket.c
31498 @@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
31499 struct rocket_ports tmp;
31500 int board;
31501
31502 + pax_track_stack();
31503 +
31504 if (!retports)
31505 return -EFAULT;
31506 memset(&tmp, 0, sizeof (tmp));
31507 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31508 index 8c262aa..4d3b058 100644
31509 --- a/drivers/char/sonypi.c
31510 +++ b/drivers/char/sonypi.c
31511 @@ -55,6 +55,7 @@
31512 #include <asm/uaccess.h>
31513 #include <asm/io.h>
31514 #include <asm/system.h>
31515 +#include <asm/local.h>
31516
31517 #include <linux/sonypi.h>
31518
31519 @@ -491,7 +492,7 @@ static struct sonypi_device {
31520 spinlock_t fifo_lock;
31521 wait_queue_head_t fifo_proc_list;
31522 struct fasync_struct *fifo_async;
31523 - int open_count;
31524 + local_t open_count;
31525 int model;
31526 struct input_dev *input_jog_dev;
31527 struct input_dev *input_key_dev;
31528 @@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31529 static int sonypi_misc_release(struct inode *inode, struct file *file)
31530 {
31531 mutex_lock(&sonypi_device.lock);
31532 - sonypi_device.open_count--;
31533 + local_dec(&sonypi_device.open_count);
31534 mutex_unlock(&sonypi_device.lock);
31535 return 0;
31536 }
31537 @@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31538 lock_kernel();
31539 mutex_lock(&sonypi_device.lock);
31540 /* Flush input queue on first open */
31541 - if (!sonypi_device.open_count)
31542 + if (!local_read(&sonypi_device.open_count))
31543 kfifo_reset(sonypi_device.fifo);
31544 - sonypi_device.open_count++;
31545 + local_inc(&sonypi_device.open_count);
31546 mutex_unlock(&sonypi_device.lock);
31547 unlock_kernel();
31548 return 0;
31549 diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
31550 index db6dcfa..13834cb 100644
31551 --- a/drivers/char/stallion.c
31552 +++ b/drivers/char/stallion.c
31553 @@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlport __user *arg)
31554 struct stlport stl_dummyport;
31555 struct stlport *portp;
31556
31557 + pax_track_stack();
31558 +
31559 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
31560 return -EFAULT;
31561 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
31562 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31563 index a0789f6..cea3902 100644
31564 --- a/drivers/char/tpm/tpm.c
31565 +++ b/drivers/char/tpm/tpm.c
31566 @@ -405,7 +405,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31567 chip->vendor.req_complete_val)
31568 goto out_recv;
31569
31570 - if ((status == chip->vendor.req_canceled)) {
31571 + if (status == chip->vendor.req_canceled) {
31572 dev_err(chip->dev, "Operation Canceled\n");
31573 rc = -ECANCELED;
31574 goto out;
31575 @@ -824,6 +824,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
31576
31577 struct tpm_chip *chip = dev_get_drvdata(dev);
31578
31579 + pax_track_stack();
31580 +
31581 tpm_cmd.header.in = tpm_readpubek_header;
31582 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
31583 "attempting to read the PUBEK");
31584 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
31585 index bf2170f..ce8cab9 100644
31586 --- a/drivers/char/tpm/tpm_bios.c
31587 +++ b/drivers/char/tpm/tpm_bios.c
31588 @@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31589 event = addr;
31590
31591 if ((event->event_type == 0 && event->event_size == 0) ||
31592 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31593 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31594 return NULL;
31595
31596 return addr;
31597 @@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31598 return NULL;
31599
31600 if ((event->event_type == 0 && event->event_size == 0) ||
31601 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31602 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31603 return NULL;
31604
31605 (*pos)++;
31606 @@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31607 int i;
31608
31609 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31610 - seq_putc(m, data[i]);
31611 + if (!seq_putc(m, data[i]))
31612 + return -EFAULT;
31613
31614 return 0;
31615 }
31616 @@ -409,8 +410,13 @@ static int read_log(struct tpm_bios_log *log)
31617 log->bios_event_log_end = log->bios_event_log + len;
31618
31619 virt = acpi_os_map_memory(start, len);
31620 + if (!virt) {
31621 + kfree(log->bios_event_log);
31622 + log->bios_event_log = NULL;
31623 + return -EFAULT;
31624 + }
31625
31626 - memcpy(log->bios_event_log, virt, len);
31627 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
31628
31629 acpi_os_unmap_memory(virt, len);
31630 return 0;
31631 diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
31632 index 123cedf..137edef 100644
31633 --- a/drivers/char/tty_io.c
31634 +++ b/drivers/char/tty_io.c
31635 @@ -1774,6 +1774,7 @@ got_driver:
31636
31637 if (IS_ERR(tty)) {
31638 mutex_unlock(&tty_mutex);
31639 + tty_driver_kref_put(driver);
31640 return PTR_ERR(tty);
31641 }
31642 }
31643 @@ -2603,8 +2604,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31644 return retval;
31645 }
31646
31647 +EXPORT_SYMBOL(tty_ioctl);
31648 +
31649 #ifdef CONFIG_COMPAT
31650 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31651 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
31652 unsigned long arg)
31653 {
31654 struct inode *inode = file->f_dentry->d_inode;
31655 @@ -2628,6 +2631,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31656
31657 return retval;
31658 }
31659 +
31660 +EXPORT_SYMBOL(tty_compat_ioctl);
31661 #endif
31662
31663 /*
31664 @@ -3073,7 +3078,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
31665
31666 void tty_default_fops(struct file_operations *fops)
31667 {
31668 - *fops = tty_fops;
31669 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
31670 }
31671
31672 /*
31673 diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
31674 index d814a3d..b55b9c9 100644
31675 --- a/drivers/char/tty_ldisc.c
31676 +++ b/drivers/char/tty_ldisc.c
31677 @@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *ld)
31678 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
31679 struct tty_ldisc_ops *ldo = ld->ops;
31680
31681 - ldo->refcount--;
31682 + atomic_dec(&ldo->refcount);
31683 module_put(ldo->owner);
31684 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31685
31686 @@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
31687 spin_lock_irqsave(&tty_ldisc_lock, flags);
31688 tty_ldiscs[disc] = new_ldisc;
31689 new_ldisc->num = disc;
31690 - new_ldisc->refcount = 0;
31691 + atomic_set(&new_ldisc->refcount, 0);
31692 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31693
31694 return ret;
31695 @@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
31696 return -EINVAL;
31697
31698 spin_lock_irqsave(&tty_ldisc_lock, flags);
31699 - if (tty_ldiscs[disc]->refcount)
31700 + if (atomic_read(&tty_ldiscs[disc]->refcount))
31701 ret = -EBUSY;
31702 else
31703 tty_ldiscs[disc] = NULL;
31704 @@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
31705 if (ldops) {
31706 ret = ERR_PTR(-EAGAIN);
31707 if (try_module_get(ldops->owner)) {
31708 - ldops->refcount++;
31709 + atomic_inc(&ldops->refcount);
31710 ret = ldops;
31711 }
31712 }
31713 @@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
31714 unsigned long flags;
31715
31716 spin_lock_irqsave(&tty_ldisc_lock, flags);
31717 - ldops->refcount--;
31718 + atomic_dec(&ldops->refcount);
31719 module_put(ldops->owner);
31720 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31721 }
31722 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31723 index a035ae3..c27fe2c 100644
31724 --- a/drivers/char/virtio_console.c
31725 +++ b/drivers/char/virtio_console.c
31726 @@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *buf, int count)
31727 * virtqueue, so we let the drivers do some boutique early-output thing. */
31728 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
31729 {
31730 - virtio_cons.put_chars = put_chars;
31731 + pax_open_kernel();
31732 + *(void **)&virtio_cons.put_chars = put_chars;
31733 + pax_close_kernel();
31734 return hvc_instantiate(0, 0, &virtio_cons);
31735 }
31736
31737 @@ -213,11 +215,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
31738 out_vq = vqs[1];
31739
31740 /* Start using the new console output. */
31741 - virtio_cons.get_chars = get_chars;
31742 - virtio_cons.put_chars = put_chars;
31743 - virtio_cons.notifier_add = notifier_add_vio;
31744 - virtio_cons.notifier_del = notifier_del_vio;
31745 - virtio_cons.notifier_hangup = notifier_del_vio;
31746 + pax_open_kernel();
31747 + *(void **)&virtio_cons.get_chars = get_chars;
31748 + *(void **)&virtio_cons.put_chars = put_chars;
31749 + *(void **)&virtio_cons.notifier_add = notifier_add_vio;
31750 + *(void **)&virtio_cons.notifier_del = notifier_del_vio;
31751 + *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
31752 + pax_close_kernel();
31753
31754 /* The first argument of hvc_alloc() is the virtual console number, so
31755 * we use zero. The second argument is the parameter for the
31756 diff --git a/drivers/char/vt.c b/drivers/char/vt.c
31757 index 0c80c68..53d59c1 100644
31758 --- a/drivers/char/vt.c
31759 +++ b/drivers/char/vt.c
31760 @@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
31761
31762 static void notify_write(struct vc_data *vc, unsigned int unicode)
31763 {
31764 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
31765 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
31766 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
31767 }
31768
31769 diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
31770 index 6351a26..999af95 100644
31771 --- a/drivers/char/vt_ioctl.c
31772 +++ b/drivers/char/vt_ioctl.c
31773 @@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31774 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
31775 return -EFAULT;
31776
31777 - if (!capable(CAP_SYS_TTY_CONFIG))
31778 - perm = 0;
31779 -
31780 switch (cmd) {
31781 case KDGKBENT:
31782 key_map = key_maps[s];
31783 @@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31784 val = (i ? K_HOLE : K_NOSUCHMAP);
31785 return put_user(val, &user_kbe->kb_value);
31786 case KDSKBENT:
31787 + if (!capable(CAP_SYS_TTY_CONFIG))
31788 + perm = 0;
31789 +
31790 if (!perm)
31791 return -EPERM;
31792 +
31793 if (!i && v == K_NOSUCHMAP) {
31794 /* deallocate map */
31795 key_map = key_maps[s];
31796 @@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31797 int i, j, k;
31798 int ret;
31799
31800 - if (!capable(CAP_SYS_TTY_CONFIG))
31801 - perm = 0;
31802 -
31803 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
31804 if (!kbs) {
31805 ret = -ENOMEM;
31806 @@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31807 kfree(kbs);
31808 return ((p && *p) ? -EOVERFLOW : 0);
31809 case KDSKBSENT:
31810 + if (!capable(CAP_SYS_TTY_CONFIG))
31811 + perm = 0;
31812 +
31813 if (!perm) {
31814 ret = -EPERM;
31815 goto reterr;
31816 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
31817 index c7ae026..1769c1d 100644
31818 --- a/drivers/cpufreq/cpufreq.c
31819 +++ b/drivers/cpufreq/cpufreq.c
31820 @@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct kobject *kobj)
31821 complete(&policy->kobj_unregister);
31822 }
31823
31824 -static struct sysfs_ops sysfs_ops = {
31825 +static const struct sysfs_ops sysfs_ops = {
31826 .show = show,
31827 .store = store,
31828 };
31829 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
31830 index 97b0038..2056670 100644
31831 --- a/drivers/cpuidle/sysfs.c
31832 +++ b/drivers/cpuidle/sysfs.c
31833 @@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
31834 return ret;
31835 }
31836
31837 -static struct sysfs_ops cpuidle_sysfs_ops = {
31838 +static const struct sysfs_ops cpuidle_sysfs_ops = {
31839 .show = cpuidle_show,
31840 .store = cpuidle_store,
31841 };
31842 @@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct kobject * kobj,
31843 return ret;
31844 }
31845
31846 -static struct sysfs_ops cpuidle_state_sysfs_ops = {
31847 +static const struct sysfs_ops cpuidle_state_sysfs_ops = {
31848 .show = cpuidle_state_show,
31849 };
31850
31851 @@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpuidle = {
31852 .release = cpuidle_state_sysfs_release,
31853 };
31854
31855 -static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31856 +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31857 {
31858 kobject_put(&device->kobjs[i]->kobj);
31859 wait_for_completion(&device->kobjs[i]->kobj_unregister);
31860 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
31861 index 5f753fc..0377ae9 100644
31862 --- a/drivers/crypto/hifn_795x.c
31863 +++ b/drivers/crypto/hifn_795x.c
31864 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
31865 0xCA, 0x34, 0x2B, 0x2E};
31866 struct scatterlist sg;
31867
31868 + pax_track_stack();
31869 +
31870 memset(src, 0, sizeof(src));
31871 memset(ctx.key, 0, sizeof(ctx.key));
31872
31873 diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
31874 index 71e6482..de8d96c 100644
31875 --- a/drivers/crypto/padlock-aes.c
31876 +++ b/drivers/crypto/padlock-aes.c
31877 @@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
31878 struct crypto_aes_ctx gen_aes;
31879 int cpu;
31880
31881 + pax_track_stack();
31882 +
31883 if (key_len % 8) {
31884 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
31885 return -EINVAL;
31886 diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
31887 index dcc4ab7..cc834bb 100644
31888 --- a/drivers/dma/ioat/dma.c
31889 +++ b/drivers/dma/ioat/dma.c
31890 @@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
31891 return entry->show(&chan->common, page);
31892 }
31893
31894 -struct sysfs_ops ioat_sysfs_ops = {
31895 +const struct sysfs_ops ioat_sysfs_ops = {
31896 .show = ioat_attr_show,
31897 };
31898
31899 diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
31900 index bbc3e78..f2db62c 100644
31901 --- a/drivers/dma/ioat/dma.h
31902 +++ b/drivers/dma/ioat/dma.h
31903 @@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
31904 unsigned long *phys_complete);
31905 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
31906 void ioat_kobject_del(struct ioatdma_device *device);
31907 -extern struct sysfs_ops ioat_sysfs_ops;
31908 +extern const struct sysfs_ops ioat_sysfs_ops;
31909 extern struct ioat_sysfs_entry ioat_version_attr;
31910 extern struct ioat_sysfs_entry ioat_cap_attr;
31911 #endif /* IOATDMA_H */
31912 diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
31913 index 9908c9e..3ceb0e5 100644
31914 --- a/drivers/dma/ioat/dma_v3.c
31915 +++ b/drivers/dma/ioat/dma_v3.c
31916 @@ -71,10 +71,10 @@
31917 /* provide a lookup table for setting the source address in the base or
31918 * extended descriptor of an xor or pq descriptor
31919 */
31920 -static const u8 xor_idx_to_desc __read_mostly = 0xd0;
31921 -static const u8 xor_idx_to_field[] __read_mostly = { 1, 4, 5, 6, 7, 0, 1, 2 };
31922 -static const u8 pq_idx_to_desc __read_mostly = 0xf8;
31923 -static const u8 pq_idx_to_field[] __read_mostly = { 1, 4, 5, 0, 1, 2, 4, 5 };
31924 +static const u8 xor_idx_to_desc = 0xd0;
31925 +static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
31926 +static const u8 pq_idx_to_desc = 0xf8;
31927 +static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
31928
31929 static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
31930 {
31931 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
31932 index 85c464a..afd1e73 100644
31933 --- a/drivers/edac/amd64_edac.c
31934 +++ b/drivers/edac/amd64_edac.c
31935 @@ -3099,7 +3099,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
31936 * PCI core identifies what devices are on a system during boot, and then
31937 * inquiry this table to see if this driver is for a given device found.
31938 */
31939 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
31940 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
31941 {
31942 .vendor = PCI_VENDOR_ID_AMD,
31943 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
31944 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
31945 index 2b95f1a..4f52793 100644
31946 --- a/drivers/edac/amd76x_edac.c
31947 +++ b/drivers/edac/amd76x_edac.c
31948 @@ -322,7 +322,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
31949 edac_mc_free(mci);
31950 }
31951
31952 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
31953 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
31954 {
31955 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31956 AMD762},
31957 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
31958 index d205d49..74c9672 100644
31959 --- a/drivers/edac/e752x_edac.c
31960 +++ b/drivers/edac/e752x_edac.c
31961 @@ -1282,7 +1282,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
31962 edac_mc_free(mci);
31963 }
31964
31965 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
31966 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
31967 {
31968 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31969 E7520},
31970 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
31971 index c7d11cc..c59c1ca 100644
31972 --- a/drivers/edac/e7xxx_edac.c
31973 +++ b/drivers/edac/e7xxx_edac.c
31974 @@ -526,7 +526,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
31975 edac_mc_free(mci);
31976 }
31977
31978 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
31979 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
31980 {
31981 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31982 E7205},
31983 diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
31984 index 5376457..5fdedbc 100644
31985 --- a/drivers/edac/edac_device_sysfs.c
31986 +++ b/drivers/edac/edac_device_sysfs.c
31987 @@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
31988 }
31989
31990 /* edac_dev file operations for an 'ctl_info' */
31991 -static struct sysfs_ops device_ctl_info_ops = {
31992 +static const struct sysfs_ops device_ctl_info_ops = {
31993 .show = edac_dev_ctl_info_show,
31994 .store = edac_dev_ctl_info_store
31995 };
31996 @@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(struct kobject *kobj,
31997 }
31998
31999 /* edac_dev file operations for an 'instance' */
32000 -static struct sysfs_ops device_instance_ops = {
32001 +static const struct sysfs_ops device_instance_ops = {
32002 .show = edac_dev_instance_show,
32003 .store = edac_dev_instance_store
32004 };
32005 @@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(struct kobject *kobj,
32006 }
32007
32008 /* edac_dev file operations for a 'block' */
32009 -static struct sysfs_ops device_block_ops = {
32010 +static const struct sysfs_ops device_block_ops = {
32011 .show = edac_dev_block_show,
32012 .store = edac_dev_block_store
32013 };
32014 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
32015 index e1d4ce0..88840e9 100644
32016 --- a/drivers/edac/edac_mc_sysfs.c
32017 +++ b/drivers/edac/edac_mc_sysfs.c
32018 @@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
32019 return -EIO;
32020 }
32021
32022 -static struct sysfs_ops csrowfs_ops = {
32023 +static const struct sysfs_ops csrowfs_ops = {
32024 .show = csrowdev_show,
32025 .store = csrowdev_store
32026 };
32027 @@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
32028 }
32029
32030 /* Intermediate show/store table */
32031 -static struct sysfs_ops mci_ops = {
32032 +static const struct sysfs_ops mci_ops = {
32033 .show = mcidev_show,
32034 .store = mcidev_store
32035 };
32036 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32037 index 422728c..d8d9c88 100644
32038 --- a/drivers/edac/edac_pci_sysfs.c
32039 +++ b/drivers/edac/edac_pci_sysfs.c
32040 @@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32041 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32042 static int edac_pci_poll_msec = 1000; /* one second workq period */
32043
32044 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32045 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32046 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32047 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32048
32049 static struct kobject *edac_pci_top_main_kobj;
32050 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32051 @@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
32052 }
32053
32054 /* fs_ops table */
32055 -static struct sysfs_ops pci_instance_ops = {
32056 +static const struct sysfs_ops pci_instance_ops = {
32057 .show = edac_pci_instance_show,
32058 .store = edac_pci_instance_store
32059 };
32060 @@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct kobject *kobj,
32061 return -EIO;
32062 }
32063
32064 -static struct sysfs_ops edac_pci_sysfs_ops = {
32065 +static const struct sysfs_ops edac_pci_sysfs_ops = {
32066 .show = edac_pci_dev_show,
32067 .store = edac_pci_dev_store
32068 };
32069 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32070 edac_printk(KERN_CRIT, EDAC_PCI,
32071 "Signaled System Error on %s\n",
32072 pci_name(dev));
32073 - atomic_inc(&pci_nonparity_count);
32074 + atomic_inc_unchecked(&pci_nonparity_count);
32075 }
32076
32077 if (status & (PCI_STATUS_PARITY)) {
32078 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32079 "Master Data Parity Error on %s\n",
32080 pci_name(dev));
32081
32082 - atomic_inc(&pci_parity_count);
32083 + atomic_inc_unchecked(&pci_parity_count);
32084 }
32085
32086 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32087 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32088 "Detected Parity Error on %s\n",
32089 pci_name(dev));
32090
32091 - atomic_inc(&pci_parity_count);
32092 + atomic_inc_unchecked(&pci_parity_count);
32093 }
32094 }
32095
32096 @@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32097 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32098 "Signaled System Error on %s\n",
32099 pci_name(dev));
32100 - atomic_inc(&pci_nonparity_count);
32101 + atomic_inc_unchecked(&pci_nonparity_count);
32102 }
32103
32104 if (status & (PCI_STATUS_PARITY)) {
32105 @@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32106 "Master Data Parity Error on "
32107 "%s\n", pci_name(dev));
32108
32109 - atomic_inc(&pci_parity_count);
32110 + atomic_inc_unchecked(&pci_parity_count);
32111 }
32112
32113 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32114 @@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32115 "Detected Parity Error on %s\n",
32116 pci_name(dev));
32117
32118 - atomic_inc(&pci_parity_count);
32119 + atomic_inc_unchecked(&pci_parity_count);
32120 }
32121 }
32122 }
32123 @@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
32124 if (!check_pci_errors)
32125 return;
32126
32127 - before_count = atomic_read(&pci_parity_count);
32128 + before_count = atomic_read_unchecked(&pci_parity_count);
32129
32130 /* scan all PCI devices looking for a Parity Error on devices and
32131 * bridges.
32132 @@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
32133 /* Only if operator has selected panic on PCI Error */
32134 if (edac_pci_get_panic_on_pe()) {
32135 /* If the count is different 'after' from 'before' */
32136 - if (before_count != atomic_read(&pci_parity_count))
32137 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32138 panic("EDAC: PCI Parity Error");
32139 }
32140 }
32141 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
32142 index 6c9a0f2..9c1cf7e 100644
32143 --- a/drivers/edac/i3000_edac.c
32144 +++ b/drivers/edac/i3000_edac.c
32145 @@ -471,7 +471,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
32146 edac_mc_free(mci);
32147 }
32148
32149 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
32150 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
32151 {
32152 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32153 I3000},
32154 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
32155 index fde4db9..fe108f9 100644
32156 --- a/drivers/edac/i3200_edac.c
32157 +++ b/drivers/edac/i3200_edac.c
32158 @@ -444,7 +444,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
32159 edac_mc_free(mci);
32160 }
32161
32162 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
32163 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
32164 {
32165 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32166 I3200},
32167 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
32168 index adc10a2..57d4ccf 100644
32169 --- a/drivers/edac/i5000_edac.c
32170 +++ b/drivers/edac/i5000_edac.c
32171 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
32172 *
32173 * The "E500P" device is the first device supported.
32174 */
32175 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
32176 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
32177 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
32178 .driver_data = I5000P},
32179
32180 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
32181 index 22db05a..b2b5503 100644
32182 --- a/drivers/edac/i5100_edac.c
32183 +++ b/drivers/edac/i5100_edac.c
32184 @@ -944,7 +944,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
32185 edac_mc_free(mci);
32186 }
32187
32188 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
32189 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
32190 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
32191 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
32192 { 0, }
32193 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
32194 index f99d106..f050710 100644
32195 --- a/drivers/edac/i5400_edac.c
32196 +++ b/drivers/edac/i5400_edac.c
32197 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
32198 *
32199 * The "E500P" device is the first device supported.
32200 */
32201 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
32202 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
32203 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
32204 {0,} /* 0 terminated list. */
32205 };
32206 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
32207 index 577760a..9ce16ce 100644
32208 --- a/drivers/edac/i82443bxgx_edac.c
32209 +++ b/drivers/edac/i82443bxgx_edac.c
32210 @@ -381,7 +381,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
32211
32212 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
32213
32214 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
32215 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
32216 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
32217 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
32218 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
32219 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
32220 index c0088ba..64a7b98 100644
32221 --- a/drivers/edac/i82860_edac.c
32222 +++ b/drivers/edac/i82860_edac.c
32223 @@ -271,7 +271,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
32224 edac_mc_free(mci);
32225 }
32226
32227 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
32228 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
32229 {
32230 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32231 I82860},
32232 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
32233 index b2d83b9..a34357b 100644
32234 --- a/drivers/edac/i82875p_edac.c
32235 +++ b/drivers/edac/i82875p_edac.c
32236 @@ -512,7 +512,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
32237 edac_mc_free(mci);
32238 }
32239
32240 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
32241 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
32242 {
32243 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32244 I82875P},
32245 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
32246 index 2eed3ea..87bbbd1 100644
32247 --- a/drivers/edac/i82975x_edac.c
32248 +++ b/drivers/edac/i82975x_edac.c
32249 @@ -586,7 +586,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
32250 edac_mc_free(mci);
32251 }
32252
32253 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
32254 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
32255 {
32256 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32257 I82975X
32258 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
32259 index 9900675..78ac2b6 100644
32260 --- a/drivers/edac/r82600_edac.c
32261 +++ b/drivers/edac/r82600_edac.c
32262 @@ -374,7 +374,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
32263 edac_mc_free(mci);
32264 }
32265
32266 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
32267 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
32268 {
32269 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
32270 },
32271 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
32272 index d4ec605..4cfec4e 100644
32273 --- a/drivers/edac/x38_edac.c
32274 +++ b/drivers/edac/x38_edac.c
32275 @@ -441,7 +441,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
32276 edac_mc_free(mci);
32277 }
32278
32279 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
32280 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
32281 {
32282 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32283 X38},
32284 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32285 index 3fc2ceb..daf098f 100644
32286 --- a/drivers/firewire/core-card.c
32287 +++ b/drivers/firewire/core-card.c
32288 @@ -558,7 +558,7 @@ void fw_card_release(struct kref *kref)
32289
32290 void fw_core_remove_card(struct fw_card *card)
32291 {
32292 - struct fw_card_driver dummy_driver = dummy_driver_template;
32293 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32294
32295 card->driver->update_phy_reg(card, 4,
32296 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32297 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32298 index 4560d8f..36db24a 100644
32299 --- a/drivers/firewire/core-cdev.c
32300 +++ b/drivers/firewire/core-cdev.c
32301 @@ -1141,8 +1141,7 @@ static int init_iso_resource(struct client *client,
32302 int ret;
32303
32304 if ((request->channels == 0 && request->bandwidth == 0) ||
32305 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32306 - request->bandwidth < 0)
32307 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32308 return -EINVAL;
32309
32310 r = kmalloc(sizeof(*r), GFP_KERNEL);
32311 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32312 index da628c7..cf54a2c 100644
32313 --- a/drivers/firewire/core-transaction.c
32314 +++ b/drivers/firewire/core-transaction.c
32315 @@ -36,6 +36,7 @@
32316 #include <linux/string.h>
32317 #include <linux/timer.h>
32318 #include <linux/types.h>
32319 +#include <linux/sched.h>
32320
32321 #include <asm/byteorder.h>
32322
32323 @@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
32324 struct transaction_callback_data d;
32325 struct fw_transaction t;
32326
32327 + pax_track_stack();
32328 +
32329 init_completion(&d.done);
32330 d.payload = payload;
32331 fw_send_request(card, &t, tcode, destination_id, generation, speed,
32332 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32333 index 7ff6e75..a2965d9 100644
32334 --- a/drivers/firewire/core.h
32335 +++ b/drivers/firewire/core.h
32336 @@ -86,6 +86,7 @@ struct fw_card_driver {
32337
32338 int (*stop_iso)(struct fw_iso_context *ctx);
32339 };
32340 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32341
32342 void fw_card_initialize(struct fw_card *card,
32343 const struct fw_card_driver *driver, struct device *device);
32344 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32345 index 3a2ccb0..82fd7c4 100644
32346 --- a/drivers/firmware/dmi_scan.c
32347 +++ b/drivers/firmware/dmi_scan.c
32348 @@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
32349 }
32350 }
32351 else {
32352 - /*
32353 - * no iounmap() for that ioremap(); it would be a no-op, but
32354 - * it's so early in setup that sucker gets confused into doing
32355 - * what it shouldn't if we actually call it.
32356 - */
32357 p = dmi_ioremap(0xF0000, 0x10000);
32358 if (p == NULL)
32359 goto error;
32360 @@ -667,7 +662,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32361 if (buf == NULL)
32362 return -1;
32363
32364 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32365 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32366
32367 iounmap(buf);
32368 return 0;
32369 diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
32370 index 9e4f59d..110e24e 100644
32371 --- a/drivers/firmware/edd.c
32372 +++ b/drivers/firmware/edd.c
32373 @@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
32374 return ret;
32375 }
32376
32377 -static struct sysfs_ops edd_attr_ops = {
32378 +static const struct sysfs_ops edd_attr_ops = {
32379 .show = edd_attr_show,
32380 };
32381
32382 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32383 index f4f709d..082f06e 100644
32384 --- a/drivers/firmware/efivars.c
32385 +++ b/drivers/firmware/efivars.c
32386 @@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
32387 return ret;
32388 }
32389
32390 -static struct sysfs_ops efivar_attr_ops = {
32391 +static const struct sysfs_ops efivar_attr_ops = {
32392 .show = efivar_attr_show,
32393 .store = efivar_attr_store,
32394 };
32395 diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
32396 index 051d1eb..0a5d4e7 100644
32397 --- a/drivers/firmware/iscsi_ibft.c
32398 +++ b/drivers/firmware/iscsi_ibft.c
32399 @@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struct kobject *kobj,
32400 return ret;
32401 }
32402
32403 -static struct sysfs_ops ibft_attr_ops = {
32404 +static const struct sysfs_ops ibft_attr_ops = {
32405 .show = ibft_show_attribute,
32406 };
32407
32408 diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
32409 index 56f9234..8c58c7b 100644
32410 --- a/drivers/firmware/memmap.c
32411 +++ b/drivers/firmware/memmap.c
32412 @@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
32413 NULL
32414 };
32415
32416 -static struct sysfs_ops memmap_attr_ops = {
32417 +static const struct sysfs_ops memmap_attr_ops = {
32418 .show = memmap_attr_show,
32419 };
32420
32421 diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
32422 index b16c9a8..2af7d3f 100644
32423 --- a/drivers/gpio/vr41xx_giu.c
32424 +++ b/drivers/gpio/vr41xx_giu.c
32425 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32426 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32427 maskl, pendl, maskh, pendh);
32428
32429 - atomic_inc(&irq_err_count);
32430 + atomic_inc_unchecked(&irq_err_count);
32431
32432 return -EINVAL;
32433 }
32434 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
32435 index bea6efc..3dc0f42 100644
32436 --- a/drivers/gpu/drm/drm_crtc.c
32437 +++ b/drivers/gpu/drm/drm_crtc.c
32438 @@ -1323,7 +1323,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32439 */
32440 if ((out_resp->count_modes >= mode_count) && mode_count) {
32441 copied = 0;
32442 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
32443 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
32444 list_for_each_entry(mode, &connector->modes, head) {
32445 drm_crtc_convert_to_umode(&u_mode, mode);
32446 if (copy_to_user(mode_ptr + copied,
32447 @@ -1338,8 +1338,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32448
32449 if ((out_resp->count_props >= props_count) && props_count) {
32450 copied = 0;
32451 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
32452 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
32453 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
32454 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
32455 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
32456 if (connector->property_ids[i] != 0) {
32457 if (put_user(connector->property_ids[i],
32458 @@ -1361,7 +1361,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32459
32460 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
32461 copied = 0;
32462 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
32463 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
32464 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
32465 if (connector->encoder_ids[i] != 0) {
32466 if (put_user(connector->encoder_ids[i],
32467 @@ -1513,7 +1513,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
32468 }
32469
32470 for (i = 0; i < crtc_req->count_connectors; i++) {
32471 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
32472 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
32473 if (get_user(out_id, &set_connectors_ptr[i])) {
32474 ret = -EFAULT;
32475 goto out;
32476 @@ -2118,7 +2118,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32477 out_resp->flags = property->flags;
32478
32479 if ((out_resp->count_values >= value_count) && value_count) {
32480 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
32481 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
32482 for (i = 0; i < value_count; i++) {
32483 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
32484 ret = -EFAULT;
32485 @@ -2131,7 +2131,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32486 if (property->flags & DRM_MODE_PROP_ENUM) {
32487 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
32488 copied = 0;
32489 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
32490 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
32491 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
32492
32493 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
32494 @@ -2154,7 +2154,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32495 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
32496 copied = 0;
32497 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
32498 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
32499 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
32500
32501 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
32502 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
32503 @@ -2226,7 +2226,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
32504 blob = obj_to_blob(obj);
32505
32506 if (out_resp->length == blob->length) {
32507 - blob_ptr = (void *)(unsigned long)out_resp->data;
32508 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
32509 if (copy_to_user(blob_ptr, blob->data, blob->length)){
32510 ret = -EFAULT;
32511 goto done;
32512 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32513 index 1b8745d..92fdbf6 100644
32514 --- a/drivers/gpu/drm/drm_crtc_helper.c
32515 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32516 @@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32517 struct drm_crtc *tmp;
32518 int crtc_mask = 1;
32519
32520 - WARN(!crtc, "checking null crtc?");
32521 + BUG_ON(!crtc);
32522
32523 dev = crtc->dev;
32524
32525 @@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
32526
32527 adjusted_mode = drm_mode_duplicate(dev, mode);
32528
32529 + pax_track_stack();
32530 +
32531 crtc->enabled = drm_helper_crtc_in_use(crtc);
32532
32533 if (!crtc->enabled)
32534 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32535 index 0e27d98..dec8768 100644
32536 --- a/drivers/gpu/drm/drm_drv.c
32537 +++ b/drivers/gpu/drm/drm_drv.c
32538 @@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
32539 char *kdata = NULL;
32540
32541 atomic_inc(&dev->ioctl_count);
32542 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32543 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32544 ++file_priv->ioctl_count;
32545
32546 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32547 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32548 index ba14553..182d0bb 100644
32549 --- a/drivers/gpu/drm/drm_fops.c
32550 +++ b/drivers/gpu/drm/drm_fops.c
32551 @@ -66,7 +66,7 @@ static int drm_setup(struct drm_device * dev)
32552 }
32553
32554 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32555 - atomic_set(&dev->counts[i], 0);
32556 + atomic_set_unchecked(&dev->counts[i], 0);
32557
32558 dev->sigdata.lock = NULL;
32559
32560 @@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct file *filp)
32561
32562 retcode = drm_open_helper(inode, filp, dev);
32563 if (!retcode) {
32564 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32565 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32566 spin_lock(&dev->count_lock);
32567 - if (!dev->open_count++) {
32568 + if (local_inc_return(&dev->open_count) == 1) {
32569 spin_unlock(&dev->count_lock);
32570 retcode = drm_setup(dev);
32571 goto out;
32572 @@ -435,7 +435,7 @@ int drm_release(struct inode *inode, struct file *filp)
32573
32574 lock_kernel();
32575
32576 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32577 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
32578
32579 if (dev->driver->preclose)
32580 dev->driver->preclose(dev, file_priv);
32581 @@ -447,7 +447,7 @@ int drm_release(struct inode *inode, struct file *filp)
32582 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32583 task_pid_nr(current),
32584 (long)old_encode_dev(file_priv->minor->device),
32585 - dev->open_count);
32586 + local_read(&dev->open_count));
32587
32588 /* if the master has gone away we can't do anything with the lock */
32589 if (file_priv->minor->master)
32590 @@ -524,9 +524,9 @@ int drm_release(struct inode *inode, struct file *filp)
32591 * End inline drm_release
32592 */
32593
32594 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32595 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32596 spin_lock(&dev->count_lock);
32597 - if (!--dev->open_count) {
32598 + if (local_dec_and_test(&dev->open_count)) {
32599 if (atomic_read(&dev->ioctl_count)) {
32600 DRM_ERROR("Device busy: %d\n",
32601 atomic_read(&dev->ioctl_count));
32602 diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
32603 index 8bf3770..7942280 100644
32604 --- a/drivers/gpu/drm/drm_gem.c
32605 +++ b/drivers/gpu/drm/drm_gem.c
32606 @@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
32607 spin_lock_init(&dev->object_name_lock);
32608 idr_init(&dev->object_name_idr);
32609 atomic_set(&dev->object_count, 0);
32610 - atomic_set(&dev->object_memory, 0);
32611 + atomic_set_unchecked(&dev->object_memory, 0);
32612 atomic_set(&dev->pin_count, 0);
32613 - atomic_set(&dev->pin_memory, 0);
32614 + atomic_set_unchecked(&dev->pin_memory, 0);
32615 atomic_set(&dev->gtt_count, 0);
32616 - atomic_set(&dev->gtt_memory, 0);
32617 + atomic_set_unchecked(&dev->gtt_memory, 0);
32618
32619 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
32620 if (!mm) {
32621 @@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
32622 goto fput;
32623 }
32624 atomic_inc(&dev->object_count);
32625 - atomic_add(obj->size, &dev->object_memory);
32626 + atomic_add_unchecked(obj->size, &dev->object_memory);
32627 return obj;
32628 fput:
32629 fput(obj->filp);
32630 @@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
32631
32632 fput(obj->filp);
32633 atomic_dec(&dev->object_count);
32634 - atomic_sub(obj->size, &dev->object_memory);
32635 + atomic_sub_unchecked(obj->size, &dev->object_memory);
32636 kfree(obj);
32637 }
32638 EXPORT_SYMBOL(drm_gem_object_free);
32639 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32640 index f0f6c6b..34af322 100644
32641 --- a/drivers/gpu/drm/drm_info.c
32642 +++ b/drivers/gpu/drm/drm_info.c
32643 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32644 struct drm_local_map *map;
32645 struct drm_map_list *r_list;
32646
32647 - /* Hardcoded from _DRM_FRAME_BUFFER,
32648 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32649 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32650 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32651 + static const char * const types[] = {
32652 + [_DRM_FRAME_BUFFER] = "FB",
32653 + [_DRM_REGISTERS] = "REG",
32654 + [_DRM_SHM] = "SHM",
32655 + [_DRM_AGP] = "AGP",
32656 + [_DRM_SCATTER_GATHER] = "SG",
32657 + [_DRM_CONSISTENT] = "PCI",
32658 + [_DRM_GEM] = "GEM" };
32659 const char *type;
32660 int i;
32661
32662 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32663 map = r_list->map;
32664 if (!map)
32665 continue;
32666 - if (map->type < 0 || map->type > 5)
32667 + if (map->type >= ARRAY_SIZE(types))
32668 type = "??";
32669 else
32670 type = types[map->type];
32671 @@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file *m, void* data)
32672 struct drm_device *dev = node->minor->dev;
32673
32674 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
32675 - seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
32676 + seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
32677 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
32678 - seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
32679 - seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
32680 + seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
32681 + seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
32682 seq_printf(m, "%d gtt total\n", dev->gtt_total);
32683 return 0;
32684 }
32685 @@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32686 mutex_lock(&dev->struct_mutex);
32687 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
32688 atomic_read(&dev->vma_count),
32689 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32690 + NULL, 0);
32691 +#else
32692 high_memory, (u64)virt_to_phys(high_memory));
32693 +#endif
32694
32695 list_for_each_entry(pt, &dev->vmalist, head) {
32696 vma = pt->vma;
32697 @@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, void *data)
32698 continue;
32699 seq_printf(m,
32700 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
32701 - pt->pid, vma->vm_start, vma->vm_end,
32702 + pt->pid,
32703 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32704 + 0, 0,
32705 +#else
32706 + vma->vm_start, vma->vm_end,
32707 +#endif
32708 vma->vm_flags & VM_READ ? 'r' : '-',
32709 vma->vm_flags & VM_WRITE ? 'w' : '-',
32710 vma->vm_flags & VM_EXEC ? 'x' : '-',
32711 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32712 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32713 vma->vm_flags & VM_IO ? 'i' : '-',
32714 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32715 + 0);
32716 +#else
32717 vma->vm_pgoff);
32718 +#endif
32719
32720 #if defined(__i386__)
32721 pgprot = pgprot_val(vma->vm_page_prot);
32722 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32723 index 282d9fd..71e5f11 100644
32724 --- a/drivers/gpu/drm/drm_ioc32.c
32725 +++ b/drivers/gpu/drm/drm_ioc32.c
32726 @@ -463,7 +463,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32727 request = compat_alloc_user_space(nbytes);
32728 if (!access_ok(VERIFY_WRITE, request, nbytes))
32729 return -EFAULT;
32730 - list = (struct drm_buf_desc *) (request + 1);
32731 + list = (struct drm_buf_desc __user *) (request + 1);
32732
32733 if (__put_user(count, &request->count)
32734 || __put_user(list, &request->list))
32735 @@ -525,7 +525,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32736 request = compat_alloc_user_space(nbytes);
32737 if (!access_ok(VERIFY_WRITE, request, nbytes))
32738 return -EFAULT;
32739 - list = (struct drm_buf_pub *) (request + 1);
32740 + list = (struct drm_buf_pub __user *) (request + 1);
32741
32742 if (__put_user(count, &request->count)
32743 || __put_user(list, &request->list))
32744 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32745 index 9b9ff46..4ea724c 100644
32746 --- a/drivers/gpu/drm/drm_ioctl.c
32747 +++ b/drivers/gpu/drm/drm_ioctl.c
32748 @@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32749 stats->data[i].value =
32750 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32751 else
32752 - stats->data[i].value = atomic_read(&dev->counts[i]);
32753 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32754 stats->data[i].type = dev->types[i];
32755 }
32756
32757 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32758 index e2f70a5..c703e86 100644
32759 --- a/drivers/gpu/drm/drm_lock.c
32760 +++ b/drivers/gpu/drm/drm_lock.c
32761 @@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32762 if (drm_lock_take(&master->lock, lock->context)) {
32763 master->lock.file_priv = file_priv;
32764 master->lock.lock_time = jiffies;
32765 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32766 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32767 break; /* Got lock */
32768 }
32769
32770 @@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32771 return -EINVAL;
32772 }
32773
32774 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32775 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32776
32777 /* kernel_context_switch isn't used by any of the x86 drm
32778 * modules but is required by the Sparc driver.
32779 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32780 index 7d1d88c..b9131b2 100644
32781 --- a/drivers/gpu/drm/i810/i810_dma.c
32782 +++ b/drivers/gpu/drm/i810/i810_dma.c
32783 @@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32784 dma->buflist[vertex->idx],
32785 vertex->discard, vertex->used);
32786
32787 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32788 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32789 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32790 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32791 sarea_priv->last_enqueue = dev_priv->counter - 1;
32792 sarea_priv->last_dispatch = (int)hw_status[5];
32793
32794 @@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32795 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32796 mc->last_render);
32797
32798 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32799 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32800 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32801 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32802 sarea_priv->last_enqueue = dev_priv->counter - 1;
32803 sarea_priv->last_dispatch = (int)hw_status[5];
32804
32805 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32806 index 21e2691..7321edd 100644
32807 --- a/drivers/gpu/drm/i810/i810_drv.h
32808 +++ b/drivers/gpu/drm/i810/i810_drv.h
32809 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32810 int page_flipping;
32811
32812 wait_queue_head_t irq_queue;
32813 - atomic_t irq_received;
32814 - atomic_t irq_emitted;
32815 + atomic_unchecked_t irq_received;
32816 + atomic_unchecked_t irq_emitted;
32817
32818 int front_offset;
32819 } drm_i810_private_t;
32820 diff --git a/drivers/gpu/drm/i830/i830_drv.h b/drivers/gpu/drm/i830/i830_drv.h
32821 index da82afe..48a45de 100644
32822 --- a/drivers/gpu/drm/i830/i830_drv.h
32823 +++ b/drivers/gpu/drm/i830/i830_drv.h
32824 @@ -115,8 +115,8 @@ typedef struct drm_i830_private {
32825 int page_flipping;
32826
32827 wait_queue_head_t irq_queue;
32828 - atomic_t irq_received;
32829 - atomic_t irq_emitted;
32830 + atomic_unchecked_t irq_received;
32831 + atomic_unchecked_t irq_emitted;
32832
32833 int use_mi_batchbuffer_start;
32834
32835 diff --git a/drivers/gpu/drm/i830/i830_irq.c b/drivers/gpu/drm/i830/i830_irq.c
32836 index 91ec2bb..6f21fab 100644
32837 --- a/drivers/gpu/drm/i830/i830_irq.c
32838 +++ b/drivers/gpu/drm/i830/i830_irq.c
32839 @@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
32840
32841 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
32842
32843 - atomic_inc(&dev_priv->irq_received);
32844 + atomic_inc_unchecked(&dev_priv->irq_received);
32845 wake_up_interruptible(&dev_priv->irq_queue);
32846
32847 return IRQ_HANDLED;
32848 @@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_device * dev)
32849
32850 DRM_DEBUG("%s\n", __func__);
32851
32852 - atomic_inc(&dev_priv->irq_emitted);
32853 + atomic_inc_unchecked(&dev_priv->irq_emitted);
32854
32855 BEGIN_LP_RING(2);
32856 OUT_RING(0);
32857 OUT_RING(GFX_OP_USER_INTERRUPT);
32858 ADVANCE_LP_RING();
32859
32860 - return atomic_read(&dev_priv->irq_emitted);
32861 + return atomic_read_unchecked(&dev_priv->irq_emitted);
32862 }
32863
32864 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32865 @@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32866
32867 DRM_DEBUG("%s\n", __func__);
32868
32869 - if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32870 + if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32871 return 0;
32872
32873 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
32874 @@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32875
32876 for (;;) {
32877 __set_current_state(TASK_INTERRUPTIBLE);
32878 - if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32879 + if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32880 break;
32881 if ((signed)(end - jiffies) <= 0) {
32882 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
32883 @@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct drm_device * dev)
32884 I830_WRITE16(I830REG_HWSTAM, 0xffff);
32885 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
32886 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
32887 - atomic_set(&dev_priv->irq_received, 0);
32888 - atomic_set(&dev_priv->irq_emitted, 0);
32889 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32890 + atomic_set_unchecked(&dev_priv->irq_emitted, 0);
32891 init_waitqueue_head(&dev_priv->irq_queue);
32892 }
32893
32894 diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
32895 index 288fc50..c6092055 100644
32896 --- a/drivers/gpu/drm/i915/dvo.h
32897 +++ b/drivers/gpu/drm/i915/dvo.h
32898 @@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
32899 *
32900 * \return singly-linked list of modes or NULL if no modes found.
32901 */
32902 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
32903 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
32904
32905 /**
32906 * Clean up driver-specific bits of the output
32907 */
32908 - void (*destroy) (struct intel_dvo_device *dvo);
32909 + void (* const destroy) (struct intel_dvo_device *dvo);
32910
32911 /**
32912 * Debugging hook to dump device registers to log file
32913 */
32914 - void (*dump_regs)(struct intel_dvo_device *dvo);
32915 + void (* const dump_regs)(struct intel_dvo_device *dvo);
32916 };
32917
32918 -extern struct intel_dvo_dev_ops sil164_ops;
32919 -extern struct intel_dvo_dev_ops ch7xxx_ops;
32920 -extern struct intel_dvo_dev_ops ivch_ops;
32921 -extern struct intel_dvo_dev_ops tfp410_ops;
32922 -extern struct intel_dvo_dev_ops ch7017_ops;
32923 +extern const struct intel_dvo_dev_ops sil164_ops;
32924 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
32925 +extern const struct intel_dvo_dev_ops ivch_ops;
32926 +extern const struct intel_dvo_dev_ops tfp410_ops;
32927 +extern const struct intel_dvo_dev_ops ch7017_ops;
32928
32929 #endif /* _INTEL_DVO_H */
32930 diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
32931 index 621815b..499d82e 100644
32932 --- a/drivers/gpu/drm/i915/dvo_ch7017.c
32933 +++ b/drivers/gpu/drm/i915/dvo_ch7017.c
32934 @@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_dvo_device *dvo)
32935 }
32936 }
32937
32938 -struct intel_dvo_dev_ops ch7017_ops = {
32939 +const struct intel_dvo_dev_ops ch7017_ops = {
32940 .init = ch7017_init,
32941 .detect = ch7017_detect,
32942 .mode_valid = ch7017_mode_valid,
32943 diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
32944 index a9b8962..ac769ba 100644
32945 --- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
32946 +++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
32947 @@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_dvo_device *dvo)
32948 }
32949 }
32950
32951 -struct intel_dvo_dev_ops ch7xxx_ops = {
32952 +const struct intel_dvo_dev_ops ch7xxx_ops = {
32953 .init = ch7xxx_init,
32954 .detect = ch7xxx_detect,
32955 .mode_valid = ch7xxx_mode_valid,
32956 diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
32957 index aa176f9..ed2930c 100644
32958 --- a/drivers/gpu/drm/i915/dvo_ivch.c
32959 +++ b/drivers/gpu/drm/i915/dvo_ivch.c
32960 @@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dvo_device *dvo)
32961 }
32962 }
32963
32964 -struct intel_dvo_dev_ops ivch_ops= {
32965 +const struct intel_dvo_dev_ops ivch_ops= {
32966 .init = ivch_init,
32967 .dpms = ivch_dpms,
32968 .save = ivch_save,
32969 diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
32970 index e1c1f73..7dbebcf 100644
32971 --- a/drivers/gpu/drm/i915/dvo_sil164.c
32972 +++ b/drivers/gpu/drm/i915/dvo_sil164.c
32973 @@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_dvo_device *dvo)
32974 }
32975 }
32976
32977 -struct intel_dvo_dev_ops sil164_ops = {
32978 +const struct intel_dvo_dev_ops sil164_ops = {
32979 .init = sil164_init,
32980 .detect = sil164_detect,
32981 .mode_valid = sil164_mode_valid,
32982 diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
32983 index 16dce84..7e1b6f8 100644
32984 --- a/drivers/gpu/drm/i915/dvo_tfp410.c
32985 +++ b/drivers/gpu/drm/i915/dvo_tfp410.c
32986 @@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_dvo_device *dvo)
32987 }
32988 }
32989
32990 -struct intel_dvo_dev_ops tfp410_ops = {
32991 +const struct intel_dvo_dev_ops tfp410_ops = {
32992 .init = tfp410_init,
32993 .detect = tfp410_detect,
32994 .mode_valid = tfp410_mode_valid,
32995 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32996 index 7e859d6..7d1cf2b 100644
32997 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32998 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32999 @@ -192,7 +192,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33000 I915_READ(GTIMR));
33001 }
33002 seq_printf(m, "Interrupts received: %d\n",
33003 - atomic_read(&dev_priv->irq_received));
33004 + atomic_read_unchecked(&dev_priv->irq_received));
33005 if (dev_priv->hw_status_page != NULL) {
33006 seq_printf(m, "Current sequence: %d\n",
33007 i915_get_gem_seqno(dev));
33008 diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
33009 index 5449239..7e4f68d 100644
33010 --- a/drivers/gpu/drm/i915/i915_drv.c
33011 +++ b/drivers/gpu/drm/i915/i915_drv.c
33012 @@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
33013 return i915_resume(dev);
33014 }
33015
33016 -static struct vm_operations_struct i915_gem_vm_ops = {
33017 +static const struct vm_operations_struct i915_gem_vm_ops = {
33018 .fault = i915_gem_fault,
33019 .open = drm_gem_vm_open,
33020 .close = drm_gem_vm_close,
33021 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33022 index 97163f7..c24c7c7 100644
33023 --- a/drivers/gpu/drm/i915/i915_drv.h
33024 +++ b/drivers/gpu/drm/i915/i915_drv.h
33025 @@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
33026 /* display clock increase/decrease */
33027 /* pll clock increase/decrease */
33028 /* clock gating init */
33029 -};
33030 +} __no_const;
33031
33032 typedef struct drm_i915_private {
33033 struct drm_device *dev;
33034 @@ -197,7 +197,7 @@ typedef struct drm_i915_private {
33035 int page_flipping;
33036
33037 wait_queue_head_t irq_queue;
33038 - atomic_t irq_received;
33039 + atomic_unchecked_t irq_received;
33040 /** Protects user_irq_refcount and irq_mask_reg */
33041 spinlock_t user_irq_lock;
33042 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
33043 diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
33044 index 27a3074..eb3f959 100644
33045 --- a/drivers/gpu/drm/i915/i915_gem.c
33046 +++ b/drivers/gpu/drm/i915/i915_gem.c
33047 @@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
33048
33049 args->aper_size = dev->gtt_total;
33050 args->aper_available_size = (args->aper_size -
33051 - atomic_read(&dev->pin_memory));
33052 + atomic_read_unchecked(&dev->pin_memory));
33053
33054 return 0;
33055 }
33056 @@ -2058,7 +2058,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
33057
33058 if (obj_priv->gtt_space) {
33059 atomic_dec(&dev->gtt_count);
33060 - atomic_sub(obj->size, &dev->gtt_memory);
33061 + atomic_sub_unchecked(obj->size, &dev->gtt_memory);
33062
33063 drm_mm_put_block(obj_priv->gtt_space);
33064 obj_priv->gtt_space = NULL;
33065 @@ -2701,7 +2701,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
33066 goto search_free;
33067 }
33068 atomic_inc(&dev->gtt_count);
33069 - atomic_add(obj->size, &dev->gtt_memory);
33070 + atomic_add_unchecked(obj->size, &dev->gtt_memory);
33071
33072 /* Assert that the object is not currently in any GPU domain. As it
33073 * wasn't in the GTT, there shouldn't be any way it could have been in
33074 @@ -3755,9 +3755,9 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
33075 "%d/%d gtt bytes\n",
33076 atomic_read(&dev->object_count),
33077 atomic_read(&dev->pin_count),
33078 - atomic_read(&dev->object_memory),
33079 - atomic_read(&dev->pin_memory),
33080 - atomic_read(&dev->gtt_memory),
33081 + atomic_read_unchecked(&dev->object_memory),
33082 + atomic_read_unchecked(&dev->pin_memory),
33083 + atomic_read_unchecked(&dev->gtt_memory),
33084 dev->gtt_total);
33085 }
33086 goto err;
33087 @@ -3989,7 +3989,7 @@ i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment)
33088 */
33089 if (obj_priv->pin_count == 1) {
33090 atomic_inc(&dev->pin_count);
33091 - atomic_add(obj->size, &dev->pin_memory);
33092 + atomic_add_unchecked(obj->size, &dev->pin_memory);
33093 if (!obj_priv->active &&
33094 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
33095 !list_empty(&obj_priv->list))
33096 @@ -4022,7 +4022,7 @@ i915_gem_object_unpin(struct drm_gem_object *obj)
33097 list_move_tail(&obj_priv->list,
33098 &dev_priv->mm.inactive_list);
33099 atomic_dec(&dev->pin_count);
33100 - atomic_sub(obj->size, &dev->pin_memory);
33101 + atomic_sub_unchecked(obj->size, &dev->pin_memory);
33102 }
33103 i915_verify_inactive(dev, __FILE__, __LINE__);
33104 }
33105 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33106 index 63f28ad..f5469da 100644
33107 --- a/drivers/gpu/drm/i915/i915_irq.c
33108 +++ b/drivers/gpu/drm/i915/i915_irq.c
33109 @@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
33110 int irq_received;
33111 int ret = IRQ_NONE;
33112
33113 - atomic_inc(&dev_priv->irq_received);
33114 + atomic_inc_unchecked(&dev_priv->irq_received);
33115
33116 if (IS_IGDNG(dev))
33117 return igdng_irq_handler(dev);
33118 @@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct drm_device * dev)
33119 {
33120 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33121
33122 - atomic_set(&dev_priv->irq_received, 0);
33123 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33124
33125 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
33126 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
33127 diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
33128 index 5d9c6a7..d1b0e29 100644
33129 --- a/drivers/gpu/drm/i915/intel_sdvo.c
33130 +++ b/drivers/gpu/drm/i915/intel_sdvo.c
33131 @@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
33132 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
33133
33134 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
33135 - intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33136 + pax_open_kernel();
33137 + *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33138 + pax_close_kernel();
33139
33140 /* Read the regs to test if we can talk to the device */
33141 for (i = 0; i < 0x40; i++) {
33142 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33143 index be6c6b9..8615d9c 100644
33144 --- a/drivers/gpu/drm/mga/mga_drv.h
33145 +++ b/drivers/gpu/drm/mga/mga_drv.h
33146 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33147 u32 clear_cmd;
33148 u32 maccess;
33149
33150 - atomic_t vbl_received; /**< Number of vblanks received. */
33151 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33152 wait_queue_head_t fence_queue;
33153 - atomic_t last_fence_retired;
33154 + atomic_unchecked_t last_fence_retired;
33155 u32 next_fence_to_post;
33156
33157 unsigned int fb_cpp;
33158 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33159 index daa6041..a28a5da 100644
33160 --- a/drivers/gpu/drm/mga/mga_irq.c
33161 +++ b/drivers/gpu/drm/mga/mga_irq.c
33162 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33163 if (crtc != 0)
33164 return 0;
33165
33166 - return atomic_read(&dev_priv->vbl_received);
33167 + return atomic_read_unchecked(&dev_priv->vbl_received);
33168 }
33169
33170
33171 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33172 /* VBLANK interrupt */
33173 if (status & MGA_VLINEPEN) {
33174 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33175 - atomic_inc(&dev_priv->vbl_received);
33176 + atomic_inc_unchecked(&dev_priv->vbl_received);
33177 drm_handle_vblank(dev, 0);
33178 handled = 1;
33179 }
33180 @@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33181 MGA_WRITE(MGA_PRIMEND, prim_end);
33182 }
33183
33184 - atomic_inc(&dev_priv->last_fence_retired);
33185 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33186 DRM_WAKEUP(&dev_priv->fence_queue);
33187 handled = 1;
33188 }
33189 @@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
33190 * using fences.
33191 */
33192 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33193 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33194 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33195 - *sequence) <= (1 << 23)));
33196
33197 *sequence = cur_fence;
33198 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33199 index 4c39a40..b22a9ea 100644
33200 --- a/drivers/gpu/drm/r128/r128_cce.c
33201 +++ b/drivers/gpu/drm/r128/r128_cce.c
33202 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
33203
33204 /* GH: Simple idle check.
33205 */
33206 - atomic_set(&dev_priv->idle_count, 0);
33207 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33208
33209 /* We don't support anything other than bus-mastering ring mode,
33210 * but the ring can be in either AGP or PCI space for the ring
33211 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33212 index 3c60829..4faf484 100644
33213 --- a/drivers/gpu/drm/r128/r128_drv.h
33214 +++ b/drivers/gpu/drm/r128/r128_drv.h
33215 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33216 int is_pci;
33217 unsigned long cce_buffers_offset;
33218
33219 - atomic_t idle_count;
33220 + atomic_unchecked_t idle_count;
33221
33222 int page_flipping;
33223 int current_page;
33224 u32 crtc_offset;
33225 u32 crtc_offset_cntl;
33226
33227 - atomic_t vbl_received;
33228 + atomic_unchecked_t vbl_received;
33229
33230 u32 color_fmt;
33231 unsigned int front_offset;
33232 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33233 index 69810fb..97bf17a 100644
33234 --- a/drivers/gpu/drm/r128/r128_irq.c
33235 +++ b/drivers/gpu/drm/r128/r128_irq.c
33236 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33237 if (crtc != 0)
33238 return 0;
33239
33240 - return atomic_read(&dev_priv->vbl_received);
33241 + return atomic_read_unchecked(&dev_priv->vbl_received);
33242 }
33243
33244 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33245 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33246 /* VBLANK interrupt */
33247 if (status & R128_CRTC_VBLANK_INT) {
33248 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33249 - atomic_inc(&dev_priv->vbl_received);
33250 + atomic_inc_unchecked(&dev_priv->vbl_received);
33251 drm_handle_vblank(dev, 0);
33252 return IRQ_HANDLED;
33253 }
33254 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33255 index af2665c..51922d2 100644
33256 --- a/drivers/gpu/drm/r128/r128_state.c
33257 +++ b/drivers/gpu/drm/r128/r128_state.c
33258 @@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_private_t * dev_priv,
33259
33260 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
33261 {
33262 - if (atomic_read(&dev_priv->idle_count) == 0) {
33263 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
33264 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33265 } else {
33266 - atomic_set(&dev_priv->idle_count, 0);
33267 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33268 }
33269 }
33270
33271 diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
33272 index dd72b91..8644b3c 100644
33273 --- a/drivers/gpu/drm/radeon/atom.c
33274 +++ b/drivers/gpu/drm/radeon/atom.c
33275 @@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
33276 char name[512];
33277 int i;
33278
33279 + pax_track_stack();
33280 +
33281 ctx->card = card;
33282 ctx->bios = bios;
33283
33284 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33285 index 0d79577..efaa7a5 100644
33286 --- a/drivers/gpu/drm/radeon/mkregtable.c
33287 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33288 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33289 regex_t mask_rex;
33290 regmatch_t match[4];
33291 char buf[1024];
33292 - size_t end;
33293 + long end;
33294 int len;
33295 int done = 0;
33296 int r;
33297 unsigned o;
33298 struct offset *offset;
33299 char last_reg_s[10];
33300 - int last_reg;
33301 + unsigned long last_reg;
33302
33303 if (regcomp
33304 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33305 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
33306 index 6735213..38c2c67 100644
33307 --- a/drivers/gpu/drm/radeon/radeon.h
33308 +++ b/drivers/gpu/drm/radeon/radeon.h
33309 @@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device *rdev);
33310 */
33311 struct radeon_fence_driver {
33312 uint32_t scratch_reg;
33313 - atomic_t seq;
33314 + atomic_unchecked_t seq;
33315 uint32_t last_seq;
33316 unsigned long count_timeout;
33317 wait_queue_head_t queue;
33318 @@ -640,7 +640,7 @@ struct radeon_asic {
33319 uint32_t offset, uint32_t obj_size);
33320 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
33321 void (*bandwidth_update)(struct radeon_device *rdev);
33322 -};
33323 +} __no_const;
33324
33325 /*
33326 * Asic structures
33327 diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
33328 index 4e928b9..d8b6008 100644
33329 --- a/drivers/gpu/drm/radeon/radeon_atombios.c
33330 +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
33331 @@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
33332 bool linkb;
33333 struct radeon_i2c_bus_rec ddc_bus;
33334
33335 + pax_track_stack();
33336 +
33337 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33338
33339 if (data_offset == 0)
33340 @@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
33341 }
33342 }
33343
33344 -struct bios_connector {
33345 +static struct bios_connector {
33346 bool valid;
33347 uint16_t line_mux;
33348 uint16_t devices;
33349 int connector_type;
33350 struct radeon_i2c_bus_rec ddc_bus;
33351 -};
33352 +} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33353
33354 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33355 drm_device
33356 @@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33357 uint8_t dac;
33358 union atom_supported_devices *supported_devices;
33359 int i, j;
33360 - struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33361
33362 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33363
33364 diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
33365 index 083a181..ccccae0 100644
33366 --- a/drivers/gpu/drm/radeon/radeon_display.c
33367 +++ b/drivers/gpu/drm/radeon/radeon_display.c
33368 @@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pll *pll,
33369
33370 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
33371 error = freq - current_freq;
33372 - error = error < 0 ? 0xffffffff : error;
33373 + error = (int32_t)error < 0 ? 0xffffffff : error;
33374 } else
33375 error = abs(current_freq - freq);
33376 vco_diff = abs(vco - best_vco);
33377 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33378 index 76e4070..193fa7f 100644
33379 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33380 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33381 @@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
33382
33383 /* SW interrupt */
33384 wait_queue_head_t swi_queue;
33385 - atomic_t swi_emitted;
33386 + atomic_unchecked_t swi_emitted;
33387 int vblank_crtc;
33388 uint32_t irq_enable_reg;
33389 uint32_t r500_disp_irq_reg;
33390 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
33391 index 3beb26d..6ce9c4a 100644
33392 --- a/drivers/gpu/drm/radeon/radeon_fence.c
33393 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
33394 @@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
33395 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
33396 return 0;
33397 }
33398 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
33399 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
33400 if (!rdev->cp.ready) {
33401 /* FIXME: cp is not running assume everythings is done right
33402 * away
33403 @@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
33404 return r;
33405 }
33406 WREG32(rdev->fence_drv.scratch_reg, 0);
33407 - atomic_set(&rdev->fence_drv.seq, 0);
33408 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
33409 INIT_LIST_HEAD(&rdev->fence_drv.created);
33410 INIT_LIST_HEAD(&rdev->fence_drv.emited);
33411 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
33412 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33413 index a1bf11d..4a123c0 100644
33414 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33415 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33416 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33417 request = compat_alloc_user_space(sizeof(*request));
33418 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33419 || __put_user(req32.param, &request->param)
33420 - || __put_user((void __user *)(unsigned long)req32.value,
33421 + || __put_user((unsigned long)req32.value,
33422 &request->value))
33423 return -EFAULT;
33424
33425 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33426 index b79ecc4..8dab92d 100644
33427 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33428 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33429 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33430 unsigned int ret;
33431 RING_LOCALS;
33432
33433 - atomic_inc(&dev_priv->swi_emitted);
33434 - ret = atomic_read(&dev_priv->swi_emitted);
33435 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33436 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33437
33438 BEGIN_RING(4);
33439 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33440 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33441 drm_radeon_private_t *dev_priv =
33442 (drm_radeon_private_t *) dev->dev_private;
33443
33444 - atomic_set(&dev_priv->swi_emitted, 0);
33445 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33446 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33447
33448 dev->max_vblank_count = 0x001fffff;
33449 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33450 index 4747910..48ca4b3 100644
33451 --- a/drivers/gpu/drm/radeon/radeon_state.c
33452 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33453 @@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33454 {
33455 drm_radeon_private_t *dev_priv = dev->dev_private;
33456 drm_radeon_getparam_t *param = data;
33457 - int value;
33458 + int value = 0;
33459
33460 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33461
33462 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33463 index 1381e06..0e53b17 100644
33464 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33465 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33466 @@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_device *rdev)
33467 DRM_INFO("radeon: ttm finalized\n");
33468 }
33469
33470 -static struct vm_operations_struct radeon_ttm_vm_ops;
33471 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
33472 -
33473 -static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33474 -{
33475 - struct ttm_buffer_object *bo;
33476 - int r;
33477 -
33478 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
33479 - if (bo == NULL) {
33480 - return VM_FAULT_NOPAGE;
33481 - }
33482 - r = ttm_vm_ops->fault(vma, vmf);
33483 - return r;
33484 -}
33485 -
33486 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33487 {
33488 struct drm_file *file_priv;
33489 struct radeon_device *rdev;
33490 - int r;
33491
33492 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
33493 return drm_mmap(filp, vma);
33494 @@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33495
33496 file_priv = (struct drm_file *)filp->private_data;
33497 rdev = file_priv->minor->dev->dev_private;
33498 - if (rdev == NULL) {
33499 + if (!rdev)
33500 return -EINVAL;
33501 - }
33502 - r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33503 - if (unlikely(r != 0)) {
33504 - return r;
33505 - }
33506 - if (unlikely(ttm_vm_ops == NULL)) {
33507 - ttm_vm_ops = vma->vm_ops;
33508 - radeon_ttm_vm_ops = *ttm_vm_ops;
33509 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33510 - }
33511 - vma->vm_ops = &radeon_ttm_vm_ops;
33512 - return 0;
33513 + return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33514 }
33515
33516
33517 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33518 index b12ff76..0bd0c6e 100644
33519 --- a/drivers/gpu/drm/radeon/rs690.c
33520 +++ b/drivers/gpu/drm/radeon/rs690.c
33521 @@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33522 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33523 rdev->pm.sideport_bandwidth.full)
33524 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33525 - read_delay_latency.full = rfixed_const(370 * 800 * 1000);
33526 + read_delay_latency.full = rfixed_const(800 * 1000);
33527 read_delay_latency.full = rfixed_div(read_delay_latency,
33528 rdev->pm.igp_sideport_mclk);
33529 + a.full = rfixed_const(370);
33530 + read_delay_latency.full = rfixed_mul(read_delay_latency, a);
33531 } else {
33532 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33533 rdev->pm.k8_bandwidth.full)
33534 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
33535 index 0ed436e..e6e7ce3 100644
33536 --- a/drivers/gpu/drm/ttm/ttm_bo.c
33537 +++ b/drivers/gpu/drm/ttm/ttm_bo.c
33538 @@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_attrs[] = {
33539 NULL
33540 };
33541
33542 -static struct sysfs_ops ttm_bo_global_ops = {
33543 +static const struct sysfs_ops ttm_bo_global_ops = {
33544 .show = &ttm_bo_global_show
33545 };
33546
33547 diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33548 index 1c040d0..f9e4af8 100644
33549 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
33550 +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33551 @@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33552 {
33553 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
33554 vma->vm_private_data;
33555 - struct ttm_bo_device *bdev = bo->bdev;
33556 + struct ttm_bo_device *bdev;
33557 unsigned long bus_base;
33558 unsigned long bus_offset;
33559 unsigned long bus_size;
33560 @@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33561 unsigned long address = (unsigned long)vmf->virtual_address;
33562 int retval = VM_FAULT_NOPAGE;
33563
33564 + if (!bo)
33565 + return VM_FAULT_NOPAGE;
33566 + bdev = bo->bdev;
33567 +
33568 /*
33569 * Work around locking order reversal in fault / nopfn
33570 * between mmap_sem and bo_reserve: Perform a trylock operation
33571 diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
33572 index b170071..28ae90e 100644
33573 --- a/drivers/gpu/drm/ttm/ttm_global.c
33574 +++ b/drivers/gpu/drm/ttm/ttm_global.c
33575 @@ -36,7 +36,7 @@
33576 struct ttm_global_item {
33577 struct mutex mutex;
33578 void *object;
33579 - int refcount;
33580 + atomic_t refcount;
33581 };
33582
33583 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
33584 @@ -49,7 +49,7 @@ void ttm_global_init(void)
33585 struct ttm_global_item *item = &glob[i];
33586 mutex_init(&item->mutex);
33587 item->object = NULL;
33588 - item->refcount = 0;
33589 + atomic_set(&item->refcount, 0);
33590 }
33591 }
33592
33593 @@ -59,7 +59,7 @@ void ttm_global_release(void)
33594 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
33595 struct ttm_global_item *item = &glob[i];
33596 BUG_ON(item->object != NULL);
33597 - BUG_ON(item->refcount != 0);
33598 + BUG_ON(atomic_read(&item->refcount) != 0);
33599 }
33600 }
33601
33602 @@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33603 void *object;
33604
33605 mutex_lock(&item->mutex);
33606 - if (item->refcount == 0) {
33607 + if (atomic_read(&item->refcount) == 0) {
33608 item->object = kzalloc(ref->size, GFP_KERNEL);
33609 if (unlikely(item->object == NULL)) {
33610 ret = -ENOMEM;
33611 @@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33612 goto out_err;
33613
33614 }
33615 - ++item->refcount;
33616 + atomic_inc(&item->refcount);
33617 ref->object = item->object;
33618 object = item->object;
33619 mutex_unlock(&item->mutex);
33620 @@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_global_reference *ref)
33621 struct ttm_global_item *item = &glob[ref->global_type];
33622
33623 mutex_lock(&item->mutex);
33624 - BUG_ON(item->refcount == 0);
33625 + BUG_ON(atomic_read(&item->refcount) == 0);
33626 BUG_ON(ref->object != item->object);
33627 - if (--item->refcount == 0) {
33628 + if (atomic_dec_and_test(&item->refcount)) {
33629 ref->release(ref);
33630 item->object = NULL;
33631 }
33632 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
33633 index 072c281..d8ef483 100644
33634 --- a/drivers/gpu/drm/ttm/ttm_memory.c
33635 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
33636 @@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_attrs[] = {
33637 NULL
33638 };
33639
33640 -static struct sysfs_ops ttm_mem_zone_ops = {
33641 +static const struct sysfs_ops ttm_mem_zone_ops = {
33642 .show = &ttm_mem_zone_show,
33643 .store = &ttm_mem_zone_store
33644 };
33645 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33646 index cafcb84..b8e66cc 100644
33647 --- a/drivers/gpu/drm/via/via_drv.h
33648 +++ b/drivers/gpu/drm/via/via_drv.h
33649 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33650 typedef uint32_t maskarray_t[5];
33651
33652 typedef struct drm_via_irq {
33653 - atomic_t irq_received;
33654 + atomic_unchecked_t irq_received;
33655 uint32_t pending_mask;
33656 uint32_t enable_mask;
33657 wait_queue_head_t irq_queue;
33658 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33659 struct timeval last_vblank;
33660 int last_vblank_valid;
33661 unsigned usec_per_vblank;
33662 - atomic_t vbl_received;
33663 + atomic_unchecked_t vbl_received;
33664 drm_via_state_t hc_state;
33665 char pci_buf[VIA_PCI_BUF_SIZE];
33666 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33667 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33668 index 5935b88..127a8a6 100644
33669 --- a/drivers/gpu/drm/via/via_irq.c
33670 +++ b/drivers/gpu/drm/via/via_irq.c
33671 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33672 if (crtc != 0)
33673 return 0;
33674
33675 - return atomic_read(&dev_priv->vbl_received);
33676 + return atomic_read_unchecked(&dev_priv->vbl_received);
33677 }
33678
33679 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33680 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33681
33682 status = VIA_READ(VIA_REG_INTERRUPT);
33683 if (status & VIA_IRQ_VBLANK_PENDING) {
33684 - atomic_inc(&dev_priv->vbl_received);
33685 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33686 + atomic_inc_unchecked(&dev_priv->vbl_received);
33687 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33688 do_gettimeofday(&cur_vblank);
33689 if (dev_priv->last_vblank_valid) {
33690 dev_priv->usec_per_vblank =
33691 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33692 dev_priv->last_vblank = cur_vblank;
33693 dev_priv->last_vblank_valid = 1;
33694 }
33695 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33696 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33697 DRM_DEBUG("US per vblank is: %u\n",
33698 dev_priv->usec_per_vblank);
33699 }
33700 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33701
33702 for (i = 0; i < dev_priv->num_irqs; ++i) {
33703 if (status & cur_irq->pending_mask) {
33704 - atomic_inc(&cur_irq->irq_received);
33705 + atomic_inc_unchecked(&cur_irq->irq_received);
33706 DRM_WAKEUP(&cur_irq->irq_queue);
33707 handled = 1;
33708 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
33709 @@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequenc
33710 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33711 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33712 masks[irq][4]));
33713 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33714 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33715 } else {
33716 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33717 (((cur_irq_sequence =
33718 - atomic_read(&cur_irq->irq_received)) -
33719 + atomic_read_unchecked(&cur_irq->irq_received)) -
33720 *sequence) <= (1 << 23)));
33721 }
33722 *sequence = cur_irq_sequence;
33723 @@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct drm_device * dev)
33724 }
33725
33726 for (i = 0; i < dev_priv->num_irqs; ++i) {
33727 - atomic_set(&cur_irq->irq_received, 0);
33728 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33729 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33730 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33731 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33732 @@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33733 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33734 case VIA_IRQ_RELATIVE:
33735 irqwait->request.sequence +=
33736 - atomic_read(&cur_irq->irq_received);
33737 + atomic_read_unchecked(&cur_irq->irq_received);
33738 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33739 case VIA_IRQ_ABSOLUTE:
33740 break;
33741 diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
33742 index aa8688d..6a0140c 100644
33743 --- a/drivers/gpu/vga/vgaarb.c
33744 +++ b/drivers/gpu/vga/vgaarb.c
33745 @@ -894,14 +894,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
33746 uc = &priv->cards[i];
33747 }
33748
33749 - if (!uc)
33750 - return -EINVAL;
33751 + if (!uc) {
33752 + ret_val = -EINVAL;
33753 + goto done;
33754 + }
33755
33756 - if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
33757 - return -EINVAL;
33758 + if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
33759 + ret_val = -EINVAL;
33760 + goto done;
33761 + }
33762
33763 - if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
33764 - return -EINVAL;
33765 + if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
33766 + ret_val = -EINVAL;
33767 + goto done;
33768 + }
33769
33770 vga_put(pdev, io_state);
33771
33772 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33773 index f3f1415..e561d90 100644
33774 --- a/drivers/hid/hid-core.c
33775 +++ b/drivers/hid/hid-core.c
33776 @@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device *hdev)
33777
33778 int hid_add_device(struct hid_device *hdev)
33779 {
33780 - static atomic_t id = ATOMIC_INIT(0);
33781 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33782 int ret;
33783
33784 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33785 @@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hdev)
33786 /* XXX hack, any other cleaner solution after the driver core
33787 * is converted to allow more than 20 bytes as the device name? */
33788 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33789 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33790 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33791
33792 ret = device_add(&hdev->dev);
33793 if (!ret)
33794 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33795 index 8b6ee24..70f657d 100644
33796 --- a/drivers/hid/usbhid/hiddev.c
33797 +++ b/drivers/hid/usbhid/hiddev.c
33798 @@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33799 return put_user(HID_VERSION, (int __user *)arg);
33800
33801 case HIDIOCAPPLICATION:
33802 - if (arg < 0 || arg >= hid->maxapplication)
33803 + if (arg >= hid->maxapplication)
33804 return -EINVAL;
33805
33806 for (i = 0; i < hid->maxcollection; i++)
33807 diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
33808 index 5d5ed69..f40533e 100644
33809 --- a/drivers/hwmon/lis3lv02d.c
33810 +++ b/drivers/hwmon/lis3lv02d.c
33811 @@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
33812 * the lid is closed. This leads to interrupts as soon as a little move
33813 * is done.
33814 */
33815 - atomic_inc(&lis3_dev.count);
33816 + atomic_inc_unchecked(&lis3_dev.count);
33817
33818 wake_up_interruptible(&lis3_dev.misc_wait);
33819 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33820 @@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33821 if (test_and_set_bit(0, &lis3_dev.misc_opened))
33822 return -EBUSY; /* already open */
33823
33824 - atomic_set(&lis3_dev.count, 0);
33825 + atomic_set_unchecked(&lis3_dev.count, 0);
33826
33827 /*
33828 * The sensor can generate interrupts for free-fall and direction
33829 @@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33830 add_wait_queue(&lis3_dev.misc_wait, &wait);
33831 while (true) {
33832 set_current_state(TASK_INTERRUPTIBLE);
33833 - data = atomic_xchg(&lis3_dev.count, 0);
33834 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33835 if (data)
33836 break;
33837
33838 @@ -244,7 +244,7 @@ out:
33839 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33840 {
33841 poll_wait(file, &lis3_dev.misc_wait, wait);
33842 - if (atomic_read(&lis3_dev.count))
33843 + if (atomic_read_unchecked(&lis3_dev.count))
33844 return POLLIN | POLLRDNORM;
33845 return 0;
33846 }
33847 diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
33848 index 7cdd76f..fe0efdf 100644
33849 --- a/drivers/hwmon/lis3lv02d.h
33850 +++ b/drivers/hwmon/lis3lv02d.h
33851 @@ -201,7 +201,7 @@ struct lis3lv02d {
33852
33853 struct input_polled_dev *idev; /* input device */
33854 struct platform_device *pdev; /* platform device */
33855 - atomic_t count; /* interrupt count after last read */
33856 + atomic_unchecked_t count; /* interrupt count after last read */
33857 int xcalib; /* calibrated null value for x */
33858 int ycalib; /* calibrated null value for y */
33859 int zcalib; /* calibrated null value for z */
33860 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33861 index 2040507..706ec1e 100644
33862 --- a/drivers/hwmon/sht15.c
33863 +++ b/drivers/hwmon/sht15.c
33864 @@ -112,7 +112,7 @@ struct sht15_data {
33865 int supply_uV;
33866 int supply_uV_valid;
33867 struct work_struct update_supply_work;
33868 - atomic_t interrupt_handled;
33869 + atomic_unchecked_t interrupt_handled;
33870 };
33871
33872 /**
33873 @@ -245,13 +245,13 @@ static inline int sht15_update_single_val(struct sht15_data *data,
33874 return ret;
33875
33876 gpio_direction_input(data->pdata->gpio_data);
33877 - atomic_set(&data->interrupt_handled, 0);
33878 + atomic_set_unchecked(&data->interrupt_handled, 0);
33879
33880 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33881 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33882 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33883 /* Only relevant if the interrupt hasn't occured. */
33884 - if (!atomic_read(&data->interrupt_handled))
33885 + if (!atomic_read_unchecked(&data->interrupt_handled))
33886 schedule_work(&data->read_work);
33887 }
33888 ret = wait_event_timeout(data->wait_queue,
33889 @@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33890 struct sht15_data *data = d;
33891 /* First disable the interrupt */
33892 disable_irq_nosync(irq);
33893 - atomic_inc(&data->interrupt_handled);
33894 + atomic_inc_unchecked(&data->interrupt_handled);
33895 /* Then schedule a reading work struct */
33896 if (data->flag != SHT15_READING_NOTHING)
33897 schedule_work(&data->read_work);
33898 @@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33899 here as could have gone low in meantime so verify
33900 it hasn't!
33901 */
33902 - atomic_set(&data->interrupt_handled, 0);
33903 + atomic_set_unchecked(&data->interrupt_handled, 0);
33904 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33905 /* If still not occured or another handler has been scheduled */
33906 if (gpio_get_value(data->pdata->gpio_data)
33907 - || atomic_read(&data->interrupt_handled))
33908 + || atomic_read_unchecked(&data->interrupt_handled))
33909 return;
33910 }
33911 /* Read the data back from the device */
33912 diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
33913 index 97851c5..cb40626 100644
33914 --- a/drivers/hwmon/w83791d.c
33915 +++ b/drivers/hwmon/w83791d.c
33916 @@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_client *client, int kind,
33917 struct i2c_board_info *info);
33918 static int w83791d_remove(struct i2c_client *client);
33919
33920 -static int w83791d_read(struct i2c_client *client, u8 register);
33921 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
33922 +static int w83791d_read(struct i2c_client *client, u8 reg);
33923 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
33924 static struct w83791d_data *w83791d_update_device(struct device *dev);
33925
33926 #ifdef DEBUG
33927 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33928 index 378fcb5..5e91fa8 100644
33929 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33930 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33931 @@ -43,7 +43,7 @@
33932 extern struct i2c_adapter amd756_smbus;
33933
33934 static struct i2c_adapter *s4882_adapter;
33935 -static struct i2c_algorithm *s4882_algo;
33936 +static i2c_algorithm_no_const *s4882_algo;
33937
33938 /* Wrapper access functions for multiplexed SMBus */
33939 static DEFINE_MUTEX(amd756_lock);
33940 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33941 index 29015eb..af2d8e9 100644
33942 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33943 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33944 @@ -41,7 +41,7 @@
33945 extern struct i2c_adapter *nforce2_smbus;
33946
33947 static struct i2c_adapter *s4985_adapter;
33948 -static struct i2c_algorithm *s4985_algo;
33949 +static i2c_algorithm_no_const *s4985_algo;
33950
33951 /* Wrapper access functions for multiplexed SMBus */
33952 static DEFINE_MUTEX(nforce2_lock);
33953 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
33954 index 878f8ec..12376fc 100644
33955 --- a/drivers/ide/aec62xx.c
33956 +++ b/drivers/ide/aec62xx.c
33957 @@ -180,7 +180,7 @@ static const struct ide_port_ops atp86x_port_ops = {
33958 .cable_detect = atp86x_cable_detect,
33959 };
33960
33961 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
33962 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
33963 { /* 0: AEC6210 */
33964 .name = DRV_NAME,
33965 .init_chipset = init_chipset_aec62xx,
33966 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
33967 index e59b6de..4b4fc65 100644
33968 --- a/drivers/ide/alim15x3.c
33969 +++ b/drivers/ide/alim15x3.c
33970 @@ -509,7 +509,7 @@ static const struct ide_dma_ops ali_dma_ops = {
33971 .dma_sff_read_status = ide_dma_sff_read_status,
33972 };
33973
33974 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
33975 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
33976 .name = DRV_NAME,
33977 .init_chipset = init_chipset_ali15x3,
33978 .init_hwif = init_hwif_ali15x3,
33979 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
33980 index 628cd2e..087a414 100644
33981 --- a/drivers/ide/amd74xx.c
33982 +++ b/drivers/ide/amd74xx.c
33983 @@ -221,7 +221,7 @@ static const struct ide_port_ops amd_port_ops = {
33984 .udma_mask = udma, \
33985 }
33986
33987 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
33988 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
33989 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
33990 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
33991 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
33992 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
33993 index 837322b..837fd71 100644
33994 --- a/drivers/ide/atiixp.c
33995 +++ b/drivers/ide/atiixp.c
33996 @@ -137,7 +137,7 @@ static const struct ide_port_ops atiixp_port_ops = {
33997 .cable_detect = atiixp_cable_detect,
33998 };
33999
34000 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
34001 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
34002 { /* 0: IXP200/300/400/700 */
34003 .name = DRV_NAME,
34004 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
34005 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
34006 index ca0c46f..d55318a 100644
34007 --- a/drivers/ide/cmd64x.c
34008 +++ b/drivers/ide/cmd64x.c
34009 @@ -372,7 +372,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
34010 .dma_sff_read_status = ide_dma_sff_read_status,
34011 };
34012
34013 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
34014 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
34015 { /* 0: CMD643 */
34016 .name = DRV_NAME,
34017 .init_chipset = init_chipset_cmd64x,
34018 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
34019 index 09f98ed..cebc5bc 100644
34020 --- a/drivers/ide/cs5520.c
34021 +++ b/drivers/ide/cs5520.c
34022 @@ -93,7 +93,7 @@ static const struct ide_port_ops cs5520_port_ops = {
34023 .set_dma_mode = cs5520_set_dma_mode,
34024 };
34025
34026 -static const struct ide_port_info cyrix_chipset __devinitdata = {
34027 +static const struct ide_port_info cyrix_chipset __devinitconst = {
34028 .name = DRV_NAME,
34029 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
34030 .port_ops = &cs5520_port_ops,
34031 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
34032 index 40bf05e..7d58ca0 100644
34033 --- a/drivers/ide/cs5530.c
34034 +++ b/drivers/ide/cs5530.c
34035 @@ -244,7 +244,7 @@ static const struct ide_port_ops cs5530_port_ops = {
34036 .udma_filter = cs5530_udma_filter,
34037 };
34038
34039 -static const struct ide_port_info cs5530_chipset __devinitdata = {
34040 +static const struct ide_port_info cs5530_chipset __devinitconst = {
34041 .name = DRV_NAME,
34042 .init_chipset = init_chipset_cs5530,
34043 .init_hwif = init_hwif_cs5530,
34044 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
34045 index 983d957..53e6172 100644
34046 --- a/drivers/ide/cs5535.c
34047 +++ b/drivers/ide/cs5535.c
34048 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
34049 .cable_detect = cs5535_cable_detect,
34050 };
34051
34052 -static const struct ide_port_info cs5535_chipset __devinitdata = {
34053 +static const struct ide_port_info cs5535_chipset __devinitconst = {
34054 .name = DRV_NAME,
34055 .port_ops = &cs5535_port_ops,
34056 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
34057 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
34058 index 74fc540..8e933d8 100644
34059 --- a/drivers/ide/cy82c693.c
34060 +++ b/drivers/ide/cy82c693.c
34061 @@ -288,7 +288,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
34062 .set_dma_mode = cy82c693_set_dma_mode,
34063 };
34064
34065 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
34066 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
34067 .name = DRV_NAME,
34068 .init_iops = init_iops_cy82c693,
34069 .port_ops = &cy82c693_port_ops,
34070 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
34071 index 7ce68ef..e78197d 100644
34072 --- a/drivers/ide/hpt366.c
34073 +++ b/drivers/ide/hpt366.c
34074 @@ -507,7 +507,7 @@ static struct hpt_timings hpt37x_timings = {
34075 }
34076 };
34077
34078 -static const struct hpt_info hpt36x __devinitdata = {
34079 +static const struct hpt_info hpt36x __devinitconst = {
34080 .chip_name = "HPT36x",
34081 .chip_type = HPT36x,
34082 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
34083 @@ -515,7 +515,7 @@ static const struct hpt_info hpt36x __devinitdata = {
34084 .timings = &hpt36x_timings
34085 };
34086
34087 -static const struct hpt_info hpt370 __devinitdata = {
34088 +static const struct hpt_info hpt370 __devinitconst = {
34089 .chip_name = "HPT370",
34090 .chip_type = HPT370,
34091 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34092 @@ -523,7 +523,7 @@ static const struct hpt_info hpt370 __devinitdata = {
34093 .timings = &hpt37x_timings
34094 };
34095
34096 -static const struct hpt_info hpt370a __devinitdata = {
34097 +static const struct hpt_info hpt370a __devinitconst = {
34098 .chip_name = "HPT370A",
34099 .chip_type = HPT370A,
34100 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34101 @@ -531,7 +531,7 @@ static const struct hpt_info hpt370a __devinitdata = {
34102 .timings = &hpt37x_timings
34103 };
34104
34105 -static const struct hpt_info hpt374 __devinitdata = {
34106 +static const struct hpt_info hpt374 __devinitconst = {
34107 .chip_name = "HPT374",
34108 .chip_type = HPT374,
34109 .udma_mask = ATA_UDMA5,
34110 @@ -539,7 +539,7 @@ static const struct hpt_info hpt374 __devinitdata = {
34111 .timings = &hpt37x_timings
34112 };
34113
34114 -static const struct hpt_info hpt372 __devinitdata = {
34115 +static const struct hpt_info hpt372 __devinitconst = {
34116 .chip_name = "HPT372",
34117 .chip_type = HPT372,
34118 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34119 @@ -547,7 +547,7 @@ static const struct hpt_info hpt372 __devinitdata = {
34120 .timings = &hpt37x_timings
34121 };
34122
34123 -static const struct hpt_info hpt372a __devinitdata = {
34124 +static const struct hpt_info hpt372a __devinitconst = {
34125 .chip_name = "HPT372A",
34126 .chip_type = HPT372A,
34127 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34128 @@ -555,7 +555,7 @@ static const struct hpt_info hpt372a __devinitdata = {
34129 .timings = &hpt37x_timings
34130 };
34131
34132 -static const struct hpt_info hpt302 __devinitdata = {
34133 +static const struct hpt_info hpt302 __devinitconst = {
34134 .chip_name = "HPT302",
34135 .chip_type = HPT302,
34136 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34137 @@ -563,7 +563,7 @@ static const struct hpt_info hpt302 __devinitdata = {
34138 .timings = &hpt37x_timings
34139 };
34140
34141 -static const struct hpt_info hpt371 __devinitdata = {
34142 +static const struct hpt_info hpt371 __devinitconst = {
34143 .chip_name = "HPT371",
34144 .chip_type = HPT371,
34145 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34146 @@ -571,7 +571,7 @@ static const struct hpt_info hpt371 __devinitdata = {
34147 .timings = &hpt37x_timings
34148 };
34149
34150 -static const struct hpt_info hpt372n __devinitdata = {
34151 +static const struct hpt_info hpt372n __devinitconst = {
34152 .chip_name = "HPT372N",
34153 .chip_type = HPT372N,
34154 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34155 @@ -579,7 +579,7 @@ static const struct hpt_info hpt372n __devinitdata = {
34156 .timings = &hpt37x_timings
34157 };
34158
34159 -static const struct hpt_info hpt302n __devinitdata = {
34160 +static const struct hpt_info hpt302n __devinitconst = {
34161 .chip_name = "HPT302N",
34162 .chip_type = HPT302N,
34163 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34164 @@ -587,7 +587,7 @@ static const struct hpt_info hpt302n __devinitdata = {
34165 .timings = &hpt37x_timings
34166 };
34167
34168 -static const struct hpt_info hpt371n __devinitdata = {
34169 +static const struct hpt_info hpt371n __devinitconst = {
34170 .chip_name = "HPT371N",
34171 .chip_type = HPT371N,
34172 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34173 @@ -1422,7 +1422,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
34174 .dma_sff_read_status = ide_dma_sff_read_status,
34175 };
34176
34177 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
34178 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
34179 { /* 0: HPT36x */
34180 .name = DRV_NAME,
34181 .init_chipset = init_chipset_hpt366,
34182 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34183 index 2de76cc..74186a1 100644
34184 --- a/drivers/ide/ide-cd.c
34185 +++ b/drivers/ide/ide-cd.c
34186 @@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34187 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34188 if ((unsigned long)buf & alignment
34189 || blk_rq_bytes(rq) & q->dma_pad_mask
34190 - || object_is_on_stack(buf))
34191 + || object_starts_on_stack(buf))
34192 drive->dma = 0;
34193 }
34194 }
34195 diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
34196 index fefbdfc..62ff465 100644
34197 --- a/drivers/ide/ide-floppy.c
34198 +++ b/drivers/ide/ide-floppy.c
34199 @@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
34200 u8 pc_buf[256], header_len, desc_cnt;
34201 int i, rc = 1, blocks, length;
34202
34203 + pax_track_stack();
34204 +
34205 ide_debug_log(IDE_DBG_FUNC, "enter");
34206
34207 drive->bios_cyl = 0;
34208 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
34209 index 39d4e01..11538ce 100644
34210 --- a/drivers/ide/ide-pci-generic.c
34211 +++ b/drivers/ide/ide-pci-generic.c
34212 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
34213 .udma_mask = ATA_UDMA6, \
34214 }
34215
34216 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
34217 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
34218 /* 0: Unknown */
34219 DECLARE_GENERIC_PCI_DEV(0),
34220
34221 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
34222 index 0d266a5..aaca790 100644
34223 --- a/drivers/ide/it8172.c
34224 +++ b/drivers/ide/it8172.c
34225 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
34226 .set_dma_mode = it8172_set_dma_mode,
34227 };
34228
34229 -static const struct ide_port_info it8172_port_info __devinitdata = {
34230 +static const struct ide_port_info it8172_port_info __devinitconst = {
34231 .name = DRV_NAME,
34232 .port_ops = &it8172_port_ops,
34233 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
34234 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
34235 index 4797616..4be488a 100644
34236 --- a/drivers/ide/it8213.c
34237 +++ b/drivers/ide/it8213.c
34238 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
34239 .cable_detect = it8213_cable_detect,
34240 };
34241
34242 -static const struct ide_port_info it8213_chipset __devinitdata = {
34243 +static const struct ide_port_info it8213_chipset __devinitconst = {
34244 .name = DRV_NAME,
34245 .enablebits = { {0x41, 0x80, 0x80} },
34246 .port_ops = &it8213_port_ops,
34247 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
34248 index 51aa745..146ee60 100644
34249 --- a/drivers/ide/it821x.c
34250 +++ b/drivers/ide/it821x.c
34251 @@ -627,7 +627,7 @@ static const struct ide_port_ops it821x_port_ops = {
34252 .cable_detect = it821x_cable_detect,
34253 };
34254
34255 -static const struct ide_port_info it821x_chipset __devinitdata = {
34256 +static const struct ide_port_info it821x_chipset __devinitconst = {
34257 .name = DRV_NAME,
34258 .init_chipset = init_chipset_it821x,
34259 .init_hwif = init_hwif_it821x,
34260 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
34261 index bf2be64..9270098 100644
34262 --- a/drivers/ide/jmicron.c
34263 +++ b/drivers/ide/jmicron.c
34264 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
34265 .cable_detect = jmicron_cable_detect,
34266 };
34267
34268 -static const struct ide_port_info jmicron_chipset __devinitdata = {
34269 +static const struct ide_port_info jmicron_chipset __devinitconst = {
34270 .name = DRV_NAME,
34271 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
34272 .port_ops = &jmicron_port_ops,
34273 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
34274 index 95327a2..73f78d8 100644
34275 --- a/drivers/ide/ns87415.c
34276 +++ b/drivers/ide/ns87415.c
34277 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
34278 .dma_sff_read_status = superio_dma_sff_read_status,
34279 };
34280
34281 -static const struct ide_port_info ns87415_chipset __devinitdata = {
34282 +static const struct ide_port_info ns87415_chipset __devinitconst = {
34283 .name = DRV_NAME,
34284 .init_hwif = init_hwif_ns87415,
34285 .tp_ops = &ns87415_tp_ops,
34286 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
34287 index f1d70d6..e1de05b 100644
34288 --- a/drivers/ide/opti621.c
34289 +++ b/drivers/ide/opti621.c
34290 @@ -202,7 +202,7 @@ static const struct ide_port_ops opti621_port_ops = {
34291 .set_pio_mode = opti621_set_pio_mode,
34292 };
34293
34294 -static const struct ide_port_info opti621_chipset __devinitdata = {
34295 +static const struct ide_port_info opti621_chipset __devinitconst = {
34296 .name = DRV_NAME,
34297 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
34298 .port_ops = &opti621_port_ops,
34299 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
34300 index 65ba823..7311f4d 100644
34301 --- a/drivers/ide/pdc202xx_new.c
34302 +++ b/drivers/ide/pdc202xx_new.c
34303 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
34304 .udma_mask = udma, \
34305 }
34306
34307 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
34308 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
34309 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
34310 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
34311 };
34312 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
34313 index cb812f3..af816ef 100644
34314 --- a/drivers/ide/pdc202xx_old.c
34315 +++ b/drivers/ide/pdc202xx_old.c
34316 @@ -285,7 +285,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
34317 .max_sectors = sectors, \
34318 }
34319
34320 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
34321 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
34322 { /* 0: PDC20246 */
34323 .name = DRV_NAME,
34324 .init_chipset = init_chipset_pdc202xx,
34325 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
34326 index bf14f39..15c4b98 100644
34327 --- a/drivers/ide/piix.c
34328 +++ b/drivers/ide/piix.c
34329 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
34330 .udma_mask = udma, \
34331 }
34332
34333 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
34334 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
34335 /* 0: MPIIX */
34336 { /*
34337 * MPIIX actually has only a single IDE channel mapped to
34338 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
34339 index a6414a8..c04173e 100644
34340 --- a/drivers/ide/rz1000.c
34341 +++ b/drivers/ide/rz1000.c
34342 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
34343 }
34344 }
34345
34346 -static const struct ide_port_info rz1000_chipset __devinitdata = {
34347 +static const struct ide_port_info rz1000_chipset __devinitconst = {
34348 .name = DRV_NAME,
34349 .host_flags = IDE_HFLAG_NO_DMA,
34350 };
34351 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
34352 index d467478..9203942 100644
34353 --- a/drivers/ide/sc1200.c
34354 +++ b/drivers/ide/sc1200.c
34355 @@ -290,7 +290,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
34356 .dma_sff_read_status = ide_dma_sff_read_status,
34357 };
34358
34359 -static const struct ide_port_info sc1200_chipset __devinitdata = {
34360 +static const struct ide_port_info sc1200_chipset __devinitconst = {
34361 .name = DRV_NAME,
34362 .port_ops = &sc1200_port_ops,
34363 .dma_ops = &sc1200_dma_ops,
34364 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
34365 index 1104bb3..59c5194 100644
34366 --- a/drivers/ide/scc_pata.c
34367 +++ b/drivers/ide/scc_pata.c
34368 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
34369 .dma_sff_read_status = scc_dma_sff_read_status,
34370 };
34371
34372 -static const struct ide_port_info scc_chipset __devinitdata = {
34373 +static const struct ide_port_info scc_chipset __devinitconst = {
34374 .name = "sccIDE",
34375 .init_iops = init_iops_scc,
34376 .init_dma = scc_init_dma,
34377 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
34378 index b6554ef..6cc2cc3 100644
34379 --- a/drivers/ide/serverworks.c
34380 +++ b/drivers/ide/serverworks.c
34381 @@ -353,7 +353,7 @@ static const struct ide_port_ops svwks_port_ops = {
34382 .cable_detect = svwks_cable_detect,
34383 };
34384
34385 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
34386 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
34387 { /* 0: OSB4 */
34388 .name = DRV_NAME,
34389 .init_chipset = init_chipset_svwks,
34390 diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
34391 index ab3db61..afed580 100644
34392 --- a/drivers/ide/setup-pci.c
34393 +++ b/drivers/ide/setup-pci.c
34394 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
34395 int ret, i, n_ports = dev2 ? 4 : 2;
34396 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
34397
34398 + pax_track_stack();
34399 +
34400 for (i = 0; i < n_ports / 2; i++) {
34401 ret = ide_setup_pci_controller(pdev[i], d, !i);
34402 if (ret < 0)
34403 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
34404 index d95df52..0b03a39 100644
34405 --- a/drivers/ide/siimage.c
34406 +++ b/drivers/ide/siimage.c
34407 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
34408 .udma_mask = ATA_UDMA6, \
34409 }
34410
34411 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
34412 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
34413 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
34414 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
34415 };
34416 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
34417 index 3b88eba..ca8699d 100644
34418 --- a/drivers/ide/sis5513.c
34419 +++ b/drivers/ide/sis5513.c
34420 @@ -561,7 +561,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
34421 .cable_detect = sis_cable_detect,
34422 };
34423
34424 -static const struct ide_port_info sis5513_chipset __devinitdata = {
34425 +static const struct ide_port_info sis5513_chipset __devinitconst = {
34426 .name = DRV_NAME,
34427 .init_chipset = init_chipset_sis5513,
34428 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
34429 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
34430 index d698da4..fca42a4 100644
34431 --- a/drivers/ide/sl82c105.c
34432 +++ b/drivers/ide/sl82c105.c
34433 @@ -319,7 +319,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
34434 .dma_sff_read_status = ide_dma_sff_read_status,
34435 };
34436
34437 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
34438 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
34439 .name = DRV_NAME,
34440 .init_chipset = init_chipset_sl82c105,
34441 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
34442 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
34443 index 1ccfb40..83d5779 100644
34444 --- a/drivers/ide/slc90e66.c
34445 +++ b/drivers/ide/slc90e66.c
34446 @@ -131,7 +131,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
34447 .cable_detect = slc90e66_cable_detect,
34448 };
34449
34450 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
34451 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
34452 .name = DRV_NAME,
34453 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
34454 .port_ops = &slc90e66_port_ops,
34455 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
34456 index 05a93d6..5f9e325 100644
34457 --- a/drivers/ide/tc86c001.c
34458 +++ b/drivers/ide/tc86c001.c
34459 @@ -190,7 +190,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
34460 .dma_sff_read_status = ide_dma_sff_read_status,
34461 };
34462
34463 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
34464 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
34465 .name = DRV_NAME,
34466 .init_hwif = init_hwif_tc86c001,
34467 .port_ops = &tc86c001_port_ops,
34468 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
34469 index 8773c3b..7907d6c 100644
34470 --- a/drivers/ide/triflex.c
34471 +++ b/drivers/ide/triflex.c
34472 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
34473 .set_dma_mode = triflex_set_mode,
34474 };
34475
34476 -static const struct ide_port_info triflex_device __devinitdata = {
34477 +static const struct ide_port_info triflex_device __devinitconst = {
34478 .name = DRV_NAME,
34479 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
34480 .port_ops = &triflex_port_ops,
34481 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
34482 index 4b42ca0..e494a98 100644
34483 --- a/drivers/ide/trm290.c
34484 +++ b/drivers/ide/trm290.c
34485 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
34486 .dma_check = trm290_dma_check,
34487 };
34488
34489 -static const struct ide_port_info trm290_chipset __devinitdata = {
34490 +static const struct ide_port_info trm290_chipset __devinitconst = {
34491 .name = DRV_NAME,
34492 .init_hwif = init_hwif_trm290,
34493 .tp_ops = &trm290_tp_ops,
34494 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
34495 index 028de26..520d5d5 100644
34496 --- a/drivers/ide/via82cxxx.c
34497 +++ b/drivers/ide/via82cxxx.c
34498 @@ -374,7 +374,7 @@ static const struct ide_port_ops via_port_ops = {
34499 .cable_detect = via82cxxx_cable_detect,
34500 };
34501
34502 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
34503 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
34504 .name = DRV_NAME,
34505 .init_chipset = init_chipset_via82cxxx,
34506 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
34507 diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
34508 index 2cd00b5..14de699 100644
34509 --- a/drivers/ieee1394/dv1394.c
34510 +++ b/drivers/ieee1394/dv1394.c
34511 @@ -739,7 +739,7 @@ static void frame_prepare(struct video_card *video, unsigned int this_frame)
34512 based upon DIF section and sequence
34513 */
34514
34515 -static void inline
34516 +static inline void
34517 frame_put_packet (struct frame *f, struct packet *p)
34518 {
34519 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
34520 diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
34521 index e947d8f..6a966b9 100644
34522 --- a/drivers/ieee1394/hosts.c
34523 +++ b/drivers/ieee1394/hosts.c
34524 @@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command,
34525 }
34526
34527 static struct hpsb_host_driver dummy_driver = {
34528 + .name = "dummy",
34529 .transmit_packet = dummy_transmit_packet,
34530 .devctl = dummy_devctl,
34531 .isoctl = dummy_isoctl
34532 diff --git a/drivers/ieee1394/init_ohci1394_dma.c b/drivers/ieee1394/init_ohci1394_dma.c
34533 index ddaab6e..8d37435 100644
34534 --- a/drivers/ieee1394/init_ohci1394_dma.c
34535 +++ b/drivers/ieee1394/init_ohci1394_dma.c
34536 @@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_controllers(void)
34537 for (func = 0; func < 8; func++) {
34538 u32 class = read_pci_config(num,slot,func,
34539 PCI_CLASS_REVISION);
34540 - if ((class == 0xffffffff))
34541 + if (class == 0xffffffff)
34542 continue; /* No device at this func */
34543
34544 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
34545 diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
34546 index 65c1429..5d8c11f 100644
34547 --- a/drivers/ieee1394/ohci1394.c
34548 +++ b/drivers/ieee1394/ohci1394.c
34549 @@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
34550 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
34551
34552 /* Module Parameters */
34553 -static int phys_dma = 1;
34554 +static int phys_dma;
34555 module_param(phys_dma, int, 0444);
34556 -MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
34557 +MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
34558
34559 static void dma_trm_tasklet(unsigned long data);
34560 static void dma_trm_reset(struct dma_trm_ctx *d);
34561 diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
34562 index f199896..78c9fc8 100644
34563 --- a/drivers/ieee1394/sbp2.c
34564 +++ b/drivers/ieee1394/sbp2.c
34565 @@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
34566 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
34567 MODULE_LICENSE("GPL");
34568
34569 -static int sbp2_module_init(void)
34570 +static int __init sbp2_module_init(void)
34571 {
34572 int ret;
34573
34574 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34575 index a5dea6b..0cefe8f 100644
34576 --- a/drivers/infiniband/core/cm.c
34577 +++ b/drivers/infiniband/core/cm.c
34578 @@ -112,7 +112,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34579
34580 struct cm_counter_group {
34581 struct kobject obj;
34582 - atomic_long_t counter[CM_ATTR_COUNT];
34583 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34584 };
34585
34586 struct cm_counter_attribute {
34587 @@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34588 struct ib_mad_send_buf *msg = NULL;
34589 int ret;
34590
34591 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34592 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34593 counter[CM_REQ_COUNTER]);
34594
34595 /* Quick state check to discard duplicate REQs. */
34596 @@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34597 if (!cm_id_priv)
34598 return;
34599
34600 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34601 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34602 counter[CM_REP_COUNTER]);
34603 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34604 if (ret)
34605 @@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work *work)
34606 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34607 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34608 spin_unlock_irq(&cm_id_priv->lock);
34609 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34610 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34611 counter[CM_RTU_COUNTER]);
34612 goto out;
34613 }
34614 @@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_work *work)
34615 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34616 dreq_msg->local_comm_id);
34617 if (!cm_id_priv) {
34618 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34619 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34620 counter[CM_DREQ_COUNTER]);
34621 cm_issue_drep(work->port, work->mad_recv_wc);
34622 return -EINVAL;
34623 @@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_work *work)
34624 case IB_CM_MRA_REP_RCVD:
34625 break;
34626 case IB_CM_TIMEWAIT:
34627 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34628 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34629 counter[CM_DREQ_COUNTER]);
34630 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34631 goto unlock;
34632 @@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_work *work)
34633 cm_free_msg(msg);
34634 goto deref;
34635 case IB_CM_DREQ_RCVD:
34636 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34637 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34638 counter[CM_DREQ_COUNTER]);
34639 goto unlock;
34640 default:
34641 @@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work *work)
34642 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34643 cm_id_priv->msg, timeout)) {
34644 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34645 - atomic_long_inc(&work->port->
34646 + atomic_long_inc_unchecked(&work->port->
34647 counter_group[CM_RECV_DUPLICATES].
34648 counter[CM_MRA_COUNTER]);
34649 goto out;
34650 @@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work *work)
34651 break;
34652 case IB_CM_MRA_REQ_RCVD:
34653 case IB_CM_MRA_REP_RCVD:
34654 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34655 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34656 counter[CM_MRA_COUNTER]);
34657 /* fall through */
34658 default:
34659 @@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work *work)
34660 case IB_CM_LAP_IDLE:
34661 break;
34662 case IB_CM_MRA_LAP_SENT:
34663 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34664 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34665 counter[CM_LAP_COUNTER]);
34666 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34667 goto unlock;
34668 @@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work *work)
34669 cm_free_msg(msg);
34670 goto deref;
34671 case IB_CM_LAP_RCVD:
34672 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34673 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34674 counter[CM_LAP_COUNTER]);
34675 goto unlock;
34676 default:
34677 @@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34678 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34679 if (cur_cm_id_priv) {
34680 spin_unlock_irq(&cm.lock);
34681 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34682 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34683 counter[CM_SIDR_REQ_COUNTER]);
34684 goto out; /* Duplicate message. */
34685 }
34686 @@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34687 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34688 msg->retries = 1;
34689
34690 - atomic_long_add(1 + msg->retries,
34691 + atomic_long_add_unchecked(1 + msg->retries,
34692 &port->counter_group[CM_XMIT].counter[attr_index]);
34693 if (msg->retries)
34694 - atomic_long_add(msg->retries,
34695 + atomic_long_add_unchecked(msg->retries,
34696 &port->counter_group[CM_XMIT_RETRIES].
34697 counter[attr_index]);
34698
34699 @@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34700 }
34701
34702 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34703 - atomic_long_inc(&port->counter_group[CM_RECV].
34704 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34705 counter[attr_id - CM_ATTR_ID_OFFSET]);
34706
34707 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34708 @@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34709 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34710
34711 return sprintf(buf, "%ld\n",
34712 - atomic_long_read(&group->counter[cm_attr->index]));
34713 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34714 }
34715
34716 -static struct sysfs_ops cm_counter_ops = {
34717 +static const struct sysfs_ops cm_counter_ops = {
34718 .show = cm_show_counter
34719 };
34720
34721 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34722 index 4507043..14ad522 100644
34723 --- a/drivers/infiniband/core/fmr_pool.c
34724 +++ b/drivers/infiniband/core/fmr_pool.c
34725 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
34726
34727 struct task_struct *thread;
34728
34729 - atomic_t req_ser;
34730 - atomic_t flush_ser;
34731 + atomic_unchecked_t req_ser;
34732 + atomic_unchecked_t flush_ser;
34733
34734 wait_queue_head_t force_wait;
34735 };
34736 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34737 struct ib_fmr_pool *pool = pool_ptr;
34738
34739 do {
34740 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34741 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34742 ib_fmr_batch_release(pool);
34743
34744 - atomic_inc(&pool->flush_ser);
34745 + atomic_inc_unchecked(&pool->flush_ser);
34746 wake_up_interruptible(&pool->force_wait);
34747
34748 if (pool->flush_function)
34749 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34750 }
34751
34752 set_current_state(TASK_INTERRUPTIBLE);
34753 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34754 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34755 !kthread_should_stop())
34756 schedule();
34757 __set_current_state(TASK_RUNNING);
34758 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34759 pool->dirty_watermark = params->dirty_watermark;
34760 pool->dirty_len = 0;
34761 spin_lock_init(&pool->pool_lock);
34762 - atomic_set(&pool->req_ser, 0);
34763 - atomic_set(&pool->flush_ser, 0);
34764 + atomic_set_unchecked(&pool->req_ser, 0);
34765 + atomic_set_unchecked(&pool->flush_ser, 0);
34766 init_waitqueue_head(&pool->force_wait);
34767
34768 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34769 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34770 }
34771 spin_unlock_irq(&pool->pool_lock);
34772
34773 - serial = atomic_inc_return(&pool->req_ser);
34774 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34775 wake_up_process(pool->thread);
34776
34777 if (wait_event_interruptible(pool->force_wait,
34778 - atomic_read(&pool->flush_ser) - serial >= 0))
34779 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34780 return -EINTR;
34781
34782 return 0;
34783 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34784 } else {
34785 list_add_tail(&fmr->list, &pool->dirty_list);
34786 if (++pool->dirty_len >= pool->dirty_watermark) {
34787 - atomic_inc(&pool->req_ser);
34788 + atomic_inc_unchecked(&pool->req_ser);
34789 wake_up_process(pool->thread);
34790 }
34791 }
34792 diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
34793 index 158a214..1558bb7 100644
34794 --- a/drivers/infiniband/core/sysfs.c
34795 +++ b/drivers/infiniband/core/sysfs.c
34796 @@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kobject *kobj,
34797 return port_attr->show(p, port_attr, buf);
34798 }
34799
34800 -static struct sysfs_ops port_sysfs_ops = {
34801 +static const struct sysfs_ops port_sysfs_ops = {
34802 .show = port_attr_show
34803 };
34804
34805 diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
34806 index 5440da0..1194ecb 100644
34807 --- a/drivers/infiniband/core/uverbs_marshall.c
34808 +++ b/drivers/infiniband/core/uverbs_marshall.c
34809 @@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
34810 dst->grh.sgid_index = src->grh.sgid_index;
34811 dst->grh.hop_limit = src->grh.hop_limit;
34812 dst->grh.traffic_class = src->grh.traffic_class;
34813 + memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
34814 dst->dlid = src->dlid;
34815 dst->sl = src->sl;
34816 dst->src_path_bits = src->src_path_bits;
34817 dst->static_rate = src->static_rate;
34818 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
34819 dst->port_num = src->port_num;
34820 + dst->reserved = 0;
34821 }
34822 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
34823
34824 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34825 struct ib_qp_attr *src)
34826 {
34827 + dst->qp_state = src->qp_state;
34828 dst->cur_qp_state = src->cur_qp_state;
34829 dst->path_mtu = src->path_mtu;
34830 dst->path_mig_state = src->path_mig_state;
34831 @@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34832 dst->rnr_retry = src->rnr_retry;
34833 dst->alt_port_num = src->alt_port_num;
34834 dst->alt_timeout = src->alt_timeout;
34835 + memset(dst->reserved, 0, sizeof(dst->reserved));
34836 }
34837 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
34838
34839 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
34840 index 100da85..62e6b88 100644
34841 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
34842 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
34843 @@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
34844 struct infinipath_counters counters;
34845 struct ipath_devdata *dd;
34846
34847 + pax_track_stack();
34848 +
34849 dd = file->f_path.dentry->d_inode->i_private;
34850 dd->ipath_f_read_counters(dd, &counters);
34851
34852 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34853 index cbde0cf..afaf55c 100644
34854 --- a/drivers/infiniband/hw/nes/nes.c
34855 +++ b/drivers/infiniband/hw/nes/nes.c
34856 @@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34857 LIST_HEAD(nes_adapter_list);
34858 static LIST_HEAD(nes_dev_list);
34859
34860 -atomic_t qps_destroyed;
34861 +atomic_unchecked_t qps_destroyed;
34862
34863 static unsigned int ee_flsh_adapter;
34864 static unsigned int sysfs_nonidx_addr;
34865 @@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34866 struct nes_adapter *nesadapter = nesdev->nesadapter;
34867 u32 qp_id;
34868
34869 - atomic_inc(&qps_destroyed);
34870 + atomic_inc_unchecked(&qps_destroyed);
34871
34872 /* Free the control structures */
34873
34874 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34875 index bcc6abc..9c76b2f 100644
34876 --- a/drivers/infiniband/hw/nes/nes.h
34877 +++ b/drivers/infiniband/hw/nes/nes.h
34878 @@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
34879 extern unsigned int wqm_quanta;
34880 extern struct list_head nes_adapter_list;
34881
34882 -extern atomic_t cm_connects;
34883 -extern atomic_t cm_accepts;
34884 -extern atomic_t cm_disconnects;
34885 -extern atomic_t cm_closes;
34886 -extern atomic_t cm_connecteds;
34887 -extern atomic_t cm_connect_reqs;
34888 -extern atomic_t cm_rejects;
34889 -extern atomic_t mod_qp_timouts;
34890 -extern atomic_t qps_created;
34891 -extern atomic_t qps_destroyed;
34892 -extern atomic_t sw_qps_destroyed;
34893 +extern atomic_unchecked_t cm_connects;
34894 +extern atomic_unchecked_t cm_accepts;
34895 +extern atomic_unchecked_t cm_disconnects;
34896 +extern atomic_unchecked_t cm_closes;
34897 +extern atomic_unchecked_t cm_connecteds;
34898 +extern atomic_unchecked_t cm_connect_reqs;
34899 +extern atomic_unchecked_t cm_rejects;
34900 +extern atomic_unchecked_t mod_qp_timouts;
34901 +extern atomic_unchecked_t qps_created;
34902 +extern atomic_unchecked_t qps_destroyed;
34903 +extern atomic_unchecked_t sw_qps_destroyed;
34904 extern u32 mh_detected;
34905 extern u32 mh_pauses_sent;
34906 extern u32 cm_packets_sent;
34907 @@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
34908 extern u32 cm_listens_created;
34909 extern u32 cm_listens_destroyed;
34910 extern u32 cm_backlog_drops;
34911 -extern atomic_t cm_loopbacks;
34912 -extern atomic_t cm_nodes_created;
34913 -extern atomic_t cm_nodes_destroyed;
34914 -extern atomic_t cm_accel_dropped_pkts;
34915 -extern atomic_t cm_resets_recvd;
34916 +extern atomic_unchecked_t cm_loopbacks;
34917 +extern atomic_unchecked_t cm_nodes_created;
34918 +extern atomic_unchecked_t cm_nodes_destroyed;
34919 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34920 +extern atomic_unchecked_t cm_resets_recvd;
34921
34922 extern u32 int_mod_timer_init;
34923 extern u32 int_mod_cq_depth_256;
34924 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34925 index 73473db..5ed06e8 100644
34926 --- a/drivers/infiniband/hw/nes/nes_cm.c
34927 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34928 @@ -69,11 +69,11 @@ u32 cm_packets_received;
34929 u32 cm_listens_created;
34930 u32 cm_listens_destroyed;
34931 u32 cm_backlog_drops;
34932 -atomic_t cm_loopbacks;
34933 -atomic_t cm_nodes_created;
34934 -atomic_t cm_nodes_destroyed;
34935 -atomic_t cm_accel_dropped_pkts;
34936 -atomic_t cm_resets_recvd;
34937 +atomic_unchecked_t cm_loopbacks;
34938 +atomic_unchecked_t cm_nodes_created;
34939 +atomic_unchecked_t cm_nodes_destroyed;
34940 +atomic_unchecked_t cm_accel_dropped_pkts;
34941 +atomic_unchecked_t cm_resets_recvd;
34942
34943 static inline int mini_cm_accelerated(struct nes_cm_core *,
34944 struct nes_cm_node *);
34945 @@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
34946
34947 static struct nes_cm_core *g_cm_core;
34948
34949 -atomic_t cm_connects;
34950 -atomic_t cm_accepts;
34951 -atomic_t cm_disconnects;
34952 -atomic_t cm_closes;
34953 -atomic_t cm_connecteds;
34954 -atomic_t cm_connect_reqs;
34955 -atomic_t cm_rejects;
34956 +atomic_unchecked_t cm_connects;
34957 +atomic_unchecked_t cm_accepts;
34958 +atomic_unchecked_t cm_disconnects;
34959 +atomic_unchecked_t cm_closes;
34960 +atomic_unchecked_t cm_connecteds;
34961 +atomic_unchecked_t cm_connect_reqs;
34962 +atomic_unchecked_t cm_rejects;
34963
34964
34965 /**
34966 @@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34967 cm_node->rem_mac);
34968
34969 add_hte_node(cm_core, cm_node);
34970 - atomic_inc(&cm_nodes_created);
34971 + atomic_inc_unchecked(&cm_nodes_created);
34972
34973 return cm_node;
34974 }
34975 @@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34976 }
34977
34978 atomic_dec(&cm_core->node_cnt);
34979 - atomic_inc(&cm_nodes_destroyed);
34980 + atomic_inc_unchecked(&cm_nodes_destroyed);
34981 nesqp = cm_node->nesqp;
34982 if (nesqp) {
34983 nesqp->cm_node = NULL;
34984 @@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34985
34986 static void drop_packet(struct sk_buff *skb)
34987 {
34988 - atomic_inc(&cm_accel_dropped_pkts);
34989 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34990 dev_kfree_skb_any(skb);
34991 }
34992
34993 @@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34994
34995 int reset = 0; /* whether to send reset in case of err.. */
34996 int passive_state;
34997 - atomic_inc(&cm_resets_recvd);
34998 + atomic_inc_unchecked(&cm_resets_recvd);
34999 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35000 " refcnt=%d\n", cm_node, cm_node->state,
35001 atomic_read(&cm_node->ref_count));
35002 @@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35003 rem_ref_cm_node(cm_node->cm_core, cm_node);
35004 return NULL;
35005 }
35006 - atomic_inc(&cm_loopbacks);
35007 + atomic_inc_unchecked(&cm_loopbacks);
35008 loopbackremotenode->loopbackpartner = cm_node;
35009 loopbackremotenode->tcp_cntxt.rcv_wscale =
35010 NES_CM_DEFAULT_RCV_WND_SCALE;
35011 @@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35012 add_ref_cm_node(cm_node);
35013 } else if (cm_node->state == NES_CM_STATE_TSA) {
35014 rem_ref_cm_node(cm_core, cm_node);
35015 - atomic_inc(&cm_accel_dropped_pkts);
35016 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
35017 dev_kfree_skb_any(skb);
35018 break;
35019 }
35020 @@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35021
35022 if ((cm_id) && (cm_id->event_handler)) {
35023 if (issue_disconn) {
35024 - atomic_inc(&cm_disconnects);
35025 + atomic_inc_unchecked(&cm_disconnects);
35026 cm_event.event = IW_CM_EVENT_DISCONNECT;
35027 cm_event.status = disconn_status;
35028 cm_event.local_addr = cm_id->local_addr;
35029 @@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35030 }
35031
35032 if (issue_close) {
35033 - atomic_inc(&cm_closes);
35034 + atomic_inc_unchecked(&cm_closes);
35035 nes_disconnect(nesqp, 1);
35036
35037 cm_id->provider_data = nesqp;
35038 @@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35039
35040 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35041 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35042 - atomic_inc(&cm_accepts);
35043 + atomic_inc_unchecked(&cm_accepts);
35044
35045 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35046 atomic_read(&nesvnic->netdev->refcnt));
35047 @@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35048
35049 struct nes_cm_core *cm_core;
35050
35051 - atomic_inc(&cm_rejects);
35052 + atomic_inc_unchecked(&cm_rejects);
35053 cm_node = (struct nes_cm_node *) cm_id->provider_data;
35054 loopback = cm_node->loopbackpartner;
35055 cm_core = cm_node->cm_core;
35056 @@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35057 ntohl(cm_id->local_addr.sin_addr.s_addr),
35058 ntohs(cm_id->local_addr.sin_port));
35059
35060 - atomic_inc(&cm_connects);
35061 + atomic_inc_unchecked(&cm_connects);
35062 nesqp->active_conn = 1;
35063
35064 /* cache the cm_id in the qp */
35065 @@ -3195,7 +3195,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35066 if (nesqp->destroyed) {
35067 return;
35068 }
35069 - atomic_inc(&cm_connecteds);
35070 + atomic_inc_unchecked(&cm_connecteds);
35071 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35072 " local port 0x%04X. jiffies = %lu.\n",
35073 nesqp->hwqp.qp_id,
35074 @@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35075
35076 ret = cm_id->event_handler(cm_id, &cm_event);
35077 cm_id->add_ref(cm_id);
35078 - atomic_inc(&cm_closes);
35079 + atomic_inc_unchecked(&cm_closes);
35080 cm_event.event = IW_CM_EVENT_CLOSE;
35081 cm_event.status = IW_CM_EVENT_STATUS_OK;
35082 cm_event.provider_data = cm_id->provider_data;
35083 @@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35084 return;
35085 cm_id = cm_node->cm_id;
35086
35087 - atomic_inc(&cm_connect_reqs);
35088 + atomic_inc_unchecked(&cm_connect_reqs);
35089 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35090 cm_node, cm_id, jiffies);
35091
35092 @@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35093 return;
35094 cm_id = cm_node->cm_id;
35095
35096 - atomic_inc(&cm_connect_reqs);
35097 + atomic_inc_unchecked(&cm_connect_reqs);
35098 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35099 cm_node, cm_id, jiffies);
35100
35101 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35102 index e593af3..870694a 100644
35103 --- a/drivers/infiniband/hw/nes/nes_nic.c
35104 +++ b/drivers/infiniband/hw/nes/nes_nic.c
35105 @@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35106 target_stat_values[++index] = mh_detected;
35107 target_stat_values[++index] = mh_pauses_sent;
35108 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35109 - target_stat_values[++index] = atomic_read(&cm_connects);
35110 - target_stat_values[++index] = atomic_read(&cm_accepts);
35111 - target_stat_values[++index] = atomic_read(&cm_disconnects);
35112 - target_stat_values[++index] = atomic_read(&cm_connecteds);
35113 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35114 - target_stat_values[++index] = atomic_read(&cm_rejects);
35115 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35116 - target_stat_values[++index] = atomic_read(&qps_created);
35117 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35118 - target_stat_values[++index] = atomic_read(&qps_destroyed);
35119 - target_stat_values[++index] = atomic_read(&cm_closes);
35120 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35121 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35122 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35123 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35124 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35125 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35126 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35127 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35128 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35129 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35130 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35131 target_stat_values[++index] = cm_packets_sent;
35132 target_stat_values[++index] = cm_packets_bounced;
35133 target_stat_values[++index] = cm_packets_created;
35134 @@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35135 target_stat_values[++index] = cm_listens_created;
35136 target_stat_values[++index] = cm_listens_destroyed;
35137 target_stat_values[++index] = cm_backlog_drops;
35138 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
35139 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
35140 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35141 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35142 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35143 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35144 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35145 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35146 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35147 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35148 target_stat_values[++index] = int_mod_timer_init;
35149 target_stat_values[++index] = int_mod_cq_depth_1;
35150 target_stat_values[++index] = int_mod_cq_depth_4;
35151 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35152 index a680c42..f914deb 100644
35153 --- a/drivers/infiniband/hw/nes/nes_verbs.c
35154 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
35155 @@ -45,9 +45,9 @@
35156
35157 #include <rdma/ib_umem.h>
35158
35159 -atomic_t mod_qp_timouts;
35160 -atomic_t qps_created;
35161 -atomic_t sw_qps_destroyed;
35162 +atomic_unchecked_t mod_qp_timouts;
35163 +atomic_unchecked_t qps_created;
35164 +atomic_unchecked_t sw_qps_destroyed;
35165
35166 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35167
35168 @@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35169 if (init_attr->create_flags)
35170 return ERR_PTR(-EINVAL);
35171
35172 - atomic_inc(&qps_created);
35173 + atomic_inc_unchecked(&qps_created);
35174 switch (init_attr->qp_type) {
35175 case IB_QPT_RC:
35176 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35177 @@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35178 struct iw_cm_event cm_event;
35179 int ret;
35180
35181 - atomic_inc(&sw_qps_destroyed);
35182 + atomic_inc_unchecked(&sw_qps_destroyed);
35183 nesqp->destroyed = 1;
35184
35185 /* Blow away the connection if it exists. */
35186 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35187 index ac11be0..3883c04 100644
35188 --- a/drivers/input/gameport/gameport.c
35189 +++ b/drivers/input/gameport/gameport.c
35190 @@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
35191 */
35192 static void gameport_init_port(struct gameport *gameport)
35193 {
35194 - static atomic_t gameport_no = ATOMIC_INIT(0);
35195 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35196
35197 __module_get(THIS_MODULE);
35198
35199 mutex_init(&gameport->drv_mutex);
35200 device_initialize(&gameport->dev);
35201 - dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
35202 + dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35203 gameport->dev.bus = &gameport_bus;
35204 gameport->dev.release = gameport_release_port;
35205 if (gameport->parent)
35206 diff --git a/drivers/input/input.c b/drivers/input/input.c
35207 index c82ae82..8cfb9cb 100644
35208 --- a/drivers/input/input.c
35209 +++ b/drivers/input/input.c
35210 @@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
35211 */
35212 int input_register_device(struct input_dev *dev)
35213 {
35214 - static atomic_t input_no = ATOMIC_INIT(0);
35215 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35216 struct input_handler *handler;
35217 const char *path;
35218 int error;
35219 @@ -1585,7 +1585,7 @@ int input_register_device(struct input_dev *dev)
35220 dev->setkeycode = input_default_setkeycode;
35221
35222 dev_set_name(&dev->dev, "input%ld",
35223 - (unsigned long) atomic_inc_return(&input_no) - 1);
35224 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35225
35226 error = device_add(&dev->dev);
35227 if (error)
35228 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35229 index ca13a6b..b032b0c 100644
35230 --- a/drivers/input/joystick/sidewinder.c
35231 +++ b/drivers/input/joystick/sidewinder.c
35232 @@ -30,6 +30,7 @@
35233 #include <linux/kernel.h>
35234 #include <linux/module.h>
35235 #include <linux/slab.h>
35236 +#include <linux/sched.h>
35237 #include <linux/init.h>
35238 #include <linux/input.h>
35239 #include <linux/gameport.h>
35240 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
35241 unsigned char buf[SW_LENGTH];
35242 int i;
35243
35244 + pax_track_stack();
35245 +
35246 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
35247
35248 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
35249 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35250 index 79e3edc..01412b9 100644
35251 --- a/drivers/input/joystick/xpad.c
35252 +++ b/drivers/input/joystick/xpad.c
35253 @@ -621,7 +621,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35254
35255 static int xpad_led_probe(struct usb_xpad *xpad)
35256 {
35257 - static atomic_t led_seq = ATOMIC_INIT(0);
35258 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35259 long led_no;
35260 struct xpad_led *led;
35261 struct led_classdev *led_cdev;
35262 @@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35263 if (!led)
35264 return -ENOMEM;
35265
35266 - led_no = (long)atomic_inc_return(&led_seq) - 1;
35267 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35268
35269 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35270 led->xpad = xpad;
35271 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35272 index 0236f0d..c7327f1 100644
35273 --- a/drivers/input/serio/serio.c
35274 +++ b/drivers/input/serio/serio.c
35275 @@ -527,7 +527,7 @@ static void serio_release_port(struct device *dev)
35276 */
35277 static void serio_init_port(struct serio *serio)
35278 {
35279 - static atomic_t serio_no = ATOMIC_INIT(0);
35280 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35281
35282 __module_get(THIS_MODULE);
35283
35284 @@ -536,7 +536,7 @@ static void serio_init_port(struct serio *serio)
35285 mutex_init(&serio->drv_mutex);
35286 device_initialize(&serio->dev);
35287 dev_set_name(&serio->dev, "serio%ld",
35288 - (long)atomic_inc_return(&serio_no) - 1);
35289 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
35290 serio->dev.bus = &serio_bus;
35291 serio->dev.release = serio_release_port;
35292 if (serio->parent) {
35293 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
35294 index 33dcd8d..2783d25 100644
35295 --- a/drivers/isdn/gigaset/common.c
35296 +++ b/drivers/isdn/gigaset/common.c
35297 @@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
35298 cs->commands_pending = 0;
35299 cs->cur_at_seq = 0;
35300 cs->gotfwver = -1;
35301 - cs->open_count = 0;
35302 + local_set(&cs->open_count, 0);
35303 cs->dev = NULL;
35304 cs->tty = NULL;
35305 cs->tty_dev = NULL;
35306 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
35307 index a2f6125..6a70677 100644
35308 --- a/drivers/isdn/gigaset/gigaset.h
35309 +++ b/drivers/isdn/gigaset/gigaset.h
35310 @@ -34,6 +34,7 @@
35311 #include <linux/tty_driver.h>
35312 #include <linux/list.h>
35313 #include <asm/atomic.h>
35314 +#include <asm/local.h>
35315
35316 #define GIG_VERSION {0,5,0,0}
35317 #define GIG_COMPAT {0,4,0,0}
35318 @@ -446,7 +447,7 @@ struct cardstate {
35319 spinlock_t cmdlock;
35320 unsigned curlen, cmdbytes;
35321
35322 - unsigned open_count;
35323 + local_t open_count;
35324 struct tty_struct *tty;
35325 struct tasklet_struct if_wake_tasklet;
35326 unsigned control_state;
35327 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35328 index b3065b8..c7e8cc9 100644
35329 --- a/drivers/isdn/gigaset/interface.c
35330 +++ b/drivers/isdn/gigaset/interface.c
35331 @@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35332 return -ERESTARTSYS; // FIXME -EINTR?
35333 tty->driver_data = cs;
35334
35335 - ++cs->open_count;
35336 -
35337 - if (cs->open_count == 1) {
35338 + if (local_inc_return(&cs->open_count) == 1) {
35339 spin_lock_irqsave(&cs->lock, flags);
35340 cs->tty = tty;
35341 spin_unlock_irqrestore(&cs->lock, flags);
35342 @@ -195,10 +193,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35343
35344 if (!cs->connected)
35345 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35346 - else if (!cs->open_count)
35347 + else if (!local_read(&cs->open_count))
35348 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35349 else {
35350 - if (!--cs->open_count) {
35351 + if (!local_dec_return(&cs->open_count)) {
35352 spin_lock_irqsave(&cs->lock, flags);
35353 cs->tty = NULL;
35354 spin_unlock_irqrestore(&cs->lock, flags);
35355 @@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
35356 if (!cs->connected) {
35357 gig_dbg(DEBUG_IF, "not connected");
35358 retval = -ENODEV;
35359 - } else if (!cs->open_count)
35360 + } else if (!local_read(&cs->open_count))
35361 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35362 else {
35363 retval = 0;
35364 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
35365 if (!cs->connected) {
35366 gig_dbg(DEBUG_IF, "not connected");
35367 retval = -ENODEV;
35368 - } else if (!cs->open_count)
35369 + } else if (!local_read(&cs->open_count))
35370 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35371 else if (cs->mstate != MS_LOCKED) {
35372 dev_warn(cs->dev, "can't write to unlocked device\n");
35373 @@ -395,7 +393,7 @@ static int if_write_room(struct tty_struct *tty)
35374 if (!cs->connected) {
35375 gig_dbg(DEBUG_IF, "not connected");
35376 retval = -ENODEV;
35377 - } else if (!cs->open_count)
35378 + } else if (!local_read(&cs->open_count))
35379 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35380 else if (cs->mstate != MS_LOCKED) {
35381 dev_warn(cs->dev, "can't write to unlocked device\n");
35382 @@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
35383
35384 if (!cs->connected)
35385 gig_dbg(DEBUG_IF, "not connected");
35386 - else if (!cs->open_count)
35387 + else if (!local_read(&cs->open_count))
35388 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35389 else if (cs->mstate != MS_LOCKED)
35390 dev_warn(cs->dev, "can't write to unlocked device\n");
35391 @@ -453,7 +451,7 @@ static void if_throttle(struct tty_struct *tty)
35392
35393 if (!cs->connected)
35394 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35395 - else if (!cs->open_count)
35396 + else if (!local_read(&cs->open_count))
35397 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35398 else {
35399 //FIXME
35400 @@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_struct *tty)
35401
35402 if (!cs->connected)
35403 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35404 - else if (!cs->open_count)
35405 + else if (!local_read(&cs->open_count))
35406 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35407 else {
35408 //FIXME
35409 @@ -510,7 +508,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
35410 goto out;
35411 }
35412
35413 - if (!cs->open_count) {
35414 + if (!local_read(&cs->open_count)) {
35415 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35416 goto out;
35417 }
35418 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35419 index a7c0083..62a7cb6 100644
35420 --- a/drivers/isdn/hardware/avm/b1.c
35421 +++ b/drivers/isdn/hardware/avm/b1.c
35422 @@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
35423 }
35424 if (left) {
35425 if (t4file->user) {
35426 - if (copy_from_user(buf, dp, left))
35427 + if (left > sizeof buf || copy_from_user(buf, dp, left))
35428 return -EFAULT;
35429 } else {
35430 memcpy(buf, dp, left);
35431 @@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
35432 }
35433 if (left) {
35434 if (config->user) {
35435 - if (copy_from_user(buf, dp, left))
35436 + if (left > sizeof buf || copy_from_user(buf, dp, left))
35437 return -EFAULT;
35438 } else {
35439 memcpy(buf, dp, left);
35440 diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
35441 index f130724..c373c68 100644
35442 --- a/drivers/isdn/hardware/eicon/capidtmf.c
35443 +++ b/drivers/isdn/hardware/eicon/capidtmf.c
35444 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
35445 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
35446 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
35447
35448 + pax_track_stack();
35449
35450 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
35451 {
35452 diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
35453 index 4d425c6..a9be6c4 100644
35454 --- a/drivers/isdn/hardware/eicon/capifunc.c
35455 +++ b/drivers/isdn/hardware/eicon/capifunc.c
35456 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
35457 IDI_SYNC_REQ req;
35458 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35459
35460 + pax_track_stack();
35461 +
35462 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35463
35464 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35465 diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
35466 index 3029234..ef0d9e2 100644
35467 --- a/drivers/isdn/hardware/eicon/diddfunc.c
35468 +++ b/drivers/isdn/hardware/eicon/diddfunc.c
35469 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35470 IDI_SYNC_REQ req;
35471 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35472
35473 + pax_track_stack();
35474 +
35475 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35476
35477 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35478 diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
35479 index d36a4c0..11e7d1a 100644
35480 --- a/drivers/isdn/hardware/eicon/divasfunc.c
35481 +++ b/drivers/isdn/hardware/eicon/divasfunc.c
35482 @@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35483 IDI_SYNC_REQ req;
35484 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35485
35486 + pax_track_stack();
35487 +
35488 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35489
35490 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35491 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
35492 index 85784a7..a19ca98 100644
35493 --- a/drivers/isdn/hardware/eicon/divasync.h
35494 +++ b/drivers/isdn/hardware/eicon/divasync.h
35495 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
35496 } diva_didd_add_adapter_t;
35497 typedef struct _diva_didd_remove_adapter {
35498 IDI_CALL p_request;
35499 -} diva_didd_remove_adapter_t;
35500 +} __no_const diva_didd_remove_adapter_t;
35501 typedef struct _diva_didd_read_adapter_array {
35502 void * buffer;
35503 dword length;
35504 diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
35505 index db87d51..7d09acf 100644
35506 --- a/drivers/isdn/hardware/eicon/idifunc.c
35507 +++ b/drivers/isdn/hardware/eicon/idifunc.c
35508 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35509 IDI_SYNC_REQ req;
35510 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35511
35512 + pax_track_stack();
35513 +
35514 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35515
35516 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35517 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
35518 index ae89fb8..0fab299 100644
35519 --- a/drivers/isdn/hardware/eicon/message.c
35520 +++ b/drivers/isdn/hardware/eicon/message.c
35521 @@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
35522 dword d;
35523 word w;
35524
35525 + pax_track_stack();
35526 +
35527 a = plci->adapter;
35528 Id = ((word)plci->Id<<8)|a->Id;
35529 PUT_WORD(&SS_Ind[4],0x0000);
35530 @@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
35531 word j, n, w;
35532 dword d;
35533
35534 + pax_track_stack();
35535 +
35536
35537 for(i=0;i<8;i++) bp_parms[i].length = 0;
35538 for(i=0;i<2;i++) global_config[i].length = 0;
35539 @@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
35540 const byte llc3[] = {4,3,2,2,6,6,0};
35541 const byte header[] = {0,2,3,3,0,0,0};
35542
35543 + pax_track_stack();
35544 +
35545 for(i=0;i<8;i++) bp_parms[i].length = 0;
35546 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
35547 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
35548 @@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
35549 word appl_number_group_type[MAX_APPL];
35550 PLCI *auxplci;
35551
35552 + pax_track_stack();
35553 +
35554 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
35555
35556 if(!a->group_optimization_enabled)
35557 diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
35558 index a564b75..f3cf8b5 100644
35559 --- a/drivers/isdn/hardware/eicon/mntfunc.c
35560 +++ b/drivers/isdn/hardware/eicon/mntfunc.c
35561 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35562 IDI_SYNC_REQ req;
35563 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35564
35565 + pax_track_stack();
35566 +
35567 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35568
35569 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35570 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
35571 index a3bd163..8956575 100644
35572 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
35573 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
35574 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
35575 typedef struct _diva_os_idi_adapter_interface {
35576 diva_init_card_proc_t cleanup_adapter_proc;
35577 diva_cmd_card_proc_t cmd_proc;
35578 -} diva_os_idi_adapter_interface_t;
35579 +} __no_const diva_os_idi_adapter_interface_t;
35580
35581 typedef struct _diva_os_xdi_adapter {
35582 struct list_head link;
35583 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
35584 index adb1e8c..21b590b 100644
35585 --- a/drivers/isdn/i4l/isdn_common.c
35586 +++ b/drivers/isdn/i4l/isdn_common.c
35587 @@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
35588 } iocpar;
35589 void __user *argp = (void __user *)arg;
35590
35591 + pax_track_stack();
35592 +
35593 #define name iocpar.name
35594 #define bname iocpar.bname
35595 #define iocts iocpar.iocts
35596 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35597 index bf7997a..cf091db 100644
35598 --- a/drivers/isdn/icn/icn.c
35599 +++ b/drivers/isdn/icn/icn.c
35600 @@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
35601 if (count > len)
35602 count = len;
35603 if (user) {
35604 - if (copy_from_user(msg, buf, count))
35605 + if (count > sizeof msg || copy_from_user(msg, buf, count))
35606 return -EFAULT;
35607 } else
35608 memcpy(msg, buf, count);
35609 diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
35610 index feb0fa4..f76f830 100644
35611 --- a/drivers/isdn/mISDN/socket.c
35612 +++ b/drivers/isdn/mISDN/socket.c
35613 @@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35614 if (dev) {
35615 struct mISDN_devinfo di;
35616
35617 + memset(&di, 0, sizeof(di));
35618 di.id = dev->id;
35619 di.Dprotocols = dev->Dprotocols;
35620 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35621 @@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35622 if (dev) {
35623 struct mISDN_devinfo di;
35624
35625 + memset(&di, 0, sizeof(di));
35626 di.id = dev->id;
35627 di.Dprotocols = dev->Dprotocols;
35628 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35629 diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
35630 index 485be8b..f0225bc 100644
35631 --- a/drivers/isdn/sc/interrupt.c
35632 +++ b/drivers/isdn/sc/interrupt.c
35633 @@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35634 }
35635 else if(callid>=0x0000 && callid<=0x7FFF)
35636 {
35637 + int len;
35638 +
35639 pr_debug("%s: Got Incoming Call\n",
35640 sc_adapter[card]->devicename);
35641 - strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
35642 - strcpy(setup.eazmsn,
35643 - sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
35644 + len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
35645 + sizeof(setup.phone));
35646 + if (len >= sizeof(setup.phone))
35647 + continue;
35648 + len = strlcpy(setup.eazmsn,
35649 + sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35650 + sizeof(setup.eazmsn));
35651 + if (len >= sizeof(setup.eazmsn))
35652 + continue;
35653 setup.si1 = 7;
35654 setup.si2 = 0;
35655 setup.plan = 0;
35656 @@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35657 * Handle a GetMyNumber Rsp
35658 */
35659 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
35660 - strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
35661 + strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35662 + rcvmsg.msg_data.byte_array,
35663 + sizeof(rcvmsg.msg_data.byte_array));
35664 continue;
35665 }
35666
35667 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35668 index 8744d24..d1f9a9a 100644
35669 --- a/drivers/lguest/core.c
35670 +++ b/drivers/lguest/core.c
35671 @@ -91,9 +91,17 @@ static __init int map_switcher(void)
35672 * it's worked so far. The end address needs +1 because __get_vm_area
35673 * allocates an extra guard page, so we need space for that.
35674 */
35675 +
35676 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35677 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35678 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35679 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35680 +#else
35681 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35682 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35683 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35684 +#endif
35685 +
35686 if (!switcher_vma) {
35687 err = -ENOMEM;
35688 printk("lguest: could not map switcher pages high\n");
35689 @@ -118,7 +126,7 @@ static __init int map_switcher(void)
35690 * Now the Switcher is mapped at the right address, we can't fail!
35691 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
35692 */
35693 - memcpy(switcher_vma->addr, start_switcher_text,
35694 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35695 end_switcher_text - start_switcher_text);
35696
35697 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35698 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35699 index 6ae3888..8b38145 100644
35700 --- a/drivers/lguest/x86/core.c
35701 +++ b/drivers/lguest/x86/core.c
35702 @@ -59,7 +59,7 @@ static struct {
35703 /* Offset from where switcher.S was compiled to where we've copied it */
35704 static unsigned long switcher_offset(void)
35705 {
35706 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35707 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35708 }
35709
35710 /* This cpu's struct lguest_pages. */
35711 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35712 * These copies are pretty cheap, so we do them unconditionally: */
35713 /* Save the current Host top-level page directory.
35714 */
35715 +
35716 +#ifdef CONFIG_PAX_PER_CPU_PGD
35717 + pages->state.host_cr3 = read_cr3();
35718 +#else
35719 pages->state.host_cr3 = __pa(current->mm->pgd);
35720 +#endif
35721 +
35722 /*
35723 * Set up the Guest's page tables to see this CPU's pages (and no
35724 * other CPU's pages).
35725 @@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
35726 * compiled-in switcher code and the high-mapped copy we just made.
35727 */
35728 for (i = 0; i < IDT_ENTRIES; i++)
35729 - default_idt_entries[i] += switcher_offset();
35730 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35731
35732 /*
35733 * Set up the Switcher's per-cpu areas.
35734 @@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
35735 * it will be undisturbed when we switch. To change %cs and jump we
35736 * need this structure to feed to Intel's "lcall" instruction.
35737 */
35738 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35739 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35740 lguest_entry.segment = LGUEST_CS;
35741
35742 /*
35743 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35744 index 40634b0..4f5855e 100644
35745 --- a/drivers/lguest/x86/switcher_32.S
35746 +++ b/drivers/lguest/x86/switcher_32.S
35747 @@ -87,6 +87,7 @@
35748 #include <asm/page.h>
35749 #include <asm/segment.h>
35750 #include <asm/lguest.h>
35751 +#include <asm/processor-flags.h>
35752
35753 // We mark the start of the code to copy
35754 // It's placed in .text tho it's never run here
35755 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35756 // Changes type when we load it: damn Intel!
35757 // For after we switch over our page tables
35758 // That entry will be read-only: we'd crash.
35759 +
35760 +#ifdef CONFIG_PAX_KERNEXEC
35761 + mov %cr0, %edx
35762 + xor $X86_CR0_WP, %edx
35763 + mov %edx, %cr0
35764 +#endif
35765 +
35766 movl $(GDT_ENTRY_TSS*8), %edx
35767 ltr %dx
35768
35769 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35770 // Let's clear it again for our return.
35771 // The GDT descriptor of the Host
35772 // Points to the table after two "size" bytes
35773 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35774 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35775 // Clear "used" from type field (byte 5, bit 2)
35776 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35777 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35778 +
35779 +#ifdef CONFIG_PAX_KERNEXEC
35780 + mov %cr0, %eax
35781 + xor $X86_CR0_WP, %eax
35782 + mov %eax, %cr0
35783 +#endif
35784
35785 // Once our page table's switched, the Guest is live!
35786 // The Host fades as we run this final step.
35787 @@ -295,13 +309,12 @@ deliver_to_host:
35788 // I consulted gcc, and it gave
35789 // These instructions, which I gladly credit:
35790 leal (%edx,%ebx,8), %eax
35791 - movzwl (%eax),%edx
35792 - movl 4(%eax), %eax
35793 - xorw %ax, %ax
35794 - orl %eax, %edx
35795 + movl 4(%eax), %edx
35796 + movw (%eax), %dx
35797 // Now the address of the handler's in %edx
35798 // We call it now: its "iret" drops us home.
35799 - jmp *%edx
35800 + ljmp $__KERNEL_CS, $1f
35801 +1: jmp *%edx
35802
35803 // Every interrupt can come to us here
35804 // But we must truly tell each apart.
35805 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
35806 index 588a5b0..b71db89 100644
35807 --- a/drivers/macintosh/macio_asic.c
35808 +++ b/drivers/macintosh/macio_asic.c
35809 @@ -701,7 +701,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
35810 * MacIO is matched against any Apple ID, it's probe() function
35811 * will then decide wether it applies or not
35812 */
35813 -static const struct pci_device_id __devinitdata pci_ids [] = { {
35814 +static const struct pci_device_id __devinitconst pci_ids [] = { {
35815 .vendor = PCI_VENDOR_ID_APPLE,
35816 .device = PCI_ANY_ID,
35817 .subvendor = PCI_ANY_ID,
35818 diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
35819 index a348bb0..ecd9b3f 100644
35820 --- a/drivers/macintosh/via-pmu-backlight.c
35821 +++ b/drivers/macintosh/via-pmu-backlight.c
35822 @@ -15,7 +15,7 @@
35823
35824 #define MAX_PMU_LEVEL 0xFF
35825
35826 -static struct backlight_ops pmu_backlight_data;
35827 +static const struct backlight_ops pmu_backlight_data;
35828 static DEFINE_SPINLOCK(pmu_backlight_lock);
35829 static int sleeping, uses_pmu_bl;
35830 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
35831 @@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(struct backlight_device *bd)
35832 return bd->props.brightness;
35833 }
35834
35835 -static struct backlight_ops pmu_backlight_data = {
35836 +static const struct backlight_ops pmu_backlight_data = {
35837 .get_brightness = pmu_backlight_get_brightness,
35838 .update_status = pmu_backlight_update_status,
35839
35840 diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
35841 index 6f308a4..b5f7ff7 100644
35842 --- a/drivers/macintosh/via-pmu.c
35843 +++ b/drivers/macintosh/via-pmu.c
35844 @@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state_t state)
35845 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
35846 }
35847
35848 -static struct platform_suspend_ops pmu_pm_ops = {
35849 +static const struct platform_suspend_ops pmu_pm_ops = {
35850 .enter = powerbook_sleep,
35851 .valid = pmu_sleep_valid,
35852 };
35853 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35854 index 818b617..4656e38 100644
35855 --- a/drivers/md/dm-ioctl.c
35856 +++ b/drivers/md/dm-ioctl.c
35857 @@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35858 cmd == DM_LIST_VERSIONS_CMD)
35859 return 0;
35860
35861 - if ((cmd == DM_DEV_CREATE_CMD)) {
35862 + if (cmd == DM_DEV_CREATE_CMD) {
35863 if (!*param->name) {
35864 DMWARN("name not supplied when creating device");
35865 return -EINVAL;
35866 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35867 index 6021d0a..a878643 100644
35868 --- a/drivers/md/dm-raid1.c
35869 +++ b/drivers/md/dm-raid1.c
35870 @@ -41,7 +41,7 @@ enum dm_raid1_error {
35871
35872 struct mirror {
35873 struct mirror_set *ms;
35874 - atomic_t error_count;
35875 + atomic_unchecked_t error_count;
35876 unsigned long error_type;
35877 struct dm_dev *dev;
35878 sector_t offset;
35879 @@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35880 * simple way to tell if a device has encountered
35881 * errors.
35882 */
35883 - atomic_inc(&m->error_count);
35884 + atomic_inc_unchecked(&m->error_count);
35885
35886 if (test_and_set_bit(error_type, &m->error_type))
35887 return;
35888 @@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35889 }
35890
35891 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
35892 - if (!atomic_read(&new->error_count)) {
35893 + if (!atomic_read_unchecked(&new->error_count)) {
35894 set_default_mirror(new);
35895 break;
35896 }
35897 @@ -363,7 +363,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35898 struct mirror *m = get_default_mirror(ms);
35899
35900 do {
35901 - if (likely(!atomic_read(&m->error_count)))
35902 + if (likely(!atomic_read_unchecked(&m->error_count)))
35903 return m;
35904
35905 if (m-- == ms->mirror)
35906 @@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
35907 {
35908 struct mirror *default_mirror = get_default_mirror(m->ms);
35909
35910 - return !atomic_read(&default_mirror->error_count);
35911 + return !atomic_read_unchecked(&default_mirror->error_count);
35912 }
35913
35914 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35915 @@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35916 */
35917 if (likely(region_in_sync(ms, region, 1)))
35918 m = choose_mirror(ms, bio->bi_sector);
35919 - else if (m && atomic_read(&m->error_count))
35920 + else if (m && atomic_read_unchecked(&m->error_count))
35921 m = NULL;
35922
35923 if (likely(m))
35924 @@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35925 }
35926
35927 ms->mirror[mirror].ms = ms;
35928 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35929 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35930 ms->mirror[mirror].error_type = 0;
35931 ms->mirror[mirror].offset = offset;
35932
35933 @@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_target *ti)
35934 */
35935 static char device_status_char(struct mirror *m)
35936 {
35937 - if (!atomic_read(&(m->error_count)))
35938 + if (!atomic_read_unchecked(&(m->error_count)))
35939 return 'A';
35940
35941 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
35942 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35943 index bd58703..9f26571 100644
35944 --- a/drivers/md/dm-stripe.c
35945 +++ b/drivers/md/dm-stripe.c
35946 @@ -20,7 +20,7 @@ struct stripe {
35947 struct dm_dev *dev;
35948 sector_t physical_start;
35949
35950 - atomic_t error_count;
35951 + atomic_unchecked_t error_count;
35952 };
35953
35954 struct stripe_c {
35955 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35956 kfree(sc);
35957 return r;
35958 }
35959 - atomic_set(&(sc->stripe[i].error_count), 0);
35960 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35961 }
35962
35963 ti->private = sc;
35964 @@ -257,7 +257,7 @@ static int stripe_status(struct dm_target *ti,
35965 DMEMIT("%d ", sc->stripes);
35966 for (i = 0; i < sc->stripes; i++) {
35967 DMEMIT("%s ", sc->stripe[i].dev->name);
35968 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35969 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35970 'D' : 'A';
35971 }
35972 buffer[i] = '\0';
35973 @@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35974 */
35975 for (i = 0; i < sc->stripes; i++)
35976 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35977 - atomic_inc(&(sc->stripe[i].error_count));
35978 - if (atomic_read(&(sc->stripe[i].error_count)) <
35979 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35980 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35981 DM_IO_ERROR_THRESHOLD)
35982 queue_work(kstriped, &sc->kstriped_ws);
35983 }
35984 diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c
35985 index 4b04590..13a77b2 100644
35986 --- a/drivers/md/dm-sysfs.c
35987 +++ b/drivers/md/dm-sysfs.c
35988 @@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
35989 NULL,
35990 };
35991
35992 -static struct sysfs_ops dm_sysfs_ops = {
35993 +static const struct sysfs_ops dm_sysfs_ops = {
35994 .show = dm_attr_show,
35995 };
35996
35997 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35998 index 03345bb..332250d 100644
35999 --- a/drivers/md/dm-table.c
36000 +++ b/drivers/md/dm-table.c
36001 @@ -376,7 +376,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
36002 if (!dev_size)
36003 return 0;
36004
36005 - if ((start >= dev_size) || (start + len > dev_size)) {
36006 + if ((start >= dev_size) || (len > dev_size - start)) {
36007 DMWARN("%s: %s too small for target: "
36008 "start=%llu, len=%llu, dev_size=%llu",
36009 dm_device_name(ti->table->md), bdevname(bdev, b),
36010 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
36011 index c988ac2..c418141 100644
36012 --- a/drivers/md/dm.c
36013 +++ b/drivers/md/dm.c
36014 @@ -165,9 +165,9 @@ struct mapped_device {
36015 /*
36016 * Event handling.
36017 */
36018 - atomic_t event_nr;
36019 + atomic_unchecked_t event_nr;
36020 wait_queue_head_t eventq;
36021 - atomic_t uevent_seq;
36022 + atomic_unchecked_t uevent_seq;
36023 struct list_head uevent_list;
36024 spinlock_t uevent_lock; /* Protect access to uevent_list */
36025
36026 @@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(int minor)
36027 rwlock_init(&md->map_lock);
36028 atomic_set(&md->holders, 1);
36029 atomic_set(&md->open_count, 0);
36030 - atomic_set(&md->event_nr, 0);
36031 - atomic_set(&md->uevent_seq, 0);
36032 + atomic_set_unchecked(&md->event_nr, 0);
36033 + atomic_set_unchecked(&md->uevent_seq, 0);
36034 INIT_LIST_HEAD(&md->uevent_list);
36035 spin_lock_init(&md->uevent_lock);
36036
36037 @@ -1927,7 +1927,7 @@ static void event_callback(void *context)
36038
36039 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36040
36041 - atomic_inc(&md->event_nr);
36042 + atomic_inc_unchecked(&md->event_nr);
36043 wake_up(&md->eventq);
36044 }
36045
36046 @@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36047
36048 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36049 {
36050 - return atomic_add_return(1, &md->uevent_seq);
36051 + return atomic_add_return_unchecked(1, &md->uevent_seq);
36052 }
36053
36054 uint32_t dm_get_event_nr(struct mapped_device *md)
36055 {
36056 - return atomic_read(&md->event_nr);
36057 + return atomic_read_unchecked(&md->event_nr);
36058 }
36059
36060 int dm_wait_event(struct mapped_device *md, int event_nr)
36061 {
36062 return wait_event_interruptible(md->eventq,
36063 - (event_nr != atomic_read(&md->event_nr)));
36064 + (event_nr != atomic_read_unchecked(&md->event_nr)));
36065 }
36066
36067 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36068 diff --git a/drivers/md/md.c b/drivers/md/md.c
36069 index 4ce6e2f..7a9530a 100644
36070 --- a/drivers/md/md.c
36071 +++ b/drivers/md/md.c
36072 @@ -153,10 +153,10 @@ static int start_readonly;
36073 * start build, activate spare
36074 */
36075 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36076 -static atomic_t md_event_count;
36077 +static atomic_unchecked_t md_event_count;
36078 void md_new_event(mddev_t *mddev)
36079 {
36080 - atomic_inc(&md_event_count);
36081 + atomic_inc_unchecked(&md_event_count);
36082 wake_up(&md_event_waiters);
36083 }
36084 EXPORT_SYMBOL_GPL(md_new_event);
36085 @@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36086 */
36087 static void md_new_event_inintr(mddev_t *mddev)
36088 {
36089 - atomic_inc(&md_event_count);
36090 + atomic_inc_unchecked(&md_event_count);
36091 wake_up(&md_event_waiters);
36092 }
36093
36094 @@ -1226,7 +1226,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
36095
36096 rdev->preferred_minor = 0xffff;
36097 rdev->data_offset = le64_to_cpu(sb->data_offset);
36098 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36099 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36100
36101 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36102 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36103 @@ -1400,7 +1400,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
36104 else
36105 sb->resync_offset = cpu_to_le64(0);
36106
36107 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36108 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36109
36110 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36111 sb->size = cpu_to_le64(mddev->dev_sectors);
36112 @@ -2222,7 +2222,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36113 static ssize_t
36114 errors_show(mdk_rdev_t *rdev, char *page)
36115 {
36116 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36117 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36118 }
36119
36120 static ssize_t
36121 @@ -2231,7 +2231,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
36122 char *e;
36123 unsigned long n = simple_strtoul(buf, &e, 10);
36124 if (*buf && (*e == 0 || *e == '\n')) {
36125 - atomic_set(&rdev->corrected_errors, n);
36126 + atomic_set_unchecked(&rdev->corrected_errors, n);
36127 return len;
36128 }
36129 return -EINVAL;
36130 @@ -2525,7 +2525,7 @@ static void rdev_free(struct kobject *ko)
36131 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
36132 kfree(rdev);
36133 }
36134 -static struct sysfs_ops rdev_sysfs_ops = {
36135 +static const struct sysfs_ops rdev_sysfs_ops = {
36136 .show = rdev_attr_show,
36137 .store = rdev_attr_store,
36138 };
36139 @@ -2574,8 +2574,8 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
36140 rdev->data_offset = 0;
36141 rdev->sb_events = 0;
36142 atomic_set(&rdev->nr_pending, 0);
36143 - atomic_set(&rdev->read_errors, 0);
36144 - atomic_set(&rdev->corrected_errors, 0);
36145 + atomic_set_unchecked(&rdev->read_errors, 0);
36146 + atomic_set_unchecked(&rdev->corrected_errors, 0);
36147
36148 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
36149 if (!size) {
36150 @@ -3895,7 +3895,7 @@ static void md_free(struct kobject *ko)
36151 kfree(mddev);
36152 }
36153
36154 -static struct sysfs_ops md_sysfs_ops = {
36155 +static const struct sysfs_ops md_sysfs_ops = {
36156 .show = md_attr_show,
36157 .store = md_attr_store,
36158 };
36159 @@ -4482,7 +4482,8 @@ out:
36160 err = 0;
36161 blk_integrity_unregister(disk);
36162 md_new_event(mddev);
36163 - sysfs_notify_dirent(mddev->sysfs_state);
36164 + if (mddev->sysfs_state)
36165 + sysfs_notify_dirent(mddev->sysfs_state);
36166 return err;
36167 }
36168
36169 @@ -5962,7 +5963,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36170
36171 spin_unlock(&pers_lock);
36172 seq_printf(seq, "\n");
36173 - mi->event = atomic_read(&md_event_count);
36174 + mi->event = atomic_read_unchecked(&md_event_count);
36175 return 0;
36176 }
36177 if (v == (void*)2) {
36178 @@ -6051,7 +6052,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36179 chunk_kb ? "KB" : "B");
36180 if (bitmap->file) {
36181 seq_printf(seq, ", file: ");
36182 - seq_path(seq, &bitmap->file->f_path, " \t\n");
36183 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
36184 }
36185
36186 seq_printf(seq, "\n");
36187 @@ -6085,7 +6086,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36188 else {
36189 struct seq_file *p = file->private_data;
36190 p->private = mi;
36191 - mi->event = atomic_read(&md_event_count);
36192 + mi->event = atomic_read_unchecked(&md_event_count);
36193 }
36194 return error;
36195 }
36196 @@ -6101,7 +6102,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36197 /* always allow read */
36198 mask = POLLIN | POLLRDNORM;
36199
36200 - if (mi->event != atomic_read(&md_event_count))
36201 + if (mi->event != atomic_read_unchecked(&md_event_count))
36202 mask |= POLLERR | POLLPRI;
36203 return mask;
36204 }
36205 @@ -6145,7 +6146,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
36206 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36207 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36208 (int)part_stat_read(&disk->part0, sectors[1]) -
36209 - atomic_read(&disk->sync_io);
36210 + atomic_read_unchecked(&disk->sync_io);
36211 /* sync IO will cause sync_io to increase before the disk_stats
36212 * as sync_io is counted when a request starts, and
36213 * disk_stats is counted when it completes.
36214 diff --git a/drivers/md/md.h b/drivers/md/md.h
36215 index 87430fe..0024a4c 100644
36216 --- a/drivers/md/md.h
36217 +++ b/drivers/md/md.h
36218 @@ -94,10 +94,10 @@ struct mdk_rdev_s
36219 * only maintained for arrays that
36220 * support hot removal
36221 */
36222 - atomic_t read_errors; /* number of consecutive read errors that
36223 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
36224 * we have tried to ignore.
36225 */
36226 - atomic_t corrected_errors; /* number of corrected read errors,
36227 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36228 * for reporting to userspace and storing
36229 * in superblock.
36230 */
36231 @@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
36232
36233 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36234 {
36235 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36236 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36237 }
36238
36239 struct mdk_personality
36240 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36241 index 968cb14..f0ad2e4 100644
36242 --- a/drivers/md/raid1.c
36243 +++ b/drivers/md/raid1.c
36244 @@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
36245 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
36246 continue;
36247 rdev = conf->mirrors[d].rdev;
36248 - atomic_add(s, &rdev->corrected_errors);
36249 + atomic_add_unchecked(s, &rdev->corrected_errors);
36250 if (sync_page_io(rdev->bdev,
36251 sect + rdev->data_offset,
36252 s<<9,
36253 @@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
36254 /* Well, this device is dead */
36255 md_error(mddev, rdev);
36256 else {
36257 - atomic_add(s, &rdev->corrected_errors);
36258 + atomic_add_unchecked(s, &rdev->corrected_errors);
36259 printk(KERN_INFO
36260 "raid1:%s: read error corrected "
36261 "(%d sectors at %llu on %s)\n",
36262 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36263 index 1b4e232..cf0f534 100644
36264 --- a/drivers/md/raid10.c
36265 +++ b/drivers/md/raid10.c
36266 @@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bio, int error)
36267 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
36268 set_bit(R10BIO_Uptodate, &r10_bio->state);
36269 else {
36270 - atomic_add(r10_bio->sectors,
36271 + atomic_add_unchecked(r10_bio->sectors,
36272 &conf->mirrors[d].rdev->corrected_errors);
36273 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
36274 md_error(r10_bio->mddev,
36275 @@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
36276 test_bit(In_sync, &rdev->flags)) {
36277 atomic_inc(&rdev->nr_pending);
36278 rcu_read_unlock();
36279 - atomic_add(s, &rdev->corrected_errors);
36280 + atomic_add_unchecked(s, &rdev->corrected_errors);
36281 if (sync_page_io(rdev->bdev,
36282 r10_bio->devs[sl].addr +
36283 sect + rdev->data_offset,
36284 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36285 index 883215d..675bf47 100644
36286 --- a/drivers/md/raid5.c
36287 +++ b/drivers/md/raid5.c
36288 @@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
36289 bi->bi_next = NULL;
36290 if ((rw & WRITE) &&
36291 test_bit(R5_ReWrite, &sh->dev[i].flags))
36292 - atomic_add(STRIPE_SECTORS,
36293 + atomic_add_unchecked(STRIPE_SECTORS,
36294 &rdev->corrected_errors);
36295 generic_make_request(bi);
36296 } else {
36297 @@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struct bio * bi, int error)
36298 clear_bit(R5_ReadError, &sh->dev[i].flags);
36299 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36300 }
36301 - if (atomic_read(&conf->disks[i].rdev->read_errors))
36302 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
36303 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
36304 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
36305 } else {
36306 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
36307 int retry = 0;
36308 rdev = conf->disks[i].rdev;
36309
36310 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36311 - atomic_inc(&rdev->read_errors);
36312 + atomic_inc_unchecked(&rdev->read_errors);
36313 if (conf->mddev->degraded >= conf->max_degraded)
36314 printk_rl(KERN_WARNING
36315 "raid5:%s: read error not correctable "
36316 @@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36317 (unsigned long long)(sh->sector
36318 + rdev->data_offset),
36319 bdn);
36320 - else if (atomic_read(&rdev->read_errors)
36321 + else if (atomic_read_unchecked(&rdev->read_errors)
36322 > conf->max_nr_stripes)
36323 printk(KERN_WARNING
36324 "raid5:%s: Too many read errors, failing device %s.\n",
36325 @@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
36326 sector_t r_sector;
36327 struct stripe_head sh2;
36328
36329 + pax_track_stack();
36330
36331 chunk_offset = sector_div(new_sector, sectors_per_chunk);
36332 stripe = new_sector;
36333 diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
36334 index 05bde9c..2f31d40 100644
36335 --- a/drivers/media/common/saa7146_hlp.c
36336 +++ b/drivers/media/common/saa7146_hlp.c
36337 @@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
36338
36339 int x[32], y[32], w[32], h[32];
36340
36341 + pax_track_stack();
36342 +
36343 /* clear out memory */
36344 memset(&line_list[0], 0x00, sizeof(u32)*32);
36345 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
36346 diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36347 index cb22da5..82b686e 100644
36348 --- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36349 +++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36350 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
36351 u8 buf[HOST_LINK_BUF_SIZE];
36352 int i;
36353
36354 + pax_track_stack();
36355 +
36356 dprintk("%s\n", __func__);
36357
36358 /* check if we have space for a link buf in the rx_buffer */
36359 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
36360 unsigned long timeout;
36361 int written;
36362
36363 + pax_track_stack();
36364 +
36365 dprintk("%s\n", __func__);
36366
36367 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
36368 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
36369 index 2fe05d0..a3289c4 100644
36370 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
36371 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
36372 @@ -71,7 +71,7 @@ struct dvb_demux_feed {
36373 union {
36374 dmx_ts_cb ts;
36375 dmx_section_cb sec;
36376 - } cb;
36377 + } __no_const cb;
36378
36379 struct dvb_demux *demux;
36380 void *priv;
36381 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
36382 index 94159b9..376bd8e 100644
36383 --- a/drivers/media/dvb/dvb-core/dvbdev.c
36384 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
36385 @@ -191,7 +191,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36386 const struct dvb_device *template, void *priv, int type)
36387 {
36388 struct dvb_device *dvbdev;
36389 - struct file_operations *dvbdevfops;
36390 + file_operations_no_const *dvbdevfops;
36391 struct device *clsdev;
36392 int minor;
36393 int id;
36394 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
36395 index 2a53dd0..db8c07a 100644
36396 --- a/drivers/media/dvb/dvb-usb/cxusb.c
36397 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
36398 @@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36399 struct dib0700_adapter_state {
36400 int (*set_param_save) (struct dvb_frontend *,
36401 struct dvb_frontend_parameters *);
36402 -};
36403 +} __no_const;
36404
36405 static int dib7070_set_param_override(struct dvb_frontend *fe,
36406 struct dvb_frontend_parameters *fep)
36407 diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
36408 index db7f7f7..f55e96f 100644
36409 --- a/drivers/media/dvb/dvb-usb/dib0700_core.c
36410 +++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
36411 @@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
36412
36413 u8 buf[260];
36414
36415 + pax_track_stack();
36416 +
36417 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
36418 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
36419
36420 diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36421 index 524acf5..5ffc403 100644
36422 --- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
36423 +++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36424 @@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
36425
36426 struct dib0700_adapter_state {
36427 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
36428 -};
36429 +} __no_const;
36430
36431 /* Hauppauge Nova-T 500 (aka Bristol)
36432 * has a LNA on GPIO0 which is enabled by setting 1 */
36433 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
36434 index ba91735..4261d84 100644
36435 --- a/drivers/media/dvb/frontends/dib3000.h
36436 +++ b/drivers/media/dvb/frontends/dib3000.h
36437 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36438 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36439 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36440 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36441 -};
36442 +} __no_const;
36443
36444 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36445 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36446 diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
36447 index c709ce6..b3fe620 100644
36448 --- a/drivers/media/dvb/frontends/or51211.c
36449 +++ b/drivers/media/dvb/frontends/or51211.c
36450 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
36451 u8 tudata[585];
36452 int i;
36453
36454 + pax_track_stack();
36455 +
36456 dprintk("Firmware is %zd bytes\n",fw->size);
36457
36458 /* Get eprom data */
36459 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36460 index 482d0f3..ee1e202 100644
36461 --- a/drivers/media/radio/radio-cadet.c
36462 +++ b/drivers/media/radio/radio-cadet.c
36463 @@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36464 while (i < count && dev->rdsin != dev->rdsout)
36465 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36466
36467 - if (copy_to_user(data, readbuf, i))
36468 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
36469 return -EFAULT;
36470 return i;
36471 }
36472 diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
36473 index 6dd51e2..0359b92 100644
36474 --- a/drivers/media/video/cx18/cx18-driver.c
36475 +++ b/drivers/media/video/cx18/cx18-driver.c
36476 @@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
36477
36478 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
36479
36480 -static atomic_t cx18_instance = ATOMIC_INIT(0);
36481 +static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
36482
36483 /* Parameter declarations */
36484 static int cardtype[CX18_MAX_CARDS];
36485 @@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
36486 struct i2c_client c;
36487 u8 eedata[256];
36488
36489 + pax_track_stack();
36490 +
36491 memset(&c, 0, sizeof(c));
36492 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
36493 c.adapter = &cx->i2c_adap[0];
36494 @@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
36495 struct cx18 *cx;
36496
36497 /* FIXME - module parameter arrays constrain max instances */
36498 - i = atomic_inc_return(&cx18_instance) - 1;
36499 + i = atomic_inc_return_unchecked(&cx18_instance) - 1;
36500 if (i >= CX18_MAX_CARDS) {
36501 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
36502 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
36503 diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
36504 index 463ec34..2f4625a 100644
36505 --- a/drivers/media/video/ivtv/ivtv-driver.c
36506 +++ b/drivers/media/video/ivtv/ivtv-driver.c
36507 @@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
36508 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
36509
36510 /* ivtv instance counter */
36511 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
36512 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
36513
36514 /* Parameter declarations */
36515 static int cardtype[IVTV_MAX_CARDS];
36516 diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
36517 index 5fc4ac0..652a54a 100644
36518 --- a/drivers/media/video/omap24xxcam.c
36519 +++ b/drivers/media/video/omap24xxcam.c
36520 @@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
36521 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
36522
36523 do_gettimeofday(&vb->ts);
36524 - vb->field_count = atomic_add_return(2, &fh->field_count);
36525 + vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
36526 if (csr & csr_error) {
36527 vb->state = VIDEOBUF_ERROR;
36528 if (!atomic_read(&fh->cam->in_reset)) {
36529 diff --git a/drivers/media/video/omap24xxcam.h b/drivers/media/video/omap24xxcam.h
36530 index 2ce67f5..cf26a5b 100644
36531 --- a/drivers/media/video/omap24xxcam.h
36532 +++ b/drivers/media/video/omap24xxcam.h
36533 @@ -533,7 +533,7 @@ struct omap24xxcam_fh {
36534 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
36535 struct videobuf_queue vbq;
36536 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
36537 - atomic_t field_count; /* field counter for videobuf_buffer */
36538 + atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
36539 /* accessing cam here doesn't need serialisation: it's constant */
36540 struct omap24xxcam_device *cam;
36541 };
36542 diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36543 index 299afa4..eb47459 100644
36544 --- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36545 +++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36546 @@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
36547 u8 *eeprom;
36548 struct tveeprom tvdata;
36549
36550 + pax_track_stack();
36551 +
36552 memset(&tvdata,0,sizeof(tvdata));
36553
36554 eeprom = pvr2_eeprom_fetch(hdw);
36555 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36556 index 5b152ff..3320638 100644
36557 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36558 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36559 @@ -195,7 +195,7 @@ struct pvr2_hdw {
36560
36561 /* I2C stuff */
36562 struct i2c_adapter i2c_adap;
36563 - struct i2c_algorithm i2c_algo;
36564 + i2c_algorithm_no_const i2c_algo;
36565 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
36566 int i2c_cx25840_hack_state;
36567 int i2c_linked;
36568 diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
36569 index 1eabff6..8e2313a 100644
36570 --- a/drivers/media/video/saa7134/saa6752hs.c
36571 +++ b/drivers/media/video/saa7134/saa6752hs.c
36572 @@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
36573 unsigned char localPAT[256];
36574 unsigned char localPMT[256];
36575
36576 + pax_track_stack();
36577 +
36578 /* Set video format - must be done first as it resets other settings */
36579 set_reg8(client, 0x41, h->video_format);
36580
36581 diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
36582 index 9c1d3ac..b1b49e9 100644
36583 --- a/drivers/media/video/saa7164/saa7164-cmd.c
36584 +++ b/drivers/media/video/saa7164/saa7164-cmd.c
36585 @@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
36586 wait_queue_head_t *q = 0;
36587 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36588
36589 + pax_track_stack();
36590 +
36591 /* While any outstand message on the bus exists... */
36592 do {
36593
36594 @@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
36595 u8 tmp[512];
36596 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36597
36598 + pax_track_stack();
36599 +
36600 while (loop) {
36601
36602 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
36603 diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
36604 index b085496..cde0270 100644
36605 --- a/drivers/media/video/usbvideo/ibmcam.c
36606 +++ b/drivers/media/video/usbvideo/ibmcam.c
36607 @@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] = {
36608 static int __init ibmcam_init(void)
36609 {
36610 struct usbvideo_cb cbTbl;
36611 - memset(&cbTbl, 0, sizeof(cbTbl));
36612 - cbTbl.probe = ibmcam_probe;
36613 - cbTbl.setupOnOpen = ibmcam_setup_on_open;
36614 - cbTbl.videoStart = ibmcam_video_start;
36615 - cbTbl.videoStop = ibmcam_video_stop;
36616 - cbTbl.processData = ibmcam_ProcessIsocData;
36617 - cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36618 - cbTbl.adjustPicture = ibmcam_adjust_picture;
36619 - cbTbl.getFPS = ibmcam_calculate_fps;
36620 + memset((void *)&cbTbl, 0, sizeof(cbTbl));
36621 + *(void **)&cbTbl.probe = ibmcam_probe;
36622 + *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
36623 + *(void **)&cbTbl.videoStart = ibmcam_video_start;
36624 + *(void **)&cbTbl.videoStop = ibmcam_video_stop;
36625 + *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
36626 + *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36627 + *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
36628 + *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
36629 return usbvideo_register(
36630 &cams,
36631 MAX_IBMCAM,
36632 diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
36633 index 31d57f2..600b735 100644
36634 --- a/drivers/media/video/usbvideo/konicawc.c
36635 +++ b/drivers/media/video/usbvideo/konicawc.c
36636 @@ -225,7 +225,7 @@ static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev
36637 int error;
36638
36639 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36640 - strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36641 + strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36642
36643 cam->input = input_dev = input_allocate_device();
36644 if (!input_dev) {
36645 @@ -935,16 +935,16 @@ static int __init konicawc_init(void)
36646 struct usbvideo_cb cbTbl;
36647 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
36648 DRIVER_DESC "\n");
36649 - memset(&cbTbl, 0, sizeof(cbTbl));
36650 - cbTbl.probe = konicawc_probe;
36651 - cbTbl.setupOnOpen = konicawc_setup_on_open;
36652 - cbTbl.processData = konicawc_process_isoc;
36653 - cbTbl.getFPS = konicawc_calculate_fps;
36654 - cbTbl.setVideoMode = konicawc_set_video_mode;
36655 - cbTbl.startDataPump = konicawc_start_data;
36656 - cbTbl.stopDataPump = konicawc_stop_data;
36657 - cbTbl.adjustPicture = konicawc_adjust_picture;
36658 - cbTbl.userFree = konicawc_free_uvd;
36659 + memset((void * )&cbTbl, 0, sizeof(cbTbl));
36660 + *(void **)&cbTbl.probe = konicawc_probe;
36661 + *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
36662 + *(void **)&cbTbl.processData = konicawc_process_isoc;
36663 + *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
36664 + *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
36665 + *(void **)&cbTbl.startDataPump = konicawc_start_data;
36666 + *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
36667 + *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
36668 + *(void **)&cbTbl.userFree = konicawc_free_uvd;
36669 return usbvideo_register(
36670 &cams,
36671 MAX_CAMERAS,
36672 diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
36673 index 803d3e4..c4d1b96 100644
36674 --- a/drivers/media/video/usbvideo/quickcam_messenger.c
36675 +++ b/drivers/media/video/usbvideo/quickcam_messenger.c
36676 @@ -89,7 +89,7 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
36677 int error;
36678
36679 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36680 - strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36681 + strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36682
36683 cam->input = input_dev = input_allocate_device();
36684 if (!input_dev) {
36685 diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
36686 index fbd1b63..292f9f0 100644
36687 --- a/drivers/media/video/usbvideo/ultracam.c
36688 +++ b/drivers/media/video/usbvideo/ultracam.c
36689 @@ -655,14 +655,14 @@ static int __init ultracam_init(void)
36690 {
36691 struct usbvideo_cb cbTbl;
36692 memset(&cbTbl, 0, sizeof(cbTbl));
36693 - cbTbl.probe = ultracam_probe;
36694 - cbTbl.setupOnOpen = ultracam_setup_on_open;
36695 - cbTbl.videoStart = ultracam_video_start;
36696 - cbTbl.videoStop = ultracam_video_stop;
36697 - cbTbl.processData = ultracam_ProcessIsocData;
36698 - cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36699 - cbTbl.adjustPicture = ultracam_adjust_picture;
36700 - cbTbl.getFPS = ultracam_calculate_fps;
36701 + *(void **)&cbTbl.probe = ultracam_probe;
36702 + *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
36703 + *(void **)&cbTbl.videoStart = ultracam_video_start;
36704 + *(void **)&cbTbl.videoStop = ultracam_video_stop;
36705 + *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
36706 + *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36707 + *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
36708 + *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
36709 return usbvideo_register(
36710 &cams,
36711 MAX_CAMERAS,
36712 diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
36713 index dea8b32..34f6878 100644
36714 --- a/drivers/media/video/usbvideo/usbvideo.c
36715 +++ b/drivers/media/video/usbvideo/usbvideo.c
36716 @@ -697,15 +697,15 @@ int usbvideo_register(
36717 __func__, cams, base_size, num_cams);
36718
36719 /* Copy callbacks, apply defaults for those that are not set */
36720 - memmove(&cams->cb, cbTbl, sizeof(cams->cb));
36721 + memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
36722 if (cams->cb.getFrame == NULL)
36723 - cams->cb.getFrame = usbvideo_GetFrame;
36724 + *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
36725 if (cams->cb.disconnect == NULL)
36726 - cams->cb.disconnect = usbvideo_Disconnect;
36727 + *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
36728 if (cams->cb.startDataPump == NULL)
36729 - cams->cb.startDataPump = usbvideo_StartDataPump;
36730 + *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
36731 if (cams->cb.stopDataPump == NULL)
36732 - cams->cb.stopDataPump = usbvideo_StopDataPump;
36733 + *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
36734
36735 cams->num_cameras = num_cams;
36736 cams->cam = (struct uvd *) &cams[1];
36737 diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
36738 index c66985b..7fa143a 100644
36739 --- a/drivers/media/video/usbvideo/usbvideo.h
36740 +++ b/drivers/media/video/usbvideo/usbvideo.h
36741 @@ -268,7 +268,7 @@ struct usbvideo_cb {
36742 int (*startDataPump)(struct uvd *uvd);
36743 void (*stopDataPump)(struct uvd *uvd);
36744 int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
36745 -};
36746 +} __no_const;
36747
36748 struct usbvideo {
36749 int num_cameras; /* As allocated */
36750 diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
36751 index e0f91e4..37554ea 100644
36752 --- a/drivers/media/video/usbvision/usbvision-core.c
36753 +++ b/drivers/media/video/usbvision/usbvision-core.c
36754 @@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
36755 unsigned char rv, gv, bv;
36756 static unsigned char *Y, *U, *V;
36757
36758 + pax_track_stack();
36759 +
36760 frame = usbvision->curFrame;
36761 imageSize = frame->frmwidth * frame->frmheight;
36762 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
36763 diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
36764 index 0d06e7c..3d17d24 100644
36765 --- a/drivers/media/video/v4l2-device.c
36766 +++ b/drivers/media/video/v4l2-device.c
36767 @@ -50,9 +50,9 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
36768 EXPORT_SYMBOL_GPL(v4l2_device_register);
36769
36770 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
36771 - atomic_t *instance)
36772 + atomic_unchecked_t *instance)
36773 {
36774 - int num = atomic_inc_return(instance) - 1;
36775 + int num = atomic_inc_return_unchecked(instance) - 1;
36776 int len = strlen(basename);
36777
36778 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
36779 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
36780 index 032ebae..6a3532c 100644
36781 --- a/drivers/media/video/videobuf-dma-sg.c
36782 +++ b/drivers/media/video/videobuf-dma-sg.c
36783 @@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
36784 {
36785 struct videobuf_queue q;
36786
36787 + pax_track_stack();
36788 +
36789 /* Required to make generic handler to call __videobuf_alloc */
36790 q.int_ops = &sg_ops;
36791
36792 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36793 index b6992b7..9fa7547 100644
36794 --- a/drivers/message/fusion/mptbase.c
36795 +++ b/drivers/message/fusion/mptbase.c
36796 @@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
36797 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36798 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36799
36800 +#ifdef CONFIG_GRKERNSEC_HIDESYM
36801 + len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36802 + NULL, NULL);
36803 +#else
36804 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36805 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36806 +#endif
36807 +
36808 /*
36809 * Rounding UP to nearest 4-kB boundary here...
36810 */
36811 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36812 index 83873e3..e360e9a 100644
36813 --- a/drivers/message/fusion/mptsas.c
36814 +++ b/drivers/message/fusion/mptsas.c
36815 @@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36816 return 0;
36817 }
36818
36819 +static inline void
36820 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36821 +{
36822 + if (phy_info->port_details) {
36823 + phy_info->port_details->rphy = rphy;
36824 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36825 + ioc->name, rphy));
36826 + }
36827 +
36828 + if (rphy) {
36829 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36830 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36831 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36832 + ioc->name, rphy, rphy->dev.release));
36833 + }
36834 +}
36835 +
36836 /* no mutex */
36837 static void
36838 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36839 @@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36840 return NULL;
36841 }
36842
36843 -static inline void
36844 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36845 -{
36846 - if (phy_info->port_details) {
36847 - phy_info->port_details->rphy = rphy;
36848 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36849 - ioc->name, rphy));
36850 - }
36851 -
36852 - if (rphy) {
36853 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36854 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36855 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36856 - ioc->name, rphy, rphy->dev.release));
36857 - }
36858 -}
36859 -
36860 static inline struct sas_port *
36861 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36862 {
36863 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36864 index bd096ca..332cf76 100644
36865 --- a/drivers/message/fusion/mptscsih.c
36866 +++ b/drivers/message/fusion/mptscsih.c
36867 @@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36868
36869 h = shost_priv(SChost);
36870
36871 - if (h) {
36872 - if (h->info_kbuf == NULL)
36873 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36874 - return h->info_kbuf;
36875 - h->info_kbuf[0] = '\0';
36876 + if (!h)
36877 + return NULL;
36878
36879 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36880 - h->info_kbuf[size-1] = '\0';
36881 - }
36882 + if (h->info_kbuf == NULL)
36883 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36884 + return h->info_kbuf;
36885 + h->info_kbuf[0] = '\0';
36886 +
36887 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36888 + h->info_kbuf[size-1] = '\0';
36889
36890 return h->info_kbuf;
36891 }
36892 diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
36893 index efba702..59b2c0f 100644
36894 --- a/drivers/message/i2o/i2o_config.c
36895 +++ b/drivers/message/i2o/i2o_config.c
36896 @@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned long arg)
36897 struct i2o_message *msg;
36898 unsigned int iop;
36899
36900 + pax_track_stack();
36901 +
36902 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
36903 return -EFAULT;
36904
36905 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36906 index 7045c45..c07b170 100644
36907 --- a/drivers/message/i2o/i2o_proc.c
36908 +++ b/drivers/message/i2o/i2o_proc.c
36909 @@ -259,13 +259,6 @@ static char *scsi_devices[] = {
36910 "Array Controller Device"
36911 };
36912
36913 -static char *chtostr(u8 * chars, int n)
36914 -{
36915 - char tmp[256];
36916 - tmp[0] = 0;
36917 - return strncat(tmp, (char *)chars, n);
36918 -}
36919 -
36920 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36921 char *group)
36922 {
36923 @@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36924
36925 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36926 seq_printf(seq, "%-#8x", ddm_table.module_id);
36927 - seq_printf(seq, "%-29s",
36928 - chtostr(ddm_table.module_name_version, 28));
36929 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36930 seq_printf(seq, "%9d ", ddm_table.data_size);
36931 seq_printf(seq, "%8d", ddm_table.code_size);
36932
36933 @@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36934
36935 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36936 seq_printf(seq, "%-#8x", dst->module_id);
36937 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
36938 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
36939 + seq_printf(seq, "%-.28s", dst->module_name_version);
36940 + seq_printf(seq, "%-.8s", dst->date);
36941 seq_printf(seq, "%8d ", dst->module_size);
36942 seq_printf(seq, "%8d ", dst->mpb_size);
36943 seq_printf(seq, "0x%04x", dst->module_flags);
36944 @@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36945 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36946 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36947 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36948 - seq_printf(seq, "Vendor info : %s\n",
36949 - chtostr((u8 *) (work32 + 2), 16));
36950 - seq_printf(seq, "Product info : %s\n",
36951 - chtostr((u8 *) (work32 + 6), 16));
36952 - seq_printf(seq, "Description : %s\n",
36953 - chtostr((u8 *) (work32 + 10), 16));
36954 - seq_printf(seq, "Product rev. : %s\n",
36955 - chtostr((u8 *) (work32 + 14), 8));
36956 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36957 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36958 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36959 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36960
36961 seq_printf(seq, "Serial number : ");
36962 print_serial_number(seq, (u8 *) (work32 + 16),
36963 @@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36964 }
36965
36966 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36967 - seq_printf(seq, "Module name : %s\n",
36968 - chtostr(result.module_name, 24));
36969 - seq_printf(seq, "Module revision : %s\n",
36970 - chtostr(result.module_rev, 8));
36971 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36972 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36973
36974 seq_printf(seq, "Serial number : ");
36975 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36976 @@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36977 return 0;
36978 }
36979
36980 - seq_printf(seq, "Device name : %s\n",
36981 - chtostr(result.device_name, 64));
36982 - seq_printf(seq, "Service name : %s\n",
36983 - chtostr(result.service_name, 64));
36984 - seq_printf(seq, "Physical name : %s\n",
36985 - chtostr(result.physical_location, 64));
36986 - seq_printf(seq, "Instance number : %s\n",
36987 - chtostr(result.instance_number, 4));
36988 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36989 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36990 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36991 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36992
36993 return 0;
36994 }
36995 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36996 index 27cf4af..b1205b8 100644
36997 --- a/drivers/message/i2o/iop.c
36998 +++ b/drivers/message/i2o/iop.c
36999 @@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
37000
37001 spin_lock_irqsave(&c->context_list_lock, flags);
37002
37003 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
37004 - atomic_inc(&c->context_list_counter);
37005 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
37006 + atomic_inc_unchecked(&c->context_list_counter);
37007
37008 - entry->context = atomic_read(&c->context_list_counter);
37009 + entry->context = atomic_read_unchecked(&c->context_list_counter);
37010
37011 list_add(&entry->list, &c->context_list);
37012
37013 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
37014
37015 #if BITS_PER_LONG == 64
37016 spin_lock_init(&c->context_list_lock);
37017 - atomic_set(&c->context_list_counter, 0);
37018 + atomic_set_unchecked(&c->context_list_counter, 0);
37019 INIT_LIST_HEAD(&c->context_list);
37020 #endif
37021
37022 diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
37023 index 78e3e85..66c9a0d 100644
37024 --- a/drivers/mfd/ab3100-core.c
37025 +++ b/drivers/mfd/ab3100-core.c
37026 @@ -777,7 +777,7 @@ struct ab_family_id {
37027 char *name;
37028 };
37029
37030 -static const struct ab_family_id ids[] __initdata = {
37031 +static const struct ab_family_id ids[] __initconst = {
37032 /* AB3100 */
37033 {
37034 .id = 0xc0,
37035 diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
37036 index 8d8c932..8104515 100644
37037 --- a/drivers/mfd/wm8350-i2c.c
37038 +++ b/drivers/mfd/wm8350-i2c.c
37039 @@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
37040 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
37041 int ret;
37042
37043 + pax_track_stack();
37044 +
37045 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
37046 return -EINVAL;
37047
37048 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
37049 index e4ff50b..4cc3f04 100644
37050 --- a/drivers/misc/kgdbts.c
37051 +++ b/drivers/misc/kgdbts.c
37052 @@ -118,7 +118,7 @@
37053 } while (0)
37054 #define MAX_CONFIG_LEN 40
37055
37056 -static struct kgdb_io kgdbts_io_ops;
37057 +static const struct kgdb_io kgdbts_io_ops;
37058 static char get_buf[BUFMAX];
37059 static int get_buf_cnt;
37060 static char put_buf[BUFMAX];
37061 @@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void)
37062 module_put(THIS_MODULE);
37063 }
37064
37065 -static struct kgdb_io kgdbts_io_ops = {
37066 +static const struct kgdb_io kgdbts_io_ops = {
37067 .name = "kgdbts",
37068 .read_char = kgdbts_get_char,
37069 .write_char = kgdbts_put_char,
37070 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
37071 index 37e7cfc..67cfb76 100644
37072 --- a/drivers/misc/sgi-gru/gruhandles.c
37073 +++ b/drivers/misc/sgi-gru/gruhandles.c
37074 @@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37075
37076 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
37077 {
37078 - atomic_long_inc(&mcs_op_statistics[op].count);
37079 - atomic_long_add(clks, &mcs_op_statistics[op].total);
37080 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
37081 + atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
37082 if (mcs_op_statistics[op].max < clks)
37083 mcs_op_statistics[op].max = clks;
37084 }
37085 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
37086 index 3f2375c..467c6e6 100644
37087 --- a/drivers/misc/sgi-gru/gruprocfs.c
37088 +++ b/drivers/misc/sgi-gru/gruprocfs.c
37089 @@ -32,9 +32,9 @@
37090
37091 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
37092
37093 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
37094 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
37095 {
37096 - unsigned long val = atomic_long_read(v);
37097 + unsigned long val = atomic_long_read_unchecked(v);
37098
37099 if (val)
37100 seq_printf(s, "%16lu %s\n", val, id);
37101 @@ -136,8 +136,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
37102 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
37103
37104 for (op = 0; op < mcsop_last; op++) {
37105 - count = atomic_long_read(&mcs_op_statistics[op].count);
37106 - total = atomic_long_read(&mcs_op_statistics[op].total);
37107 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
37108 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
37109 max = mcs_op_statistics[op].max;
37110 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
37111 count ? total / count : 0, max);
37112 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
37113 index 46990bc..4a251b5 100644
37114 --- a/drivers/misc/sgi-gru/grutables.h
37115 +++ b/drivers/misc/sgi-gru/grutables.h
37116 @@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
37117 * GRU statistics.
37118 */
37119 struct gru_stats_s {
37120 - atomic_long_t vdata_alloc;
37121 - atomic_long_t vdata_free;
37122 - atomic_long_t gts_alloc;
37123 - atomic_long_t gts_free;
37124 - atomic_long_t vdata_double_alloc;
37125 - atomic_long_t gts_double_allocate;
37126 - atomic_long_t assign_context;
37127 - atomic_long_t assign_context_failed;
37128 - atomic_long_t free_context;
37129 - atomic_long_t load_user_context;
37130 - atomic_long_t load_kernel_context;
37131 - atomic_long_t lock_kernel_context;
37132 - atomic_long_t unlock_kernel_context;
37133 - atomic_long_t steal_user_context;
37134 - atomic_long_t steal_kernel_context;
37135 - atomic_long_t steal_context_failed;
37136 - atomic_long_t nopfn;
37137 - atomic_long_t break_cow;
37138 - atomic_long_t asid_new;
37139 - atomic_long_t asid_next;
37140 - atomic_long_t asid_wrap;
37141 - atomic_long_t asid_reuse;
37142 - atomic_long_t intr;
37143 - atomic_long_t intr_mm_lock_failed;
37144 - atomic_long_t call_os;
37145 - atomic_long_t call_os_offnode_reference;
37146 - atomic_long_t call_os_check_for_bug;
37147 - atomic_long_t call_os_wait_queue;
37148 - atomic_long_t user_flush_tlb;
37149 - atomic_long_t user_unload_context;
37150 - atomic_long_t user_exception;
37151 - atomic_long_t set_context_option;
37152 - atomic_long_t migrate_check;
37153 - atomic_long_t migrated_retarget;
37154 - atomic_long_t migrated_unload;
37155 - atomic_long_t migrated_unload_delay;
37156 - atomic_long_t migrated_nopfn_retarget;
37157 - atomic_long_t migrated_nopfn_unload;
37158 - atomic_long_t tlb_dropin;
37159 - atomic_long_t tlb_dropin_fail_no_asid;
37160 - atomic_long_t tlb_dropin_fail_upm;
37161 - atomic_long_t tlb_dropin_fail_invalid;
37162 - atomic_long_t tlb_dropin_fail_range_active;
37163 - atomic_long_t tlb_dropin_fail_idle;
37164 - atomic_long_t tlb_dropin_fail_fmm;
37165 - atomic_long_t tlb_dropin_fail_no_exception;
37166 - atomic_long_t tlb_dropin_fail_no_exception_war;
37167 - atomic_long_t tfh_stale_on_fault;
37168 - atomic_long_t mmu_invalidate_range;
37169 - atomic_long_t mmu_invalidate_page;
37170 - atomic_long_t mmu_clear_flush_young;
37171 - atomic_long_t flush_tlb;
37172 - atomic_long_t flush_tlb_gru;
37173 - atomic_long_t flush_tlb_gru_tgh;
37174 - atomic_long_t flush_tlb_gru_zero_asid;
37175 + atomic_long_unchecked_t vdata_alloc;
37176 + atomic_long_unchecked_t vdata_free;
37177 + atomic_long_unchecked_t gts_alloc;
37178 + atomic_long_unchecked_t gts_free;
37179 + atomic_long_unchecked_t vdata_double_alloc;
37180 + atomic_long_unchecked_t gts_double_allocate;
37181 + atomic_long_unchecked_t assign_context;
37182 + atomic_long_unchecked_t assign_context_failed;
37183 + atomic_long_unchecked_t free_context;
37184 + atomic_long_unchecked_t load_user_context;
37185 + atomic_long_unchecked_t load_kernel_context;
37186 + atomic_long_unchecked_t lock_kernel_context;
37187 + atomic_long_unchecked_t unlock_kernel_context;
37188 + atomic_long_unchecked_t steal_user_context;
37189 + atomic_long_unchecked_t steal_kernel_context;
37190 + atomic_long_unchecked_t steal_context_failed;
37191 + atomic_long_unchecked_t nopfn;
37192 + atomic_long_unchecked_t break_cow;
37193 + atomic_long_unchecked_t asid_new;
37194 + atomic_long_unchecked_t asid_next;
37195 + atomic_long_unchecked_t asid_wrap;
37196 + atomic_long_unchecked_t asid_reuse;
37197 + atomic_long_unchecked_t intr;
37198 + atomic_long_unchecked_t intr_mm_lock_failed;
37199 + atomic_long_unchecked_t call_os;
37200 + atomic_long_unchecked_t call_os_offnode_reference;
37201 + atomic_long_unchecked_t call_os_check_for_bug;
37202 + atomic_long_unchecked_t call_os_wait_queue;
37203 + atomic_long_unchecked_t user_flush_tlb;
37204 + atomic_long_unchecked_t user_unload_context;
37205 + atomic_long_unchecked_t user_exception;
37206 + atomic_long_unchecked_t set_context_option;
37207 + atomic_long_unchecked_t migrate_check;
37208 + atomic_long_unchecked_t migrated_retarget;
37209 + atomic_long_unchecked_t migrated_unload;
37210 + atomic_long_unchecked_t migrated_unload_delay;
37211 + atomic_long_unchecked_t migrated_nopfn_retarget;
37212 + atomic_long_unchecked_t migrated_nopfn_unload;
37213 + atomic_long_unchecked_t tlb_dropin;
37214 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37215 + atomic_long_unchecked_t tlb_dropin_fail_upm;
37216 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
37217 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
37218 + atomic_long_unchecked_t tlb_dropin_fail_idle;
37219 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
37220 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37221 + atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
37222 + atomic_long_unchecked_t tfh_stale_on_fault;
37223 + atomic_long_unchecked_t mmu_invalidate_range;
37224 + atomic_long_unchecked_t mmu_invalidate_page;
37225 + atomic_long_unchecked_t mmu_clear_flush_young;
37226 + atomic_long_unchecked_t flush_tlb;
37227 + atomic_long_unchecked_t flush_tlb_gru;
37228 + atomic_long_unchecked_t flush_tlb_gru_tgh;
37229 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37230
37231 - atomic_long_t copy_gpa;
37232 + atomic_long_unchecked_t copy_gpa;
37233
37234 - atomic_long_t mesq_receive;
37235 - atomic_long_t mesq_receive_none;
37236 - atomic_long_t mesq_send;
37237 - atomic_long_t mesq_send_failed;
37238 - atomic_long_t mesq_noop;
37239 - atomic_long_t mesq_send_unexpected_error;
37240 - atomic_long_t mesq_send_lb_overflow;
37241 - atomic_long_t mesq_send_qlimit_reached;
37242 - atomic_long_t mesq_send_amo_nacked;
37243 - atomic_long_t mesq_send_put_nacked;
37244 - atomic_long_t mesq_qf_not_full;
37245 - atomic_long_t mesq_qf_locked;
37246 - atomic_long_t mesq_qf_noop_not_full;
37247 - atomic_long_t mesq_qf_switch_head_failed;
37248 - atomic_long_t mesq_qf_unexpected_error;
37249 - atomic_long_t mesq_noop_unexpected_error;
37250 - atomic_long_t mesq_noop_lb_overflow;
37251 - atomic_long_t mesq_noop_qlimit_reached;
37252 - atomic_long_t mesq_noop_amo_nacked;
37253 - atomic_long_t mesq_noop_put_nacked;
37254 + atomic_long_unchecked_t mesq_receive;
37255 + atomic_long_unchecked_t mesq_receive_none;
37256 + atomic_long_unchecked_t mesq_send;
37257 + atomic_long_unchecked_t mesq_send_failed;
37258 + atomic_long_unchecked_t mesq_noop;
37259 + atomic_long_unchecked_t mesq_send_unexpected_error;
37260 + atomic_long_unchecked_t mesq_send_lb_overflow;
37261 + atomic_long_unchecked_t mesq_send_qlimit_reached;
37262 + atomic_long_unchecked_t mesq_send_amo_nacked;
37263 + atomic_long_unchecked_t mesq_send_put_nacked;
37264 + atomic_long_unchecked_t mesq_qf_not_full;
37265 + atomic_long_unchecked_t mesq_qf_locked;
37266 + atomic_long_unchecked_t mesq_qf_noop_not_full;
37267 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
37268 + atomic_long_unchecked_t mesq_qf_unexpected_error;
37269 + atomic_long_unchecked_t mesq_noop_unexpected_error;
37270 + atomic_long_unchecked_t mesq_noop_lb_overflow;
37271 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
37272 + atomic_long_unchecked_t mesq_noop_amo_nacked;
37273 + atomic_long_unchecked_t mesq_noop_put_nacked;
37274
37275 };
37276
37277 @@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37278 cchop_deallocate, tghop_invalidate, mcsop_last};
37279
37280 struct mcs_op_statistic {
37281 - atomic_long_t count;
37282 - atomic_long_t total;
37283 + atomic_long_unchecked_t count;
37284 + atomic_long_unchecked_t total;
37285 unsigned long max;
37286 };
37287
37288 @@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37289
37290 #define STAT(id) do { \
37291 if (gru_options & OPT_STATS) \
37292 - atomic_long_inc(&gru_stats.id); \
37293 + atomic_long_inc_unchecked(&gru_stats.id); \
37294 } while (0)
37295
37296 #ifdef CONFIG_SGI_GRU_DEBUG
37297 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37298 index 2275126..12a9dbfb 100644
37299 --- a/drivers/misc/sgi-xp/xp.h
37300 +++ b/drivers/misc/sgi-xp/xp.h
37301 @@ -289,7 +289,7 @@ struct xpc_interface {
37302 xpc_notify_func, void *);
37303 void (*received) (short, int, void *);
37304 enum xp_retval (*partid_to_nasids) (short, void *);
37305 -};
37306 +} __no_const;
37307
37308 extern struct xpc_interface xpc_interface;
37309
37310 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37311 index b94d5f7..7f494c5 100644
37312 --- a/drivers/misc/sgi-xp/xpc.h
37313 +++ b/drivers/misc/sgi-xp/xpc.h
37314 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
37315 void (*received_payload) (struct xpc_channel *, void *);
37316 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37317 };
37318 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37319
37320 /* struct xpc_partition act_state values (for XPC HB) */
37321
37322 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37323 /* found in xpc_main.c */
37324 extern struct device *xpc_part;
37325 extern struct device *xpc_chan;
37326 -extern struct xpc_arch_operations xpc_arch_ops;
37327 +extern xpc_arch_operations_no_const xpc_arch_ops;
37328 extern int xpc_disengage_timelimit;
37329 extern int xpc_disengage_timedout;
37330 extern int xpc_activate_IRQ_rcvd;
37331 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37332 index fd3688a..7e211a4 100644
37333 --- a/drivers/misc/sgi-xp/xpc_main.c
37334 +++ b/drivers/misc/sgi-xp/xpc_main.c
37335 @@ -169,7 +169,7 @@ static struct notifier_block xpc_die_notifier = {
37336 .notifier_call = xpc_system_die,
37337 };
37338
37339 -struct xpc_arch_operations xpc_arch_ops;
37340 +xpc_arch_operations_no_const xpc_arch_ops;
37341
37342 /*
37343 * Timer function to enforce the timelimit on the partition disengage.
37344 diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
37345 index 8b70e03..700bda6 100644
37346 --- a/drivers/misc/sgi-xp/xpc_sn2.c
37347 +++ b/drivers/misc/sgi-xp/xpc_sn2.c
37348 @@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_channel *ch, void *payload)
37349 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
37350 }
37351
37352 -static struct xpc_arch_operations xpc_arch_ops_sn2 = {
37353 +static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
37354 .setup_partitions = xpc_setup_partitions_sn2,
37355 .teardown_partitions = xpc_teardown_partitions_sn2,
37356 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
37357 @@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
37358 int ret;
37359 size_t buf_size;
37360
37361 - xpc_arch_ops = xpc_arch_ops_sn2;
37362 + pax_open_kernel();
37363 + memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
37364 + pax_close_kernel();
37365
37366 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
37367 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
37368 diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
37369 index 8e08d71..7cb8c9b 100644
37370 --- a/drivers/misc/sgi-xp/xpc_uv.c
37371 +++ b/drivers/misc/sgi-xp/xpc_uv.c
37372 @@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
37373 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
37374 }
37375
37376 -static struct xpc_arch_operations xpc_arch_ops_uv = {
37377 +static const struct xpc_arch_operations xpc_arch_ops_uv = {
37378 .setup_partitions = xpc_setup_partitions_uv,
37379 .teardown_partitions = xpc_teardown_partitions_uv,
37380 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
37381 @@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_arch_ops_uv = {
37382 int
37383 xpc_init_uv(void)
37384 {
37385 - xpc_arch_ops = xpc_arch_ops_uv;
37386 + pax_open_kernel();
37387 + memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
37388 + pax_close_kernel();
37389
37390 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
37391 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
37392 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
37393 index 6fd20b42..650efe3 100644
37394 --- a/drivers/mmc/host/sdhci-pci.c
37395 +++ b/drivers/mmc/host/sdhci-pci.c
37396 @@ -297,7 +297,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
37397 .probe = via_probe,
37398 };
37399
37400 -static const struct pci_device_id pci_ids[] __devinitdata = {
37401 +static const struct pci_device_id pci_ids[] __devinitconst = {
37402 {
37403 .vendor = PCI_VENDOR_ID_RICOH,
37404 .device = PCI_DEVICE_ID_RICOH_R5C822,
37405 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
37406 index e7563a9..5f90ce5 100644
37407 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
37408 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
37409 @@ -743,6 +743,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
37410 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
37411 unsigned long timeo = jiffies + HZ;
37412
37413 + pax_track_stack();
37414 +
37415 /* Prevent setting state FL_SYNCING for chip in suspended state. */
37416 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
37417 goto sleep;
37418 @@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
37419 unsigned long initial_adr;
37420 int initial_len = len;
37421
37422 + pax_track_stack();
37423 +
37424 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
37425 adr += chip->start;
37426 initial_adr = adr;
37427 @@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
37428 int retries = 3;
37429 int ret;
37430
37431 + pax_track_stack();
37432 +
37433 adr += chip->start;
37434
37435 retry:
37436 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
37437 index 0667a67..3ab97ed 100644
37438 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
37439 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
37440 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
37441 unsigned long cmd_addr;
37442 struct cfi_private *cfi = map->fldrv_priv;
37443
37444 + pax_track_stack();
37445 +
37446 adr += chip->start;
37447
37448 /* Ensure cmd read/writes are aligned. */
37449 @@ -428,6 +430,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
37450 DECLARE_WAITQUEUE(wait, current);
37451 int wbufsize, z;
37452
37453 + pax_track_stack();
37454 +
37455 /* M58LW064A requires bus alignment for buffer wriets -- saw */
37456 if (adr & (map_bankwidth(map)-1))
37457 return -EINVAL;
37458 @@ -742,6 +746,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
37459 DECLARE_WAITQUEUE(wait, current);
37460 int ret = 0;
37461
37462 + pax_track_stack();
37463 +
37464 adr += chip->start;
37465
37466 /* Let's determine this according to the interleave only once */
37467 @@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
37468 unsigned long timeo = jiffies + HZ;
37469 DECLARE_WAITQUEUE(wait, current);
37470
37471 + pax_track_stack();
37472 +
37473 adr += chip->start;
37474
37475 /* Let's determine this according to the interleave only once */
37476 @@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
37477 unsigned long timeo = jiffies + HZ;
37478 DECLARE_WAITQUEUE(wait, current);
37479
37480 + pax_track_stack();
37481 +
37482 adr += chip->start;
37483
37484 /* Let's determine this according to the interleave only once */
37485 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37486 index 5bf5f46..c5de373 100644
37487 --- a/drivers/mtd/devices/doc2000.c
37488 +++ b/drivers/mtd/devices/doc2000.c
37489 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37490
37491 /* The ECC will not be calculated correctly if less than 512 is written */
37492 /* DBB-
37493 - if (len != 0x200 && eccbuf)
37494 + if (len != 0x200)
37495 printk(KERN_WARNING
37496 "ECC needs a full sector write (adr: %lx size %lx)\n",
37497 (long) to, (long) len);
37498 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
37499 index 0990f78..bb4e8a4 100644
37500 --- a/drivers/mtd/devices/doc2001.c
37501 +++ b/drivers/mtd/devices/doc2001.c
37502 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
37503 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
37504
37505 /* Don't allow read past end of device */
37506 - if (from >= this->totlen)
37507 + if (from >= this->totlen || !len)
37508 return -EINVAL;
37509
37510 /* Don't allow a single read to cross a 512-byte block boundary */
37511 diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
37512 index e56d6b4..f07e6cf 100644
37513 --- a/drivers/mtd/ftl.c
37514 +++ b/drivers/mtd/ftl.c
37515 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
37516 loff_t offset;
37517 uint16_t srcunitswap = cpu_to_le16(srcunit);
37518
37519 + pax_track_stack();
37520 +
37521 eun = &part->EUNInfo[srcunit];
37522 xfer = &part->XferInfo[xferunit];
37523 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
37524 diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
37525 index 8aca552..146446e 100755
37526 --- a/drivers/mtd/inftlcore.c
37527 +++ b/drivers/mtd/inftlcore.c
37528 @@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
37529 struct inftl_oob oob;
37530 size_t retlen;
37531
37532 + pax_track_stack();
37533 +
37534 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
37535 "pending=%d)\n", inftl, thisVUC, pendingblock);
37536
37537 diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
37538 index 32e82ae..ed50953 100644
37539 --- a/drivers/mtd/inftlmount.c
37540 +++ b/drivers/mtd/inftlmount.c
37541 @@ -54,6 +54,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
37542 struct INFTLPartition *ip;
37543 size_t retlen;
37544
37545 + pax_track_stack();
37546 +
37547 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
37548
37549 /*
37550 diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
37551 index 79bf40f..fe5f8fd 100644
37552 --- a/drivers/mtd/lpddr/qinfo_probe.c
37553 +++ b/drivers/mtd/lpddr/qinfo_probe.c
37554 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
37555 {
37556 map_word pfow_val[4];
37557
37558 + pax_track_stack();
37559 +
37560 /* Check identification string */
37561 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
37562 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
37563 diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
37564 index 726a1b8..f46b460 100644
37565 --- a/drivers/mtd/mtdchar.c
37566 +++ b/drivers/mtd/mtdchar.c
37567 @@ -461,6 +461,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
37568 u_long size;
37569 struct mtd_info_user info;
37570
37571 + pax_track_stack();
37572 +
37573 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
37574
37575 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
37576 diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
37577 index 1002e18..26d82d5 100644
37578 --- a/drivers/mtd/nftlcore.c
37579 +++ b/drivers/mtd/nftlcore.c
37580 @@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
37581 int inplace = 1;
37582 size_t retlen;
37583
37584 + pax_track_stack();
37585 +
37586 memset(BlockMap, 0xff, sizeof(BlockMap));
37587 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
37588
37589 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37590 index 8b22b18..6fada85 100644
37591 --- a/drivers/mtd/nftlmount.c
37592 +++ b/drivers/mtd/nftlmount.c
37593 @@ -23,6 +23,7 @@
37594 #include <asm/errno.h>
37595 #include <linux/delay.h>
37596 #include <linux/slab.h>
37597 +#include <linux/sched.h>
37598 #include <linux/mtd/mtd.h>
37599 #include <linux/mtd/nand.h>
37600 #include <linux/mtd/nftl.h>
37601 @@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
37602 struct mtd_info *mtd = nftl->mbd.mtd;
37603 unsigned int i;
37604
37605 + pax_track_stack();
37606 +
37607 /* Assume logical EraseSize == physical erasesize for starting the scan.
37608 We'll sort it out later if we find a MediaHeader which says otherwise */
37609 /* Actually, we won't. The new DiskOnChip driver has already scanned
37610 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
37611 index 14cec04..d775b87 100644
37612 --- a/drivers/mtd/ubi/build.c
37613 +++ b/drivers/mtd/ubi/build.c
37614 @@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
37615 static int __init bytes_str_to_int(const char *str)
37616 {
37617 char *endp;
37618 - unsigned long result;
37619 + unsigned long result, scale = 1;
37620
37621 result = simple_strtoul(str, &endp, 0);
37622 if (str == endp || result >= INT_MAX) {
37623 @@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const char *str)
37624
37625 switch (*endp) {
37626 case 'G':
37627 - result *= 1024;
37628 + scale *= 1024;
37629 case 'M':
37630 - result *= 1024;
37631 + scale *= 1024;
37632 case 'K':
37633 - result *= 1024;
37634 + scale *= 1024;
37635 if (endp[1] == 'i' && endp[2] == 'B')
37636 endp += 2;
37637 case '\0':
37638 @@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const char *str)
37639 return -EINVAL;
37640 }
37641
37642 - return result;
37643 + if ((intoverflow_t)result*scale >= INT_MAX) {
37644 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
37645 + str);
37646 + return -EINVAL;
37647 + }
37648 +
37649 + return result*scale;
37650 }
37651
37652 /**
37653 diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
37654 index ab68886..ca405e8 100644
37655 --- a/drivers/net/atlx/atl2.c
37656 +++ b/drivers/net/atlx/atl2.c
37657 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
37658 */
37659
37660 #define ATL2_PARAM(X, desc) \
37661 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37662 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37663 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
37664 MODULE_PARM_DESC(X, desc);
37665 #else
37666 diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
37667 index 4874b2b..67f8526 100644
37668 --- a/drivers/net/bnx2.c
37669 +++ b/drivers/net/bnx2.c
37670 @@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
37671 int rc = 0;
37672 u32 magic, csum;
37673
37674 + pax_track_stack();
37675 +
37676 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
37677 goto test_nvram_done;
37678
37679 diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
37680 index fd3eb07..8a6978d 100644
37681 --- a/drivers/net/cxgb3/l2t.h
37682 +++ b/drivers/net/cxgb3/l2t.h
37683 @@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37684 */
37685 struct l2t_skb_cb {
37686 arp_failure_handler_func arp_failure_handler;
37687 -};
37688 +} __no_const;
37689
37690 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37691
37692 diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
37693 index 032cfe0..411af379 100644
37694 --- a/drivers/net/cxgb3/t3_hw.c
37695 +++ b/drivers/net/cxgb3/t3_hw.c
37696 @@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
37697 int i, addr, ret;
37698 struct t3_vpd vpd;
37699
37700 + pax_track_stack();
37701 +
37702 /*
37703 * Card information is normally at VPD_BASE but some early cards had
37704 * it at 0.
37705 diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
37706 index d1e0563..b9e129c 100644
37707 --- a/drivers/net/e1000e/82571.c
37708 +++ b/drivers/net/e1000e/82571.c
37709 @@ -212,7 +212,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
37710 {
37711 struct e1000_hw *hw = &adapter->hw;
37712 struct e1000_mac_info *mac = &hw->mac;
37713 - struct e1000_mac_operations *func = &mac->ops;
37714 + e1000_mac_operations_no_const *func = &mac->ops;
37715 u32 swsm = 0;
37716 u32 swsm2 = 0;
37717 bool force_clear_smbi = false;
37718 @@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
37719 temp = er32(ICRXDMTC);
37720 }
37721
37722 -static struct e1000_mac_operations e82571_mac_ops = {
37723 +static const struct e1000_mac_operations e82571_mac_ops = {
37724 /* .check_mng_mode: mac type dependent */
37725 /* .check_for_link: media type dependent */
37726 .id_led_init = e1000e_id_led_init,
37727 @@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e82571_mac_ops = {
37728 .setup_led = e1000e_setup_led_generic,
37729 };
37730
37731 -static struct e1000_phy_operations e82_phy_ops_igp = {
37732 +static const struct e1000_phy_operations e82_phy_ops_igp = {
37733 .acquire_phy = e1000_get_hw_semaphore_82571,
37734 .check_reset_block = e1000e_check_reset_block_generic,
37735 .commit_phy = NULL,
37736 @@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_phy_ops_igp = {
37737 .cfg_on_link_up = NULL,
37738 };
37739
37740 -static struct e1000_phy_operations e82_phy_ops_m88 = {
37741 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
37742 .acquire_phy = e1000_get_hw_semaphore_82571,
37743 .check_reset_block = e1000e_check_reset_block_generic,
37744 .commit_phy = e1000e_phy_sw_reset,
37745 @@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_phy_ops_m88 = {
37746 .cfg_on_link_up = NULL,
37747 };
37748
37749 -static struct e1000_phy_operations e82_phy_ops_bm = {
37750 +static const struct e1000_phy_operations e82_phy_ops_bm = {
37751 .acquire_phy = e1000_get_hw_semaphore_82571,
37752 .check_reset_block = e1000e_check_reset_block_generic,
37753 .commit_phy = e1000e_phy_sw_reset,
37754 @@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_phy_ops_bm = {
37755 .cfg_on_link_up = NULL,
37756 };
37757
37758 -static struct e1000_nvm_operations e82571_nvm_ops = {
37759 +static const struct e1000_nvm_operations e82571_nvm_ops = {
37760 .acquire_nvm = e1000_acquire_nvm_82571,
37761 .read_nvm = e1000e_read_nvm_eerd,
37762 .release_nvm = e1000_release_nvm_82571,
37763 diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
37764 index 47db9bd..fa58ccd 100644
37765 --- a/drivers/net/e1000e/e1000.h
37766 +++ b/drivers/net/e1000e/e1000.h
37767 @@ -375,9 +375,9 @@ struct e1000_info {
37768 u32 pba;
37769 u32 max_hw_frame_size;
37770 s32 (*get_variants)(struct e1000_adapter *);
37771 - struct e1000_mac_operations *mac_ops;
37772 - struct e1000_phy_operations *phy_ops;
37773 - struct e1000_nvm_operations *nvm_ops;
37774 + const struct e1000_mac_operations *mac_ops;
37775 + const struct e1000_phy_operations *phy_ops;
37776 + const struct e1000_nvm_operations *nvm_ops;
37777 };
37778
37779 /* hardware capability, feature, and workaround flags */
37780 diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
37781 index ae5d736..e9a93a1 100644
37782 --- a/drivers/net/e1000e/es2lan.c
37783 +++ b/drivers/net/e1000e/es2lan.c
37784 @@ -207,7 +207,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
37785 {
37786 struct e1000_hw *hw = &adapter->hw;
37787 struct e1000_mac_info *mac = &hw->mac;
37788 - struct e1000_mac_operations *func = &mac->ops;
37789 + e1000_mac_operations_no_const *func = &mac->ops;
37790
37791 /* Set media type */
37792 switch (adapter->pdev->device) {
37793 @@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
37794 temp = er32(ICRXDMTC);
37795 }
37796
37797 -static struct e1000_mac_operations es2_mac_ops = {
37798 +static const struct e1000_mac_operations es2_mac_ops = {
37799 .id_led_init = e1000e_id_led_init,
37800 .check_mng_mode = e1000e_check_mng_mode_generic,
37801 /* check_for_link dependent on media type */
37802 @@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_mac_ops = {
37803 .setup_led = e1000e_setup_led_generic,
37804 };
37805
37806 -static struct e1000_phy_operations es2_phy_ops = {
37807 +static const struct e1000_phy_operations es2_phy_ops = {
37808 .acquire_phy = e1000_acquire_phy_80003es2lan,
37809 .check_reset_block = e1000e_check_reset_block_generic,
37810 .commit_phy = e1000e_phy_sw_reset,
37811 @@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_phy_ops = {
37812 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
37813 };
37814
37815 -static struct e1000_nvm_operations es2_nvm_ops = {
37816 +static const struct e1000_nvm_operations es2_nvm_ops = {
37817 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
37818 .read_nvm = e1000e_read_nvm_eerd,
37819 .release_nvm = e1000_release_nvm_80003es2lan,
37820 diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
37821 index 11f3b7c..6381887 100644
37822 --- a/drivers/net/e1000e/hw.h
37823 +++ b/drivers/net/e1000e/hw.h
37824 @@ -753,6 +753,7 @@ struct e1000_mac_operations {
37825 s32 (*setup_physical_interface)(struct e1000_hw *);
37826 s32 (*setup_led)(struct e1000_hw *);
37827 };
37828 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37829
37830 /* Function pointers for the PHY. */
37831 struct e1000_phy_operations {
37832 @@ -774,6 +775,7 @@ struct e1000_phy_operations {
37833 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
37834 s32 (*cfg_on_link_up)(struct e1000_hw *);
37835 };
37836 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37837
37838 /* Function pointers for the NVM. */
37839 struct e1000_nvm_operations {
37840 @@ -785,9 +787,10 @@ struct e1000_nvm_operations {
37841 s32 (*validate_nvm)(struct e1000_hw *);
37842 s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
37843 };
37844 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
37845
37846 struct e1000_mac_info {
37847 - struct e1000_mac_operations ops;
37848 + e1000_mac_operations_no_const ops;
37849
37850 u8 addr[6];
37851 u8 perm_addr[6];
37852 @@ -823,7 +826,7 @@ struct e1000_mac_info {
37853 };
37854
37855 struct e1000_phy_info {
37856 - struct e1000_phy_operations ops;
37857 + e1000_phy_operations_no_const ops;
37858
37859 enum e1000_phy_type type;
37860
37861 @@ -857,7 +860,7 @@ struct e1000_phy_info {
37862 };
37863
37864 struct e1000_nvm_info {
37865 - struct e1000_nvm_operations ops;
37866 + e1000_nvm_operations_no_const ops;
37867
37868 enum e1000_nvm_type type;
37869 enum e1000_nvm_override override;
37870 diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
37871 index de39f9a..e28d3e0 100644
37872 --- a/drivers/net/e1000e/ich8lan.c
37873 +++ b/drivers/net/e1000e/ich8lan.c
37874 @@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
37875 }
37876 }
37877
37878 -static struct e1000_mac_operations ich8_mac_ops = {
37879 +static const struct e1000_mac_operations ich8_mac_ops = {
37880 .id_led_init = e1000e_id_led_init,
37881 .check_mng_mode = e1000_check_mng_mode_ich8lan,
37882 .check_for_link = e1000_check_for_copper_link_ich8lan,
37883 @@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_mac_ops = {
37884 /* id_led_init dependent on mac type */
37885 };
37886
37887 -static struct e1000_phy_operations ich8_phy_ops = {
37888 +static const struct e1000_phy_operations ich8_phy_ops = {
37889 .acquire_phy = e1000_acquire_swflag_ich8lan,
37890 .check_reset_block = e1000_check_reset_block_ich8lan,
37891 .commit_phy = NULL,
37892 @@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_phy_ops = {
37893 .write_phy_reg = e1000e_write_phy_reg_igp,
37894 };
37895
37896 -static struct e1000_nvm_operations ich8_nvm_ops = {
37897 +static const struct e1000_nvm_operations ich8_nvm_ops = {
37898 .acquire_nvm = e1000_acquire_nvm_ich8lan,
37899 .read_nvm = e1000_read_nvm_ich8lan,
37900 .release_nvm = e1000_release_nvm_ich8lan,
37901 diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
37902 index 18d5fbb..542d96d 100644
37903 --- a/drivers/net/fealnx.c
37904 +++ b/drivers/net/fealnx.c
37905 @@ -151,7 +151,7 @@ struct chip_info {
37906 int flags;
37907 };
37908
37909 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
37910 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
37911 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37912 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
37913 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37914 diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
37915 index 0e5b54b..b503f82 100644
37916 --- a/drivers/net/hamradio/6pack.c
37917 +++ b/drivers/net/hamradio/6pack.c
37918 @@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
37919 unsigned char buf[512];
37920 int count1;
37921
37922 + pax_track_stack();
37923 +
37924 if (!count)
37925 return;
37926
37927 diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
37928 index 5862282..7cce8cb 100644
37929 --- a/drivers/net/ibmveth.c
37930 +++ b/drivers/net/ibmveth.c
37931 @@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attrs[] = {
37932 NULL,
37933 };
37934
37935 -static struct sysfs_ops veth_pool_ops = {
37936 +static const struct sysfs_ops veth_pool_ops = {
37937 .show = veth_pool_show,
37938 .store = veth_pool_store,
37939 };
37940 diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
37941 index d617f2d..57b5309 100644
37942 --- a/drivers/net/igb/e1000_82575.c
37943 +++ b/drivers/net/igb/e1000_82575.c
37944 @@ -1411,7 +1411,7 @@ void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
37945 wr32(E1000_VT_CTL, vt_ctl);
37946 }
37947
37948 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
37949 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
37950 .reset_hw = igb_reset_hw_82575,
37951 .init_hw = igb_init_hw_82575,
37952 .check_for_link = igb_check_for_link_82575,
37953 @@ -1420,13 +1420,13 @@ static struct e1000_mac_operations e1000_mac_ops_82575 = {
37954 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
37955 };
37956
37957 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
37958 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
37959 .acquire = igb_acquire_phy_82575,
37960 .get_cfg_done = igb_get_cfg_done_82575,
37961 .release = igb_release_phy_82575,
37962 };
37963
37964 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
37965 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
37966 .acquire = igb_acquire_nvm_82575,
37967 .read = igb_read_nvm_eerd,
37968 .release = igb_release_nvm_82575,
37969 diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
37970 index 72081df..d855cf5 100644
37971 --- a/drivers/net/igb/e1000_hw.h
37972 +++ b/drivers/net/igb/e1000_hw.h
37973 @@ -288,6 +288,7 @@ struct e1000_mac_operations {
37974 s32 (*read_mac_addr)(struct e1000_hw *);
37975 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
37976 };
37977 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37978
37979 struct e1000_phy_operations {
37980 s32 (*acquire)(struct e1000_hw *);
37981 @@ -303,6 +304,7 @@ struct e1000_phy_operations {
37982 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
37983 s32 (*write_reg)(struct e1000_hw *, u32, u16);
37984 };
37985 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37986
37987 struct e1000_nvm_operations {
37988 s32 (*acquire)(struct e1000_hw *);
37989 @@ -310,6 +312,7 @@ struct e1000_nvm_operations {
37990 void (*release)(struct e1000_hw *);
37991 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
37992 };
37993 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
37994
37995 struct e1000_info {
37996 s32 (*get_invariants)(struct e1000_hw *);
37997 @@ -321,7 +324,7 @@ struct e1000_info {
37998 extern const struct e1000_info e1000_82575_info;
37999
38000 struct e1000_mac_info {
38001 - struct e1000_mac_operations ops;
38002 + e1000_mac_operations_no_const ops;
38003
38004 u8 addr[6];
38005 u8 perm_addr[6];
38006 @@ -365,7 +368,7 @@ struct e1000_mac_info {
38007 };
38008
38009 struct e1000_phy_info {
38010 - struct e1000_phy_operations ops;
38011 + e1000_phy_operations_no_const ops;
38012
38013 enum e1000_phy_type type;
38014
38015 @@ -400,7 +403,7 @@ struct e1000_phy_info {
38016 };
38017
38018 struct e1000_nvm_info {
38019 - struct e1000_nvm_operations ops;
38020 + e1000_nvm_operations_no_const ops;
38021
38022 enum e1000_nvm_type type;
38023 enum e1000_nvm_override override;
38024 @@ -446,6 +449,7 @@ struct e1000_mbx_operations {
38025 s32 (*check_for_ack)(struct e1000_hw *, u16);
38026 s32 (*check_for_rst)(struct e1000_hw *, u16);
38027 };
38028 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38029
38030 struct e1000_mbx_stats {
38031 u32 msgs_tx;
38032 @@ -457,7 +461,7 @@ struct e1000_mbx_stats {
38033 };
38034
38035 struct e1000_mbx_info {
38036 - struct e1000_mbx_operations ops;
38037 + e1000_mbx_operations_no_const ops;
38038 struct e1000_mbx_stats stats;
38039 u32 timeout;
38040 u32 usec_delay;
38041 diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
38042 index 1e8ce37..549c453 100644
38043 --- a/drivers/net/igbvf/vf.h
38044 +++ b/drivers/net/igbvf/vf.h
38045 @@ -187,9 +187,10 @@ struct e1000_mac_operations {
38046 s32 (*read_mac_addr)(struct e1000_hw *);
38047 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
38048 };
38049 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38050
38051 struct e1000_mac_info {
38052 - struct e1000_mac_operations ops;
38053 + e1000_mac_operations_no_const ops;
38054 u8 addr[6];
38055 u8 perm_addr[6];
38056
38057 @@ -211,6 +212,7 @@ struct e1000_mbx_operations {
38058 s32 (*check_for_ack)(struct e1000_hw *);
38059 s32 (*check_for_rst)(struct e1000_hw *);
38060 };
38061 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38062
38063 struct e1000_mbx_stats {
38064 u32 msgs_tx;
38065 @@ -222,7 +224,7 @@ struct e1000_mbx_stats {
38066 };
38067
38068 struct e1000_mbx_info {
38069 - struct e1000_mbx_operations ops;
38070 + e1000_mbx_operations_no_const ops;
38071 struct e1000_mbx_stats stats;
38072 u32 timeout;
38073 u32 usec_delay;
38074 diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
38075 index aa7286b..a61394f 100644
38076 --- a/drivers/net/iseries_veth.c
38077 +++ b/drivers/net/iseries_veth.c
38078 @@ -384,7 +384,7 @@ static struct attribute *veth_cnx_default_attrs[] = {
38079 NULL
38080 };
38081
38082 -static struct sysfs_ops veth_cnx_sysfs_ops = {
38083 +static const struct sysfs_ops veth_cnx_sysfs_ops = {
38084 .show = veth_cnx_attribute_show
38085 };
38086
38087 @@ -441,7 +441,7 @@ static struct attribute *veth_port_default_attrs[] = {
38088 NULL
38089 };
38090
38091 -static struct sysfs_ops veth_port_sysfs_ops = {
38092 +static const struct sysfs_ops veth_port_sysfs_ops = {
38093 .show = veth_port_attribute_show
38094 };
38095
38096 diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
38097 index 8aa44dc..fa1e797 100644
38098 --- a/drivers/net/ixgb/ixgb_main.c
38099 +++ b/drivers/net/ixgb/ixgb_main.c
38100 @@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev)
38101 u32 rctl;
38102 int i;
38103
38104 + pax_track_stack();
38105 +
38106 /* Check for Promiscuous and All Multicast modes */
38107
38108 rctl = IXGB_READ_REG(hw, RCTL);
38109 diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
38110 index af35e1d..8781785 100644
38111 --- a/drivers/net/ixgb/ixgb_param.c
38112 +++ b/drivers/net/ixgb/ixgb_param.c
38113 @@ -260,6 +260,9 @@ void __devinit
38114 ixgb_check_options(struct ixgb_adapter *adapter)
38115 {
38116 int bd = adapter->bd_number;
38117 +
38118 + pax_track_stack();
38119 +
38120 if (bd >= IXGB_MAX_NIC) {
38121 printk(KERN_NOTICE
38122 "Warning: no configuration for board #%i\n", bd);
38123 diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
38124 index b17aa73..ed74540 100644
38125 --- a/drivers/net/ixgbe/ixgbe_type.h
38126 +++ b/drivers/net/ixgbe/ixgbe_type.h
38127 @@ -2327,6 +2327,7 @@ struct ixgbe_eeprom_operations {
38128 s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
38129 s32 (*update_checksum)(struct ixgbe_hw *);
38130 };
38131 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
38132
38133 struct ixgbe_mac_operations {
38134 s32 (*init_hw)(struct ixgbe_hw *);
38135 @@ -2376,6 +2377,7 @@ struct ixgbe_mac_operations {
38136 /* Flow Control */
38137 s32 (*fc_enable)(struct ixgbe_hw *, s32);
38138 };
38139 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
38140
38141 struct ixgbe_phy_operations {
38142 s32 (*identify)(struct ixgbe_hw *);
38143 @@ -2394,9 +2396,10 @@ struct ixgbe_phy_operations {
38144 s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
38145 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
38146 };
38147 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
38148
38149 struct ixgbe_eeprom_info {
38150 - struct ixgbe_eeprom_operations ops;
38151 + ixgbe_eeprom_operations_no_const ops;
38152 enum ixgbe_eeprom_type type;
38153 u32 semaphore_delay;
38154 u16 word_size;
38155 @@ -2404,7 +2407,7 @@ struct ixgbe_eeprom_info {
38156 };
38157
38158 struct ixgbe_mac_info {
38159 - struct ixgbe_mac_operations ops;
38160 + ixgbe_mac_operations_no_const ops;
38161 enum ixgbe_mac_type type;
38162 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38163 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38164 @@ -2423,7 +2426,7 @@ struct ixgbe_mac_info {
38165 };
38166
38167 struct ixgbe_phy_info {
38168 - struct ixgbe_phy_operations ops;
38169 + ixgbe_phy_operations_no_const ops;
38170 struct mdio_if_info mdio;
38171 enum ixgbe_phy_type type;
38172 u32 id;
38173 diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
38174 index 291a505..2543756 100644
38175 --- a/drivers/net/mlx4/main.c
38176 +++ b/drivers/net/mlx4/main.c
38177 @@ -38,6 +38,7 @@
38178 #include <linux/errno.h>
38179 #include <linux/pci.h>
38180 #include <linux/dma-mapping.h>
38181 +#include <linux/sched.h>
38182
38183 #include <linux/mlx4/device.h>
38184 #include <linux/mlx4/doorbell.h>
38185 @@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
38186 u64 icm_size;
38187 int err;
38188
38189 + pax_track_stack();
38190 +
38191 err = mlx4_QUERY_FW(dev);
38192 if (err) {
38193 if (err == -EACCES)
38194 diff --git a/drivers/net/niu.c b/drivers/net/niu.c
38195 index 2dce134..fa5ce75 100644
38196 --- a/drivers/net/niu.c
38197 +++ b/drivers/net/niu.c
38198 @@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
38199 int i, num_irqs, err;
38200 u8 first_ldg;
38201
38202 + pax_track_stack();
38203 +
38204 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
38205 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
38206 ldg_num_map[i] = first_ldg + i;
38207 diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
38208 index c1b3f09..97cd8c4 100644
38209 --- a/drivers/net/pcnet32.c
38210 +++ b/drivers/net/pcnet32.c
38211 @@ -79,7 +79,7 @@ static int cards_found;
38212 /*
38213 * VLB I/O addresses
38214 */
38215 -static unsigned int pcnet32_portlist[] __initdata =
38216 +static unsigned int pcnet32_portlist[] __devinitdata =
38217 { 0x300, 0x320, 0x340, 0x360, 0 };
38218
38219 static int pcnet32_debug = 0;
38220 @@ -267,7 +267,7 @@ struct pcnet32_private {
38221 struct sk_buff **rx_skbuff;
38222 dma_addr_t *tx_dma_addr;
38223 dma_addr_t *rx_dma_addr;
38224 - struct pcnet32_access a;
38225 + struct pcnet32_access *a;
38226 spinlock_t lock; /* Guard lock */
38227 unsigned int cur_rx, cur_tx; /* The next free ring entry */
38228 unsigned int rx_ring_size; /* current rx ring size */
38229 @@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct net_device *dev)
38230 u16 val;
38231
38232 netif_wake_queue(dev);
38233 - val = lp->a.read_csr(ioaddr, CSR3);
38234 + val = lp->a->read_csr(ioaddr, CSR3);
38235 val &= 0x00ff;
38236 - lp->a.write_csr(ioaddr, CSR3, val);
38237 + lp->a->write_csr(ioaddr, CSR3, val);
38238 napi_enable(&lp->napi);
38239 }
38240
38241 @@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
38242 r = mii_link_ok(&lp->mii_if);
38243 } else if (lp->chip_version >= PCNET32_79C970A) {
38244 ulong ioaddr = dev->base_addr; /* card base I/O address */
38245 - r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38246 + r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38247 } else { /* can not detect link on really old chips */
38248 r = 1;
38249 }
38250 @@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
38251 pcnet32_netif_stop(dev);
38252
38253 spin_lock_irqsave(&lp->lock, flags);
38254 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38255 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38256
38257 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
38258
38259 @@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
38260 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38261 {
38262 struct pcnet32_private *lp = netdev_priv(dev);
38263 - struct pcnet32_access *a = &lp->a; /* access to registers */
38264 + struct pcnet32_access *a = lp->a; /* access to registers */
38265 ulong ioaddr = dev->base_addr; /* card base I/O address */
38266 struct sk_buff *skb; /* sk buff */
38267 int x, i; /* counters */
38268 @@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38269 pcnet32_netif_stop(dev);
38270
38271 spin_lock_irqsave(&lp->lock, flags);
38272 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38273 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38274
38275 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
38276
38277 /* Reset the PCNET32 */
38278 - lp->a.reset(ioaddr);
38279 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38280 + lp->a->reset(ioaddr);
38281 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38282
38283 /* switch pcnet32 to 32bit mode */
38284 - lp->a.write_bcr(ioaddr, 20, 2);
38285 + lp->a->write_bcr(ioaddr, 20, 2);
38286
38287 /* purge & init rings but don't actually restart */
38288 pcnet32_restart(dev, 0x0000);
38289
38290 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38291 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38292
38293 /* Initialize Transmit buffers. */
38294 size = data_len + 15;
38295 @@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38296
38297 /* set int loopback in CSR15 */
38298 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
38299 - lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
38300 + lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
38301
38302 teststatus = cpu_to_le16(0x8000);
38303 - lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38304 + lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38305
38306 /* Check status of descriptors */
38307 for (x = 0; x < numbuffs; x++) {
38308 @@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38309 }
38310 }
38311
38312 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38313 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38314 wmb();
38315 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
38316 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
38317 @@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38318 pcnet32_restart(dev, CSR0_NORMAL);
38319 } else {
38320 pcnet32_purge_rx_ring(dev);
38321 - lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38322 + lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38323 }
38324 spin_unlock_irqrestore(&lp->lock, flags);
38325
38326 @@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38327 static void pcnet32_led_blink_callback(struct net_device *dev)
38328 {
38329 struct pcnet32_private *lp = netdev_priv(dev);
38330 - struct pcnet32_access *a = &lp->a;
38331 + struct pcnet32_access *a = lp->a;
38332 ulong ioaddr = dev->base_addr;
38333 unsigned long flags;
38334 int i;
38335 @@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(struct net_device *dev)
38336 static int pcnet32_phys_id(struct net_device *dev, u32 data)
38337 {
38338 struct pcnet32_private *lp = netdev_priv(dev);
38339 - struct pcnet32_access *a = &lp->a;
38340 + struct pcnet32_access *a = lp->a;
38341 ulong ioaddr = dev->base_addr;
38342 unsigned long flags;
38343 int i, regs[4];
38344 @@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
38345 {
38346 int csr5;
38347 struct pcnet32_private *lp = netdev_priv(dev);
38348 - struct pcnet32_access *a = &lp->a;
38349 + struct pcnet32_access *a = lp->a;
38350 ulong ioaddr = dev->base_addr;
38351 int ticks;
38352
38353 @@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38354 spin_lock_irqsave(&lp->lock, flags);
38355 if (pcnet32_tx(dev)) {
38356 /* reset the chip to clear the error condition, then restart */
38357 - lp->a.reset(ioaddr);
38358 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38359 + lp->a->reset(ioaddr);
38360 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38361 pcnet32_restart(dev, CSR0_START);
38362 netif_wake_queue(dev);
38363 }
38364 @@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38365 __napi_complete(napi);
38366
38367 /* clear interrupt masks */
38368 - val = lp->a.read_csr(ioaddr, CSR3);
38369 + val = lp->a->read_csr(ioaddr, CSR3);
38370 val &= 0x00ff;
38371 - lp->a.write_csr(ioaddr, CSR3, val);
38372 + lp->a->write_csr(ioaddr, CSR3, val);
38373
38374 /* Set interrupt enable. */
38375 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
38376 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
38377
38378 spin_unlock_irqrestore(&lp->lock, flags);
38379 }
38380 @@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38381 int i, csr0;
38382 u16 *buff = ptr;
38383 struct pcnet32_private *lp = netdev_priv(dev);
38384 - struct pcnet32_access *a = &lp->a;
38385 + struct pcnet32_access *a = lp->a;
38386 ulong ioaddr = dev->base_addr;
38387 unsigned long flags;
38388
38389 @@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38390 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
38391 if (lp->phymask & (1 << j)) {
38392 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
38393 - lp->a.write_bcr(ioaddr, 33,
38394 + lp->a->write_bcr(ioaddr, 33,
38395 (j << 5) | i);
38396 - *buff++ = lp->a.read_bcr(ioaddr, 34);
38397 + *buff++ = lp->a->read_bcr(ioaddr, 34);
38398 }
38399 }
38400 }
38401 @@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38402 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
38403 lp->options |= PCNET32_PORT_FD;
38404
38405 - lp->a = *a;
38406 + lp->a = a;
38407
38408 /* prior to register_netdev, dev->name is not yet correct */
38409 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
38410 @@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38411 if (lp->mii) {
38412 /* lp->phycount and lp->phymask are set to 0 by memset above */
38413
38414 - lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38415 + lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38416 /* scan for PHYs */
38417 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38418 unsigned short id1, id2;
38419 @@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38420 "Found PHY %04x:%04x at address %d.\n",
38421 id1, id2, i);
38422 }
38423 - lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38424 + lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38425 if (lp->phycount > 1) {
38426 lp->options |= PCNET32_PORT_MII;
38427 }
38428 @@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_device *dev)
38429 }
38430
38431 /* Reset the PCNET32 */
38432 - lp->a.reset(ioaddr);
38433 + lp->a->reset(ioaddr);
38434
38435 /* switch pcnet32 to 32bit mode */
38436 - lp->a.write_bcr(ioaddr, 20, 2);
38437 + lp->a->write_bcr(ioaddr, 20, 2);
38438
38439 if (netif_msg_ifup(lp))
38440 printk(KERN_DEBUG
38441 @@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_device *dev)
38442 (u32) (lp->init_dma_addr));
38443
38444 /* set/reset autoselect bit */
38445 - val = lp->a.read_bcr(ioaddr, 2) & ~2;
38446 + val = lp->a->read_bcr(ioaddr, 2) & ~2;
38447 if (lp->options & PCNET32_PORT_ASEL)
38448 val |= 2;
38449 - lp->a.write_bcr(ioaddr, 2, val);
38450 + lp->a->write_bcr(ioaddr, 2, val);
38451
38452 /* handle full duplex setting */
38453 if (lp->mii_if.full_duplex) {
38454 - val = lp->a.read_bcr(ioaddr, 9) & ~3;
38455 + val = lp->a->read_bcr(ioaddr, 9) & ~3;
38456 if (lp->options & PCNET32_PORT_FD) {
38457 val |= 1;
38458 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
38459 @@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_device *dev)
38460 if (lp->chip_version == 0x2627)
38461 val |= 3;
38462 }
38463 - lp->a.write_bcr(ioaddr, 9, val);
38464 + lp->a->write_bcr(ioaddr, 9, val);
38465 }
38466
38467 /* set/reset GPSI bit in test register */
38468 - val = lp->a.read_csr(ioaddr, 124) & ~0x10;
38469 + val = lp->a->read_csr(ioaddr, 124) & ~0x10;
38470 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
38471 val |= 0x10;
38472 - lp->a.write_csr(ioaddr, 124, val);
38473 + lp->a->write_csr(ioaddr, 124, val);
38474
38475 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
38476 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
38477 @@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_device *dev)
38478 * duplex, and/or enable auto negotiation, and clear DANAS
38479 */
38480 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
38481 - lp->a.write_bcr(ioaddr, 32,
38482 - lp->a.read_bcr(ioaddr, 32) | 0x0080);
38483 + lp->a->write_bcr(ioaddr, 32,
38484 + lp->a->read_bcr(ioaddr, 32) | 0x0080);
38485 /* disable Auto Negotiation, set 10Mpbs, HD */
38486 - val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
38487 + val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
38488 if (lp->options & PCNET32_PORT_FD)
38489 val |= 0x10;
38490 if (lp->options & PCNET32_PORT_100)
38491 val |= 0x08;
38492 - lp->a.write_bcr(ioaddr, 32, val);
38493 + lp->a->write_bcr(ioaddr, 32, val);
38494 } else {
38495 if (lp->options & PCNET32_PORT_ASEL) {
38496 - lp->a.write_bcr(ioaddr, 32,
38497 - lp->a.read_bcr(ioaddr,
38498 + lp->a->write_bcr(ioaddr, 32,
38499 + lp->a->read_bcr(ioaddr,
38500 32) | 0x0080);
38501 /* enable auto negotiate, setup, disable fd */
38502 - val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
38503 + val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
38504 val |= 0x20;
38505 - lp->a.write_bcr(ioaddr, 32, val);
38506 + lp->a->write_bcr(ioaddr, 32, val);
38507 }
38508 }
38509 } else {
38510 @@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_device *dev)
38511 * There is really no good other way to handle multiple PHYs
38512 * other than turning off all automatics
38513 */
38514 - val = lp->a.read_bcr(ioaddr, 2);
38515 - lp->a.write_bcr(ioaddr, 2, val & ~2);
38516 - val = lp->a.read_bcr(ioaddr, 32);
38517 - lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38518 + val = lp->a->read_bcr(ioaddr, 2);
38519 + lp->a->write_bcr(ioaddr, 2, val & ~2);
38520 + val = lp->a->read_bcr(ioaddr, 32);
38521 + lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38522
38523 if (!(lp->options & PCNET32_PORT_ASEL)) {
38524 /* setup ecmd */
38525 @@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_device *dev)
38526 ecmd.speed =
38527 lp->
38528 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
38529 - bcr9 = lp->a.read_bcr(ioaddr, 9);
38530 + bcr9 = lp->a->read_bcr(ioaddr, 9);
38531
38532 if (lp->options & PCNET32_PORT_FD) {
38533 ecmd.duplex = DUPLEX_FULL;
38534 @@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_device *dev)
38535 ecmd.duplex = DUPLEX_HALF;
38536 bcr9 |= ~(1 << 0);
38537 }
38538 - lp->a.write_bcr(ioaddr, 9, bcr9);
38539 + lp->a->write_bcr(ioaddr, 9, bcr9);
38540 }
38541
38542 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38543 @@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_device *dev)
38544
38545 #ifdef DO_DXSUFLO
38546 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
38547 - val = lp->a.read_csr(ioaddr, CSR3);
38548 + val = lp->a->read_csr(ioaddr, CSR3);
38549 val |= 0x40;
38550 - lp->a.write_csr(ioaddr, CSR3, val);
38551 + lp->a->write_csr(ioaddr, CSR3, val);
38552 }
38553 #endif
38554
38555 @@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_device *dev)
38556 napi_enable(&lp->napi);
38557
38558 /* Re-initialize the PCNET32, and start it when done. */
38559 - lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38560 - lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38561 + lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38562 + lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38563
38564 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38565 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38566 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38567 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38568
38569 netif_start_queue(dev);
38570
38571 @@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_device *dev)
38572
38573 i = 0;
38574 while (i++ < 100)
38575 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38576 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38577 break;
38578 /*
38579 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
38580 * reports that doing so triggers a bug in the '974.
38581 */
38582 - lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
38583 + lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
38584
38585 if (netif_msg_ifup(lp))
38586 printk(KERN_DEBUG
38587 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
38588 dev->name, i,
38589 (u32) (lp->init_dma_addr),
38590 - lp->a.read_csr(ioaddr, CSR0));
38591 + lp->a->read_csr(ioaddr, CSR0));
38592
38593 spin_unlock_irqrestore(&lp->lock, flags);
38594
38595 @@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_device *dev)
38596 * Switch back to 16bit mode to avoid problems with dumb
38597 * DOS packet driver after a warm reboot
38598 */
38599 - lp->a.write_bcr(ioaddr, 20, 4);
38600 + lp->a->write_bcr(ioaddr, 20, 4);
38601
38602 err_free_irq:
38603 spin_unlock_irqrestore(&lp->lock, flags);
38604 @@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38605
38606 /* wait for stop */
38607 for (i = 0; i < 100; i++)
38608 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
38609 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
38610 break;
38611
38612 if (i >= 100 && netif_msg_drv(lp))
38613 @@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38614 return;
38615
38616 /* ReInit Ring */
38617 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38618 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38619 i = 0;
38620 while (i++ < 1000)
38621 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38622 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38623 break;
38624
38625 - lp->a.write_csr(ioaddr, CSR0, csr0_bits);
38626 + lp->a->write_csr(ioaddr, CSR0, csr0_bits);
38627 }
38628
38629 static void pcnet32_tx_timeout(struct net_device *dev)
38630 @@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
38631 if (pcnet32_debug & NETIF_MSG_DRV)
38632 printk(KERN_ERR
38633 "%s: transmit timed out, status %4.4x, resetting.\n",
38634 - dev->name, lp->a.read_csr(ioaddr, CSR0));
38635 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38636 + dev->name, lp->a->read_csr(ioaddr, CSR0));
38637 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38638 dev->stats.tx_errors++;
38639 if (netif_msg_tx_err(lp)) {
38640 int i;
38641 @@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38642 if (netif_msg_tx_queued(lp)) {
38643 printk(KERN_DEBUG
38644 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
38645 - dev->name, lp->a.read_csr(ioaddr, CSR0));
38646 + dev->name, lp->a->read_csr(ioaddr, CSR0));
38647 }
38648
38649 /* Default status -- will not enable Successful-TxDone
38650 @@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38651 dev->stats.tx_bytes += skb->len;
38652
38653 /* Trigger an immediate send poll. */
38654 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38655 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38656
38657 dev->trans_start = jiffies;
38658
38659 @@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
38660
38661 spin_lock(&lp->lock);
38662
38663 - csr0 = lp->a.read_csr(ioaddr, CSR0);
38664 + csr0 = lp->a->read_csr(ioaddr, CSR0);
38665 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
38666 if (csr0 == 0xffff) {
38667 break; /* PCMCIA remove happened */
38668 }
38669 /* Acknowledge all of the current interrupt sources ASAP. */
38670 - lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38671 + lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38672
38673 if (netif_msg_intr(lp))
38674 printk(KERN_DEBUG
38675 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
38676 - dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
38677 + dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
38678
38679 /* Log misc errors. */
38680 if (csr0 & 0x4000)
38681 @@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
38682 if (napi_schedule_prep(&lp->napi)) {
38683 u16 val;
38684 /* set interrupt masks */
38685 - val = lp->a.read_csr(ioaddr, CSR3);
38686 + val = lp->a->read_csr(ioaddr, CSR3);
38687 val |= 0x5f00;
38688 - lp->a.write_csr(ioaddr, CSR3, val);
38689 + lp->a->write_csr(ioaddr, CSR3, val);
38690
38691 __napi_schedule(&lp->napi);
38692 break;
38693 }
38694 - csr0 = lp->a.read_csr(ioaddr, CSR0);
38695 + csr0 = lp->a->read_csr(ioaddr, CSR0);
38696 }
38697
38698 if (netif_msg_intr(lp))
38699 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
38700 - dev->name, lp->a.read_csr(ioaddr, CSR0));
38701 + dev->name, lp->a->read_csr(ioaddr, CSR0));
38702
38703 spin_unlock(&lp->lock);
38704
38705 @@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_device *dev)
38706
38707 spin_lock_irqsave(&lp->lock, flags);
38708
38709 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38710 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38711
38712 if (netif_msg_ifdown(lp))
38713 printk(KERN_DEBUG
38714 "%s: Shutting down ethercard, status was %2.2x.\n",
38715 - dev->name, lp->a.read_csr(ioaddr, CSR0));
38716 + dev->name, lp->a->read_csr(ioaddr, CSR0));
38717
38718 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
38719 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38720 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38721
38722 /*
38723 * Switch back to 16bit mode to avoid problems with dumb
38724 * DOS packet driver after a warm reboot
38725 */
38726 - lp->a.write_bcr(ioaddr, 20, 4);
38727 + lp->a->write_bcr(ioaddr, 20, 4);
38728
38729 spin_unlock_irqrestore(&lp->lock, flags);
38730
38731 @@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
38732 unsigned long flags;
38733
38734 spin_lock_irqsave(&lp->lock, flags);
38735 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38736 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38737 spin_unlock_irqrestore(&lp->lock, flags);
38738
38739 return &dev->stats;
38740 @@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
38741 if (dev->flags & IFF_ALLMULTI) {
38742 ib->filter[0] = cpu_to_le32(~0U);
38743 ib->filter[1] = cpu_to_le32(~0U);
38744 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38745 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38746 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38747 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38748 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38749 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38750 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38751 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38752 return;
38753 }
38754 /* clear the multicast filter */
38755 @@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
38756 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
38757 }
38758 for (i = 0; i < 4; i++)
38759 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
38760 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
38761 le16_to_cpu(mcast_table[i]));
38762 return;
38763 }
38764 @@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38765
38766 spin_lock_irqsave(&lp->lock, flags);
38767 suspended = pcnet32_suspend(dev, &flags, 0);
38768 - csr15 = lp->a.read_csr(ioaddr, CSR15);
38769 + csr15 = lp->a->read_csr(ioaddr, CSR15);
38770 if (dev->flags & IFF_PROMISC) {
38771 /* Log any net taps. */
38772 if (netif_msg_hw(lp))
38773 @@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38774 lp->init_block->mode =
38775 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
38776 7);
38777 - lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
38778 + lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
38779 } else {
38780 lp->init_block->mode =
38781 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
38782 - lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38783 + lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38784 pcnet32_load_multicast(dev);
38785 }
38786
38787 if (suspended) {
38788 int csr5;
38789 /* clear SUSPEND (SPND) - CSR5 bit 0 */
38790 - csr5 = lp->a.read_csr(ioaddr, CSR5);
38791 - lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38792 + csr5 = lp->a->read_csr(ioaddr, CSR5);
38793 + lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38794 } else {
38795 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38796 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38797 pcnet32_restart(dev, CSR0_NORMAL);
38798 netif_wake_queue(dev);
38799 }
38800 @@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
38801 if (!lp->mii)
38802 return 0;
38803
38804 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38805 - val_out = lp->a.read_bcr(ioaddr, 34);
38806 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38807 + val_out = lp->a->read_bcr(ioaddr, 34);
38808
38809 return val_out;
38810 }
38811 @@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
38812 if (!lp->mii)
38813 return;
38814
38815 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38816 - lp->a.write_bcr(ioaddr, 34, val);
38817 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38818 + lp->a->write_bcr(ioaddr, 34, val);
38819 }
38820
38821 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38822 @@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38823 curr_link = mii_link_ok(&lp->mii_if);
38824 } else {
38825 ulong ioaddr = dev->base_addr; /* card base I/O address */
38826 - curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38827 + curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38828 }
38829 if (!curr_link) {
38830 if (prev_link || verbose) {
38831 @@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38832 (ecmd.duplex ==
38833 DUPLEX_FULL) ? "full" : "half");
38834 }
38835 - bcr9 = lp->a.read_bcr(dev->base_addr, 9);
38836 + bcr9 = lp->a->read_bcr(dev->base_addr, 9);
38837 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
38838 if (lp->mii_if.full_duplex)
38839 bcr9 |= (1 << 0);
38840 else
38841 bcr9 &= ~(1 << 0);
38842 - lp->a.write_bcr(dev->base_addr, 9, bcr9);
38843 + lp->a->write_bcr(dev->base_addr, 9, bcr9);
38844 }
38845 } else {
38846 if (netif_msg_link(lp))
38847 diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
38848 index 7cc9898..6eb50d3 100644
38849 --- a/drivers/net/sis190.c
38850 +++ b/drivers/net/sis190.c
38851 @@ -1598,7 +1598,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
38852 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
38853 struct net_device *dev)
38854 {
38855 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
38856 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
38857 struct sis190_private *tp = netdev_priv(dev);
38858 struct pci_dev *isa_bridge;
38859 u8 reg, tmp8;
38860 diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
38861 index e13685a..60c948c 100644
38862 --- a/drivers/net/sundance.c
38863 +++ b/drivers/net/sundance.c
38864 @@ -225,7 +225,7 @@ enum {
38865 struct pci_id_info {
38866 const char *name;
38867 };
38868 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
38869 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
38870 {"D-Link DFE-550TX FAST Ethernet Adapter"},
38871 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
38872 {"D-Link DFE-580TX 4 port Server Adapter"},
38873 diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
38874 index 529f55a..cccaa18 100644
38875 --- a/drivers/net/tg3.h
38876 +++ b/drivers/net/tg3.h
38877 @@ -95,6 +95,7 @@
38878 #define CHIPREV_ID_5750_A0 0x4000
38879 #define CHIPREV_ID_5750_A1 0x4001
38880 #define CHIPREV_ID_5750_A3 0x4003
38881 +#define CHIPREV_ID_5750_C1 0x4201
38882 #define CHIPREV_ID_5750_C2 0x4202
38883 #define CHIPREV_ID_5752_A0_HW 0x5000
38884 #define CHIPREV_ID_5752_A0 0x6000
38885 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
38886 index b9db1b5..720f9ce 100644
38887 --- a/drivers/net/tokenring/abyss.c
38888 +++ b/drivers/net/tokenring/abyss.c
38889 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
38890
38891 static int __init abyss_init (void)
38892 {
38893 - abyss_netdev_ops = tms380tr_netdev_ops;
38894 + pax_open_kernel();
38895 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38896
38897 - abyss_netdev_ops.ndo_open = abyss_open;
38898 - abyss_netdev_ops.ndo_stop = abyss_close;
38899 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
38900 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
38901 + pax_close_kernel();
38902
38903 return pci_register_driver(&abyss_driver);
38904 }
38905 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
38906 index 456f8bf..373e56d 100644
38907 --- a/drivers/net/tokenring/madgemc.c
38908 +++ b/drivers/net/tokenring/madgemc.c
38909 @@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver = {
38910
38911 static int __init madgemc_init (void)
38912 {
38913 - madgemc_netdev_ops = tms380tr_netdev_ops;
38914 - madgemc_netdev_ops.ndo_open = madgemc_open;
38915 - madgemc_netdev_ops.ndo_stop = madgemc_close;
38916 + pax_open_kernel();
38917 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38918 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
38919 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
38920 + pax_close_kernel();
38921
38922 return mca_register_driver (&madgemc_driver);
38923 }
38924 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
38925 index 16e8783..925bd49 100644
38926 --- a/drivers/net/tokenring/proteon.c
38927 +++ b/drivers/net/tokenring/proteon.c
38928 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
38929 struct platform_device *pdev;
38930 int i, num = 0, err = 0;
38931
38932 - proteon_netdev_ops = tms380tr_netdev_ops;
38933 - proteon_netdev_ops.ndo_open = proteon_open;
38934 - proteon_netdev_ops.ndo_stop = tms380tr_close;
38935 + pax_open_kernel();
38936 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38937 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
38938 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
38939 + pax_close_kernel();
38940
38941 err = platform_driver_register(&proteon_driver);
38942 if (err)
38943 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
38944 index 46db5c5..37c1536 100644
38945 --- a/drivers/net/tokenring/skisa.c
38946 +++ b/drivers/net/tokenring/skisa.c
38947 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
38948 struct platform_device *pdev;
38949 int i, num = 0, err = 0;
38950
38951 - sk_isa_netdev_ops = tms380tr_netdev_ops;
38952 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
38953 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
38954 + pax_open_kernel();
38955 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38956 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
38957 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
38958 + pax_close_kernel();
38959
38960 err = platform_driver_register(&sk_isa_driver);
38961 if (err)
38962 diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
38963 index 74e5ba4..5cf6bc9 100644
38964 --- a/drivers/net/tulip/de2104x.c
38965 +++ b/drivers/net/tulip/de2104x.c
38966 @@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
38967 struct de_srom_info_leaf *il;
38968 void *bufp;
38969
38970 + pax_track_stack();
38971 +
38972 /* download entire eeprom */
38973 for (i = 0; i < DE_EEPROM_WORDS; i++)
38974 ((__le16 *)ee_data)[i] =
38975 diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
38976 index a8349b7..90f9dfe 100644
38977 --- a/drivers/net/tulip/de4x5.c
38978 +++ b/drivers/net/tulip/de4x5.c
38979 @@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38980 for (i=0; i<ETH_ALEN; i++) {
38981 tmp.addr[i] = dev->dev_addr[i];
38982 }
38983 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38984 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38985 break;
38986
38987 case DE4X5_SET_HWADDR: /* Set the hardware address */
38988 @@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38989 spin_lock_irqsave(&lp->lock, flags);
38990 memcpy(&statbuf, &lp->pktStats, ioc->len);
38991 spin_unlock_irqrestore(&lp->lock, flags);
38992 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
38993 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
38994 return -EFAULT;
38995 break;
38996 }
38997 diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
38998 index 391acd3..56d11cd 100644
38999 --- a/drivers/net/tulip/eeprom.c
39000 +++ b/drivers/net/tulip/eeprom.c
39001 @@ -80,7 +80,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
39002 {NULL}};
39003
39004
39005 -static const char *block_name[] __devinitdata = {
39006 +static const char *block_name[] __devinitconst = {
39007 "21140 non-MII",
39008 "21140 MII PHY",
39009 "21142 Serial PHY",
39010 diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
39011 index b38d3b7..b1cff23 100644
39012 --- a/drivers/net/tulip/winbond-840.c
39013 +++ b/drivers/net/tulip/winbond-840.c
39014 @@ -235,7 +235,7 @@ struct pci_id_info {
39015 int drv_flags; /* Driver use, intended as capability flags. */
39016 };
39017
39018 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
39019 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
39020 { /* Sometime a Level-One switch card. */
39021 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
39022 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
39023 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39024 index f450bc9..2b747c8 100644
39025 --- a/drivers/net/usb/hso.c
39026 +++ b/drivers/net/usb/hso.c
39027 @@ -71,7 +71,7 @@
39028 #include <asm/byteorder.h>
39029 #include <linux/serial_core.h>
39030 #include <linux/serial.h>
39031 -
39032 +#include <asm/local.h>
39033
39034 #define DRIVER_VERSION "1.2"
39035 #define MOD_AUTHOR "Option Wireless"
39036 @@ -258,7 +258,7 @@ struct hso_serial {
39037
39038 /* from usb_serial_port */
39039 struct tty_struct *tty;
39040 - int open_count;
39041 + local_t open_count;
39042 spinlock_t serial_lock;
39043
39044 int (*write_data) (struct hso_serial *serial);
39045 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39046 struct urb *urb;
39047
39048 urb = serial->rx_urb[0];
39049 - if (serial->open_count > 0) {
39050 + if (local_read(&serial->open_count) > 0) {
39051 count = put_rxbuf_data(urb, serial);
39052 if (count == -1)
39053 return;
39054 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39055 DUMP1(urb->transfer_buffer, urb->actual_length);
39056
39057 /* Anyone listening? */
39058 - if (serial->open_count == 0)
39059 + if (local_read(&serial->open_count) == 0)
39060 return;
39061
39062 if (status == 0) {
39063 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39064 spin_unlock_irq(&serial->serial_lock);
39065
39066 /* check for port already opened, if not set the termios */
39067 - serial->open_count++;
39068 - if (serial->open_count == 1) {
39069 + if (local_inc_return(&serial->open_count) == 1) {
39070 tty->low_latency = 1;
39071 serial->rx_state = RX_IDLE;
39072 /* Force default termio settings */
39073 @@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39074 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39075 if (result) {
39076 hso_stop_serial_device(serial->parent);
39077 - serial->open_count--;
39078 + local_dec(&serial->open_count);
39079 kref_put(&serial->parent->ref, hso_serial_ref_free);
39080 }
39081 } else {
39082 @@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39083
39084 /* reset the rts and dtr */
39085 /* do the actual close */
39086 - serial->open_count--;
39087 + local_dec(&serial->open_count);
39088
39089 - if (serial->open_count <= 0) {
39090 - serial->open_count = 0;
39091 + if (local_read(&serial->open_count) <= 0) {
39092 + local_set(&serial->open_count, 0);
39093 spin_lock_irq(&serial->serial_lock);
39094 if (serial->tty == tty) {
39095 serial->tty->driver_data = NULL;
39096 @@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39097
39098 /* the actual setup */
39099 spin_lock_irqsave(&serial->serial_lock, flags);
39100 - if (serial->open_count)
39101 + if (local_read(&serial->open_count))
39102 _hso_serial_set_termios(tty, old);
39103 else
39104 tty->termios = old;
39105 @@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interface *iface)
39106 /* Start all serial ports */
39107 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39108 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39109 - if (dev2ser(serial_table[i])->open_count) {
39110 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
39111 result =
39112 hso_start_serial_device(serial_table[i], GFP_NOIO);
39113 hso_kick_transmit(dev2ser(serial_table[i]));
39114 diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
39115 index 3e94f0c..ffdd926 100644
39116 --- a/drivers/net/vxge/vxge-config.h
39117 +++ b/drivers/net/vxge/vxge-config.h
39118 @@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
39119 void (*link_down)(struct __vxge_hw_device *devh);
39120 void (*crit_err)(struct __vxge_hw_device *devh,
39121 enum vxge_hw_event type, u64 ext_data);
39122 -};
39123 +} __no_const;
39124
39125 /*
39126 * struct __vxge_hw_blockpool_entry - Block private data structure
39127 diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
39128 index 068d7a9..35293de 100644
39129 --- a/drivers/net/vxge/vxge-main.c
39130 +++ b/drivers/net/vxge/vxge-main.c
39131 @@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
39132 struct sk_buff *completed[NR_SKB_COMPLETED];
39133 int more;
39134
39135 + pax_track_stack();
39136 +
39137 do {
39138 more = 0;
39139 skb_ptr = completed;
39140 @@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
39141 u8 mtable[256] = {0}; /* CPU to vpath mapping */
39142 int index;
39143
39144 + pax_track_stack();
39145 +
39146 /*
39147 * Filling
39148 * - itable with bucket numbers
39149 diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
39150 index 461742b..81be42e 100644
39151 --- a/drivers/net/vxge/vxge-traffic.h
39152 +++ b/drivers/net/vxge/vxge-traffic.h
39153 @@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
39154 struct vxge_hw_mempool_dma *dma_object,
39155 u32 index,
39156 u32 is_last);
39157 -};
39158 +} __no_const;
39159
39160 void
39161 __vxge_hw_mempool_destroy(
39162 diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
39163 index cd8cb95..4153b79 100644
39164 --- a/drivers/net/wan/cycx_x25.c
39165 +++ b/drivers/net/wan/cycx_x25.c
39166 @@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned char *p, int len)
39167 unsigned char hex[1024],
39168 * phex = hex;
39169
39170 + pax_track_stack();
39171 +
39172 if (len >= (sizeof(hex) / 2))
39173 len = (sizeof(hex) / 2) - 1;
39174
39175 diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
39176 index aa9248f..a4e3c3b 100644
39177 --- a/drivers/net/wan/hdlc_x25.c
39178 +++ b/drivers/net/wan/hdlc_x25.c
39179 @@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
39180
39181 static int x25_open(struct net_device *dev)
39182 {
39183 - struct lapb_register_struct cb;
39184 + static struct lapb_register_struct cb = {
39185 + .connect_confirmation = x25_connected,
39186 + .connect_indication = x25_connected,
39187 + .disconnect_confirmation = x25_disconnected,
39188 + .disconnect_indication = x25_disconnected,
39189 + .data_indication = x25_data_indication,
39190 + .data_transmit = x25_data_transmit
39191 + };
39192 int result;
39193
39194 - cb.connect_confirmation = x25_connected;
39195 - cb.connect_indication = x25_connected;
39196 - cb.disconnect_confirmation = x25_disconnected;
39197 - cb.disconnect_indication = x25_disconnected;
39198 - cb.data_indication = x25_data_indication;
39199 - cb.data_transmit = x25_data_transmit;
39200 -
39201 result = lapb_register(dev, &cb);
39202 if (result != LAPB_OK)
39203 return result;
39204 diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
39205 index 5ad287c..783b020 100644
39206 --- a/drivers/net/wimax/i2400m/usb-fw.c
39207 +++ b/drivers/net/wimax/i2400m/usb-fw.c
39208 @@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
39209 int do_autopm = 1;
39210 DECLARE_COMPLETION_ONSTACK(notif_completion);
39211
39212 + pax_track_stack();
39213 +
39214 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
39215 i2400m, ack, ack_size);
39216 BUG_ON(_ack == i2400m->bm_ack_buf);
39217 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
39218 index 6c26840..62c97c3 100644
39219 --- a/drivers/net/wireless/airo.c
39220 +++ b/drivers/net/wireless/airo.c
39221 @@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
39222 BSSListElement * loop_net;
39223 BSSListElement * tmp_net;
39224
39225 + pax_track_stack();
39226 +
39227 /* Blow away current list of scan results */
39228 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
39229 list_move_tail (&loop_net->list, &ai->network_free_list);
39230 @@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
39231 WepKeyRid wkr;
39232 int rc;
39233
39234 + pax_track_stack();
39235 +
39236 memset( &mySsid, 0, sizeof( mySsid ) );
39237 kfree (ai->flash);
39238 ai->flash = NULL;
39239 @@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct inode *inode,
39240 __le32 *vals = stats.vals;
39241 int len;
39242
39243 + pax_track_stack();
39244 +
39245 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39246 return -ENOMEM;
39247 data = (struct proc_data *)file->private_data;
39248 @@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
39249 /* If doLoseSync is not 1, we won't do a Lose Sync */
39250 int doLoseSync = -1;
39251
39252 + pax_track_stack();
39253 +
39254 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39255 return -ENOMEM;
39256 data = (struct proc_data *)file->private_data;
39257 @@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_device *dev,
39258 int i;
39259 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
39260
39261 + pax_track_stack();
39262 +
39263 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
39264 if (!qual)
39265 return -ENOMEM;
39266 @@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
39267 CapabilityRid cap_rid;
39268 __le32 *vals = stats_rid.vals;
39269
39270 + pax_track_stack();
39271 +
39272 /* Get stats out of the card */
39273 clear_bit(JOB_WSTATS, &local->jobs);
39274 if (local->power.event) {
39275 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
39276 index 747508c..82e965d 100644
39277 --- a/drivers/net/wireless/ath/ath5k/debug.c
39278 +++ b/drivers/net/wireless/ath/ath5k/debug.c
39279 @@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
39280 unsigned int v;
39281 u64 tsf;
39282
39283 + pax_track_stack();
39284 +
39285 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
39286 len += snprintf(buf+len, sizeof(buf)-len,
39287 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
39288 @@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
39289 unsigned int len = 0;
39290 unsigned int i;
39291
39292 + pax_track_stack();
39293 +
39294 len += snprintf(buf+len, sizeof(buf)-len,
39295 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
39296
39297 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
39298 index 2be4c22..593b1eb 100644
39299 --- a/drivers/net/wireless/ath/ath9k/debug.c
39300 +++ b/drivers/net/wireless/ath/ath9k/debug.c
39301 @@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
39302 char buf[512];
39303 unsigned int len = 0;
39304
39305 + pax_track_stack();
39306 +
39307 len += snprintf(buf + len, sizeof(buf) - len,
39308 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
39309 len += snprintf(buf + len, sizeof(buf) - len,
39310 @@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
39311 int i;
39312 u8 addr[ETH_ALEN];
39313
39314 + pax_track_stack();
39315 +
39316 len += snprintf(buf + len, sizeof(buf) - len,
39317 "primary: %s (%s chan=%d ht=%d)\n",
39318 wiphy_name(sc->pri_wiphy->hw->wiphy),
39319 diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
39320 index 80b19a4..dab3a45 100644
39321 --- a/drivers/net/wireless/b43/debugfs.c
39322 +++ b/drivers/net/wireless/b43/debugfs.c
39323 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
39324 struct b43_debugfs_fops {
39325 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
39326 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
39327 - struct file_operations fops;
39328 + const struct file_operations fops;
39329 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
39330 size_t file_struct_offset;
39331 };
39332 diff --git a/drivers/net/wireless/b43legacy/debugfs.c b/drivers/net/wireless/b43legacy/debugfs.c
39333 index 1f85ac5..c99b4b4 100644
39334 --- a/drivers/net/wireless/b43legacy/debugfs.c
39335 +++ b/drivers/net/wireless/b43legacy/debugfs.c
39336 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
39337 struct b43legacy_debugfs_fops {
39338 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
39339 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
39340 - struct file_operations fops;
39341 + const struct file_operations fops;
39342 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
39343 size_t file_struct_offset;
39344 /* Take wl->irq_lock before calling read/write? */
39345 diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
39346 index 43102bf..3b569c3 100644
39347 --- a/drivers/net/wireless/ipw2x00/ipw2100.c
39348 +++ b/drivers/net/wireless/ipw2x00/ipw2100.c
39349 @@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
39350 int err;
39351 DECLARE_SSID_BUF(ssid);
39352
39353 + pax_track_stack();
39354 +
39355 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
39356
39357 if (ssid_len)
39358 @@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
39359 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
39360 int err;
39361
39362 + pax_track_stack();
39363 +
39364 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
39365 idx, keylen, len);
39366
39367 diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
39368 index 282b1f7..169f0cf 100644
39369 --- a/drivers/net/wireless/ipw2x00/libipw_rx.c
39370 +++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
39371 @@ -1566,6 +1566,8 @@ static void libipw_process_probe_response(struct libipw_device
39372 unsigned long flags;
39373 DECLARE_SSID_BUF(ssid);
39374
39375 + pax_track_stack();
39376 +
39377 LIBIPW_DEBUG_SCAN("'%s' (%pM"
39378 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
39379 print_ssid(ssid, info_element->data, info_element->len),
39380 diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
39381 index 950267a..80d5fd2 100644
39382 --- a/drivers/net/wireless/iwlwifi/iwl-1000.c
39383 +++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
39384 @@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib = {
39385 },
39386 };
39387
39388 -static struct iwl_ops iwl1000_ops = {
39389 +static const struct iwl_ops iwl1000_ops = {
39390 .ucode = &iwl5000_ucode,
39391 .lib = &iwl1000_lib,
39392 .hcmd = &iwl5000_hcmd,
39393 diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
39394 index 56bfcc3..b348020 100644
39395 --- a/drivers/net/wireless/iwlwifi/iwl-3945.c
39396 +++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
39397 @@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
39398 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
39399 };
39400
39401 -static struct iwl_ops iwl3945_ops = {
39402 +static const struct iwl_ops iwl3945_ops = {
39403 .ucode = &iwl3945_ucode,
39404 .lib = &iwl3945_lib,
39405 .hcmd = &iwl3945_hcmd,
39406 diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
39407 index 585b8d4..e142963 100644
39408 --- a/drivers/net/wireless/iwlwifi/iwl-4965.c
39409 +++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
39410 @@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib = {
39411 },
39412 };
39413
39414 -static struct iwl_ops iwl4965_ops = {
39415 +static const struct iwl_ops iwl4965_ops = {
39416 .ucode = &iwl4965_ucode,
39417 .lib = &iwl4965_lib,
39418 .hcmd = &iwl4965_hcmd,
39419 diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
39420 index 1f423f2..e37c192 100644
39421 --- a/drivers/net/wireless/iwlwifi/iwl-5000.c
39422 +++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
39423 @@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib = {
39424 },
39425 };
39426
39427 -struct iwl_ops iwl5000_ops = {
39428 +const struct iwl_ops iwl5000_ops = {
39429 .ucode = &iwl5000_ucode,
39430 .lib = &iwl5000_lib,
39431 .hcmd = &iwl5000_hcmd,
39432 .utils = &iwl5000_hcmd_utils,
39433 };
39434
39435 -static struct iwl_ops iwl5150_ops = {
39436 +static const struct iwl_ops iwl5150_ops = {
39437 .ucode = &iwl5000_ucode,
39438 .lib = &iwl5150_lib,
39439 .hcmd = &iwl5000_hcmd,
39440 diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
39441 index 1473452..f07d5e1 100644
39442 --- a/drivers/net/wireless/iwlwifi/iwl-6000.c
39443 +++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
39444 @@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000_hcmd_utils = {
39445 .calc_rssi = iwl5000_calc_rssi,
39446 };
39447
39448 -static struct iwl_ops iwl6000_ops = {
39449 +static const struct iwl_ops iwl6000_ops = {
39450 .ucode = &iwl5000_ucode,
39451 .lib = &iwl6000_lib,
39452 .hcmd = &iwl5000_hcmd,
39453 diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39454 index 1a3dfa2..b3e0a61 100644
39455 --- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39456 +++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39457 @@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
39458 u8 active_index = 0;
39459 s32 tpt = 0;
39460
39461 + pax_track_stack();
39462 +
39463 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
39464
39465 if (!ieee80211_is_data(hdr->frame_control) ||
39466 @@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
39467 u8 valid_tx_ant = 0;
39468 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
39469
39470 + pax_track_stack();
39471 +
39472 /* Override starting rate (index 0) if needed for debug purposes */
39473 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
39474
39475 diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
39476 index 0e56d78..6a3c107 100644
39477 --- a/drivers/net/wireless/iwlwifi/iwl-agn.c
39478 +++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
39479 @@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39480 if (iwl_debug_level & IWL_DL_INFO)
39481 dev_printk(KERN_DEBUG, &(pdev->dev),
39482 "Disabling hw_scan\n");
39483 - iwl_hw_ops.hw_scan = NULL;
39484 + pax_open_kernel();
39485 + *(void **)&iwl_hw_ops.hw_scan = NULL;
39486 + pax_close_kernel();
39487 }
39488
39489 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
39490 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
39491 index cbc6290..eb323d7 100644
39492 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
39493 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
39494 @@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv);
39495 #endif
39496
39497 #else
39498 -#define IWL_DEBUG(__priv, level, fmt, args...)
39499 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
39500 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
39501 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
39502 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
39503 void *p, u32 len)
39504 {}
39505 diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39506 index a198bcf..8e68233 100644
39507 --- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39508 +++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39509 @@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
39510 int pos = 0;
39511 const size_t bufsz = sizeof(buf);
39512
39513 + pax_track_stack();
39514 +
39515 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
39516 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
39517 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
39518 @@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
39519 const size_t bufsz = sizeof(buf);
39520 ssize_t ret;
39521
39522 + pax_track_stack();
39523 +
39524 for (i = 0; i < AC_NUM; i++) {
39525 pos += scnprintf(buf + pos, bufsz - pos,
39526 "\tcw_min\tcw_max\taifsn\ttxop\n");
39527 diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
39528 index 3539ea4..b174bfa 100644
39529 --- a/drivers/net/wireless/iwlwifi/iwl-dev.h
39530 +++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
39531 @@ -68,7 +68,7 @@ struct iwl_tx_queue;
39532
39533 /* shared structures from iwl-5000.c */
39534 extern struct iwl_mod_params iwl50_mod_params;
39535 -extern struct iwl_ops iwl5000_ops;
39536 +extern const struct iwl_ops iwl5000_ops;
39537 extern struct iwl_ucode_ops iwl5000_ucode;
39538 extern struct iwl_lib_ops iwl5000_lib;
39539 extern struct iwl_hcmd_ops iwl5000_hcmd;
39540 diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39541 index 619590d..69235ee 100644
39542 --- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
39543 +++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39544 @@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
39545 */
39546 if (iwl3945_mod_params.disable_hw_scan) {
39547 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
39548 - iwl3945_hw_ops.hw_scan = NULL;
39549 + pax_open_kernel();
39550 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
39551 + pax_close_kernel();
39552 }
39553
39554
39555 diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39556 index 1465379..fe4d78b 100644
39557 --- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
39558 +++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39559 @@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
39560 int buf_len = 512;
39561 size_t len = 0;
39562
39563 + pax_track_stack();
39564 +
39565 if (*ppos != 0)
39566 return 0;
39567 if (count < sizeof(buf))
39568 diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
39569 index 893a55c..7f66a50 100644
39570 --- a/drivers/net/wireless/libertas/debugfs.c
39571 +++ b/drivers/net/wireless/libertas/debugfs.c
39572 @@ -708,7 +708,7 @@ out_unlock:
39573 struct lbs_debugfs_files {
39574 const char *name;
39575 int perm;
39576 - struct file_operations fops;
39577 + const struct file_operations fops;
39578 };
39579
39580 static const struct lbs_debugfs_files debugfs_files[] = {
39581 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39582 index 2ecbedb..42704f0 100644
39583 --- a/drivers/net/wireless/rndis_wlan.c
39584 +++ b/drivers/net/wireless/rndis_wlan.c
39585 @@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39586
39587 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
39588
39589 - if (rts_threshold < 0 || rts_threshold > 2347)
39590 + if (rts_threshold > 2347)
39591 rts_threshold = 2347;
39592
39593 tmp = cpu_to_le32(rts_threshold);
39594 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39595 index 334ccd6..47f8944 100644
39596 --- a/drivers/oprofile/buffer_sync.c
39597 +++ b/drivers/oprofile/buffer_sync.c
39598 @@ -342,7 +342,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39599 if (cookie == NO_COOKIE)
39600 offset = pc;
39601 if (cookie == INVALID_COOKIE) {
39602 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39603 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39604 offset = pc;
39605 }
39606 if (cookie != last_cookie) {
39607 @@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39608 /* add userspace sample */
39609
39610 if (!mm) {
39611 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
39612 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39613 return 0;
39614 }
39615
39616 cookie = lookup_dcookie(mm, s->eip, &offset);
39617
39618 if (cookie == INVALID_COOKIE) {
39619 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39620 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39621 return 0;
39622 }
39623
39624 @@ -562,7 +562,7 @@ void sync_buffer(int cpu)
39625 /* ignore backtraces if failed to add a sample */
39626 if (state == sb_bt_start) {
39627 state = sb_bt_ignore;
39628 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39629 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39630 }
39631 }
39632 release_mm(mm);
39633 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39634 index 5df60a6..72f5c1c 100644
39635 --- a/drivers/oprofile/event_buffer.c
39636 +++ b/drivers/oprofile/event_buffer.c
39637 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39638 }
39639
39640 if (buffer_pos == buffer_size) {
39641 - atomic_inc(&oprofile_stats.event_lost_overflow);
39642 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39643 return;
39644 }
39645
39646 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39647 index dc8a042..fe5f315 100644
39648 --- a/drivers/oprofile/oprof.c
39649 +++ b/drivers/oprofile/oprof.c
39650 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39651 if (oprofile_ops.switch_events())
39652 return;
39653
39654 - atomic_inc(&oprofile_stats.multiplex_counter);
39655 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39656 start_switch_worker();
39657 }
39658
39659 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39660 index 61689e8..387f7f8 100644
39661 --- a/drivers/oprofile/oprofile_stats.c
39662 +++ b/drivers/oprofile/oprofile_stats.c
39663 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39664 cpu_buf->sample_invalid_eip = 0;
39665 }
39666
39667 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39668 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39669 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
39670 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39671 - atomic_set(&oprofile_stats.multiplex_counter, 0);
39672 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39673 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39674 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39675 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39676 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39677 }
39678
39679
39680 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39681 index 0b54e46..a37c527 100644
39682 --- a/drivers/oprofile/oprofile_stats.h
39683 +++ b/drivers/oprofile/oprofile_stats.h
39684 @@ -13,11 +13,11 @@
39685 #include <asm/atomic.h>
39686
39687 struct oprofile_stat_struct {
39688 - atomic_t sample_lost_no_mm;
39689 - atomic_t sample_lost_no_mapping;
39690 - atomic_t bt_lost_no_mapping;
39691 - atomic_t event_lost_overflow;
39692 - atomic_t multiplex_counter;
39693 + atomic_unchecked_t sample_lost_no_mm;
39694 + atomic_unchecked_t sample_lost_no_mapping;
39695 + atomic_unchecked_t bt_lost_no_mapping;
39696 + atomic_unchecked_t event_lost_overflow;
39697 + atomic_unchecked_t multiplex_counter;
39698 };
39699
39700 extern struct oprofile_stat_struct oprofile_stats;
39701 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39702 index 2766a6d..80c77e2 100644
39703 --- a/drivers/oprofile/oprofilefs.c
39704 +++ b/drivers/oprofile/oprofilefs.c
39705 @@ -187,7 +187,7 @@ static const struct file_operations atomic_ro_fops = {
39706
39707
39708 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39709 - char const *name, atomic_t *val)
39710 + char const *name, atomic_unchecked_t *val)
39711 {
39712 struct dentry *d = __oprofilefs_create_file(sb, root, name,
39713 &atomic_ro_fops, 0444);
39714 diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
39715 index 13a64bc..ad62835 100644
39716 --- a/drivers/parisc/pdc_stable.c
39717 +++ b/drivers/parisc/pdc_stable.c
39718 @@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
39719 return ret;
39720 }
39721
39722 -static struct sysfs_ops pdcspath_attr_ops = {
39723 +static const struct sysfs_ops pdcspath_attr_ops = {
39724 .show = pdcspath_attr_show,
39725 .store = pdcspath_attr_store,
39726 };
39727 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39728 index 8eefe56..40751a7 100644
39729 --- a/drivers/parport/procfs.c
39730 +++ b/drivers/parport/procfs.c
39731 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
39732
39733 *ppos += len;
39734
39735 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
39736 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
39737 }
39738
39739 #ifdef CONFIG_PARPORT_1284
39740 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39741
39742 *ppos += len;
39743
39744 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39745 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39746 }
39747 #endif /* IEEE1284.3 support. */
39748
39749 diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
39750 index 73e7d8e..c80f3d2 100644
39751 --- a/drivers/pci/hotplug/acpiphp_glue.c
39752 +++ b/drivers/pci/hotplug/acpiphp_glue.c
39753 @@ -111,7 +111,7 @@ static int post_dock_fixups(struct notifier_block *nb, unsigned long val,
39754 }
39755
39756
39757 -static struct acpi_dock_ops acpiphp_dock_ops = {
39758 +static const struct acpi_dock_ops acpiphp_dock_ops = {
39759 .handler = handle_hotplug_event_func,
39760 };
39761
39762 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
39763 index 9fff878..ad0ad53 100644
39764 --- a/drivers/pci/hotplug/cpci_hotplug.h
39765 +++ b/drivers/pci/hotplug/cpci_hotplug.h
39766 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
39767 int (*hardware_test) (struct slot* slot, u32 value);
39768 u8 (*get_power) (struct slot* slot);
39769 int (*set_power) (struct slot* slot, int value);
39770 -};
39771 +} __no_const;
39772
39773 struct cpci_hp_controller {
39774 unsigned int irq;
39775 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
39776 index 76ba8a1..20ca857 100644
39777 --- a/drivers/pci/hotplug/cpqphp_nvram.c
39778 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
39779 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
39780
39781 void compaq_nvram_init (void __iomem *rom_start)
39782 {
39783 +
39784 +#ifndef CONFIG_PAX_KERNEXEC
39785 if (rom_start) {
39786 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
39787 }
39788 +#endif
39789 +
39790 dbg("int15 entry = %p\n", compaq_int15_entry_point);
39791
39792 /* initialize our int15 lock */
39793 diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
39794 index 6151389..0a894ef 100644
39795 --- a/drivers/pci/hotplug/fakephp.c
39796 +++ b/drivers/pci/hotplug/fakephp.c
39797 @@ -73,7 +73,7 @@ static void legacy_release(struct kobject *kobj)
39798 }
39799
39800 static struct kobj_type legacy_ktype = {
39801 - .sysfs_ops = &(struct sysfs_ops){
39802 + .sysfs_ops = &(const struct sysfs_ops){
39803 .store = legacy_store, .show = legacy_show
39804 },
39805 .release = &legacy_release,
39806 diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
39807 index 5b680df..fe05b7e 100644
39808 --- a/drivers/pci/intel-iommu.c
39809 +++ b/drivers/pci/intel-iommu.c
39810 @@ -2643,7 +2643,7 @@ error:
39811 return 0;
39812 }
39813
39814 -static dma_addr_t intel_map_page(struct device *dev, struct page *page,
39815 +dma_addr_t intel_map_page(struct device *dev, struct page *page,
39816 unsigned long offset, size_t size,
39817 enum dma_data_direction dir,
39818 struct dma_attrs *attrs)
39819 @@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
39820 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
39821 }
39822
39823 -static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39824 +void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39825 size_t size, enum dma_data_direction dir,
39826 struct dma_attrs *attrs)
39827 {
39828 @@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39829 }
39830 }
39831
39832 -static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39833 +void *intel_alloc_coherent(struct device *hwdev, size_t size,
39834 dma_addr_t *dma_handle, gfp_t flags)
39835 {
39836 void *vaddr;
39837 @@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39838 return NULL;
39839 }
39840
39841 -static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39842 +void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39843 dma_addr_t dma_handle)
39844 {
39845 int order;
39846 @@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39847 free_pages((unsigned long)vaddr, order);
39848 }
39849
39850 -static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39851 +void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39852 int nelems, enum dma_data_direction dir,
39853 struct dma_attrs *attrs)
39854 {
39855 @@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(struct device *hddev,
39856 return nelems;
39857 }
39858
39859 -static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39860 +int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39861 enum dma_data_direction dir, struct dma_attrs *attrs)
39862 {
39863 int i;
39864 @@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
39865 return nelems;
39866 }
39867
39868 -static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39869 +int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39870 {
39871 return !dma_addr;
39872 }
39873
39874 -struct dma_map_ops intel_dma_ops = {
39875 +const struct dma_map_ops intel_dma_ops = {
39876 .alloc_coherent = intel_alloc_coherent,
39877 .free_coherent = intel_free_coherent,
39878 .map_sg = intel_map_sg,
39879 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
39880 index 5b7056c..607bc94 100644
39881 --- a/drivers/pci/pcie/aspm.c
39882 +++ b/drivers/pci/pcie/aspm.c
39883 @@ -27,9 +27,9 @@
39884 #define MODULE_PARAM_PREFIX "pcie_aspm."
39885
39886 /* Note: those are not register definitions */
39887 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
39888 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
39889 -#define ASPM_STATE_L1 (4) /* L1 state */
39890 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
39891 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
39892 +#define ASPM_STATE_L1 (4U) /* L1 state */
39893 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
39894 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
39895
39896 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
39897 index 8105e32..ca10419 100644
39898 --- a/drivers/pci/probe.c
39899 +++ b/drivers/pci/probe.c
39900 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
39901 return ret;
39902 }
39903
39904 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
39905 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
39906 struct device_attribute *attr,
39907 char *buf)
39908 {
39909 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
39910 }
39911
39912 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
39913 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
39914 struct device_attribute *attr,
39915 char *buf)
39916 {
39917 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
39918 index a03ad8c..024b0da 100644
39919 --- a/drivers/pci/proc.c
39920 +++ b/drivers/pci/proc.c
39921 @@ -480,7 +480,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
39922 static int __init pci_proc_init(void)
39923 {
39924 struct pci_dev *dev = NULL;
39925 +
39926 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
39927 +#ifdef CONFIG_GRKERNSEC_PROC_USER
39928 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
39929 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
39930 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
39931 +#endif
39932 +#else
39933 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
39934 +#endif
39935 proc_create("devices", 0, proc_bus_pci_dir,
39936 &proc_bus_pci_dev_operations);
39937 proc_initialized = 1;
39938 diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
39939 index 8c02b6c..5584d8e 100644
39940 --- a/drivers/pci/slot.c
39941 +++ b/drivers/pci/slot.c
39942 @@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struct kobject *kobj,
39943 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
39944 }
39945
39946 -static struct sysfs_ops pci_slot_sysfs_ops = {
39947 +static const struct sysfs_ops pci_slot_sysfs_ops = {
39948 .show = pci_slot_attr_show,
39949 .store = pci_slot_attr_store,
39950 };
39951 diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
39952 index 30cf71d2..50938f1 100644
39953 --- a/drivers/pcmcia/pcmcia_ioctl.c
39954 +++ b/drivers/pcmcia/pcmcia_ioctl.c
39955 @@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
39956 return -EFAULT;
39957 }
39958 }
39959 - buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
39960 + buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
39961 if (!buf)
39962 return -ENOMEM;
39963
39964 diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
39965 index 52183c4..b224c69 100644
39966 --- a/drivers/platform/x86/acer-wmi.c
39967 +++ b/drivers/platform/x86/acer-wmi.c
39968 @@ -918,7 +918,7 @@ static int update_bl_status(struct backlight_device *bd)
39969 return 0;
39970 }
39971
39972 -static struct backlight_ops acer_bl_ops = {
39973 +static const struct backlight_ops acer_bl_ops = {
39974 .get_brightness = read_brightness,
39975 .update_status = update_bl_status,
39976 };
39977 diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
39978 index 767cb61..a87380b 100644
39979 --- a/drivers/platform/x86/asus-laptop.c
39980 +++ b/drivers/platform/x86/asus-laptop.c
39981 @@ -250,7 +250,7 @@ static struct backlight_device *asus_backlight_device;
39982 */
39983 static int read_brightness(struct backlight_device *bd);
39984 static int update_bl_status(struct backlight_device *bd);
39985 -static struct backlight_ops asusbl_ops = {
39986 +static const struct backlight_ops asusbl_ops = {
39987 .get_brightness = read_brightness,
39988 .update_status = update_bl_status,
39989 };
39990 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
39991 index d66c07a..a4abaac 100644
39992 --- a/drivers/platform/x86/asus_acpi.c
39993 +++ b/drivers/platform/x86/asus_acpi.c
39994 @@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
39995 return 0;
39996 }
39997
39998 -static struct backlight_ops asus_backlight_data = {
39999 +static const struct backlight_ops asus_backlight_data = {
40000 .get_brightness = read_brightness,
40001 .update_status = set_brightness_status,
40002 };
40003 diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
40004 index 11003bb..550ff1b 100644
40005 --- a/drivers/platform/x86/compal-laptop.c
40006 +++ b/drivers/platform/x86/compal-laptop.c
40007 @@ -163,7 +163,7 @@ static int bl_update_status(struct backlight_device *b)
40008 return set_lcd_level(b->props.brightness);
40009 }
40010
40011 -static struct backlight_ops compalbl_ops = {
40012 +static const struct backlight_ops compalbl_ops = {
40013 .get_brightness = bl_get_brightness,
40014 .update_status = bl_update_status,
40015 };
40016 diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
40017 index 07a74da..9dc99fa 100644
40018 --- a/drivers/platform/x86/dell-laptop.c
40019 +++ b/drivers/platform/x86/dell-laptop.c
40020 @@ -318,7 +318,7 @@ static int dell_get_intensity(struct backlight_device *bd)
40021 return buffer.output[1];
40022 }
40023
40024 -static struct backlight_ops dell_ops = {
40025 +static const struct backlight_ops dell_ops = {
40026 .get_brightness = dell_get_intensity,
40027 .update_status = dell_send_intensity,
40028 };
40029 diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
40030 index c533b1c..5c81f22 100644
40031 --- a/drivers/platform/x86/eeepc-laptop.c
40032 +++ b/drivers/platform/x86/eeepc-laptop.c
40033 @@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device;
40034 */
40035 static int read_brightness(struct backlight_device *bd);
40036 static int update_bl_status(struct backlight_device *bd);
40037 -static struct backlight_ops eeepcbl_ops = {
40038 +static const struct backlight_ops eeepcbl_ops = {
40039 .get_brightness = read_brightness,
40040 .update_status = update_bl_status,
40041 };
40042 diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
40043 index bcd4ba8..a249b35 100644
40044 --- a/drivers/platform/x86/fujitsu-laptop.c
40045 +++ b/drivers/platform/x86/fujitsu-laptop.c
40046 @@ -436,7 +436,7 @@ static int bl_update_status(struct backlight_device *b)
40047 return ret;
40048 }
40049
40050 -static struct backlight_ops fujitsubl_ops = {
40051 +static const struct backlight_ops fujitsubl_ops = {
40052 .get_brightness = bl_get_brightness,
40053 .update_status = bl_update_status,
40054 };
40055 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40056 index 759763d..1093ba2 100644
40057 --- a/drivers/platform/x86/msi-laptop.c
40058 +++ b/drivers/platform/x86/msi-laptop.c
40059 @@ -161,7 +161,7 @@ static int bl_update_status(struct backlight_device *b)
40060 return set_lcd_level(b->props.brightness);
40061 }
40062
40063 -static struct backlight_ops msibl_ops = {
40064 +static const struct backlight_ops msibl_ops = {
40065 .get_brightness = bl_get_brightness,
40066 .update_status = bl_update_status,
40067 };
40068 diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
40069 index fe7cf01..9012d8d 100644
40070 --- a/drivers/platform/x86/panasonic-laptop.c
40071 +++ b/drivers/platform/x86/panasonic-laptop.c
40072 @@ -352,7 +352,7 @@ static int bl_set_status(struct backlight_device *bd)
40073 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
40074 }
40075
40076 -static struct backlight_ops pcc_backlight_ops = {
40077 +static const struct backlight_ops pcc_backlight_ops = {
40078 .get_brightness = bl_get,
40079 .update_status = bl_set_status,
40080 };
40081 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40082 index a2a742c..b37e25e 100644
40083 --- a/drivers/platform/x86/sony-laptop.c
40084 +++ b/drivers/platform/x86/sony-laptop.c
40085 @@ -850,7 +850,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
40086 }
40087
40088 static struct backlight_device *sony_backlight_device;
40089 -static struct backlight_ops sony_backlight_ops = {
40090 +static const struct backlight_ops sony_backlight_ops = {
40091 .update_status = sony_backlight_update_status,
40092 .get_brightness = sony_backlight_get_brightness,
40093 };
40094 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40095 index 68271ae..5e8fb10 100644
40096 --- a/drivers/platform/x86/thinkpad_acpi.c
40097 +++ b/drivers/platform/x86/thinkpad_acpi.c
40098 @@ -2139,7 +2139,7 @@ static int hotkey_mask_get(void)
40099 return 0;
40100 }
40101
40102 -void static hotkey_mask_warn_incomplete_mask(void)
40103 +static void hotkey_mask_warn_incomplete_mask(void)
40104 {
40105 /* log only what the user can fix... */
40106 const u32 wantedmask = hotkey_driver_mask &
40107 @@ -6125,7 +6125,7 @@ static void tpacpi_brightness_notify_change(void)
40108 BACKLIGHT_UPDATE_HOTKEY);
40109 }
40110
40111 -static struct backlight_ops ibm_backlight_data = {
40112 +static const struct backlight_ops ibm_backlight_data = {
40113 .get_brightness = brightness_get,
40114 .update_status = brightness_update_status,
40115 };
40116 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
40117 index 51c0a8b..0786629 100644
40118 --- a/drivers/platform/x86/toshiba_acpi.c
40119 +++ b/drivers/platform/x86/toshiba_acpi.c
40120 @@ -671,7 +671,7 @@ static acpi_status remove_device(void)
40121 return AE_OK;
40122 }
40123
40124 -static struct backlight_ops toshiba_backlight_data = {
40125 +static const struct backlight_ops toshiba_backlight_data = {
40126 .get_brightness = get_lcd,
40127 .update_status = set_lcd_status,
40128 };
40129 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40130 index fc83783c..cf370d7 100644
40131 --- a/drivers/pnp/pnpbios/bioscalls.c
40132 +++ b/drivers/pnp/pnpbios/bioscalls.c
40133 @@ -60,7 +60,7 @@ do { \
40134 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40135 } while(0)
40136
40137 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40138 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40139 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40140
40141 /*
40142 @@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40143
40144 cpu = get_cpu();
40145 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40146 +
40147 + pax_open_kernel();
40148 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40149 + pax_close_kernel();
40150
40151 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40152 spin_lock_irqsave(&pnp_bios_lock, flags);
40153 @@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40154 :"memory");
40155 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40156
40157 + pax_open_kernel();
40158 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40159 + pax_close_kernel();
40160 +
40161 put_cpu();
40162
40163 /* If we get here and this is set then the PnP BIOS faulted on us. */
40164 @@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40165 return status;
40166 }
40167
40168 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
40169 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40170 {
40171 int i;
40172
40173 @@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40174 pnp_bios_callpoint.offset = header->fields.pm16offset;
40175 pnp_bios_callpoint.segment = PNP_CS16;
40176
40177 + pax_open_kernel();
40178 +
40179 for_each_possible_cpu(i) {
40180 struct desc_struct *gdt = get_cpu_gdt_table(i);
40181 if (!gdt)
40182 @@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40183 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40184 (unsigned long)__va(header->fields.pm16dseg));
40185 }
40186 +
40187 + pax_close_kernel();
40188 }
40189 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40190 index ba97654..66b99d4 100644
40191 --- a/drivers/pnp/resource.c
40192 +++ b/drivers/pnp/resource.c
40193 @@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40194 return 1;
40195
40196 /* check if the resource is valid */
40197 - if (*irq < 0 || *irq > 15)
40198 + if (*irq > 15)
40199 return 0;
40200
40201 /* check if the resource is reserved */
40202 @@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40203 return 1;
40204
40205 /* check if the resource is valid */
40206 - if (*dma < 0 || *dma == 4 || *dma > 7)
40207 + if (*dma == 4 || *dma > 7)
40208 return 0;
40209
40210 /* check if the resource is reserved */
40211 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
40212 index 62bb981..24a2dc9 100644
40213 --- a/drivers/power/bq27x00_battery.c
40214 +++ b/drivers/power/bq27x00_battery.c
40215 @@ -44,7 +44,7 @@ struct bq27x00_device_info;
40216 struct bq27x00_access_methods {
40217 int (*read)(u8 reg, int *rt_value, int b_single,
40218 struct bq27x00_device_info *di);
40219 -};
40220 +} __no_const;
40221
40222 struct bq27x00_device_info {
40223 struct device *dev;
40224 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40225 index 62227cd..b5b538b 100644
40226 --- a/drivers/rtc/rtc-dev.c
40227 +++ b/drivers/rtc/rtc-dev.c
40228 @@ -14,6 +14,7 @@
40229 #include <linux/module.h>
40230 #include <linux/rtc.h>
40231 #include <linux/sched.h>
40232 +#include <linux/grsecurity.h>
40233 #include "rtc-core.h"
40234
40235 static dev_t rtc_devt;
40236 @@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *file,
40237 if (copy_from_user(&tm, uarg, sizeof(tm)))
40238 return -EFAULT;
40239
40240 + gr_log_timechange();
40241 +
40242 return rtc_set_time(rtc, &tm);
40243
40244 case RTC_PIE_ON:
40245 diff --git a/drivers/s390/cio/qdio_perf.c b/drivers/s390/cio/qdio_perf.c
40246 index 968e3c7..fbc637a 100644
40247 --- a/drivers/s390/cio/qdio_perf.c
40248 +++ b/drivers/s390/cio/qdio_perf.c
40249 @@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_pde;
40250 static int qdio_perf_proc_show(struct seq_file *m, void *v)
40251 {
40252 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
40253 - (long)atomic_long_read(&perf_stats.qdio_int));
40254 + (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
40255 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
40256 - (long)atomic_long_read(&perf_stats.pci_int));
40257 + (long)atomic_long_read_unchecked(&perf_stats.pci_int));
40258 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
40259 - (long)atomic_long_read(&perf_stats.thin_int));
40260 + (long)atomic_long_read_unchecked(&perf_stats.thin_int));
40261 seq_printf(m, "\n");
40262 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
40263 - (long)atomic_long_read(&perf_stats.tasklet_inbound));
40264 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
40265 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
40266 - (long)atomic_long_read(&perf_stats.tasklet_outbound));
40267 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
40268 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
40269 - (long)atomic_long_read(&perf_stats.tasklet_thinint),
40270 - (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
40271 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
40272 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
40273 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
40274 - (long)atomic_long_read(&perf_stats.thinint_inbound),
40275 - (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
40276 + (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
40277 + (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
40278 seq_printf(m, "\n");
40279 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
40280 - (long)atomic_long_read(&perf_stats.siga_in));
40281 + (long)atomic_long_read_unchecked(&perf_stats.siga_in));
40282 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
40283 - (long)atomic_long_read(&perf_stats.siga_out));
40284 + (long)atomic_long_read_unchecked(&perf_stats.siga_out));
40285 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
40286 - (long)atomic_long_read(&perf_stats.siga_sync));
40287 + (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
40288 seq_printf(m, "\n");
40289 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
40290 - (long)atomic_long_read(&perf_stats.inbound_handler));
40291 + (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
40292 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
40293 - (long)atomic_long_read(&perf_stats.outbound_handler));
40294 + (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
40295 seq_printf(m, "\n");
40296 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
40297 - (long)atomic_long_read(&perf_stats.fast_requeue));
40298 + (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
40299 seq_printf(m, "Number of outbound target full condition\t: %li\n",
40300 - (long)atomic_long_read(&perf_stats.outbound_target_full));
40301 + (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
40302 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
40303 - (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
40304 + (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
40305 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
40306 - (long)atomic_long_read(&perf_stats.debug_stop_polling));
40307 + (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
40308 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
40309 - (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
40310 + (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
40311 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
40312 - (long)atomic_long_read(&perf_stats.debug_eqbs_all),
40313 - (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
40314 + (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
40315 + (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
40316 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
40317 - (long)atomic_long_read(&perf_stats.debug_sqbs_all),
40318 - (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
40319 + (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
40320 + (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
40321 seq_printf(m, "\n");
40322 return 0;
40323 }
40324 diff --git a/drivers/s390/cio/qdio_perf.h b/drivers/s390/cio/qdio_perf.h
40325 index ff4504c..b3604c3 100644
40326 --- a/drivers/s390/cio/qdio_perf.h
40327 +++ b/drivers/s390/cio/qdio_perf.h
40328 @@ -13,46 +13,46 @@
40329
40330 struct qdio_perf_stats {
40331 /* interrupt handler calls */
40332 - atomic_long_t qdio_int;
40333 - atomic_long_t pci_int;
40334 - atomic_long_t thin_int;
40335 + atomic_long_unchecked_t qdio_int;
40336 + atomic_long_unchecked_t pci_int;
40337 + atomic_long_unchecked_t thin_int;
40338
40339 /* tasklet runs */
40340 - atomic_long_t tasklet_inbound;
40341 - atomic_long_t tasklet_outbound;
40342 - atomic_long_t tasklet_thinint;
40343 - atomic_long_t tasklet_thinint_loop;
40344 - atomic_long_t thinint_inbound;
40345 - atomic_long_t thinint_inbound_loop;
40346 - atomic_long_t thinint_inbound_loop2;
40347 + atomic_long_unchecked_t tasklet_inbound;
40348 + atomic_long_unchecked_t tasklet_outbound;
40349 + atomic_long_unchecked_t tasklet_thinint;
40350 + atomic_long_unchecked_t tasklet_thinint_loop;
40351 + atomic_long_unchecked_t thinint_inbound;
40352 + atomic_long_unchecked_t thinint_inbound_loop;
40353 + atomic_long_unchecked_t thinint_inbound_loop2;
40354
40355 /* signal adapter calls */
40356 - atomic_long_t siga_out;
40357 - atomic_long_t siga_in;
40358 - atomic_long_t siga_sync;
40359 + atomic_long_unchecked_t siga_out;
40360 + atomic_long_unchecked_t siga_in;
40361 + atomic_long_unchecked_t siga_sync;
40362
40363 /* misc */
40364 - atomic_long_t inbound_handler;
40365 - atomic_long_t outbound_handler;
40366 - atomic_long_t fast_requeue;
40367 - atomic_long_t outbound_target_full;
40368 + atomic_long_unchecked_t inbound_handler;
40369 + atomic_long_unchecked_t outbound_handler;
40370 + atomic_long_unchecked_t fast_requeue;
40371 + atomic_long_unchecked_t outbound_target_full;
40372
40373 /* for debugging */
40374 - atomic_long_t debug_tl_out_timer;
40375 - atomic_long_t debug_stop_polling;
40376 - atomic_long_t debug_eqbs_all;
40377 - atomic_long_t debug_eqbs_incomplete;
40378 - atomic_long_t debug_sqbs_all;
40379 - atomic_long_t debug_sqbs_incomplete;
40380 + atomic_long_unchecked_t debug_tl_out_timer;
40381 + atomic_long_unchecked_t debug_stop_polling;
40382 + atomic_long_unchecked_t debug_eqbs_all;
40383 + atomic_long_unchecked_t debug_eqbs_incomplete;
40384 + atomic_long_unchecked_t debug_sqbs_all;
40385 + atomic_long_unchecked_t debug_sqbs_incomplete;
40386 };
40387
40388 extern struct qdio_perf_stats perf_stats;
40389 extern int qdio_performance_stats;
40390
40391 -static inline void qdio_perf_stat_inc(atomic_long_t *count)
40392 +static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
40393 {
40394 if (qdio_performance_stats)
40395 - atomic_long_inc(count);
40396 + atomic_long_inc_unchecked(count);
40397 }
40398
40399 int qdio_setup_perf_stats(void);
40400 diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
40401 index 1ddcf40..a85f062 100644
40402 --- a/drivers/scsi/BusLogic.c
40403 +++ b/drivers/scsi/BusLogic.c
40404 @@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
40405 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
40406 *PrototypeHostAdapter)
40407 {
40408 + pax_track_stack();
40409 +
40410 /*
40411 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
40412 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
40413 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
40414 index cdbdec9..b7d560b 100644
40415 --- a/drivers/scsi/aacraid/aacraid.h
40416 +++ b/drivers/scsi/aacraid/aacraid.h
40417 @@ -471,7 +471,7 @@ struct adapter_ops
40418 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
40419 /* Administrative operations */
40420 int (*adapter_comm)(struct aac_dev * dev, int comm);
40421 -};
40422 +} __no_const;
40423
40424 /*
40425 * Define which interrupt handler needs to be installed
40426 diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
40427 index a5b8e7b..a6a0e43 100644
40428 --- a/drivers/scsi/aacraid/commctrl.c
40429 +++ b/drivers/scsi/aacraid/commctrl.c
40430 @@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
40431 u32 actual_fibsize64, actual_fibsize = 0;
40432 int i;
40433
40434 + pax_track_stack();
40435
40436 if (dev->in_reset) {
40437 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
40438 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
40439 index 9b97c3e..f099725 100644
40440 --- a/drivers/scsi/aacraid/linit.c
40441 +++ b/drivers/scsi/aacraid/linit.c
40442 @@ -91,7 +91,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
40443 #elif defined(__devinitconst)
40444 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40445 #else
40446 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
40447 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40448 #endif
40449 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
40450 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
40451 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
40452 index 996f722..9127845 100644
40453 --- a/drivers/scsi/aic94xx/aic94xx_init.c
40454 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
40455 @@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(struct device *dev,
40456 flash_error_table[i].reason);
40457 }
40458
40459 -static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
40460 +static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
40461 asd_show_update_bios, asd_store_update_bios);
40462
40463 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
40464 @@ -1011,7 +1011,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
40465 .lldd_control_phy = asd_control_phy,
40466 };
40467
40468 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
40469 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
40470 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
40471 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
40472 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
40473 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40474 index 58efd4b..cb48dc7 100644
40475 --- a/drivers/scsi/bfa/bfa_ioc.h
40476 +++ b/drivers/scsi/bfa/bfa_ioc.h
40477 @@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
40478 bfa_ioc_disable_cbfn_t disable_cbfn;
40479 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40480 bfa_ioc_reset_cbfn_t reset_cbfn;
40481 -};
40482 +} __no_const;
40483
40484 /**
40485 * Heartbeat failure notification queue element.
40486 diff --git a/drivers/scsi/bfa/bfa_iocfc.h b/drivers/scsi/bfa/bfa_iocfc.h
40487 index 7ad177e..5503586 100644
40488 --- a/drivers/scsi/bfa/bfa_iocfc.h
40489 +++ b/drivers/scsi/bfa/bfa_iocfc.h
40490 @@ -61,7 +61,7 @@ struct bfa_hwif_s {
40491 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
40492 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
40493 u32 *nvecs, u32 *maxvec);
40494 -};
40495 +} __no_const;
40496 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
40497
40498 struct bfa_iocfc_s {
40499 diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
40500 index 4967643..cbec06b 100644
40501 --- a/drivers/scsi/dpt_i2o.c
40502 +++ b/drivers/scsi/dpt_i2o.c
40503 @@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
40504 dma_addr_t addr;
40505 ulong flags = 0;
40506
40507 + pax_track_stack();
40508 +
40509 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
40510 // get user msg size in u32s
40511 if(get_user(size, &user_msg[0])){
40512 @@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
40513 s32 rcode;
40514 dma_addr_t addr;
40515
40516 + pax_track_stack();
40517 +
40518 memset(msg, 0 , sizeof(msg));
40519 len = scsi_bufflen(cmd);
40520 direction = 0x00000000;
40521 diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
40522 index c7076ce..e20c67c 100644
40523 --- a/drivers/scsi/eata.c
40524 +++ b/drivers/scsi/eata.c
40525 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
40526 struct hostdata *ha;
40527 char name[16];
40528
40529 + pax_track_stack();
40530 +
40531 sprintf(name, "%s%d", driver_name, j);
40532
40533 if (!request_region(port_base, REGION_SIZE, driver_name)) {
40534 diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
40535 index 11ae5c9..891daec 100644
40536 --- a/drivers/scsi/fcoe/libfcoe.c
40537 +++ b/drivers/scsi/fcoe/libfcoe.c
40538 @@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
40539 size_t rlen;
40540 size_t dlen;
40541
40542 + pax_track_stack();
40543 +
40544 fiph = (struct fip_header *)skb->data;
40545 sub = fiph->fip_subcode;
40546 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
40547 diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
40548 index 71c7bbe..e93088a 100644
40549 --- a/drivers/scsi/fnic/fnic_main.c
40550 +++ b/drivers/scsi/fnic/fnic_main.c
40551 @@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
40552 /* Start local port initiatialization */
40553
40554 lp->link_up = 0;
40555 - lp->tt = fnic_transport_template;
40556 + memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
40557
40558 lp->max_retry_count = fnic->config.flogi_retries;
40559 lp->max_rport_retry_count = fnic->config.plogi_retries;
40560 diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
40561 index bb96d74..9ec3ce4 100644
40562 --- a/drivers/scsi/gdth.c
40563 +++ b/drivers/scsi/gdth.c
40564 @@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
40565 ulong flags;
40566 gdth_ha_str *ha;
40567
40568 + pax_track_stack();
40569 +
40570 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
40571 return -EFAULT;
40572 ha = gdth_find_ha(ldrv.ionode);
40573 @@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
40574 gdth_ha_str *ha;
40575 int rval;
40576
40577 + pax_track_stack();
40578 +
40579 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
40580 res.number >= MAX_HDRIVES)
40581 return -EFAULT;
40582 @@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg, char *cmnd)
40583 gdth_ha_str *ha;
40584 int rval;
40585
40586 + pax_track_stack();
40587 +
40588 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
40589 return -EFAULT;
40590 ha = gdth_find_ha(gen.ionode);
40591 @@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
40592 int i;
40593 gdth_cmd_str gdtcmd;
40594 char cmnd[MAX_COMMAND_SIZE];
40595 +
40596 + pax_track_stack();
40597 +
40598 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
40599
40600 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
40601 diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
40602 index 1258da3..20d8ae6 100644
40603 --- a/drivers/scsi/gdth_proc.c
40604 +++ b/drivers/scsi/gdth_proc.c
40605 @@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
40606 ulong64 paddr;
40607
40608 char cmnd[MAX_COMMAND_SIZE];
40609 +
40610 + pax_track_stack();
40611 +
40612 memset(cmnd, 0xff, 12);
40613 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
40614
40615 @@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
40616 gdth_hget_str *phg;
40617 char cmnd[MAX_COMMAND_SIZE];
40618
40619 + pax_track_stack();
40620 +
40621 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
40622 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
40623 if (!gdtcmd || !estr)
40624 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40625 index d03a926..f324286 100644
40626 --- a/drivers/scsi/hosts.c
40627 +++ b/drivers/scsi/hosts.c
40628 @@ -40,7 +40,7 @@
40629 #include "scsi_logging.h"
40630
40631
40632 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
40633 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
40634
40635
40636 static void scsi_host_cls_release(struct device *dev)
40637 @@ -347,7 +347,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40638 * subtract one because we increment first then return, but we need to
40639 * know what the next host number was before increment
40640 */
40641 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40642 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40643 shost->dma_channel = 0xff;
40644
40645 /* These three are default values which can be overridden */
40646 diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
40647 index a601159..55e19d2 100644
40648 --- a/drivers/scsi/ipr.c
40649 +++ b/drivers/scsi/ipr.c
40650 @@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
40651 return true;
40652 }
40653
40654 -static struct ata_port_operations ipr_sata_ops = {
40655 +static const struct ata_port_operations ipr_sata_ops = {
40656 .phy_reset = ipr_ata_phy_reset,
40657 .hardreset = ipr_sata_reset,
40658 .post_internal_cmd = ipr_ata_post_internal,
40659 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
40660 index 4e49fbc..97907ff 100644
40661 --- a/drivers/scsi/ips.h
40662 +++ b/drivers/scsi/ips.h
40663 @@ -1027,7 +1027,7 @@ typedef struct {
40664 int (*intr)(struct ips_ha *);
40665 void (*enableint)(struct ips_ha *);
40666 uint32_t (*statupd)(struct ips_ha *);
40667 -} ips_hw_func_t;
40668 +} __no_const ips_hw_func_t;
40669
40670 typedef struct ips_ha {
40671 uint8_t ha_id[IPS_MAX_CHANNELS+1];
40672 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40673 index c1c1574..a9c9348 100644
40674 --- a/drivers/scsi/libfc/fc_exch.c
40675 +++ b/drivers/scsi/libfc/fc_exch.c
40676 @@ -86,12 +86,12 @@ struct fc_exch_mgr {
40677 * all together if not used XXX
40678 */
40679 struct {
40680 - atomic_t no_free_exch;
40681 - atomic_t no_free_exch_xid;
40682 - atomic_t xid_not_found;
40683 - atomic_t xid_busy;
40684 - atomic_t seq_not_found;
40685 - atomic_t non_bls_resp;
40686 + atomic_unchecked_t no_free_exch;
40687 + atomic_unchecked_t no_free_exch_xid;
40688 + atomic_unchecked_t xid_not_found;
40689 + atomic_unchecked_t xid_busy;
40690 + atomic_unchecked_t seq_not_found;
40691 + atomic_unchecked_t non_bls_resp;
40692 } stats;
40693 };
40694 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
40695 @@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40696 /* allocate memory for exchange */
40697 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40698 if (!ep) {
40699 - atomic_inc(&mp->stats.no_free_exch);
40700 + atomic_inc_unchecked(&mp->stats.no_free_exch);
40701 goto out;
40702 }
40703 memset(ep, 0, sizeof(*ep));
40704 @@ -557,7 +557,7 @@ out:
40705 return ep;
40706 err:
40707 spin_unlock_bh(&pool->lock);
40708 - atomic_inc(&mp->stats.no_free_exch_xid);
40709 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40710 mempool_free(ep, mp->ep_pool);
40711 return NULL;
40712 }
40713 @@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40714 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40715 ep = fc_exch_find(mp, xid);
40716 if (!ep) {
40717 - atomic_inc(&mp->stats.xid_not_found);
40718 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40719 reject = FC_RJT_OX_ID;
40720 goto out;
40721 }
40722 @@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40723 ep = fc_exch_find(mp, xid);
40724 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40725 if (ep) {
40726 - atomic_inc(&mp->stats.xid_busy);
40727 + atomic_inc_unchecked(&mp->stats.xid_busy);
40728 reject = FC_RJT_RX_ID;
40729 goto rel;
40730 }
40731 @@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40732 }
40733 xid = ep->xid; /* get our XID */
40734 } else if (!ep) {
40735 - atomic_inc(&mp->stats.xid_not_found);
40736 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40737 reject = FC_RJT_RX_ID; /* XID not found */
40738 goto out;
40739 }
40740 @@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40741 } else {
40742 sp = &ep->seq;
40743 if (sp->id != fh->fh_seq_id) {
40744 - atomic_inc(&mp->stats.seq_not_found);
40745 + atomic_inc_unchecked(&mp->stats.seq_not_found);
40746 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
40747 goto rel;
40748 }
40749 @@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40750
40751 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40752 if (!ep) {
40753 - atomic_inc(&mp->stats.xid_not_found);
40754 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40755 goto out;
40756 }
40757 if (ep->esb_stat & ESB_ST_COMPLETE) {
40758 - atomic_inc(&mp->stats.xid_not_found);
40759 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40760 goto out;
40761 }
40762 if (ep->rxid == FC_XID_UNKNOWN)
40763 ep->rxid = ntohs(fh->fh_rx_id);
40764 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40765 - atomic_inc(&mp->stats.xid_not_found);
40766 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40767 goto rel;
40768 }
40769 if (ep->did != ntoh24(fh->fh_s_id) &&
40770 ep->did != FC_FID_FLOGI) {
40771 - atomic_inc(&mp->stats.xid_not_found);
40772 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40773 goto rel;
40774 }
40775 sof = fr_sof(fp);
40776 @@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40777 } else {
40778 sp = &ep->seq;
40779 if (sp->id != fh->fh_seq_id) {
40780 - atomic_inc(&mp->stats.seq_not_found);
40781 + atomic_inc_unchecked(&mp->stats.seq_not_found);
40782 goto rel;
40783 }
40784 }
40785 @@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40786 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40787
40788 if (!sp)
40789 - atomic_inc(&mp->stats.xid_not_found);
40790 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40791 else
40792 - atomic_inc(&mp->stats.non_bls_resp);
40793 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
40794
40795 fc_frame_free(fp);
40796 }
40797 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40798 index 0ee989f..a582241 100644
40799 --- a/drivers/scsi/libsas/sas_ata.c
40800 +++ b/drivers/scsi/libsas/sas_ata.c
40801 @@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_link *link, unsigned int sc_reg_in,
40802 }
40803 }
40804
40805 -static struct ata_port_operations sas_sata_ops = {
40806 +static const struct ata_port_operations sas_sata_ops = {
40807 .phy_reset = sas_ata_phy_reset,
40808 .post_internal_cmd = sas_ata_post_internal,
40809 .qc_defer = ata_std_qc_defer,
40810 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40811 index aa10f79..5cc79e4 100644
40812 --- a/drivers/scsi/lpfc/lpfc.h
40813 +++ b/drivers/scsi/lpfc/lpfc.h
40814 @@ -400,7 +400,7 @@ struct lpfc_vport {
40815 struct dentry *debug_nodelist;
40816 struct dentry *vport_debugfs_root;
40817 struct lpfc_debugfs_trc *disc_trc;
40818 - atomic_t disc_trc_cnt;
40819 + atomic_unchecked_t disc_trc_cnt;
40820 #endif
40821 uint8_t stat_data_enabled;
40822 uint8_t stat_data_blocked;
40823 @@ -725,8 +725,8 @@ struct lpfc_hba {
40824 struct timer_list fabric_block_timer;
40825 unsigned long bit_flags;
40826 #define FABRIC_COMANDS_BLOCKED 0
40827 - atomic_t num_rsrc_err;
40828 - atomic_t num_cmd_success;
40829 + atomic_unchecked_t num_rsrc_err;
40830 + atomic_unchecked_t num_cmd_success;
40831 unsigned long last_rsrc_error_time;
40832 unsigned long last_ramp_down_time;
40833 unsigned long last_ramp_up_time;
40834 @@ -740,7 +740,7 @@ struct lpfc_hba {
40835 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
40836 struct dentry *debug_slow_ring_trc;
40837 struct lpfc_debugfs_trc *slow_ring_trc;
40838 - atomic_t slow_ring_trc_cnt;
40839 + atomic_unchecked_t slow_ring_trc_cnt;
40840 #endif
40841
40842 /* Used for deferred freeing of ELS data buffers */
40843 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
40844 index 8d0f0de..7c77a62 100644
40845 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
40846 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
40847 @@ -124,7 +124,7 @@ struct lpfc_debug {
40848 int len;
40849 };
40850
40851 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40852 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40853 static unsigned long lpfc_debugfs_start_time = 0L;
40854
40855 /**
40856 @@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
40857 lpfc_debugfs_enable = 0;
40858
40859 len = 0;
40860 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
40861 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
40862 (lpfc_debugfs_max_disc_trc - 1);
40863 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
40864 dtp = vport->disc_trc + i;
40865 @@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
40866 lpfc_debugfs_enable = 0;
40867
40868 len = 0;
40869 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
40870 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
40871 (lpfc_debugfs_max_slow_ring_trc - 1);
40872 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
40873 dtp = phba->slow_ring_trc + i;
40874 @@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
40875 uint32_t *ptr;
40876 char buffer[1024];
40877
40878 + pax_track_stack();
40879 +
40880 off = 0;
40881 spin_lock_irq(&phba->hbalock);
40882
40883 @@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
40884 !vport || !vport->disc_trc)
40885 return;
40886
40887 - index = atomic_inc_return(&vport->disc_trc_cnt) &
40888 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
40889 (lpfc_debugfs_max_disc_trc - 1);
40890 dtp = vport->disc_trc + index;
40891 dtp->fmt = fmt;
40892 dtp->data1 = data1;
40893 dtp->data2 = data2;
40894 dtp->data3 = data3;
40895 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40896 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40897 dtp->jif = jiffies;
40898 #endif
40899 return;
40900 @@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
40901 !phba || !phba->slow_ring_trc)
40902 return;
40903
40904 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
40905 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
40906 (lpfc_debugfs_max_slow_ring_trc - 1);
40907 dtp = phba->slow_ring_trc + index;
40908 dtp->fmt = fmt;
40909 dtp->data1 = data1;
40910 dtp->data2 = data2;
40911 dtp->data3 = data3;
40912 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40913 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40914 dtp->jif = jiffies;
40915 #endif
40916 return;
40917 @@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40918 "slow_ring buffer\n");
40919 goto debug_failed;
40920 }
40921 - atomic_set(&phba->slow_ring_trc_cnt, 0);
40922 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
40923 memset(phba->slow_ring_trc, 0,
40924 (sizeof(struct lpfc_debugfs_trc) *
40925 lpfc_debugfs_max_slow_ring_trc));
40926 @@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40927 "buffer\n");
40928 goto debug_failed;
40929 }
40930 - atomic_set(&vport->disc_trc_cnt, 0);
40931 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
40932
40933 snprintf(name, sizeof(name), "discovery_trace");
40934 vport->debug_disc_trc =
40935 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
40936 index 549bc7d..8189dbb 100644
40937 --- a/drivers/scsi/lpfc/lpfc_init.c
40938 +++ b/drivers/scsi/lpfc/lpfc_init.c
40939 @@ -8021,8 +8021,10 @@ lpfc_init(void)
40940 printk(LPFC_COPYRIGHT "\n");
40941
40942 if (lpfc_enable_npiv) {
40943 - lpfc_transport_functions.vport_create = lpfc_vport_create;
40944 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
40945 + pax_open_kernel();
40946 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
40947 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
40948 + pax_close_kernel();
40949 }
40950 lpfc_transport_template =
40951 fc_attach_transport(&lpfc_transport_functions);
40952 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
40953 index c88f59f..ff2a42f 100644
40954 --- a/drivers/scsi/lpfc/lpfc_scsi.c
40955 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
40956 @@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
40957 uint32_t evt_posted;
40958
40959 spin_lock_irqsave(&phba->hbalock, flags);
40960 - atomic_inc(&phba->num_rsrc_err);
40961 + atomic_inc_unchecked(&phba->num_rsrc_err);
40962 phba->last_rsrc_error_time = jiffies;
40963
40964 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
40965 @@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
40966 unsigned long flags;
40967 struct lpfc_hba *phba = vport->phba;
40968 uint32_t evt_posted;
40969 - atomic_inc(&phba->num_cmd_success);
40970 + atomic_inc_unchecked(&phba->num_cmd_success);
40971
40972 if (vport->cfg_lun_queue_depth <= queue_depth)
40973 return;
40974 @@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
40975 int i;
40976 struct lpfc_rport_data *rdata;
40977
40978 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
40979 - num_cmd_success = atomic_read(&phba->num_cmd_success);
40980 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
40981 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
40982
40983 vports = lpfc_create_vport_work_array(phba);
40984 if (vports != NULL)
40985 @@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
40986 }
40987 }
40988 lpfc_destroy_vport_work_array(phba, vports);
40989 - atomic_set(&phba->num_rsrc_err, 0);
40990 - atomic_set(&phba->num_cmd_success, 0);
40991 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
40992 + atomic_set_unchecked(&phba->num_cmd_success, 0);
40993 }
40994
40995 /**
40996 @@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
40997 }
40998 }
40999 lpfc_destroy_vport_work_array(phba, vports);
41000 - atomic_set(&phba->num_rsrc_err, 0);
41001 - atomic_set(&phba->num_cmd_success, 0);
41002 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41003 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41004 }
41005
41006 /**
41007 diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
41008 index 234f0b7..3020aea 100644
41009 --- a/drivers/scsi/megaraid/megaraid_mbox.c
41010 +++ b/drivers/scsi/megaraid/megaraid_mbox.c
41011 @@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
41012 int rval;
41013 int i;
41014
41015 + pax_track_stack();
41016 +
41017 // Allocate memory for the base list of scb for management module.
41018 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
41019
41020 diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
41021 index 7a117c1..ee01e9e 100644
41022 --- a/drivers/scsi/osd/osd_initiator.c
41023 +++ b/drivers/scsi/osd/osd_initiator.c
41024 @@ -94,6 +94,8 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
41025 int nelem = ARRAY_SIZE(get_attrs), a = 0;
41026 int ret;
41027
41028 + pax_track_stack();
41029 +
41030 or = osd_start_request(od, GFP_KERNEL);
41031 if (!or)
41032 return -ENOMEM;
41033 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41034 index 9ab8c86..9425ad3 100644
41035 --- a/drivers/scsi/pmcraid.c
41036 +++ b/drivers/scsi/pmcraid.c
41037 @@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41038 res->scsi_dev = scsi_dev;
41039 scsi_dev->hostdata = res;
41040 res->change_detected = 0;
41041 - atomic_set(&res->read_failures, 0);
41042 - atomic_set(&res->write_failures, 0);
41043 + atomic_set_unchecked(&res->read_failures, 0);
41044 + atomic_set_unchecked(&res->write_failures, 0);
41045 rc = 0;
41046 }
41047 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41048 @@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41049
41050 /* If this was a SCSI read/write command keep count of errors */
41051 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41052 - atomic_inc(&res->read_failures);
41053 + atomic_inc_unchecked(&res->read_failures);
41054 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41055 - atomic_inc(&res->write_failures);
41056 + atomic_inc_unchecked(&res->write_failures);
41057
41058 if (!RES_IS_GSCSI(res->cfg_entry) &&
41059 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41060 @@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41061
41062 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41063 /* add resources only after host is added into system */
41064 - if (!atomic_read(&pinstance->expose_resources))
41065 + if (!atomic_read_unchecked(&pinstance->expose_resources))
41066 return;
41067
41068 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
41069 @@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instance(
41070 init_waitqueue_head(&pinstance->reset_wait_q);
41071
41072 atomic_set(&pinstance->outstanding_cmds, 0);
41073 - atomic_set(&pinstance->expose_resources, 0);
41074 + atomic_set_unchecked(&pinstance->expose_resources, 0);
41075
41076 INIT_LIST_HEAD(&pinstance->free_res_q);
41077 INIT_LIST_HEAD(&pinstance->used_res_q);
41078 @@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
41079 /* Schedule worker thread to handle CCN and take care of adding and
41080 * removing devices to OS
41081 */
41082 - atomic_set(&pinstance->expose_resources, 1);
41083 + atomic_set_unchecked(&pinstance->expose_resources, 1);
41084 schedule_work(&pinstance->worker_q);
41085 return rc;
41086
41087 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41088 index 3441b3f..6cbe8f7 100644
41089 --- a/drivers/scsi/pmcraid.h
41090 +++ b/drivers/scsi/pmcraid.h
41091 @@ -690,7 +690,7 @@ struct pmcraid_instance {
41092 atomic_t outstanding_cmds;
41093
41094 /* should add/delete resources to mid-layer now ?*/
41095 - atomic_t expose_resources;
41096 + atomic_unchecked_t expose_resources;
41097
41098 /* Tasklet to handle deferred processing */
41099 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
41100 @@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
41101 struct list_head queue; /* link to "to be exposed" resources */
41102 struct pmcraid_config_table_entry cfg_entry;
41103 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41104 - atomic_t read_failures; /* count of failed READ commands */
41105 - atomic_t write_failures; /* count of failed WRITE commands */
41106 + atomic_unchecked_t read_failures; /* count of failed READ commands */
41107 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41108
41109 /* To indicate add/delete/modify during CCN */
41110 u8 change_detected;
41111 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
41112 index 2150618..7034215 100644
41113 --- a/drivers/scsi/qla2xxx/qla_def.h
41114 +++ b/drivers/scsi/qla2xxx/qla_def.h
41115 @@ -2089,7 +2089,7 @@ struct isp_operations {
41116
41117 int (*get_flash_version) (struct scsi_qla_host *, void *);
41118 int (*start_scsi) (srb_t *);
41119 -};
41120 +} __no_const;
41121
41122 /* MSI-X Support *************************************************************/
41123
41124 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41125 index 81b5f29..2ae1fad 100644
41126 --- a/drivers/scsi/qla4xxx/ql4_def.h
41127 +++ b/drivers/scsi/qla4xxx/ql4_def.h
41128 @@ -240,7 +240,7 @@ struct ddb_entry {
41129 atomic_t retry_relogin_timer; /* Min Time between relogins
41130 * (4000 only) */
41131 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
41132 - atomic_t relogin_retry_count; /* Num of times relogin has been
41133 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41134 * retried */
41135
41136 uint16_t port;
41137 diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
41138 index af8c323..515dd51 100644
41139 --- a/drivers/scsi/qla4xxx/ql4_init.c
41140 +++ b/drivers/scsi/qla4xxx/ql4_init.c
41141 @@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
41142 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
41143 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41144 atomic_set(&ddb_entry->relogin_timer, 0);
41145 - atomic_set(&ddb_entry->relogin_retry_count, 0);
41146 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41147 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41148 list_add_tail(&ddb_entry->list, &ha->ddb_list);
41149 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
41150 @@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
41151 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41152 atomic_set(&ddb_entry->port_down_timer,
41153 ha->port_down_retry_count);
41154 - atomic_set(&ddb_entry->relogin_retry_count, 0);
41155 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41156 atomic_set(&ddb_entry->relogin_timer, 0);
41157 clear_bit(DF_RELOGIN, &ddb_entry->flags);
41158 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
41159 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41160 index 83c8b5e..a82b348 100644
41161 --- a/drivers/scsi/qla4xxx/ql4_os.c
41162 +++ b/drivers/scsi/qla4xxx/ql4_os.c
41163 @@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
41164 ddb_entry->fw_ddb_device_state ==
41165 DDB_DS_SESSION_FAILED) {
41166 /* Reset retry relogin timer */
41167 - atomic_inc(&ddb_entry->relogin_retry_count);
41168 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41169 DEBUG2(printk("scsi%ld: index[%d] relogin"
41170 " timed out-retrying"
41171 " relogin (%d)\n",
41172 ha->host_no,
41173 ddb_entry->fw_ddb_index,
41174 - atomic_read(&ddb_entry->
41175 + atomic_read_unchecked(&ddb_entry->
41176 relogin_retry_count))
41177 );
41178 start_dpc++;
41179 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41180 index dd098ca..686ce01 100644
41181 --- a/drivers/scsi/scsi.c
41182 +++ b/drivers/scsi/scsi.c
41183 @@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41184 unsigned long timeout;
41185 int rtn = 0;
41186
41187 - atomic_inc(&cmd->device->iorequest_cnt);
41188 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41189
41190 /* check if the device is still usable */
41191 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41192 diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
41193 index bc3e363..e1a8e50 100644
41194 --- a/drivers/scsi/scsi_debug.c
41195 +++ b/drivers/scsi/scsi_debug.c
41196 @@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
41197 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
41198 unsigned char *cmd = (unsigned char *)scp->cmnd;
41199
41200 + pax_track_stack();
41201 +
41202 if ((errsts = check_readiness(scp, 1, devip)))
41203 return errsts;
41204 memset(arr, 0, sizeof(arr));
41205 @@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
41206 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
41207 unsigned char *cmd = (unsigned char *)scp->cmnd;
41208
41209 + pax_track_stack();
41210 +
41211 if ((errsts = check_readiness(scp, 1, devip)))
41212 return errsts;
41213 memset(arr, 0, sizeof(arr));
41214 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41215 index 8df12522..c4c1472 100644
41216 --- a/drivers/scsi/scsi_lib.c
41217 +++ b/drivers/scsi/scsi_lib.c
41218 @@ -1389,7 +1389,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41219 shost = sdev->host;
41220 scsi_init_cmd_errh(cmd);
41221 cmd->result = DID_NO_CONNECT << 16;
41222 - atomic_inc(&cmd->device->iorequest_cnt);
41223 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41224
41225 /*
41226 * SCSI request completion path will do scsi_device_unbusy(),
41227 @@ -1420,9 +1420,9 @@ static void scsi_softirq_done(struct request *rq)
41228 */
41229 cmd->serial_number = 0;
41230
41231 - atomic_inc(&cmd->device->iodone_cnt);
41232 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
41233 if (cmd->result)
41234 - atomic_inc(&cmd->device->ioerr_cnt);
41235 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41236
41237 disposition = scsi_decide_disposition(cmd);
41238 if (disposition != SUCCESS &&
41239 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41240 index 91a93e0..eae0fe3 100644
41241 --- a/drivers/scsi/scsi_sysfs.c
41242 +++ b/drivers/scsi/scsi_sysfs.c
41243 @@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41244 char *buf) \
41245 { \
41246 struct scsi_device *sdev = to_scsi_device(dev); \
41247 - unsigned long long count = atomic_read(&sdev->field); \
41248 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
41249 return snprintf(buf, 20, "0x%llx\n", count); \
41250 } \
41251 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41252 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41253 index 1030327..f91fd30 100644
41254 --- a/drivers/scsi/scsi_tgt_lib.c
41255 +++ b/drivers/scsi/scsi_tgt_lib.c
41256 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41257 int err;
41258
41259 dprintk("%lx %u\n", uaddr, len);
41260 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41261 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41262 if (err) {
41263 /*
41264 * TODO: need to fixup sg_tablesize, max_segment_size,
41265 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41266 index db02e31..1b42ea9 100644
41267 --- a/drivers/scsi/scsi_transport_fc.c
41268 +++ b/drivers/scsi/scsi_transport_fc.c
41269 @@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
41270 * Netlink Infrastructure
41271 */
41272
41273 -static atomic_t fc_event_seq;
41274 +static atomic_unchecked_t fc_event_seq;
41275
41276 /**
41277 * fc_get_event_number - Obtain the next sequential FC event number
41278 @@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
41279 u32
41280 fc_get_event_number(void)
41281 {
41282 - return atomic_add_return(1, &fc_event_seq);
41283 + return atomic_add_return_unchecked(1, &fc_event_seq);
41284 }
41285 EXPORT_SYMBOL(fc_get_event_number);
41286
41287 @@ -641,7 +641,7 @@ static __init int fc_transport_init(void)
41288 {
41289 int error;
41290
41291 - atomic_set(&fc_event_seq, 0);
41292 + atomic_set_unchecked(&fc_event_seq, 0);
41293
41294 error = transport_class_register(&fc_host_class);
41295 if (error)
41296 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41297 index de2f8c4..63c5278 100644
41298 --- a/drivers/scsi/scsi_transport_iscsi.c
41299 +++ b/drivers/scsi/scsi_transport_iscsi.c
41300 @@ -81,7 +81,7 @@ struct iscsi_internal {
41301 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
41302 };
41303
41304 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41305 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41306 static struct workqueue_struct *iscsi_eh_timer_workq;
41307
41308 /*
41309 @@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41310 int err;
41311
41312 ihost = shost->shost_data;
41313 - session->sid = atomic_add_return(1, &iscsi_session_nr);
41314 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41315
41316 if (id == ISCSI_MAX_TARGET) {
41317 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
41318 @@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(void)
41319 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41320 ISCSI_TRANSPORT_VERSION);
41321
41322 - atomic_set(&iscsi_session_nr, 0);
41323 + atomic_set_unchecked(&iscsi_session_nr, 0);
41324
41325 err = class_register(&iscsi_transport_class);
41326 if (err)
41327 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41328 index 21a045e..ec89e03 100644
41329 --- a/drivers/scsi/scsi_transport_srp.c
41330 +++ b/drivers/scsi/scsi_transport_srp.c
41331 @@ -33,7 +33,7 @@
41332 #include "scsi_transport_srp_internal.h"
41333
41334 struct srp_host_attrs {
41335 - atomic_t next_port_id;
41336 + atomic_unchecked_t next_port_id;
41337 };
41338 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41339
41340 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41341 struct Scsi_Host *shost = dev_to_shost(dev);
41342 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41343
41344 - atomic_set(&srp_host->next_port_id, 0);
41345 + atomic_set_unchecked(&srp_host->next_port_id, 0);
41346 return 0;
41347 }
41348
41349 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41350 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41351 rport->roles = ids->roles;
41352
41353 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41354 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41355 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41356
41357 transport_setup_device(&rport->dev);
41358 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41359 index 040f751..98a5ed2 100644
41360 --- a/drivers/scsi/sg.c
41361 +++ b/drivers/scsi/sg.c
41362 @@ -1064,7 +1064,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
41363 sdp->disk->disk_name,
41364 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41365 NULL,
41366 - (char *)arg);
41367 + (char __user *)arg);
41368 case BLKTRACESTART:
41369 return blk_trace_startstop(sdp->device->request_queue, 1);
41370 case BLKTRACESTOP:
41371 @@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
41372 const struct file_operations * fops;
41373 };
41374
41375 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
41376 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
41377 {"allow_dio", &adio_fops},
41378 {"debug", &debug_fops},
41379 {"def_reserved_size", &dressz_fops},
41380 @@ -2307,7 +2307,7 @@ sg_proc_init(void)
41381 {
41382 int k, mask;
41383 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
41384 - struct sg_proc_leaf * leaf;
41385 + const struct sg_proc_leaf * leaf;
41386
41387 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
41388 if (!sg_proc_sgp)
41389 diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
41390 index 45374d6..61ee484 100644
41391 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c
41392 +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
41393 @@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
41394 int do_iounmap = 0;
41395 int do_disable_device = 1;
41396
41397 + pax_track_stack();
41398 +
41399 memset(&sym_dev, 0, sizeof(sym_dev));
41400 memset(&nvram, 0, sizeof(nvram));
41401 sym_dev.pdev = pdev;
41402 diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
41403 index eadc1ab..2d81457 100644
41404 --- a/drivers/serial/kgdboc.c
41405 +++ b/drivers/serial/kgdboc.c
41406 @@ -18,7 +18,7 @@
41407
41408 #define MAX_CONFIG_LEN 40
41409
41410 -static struct kgdb_io kgdboc_io_ops;
41411 +static const struct kgdb_io kgdboc_io_ops;
41412
41413 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41414 static int configured = -1;
41415 @@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void)
41416 module_put(THIS_MODULE);
41417 }
41418
41419 -static struct kgdb_io kgdboc_io_ops = {
41420 +static const struct kgdb_io kgdboc_io_ops = {
41421 .name = "kgdboc",
41422 .read_char = kgdboc_get_char,
41423 .write_char = kgdboc_put_char,
41424 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41425 index b76f246..7f41af7 100644
41426 --- a/drivers/spi/spi.c
41427 +++ b/drivers/spi/spi.c
41428 @@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
41429 EXPORT_SYMBOL_GPL(spi_sync);
41430
41431 /* portable code must never pass more than 32 bytes */
41432 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41433 +#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
41434
41435 static u8 *buf;
41436
41437 diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
41438 index 99010d4..6bad87b 100644
41439 --- a/drivers/staging/android/binder.c
41440 +++ b/drivers/staging/android/binder.c
41441 @@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_area_struct *vma)
41442 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
41443 }
41444
41445 -static struct vm_operations_struct binder_vm_ops = {
41446 +static const struct vm_operations_struct binder_vm_ops = {
41447 .open = binder_vma_open,
41448 .close = binder_vma_close,
41449 };
41450 diff --git a/drivers/staging/b3dfg/b3dfg.c b/drivers/staging/b3dfg/b3dfg.c
41451 index cda26bb..39fed3f 100644
41452 --- a/drivers/staging/b3dfg/b3dfg.c
41453 +++ b/drivers/staging/b3dfg/b3dfg.c
41454 @@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_area_struct *vma,
41455 return VM_FAULT_NOPAGE;
41456 }
41457
41458 -static struct vm_operations_struct b3dfg_vm_ops = {
41459 +static const struct vm_operations_struct b3dfg_vm_ops = {
41460 .fault = b3dfg_vma_fault,
41461 };
41462
41463 @@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp, struct vm_area_struct *vma)
41464 return r;
41465 }
41466
41467 -static struct file_operations b3dfg_fops = {
41468 +static const struct file_operations b3dfg_fops = {
41469 .owner = THIS_MODULE,
41470 .open = b3dfg_open,
41471 .release = b3dfg_release,
41472 diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
41473 index 908f25a..c9a579b 100644
41474 --- a/drivers/staging/comedi/comedi_fops.c
41475 +++ b/drivers/staging/comedi/comedi_fops.c
41476 @@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct *area)
41477 mutex_unlock(&dev->mutex);
41478 }
41479
41480 -static struct vm_operations_struct comedi_vm_ops = {
41481 +static const struct vm_operations_struct comedi_vm_ops = {
41482 .close = comedi_unmap,
41483 };
41484
41485 diff --git a/drivers/staging/dream/qdsp5/adsp_driver.c b/drivers/staging/dream/qdsp5/adsp_driver.c
41486 index e55a0db..577b776 100644
41487 --- a/drivers/staging/dream/qdsp5/adsp_driver.c
41488 +++ b/drivers/staging/dream/qdsp5/adsp_driver.c
41489 @@ -576,7 +576,7 @@ static struct adsp_device *inode_to_device(struct inode *inode)
41490 static dev_t adsp_devno;
41491 static struct class *adsp_class;
41492
41493 -static struct file_operations adsp_fops = {
41494 +static const struct file_operations adsp_fops = {
41495 .owner = THIS_MODULE,
41496 .open = adsp_open,
41497 .unlocked_ioctl = adsp_ioctl,
41498 diff --git a/drivers/staging/dream/qdsp5/audio_aac.c b/drivers/staging/dream/qdsp5/audio_aac.c
41499 index ad2390f..4116ee8 100644
41500 --- a/drivers/staging/dream/qdsp5/audio_aac.c
41501 +++ b/drivers/staging/dream/qdsp5/audio_aac.c
41502 @@ -1022,7 +1022,7 @@ done:
41503 return rc;
41504 }
41505
41506 -static struct file_operations audio_aac_fops = {
41507 +static const struct file_operations audio_aac_fops = {
41508 .owner = THIS_MODULE,
41509 .open = audio_open,
41510 .release = audio_release,
41511 diff --git a/drivers/staging/dream/qdsp5/audio_amrnb.c b/drivers/staging/dream/qdsp5/audio_amrnb.c
41512 index cd818a5..870b37b 100644
41513 --- a/drivers/staging/dream/qdsp5/audio_amrnb.c
41514 +++ b/drivers/staging/dream/qdsp5/audio_amrnb.c
41515 @@ -833,7 +833,7 @@ done:
41516 return rc;
41517 }
41518
41519 -static struct file_operations audio_amrnb_fops = {
41520 +static const struct file_operations audio_amrnb_fops = {
41521 .owner = THIS_MODULE,
41522 .open = audamrnb_open,
41523 .release = audamrnb_release,
41524 diff --git a/drivers/staging/dream/qdsp5/audio_evrc.c b/drivers/staging/dream/qdsp5/audio_evrc.c
41525 index 4b43e18..cedafda 100644
41526 --- a/drivers/staging/dream/qdsp5/audio_evrc.c
41527 +++ b/drivers/staging/dream/qdsp5/audio_evrc.c
41528 @@ -805,7 +805,7 @@ dma_fail:
41529 return rc;
41530 }
41531
41532 -static struct file_operations audio_evrc_fops = {
41533 +static const struct file_operations audio_evrc_fops = {
41534 .owner = THIS_MODULE,
41535 .open = audevrc_open,
41536 .release = audevrc_release,
41537 diff --git a/drivers/staging/dream/qdsp5/audio_in.c b/drivers/staging/dream/qdsp5/audio_in.c
41538 index 3d950a2..9431118 100644
41539 --- a/drivers/staging/dream/qdsp5/audio_in.c
41540 +++ b/drivers/staging/dream/qdsp5/audio_in.c
41541 @@ -913,7 +913,7 @@ static int audpre_open(struct inode *inode, struct file *file)
41542 return 0;
41543 }
41544
41545 -static struct file_operations audio_fops = {
41546 +static const struct file_operations audio_fops = {
41547 .owner = THIS_MODULE,
41548 .open = audio_in_open,
41549 .release = audio_in_release,
41550 @@ -922,7 +922,7 @@ static struct file_operations audio_fops = {
41551 .unlocked_ioctl = audio_in_ioctl,
41552 };
41553
41554 -static struct file_operations audpre_fops = {
41555 +static const struct file_operations audpre_fops = {
41556 .owner = THIS_MODULE,
41557 .open = audpre_open,
41558 .unlocked_ioctl = audpre_ioctl,
41559 diff --git a/drivers/staging/dream/qdsp5/audio_mp3.c b/drivers/staging/dream/qdsp5/audio_mp3.c
41560 index b95574f..286c2f4 100644
41561 --- a/drivers/staging/dream/qdsp5/audio_mp3.c
41562 +++ b/drivers/staging/dream/qdsp5/audio_mp3.c
41563 @@ -941,7 +941,7 @@ done:
41564 return rc;
41565 }
41566
41567 -static struct file_operations audio_mp3_fops = {
41568 +static const struct file_operations audio_mp3_fops = {
41569 .owner = THIS_MODULE,
41570 .open = audio_open,
41571 .release = audio_release,
41572 diff --git a/drivers/staging/dream/qdsp5/audio_out.c b/drivers/staging/dream/qdsp5/audio_out.c
41573 index d1adcf6..f8f9833 100644
41574 --- a/drivers/staging/dream/qdsp5/audio_out.c
41575 +++ b/drivers/staging/dream/qdsp5/audio_out.c
41576 @@ -810,7 +810,7 @@ static int audpp_open(struct inode *inode, struct file *file)
41577 return 0;
41578 }
41579
41580 -static struct file_operations audio_fops = {
41581 +static const struct file_operations audio_fops = {
41582 .owner = THIS_MODULE,
41583 .open = audio_open,
41584 .release = audio_release,
41585 @@ -819,7 +819,7 @@ static struct file_operations audio_fops = {
41586 .unlocked_ioctl = audio_ioctl,
41587 };
41588
41589 -static struct file_operations audpp_fops = {
41590 +static const struct file_operations audpp_fops = {
41591 .owner = THIS_MODULE,
41592 .open = audpp_open,
41593 .unlocked_ioctl = audpp_ioctl,
41594 diff --git a/drivers/staging/dream/qdsp5/audio_qcelp.c b/drivers/staging/dream/qdsp5/audio_qcelp.c
41595 index f0f50e3..f6b9dbc 100644
41596 --- a/drivers/staging/dream/qdsp5/audio_qcelp.c
41597 +++ b/drivers/staging/dream/qdsp5/audio_qcelp.c
41598 @@ -816,7 +816,7 @@ err:
41599 return rc;
41600 }
41601
41602 -static struct file_operations audio_qcelp_fops = {
41603 +static const struct file_operations audio_qcelp_fops = {
41604 .owner = THIS_MODULE,
41605 .open = audqcelp_open,
41606 .release = audqcelp_release,
41607 diff --git a/drivers/staging/dream/qdsp5/snd.c b/drivers/staging/dream/qdsp5/snd.c
41608 index 037d7ff..5469ec3 100644
41609 --- a/drivers/staging/dream/qdsp5/snd.c
41610 +++ b/drivers/staging/dream/qdsp5/snd.c
41611 @@ -242,7 +242,7 @@ err:
41612 return rc;
41613 }
41614
41615 -static struct file_operations snd_fops = {
41616 +static const struct file_operations snd_fops = {
41617 .owner = THIS_MODULE,
41618 .open = snd_open,
41619 .release = snd_release,
41620 diff --git a/drivers/staging/dream/smd/smd_qmi.c b/drivers/staging/dream/smd/smd_qmi.c
41621 index d4e7d88..0ea632a 100644
41622 --- a/drivers/staging/dream/smd/smd_qmi.c
41623 +++ b/drivers/staging/dream/smd/smd_qmi.c
41624 @@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip, struct file *fp)
41625 return 0;
41626 }
41627
41628 -static struct file_operations qmi_fops = {
41629 +static const struct file_operations qmi_fops = {
41630 .owner = THIS_MODULE,
41631 .read = qmi_read,
41632 .write = qmi_write,
41633 diff --git a/drivers/staging/dream/smd/smd_rpcrouter_device.c b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41634 index cd3910b..ff053d3 100644
41635 --- a/drivers/staging/dream/smd/smd_rpcrouter_device.c
41636 +++ b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41637 @@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file *filp, unsigned int cmd,
41638 return rc;
41639 }
41640
41641 -static struct file_operations rpcrouter_server_fops = {
41642 +static const struct file_operations rpcrouter_server_fops = {
41643 .owner = THIS_MODULE,
41644 .open = rpcrouter_open,
41645 .release = rpcrouter_release,
41646 @@ -224,7 +224,7 @@ static struct file_operations rpcrouter_server_fops = {
41647 .unlocked_ioctl = rpcrouter_ioctl,
41648 };
41649
41650 -static struct file_operations rpcrouter_router_fops = {
41651 +static const struct file_operations rpcrouter_router_fops = {
41652 .owner = THIS_MODULE,
41653 .open = rpcrouter_open,
41654 .release = rpcrouter_release,
41655 diff --git a/drivers/staging/dst/dcore.c b/drivers/staging/dst/dcore.c
41656 index c24e4e0..07665be 100644
41657 --- a/drivers/staging/dst/dcore.c
41658 +++ b/drivers/staging/dst/dcore.c
41659 @@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendisk *disk, fmode_t mode)
41660 return 0;
41661 }
41662
41663 -static struct block_device_operations dst_blk_ops = {
41664 +static const struct block_device_operations dst_blk_ops = {
41665 .open = dst_bdev_open,
41666 .release = dst_bdev_release,
41667 .owner = THIS_MODULE,
41668 @@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(struct dst_ctl *ctl,
41669 n->size = ctl->size;
41670
41671 atomic_set(&n->refcnt, 1);
41672 - atomic_long_set(&n->gen, 0);
41673 + atomic_long_set_unchecked(&n->gen, 0);
41674 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
41675
41676 err = dst_node_sysfs_init(n);
41677 diff --git a/drivers/staging/dst/trans.c b/drivers/staging/dst/trans.c
41678 index 557d372..8d84422 100644
41679 --- a/drivers/staging/dst/trans.c
41680 +++ b/drivers/staging/dst/trans.c
41681 @@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n, struct bio *bio)
41682 t->error = 0;
41683 t->retries = 0;
41684 atomic_set(&t->refcnt, 1);
41685 - t->gen = atomic_long_inc_return(&n->gen);
41686 + t->gen = atomic_long_inc_return_unchecked(&n->gen);
41687
41688 t->enc = bio_data_dir(bio);
41689 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
41690 diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
41691 index 94f7752..d051514 100644
41692 --- a/drivers/staging/et131x/et1310_tx.c
41693 +++ b/drivers/staging/et131x/et1310_tx.c
41694 @@ -710,11 +710,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
41695 struct net_device_stats *stats = &etdev->net_stats;
41696
41697 if (pMpTcb->Flags & fMP_DEST_BROAD)
41698 - atomic_inc(&etdev->Stats.brdcstxmt);
41699 + atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
41700 else if (pMpTcb->Flags & fMP_DEST_MULTI)
41701 - atomic_inc(&etdev->Stats.multixmt);
41702 + atomic_inc_unchecked(&etdev->Stats.multixmt);
41703 else
41704 - atomic_inc(&etdev->Stats.unixmt);
41705 + atomic_inc_unchecked(&etdev->Stats.unixmt);
41706
41707 if (pMpTcb->Packet) {
41708 stats->tx_bytes += pMpTcb->Packet->len;
41709 diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
41710 index 1dfe06f..f469b4d 100644
41711 --- a/drivers/staging/et131x/et131x_adapter.h
41712 +++ b/drivers/staging/et131x/et131x_adapter.h
41713 @@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
41714 * operations
41715 */
41716 u32 unircv; /* # multicast packets received */
41717 - atomic_t unixmt; /* # multicast packets for Tx */
41718 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
41719 u32 multircv; /* # multicast packets received */
41720 - atomic_t multixmt; /* # multicast packets for Tx */
41721 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
41722 u32 brdcstrcv; /* # broadcast packets received */
41723 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
41724 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
41725 u32 norcvbuf; /* # Rx packets discarded */
41726 u32 noxmtbuf; /* # Tx packets discarded */
41727
41728 diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/go7007/go7007-v4l2.c
41729 index 4bd353a..e28f455 100644
41730 --- a/drivers/staging/go7007/go7007-v4l2.c
41731 +++ b/drivers/staging/go7007/go7007-v4l2.c
41732 @@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41733 return 0;
41734 }
41735
41736 -static struct vm_operations_struct go7007_vm_ops = {
41737 +static const struct vm_operations_struct go7007_vm_ops = {
41738 .open = go7007_vm_open,
41739 .close = go7007_vm_close,
41740 .fault = go7007_vm_fault,
41741 diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
41742 index 366dc95..b974d87 100644
41743 --- a/drivers/staging/hv/Channel.c
41744 +++ b/drivers/staging/hv/Channel.c
41745 @@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
41746
41747 DPRINT_ENTER(VMBUS);
41748
41749 - nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
41750 - atomic_inc(&gVmbusConnection.NextGpadlHandle);
41751 + nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
41752 + atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
41753
41754 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
41755 ASSERT(msgInfo != NULL);
41756 diff --git a/drivers/staging/hv/Hv.c b/drivers/staging/hv/Hv.c
41757 index b12237f..01ae28a 100644
41758 --- a/drivers/staging/hv/Hv.c
41759 +++ b/drivers/staging/hv/Hv.c
41760 @@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, void *Input, void *Output)
41761 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
41762 u32 outputAddressHi = outputAddress >> 32;
41763 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
41764 - volatile void *hypercallPage = gHvContext.HypercallPage;
41765 + volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
41766
41767 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
41768 Control, Input, Output);
41769 diff --git a/drivers/staging/hv/VmbusApi.h b/drivers/staging/hv/VmbusApi.h
41770 index d089bb1..2ebc158 100644
41771 --- a/drivers/staging/hv/VmbusApi.h
41772 +++ b/drivers/staging/hv/VmbusApi.h
41773 @@ -109,7 +109,7 @@ struct vmbus_channel_interface {
41774 u32 *GpadlHandle);
41775 int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle);
41776 void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo);
41777 -};
41778 +} __no_const;
41779
41780 /* Base driver object */
41781 struct hv_driver {
41782 diff --git a/drivers/staging/hv/VmbusPrivate.h b/drivers/staging/hv/VmbusPrivate.h
41783 index 5a37cce..6ecc88c 100644
41784 --- a/drivers/staging/hv/VmbusPrivate.h
41785 +++ b/drivers/staging/hv/VmbusPrivate.h
41786 @@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
41787 struct VMBUS_CONNECTION {
41788 enum VMBUS_CONNECT_STATE ConnectState;
41789
41790 - atomic_t NextGpadlHandle;
41791 + atomic_unchecked_t NextGpadlHandle;
41792
41793 /*
41794 * Represents channel interrupts. Each bit position represents a
41795 diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
41796 index 871a202..ca50ddf 100644
41797 --- a/drivers/staging/hv/blkvsc_drv.c
41798 +++ b/drivers/staging/hv/blkvsc_drv.c
41799 @@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
41800 /* The one and only one */
41801 static struct blkvsc_driver_context g_blkvsc_drv;
41802
41803 -static struct block_device_operations block_ops = {
41804 +static const struct block_device_operations block_ops = {
41805 .owner = THIS_MODULE,
41806 .open = blkvsc_open,
41807 .release = blkvsc_release,
41808 diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
41809 index 6acc49a..fbc8d46 100644
41810 --- a/drivers/staging/hv/vmbus_drv.c
41811 +++ b/drivers/staging/hv/vmbus_drv.c
41812 @@ -532,7 +532,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41813 to_device_context(root_device_obj);
41814 struct device_context *child_device_ctx =
41815 to_device_context(child_device_obj);
41816 - static atomic_t device_num = ATOMIC_INIT(0);
41817 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41818
41819 DPRINT_ENTER(VMBUS_DRV);
41820
41821 @@ -541,7 +541,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41822
41823 /* Set the device name. Otherwise, device_register() will fail. */
41824 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
41825 - atomic_inc_return(&device_num));
41826 + atomic_inc_return_unchecked(&device_num));
41827
41828 /* The new device belongs to this bus */
41829 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
41830 diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
41831 index d926189..17b19fd 100644
41832 --- a/drivers/staging/iio/ring_generic.h
41833 +++ b/drivers/staging/iio/ring_generic.h
41834 @@ -87,7 +87,7 @@ struct iio_ring_access_funcs {
41835
41836 int (*is_enabled)(struct iio_ring_buffer *ring);
41837 int (*enable)(struct iio_ring_buffer *ring);
41838 -};
41839 +} __no_const;
41840
41841 /**
41842 * struct iio_ring_buffer - general ring buffer structure
41843 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41844 index 1b237b7..88c624e 100644
41845 --- a/drivers/staging/octeon/ethernet-rx.c
41846 +++ b/drivers/staging/octeon/ethernet-rx.c
41847 @@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41848 /* Increment RX stats for virtual ports */
41849 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41850 #ifdef CONFIG_64BIT
41851 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41852 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41853 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41854 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41855 #else
41856 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41857 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41858 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41859 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41860 #endif
41861 }
41862 netif_receive_skb(skb);
41863 @@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41864 dev->name);
41865 */
41866 #ifdef CONFIG_64BIT
41867 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41868 + atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
41869 #else
41870 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41871 + atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
41872 #endif
41873 dev_kfree_skb_irq(skb);
41874 }
41875 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41876 index 492c502..d9909f1 100644
41877 --- a/drivers/staging/octeon/ethernet.c
41878 +++ b/drivers/staging/octeon/ethernet.c
41879 @@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41880 * since the RX tasklet also increments it.
41881 */
41882 #ifdef CONFIG_64BIT
41883 - atomic64_add(rx_status.dropped_packets,
41884 - (atomic64_t *)&priv->stats.rx_dropped);
41885 + atomic64_add_unchecked(rx_status.dropped_packets,
41886 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41887 #else
41888 - atomic_add(rx_status.dropped_packets,
41889 - (atomic_t *)&priv->stats.rx_dropped);
41890 + atomic_add_unchecked(rx_status.dropped_packets,
41891 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
41892 #endif
41893 }
41894
41895 diff --git a/drivers/staging/otus/80211core/pub_zfi.h b/drivers/staging/otus/80211core/pub_zfi.h
41896 index a35bd5d..28fff45 100644
41897 --- a/drivers/staging/otus/80211core/pub_zfi.h
41898 +++ b/drivers/staging/otus/80211core/pub_zfi.h
41899 @@ -531,7 +531,7 @@ struct zsCbFuncTbl
41900 u8_t (*zfcbClassifyTxPacket)(zdev_t* dev, zbuf_t* buf);
41901
41902 void (*zfcbHwWatchDogNotify)(zdev_t* dev);
41903 -};
41904 +} __no_const;
41905
41906 extern void zfZeroMemory(u8_t* va, u16_t length);
41907 #define ZM_INIT_CB_FUNC_TABLE(p) zfZeroMemory((u8_t *)p, sizeof(struct zsCbFuncTbl));
41908 diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
41909 index c39a25f..696f5aa 100644
41910 --- a/drivers/staging/panel/panel.c
41911 +++ b/drivers/staging/panel/panel.c
41912 @@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *inode, struct file *file)
41913 return 0;
41914 }
41915
41916 -static struct file_operations lcd_fops = {
41917 +static const struct file_operations lcd_fops = {
41918 .write = lcd_write,
41919 .open = lcd_open,
41920 .release = lcd_release,
41921 @@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *inode, struct file *file)
41922 return 0;
41923 }
41924
41925 -static struct file_operations keypad_fops = {
41926 +static const struct file_operations keypad_fops = {
41927 .read = keypad_read, /* read */
41928 .open = keypad_open, /* open */
41929 .release = keypad_release, /* close */
41930 diff --git a/drivers/staging/phison/phison.c b/drivers/staging/phison/phison.c
41931 index 270ebcb..37e46af 100644
41932 --- a/drivers/staging/phison/phison.c
41933 +++ b/drivers/staging/phison/phison.c
41934 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_sht = {
41935 ATA_BMDMA_SHT(DRV_NAME),
41936 };
41937
41938 -static struct ata_port_operations phison_ops = {
41939 +static const struct ata_port_operations phison_ops = {
41940 .inherits = &ata_bmdma_port_ops,
41941 .prereset = phison_pre_reset,
41942 };
41943 diff --git a/drivers/staging/poch/poch.c b/drivers/staging/poch/poch.c
41944 index 2eb8e3d..57616a7 100644
41945 --- a/drivers/staging/poch/poch.c
41946 +++ b/drivers/staging/poch/poch.c
41947 @@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inode, struct file *filp,
41948 return 0;
41949 }
41950
41951 -static struct file_operations poch_fops = {
41952 +static const struct file_operations poch_fops = {
41953 .owner = THIS_MODULE,
41954 .open = poch_open,
41955 .release = poch_release,
41956 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
41957 index c94de31..19402bc 100644
41958 --- a/drivers/staging/pohmelfs/inode.c
41959 +++ b/drivers/staging/pohmelfs/inode.c
41960 @@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
41961 mutex_init(&psb->mcache_lock);
41962 psb->mcache_root = RB_ROOT;
41963 psb->mcache_timeout = msecs_to_jiffies(5000);
41964 - atomic_long_set(&psb->mcache_gen, 0);
41965 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
41966
41967 psb->trans_max_pages = 100;
41968
41969 @@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
41970 INIT_LIST_HEAD(&psb->crypto_ready_list);
41971 INIT_LIST_HEAD(&psb->crypto_active_list);
41972
41973 - atomic_set(&psb->trans_gen, 1);
41974 + atomic_set_unchecked(&psb->trans_gen, 1);
41975 atomic_long_set(&psb->total_inodes, 0);
41976
41977 mutex_init(&psb->state_lock);
41978 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
41979 index e22665c..a2a9390 100644
41980 --- a/drivers/staging/pohmelfs/mcache.c
41981 +++ b/drivers/staging/pohmelfs/mcache.c
41982 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
41983 m->data = data;
41984 m->start = start;
41985 m->size = size;
41986 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
41987 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
41988
41989 mutex_lock(&psb->mcache_lock);
41990 err = pohmelfs_mcache_insert(psb, m);
41991 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
41992 index 623a07d..4035c19 100644
41993 --- a/drivers/staging/pohmelfs/netfs.h
41994 +++ b/drivers/staging/pohmelfs/netfs.h
41995 @@ -570,14 +570,14 @@ struct pohmelfs_config;
41996 struct pohmelfs_sb {
41997 struct rb_root mcache_root;
41998 struct mutex mcache_lock;
41999 - atomic_long_t mcache_gen;
42000 + atomic_long_unchecked_t mcache_gen;
42001 unsigned long mcache_timeout;
42002
42003 unsigned int idx;
42004
42005 unsigned int trans_retries;
42006
42007 - atomic_t trans_gen;
42008 + atomic_unchecked_t trans_gen;
42009
42010 unsigned int crypto_attached_size;
42011 unsigned int crypto_align_size;
42012 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
42013 index 36a2535..0591bf4 100644
42014 --- a/drivers/staging/pohmelfs/trans.c
42015 +++ b/drivers/staging/pohmelfs/trans.c
42016 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
42017 int err;
42018 struct netfs_cmd *cmd = t->iovec.iov_base;
42019
42020 - t->gen = atomic_inc_return(&psb->trans_gen);
42021 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
42022
42023 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
42024 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
42025 diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
42026 index f890a16..509ece8 100644
42027 --- a/drivers/staging/sep/sep_driver.c
42028 +++ b/drivers/staging/sep/sep_driver.c
42029 @@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver = {
42030 static dev_t sep_devno;
42031
42032 /* the files operations structure of the driver */
42033 -static struct file_operations sep_file_operations = {
42034 +static const struct file_operations sep_file_operations = {
42035 .owner = THIS_MODULE,
42036 .ioctl = sep_ioctl,
42037 .poll = sep_poll,
42038 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
42039 index 5e16bc3..7655b10 100644
42040 --- a/drivers/staging/usbip/usbip_common.h
42041 +++ b/drivers/staging/usbip/usbip_common.h
42042 @@ -374,7 +374,7 @@ struct usbip_device {
42043 void (*shutdown)(struct usbip_device *);
42044 void (*reset)(struct usbip_device *);
42045 void (*unusable)(struct usbip_device *);
42046 - } eh_ops;
42047 + } __no_const eh_ops;
42048 };
42049
42050
42051 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42052 index 57f7946..d9df23d 100644
42053 --- a/drivers/staging/usbip/vhci.h
42054 +++ b/drivers/staging/usbip/vhci.h
42055 @@ -92,7 +92,7 @@ struct vhci_hcd {
42056 unsigned resuming:1;
42057 unsigned long re_timeout;
42058
42059 - atomic_t seqnum;
42060 + atomic_unchecked_t seqnum;
42061
42062 /*
42063 * NOTE:
42064 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42065 index 20cd7db..c2693ff 100644
42066 --- a/drivers/staging/usbip/vhci_hcd.c
42067 +++ b/drivers/staging/usbip/vhci_hcd.c
42068 @@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
42069 return;
42070 }
42071
42072 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42073 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42074 if (priv->seqnum == 0xffff)
42075 usbip_uinfo("seqnum max\n");
42076
42077 @@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42078 return -ENOMEM;
42079 }
42080
42081 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42082 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42083 if (unlink->seqnum == 0xffff)
42084 usbip_uinfo("seqnum max\n");
42085
42086 @@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hcd)
42087 vdev->rhport = rhport;
42088 }
42089
42090 - atomic_set(&vhci->seqnum, 0);
42091 + atomic_set_unchecked(&vhci->seqnum, 0);
42092 spin_lock_init(&vhci->lock);
42093
42094
42095 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42096 index 7fd76fe..673695a 100644
42097 --- a/drivers/staging/usbip/vhci_rx.c
42098 +++ b/drivers/staging/usbip/vhci_rx.c
42099 @@ -79,7 +79,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42100 usbip_uerr("cannot find a urb of seqnum %u\n",
42101 pdu->base.seqnum);
42102 usbip_uinfo("max seqnum %d\n",
42103 - atomic_read(&the_controller->seqnum));
42104 + atomic_read_unchecked(&the_controller->seqnum));
42105 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42106 return;
42107 }
42108 diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
42109 index 7891288..8e31300 100644
42110 --- a/drivers/staging/vme/devices/vme_user.c
42111 +++ b/drivers/staging/vme/devices/vme_user.c
42112 @@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *, struct file *, unsigned int,
42113 static int __init vme_user_probe(struct device *, int, int);
42114 static int __exit vme_user_remove(struct device *, int, int);
42115
42116 -static struct file_operations vme_user_fops = {
42117 +static const struct file_operations vme_user_fops = {
42118 .open = vme_user_open,
42119 .release = vme_user_release,
42120 .read = vme_user_read,
42121 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42122 index 58abf44..00c1fc8 100644
42123 --- a/drivers/staging/vt6655/hostap.c
42124 +++ b/drivers/staging/vt6655/hostap.c
42125 @@ -84,7 +84,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42126 PSDevice apdev_priv;
42127 struct net_device *dev = pDevice->dev;
42128 int ret;
42129 - const struct net_device_ops apdev_netdev_ops = {
42130 + net_device_ops_no_const apdev_netdev_ops = {
42131 .ndo_start_xmit = pDevice->tx_80211,
42132 };
42133
42134 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42135 index 0c8267a..db1f363 100644
42136 --- a/drivers/staging/vt6656/hostap.c
42137 +++ b/drivers/staging/vt6656/hostap.c
42138 @@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42139 PSDevice apdev_priv;
42140 struct net_device *dev = pDevice->dev;
42141 int ret;
42142 - const struct net_device_ops apdev_netdev_ops = {
42143 + net_device_ops_no_const apdev_netdev_ops = {
42144 .ndo_start_xmit = pDevice->tx_80211,
42145 };
42146
42147 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
42148 index 925678b..da7f5ed 100644
42149 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
42150 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
42151 @@ -205,7 +205,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
42152
42153 struct usbctlx_completor {
42154 int (*complete) (struct usbctlx_completor *);
42155 -};
42156 +} __no_const;
42157 typedef struct usbctlx_completor usbctlx_completor_t;
42158
42159 static int
42160 diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
42161 index 40de151..924f268 100644
42162 --- a/drivers/telephony/ixj.c
42163 +++ b/drivers/telephony/ixj.c
42164 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
42165 bool mContinue;
42166 char *pIn, *pOut;
42167
42168 + pax_track_stack();
42169 +
42170 if (!SCI_Prepare(j))
42171 return 0;
42172
42173 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
42174 index e941367..b631f5a 100644
42175 --- a/drivers/uio/uio.c
42176 +++ b/drivers/uio/uio.c
42177 @@ -23,6 +23,7 @@
42178 #include <linux/string.h>
42179 #include <linux/kobject.h>
42180 #include <linux/uio_driver.h>
42181 +#include <asm/local.h>
42182
42183 #define UIO_MAX_DEVICES 255
42184
42185 @@ -30,10 +31,10 @@ struct uio_device {
42186 struct module *owner;
42187 struct device *dev;
42188 int minor;
42189 - atomic_t event;
42190 + atomic_unchecked_t event;
42191 struct fasync_struct *async_queue;
42192 wait_queue_head_t wait;
42193 - int vma_count;
42194 + local_t vma_count;
42195 struct uio_info *info;
42196 struct kobject *map_dir;
42197 struct kobject *portio_dir;
42198 @@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
42199 return entry->show(mem, buf);
42200 }
42201
42202 -static struct sysfs_ops map_sysfs_ops = {
42203 +static const struct sysfs_ops map_sysfs_ops = {
42204 .show = map_type_show,
42205 };
42206
42207 @@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
42208 return entry->show(port, buf);
42209 }
42210
42211 -static struct sysfs_ops portio_sysfs_ops = {
42212 +static const struct sysfs_ops portio_sysfs_ops = {
42213 .show = portio_type_show,
42214 };
42215
42216 @@ -255,7 +256,7 @@ static ssize_t show_event(struct device *dev,
42217 struct uio_device *idev = dev_get_drvdata(dev);
42218 if (idev)
42219 return sprintf(buf, "%u\n",
42220 - (unsigned int)atomic_read(&idev->event));
42221 + (unsigned int)atomic_read_unchecked(&idev->event));
42222 else
42223 return -ENODEV;
42224 }
42225 @@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *info)
42226 {
42227 struct uio_device *idev = info->uio_dev;
42228
42229 - atomic_inc(&idev->event);
42230 + atomic_inc_unchecked(&idev->event);
42231 wake_up_interruptible(&idev->wait);
42232 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
42233 }
42234 @@ -477,7 +478,7 @@ static int uio_open(struct inode *inode, struct file *filep)
42235 }
42236
42237 listener->dev = idev;
42238 - listener->event_count = atomic_read(&idev->event);
42239 + listener->event_count = atomic_read_unchecked(&idev->event);
42240 filep->private_data = listener;
42241
42242 if (idev->info->open) {
42243 @@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
42244 return -EIO;
42245
42246 poll_wait(filep, &idev->wait, wait);
42247 - if (listener->event_count != atomic_read(&idev->event))
42248 + if (listener->event_count != atomic_read_unchecked(&idev->event))
42249 return POLLIN | POLLRDNORM;
42250 return 0;
42251 }
42252 @@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
42253 do {
42254 set_current_state(TASK_INTERRUPTIBLE);
42255
42256 - event_count = atomic_read(&idev->event);
42257 + event_count = atomic_read_unchecked(&idev->event);
42258 if (event_count != listener->event_count) {
42259 if (copy_to_user(buf, &event_count, count))
42260 retval = -EFAULT;
42261 @@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
42262 static void uio_vma_open(struct vm_area_struct *vma)
42263 {
42264 struct uio_device *idev = vma->vm_private_data;
42265 - idev->vma_count++;
42266 + local_inc(&idev->vma_count);
42267 }
42268
42269 static void uio_vma_close(struct vm_area_struct *vma)
42270 {
42271 struct uio_device *idev = vma->vm_private_data;
42272 - idev->vma_count--;
42273 + local_dec(&idev->vma_count);
42274 }
42275
42276 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42277 @@ -840,7 +841,7 @@ int __uio_register_device(struct module *owner,
42278 idev->owner = owner;
42279 idev->info = info;
42280 init_waitqueue_head(&idev->wait);
42281 - atomic_set(&idev->event, 0);
42282 + atomic_set_unchecked(&idev->event, 0);
42283
42284 ret = uio_get_minor(idev);
42285 if (ret)
42286 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
42287 index fbea856..06efea6 100644
42288 --- a/drivers/usb/atm/usbatm.c
42289 +++ b/drivers/usb/atm/usbatm.c
42290 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42291 if (printk_ratelimit())
42292 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42293 __func__, vpi, vci);
42294 - atomic_inc(&vcc->stats->rx_err);
42295 + atomic_inc_unchecked(&vcc->stats->rx_err);
42296 return;
42297 }
42298
42299 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42300 if (length > ATM_MAX_AAL5_PDU) {
42301 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42302 __func__, length, vcc);
42303 - atomic_inc(&vcc->stats->rx_err);
42304 + atomic_inc_unchecked(&vcc->stats->rx_err);
42305 goto out;
42306 }
42307
42308 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42309 if (sarb->len < pdu_length) {
42310 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42311 __func__, pdu_length, sarb->len, vcc);
42312 - atomic_inc(&vcc->stats->rx_err);
42313 + atomic_inc_unchecked(&vcc->stats->rx_err);
42314 goto out;
42315 }
42316
42317 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42318 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42319 __func__, vcc);
42320 - atomic_inc(&vcc->stats->rx_err);
42321 + atomic_inc_unchecked(&vcc->stats->rx_err);
42322 goto out;
42323 }
42324
42325 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42326 if (printk_ratelimit())
42327 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42328 __func__, length);
42329 - atomic_inc(&vcc->stats->rx_drop);
42330 + atomic_inc_unchecked(&vcc->stats->rx_drop);
42331 goto out;
42332 }
42333
42334 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42335
42336 vcc->push(vcc, skb);
42337
42338 - atomic_inc(&vcc->stats->rx);
42339 + atomic_inc_unchecked(&vcc->stats->rx);
42340 out:
42341 skb_trim(sarb, 0);
42342 }
42343 @@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned long data)
42344 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42345
42346 usbatm_pop(vcc, skb);
42347 - atomic_inc(&vcc->stats->tx);
42348 + atomic_inc_unchecked(&vcc->stats->tx);
42349
42350 skb = skb_dequeue(&instance->sndqueue);
42351 }
42352 @@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
42353 if (!left--)
42354 return sprintf(page,
42355 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42356 - atomic_read(&atm_dev->stats.aal5.tx),
42357 - atomic_read(&atm_dev->stats.aal5.tx_err),
42358 - atomic_read(&atm_dev->stats.aal5.rx),
42359 - atomic_read(&atm_dev->stats.aal5.rx_err),
42360 - atomic_read(&atm_dev->stats.aal5.rx_drop));
42361 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42362 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42363 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42364 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42365 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42366
42367 if (!left--) {
42368 if (instance->disconnected)
42369 diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
42370 index 3e564bf..949b448 100644
42371 --- a/drivers/usb/class/cdc-wdm.c
42372 +++ b/drivers/usb/class/cdc-wdm.c
42373 @@ -314,7 +314,7 @@ static ssize_t wdm_write
42374 if (r < 0)
42375 goto outnp;
42376
42377 - if (!file->f_flags && O_NONBLOCK)
42378 + if (!(file->f_flags & O_NONBLOCK))
42379 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
42380 &desc->flags));
42381 else
42382 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
42383 index 24e6205..fe5a5d4 100644
42384 --- a/drivers/usb/core/hcd.c
42385 +++ b/drivers/usb/core/hcd.c
42386 @@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
42387
42388 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42389
42390 -struct usb_mon_operations *mon_ops;
42391 +const struct usb_mon_operations *mon_ops;
42392
42393 /*
42394 * The registration is unlocked.
42395 @@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
42396 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42397 */
42398
42399 -int usb_mon_register (struct usb_mon_operations *ops)
42400 +int usb_mon_register (const struct usb_mon_operations *ops)
42401 {
42402
42403 if (mon_ops)
42404 diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
42405 index bcbe104..9cfd1c6 100644
42406 --- a/drivers/usb/core/hcd.h
42407 +++ b/drivers/usb/core/hcd.h
42408 @@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) { }
42409 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42410
42411 struct usb_mon_operations {
42412 - void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
42413 - void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42414 - void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42415 + void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
42416 + void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42417 + void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42418 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
42419 };
42420
42421 -extern struct usb_mon_operations *mon_ops;
42422 +extern const struct usb_mon_operations *mon_ops;
42423
42424 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
42425 {
42426 @@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
42427 (*mon_ops->urb_complete)(bus, urb, status);
42428 }
42429
42430 -int usb_mon_register(struct usb_mon_operations *ops);
42431 +int usb_mon_register(const struct usb_mon_operations *ops);
42432 void usb_mon_deregister(void);
42433
42434 #else
42435 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
42436 index 409cc94..a673bad 100644
42437 --- a/drivers/usb/core/message.c
42438 +++ b/drivers/usb/core/message.c
42439 @@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
42440 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42441 if (buf) {
42442 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42443 - if (len > 0) {
42444 - smallbuf = kmalloc(++len, GFP_NOIO);
42445 + if (len++ > 0) {
42446 + smallbuf = kmalloc(len, GFP_NOIO);
42447 if (!smallbuf)
42448 return buf;
42449 memcpy(smallbuf, buf, len);
42450 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
42451 index 62ff5e7..530b74e 100644
42452 --- a/drivers/usb/misc/appledisplay.c
42453 +++ b/drivers/usb/misc/appledisplay.c
42454 @@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
42455 return pdata->msgdata[1];
42456 }
42457
42458 -static struct backlight_ops appledisplay_bl_data = {
42459 +static const struct backlight_ops appledisplay_bl_data = {
42460 .get_brightness = appledisplay_bl_get_brightness,
42461 .update_status = appledisplay_bl_update_status,
42462 };
42463 diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
42464 index e0c2db3..bd8cb66 100644
42465 --- a/drivers/usb/mon/mon_main.c
42466 +++ b/drivers/usb/mon/mon_main.c
42467 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42468 /*
42469 * Ops
42470 */
42471 -static struct usb_mon_operations mon_ops_0 = {
42472 +static const struct usb_mon_operations mon_ops_0 = {
42473 .urb_submit = mon_submit,
42474 .urb_submit_error = mon_submit_error,
42475 .urb_complete = mon_complete,
42476 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
42477 index d6bea3e..60b250e 100644
42478 --- a/drivers/usb/wusbcore/wa-hc.h
42479 +++ b/drivers/usb/wusbcore/wa-hc.h
42480 @@ -192,7 +192,7 @@ struct wahc {
42481 struct list_head xfer_delayed_list;
42482 spinlock_t xfer_list_lock;
42483 struct work_struct xfer_work;
42484 - atomic_t xfer_id_count;
42485 + atomic_unchecked_t xfer_id_count;
42486 };
42487
42488
42489 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
42490 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42491 spin_lock_init(&wa->xfer_list_lock);
42492 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42493 - atomic_set(&wa->xfer_id_count, 1);
42494 + atomic_set_unchecked(&wa->xfer_id_count, 1);
42495 }
42496
42497 /**
42498 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
42499 index 613a5fc..3174865 100644
42500 --- a/drivers/usb/wusbcore/wa-xfer.c
42501 +++ b/drivers/usb/wusbcore/wa-xfer.c
42502 @@ -293,7 +293,7 @@ out:
42503 */
42504 static void wa_xfer_id_init(struct wa_xfer *xfer)
42505 {
42506 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42507 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42508 }
42509
42510 /*
42511 diff --git a/drivers/uwb/wlp/messages.c b/drivers/uwb/wlp/messages.c
42512 index aa42fce..f8a828c 100644
42513 --- a/drivers/uwb/wlp/messages.c
42514 +++ b/drivers/uwb/wlp/messages.c
42515 @@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct sk_buff *skb)
42516 size_t len = skb->len;
42517 size_t used;
42518 ssize_t result;
42519 - struct wlp_nonce enonce, rnonce;
42520 + struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
42521 enum wlp_assc_error assc_err;
42522 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
42523 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
42524 diff --git a/drivers/uwb/wlp/sysfs.c b/drivers/uwb/wlp/sysfs.c
42525 index 0370399..6627c94 100644
42526 --- a/drivers/uwb/wlp/sysfs.c
42527 +++ b/drivers/uwb/wlp/sysfs.c
42528 @@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobject *kobj, struct attribute *attr,
42529 return ret;
42530 }
42531
42532 -static
42533 -struct sysfs_ops wss_sysfs_ops = {
42534 +static const struct sysfs_ops wss_sysfs_ops = {
42535 .show = wlp_wss_attr_show,
42536 .store = wlp_wss_attr_store,
42537 };
42538 diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
42539 index d5e8010..5687b56 100644
42540 --- a/drivers/video/atmel_lcdfb.c
42541 +++ b/drivers/video/atmel_lcdfb.c
42542 @@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struct backlight_device *bl)
42543 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
42544 }
42545
42546 -static struct backlight_ops atmel_lcdc_bl_ops = {
42547 +static const struct backlight_ops atmel_lcdc_bl_ops = {
42548 .update_status = atmel_bl_update_status,
42549 .get_brightness = atmel_bl_get_brightness,
42550 };
42551 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42552 index e4e4d43..66bcbcc 100644
42553 --- a/drivers/video/aty/aty128fb.c
42554 +++ b/drivers/video/aty/aty128fb.c
42555 @@ -149,7 +149,7 @@ enum {
42556 };
42557
42558 /* Must match above enum */
42559 -static const char *r128_family[] __devinitdata = {
42560 +static const char *r128_family[] __devinitconst = {
42561 "AGP",
42562 "PCI",
42563 "PRO AGP",
42564 @@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(struct backlight_device *bd)
42565 return bd->props.brightness;
42566 }
42567
42568 -static struct backlight_ops aty128_bl_data = {
42569 +static const struct backlight_ops aty128_bl_data = {
42570 .get_brightness = aty128_bl_get_brightness,
42571 .update_status = aty128_bl_update_status,
42572 };
42573 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
42574 index 913b4a4..9295a38 100644
42575 --- a/drivers/video/aty/atyfb_base.c
42576 +++ b/drivers/video/aty/atyfb_base.c
42577 @@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct backlight_device *bd)
42578 return bd->props.brightness;
42579 }
42580
42581 -static struct backlight_ops aty_bl_data = {
42582 +static const struct backlight_ops aty_bl_data = {
42583 .get_brightness = aty_bl_get_brightness,
42584 .update_status = aty_bl_update_status,
42585 };
42586 diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
42587 index 1a056ad..221bd6a 100644
42588 --- a/drivers/video/aty/radeon_backlight.c
42589 +++ b/drivers/video/aty/radeon_backlight.c
42590 @@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(struct backlight_device *bd)
42591 return bd->props.brightness;
42592 }
42593
42594 -static struct backlight_ops radeon_bl_data = {
42595 +static const struct backlight_ops radeon_bl_data = {
42596 .get_brightness = radeon_bl_get_brightness,
42597 .update_status = radeon_bl_update_status,
42598 };
42599 diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
42600 index ad05da5..3cb2cb9 100644
42601 --- a/drivers/video/backlight/adp5520_bl.c
42602 +++ b/drivers/video/backlight/adp5520_bl.c
42603 @@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl)
42604 return error ? data->current_brightness : reg_val;
42605 }
42606
42607 -static struct backlight_ops adp5520_bl_ops = {
42608 +static const struct backlight_ops adp5520_bl_ops = {
42609 .update_status = adp5520_bl_update_status,
42610 .get_brightness = adp5520_bl_get_brightness,
42611 };
42612 diff --git a/drivers/video/backlight/adx_bl.c b/drivers/video/backlight/adx_bl.c
42613 index 2c3bdfc..d769b0b 100644
42614 --- a/drivers/video/backlight/adx_bl.c
42615 +++ b/drivers/video/backlight/adx_bl.c
42616 @@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct fb_info *fb)
42617 return 1;
42618 }
42619
42620 -static struct backlight_ops adx_backlight_ops = {
42621 +static const struct backlight_ops adx_backlight_ops = {
42622 .options = 0,
42623 .update_status = adx_backlight_update_status,
42624 .get_brightness = adx_backlight_get_brightness,
42625 diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
42626 index 505c082..6b6b3cc 100644
42627 --- a/drivers/video/backlight/atmel-pwm-bl.c
42628 +++ b/drivers/video/backlight/atmel-pwm-bl.c
42629 @@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
42630 return pwm_channel_enable(&pwmbl->pwmc);
42631 }
42632
42633 -static struct backlight_ops atmel_pwm_bl_ops = {
42634 +static const struct backlight_ops atmel_pwm_bl_ops = {
42635 .get_brightness = atmel_pwm_bl_get_intensity,
42636 .update_status = atmel_pwm_bl_set_intensity,
42637 };
42638 diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
42639 index 5e20e6e..89025e6 100644
42640 --- a/drivers/video/backlight/backlight.c
42641 +++ b/drivers/video/backlight/backlight.c
42642 @@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
42643 * ERR_PTR() or a pointer to the newly allocated device.
42644 */
42645 struct backlight_device *backlight_device_register(const char *name,
42646 - struct device *parent, void *devdata, struct backlight_ops *ops)
42647 + struct device *parent, void *devdata, const struct backlight_ops *ops)
42648 {
42649 struct backlight_device *new_bd;
42650 int rc;
42651 diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
42652 index 9677494..b4bcf80 100644
42653 --- a/drivers/video/backlight/corgi_lcd.c
42654 +++ b/drivers/video/backlight/corgi_lcd.c
42655 @@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit)
42656 }
42657 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
42658
42659 -static struct backlight_ops corgi_bl_ops = {
42660 +static const struct backlight_ops corgi_bl_ops = {
42661 .get_brightness = corgi_bl_get_intensity,
42662 .update_status = corgi_bl_update_status,
42663 };
42664 diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
42665 index b9fe62b..2914bf1 100644
42666 --- a/drivers/video/backlight/cr_bllcd.c
42667 +++ b/drivers/video/backlight/cr_bllcd.c
42668 @@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(struct backlight_device *bd)
42669 return intensity;
42670 }
42671
42672 -static struct backlight_ops cr_backlight_ops = {
42673 +static const struct backlight_ops cr_backlight_ops = {
42674 .get_brightness = cr_backlight_get_intensity,
42675 .update_status = cr_backlight_set_intensity,
42676 };
42677 diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
42678 index 701a108..feacfd5 100644
42679 --- a/drivers/video/backlight/da903x_bl.c
42680 +++ b/drivers/video/backlight/da903x_bl.c
42681 @@ -94,7 +94,7 @@ static int da903x_backlight_get_brightness(struct backlight_device *bl)
42682 return data->current_brightness;
42683 }
42684
42685 -static struct backlight_ops da903x_backlight_ops = {
42686 +static const struct backlight_ops da903x_backlight_ops = {
42687 .update_status = da903x_backlight_update_status,
42688 .get_brightness = da903x_backlight_get_brightness,
42689 };
42690 diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
42691 index 6d27f62..e6d348e 100644
42692 --- a/drivers/video/backlight/generic_bl.c
42693 +++ b/drivers/video/backlight/generic_bl.c
42694 @@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
42695 }
42696 EXPORT_SYMBOL(corgibl_limit_intensity);
42697
42698 -static struct backlight_ops genericbl_ops = {
42699 +static const struct backlight_ops genericbl_ops = {
42700 .options = BL_CORE_SUSPENDRESUME,
42701 .get_brightness = genericbl_get_intensity,
42702 .update_status = genericbl_send_intensity,
42703 diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
42704 index 7fb4eef..f7cc528 100644
42705 --- a/drivers/video/backlight/hp680_bl.c
42706 +++ b/drivers/video/backlight/hp680_bl.c
42707 @@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
42708 return current_intensity;
42709 }
42710
42711 -static struct backlight_ops hp680bl_ops = {
42712 +static const struct backlight_ops hp680bl_ops = {
42713 .get_brightness = hp680bl_get_intensity,
42714 .update_status = hp680bl_set_intensity,
42715 };
42716 diff --git a/drivers/video/backlight/jornada720_bl.c b/drivers/video/backlight/jornada720_bl.c
42717 index 7aed256..db9071f 100644
42718 --- a/drivers/video/backlight/jornada720_bl.c
42719 +++ b/drivers/video/backlight/jornada720_bl.c
42720 @@ -93,7 +93,7 @@ out:
42721 return ret;
42722 }
42723
42724 -static struct backlight_ops jornada_bl_ops = {
42725 +static const struct backlight_ops jornada_bl_ops = {
42726 .get_brightness = jornada_bl_get_brightness,
42727 .update_status = jornada_bl_update_status,
42728 .options = BL_CORE_SUSPENDRESUME,
42729 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
42730 index a38fda1..939e7b8 100644
42731 --- a/drivers/video/backlight/kb3886_bl.c
42732 +++ b/drivers/video/backlight/kb3886_bl.c
42733 @@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct backlight_device *bd)
42734 return kb3886bl_intensity;
42735 }
42736
42737 -static struct backlight_ops kb3886bl_ops = {
42738 +static const struct backlight_ops kb3886bl_ops = {
42739 .get_brightness = kb3886bl_get_intensity,
42740 .update_status = kb3886bl_send_intensity,
42741 };
42742 diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
42743 index 6b488b8..00a9591 100644
42744 --- a/drivers/video/backlight/locomolcd.c
42745 +++ b/drivers/video/backlight/locomolcd.c
42746 @@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struct backlight_device *bd)
42747 return current_intensity;
42748 }
42749
42750 -static struct backlight_ops locomobl_data = {
42751 +static const struct backlight_ops locomobl_data = {
42752 .get_brightness = locomolcd_get_intensity,
42753 .update_status = locomolcd_set_intensity,
42754 };
42755 diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
42756 index 99bdfa8..3dac448 100644
42757 --- a/drivers/video/backlight/mbp_nvidia_bl.c
42758 +++ b/drivers/video/backlight/mbp_nvidia_bl.c
42759 @@ -33,7 +33,7 @@ struct dmi_match_data {
42760 unsigned long iostart;
42761 unsigned long iolen;
42762 /* Backlight operations structure. */
42763 - struct backlight_ops backlight_ops;
42764 + const struct backlight_ops backlight_ops;
42765 };
42766
42767 /* Module parameters. */
42768 diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
42769 index cbad67e..3cf900e 100644
42770 --- a/drivers/video/backlight/omap1_bl.c
42771 +++ b/drivers/video/backlight/omap1_bl.c
42772 @@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct backlight_device *dev)
42773 return bl->current_intensity;
42774 }
42775
42776 -static struct backlight_ops omapbl_ops = {
42777 +static const struct backlight_ops omapbl_ops = {
42778 .get_brightness = omapbl_get_intensity,
42779 .update_status = omapbl_update_status,
42780 };
42781 diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
42782 index 9edaf24..075786e 100644
42783 --- a/drivers/video/backlight/progear_bl.c
42784 +++ b/drivers/video/backlight/progear_bl.c
42785 @@ -54,7 +54,7 @@ static int progearbl_get_intensity(struct backlight_device *bd)
42786 return intensity - HW_LEVEL_MIN;
42787 }
42788
42789 -static struct backlight_ops progearbl_ops = {
42790 +static const struct backlight_ops progearbl_ops = {
42791 .get_brightness = progearbl_get_intensity,
42792 .update_status = progearbl_set_intensity,
42793 };
42794 diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
42795 index 8871662..df9e0b3 100644
42796 --- a/drivers/video/backlight/pwm_bl.c
42797 +++ b/drivers/video/backlight/pwm_bl.c
42798 @@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(struct backlight_device *bl)
42799 return bl->props.brightness;
42800 }
42801
42802 -static struct backlight_ops pwm_backlight_ops = {
42803 +static const struct backlight_ops pwm_backlight_ops = {
42804 .update_status = pwm_backlight_update_status,
42805 .get_brightness = pwm_backlight_get_brightness,
42806 };
42807 diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
42808 index 43edbad..e14ce4d 100644
42809 --- a/drivers/video/backlight/tosa_bl.c
42810 +++ b/drivers/video/backlight/tosa_bl.c
42811 @@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct backlight_device *dev)
42812 return props->brightness;
42813 }
42814
42815 -static struct backlight_ops bl_ops = {
42816 +static const struct backlight_ops bl_ops = {
42817 .get_brightness = tosa_bl_get_brightness,
42818 .update_status = tosa_bl_update_status,
42819 };
42820 diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
42821 index 467bdb7..e32add3 100644
42822 --- a/drivers/video/backlight/wm831x_bl.c
42823 +++ b/drivers/video/backlight/wm831x_bl.c
42824 @@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightness(struct backlight_device *bl)
42825 return data->current_brightness;
42826 }
42827
42828 -static struct backlight_ops wm831x_backlight_ops = {
42829 +static const struct backlight_ops wm831x_backlight_ops = {
42830 .options = BL_CORE_SUSPENDRESUME,
42831 .update_status = wm831x_backlight_update_status,
42832 .get_brightness = wm831x_backlight_get_brightness,
42833 diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
42834 index e49ae5e..db4e6f7 100644
42835 --- a/drivers/video/bf54x-lq043fb.c
42836 +++ b/drivers/video/bf54x-lq043fb.c
42837 @@ -463,7 +463,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42838 return 0;
42839 }
42840
42841 -static struct backlight_ops bfin_lq043fb_bl_ops = {
42842 +static const struct backlight_ops bfin_lq043fb_bl_ops = {
42843 .get_brightness = bl_get_brightness,
42844 };
42845
42846 diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
42847 index 2c72a7c..d523e52 100644
42848 --- a/drivers/video/bfin-t350mcqb-fb.c
42849 +++ b/drivers/video/bfin-t350mcqb-fb.c
42850 @@ -381,7 +381,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42851 return 0;
42852 }
42853
42854 -static struct backlight_ops bfin_lq043fb_bl_ops = {
42855 +static const struct backlight_ops bfin_lq043fb_bl_ops = {
42856 .get_brightness = bl_get_brightness,
42857 };
42858
42859 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42860 index f53b9f1..958bf4e 100644
42861 --- a/drivers/video/fbcmap.c
42862 +++ b/drivers/video/fbcmap.c
42863 @@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42864 rc = -ENODEV;
42865 goto out;
42866 }
42867 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42868 - !info->fbops->fb_setcmap)) {
42869 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42870 rc = -EINVAL;
42871 goto out1;
42872 }
42873 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42874 index 99bbd28..ad3829e 100644
42875 --- a/drivers/video/fbmem.c
42876 +++ b/drivers/video/fbmem.c
42877 @@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42878 image->dx += image->width + 8;
42879 }
42880 } else if (rotate == FB_ROTATE_UD) {
42881 - for (x = 0; x < num && image->dx >= 0; x++) {
42882 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42883 info->fbops->fb_imageblit(info, image);
42884 image->dx -= image->width + 8;
42885 }
42886 @@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42887 image->dy += image->height + 8;
42888 }
42889 } else if (rotate == FB_ROTATE_CCW) {
42890 - for (x = 0; x < num && image->dy >= 0; x++) {
42891 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42892 info->fbops->fb_imageblit(info, image);
42893 image->dy -= image->height + 8;
42894 }
42895 @@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
42896 int flags = info->flags;
42897 int ret = 0;
42898
42899 + pax_track_stack();
42900 +
42901 if (var->activate & FB_ACTIVATE_INV_MODE) {
42902 struct fb_videomode mode1, mode2;
42903
42904 @@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42905 void __user *argp = (void __user *)arg;
42906 long ret = 0;
42907
42908 + pax_track_stack();
42909 +
42910 switch (cmd) {
42911 case FBIOGET_VSCREENINFO:
42912 if (!lock_fb_info(info))
42913 @@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42914 return -EFAULT;
42915 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42916 return -EINVAL;
42917 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42918 + if (con2fb.framebuffer >= FB_MAX)
42919 return -EINVAL;
42920 if (!registered_fb[con2fb.framebuffer])
42921 request_module("fb%d", con2fb.framebuffer);
42922 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
42923 index f20eff8..3e4f622 100644
42924 --- a/drivers/video/geode/gx1fb_core.c
42925 +++ b/drivers/video/geode/gx1fb_core.c
42926 @@ -30,7 +30,7 @@ static int crt_option = 1;
42927 static char panel_option[32] = "";
42928
42929 /* Modes relevant to the GX1 (taken from modedb.c) */
42930 -static const struct fb_videomode __initdata gx1_modedb[] = {
42931 +static const struct fb_videomode __initconst gx1_modedb[] = {
42932 /* 640x480-60 VESA */
42933 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
42934 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
42935 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
42936 index 896e53d..4d87d0b 100644
42937 --- a/drivers/video/gxt4500.c
42938 +++ b/drivers/video/gxt4500.c
42939 @@ -156,7 +156,7 @@ struct gxt4500_par {
42940 static char *mode_option;
42941
42942 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
42943 -static const struct fb_videomode defaultmode __devinitdata = {
42944 +static const struct fb_videomode defaultmode __devinitconst = {
42945 .refresh = 60,
42946 .xres = 1280,
42947 .yres = 1024,
42948 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
42949 return 0;
42950 }
42951
42952 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
42953 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
42954 .id = "IBM GXT4500P",
42955 .type = FB_TYPE_PACKED_PIXELS,
42956 .visual = FB_VISUAL_PSEUDOCOLOR,
42957 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42958 index f5bedee..28c6028 100644
42959 --- a/drivers/video/i810/i810_accel.c
42960 +++ b/drivers/video/i810/i810_accel.c
42961 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42962 }
42963 }
42964 printk("ringbuffer lockup!!!\n");
42965 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42966 i810_report_error(mmio);
42967 par->dev_flags |= LOCKUP;
42968 info->pixmap.scan_align = 1;
42969 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
42970 index 5743ea2..457f82c 100644
42971 --- a/drivers/video/i810/i810_main.c
42972 +++ b/drivers/video/i810/i810_main.c
42973 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
42974 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
42975
42976 /* PCI */
42977 -static const char *i810_pci_list[] __devinitdata = {
42978 +static const char *i810_pci_list[] __devinitconst = {
42979 "Intel(R) 810 Framebuffer Device" ,
42980 "Intel(R) 810-DC100 Framebuffer Device" ,
42981 "Intel(R) 810E Framebuffer Device" ,
42982 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42983 index 3c14e43..eafa544 100644
42984 --- a/drivers/video/logo/logo_linux_clut224.ppm
42985 +++ b/drivers/video/logo/logo_linux_clut224.ppm
42986 @@ -1,1604 +1,1123 @@
42987 P3
42988 -# Standard 224-color Linux logo
42989 80 80
42990 255
42991 - 0 0 0 0 0 0 0 0 0 0 0 0
42992 - 0 0 0 0 0 0 0 0 0 0 0 0
42993 - 0 0 0 0 0 0 0 0 0 0 0 0
42994 - 0 0 0 0 0 0 0 0 0 0 0 0
42995 - 0 0 0 0 0 0 0 0 0 0 0 0
42996 - 0 0 0 0 0 0 0 0 0 0 0 0
42997 - 0 0 0 0 0 0 0 0 0 0 0 0
42998 - 0 0 0 0 0 0 0 0 0 0 0 0
42999 - 0 0 0 0 0 0 0 0 0 0 0 0
43000 - 6 6 6 6 6 6 10 10 10 10 10 10
43001 - 10 10 10 6 6 6 6 6 6 6 6 6
43002 - 0 0 0 0 0 0 0 0 0 0 0 0
43003 - 0 0 0 0 0 0 0 0 0 0 0 0
43004 - 0 0 0 0 0 0 0 0 0 0 0 0
43005 - 0 0 0 0 0 0 0 0 0 0 0 0
43006 - 0 0 0 0 0 0 0 0 0 0 0 0
43007 - 0 0 0 0 0 0 0 0 0 0 0 0
43008 - 0 0 0 0 0 0 0 0 0 0 0 0
43009 - 0 0 0 0 0 0 0 0 0 0 0 0
43010 - 0 0 0 0 0 0 0 0 0 0 0 0
43011 - 0 0 0 0 0 0 0 0 0 0 0 0
43012 - 0 0 0 0 0 0 0 0 0 0 0 0
43013 - 0 0 0 0 0 0 0 0 0 0 0 0
43014 - 0 0 0 0 0 0 0 0 0 0 0 0
43015 - 0 0 0 0 0 0 0 0 0 0 0 0
43016 - 0 0 0 0 0 0 0 0 0 0 0 0
43017 - 0 0 0 0 0 0 0 0 0 0 0 0
43018 - 0 0 0 0 0 0 0 0 0 0 0 0
43019 - 0 0 0 6 6 6 10 10 10 14 14 14
43020 - 22 22 22 26 26 26 30 30 30 34 34 34
43021 - 30 30 30 30 30 30 26 26 26 18 18 18
43022 - 14 14 14 10 10 10 6 6 6 0 0 0
43023 - 0 0 0 0 0 0 0 0 0 0 0 0
43024 - 0 0 0 0 0 0 0 0 0 0 0 0
43025 - 0 0 0 0 0 0 0 0 0 0 0 0
43026 - 0 0 0 0 0 0 0 0 0 0 0 0
43027 - 0 0 0 0 0 0 0 0 0 0 0 0
43028 - 0 0 0 0 0 0 0 0 0 0 0 0
43029 - 0 0 0 0 0 0 0 0 0 0 0 0
43030 - 0 0 0 0 0 0 0 0 0 0 0 0
43031 - 0 0 0 0 0 0 0 0 0 0 0 0
43032 - 0 0 0 0 0 1 0 0 1 0 0 0
43033 - 0 0 0 0 0 0 0 0 0 0 0 0
43034 - 0 0 0 0 0 0 0 0 0 0 0 0
43035 - 0 0 0 0 0 0 0 0 0 0 0 0
43036 - 0 0 0 0 0 0 0 0 0 0 0 0
43037 - 0 0 0 0 0 0 0 0 0 0 0 0
43038 - 0 0 0 0 0 0 0 0 0 0 0 0
43039 - 6 6 6 14 14 14 26 26 26 42 42 42
43040 - 54 54 54 66 66 66 78 78 78 78 78 78
43041 - 78 78 78 74 74 74 66 66 66 54 54 54
43042 - 42 42 42 26 26 26 18 18 18 10 10 10
43043 - 6 6 6 0 0 0 0 0 0 0 0 0
43044 - 0 0 0 0 0 0 0 0 0 0 0 0
43045 - 0 0 0 0 0 0 0 0 0 0 0 0
43046 - 0 0 0 0 0 0 0 0 0 0 0 0
43047 - 0 0 0 0 0 0 0 0 0 0 0 0
43048 - 0 0 0 0 0 0 0 0 0 0 0 0
43049 - 0 0 0 0 0 0 0 0 0 0 0 0
43050 - 0 0 0 0 0 0 0 0 0 0 0 0
43051 - 0 0 0 0 0 0 0 0 0 0 0 0
43052 - 0 0 1 0 0 0 0 0 0 0 0 0
43053 - 0 0 0 0 0 0 0 0 0 0 0 0
43054 - 0 0 0 0 0 0 0 0 0 0 0 0
43055 - 0 0 0 0 0 0 0 0 0 0 0 0
43056 - 0 0 0 0 0 0 0 0 0 0 0 0
43057 - 0 0 0 0 0 0 0 0 0 0 0 0
43058 - 0 0 0 0 0 0 0 0 0 10 10 10
43059 - 22 22 22 42 42 42 66 66 66 86 86 86
43060 - 66 66 66 38 38 38 38 38 38 22 22 22
43061 - 26 26 26 34 34 34 54 54 54 66 66 66
43062 - 86 86 86 70 70 70 46 46 46 26 26 26
43063 - 14 14 14 6 6 6 0 0 0 0 0 0
43064 - 0 0 0 0 0 0 0 0 0 0 0 0
43065 - 0 0 0 0 0 0 0 0 0 0 0 0
43066 - 0 0 0 0 0 0 0 0 0 0 0 0
43067 - 0 0 0 0 0 0 0 0 0 0 0 0
43068 - 0 0 0 0 0 0 0 0 0 0 0 0
43069 - 0 0 0 0 0 0 0 0 0 0 0 0
43070 - 0 0 0 0 0 0 0 0 0 0 0 0
43071 - 0 0 0 0 0 0 0 0 0 0 0 0
43072 - 0 0 1 0 0 1 0 0 1 0 0 0
43073 - 0 0 0 0 0 0 0 0 0 0 0 0
43074 - 0 0 0 0 0 0 0 0 0 0 0 0
43075 - 0 0 0 0 0 0 0 0 0 0 0 0
43076 - 0 0 0 0 0 0 0 0 0 0 0 0
43077 - 0 0 0 0 0 0 0 0 0 0 0 0
43078 - 0 0 0 0 0 0 10 10 10 26 26 26
43079 - 50 50 50 82 82 82 58 58 58 6 6 6
43080 - 2 2 6 2 2 6 2 2 6 2 2 6
43081 - 2 2 6 2 2 6 2 2 6 2 2 6
43082 - 6 6 6 54 54 54 86 86 86 66 66 66
43083 - 38 38 38 18 18 18 6 6 6 0 0 0
43084 - 0 0 0 0 0 0 0 0 0 0 0 0
43085 - 0 0 0 0 0 0 0 0 0 0 0 0
43086 - 0 0 0 0 0 0 0 0 0 0 0 0
43087 - 0 0 0 0 0 0 0 0 0 0 0 0
43088 - 0 0 0 0 0 0 0 0 0 0 0 0
43089 - 0 0 0 0 0 0 0 0 0 0 0 0
43090 - 0 0 0 0 0 0 0 0 0 0 0 0
43091 - 0 0 0 0 0 0 0 0 0 0 0 0
43092 - 0 0 0 0 0 0 0 0 0 0 0 0
43093 - 0 0 0 0 0 0 0 0 0 0 0 0
43094 - 0 0 0 0 0 0 0 0 0 0 0 0
43095 - 0 0 0 0 0 0 0 0 0 0 0 0
43096 - 0 0 0 0 0 0 0 0 0 0 0 0
43097 - 0 0 0 0 0 0 0 0 0 0 0 0
43098 - 0 0 0 6 6 6 22 22 22 50 50 50
43099 - 78 78 78 34 34 34 2 2 6 2 2 6
43100 - 2 2 6 2 2 6 2 2 6 2 2 6
43101 - 2 2 6 2 2 6 2 2 6 2 2 6
43102 - 2 2 6 2 2 6 6 6 6 70 70 70
43103 - 78 78 78 46 46 46 22 22 22 6 6 6
43104 - 0 0 0 0 0 0 0 0 0 0 0 0
43105 - 0 0 0 0 0 0 0 0 0 0 0 0
43106 - 0 0 0 0 0 0 0 0 0 0 0 0
43107 - 0 0 0 0 0 0 0 0 0 0 0 0
43108 - 0 0 0 0 0 0 0 0 0 0 0 0
43109 - 0 0 0 0 0 0 0 0 0 0 0 0
43110 - 0 0 0 0 0 0 0 0 0 0 0 0
43111 - 0 0 0 0 0 0 0 0 0 0 0 0
43112 - 0 0 1 0 0 1 0 0 1 0 0 0
43113 - 0 0 0 0 0 0 0 0 0 0 0 0
43114 - 0 0 0 0 0 0 0 0 0 0 0 0
43115 - 0 0 0 0 0 0 0 0 0 0 0 0
43116 - 0 0 0 0 0 0 0 0 0 0 0 0
43117 - 0 0 0 0 0 0 0 0 0 0 0 0
43118 - 6 6 6 18 18 18 42 42 42 82 82 82
43119 - 26 26 26 2 2 6 2 2 6 2 2 6
43120 - 2 2 6 2 2 6 2 2 6 2 2 6
43121 - 2 2 6 2 2 6 2 2 6 14 14 14
43122 - 46 46 46 34 34 34 6 6 6 2 2 6
43123 - 42 42 42 78 78 78 42 42 42 18 18 18
43124 - 6 6 6 0 0 0 0 0 0 0 0 0
43125 - 0 0 0 0 0 0 0 0 0 0 0 0
43126 - 0 0 0 0 0 0 0 0 0 0 0 0
43127 - 0 0 0 0 0 0 0 0 0 0 0 0
43128 - 0 0 0 0 0 0 0 0 0 0 0 0
43129 - 0 0 0 0 0 0 0 0 0 0 0 0
43130 - 0 0 0 0 0 0 0 0 0 0 0 0
43131 - 0 0 0 0 0 0 0 0 0 0 0 0
43132 - 0 0 1 0 0 0 0 0 1 0 0 0
43133 - 0 0 0 0 0 0 0 0 0 0 0 0
43134 - 0 0 0 0 0 0 0 0 0 0 0 0
43135 - 0 0 0 0 0 0 0 0 0 0 0 0
43136 - 0 0 0 0 0 0 0 0 0 0 0 0
43137 - 0 0 0 0 0 0 0 0 0 0 0 0
43138 - 10 10 10 30 30 30 66 66 66 58 58 58
43139 - 2 2 6 2 2 6 2 2 6 2 2 6
43140 - 2 2 6 2 2 6 2 2 6 2 2 6
43141 - 2 2 6 2 2 6 2 2 6 26 26 26
43142 - 86 86 86 101 101 101 46 46 46 10 10 10
43143 - 2 2 6 58 58 58 70 70 70 34 34 34
43144 - 10 10 10 0 0 0 0 0 0 0 0 0
43145 - 0 0 0 0 0 0 0 0 0 0 0 0
43146 - 0 0 0 0 0 0 0 0 0 0 0 0
43147 - 0 0 0 0 0 0 0 0 0 0 0 0
43148 - 0 0 0 0 0 0 0 0 0 0 0 0
43149 - 0 0 0 0 0 0 0 0 0 0 0 0
43150 - 0 0 0 0 0 0 0 0 0 0 0 0
43151 - 0 0 0 0 0 0 0 0 0 0 0 0
43152 - 0 0 1 0 0 1 0 0 1 0 0 0
43153 - 0 0 0 0 0 0 0 0 0 0 0 0
43154 - 0 0 0 0 0 0 0 0 0 0 0 0
43155 - 0 0 0 0 0 0 0 0 0 0 0 0
43156 - 0 0 0 0 0 0 0 0 0 0 0 0
43157 - 0 0 0 0 0 0 0 0 0 0 0 0
43158 - 14 14 14 42 42 42 86 86 86 10 10 10
43159 - 2 2 6 2 2 6 2 2 6 2 2 6
43160 - 2 2 6 2 2 6 2 2 6 2 2 6
43161 - 2 2 6 2 2 6 2 2 6 30 30 30
43162 - 94 94 94 94 94 94 58 58 58 26 26 26
43163 - 2 2 6 6 6 6 78 78 78 54 54 54
43164 - 22 22 22 6 6 6 0 0 0 0 0 0
43165 - 0 0 0 0 0 0 0 0 0 0 0 0
43166 - 0 0 0 0 0 0 0 0 0 0 0 0
43167 - 0 0 0 0 0 0 0 0 0 0 0 0
43168 - 0 0 0 0 0 0 0 0 0 0 0 0
43169 - 0 0 0 0 0 0 0 0 0 0 0 0
43170 - 0 0 0 0 0 0 0 0 0 0 0 0
43171 - 0 0 0 0 0 0 0 0 0 0 0 0
43172 - 0 0 0 0 0 0 0 0 0 0 0 0
43173 - 0 0 0 0 0 0 0 0 0 0 0 0
43174 - 0 0 0 0 0 0 0 0 0 0 0 0
43175 - 0 0 0 0 0 0 0 0 0 0 0 0
43176 - 0 0 0 0 0 0 0 0 0 0 0 0
43177 - 0 0 0 0 0 0 0 0 0 6 6 6
43178 - 22 22 22 62 62 62 62 62 62 2 2 6
43179 - 2 2 6 2 2 6 2 2 6 2 2 6
43180 - 2 2 6 2 2 6 2 2 6 2 2 6
43181 - 2 2 6 2 2 6 2 2 6 26 26 26
43182 - 54 54 54 38 38 38 18 18 18 10 10 10
43183 - 2 2 6 2 2 6 34 34 34 82 82 82
43184 - 38 38 38 14 14 14 0 0 0 0 0 0
43185 - 0 0 0 0 0 0 0 0 0 0 0 0
43186 - 0 0 0 0 0 0 0 0 0 0 0 0
43187 - 0 0 0 0 0 0 0 0 0 0 0 0
43188 - 0 0 0 0 0 0 0 0 0 0 0 0
43189 - 0 0 0 0 0 0 0 0 0 0 0 0
43190 - 0 0 0 0 0 0 0 0 0 0 0 0
43191 - 0 0 0 0 0 0 0 0 0 0 0 0
43192 - 0 0 0 0 0 1 0 0 1 0 0 0
43193 - 0 0 0 0 0 0 0 0 0 0 0 0
43194 - 0 0 0 0 0 0 0 0 0 0 0 0
43195 - 0 0 0 0 0 0 0 0 0 0 0 0
43196 - 0 0 0 0 0 0 0 0 0 0 0 0
43197 - 0 0 0 0 0 0 0 0 0 6 6 6
43198 - 30 30 30 78 78 78 30 30 30 2 2 6
43199 - 2 2 6 2 2 6 2 2 6 2 2 6
43200 - 2 2 6 2 2 6 2 2 6 2 2 6
43201 - 2 2 6 2 2 6 2 2 6 10 10 10
43202 - 10 10 10 2 2 6 2 2 6 2 2 6
43203 - 2 2 6 2 2 6 2 2 6 78 78 78
43204 - 50 50 50 18 18 18 6 6 6 0 0 0
43205 - 0 0 0 0 0 0 0 0 0 0 0 0
43206 - 0 0 0 0 0 0 0 0 0 0 0 0
43207 - 0 0 0 0 0 0 0 0 0 0 0 0
43208 - 0 0 0 0 0 0 0 0 0 0 0 0
43209 - 0 0 0 0 0 0 0 0 0 0 0 0
43210 - 0 0 0 0 0 0 0 0 0 0 0 0
43211 - 0 0 0 0 0 0 0 0 0 0 0 0
43212 - 0 0 1 0 0 0 0 0 0 0 0 0
43213 - 0 0 0 0 0 0 0 0 0 0 0 0
43214 - 0 0 0 0 0 0 0 0 0 0 0 0
43215 - 0 0 0 0 0 0 0 0 0 0 0 0
43216 - 0 0 0 0 0 0 0 0 0 0 0 0
43217 - 0 0 0 0 0 0 0 0 0 10 10 10
43218 - 38 38 38 86 86 86 14 14 14 2 2 6
43219 - 2 2 6 2 2 6 2 2 6 2 2 6
43220 - 2 2 6 2 2 6 2 2 6 2 2 6
43221 - 2 2 6 2 2 6 2 2 6 2 2 6
43222 - 2 2 6 2 2 6 2 2 6 2 2 6
43223 - 2 2 6 2 2 6 2 2 6 54 54 54
43224 - 66 66 66 26 26 26 6 6 6 0 0 0
43225 - 0 0 0 0 0 0 0 0 0 0 0 0
43226 - 0 0 0 0 0 0 0 0 0 0 0 0
43227 - 0 0 0 0 0 0 0 0 0 0 0 0
43228 - 0 0 0 0 0 0 0 0 0 0 0 0
43229 - 0 0 0 0 0 0 0 0 0 0 0 0
43230 - 0 0 0 0 0 0 0 0 0 0 0 0
43231 - 0 0 0 0 0 0 0 0 0 0 0 0
43232 - 0 0 0 0 0 1 0 0 1 0 0 0
43233 - 0 0 0 0 0 0 0 0 0 0 0 0
43234 - 0 0 0 0 0 0 0 0 0 0 0 0
43235 - 0 0 0 0 0 0 0 0 0 0 0 0
43236 - 0 0 0 0 0 0 0 0 0 0 0 0
43237 - 0 0 0 0 0 0 0 0 0 14 14 14
43238 - 42 42 42 82 82 82 2 2 6 2 2 6
43239 - 2 2 6 6 6 6 10 10 10 2 2 6
43240 - 2 2 6 2 2 6 2 2 6 2 2 6
43241 - 2 2 6 2 2 6 2 2 6 6 6 6
43242 - 14 14 14 10 10 10 2 2 6 2 2 6
43243 - 2 2 6 2 2 6 2 2 6 18 18 18
43244 - 82 82 82 34 34 34 10 10 10 0 0 0
43245 - 0 0 0 0 0 0 0 0 0 0 0 0
43246 - 0 0 0 0 0 0 0 0 0 0 0 0
43247 - 0 0 0 0 0 0 0 0 0 0 0 0
43248 - 0 0 0 0 0 0 0 0 0 0 0 0
43249 - 0 0 0 0 0 0 0 0 0 0 0 0
43250 - 0 0 0 0 0 0 0 0 0 0 0 0
43251 - 0 0 0 0 0 0 0 0 0 0 0 0
43252 - 0 0 1 0 0 0 0 0 0 0 0 0
43253 - 0 0 0 0 0 0 0 0 0 0 0 0
43254 - 0 0 0 0 0 0 0 0 0 0 0 0
43255 - 0 0 0 0 0 0 0 0 0 0 0 0
43256 - 0 0 0 0 0 0 0 0 0 0 0 0
43257 - 0 0 0 0 0 0 0 0 0 14 14 14
43258 - 46 46 46 86 86 86 2 2 6 2 2 6
43259 - 6 6 6 6 6 6 22 22 22 34 34 34
43260 - 6 6 6 2 2 6 2 2 6 2 2 6
43261 - 2 2 6 2 2 6 18 18 18 34 34 34
43262 - 10 10 10 50 50 50 22 22 22 2 2 6
43263 - 2 2 6 2 2 6 2 2 6 10 10 10
43264 - 86 86 86 42 42 42 14 14 14 0 0 0
43265 - 0 0 0 0 0 0 0 0 0 0 0 0
43266 - 0 0 0 0 0 0 0 0 0 0 0 0
43267 - 0 0 0 0 0 0 0 0 0 0 0 0
43268 - 0 0 0 0 0 0 0 0 0 0 0 0
43269 - 0 0 0 0 0 0 0 0 0 0 0 0
43270 - 0 0 0 0 0 0 0 0 0 0 0 0
43271 - 0 0 0 0 0 0 0 0 0 0 0 0
43272 - 0 0 1 0 0 1 0 0 1 0 0 0
43273 - 0 0 0 0 0 0 0 0 0 0 0 0
43274 - 0 0 0 0 0 0 0 0 0 0 0 0
43275 - 0 0 0 0 0 0 0 0 0 0 0 0
43276 - 0 0 0 0 0 0 0 0 0 0 0 0
43277 - 0 0 0 0 0 0 0 0 0 14 14 14
43278 - 46 46 46 86 86 86 2 2 6 2 2 6
43279 - 38 38 38 116 116 116 94 94 94 22 22 22
43280 - 22 22 22 2 2 6 2 2 6 2 2 6
43281 - 14 14 14 86 86 86 138 138 138 162 162 162
43282 -154 154 154 38 38 38 26 26 26 6 6 6
43283 - 2 2 6 2 2 6 2 2 6 2 2 6
43284 - 86 86 86 46 46 46 14 14 14 0 0 0
43285 - 0 0 0 0 0 0 0 0 0 0 0 0
43286 - 0 0 0 0 0 0 0 0 0 0 0 0
43287 - 0 0 0 0 0 0 0 0 0 0 0 0
43288 - 0 0 0 0 0 0 0 0 0 0 0 0
43289 - 0 0 0 0 0 0 0 0 0 0 0 0
43290 - 0 0 0 0 0 0 0 0 0 0 0 0
43291 - 0 0 0 0 0 0 0 0 0 0 0 0
43292 - 0 0 0 0 0 0 0 0 0 0 0 0
43293 - 0 0 0 0 0 0 0 0 0 0 0 0
43294 - 0 0 0 0 0 0 0 0 0 0 0 0
43295 - 0 0 0 0 0 0 0 0 0 0 0 0
43296 - 0 0 0 0 0 0 0 0 0 0 0 0
43297 - 0 0 0 0 0 0 0 0 0 14 14 14
43298 - 46 46 46 86 86 86 2 2 6 14 14 14
43299 -134 134 134 198 198 198 195 195 195 116 116 116
43300 - 10 10 10 2 2 6 2 2 6 6 6 6
43301 -101 98 89 187 187 187 210 210 210 218 218 218
43302 -214 214 214 134 134 134 14 14 14 6 6 6
43303 - 2 2 6 2 2 6 2 2 6 2 2 6
43304 - 86 86 86 50 50 50 18 18 18 6 6 6
43305 - 0 0 0 0 0 0 0 0 0 0 0 0
43306 - 0 0 0 0 0 0 0 0 0 0 0 0
43307 - 0 0 0 0 0 0 0 0 0 0 0 0
43308 - 0 0 0 0 0 0 0 0 0 0 0 0
43309 - 0 0 0 0 0 0 0 0 0 0 0 0
43310 - 0 0 0 0 0 0 0 0 0 0 0 0
43311 - 0 0 0 0 0 0 0 0 1 0 0 0
43312 - 0 0 1 0 0 1 0 0 1 0 0 0
43313 - 0 0 0 0 0 0 0 0 0 0 0 0
43314 - 0 0 0 0 0 0 0 0 0 0 0 0
43315 - 0 0 0 0 0 0 0 0 0 0 0 0
43316 - 0 0 0 0 0 0 0 0 0 0 0 0
43317 - 0 0 0 0 0 0 0 0 0 14 14 14
43318 - 46 46 46 86 86 86 2 2 6 54 54 54
43319 -218 218 218 195 195 195 226 226 226 246 246 246
43320 - 58 58 58 2 2 6 2 2 6 30 30 30
43321 -210 210 210 253 253 253 174 174 174 123 123 123
43322 -221 221 221 234 234 234 74 74 74 2 2 6
43323 - 2 2 6 2 2 6 2 2 6 2 2 6
43324 - 70 70 70 58 58 58 22 22 22 6 6 6
43325 - 0 0 0 0 0 0 0 0 0 0 0 0
43326 - 0 0 0 0 0 0 0 0 0 0 0 0
43327 - 0 0 0 0 0 0 0 0 0 0 0 0
43328 - 0 0 0 0 0 0 0 0 0 0 0 0
43329 - 0 0 0 0 0 0 0 0 0 0 0 0
43330 - 0 0 0 0 0 0 0 0 0 0 0 0
43331 - 0 0 0 0 0 0 0 0 0 0 0 0
43332 - 0 0 0 0 0 0 0 0 0 0 0 0
43333 - 0 0 0 0 0 0 0 0 0 0 0 0
43334 - 0 0 0 0 0 0 0 0 0 0 0 0
43335 - 0 0 0 0 0 0 0 0 0 0 0 0
43336 - 0 0 0 0 0 0 0 0 0 0 0 0
43337 - 0 0 0 0 0 0 0 0 0 14 14 14
43338 - 46 46 46 82 82 82 2 2 6 106 106 106
43339 -170 170 170 26 26 26 86 86 86 226 226 226
43340 -123 123 123 10 10 10 14 14 14 46 46 46
43341 -231 231 231 190 190 190 6 6 6 70 70 70
43342 - 90 90 90 238 238 238 158 158 158 2 2 6
43343 - 2 2 6 2 2 6 2 2 6 2 2 6
43344 - 70 70 70 58 58 58 22 22 22 6 6 6
43345 - 0 0 0 0 0 0 0 0 0 0 0 0
43346 - 0 0 0 0 0 0 0 0 0 0 0 0
43347 - 0 0 0 0 0 0 0 0 0 0 0 0
43348 - 0 0 0 0 0 0 0 0 0 0 0 0
43349 - 0 0 0 0 0 0 0 0 0 0 0 0
43350 - 0 0 0 0 0 0 0 0 0 0 0 0
43351 - 0 0 0 0 0 0 0 0 1 0 0 0
43352 - 0 0 1 0 0 1 0 0 1 0 0 0
43353 - 0 0 0 0 0 0 0 0 0 0 0 0
43354 - 0 0 0 0 0 0 0 0 0 0 0 0
43355 - 0 0 0 0 0 0 0 0 0 0 0 0
43356 - 0 0 0 0 0 0 0 0 0 0 0 0
43357 - 0 0 0 0 0 0 0 0 0 14 14 14
43358 - 42 42 42 86 86 86 6 6 6 116 116 116
43359 -106 106 106 6 6 6 70 70 70 149 149 149
43360 -128 128 128 18 18 18 38 38 38 54 54 54
43361 -221 221 221 106 106 106 2 2 6 14 14 14
43362 - 46 46 46 190 190 190 198 198 198 2 2 6
43363 - 2 2 6 2 2 6 2 2 6 2 2 6
43364 - 74 74 74 62 62 62 22 22 22 6 6 6
43365 - 0 0 0 0 0 0 0 0 0 0 0 0
43366 - 0 0 0 0 0 0 0 0 0 0 0 0
43367 - 0 0 0 0 0 0 0 0 0 0 0 0
43368 - 0 0 0 0 0 0 0 0 0 0 0 0
43369 - 0 0 0 0 0 0 0 0 0 0 0 0
43370 - 0 0 0 0 0 0 0 0 0 0 0 0
43371 - 0 0 0 0 0 0 0 0 1 0 0 0
43372 - 0 0 1 0 0 0 0 0 1 0 0 0
43373 - 0 0 0 0 0 0 0 0 0 0 0 0
43374 - 0 0 0 0 0 0 0 0 0 0 0 0
43375 - 0 0 0 0 0 0 0 0 0 0 0 0
43376 - 0 0 0 0 0 0 0 0 0 0 0 0
43377 - 0 0 0 0 0 0 0 0 0 14 14 14
43378 - 42 42 42 94 94 94 14 14 14 101 101 101
43379 -128 128 128 2 2 6 18 18 18 116 116 116
43380 -118 98 46 121 92 8 121 92 8 98 78 10
43381 -162 162 162 106 106 106 2 2 6 2 2 6
43382 - 2 2 6 195 195 195 195 195 195 6 6 6
43383 - 2 2 6 2 2 6 2 2 6 2 2 6
43384 - 74 74 74 62 62 62 22 22 22 6 6 6
43385 - 0 0 0 0 0 0 0 0 0 0 0 0
43386 - 0 0 0 0 0 0 0 0 0 0 0 0
43387 - 0 0 0 0 0 0 0 0 0 0 0 0
43388 - 0 0 0 0 0 0 0 0 0 0 0 0
43389 - 0 0 0 0 0 0 0 0 0 0 0 0
43390 - 0 0 0 0 0 0 0 0 0 0 0 0
43391 - 0 0 0 0 0 0 0 0 1 0 0 1
43392 - 0 0 1 0 0 0 0 0 1 0 0 0
43393 - 0 0 0 0 0 0 0 0 0 0 0 0
43394 - 0 0 0 0 0 0 0 0 0 0 0 0
43395 - 0 0 0 0 0 0 0 0 0 0 0 0
43396 - 0 0 0 0 0 0 0 0 0 0 0 0
43397 - 0 0 0 0 0 0 0 0 0 10 10 10
43398 - 38 38 38 90 90 90 14 14 14 58 58 58
43399 -210 210 210 26 26 26 54 38 6 154 114 10
43400 -226 170 11 236 186 11 225 175 15 184 144 12
43401 -215 174 15 175 146 61 37 26 9 2 2 6
43402 - 70 70 70 246 246 246 138 138 138 2 2 6
43403 - 2 2 6 2 2 6 2 2 6 2 2 6
43404 - 70 70 70 66 66 66 26 26 26 6 6 6
43405 - 0 0 0 0 0 0 0 0 0 0 0 0
43406 - 0 0 0 0 0 0 0 0 0 0 0 0
43407 - 0 0 0 0 0 0 0 0 0 0 0 0
43408 - 0 0 0 0 0 0 0 0 0 0 0 0
43409 - 0 0 0 0 0 0 0 0 0 0 0 0
43410 - 0 0 0 0 0 0 0 0 0 0 0 0
43411 - 0 0 0 0 0 0 0 0 0 0 0 0
43412 - 0 0 0 0 0 0 0 0 0 0 0 0
43413 - 0 0 0 0 0 0 0 0 0 0 0 0
43414 - 0 0 0 0 0 0 0 0 0 0 0 0
43415 - 0 0 0 0 0 0 0 0 0 0 0 0
43416 - 0 0 0 0 0 0 0 0 0 0 0 0
43417 - 0 0 0 0 0 0 0 0 0 10 10 10
43418 - 38 38 38 86 86 86 14 14 14 10 10 10
43419 -195 195 195 188 164 115 192 133 9 225 175 15
43420 -239 182 13 234 190 10 232 195 16 232 200 30
43421 -245 207 45 241 208 19 232 195 16 184 144 12
43422 -218 194 134 211 206 186 42 42 42 2 2 6
43423 - 2 2 6 2 2 6 2 2 6 2 2 6
43424 - 50 50 50 74 74 74 30 30 30 6 6 6
43425 - 0 0 0 0 0 0 0 0 0 0 0 0
43426 - 0 0 0 0 0 0 0 0 0 0 0 0
43427 - 0 0 0 0 0 0 0 0 0 0 0 0
43428 - 0 0 0 0 0 0 0 0 0 0 0 0
43429 - 0 0 0 0 0 0 0 0 0 0 0 0
43430 - 0 0 0 0 0 0 0 0 0 0 0 0
43431 - 0 0 0 0 0 0 0 0 0 0 0 0
43432 - 0 0 0 0 0 0 0 0 0 0 0 0
43433 - 0 0 0 0 0 0 0 0 0 0 0 0
43434 - 0 0 0 0 0 0 0 0 0 0 0 0
43435 - 0 0 0 0 0 0 0 0 0 0 0 0
43436 - 0 0 0 0 0 0 0 0 0 0 0 0
43437 - 0 0 0 0 0 0 0 0 0 10 10 10
43438 - 34 34 34 86 86 86 14 14 14 2 2 6
43439 -121 87 25 192 133 9 219 162 10 239 182 13
43440 -236 186 11 232 195 16 241 208 19 244 214 54
43441 -246 218 60 246 218 38 246 215 20 241 208 19
43442 -241 208 19 226 184 13 121 87 25 2 2 6
43443 - 2 2 6 2 2 6 2 2 6 2 2 6
43444 - 50 50 50 82 82 82 34 34 34 10 10 10
43445 - 0 0 0 0 0 0 0 0 0 0 0 0
43446 - 0 0 0 0 0 0 0 0 0 0 0 0
43447 - 0 0 0 0 0 0 0 0 0 0 0 0
43448 - 0 0 0 0 0 0 0 0 0 0 0 0
43449 - 0 0 0 0 0 0 0 0 0 0 0 0
43450 - 0 0 0 0 0 0 0 0 0 0 0 0
43451 - 0 0 0 0 0 0 0 0 0 0 0 0
43452 - 0 0 0 0 0 0 0 0 0 0 0 0
43453 - 0 0 0 0 0 0 0 0 0 0 0 0
43454 - 0 0 0 0 0 0 0 0 0 0 0 0
43455 - 0 0 0 0 0 0 0 0 0 0 0 0
43456 - 0 0 0 0 0 0 0 0 0 0 0 0
43457 - 0 0 0 0 0 0 0 0 0 10 10 10
43458 - 34 34 34 82 82 82 30 30 30 61 42 6
43459 -180 123 7 206 145 10 230 174 11 239 182 13
43460 -234 190 10 238 202 15 241 208 19 246 218 74
43461 -246 218 38 246 215 20 246 215 20 246 215 20
43462 -226 184 13 215 174 15 184 144 12 6 6 6
43463 - 2 2 6 2 2 6 2 2 6 2 2 6
43464 - 26 26 26 94 94 94 42 42 42 14 14 14
43465 - 0 0 0 0 0 0 0 0 0 0 0 0
43466 - 0 0 0 0 0 0 0 0 0 0 0 0
43467 - 0 0 0 0 0 0 0 0 0 0 0 0
43468 - 0 0 0 0 0 0 0 0 0 0 0 0
43469 - 0 0 0 0 0 0 0 0 0 0 0 0
43470 - 0 0 0 0 0 0 0 0 0 0 0 0
43471 - 0 0 0 0 0 0 0 0 0 0 0 0
43472 - 0 0 0 0 0 0 0 0 0 0 0 0
43473 - 0 0 0 0 0 0 0 0 0 0 0 0
43474 - 0 0 0 0 0 0 0 0 0 0 0 0
43475 - 0 0 0 0 0 0 0 0 0 0 0 0
43476 - 0 0 0 0 0 0 0 0 0 0 0 0
43477 - 0 0 0 0 0 0 0 0 0 10 10 10
43478 - 30 30 30 78 78 78 50 50 50 104 69 6
43479 -192 133 9 216 158 10 236 178 12 236 186 11
43480 -232 195 16 241 208 19 244 214 54 245 215 43
43481 -246 215 20 246 215 20 241 208 19 198 155 10
43482 -200 144 11 216 158 10 156 118 10 2 2 6
43483 - 2 2 6 2 2 6 2 2 6 2 2 6
43484 - 6 6 6 90 90 90 54 54 54 18 18 18
43485 - 6 6 6 0 0 0 0 0 0 0 0 0
43486 - 0 0 0 0 0 0 0 0 0 0 0 0
43487 - 0 0 0 0 0 0 0 0 0 0 0 0
43488 - 0 0 0 0 0 0 0 0 0 0 0 0
43489 - 0 0 0 0 0 0 0 0 0 0 0 0
43490 - 0 0 0 0 0 0 0 0 0 0 0 0
43491 - 0 0 0 0 0 0 0 0 0 0 0 0
43492 - 0 0 0 0 0 0 0 0 0 0 0 0
43493 - 0 0 0 0 0 0 0 0 0 0 0 0
43494 - 0 0 0 0 0 0 0 0 0 0 0 0
43495 - 0 0 0 0 0 0 0 0 0 0 0 0
43496 - 0 0 0 0 0 0 0 0 0 0 0 0
43497 - 0 0 0 0 0 0 0 0 0 10 10 10
43498 - 30 30 30 78 78 78 46 46 46 22 22 22
43499 -137 92 6 210 162 10 239 182 13 238 190 10
43500 -238 202 15 241 208 19 246 215 20 246 215 20
43501 -241 208 19 203 166 17 185 133 11 210 150 10
43502 -216 158 10 210 150 10 102 78 10 2 2 6
43503 - 6 6 6 54 54 54 14 14 14 2 2 6
43504 - 2 2 6 62 62 62 74 74 74 30 30 30
43505 - 10 10 10 0 0 0 0 0 0 0 0 0
43506 - 0 0 0 0 0 0 0 0 0 0 0 0
43507 - 0 0 0 0 0 0 0 0 0 0 0 0
43508 - 0 0 0 0 0 0 0 0 0 0 0 0
43509 - 0 0 0 0 0 0 0 0 0 0 0 0
43510 - 0 0 0 0 0 0 0 0 0 0 0 0
43511 - 0 0 0 0 0 0 0 0 0 0 0 0
43512 - 0 0 0 0 0 0 0 0 0 0 0 0
43513 - 0 0 0 0 0 0 0 0 0 0 0 0
43514 - 0 0 0 0 0 0 0 0 0 0 0 0
43515 - 0 0 0 0 0 0 0 0 0 0 0 0
43516 - 0 0 0 0 0 0 0 0 0 0 0 0
43517 - 0 0 0 0 0 0 0 0 0 10 10 10
43518 - 34 34 34 78 78 78 50 50 50 6 6 6
43519 - 94 70 30 139 102 15 190 146 13 226 184 13
43520 -232 200 30 232 195 16 215 174 15 190 146 13
43521 -168 122 10 192 133 9 210 150 10 213 154 11
43522 -202 150 34 182 157 106 101 98 89 2 2 6
43523 - 2 2 6 78 78 78 116 116 116 58 58 58
43524 - 2 2 6 22 22 22 90 90 90 46 46 46
43525 - 18 18 18 6 6 6 0 0 0 0 0 0
43526 - 0 0 0 0 0 0 0 0 0 0 0 0
43527 - 0 0 0 0 0 0 0 0 0 0 0 0
43528 - 0 0 0 0 0 0 0 0 0 0 0 0
43529 - 0 0 0 0 0 0 0 0 0 0 0 0
43530 - 0 0 0 0 0 0 0 0 0 0 0 0
43531 - 0 0 0 0 0 0 0 0 0 0 0 0
43532 - 0 0 0 0 0 0 0 0 0 0 0 0
43533 - 0 0 0 0 0 0 0 0 0 0 0 0
43534 - 0 0 0 0 0 0 0 0 0 0 0 0
43535 - 0 0 0 0 0 0 0 0 0 0 0 0
43536 - 0 0 0 0 0 0 0 0 0 0 0 0
43537 - 0 0 0 0 0 0 0 0 0 10 10 10
43538 - 38 38 38 86 86 86 50 50 50 6 6 6
43539 -128 128 128 174 154 114 156 107 11 168 122 10
43540 -198 155 10 184 144 12 197 138 11 200 144 11
43541 -206 145 10 206 145 10 197 138 11 188 164 115
43542 -195 195 195 198 198 198 174 174 174 14 14 14
43543 - 2 2 6 22 22 22 116 116 116 116 116 116
43544 - 22 22 22 2 2 6 74 74 74 70 70 70
43545 - 30 30 30 10 10 10 0 0 0 0 0 0
43546 - 0 0 0 0 0 0 0 0 0 0 0 0
43547 - 0 0 0 0 0 0 0 0 0 0 0 0
43548 - 0 0 0 0 0 0 0 0 0 0 0 0
43549 - 0 0 0 0 0 0 0 0 0 0 0 0
43550 - 0 0 0 0 0 0 0 0 0 0 0 0
43551 - 0 0 0 0 0 0 0 0 0 0 0 0
43552 - 0 0 0 0 0 0 0 0 0 0 0 0
43553 - 0 0 0 0 0 0 0 0 0 0 0 0
43554 - 0 0 0 0 0 0 0 0 0 0 0 0
43555 - 0 0 0 0 0 0 0 0 0 0 0 0
43556 - 0 0 0 0 0 0 0 0 0 0 0 0
43557 - 0 0 0 0 0 0 6 6 6 18 18 18
43558 - 50 50 50 101 101 101 26 26 26 10 10 10
43559 -138 138 138 190 190 190 174 154 114 156 107 11
43560 -197 138 11 200 144 11 197 138 11 192 133 9
43561 -180 123 7 190 142 34 190 178 144 187 187 187
43562 -202 202 202 221 221 221 214 214 214 66 66 66
43563 - 2 2 6 2 2 6 50 50 50 62 62 62
43564 - 6 6 6 2 2 6 10 10 10 90 90 90
43565 - 50 50 50 18 18 18 6 6 6 0 0 0
43566 - 0 0 0 0 0 0 0 0 0 0 0 0
43567 - 0 0 0 0 0 0 0 0 0 0 0 0
43568 - 0 0 0 0 0 0 0 0 0 0 0 0
43569 - 0 0 0 0 0 0 0 0 0 0 0 0
43570 - 0 0 0 0 0 0 0 0 0 0 0 0
43571 - 0 0 0 0 0 0 0 0 0 0 0 0
43572 - 0 0 0 0 0 0 0 0 0 0 0 0
43573 - 0 0 0 0 0 0 0 0 0 0 0 0
43574 - 0 0 0 0 0 0 0 0 0 0 0 0
43575 - 0 0 0 0 0 0 0 0 0 0 0 0
43576 - 0 0 0 0 0 0 0 0 0 0 0 0
43577 - 0 0 0 0 0 0 10 10 10 34 34 34
43578 - 74 74 74 74 74 74 2 2 6 6 6 6
43579 -144 144 144 198 198 198 190 190 190 178 166 146
43580 -154 121 60 156 107 11 156 107 11 168 124 44
43581 -174 154 114 187 187 187 190 190 190 210 210 210
43582 -246 246 246 253 253 253 253 253 253 182 182 182
43583 - 6 6 6 2 2 6 2 2 6 2 2 6
43584 - 2 2 6 2 2 6 2 2 6 62 62 62
43585 - 74 74 74 34 34 34 14 14 14 0 0 0
43586 - 0 0 0 0 0 0 0 0 0 0 0 0
43587 - 0 0 0 0 0 0 0 0 0 0 0 0
43588 - 0 0 0 0 0 0 0 0 0 0 0 0
43589 - 0 0 0 0 0 0 0 0 0 0 0 0
43590 - 0 0 0 0 0 0 0 0 0 0 0 0
43591 - 0 0 0 0 0 0 0 0 0 0 0 0
43592 - 0 0 0 0 0 0 0 0 0 0 0 0
43593 - 0 0 0 0 0 0 0 0 0 0 0 0
43594 - 0 0 0 0 0 0 0 0 0 0 0 0
43595 - 0 0 0 0 0 0 0 0 0 0 0 0
43596 - 0 0 0 0 0 0 0 0 0 0 0 0
43597 - 0 0 0 10 10 10 22 22 22 54 54 54
43598 - 94 94 94 18 18 18 2 2 6 46 46 46
43599 -234 234 234 221 221 221 190 190 190 190 190 190
43600 -190 190 190 187 187 187 187 187 187 190 190 190
43601 -190 190 190 195 195 195 214 214 214 242 242 242
43602 -253 253 253 253 253 253 253 253 253 253 253 253
43603 - 82 82 82 2 2 6 2 2 6 2 2 6
43604 - 2 2 6 2 2 6 2 2 6 14 14 14
43605 - 86 86 86 54 54 54 22 22 22 6 6 6
43606 - 0 0 0 0 0 0 0 0 0 0 0 0
43607 - 0 0 0 0 0 0 0 0 0 0 0 0
43608 - 0 0 0 0 0 0 0 0 0 0 0 0
43609 - 0 0 0 0 0 0 0 0 0 0 0 0
43610 - 0 0 0 0 0 0 0 0 0 0 0 0
43611 - 0 0 0 0 0 0 0 0 0 0 0 0
43612 - 0 0 0 0 0 0 0 0 0 0 0 0
43613 - 0 0 0 0 0 0 0 0 0 0 0 0
43614 - 0 0 0 0 0 0 0 0 0 0 0 0
43615 - 0 0 0 0 0 0 0 0 0 0 0 0
43616 - 0 0 0 0 0 0 0 0 0 0 0 0
43617 - 6 6 6 18 18 18 46 46 46 90 90 90
43618 - 46 46 46 18 18 18 6 6 6 182 182 182
43619 -253 253 253 246 246 246 206 206 206 190 190 190
43620 -190 190 190 190 190 190 190 190 190 190 190 190
43621 -206 206 206 231 231 231 250 250 250 253 253 253
43622 -253 253 253 253 253 253 253 253 253 253 253 253
43623 -202 202 202 14 14 14 2 2 6 2 2 6
43624 - 2 2 6 2 2 6 2 2 6 2 2 6
43625 - 42 42 42 86 86 86 42 42 42 18 18 18
43626 - 6 6 6 0 0 0 0 0 0 0 0 0
43627 - 0 0 0 0 0 0 0 0 0 0 0 0
43628 - 0 0 0 0 0 0 0 0 0 0 0 0
43629 - 0 0 0 0 0 0 0 0 0 0 0 0
43630 - 0 0 0 0 0 0 0 0 0 0 0 0
43631 - 0 0 0 0 0 0 0 0 0 0 0 0
43632 - 0 0 0 0 0 0 0 0 0 0 0 0
43633 - 0 0 0 0 0 0 0 0 0 0 0 0
43634 - 0 0 0 0 0 0 0 0 0 0 0 0
43635 - 0 0 0 0 0 0 0 0 0 0 0 0
43636 - 0 0 0 0 0 0 0 0 0 6 6 6
43637 - 14 14 14 38 38 38 74 74 74 66 66 66
43638 - 2 2 6 6 6 6 90 90 90 250 250 250
43639 -253 253 253 253 253 253 238 238 238 198 198 198
43640 -190 190 190 190 190 190 195 195 195 221 221 221
43641 -246 246 246 253 253 253 253 253 253 253 253 253
43642 -253 253 253 253 253 253 253 253 253 253 253 253
43643 -253 253 253 82 82 82 2 2 6 2 2 6
43644 - 2 2 6 2 2 6 2 2 6 2 2 6
43645 - 2 2 6 78 78 78 70 70 70 34 34 34
43646 - 14 14 14 6 6 6 0 0 0 0 0 0
43647 - 0 0 0 0 0 0 0 0 0 0 0 0
43648 - 0 0 0 0 0 0 0 0 0 0 0 0
43649 - 0 0 0 0 0 0 0 0 0 0 0 0
43650 - 0 0 0 0 0 0 0 0 0 0 0 0
43651 - 0 0 0 0 0 0 0 0 0 0 0 0
43652 - 0 0 0 0 0 0 0 0 0 0 0 0
43653 - 0 0 0 0 0 0 0 0 0 0 0 0
43654 - 0 0 0 0 0 0 0 0 0 0 0 0
43655 - 0 0 0 0 0 0 0 0 0 0 0 0
43656 - 0 0 0 0 0 0 0 0 0 14 14 14
43657 - 34 34 34 66 66 66 78 78 78 6 6 6
43658 - 2 2 6 18 18 18 218 218 218 253 253 253
43659 -253 253 253 253 253 253 253 253 253 246 246 246
43660 -226 226 226 231 231 231 246 246 246 253 253 253
43661 -253 253 253 253 253 253 253 253 253 253 253 253
43662 -253 253 253 253 253 253 253 253 253 253 253 253
43663 -253 253 253 178 178 178 2 2 6 2 2 6
43664 - 2 2 6 2 2 6 2 2 6 2 2 6
43665 - 2 2 6 18 18 18 90 90 90 62 62 62
43666 - 30 30 30 10 10 10 0 0 0 0 0 0
43667 - 0 0 0 0 0 0 0 0 0 0 0 0
43668 - 0 0 0 0 0 0 0 0 0 0 0 0
43669 - 0 0 0 0 0 0 0 0 0 0 0 0
43670 - 0 0 0 0 0 0 0 0 0 0 0 0
43671 - 0 0 0 0 0 0 0 0 0 0 0 0
43672 - 0 0 0 0 0 0 0 0 0 0 0 0
43673 - 0 0 0 0 0 0 0 0 0 0 0 0
43674 - 0 0 0 0 0 0 0 0 0 0 0 0
43675 - 0 0 0 0 0 0 0 0 0 0 0 0
43676 - 0 0 0 0 0 0 10 10 10 26 26 26
43677 - 58 58 58 90 90 90 18 18 18 2 2 6
43678 - 2 2 6 110 110 110 253 253 253 253 253 253
43679 -253 253 253 253 253 253 253 253 253 253 253 253
43680 -250 250 250 253 253 253 253 253 253 253 253 253
43681 -253 253 253 253 253 253 253 253 253 253 253 253
43682 -253 253 253 253 253 253 253 253 253 253 253 253
43683 -253 253 253 231 231 231 18 18 18 2 2 6
43684 - 2 2 6 2 2 6 2 2 6 2 2 6
43685 - 2 2 6 2 2 6 18 18 18 94 94 94
43686 - 54 54 54 26 26 26 10 10 10 0 0 0
43687 - 0 0 0 0 0 0 0 0 0 0 0 0
43688 - 0 0 0 0 0 0 0 0 0 0 0 0
43689 - 0 0 0 0 0 0 0 0 0 0 0 0
43690 - 0 0 0 0 0 0 0 0 0 0 0 0
43691 - 0 0 0 0 0 0 0 0 0 0 0 0
43692 - 0 0 0 0 0 0 0 0 0 0 0 0
43693 - 0 0 0 0 0 0 0 0 0 0 0 0
43694 - 0 0 0 0 0 0 0 0 0 0 0 0
43695 - 0 0 0 0 0 0 0 0 0 0 0 0
43696 - 0 0 0 6 6 6 22 22 22 50 50 50
43697 - 90 90 90 26 26 26 2 2 6 2 2 6
43698 - 14 14 14 195 195 195 250 250 250 253 253 253
43699 -253 253 253 253 253 253 253 253 253 253 253 253
43700 -253 253 253 253 253 253 253 253 253 253 253 253
43701 -253 253 253 253 253 253 253 253 253 253 253 253
43702 -253 253 253 253 253 253 253 253 253 253 253 253
43703 -250 250 250 242 242 242 54 54 54 2 2 6
43704 - 2 2 6 2 2 6 2 2 6 2 2 6
43705 - 2 2 6 2 2 6 2 2 6 38 38 38
43706 - 86 86 86 50 50 50 22 22 22 6 6 6
43707 - 0 0 0 0 0 0 0 0 0 0 0 0
43708 - 0 0 0 0 0 0 0 0 0 0 0 0
43709 - 0 0 0 0 0 0 0 0 0 0 0 0
43710 - 0 0 0 0 0 0 0 0 0 0 0 0
43711 - 0 0 0 0 0 0 0 0 0 0 0 0
43712 - 0 0 0 0 0 0 0 0 0 0 0 0
43713 - 0 0 0 0 0 0 0 0 0 0 0 0
43714 - 0 0 0 0 0 0 0 0 0 0 0 0
43715 - 0 0 0 0 0 0 0 0 0 0 0 0
43716 - 6 6 6 14 14 14 38 38 38 82 82 82
43717 - 34 34 34 2 2 6 2 2 6 2 2 6
43718 - 42 42 42 195 195 195 246 246 246 253 253 253
43719 -253 253 253 253 253 253 253 253 253 250 250 250
43720 -242 242 242 242 242 242 250 250 250 253 253 253
43721 -253 253 253 253 253 253 253 253 253 253 253 253
43722 -253 253 253 250 250 250 246 246 246 238 238 238
43723 -226 226 226 231 231 231 101 101 101 6 6 6
43724 - 2 2 6 2 2 6 2 2 6 2 2 6
43725 - 2 2 6 2 2 6 2 2 6 2 2 6
43726 - 38 38 38 82 82 82 42 42 42 14 14 14
43727 - 6 6 6 0 0 0 0 0 0 0 0 0
43728 - 0 0 0 0 0 0 0 0 0 0 0 0
43729 - 0 0 0 0 0 0 0 0 0 0 0 0
43730 - 0 0 0 0 0 0 0 0 0 0 0 0
43731 - 0 0 0 0 0 0 0 0 0 0 0 0
43732 - 0 0 0 0 0 0 0 0 0 0 0 0
43733 - 0 0 0 0 0 0 0 0 0 0 0 0
43734 - 0 0 0 0 0 0 0 0 0 0 0 0
43735 - 0 0 0 0 0 0 0 0 0 0 0 0
43736 - 10 10 10 26 26 26 62 62 62 66 66 66
43737 - 2 2 6 2 2 6 2 2 6 6 6 6
43738 - 70 70 70 170 170 170 206 206 206 234 234 234
43739 -246 246 246 250 250 250 250 250 250 238 238 238
43740 -226 226 226 231 231 231 238 238 238 250 250 250
43741 -250 250 250 250 250 250 246 246 246 231 231 231
43742 -214 214 214 206 206 206 202 202 202 202 202 202
43743 -198 198 198 202 202 202 182 182 182 18 18 18
43744 - 2 2 6 2 2 6 2 2 6 2 2 6
43745 - 2 2 6 2 2 6 2 2 6 2 2 6
43746 - 2 2 6 62 62 62 66 66 66 30 30 30
43747 - 10 10 10 0 0 0 0 0 0 0 0 0
43748 - 0 0 0 0 0 0 0 0 0 0 0 0
43749 - 0 0 0 0 0 0 0 0 0 0 0 0
43750 - 0 0 0 0 0 0 0 0 0 0 0 0
43751 - 0 0 0 0 0 0 0 0 0 0 0 0
43752 - 0 0 0 0 0 0 0 0 0 0 0 0
43753 - 0 0 0 0 0 0 0 0 0 0 0 0
43754 - 0 0 0 0 0 0 0 0 0 0 0 0
43755 - 0 0 0 0 0 0 0 0 0 0 0 0
43756 - 14 14 14 42 42 42 82 82 82 18 18 18
43757 - 2 2 6 2 2 6 2 2 6 10 10 10
43758 - 94 94 94 182 182 182 218 218 218 242 242 242
43759 -250 250 250 253 253 253 253 253 253 250 250 250
43760 -234 234 234 253 253 253 253 253 253 253 253 253
43761 -253 253 253 253 253 253 253 253 253 246 246 246
43762 -238 238 238 226 226 226 210 210 210 202 202 202
43763 -195 195 195 195 195 195 210 210 210 158 158 158
43764 - 6 6 6 14 14 14 50 50 50 14 14 14
43765 - 2 2 6 2 2 6 2 2 6 2 2 6
43766 - 2 2 6 6 6 6 86 86 86 46 46 46
43767 - 18 18 18 6 6 6 0 0 0 0 0 0
43768 - 0 0 0 0 0 0 0 0 0 0 0 0
43769 - 0 0 0 0 0 0 0 0 0 0 0 0
43770 - 0 0 0 0 0 0 0 0 0 0 0 0
43771 - 0 0 0 0 0 0 0 0 0 0 0 0
43772 - 0 0 0 0 0 0 0 0 0 0 0 0
43773 - 0 0 0 0 0 0 0 0 0 0 0 0
43774 - 0 0 0 0 0 0 0 0 0 0 0 0
43775 - 0 0 0 0 0 0 0 0 0 6 6 6
43776 - 22 22 22 54 54 54 70 70 70 2 2 6
43777 - 2 2 6 10 10 10 2 2 6 22 22 22
43778 -166 166 166 231 231 231 250 250 250 253 253 253
43779 -253 253 253 253 253 253 253 253 253 250 250 250
43780 -242 242 242 253 253 253 253 253 253 253 253 253
43781 -253 253 253 253 253 253 253 253 253 253 253 253
43782 -253 253 253 253 253 253 253 253 253 246 246 246
43783 -231 231 231 206 206 206 198 198 198 226 226 226
43784 - 94 94 94 2 2 6 6 6 6 38 38 38
43785 - 30 30 30 2 2 6 2 2 6 2 2 6
43786 - 2 2 6 2 2 6 62 62 62 66 66 66
43787 - 26 26 26 10 10 10 0 0 0 0 0 0
43788 - 0 0 0 0 0 0 0 0 0 0 0 0
43789 - 0 0 0 0 0 0 0 0 0 0 0 0
43790 - 0 0 0 0 0 0 0 0 0 0 0 0
43791 - 0 0 0 0 0 0 0 0 0 0 0 0
43792 - 0 0 0 0 0 0 0 0 0 0 0 0
43793 - 0 0 0 0 0 0 0 0 0 0 0 0
43794 - 0 0 0 0 0 0 0 0 0 0 0 0
43795 - 0 0 0 0 0 0 0 0 0 10 10 10
43796 - 30 30 30 74 74 74 50 50 50 2 2 6
43797 - 26 26 26 26 26 26 2 2 6 106 106 106
43798 -238 238 238 253 253 253 253 253 253 253 253 253
43799 -253 253 253 253 253 253 253 253 253 253 253 253
43800 -253 253 253 253 253 253 253 253 253 253 253 253
43801 -253 253 253 253 253 253 253 253 253 253 253 253
43802 -253 253 253 253 253 253 253 253 253 253 253 253
43803 -253 253 253 246 246 246 218 218 218 202 202 202
43804 -210 210 210 14 14 14 2 2 6 2 2 6
43805 - 30 30 30 22 22 22 2 2 6 2 2 6
43806 - 2 2 6 2 2 6 18 18 18 86 86 86
43807 - 42 42 42 14 14 14 0 0 0 0 0 0
43808 - 0 0 0 0 0 0 0 0 0 0 0 0
43809 - 0 0 0 0 0 0 0 0 0 0 0 0
43810 - 0 0 0 0 0 0 0 0 0 0 0 0
43811 - 0 0 0 0 0 0 0 0 0 0 0 0
43812 - 0 0 0 0 0 0 0 0 0 0 0 0
43813 - 0 0 0 0 0 0 0 0 0 0 0 0
43814 - 0 0 0 0 0 0 0 0 0 0 0 0
43815 - 0 0 0 0 0 0 0 0 0 14 14 14
43816 - 42 42 42 90 90 90 22 22 22 2 2 6
43817 - 42 42 42 2 2 6 18 18 18 218 218 218
43818 -253 253 253 253 253 253 253 253 253 253 253 253
43819 -253 253 253 253 253 253 253 253 253 253 253 253
43820 -253 253 253 253 253 253 253 253 253 253 253 253
43821 -253 253 253 253 253 253 253 253 253 253 253 253
43822 -253 253 253 253 253 253 253 253 253 253 253 253
43823 -253 253 253 253 253 253 250 250 250 221 221 221
43824 -218 218 218 101 101 101 2 2 6 14 14 14
43825 - 18 18 18 38 38 38 10 10 10 2 2 6
43826 - 2 2 6 2 2 6 2 2 6 78 78 78
43827 - 58 58 58 22 22 22 6 6 6 0 0 0
43828 - 0 0 0 0 0 0 0 0 0 0 0 0
43829 - 0 0 0 0 0 0 0 0 0 0 0 0
43830 - 0 0 0 0 0 0 0 0 0 0 0 0
43831 - 0 0 0 0 0 0 0 0 0 0 0 0
43832 - 0 0 0 0 0 0 0 0 0 0 0 0
43833 - 0 0 0 0 0 0 0 0 0 0 0 0
43834 - 0 0 0 0 0 0 0 0 0 0 0 0
43835 - 0 0 0 0 0 0 6 6 6 18 18 18
43836 - 54 54 54 82 82 82 2 2 6 26 26 26
43837 - 22 22 22 2 2 6 123 123 123 253 253 253
43838 -253 253 253 253 253 253 253 253 253 253 253 253
43839 -253 253 253 253 253 253 253 253 253 253 253 253
43840 -253 253 253 253 253 253 253 253 253 253 253 253
43841 -253 253 253 253 253 253 253 253 253 253 253 253
43842 -253 253 253 253 253 253 253 253 253 253 253 253
43843 -253 253 253 253 253 253 253 253 253 250 250 250
43844 -238 238 238 198 198 198 6 6 6 38 38 38
43845 - 58 58 58 26 26 26 38 38 38 2 2 6
43846 - 2 2 6 2 2 6 2 2 6 46 46 46
43847 - 78 78 78 30 30 30 10 10 10 0 0 0
43848 - 0 0 0 0 0 0 0 0 0 0 0 0
43849 - 0 0 0 0 0 0 0 0 0 0 0 0
43850 - 0 0 0 0 0 0 0 0 0 0 0 0
43851 - 0 0 0 0 0 0 0 0 0 0 0 0
43852 - 0 0 0 0 0 0 0 0 0 0 0 0
43853 - 0 0 0 0 0 0 0 0 0 0 0 0
43854 - 0 0 0 0 0 0 0 0 0 0 0 0
43855 - 0 0 0 0 0 0 10 10 10 30 30 30
43856 - 74 74 74 58 58 58 2 2 6 42 42 42
43857 - 2 2 6 22 22 22 231 231 231 253 253 253
43858 -253 253 253 253 253 253 253 253 253 253 253 253
43859 -253 253 253 253 253 253 253 253 253 250 250 250
43860 -253 253 253 253 253 253 253 253 253 253 253 253
43861 -253 253 253 253 253 253 253 253 253 253 253 253
43862 -253 253 253 253 253 253 253 253 253 253 253 253
43863 -253 253 253 253 253 253 253 253 253 253 253 253
43864 -253 253 253 246 246 246 46 46 46 38 38 38
43865 - 42 42 42 14 14 14 38 38 38 14 14 14
43866 - 2 2 6 2 2 6 2 2 6 6 6 6
43867 - 86 86 86 46 46 46 14 14 14 0 0 0
43868 - 0 0 0 0 0 0 0 0 0 0 0 0
43869 - 0 0 0 0 0 0 0 0 0 0 0 0
43870 - 0 0 0 0 0 0 0 0 0 0 0 0
43871 - 0 0 0 0 0 0 0 0 0 0 0 0
43872 - 0 0 0 0 0 0 0 0 0 0 0 0
43873 - 0 0 0 0 0 0 0 0 0 0 0 0
43874 - 0 0 0 0 0 0 0 0 0 0 0 0
43875 - 0 0 0 6 6 6 14 14 14 42 42 42
43876 - 90 90 90 18 18 18 18 18 18 26 26 26
43877 - 2 2 6 116 116 116 253 253 253 253 253 253
43878 -253 253 253 253 253 253 253 253 253 253 253 253
43879 -253 253 253 253 253 253 250 250 250 238 238 238
43880 -253 253 253 253 253 253 253 253 253 253 253 253
43881 -253 253 253 253 253 253 253 253 253 253 253 253
43882 -253 253 253 253 253 253 253 253 253 253 253 253
43883 -253 253 253 253 253 253 253 253 253 253 253 253
43884 -253 253 253 253 253 253 94 94 94 6 6 6
43885 - 2 2 6 2 2 6 10 10 10 34 34 34
43886 - 2 2 6 2 2 6 2 2 6 2 2 6
43887 - 74 74 74 58 58 58 22 22 22 6 6 6
43888 - 0 0 0 0 0 0 0 0 0 0 0 0
43889 - 0 0 0 0 0 0 0 0 0 0 0 0
43890 - 0 0 0 0 0 0 0 0 0 0 0 0
43891 - 0 0 0 0 0 0 0 0 0 0 0 0
43892 - 0 0 0 0 0 0 0 0 0 0 0 0
43893 - 0 0 0 0 0 0 0 0 0 0 0 0
43894 - 0 0 0 0 0 0 0 0 0 0 0 0
43895 - 0 0 0 10 10 10 26 26 26 66 66 66
43896 - 82 82 82 2 2 6 38 38 38 6 6 6
43897 - 14 14 14 210 210 210 253 253 253 253 253 253
43898 -253 253 253 253 253 253 253 253 253 253 253 253
43899 -253 253 253 253 253 253 246 246 246 242 242 242
43900 -253 253 253 253 253 253 253 253 253 253 253 253
43901 -253 253 253 253 253 253 253 253 253 253 253 253
43902 -253 253 253 253 253 253 253 253 253 253 253 253
43903 -253 253 253 253 253 253 253 253 253 253 253 253
43904 -253 253 253 253 253 253 144 144 144 2 2 6
43905 - 2 2 6 2 2 6 2 2 6 46 46 46
43906 - 2 2 6 2 2 6 2 2 6 2 2 6
43907 - 42 42 42 74 74 74 30 30 30 10 10 10
43908 - 0 0 0 0 0 0 0 0 0 0 0 0
43909 - 0 0 0 0 0 0 0 0 0 0 0 0
43910 - 0 0 0 0 0 0 0 0 0 0 0 0
43911 - 0 0 0 0 0 0 0 0 0 0 0 0
43912 - 0 0 0 0 0 0 0 0 0 0 0 0
43913 - 0 0 0 0 0 0 0 0 0 0 0 0
43914 - 0 0 0 0 0 0 0 0 0 0 0 0
43915 - 6 6 6 14 14 14 42 42 42 90 90 90
43916 - 26 26 26 6 6 6 42 42 42 2 2 6
43917 - 74 74 74 250 250 250 253 253 253 253 253 253
43918 -253 253 253 253 253 253 253 253 253 253 253 253
43919 -253 253 253 253 253 253 242 242 242 242 242 242
43920 -253 253 253 253 253 253 253 253 253 253 253 253
43921 -253 253 253 253 253 253 253 253 253 253 253 253
43922 -253 253 253 253 253 253 253 253 253 253 253 253
43923 -253 253 253 253 253 253 253 253 253 253 253 253
43924 -253 253 253 253 253 253 182 182 182 2 2 6
43925 - 2 2 6 2 2 6 2 2 6 46 46 46
43926 - 2 2 6 2 2 6 2 2 6 2 2 6
43927 - 10 10 10 86 86 86 38 38 38 10 10 10
43928 - 0 0 0 0 0 0 0 0 0 0 0 0
43929 - 0 0 0 0 0 0 0 0 0 0 0 0
43930 - 0 0 0 0 0 0 0 0 0 0 0 0
43931 - 0 0 0 0 0 0 0 0 0 0 0 0
43932 - 0 0 0 0 0 0 0 0 0 0 0 0
43933 - 0 0 0 0 0 0 0 0 0 0 0 0
43934 - 0 0 0 0 0 0 0 0 0 0 0 0
43935 - 10 10 10 26 26 26 66 66 66 82 82 82
43936 - 2 2 6 22 22 22 18 18 18 2 2 6
43937 -149 149 149 253 253 253 253 253 253 253 253 253
43938 -253 253 253 253 253 253 253 253 253 253 253 253
43939 -253 253 253 253 253 253 234 234 234 242 242 242
43940 -253 253 253 253 253 253 253 253 253 253 253 253
43941 -253 253 253 253 253 253 253 253 253 253 253 253
43942 -253 253 253 253 253 253 253 253 253 253 253 253
43943 -253 253 253 253 253 253 253 253 253 253 253 253
43944 -253 253 253 253 253 253 206 206 206 2 2 6
43945 - 2 2 6 2 2 6 2 2 6 38 38 38
43946 - 2 2 6 2 2 6 2 2 6 2 2 6
43947 - 6 6 6 86 86 86 46 46 46 14 14 14
43948 - 0 0 0 0 0 0 0 0 0 0 0 0
43949 - 0 0 0 0 0 0 0 0 0 0 0 0
43950 - 0 0 0 0 0 0 0 0 0 0 0 0
43951 - 0 0 0 0 0 0 0 0 0 0 0 0
43952 - 0 0 0 0 0 0 0 0 0 0 0 0
43953 - 0 0 0 0 0 0 0 0 0 0 0 0
43954 - 0 0 0 0 0 0 0 0 0 6 6 6
43955 - 18 18 18 46 46 46 86 86 86 18 18 18
43956 - 2 2 6 34 34 34 10 10 10 6 6 6
43957 -210 210 210 253 253 253 253 253 253 253 253 253
43958 -253 253 253 253 253 253 253 253 253 253 253 253
43959 -253 253 253 253 253 253 234 234 234 242 242 242
43960 -253 253 253 253 253 253 253 253 253 253 253 253
43961 -253 253 253 253 253 253 253 253 253 253 253 253
43962 -253 253 253 253 253 253 253 253 253 253 253 253
43963 -253 253 253 253 253 253 253 253 253 253 253 253
43964 -253 253 253 253 253 253 221 221 221 6 6 6
43965 - 2 2 6 2 2 6 6 6 6 30 30 30
43966 - 2 2 6 2 2 6 2 2 6 2 2 6
43967 - 2 2 6 82 82 82 54 54 54 18 18 18
43968 - 6 6 6 0 0 0 0 0 0 0 0 0
43969 - 0 0 0 0 0 0 0 0 0 0 0 0
43970 - 0 0 0 0 0 0 0 0 0 0 0 0
43971 - 0 0 0 0 0 0 0 0 0 0 0 0
43972 - 0 0 0 0 0 0 0 0 0 0 0 0
43973 - 0 0 0 0 0 0 0 0 0 0 0 0
43974 - 0 0 0 0 0 0 0 0 0 10 10 10
43975 - 26 26 26 66 66 66 62 62 62 2 2 6
43976 - 2 2 6 38 38 38 10 10 10 26 26 26
43977 -238 238 238 253 253 253 253 253 253 253 253 253
43978 -253 253 253 253 253 253 253 253 253 253 253 253
43979 -253 253 253 253 253 253 231 231 231 238 238 238
43980 -253 253 253 253 253 253 253 253 253 253 253 253
43981 -253 253 253 253 253 253 253 253 253 253 253 253
43982 -253 253 253 253 253 253 253 253 253 253 253 253
43983 -253 253 253 253 253 253 253 253 253 253 253 253
43984 -253 253 253 253 253 253 231 231 231 6 6 6
43985 - 2 2 6 2 2 6 10 10 10 30 30 30
43986 - 2 2 6 2 2 6 2 2 6 2 2 6
43987 - 2 2 6 66 66 66 58 58 58 22 22 22
43988 - 6 6 6 0 0 0 0 0 0 0 0 0
43989 - 0 0 0 0 0 0 0 0 0 0 0 0
43990 - 0 0 0 0 0 0 0 0 0 0 0 0
43991 - 0 0 0 0 0 0 0 0 0 0 0 0
43992 - 0 0 0 0 0 0 0 0 0 0 0 0
43993 - 0 0 0 0 0 0 0 0 0 0 0 0
43994 - 0 0 0 0 0 0 0 0 0 10 10 10
43995 - 38 38 38 78 78 78 6 6 6 2 2 6
43996 - 2 2 6 46 46 46 14 14 14 42 42 42
43997 -246 246 246 253 253 253 253 253 253 253 253 253
43998 -253 253 253 253 253 253 253 253 253 253 253 253
43999 -253 253 253 253 253 253 231 231 231 242 242 242
44000 -253 253 253 253 253 253 253 253 253 253 253 253
44001 -253 253 253 253 253 253 253 253 253 253 253 253
44002 -253 253 253 253 253 253 253 253 253 253 253 253
44003 -253 253 253 253 253 253 253 253 253 253 253 253
44004 -253 253 253 253 253 253 234 234 234 10 10 10
44005 - 2 2 6 2 2 6 22 22 22 14 14 14
44006 - 2 2 6 2 2 6 2 2 6 2 2 6
44007 - 2 2 6 66 66 66 62 62 62 22 22 22
44008 - 6 6 6 0 0 0 0 0 0 0 0 0
44009 - 0 0 0 0 0 0 0 0 0 0 0 0
44010 - 0 0 0 0 0 0 0 0 0 0 0 0
44011 - 0 0 0 0 0 0 0 0 0 0 0 0
44012 - 0 0 0 0 0 0 0 0 0 0 0 0
44013 - 0 0 0 0 0 0 0 0 0 0 0 0
44014 - 0 0 0 0 0 0 6 6 6 18 18 18
44015 - 50 50 50 74 74 74 2 2 6 2 2 6
44016 - 14 14 14 70 70 70 34 34 34 62 62 62
44017 -250 250 250 253 253 253 253 253 253 253 253 253
44018 -253 253 253 253 253 253 253 253 253 253 253 253
44019 -253 253 253 253 253 253 231 231 231 246 246 246
44020 -253 253 253 253 253 253 253 253 253 253 253 253
44021 -253 253 253 253 253 253 253 253 253 253 253 253
44022 -253 253 253 253 253 253 253 253 253 253 253 253
44023 -253 253 253 253 253 253 253 253 253 253 253 253
44024 -253 253 253 253 253 253 234 234 234 14 14 14
44025 - 2 2 6 2 2 6 30 30 30 2 2 6
44026 - 2 2 6 2 2 6 2 2 6 2 2 6
44027 - 2 2 6 66 66 66 62 62 62 22 22 22
44028 - 6 6 6 0 0 0 0 0 0 0 0 0
44029 - 0 0 0 0 0 0 0 0 0 0 0 0
44030 - 0 0 0 0 0 0 0 0 0 0 0 0
44031 - 0 0 0 0 0 0 0 0 0 0 0 0
44032 - 0 0 0 0 0 0 0 0 0 0 0 0
44033 - 0 0 0 0 0 0 0 0 0 0 0 0
44034 - 0 0 0 0 0 0 6 6 6 18 18 18
44035 - 54 54 54 62 62 62 2 2 6 2 2 6
44036 - 2 2 6 30 30 30 46 46 46 70 70 70
44037 -250 250 250 253 253 253 253 253 253 253 253 253
44038 -253 253 253 253 253 253 253 253 253 253 253 253
44039 -253 253 253 253 253 253 231 231 231 246 246 246
44040 -253 253 253 253 253 253 253 253 253 253 253 253
44041 -253 253 253 253 253 253 253 253 253 253 253 253
44042 -253 253 253 253 253 253 253 253 253 253 253 253
44043 -253 253 253 253 253 253 253 253 253 253 253 253
44044 -253 253 253 253 253 253 226 226 226 10 10 10
44045 - 2 2 6 6 6 6 30 30 30 2 2 6
44046 - 2 2 6 2 2 6 2 2 6 2 2 6
44047 - 2 2 6 66 66 66 58 58 58 22 22 22
44048 - 6 6 6 0 0 0 0 0 0 0 0 0
44049 - 0 0 0 0 0 0 0 0 0 0 0 0
44050 - 0 0 0 0 0 0 0 0 0 0 0 0
44051 - 0 0 0 0 0 0 0 0 0 0 0 0
44052 - 0 0 0 0 0 0 0 0 0 0 0 0
44053 - 0 0 0 0 0 0 0 0 0 0 0 0
44054 - 0 0 0 0 0 0 6 6 6 22 22 22
44055 - 58 58 58 62 62 62 2 2 6 2 2 6
44056 - 2 2 6 2 2 6 30 30 30 78 78 78
44057 -250 250 250 253 253 253 253 253 253 253 253 253
44058 -253 253 253 253 253 253 253 253 253 253 253 253
44059 -253 253 253 253 253 253 231 231 231 246 246 246
44060 -253 253 253 253 253 253 253 253 253 253 253 253
44061 -253 253 253 253 253 253 253 253 253 253 253 253
44062 -253 253 253 253 253 253 253 253 253 253 253 253
44063 -253 253 253 253 253 253 253 253 253 253 253 253
44064 -253 253 253 253 253 253 206 206 206 2 2 6
44065 - 22 22 22 34 34 34 18 14 6 22 22 22
44066 - 26 26 26 18 18 18 6 6 6 2 2 6
44067 - 2 2 6 82 82 82 54 54 54 18 18 18
44068 - 6 6 6 0 0 0 0 0 0 0 0 0
44069 - 0 0 0 0 0 0 0 0 0 0 0 0
44070 - 0 0 0 0 0 0 0 0 0 0 0 0
44071 - 0 0 0 0 0 0 0 0 0 0 0 0
44072 - 0 0 0 0 0 0 0 0 0 0 0 0
44073 - 0 0 0 0 0 0 0 0 0 0 0 0
44074 - 0 0 0 0 0 0 6 6 6 26 26 26
44075 - 62 62 62 106 106 106 74 54 14 185 133 11
44076 -210 162 10 121 92 8 6 6 6 62 62 62
44077 -238 238 238 253 253 253 253 253 253 253 253 253
44078 -253 253 253 253 253 253 253 253 253 253 253 253
44079 -253 253 253 253 253 253 231 231 231 246 246 246
44080 -253 253 253 253 253 253 253 253 253 253 253 253
44081 -253 253 253 253 253 253 253 253 253 253 253 253
44082 -253 253 253 253 253 253 253 253 253 253 253 253
44083 -253 253 253 253 253 253 253 253 253 253 253 253
44084 -253 253 253 253 253 253 158 158 158 18 18 18
44085 - 14 14 14 2 2 6 2 2 6 2 2 6
44086 - 6 6 6 18 18 18 66 66 66 38 38 38
44087 - 6 6 6 94 94 94 50 50 50 18 18 18
44088 - 6 6 6 0 0 0 0 0 0 0 0 0
44089 - 0 0 0 0 0 0 0 0 0 0 0 0
44090 - 0 0 0 0 0 0 0 0 0 0 0 0
44091 - 0 0 0 0 0 0 0 0 0 0 0 0
44092 - 0 0 0 0 0 0 0 0 0 0 0 0
44093 - 0 0 0 0 0 0 0 0 0 6 6 6
44094 - 10 10 10 10 10 10 18 18 18 38 38 38
44095 - 78 78 78 142 134 106 216 158 10 242 186 14
44096 -246 190 14 246 190 14 156 118 10 10 10 10
44097 - 90 90 90 238 238 238 253 253 253 253 253 253
44098 -253 253 253 253 253 253 253 253 253 253 253 253
44099 -253 253 253 253 253 253 231 231 231 250 250 250
44100 -253 253 253 253 253 253 253 253 253 253 253 253
44101 -253 253 253 253 253 253 253 253 253 253 253 253
44102 -253 253 253 253 253 253 253 253 253 253 253 253
44103 -253 253 253 253 253 253 253 253 253 246 230 190
44104 -238 204 91 238 204 91 181 142 44 37 26 9
44105 - 2 2 6 2 2 6 2 2 6 2 2 6
44106 - 2 2 6 2 2 6 38 38 38 46 46 46
44107 - 26 26 26 106 106 106 54 54 54 18 18 18
44108 - 6 6 6 0 0 0 0 0 0 0 0 0
44109 - 0 0 0 0 0 0 0 0 0 0 0 0
44110 - 0 0 0 0 0 0 0 0 0 0 0 0
44111 - 0 0 0 0 0 0 0 0 0 0 0 0
44112 - 0 0 0 0 0 0 0 0 0 0 0 0
44113 - 0 0 0 6 6 6 14 14 14 22 22 22
44114 - 30 30 30 38 38 38 50 50 50 70 70 70
44115 -106 106 106 190 142 34 226 170 11 242 186 14
44116 -246 190 14 246 190 14 246 190 14 154 114 10
44117 - 6 6 6 74 74 74 226 226 226 253 253 253
44118 -253 253 253 253 253 253 253 253 253 253 253 253
44119 -253 253 253 253 253 253 231 231 231 250 250 250
44120 -253 253 253 253 253 253 253 253 253 253 253 253
44121 -253 253 253 253 253 253 253 253 253 253 253 253
44122 -253 253 253 253 253 253 253 253 253 253 253 253
44123 -253 253 253 253 253 253 253 253 253 228 184 62
44124 -241 196 14 241 208 19 232 195 16 38 30 10
44125 - 2 2 6 2 2 6 2 2 6 2 2 6
44126 - 2 2 6 6 6 6 30 30 30 26 26 26
44127 -203 166 17 154 142 90 66 66 66 26 26 26
44128 - 6 6 6 0 0 0 0 0 0 0 0 0
44129 - 0 0 0 0 0 0 0 0 0 0 0 0
44130 - 0 0 0 0 0 0 0 0 0 0 0 0
44131 - 0 0 0 0 0 0 0 0 0 0 0 0
44132 - 0 0 0 0 0 0 0 0 0 0 0 0
44133 - 6 6 6 18 18 18 38 38 38 58 58 58
44134 - 78 78 78 86 86 86 101 101 101 123 123 123
44135 -175 146 61 210 150 10 234 174 13 246 186 14
44136 -246 190 14 246 190 14 246 190 14 238 190 10
44137 -102 78 10 2 2 6 46 46 46 198 198 198
44138 -253 253 253 253 253 253 253 253 253 253 253 253
44139 -253 253 253 253 253 253 234 234 234 242 242 242
44140 -253 253 253 253 253 253 253 253 253 253 253 253
44141 -253 253 253 253 253 253 253 253 253 253 253 253
44142 -253 253 253 253 253 253 253 253 253 253 253 253
44143 -253 253 253 253 253 253 253 253 253 224 178 62
44144 -242 186 14 241 196 14 210 166 10 22 18 6
44145 - 2 2 6 2 2 6 2 2 6 2 2 6
44146 - 2 2 6 2 2 6 6 6 6 121 92 8
44147 -238 202 15 232 195 16 82 82 82 34 34 34
44148 - 10 10 10 0 0 0 0 0 0 0 0 0
44149 - 0 0 0 0 0 0 0 0 0 0 0 0
44150 - 0 0 0 0 0 0 0 0 0 0 0 0
44151 - 0 0 0 0 0 0 0 0 0 0 0 0
44152 - 0 0 0 0 0 0 0 0 0 0 0 0
44153 - 14 14 14 38 38 38 70 70 70 154 122 46
44154 -190 142 34 200 144 11 197 138 11 197 138 11
44155 -213 154 11 226 170 11 242 186 14 246 190 14
44156 -246 190 14 246 190 14 246 190 14 246 190 14
44157 -225 175 15 46 32 6 2 2 6 22 22 22
44158 -158 158 158 250 250 250 253 253 253 253 253 253
44159 -253 253 253 253 253 253 253 253 253 253 253 253
44160 -253 253 253 253 253 253 253 253 253 253 253 253
44161 -253 253 253 253 253 253 253 253 253 253 253 253
44162 -253 253 253 253 253 253 253 253 253 253 253 253
44163 -253 253 253 250 250 250 242 242 242 224 178 62
44164 -239 182 13 236 186 11 213 154 11 46 32 6
44165 - 2 2 6 2 2 6 2 2 6 2 2 6
44166 - 2 2 6 2 2 6 61 42 6 225 175 15
44167 -238 190 10 236 186 11 112 100 78 42 42 42
44168 - 14 14 14 0 0 0 0 0 0 0 0 0
44169 - 0 0 0 0 0 0 0 0 0 0 0 0
44170 - 0 0 0 0 0 0 0 0 0 0 0 0
44171 - 0 0 0 0 0 0 0 0 0 0 0 0
44172 - 0 0 0 0 0 0 0 0 0 6 6 6
44173 - 22 22 22 54 54 54 154 122 46 213 154 11
44174 -226 170 11 230 174 11 226 170 11 226 170 11
44175 -236 178 12 242 186 14 246 190 14 246 190 14
44176 -246 190 14 246 190 14 246 190 14 246 190 14
44177 -241 196 14 184 144 12 10 10 10 2 2 6
44178 - 6 6 6 116 116 116 242 242 242 253 253 253
44179 -253 253 253 253 253 253 253 253 253 253 253 253
44180 -253 253 253 253 253 253 253 253 253 253 253 253
44181 -253 253 253 253 253 253 253 253 253 253 253 253
44182 -253 253 253 253 253 253 253 253 253 253 253 253
44183 -253 253 253 231 231 231 198 198 198 214 170 54
44184 -236 178 12 236 178 12 210 150 10 137 92 6
44185 - 18 14 6 2 2 6 2 2 6 2 2 6
44186 - 6 6 6 70 47 6 200 144 11 236 178 12
44187 -239 182 13 239 182 13 124 112 88 58 58 58
44188 - 22 22 22 6 6 6 0 0 0 0 0 0
44189 - 0 0 0 0 0 0 0 0 0 0 0 0
44190 - 0 0 0 0 0 0 0 0 0 0 0 0
44191 - 0 0 0 0 0 0 0 0 0 0 0 0
44192 - 0 0 0 0 0 0 0 0 0 10 10 10
44193 - 30 30 30 70 70 70 180 133 36 226 170 11
44194 -239 182 13 242 186 14 242 186 14 246 186 14
44195 -246 190 14 246 190 14 246 190 14 246 190 14
44196 -246 190 14 246 190 14 246 190 14 246 190 14
44197 -246 190 14 232 195 16 98 70 6 2 2 6
44198 - 2 2 6 2 2 6 66 66 66 221 221 221
44199 -253 253 253 253 253 253 253 253 253 253 253 253
44200 -253 253 253 253 253 253 253 253 253 253 253 253
44201 -253 253 253 253 253 253 253 253 253 253 253 253
44202 -253 253 253 253 253 253 253 253 253 253 253 253
44203 -253 253 253 206 206 206 198 198 198 214 166 58
44204 -230 174 11 230 174 11 216 158 10 192 133 9
44205 -163 110 8 116 81 8 102 78 10 116 81 8
44206 -167 114 7 197 138 11 226 170 11 239 182 13
44207 -242 186 14 242 186 14 162 146 94 78 78 78
44208 - 34 34 34 14 14 14 6 6 6 0 0 0
44209 - 0 0 0 0 0 0 0 0 0 0 0 0
44210 - 0 0 0 0 0 0 0 0 0 0 0 0
44211 - 0 0 0 0 0 0 0 0 0 0 0 0
44212 - 0 0 0 0 0 0 0 0 0 6 6 6
44213 - 30 30 30 78 78 78 190 142 34 226 170 11
44214 -239 182 13 246 190 14 246 190 14 246 190 14
44215 -246 190 14 246 190 14 246 190 14 246 190 14
44216 -246 190 14 246 190 14 246 190 14 246 190 14
44217 -246 190 14 241 196 14 203 166 17 22 18 6
44218 - 2 2 6 2 2 6 2 2 6 38 38 38
44219 -218 218 218 253 253 253 253 253 253 253 253 253
44220 -253 253 253 253 253 253 253 253 253 253 253 253
44221 -253 253 253 253 253 253 253 253 253 253 253 253
44222 -253 253 253 253 253 253 253 253 253 253 253 253
44223 -250 250 250 206 206 206 198 198 198 202 162 69
44224 -226 170 11 236 178 12 224 166 10 210 150 10
44225 -200 144 11 197 138 11 192 133 9 197 138 11
44226 -210 150 10 226 170 11 242 186 14 246 190 14
44227 -246 190 14 246 186 14 225 175 15 124 112 88
44228 - 62 62 62 30 30 30 14 14 14 6 6 6
44229 - 0 0 0 0 0 0 0 0 0 0 0 0
44230 - 0 0 0 0 0 0 0 0 0 0 0 0
44231 - 0 0 0 0 0 0 0 0 0 0 0 0
44232 - 0 0 0 0 0 0 0 0 0 10 10 10
44233 - 30 30 30 78 78 78 174 135 50 224 166 10
44234 -239 182 13 246 190 14 246 190 14 246 190 14
44235 -246 190 14 246 190 14 246 190 14 246 190 14
44236 -246 190 14 246 190 14 246 190 14 246 190 14
44237 -246 190 14 246 190 14 241 196 14 139 102 15
44238 - 2 2 6 2 2 6 2 2 6 2 2 6
44239 - 78 78 78 250 250 250 253 253 253 253 253 253
44240 -253 253 253 253 253 253 253 253 253 253 253 253
44241 -253 253 253 253 253 253 253 253 253 253 253 253
44242 -253 253 253 253 253 253 253 253 253 253 253 253
44243 -250 250 250 214 214 214 198 198 198 190 150 46
44244 -219 162 10 236 178 12 234 174 13 224 166 10
44245 -216 158 10 213 154 11 213 154 11 216 158 10
44246 -226 170 11 239 182 13 246 190 14 246 190 14
44247 -246 190 14 246 190 14 242 186 14 206 162 42
44248 -101 101 101 58 58 58 30 30 30 14 14 14
44249 - 6 6 6 0 0 0 0 0 0 0 0 0
44250 - 0 0 0 0 0 0 0 0 0 0 0 0
44251 - 0 0 0 0 0 0 0 0 0 0 0 0
44252 - 0 0 0 0 0 0 0 0 0 10 10 10
44253 - 30 30 30 74 74 74 174 135 50 216 158 10
44254 -236 178 12 246 190 14 246 190 14 246 190 14
44255 -246 190 14 246 190 14 246 190 14 246 190 14
44256 -246 190 14 246 190 14 246 190 14 246 190 14
44257 -246 190 14 246 190 14 241 196 14 226 184 13
44258 - 61 42 6 2 2 6 2 2 6 2 2 6
44259 - 22 22 22 238 238 238 253 253 253 253 253 253
44260 -253 253 253 253 253 253 253 253 253 253 253 253
44261 -253 253 253 253 253 253 253 253 253 253 253 253
44262 -253 253 253 253 253 253 253 253 253 253 253 253
44263 -253 253 253 226 226 226 187 187 187 180 133 36
44264 -216 158 10 236 178 12 239 182 13 236 178 12
44265 -230 174 11 226 170 11 226 170 11 230 174 11
44266 -236 178 12 242 186 14 246 190 14 246 190 14
44267 -246 190 14 246 190 14 246 186 14 239 182 13
44268 -206 162 42 106 106 106 66 66 66 34 34 34
44269 - 14 14 14 6 6 6 0 0 0 0 0 0
44270 - 0 0 0 0 0 0 0 0 0 0 0 0
44271 - 0 0 0 0 0 0 0 0 0 0 0 0
44272 - 0 0 0 0 0 0 0 0 0 6 6 6
44273 - 26 26 26 70 70 70 163 133 67 213 154 11
44274 -236 178 12 246 190 14 246 190 14 246 190 14
44275 -246 190 14 246 190 14 246 190 14 246 190 14
44276 -246 190 14 246 190 14 246 190 14 246 190 14
44277 -246 190 14 246 190 14 246 190 14 241 196 14
44278 -190 146 13 18 14 6 2 2 6 2 2 6
44279 - 46 46 46 246 246 246 253 253 253 253 253 253
44280 -253 253 253 253 253 253 253 253 253 253 253 253
44281 -253 253 253 253 253 253 253 253 253 253 253 253
44282 -253 253 253 253 253 253 253 253 253 253 253 253
44283 -253 253 253 221 221 221 86 86 86 156 107 11
44284 -216 158 10 236 178 12 242 186 14 246 186 14
44285 -242 186 14 239 182 13 239 182 13 242 186 14
44286 -242 186 14 246 186 14 246 190 14 246 190 14
44287 -246 190 14 246 190 14 246 190 14 246 190 14
44288 -242 186 14 225 175 15 142 122 72 66 66 66
44289 - 30 30 30 10 10 10 0 0 0 0 0 0
44290 - 0 0 0 0 0 0 0 0 0 0 0 0
44291 - 0 0 0 0 0 0 0 0 0 0 0 0
44292 - 0 0 0 0 0 0 0 0 0 6 6 6
44293 - 26 26 26 70 70 70 163 133 67 210 150 10
44294 -236 178 12 246 190 14 246 190 14 246 190 14
44295 -246 190 14 246 190 14 246 190 14 246 190 14
44296 -246 190 14 246 190 14 246 190 14 246 190 14
44297 -246 190 14 246 190 14 246 190 14 246 190 14
44298 -232 195 16 121 92 8 34 34 34 106 106 106
44299 -221 221 221 253 253 253 253 253 253 253 253 253
44300 -253 253 253 253 253 253 253 253 253 253 253 253
44301 -253 253 253 253 253 253 253 253 253 253 253 253
44302 -253 253 253 253 253 253 253 253 253 253 253 253
44303 -242 242 242 82 82 82 18 14 6 163 110 8
44304 -216 158 10 236 178 12 242 186 14 246 190 14
44305 -246 190 14 246 190 14 246 190 14 246 190 14
44306 -246 190 14 246 190 14 246 190 14 246 190 14
44307 -246 190 14 246 190 14 246 190 14 246 190 14
44308 -246 190 14 246 190 14 242 186 14 163 133 67
44309 - 46 46 46 18 18 18 6 6 6 0 0 0
44310 - 0 0 0 0 0 0 0 0 0 0 0 0
44311 - 0 0 0 0 0 0 0 0 0 0 0 0
44312 - 0 0 0 0 0 0 0 0 0 10 10 10
44313 - 30 30 30 78 78 78 163 133 67 210 150 10
44314 -236 178 12 246 186 14 246 190 14 246 190 14
44315 -246 190 14 246 190 14 246 190 14 246 190 14
44316 -246 190 14 246 190 14 246 190 14 246 190 14
44317 -246 190 14 246 190 14 246 190 14 246 190 14
44318 -241 196 14 215 174 15 190 178 144 253 253 253
44319 -253 253 253 253 253 253 253 253 253 253 253 253
44320 -253 253 253 253 253 253 253 253 253 253 253 253
44321 -253 253 253 253 253 253 253 253 253 253 253 253
44322 -253 253 253 253 253 253 253 253 253 218 218 218
44323 - 58 58 58 2 2 6 22 18 6 167 114 7
44324 -216 158 10 236 178 12 246 186 14 246 190 14
44325 -246 190 14 246 190 14 246 190 14 246 190 14
44326 -246 190 14 246 190 14 246 190 14 246 190 14
44327 -246 190 14 246 190 14 246 190 14 246 190 14
44328 -246 190 14 246 186 14 242 186 14 190 150 46
44329 - 54 54 54 22 22 22 6 6 6 0 0 0
44330 - 0 0 0 0 0 0 0 0 0 0 0 0
44331 - 0 0 0 0 0 0 0 0 0 0 0 0
44332 - 0 0 0 0 0 0 0 0 0 14 14 14
44333 - 38 38 38 86 86 86 180 133 36 213 154 11
44334 -236 178 12 246 186 14 246 190 14 246 190 14
44335 -246 190 14 246 190 14 246 190 14 246 190 14
44336 -246 190 14 246 190 14 246 190 14 246 190 14
44337 -246 190 14 246 190 14 246 190 14 246 190 14
44338 -246 190 14 232 195 16 190 146 13 214 214 214
44339 -253 253 253 253 253 253 253 253 253 253 253 253
44340 -253 253 253 253 253 253 253 253 253 253 253 253
44341 -253 253 253 253 253 253 253 253 253 253 253 253
44342 -253 253 253 250 250 250 170 170 170 26 26 26
44343 - 2 2 6 2 2 6 37 26 9 163 110 8
44344 -219 162 10 239 182 13 246 186 14 246 190 14
44345 -246 190 14 246 190 14 246 190 14 246 190 14
44346 -246 190 14 246 190 14 246 190 14 246 190 14
44347 -246 190 14 246 190 14 246 190 14 246 190 14
44348 -246 186 14 236 178 12 224 166 10 142 122 72
44349 - 46 46 46 18 18 18 6 6 6 0 0 0
44350 - 0 0 0 0 0 0 0 0 0 0 0 0
44351 - 0 0 0 0 0 0 0 0 0 0 0 0
44352 - 0 0 0 0 0 0 6 6 6 18 18 18
44353 - 50 50 50 109 106 95 192 133 9 224 166 10
44354 -242 186 14 246 190 14 246 190 14 246 190 14
44355 -246 190 14 246 190 14 246 190 14 246 190 14
44356 -246 190 14 246 190 14 246 190 14 246 190 14
44357 -246 190 14 246 190 14 246 190 14 246 190 14
44358 -242 186 14 226 184 13 210 162 10 142 110 46
44359 -226 226 226 253 253 253 253 253 253 253 253 253
44360 -253 253 253 253 253 253 253 253 253 253 253 253
44361 -253 253 253 253 253 253 253 253 253 253 253 253
44362 -198 198 198 66 66 66 2 2 6 2 2 6
44363 - 2 2 6 2 2 6 50 34 6 156 107 11
44364 -219 162 10 239 182 13 246 186 14 246 190 14
44365 -246 190 14 246 190 14 246 190 14 246 190 14
44366 -246 190 14 246 190 14 246 190 14 246 190 14
44367 -246 190 14 246 190 14 246 190 14 242 186 14
44368 -234 174 13 213 154 11 154 122 46 66 66 66
44369 - 30 30 30 10 10 10 0 0 0 0 0 0
44370 - 0 0 0 0 0 0 0 0 0 0 0 0
44371 - 0 0 0 0 0 0 0 0 0 0 0 0
44372 - 0 0 0 0 0 0 6 6 6 22 22 22
44373 - 58 58 58 154 121 60 206 145 10 234 174 13
44374 -242 186 14 246 186 14 246 190 14 246 190 14
44375 -246 190 14 246 190 14 246 190 14 246 190 14
44376 -246 190 14 246 190 14 246 190 14 246 190 14
44377 -246 190 14 246 190 14 246 190 14 246 190 14
44378 -246 186 14 236 178 12 210 162 10 163 110 8
44379 - 61 42 6 138 138 138 218 218 218 250 250 250
44380 -253 253 253 253 253 253 253 253 253 250 250 250
44381 -242 242 242 210 210 210 144 144 144 66 66 66
44382 - 6 6 6 2 2 6 2 2 6 2 2 6
44383 - 2 2 6 2 2 6 61 42 6 163 110 8
44384 -216 158 10 236 178 12 246 190 14 246 190 14
44385 -246 190 14 246 190 14 246 190 14 246 190 14
44386 -246 190 14 246 190 14 246 190 14 246 190 14
44387 -246 190 14 239 182 13 230 174 11 216 158 10
44388 -190 142 34 124 112 88 70 70 70 38 38 38
44389 - 18 18 18 6 6 6 0 0 0 0 0 0
44390 - 0 0 0 0 0 0 0 0 0 0 0 0
44391 - 0 0 0 0 0 0 0 0 0 0 0 0
44392 - 0 0 0 0 0 0 6 6 6 22 22 22
44393 - 62 62 62 168 124 44 206 145 10 224 166 10
44394 -236 178 12 239 182 13 242 186 14 242 186 14
44395 -246 186 14 246 190 14 246 190 14 246 190 14
44396 -246 190 14 246 190 14 246 190 14 246 190 14
44397 -246 190 14 246 190 14 246 190 14 246 190 14
44398 -246 190 14 236 178 12 216 158 10 175 118 6
44399 - 80 54 7 2 2 6 6 6 6 30 30 30
44400 - 54 54 54 62 62 62 50 50 50 38 38 38
44401 - 14 14 14 2 2 6 2 2 6 2 2 6
44402 - 2 2 6 2 2 6 2 2 6 2 2 6
44403 - 2 2 6 6 6 6 80 54 7 167 114 7
44404 -213 154 11 236 178 12 246 190 14 246 190 14
44405 -246 190 14 246 190 14 246 190 14 246 190 14
44406 -246 190 14 242 186 14 239 182 13 239 182 13
44407 -230 174 11 210 150 10 174 135 50 124 112 88
44408 - 82 82 82 54 54 54 34 34 34 18 18 18
44409 - 6 6 6 0 0 0 0 0 0 0 0 0
44410 - 0 0 0 0 0 0 0 0 0 0 0 0
44411 - 0 0 0 0 0 0 0 0 0 0 0 0
44412 - 0 0 0 0 0 0 6 6 6 18 18 18
44413 - 50 50 50 158 118 36 192 133 9 200 144 11
44414 -216 158 10 219 162 10 224 166 10 226 170 11
44415 -230 174 11 236 178 12 239 182 13 239 182 13
44416 -242 186 14 246 186 14 246 190 14 246 190 14
44417 -246 190 14 246 190 14 246 190 14 246 190 14
44418 -246 186 14 230 174 11 210 150 10 163 110 8
44419 -104 69 6 10 10 10 2 2 6 2 2 6
44420 - 2 2 6 2 2 6 2 2 6 2 2 6
44421 - 2 2 6 2 2 6 2 2 6 2 2 6
44422 - 2 2 6 2 2 6 2 2 6 2 2 6
44423 - 2 2 6 6 6 6 91 60 6 167 114 7
44424 -206 145 10 230 174 11 242 186 14 246 190 14
44425 -246 190 14 246 190 14 246 186 14 242 186 14
44426 -239 182 13 230 174 11 224 166 10 213 154 11
44427 -180 133 36 124 112 88 86 86 86 58 58 58
44428 - 38 38 38 22 22 22 10 10 10 6 6 6
44429 - 0 0 0 0 0 0 0 0 0 0 0 0
44430 - 0 0 0 0 0 0 0 0 0 0 0 0
44431 - 0 0 0 0 0 0 0 0 0 0 0 0
44432 - 0 0 0 0 0 0 0 0 0 14 14 14
44433 - 34 34 34 70 70 70 138 110 50 158 118 36
44434 -167 114 7 180 123 7 192 133 9 197 138 11
44435 -200 144 11 206 145 10 213 154 11 219 162 10
44436 -224 166 10 230 174 11 239 182 13 242 186 14
44437 -246 186 14 246 186 14 246 186 14 246 186 14
44438 -239 182 13 216 158 10 185 133 11 152 99 6
44439 -104 69 6 18 14 6 2 2 6 2 2 6
44440 - 2 2 6 2 2 6 2 2 6 2 2 6
44441 - 2 2 6 2 2 6 2 2 6 2 2 6
44442 - 2 2 6 2 2 6 2 2 6 2 2 6
44443 - 2 2 6 6 6 6 80 54 7 152 99 6
44444 -192 133 9 219 162 10 236 178 12 239 182 13
44445 -246 186 14 242 186 14 239 182 13 236 178 12
44446 -224 166 10 206 145 10 192 133 9 154 121 60
44447 - 94 94 94 62 62 62 42 42 42 22 22 22
44448 - 14 14 14 6 6 6 0 0 0 0 0 0
44449 - 0 0 0 0 0 0 0 0 0 0 0 0
44450 - 0 0 0 0 0 0 0 0 0 0 0 0
44451 - 0 0 0 0 0 0 0 0 0 0 0 0
44452 - 0 0 0 0 0 0 0 0 0 6 6 6
44453 - 18 18 18 34 34 34 58 58 58 78 78 78
44454 -101 98 89 124 112 88 142 110 46 156 107 11
44455 -163 110 8 167 114 7 175 118 6 180 123 7
44456 -185 133 11 197 138 11 210 150 10 219 162 10
44457 -226 170 11 236 178 12 236 178 12 234 174 13
44458 -219 162 10 197 138 11 163 110 8 130 83 6
44459 - 91 60 6 10 10 10 2 2 6 2 2 6
44460 - 18 18 18 38 38 38 38 38 38 38 38 38
44461 - 38 38 38 38 38 38 38 38 38 38 38 38
44462 - 38 38 38 38 38 38 26 26 26 2 2 6
44463 - 2 2 6 6 6 6 70 47 6 137 92 6
44464 -175 118 6 200 144 11 219 162 10 230 174 11
44465 -234 174 13 230 174 11 219 162 10 210 150 10
44466 -192 133 9 163 110 8 124 112 88 82 82 82
44467 - 50 50 50 30 30 30 14 14 14 6 6 6
44468 - 0 0 0 0 0 0 0 0 0 0 0 0
44469 - 0 0 0 0 0 0 0 0 0 0 0 0
44470 - 0 0 0 0 0 0 0 0 0 0 0 0
44471 - 0 0 0 0 0 0 0 0 0 0 0 0
44472 - 0 0 0 0 0 0 0 0 0 0 0 0
44473 - 6 6 6 14 14 14 22 22 22 34 34 34
44474 - 42 42 42 58 58 58 74 74 74 86 86 86
44475 -101 98 89 122 102 70 130 98 46 121 87 25
44476 -137 92 6 152 99 6 163 110 8 180 123 7
44477 -185 133 11 197 138 11 206 145 10 200 144 11
44478 -180 123 7 156 107 11 130 83 6 104 69 6
44479 - 50 34 6 54 54 54 110 110 110 101 98 89
44480 - 86 86 86 82 82 82 78 78 78 78 78 78
44481 - 78 78 78 78 78 78 78 78 78 78 78 78
44482 - 78 78 78 82 82 82 86 86 86 94 94 94
44483 -106 106 106 101 101 101 86 66 34 124 80 6
44484 -156 107 11 180 123 7 192 133 9 200 144 11
44485 -206 145 10 200 144 11 192 133 9 175 118 6
44486 -139 102 15 109 106 95 70 70 70 42 42 42
44487 - 22 22 22 10 10 10 0 0 0 0 0 0
44488 - 0 0 0 0 0 0 0 0 0 0 0 0
44489 - 0 0 0 0 0 0 0 0 0 0 0 0
44490 - 0 0 0 0 0 0 0 0 0 0 0 0
44491 - 0 0 0 0 0 0 0 0 0 0 0 0
44492 - 0 0 0 0 0 0 0 0 0 0 0 0
44493 - 0 0 0 0 0 0 6 6 6 10 10 10
44494 - 14 14 14 22 22 22 30 30 30 38 38 38
44495 - 50 50 50 62 62 62 74 74 74 90 90 90
44496 -101 98 89 112 100 78 121 87 25 124 80 6
44497 -137 92 6 152 99 6 152 99 6 152 99 6
44498 -138 86 6 124 80 6 98 70 6 86 66 30
44499 -101 98 89 82 82 82 58 58 58 46 46 46
44500 - 38 38 38 34 34 34 34 34 34 34 34 34
44501 - 34 34 34 34 34 34 34 34 34 34 34 34
44502 - 34 34 34 34 34 34 38 38 38 42 42 42
44503 - 54 54 54 82 82 82 94 86 76 91 60 6
44504 -134 86 6 156 107 11 167 114 7 175 118 6
44505 -175 118 6 167 114 7 152 99 6 121 87 25
44506 -101 98 89 62 62 62 34 34 34 18 18 18
44507 - 6 6 6 0 0 0 0 0 0 0 0 0
44508 - 0 0 0 0 0 0 0 0 0 0 0 0
44509 - 0 0 0 0 0 0 0 0 0 0 0 0
44510 - 0 0 0 0 0 0 0 0 0 0 0 0
44511 - 0 0 0 0 0 0 0 0 0 0 0 0
44512 - 0 0 0 0 0 0 0 0 0 0 0 0
44513 - 0 0 0 0 0 0 0 0 0 0 0 0
44514 - 0 0 0 6 6 6 6 6 6 10 10 10
44515 - 18 18 18 22 22 22 30 30 30 42 42 42
44516 - 50 50 50 66 66 66 86 86 86 101 98 89
44517 -106 86 58 98 70 6 104 69 6 104 69 6
44518 -104 69 6 91 60 6 82 62 34 90 90 90
44519 - 62 62 62 38 38 38 22 22 22 14 14 14
44520 - 10 10 10 10 10 10 10 10 10 10 10 10
44521 - 10 10 10 10 10 10 6 6 6 10 10 10
44522 - 10 10 10 10 10 10 10 10 10 14 14 14
44523 - 22 22 22 42 42 42 70 70 70 89 81 66
44524 - 80 54 7 104 69 6 124 80 6 137 92 6
44525 -134 86 6 116 81 8 100 82 52 86 86 86
44526 - 58 58 58 30 30 30 14 14 14 6 6 6
44527 - 0 0 0 0 0 0 0 0 0 0 0 0
44528 - 0 0 0 0 0 0 0 0 0 0 0 0
44529 - 0 0 0 0 0 0 0 0 0 0 0 0
44530 - 0 0 0 0 0 0 0 0 0 0 0 0
44531 - 0 0 0 0 0 0 0 0 0 0 0 0
44532 - 0 0 0 0 0 0 0 0 0 0 0 0
44533 - 0 0 0 0 0 0 0 0 0 0 0 0
44534 - 0 0 0 0 0 0 0 0 0 0 0 0
44535 - 0 0 0 6 6 6 10 10 10 14 14 14
44536 - 18 18 18 26 26 26 38 38 38 54 54 54
44537 - 70 70 70 86 86 86 94 86 76 89 81 66
44538 - 89 81 66 86 86 86 74 74 74 50 50 50
44539 - 30 30 30 14 14 14 6 6 6 0 0 0
44540 - 0 0 0 0 0 0 0 0 0 0 0 0
44541 - 0 0 0 0 0 0 0 0 0 0 0 0
44542 - 0 0 0 0 0 0 0 0 0 0 0 0
44543 - 6 6 6 18 18 18 34 34 34 58 58 58
44544 - 82 82 82 89 81 66 89 81 66 89 81 66
44545 - 94 86 66 94 86 76 74 74 74 50 50 50
44546 - 26 26 26 14 14 14 6 6 6 0 0 0
44547 - 0 0 0 0 0 0 0 0 0 0 0 0
44548 - 0 0 0 0 0 0 0 0 0 0 0 0
44549 - 0 0 0 0 0 0 0 0 0 0 0 0
44550 - 0 0 0 0 0 0 0 0 0 0 0 0
44551 - 0 0 0 0 0 0 0 0 0 0 0 0
44552 - 0 0 0 0 0 0 0 0 0 0 0 0
44553 - 0 0 0 0 0 0 0 0 0 0 0 0
44554 - 0 0 0 0 0 0 0 0 0 0 0 0
44555 - 0 0 0 0 0 0 0 0 0 0 0 0
44556 - 6 6 6 6 6 6 14 14 14 18 18 18
44557 - 30 30 30 38 38 38 46 46 46 54 54 54
44558 - 50 50 50 42 42 42 30 30 30 18 18 18
44559 - 10 10 10 0 0 0 0 0 0 0 0 0
44560 - 0 0 0 0 0 0 0 0 0 0 0 0
44561 - 0 0 0 0 0 0 0 0 0 0 0 0
44562 - 0 0 0 0 0 0 0 0 0 0 0 0
44563 - 0 0 0 6 6 6 14 14 14 26 26 26
44564 - 38 38 38 50 50 50 58 58 58 58 58 58
44565 - 54 54 54 42 42 42 30 30 30 18 18 18
44566 - 10 10 10 0 0 0 0 0 0 0 0 0
44567 - 0 0 0 0 0 0 0 0 0 0 0 0
44568 - 0 0 0 0 0 0 0 0 0 0 0 0
44569 - 0 0 0 0 0 0 0 0 0 0 0 0
44570 - 0 0 0 0 0 0 0 0 0 0 0 0
44571 - 0 0 0 0 0 0 0 0 0 0 0 0
44572 - 0 0 0 0 0 0 0 0 0 0 0 0
44573 - 0 0 0 0 0 0 0 0 0 0 0 0
44574 - 0 0 0 0 0 0 0 0 0 0 0 0
44575 - 0 0 0 0 0 0 0 0 0 0 0 0
44576 - 0 0 0 0 0 0 0 0 0 6 6 6
44577 - 6 6 6 10 10 10 14 14 14 18 18 18
44578 - 18 18 18 14 14 14 10 10 10 6 6 6
44579 - 0 0 0 0 0 0 0 0 0 0 0 0
44580 - 0 0 0 0 0 0 0 0 0 0 0 0
44581 - 0 0 0 0 0 0 0 0 0 0 0 0
44582 - 0 0 0 0 0 0 0 0 0 0 0 0
44583 - 0 0 0 0 0 0 0 0 0 6 6 6
44584 - 14 14 14 18 18 18 22 22 22 22 22 22
44585 - 18 18 18 14 14 14 10 10 10 6 6 6
44586 - 0 0 0 0 0 0 0 0 0 0 0 0
44587 - 0 0 0 0 0 0 0 0 0 0 0 0
44588 - 0 0 0 0 0 0 0 0 0 0 0 0
44589 - 0 0 0 0 0 0 0 0 0 0 0 0
44590 - 0 0 0 0 0 0 0 0 0 0 0 0
44591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44604 +4 4 4 4 4 4
44605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44618 +4 4 4 4 4 4
44619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44632 +4 4 4 4 4 4
44633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44646 +4 4 4 4 4 4
44647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44660 +4 4 4 4 4 4
44661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674 +4 4 4 4 4 4
44675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44679 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
44680 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
44681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
44685 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44686 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
44687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688 +4 4 4 4 4 4
44689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44693 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
44694 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
44695 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
44699 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
44700 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
44701 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702 +4 4 4 4 4 4
44703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44707 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
44708 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
44709 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
44713 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
44714 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
44715 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
44716 +4 4 4 4 4 4
44717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44720 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
44721 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
44722 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
44723 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
44724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44726 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
44727 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
44728 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
44729 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
44730 +4 4 4 4 4 4
44731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44734 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
44735 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
44736 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
44737 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
44738 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44739 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
44740 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
44741 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
44742 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
44743 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
44744 +4 4 4 4 4 4
44745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44748 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
44749 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
44750 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
44751 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
44752 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44753 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
44754 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
44755 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
44756 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
44757 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
44758 +4 4 4 4 4 4
44759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44761 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
44762 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
44763 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
44764 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
44765 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
44766 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
44767 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
44768 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
44769 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
44770 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
44771 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
44772 +4 4 4 4 4 4
44773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44775 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
44776 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
44777 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
44778 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
44779 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
44780 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
44781 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
44782 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
44783 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
44784 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
44785 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
44786 +4 4 4 4 4 4
44787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44789 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
44790 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
44791 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
44792 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
44793 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
44794 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
44795 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
44796 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
44797 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
44798 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
44799 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44800 +4 4 4 4 4 4
44801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44803 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
44804 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
44805 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
44806 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
44807 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
44808 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
44809 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
44810 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
44811 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
44812 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
44813 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
44814 +4 4 4 4 4 4
44815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44816 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
44817 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
44818 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
44819 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
44820 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
44821 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
44822 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
44823 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
44824 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
44825 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
44826 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
44827 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
44828 +4 4 4 4 4 4
44829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44830 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
44831 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
44832 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
44833 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44834 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
44835 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
44836 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
44837 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
44838 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
44839 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
44840 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
44841 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
44842 +0 0 0 4 4 4
44843 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44844 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
44845 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
44846 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
44847 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
44848 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
44849 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
44850 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
44851 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
44852 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
44853 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
44854 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
44855 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
44856 +2 0 0 0 0 0
44857 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
44858 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
44859 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
44860 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
44861 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
44862 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
44863 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
44864 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
44865 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
44866 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
44867 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
44868 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
44869 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
44870 +37 38 37 0 0 0
44871 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44872 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
44873 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
44874 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
44875 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
44876 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
44877 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
44878 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
44879 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
44880 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
44881 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
44882 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
44883 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
44884 +85 115 134 4 0 0
44885 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
44886 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
44887 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
44888 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
44889 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
44890 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
44891 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
44892 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
44893 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
44894 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
44895 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
44896 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
44897 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
44898 +60 73 81 4 0 0
44899 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
44900 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
44901 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
44902 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
44903 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
44904 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
44905 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
44906 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
44907 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
44908 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
44909 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
44910 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
44911 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
44912 +16 19 21 4 0 0
44913 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44914 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44915 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44916 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44917 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44918 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44919 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
44920 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
44921 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
44922 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
44923 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
44924 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
44925 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44926 +4 0 0 4 3 3
44927 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44928 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44929 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44931 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44932 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44933 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44934 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44935 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44936 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44937 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44938 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44939 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44940 +3 2 2 4 4 4
44941 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44942 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44943 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44944 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44945 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44946 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44947 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44948 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44949 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44950 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44951 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44952 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44953 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44954 +4 4 4 4 4 4
44955 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44956 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44957 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44958 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44959 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44960 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44961 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44962 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44963 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44964 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44965 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44966 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44967 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44968 +4 4 4 4 4 4
44969 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44970 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44971 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44972 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44973 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44974 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44975 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44976 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44977 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44978 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44979 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44980 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44981 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44982 +5 5 5 5 5 5
44983 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44984 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44985 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44986 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44987 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44988 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44989 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44990 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44991 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44992 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44993 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44994 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44995 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44996 +5 5 5 4 4 4
44997 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44998 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44999 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45000 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45001 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45002 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45003 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45004 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45005 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45006 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45007 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45008 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45010 +4 4 4 4 4 4
45011 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45012 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45013 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45014 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45015 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45016 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45017 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45018 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45019 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45020 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45021 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45022 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45024 +4 4 4 4 4 4
45025 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45026 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45027 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45028 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45029 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45030 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45031 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45032 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45033 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45034 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45035 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45038 +4 4 4 4 4 4
45039 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
45040 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
45041 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
45042 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
45043 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45044 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45045 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45046 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
45047 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
45048 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
45049 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
45050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45052 +4 4 4 4 4 4
45053 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
45054 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
45055 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
45056 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
45057 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45058 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
45059 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45060 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
45061 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
45062 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
45063 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45066 +4 4 4 4 4 4
45067 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
45068 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
45069 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
45070 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
45071 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45072 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
45073 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
45074 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
45075 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
45076 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
45077 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
45078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45080 +4 4 4 4 4 4
45081 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
45082 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
45083 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
45084 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
45085 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45086 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
45087 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
45088 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
45089 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
45090 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
45091 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
45092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45094 +4 4 4 4 4 4
45095 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
45096 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
45097 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
45098 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45099 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
45100 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
45101 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
45102 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
45103 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
45104 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
45105 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45108 +4 4 4 4 4 4
45109 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
45110 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
45111 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
45112 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45113 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45114 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
45115 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
45116 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
45117 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
45118 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
45119 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45122 +4 4 4 4 4 4
45123 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
45124 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
45125 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45126 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45127 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45128 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
45129 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
45130 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
45131 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
45132 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
45133 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45136 +4 4 4 4 4 4
45137 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
45138 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
45139 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45140 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45141 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45142 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
45143 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
45144 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
45145 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45146 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45147 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45150 +4 4 4 4 4 4
45151 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45152 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
45153 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45154 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
45155 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
45156 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
45157 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
45158 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
45159 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45160 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45161 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45164 +4 4 4 4 4 4
45165 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45166 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
45167 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45168 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
45169 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45170 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
45171 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
45172 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
45173 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45174 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45175 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45178 +4 4 4 4 4 4
45179 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
45180 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
45181 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45182 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
45183 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
45184 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
45185 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
45186 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
45187 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45188 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45189 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45192 +4 4 4 4 4 4
45193 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
45194 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
45195 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45196 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
45197 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
45198 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
45199 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
45200 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
45201 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45202 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45203 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45206 +4 4 4 4 4 4
45207 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45208 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
45209 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45210 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
45211 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
45212 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
45213 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
45214 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
45215 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45216 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45217 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45220 +4 4 4 4 4 4
45221 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
45222 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
45223 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45224 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
45225 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
45226 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
45227 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
45228 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
45229 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
45230 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45231 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45234 +4 4 4 4 4 4
45235 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45236 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
45237 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
45238 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
45239 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
45240 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
45241 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
45242 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
45243 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45244 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45245 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45248 +4 4 4 4 4 4
45249 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45250 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
45251 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45252 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
45253 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
45254 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
45255 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
45256 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
45257 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45258 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45259 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45262 +4 4 4 4 4 4
45263 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45264 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
45265 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
45266 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
45267 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
45268 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
45269 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45270 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
45271 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45272 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45273 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45276 +4 4 4 4 4 4
45277 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45278 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
45279 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
45280 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45281 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
45282 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
45283 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45284 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
45285 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45286 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45287 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45290 +4 4 4 4 4 4
45291 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45292 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
45293 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
45294 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
45295 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
45296 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
45297 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
45298 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
45299 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
45300 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45301 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45304 +4 4 4 4 4 4
45305 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45306 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
45307 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
45308 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
45309 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
45310 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
45311 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
45312 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
45313 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
45314 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45315 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45318 +4 4 4 4 4 4
45319 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
45320 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
45321 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
45322 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
45323 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45324 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
45325 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
45326 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
45327 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
45328 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45329 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45332 +4 4 4 4 4 4
45333 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45334 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
45335 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
45336 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
45337 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
45338 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
45339 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
45340 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
45341 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
45342 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45343 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45346 +4 4 4 4 4 4
45347 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
45348 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
45349 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
45350 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
45351 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
45352 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
45353 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
45354 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
45355 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
45356 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
45357 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45360 +4 4 4 4 4 4
45361 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
45362 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45363 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
45364 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
45365 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
45366 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
45367 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
45368 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
45369 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
45370 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
45371 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45374 +4 4 4 4 4 4
45375 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
45376 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45377 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
45378 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
45379 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
45380 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
45381 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45382 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
45383 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
45384 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
45385 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45388 +4 4 4 4 4 4
45389 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
45390 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
45391 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
45392 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
45393 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
45394 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
45395 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
45396 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
45397 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
45398 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
45399 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45402 +4 4 4 4 4 4
45403 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
45404 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
45405 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45406 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
45407 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
45408 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
45409 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
45410 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
45411 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
45412 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
45413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45416 +4 4 4 4 4 4
45417 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45418 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
45419 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
45420 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
45421 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
45422 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
45423 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
45424 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
45425 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
45426 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45430 +4 4 4 4 4 4
45431 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
45432 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
45433 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
45434 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
45435 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
45436 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
45437 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
45438 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
45439 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
45440 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45444 +4 4 4 4 4 4
45445 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
45446 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
45447 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
45448 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
45449 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
45450 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
45451 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
45452 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
45453 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45454 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45458 +4 4 4 4 4 4
45459 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
45460 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45461 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
45462 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45463 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
45464 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
45465 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
45466 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
45467 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
45468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45472 +4 4 4 4 4 4
45473 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
45474 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
45475 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
45476 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
45477 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
45478 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
45479 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
45480 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
45481 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
45482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45486 +4 4 4 4 4 4
45487 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45488 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
45489 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
45490 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
45491 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
45492 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
45493 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
45494 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
45495 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45500 +4 4 4 4 4 4
45501 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
45502 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
45503 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45504 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
45505 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
45506 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
45507 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
45508 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
45509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45514 +4 4 4 4 4 4
45515 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45516 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
45517 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
45518 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
45519 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
45520 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
45521 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
45522 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45528 +4 4 4 4 4 4
45529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45530 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
45531 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45532 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
45533 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
45534 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
45535 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
45536 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
45537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45542 +4 4 4 4 4 4
45543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45544 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
45545 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
45546 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
45547 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
45548 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
45549 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
45550 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
45551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45556 +4 4 4 4 4 4
45557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45558 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45559 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
45560 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45561 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
45562 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
45563 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
45564 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45570 +4 4 4 4 4 4
45571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45573 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45574 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
45575 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
45576 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
45577 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
45578 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45584 +4 4 4 4 4 4
45585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45588 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45589 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
45590 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
45591 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
45592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45598 +4 4 4 4 4 4
45599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45602 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45603 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45604 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
45605 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
45606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45612 +4 4 4 4 4 4
45613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45616 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45617 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45618 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45619 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
45620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45626 +4 4 4 4 4 4
45627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45630 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
45631 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
45632 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
45633 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
45634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45640 +4 4 4 4 4 4
45641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45645 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
45646 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45647 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45654 +4 4 4 4 4 4
45655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45659 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
45660 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
45661 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45668 +4 4 4 4 4 4
45669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45673 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
45674 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
45675 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45682 +4 4 4 4 4 4
45683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45687 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
45688 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
45689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45696 +4 4 4 4 4 4
45697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45701 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45702 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
45703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45710 +4 4 4 4 4 4
45711 diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
45712 index 443e3c8..c443d6a 100644
45713 --- a/drivers/video/nvidia/nv_backlight.c
45714 +++ b/drivers/video/nvidia/nv_backlight.c
45715 @@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(struct backlight_device *bd)
45716 return bd->props.brightness;
45717 }
45718
45719 -static struct backlight_ops nvidia_bl_ops = {
45720 +static const struct backlight_ops nvidia_bl_ops = {
45721 .get_brightness = nvidia_bl_get_brightness,
45722 .update_status = nvidia_bl_update_status,
45723 };
45724 diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
45725 index d94c57f..912984c 100644
45726 --- a/drivers/video/riva/fbdev.c
45727 +++ b/drivers/video/riva/fbdev.c
45728 @@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct backlight_device *bd)
45729 return bd->props.brightness;
45730 }
45731
45732 -static struct backlight_ops riva_bl_ops = {
45733 +static const struct backlight_ops riva_bl_ops = {
45734 .get_brightness = riva_bl_get_brightness,
45735 .update_status = riva_bl_update_status,
45736 };
45737 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
45738 index 54fbb29..2c108fc 100644
45739 --- a/drivers/video/uvesafb.c
45740 +++ b/drivers/video/uvesafb.c
45741 @@ -18,6 +18,7 @@
45742 #include <linux/fb.h>
45743 #include <linux/io.h>
45744 #include <linux/mutex.h>
45745 +#include <linux/moduleloader.h>
45746 #include <video/edid.h>
45747 #include <video/uvesafb.h>
45748 #ifdef CONFIG_X86
45749 @@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
45750 NULL,
45751 };
45752
45753 - return call_usermodehelper(v86d_path, argv, envp, 1);
45754 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
45755 }
45756
45757 /*
45758 @@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
45759 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
45760 par->pmi_setpal = par->ypan = 0;
45761 } else {
45762 +
45763 +#ifdef CONFIG_PAX_KERNEXEC
45764 +#ifdef CONFIG_MODULES
45765 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
45766 +#endif
45767 + if (!par->pmi_code) {
45768 + par->pmi_setpal = par->ypan = 0;
45769 + return 0;
45770 + }
45771 +#endif
45772 +
45773 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
45774 + task->t.regs.edi);
45775 +
45776 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45777 + pax_open_kernel();
45778 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
45779 + pax_close_kernel();
45780 +
45781 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
45782 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
45783 +#else
45784 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
45785 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
45786 +#endif
45787 +
45788 printk(KERN_INFO "uvesafb: protected mode interface info at "
45789 "%04x:%04x\n",
45790 (u16)task->t.regs.es, (u16)task->t.regs.edi);
45791 @@ -1799,6 +1822,11 @@ out:
45792 if (par->vbe_modes)
45793 kfree(par->vbe_modes);
45794
45795 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45796 + if (par->pmi_code)
45797 + module_free_exec(NULL, par->pmi_code);
45798 +#endif
45799 +
45800 framebuffer_release(info);
45801 return err;
45802 }
45803 @@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platform_device *dev)
45804 kfree(par->vbe_state_orig);
45805 if (par->vbe_state_saved)
45806 kfree(par->vbe_state_saved);
45807 +
45808 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45809 + if (par->pmi_code)
45810 + module_free_exec(NULL, par->pmi_code);
45811 +#endif
45812 +
45813 }
45814
45815 framebuffer_release(info);
45816 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
45817 index bd37ee1..cb827e8 100644
45818 --- a/drivers/video/vesafb.c
45819 +++ b/drivers/video/vesafb.c
45820 @@ -9,6 +9,7 @@
45821 */
45822
45823 #include <linux/module.h>
45824 +#include <linux/moduleloader.h>
45825 #include <linux/kernel.h>
45826 #include <linux/errno.h>
45827 #include <linux/string.h>
45828 @@ -53,8 +54,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
45829 static int vram_total __initdata; /* Set total amount of memory */
45830 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
45831 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
45832 -static void (*pmi_start)(void) __read_mostly;
45833 -static void (*pmi_pal) (void) __read_mostly;
45834 +static void (*pmi_start)(void) __read_only;
45835 +static void (*pmi_pal) (void) __read_only;
45836 static int depth __read_mostly;
45837 static int vga_compat __read_mostly;
45838 /* --------------------------------------------------------------------- */
45839 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
45840 unsigned int size_vmode;
45841 unsigned int size_remap;
45842 unsigned int size_total;
45843 + void *pmi_code = NULL;
45844
45845 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45846 return -ENODEV;
45847 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45848 size_remap = size_total;
45849 vesafb_fix.smem_len = size_remap;
45850
45851 -#ifndef __i386__
45852 - screen_info.vesapm_seg = 0;
45853 -#endif
45854 -
45855 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45856 printk(KERN_WARNING
45857 "vesafb: cannot reserve video memory at 0x%lx\n",
45858 @@ -315,9 +313,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45859 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45860 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45861
45862 +#ifdef __i386__
45863 +
45864 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45865 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
45866 + if (!pmi_code)
45867 +#elif !defined(CONFIG_PAX_KERNEXEC)
45868 + if (0)
45869 +#endif
45870 +
45871 +#endif
45872 + screen_info.vesapm_seg = 0;
45873 +
45874 if (screen_info.vesapm_seg) {
45875 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45876 - screen_info.vesapm_seg,screen_info.vesapm_off);
45877 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45878 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45879 }
45880
45881 if (screen_info.vesapm_seg < 0xc000)
45882 @@ -325,9 +335,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45883
45884 if (ypan || pmi_setpal) {
45885 unsigned short *pmi_base;
45886 +
45887 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45888 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45889 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45890 +
45891 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45892 + pax_open_kernel();
45893 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45894 +#else
45895 + pmi_code = pmi_base;
45896 +#endif
45897 +
45898 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45899 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45900 +
45901 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45902 + pmi_start = ktva_ktla(pmi_start);
45903 + pmi_pal = ktva_ktla(pmi_pal);
45904 + pax_close_kernel();
45905 +#endif
45906 +
45907 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45908 if (pmi_base[3]) {
45909 printk(KERN_INFO "vesafb: pmi: ports = ");
45910 @@ -469,6 +495,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45911 info->node, info->fix.id);
45912 return 0;
45913 err:
45914 +
45915 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45916 + module_free_exec(NULL, pmi_code);
45917 +#endif
45918 +
45919 if (info->screen_base)
45920 iounmap(info->screen_base);
45921 framebuffer_release(info);
45922 diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c
45923 index 88a60e0..6783cc2 100644
45924 --- a/drivers/xen/sys-hypervisor.c
45925 +++ b/drivers/xen/sys-hypervisor.c
45926 @@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct kobject *kobj,
45927 return 0;
45928 }
45929
45930 -static struct sysfs_ops hyp_sysfs_ops = {
45931 +static const struct sysfs_ops hyp_sysfs_ops = {
45932 .show = hyp_sysfs_show,
45933 .store = hyp_sysfs_store,
45934 };
45935 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45936 index 18f74ec..3227009 100644
45937 --- a/fs/9p/vfs_inode.c
45938 +++ b/fs/9p/vfs_inode.c
45939 @@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45940 static void
45941 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45942 {
45943 - char *s = nd_get_link(nd);
45944 + const char *s = nd_get_link(nd);
45945
45946 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
45947 IS_ERR(s) ? "<error>" : s);
45948 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45949 index bb4cc5b..df5eaa0 100644
45950 --- a/fs/Kconfig.binfmt
45951 +++ b/fs/Kconfig.binfmt
45952 @@ -86,7 +86,7 @@ config HAVE_AOUT
45953
45954 config BINFMT_AOUT
45955 tristate "Kernel support for a.out and ECOFF binaries"
45956 - depends on HAVE_AOUT
45957 + depends on HAVE_AOUT && BROKEN
45958 ---help---
45959 A.out (Assembler.OUTput) is a set of formats for libraries and
45960 executables used in the earliest versions of UNIX. Linux used
45961 diff --git a/fs/aio.c b/fs/aio.c
45962 index 22a19ad..d484e5b 100644
45963 --- a/fs/aio.c
45964 +++ b/fs/aio.c
45965 @@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45966 size += sizeof(struct io_event) * nr_events;
45967 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45968
45969 - if (nr_pages < 0)
45970 + if (nr_pages <= 0)
45971 return -EINVAL;
45972
45973 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45974 @@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ctx,
45975 struct aio_timeout to;
45976 int retry = 0;
45977
45978 + pax_track_stack();
45979 +
45980 /* needed to zero any padding within an entry (there shouldn't be
45981 * any, but C is fun!
45982 */
45983 @@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45984 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
45985 {
45986 ssize_t ret;
45987 + struct iovec iovstack;
45988
45989 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
45990 kiocb->ki_nbytes, 1,
45991 - &kiocb->ki_inline_vec, &kiocb->ki_iovec);
45992 + &iovstack, &kiocb->ki_iovec);
45993 if (ret < 0)
45994 goto out;
45995
45996 + if (kiocb->ki_iovec == &iovstack) {
45997 + kiocb->ki_inline_vec = iovstack;
45998 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
45999 + }
46000 kiocb->ki_nr_segs = kiocb->ki_nbytes;
46001 kiocb->ki_cur_seg = 0;
46002 /* ki_nbytes/left now reflect bytes instead of segs */
46003 diff --git a/fs/attr.c b/fs/attr.c
46004 index 96d394b..33cf5b4 100644
46005 --- a/fs/attr.c
46006 +++ b/fs/attr.c
46007 @@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
46008 unsigned long limit;
46009
46010 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
46011 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
46012 if (limit != RLIM_INFINITY && offset > limit)
46013 goto out_sig;
46014 if (offset > inode->i_sb->s_maxbytes)
46015 diff --git a/fs/autofs/root.c b/fs/autofs/root.c
46016 index 4a1401c..05eb5ca 100644
46017 --- a/fs/autofs/root.c
46018 +++ b/fs/autofs/root.c
46019 @@ -299,7 +299,8 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
46020 set_bit(n,sbi->symlink_bitmap);
46021 sl = &sbi->symlink[n];
46022 sl->len = strlen(symname);
46023 - sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
46024 + slsize = sl->len+1;
46025 + sl->data = kmalloc(slsize, GFP_KERNEL);
46026 if (!sl->data) {
46027 clear_bit(n,sbi->symlink_bitmap);
46028 unlock_kernel();
46029 diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
46030 index b4ea829..e63ef18 100644
46031 --- a/fs/autofs4/symlink.c
46032 +++ b/fs/autofs4/symlink.c
46033 @@ -15,7 +15,7 @@
46034 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
46035 {
46036 struct autofs_info *ino = autofs4_dentry_ino(dentry);
46037 - nd_set_link(nd, (char *)ino->u.symlink);
46038 + nd_set_link(nd, ino->u.symlink);
46039 return NULL;
46040 }
46041
46042 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
46043 index 2341375..df9d1c2 100644
46044 --- a/fs/autofs4/waitq.c
46045 +++ b/fs/autofs4/waitq.c
46046 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
46047 {
46048 unsigned long sigpipe, flags;
46049 mm_segment_t fs;
46050 - const char *data = (const char *)addr;
46051 + const char __user *data = (const char __force_user *)addr;
46052 ssize_t wr = 0;
46053
46054 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
46055 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
46056 index 9158c07..3f06659 100644
46057 --- a/fs/befs/linuxvfs.c
46058 +++ b/fs/befs/linuxvfs.c
46059 @@ -498,7 +498,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46060 {
46061 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
46062 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
46063 - char *link = nd_get_link(nd);
46064 + const char *link = nd_get_link(nd);
46065 if (!IS_ERR(link))
46066 kfree(link);
46067 }
46068 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
46069 index 0133b5a..b3baa9f 100644
46070 --- a/fs/binfmt_aout.c
46071 +++ b/fs/binfmt_aout.c
46072 @@ -16,6 +16,7 @@
46073 #include <linux/string.h>
46074 #include <linux/fs.h>
46075 #include <linux/file.h>
46076 +#include <linux/security.h>
46077 #include <linux/stat.h>
46078 #include <linux/fcntl.h>
46079 #include <linux/ptrace.h>
46080 @@ -102,6 +103,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46081 #endif
46082 # define START_STACK(u) (u.start_stack)
46083
46084 + memset(&dump, 0, sizeof(dump));
46085 +
46086 fs = get_fs();
46087 set_fs(KERNEL_DS);
46088 has_dumped = 1;
46089 @@ -113,10 +116,12 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46090
46091 /* If the size of the dump file exceeds the rlimit, then see what would happen
46092 if we wrote the stack, but not the data area. */
46093 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
46094 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
46095 dump.u_dsize = 0;
46096
46097 /* Make sure we have enough room to write the stack and data areas. */
46098 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
46099 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
46100 dump.u_ssize = 0;
46101
46102 @@ -146,9 +151,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46103 dump_size = dump.u_ssize << PAGE_SHIFT;
46104 DUMP_WRITE(dump_start,dump_size);
46105 }
46106 -/* Finally dump the task struct. Not be used by gdb, but could be useful */
46107 - set_fs(KERNEL_DS);
46108 - DUMP_WRITE(current,sizeof(*current));
46109 +/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
46110 end_coredump:
46111 set_fs(fs);
46112 return has_dumped;
46113 @@ -249,6 +252,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46114 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
46115 if (rlim >= RLIM_INFINITY)
46116 rlim = ~0;
46117 +
46118 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
46119 if (ex.a_data + ex.a_bss > rlim)
46120 return -ENOMEM;
46121
46122 @@ -277,6 +282,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46123 install_exec_creds(bprm);
46124 current->flags &= ~PF_FORKNOEXEC;
46125
46126 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46127 + current->mm->pax_flags = 0UL;
46128 +#endif
46129 +
46130 +#ifdef CONFIG_PAX_PAGEEXEC
46131 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
46132 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
46133 +
46134 +#ifdef CONFIG_PAX_EMUTRAMP
46135 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
46136 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
46137 +#endif
46138 +
46139 +#ifdef CONFIG_PAX_MPROTECT
46140 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
46141 + current->mm->pax_flags |= MF_PAX_MPROTECT;
46142 +#endif
46143 +
46144 + }
46145 +#endif
46146 +
46147 if (N_MAGIC(ex) == OMAGIC) {
46148 unsigned long text_addr, map_size;
46149 loff_t pos;
46150 @@ -349,7 +375,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46151
46152 down_write(&current->mm->mmap_sem);
46153 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
46154 - PROT_READ | PROT_WRITE | PROT_EXEC,
46155 + PROT_READ | PROT_WRITE,
46156 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
46157 fd_offset + ex.a_text);
46158 up_write(&current->mm->mmap_sem);
46159 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
46160 index 1ed37ba..32cc555 100644
46161 --- a/fs/binfmt_elf.c
46162 +++ b/fs/binfmt_elf.c
46163 @@ -50,6 +50,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46164 #define elf_core_dump NULL
46165 #endif
46166
46167 +#ifdef CONFIG_PAX_MPROTECT
46168 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
46169 +#endif
46170 +
46171 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
46172 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
46173 #else
46174 @@ -69,6 +73,11 @@ static struct linux_binfmt elf_format = {
46175 .load_binary = load_elf_binary,
46176 .load_shlib = load_elf_library,
46177 .core_dump = elf_core_dump,
46178 +
46179 +#ifdef CONFIG_PAX_MPROTECT
46180 + .handle_mprotect= elf_handle_mprotect,
46181 +#endif
46182 +
46183 .min_coredump = ELF_EXEC_PAGESIZE,
46184 .hasvdso = 1
46185 };
46186 @@ -77,6 +86,8 @@ static struct linux_binfmt elf_format = {
46187
46188 static int set_brk(unsigned long start, unsigned long end)
46189 {
46190 + unsigned long e = end;
46191 +
46192 start = ELF_PAGEALIGN(start);
46193 end = ELF_PAGEALIGN(end);
46194 if (end > start) {
46195 @@ -87,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
46196 if (BAD_ADDR(addr))
46197 return addr;
46198 }
46199 - current->mm->start_brk = current->mm->brk = end;
46200 + current->mm->start_brk = current->mm->brk = e;
46201 return 0;
46202 }
46203
46204 @@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46205 elf_addr_t __user *u_rand_bytes;
46206 const char *k_platform = ELF_PLATFORM;
46207 const char *k_base_platform = ELF_BASE_PLATFORM;
46208 - unsigned char k_rand_bytes[16];
46209 + u32 k_rand_bytes[4];
46210 int items;
46211 elf_addr_t *elf_info;
46212 int ei_index = 0;
46213 const struct cred *cred = current_cred();
46214 struct vm_area_struct *vma;
46215 + unsigned long saved_auxv[AT_VECTOR_SIZE];
46216 +
46217 + pax_track_stack();
46218
46219 /*
46220 * In some cases (e.g. Hyper-Threading), we want to avoid L1
46221 @@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46222 * Generate 16 random bytes for userspace PRNG seeding.
46223 */
46224 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
46225 - u_rand_bytes = (elf_addr_t __user *)
46226 - STACK_ALLOC(p, sizeof(k_rand_bytes));
46227 + srandom32(k_rand_bytes[0] ^ random32());
46228 + srandom32(k_rand_bytes[1] ^ random32());
46229 + srandom32(k_rand_bytes[2] ^ random32());
46230 + srandom32(k_rand_bytes[3] ^ random32());
46231 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
46232 + u_rand_bytes = (elf_addr_t __user *) p;
46233 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
46234 return -EFAULT;
46235
46236 @@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46237 return -EFAULT;
46238 current->mm->env_end = p;
46239
46240 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
46241 +
46242 /* Put the elf_info on the stack in the right place. */
46243 sp = (elf_addr_t __user *)envp + 1;
46244 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
46245 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
46246 return -EFAULT;
46247 return 0;
46248 }
46249 @@ -385,10 +405,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46250 {
46251 struct elf_phdr *elf_phdata;
46252 struct elf_phdr *eppnt;
46253 - unsigned long load_addr = 0;
46254 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
46255 int load_addr_set = 0;
46256 unsigned long last_bss = 0, elf_bss = 0;
46257 - unsigned long error = ~0UL;
46258 + unsigned long error = -EINVAL;
46259 unsigned long total_size;
46260 int retval, i, size;
46261
46262 @@ -434,6 +454,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46263 goto out_close;
46264 }
46265
46266 +#ifdef CONFIG_PAX_SEGMEXEC
46267 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
46268 + pax_task_size = SEGMEXEC_TASK_SIZE;
46269 +#endif
46270 +
46271 eppnt = elf_phdata;
46272 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
46273 if (eppnt->p_type == PT_LOAD) {
46274 @@ -477,8 +502,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46275 k = load_addr + eppnt->p_vaddr;
46276 if (BAD_ADDR(k) ||
46277 eppnt->p_filesz > eppnt->p_memsz ||
46278 - eppnt->p_memsz > TASK_SIZE ||
46279 - TASK_SIZE - eppnt->p_memsz < k) {
46280 + eppnt->p_memsz > pax_task_size ||
46281 + pax_task_size - eppnt->p_memsz < k) {
46282 error = -ENOMEM;
46283 goto out_close;
46284 }
46285 @@ -532,6 +557,194 @@ out:
46286 return error;
46287 }
46288
46289 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
46290 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
46291 +{
46292 + unsigned long pax_flags = 0UL;
46293 +
46294 +#ifdef CONFIG_PAX_PAGEEXEC
46295 + if (elf_phdata->p_flags & PF_PAGEEXEC)
46296 + pax_flags |= MF_PAX_PAGEEXEC;
46297 +#endif
46298 +
46299 +#ifdef CONFIG_PAX_SEGMEXEC
46300 + if (elf_phdata->p_flags & PF_SEGMEXEC)
46301 + pax_flags |= MF_PAX_SEGMEXEC;
46302 +#endif
46303 +
46304 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46305 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46306 + if (nx_enabled)
46307 + pax_flags &= ~MF_PAX_SEGMEXEC;
46308 + else
46309 + pax_flags &= ~MF_PAX_PAGEEXEC;
46310 + }
46311 +#endif
46312 +
46313 +#ifdef CONFIG_PAX_EMUTRAMP
46314 + if (elf_phdata->p_flags & PF_EMUTRAMP)
46315 + pax_flags |= MF_PAX_EMUTRAMP;
46316 +#endif
46317 +
46318 +#ifdef CONFIG_PAX_MPROTECT
46319 + if (elf_phdata->p_flags & PF_MPROTECT)
46320 + pax_flags |= MF_PAX_MPROTECT;
46321 +#endif
46322 +
46323 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46324 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
46325 + pax_flags |= MF_PAX_RANDMMAP;
46326 +#endif
46327 +
46328 + return pax_flags;
46329 +}
46330 +#endif
46331 +
46332 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
46333 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
46334 +{
46335 + unsigned long pax_flags = 0UL;
46336 +
46337 +#ifdef CONFIG_PAX_PAGEEXEC
46338 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
46339 + pax_flags |= MF_PAX_PAGEEXEC;
46340 +#endif
46341 +
46342 +#ifdef CONFIG_PAX_SEGMEXEC
46343 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
46344 + pax_flags |= MF_PAX_SEGMEXEC;
46345 +#endif
46346 +
46347 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46348 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46349 + if (nx_enabled)
46350 + pax_flags &= ~MF_PAX_SEGMEXEC;
46351 + else
46352 + pax_flags &= ~MF_PAX_PAGEEXEC;
46353 + }
46354 +#endif
46355 +
46356 +#ifdef CONFIG_PAX_EMUTRAMP
46357 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
46358 + pax_flags |= MF_PAX_EMUTRAMP;
46359 +#endif
46360 +
46361 +#ifdef CONFIG_PAX_MPROTECT
46362 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
46363 + pax_flags |= MF_PAX_MPROTECT;
46364 +#endif
46365 +
46366 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46367 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
46368 + pax_flags |= MF_PAX_RANDMMAP;
46369 +#endif
46370 +
46371 + return pax_flags;
46372 +}
46373 +#endif
46374 +
46375 +#ifdef CONFIG_PAX_EI_PAX
46376 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
46377 +{
46378 + unsigned long pax_flags = 0UL;
46379 +
46380 +#ifdef CONFIG_PAX_PAGEEXEC
46381 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
46382 + pax_flags |= MF_PAX_PAGEEXEC;
46383 +#endif
46384 +
46385 +#ifdef CONFIG_PAX_SEGMEXEC
46386 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
46387 + pax_flags |= MF_PAX_SEGMEXEC;
46388 +#endif
46389 +
46390 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46391 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46392 + if (nx_enabled)
46393 + pax_flags &= ~MF_PAX_SEGMEXEC;
46394 + else
46395 + pax_flags &= ~MF_PAX_PAGEEXEC;
46396 + }
46397 +#endif
46398 +
46399 +#ifdef CONFIG_PAX_EMUTRAMP
46400 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
46401 + pax_flags |= MF_PAX_EMUTRAMP;
46402 +#endif
46403 +
46404 +#ifdef CONFIG_PAX_MPROTECT
46405 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
46406 + pax_flags |= MF_PAX_MPROTECT;
46407 +#endif
46408 +
46409 +#ifdef CONFIG_PAX_ASLR
46410 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
46411 + pax_flags |= MF_PAX_RANDMMAP;
46412 +#endif
46413 +
46414 + return pax_flags;
46415 +}
46416 +#endif
46417 +
46418 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
46419 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
46420 +{
46421 + unsigned long pax_flags = 0UL;
46422 +
46423 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
46424 + unsigned long i;
46425 + int found_flags = 0;
46426 +#endif
46427 +
46428 +#ifdef CONFIG_PAX_EI_PAX
46429 + pax_flags = pax_parse_ei_pax(elf_ex);
46430 +#endif
46431 +
46432 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
46433 + for (i = 0UL; i < elf_ex->e_phnum; i++)
46434 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
46435 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
46436 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
46437 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
46438 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
46439 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
46440 + return -EINVAL;
46441 +
46442 +#ifdef CONFIG_PAX_SOFTMODE
46443 + if (pax_softmode)
46444 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
46445 + else
46446 +#endif
46447 +
46448 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
46449 + found_flags = 1;
46450 + break;
46451 + }
46452 +#endif
46453 +
46454 +#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
46455 + if (found_flags == 0) {
46456 + struct elf_phdr phdr;
46457 + memset(&phdr, 0, sizeof(phdr));
46458 + phdr.p_flags = PF_NOEMUTRAMP;
46459 +#ifdef CONFIG_PAX_SOFTMODE
46460 + if (pax_softmode)
46461 + pax_flags = pax_parse_softmode(&phdr);
46462 + else
46463 +#endif
46464 + pax_flags = pax_parse_hardmode(&phdr);
46465 + }
46466 +#endif
46467 +
46468 +
46469 + if (0 > pax_check_flags(&pax_flags))
46470 + return -EINVAL;
46471 +
46472 + current->mm->pax_flags = pax_flags;
46473 + return 0;
46474 +}
46475 +#endif
46476 +
46477 /*
46478 * These are the functions used to load ELF style executables and shared
46479 * libraries. There is no binary dependent code anywhere else.
46480 @@ -548,6 +761,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
46481 {
46482 unsigned int random_variable = 0;
46483
46484 +#ifdef CONFIG_PAX_RANDUSTACK
46485 + if (randomize_va_space)
46486 + return stack_top - current->mm->delta_stack;
46487 +#endif
46488 +
46489 if ((current->flags & PF_RANDOMIZE) &&
46490 !(current->personality & ADDR_NO_RANDOMIZE)) {
46491 random_variable = get_random_int() & STACK_RND_MASK;
46492 @@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46493 unsigned long load_addr = 0, load_bias = 0;
46494 int load_addr_set = 0;
46495 char * elf_interpreter = NULL;
46496 - unsigned long error;
46497 + unsigned long error = 0;
46498 struct elf_phdr *elf_ppnt, *elf_phdata;
46499 unsigned long elf_bss, elf_brk;
46500 int retval, i;
46501 @@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46502 unsigned long start_code, end_code, start_data, end_data;
46503 unsigned long reloc_func_desc = 0;
46504 int executable_stack = EXSTACK_DEFAULT;
46505 - unsigned long def_flags = 0;
46506 struct {
46507 struct elfhdr elf_ex;
46508 struct elfhdr interp_elf_ex;
46509 } *loc;
46510 + unsigned long pax_task_size = TASK_SIZE;
46511
46512 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
46513 if (!loc) {
46514 @@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46515
46516 /* OK, This is the point of no return */
46517 current->flags &= ~PF_FORKNOEXEC;
46518 - current->mm->def_flags = def_flags;
46519 +
46520 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46521 + current->mm->pax_flags = 0UL;
46522 +#endif
46523 +
46524 +#ifdef CONFIG_PAX_DLRESOLVE
46525 + current->mm->call_dl_resolve = 0UL;
46526 +#endif
46527 +
46528 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46529 + current->mm->call_syscall = 0UL;
46530 +#endif
46531 +
46532 +#ifdef CONFIG_PAX_ASLR
46533 + current->mm->delta_mmap = 0UL;
46534 + current->mm->delta_stack = 0UL;
46535 +#endif
46536 +
46537 + current->mm->def_flags = 0;
46538 +
46539 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
46540 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
46541 + send_sig(SIGKILL, current, 0);
46542 + goto out_free_dentry;
46543 + }
46544 +#endif
46545 +
46546 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46547 + pax_set_initial_flags(bprm);
46548 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
46549 + if (pax_set_initial_flags_func)
46550 + (pax_set_initial_flags_func)(bprm);
46551 +#endif
46552 +
46553 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46554 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
46555 + current->mm->context.user_cs_limit = PAGE_SIZE;
46556 + current->mm->def_flags |= VM_PAGEEXEC;
46557 + }
46558 +#endif
46559 +
46560 +#ifdef CONFIG_PAX_SEGMEXEC
46561 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
46562 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
46563 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
46564 + pax_task_size = SEGMEXEC_TASK_SIZE;
46565 + }
46566 +#endif
46567 +
46568 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
46569 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46570 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
46571 + put_cpu();
46572 + }
46573 +#endif
46574
46575 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
46576 may depend on the personality. */
46577 SET_PERSONALITY(loc->elf_ex);
46578 +
46579 +#ifdef CONFIG_PAX_ASLR
46580 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
46581 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
46582 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
46583 + }
46584 +#endif
46585 +
46586 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46587 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46588 + executable_stack = EXSTACK_DISABLE_X;
46589 + current->personality &= ~READ_IMPLIES_EXEC;
46590 + } else
46591 +#endif
46592 +
46593 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
46594 current->personality |= READ_IMPLIES_EXEC;
46595
46596 @@ -800,10 +1087,27 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46597 * might try to exec. This is because the brk will
46598 * follow the loader, and is not movable. */
46599 #ifdef CONFIG_X86
46600 - load_bias = 0;
46601 + if (current->flags & PF_RANDOMIZE)
46602 + load_bias = 0;
46603 + else
46604 + load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46605 #else
46606 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46607 #endif
46608 +
46609 +#ifdef CONFIG_PAX_RANDMMAP
46610 + /* PaX: randomize base address at the default exe base if requested */
46611 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
46612 +#ifdef CONFIG_SPARC64
46613 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
46614 +#else
46615 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
46616 +#endif
46617 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
46618 + elf_flags |= MAP_FIXED;
46619 + }
46620 +#endif
46621 +
46622 }
46623
46624 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
46625 @@ -836,9 +1140,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46626 * allowed task size. Note that p_filesz must always be
46627 * <= p_memsz so it is only necessary to check p_memsz.
46628 */
46629 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46630 - elf_ppnt->p_memsz > TASK_SIZE ||
46631 - TASK_SIZE - elf_ppnt->p_memsz < k) {
46632 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46633 + elf_ppnt->p_memsz > pax_task_size ||
46634 + pax_task_size - elf_ppnt->p_memsz < k) {
46635 /* set_brk can never work. Avoid overflows. */
46636 send_sig(SIGKILL, current, 0);
46637 retval = -EINVAL;
46638 @@ -866,6 +1170,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46639 start_data += load_bias;
46640 end_data += load_bias;
46641
46642 +#ifdef CONFIG_PAX_RANDMMAP
46643 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
46644 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
46645 +#endif
46646 +
46647 /* Calling set_brk effectively mmaps the pages that we need
46648 * for the bss and break sections. We must do this before
46649 * mapping in the interpreter, to make sure it doesn't wind
46650 @@ -877,9 +1186,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46651 goto out_free_dentry;
46652 }
46653 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
46654 - send_sig(SIGSEGV, current, 0);
46655 - retval = -EFAULT; /* Nobody gets to see this, but.. */
46656 - goto out_free_dentry;
46657 + /*
46658 + * This bss-zeroing can fail if the ELF
46659 + * file specifies odd protections. So
46660 + * we don't check the return value
46661 + */
46662 }
46663
46664 if (elf_interpreter) {
46665 @@ -1112,8 +1423,10 @@ static int dump_seek(struct file *file, loff_t off)
46666 unsigned long n = off;
46667 if (n > PAGE_SIZE)
46668 n = PAGE_SIZE;
46669 - if (!dump_write(file, buf, n))
46670 + if (!dump_write(file, buf, n)) {
46671 + free_page((unsigned long)buf);
46672 return 0;
46673 + }
46674 off -= n;
46675 }
46676 free_page((unsigned long)buf);
46677 @@ -1125,7 +1438,7 @@ static int dump_seek(struct file *file, loff_t off)
46678 * Decide what to dump of a segment, part, all or none.
46679 */
46680 static unsigned long vma_dump_size(struct vm_area_struct *vma,
46681 - unsigned long mm_flags)
46682 + unsigned long mm_flags, long signr)
46683 {
46684 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
46685
46686 @@ -1159,7 +1472,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
46687 if (vma->vm_file == NULL)
46688 return 0;
46689
46690 - if (FILTER(MAPPED_PRIVATE))
46691 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46692 goto whole;
46693
46694 /*
46695 @@ -1255,8 +1568,11 @@ static int writenote(struct memelfnote *men, struct file *file,
46696 #undef DUMP_WRITE
46697
46698 #define DUMP_WRITE(addr, nr) \
46699 + do { \
46700 + gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
46701 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
46702 - goto end_coredump;
46703 + goto end_coredump; \
46704 + } while (0);
46705
46706 static void fill_elf_header(struct elfhdr *elf, int segs,
46707 u16 machine, u32 flags, u8 osabi)
46708 @@ -1385,9 +1701,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46709 {
46710 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46711 int i = 0;
46712 - do
46713 + do {
46714 i += 2;
46715 - while (auxv[i - 2] != AT_NULL);
46716 + } while (auxv[i - 2] != AT_NULL);
46717 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46718 }
46719
46720 @@ -1973,7 +2289,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46721 phdr.p_offset = offset;
46722 phdr.p_vaddr = vma->vm_start;
46723 phdr.p_paddr = 0;
46724 - phdr.p_filesz = vma_dump_size(vma, mm_flags);
46725 + phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
46726 phdr.p_memsz = vma->vm_end - vma->vm_start;
46727 offset += phdr.p_filesz;
46728 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46729 @@ -2006,7 +2322,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46730 unsigned long addr;
46731 unsigned long end;
46732
46733 - end = vma->vm_start + vma_dump_size(vma, mm_flags);
46734 + end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
46735
46736 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46737 struct page *page;
46738 @@ -2015,6 +2331,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46739 page = get_dump_page(addr);
46740 if (page) {
46741 void *kaddr = kmap(page);
46742 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46743 stop = ((size += PAGE_SIZE) > limit) ||
46744 !dump_write(file, kaddr, PAGE_SIZE);
46745 kunmap(page);
46746 @@ -2042,6 +2359,97 @@ out:
46747
46748 #endif /* USE_ELF_CORE_DUMP */
46749
46750 +#ifdef CONFIG_PAX_MPROTECT
46751 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
46752 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46753 + * we'll remove VM_MAYWRITE for good on RELRO segments.
46754 + *
46755 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46756 + * basis because we want to allow the common case and not the special ones.
46757 + */
46758 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46759 +{
46760 + struct elfhdr elf_h;
46761 + struct elf_phdr elf_p;
46762 + unsigned long i;
46763 + unsigned long oldflags;
46764 + bool is_textrel_rw, is_textrel_rx, is_relro;
46765 +
46766 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46767 + return;
46768 +
46769 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46770 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46771 +
46772 +#ifdef CONFIG_PAX_ELFRELOCS
46773 + /* possible TEXTREL */
46774 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46775 + 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);
46776 +#else
46777 + is_textrel_rw = false;
46778 + is_textrel_rx = false;
46779 +#endif
46780 +
46781 + /* possible RELRO */
46782 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46783 +
46784 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46785 + return;
46786 +
46787 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46788 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46789 +
46790 +#ifdef CONFIG_PAX_ETEXECRELOCS
46791 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46792 +#else
46793 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46794 +#endif
46795 +
46796 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46797 + !elf_check_arch(&elf_h) ||
46798 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46799 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46800 + return;
46801 +
46802 + for (i = 0UL; i < elf_h.e_phnum; i++) {
46803 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46804 + return;
46805 + switch (elf_p.p_type) {
46806 + case PT_DYNAMIC:
46807 + if (!is_textrel_rw && !is_textrel_rx)
46808 + continue;
46809 + i = 0UL;
46810 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46811 + elf_dyn dyn;
46812 +
46813 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46814 + return;
46815 + if (dyn.d_tag == DT_NULL)
46816 + return;
46817 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46818 + gr_log_textrel(vma);
46819 + if (is_textrel_rw)
46820 + vma->vm_flags |= VM_MAYWRITE;
46821 + else
46822 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46823 + vma->vm_flags &= ~VM_MAYWRITE;
46824 + return;
46825 + }
46826 + i++;
46827 + }
46828 + return;
46829 +
46830 + case PT_GNU_RELRO:
46831 + if (!is_relro)
46832 + continue;
46833 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46834 + vma->vm_flags &= ~VM_MAYWRITE;
46835 + return;
46836 + }
46837 + }
46838 +}
46839 +#endif
46840 +
46841 static int __init init_elf_binfmt(void)
46842 {
46843 return register_binfmt(&elf_format);
46844 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46845 index ca88c46..f155a60 100644
46846 --- a/fs/binfmt_flat.c
46847 +++ b/fs/binfmt_flat.c
46848 @@ -564,7 +564,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46849 realdatastart = (unsigned long) -ENOMEM;
46850 printk("Unable to allocate RAM for process data, errno %d\n",
46851 (int)-realdatastart);
46852 + down_write(&current->mm->mmap_sem);
46853 do_munmap(current->mm, textpos, text_len);
46854 + up_write(&current->mm->mmap_sem);
46855 ret = realdatastart;
46856 goto err;
46857 }
46858 @@ -588,8 +590,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46859 }
46860 if (IS_ERR_VALUE(result)) {
46861 printk("Unable to read data+bss, errno %d\n", (int)-result);
46862 + down_write(&current->mm->mmap_sem);
46863 do_munmap(current->mm, textpos, text_len);
46864 do_munmap(current->mm, realdatastart, data_len + extra);
46865 + up_write(&current->mm->mmap_sem);
46866 ret = result;
46867 goto err;
46868 }
46869 @@ -658,8 +662,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46870 }
46871 if (IS_ERR_VALUE(result)) {
46872 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46873 + down_write(&current->mm->mmap_sem);
46874 do_munmap(current->mm, textpos, text_len + data_len + extra +
46875 MAX_SHARED_LIBS * sizeof(unsigned long));
46876 + up_write(&current->mm->mmap_sem);
46877 ret = result;
46878 goto err;
46879 }
46880 diff --git a/fs/bio.c b/fs/bio.c
46881 index e696713..83de133 100644
46882 --- a/fs/bio.c
46883 +++ b/fs/bio.c
46884 @@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
46885
46886 i = 0;
46887 while (i < bio_slab_nr) {
46888 - struct bio_slab *bslab = &bio_slabs[i];
46889 + bslab = &bio_slabs[i];
46890
46891 if (!bslab->slab && entry == -1)
46892 entry = i;
46893 @@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46894 const int read = bio_data_dir(bio) == READ;
46895 struct bio_map_data *bmd = bio->bi_private;
46896 int i;
46897 - char *p = bmd->sgvecs[0].iov_base;
46898 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46899
46900 __bio_for_each_segment(bvec, bio, i, 0) {
46901 char *addr = page_address(bvec->bv_page);
46902 diff --git a/fs/block_dev.c b/fs/block_dev.c
46903 index e65efa2..04fae57 100644
46904 --- a/fs/block_dev.c
46905 +++ b/fs/block_dev.c
46906 @@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev, void *holder)
46907 else if (bdev->bd_contains == bdev)
46908 res = 0; /* is a whole device which isn't held */
46909
46910 - else if (bdev->bd_contains->bd_holder == bd_claim)
46911 + else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
46912 res = 0; /* is a partition of a device that is being partitioned */
46913 else if (bdev->bd_contains->bd_holder != NULL)
46914 res = -EBUSY; /* is a partition of a held device */
46915 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46916 index c4bc570..42acd8d 100644
46917 --- a/fs/btrfs/ctree.c
46918 +++ b/fs/btrfs/ctree.c
46919 @@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46920 free_extent_buffer(buf);
46921 add_root_to_dirty_list(root);
46922 } else {
46923 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46924 - parent_start = parent->start;
46925 - else
46926 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46927 + if (parent)
46928 + parent_start = parent->start;
46929 + else
46930 + parent_start = 0;
46931 + } else
46932 parent_start = 0;
46933
46934 WARN_ON(trans->transid != btrfs_header_generation(parent));
46935 @@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_trans_handle *trans,
46936
46937 ret = 0;
46938 if (slot == 0) {
46939 - struct btrfs_disk_key disk_key;
46940 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
46941 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
46942 }
46943 diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
46944 index f447188..59c17c5 100644
46945 --- a/fs/btrfs/disk-io.c
46946 +++ b/fs/btrfs/disk-io.c
46947 @@ -39,7 +39,7 @@
46948 #include "tree-log.h"
46949 #include "free-space-cache.h"
46950
46951 -static struct extent_io_ops btree_extent_io_ops;
46952 +static const struct extent_io_ops btree_extent_io_ops;
46953 static void end_workqueue_fn(struct btrfs_work *work);
46954 static void free_fs_root(struct btrfs_root *root);
46955
46956 @@ -2607,7 +2607,7 @@ out:
46957 return 0;
46958 }
46959
46960 -static struct extent_io_ops btree_extent_io_ops = {
46961 +static const struct extent_io_ops btree_extent_io_ops = {
46962 .write_cache_pages_lock_hook = btree_lock_page_hook,
46963 .readpage_end_io_hook = btree_readpage_end_io_hook,
46964 .submit_bio_hook = btree_submit_bio_hook,
46965 diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
46966 index 559f724..a026171 100644
46967 --- a/fs/btrfs/extent-tree.c
46968 +++ b/fs/btrfs/extent-tree.c
46969 @@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,
46970 u64 group_start = group->key.objectid;
46971 new_extents = kmalloc(sizeof(*new_extents),
46972 GFP_NOFS);
46973 + if (!new_extents) {
46974 + ret = -ENOMEM;
46975 + goto out;
46976 + }
46977 nr_extents = 1;
46978 ret = get_new_locations(reloc_inode,
46979 extent_key,
46980 diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
46981 index 36de250..7ec75c7 100644
46982 --- a/fs/btrfs/extent_io.h
46983 +++ b/fs/btrfs/extent_io.h
46984 @@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
46985 struct bio *bio, int mirror_num,
46986 unsigned long bio_flags);
46987 struct extent_io_ops {
46988 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
46989 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
46990 u64 start, u64 end, int *page_started,
46991 unsigned long *nr_written);
46992 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
46993 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
46994 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
46995 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
46996 extent_submit_bio_hook_t *submit_bio_hook;
46997 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
46998 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
46999 size_t size, struct bio *bio,
47000 unsigned long bio_flags);
47001 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
47002 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47003 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
47004 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
47005 u64 start, u64 end,
47006 struct extent_state *state);
47007 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
47008 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
47009 u64 start, u64 end,
47010 struct extent_state *state);
47011 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47012 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47013 struct extent_state *state);
47014 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47015 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47016 struct extent_state *state, int uptodate);
47017 - int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
47018 + int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
47019 unsigned long old, unsigned long bits);
47020 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
47021 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
47022 unsigned long bits);
47023 - int (*merge_extent_hook)(struct inode *inode,
47024 + int (* const merge_extent_hook)(struct inode *inode,
47025 struct extent_state *new,
47026 struct extent_state *other);
47027 - int (*split_extent_hook)(struct inode *inode,
47028 + int (* const split_extent_hook)(struct inode *inode,
47029 struct extent_state *orig, u64 split);
47030 - int (*write_cache_pages_lock_hook)(struct page *page);
47031 + int (* const write_cache_pages_lock_hook)(struct page *page);
47032 };
47033
47034 struct extent_io_tree {
47035 @@ -88,7 +88,7 @@ struct extent_io_tree {
47036 u64 dirty_bytes;
47037 spinlock_t lock;
47038 spinlock_t buffer_lock;
47039 - struct extent_io_ops *ops;
47040 + const struct extent_io_ops *ops;
47041 };
47042
47043 struct extent_state {
47044 diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
47045 index cb2849f..3718fb4 100644
47046 --- a/fs/btrfs/free-space-cache.c
47047 +++ b/fs/btrfs/free-space-cache.c
47048 @@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
47049
47050 while(1) {
47051 if (entry->bytes < bytes || entry->offset < min_start) {
47052 - struct rb_node *node;
47053 -
47054 node = rb_next(&entry->offset_index);
47055 if (!node)
47056 break;
47057 @@ -1226,7 +1224,7 @@ again:
47058 */
47059 while (entry->bitmap || found_bitmap ||
47060 (!entry->bitmap && entry->bytes < min_bytes)) {
47061 - struct rb_node *node = rb_next(&entry->offset_index);
47062 + node = rb_next(&entry->offset_index);
47063
47064 if (entry->bitmap && entry->bytes > bytes + empty_size) {
47065 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
47066 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
47067 index e03a836..323837e 100644
47068 --- a/fs/btrfs/inode.c
47069 +++ b/fs/btrfs/inode.c
47070 @@ -63,7 +63,7 @@ static const struct inode_operations btrfs_file_inode_operations;
47071 static const struct address_space_operations btrfs_aops;
47072 static const struct address_space_operations btrfs_symlink_aops;
47073 static const struct file_operations btrfs_dir_file_operations;
47074 -static struct extent_io_ops btrfs_extent_io_ops;
47075 +static const struct extent_io_ops btrfs_extent_io_ops;
47076
47077 static struct kmem_cache *btrfs_inode_cachep;
47078 struct kmem_cache *btrfs_trans_handle_cachep;
47079 @@ -925,6 +925,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
47080 1, 0, NULL, GFP_NOFS);
47081 while (start < end) {
47082 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
47083 + BUG_ON(!async_cow);
47084 async_cow->inode = inode;
47085 async_cow->root = root;
47086 async_cow->locked_page = locked_page;
47087 @@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(struct btrfs_path *path,
47088 inline_size = btrfs_file_extent_inline_item_len(leaf,
47089 btrfs_item_nr(leaf, path->slots[0]));
47090 tmp = kmalloc(inline_size, GFP_NOFS);
47091 + if (!tmp)
47092 + return -ENOMEM;
47093 ptr = btrfs_file_extent_inline_start(item);
47094
47095 read_extent_buffer(leaf, tmp, ptr, inline_size);
47096 @@ -5410,7 +5413,7 @@ fail:
47097 return -ENOMEM;
47098 }
47099
47100 -static int btrfs_getattr(struct vfsmount *mnt,
47101 +int btrfs_getattr(struct vfsmount *mnt,
47102 struct dentry *dentry, struct kstat *stat)
47103 {
47104 struct inode *inode = dentry->d_inode;
47105 @@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
47106 return 0;
47107 }
47108
47109 +EXPORT_SYMBOL(btrfs_getattr);
47110 +
47111 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
47112 +{
47113 + return BTRFS_I(inode)->root->anon_super.s_dev;
47114 +}
47115 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
47116 +
47117 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
47118 struct inode *new_dir, struct dentry *new_dentry)
47119 {
47120 @@ -5972,7 +5983,7 @@ static const struct file_operations btrfs_dir_file_operations = {
47121 .fsync = btrfs_sync_file,
47122 };
47123
47124 -static struct extent_io_ops btrfs_extent_io_ops = {
47125 +static const struct extent_io_ops btrfs_extent_io_ops = {
47126 .fill_delalloc = run_delalloc_range,
47127 .submit_bio_hook = btrfs_submit_bio_hook,
47128 .merge_bio_hook = btrfs_merge_bio_hook,
47129 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
47130 index ab7ab53..94e0781 100644
47131 --- a/fs/btrfs/relocation.c
47132 +++ b/fs/btrfs/relocation.c
47133 @@ -884,7 +884,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
47134 }
47135 spin_unlock(&rc->reloc_root_tree.lock);
47136
47137 - BUG_ON((struct btrfs_root *)node->data != root);
47138 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
47139
47140 if (!del) {
47141 spin_lock(&rc->reloc_root_tree.lock);
47142 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
47143 index a240b6f..4ce16ef 100644
47144 --- a/fs/btrfs/sysfs.c
47145 +++ b/fs/btrfs/sysfs.c
47146 @@ -164,12 +164,12 @@ static void btrfs_root_release(struct kobject *kobj)
47147 complete(&root->kobj_unregister);
47148 }
47149
47150 -static struct sysfs_ops btrfs_super_attr_ops = {
47151 +static const struct sysfs_ops btrfs_super_attr_ops = {
47152 .show = btrfs_super_attr_show,
47153 .store = btrfs_super_attr_store,
47154 };
47155
47156 -static struct sysfs_ops btrfs_root_attr_ops = {
47157 +static const struct sysfs_ops btrfs_root_attr_ops = {
47158 .show = btrfs_root_attr_show,
47159 .store = btrfs_root_attr_store,
47160 };
47161 diff --git a/fs/buffer.c b/fs/buffer.c
47162 index 6fa5302..395d9f6 100644
47163 --- a/fs/buffer.c
47164 +++ b/fs/buffer.c
47165 @@ -25,6 +25,7 @@
47166 #include <linux/percpu.h>
47167 #include <linux/slab.h>
47168 #include <linux/capability.h>
47169 +#include <linux/security.h>
47170 #include <linux/blkdev.h>
47171 #include <linux/file.h>
47172 #include <linux/quotaops.h>
47173 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
47174 index 3797e00..ce776f6 100644
47175 --- a/fs/cachefiles/bind.c
47176 +++ b/fs/cachefiles/bind.c
47177 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
47178 args);
47179
47180 /* start by checking things over */
47181 - ASSERT(cache->fstop_percent >= 0 &&
47182 - cache->fstop_percent < cache->fcull_percent &&
47183 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
47184 cache->fcull_percent < cache->frun_percent &&
47185 cache->frun_percent < 100);
47186
47187 - ASSERT(cache->bstop_percent >= 0 &&
47188 - cache->bstop_percent < cache->bcull_percent &&
47189 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
47190 cache->bcull_percent < cache->brun_percent &&
47191 cache->brun_percent < 100);
47192
47193 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
47194 index 4618516..bb30d01 100644
47195 --- a/fs/cachefiles/daemon.c
47196 +++ b/fs/cachefiles/daemon.c
47197 @@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
47198 if (test_bit(CACHEFILES_DEAD, &cache->flags))
47199 return -EIO;
47200
47201 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
47202 + if (datalen > PAGE_SIZE - 1)
47203 return -EOPNOTSUPP;
47204
47205 /* drag the command string into the kernel so we can parse it */
47206 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
47207 if (args[0] != '%' || args[1] != '\0')
47208 return -EINVAL;
47209
47210 - if (fstop < 0 || fstop >= cache->fcull_percent)
47211 + if (fstop >= cache->fcull_percent)
47212 return cachefiles_daemon_range_error(cache, args);
47213
47214 cache->fstop_percent = fstop;
47215 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
47216 if (args[0] != '%' || args[1] != '\0')
47217 return -EINVAL;
47218
47219 - if (bstop < 0 || bstop >= cache->bcull_percent)
47220 + if (bstop >= cache->bcull_percent)
47221 return cachefiles_daemon_range_error(cache, args);
47222
47223 cache->bstop_percent = bstop;
47224 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
47225 index f7c255f..fcd61de 100644
47226 --- a/fs/cachefiles/internal.h
47227 +++ b/fs/cachefiles/internal.h
47228 @@ -56,7 +56,7 @@ struct cachefiles_cache {
47229 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
47230 struct rb_root active_nodes; /* active nodes (can't be culled) */
47231 rwlock_t active_lock; /* lock for active_nodes */
47232 - atomic_t gravecounter; /* graveyard uniquifier */
47233 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
47234 unsigned frun_percent; /* when to stop culling (% files) */
47235 unsigned fcull_percent; /* when to start culling (% files) */
47236 unsigned fstop_percent; /* when to stop allocating (% files) */
47237 @@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
47238 * proc.c
47239 */
47240 #ifdef CONFIG_CACHEFILES_HISTOGRAM
47241 -extern atomic_t cachefiles_lookup_histogram[HZ];
47242 -extern atomic_t cachefiles_mkdir_histogram[HZ];
47243 -extern atomic_t cachefiles_create_histogram[HZ];
47244 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47245 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47246 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
47247
47248 extern int __init cachefiles_proc_init(void);
47249 extern void cachefiles_proc_cleanup(void);
47250 static inline
47251 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
47252 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
47253 {
47254 unsigned long jif = jiffies - start_jif;
47255 if (jif >= HZ)
47256 jif = HZ - 1;
47257 - atomic_inc(&histogram[jif]);
47258 + atomic_inc_unchecked(&histogram[jif]);
47259 }
47260
47261 #else
47262 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
47263 index 14ac480..a62766c 100644
47264 --- a/fs/cachefiles/namei.c
47265 +++ b/fs/cachefiles/namei.c
47266 @@ -250,7 +250,7 @@ try_again:
47267 /* first step is to make up a grave dentry in the graveyard */
47268 sprintf(nbuffer, "%08x%08x",
47269 (uint32_t) get_seconds(),
47270 - (uint32_t) atomic_inc_return(&cache->gravecounter));
47271 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
47272
47273 /* do the multiway lock magic */
47274 trap = lock_rename(cache->graveyard, dir);
47275 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
47276 index eccd339..4c1d995 100644
47277 --- a/fs/cachefiles/proc.c
47278 +++ b/fs/cachefiles/proc.c
47279 @@ -14,9 +14,9 @@
47280 #include <linux/seq_file.h>
47281 #include "internal.h"
47282
47283 -atomic_t cachefiles_lookup_histogram[HZ];
47284 -atomic_t cachefiles_mkdir_histogram[HZ];
47285 -atomic_t cachefiles_create_histogram[HZ];
47286 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47287 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47288 +atomic_unchecked_t cachefiles_create_histogram[HZ];
47289
47290 /*
47291 * display the latency histogram
47292 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
47293 return 0;
47294 default:
47295 index = (unsigned long) v - 3;
47296 - x = atomic_read(&cachefiles_lookup_histogram[index]);
47297 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
47298 - z = atomic_read(&cachefiles_create_histogram[index]);
47299 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
47300 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
47301 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
47302 if (x == 0 && y == 0 && z == 0)
47303 return 0;
47304
47305 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
47306 index a6c8c6f..5cf8517 100644
47307 --- a/fs/cachefiles/rdwr.c
47308 +++ b/fs/cachefiles/rdwr.c
47309 @@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
47310 old_fs = get_fs();
47311 set_fs(KERNEL_DS);
47312 ret = file->f_op->write(
47313 - file, (const void __user *) data, len, &pos);
47314 + file, (const void __force_user *) data, len, &pos);
47315 set_fs(old_fs);
47316 kunmap(page);
47317 if (ret != len)
47318 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
47319 index 42cec2a..2aba466 100644
47320 --- a/fs/cifs/cifs_debug.c
47321 +++ b/fs/cifs/cifs_debug.c
47322 @@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
47323 tcon = list_entry(tmp3,
47324 struct cifsTconInfo,
47325 tcon_list);
47326 - atomic_set(&tcon->num_smbs_sent, 0);
47327 - atomic_set(&tcon->num_writes, 0);
47328 - atomic_set(&tcon->num_reads, 0);
47329 - atomic_set(&tcon->num_oplock_brks, 0);
47330 - atomic_set(&tcon->num_opens, 0);
47331 - atomic_set(&tcon->num_posixopens, 0);
47332 - atomic_set(&tcon->num_posixmkdirs, 0);
47333 - atomic_set(&tcon->num_closes, 0);
47334 - atomic_set(&tcon->num_deletes, 0);
47335 - atomic_set(&tcon->num_mkdirs, 0);
47336 - atomic_set(&tcon->num_rmdirs, 0);
47337 - atomic_set(&tcon->num_renames, 0);
47338 - atomic_set(&tcon->num_t2renames, 0);
47339 - atomic_set(&tcon->num_ffirst, 0);
47340 - atomic_set(&tcon->num_fnext, 0);
47341 - atomic_set(&tcon->num_fclose, 0);
47342 - atomic_set(&tcon->num_hardlinks, 0);
47343 - atomic_set(&tcon->num_symlinks, 0);
47344 - atomic_set(&tcon->num_locks, 0);
47345 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
47346 + atomic_set_unchecked(&tcon->num_writes, 0);
47347 + atomic_set_unchecked(&tcon->num_reads, 0);
47348 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
47349 + atomic_set_unchecked(&tcon->num_opens, 0);
47350 + atomic_set_unchecked(&tcon->num_posixopens, 0);
47351 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
47352 + atomic_set_unchecked(&tcon->num_closes, 0);
47353 + atomic_set_unchecked(&tcon->num_deletes, 0);
47354 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
47355 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
47356 + atomic_set_unchecked(&tcon->num_renames, 0);
47357 + atomic_set_unchecked(&tcon->num_t2renames, 0);
47358 + atomic_set_unchecked(&tcon->num_ffirst, 0);
47359 + atomic_set_unchecked(&tcon->num_fnext, 0);
47360 + atomic_set_unchecked(&tcon->num_fclose, 0);
47361 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
47362 + atomic_set_unchecked(&tcon->num_symlinks, 0);
47363 + atomic_set_unchecked(&tcon->num_locks, 0);
47364 }
47365 }
47366 }
47367 @@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
47368 if (tcon->need_reconnect)
47369 seq_puts(m, "\tDISCONNECTED ");
47370 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
47371 - atomic_read(&tcon->num_smbs_sent),
47372 - atomic_read(&tcon->num_oplock_brks));
47373 + atomic_read_unchecked(&tcon->num_smbs_sent),
47374 + atomic_read_unchecked(&tcon->num_oplock_brks));
47375 seq_printf(m, "\nReads: %d Bytes: %lld",
47376 - atomic_read(&tcon->num_reads),
47377 + atomic_read_unchecked(&tcon->num_reads),
47378 (long long)(tcon->bytes_read));
47379 seq_printf(m, "\nWrites: %d Bytes: %lld",
47380 - atomic_read(&tcon->num_writes),
47381 + atomic_read_unchecked(&tcon->num_writes),
47382 (long long)(tcon->bytes_written));
47383 seq_printf(m, "\nFlushes: %d",
47384 - atomic_read(&tcon->num_flushes));
47385 + atomic_read_unchecked(&tcon->num_flushes));
47386 seq_printf(m, "\nLocks: %d HardLinks: %d "
47387 "Symlinks: %d",
47388 - atomic_read(&tcon->num_locks),
47389 - atomic_read(&tcon->num_hardlinks),
47390 - atomic_read(&tcon->num_symlinks));
47391 + atomic_read_unchecked(&tcon->num_locks),
47392 + atomic_read_unchecked(&tcon->num_hardlinks),
47393 + atomic_read_unchecked(&tcon->num_symlinks));
47394 seq_printf(m, "\nOpens: %d Closes: %d "
47395 "Deletes: %d",
47396 - atomic_read(&tcon->num_opens),
47397 - atomic_read(&tcon->num_closes),
47398 - atomic_read(&tcon->num_deletes));
47399 + atomic_read_unchecked(&tcon->num_opens),
47400 + atomic_read_unchecked(&tcon->num_closes),
47401 + atomic_read_unchecked(&tcon->num_deletes));
47402 seq_printf(m, "\nPosix Opens: %d "
47403 "Posix Mkdirs: %d",
47404 - atomic_read(&tcon->num_posixopens),
47405 - atomic_read(&tcon->num_posixmkdirs));
47406 + atomic_read_unchecked(&tcon->num_posixopens),
47407 + atomic_read_unchecked(&tcon->num_posixmkdirs));
47408 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
47409 - atomic_read(&tcon->num_mkdirs),
47410 - atomic_read(&tcon->num_rmdirs));
47411 + atomic_read_unchecked(&tcon->num_mkdirs),
47412 + atomic_read_unchecked(&tcon->num_rmdirs));
47413 seq_printf(m, "\nRenames: %d T2 Renames %d",
47414 - atomic_read(&tcon->num_renames),
47415 - atomic_read(&tcon->num_t2renames));
47416 + atomic_read_unchecked(&tcon->num_renames),
47417 + atomic_read_unchecked(&tcon->num_t2renames));
47418 seq_printf(m, "\nFindFirst: %d FNext %d "
47419 "FClose %d",
47420 - atomic_read(&tcon->num_ffirst),
47421 - atomic_read(&tcon->num_fnext),
47422 - atomic_read(&tcon->num_fclose));
47423 + atomic_read_unchecked(&tcon->num_ffirst),
47424 + atomic_read_unchecked(&tcon->num_fnext),
47425 + atomic_read_unchecked(&tcon->num_fclose));
47426 }
47427 }
47428 }
47429 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
47430 index 1445407..68cb0dc 100644
47431 --- a/fs/cifs/cifsfs.c
47432 +++ b/fs/cifs/cifsfs.c
47433 @@ -869,7 +869,7 @@ cifs_init_request_bufs(void)
47434 cifs_req_cachep = kmem_cache_create("cifs_request",
47435 CIFSMaxBufSize +
47436 MAX_CIFS_HDR_SIZE, 0,
47437 - SLAB_HWCACHE_ALIGN, NULL);
47438 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
47439 if (cifs_req_cachep == NULL)
47440 return -ENOMEM;
47441
47442 @@ -896,7 +896,7 @@ cifs_init_request_bufs(void)
47443 efficient to alloc 1 per page off the slab compared to 17K (5page)
47444 alloc of large cifs buffers even when page debugging is on */
47445 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
47446 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
47447 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
47448 NULL);
47449 if (cifs_sm_req_cachep == NULL) {
47450 mempool_destroy(cifs_req_poolp);
47451 @@ -991,8 +991,8 @@ init_cifs(void)
47452 atomic_set(&bufAllocCount, 0);
47453 atomic_set(&smBufAllocCount, 0);
47454 #ifdef CONFIG_CIFS_STATS2
47455 - atomic_set(&totBufAllocCount, 0);
47456 - atomic_set(&totSmBufAllocCount, 0);
47457 + atomic_set_unchecked(&totBufAllocCount, 0);
47458 + atomic_set_unchecked(&totSmBufAllocCount, 0);
47459 #endif /* CONFIG_CIFS_STATS2 */
47460
47461 atomic_set(&midCount, 0);
47462 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
47463 index e29581e..1c22bab 100644
47464 --- a/fs/cifs/cifsglob.h
47465 +++ b/fs/cifs/cifsglob.h
47466 @@ -252,28 +252,28 @@ struct cifsTconInfo {
47467 __u16 Flags; /* optional support bits */
47468 enum statusEnum tidStatus;
47469 #ifdef CONFIG_CIFS_STATS
47470 - atomic_t num_smbs_sent;
47471 - atomic_t num_writes;
47472 - atomic_t num_reads;
47473 - atomic_t num_flushes;
47474 - atomic_t num_oplock_brks;
47475 - atomic_t num_opens;
47476 - atomic_t num_closes;
47477 - atomic_t num_deletes;
47478 - atomic_t num_mkdirs;
47479 - atomic_t num_posixopens;
47480 - atomic_t num_posixmkdirs;
47481 - atomic_t num_rmdirs;
47482 - atomic_t num_renames;
47483 - atomic_t num_t2renames;
47484 - atomic_t num_ffirst;
47485 - atomic_t num_fnext;
47486 - atomic_t num_fclose;
47487 - atomic_t num_hardlinks;
47488 - atomic_t num_symlinks;
47489 - atomic_t num_locks;
47490 - atomic_t num_acl_get;
47491 - atomic_t num_acl_set;
47492 + atomic_unchecked_t num_smbs_sent;
47493 + atomic_unchecked_t num_writes;
47494 + atomic_unchecked_t num_reads;
47495 + atomic_unchecked_t num_flushes;
47496 + atomic_unchecked_t num_oplock_brks;
47497 + atomic_unchecked_t num_opens;
47498 + atomic_unchecked_t num_closes;
47499 + atomic_unchecked_t num_deletes;
47500 + atomic_unchecked_t num_mkdirs;
47501 + atomic_unchecked_t num_posixopens;
47502 + atomic_unchecked_t num_posixmkdirs;
47503 + atomic_unchecked_t num_rmdirs;
47504 + atomic_unchecked_t num_renames;
47505 + atomic_unchecked_t num_t2renames;
47506 + atomic_unchecked_t num_ffirst;
47507 + atomic_unchecked_t num_fnext;
47508 + atomic_unchecked_t num_fclose;
47509 + atomic_unchecked_t num_hardlinks;
47510 + atomic_unchecked_t num_symlinks;
47511 + atomic_unchecked_t num_locks;
47512 + atomic_unchecked_t num_acl_get;
47513 + atomic_unchecked_t num_acl_set;
47514 #ifdef CONFIG_CIFS_STATS2
47515 unsigned long long time_writes;
47516 unsigned long long time_reads;
47517 @@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
47518 }
47519
47520 #ifdef CONFIG_CIFS_STATS
47521 -#define cifs_stats_inc atomic_inc
47522 +#define cifs_stats_inc atomic_inc_unchecked
47523
47524 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
47525 unsigned int bytes)
47526 @@ -701,8 +701,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
47527 /* Various Debug counters */
47528 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
47529 #ifdef CONFIG_CIFS_STATS2
47530 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
47531 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
47532 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
47533 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
47534 #endif
47535 GLOBAL_EXTERN atomic_t smBufAllocCount;
47536 GLOBAL_EXTERN atomic_t midCount;
47537 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
47538 index fc1e048..28b3441 100644
47539 --- a/fs/cifs/link.c
47540 +++ b/fs/cifs/link.c
47541 @@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
47542
47543 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
47544 {
47545 - char *p = nd_get_link(nd);
47546 + const char *p = nd_get_link(nd);
47547 if (!IS_ERR(p))
47548 kfree(p);
47549 }
47550 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
47551 index 95b82e8..12a538d 100644
47552 --- a/fs/cifs/misc.c
47553 +++ b/fs/cifs/misc.c
47554 @@ -155,7 +155,7 @@ cifs_buf_get(void)
47555 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
47556 atomic_inc(&bufAllocCount);
47557 #ifdef CONFIG_CIFS_STATS2
47558 - atomic_inc(&totBufAllocCount);
47559 + atomic_inc_unchecked(&totBufAllocCount);
47560 #endif /* CONFIG_CIFS_STATS2 */
47561 }
47562
47563 @@ -190,7 +190,7 @@ cifs_small_buf_get(void)
47564 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
47565 atomic_inc(&smBufAllocCount);
47566 #ifdef CONFIG_CIFS_STATS2
47567 - atomic_inc(&totSmBufAllocCount);
47568 + atomic_inc_unchecked(&totSmBufAllocCount);
47569 #endif /* CONFIG_CIFS_STATS2 */
47570
47571 }
47572 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
47573 index a5bf577..6d19845 100644
47574 --- a/fs/coda/cache.c
47575 +++ b/fs/coda/cache.c
47576 @@ -24,14 +24,14 @@
47577 #include <linux/coda_fs_i.h>
47578 #include <linux/coda_cache.h>
47579
47580 -static atomic_t permission_epoch = ATOMIC_INIT(0);
47581 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
47582
47583 /* replace or extend an acl cache hit */
47584 void coda_cache_enter(struct inode *inode, int mask)
47585 {
47586 struct coda_inode_info *cii = ITOC(inode);
47587
47588 - cii->c_cached_epoch = atomic_read(&permission_epoch);
47589 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47590 if (cii->c_uid != current_fsuid()) {
47591 cii->c_uid = current_fsuid();
47592 cii->c_cached_perm = mask;
47593 @@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inode, int mask)
47594 void coda_cache_clear_inode(struct inode *inode)
47595 {
47596 struct coda_inode_info *cii = ITOC(inode);
47597 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47598 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47599 }
47600
47601 /* remove all acl caches */
47602 void coda_cache_clear_all(struct super_block *sb)
47603 {
47604 - atomic_inc(&permission_epoch);
47605 + atomic_inc_unchecked(&permission_epoch);
47606 }
47607
47608
47609 @@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode, int mask)
47610
47611 hit = (mask & cii->c_cached_perm) == mask &&
47612 cii->c_uid == current_fsuid() &&
47613 - cii->c_cached_epoch == atomic_read(&permission_epoch);
47614 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47615
47616 return hit;
47617 }
47618 diff --git a/fs/compat.c b/fs/compat.c
47619 index d1e2411..27064e4 100644
47620 --- a/fs/compat.c
47621 +++ b/fs/compat.c
47622 @@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
47623 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
47624 {
47625 compat_ino_t ino = stat->ino;
47626 - typeof(ubuf->st_uid) uid = 0;
47627 - typeof(ubuf->st_gid) gid = 0;
47628 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
47629 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
47630 int err;
47631
47632 SET_UID(uid, stat->uid);
47633 @@ -533,7 +533,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47634
47635 set_fs(KERNEL_DS);
47636 /* The __user pointer cast is valid because of the set_fs() */
47637 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47638 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47639 set_fs(oldfs);
47640 /* truncating is ok because it's a user address */
47641 if (!ret)
47642 @@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
47643
47644 struct compat_readdir_callback {
47645 struct compat_old_linux_dirent __user *dirent;
47646 + struct file * file;
47647 int result;
47648 };
47649
47650 @@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47651 buf->result = -EOVERFLOW;
47652 return -EOVERFLOW;
47653 }
47654 +
47655 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47656 + return 0;
47657 +
47658 buf->result++;
47659 dirent = buf->dirent;
47660 if (!access_ok(VERIFY_WRITE, dirent,
47661 @@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47662
47663 buf.result = 0;
47664 buf.dirent = dirent;
47665 + buf.file = file;
47666
47667 error = vfs_readdir(file, compat_fillonedir, &buf);
47668 if (buf.result)
47669 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
47670 struct compat_getdents_callback {
47671 struct compat_linux_dirent __user *current_dir;
47672 struct compat_linux_dirent __user *previous;
47673 + struct file * file;
47674 int count;
47675 int error;
47676 };
47677 @@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47678 buf->error = -EOVERFLOW;
47679 return -EOVERFLOW;
47680 }
47681 +
47682 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47683 + return 0;
47684 +
47685 dirent = buf->previous;
47686 if (dirent) {
47687 if (__put_user(offset, &dirent->d_off))
47688 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47689 buf.previous = NULL;
47690 buf.count = count;
47691 buf.error = 0;
47692 + buf.file = file;
47693
47694 error = vfs_readdir(file, compat_filldir, &buf);
47695 if (error >= 0)
47696 @@ -987,6 +999,7 @@ out:
47697 struct compat_getdents_callback64 {
47698 struct linux_dirent64 __user *current_dir;
47699 struct linux_dirent64 __user *previous;
47700 + struct file * file;
47701 int count;
47702 int error;
47703 };
47704 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47705 buf->error = -EINVAL; /* only used if we fail.. */
47706 if (reclen > buf->count)
47707 return -EINVAL;
47708 +
47709 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47710 + return 0;
47711 +
47712 dirent = buf->previous;
47713
47714 if (dirent) {
47715 @@ -1054,13 +1071,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47716 buf.previous = NULL;
47717 buf.count = count;
47718 buf.error = 0;
47719 + buf.file = file;
47720
47721 error = vfs_readdir(file, compat_filldir64, &buf);
47722 if (error >= 0)
47723 error = buf.error;
47724 lastdirent = buf.previous;
47725 if (lastdirent) {
47726 - typeof(lastdirent->d_off) d_off = file->f_pos;
47727 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47728 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47729 error = -EFAULT;
47730 else
47731 @@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
47732 * verify all the pointers
47733 */
47734 ret = -EINVAL;
47735 - if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
47736 + if (nr_segs > UIO_MAXIOV)
47737 goto out;
47738 if (!file->f_op)
47739 goto out;
47740 @@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
47741 compat_uptr_t __user *envp,
47742 struct pt_regs * regs)
47743 {
47744 +#ifdef CONFIG_GRKERNSEC
47745 + struct file *old_exec_file;
47746 + struct acl_subject_label *old_acl;
47747 + struct rlimit old_rlim[RLIM_NLIMITS];
47748 +#endif
47749 struct linux_binprm *bprm;
47750 struct file *file;
47751 struct files_struct *displaced;
47752 bool clear_in_exec;
47753 int retval;
47754 + const struct cred *cred = current_cred();
47755 +
47756 + /*
47757 + * We move the actual failure in case of RLIMIT_NPROC excess from
47758 + * set*uid() to execve() because too many poorly written programs
47759 + * don't check setuid() return code. Here we additionally recheck
47760 + * whether NPROC limit is still exceeded.
47761 + */
47762 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47763 +
47764 + if ((current->flags & PF_NPROC_EXCEEDED) &&
47765 + atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
47766 + retval = -EAGAIN;
47767 + goto out_ret;
47768 + }
47769 +
47770 + /* We're below the limit (still or again), so we don't want to make
47771 + * further execve() calls fail. */
47772 + current->flags &= ~PF_NPROC_EXCEEDED;
47773
47774 retval = unshare_files(&displaced);
47775 if (retval)
47776 @@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
47777 bprm->filename = filename;
47778 bprm->interp = filename;
47779
47780 + if (gr_process_user_ban()) {
47781 + retval = -EPERM;
47782 + goto out_file;
47783 + }
47784 +
47785 + retval = -EACCES;
47786 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
47787 + goto out_file;
47788 +
47789 retval = bprm_mm_init(bprm);
47790 if (retval)
47791 goto out_file;
47792 @@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
47793 if (retval < 0)
47794 goto out;
47795
47796 + if (!gr_tpe_allow(file)) {
47797 + retval = -EACCES;
47798 + goto out;
47799 + }
47800 +
47801 + if (gr_check_crash_exec(file)) {
47802 + retval = -EACCES;
47803 + goto out;
47804 + }
47805 +
47806 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47807 +
47808 + gr_handle_exec_args_compat(bprm, argv);
47809 +
47810 +#ifdef CONFIG_GRKERNSEC
47811 + old_acl = current->acl;
47812 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47813 + old_exec_file = current->exec_file;
47814 + get_file(file);
47815 + current->exec_file = file;
47816 +#endif
47817 +
47818 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47819 + bprm->unsafe & LSM_UNSAFE_SHARE);
47820 + if (retval < 0)
47821 + goto out_fail;
47822 +
47823 retval = search_binary_handler(bprm, regs);
47824 if (retval < 0)
47825 - goto out;
47826 + goto out_fail;
47827 +#ifdef CONFIG_GRKERNSEC
47828 + if (old_exec_file)
47829 + fput(old_exec_file);
47830 +#endif
47831
47832 /* execve succeeded */
47833 current->fs->in_exec = 0;
47834 @@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
47835 put_files_struct(displaced);
47836 return retval;
47837
47838 +out_fail:
47839 +#ifdef CONFIG_GRKERNSEC
47840 + current->acl = old_acl;
47841 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47842 + fput(current->exec_file);
47843 + current->exec_file = old_exec_file;
47844 +#endif
47845 +
47846 out:
47847 if (bprm->mm) {
47848 acct_arg_size(bprm, 0);
47849 @@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
47850 struct fdtable *fdt;
47851 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
47852
47853 + pax_track_stack();
47854 +
47855 if (n < 0)
47856 goto out_nofds;
47857
47858 @@ -2151,7 +2243,7 @@ asmlinkage long compat_sys_nfsservctl(int cmd,
47859 oldfs = get_fs();
47860 set_fs(KERNEL_DS);
47861 /* The __user pointer casts are valid because of the set_fs() */
47862 - err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
47863 + err = sys_nfsservctl(cmd, (void __force_user *) karg, (void __force_user *) kres);
47864 set_fs(oldfs);
47865
47866 if (err)
47867 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47868 index 0adced2..bbb1b0d 100644
47869 --- a/fs/compat_binfmt_elf.c
47870 +++ b/fs/compat_binfmt_elf.c
47871 @@ -29,10 +29,12 @@
47872 #undef elfhdr
47873 #undef elf_phdr
47874 #undef elf_note
47875 +#undef elf_dyn
47876 #undef elf_addr_t
47877 #define elfhdr elf32_hdr
47878 #define elf_phdr elf32_phdr
47879 #define elf_note elf32_note
47880 +#define elf_dyn Elf32_Dyn
47881 #define elf_addr_t Elf32_Addr
47882
47883 /*
47884 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47885 index d84e705..d8c364c 100644
47886 --- a/fs/compat_ioctl.c
47887 +++ b/fs/compat_ioctl.c
47888 @@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned
47889 up = (struct compat_video_spu_palette __user *) arg;
47890 err = get_user(palp, &up->palette);
47891 err |= get_user(length, &up->length);
47892 + if (err)
47893 + return -EFAULT;
47894
47895 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
47896 err = put_user(compat_ptr(palp), &up_native->palette);
47897 @@ -1513,7 +1515,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
47898 return -EFAULT;
47899 if (__get_user(udata, &ss32->iomem_base))
47900 return -EFAULT;
47901 - ss.iomem_base = compat_ptr(udata);
47902 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47903 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47904 __get_user(ss.port_high, &ss32->port_high))
47905 return -EFAULT;
47906 @@ -1809,7 +1811,7 @@ static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
47907 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47908 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47909 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47910 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47911 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47912 return -EFAULT;
47913
47914 return ioctl_preallocate(file, p);
47915 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47916 index 8e48b52..f01ed91 100644
47917 --- a/fs/configfs/dir.c
47918 +++ b/fs/configfs/dir.c
47919 @@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47920 }
47921 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47922 struct configfs_dirent *next;
47923 - const char * name;
47924 + const unsigned char * name;
47925 + char d_name[sizeof(next->s_dentry->d_iname)];
47926 int len;
47927
47928 next = list_entry(p, struct configfs_dirent,
47929 @@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47930 continue;
47931
47932 name = configfs_get_name(next);
47933 - len = strlen(name);
47934 + if (next->s_dentry && name == next->s_dentry->d_iname) {
47935 + len = next->s_dentry->d_name.len;
47936 + memcpy(d_name, name, len);
47937 + name = d_name;
47938 + } else
47939 + len = strlen(name);
47940 if (next->s_dentry)
47941 ino = next->s_dentry->d_inode->i_ino;
47942 else
47943 diff --git a/fs/dcache.c b/fs/dcache.c
47944 index 44c0aea..2529092 100644
47945 --- a/fs/dcache.c
47946 +++ b/fs/dcache.c
47947 @@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
47948
47949 static struct kmem_cache *dentry_cache __read_mostly;
47950
47951 -#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
47952 -
47953 /*
47954 * This is the single most critical data structure when it comes
47955 * to the dcache: the hashtable for lookups. Somebody should try
47956 @@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned long mempages)
47957 mempages -= reserve;
47958
47959 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47960 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47961 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47962
47963 dcache_init();
47964 inode_init();
47965 diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
47966 index c010ecf..a8d8c59 100644
47967 --- a/fs/dlm/lockspace.c
47968 +++ b/fs/dlm/lockspace.c
47969 @@ -148,7 +148,7 @@ static void lockspace_kobj_release(struct kobject *k)
47970 kfree(ls);
47971 }
47972
47973 -static struct sysfs_ops dlm_attr_ops = {
47974 +static const struct sysfs_ops dlm_attr_ops = {
47975 .show = dlm_attr_show,
47976 .store = dlm_attr_store,
47977 };
47978 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47979 index 88ba4d4..073f003 100644
47980 --- a/fs/ecryptfs/inode.c
47981 +++ b/fs/ecryptfs/inode.c
47982 @@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47983 old_fs = get_fs();
47984 set_fs(get_ds());
47985 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47986 - (char __user *)lower_buf,
47987 + (char __force_user *)lower_buf,
47988 lower_bufsiz);
47989 set_fs(old_fs);
47990 if (rc < 0)
47991 @@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47992 }
47993 old_fs = get_fs();
47994 set_fs(get_ds());
47995 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
47996 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
47997 set_fs(old_fs);
47998 if (rc < 0)
47999 goto out_free;
48000 diff --git a/fs/exec.c b/fs/exec.c
48001 index 86fafc6..b307bfa 100644
48002 --- a/fs/exec.c
48003 +++ b/fs/exec.c
48004 @@ -56,12 +56,24 @@
48005 #include <linux/fsnotify.h>
48006 #include <linux/fs_struct.h>
48007 #include <linux/pipe_fs_i.h>
48008 +#include <linux/random.h>
48009 +#include <linux/seq_file.h>
48010 +
48011 +#ifdef CONFIG_PAX_REFCOUNT
48012 +#include <linux/kallsyms.h>
48013 +#include <linux/kdebug.h>
48014 +#endif
48015
48016 #include <asm/uaccess.h>
48017 #include <asm/mmu_context.h>
48018 #include <asm/tlb.h>
48019 #include "internal.h"
48020
48021 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
48022 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
48023 +EXPORT_SYMBOL(pax_set_initial_flags_func);
48024 +#endif
48025 +
48026 int core_uses_pid;
48027 char core_pattern[CORENAME_MAX_SIZE] = "core";
48028 unsigned int core_pipe_limit;
48029 @@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
48030 int write)
48031 {
48032 struct page *page;
48033 - int ret;
48034
48035 -#ifdef CONFIG_STACK_GROWSUP
48036 - if (write) {
48037 - ret = expand_stack_downwards(bprm->vma, pos);
48038 - if (ret < 0)
48039 - return NULL;
48040 - }
48041 -#endif
48042 - ret = get_user_pages(current, bprm->mm, pos,
48043 - 1, write, 1, &page, NULL);
48044 - if (ret <= 0)
48045 + if (0 > expand_stack_downwards(bprm->vma, pos))
48046 + return NULL;
48047 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
48048 return NULL;
48049
48050 if (write) {
48051 @@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48052 vma->vm_end = STACK_TOP_MAX;
48053 vma->vm_start = vma->vm_end - PAGE_SIZE;
48054 vma->vm_flags = VM_STACK_FLAGS;
48055 +
48056 +#ifdef CONFIG_PAX_SEGMEXEC
48057 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
48058 +#endif
48059 +
48060 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
48061
48062 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
48063 @@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48064 mm->stack_vm = mm->total_vm = 1;
48065 up_write(&mm->mmap_sem);
48066 bprm->p = vma->vm_end - sizeof(void *);
48067 +
48068 +#ifdef CONFIG_PAX_RANDUSTACK
48069 + if (randomize_va_space)
48070 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
48071 +#endif
48072 +
48073 return 0;
48074 err:
48075 up_write(&mm->mmap_sem);
48076 @@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
48077 int r;
48078 mm_segment_t oldfs = get_fs();
48079 set_fs(KERNEL_DS);
48080 - r = copy_strings(argc, (char __user * __user *)argv, bprm);
48081 + r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
48082 set_fs(oldfs);
48083 return r;
48084 }
48085 @@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48086 unsigned long new_end = old_end - shift;
48087 struct mmu_gather *tlb;
48088
48089 - BUG_ON(new_start > new_end);
48090 + if (new_start >= new_end || new_start < mmap_min_addr)
48091 + return -ENOMEM;
48092
48093 /*
48094 * ensure there are no vmas between where we want to go
48095 @@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48096 if (vma != find_vma(mm, new_start))
48097 return -EFAULT;
48098
48099 +#ifdef CONFIG_PAX_SEGMEXEC
48100 + BUG_ON(pax_find_mirror_vma(vma));
48101 +#endif
48102 +
48103 /*
48104 * cover the whole range: [new_start, old_end)
48105 */
48106 @@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
48107 stack_top = arch_align_stack(stack_top);
48108 stack_top = PAGE_ALIGN(stack_top);
48109
48110 - if (unlikely(stack_top < mmap_min_addr) ||
48111 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
48112 - return -ENOMEM;
48113 -
48114 stack_shift = vma->vm_end - stack_top;
48115
48116 bprm->p -= stack_shift;
48117 @@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm *bprm,
48118 bprm->exec -= stack_shift;
48119
48120 down_write(&mm->mmap_sem);
48121 +
48122 + /* Move stack pages down in memory. */
48123 + if (stack_shift) {
48124 + ret = shift_arg_pages(vma, stack_shift);
48125 + if (ret)
48126 + goto out_unlock;
48127 + }
48128 +
48129 vm_flags = VM_STACK_FLAGS;
48130
48131 /*
48132 @@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm *bprm,
48133 vm_flags &= ~VM_EXEC;
48134 vm_flags |= mm->def_flags;
48135
48136 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48137 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48138 + vm_flags &= ~VM_EXEC;
48139 +
48140 +#ifdef CONFIG_PAX_MPROTECT
48141 + if (mm->pax_flags & MF_PAX_MPROTECT)
48142 + vm_flags &= ~VM_MAYEXEC;
48143 +#endif
48144 +
48145 + }
48146 +#endif
48147 +
48148 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
48149 vm_flags);
48150 if (ret)
48151 goto out_unlock;
48152 BUG_ON(prev != vma);
48153
48154 - /* Move stack pages down in memory. */
48155 - if (stack_shift) {
48156 - ret = shift_arg_pages(vma, stack_shift);
48157 - if (ret)
48158 - goto out_unlock;
48159 - }
48160 -
48161 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
48162 stack_size = vma->vm_end - vma->vm_start;
48163 /*
48164 @@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_t offset,
48165 old_fs = get_fs();
48166 set_fs(get_ds());
48167 /* The cast to a user pointer is valid due to the set_fs() */
48168 - result = vfs_read(file, (void __user *)addr, count, &pos);
48169 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
48170 set_fs(old_fs);
48171 return result;
48172 }
48173 @@ -1152,7 +1181,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
48174 }
48175 rcu_read_unlock();
48176
48177 - if (p->fs->users > n_fs) {
48178 + if (atomic_read(&p->fs->users) > n_fs) {
48179 bprm->unsafe |= LSM_UNSAFE_SHARE;
48180 } else {
48181 res = -EAGAIN;
48182 @@ -1347,11 +1376,35 @@ int do_execve(char * filename,
48183 char __user *__user *envp,
48184 struct pt_regs * regs)
48185 {
48186 +#ifdef CONFIG_GRKERNSEC
48187 + struct file *old_exec_file;
48188 + struct acl_subject_label *old_acl;
48189 + struct rlimit old_rlim[RLIM_NLIMITS];
48190 +#endif
48191 struct linux_binprm *bprm;
48192 struct file *file;
48193 struct files_struct *displaced;
48194 bool clear_in_exec;
48195 int retval;
48196 + const struct cred *cred = current_cred();
48197 +
48198 + /*
48199 + * We move the actual failure in case of RLIMIT_NPROC excess from
48200 + * set*uid() to execve() because too many poorly written programs
48201 + * don't check setuid() return code. Here we additionally recheck
48202 + * whether NPROC limit is still exceeded.
48203 + */
48204 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48205 +
48206 + if ((current->flags & PF_NPROC_EXCEEDED) &&
48207 + atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48208 + retval = -EAGAIN;
48209 + goto out_ret;
48210 + }
48211 +
48212 + /* We're below the limit (still or again), so we don't want to make
48213 + * further execve() calls fail. */
48214 + current->flags &= ~PF_NPROC_EXCEEDED;
48215
48216 retval = unshare_files(&displaced);
48217 if (retval)
48218 @@ -1383,6 +1436,16 @@ int do_execve(char * filename,
48219 bprm->filename = filename;
48220 bprm->interp = filename;
48221
48222 + if (gr_process_user_ban()) {
48223 + retval = -EPERM;
48224 + goto out_file;
48225 + }
48226 +
48227 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
48228 + retval = -EACCES;
48229 + goto out_file;
48230 + }
48231 +
48232 retval = bprm_mm_init(bprm);
48233 if (retval)
48234 goto out_file;
48235 @@ -1412,10 +1475,41 @@ int do_execve(char * filename,
48236 if (retval < 0)
48237 goto out;
48238
48239 + if (!gr_tpe_allow(file)) {
48240 + retval = -EACCES;
48241 + goto out;
48242 + }
48243 +
48244 + if (gr_check_crash_exec(file)) {
48245 + retval = -EACCES;
48246 + goto out;
48247 + }
48248 +
48249 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48250 +
48251 + gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
48252 +
48253 +#ifdef CONFIG_GRKERNSEC
48254 + old_acl = current->acl;
48255 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48256 + old_exec_file = current->exec_file;
48257 + get_file(file);
48258 + current->exec_file = file;
48259 +#endif
48260 +
48261 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48262 + bprm->unsafe & LSM_UNSAFE_SHARE);
48263 + if (retval < 0)
48264 + goto out_fail;
48265 +
48266 current->flags &= ~PF_KTHREAD;
48267 retval = search_binary_handler(bprm,regs);
48268 if (retval < 0)
48269 - goto out;
48270 + goto out_fail;
48271 +#ifdef CONFIG_GRKERNSEC
48272 + if (old_exec_file)
48273 + fput(old_exec_file);
48274 +#endif
48275
48276 /* execve succeeded */
48277 current->fs->in_exec = 0;
48278 @@ -1426,6 +1520,14 @@ int do_execve(char * filename,
48279 put_files_struct(displaced);
48280 return retval;
48281
48282 +out_fail:
48283 +#ifdef CONFIG_GRKERNSEC
48284 + current->acl = old_acl;
48285 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48286 + fput(current->exec_file);
48287 + current->exec_file = old_exec_file;
48288 +#endif
48289 +
48290 out:
48291 if (bprm->mm) {
48292 acct_arg_size(bprm, 0);
48293 @@ -1591,6 +1693,220 @@ out:
48294 return ispipe;
48295 }
48296
48297 +int pax_check_flags(unsigned long *flags)
48298 +{
48299 + int retval = 0;
48300 +
48301 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
48302 + if (*flags & MF_PAX_SEGMEXEC)
48303 + {
48304 + *flags &= ~MF_PAX_SEGMEXEC;
48305 + retval = -EINVAL;
48306 + }
48307 +#endif
48308 +
48309 + if ((*flags & MF_PAX_PAGEEXEC)
48310 +
48311 +#ifdef CONFIG_PAX_PAGEEXEC
48312 + && (*flags & MF_PAX_SEGMEXEC)
48313 +#endif
48314 +
48315 + )
48316 + {
48317 + *flags &= ~MF_PAX_PAGEEXEC;
48318 + retval = -EINVAL;
48319 + }
48320 +
48321 + if ((*flags & MF_PAX_MPROTECT)
48322 +
48323 +#ifdef CONFIG_PAX_MPROTECT
48324 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48325 +#endif
48326 +
48327 + )
48328 + {
48329 + *flags &= ~MF_PAX_MPROTECT;
48330 + retval = -EINVAL;
48331 + }
48332 +
48333 + if ((*flags & MF_PAX_EMUTRAMP)
48334 +
48335 +#ifdef CONFIG_PAX_EMUTRAMP
48336 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48337 +#endif
48338 +
48339 + )
48340 + {
48341 + *flags &= ~MF_PAX_EMUTRAMP;
48342 + retval = -EINVAL;
48343 + }
48344 +
48345 + return retval;
48346 +}
48347 +
48348 +EXPORT_SYMBOL(pax_check_flags);
48349 +
48350 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48351 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
48352 +{
48353 + struct task_struct *tsk = current;
48354 + struct mm_struct *mm = current->mm;
48355 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
48356 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
48357 + char *path_exec = NULL;
48358 + char *path_fault = NULL;
48359 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
48360 +
48361 + if (buffer_exec && buffer_fault) {
48362 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
48363 +
48364 + down_read(&mm->mmap_sem);
48365 + vma = mm->mmap;
48366 + while (vma && (!vma_exec || !vma_fault)) {
48367 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
48368 + vma_exec = vma;
48369 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
48370 + vma_fault = vma;
48371 + vma = vma->vm_next;
48372 + }
48373 + if (vma_exec) {
48374 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
48375 + if (IS_ERR(path_exec))
48376 + path_exec = "<path too long>";
48377 + else {
48378 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
48379 + if (path_exec) {
48380 + *path_exec = 0;
48381 + path_exec = buffer_exec;
48382 + } else
48383 + path_exec = "<path too long>";
48384 + }
48385 + }
48386 + if (vma_fault) {
48387 + start = vma_fault->vm_start;
48388 + end = vma_fault->vm_end;
48389 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48390 + if (vma_fault->vm_file) {
48391 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48392 + if (IS_ERR(path_fault))
48393 + path_fault = "<path too long>";
48394 + else {
48395 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48396 + if (path_fault) {
48397 + *path_fault = 0;
48398 + path_fault = buffer_fault;
48399 + } else
48400 + path_fault = "<path too long>";
48401 + }
48402 + } else
48403 + path_fault = "<anonymous mapping>";
48404 + }
48405 + up_read(&mm->mmap_sem);
48406 + }
48407 + if (tsk->signal->curr_ip)
48408 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48409 + else
48410 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48411 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
48412 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
48413 + task_uid(tsk), task_euid(tsk), pc, sp);
48414 + free_page((unsigned long)buffer_exec);
48415 + free_page((unsigned long)buffer_fault);
48416 + pax_report_insns(regs, pc, sp);
48417 + do_coredump(SIGKILL, SIGKILL, regs);
48418 +}
48419 +#endif
48420 +
48421 +#ifdef CONFIG_PAX_REFCOUNT
48422 +void pax_report_refcount_overflow(struct pt_regs *regs)
48423 +{
48424 + if (current->signal->curr_ip)
48425 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48426 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
48427 + else
48428 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48429 + current->comm, task_pid_nr(current), current_uid(), current_euid());
48430 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48431 + show_regs(regs);
48432 + force_sig_specific(SIGKILL, current);
48433 +}
48434 +#endif
48435 +
48436 +#ifdef CONFIG_PAX_USERCOPY
48437 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48438 +int object_is_on_stack(const void *obj, unsigned long len)
48439 +{
48440 + const void * const stack = task_stack_page(current);
48441 + const void * const stackend = stack + THREAD_SIZE;
48442 +
48443 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48444 + const void *frame = NULL;
48445 + const void *oldframe;
48446 +#endif
48447 +
48448 + if (obj + len < obj)
48449 + return -1;
48450 +
48451 + if (obj + len <= stack || stackend <= obj)
48452 + return 0;
48453 +
48454 + if (obj < stack || stackend < obj + len)
48455 + return -1;
48456 +
48457 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48458 + oldframe = __builtin_frame_address(1);
48459 + if (oldframe)
48460 + frame = __builtin_frame_address(2);
48461 + /*
48462 + low ----------------------------------------------> high
48463 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
48464 + ^----------------^
48465 + allow copies only within here
48466 + */
48467 + while (stack <= frame && frame < stackend) {
48468 + /* if obj + len extends past the last frame, this
48469 + check won't pass and the next frame will be 0,
48470 + causing us to bail out and correctly report
48471 + the copy as invalid
48472 + */
48473 + if (obj + len <= frame)
48474 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48475 + oldframe = frame;
48476 + frame = *(const void * const *)frame;
48477 + }
48478 + return -1;
48479 +#else
48480 + return 1;
48481 +#endif
48482 +}
48483 +
48484 +
48485 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48486 +{
48487 + if (current->signal->curr_ip)
48488 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48489 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48490 + else
48491 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48492 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48493 +
48494 + dump_stack();
48495 + gr_handle_kernel_exploit();
48496 + do_group_exit(SIGKILL);
48497 +}
48498 +#endif
48499 +
48500 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48501 +void pax_track_stack(void)
48502 +{
48503 + unsigned long sp = (unsigned long)&sp;
48504 + if (sp < current_thread_info()->lowest_stack &&
48505 + sp > (unsigned long)task_stack_page(current))
48506 + current_thread_info()->lowest_stack = sp;
48507 +}
48508 +EXPORT_SYMBOL(pax_track_stack);
48509 +#endif
48510 +
48511 static int zap_process(struct task_struct *start)
48512 {
48513 struct task_struct *t;
48514 @@ -1793,17 +2109,17 @@ static void wait_for_dump_helpers(struct file *file)
48515 pipe = file->f_path.dentry->d_inode->i_pipe;
48516
48517 pipe_lock(pipe);
48518 - pipe->readers++;
48519 - pipe->writers--;
48520 + atomic_inc(&pipe->readers);
48521 + atomic_dec(&pipe->writers);
48522
48523 - while ((pipe->readers > 1) && (!signal_pending(current))) {
48524 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
48525 wake_up_interruptible_sync(&pipe->wait);
48526 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48527 pipe_wait(pipe);
48528 }
48529
48530 - pipe->readers--;
48531 - pipe->writers++;
48532 + atomic_dec(&pipe->readers);
48533 + atomic_inc(&pipe->writers);
48534 pipe_unlock(pipe);
48535
48536 }
48537 @@ -1826,10 +2142,13 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48538 char **helper_argv = NULL;
48539 int helper_argc = 0;
48540 int dump_count = 0;
48541 - static atomic_t core_dump_count = ATOMIC_INIT(0);
48542 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
48543
48544 audit_core_dumps(signr);
48545
48546 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
48547 + gr_handle_brute_attach(current, mm->flags);
48548 +
48549 binfmt = mm->binfmt;
48550 if (!binfmt || !binfmt->core_dump)
48551 goto fail;
48552 @@ -1874,6 +2193,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48553 */
48554 clear_thread_flag(TIF_SIGPENDING);
48555
48556 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
48557 +
48558 /*
48559 * lock_kernel() because format_corename() is controlled by sysctl, which
48560 * uses lock_kernel()
48561 @@ -1908,7 +2229,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48562 goto fail_unlock;
48563 }
48564
48565 - dump_count = atomic_inc_return(&core_dump_count);
48566 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
48567 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
48568 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
48569 task_tgid_vnr(current), current->comm);
48570 @@ -1972,7 +2293,7 @@ close_fail:
48571 filp_close(file, NULL);
48572 fail_dropcount:
48573 if (dump_count)
48574 - atomic_dec(&core_dump_count);
48575 + atomic_dec_unchecked(&core_dump_count);
48576 fail_unlock:
48577 if (helper_argv)
48578 argv_free(helper_argv);
48579 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48580 index 7f8d2e5..a1abdbb 100644
48581 --- a/fs/ext2/balloc.c
48582 +++ b/fs/ext2/balloc.c
48583 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48584
48585 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48586 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48587 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48588 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48589 sbi->s_resuid != current_fsuid() &&
48590 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48591 return 0;
48592 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48593 index 27967f9..9f2a5fb 100644
48594 --- a/fs/ext3/balloc.c
48595 +++ b/fs/ext3/balloc.c
48596 @@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
48597
48598 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48599 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48600 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48601 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48602 sbi->s_resuid != current_fsuid() &&
48603 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48604 return 0;
48605 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48606 index e85b63c..80398e6 100644
48607 --- a/fs/ext4/balloc.c
48608 +++ b/fs/ext4/balloc.c
48609 @@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
48610 /* Hm, nope. Are (enough) root reserved blocks available? */
48611 if (sbi->s_resuid == current_fsuid() ||
48612 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
48613 - capable(CAP_SYS_RESOURCE)) {
48614 + capable_nolog(CAP_SYS_RESOURCE)) {
48615 if (free_blocks >= (nblocks + dirty_blocks))
48616 return 1;
48617 }
48618 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48619 index 67c46ed..1f237e5 100644
48620 --- a/fs/ext4/ext4.h
48621 +++ b/fs/ext4/ext4.h
48622 @@ -1077,19 +1077,19 @@ struct ext4_sb_info {
48623
48624 /* stats for buddy allocator */
48625 spinlock_t s_mb_pa_lock;
48626 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48627 - atomic_t s_bal_success; /* we found long enough chunks */
48628 - atomic_t s_bal_allocated; /* in blocks */
48629 - atomic_t s_bal_ex_scanned; /* total extents scanned */
48630 - atomic_t s_bal_goals; /* goal hits */
48631 - atomic_t s_bal_breaks; /* too long searches */
48632 - atomic_t s_bal_2orders; /* 2^order hits */
48633 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48634 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48635 + atomic_unchecked_t s_bal_allocated; /* in blocks */
48636 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48637 + atomic_unchecked_t s_bal_goals; /* goal hits */
48638 + atomic_unchecked_t s_bal_breaks; /* too long searches */
48639 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48640 spinlock_t s_bal_lock;
48641 unsigned long s_mb_buddies_generated;
48642 unsigned long long s_mb_generation_time;
48643 - atomic_t s_mb_lost_chunks;
48644 - atomic_t s_mb_preallocated;
48645 - atomic_t s_mb_discarded;
48646 + atomic_unchecked_t s_mb_lost_chunks;
48647 + atomic_unchecked_t s_mb_preallocated;
48648 + atomic_unchecked_t s_mb_discarded;
48649 atomic_t s_lock_busy;
48650
48651 /* locality groups */
48652 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
48653 index 2a60541..7439d61 100644
48654 --- a/fs/ext4/file.c
48655 +++ b/fs/ext4/file.c
48656 @@ -122,8 +122,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
48657 cp = d_path(&path, buf, sizeof(buf));
48658 path_put(&path);
48659 if (!IS_ERR(cp)) {
48660 - memcpy(sbi->s_es->s_last_mounted, cp,
48661 - sizeof(sbi->s_es->s_last_mounted));
48662 + strlcpy(sbi->s_es->s_last_mounted, cp,
48663 + sizeof(sbi->s_es->s_last_mounted));
48664 sb->s_dirt = 1;
48665 }
48666 }
48667 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48668 index 42bac1b..0aab9d8 100644
48669 --- a/fs/ext4/mballoc.c
48670 +++ b/fs/ext4/mballoc.c
48671 @@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48672 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48673
48674 if (EXT4_SB(sb)->s_mb_stats)
48675 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48676 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48677
48678 break;
48679 }
48680 @@ -2131,7 +2131,7 @@ repeat:
48681 ac->ac_status = AC_STATUS_CONTINUE;
48682 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48683 cr = 3;
48684 - atomic_inc(&sbi->s_mb_lost_chunks);
48685 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48686 goto repeat;
48687 }
48688 }
48689 @@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
48690 ext4_grpblk_t counters[16];
48691 } sg;
48692
48693 + pax_track_stack();
48694 +
48695 group--;
48696 if (group == 0)
48697 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
48698 @@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *sb)
48699 if (sbi->s_mb_stats) {
48700 printk(KERN_INFO
48701 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
48702 - atomic_read(&sbi->s_bal_allocated),
48703 - atomic_read(&sbi->s_bal_reqs),
48704 - atomic_read(&sbi->s_bal_success));
48705 + atomic_read_unchecked(&sbi->s_bal_allocated),
48706 + atomic_read_unchecked(&sbi->s_bal_reqs),
48707 + atomic_read_unchecked(&sbi->s_bal_success));
48708 printk(KERN_INFO
48709 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
48710 "%u 2^N hits, %u breaks, %u lost\n",
48711 - atomic_read(&sbi->s_bal_ex_scanned),
48712 - atomic_read(&sbi->s_bal_goals),
48713 - atomic_read(&sbi->s_bal_2orders),
48714 - atomic_read(&sbi->s_bal_breaks),
48715 - atomic_read(&sbi->s_mb_lost_chunks));
48716 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48717 + atomic_read_unchecked(&sbi->s_bal_goals),
48718 + atomic_read_unchecked(&sbi->s_bal_2orders),
48719 + atomic_read_unchecked(&sbi->s_bal_breaks),
48720 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48721 printk(KERN_INFO
48722 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
48723 sbi->s_mb_buddies_generated++,
48724 sbi->s_mb_generation_time);
48725 printk(KERN_INFO
48726 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
48727 - atomic_read(&sbi->s_mb_preallocated),
48728 - atomic_read(&sbi->s_mb_discarded));
48729 + atomic_read_unchecked(&sbi->s_mb_preallocated),
48730 + atomic_read_unchecked(&sbi->s_mb_discarded));
48731 }
48732
48733 free_percpu(sbi->s_locality_groups);
48734 @@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48735 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48736
48737 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48738 - atomic_inc(&sbi->s_bal_reqs);
48739 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48740 + atomic_inc_unchecked(&sbi->s_bal_reqs);
48741 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48742 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
48743 - atomic_inc(&sbi->s_bal_success);
48744 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48745 + atomic_inc_unchecked(&sbi->s_bal_success);
48746 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48747 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48748 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48749 - atomic_inc(&sbi->s_bal_goals);
48750 + atomic_inc_unchecked(&sbi->s_bal_goals);
48751 if (ac->ac_found > sbi->s_mb_max_to_scan)
48752 - atomic_inc(&sbi->s_bal_breaks);
48753 + atomic_inc_unchecked(&sbi->s_bal_breaks);
48754 }
48755
48756 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48757 @@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48758 trace_ext4_mb_new_inode_pa(ac, pa);
48759
48760 ext4_mb_use_inode_pa(ac, pa);
48761 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48762 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48763
48764 ei = EXT4_I(ac->ac_inode);
48765 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48766 @@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48767 trace_ext4_mb_new_group_pa(ac, pa);
48768
48769 ext4_mb_use_group_pa(ac, pa);
48770 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48771 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48772
48773 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48774 lg = ac->ac_lg;
48775 @@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48776 * from the bitmap and continue.
48777 */
48778 }
48779 - atomic_add(free, &sbi->s_mb_discarded);
48780 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
48781
48782 return err;
48783 }
48784 @@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48785 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48786 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48787 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48788 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48789 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48790
48791 if (ac) {
48792 ac->ac_sb = sb;
48793 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
48794 index f27e045..be5a1c3 100644
48795 --- a/fs/ext4/super.c
48796 +++ b/fs/ext4/super.c
48797 @@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobject *kobj)
48798 }
48799
48800
48801 -static struct sysfs_ops ext4_attr_ops = {
48802 +static const struct sysfs_ops ext4_attr_ops = {
48803 .show = ext4_attr_show,
48804 .store = ext4_attr_store,
48805 };
48806 diff --git a/fs/fcntl.c b/fs/fcntl.c
48807 index 97e01dc..e9aab2d 100644
48808 --- a/fs/fcntl.c
48809 +++ b/fs/fcntl.c
48810 @@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48811 if (err)
48812 return err;
48813
48814 + if (gr_handle_chroot_fowner(pid, type))
48815 + return -ENOENT;
48816 + if (gr_check_protected_task_fowner(pid, type))
48817 + return -EACCES;
48818 +
48819 f_modown(filp, pid, type, force);
48820 return 0;
48821 }
48822 @@ -265,7 +270,7 @@ pid_t f_getown(struct file *filp)
48823
48824 static int f_setown_ex(struct file *filp, unsigned long arg)
48825 {
48826 - struct f_owner_ex * __user owner_p = (void * __user)arg;
48827 + struct f_owner_ex __user *owner_p = (void __user *)arg;
48828 struct f_owner_ex owner;
48829 struct pid *pid;
48830 int type;
48831 @@ -305,7 +310,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
48832
48833 static int f_getown_ex(struct file *filp, unsigned long arg)
48834 {
48835 - struct f_owner_ex * __user owner_p = (void * __user)arg;
48836 + struct f_owner_ex __user *owner_p = (void __user *)arg;
48837 struct f_owner_ex owner;
48838 int ret = 0;
48839
48840 @@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
48841 switch (cmd) {
48842 case F_DUPFD:
48843 case F_DUPFD_CLOEXEC:
48844 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
48845 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
48846 break;
48847 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
48848 diff --git a/fs/fifo.c b/fs/fifo.c
48849 index f8f97b8..b1f2259 100644
48850 --- a/fs/fifo.c
48851 +++ b/fs/fifo.c
48852 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48853 */
48854 filp->f_op = &read_pipefifo_fops;
48855 pipe->r_counter++;
48856 - if (pipe->readers++ == 0)
48857 + if (atomic_inc_return(&pipe->readers) == 1)
48858 wake_up_partner(inode);
48859
48860 - if (!pipe->writers) {
48861 + if (!atomic_read(&pipe->writers)) {
48862 if ((filp->f_flags & O_NONBLOCK)) {
48863 /* suppress POLLHUP until we have
48864 * seen a writer */
48865 @@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48866 * errno=ENXIO when there is no process reading the FIFO.
48867 */
48868 ret = -ENXIO;
48869 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48870 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48871 goto err;
48872
48873 filp->f_op = &write_pipefifo_fops;
48874 pipe->w_counter++;
48875 - if (!pipe->writers++)
48876 + if (atomic_inc_return(&pipe->writers) == 1)
48877 wake_up_partner(inode);
48878
48879 - if (!pipe->readers) {
48880 + if (!atomic_read(&pipe->readers)) {
48881 wait_for_partner(inode, &pipe->r_counter);
48882 if (signal_pending(current))
48883 goto err_wr;
48884 @@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48885 */
48886 filp->f_op = &rdwr_pipefifo_fops;
48887
48888 - pipe->readers++;
48889 - pipe->writers++;
48890 + atomic_inc(&pipe->readers);
48891 + atomic_inc(&pipe->writers);
48892 pipe->r_counter++;
48893 pipe->w_counter++;
48894 - if (pipe->readers == 1 || pipe->writers == 1)
48895 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48896 wake_up_partner(inode);
48897 break;
48898
48899 @@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48900 return 0;
48901
48902 err_rd:
48903 - if (!--pipe->readers)
48904 + if (atomic_dec_and_test(&pipe->readers))
48905 wake_up_interruptible(&pipe->wait);
48906 ret = -ERESTARTSYS;
48907 goto err;
48908
48909 err_wr:
48910 - if (!--pipe->writers)
48911 + if (atomic_dec_and_test(&pipe->writers))
48912 wake_up_interruptible(&pipe->wait);
48913 ret = -ERESTARTSYS;
48914 goto err;
48915
48916 err:
48917 - if (!pipe->readers && !pipe->writers)
48918 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48919 free_pipe_info(inode);
48920
48921 err_nocleanup:
48922 diff --git a/fs/file.c b/fs/file.c
48923 index 87e1290..a930cc4 100644
48924 --- a/fs/file.c
48925 +++ b/fs/file.c
48926 @@ -14,6 +14,7 @@
48927 #include <linux/slab.h>
48928 #include <linux/vmalloc.h>
48929 #include <linux/file.h>
48930 +#include <linux/security.h>
48931 #include <linux/fdtable.h>
48932 #include <linux/bitops.h>
48933 #include <linux/interrupt.h>
48934 @@ -257,6 +258,8 @@ int expand_files(struct files_struct *files, int nr)
48935 * N.B. For clone tasks sharing a files structure, this test
48936 * will limit the total number of files that can be opened.
48937 */
48938 +
48939 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
48940 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
48941 return -EMFILE;
48942
48943 diff --git a/fs/filesystems.c b/fs/filesystems.c
48944 index a24c58e..53f91ee 100644
48945 --- a/fs/filesystems.c
48946 +++ b/fs/filesystems.c
48947 @@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(const char *name)
48948 int len = dot ? dot - name : strlen(name);
48949
48950 fs = __get_fs_type(name, len);
48951 +
48952 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
48953 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48954 +#else
48955 if (!fs && (request_module("%.*s", len, name) == 0))
48956 +#endif
48957 fs = __get_fs_type(name, len);
48958
48959 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48960 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48961 index eee0590..ef5bc0e 100644
48962 --- a/fs/fs_struct.c
48963 +++ b/fs/fs_struct.c
48964 @@ -4,6 +4,7 @@
48965 #include <linux/path.h>
48966 #include <linux/slab.h>
48967 #include <linux/fs_struct.h>
48968 +#include <linux/grsecurity.h>
48969
48970 /*
48971 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
48972 @@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48973 old_root = fs->root;
48974 fs->root = *path;
48975 path_get(path);
48976 + gr_set_chroot_entries(current, path);
48977 write_unlock(&fs->lock);
48978 if (old_root.dentry)
48979 path_put(&old_root);
48980 @@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48981 && fs->root.mnt == old_root->mnt) {
48982 path_get(new_root);
48983 fs->root = *new_root;
48984 + gr_set_chroot_entries(p, new_root);
48985 count++;
48986 }
48987 if (fs->pwd.dentry == old_root->dentry
48988 @@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
48989 task_lock(tsk);
48990 write_lock(&fs->lock);
48991 tsk->fs = NULL;
48992 - kill = !--fs->users;
48993 + gr_clear_chroot_entries(tsk);
48994 + kill = !atomic_dec_return(&fs->users);
48995 write_unlock(&fs->lock);
48996 task_unlock(tsk);
48997 if (kill)
48998 @@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48999 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
49000 /* We don't need to lock fs - think why ;-) */
49001 if (fs) {
49002 - fs->users = 1;
49003 + atomic_set(&fs->users, 1);
49004 fs->in_exec = 0;
49005 rwlock_init(&fs->lock);
49006 fs->umask = old->umask;
49007 @@ -127,8 +131,9 @@ int unshare_fs_struct(void)
49008
49009 task_lock(current);
49010 write_lock(&fs->lock);
49011 - kill = !--fs->users;
49012 + kill = !atomic_dec_return(&fs->users);
49013 current->fs = new_fs;
49014 + gr_set_chroot_entries(current, &new_fs->root);
49015 write_unlock(&fs->lock);
49016 task_unlock(current);
49017
49018 @@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
49019
49020 /* to be mentioned only in INIT_TASK */
49021 struct fs_struct init_fs = {
49022 - .users = 1,
49023 + .users = ATOMIC_INIT(1),
49024 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
49025 .umask = 0022,
49026 };
49027 @@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
49028 task_lock(current);
49029
49030 write_lock(&init_fs.lock);
49031 - init_fs.users++;
49032 + atomic_inc(&init_fs.users);
49033 write_unlock(&init_fs.lock);
49034
49035 write_lock(&fs->lock);
49036 current->fs = &init_fs;
49037 - kill = !--fs->users;
49038 + gr_set_chroot_entries(current, &current->fs->root);
49039 + kill = !atomic_dec_return(&fs->users);
49040 write_unlock(&fs->lock);
49041
49042 task_unlock(current);
49043 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
49044 index 9905350..02eaec4 100644
49045 --- a/fs/fscache/cookie.c
49046 +++ b/fs/fscache/cookie.c
49047 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
49048 parent ? (char *) parent->def->name : "<no-parent>",
49049 def->name, netfs_data);
49050
49051 - fscache_stat(&fscache_n_acquires);
49052 + fscache_stat_unchecked(&fscache_n_acquires);
49053
49054 /* if there's no parent cookie, then we don't create one here either */
49055 if (!parent) {
49056 - fscache_stat(&fscache_n_acquires_null);
49057 + fscache_stat_unchecked(&fscache_n_acquires_null);
49058 _leave(" [no parent]");
49059 return NULL;
49060 }
49061 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
49062 /* allocate and initialise a cookie */
49063 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
49064 if (!cookie) {
49065 - fscache_stat(&fscache_n_acquires_oom);
49066 + fscache_stat_unchecked(&fscache_n_acquires_oom);
49067 _leave(" [ENOMEM]");
49068 return NULL;
49069 }
49070 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49071
49072 switch (cookie->def->type) {
49073 case FSCACHE_COOKIE_TYPE_INDEX:
49074 - fscache_stat(&fscache_n_cookie_index);
49075 + fscache_stat_unchecked(&fscache_n_cookie_index);
49076 break;
49077 case FSCACHE_COOKIE_TYPE_DATAFILE:
49078 - fscache_stat(&fscache_n_cookie_data);
49079 + fscache_stat_unchecked(&fscache_n_cookie_data);
49080 break;
49081 default:
49082 - fscache_stat(&fscache_n_cookie_special);
49083 + fscache_stat_unchecked(&fscache_n_cookie_special);
49084 break;
49085 }
49086
49087 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49088 if (fscache_acquire_non_index_cookie(cookie) < 0) {
49089 atomic_dec(&parent->n_children);
49090 __fscache_cookie_put(cookie);
49091 - fscache_stat(&fscache_n_acquires_nobufs);
49092 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
49093 _leave(" = NULL");
49094 return NULL;
49095 }
49096 }
49097
49098 - fscache_stat(&fscache_n_acquires_ok);
49099 + fscache_stat_unchecked(&fscache_n_acquires_ok);
49100 _leave(" = %p", cookie);
49101 return cookie;
49102 }
49103 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
49104 cache = fscache_select_cache_for_object(cookie->parent);
49105 if (!cache) {
49106 up_read(&fscache_addremove_sem);
49107 - fscache_stat(&fscache_n_acquires_no_cache);
49108 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
49109 _leave(" = -ENOMEDIUM [no cache]");
49110 return -ENOMEDIUM;
49111 }
49112 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
49113 object = cache->ops->alloc_object(cache, cookie);
49114 fscache_stat_d(&fscache_n_cop_alloc_object);
49115 if (IS_ERR(object)) {
49116 - fscache_stat(&fscache_n_object_no_alloc);
49117 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
49118 ret = PTR_ERR(object);
49119 goto error;
49120 }
49121
49122 - fscache_stat(&fscache_n_object_alloc);
49123 + fscache_stat_unchecked(&fscache_n_object_alloc);
49124
49125 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
49126
49127 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
49128 struct fscache_object *object;
49129 struct hlist_node *_p;
49130
49131 - fscache_stat(&fscache_n_updates);
49132 + fscache_stat_unchecked(&fscache_n_updates);
49133
49134 if (!cookie) {
49135 - fscache_stat(&fscache_n_updates_null);
49136 + fscache_stat_unchecked(&fscache_n_updates_null);
49137 _leave(" [no cookie]");
49138 return;
49139 }
49140 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49141 struct fscache_object *object;
49142 unsigned long event;
49143
49144 - fscache_stat(&fscache_n_relinquishes);
49145 + fscache_stat_unchecked(&fscache_n_relinquishes);
49146 if (retire)
49147 - fscache_stat(&fscache_n_relinquishes_retire);
49148 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
49149
49150 if (!cookie) {
49151 - fscache_stat(&fscache_n_relinquishes_null);
49152 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
49153 _leave(" [no cookie]");
49154 return;
49155 }
49156 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49157
49158 /* wait for the cookie to finish being instantiated (or to fail) */
49159 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
49160 - fscache_stat(&fscache_n_relinquishes_waitcrt);
49161 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
49162 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
49163 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
49164 }
49165 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
49166 index edd7434..0725e66 100644
49167 --- a/fs/fscache/internal.h
49168 +++ b/fs/fscache/internal.h
49169 @@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
49170 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
49171 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
49172
49173 -extern atomic_t fscache_n_op_pend;
49174 -extern atomic_t fscache_n_op_run;
49175 -extern atomic_t fscache_n_op_enqueue;
49176 -extern atomic_t fscache_n_op_deferred_release;
49177 -extern atomic_t fscache_n_op_release;
49178 -extern atomic_t fscache_n_op_gc;
49179 -extern atomic_t fscache_n_op_cancelled;
49180 -extern atomic_t fscache_n_op_rejected;
49181 +extern atomic_unchecked_t fscache_n_op_pend;
49182 +extern atomic_unchecked_t fscache_n_op_run;
49183 +extern atomic_unchecked_t fscache_n_op_enqueue;
49184 +extern atomic_unchecked_t fscache_n_op_deferred_release;
49185 +extern atomic_unchecked_t fscache_n_op_release;
49186 +extern atomic_unchecked_t fscache_n_op_gc;
49187 +extern atomic_unchecked_t fscache_n_op_cancelled;
49188 +extern atomic_unchecked_t fscache_n_op_rejected;
49189
49190 -extern atomic_t fscache_n_attr_changed;
49191 -extern atomic_t fscache_n_attr_changed_ok;
49192 -extern atomic_t fscache_n_attr_changed_nobufs;
49193 -extern atomic_t fscache_n_attr_changed_nomem;
49194 -extern atomic_t fscache_n_attr_changed_calls;
49195 +extern atomic_unchecked_t fscache_n_attr_changed;
49196 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
49197 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
49198 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
49199 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
49200
49201 -extern atomic_t fscache_n_allocs;
49202 -extern atomic_t fscache_n_allocs_ok;
49203 -extern atomic_t fscache_n_allocs_wait;
49204 -extern atomic_t fscache_n_allocs_nobufs;
49205 -extern atomic_t fscache_n_allocs_intr;
49206 -extern atomic_t fscache_n_allocs_object_dead;
49207 -extern atomic_t fscache_n_alloc_ops;
49208 -extern atomic_t fscache_n_alloc_op_waits;
49209 +extern atomic_unchecked_t fscache_n_allocs;
49210 +extern atomic_unchecked_t fscache_n_allocs_ok;
49211 +extern atomic_unchecked_t fscache_n_allocs_wait;
49212 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
49213 +extern atomic_unchecked_t fscache_n_allocs_intr;
49214 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
49215 +extern atomic_unchecked_t fscache_n_alloc_ops;
49216 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
49217
49218 -extern atomic_t fscache_n_retrievals;
49219 -extern atomic_t fscache_n_retrievals_ok;
49220 -extern atomic_t fscache_n_retrievals_wait;
49221 -extern atomic_t fscache_n_retrievals_nodata;
49222 -extern atomic_t fscache_n_retrievals_nobufs;
49223 -extern atomic_t fscache_n_retrievals_intr;
49224 -extern atomic_t fscache_n_retrievals_nomem;
49225 -extern atomic_t fscache_n_retrievals_object_dead;
49226 -extern atomic_t fscache_n_retrieval_ops;
49227 -extern atomic_t fscache_n_retrieval_op_waits;
49228 +extern atomic_unchecked_t fscache_n_retrievals;
49229 +extern atomic_unchecked_t fscache_n_retrievals_ok;
49230 +extern atomic_unchecked_t fscache_n_retrievals_wait;
49231 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
49232 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
49233 +extern atomic_unchecked_t fscache_n_retrievals_intr;
49234 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
49235 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
49236 +extern atomic_unchecked_t fscache_n_retrieval_ops;
49237 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
49238
49239 -extern atomic_t fscache_n_stores;
49240 -extern atomic_t fscache_n_stores_ok;
49241 -extern atomic_t fscache_n_stores_again;
49242 -extern atomic_t fscache_n_stores_nobufs;
49243 -extern atomic_t fscache_n_stores_oom;
49244 -extern atomic_t fscache_n_store_ops;
49245 -extern atomic_t fscache_n_store_calls;
49246 -extern atomic_t fscache_n_store_pages;
49247 -extern atomic_t fscache_n_store_radix_deletes;
49248 -extern atomic_t fscache_n_store_pages_over_limit;
49249 +extern atomic_unchecked_t fscache_n_stores;
49250 +extern atomic_unchecked_t fscache_n_stores_ok;
49251 +extern atomic_unchecked_t fscache_n_stores_again;
49252 +extern atomic_unchecked_t fscache_n_stores_nobufs;
49253 +extern atomic_unchecked_t fscache_n_stores_oom;
49254 +extern atomic_unchecked_t fscache_n_store_ops;
49255 +extern atomic_unchecked_t fscache_n_store_calls;
49256 +extern atomic_unchecked_t fscache_n_store_pages;
49257 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
49258 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
49259
49260 -extern atomic_t fscache_n_store_vmscan_not_storing;
49261 -extern atomic_t fscache_n_store_vmscan_gone;
49262 -extern atomic_t fscache_n_store_vmscan_busy;
49263 -extern atomic_t fscache_n_store_vmscan_cancelled;
49264 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49265 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
49266 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
49267 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49268
49269 -extern atomic_t fscache_n_marks;
49270 -extern atomic_t fscache_n_uncaches;
49271 +extern atomic_unchecked_t fscache_n_marks;
49272 +extern atomic_unchecked_t fscache_n_uncaches;
49273
49274 -extern atomic_t fscache_n_acquires;
49275 -extern atomic_t fscache_n_acquires_null;
49276 -extern atomic_t fscache_n_acquires_no_cache;
49277 -extern atomic_t fscache_n_acquires_ok;
49278 -extern atomic_t fscache_n_acquires_nobufs;
49279 -extern atomic_t fscache_n_acquires_oom;
49280 +extern atomic_unchecked_t fscache_n_acquires;
49281 +extern atomic_unchecked_t fscache_n_acquires_null;
49282 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
49283 +extern atomic_unchecked_t fscache_n_acquires_ok;
49284 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
49285 +extern atomic_unchecked_t fscache_n_acquires_oom;
49286
49287 -extern atomic_t fscache_n_updates;
49288 -extern atomic_t fscache_n_updates_null;
49289 -extern atomic_t fscache_n_updates_run;
49290 +extern atomic_unchecked_t fscache_n_updates;
49291 +extern atomic_unchecked_t fscache_n_updates_null;
49292 +extern atomic_unchecked_t fscache_n_updates_run;
49293
49294 -extern atomic_t fscache_n_relinquishes;
49295 -extern atomic_t fscache_n_relinquishes_null;
49296 -extern atomic_t fscache_n_relinquishes_waitcrt;
49297 -extern atomic_t fscache_n_relinquishes_retire;
49298 +extern atomic_unchecked_t fscache_n_relinquishes;
49299 +extern atomic_unchecked_t fscache_n_relinquishes_null;
49300 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49301 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
49302
49303 -extern atomic_t fscache_n_cookie_index;
49304 -extern atomic_t fscache_n_cookie_data;
49305 -extern atomic_t fscache_n_cookie_special;
49306 +extern atomic_unchecked_t fscache_n_cookie_index;
49307 +extern atomic_unchecked_t fscache_n_cookie_data;
49308 +extern atomic_unchecked_t fscache_n_cookie_special;
49309
49310 -extern atomic_t fscache_n_object_alloc;
49311 -extern atomic_t fscache_n_object_no_alloc;
49312 -extern atomic_t fscache_n_object_lookups;
49313 -extern atomic_t fscache_n_object_lookups_negative;
49314 -extern atomic_t fscache_n_object_lookups_positive;
49315 -extern atomic_t fscache_n_object_lookups_timed_out;
49316 -extern atomic_t fscache_n_object_created;
49317 -extern atomic_t fscache_n_object_avail;
49318 -extern atomic_t fscache_n_object_dead;
49319 +extern atomic_unchecked_t fscache_n_object_alloc;
49320 +extern atomic_unchecked_t fscache_n_object_no_alloc;
49321 +extern atomic_unchecked_t fscache_n_object_lookups;
49322 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
49323 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
49324 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
49325 +extern atomic_unchecked_t fscache_n_object_created;
49326 +extern atomic_unchecked_t fscache_n_object_avail;
49327 +extern atomic_unchecked_t fscache_n_object_dead;
49328
49329 -extern atomic_t fscache_n_checkaux_none;
49330 -extern atomic_t fscache_n_checkaux_okay;
49331 -extern atomic_t fscache_n_checkaux_update;
49332 -extern atomic_t fscache_n_checkaux_obsolete;
49333 +extern atomic_unchecked_t fscache_n_checkaux_none;
49334 +extern atomic_unchecked_t fscache_n_checkaux_okay;
49335 +extern atomic_unchecked_t fscache_n_checkaux_update;
49336 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
49337
49338 extern atomic_t fscache_n_cop_alloc_object;
49339 extern atomic_t fscache_n_cop_lookup_object;
49340 @@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t *stat)
49341 atomic_inc(stat);
49342 }
49343
49344 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
49345 +{
49346 + atomic_inc_unchecked(stat);
49347 +}
49348 +
49349 static inline void fscache_stat_d(atomic_t *stat)
49350 {
49351 atomic_dec(stat);
49352 @@ -259,6 +264,7 @@ extern const struct file_operations fscache_stats_fops;
49353
49354 #define __fscache_stat(stat) (NULL)
49355 #define fscache_stat(stat) do {} while (0)
49356 +#define fscache_stat_unchecked(stat) do {} while (0)
49357 #define fscache_stat_d(stat) do {} while (0)
49358 #endif
49359
49360 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
49361 index e513ac5..e888d34 100644
49362 --- a/fs/fscache/object.c
49363 +++ b/fs/fscache/object.c
49364 @@ -144,7 +144,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49365 /* update the object metadata on disk */
49366 case FSCACHE_OBJECT_UPDATING:
49367 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
49368 - fscache_stat(&fscache_n_updates_run);
49369 + fscache_stat_unchecked(&fscache_n_updates_run);
49370 fscache_stat(&fscache_n_cop_update_object);
49371 object->cache->ops->update_object(object);
49372 fscache_stat_d(&fscache_n_cop_update_object);
49373 @@ -233,7 +233,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49374 spin_lock(&object->lock);
49375 object->state = FSCACHE_OBJECT_DEAD;
49376 spin_unlock(&object->lock);
49377 - fscache_stat(&fscache_n_object_dead);
49378 + fscache_stat_unchecked(&fscache_n_object_dead);
49379 goto terminal_transit;
49380
49381 /* handle the parent cache of this object being withdrawn from
49382 @@ -248,7 +248,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49383 spin_lock(&object->lock);
49384 object->state = FSCACHE_OBJECT_DEAD;
49385 spin_unlock(&object->lock);
49386 - fscache_stat(&fscache_n_object_dead);
49387 + fscache_stat_unchecked(&fscache_n_object_dead);
49388 goto terminal_transit;
49389
49390 /* complain about the object being woken up once it is
49391 @@ -492,7 +492,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49392 parent->cookie->def->name, cookie->def->name,
49393 object->cache->tag->name);
49394
49395 - fscache_stat(&fscache_n_object_lookups);
49396 + fscache_stat_unchecked(&fscache_n_object_lookups);
49397 fscache_stat(&fscache_n_cop_lookup_object);
49398 ret = object->cache->ops->lookup_object(object);
49399 fscache_stat_d(&fscache_n_cop_lookup_object);
49400 @@ -503,7 +503,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49401 if (ret == -ETIMEDOUT) {
49402 /* probably stuck behind another object, so move this one to
49403 * the back of the queue */
49404 - fscache_stat(&fscache_n_object_lookups_timed_out);
49405 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49406 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49407 }
49408
49409 @@ -526,7 +526,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49410
49411 spin_lock(&object->lock);
49412 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49413 - fscache_stat(&fscache_n_object_lookups_negative);
49414 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49415
49416 /* transit here to allow write requests to begin stacking up
49417 * and read requests to begin returning ENODATA */
49418 @@ -572,7 +572,7 @@ void fscache_obtained_object(struct fscache_object *object)
49419 * result, in which case there may be data available */
49420 spin_lock(&object->lock);
49421 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49422 - fscache_stat(&fscache_n_object_lookups_positive);
49423 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49424
49425 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49426
49427 @@ -586,7 +586,7 @@ void fscache_obtained_object(struct fscache_object *object)
49428 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49429 } else {
49430 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49431 - fscache_stat(&fscache_n_object_created);
49432 + fscache_stat_unchecked(&fscache_n_object_created);
49433
49434 object->state = FSCACHE_OBJECT_AVAILABLE;
49435 spin_unlock(&object->lock);
49436 @@ -633,7 +633,7 @@ static void fscache_object_available(struct fscache_object *object)
49437 fscache_enqueue_dependents(object);
49438
49439 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49440 - fscache_stat(&fscache_n_object_avail);
49441 + fscache_stat_unchecked(&fscache_n_object_avail);
49442
49443 _leave("");
49444 }
49445 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49446 enum fscache_checkaux result;
49447
49448 if (!object->cookie->def->check_aux) {
49449 - fscache_stat(&fscache_n_checkaux_none);
49450 + fscache_stat_unchecked(&fscache_n_checkaux_none);
49451 return FSCACHE_CHECKAUX_OKAY;
49452 }
49453
49454 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49455 switch (result) {
49456 /* entry okay as is */
49457 case FSCACHE_CHECKAUX_OKAY:
49458 - fscache_stat(&fscache_n_checkaux_okay);
49459 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
49460 break;
49461
49462 /* entry requires update */
49463 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49464 - fscache_stat(&fscache_n_checkaux_update);
49465 + fscache_stat_unchecked(&fscache_n_checkaux_update);
49466 break;
49467
49468 /* entry requires deletion */
49469 case FSCACHE_CHECKAUX_OBSOLETE:
49470 - fscache_stat(&fscache_n_checkaux_obsolete);
49471 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49472 break;
49473
49474 default:
49475 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49476 index 313e79a..775240f 100644
49477 --- a/fs/fscache/operation.c
49478 +++ b/fs/fscache/operation.c
49479 @@ -16,7 +16,7 @@
49480 #include <linux/seq_file.h>
49481 #include "internal.h"
49482
49483 -atomic_t fscache_op_debug_id;
49484 +atomic_unchecked_t fscache_op_debug_id;
49485 EXPORT_SYMBOL(fscache_op_debug_id);
49486
49487 /**
49488 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49489 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
49490 ASSERTCMP(atomic_read(&op->usage), >, 0);
49491
49492 - fscache_stat(&fscache_n_op_enqueue);
49493 + fscache_stat_unchecked(&fscache_n_op_enqueue);
49494 switch (op->flags & FSCACHE_OP_TYPE) {
49495 case FSCACHE_OP_FAST:
49496 _debug("queue fast");
49497 @@ -76,7 +76,7 @@ static void fscache_run_op(struct fscache_object *object,
49498 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49499 if (op->processor)
49500 fscache_enqueue_operation(op);
49501 - fscache_stat(&fscache_n_op_run);
49502 + fscache_stat_unchecked(&fscache_n_op_run);
49503 }
49504
49505 /*
49506 @@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49507 if (object->n_ops > 0) {
49508 atomic_inc(&op->usage);
49509 list_add_tail(&op->pend_link, &object->pending_ops);
49510 - fscache_stat(&fscache_n_op_pend);
49511 + fscache_stat_unchecked(&fscache_n_op_pend);
49512 } else if (!list_empty(&object->pending_ops)) {
49513 atomic_inc(&op->usage);
49514 list_add_tail(&op->pend_link, &object->pending_ops);
49515 - fscache_stat(&fscache_n_op_pend);
49516 + fscache_stat_unchecked(&fscache_n_op_pend);
49517 fscache_start_operations(object);
49518 } else {
49519 ASSERTCMP(object->n_in_progress, ==, 0);
49520 @@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49521 object->n_exclusive++; /* reads and writes must wait */
49522 atomic_inc(&op->usage);
49523 list_add_tail(&op->pend_link, &object->pending_ops);
49524 - fscache_stat(&fscache_n_op_pend);
49525 + fscache_stat_unchecked(&fscache_n_op_pend);
49526 ret = 0;
49527 } else {
49528 /* not allowed to submit ops in any other state */
49529 @@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_object *object,
49530 if (object->n_exclusive > 0) {
49531 atomic_inc(&op->usage);
49532 list_add_tail(&op->pend_link, &object->pending_ops);
49533 - fscache_stat(&fscache_n_op_pend);
49534 + fscache_stat_unchecked(&fscache_n_op_pend);
49535 } else if (!list_empty(&object->pending_ops)) {
49536 atomic_inc(&op->usage);
49537 list_add_tail(&op->pend_link, &object->pending_ops);
49538 - fscache_stat(&fscache_n_op_pend);
49539 + fscache_stat_unchecked(&fscache_n_op_pend);
49540 fscache_start_operations(object);
49541 } else {
49542 ASSERTCMP(object->n_exclusive, ==, 0);
49543 @@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_object *object,
49544 object->n_ops++;
49545 atomic_inc(&op->usage);
49546 list_add_tail(&op->pend_link, &object->pending_ops);
49547 - fscache_stat(&fscache_n_op_pend);
49548 + fscache_stat_unchecked(&fscache_n_op_pend);
49549 ret = 0;
49550 } else if (object->state == FSCACHE_OBJECT_DYING ||
49551 object->state == FSCACHE_OBJECT_LC_DYING ||
49552 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49553 - fscache_stat(&fscache_n_op_rejected);
49554 + fscache_stat_unchecked(&fscache_n_op_rejected);
49555 ret = -ENOBUFS;
49556 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49557 fscache_report_unexpected_submission(object, op, ostate);
49558 @@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_operation *op)
49559
49560 ret = -EBUSY;
49561 if (!list_empty(&op->pend_link)) {
49562 - fscache_stat(&fscache_n_op_cancelled);
49563 + fscache_stat_unchecked(&fscache_n_op_cancelled);
49564 list_del_init(&op->pend_link);
49565 object->n_ops--;
49566 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
49567 @@ -344,7 +344,7 @@ void fscache_put_operation(struct fscache_operation *op)
49568 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
49569 BUG();
49570
49571 - fscache_stat(&fscache_n_op_release);
49572 + fscache_stat_unchecked(&fscache_n_op_release);
49573
49574 if (op->release) {
49575 op->release(op);
49576 @@ -361,7 +361,7 @@ void fscache_put_operation(struct fscache_operation *op)
49577 * lock, and defer it otherwise */
49578 if (!spin_trylock(&object->lock)) {
49579 _debug("defer put");
49580 - fscache_stat(&fscache_n_op_deferred_release);
49581 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
49582
49583 cache = object->cache;
49584 spin_lock(&cache->op_gc_list_lock);
49585 @@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_struct *work)
49586
49587 _debug("GC DEFERRED REL OBJ%x OP%x",
49588 object->debug_id, op->debug_id);
49589 - fscache_stat(&fscache_n_op_gc);
49590 + fscache_stat_unchecked(&fscache_n_op_gc);
49591
49592 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49593
49594 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49595 index c598ea4..6aac13e 100644
49596 --- a/fs/fscache/page.c
49597 +++ b/fs/fscache/page.c
49598 @@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49599 val = radix_tree_lookup(&cookie->stores, page->index);
49600 if (!val) {
49601 rcu_read_unlock();
49602 - fscache_stat(&fscache_n_store_vmscan_not_storing);
49603 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49604 __fscache_uncache_page(cookie, page);
49605 return true;
49606 }
49607 @@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49608 spin_unlock(&cookie->stores_lock);
49609
49610 if (xpage) {
49611 - fscache_stat(&fscache_n_store_vmscan_cancelled);
49612 - fscache_stat(&fscache_n_store_radix_deletes);
49613 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49614 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49615 ASSERTCMP(xpage, ==, page);
49616 } else {
49617 - fscache_stat(&fscache_n_store_vmscan_gone);
49618 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49619 }
49620
49621 wake_up_bit(&cookie->flags, 0);
49622 @@ -106,7 +106,7 @@ page_busy:
49623 /* we might want to wait here, but that could deadlock the allocator as
49624 * the slow-work threads writing to the cache may all end up sleeping
49625 * on memory allocation */
49626 - fscache_stat(&fscache_n_store_vmscan_busy);
49627 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49628 return false;
49629 }
49630 EXPORT_SYMBOL(__fscache_maybe_release_page);
49631 @@ -130,7 +130,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49632 FSCACHE_COOKIE_STORING_TAG);
49633 if (!radix_tree_tag_get(&cookie->stores, page->index,
49634 FSCACHE_COOKIE_PENDING_TAG)) {
49635 - fscache_stat(&fscache_n_store_radix_deletes);
49636 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49637 xpage = radix_tree_delete(&cookie->stores, page->index);
49638 }
49639 spin_unlock(&cookie->stores_lock);
49640 @@ -151,7 +151,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49641
49642 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49643
49644 - fscache_stat(&fscache_n_attr_changed_calls);
49645 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49646
49647 if (fscache_object_is_active(object)) {
49648 fscache_set_op_state(op, "CallFS");
49649 @@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49650
49651 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49652
49653 - fscache_stat(&fscache_n_attr_changed);
49654 + fscache_stat_unchecked(&fscache_n_attr_changed);
49655
49656 op = kzalloc(sizeof(*op), GFP_KERNEL);
49657 if (!op) {
49658 - fscache_stat(&fscache_n_attr_changed_nomem);
49659 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49660 _leave(" = -ENOMEM");
49661 return -ENOMEM;
49662 }
49663 @@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49664 if (fscache_submit_exclusive_op(object, op) < 0)
49665 goto nobufs;
49666 spin_unlock(&cookie->lock);
49667 - fscache_stat(&fscache_n_attr_changed_ok);
49668 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49669 fscache_put_operation(op);
49670 _leave(" = 0");
49671 return 0;
49672 @@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49673 nobufs:
49674 spin_unlock(&cookie->lock);
49675 kfree(op);
49676 - fscache_stat(&fscache_n_attr_changed_nobufs);
49677 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49678 _leave(" = %d", -ENOBUFS);
49679 return -ENOBUFS;
49680 }
49681 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49682 /* allocate a retrieval operation and attempt to submit it */
49683 op = kzalloc(sizeof(*op), GFP_NOIO);
49684 if (!op) {
49685 - fscache_stat(&fscache_n_retrievals_nomem);
49686 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49687 return NULL;
49688 }
49689
49690 @@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49691 return 0;
49692 }
49693
49694 - fscache_stat(&fscache_n_retrievals_wait);
49695 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
49696
49697 jif = jiffies;
49698 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49699 fscache_wait_bit_interruptible,
49700 TASK_INTERRUPTIBLE) != 0) {
49701 - fscache_stat(&fscache_n_retrievals_intr);
49702 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49703 _leave(" = -ERESTARTSYS");
49704 return -ERESTARTSYS;
49705 }
49706 @@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49707 */
49708 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49709 struct fscache_retrieval *op,
49710 - atomic_t *stat_op_waits,
49711 - atomic_t *stat_object_dead)
49712 + atomic_unchecked_t *stat_op_waits,
49713 + atomic_unchecked_t *stat_object_dead)
49714 {
49715 int ret;
49716
49717 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49718 goto check_if_dead;
49719
49720 _debug(">>> WT");
49721 - fscache_stat(stat_op_waits);
49722 + fscache_stat_unchecked(stat_op_waits);
49723 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49724 fscache_wait_bit_interruptible,
49725 TASK_INTERRUPTIBLE) < 0) {
49726 @@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49727
49728 check_if_dead:
49729 if (unlikely(fscache_object_is_dead(object))) {
49730 - fscache_stat(stat_object_dead);
49731 + fscache_stat_unchecked(stat_object_dead);
49732 return -ENOBUFS;
49733 }
49734 return 0;
49735 @@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49736
49737 _enter("%p,%p,,,", cookie, page);
49738
49739 - fscache_stat(&fscache_n_retrievals);
49740 + fscache_stat_unchecked(&fscache_n_retrievals);
49741
49742 if (hlist_empty(&cookie->backing_objects))
49743 goto nobufs;
49744 @@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49745 goto nobufs_unlock;
49746 spin_unlock(&cookie->lock);
49747
49748 - fscache_stat(&fscache_n_retrieval_ops);
49749 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
49750
49751 /* pin the netfs read context in case we need to do the actual netfs
49752 * read because we've encountered a cache read failure */
49753 @@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49754
49755 error:
49756 if (ret == -ENOMEM)
49757 - fscache_stat(&fscache_n_retrievals_nomem);
49758 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49759 else if (ret == -ERESTARTSYS)
49760 - fscache_stat(&fscache_n_retrievals_intr);
49761 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49762 else if (ret == -ENODATA)
49763 - fscache_stat(&fscache_n_retrievals_nodata);
49764 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49765 else if (ret < 0)
49766 - fscache_stat(&fscache_n_retrievals_nobufs);
49767 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49768 else
49769 - fscache_stat(&fscache_n_retrievals_ok);
49770 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
49771
49772 fscache_put_retrieval(op);
49773 _leave(" = %d", ret);
49774 @@ -453,7 +453,7 @@ nobufs_unlock:
49775 spin_unlock(&cookie->lock);
49776 kfree(op);
49777 nobufs:
49778 - fscache_stat(&fscache_n_retrievals_nobufs);
49779 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49780 _leave(" = -ENOBUFS");
49781 return -ENOBUFS;
49782 }
49783 @@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49784
49785 _enter("%p,,%d,,,", cookie, *nr_pages);
49786
49787 - fscache_stat(&fscache_n_retrievals);
49788 + fscache_stat_unchecked(&fscache_n_retrievals);
49789
49790 if (hlist_empty(&cookie->backing_objects))
49791 goto nobufs;
49792 @@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49793 goto nobufs_unlock;
49794 spin_unlock(&cookie->lock);
49795
49796 - fscache_stat(&fscache_n_retrieval_ops);
49797 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
49798
49799 /* pin the netfs read context in case we need to do the actual netfs
49800 * read because we've encountered a cache read failure */
49801 @@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49802
49803 error:
49804 if (ret == -ENOMEM)
49805 - fscache_stat(&fscache_n_retrievals_nomem);
49806 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49807 else if (ret == -ERESTARTSYS)
49808 - fscache_stat(&fscache_n_retrievals_intr);
49809 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49810 else if (ret == -ENODATA)
49811 - fscache_stat(&fscache_n_retrievals_nodata);
49812 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49813 else if (ret < 0)
49814 - fscache_stat(&fscache_n_retrievals_nobufs);
49815 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49816 else
49817 - fscache_stat(&fscache_n_retrievals_ok);
49818 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
49819
49820 fscache_put_retrieval(op);
49821 _leave(" = %d", ret);
49822 @@ -570,7 +570,7 @@ nobufs_unlock:
49823 spin_unlock(&cookie->lock);
49824 kfree(op);
49825 nobufs:
49826 - fscache_stat(&fscache_n_retrievals_nobufs);
49827 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49828 _leave(" = -ENOBUFS");
49829 return -ENOBUFS;
49830 }
49831 @@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49832
49833 _enter("%p,%p,,,", cookie, page);
49834
49835 - fscache_stat(&fscache_n_allocs);
49836 + fscache_stat_unchecked(&fscache_n_allocs);
49837
49838 if (hlist_empty(&cookie->backing_objects))
49839 goto nobufs;
49840 @@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49841 goto nobufs_unlock;
49842 spin_unlock(&cookie->lock);
49843
49844 - fscache_stat(&fscache_n_alloc_ops);
49845 + fscache_stat_unchecked(&fscache_n_alloc_ops);
49846
49847 ret = fscache_wait_for_retrieval_activation(
49848 object, op,
49849 @@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49850
49851 error:
49852 if (ret == -ERESTARTSYS)
49853 - fscache_stat(&fscache_n_allocs_intr);
49854 + fscache_stat_unchecked(&fscache_n_allocs_intr);
49855 else if (ret < 0)
49856 - fscache_stat(&fscache_n_allocs_nobufs);
49857 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49858 else
49859 - fscache_stat(&fscache_n_allocs_ok);
49860 + fscache_stat_unchecked(&fscache_n_allocs_ok);
49861
49862 fscache_put_retrieval(op);
49863 _leave(" = %d", ret);
49864 @@ -651,7 +651,7 @@ nobufs_unlock:
49865 spin_unlock(&cookie->lock);
49866 kfree(op);
49867 nobufs:
49868 - fscache_stat(&fscache_n_allocs_nobufs);
49869 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49870 _leave(" = -ENOBUFS");
49871 return -ENOBUFS;
49872 }
49873 @@ -694,7 +694,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49874
49875 spin_lock(&cookie->stores_lock);
49876
49877 - fscache_stat(&fscache_n_store_calls);
49878 + fscache_stat_unchecked(&fscache_n_store_calls);
49879
49880 /* find a page to store */
49881 page = NULL;
49882 @@ -705,7 +705,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49883 page = results[0];
49884 _debug("gang %d [%lx]", n, page->index);
49885 if (page->index > op->store_limit) {
49886 - fscache_stat(&fscache_n_store_pages_over_limit);
49887 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49888 goto superseded;
49889 }
49890
49891 @@ -721,7 +721,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49892
49893 if (page) {
49894 fscache_set_op_state(&op->op, "Store");
49895 - fscache_stat(&fscache_n_store_pages);
49896 + fscache_stat_unchecked(&fscache_n_store_pages);
49897 fscache_stat(&fscache_n_cop_write_page);
49898 ret = object->cache->ops->write_page(op, page);
49899 fscache_stat_d(&fscache_n_cop_write_page);
49900 @@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49901 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49902 ASSERT(PageFsCache(page));
49903
49904 - fscache_stat(&fscache_n_stores);
49905 + fscache_stat_unchecked(&fscache_n_stores);
49906
49907 op = kzalloc(sizeof(*op), GFP_NOIO);
49908 if (!op)
49909 @@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49910 spin_unlock(&cookie->stores_lock);
49911 spin_unlock(&object->lock);
49912
49913 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49914 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49915 op->store_limit = object->store_limit;
49916
49917 if (fscache_submit_op(object, &op->op) < 0)
49918 @@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49919
49920 spin_unlock(&cookie->lock);
49921 radix_tree_preload_end();
49922 - fscache_stat(&fscache_n_store_ops);
49923 - fscache_stat(&fscache_n_stores_ok);
49924 + fscache_stat_unchecked(&fscache_n_store_ops);
49925 + fscache_stat_unchecked(&fscache_n_stores_ok);
49926
49927 /* the slow work queue now carries its own ref on the object */
49928 fscache_put_operation(&op->op);
49929 @@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49930 return 0;
49931
49932 already_queued:
49933 - fscache_stat(&fscache_n_stores_again);
49934 + fscache_stat_unchecked(&fscache_n_stores_again);
49935 already_pending:
49936 spin_unlock(&cookie->stores_lock);
49937 spin_unlock(&object->lock);
49938 spin_unlock(&cookie->lock);
49939 radix_tree_preload_end();
49940 kfree(op);
49941 - fscache_stat(&fscache_n_stores_ok);
49942 + fscache_stat_unchecked(&fscache_n_stores_ok);
49943 _leave(" = 0");
49944 return 0;
49945
49946 @@ -886,14 +886,14 @@ nobufs:
49947 spin_unlock(&cookie->lock);
49948 radix_tree_preload_end();
49949 kfree(op);
49950 - fscache_stat(&fscache_n_stores_nobufs);
49951 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
49952 _leave(" = -ENOBUFS");
49953 return -ENOBUFS;
49954
49955 nomem_free:
49956 kfree(op);
49957 nomem:
49958 - fscache_stat(&fscache_n_stores_oom);
49959 + fscache_stat_unchecked(&fscache_n_stores_oom);
49960 _leave(" = -ENOMEM");
49961 return -ENOMEM;
49962 }
49963 @@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49964 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49965 ASSERTCMP(page, !=, NULL);
49966
49967 - fscache_stat(&fscache_n_uncaches);
49968 + fscache_stat_unchecked(&fscache_n_uncaches);
49969
49970 /* cache withdrawal may beat us to it */
49971 if (!PageFsCache(page))
49972 @@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
49973 unsigned long loop;
49974
49975 #ifdef CONFIG_FSCACHE_STATS
49976 - atomic_add(pagevec->nr, &fscache_n_marks);
49977 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
49978 #endif
49979
49980 for (loop = 0; loop < pagevec->nr; loop++) {
49981 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49982 index 46435f3..8cddf18 100644
49983 --- a/fs/fscache/stats.c
49984 +++ b/fs/fscache/stats.c
49985 @@ -18,95 +18,95 @@
49986 /*
49987 * operation counters
49988 */
49989 -atomic_t fscache_n_op_pend;
49990 -atomic_t fscache_n_op_run;
49991 -atomic_t fscache_n_op_enqueue;
49992 -atomic_t fscache_n_op_requeue;
49993 -atomic_t fscache_n_op_deferred_release;
49994 -atomic_t fscache_n_op_release;
49995 -atomic_t fscache_n_op_gc;
49996 -atomic_t fscache_n_op_cancelled;
49997 -atomic_t fscache_n_op_rejected;
49998 +atomic_unchecked_t fscache_n_op_pend;
49999 +atomic_unchecked_t fscache_n_op_run;
50000 +atomic_unchecked_t fscache_n_op_enqueue;
50001 +atomic_unchecked_t fscache_n_op_requeue;
50002 +atomic_unchecked_t fscache_n_op_deferred_release;
50003 +atomic_unchecked_t fscache_n_op_release;
50004 +atomic_unchecked_t fscache_n_op_gc;
50005 +atomic_unchecked_t fscache_n_op_cancelled;
50006 +atomic_unchecked_t fscache_n_op_rejected;
50007
50008 -atomic_t fscache_n_attr_changed;
50009 -atomic_t fscache_n_attr_changed_ok;
50010 -atomic_t fscache_n_attr_changed_nobufs;
50011 -atomic_t fscache_n_attr_changed_nomem;
50012 -atomic_t fscache_n_attr_changed_calls;
50013 +atomic_unchecked_t fscache_n_attr_changed;
50014 +atomic_unchecked_t fscache_n_attr_changed_ok;
50015 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
50016 +atomic_unchecked_t fscache_n_attr_changed_nomem;
50017 +atomic_unchecked_t fscache_n_attr_changed_calls;
50018
50019 -atomic_t fscache_n_allocs;
50020 -atomic_t fscache_n_allocs_ok;
50021 -atomic_t fscache_n_allocs_wait;
50022 -atomic_t fscache_n_allocs_nobufs;
50023 -atomic_t fscache_n_allocs_intr;
50024 -atomic_t fscache_n_allocs_object_dead;
50025 -atomic_t fscache_n_alloc_ops;
50026 -atomic_t fscache_n_alloc_op_waits;
50027 +atomic_unchecked_t fscache_n_allocs;
50028 +atomic_unchecked_t fscache_n_allocs_ok;
50029 +atomic_unchecked_t fscache_n_allocs_wait;
50030 +atomic_unchecked_t fscache_n_allocs_nobufs;
50031 +atomic_unchecked_t fscache_n_allocs_intr;
50032 +atomic_unchecked_t fscache_n_allocs_object_dead;
50033 +atomic_unchecked_t fscache_n_alloc_ops;
50034 +atomic_unchecked_t fscache_n_alloc_op_waits;
50035
50036 -atomic_t fscache_n_retrievals;
50037 -atomic_t fscache_n_retrievals_ok;
50038 -atomic_t fscache_n_retrievals_wait;
50039 -atomic_t fscache_n_retrievals_nodata;
50040 -atomic_t fscache_n_retrievals_nobufs;
50041 -atomic_t fscache_n_retrievals_intr;
50042 -atomic_t fscache_n_retrievals_nomem;
50043 -atomic_t fscache_n_retrievals_object_dead;
50044 -atomic_t fscache_n_retrieval_ops;
50045 -atomic_t fscache_n_retrieval_op_waits;
50046 +atomic_unchecked_t fscache_n_retrievals;
50047 +atomic_unchecked_t fscache_n_retrievals_ok;
50048 +atomic_unchecked_t fscache_n_retrievals_wait;
50049 +atomic_unchecked_t fscache_n_retrievals_nodata;
50050 +atomic_unchecked_t fscache_n_retrievals_nobufs;
50051 +atomic_unchecked_t fscache_n_retrievals_intr;
50052 +atomic_unchecked_t fscache_n_retrievals_nomem;
50053 +atomic_unchecked_t fscache_n_retrievals_object_dead;
50054 +atomic_unchecked_t fscache_n_retrieval_ops;
50055 +atomic_unchecked_t fscache_n_retrieval_op_waits;
50056
50057 -atomic_t fscache_n_stores;
50058 -atomic_t fscache_n_stores_ok;
50059 -atomic_t fscache_n_stores_again;
50060 -atomic_t fscache_n_stores_nobufs;
50061 -atomic_t fscache_n_stores_oom;
50062 -atomic_t fscache_n_store_ops;
50063 -atomic_t fscache_n_store_calls;
50064 -atomic_t fscache_n_store_pages;
50065 -atomic_t fscache_n_store_radix_deletes;
50066 -atomic_t fscache_n_store_pages_over_limit;
50067 +atomic_unchecked_t fscache_n_stores;
50068 +atomic_unchecked_t fscache_n_stores_ok;
50069 +atomic_unchecked_t fscache_n_stores_again;
50070 +atomic_unchecked_t fscache_n_stores_nobufs;
50071 +atomic_unchecked_t fscache_n_stores_oom;
50072 +atomic_unchecked_t fscache_n_store_ops;
50073 +atomic_unchecked_t fscache_n_store_calls;
50074 +atomic_unchecked_t fscache_n_store_pages;
50075 +atomic_unchecked_t fscache_n_store_radix_deletes;
50076 +atomic_unchecked_t fscache_n_store_pages_over_limit;
50077
50078 -atomic_t fscache_n_store_vmscan_not_storing;
50079 -atomic_t fscache_n_store_vmscan_gone;
50080 -atomic_t fscache_n_store_vmscan_busy;
50081 -atomic_t fscache_n_store_vmscan_cancelled;
50082 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50083 +atomic_unchecked_t fscache_n_store_vmscan_gone;
50084 +atomic_unchecked_t fscache_n_store_vmscan_busy;
50085 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50086
50087 -atomic_t fscache_n_marks;
50088 -atomic_t fscache_n_uncaches;
50089 +atomic_unchecked_t fscache_n_marks;
50090 +atomic_unchecked_t fscache_n_uncaches;
50091
50092 -atomic_t fscache_n_acquires;
50093 -atomic_t fscache_n_acquires_null;
50094 -atomic_t fscache_n_acquires_no_cache;
50095 -atomic_t fscache_n_acquires_ok;
50096 -atomic_t fscache_n_acquires_nobufs;
50097 -atomic_t fscache_n_acquires_oom;
50098 +atomic_unchecked_t fscache_n_acquires;
50099 +atomic_unchecked_t fscache_n_acquires_null;
50100 +atomic_unchecked_t fscache_n_acquires_no_cache;
50101 +atomic_unchecked_t fscache_n_acquires_ok;
50102 +atomic_unchecked_t fscache_n_acquires_nobufs;
50103 +atomic_unchecked_t fscache_n_acquires_oom;
50104
50105 -atomic_t fscache_n_updates;
50106 -atomic_t fscache_n_updates_null;
50107 -atomic_t fscache_n_updates_run;
50108 +atomic_unchecked_t fscache_n_updates;
50109 +atomic_unchecked_t fscache_n_updates_null;
50110 +atomic_unchecked_t fscache_n_updates_run;
50111
50112 -atomic_t fscache_n_relinquishes;
50113 -atomic_t fscache_n_relinquishes_null;
50114 -atomic_t fscache_n_relinquishes_waitcrt;
50115 -atomic_t fscache_n_relinquishes_retire;
50116 +atomic_unchecked_t fscache_n_relinquishes;
50117 +atomic_unchecked_t fscache_n_relinquishes_null;
50118 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50119 +atomic_unchecked_t fscache_n_relinquishes_retire;
50120
50121 -atomic_t fscache_n_cookie_index;
50122 -atomic_t fscache_n_cookie_data;
50123 -atomic_t fscache_n_cookie_special;
50124 +atomic_unchecked_t fscache_n_cookie_index;
50125 +atomic_unchecked_t fscache_n_cookie_data;
50126 +atomic_unchecked_t fscache_n_cookie_special;
50127
50128 -atomic_t fscache_n_object_alloc;
50129 -atomic_t fscache_n_object_no_alloc;
50130 -atomic_t fscache_n_object_lookups;
50131 -atomic_t fscache_n_object_lookups_negative;
50132 -atomic_t fscache_n_object_lookups_positive;
50133 -atomic_t fscache_n_object_lookups_timed_out;
50134 -atomic_t fscache_n_object_created;
50135 -atomic_t fscache_n_object_avail;
50136 -atomic_t fscache_n_object_dead;
50137 +atomic_unchecked_t fscache_n_object_alloc;
50138 +atomic_unchecked_t fscache_n_object_no_alloc;
50139 +atomic_unchecked_t fscache_n_object_lookups;
50140 +atomic_unchecked_t fscache_n_object_lookups_negative;
50141 +atomic_unchecked_t fscache_n_object_lookups_positive;
50142 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
50143 +atomic_unchecked_t fscache_n_object_created;
50144 +atomic_unchecked_t fscache_n_object_avail;
50145 +atomic_unchecked_t fscache_n_object_dead;
50146
50147 -atomic_t fscache_n_checkaux_none;
50148 -atomic_t fscache_n_checkaux_okay;
50149 -atomic_t fscache_n_checkaux_update;
50150 -atomic_t fscache_n_checkaux_obsolete;
50151 +atomic_unchecked_t fscache_n_checkaux_none;
50152 +atomic_unchecked_t fscache_n_checkaux_okay;
50153 +atomic_unchecked_t fscache_n_checkaux_update;
50154 +atomic_unchecked_t fscache_n_checkaux_obsolete;
50155
50156 atomic_t fscache_n_cop_alloc_object;
50157 atomic_t fscache_n_cop_lookup_object;
50158 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
50159 seq_puts(m, "FS-Cache statistics\n");
50160
50161 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
50162 - atomic_read(&fscache_n_cookie_index),
50163 - atomic_read(&fscache_n_cookie_data),
50164 - atomic_read(&fscache_n_cookie_special));
50165 + atomic_read_unchecked(&fscache_n_cookie_index),
50166 + atomic_read_unchecked(&fscache_n_cookie_data),
50167 + atomic_read_unchecked(&fscache_n_cookie_special));
50168
50169 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
50170 - atomic_read(&fscache_n_object_alloc),
50171 - atomic_read(&fscache_n_object_no_alloc),
50172 - atomic_read(&fscache_n_object_avail),
50173 - atomic_read(&fscache_n_object_dead));
50174 + atomic_read_unchecked(&fscache_n_object_alloc),
50175 + atomic_read_unchecked(&fscache_n_object_no_alloc),
50176 + atomic_read_unchecked(&fscache_n_object_avail),
50177 + atomic_read_unchecked(&fscache_n_object_dead));
50178 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
50179 - atomic_read(&fscache_n_checkaux_none),
50180 - atomic_read(&fscache_n_checkaux_okay),
50181 - atomic_read(&fscache_n_checkaux_update),
50182 - atomic_read(&fscache_n_checkaux_obsolete));
50183 + atomic_read_unchecked(&fscache_n_checkaux_none),
50184 + atomic_read_unchecked(&fscache_n_checkaux_okay),
50185 + atomic_read_unchecked(&fscache_n_checkaux_update),
50186 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
50187
50188 seq_printf(m, "Pages : mrk=%u unc=%u\n",
50189 - atomic_read(&fscache_n_marks),
50190 - atomic_read(&fscache_n_uncaches));
50191 + atomic_read_unchecked(&fscache_n_marks),
50192 + atomic_read_unchecked(&fscache_n_uncaches));
50193
50194 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
50195 " oom=%u\n",
50196 - atomic_read(&fscache_n_acquires),
50197 - atomic_read(&fscache_n_acquires_null),
50198 - atomic_read(&fscache_n_acquires_no_cache),
50199 - atomic_read(&fscache_n_acquires_ok),
50200 - atomic_read(&fscache_n_acquires_nobufs),
50201 - atomic_read(&fscache_n_acquires_oom));
50202 + atomic_read_unchecked(&fscache_n_acquires),
50203 + atomic_read_unchecked(&fscache_n_acquires_null),
50204 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
50205 + atomic_read_unchecked(&fscache_n_acquires_ok),
50206 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
50207 + atomic_read_unchecked(&fscache_n_acquires_oom));
50208
50209 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
50210 - atomic_read(&fscache_n_object_lookups),
50211 - atomic_read(&fscache_n_object_lookups_negative),
50212 - atomic_read(&fscache_n_object_lookups_positive),
50213 - atomic_read(&fscache_n_object_lookups_timed_out),
50214 - atomic_read(&fscache_n_object_created));
50215 + atomic_read_unchecked(&fscache_n_object_lookups),
50216 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
50217 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
50218 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
50219 + atomic_read_unchecked(&fscache_n_object_created));
50220
50221 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
50222 - atomic_read(&fscache_n_updates),
50223 - atomic_read(&fscache_n_updates_null),
50224 - atomic_read(&fscache_n_updates_run));
50225 + atomic_read_unchecked(&fscache_n_updates),
50226 + atomic_read_unchecked(&fscache_n_updates_null),
50227 + atomic_read_unchecked(&fscache_n_updates_run));
50228
50229 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
50230 - atomic_read(&fscache_n_relinquishes),
50231 - atomic_read(&fscache_n_relinquishes_null),
50232 - atomic_read(&fscache_n_relinquishes_waitcrt),
50233 - atomic_read(&fscache_n_relinquishes_retire));
50234 + atomic_read_unchecked(&fscache_n_relinquishes),
50235 + atomic_read_unchecked(&fscache_n_relinquishes_null),
50236 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
50237 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
50238
50239 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
50240 - atomic_read(&fscache_n_attr_changed),
50241 - atomic_read(&fscache_n_attr_changed_ok),
50242 - atomic_read(&fscache_n_attr_changed_nobufs),
50243 - atomic_read(&fscache_n_attr_changed_nomem),
50244 - atomic_read(&fscache_n_attr_changed_calls));
50245 + atomic_read_unchecked(&fscache_n_attr_changed),
50246 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
50247 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
50248 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
50249 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
50250
50251 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
50252 - atomic_read(&fscache_n_allocs),
50253 - atomic_read(&fscache_n_allocs_ok),
50254 - atomic_read(&fscache_n_allocs_wait),
50255 - atomic_read(&fscache_n_allocs_nobufs),
50256 - atomic_read(&fscache_n_allocs_intr));
50257 + atomic_read_unchecked(&fscache_n_allocs),
50258 + atomic_read_unchecked(&fscache_n_allocs_ok),
50259 + atomic_read_unchecked(&fscache_n_allocs_wait),
50260 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
50261 + atomic_read_unchecked(&fscache_n_allocs_intr));
50262 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
50263 - atomic_read(&fscache_n_alloc_ops),
50264 - atomic_read(&fscache_n_alloc_op_waits),
50265 - atomic_read(&fscache_n_allocs_object_dead));
50266 + atomic_read_unchecked(&fscache_n_alloc_ops),
50267 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
50268 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
50269
50270 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
50271 " int=%u oom=%u\n",
50272 - atomic_read(&fscache_n_retrievals),
50273 - atomic_read(&fscache_n_retrievals_ok),
50274 - atomic_read(&fscache_n_retrievals_wait),
50275 - atomic_read(&fscache_n_retrievals_nodata),
50276 - atomic_read(&fscache_n_retrievals_nobufs),
50277 - atomic_read(&fscache_n_retrievals_intr),
50278 - atomic_read(&fscache_n_retrievals_nomem));
50279 + atomic_read_unchecked(&fscache_n_retrievals),
50280 + atomic_read_unchecked(&fscache_n_retrievals_ok),
50281 + atomic_read_unchecked(&fscache_n_retrievals_wait),
50282 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
50283 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
50284 + atomic_read_unchecked(&fscache_n_retrievals_intr),
50285 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
50286 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
50287 - atomic_read(&fscache_n_retrieval_ops),
50288 - atomic_read(&fscache_n_retrieval_op_waits),
50289 - atomic_read(&fscache_n_retrievals_object_dead));
50290 + atomic_read_unchecked(&fscache_n_retrieval_ops),
50291 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
50292 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
50293
50294 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
50295 - atomic_read(&fscache_n_stores),
50296 - atomic_read(&fscache_n_stores_ok),
50297 - atomic_read(&fscache_n_stores_again),
50298 - atomic_read(&fscache_n_stores_nobufs),
50299 - atomic_read(&fscache_n_stores_oom));
50300 + atomic_read_unchecked(&fscache_n_stores),
50301 + atomic_read_unchecked(&fscache_n_stores_ok),
50302 + atomic_read_unchecked(&fscache_n_stores_again),
50303 + atomic_read_unchecked(&fscache_n_stores_nobufs),
50304 + atomic_read_unchecked(&fscache_n_stores_oom));
50305 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
50306 - atomic_read(&fscache_n_store_ops),
50307 - atomic_read(&fscache_n_store_calls),
50308 - atomic_read(&fscache_n_store_pages),
50309 - atomic_read(&fscache_n_store_radix_deletes),
50310 - atomic_read(&fscache_n_store_pages_over_limit));
50311 + atomic_read_unchecked(&fscache_n_store_ops),
50312 + atomic_read_unchecked(&fscache_n_store_calls),
50313 + atomic_read_unchecked(&fscache_n_store_pages),
50314 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
50315 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
50316
50317 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
50318 - atomic_read(&fscache_n_store_vmscan_not_storing),
50319 - atomic_read(&fscache_n_store_vmscan_gone),
50320 - atomic_read(&fscache_n_store_vmscan_busy),
50321 - atomic_read(&fscache_n_store_vmscan_cancelled));
50322 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
50323 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
50324 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
50325 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
50326
50327 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
50328 - atomic_read(&fscache_n_op_pend),
50329 - atomic_read(&fscache_n_op_run),
50330 - atomic_read(&fscache_n_op_enqueue),
50331 - atomic_read(&fscache_n_op_cancelled),
50332 - atomic_read(&fscache_n_op_rejected));
50333 + atomic_read_unchecked(&fscache_n_op_pend),
50334 + atomic_read_unchecked(&fscache_n_op_run),
50335 + atomic_read_unchecked(&fscache_n_op_enqueue),
50336 + atomic_read_unchecked(&fscache_n_op_cancelled),
50337 + atomic_read_unchecked(&fscache_n_op_rejected));
50338 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
50339 - atomic_read(&fscache_n_op_deferred_release),
50340 - atomic_read(&fscache_n_op_release),
50341 - atomic_read(&fscache_n_op_gc));
50342 + atomic_read_unchecked(&fscache_n_op_deferred_release),
50343 + atomic_read_unchecked(&fscache_n_op_release),
50344 + atomic_read_unchecked(&fscache_n_op_gc));
50345
50346 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
50347 atomic_read(&fscache_n_cop_alloc_object),
50348 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50349 index de792dc..448b532 100644
50350 --- a/fs/fuse/cuse.c
50351 +++ b/fs/fuse/cuse.c
50352 @@ -576,10 +576,12 @@ static int __init cuse_init(void)
50353 INIT_LIST_HEAD(&cuse_conntbl[i]);
50354
50355 /* inherit and extend fuse_dev_operations */
50356 - cuse_channel_fops = fuse_dev_operations;
50357 - cuse_channel_fops.owner = THIS_MODULE;
50358 - cuse_channel_fops.open = cuse_channel_open;
50359 - cuse_channel_fops.release = cuse_channel_release;
50360 + pax_open_kernel();
50361 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50362 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50363 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
50364 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
50365 + pax_close_kernel();
50366
50367 cuse_class = class_create(THIS_MODULE, "cuse");
50368 if (IS_ERR(cuse_class))
50369 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50370 index 1facb39..7f48557 100644
50371 --- a/fs/fuse/dev.c
50372 +++ b/fs/fuse/dev.c
50373 @@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50374 {
50375 struct fuse_notify_inval_entry_out outarg;
50376 int err = -EINVAL;
50377 - char buf[FUSE_NAME_MAX+1];
50378 + char *buf = NULL;
50379 struct qstr name;
50380
50381 if (size < sizeof(outarg))
50382 @@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50383 if (outarg.namelen > FUSE_NAME_MAX)
50384 goto err;
50385
50386 + err = -ENOMEM;
50387 + buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
50388 + if (!buf)
50389 + goto err;
50390 +
50391 err = -EINVAL;
50392 if (size != sizeof(outarg) + outarg.namelen + 1)
50393 goto err;
50394 @@ -914,17 +919,15 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50395
50396 down_read(&fc->killsb);
50397 err = -ENOENT;
50398 - if (!fc->sb)
50399 - goto err_unlock;
50400 -
50401 - err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50402 -
50403 -err_unlock:
50404 + if (fc->sb)
50405 + err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50406 up_read(&fc->killsb);
50407 + kfree(buf);
50408 return err;
50409
50410 err:
50411 fuse_copy_finish(cs);
50412 + kfree(buf);
50413 return err;
50414 }
50415
50416 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50417 index 4787ae6..73efff7 100644
50418 --- a/fs/fuse/dir.c
50419 +++ b/fs/fuse/dir.c
50420 @@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *dentry)
50421 return link;
50422 }
50423
50424 -static void free_link(char *link)
50425 +static void free_link(const char *link)
50426 {
50427 if (!IS_ERR(link))
50428 free_page((unsigned long) link);
50429 diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
50430 index 247436c..e650ccb 100644
50431 --- a/fs/gfs2/ops_inode.c
50432 +++ b/fs/gfs2/ops_inode.c
50433 @@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
50434 unsigned int x;
50435 int error;
50436
50437 + pax_track_stack();
50438 +
50439 if (ndentry->d_inode) {
50440 nip = GFS2_I(ndentry->d_inode);
50441 if (ip == nip)
50442 diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
50443 index 4463297..4fed53b 100644
50444 --- a/fs/gfs2/sys.c
50445 +++ b/fs/gfs2/sys.c
50446 @@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
50447 return a->store ? a->store(sdp, buf, len) : len;
50448 }
50449
50450 -static struct sysfs_ops gfs2_attr_ops = {
50451 +static const struct sysfs_ops gfs2_attr_ops = {
50452 .show = gfs2_attr_show,
50453 .store = gfs2_attr_store,
50454 };
50455 @@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
50456 return 0;
50457 }
50458
50459 -static struct kset_uevent_ops gfs2_uevent_ops = {
50460 +static const struct kset_uevent_ops gfs2_uevent_ops = {
50461 .uevent = gfs2_uevent,
50462 };
50463
50464 diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
50465 index f6874ac..7cd98a8 100644
50466 --- a/fs/hfsplus/catalog.c
50467 +++ b/fs/hfsplus/catalog.c
50468 @@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
50469 int err;
50470 u16 type;
50471
50472 + pax_track_stack();
50473 +
50474 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
50475 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
50476 if (err)
50477 @@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino
50478 int entry_size;
50479 int err;
50480
50481 + pax_track_stack();
50482 +
50483 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
50484 sb = dir->i_sb;
50485 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
50486 @@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
50487 int entry_size, type;
50488 int err = 0;
50489
50490 + pax_track_stack();
50491 +
50492 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
50493 dst_dir->i_ino, dst_name->name);
50494 sb = src_dir->i_sb;
50495 diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
50496 index 5f40236..dac3421 100644
50497 --- a/fs/hfsplus/dir.c
50498 +++ b/fs/hfsplus/dir.c
50499 @@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
50500 struct hfsplus_readdir_data *rd;
50501 u16 type;
50502
50503 + pax_track_stack();
50504 +
50505 if (filp->f_pos >= inode->i_size)
50506 return 0;
50507
50508 diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
50509 index 1bcf597..905a251 100644
50510 --- a/fs/hfsplus/inode.c
50511 +++ b/fs/hfsplus/inode.c
50512 @@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
50513 int res = 0;
50514 u16 type;
50515
50516 + pax_track_stack();
50517 +
50518 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
50519
50520 HFSPLUS_I(inode).dev = 0;
50521 @@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
50522 struct hfs_find_data fd;
50523 hfsplus_cat_entry entry;
50524
50525 + pax_track_stack();
50526 +
50527 if (HFSPLUS_IS_RSRC(inode))
50528 main_inode = HFSPLUS_I(inode).rsrc_inode;
50529
50530 diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
50531 index f457d2c..7ef4ad5 100644
50532 --- a/fs/hfsplus/ioctl.c
50533 +++ b/fs/hfsplus/ioctl.c
50534 @@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
50535 struct hfsplus_cat_file *file;
50536 int res;
50537
50538 + pax_track_stack();
50539 +
50540 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50541 return -EOPNOTSUPP;
50542
50543 @@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
50544 struct hfsplus_cat_file *file;
50545 ssize_t res = 0;
50546
50547 + pax_track_stack();
50548 +
50549 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50550 return -EOPNOTSUPP;
50551
50552 diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
50553 index 43022f3..7298079 100644
50554 --- a/fs/hfsplus/super.c
50555 +++ b/fs/hfsplus/super.c
50556 @@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
50557 struct nls_table *nls = NULL;
50558 int err = -EINVAL;
50559
50560 + pax_track_stack();
50561 +
50562 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
50563 if (!sbi)
50564 return -ENOMEM;
50565 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50566 index 87a1258..5694d91 100644
50567 --- a/fs/hugetlbfs/inode.c
50568 +++ b/fs/hugetlbfs/inode.c
50569 @@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50570 .kill_sb = kill_litter_super,
50571 };
50572
50573 -static struct vfsmount *hugetlbfs_vfsmount;
50574 +struct vfsmount *hugetlbfs_vfsmount;
50575
50576 static int can_do_hugetlb_shm(void)
50577 {
50578 diff --git a/fs/ioctl.c b/fs/ioctl.c
50579 index 6c75110..19d2c3c 100644
50580 --- a/fs/ioctl.c
50581 +++ b/fs/ioctl.c
50582 @@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
50583 u64 phys, u64 len, u32 flags)
50584 {
50585 struct fiemap_extent extent;
50586 - struct fiemap_extent *dest = fieinfo->fi_extents_start;
50587 + struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
50588
50589 /* only count the extents */
50590 if (fieinfo->fi_extents_max == 0) {
50591 @@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50592
50593 fieinfo.fi_flags = fiemap.fm_flags;
50594 fieinfo.fi_extents_max = fiemap.fm_extent_count;
50595 - fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
50596 + fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
50597
50598 if (fiemap.fm_extent_count != 0 &&
50599 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
50600 @@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50601 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
50602 fiemap.fm_flags = fieinfo.fi_flags;
50603 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
50604 - if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
50605 + if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
50606 error = -EFAULT;
50607
50608 return error;
50609 diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
50610 index b0435dd..81ee0be 100644
50611 --- a/fs/jbd/checkpoint.c
50612 +++ b/fs/jbd/checkpoint.c
50613 @@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal)
50614 tid_t this_tid;
50615 int result;
50616
50617 + pax_track_stack();
50618 +
50619 jbd_debug(1, "Start checkpoint\n");
50620
50621 /*
50622 diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
50623 index 546d153..736896c 100644
50624 --- a/fs/jffs2/compr_rtime.c
50625 +++ b/fs/jffs2/compr_rtime.c
50626 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
50627 int outpos = 0;
50628 int pos=0;
50629
50630 + pax_track_stack();
50631 +
50632 memset(positions,0,sizeof(positions));
50633
50634 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
50635 @@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
50636 int outpos = 0;
50637 int pos=0;
50638
50639 + pax_track_stack();
50640 +
50641 memset(positions,0,sizeof(positions));
50642
50643 while (outpos<destlen) {
50644 diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
50645 index 170d289..3254b98 100644
50646 --- a/fs/jffs2/compr_rubin.c
50647 +++ b/fs/jffs2/compr_rubin.c
50648 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
50649 int ret;
50650 uint32_t mysrclen, mydstlen;
50651
50652 + pax_track_stack();
50653 +
50654 mysrclen = *sourcelen;
50655 mydstlen = *dstlen - 8;
50656
50657 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50658 index b47679b..00d65d3 100644
50659 --- a/fs/jffs2/erase.c
50660 +++ b/fs/jffs2/erase.c
50661 @@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50662 struct jffs2_unknown_node marker = {
50663 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50664 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50665 - .totlen = cpu_to_je32(c->cleanmarker_size)
50666 + .totlen = cpu_to_je32(c->cleanmarker_size),
50667 + .hdr_crc = cpu_to_je32(0)
50668 };
50669
50670 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50671 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50672 index 5ef7bac..4fd1e3c 100644
50673 --- a/fs/jffs2/wbuf.c
50674 +++ b/fs/jffs2/wbuf.c
50675 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50676 {
50677 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50678 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50679 - .totlen = constant_cpu_to_je32(8)
50680 + .totlen = constant_cpu_to_je32(8),
50681 + .hdr_crc = constant_cpu_to_je32(0)
50682 };
50683
50684 /*
50685 diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
50686 index 082e844..52012a1 100644
50687 --- a/fs/jffs2/xattr.c
50688 +++ b/fs/jffs2/xattr.c
50689 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
50690
50691 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
50692
50693 + pax_track_stack();
50694 +
50695 /* Phase.1 : Merge same xref */
50696 for (i=0; i < XREF_TMPHASH_SIZE; i++)
50697 xref_tmphash[i] = NULL;
50698 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50699 index 2234c73..f6e6e6b 100644
50700 --- a/fs/jfs/super.c
50701 +++ b/fs/jfs/super.c
50702 @@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
50703
50704 jfs_inode_cachep =
50705 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50706 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50707 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50708 init_once);
50709 if (jfs_inode_cachep == NULL)
50710 return -ENOMEM;
50711 diff --git a/fs/libfs.c b/fs/libfs.c
50712 index ba36e93..3153fce 100644
50713 --- a/fs/libfs.c
50714 +++ b/fs/libfs.c
50715 @@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50716
50717 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50718 struct dentry *next;
50719 + char d_name[sizeof(next->d_iname)];
50720 + const unsigned char *name;
50721 +
50722 next = list_entry(p, struct dentry, d_u.d_child);
50723 if (d_unhashed(next) || !next->d_inode)
50724 continue;
50725
50726 spin_unlock(&dcache_lock);
50727 - if (filldir(dirent, next->d_name.name,
50728 + name = next->d_name.name;
50729 + if (name == next->d_iname) {
50730 + memcpy(d_name, name, next->d_name.len);
50731 + name = d_name;
50732 + }
50733 + if (filldir(dirent, name,
50734 next->d_name.len, filp->f_pos,
50735 next->d_inode->i_ino,
50736 dt_type(next->d_inode)) < 0)
50737 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50738 index c325a83..d15b07b 100644
50739 --- a/fs/lockd/clntproc.c
50740 +++ b/fs/lockd/clntproc.c
50741 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50742 /*
50743 * Cookie counter for NLM requests
50744 */
50745 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50746 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50747
50748 void nlmclnt_next_cookie(struct nlm_cookie *c)
50749 {
50750 - u32 cookie = atomic_inc_return(&nlm_cookie);
50751 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50752
50753 memcpy(c->data, &cookie, 4);
50754 c->len=4;
50755 @@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
50756 struct nlm_rqst reqst, *req;
50757 int status;
50758
50759 + pax_track_stack();
50760 +
50761 req = &reqst;
50762 memset(req, 0, sizeof(*req));
50763 locks_init_lock(&req->a_args.lock.fl);
50764 diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
50765 index 1a54ae1..6a16c27 100644
50766 --- a/fs/lockd/svc.c
50767 +++ b/fs/lockd/svc.c
50768 @@ -43,7 +43,7 @@
50769
50770 static struct svc_program nlmsvc_program;
50771
50772 -struct nlmsvc_binding * nlmsvc_ops;
50773 +const struct nlmsvc_binding * nlmsvc_ops;
50774 EXPORT_SYMBOL_GPL(nlmsvc_ops);
50775
50776 static DEFINE_MUTEX(nlmsvc_mutex);
50777 diff --git a/fs/locks.c b/fs/locks.c
50778 index a8794f2..4041e55 100644
50779 --- a/fs/locks.c
50780 +++ b/fs/locks.c
50781 @@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
50782
50783 static struct kmem_cache *filelock_cache __read_mostly;
50784
50785 +static void locks_init_lock_always(struct file_lock *fl)
50786 +{
50787 + fl->fl_next = NULL;
50788 + fl->fl_fasync = NULL;
50789 + fl->fl_owner = NULL;
50790 + fl->fl_pid = 0;
50791 + fl->fl_nspid = NULL;
50792 + fl->fl_file = NULL;
50793 + fl->fl_flags = 0;
50794 + fl->fl_type = 0;
50795 + fl->fl_start = fl->fl_end = 0;
50796 +}
50797 +
50798 /* Allocate an empty lock structure. */
50799 static struct file_lock *locks_alloc_lock(void)
50800 {
50801 - return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
50802 + struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
50803 +
50804 + if (fl)
50805 + locks_init_lock_always(fl);
50806 +
50807 + return fl;
50808 }
50809
50810 void locks_release_private(struct file_lock *fl)
50811 @@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *fl)
50812 INIT_LIST_HEAD(&fl->fl_link);
50813 INIT_LIST_HEAD(&fl->fl_block);
50814 init_waitqueue_head(&fl->fl_wait);
50815 - fl->fl_next = NULL;
50816 - fl->fl_fasync = NULL;
50817 - fl->fl_owner = NULL;
50818 - fl->fl_pid = 0;
50819 - fl->fl_nspid = NULL;
50820 - fl->fl_file = NULL;
50821 - fl->fl_flags = 0;
50822 - fl->fl_type = 0;
50823 - fl->fl_start = fl->fl_end = 0;
50824 fl->fl_ops = NULL;
50825 fl->fl_lmops = NULL;
50826 + locks_init_lock_always(fl);
50827 }
50828
50829 EXPORT_SYMBOL(locks_init_lock);
50830 @@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *filp)
50831 return;
50832
50833 if (filp->f_op && filp->f_op->flock) {
50834 - struct file_lock fl = {
50835 + struct file_lock flock = {
50836 .fl_pid = current->tgid,
50837 .fl_file = filp,
50838 .fl_flags = FL_FLOCK,
50839 .fl_type = F_UNLCK,
50840 .fl_end = OFFSET_MAX,
50841 };
50842 - filp->f_op->flock(filp, F_SETLKW, &fl);
50843 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
50844 - fl.fl_ops->fl_release_private(&fl);
50845 + filp->f_op->flock(filp, F_SETLKW, &flock);
50846 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
50847 + flock.fl_ops->fl_release_private(&flock);
50848 }
50849
50850 lock_kernel();
50851 diff --git a/fs/mbcache.c b/fs/mbcache.c
50852 index ec88ff3..b843a82 100644
50853 --- a/fs/mbcache.c
50854 +++ b/fs/mbcache.c
50855 @@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct mb_cache_op *cache_op,
50856 if (!cache)
50857 goto fail;
50858 cache->c_name = name;
50859 - cache->c_op.free = NULL;
50860 + *(void **)&cache->c_op.free = NULL;
50861 if (cache_op)
50862 - cache->c_op.free = cache_op->free;
50863 + *(void **)&cache->c_op.free = cache_op->free;
50864 atomic_set(&cache->c_entry_count, 0);
50865 cache->c_bucket_bits = bucket_bits;
50866 #ifdef MB_CACHE_INDEXES_COUNT
50867 diff --git a/fs/namei.c b/fs/namei.c
50868 index b0afbd4..8d065a1 100644
50869 --- a/fs/namei.c
50870 +++ b/fs/namei.c
50871 @@ -224,6 +224,14 @@ int generic_permission(struct inode *inode, int mask,
50872 return ret;
50873
50874 /*
50875 + * Searching includes executable on directories, else just read.
50876 + */
50877 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50878 + if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
50879 + if (capable(CAP_DAC_READ_SEARCH))
50880 + return 0;
50881 +
50882 + /*
50883 * Read/write DACs are always overridable.
50884 * Executable DACs are overridable if at least one exec bit is set.
50885 */
50886 @@ -231,14 +239,6 @@ int generic_permission(struct inode *inode, int mask,
50887 if (capable(CAP_DAC_OVERRIDE))
50888 return 0;
50889
50890 - /*
50891 - * Searching includes executable on directories, else just read.
50892 - */
50893 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50894 - if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
50895 - if (capable(CAP_DAC_READ_SEARCH))
50896 - return 0;
50897 -
50898 return -EACCES;
50899 }
50900
50901 @@ -458,7 +458,8 @@ static int exec_permission_lite(struct inode *inode)
50902 if (!ret)
50903 goto ok;
50904
50905 - if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
50906 + if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
50907 + capable(CAP_DAC_OVERRIDE))
50908 goto ok;
50909
50910 return ret;
50911 @@ -638,7 +639,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
50912 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
50913 error = PTR_ERR(cookie);
50914 if (!IS_ERR(cookie)) {
50915 - char *s = nd_get_link(nd);
50916 + const char *s = nd_get_link(nd);
50917 error = 0;
50918 if (s)
50919 error = __vfs_follow_link(nd, s);
50920 @@ -669,6 +670,13 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
50921 err = security_inode_follow_link(path->dentry, nd);
50922 if (err)
50923 goto loop;
50924 +
50925 + if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
50926 + path->dentry->d_inode, path->dentry, nd->path.mnt)) {
50927 + err = -EACCES;
50928 + goto loop;
50929 + }
50930 +
50931 current->link_count++;
50932 current->total_link_count++;
50933 nd->depth++;
50934 @@ -1016,11 +1024,19 @@ return_reval:
50935 break;
50936 }
50937 return_base:
50938 + if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT)) &&
50939 + !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50940 + path_put(&nd->path);
50941 + return -ENOENT;
50942 + }
50943 return 0;
50944 out_dput:
50945 path_put_conditional(&next, nd);
50946 break;
50947 }
50948 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
50949 + err = -ENOENT;
50950 +
50951 path_put(&nd->path);
50952 return_err:
50953 return err;
50954 @@ -1091,13 +1107,20 @@ static int do_path_lookup(int dfd, const char *name,
50955 int retval = path_init(dfd, name, flags, nd);
50956 if (!retval)
50957 retval = path_walk(name, nd);
50958 - if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
50959 - nd->path.dentry->d_inode))
50960 - audit_inode(name, nd->path.dentry);
50961 +
50962 + if (likely(!retval)) {
50963 + if (nd->path.dentry && nd->path.dentry->d_inode) {
50964 + if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50965 + retval = -ENOENT;
50966 + if (!audit_dummy_context())
50967 + audit_inode(name, nd->path.dentry);
50968 + }
50969 + }
50970 if (nd->root.mnt) {
50971 path_put(&nd->root);
50972 nd->root.mnt = NULL;
50973 }
50974 +
50975 return retval;
50976 }
50977
50978 @@ -1576,6 +1599,20 @@ int may_open(struct path *path, int acc_mode, int flag)
50979 if (error)
50980 goto err_out;
50981
50982 +
50983 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
50984 + error = -EPERM;
50985 + goto err_out;
50986 + }
50987 + if (gr_handle_rawio(inode)) {
50988 + error = -EPERM;
50989 + goto err_out;
50990 + }
50991 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
50992 + error = -EACCES;
50993 + goto err_out;
50994 + }
50995 +
50996 if (flag & O_TRUNC) {
50997 error = get_write_access(inode);
50998 if (error)
50999 @@ -1620,6 +1657,17 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51000 {
51001 int error;
51002 struct dentry *dir = nd->path.dentry;
51003 + int acc_mode = ACC_MODE(flag);
51004 +
51005 + if (flag & O_TRUNC)
51006 + acc_mode |= MAY_WRITE;
51007 + if (flag & O_APPEND)
51008 + acc_mode |= MAY_APPEND;
51009 +
51010 + if (!gr_acl_handle_creat(path->dentry, dir, nd->path.mnt, flag, acc_mode, mode)) {
51011 + error = -EACCES;
51012 + goto out_unlock;
51013 + }
51014
51015 if (!IS_POSIXACL(dir->d_inode))
51016 mode &= ~current_umask();
51017 @@ -1627,6 +1675,8 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51018 if (error)
51019 goto out_unlock;
51020 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
51021 + if (!error)
51022 + gr_handle_create(path->dentry, nd->path.mnt);
51023 out_unlock:
51024 mutex_unlock(&dir->d_inode->i_mutex);
51025 dput(nd->path.dentry);
51026 @@ -1709,6 +1759,22 @@ struct file *do_filp_open(int dfd, const char *pathname,
51027 &nd, flag);
51028 if (error)
51029 return ERR_PTR(error);
51030 +
51031 + if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
51032 + error = -EPERM;
51033 + goto exit;
51034 + }
51035 +
51036 + if (gr_handle_rawio(nd.path.dentry->d_inode)) {
51037 + error = -EPERM;
51038 + goto exit;
51039 + }
51040 +
51041 + if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, acc_mode)) {
51042 + error = -EACCES;
51043 + goto exit;
51044 + }
51045 +
51046 goto ok;
51047 }
51048
51049 @@ -1795,6 +1861,19 @@ do_last:
51050 /*
51051 * It already exists.
51052 */
51053 +
51054 + if (!gr_acl_handle_hidden_file(path.dentry, path.mnt)) {
51055 + error = -ENOENT;
51056 + goto exit_mutex_unlock;
51057 + }
51058 +
51059 + /* only check if O_CREAT is specified, all other checks need
51060 + to go into may_open */
51061 + if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
51062 + error = -EACCES;
51063 + goto exit_mutex_unlock;
51064 + }
51065 +
51066 mutex_unlock(&dir->d_inode->i_mutex);
51067 audit_inode(pathname, path.dentry);
51068
51069 @@ -1887,6 +1966,13 @@ do_link:
51070 error = security_inode_follow_link(path.dentry, &nd);
51071 if (error)
51072 goto exit_dput;
51073 +
51074 + if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
51075 + path.dentry, nd.path.mnt)) {
51076 + error = -EACCES;
51077 + goto exit_dput;
51078 + }
51079 +
51080 error = __do_follow_link(&path, &nd);
51081 if (error) {
51082 /* Does someone understand code flow here? Or it is only
51083 @@ -1984,6 +2070,10 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
51084 }
51085 return dentry;
51086 eexist:
51087 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
51088 + dput(dentry);
51089 + return ERR_PTR(-ENOENT);
51090 + }
51091 dput(dentry);
51092 dentry = ERR_PTR(-EEXIST);
51093 fail:
51094 @@ -2061,6 +2151,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51095 error = may_mknod(mode);
51096 if (error)
51097 goto out_dput;
51098 +
51099 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
51100 + error = -EPERM;
51101 + goto out_dput;
51102 + }
51103 +
51104 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
51105 + error = -EACCES;
51106 + goto out_dput;
51107 + }
51108 +
51109 error = mnt_want_write(nd.path.mnt);
51110 if (error)
51111 goto out_dput;
51112 @@ -2081,6 +2182,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51113 }
51114 out_drop_write:
51115 mnt_drop_write(nd.path.mnt);
51116 +
51117 + if (!error)
51118 + gr_handle_create(dentry, nd.path.mnt);
51119 out_dput:
51120 dput(dentry);
51121 out_unlock:
51122 @@ -2134,6 +2238,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51123 if (IS_ERR(dentry))
51124 goto out_unlock;
51125
51126 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
51127 + error = -EACCES;
51128 + goto out_dput;
51129 + }
51130 +
51131 if (!IS_POSIXACL(nd.path.dentry->d_inode))
51132 mode &= ~current_umask();
51133 error = mnt_want_write(nd.path.mnt);
51134 @@ -2145,6 +2254,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51135 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
51136 out_drop_write:
51137 mnt_drop_write(nd.path.mnt);
51138 +
51139 + if (!error)
51140 + gr_handle_create(dentry, nd.path.mnt);
51141 +
51142 out_dput:
51143 dput(dentry);
51144 out_unlock:
51145 @@ -2226,6 +2339,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51146 char * name;
51147 struct dentry *dentry;
51148 struct nameidata nd;
51149 + ino_t saved_ino = 0;
51150 + dev_t saved_dev = 0;
51151
51152 error = user_path_parent(dfd, pathname, &nd, &name);
51153 if (error)
51154 @@ -2250,6 +2365,17 @@ static long do_rmdir(int dfd, const char __user *pathname)
51155 error = PTR_ERR(dentry);
51156 if (IS_ERR(dentry))
51157 goto exit2;
51158 +
51159 + if (dentry->d_inode != NULL) {
51160 + saved_ino = dentry->d_inode->i_ino;
51161 + saved_dev = gr_get_dev_from_dentry(dentry);
51162 +
51163 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
51164 + error = -EACCES;
51165 + goto exit3;
51166 + }
51167 + }
51168 +
51169 error = mnt_want_write(nd.path.mnt);
51170 if (error)
51171 goto exit3;
51172 @@ -2257,6 +2383,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51173 if (error)
51174 goto exit4;
51175 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
51176 + if (!error && (saved_dev || saved_ino))
51177 + gr_handle_delete(saved_ino, saved_dev);
51178 exit4:
51179 mnt_drop_write(nd.path.mnt);
51180 exit3:
51181 @@ -2318,6 +2446,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51182 struct dentry *dentry;
51183 struct nameidata nd;
51184 struct inode *inode = NULL;
51185 + ino_t saved_ino = 0;
51186 + dev_t saved_dev = 0;
51187
51188 error = user_path_parent(dfd, pathname, &nd, &name);
51189 if (error)
51190 @@ -2337,8 +2467,19 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51191 if (nd.last.name[nd.last.len])
51192 goto slashes;
51193 inode = dentry->d_inode;
51194 - if (inode)
51195 + if (inode) {
51196 + if (inode->i_nlink <= 1) {
51197 + saved_ino = inode->i_ino;
51198 + saved_dev = gr_get_dev_from_dentry(dentry);
51199 + }
51200 +
51201 atomic_inc(&inode->i_count);
51202 +
51203 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
51204 + error = -EACCES;
51205 + goto exit2;
51206 + }
51207 + }
51208 error = mnt_want_write(nd.path.mnt);
51209 if (error)
51210 goto exit2;
51211 @@ -2346,6 +2487,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51212 if (error)
51213 goto exit3;
51214 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
51215 + if (!error && (saved_ino || saved_dev))
51216 + gr_handle_delete(saved_ino, saved_dev);
51217 exit3:
51218 mnt_drop_write(nd.path.mnt);
51219 exit2:
51220 @@ -2424,6 +2567,11 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51221 if (IS_ERR(dentry))
51222 goto out_unlock;
51223
51224 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
51225 + error = -EACCES;
51226 + goto out_dput;
51227 + }
51228 +
51229 error = mnt_want_write(nd.path.mnt);
51230 if (error)
51231 goto out_dput;
51232 @@ -2431,6 +2579,8 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51233 if (error)
51234 goto out_drop_write;
51235 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
51236 + if (!error)
51237 + gr_handle_create(dentry, nd.path.mnt);
51238 out_drop_write:
51239 mnt_drop_write(nd.path.mnt);
51240 out_dput:
51241 @@ -2524,6 +2674,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51242 error = PTR_ERR(new_dentry);
51243 if (IS_ERR(new_dentry))
51244 goto out_unlock;
51245 +
51246 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
51247 + old_path.dentry->d_inode,
51248 + old_path.dentry->d_inode->i_mode, to)) {
51249 + error = -EACCES;
51250 + goto out_dput;
51251 + }
51252 +
51253 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
51254 + old_path.dentry, old_path.mnt, to)) {
51255 + error = -EACCES;
51256 + goto out_dput;
51257 + }
51258 +
51259 error = mnt_want_write(nd.path.mnt);
51260 if (error)
51261 goto out_dput;
51262 @@ -2531,6 +2695,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51263 if (error)
51264 goto out_drop_write;
51265 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
51266 + if (!error)
51267 + gr_handle_create(new_dentry, nd.path.mnt);
51268 out_drop_write:
51269 mnt_drop_write(nd.path.mnt);
51270 out_dput:
51271 @@ -2708,6 +2874,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51272 char *to;
51273 int error;
51274
51275 + pax_track_stack();
51276 +
51277 error = user_path_parent(olddfd, oldname, &oldnd, &from);
51278 if (error)
51279 goto exit;
51280 @@ -2764,6 +2932,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51281 if (new_dentry == trap)
51282 goto exit5;
51283
51284 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
51285 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
51286 + to);
51287 + if (error)
51288 + goto exit5;
51289 +
51290 error = mnt_want_write(oldnd.path.mnt);
51291 if (error)
51292 goto exit5;
51293 @@ -2773,6 +2947,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51294 goto exit6;
51295 error = vfs_rename(old_dir->d_inode, old_dentry,
51296 new_dir->d_inode, new_dentry);
51297 + if (!error)
51298 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
51299 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
51300 exit6:
51301 mnt_drop_write(oldnd.path.mnt);
51302 exit5:
51303 @@ -2798,6 +2975,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
51304
51305 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
51306 {
51307 + char tmpbuf[64];
51308 + const char *newlink;
51309 int len;
51310
51311 len = PTR_ERR(link);
51312 @@ -2807,7 +2986,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
51313 len = strlen(link);
51314 if (len > (unsigned) buflen)
51315 len = buflen;
51316 - if (copy_to_user(buffer, link, len))
51317 +
51318 + if (len < sizeof(tmpbuf)) {
51319 + memcpy(tmpbuf, link, len);
51320 + newlink = tmpbuf;
51321 + } else
51322 + newlink = link;
51323 +
51324 + if (copy_to_user(buffer, newlink, len))
51325 len = -EFAULT;
51326 out:
51327 return len;
51328 diff --git a/fs/namespace.c b/fs/namespace.c
51329 index 2beb0fb..11a95a5 100644
51330 --- a/fs/namespace.c
51331 +++ b/fs/namespace.c
51332 @@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51333 if (!(sb->s_flags & MS_RDONLY))
51334 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
51335 up_write(&sb->s_umount);
51336 +
51337 + gr_log_remount(mnt->mnt_devname, retval);
51338 +
51339 return retval;
51340 }
51341
51342 @@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51343 security_sb_umount_busy(mnt);
51344 up_write(&namespace_sem);
51345 release_mounts(&umount_list);
51346 +
51347 + gr_log_unmount(mnt->mnt_devname, retval);
51348 +
51349 return retval;
51350 }
51351
51352 @@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51353 if (retval)
51354 goto dput_out;
51355
51356 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
51357 + retval = -EPERM;
51358 + goto dput_out;
51359 + }
51360 +
51361 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
51362 + retval = -EPERM;
51363 + goto dput_out;
51364 + }
51365 +
51366 if (flags & MS_REMOUNT)
51367 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
51368 data_page);
51369 @@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51370 dev_name, data_page);
51371 dput_out:
51372 path_put(&path);
51373 +
51374 + gr_log_mount(dev_name, dir_name, retval);
51375 +
51376 return retval;
51377 }
51378
51379 @@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
51380 goto out1;
51381 }
51382
51383 + if (gr_handle_chroot_pivot()) {
51384 + error = -EPERM;
51385 + path_put(&old);
51386 + goto out1;
51387 + }
51388 +
51389 read_lock(&current->fs->lock);
51390 root = current->fs->root;
51391 path_get(&current->fs->root);
51392 diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
51393 index b8b5b30..2bd9ccb 100644
51394 --- a/fs/ncpfs/dir.c
51395 +++ b/fs/ncpfs/dir.c
51396 @@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *dentry)
51397 int res, val = 0, len;
51398 __u8 __name[NCP_MAXPATHLEN + 1];
51399
51400 + pax_track_stack();
51401 +
51402 parent = dget_parent(dentry);
51403 dir = parent->d_inode;
51404
51405 @@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
51406 int error, res, len;
51407 __u8 __name[NCP_MAXPATHLEN + 1];
51408
51409 + pax_track_stack();
51410 +
51411 lock_kernel();
51412 error = -EIO;
51413 if (!ncp_conn_valid(server))
51414 @@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
51415 int error, result, len;
51416 int opmode;
51417 __u8 __name[NCP_MAXPATHLEN + 1];
51418 -
51419 +
51420 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
51421 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
51422
51423 + pax_track_stack();
51424 +
51425 error = -EIO;
51426 lock_kernel();
51427 if (!ncp_conn_valid(server))
51428 @@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51429 int error, len;
51430 __u8 __name[NCP_MAXPATHLEN + 1];
51431
51432 + pax_track_stack();
51433 +
51434 DPRINTK("ncp_mkdir: making %s/%s\n",
51435 dentry->d_parent->d_name.name, dentry->d_name.name);
51436
51437 @@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51438 if (!ncp_conn_valid(server))
51439 goto out;
51440
51441 + pax_track_stack();
51442 +
51443 ncp_age_dentry(server, dentry);
51444 len = sizeof(__name);
51445 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
51446 @@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
51447 int old_len, new_len;
51448 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
51449
51450 + pax_track_stack();
51451 +
51452 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
51453 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
51454 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
51455 diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
51456 index cf98da1..da890a9 100644
51457 --- a/fs/ncpfs/inode.c
51458 +++ b/fs/ncpfs/inode.c
51459 @@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
51460 #endif
51461 struct ncp_entry_info finfo;
51462
51463 + pax_track_stack();
51464 +
51465 data.wdog_pid = NULL;
51466 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
51467 if (!server)
51468 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
51469 index bfaef7b..e9d03ca 100644
51470 --- a/fs/nfs/inode.c
51471 +++ b/fs/nfs/inode.c
51472 @@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
51473 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
51474 nfsi->attrtimeo_timestamp = jiffies;
51475
51476 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
51477 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
51478 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
51479 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
51480 else
51481 @@ -973,16 +973,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51482 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51483 }
51484
51485 -static atomic_long_t nfs_attr_generation_counter;
51486 +static atomic_long_unchecked_t nfs_attr_generation_counter;
51487
51488 static unsigned long nfs_read_attr_generation_counter(void)
51489 {
51490 - return atomic_long_read(&nfs_attr_generation_counter);
51491 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51492 }
51493
51494 unsigned long nfs_inc_attr_generation_counter(void)
51495 {
51496 - return atomic_long_inc_return(&nfs_attr_generation_counter);
51497 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51498 }
51499
51500 void nfs_fattr_init(struct nfs_fattr *fattr)
51501 diff --git a/fs/nfsd/lockd.c b/fs/nfsd/lockd.c
51502 index cc2f505..f6a236f 100644
51503 --- a/fs/nfsd/lockd.c
51504 +++ b/fs/nfsd/lockd.c
51505 @@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
51506 fput(filp);
51507 }
51508
51509 -static struct nlmsvc_binding nfsd_nlm_ops = {
51510 +static const struct nlmsvc_binding nfsd_nlm_ops = {
51511 .fopen = nlm_fopen, /* open file for locking */
51512 .fclose = nlm_fclose, /* close file */
51513 };
51514 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
51515 index cfc3391..dcc083a 100644
51516 --- a/fs/nfsd/nfs4state.c
51517 +++ b/fs/nfsd/nfs4state.c
51518 @@ -3459,6 +3459,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
51519 unsigned int cmd;
51520 int err;
51521
51522 + pax_track_stack();
51523 +
51524 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
51525 (long long) lock->lk_offset,
51526 (long long) lock->lk_length);
51527 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
51528 index 4a82a96..0d5fb49 100644
51529 --- a/fs/nfsd/nfs4xdr.c
51530 +++ b/fs/nfsd/nfs4xdr.c
51531 @@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
51532 struct nfsd4_compoundres *resp = rqstp->rq_resp;
51533 u32 minorversion = resp->cstate.minorversion;
51534
51535 + pax_track_stack();
51536 +
51537 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
51538 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
51539 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
51540 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51541 index 2e09588..596421d 100644
51542 --- a/fs/nfsd/vfs.c
51543 +++ b/fs/nfsd/vfs.c
51544 @@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51545 } else {
51546 oldfs = get_fs();
51547 set_fs(KERNEL_DS);
51548 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51549 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51550 set_fs(oldfs);
51551 }
51552
51553 @@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51554
51555 /* Write the data. */
51556 oldfs = get_fs(); set_fs(KERNEL_DS);
51557 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51558 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51559 set_fs(oldfs);
51560 if (host_err < 0)
51561 goto out_nfserr;
51562 @@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51563 */
51564
51565 oldfs = get_fs(); set_fs(KERNEL_DS);
51566 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
51567 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
51568 set_fs(oldfs);
51569
51570 if (host_err < 0)
51571 diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
51572 index f6af760..d6b2b83 100644
51573 --- a/fs/nilfs2/ioctl.c
51574 +++ b/fs/nilfs2/ioctl.c
51575 @@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
51576 unsigned int cmd, void __user *argp)
51577 {
51578 struct nilfs_argv argv[5];
51579 - const static size_t argsz[5] = {
51580 + static const size_t argsz[5] = {
51581 sizeof(struct nilfs_vdesc),
51582 sizeof(struct nilfs_period),
51583 sizeof(__u64),
51584 diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
51585 index 7e54e52..9337248 100644
51586 --- a/fs/notify/dnotify/dnotify.c
51587 +++ b/fs/notify/dnotify/dnotify.c
51588 @@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsnotify_mark_entry *entry)
51589 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
51590 }
51591
51592 -static struct fsnotify_ops dnotify_fsnotify_ops = {
51593 +static const struct fsnotify_ops dnotify_fsnotify_ops = {
51594 .handle_event = dnotify_handle_event,
51595 .should_send_event = dnotify_should_send_event,
51596 .free_group_priv = NULL,
51597 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51598 index b8bf53b..c518688 100644
51599 --- a/fs/notify/notification.c
51600 +++ b/fs/notify/notification.c
51601 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51602 * get set to 0 so it will never get 'freed'
51603 */
51604 static struct fsnotify_event q_overflow_event;
51605 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51606 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51607
51608 /**
51609 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51610 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51611 */
51612 u32 fsnotify_get_cookie(void)
51613 {
51614 - return atomic_inc_return(&fsnotify_sync_cookie);
51615 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51616 }
51617 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51618
51619 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51620 index 5a9e344..0f8cd28 100644
51621 --- a/fs/ntfs/dir.c
51622 +++ b/fs/ntfs/dir.c
51623 @@ -1328,7 +1328,7 @@ find_next_index_buffer:
51624 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51625 ~(s64)(ndir->itype.index.block_size - 1)));
51626 /* Bounds checks. */
51627 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51628 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51629 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51630 "inode 0x%lx or driver bug.", vdir->i_ino);
51631 goto err_out;
51632 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51633 index 663c0e3..b6868e9 100644
51634 --- a/fs/ntfs/file.c
51635 +++ b/fs/ntfs/file.c
51636 @@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51637 #endif /* NTFS_RW */
51638 };
51639
51640 -const struct file_operations ntfs_empty_file_ops = {};
51641 +const struct file_operations ntfs_empty_file_ops __read_only;
51642
51643 -const struct inode_operations ntfs_empty_inode_ops = {};
51644 +const struct inode_operations ntfs_empty_inode_ops __read_only;
51645 diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
51646 index 1cd2934..880b5d2 100644
51647 --- a/fs/ocfs2/cluster/masklog.c
51648 +++ b/fs/ocfs2/cluster/masklog.c
51649 @@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
51650 return mlog_mask_store(mlog_attr->mask, buf, count);
51651 }
51652
51653 -static struct sysfs_ops mlog_attr_ops = {
51654 +static const struct sysfs_ops mlog_attr_ops = {
51655 .show = mlog_show,
51656 .store = mlog_store,
51657 };
51658 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51659 index ac10f83..2cd2607 100644
51660 --- a/fs/ocfs2/localalloc.c
51661 +++ b/fs/ocfs2/localalloc.c
51662 @@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51663 goto bail;
51664 }
51665
51666 - atomic_inc(&osb->alloc_stats.moves);
51667 + atomic_inc_unchecked(&osb->alloc_stats.moves);
51668
51669 status = 0;
51670 bail:
51671 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
51672 index f010b22..9f9ed34 100644
51673 --- a/fs/ocfs2/namei.c
51674 +++ b/fs/ocfs2/namei.c
51675 @@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *old_dir,
51676 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
51677 struct ocfs2_dir_lookup_result target_insert = { NULL, };
51678
51679 + pax_track_stack();
51680 +
51681 /* At some point it might be nice to break this function up a
51682 * bit. */
51683
51684 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51685 index d963d86..914cfbd 100644
51686 --- a/fs/ocfs2/ocfs2.h
51687 +++ b/fs/ocfs2/ocfs2.h
51688 @@ -217,11 +217,11 @@ enum ocfs2_vol_state
51689
51690 struct ocfs2_alloc_stats
51691 {
51692 - atomic_t moves;
51693 - atomic_t local_data;
51694 - atomic_t bitmap_data;
51695 - atomic_t bg_allocs;
51696 - atomic_t bg_extends;
51697 + atomic_unchecked_t moves;
51698 + atomic_unchecked_t local_data;
51699 + atomic_unchecked_t bitmap_data;
51700 + atomic_unchecked_t bg_allocs;
51701 + atomic_unchecked_t bg_extends;
51702 };
51703
51704 enum ocfs2_local_alloc_state
51705 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51706 index 79b5dac..d322952 100644
51707 --- a/fs/ocfs2/suballoc.c
51708 +++ b/fs/ocfs2/suballoc.c
51709 @@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51710 mlog_errno(status);
51711 goto bail;
51712 }
51713 - atomic_inc(&osb->alloc_stats.bg_extends);
51714 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51715
51716 /* You should never ask for this much metadata */
51717 BUG_ON(bits_wanted >
51718 @@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb,
51719 mlog_errno(status);
51720 goto bail;
51721 }
51722 - atomic_inc(&osb->alloc_stats.bg_allocs);
51723 + atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51724
51725 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
51726 ac->ac_bits_given += (*num_bits);
51727 @@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb,
51728 mlog_errno(status);
51729 goto bail;
51730 }
51731 - atomic_inc(&osb->alloc_stats.bg_allocs);
51732 + atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51733
51734 BUG_ON(num_bits != 1);
51735
51736 @@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51737 cluster_start,
51738 num_clusters);
51739 if (!status)
51740 - atomic_inc(&osb->alloc_stats.local_data);
51741 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
51742 } else {
51743 if (min_clusters > (osb->bitmap_cpg - 1)) {
51744 /* The only paths asking for contiguousness
51745 @@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51746 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51747 bg_blkno,
51748 bg_bit_off);
51749 - atomic_inc(&osb->alloc_stats.bitmap_data);
51750 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51751 }
51752 }
51753 if (status < 0) {
51754 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51755 index 9f55be4..a3f8048 100644
51756 --- a/fs/ocfs2/super.c
51757 +++ b/fs/ocfs2/super.c
51758 @@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51759 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51760 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51761 "Stats",
51762 - atomic_read(&osb->alloc_stats.bitmap_data),
51763 - atomic_read(&osb->alloc_stats.local_data),
51764 - atomic_read(&osb->alloc_stats.bg_allocs),
51765 - atomic_read(&osb->alloc_stats.moves),
51766 - atomic_read(&osb->alloc_stats.bg_extends));
51767 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51768 + atomic_read_unchecked(&osb->alloc_stats.local_data),
51769 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51770 + atomic_read_unchecked(&osb->alloc_stats.moves),
51771 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51772
51773 out += snprintf(buf + out, len - out,
51774 "%10s => State: %u Descriptor: %llu Size: %u bits "
51775 @@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51776 spin_lock_init(&osb->osb_xattr_lock);
51777 ocfs2_init_inode_steal_slot(osb);
51778
51779 - atomic_set(&osb->alloc_stats.moves, 0);
51780 - atomic_set(&osb->alloc_stats.local_data, 0);
51781 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
51782 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
51783 - atomic_set(&osb->alloc_stats.bg_extends, 0);
51784 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51785 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51786 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51787 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51788 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51789
51790 /* Copy the blockcheck stats from the superblock probe */
51791 osb->osb_ecc_stats = *stats;
51792 diff --git a/fs/open.c b/fs/open.c
51793 index 4f01e06..091f6c3 100644
51794 --- a/fs/open.c
51795 +++ b/fs/open.c
51796 @@ -275,6 +275,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
51797 error = locks_verify_truncate(inode, NULL, length);
51798 if (!error)
51799 error = security_path_truncate(&path, length, 0);
51800 +
51801 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
51802 + error = -EACCES;
51803 +
51804 if (!error) {
51805 vfs_dq_init(inode);
51806 error = do_truncate(path.dentry, length, 0, NULL);
51807 @@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
51808 if (__mnt_is_readonly(path.mnt))
51809 res = -EROFS;
51810
51811 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51812 + res = -EACCES;
51813 +
51814 out_path_release:
51815 path_put(&path);
51816 out:
51817 @@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
51818 if (error)
51819 goto dput_and_out;
51820
51821 + gr_log_chdir(path.dentry, path.mnt);
51822 +
51823 set_fs_pwd(current->fs, &path);
51824
51825 dput_and_out:
51826 @@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51827 goto out_putf;
51828
51829 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
51830 +
51831 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
51832 + error = -EPERM;
51833 +
51834 + if (!error)
51835 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
51836 +
51837 if (!error)
51838 set_fs_pwd(current->fs, &file->f_path);
51839 out_putf:
51840 @@ -588,7 +604,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
51841 if (!capable(CAP_SYS_CHROOT))
51842 goto dput_and_out;
51843
51844 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51845 + goto dput_and_out;
51846 +
51847 set_fs_root(current->fs, &path);
51848 +
51849 + gr_handle_chroot_chdir(&path);
51850 +
51851 error = 0;
51852 dput_and_out:
51853 path_put(&path);
51854 @@ -616,12 +638,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
51855 err = mnt_want_write_file(file);
51856 if (err)
51857 goto out_putf;
51858 +
51859 mutex_lock(&inode->i_mutex);
51860 +
51861 + if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
51862 + err = -EACCES;
51863 + goto out_unlock;
51864 + }
51865 +
51866 if (mode == (mode_t) -1)
51867 mode = inode->i_mode;
51868 +
51869 + if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
51870 + err = -EPERM;
51871 + goto out_unlock;
51872 + }
51873 +
51874 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
51875 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
51876 err = notify_change(dentry, &newattrs);
51877 +
51878 +out_unlock:
51879 mutex_unlock(&inode->i_mutex);
51880 mnt_drop_write(file->f_path.mnt);
51881 out_putf:
51882 @@ -645,12 +682,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
51883 error = mnt_want_write(path.mnt);
51884 if (error)
51885 goto dput_and_out;
51886 +
51887 mutex_lock(&inode->i_mutex);
51888 +
51889 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
51890 + error = -EACCES;
51891 + goto out_unlock;
51892 + }
51893 +
51894 if (mode == (mode_t) -1)
51895 mode = inode->i_mode;
51896 +
51897 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
51898 + error = -EACCES;
51899 + goto out_unlock;
51900 + }
51901 +
51902 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
51903 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
51904 error = notify_change(path.dentry, &newattrs);
51905 +
51906 +out_unlock:
51907 mutex_unlock(&inode->i_mutex);
51908 mnt_drop_write(path.mnt);
51909 dput_and_out:
51910 @@ -664,12 +716,15 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode)
51911 return sys_fchmodat(AT_FDCWD, filename, mode);
51912 }
51913
51914 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
51915 +static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
51916 {
51917 struct inode *inode = dentry->d_inode;
51918 int error;
51919 struct iattr newattrs;
51920
51921 + if (!gr_acl_handle_chown(dentry, mnt))
51922 + return -EACCES;
51923 +
51924 newattrs.ia_valid = ATTR_CTIME;
51925 if (user != (uid_t) -1) {
51926 newattrs.ia_valid |= ATTR_UID;
51927 @@ -700,7 +755,7 @@ SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
51928 error = mnt_want_write(path.mnt);
51929 if (error)
51930 goto out_release;
51931 - error = chown_common(path.dentry, user, group);
51932 + error = chown_common(path.dentry, user, group, path.mnt);
51933 mnt_drop_write(path.mnt);
51934 out_release:
51935 path_put(&path);
51936 @@ -725,7 +780,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
51937 error = mnt_want_write(path.mnt);
51938 if (error)
51939 goto out_release;
51940 - error = chown_common(path.dentry, user, group);
51941 + error = chown_common(path.dentry, user, group, path.mnt);
51942 mnt_drop_write(path.mnt);
51943 out_release:
51944 path_put(&path);
51945 @@ -744,7 +799,7 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
51946 error = mnt_want_write(path.mnt);
51947 if (error)
51948 goto out_release;
51949 - error = chown_common(path.dentry, user, group);
51950 + error = chown_common(path.dentry, user, group, path.mnt);
51951 mnt_drop_write(path.mnt);
51952 out_release:
51953 path_put(&path);
51954 @@ -767,7 +822,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
51955 goto out_fput;
51956 dentry = file->f_path.dentry;
51957 audit_inode(NULL, dentry);
51958 - error = chown_common(dentry, user, group);
51959 + error = chown_common(dentry, user, group, file->f_path.mnt);
51960 mnt_drop_write(file->f_path.mnt);
51961 out_fput:
51962 fput(file);
51963 @@ -1036,7 +1091,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
51964 if (!IS_ERR(tmp)) {
51965 fd = get_unused_fd_flags(flags);
51966 if (fd >= 0) {
51967 - struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
51968 + struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
51969 if (IS_ERR(f)) {
51970 put_unused_fd(fd);
51971 fd = PTR_ERR(f);
51972 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
51973 index 6ab70f4..f4103d1 100644
51974 --- a/fs/partitions/efi.c
51975 +++ b/fs/partitions/efi.c
51976 @@ -231,14 +231,14 @@ alloc_read_gpt_entries(struct block_device *bdev, gpt_header *gpt)
51977 if (!bdev || !gpt)
51978 return NULL;
51979
51980 + if (!le32_to_cpu(gpt->num_partition_entries))
51981 + return NULL;
51982 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
51983 + if (!pte)
51984 + return NULL;
51985 +
51986 count = le32_to_cpu(gpt->num_partition_entries) *
51987 le32_to_cpu(gpt->sizeof_partition_entry);
51988 - if (!count)
51989 - return NULL;
51990 - pte = kzalloc(count, GFP_KERNEL);
51991 - if (!pte)
51992 - return NULL;
51993 -
51994 if (read_lba(bdev, le64_to_cpu(gpt->partition_entry_lba),
51995 (u8 *) pte,
51996 count) < count) {
51997 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
51998 index dd6efdb..3babc6c 100644
51999 --- a/fs/partitions/ldm.c
52000 +++ b/fs/partitions/ldm.c
52001 @@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52002 ldm_error ("A VBLK claims to have %d parts.", num);
52003 return false;
52004 }
52005 +
52006 if (rec >= num) {
52007 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
52008 return false;
52009 @@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52010 goto found;
52011 }
52012
52013 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
52014 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
52015 if (!f) {
52016 ldm_crit ("Out of memory.");
52017 return false;
52018 diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
52019 index 5765198..7f8e9e0 100644
52020 --- a/fs/partitions/mac.c
52021 +++ b/fs/partitions/mac.c
52022 @@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
52023 return 0; /* not a MacOS disk */
52024 }
52025 blocks_in_map = be32_to_cpu(part->map_count);
52026 - if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52027 - put_dev_sector(sect);
52028 - return 0;
52029 - }
52030 printk(" [mac]");
52031 + if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52032 + put_dev_sector(sect);
52033 + return 0;
52034 + }
52035 for (slot = 1; slot <= blocks_in_map; ++slot) {
52036 int pos = slot * secsize;
52037 put_dev_sector(sect);
52038 diff --git a/fs/pipe.c b/fs/pipe.c
52039 index d0cc080..8a6f211 100644
52040 --- a/fs/pipe.c
52041 +++ b/fs/pipe.c
52042 @@ -401,9 +401,9 @@ redo:
52043 }
52044 if (bufs) /* More to do? */
52045 continue;
52046 - if (!pipe->writers)
52047 + if (!atomic_read(&pipe->writers))
52048 break;
52049 - if (!pipe->waiting_writers) {
52050 + if (!atomic_read(&pipe->waiting_writers)) {
52051 /* syscall merging: Usually we must not sleep
52052 * if O_NONBLOCK is set, or if we got some data.
52053 * But if a writer sleeps in kernel space, then
52054 @@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
52055 mutex_lock(&inode->i_mutex);
52056 pipe = inode->i_pipe;
52057
52058 - if (!pipe->readers) {
52059 + if (!atomic_read(&pipe->readers)) {
52060 send_sig(SIGPIPE, current, 0);
52061 ret = -EPIPE;
52062 goto out;
52063 @@ -511,7 +511,7 @@ redo1:
52064 for (;;) {
52065 int bufs;
52066
52067 - if (!pipe->readers) {
52068 + if (!atomic_read(&pipe->readers)) {
52069 send_sig(SIGPIPE, current, 0);
52070 if (!ret)
52071 ret = -EPIPE;
52072 @@ -597,9 +597,9 @@ redo2:
52073 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
52074 do_wakeup = 0;
52075 }
52076 - pipe->waiting_writers++;
52077 + atomic_inc(&pipe->waiting_writers);
52078 pipe_wait(pipe);
52079 - pipe->waiting_writers--;
52080 + atomic_dec(&pipe->waiting_writers);
52081 }
52082 out:
52083 mutex_unlock(&inode->i_mutex);
52084 @@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52085 mask = 0;
52086 if (filp->f_mode & FMODE_READ) {
52087 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
52088 - if (!pipe->writers && filp->f_version != pipe->w_counter)
52089 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
52090 mask |= POLLHUP;
52091 }
52092
52093 @@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52094 * Most Unices do not set POLLERR for FIFOs but on Linux they
52095 * behave exactly like pipes for poll().
52096 */
52097 - if (!pipe->readers)
52098 + if (!atomic_read(&pipe->readers))
52099 mask |= POLLERR;
52100 }
52101
52102 @@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int decr, int decw)
52103
52104 mutex_lock(&inode->i_mutex);
52105 pipe = inode->i_pipe;
52106 - pipe->readers -= decr;
52107 - pipe->writers -= decw;
52108 + atomic_sub(decr, &pipe->readers);
52109 + atomic_sub(decw, &pipe->writers);
52110
52111 - if (!pipe->readers && !pipe->writers) {
52112 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
52113 free_pipe_info(inode);
52114 } else {
52115 wake_up_interruptible_sync(&pipe->wait);
52116 @@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
52117
52118 if (inode->i_pipe) {
52119 ret = 0;
52120 - inode->i_pipe->readers++;
52121 + atomic_inc(&inode->i_pipe->readers);
52122 }
52123
52124 mutex_unlock(&inode->i_mutex);
52125 @@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
52126
52127 if (inode->i_pipe) {
52128 ret = 0;
52129 - inode->i_pipe->writers++;
52130 + atomic_inc(&inode->i_pipe->writers);
52131 }
52132
52133 mutex_unlock(&inode->i_mutex);
52134 @@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
52135 if (inode->i_pipe) {
52136 ret = 0;
52137 if (filp->f_mode & FMODE_READ)
52138 - inode->i_pipe->readers++;
52139 + atomic_inc(&inode->i_pipe->readers);
52140 if (filp->f_mode & FMODE_WRITE)
52141 - inode->i_pipe->writers++;
52142 + atomic_inc(&inode->i_pipe->writers);
52143 }
52144
52145 mutex_unlock(&inode->i_mutex);
52146 @@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
52147 inode->i_pipe = NULL;
52148 }
52149
52150 -static struct vfsmount *pipe_mnt __read_mostly;
52151 +struct vfsmount *pipe_mnt __read_mostly;
52152 static int pipefs_delete_dentry(struct dentry *dentry)
52153 {
52154 /*
52155 @@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(void)
52156 goto fail_iput;
52157 inode->i_pipe = pipe;
52158
52159 - pipe->readers = pipe->writers = 1;
52160 + atomic_set(&pipe->readers, 1);
52161 + atomic_set(&pipe->writers, 1);
52162 inode->i_fop = &rdwr_pipefifo_fops;
52163
52164 /*
52165 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
52166 index 50f8f06..c5755df 100644
52167 --- a/fs/proc/Kconfig
52168 +++ b/fs/proc/Kconfig
52169 @@ -30,12 +30,12 @@ config PROC_FS
52170
52171 config PROC_KCORE
52172 bool "/proc/kcore support" if !ARM
52173 - depends on PROC_FS && MMU
52174 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
52175
52176 config PROC_VMCORE
52177 bool "/proc/vmcore support (EXPERIMENTAL)"
52178 - depends on PROC_FS && CRASH_DUMP
52179 - default y
52180 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
52181 + default n
52182 help
52183 Exports the dump image of crashed kernel in ELF format.
52184
52185 @@ -59,8 +59,8 @@ config PROC_SYSCTL
52186 limited in memory.
52187
52188 config PROC_PAGE_MONITOR
52189 - default y
52190 - depends on PROC_FS && MMU
52191 + default n
52192 + depends on PROC_FS && MMU && !GRKERNSEC
52193 bool "Enable /proc page monitoring" if EMBEDDED
52194 help
52195 Various /proc files exist to monitor process memory utilization:
52196 diff --git a/fs/proc/array.c b/fs/proc/array.c
52197 index c5ef152..1363194 100644
52198 --- a/fs/proc/array.c
52199 +++ b/fs/proc/array.c
52200 @@ -60,6 +60,7 @@
52201 #include <linux/tty.h>
52202 #include <linux/string.h>
52203 #include <linux/mman.h>
52204 +#include <linux/grsecurity.h>
52205 #include <linux/proc_fs.h>
52206 #include <linux/ioport.h>
52207 #include <linux/uaccess.h>
52208 @@ -321,6 +322,21 @@ static inline void task_context_switch_counts(struct seq_file *m,
52209 p->nivcsw);
52210 }
52211
52212 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52213 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
52214 +{
52215 + if (p->mm)
52216 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
52217 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
52218 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
52219 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
52220 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
52221 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
52222 + else
52223 + seq_printf(m, "PaX:\t-----\n");
52224 +}
52225 +#endif
52226 +
52227 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52228 struct pid *pid, struct task_struct *task)
52229 {
52230 @@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52231 task_cap(m, task);
52232 cpuset_task_status_allowed(m, task);
52233 task_context_switch_counts(m, task);
52234 +
52235 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52236 + task_pax(m, task);
52237 +#endif
52238 +
52239 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
52240 + task_grsec_rbac(m, task);
52241 +#endif
52242 +
52243 return 0;
52244 }
52245
52246 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52247 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52248 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
52249 + _mm->pax_flags & MF_PAX_SEGMEXEC))
52250 +#endif
52251 +
52252 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52253 struct pid *pid, struct task_struct *task, int whole)
52254 {
52255 @@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52256 cputime_t cutime, cstime, utime, stime;
52257 cputime_t cgtime, gtime;
52258 unsigned long rsslim = 0;
52259 - char tcomm[sizeof(task->comm)];
52260 + char tcomm[sizeof(task->comm)] = { 0 };
52261 unsigned long flags;
52262
52263 + pax_track_stack();
52264 +
52265 state = *get_task_state(task);
52266 vsize = eip = esp = 0;
52267 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
52268 @@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52269 gtime = task_gtime(task);
52270 }
52271
52272 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52273 + if (PAX_RAND_FLAGS(mm)) {
52274 + eip = 0;
52275 + esp = 0;
52276 + wchan = 0;
52277 + }
52278 +#endif
52279 +#ifdef CONFIG_GRKERNSEC_HIDESYM
52280 + wchan = 0;
52281 + eip =0;
52282 + esp =0;
52283 +#endif
52284 +
52285 /* scale priority and nice values from timeslices to -20..20 */
52286 /* to make it look like a "normal" Unix priority/nice value */
52287 priority = task_prio(task);
52288 @@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52289 vsize,
52290 mm ? get_mm_rss(mm) : 0,
52291 rsslim,
52292 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52293 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
52294 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
52295 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
52296 +#else
52297 mm ? (permitted ? mm->start_code : 1) : 0,
52298 mm ? (permitted ? mm->end_code : 1) : 0,
52299 (permitted && mm) ? mm->start_stack : 0,
52300 +#endif
52301 esp,
52302 eip,
52303 /* The signal information here is obsolete.
52304 @@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52305
52306 return 0;
52307 }
52308 +
52309 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52310 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
52311 +{
52312 + u32 curr_ip = 0;
52313 + unsigned long flags;
52314 +
52315 + if (lock_task_sighand(task, &flags)) {
52316 + curr_ip = task->signal->curr_ip;
52317 + unlock_task_sighand(task, &flags);
52318 + }
52319 +
52320 + return sprintf(buffer, "%pI4\n", &curr_ip);
52321 +}
52322 +#endif
52323 diff --git a/fs/proc/base.c b/fs/proc/base.c
52324 index 67f7dc0..e95ea4f 100644
52325 --- a/fs/proc/base.c
52326 +++ b/fs/proc/base.c
52327 @@ -102,6 +102,22 @@ struct pid_entry {
52328 union proc_op op;
52329 };
52330
52331 +struct getdents_callback {
52332 + struct linux_dirent __user * current_dir;
52333 + struct linux_dirent __user * previous;
52334 + struct file * file;
52335 + int count;
52336 + int error;
52337 +};
52338 +
52339 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
52340 + loff_t offset, u64 ino, unsigned int d_type)
52341 +{
52342 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
52343 + buf->error = -EINVAL;
52344 + return 0;
52345 +}
52346 +
52347 #define NOD(NAME, MODE, IOP, FOP, OP) { \
52348 .name = (NAME), \
52349 .len = sizeof(NAME) - 1, \
52350 @@ -213,6 +229,9 @@ static int check_mem_permission(struct task_struct *task)
52351 if (task == current)
52352 return 0;
52353
52354 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
52355 + return -EPERM;
52356 +
52357 /*
52358 * If current is actively ptrace'ing, and would also be
52359 * permitted to freshly attach with ptrace now, permit it.
52360 @@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
52361 if (!mm->arg_end)
52362 goto out_mm; /* Shh! No looking before we're done */
52363
52364 + if (gr_acl_handle_procpidmem(task))
52365 + goto out_mm;
52366 +
52367 len = mm->arg_end - mm->arg_start;
52368
52369 if (len > PAGE_SIZE)
52370 @@ -287,12 +309,28 @@ out:
52371 return res;
52372 }
52373
52374 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52375 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52376 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
52377 + _mm->pax_flags & MF_PAX_SEGMEXEC))
52378 +#endif
52379 +
52380 static int proc_pid_auxv(struct task_struct *task, char *buffer)
52381 {
52382 int res = 0;
52383 struct mm_struct *mm = get_task_mm(task);
52384 if (mm) {
52385 unsigned int nwords = 0;
52386 +
52387 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52388 + /* allow if we're currently ptracing this task */
52389 + if (PAX_RAND_FLAGS(mm) &&
52390 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
52391 + mmput(mm);
52392 + return 0;
52393 + }
52394 +#endif
52395 +
52396 do {
52397 nwords += 2;
52398 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
52399 @@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
52400 }
52401
52402
52403 -#ifdef CONFIG_KALLSYMS
52404 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52405 /*
52406 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
52407 * Returns the resolved symbol. If that fails, simply return the address.
52408 @@ -345,7 +383,7 @@ static void unlock_trace(struct task_struct *task)
52409 mutex_unlock(&task->cred_guard_mutex);
52410 }
52411
52412 -#ifdef CONFIG_STACKTRACE
52413 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52414
52415 #define MAX_STACK_TRACE_DEPTH 64
52416
52417 @@ -545,7 +583,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
52418 return count;
52419 }
52420
52421 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52422 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52423 static int proc_pid_syscall(struct task_struct *task, char *buffer)
52424 {
52425 long nr;
52426 @@ -574,7 +612,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
52427 /************************************************************************/
52428
52429 /* permission checks */
52430 -static int proc_fd_access_allowed(struct inode *inode)
52431 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
52432 {
52433 struct task_struct *task;
52434 int allowed = 0;
52435 @@ -584,7 +622,10 @@ static int proc_fd_access_allowed(struct inode *inode)
52436 */
52437 task = get_proc_task(inode);
52438 if (task) {
52439 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52440 + if (log)
52441 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
52442 + else
52443 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52444 put_task_struct(task);
52445 }
52446 return allowed;
52447 @@ -963,6 +1004,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
52448 if (!task)
52449 goto out_no_task;
52450
52451 + if (gr_acl_handle_procpidmem(task))
52452 + goto out;
52453 +
52454 if (!ptrace_may_access(task, PTRACE_MODE_READ))
52455 goto out;
52456
52457 @@ -1377,7 +1421,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
52458 path_put(&nd->path);
52459
52460 /* Are we allowed to snoop on the tasks file descriptors? */
52461 - if (!proc_fd_access_allowed(inode))
52462 + if (!proc_fd_access_allowed(inode,0))
52463 goto out;
52464
52465 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
52466 @@ -1417,8 +1461,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
52467 struct path path;
52468
52469 /* Are we allowed to snoop on the tasks file descriptors? */
52470 - if (!proc_fd_access_allowed(inode))
52471 - goto out;
52472 + /* logging this is needed for learning on chromium to work properly,
52473 + but we don't want to flood the logs from 'ps' which does a readlink
52474 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
52475 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
52476 + */
52477 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
52478 + if (!proc_fd_access_allowed(inode,0))
52479 + goto out;
52480 + } else {
52481 + if (!proc_fd_access_allowed(inode,1))
52482 + goto out;
52483 + }
52484
52485 error = PROC_I(inode)->op.proc_get_link(inode, &path);
52486 if (error)
52487 @@ -1483,7 +1537,11 @@ static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_st
52488 rcu_read_lock();
52489 cred = __task_cred(task);
52490 inode->i_uid = cred->euid;
52491 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52492 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52493 +#else
52494 inode->i_gid = cred->egid;
52495 +#endif
52496 rcu_read_unlock();
52497 }
52498 security_task_to_inode(task, inode);
52499 @@ -1501,6 +1559,9 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52500 struct inode *inode = dentry->d_inode;
52501 struct task_struct *task;
52502 const struct cred *cred;
52503 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52504 + const struct cred *tmpcred = current_cred();
52505 +#endif
52506
52507 generic_fillattr(inode, stat);
52508
52509 @@ -1508,13 +1569,41 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52510 stat->uid = 0;
52511 stat->gid = 0;
52512 task = pid_task(proc_pid(inode), PIDTYPE_PID);
52513 +
52514 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
52515 + rcu_read_unlock();
52516 + return -ENOENT;
52517 + }
52518 +
52519 if (task) {
52520 + cred = __task_cred(task);
52521 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52522 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
52523 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52524 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52525 +#endif
52526 + ) {
52527 +#endif
52528 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52529 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52530 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52531 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52532 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52533 +#endif
52534 task_dumpable(task)) {
52535 - cred = __task_cred(task);
52536 stat->uid = cred->euid;
52537 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52538 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
52539 +#else
52540 stat->gid = cred->egid;
52541 +#endif
52542 }
52543 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52544 + } else {
52545 + rcu_read_unlock();
52546 + return -ENOENT;
52547 + }
52548 +#endif
52549 }
52550 rcu_read_unlock();
52551 return 0;
52552 @@ -1545,11 +1634,20 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
52553
52554 if (task) {
52555 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52556 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52557 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52558 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52559 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52560 +#endif
52561 task_dumpable(task)) {
52562 rcu_read_lock();
52563 cred = __task_cred(task);
52564 inode->i_uid = cred->euid;
52565 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52566 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52567 +#else
52568 inode->i_gid = cred->egid;
52569 +#endif
52570 rcu_read_unlock();
52571 } else {
52572 inode->i_uid = 0;
52573 @@ -1670,7 +1768,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
52574 int fd = proc_fd(inode);
52575
52576 if (task) {
52577 - files = get_files_struct(task);
52578 + if (!gr_acl_handle_procpidmem(task))
52579 + files = get_files_struct(task);
52580 put_task_struct(task);
52581 }
52582 if (files) {
52583 @@ -1922,12 +2021,22 @@ static const struct file_operations proc_fd_operations = {
52584 static int proc_fd_permission(struct inode *inode, int mask)
52585 {
52586 int rv;
52587 + struct task_struct *task;
52588
52589 rv = generic_permission(inode, mask, NULL);
52590 - if (rv == 0)
52591 - return 0;
52592 +
52593 if (task_pid(current) == proc_pid(inode))
52594 rv = 0;
52595 +
52596 + task = get_proc_task(inode);
52597 + if (task == NULL)
52598 + return rv;
52599 +
52600 + if (gr_acl_handle_procpidmem(task))
52601 + rv = -EACCES;
52602 +
52603 + put_task_struct(task);
52604 +
52605 return rv;
52606 }
52607
52608 @@ -2036,6 +2145,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
52609 if (!task)
52610 goto out_no_task;
52611
52612 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52613 + goto out;
52614 +
52615 /*
52616 * Yes, it does not scale. And it should not. Don't add
52617 * new entries into /proc/<tgid>/ without very good reasons.
52618 @@ -2080,6 +2192,9 @@ static int proc_pident_readdir(struct file *filp,
52619 if (!task)
52620 goto out_no_task;
52621
52622 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52623 + goto out;
52624 +
52625 ret = 0;
52626 i = filp->f_pos;
52627 switch (i) {
52628 @@ -2347,7 +2462,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52629 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52630 void *cookie)
52631 {
52632 - char *s = nd_get_link(nd);
52633 + const char *s = nd_get_link(nd);
52634 if (!IS_ERR(s))
52635 __putname(s);
52636 }
52637 @@ -2553,7 +2668,7 @@ static const struct pid_entry tgid_base_stuff[] = {
52638 #ifdef CONFIG_SCHED_DEBUG
52639 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52640 #endif
52641 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52642 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52643 INF("syscall", S_IRUGO, proc_pid_syscall),
52644 #endif
52645 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52646 @@ -2578,10 +2693,10 @@ static const struct pid_entry tgid_base_stuff[] = {
52647 #ifdef CONFIG_SECURITY
52648 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52649 #endif
52650 -#ifdef CONFIG_KALLSYMS
52651 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52652 INF("wchan", S_IRUGO, proc_pid_wchan),
52653 #endif
52654 -#ifdef CONFIG_STACKTRACE
52655 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52656 ONE("stack", S_IRUGO, proc_pid_stack),
52657 #endif
52658 #ifdef CONFIG_SCHEDSTATS
52659 @@ -2611,6 +2726,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52660 #ifdef CONFIG_TASK_IO_ACCOUNTING
52661 INF("io", S_IRUSR, proc_tgid_io_accounting),
52662 #endif
52663 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52664 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52665 +#endif
52666 };
52667
52668 static int proc_tgid_base_readdir(struct file * filp,
52669 @@ -2735,7 +2853,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52670 if (!inode)
52671 goto out;
52672
52673 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52674 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52675 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52676 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52677 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52678 +#else
52679 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52680 +#endif
52681 inode->i_op = &proc_tgid_base_inode_operations;
52682 inode->i_fop = &proc_tgid_base_operations;
52683 inode->i_flags|=S_IMMUTABLE;
52684 @@ -2777,7 +2902,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
52685 if (!task)
52686 goto out;
52687
52688 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52689 + goto out_put_task;
52690 +
52691 result = proc_pid_instantiate(dir, dentry, task, NULL);
52692 +out_put_task:
52693 put_task_struct(task);
52694 out:
52695 return result;
52696 @@ -2842,6 +2971,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52697 {
52698 unsigned int nr;
52699 struct task_struct *reaper;
52700 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52701 + const struct cred *tmpcred = current_cred();
52702 + const struct cred *itercred;
52703 +#endif
52704 + filldir_t __filldir = filldir;
52705 struct tgid_iter iter;
52706 struct pid_namespace *ns;
52707
52708 @@ -2865,8 +2999,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52709 for (iter = next_tgid(ns, iter);
52710 iter.task;
52711 iter.tgid += 1, iter = next_tgid(ns, iter)) {
52712 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52713 + rcu_read_lock();
52714 + itercred = __task_cred(iter.task);
52715 +#endif
52716 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
52717 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52718 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
52719 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52720 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52721 +#endif
52722 + )
52723 +#endif
52724 + )
52725 + __filldir = &gr_fake_filldir;
52726 + else
52727 + __filldir = filldir;
52728 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52729 + rcu_read_unlock();
52730 +#endif
52731 filp->f_pos = iter.tgid + TGID_OFFSET;
52732 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
52733 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
52734 put_task_struct(iter.task);
52735 goto out;
52736 }
52737 @@ -2892,7 +3045,7 @@ static const struct pid_entry tid_base_stuff[] = {
52738 #ifdef CONFIG_SCHED_DEBUG
52739 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52740 #endif
52741 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52742 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52743 INF("syscall", S_IRUGO, proc_pid_syscall),
52744 #endif
52745 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52746 @@ -2916,10 +3069,10 @@ static const struct pid_entry tid_base_stuff[] = {
52747 #ifdef CONFIG_SECURITY
52748 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52749 #endif
52750 -#ifdef CONFIG_KALLSYMS
52751 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52752 INF("wchan", S_IRUGO, proc_pid_wchan),
52753 #endif
52754 -#ifdef CONFIG_STACKTRACE
52755 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52756 ONE("stack", S_IRUGO, proc_pid_stack),
52757 #endif
52758 #ifdef CONFIG_SCHEDSTATS
52759 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52760 index 82676e3..5f8518a 100644
52761 --- a/fs/proc/cmdline.c
52762 +++ b/fs/proc/cmdline.c
52763 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52764
52765 static int __init proc_cmdline_init(void)
52766 {
52767 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52768 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52769 +#else
52770 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52771 +#endif
52772 return 0;
52773 }
52774 module_init(proc_cmdline_init);
52775 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52776 index 59ee7da..469b4b6 100644
52777 --- a/fs/proc/devices.c
52778 +++ b/fs/proc/devices.c
52779 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52780
52781 static int __init proc_devices_init(void)
52782 {
52783 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52784 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52785 +#else
52786 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52787 +#endif
52788 return 0;
52789 }
52790 module_init(proc_devices_init);
52791 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52792 index d78ade3..81767f9 100644
52793 --- a/fs/proc/inode.c
52794 +++ b/fs/proc/inode.c
52795 @@ -18,12 +18,19 @@
52796 #include <linux/module.h>
52797 #include <linux/smp_lock.h>
52798 #include <linux/sysctl.h>
52799 +#include <linux/grsecurity.h>
52800
52801 #include <asm/system.h>
52802 #include <asm/uaccess.h>
52803
52804 #include "internal.h"
52805
52806 +#ifdef CONFIG_PROC_SYSCTL
52807 +extern const struct inode_operations proc_sys_inode_operations;
52808 +extern const struct inode_operations proc_sys_dir_operations;
52809 +#endif
52810 +
52811 +
52812 struct proc_dir_entry *de_get(struct proc_dir_entry *de)
52813 {
52814 atomic_inc(&de->count);
52815 @@ -62,6 +69,13 @@ static void proc_delete_inode(struct inode *inode)
52816 de_put(de);
52817 if (PROC_I(inode)->sysctl)
52818 sysctl_head_put(PROC_I(inode)->sysctl);
52819 +
52820 +#ifdef CONFIG_PROC_SYSCTL
52821 + if (inode->i_op == &proc_sys_inode_operations ||
52822 + inode->i_op == &proc_sys_dir_operations)
52823 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52824 +#endif
52825 +
52826 clear_inode(inode);
52827 }
52828
52829 @@ -457,7 +471,11 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
52830 if (de->mode) {
52831 inode->i_mode = de->mode;
52832 inode->i_uid = de->uid;
52833 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52834 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52835 +#else
52836 inode->i_gid = de->gid;
52837 +#endif
52838 }
52839 if (de->size)
52840 inode->i_size = de->size;
52841 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52842 index 753ca37..26bcf3b 100644
52843 --- a/fs/proc/internal.h
52844 +++ b/fs/proc/internal.h
52845 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52846 struct pid *pid, struct task_struct *task);
52847 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52848 struct pid *pid, struct task_struct *task);
52849 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52850 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52851 +#endif
52852 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52853
52854 extern const struct file_operations proc_maps_operations;
52855 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52856 index b442dac..aab29cb 100644
52857 --- a/fs/proc/kcore.c
52858 +++ b/fs/proc/kcore.c
52859 @@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
52860 off_t offset = 0;
52861 struct kcore_list *m;
52862
52863 + pax_track_stack();
52864 +
52865 /* setup ELF header */
52866 elf = (struct elfhdr *) bufp;
52867 bufp += sizeof(struct elfhdr);
52868 @@ -477,9 +479,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52869 * the addresses in the elf_phdr on our list.
52870 */
52871 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52872 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52873 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52874 + if (tsz > buflen)
52875 tsz = buflen;
52876 -
52877 +
52878 while (buflen) {
52879 struct kcore_list *m;
52880
52881 @@ -508,20 +511,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52882 kfree(elf_buf);
52883 } else {
52884 if (kern_addr_valid(start)) {
52885 - unsigned long n;
52886 + char *elf_buf;
52887 + mm_segment_t oldfs;
52888
52889 - n = copy_to_user(buffer, (char *)start, tsz);
52890 - /*
52891 - * We cannot distingush between fault on source
52892 - * and fault on destination. When this happens
52893 - * we clear too and hope it will trigger the
52894 - * EFAULT again.
52895 - */
52896 - if (n) {
52897 - if (clear_user(buffer + tsz - n,
52898 - n))
52899 + elf_buf = kmalloc(tsz, GFP_KERNEL);
52900 + if (!elf_buf)
52901 + return -ENOMEM;
52902 + oldfs = get_fs();
52903 + set_fs(KERNEL_DS);
52904 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52905 + set_fs(oldfs);
52906 + if (copy_to_user(buffer, elf_buf, tsz)) {
52907 + kfree(elf_buf);
52908 return -EFAULT;
52909 + }
52910 }
52911 + set_fs(oldfs);
52912 + kfree(elf_buf);
52913 } else {
52914 if (clear_user(buffer, tsz))
52915 return -EFAULT;
52916 @@ -541,6 +547,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52917
52918 static int open_kcore(struct inode *inode, struct file *filp)
52919 {
52920 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52921 + return -EPERM;
52922 +#endif
52923 if (!capable(CAP_SYS_RAWIO))
52924 return -EPERM;
52925 if (kcore_need_update)
52926 diff --git a/fs/proc/kmsg.c b/fs/proc/kmsg.c
52927 index 7ca7834..cfe90a4 100644
52928 --- a/fs/proc/kmsg.c
52929 +++ b/fs/proc/kmsg.c
52930 @@ -12,37 +12,37 @@
52931 #include <linux/poll.h>
52932 #include <linux/proc_fs.h>
52933 #include <linux/fs.h>
52934 +#include <linux/syslog.h>
52935
52936 #include <asm/uaccess.h>
52937 #include <asm/io.h>
52938
52939 extern wait_queue_head_t log_wait;
52940
52941 -extern int do_syslog(int type, char __user *bug, int count);
52942 -
52943 static int kmsg_open(struct inode * inode, struct file * file)
52944 {
52945 - return do_syslog(1,NULL,0);
52946 + return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_FILE);
52947 }
52948
52949 static int kmsg_release(struct inode * inode, struct file * file)
52950 {
52951 - (void) do_syslog(0,NULL,0);
52952 + (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_FILE);
52953 return 0;
52954 }
52955
52956 static ssize_t kmsg_read(struct file *file, char __user *buf,
52957 size_t count, loff_t *ppos)
52958 {
52959 - if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, NULL, 0))
52960 + if ((file->f_flags & O_NONBLOCK) &&
52961 + !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
52962 return -EAGAIN;
52963 - return do_syslog(2, buf, count);
52964 + return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_FILE);
52965 }
52966
52967 static unsigned int kmsg_poll(struct file *file, poll_table *wait)
52968 {
52969 poll_wait(file, &log_wait, wait);
52970 - if (do_syslog(9, NULL, 0))
52971 + if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
52972 return POLLIN | POLLRDNORM;
52973 return 0;
52974 }
52975 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52976 index a65239c..ad1182a 100644
52977 --- a/fs/proc/meminfo.c
52978 +++ b/fs/proc/meminfo.c
52979 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52980 unsigned long pages[NR_LRU_LISTS];
52981 int lru;
52982
52983 + pax_track_stack();
52984 +
52985 /*
52986 * display in kilobytes.
52987 */
52988 @@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52989 vmi.used >> 10,
52990 vmi.largest_chunk >> 10
52991 #ifdef CONFIG_MEMORY_FAILURE
52992 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52993 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52994 #endif
52995 );
52996
52997 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52998 index 9fe7d7e..cdb62c9 100644
52999 --- a/fs/proc/nommu.c
53000 +++ b/fs/proc/nommu.c
53001 @@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
53002 if (len < 1)
53003 len = 1;
53004 seq_printf(m, "%*c", len, ' ');
53005 - seq_path(m, &file->f_path, "");
53006 + seq_path(m, &file->f_path, "\n\\");
53007 }
53008
53009 seq_putc(m, '\n');
53010 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
53011 index 04d1270..25e1173 100644
53012 --- a/fs/proc/proc_net.c
53013 +++ b/fs/proc/proc_net.c
53014 @@ -104,6 +104,17 @@ static struct net *get_proc_task_net(struct inode *dir)
53015 struct task_struct *task;
53016 struct nsproxy *ns;
53017 struct net *net = NULL;
53018 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53019 + const struct cred *cred = current_cred();
53020 +#endif
53021 +
53022 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53023 + if (cred->fsuid)
53024 + return net;
53025 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53026 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
53027 + return net;
53028 +#endif
53029
53030 rcu_read_lock();
53031 task = pid_task(proc_pid(dir), PIDTYPE_PID);
53032 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
53033 index f667e8a..55f4d96 100644
53034 --- a/fs/proc/proc_sysctl.c
53035 +++ b/fs/proc/proc_sysctl.c
53036 @@ -7,11 +7,13 @@
53037 #include <linux/security.h>
53038 #include "internal.h"
53039
53040 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
53041 +
53042 static const struct dentry_operations proc_sys_dentry_operations;
53043 static const struct file_operations proc_sys_file_operations;
53044 -static const struct inode_operations proc_sys_inode_operations;
53045 +const struct inode_operations proc_sys_inode_operations;
53046 static const struct file_operations proc_sys_dir_file_operations;
53047 -static const struct inode_operations proc_sys_dir_operations;
53048 +const struct inode_operations proc_sys_dir_operations;
53049
53050 static struct inode *proc_sys_make_inode(struct super_block *sb,
53051 struct ctl_table_header *head, struct ctl_table *table)
53052 @@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53053 if (!p)
53054 goto out;
53055
53056 + if (gr_handle_sysctl(p, MAY_EXEC))
53057 + goto out;
53058 +
53059 err = ERR_PTR(-ENOMEM);
53060 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
53061 if (h)
53062 @@ -119,6 +124,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53063
53064 err = NULL;
53065 dentry->d_op = &proc_sys_dentry_operations;
53066 +
53067 + gr_handle_proc_create(dentry, inode);
53068 +
53069 d_add(dentry, inode);
53070
53071 out:
53072 @@ -200,6 +208,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
53073 return -ENOMEM;
53074 } else {
53075 child->d_op = &proc_sys_dentry_operations;
53076 +
53077 + gr_handle_proc_create(child, inode);
53078 +
53079 d_add(child, inode);
53080 }
53081 } else {
53082 @@ -228,6 +239,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
53083 if (*pos < file->f_pos)
53084 continue;
53085
53086 + if (gr_handle_sysctl(table, 0))
53087 + continue;
53088 +
53089 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
53090 if (res)
53091 return res;
53092 @@ -344,6 +358,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
53093 if (IS_ERR(head))
53094 return PTR_ERR(head);
53095
53096 + if (table && gr_handle_sysctl(table, MAY_EXEC))
53097 + return -ENOENT;
53098 +
53099 generic_fillattr(inode, stat);
53100 if (table)
53101 stat->mode = (stat->mode & S_IFMT) | table->mode;
53102 @@ -358,17 +375,18 @@ static const struct file_operations proc_sys_file_operations = {
53103 };
53104
53105 static const struct file_operations proc_sys_dir_file_operations = {
53106 + .read = generic_read_dir,
53107 .readdir = proc_sys_readdir,
53108 .llseek = generic_file_llseek,
53109 };
53110
53111 -static const struct inode_operations proc_sys_inode_operations = {
53112 +const struct inode_operations proc_sys_inode_operations = {
53113 .permission = proc_sys_permission,
53114 .setattr = proc_sys_setattr,
53115 .getattr = proc_sys_getattr,
53116 };
53117
53118 -static const struct inode_operations proc_sys_dir_operations = {
53119 +const struct inode_operations proc_sys_dir_operations = {
53120 .lookup = proc_sys_lookup,
53121 .permission = proc_sys_permission,
53122 .setattr = proc_sys_setattr,
53123 diff --git a/fs/proc/root.c b/fs/proc/root.c
53124 index b080b79..d957e63 100644
53125 --- a/fs/proc/root.c
53126 +++ b/fs/proc/root.c
53127 @@ -134,7 +134,15 @@ void __init proc_root_init(void)
53128 #ifdef CONFIG_PROC_DEVICETREE
53129 proc_device_tree_init();
53130 #endif
53131 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
53132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53133 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
53134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53135 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
53136 +#endif
53137 +#else
53138 proc_mkdir("bus", NULL);
53139 +#endif
53140 proc_sys_init();
53141 }
53142
53143 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
53144 index 3b7b82a..7dbb571 100644
53145 --- a/fs/proc/task_mmu.c
53146 +++ b/fs/proc/task_mmu.c
53147 @@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53148 "VmStk:\t%8lu kB\n"
53149 "VmExe:\t%8lu kB\n"
53150 "VmLib:\t%8lu kB\n"
53151 - "VmPTE:\t%8lu kB\n",
53152 - hiwater_vm << (PAGE_SHIFT-10),
53153 + "VmPTE:\t%8lu kB\n"
53154 +
53155 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53156 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
53157 +#endif
53158 +
53159 + ,hiwater_vm << (PAGE_SHIFT-10),
53160 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
53161 mm->locked_vm << (PAGE_SHIFT-10),
53162 hiwater_rss << (PAGE_SHIFT-10),
53163 total_rss << (PAGE_SHIFT-10),
53164 data << (PAGE_SHIFT-10),
53165 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
53166 - (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
53167 + (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
53168 +
53169 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53170 + , mm->context.user_cs_base, mm->context.user_cs_limit
53171 +#endif
53172 +
53173 + );
53174 }
53175
53176 unsigned long task_vsize(struct mm_struct *mm)
53177 @@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, void *v)
53178 struct proc_maps_private *priv = m->private;
53179 struct vm_area_struct *vma = v;
53180
53181 - vma_stop(priv, vma);
53182 + if (!IS_ERR(vma))
53183 + vma_stop(priv, vma);
53184 if (priv->task)
53185 put_task_struct(priv->task);
53186 }
53187 @@ -199,6 +211,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
53188 return ret;
53189 }
53190
53191 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53192 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53193 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53194 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53195 +#endif
53196 +
53197 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53198 {
53199 struct mm_struct *mm = vma->vm_mm;
53200 @@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53201 int flags = vma->vm_flags;
53202 unsigned long ino = 0;
53203 unsigned long long pgoff = 0;
53204 - unsigned long start;
53205 dev_t dev = 0;
53206 int len;
53207
53208 @@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53209 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
53210 }
53211
53212 - /* We don't show the stack guard page in /proc/maps */
53213 - start = vma->vm_start;
53214 - if (vma->vm_flags & VM_GROWSDOWN)
53215 - if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
53216 - start += PAGE_SIZE;
53217 -
53218 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
53219 - start,
53220 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53221 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
53222 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
53223 +#else
53224 + vma->vm_start,
53225 vma->vm_end,
53226 +#endif
53227 flags & VM_READ ? 'r' : '-',
53228 flags & VM_WRITE ? 'w' : '-',
53229 flags & VM_EXEC ? 'x' : '-',
53230 flags & VM_MAYSHARE ? 's' : 'p',
53231 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53232 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
53233 +#else
53234 pgoff,
53235 +#endif
53236 MAJOR(dev), MINOR(dev), ino, &len);
53237
53238 /*
53239 @@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53240 */
53241 if (file) {
53242 pad_len_spaces(m, len);
53243 - seq_path(m, &file->f_path, "\n");
53244 + seq_path(m, &file->f_path, "\n\\");
53245 } else {
53246 const char *name = arch_vma_name(vma);
53247 if (!name) {
53248 @@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53249 if (vma->vm_start <= mm->brk &&
53250 vma->vm_end >= mm->start_brk) {
53251 name = "[heap]";
53252 - } else if (vma->vm_start <= mm->start_stack &&
53253 - vma->vm_end >= mm->start_stack) {
53254 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
53255 + (vma->vm_start <= mm->start_stack &&
53256 + vma->vm_end >= mm->start_stack)) {
53257 name = "[stack]";
53258 }
53259 } else {
53260 @@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m, void *v)
53261 };
53262
53263 memset(&mss, 0, sizeof mss);
53264 - mss.vma = vma;
53265 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53266 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53267 +
53268 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53269 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
53270 +#endif
53271 + mss.vma = vma;
53272 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53273 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53274 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53275 + }
53276 +#endif
53277
53278 show_map_vma(m, vma);
53279
53280 @@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m, void *v)
53281 "Swap: %8lu kB\n"
53282 "KernelPageSize: %8lu kB\n"
53283 "MMUPageSize: %8lu kB\n",
53284 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53285 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
53286 +#else
53287 (vma->vm_end - vma->vm_start) >> 10,
53288 +#endif
53289 mss.resident >> 10,
53290 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
53291 mss.shared_clean >> 10,
53292 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
53293 index 8f5c05d..c99c76d 100644
53294 --- a/fs/proc/task_nommu.c
53295 +++ b/fs/proc/task_nommu.c
53296 @@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53297 else
53298 bytes += kobjsize(mm);
53299
53300 - if (current->fs && current->fs->users > 1)
53301 + if (current->fs && atomic_read(&current->fs->users) > 1)
53302 sbytes += kobjsize(current->fs);
53303 else
53304 bytes += kobjsize(current->fs);
53305 @@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
53306 if (len < 1)
53307 len = 1;
53308 seq_printf(m, "%*c", len, ' ');
53309 - seq_path(m, &file->f_path, "");
53310 + seq_path(m, &file->f_path, "\n\\");
53311 }
53312
53313 seq_putc(m, '\n');
53314 diff --git a/fs/readdir.c b/fs/readdir.c
53315 index 7723401..30059a6 100644
53316 --- a/fs/readdir.c
53317 +++ b/fs/readdir.c
53318 @@ -16,6 +16,7 @@
53319 #include <linux/security.h>
53320 #include <linux/syscalls.h>
53321 #include <linux/unistd.h>
53322 +#include <linux/namei.h>
53323
53324 #include <asm/uaccess.h>
53325
53326 @@ -67,6 +68,7 @@ struct old_linux_dirent {
53327
53328 struct readdir_callback {
53329 struct old_linux_dirent __user * dirent;
53330 + struct file * file;
53331 int result;
53332 };
53333
53334 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
53335 buf->result = -EOVERFLOW;
53336 return -EOVERFLOW;
53337 }
53338 +
53339 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53340 + return 0;
53341 +
53342 buf->result++;
53343 dirent = buf->dirent;
53344 if (!access_ok(VERIFY_WRITE, dirent,
53345 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
53346
53347 buf.result = 0;
53348 buf.dirent = dirent;
53349 + buf.file = file;
53350
53351 error = vfs_readdir(file, fillonedir, &buf);
53352 if (buf.result)
53353 @@ -142,6 +149,7 @@ struct linux_dirent {
53354 struct getdents_callback {
53355 struct linux_dirent __user * current_dir;
53356 struct linux_dirent __user * previous;
53357 + struct file * file;
53358 int count;
53359 int error;
53360 };
53361 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
53362 buf->error = -EOVERFLOW;
53363 return -EOVERFLOW;
53364 }
53365 +
53366 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53367 + return 0;
53368 +
53369 dirent = buf->previous;
53370 if (dirent) {
53371 if (__put_user(offset, &dirent->d_off))
53372 @@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
53373 buf.previous = NULL;
53374 buf.count = count;
53375 buf.error = 0;
53376 + buf.file = file;
53377
53378 error = vfs_readdir(file, filldir, &buf);
53379 if (error >= 0)
53380 @@ -228,6 +241,7 @@ out:
53381 struct getdents_callback64 {
53382 struct linux_dirent64 __user * current_dir;
53383 struct linux_dirent64 __user * previous;
53384 + struct file *file;
53385 int count;
53386 int error;
53387 };
53388 @@ -242,6 +256,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
53389 buf->error = -EINVAL; /* only used if we fail.. */
53390 if (reclen > buf->count)
53391 return -EINVAL;
53392 +
53393 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53394 + return 0;
53395 +
53396 dirent = buf->previous;
53397 if (dirent) {
53398 if (__put_user(offset, &dirent->d_off))
53399 @@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53400
53401 buf.current_dir = dirent;
53402 buf.previous = NULL;
53403 + buf.file = file;
53404 buf.count = count;
53405 buf.error = 0;
53406
53407 @@ -297,7 +316,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53408 error = buf.error;
53409 lastdirent = buf.previous;
53410 if (lastdirent) {
53411 - typeof(lastdirent->d_off) d_off = file->f_pos;
53412 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
53413 if (__put_user(d_off, &lastdirent->d_off))
53414 error = -EFAULT;
53415 else
53416 diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
53417 index d42c30c..4fd8718 100644
53418 --- a/fs/reiserfs/dir.c
53419 +++ b/fs/reiserfs/dir.c
53420 @@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
53421 struct reiserfs_dir_entry de;
53422 int ret = 0;
53423
53424 + pax_track_stack();
53425 +
53426 reiserfs_write_lock(inode->i_sb);
53427
53428 reiserfs_check_lock_depth(inode->i_sb, "readdir");
53429 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
53430 index 128d3f7..8840d44 100644
53431 --- a/fs/reiserfs/do_balan.c
53432 +++ b/fs/reiserfs/do_balan.c
53433 @@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
53434 return;
53435 }
53436
53437 - atomic_inc(&(fs_generation(tb->tb_sb)));
53438 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
53439 do_balance_starts(tb);
53440
53441 /* balance leaf returns 0 except if combining L R and S into
53442 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
53443 index 72cb1cc..d0e3181 100644
53444 --- a/fs/reiserfs/item_ops.c
53445 +++ b/fs/reiserfs/item_ops.c
53446 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_item *vi)
53447 vi->vi_index, vi->vi_type, vi->vi_ih);
53448 }
53449
53450 -static struct item_operations stat_data_ops = {
53451 +static const struct item_operations stat_data_ops = {
53452 .bytes_number = sd_bytes_number,
53453 .decrement_key = sd_decrement_key,
53454 .is_left_mergeable = sd_is_left_mergeable,
53455 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtual_item *vi)
53456 vi->vi_index, vi->vi_type, vi->vi_ih);
53457 }
53458
53459 -static struct item_operations direct_ops = {
53460 +static const struct item_operations direct_ops = {
53461 .bytes_number = direct_bytes_number,
53462 .decrement_key = direct_decrement_key,
53463 .is_left_mergeable = direct_is_left_mergeable,
53464 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct virtual_item *vi)
53465 vi->vi_index, vi->vi_type, vi->vi_ih);
53466 }
53467
53468 -static struct item_operations indirect_ops = {
53469 +static const struct item_operations indirect_ops = {
53470 .bytes_number = indirect_bytes_number,
53471 .decrement_key = indirect_decrement_key,
53472 .is_left_mergeable = indirect_is_left_mergeable,
53473 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct virtual_item *vi)
53474 printk("\n");
53475 }
53476
53477 -static struct item_operations direntry_ops = {
53478 +static const struct item_operations direntry_ops = {
53479 .bytes_number = direntry_bytes_number,
53480 .decrement_key = direntry_decrement_key,
53481 .is_left_mergeable = direntry_is_left_mergeable,
53482 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct virtual_item *vi)
53483 "Invalid item type observed, run fsck ASAP");
53484 }
53485
53486 -static struct item_operations errcatch_ops = {
53487 +static const struct item_operations errcatch_ops = {
53488 errcatch_bytes_number,
53489 errcatch_decrement_key,
53490 errcatch_is_left_mergeable,
53491 @@ -746,7 +746,7 @@ static struct item_operations errcatch_ops = {
53492 #error Item types must use disk-format assigned values.
53493 #endif
53494
53495 -struct item_operations *item_ops[TYPE_ANY + 1] = {
53496 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
53497 &stat_data_ops,
53498 &indirect_ops,
53499 &direct_ops,
53500 diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
53501 index b5fe0aa..e0e25c4 100644
53502 --- a/fs/reiserfs/journal.c
53503 +++ b/fs/reiserfs/journal.c
53504 @@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
53505 struct buffer_head *bh;
53506 int i, j;
53507
53508 + pax_track_stack();
53509 +
53510 bh = __getblk(dev, block, bufsize);
53511 if (buffer_uptodate(bh))
53512 return (bh);
53513 diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
53514 index 2715791..b8996db 100644
53515 --- a/fs/reiserfs/namei.c
53516 +++ b/fs/reiserfs/namei.c
53517 @@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
53518 unsigned long savelink = 1;
53519 struct timespec ctime;
53520
53521 + pax_track_stack();
53522 +
53523 /* three balancings: (1) old name removal, (2) new name insertion
53524 and (3) maybe "save" link insertion
53525 stat data updates: (1) old directory,
53526 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
53527 index 9229e55..3d2e3b7 100644
53528 --- a/fs/reiserfs/procfs.c
53529 +++ b/fs/reiserfs/procfs.c
53530 @@ -123,7 +123,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
53531 "SMALL_TAILS " : "NO_TAILS ",
53532 replay_only(sb) ? "REPLAY_ONLY " : "",
53533 convert_reiserfs(sb) ? "CONV " : "",
53534 - atomic_read(&r->s_generation_counter),
53535 + atomic_read_unchecked(&r->s_generation_counter),
53536 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
53537 SF(s_do_balance), SF(s_unneeded_left_neighbor),
53538 SF(s_good_search_by_key_reada), SF(s_bmaps),
53539 @@ -309,6 +309,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
53540 struct journal_params *jp = &rs->s_v1.s_journal;
53541 char b[BDEVNAME_SIZE];
53542
53543 + pax_track_stack();
53544 +
53545 seq_printf(m, /* on-disk fields */
53546 "jp_journal_1st_block: \t%i\n"
53547 "jp_journal_dev: \t%s[%x]\n"
53548 diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
53549 index d036ee5..4c7dca1 100644
53550 --- a/fs/reiserfs/stree.c
53551 +++ b/fs/reiserfs/stree.c
53552 @@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
53553 int iter = 0;
53554 #endif
53555
53556 + pax_track_stack();
53557 +
53558 BUG_ON(!th->t_trans_id);
53559
53560 init_tb_struct(th, &s_del_balance, sb, path,
53561 @@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
53562 int retval;
53563 int quota_cut_bytes = 0;
53564
53565 + pax_track_stack();
53566 +
53567 BUG_ON(!th->t_trans_id);
53568
53569 le_key2cpu_key(&cpu_key, key);
53570 @@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
53571 int quota_cut_bytes;
53572 loff_t tail_pos = 0;
53573
53574 + pax_track_stack();
53575 +
53576 BUG_ON(!th->t_trans_id);
53577
53578 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
53579 @@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
53580 int retval;
53581 int fs_gen;
53582
53583 + pax_track_stack();
53584 +
53585 BUG_ON(!th->t_trans_id);
53586
53587 fs_gen = get_generation(inode->i_sb);
53588 @@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
53589 int fs_gen = 0;
53590 int quota_bytes = 0;
53591
53592 + pax_track_stack();
53593 +
53594 BUG_ON(!th->t_trans_id);
53595
53596 if (inode) { /* Do we count quotas for item? */
53597 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
53598 index f0ad05f..af3306f 100644
53599 --- a/fs/reiserfs/super.c
53600 +++ b/fs/reiserfs/super.c
53601 @@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
53602 {.option_name = NULL}
53603 };
53604
53605 + pax_track_stack();
53606 +
53607 *blocks = 0;
53608 if (!options || !*options)
53609 /* use default configuration: create tails, journaling on, no
53610 diff --git a/fs/select.c b/fs/select.c
53611 index fd38ce2..f5381b8 100644
53612 --- a/fs/select.c
53613 +++ b/fs/select.c
53614 @@ -20,6 +20,7 @@
53615 #include <linux/module.h>
53616 #include <linux/slab.h>
53617 #include <linux/poll.h>
53618 +#include <linux/security.h>
53619 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
53620 #include <linux/file.h>
53621 #include <linux/fdtable.h>
53622 @@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
53623 int retval, i, timed_out = 0;
53624 unsigned long slack = 0;
53625
53626 + pax_track_stack();
53627 +
53628 rcu_read_lock();
53629 retval = max_select_fd(n, fds);
53630 rcu_read_unlock();
53631 @@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
53632 /* Allocate small arguments on the stack to save memory and be faster */
53633 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
53634
53635 + pax_track_stack();
53636 +
53637 ret = -EINVAL;
53638 if (n < 0)
53639 goto out_nofds;
53640 @@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
53641 struct poll_list *walk = head;
53642 unsigned long todo = nfds;
53643
53644 + pax_track_stack();
53645 +
53646 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
53647 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
53648 return -EINVAL;
53649
53650 diff --git a/fs/seq_file.c b/fs/seq_file.c
53651 index eae7d9d..679f099 100644
53652 --- a/fs/seq_file.c
53653 +++ b/fs/seq_file.c
53654 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53655 return 0;
53656 }
53657 if (!m->buf) {
53658 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53659 + m->size = PAGE_SIZE;
53660 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53661 if (!m->buf)
53662 return -ENOMEM;
53663 }
53664 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53665 Eoverflow:
53666 m->op->stop(m, p);
53667 kfree(m->buf);
53668 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53669 + m->size <<= 1;
53670 + m->buf = kmalloc(m->size, GFP_KERNEL);
53671 return !m->buf ? -ENOMEM : -EAGAIN;
53672 }
53673
53674 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53675 m->version = file->f_version;
53676 /* grab buffer if we didn't have one */
53677 if (!m->buf) {
53678 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53679 + m->size = PAGE_SIZE;
53680 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53681 if (!m->buf)
53682 goto Enomem;
53683 }
53684 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53685 goto Fill;
53686 m->op->stop(m, p);
53687 kfree(m->buf);
53688 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53689 + m->size <<= 1;
53690 + m->buf = kmalloc(m->size, GFP_KERNEL);
53691 if (!m->buf)
53692 goto Enomem;
53693 m->count = 0;
53694 @@ -551,7 +555,7 @@ static void single_stop(struct seq_file *p, void *v)
53695 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
53696 void *data)
53697 {
53698 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
53699 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
53700 int res = -ENOMEM;
53701
53702 if (op) {
53703 diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
53704 index 71c29b6..54694dd 100644
53705 --- a/fs/smbfs/proc.c
53706 +++ b/fs/smbfs/proc.c
53707 @@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *server, struct smb_nls_codepage *cp)
53708
53709 out:
53710 if (server->local_nls != NULL && server->remote_nls != NULL)
53711 - server->ops->convert = convert_cp;
53712 + *(void **)&server->ops->convert = convert_cp;
53713 else
53714 - server->ops->convert = convert_memcpy;
53715 + *(void **)&server->ops->convert = convert_memcpy;
53716
53717 smb_unlock_server(server);
53718 return n;
53719 @@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
53720
53721 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
53722 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
53723 - server->ops->getattr = smb_proc_getattr_core;
53724 + *(void **)&server->ops->getattr = smb_proc_getattr_core;
53725 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
53726 - server->ops->getattr = smb_proc_getattr_ff;
53727 + *(void **)&server->ops->getattr = smb_proc_getattr_ff;
53728 }
53729
53730 /* Decode server capabilities */
53731 @@ -3439,7 +3439,7 @@ out:
53732 static void
53733 install_ops(struct smb_ops *dst, struct smb_ops *src)
53734 {
53735 - memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53736 + memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53737 }
53738
53739 /* < LANMAN2 */
53740 diff --git a/fs/smbfs/symlink.c b/fs/smbfs/symlink.c
53741 index 00b2909..2ace383 100644
53742 --- a/fs/smbfs/symlink.c
53743 +++ b/fs/smbfs/symlink.c
53744 @@ -55,7 +55,7 @@ static void *smb_follow_link(struct dentry *dentry, struct nameidata *nd)
53745
53746 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53747 {
53748 - char *s = nd_get_link(nd);
53749 + const char *s = nd_get_link(nd);
53750 if (!IS_ERR(s))
53751 __putname(s);
53752 }
53753 diff --git a/fs/splice.c b/fs/splice.c
53754 index bb92b7c..5aa72b0 100644
53755 --- a/fs/splice.c
53756 +++ b/fs/splice.c
53757 @@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
53758 pipe_lock(pipe);
53759
53760 for (;;) {
53761 - if (!pipe->readers) {
53762 + if (!atomic_read(&pipe->readers)) {
53763 send_sig(SIGPIPE, current, 0);
53764 if (!ret)
53765 ret = -EPIPE;
53766 @@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
53767 do_wakeup = 0;
53768 }
53769
53770 - pipe->waiting_writers++;
53771 + atomic_inc(&pipe->waiting_writers);
53772 pipe_wait(pipe);
53773 - pipe->waiting_writers--;
53774 + atomic_dec(&pipe->waiting_writers);
53775 }
53776
53777 pipe_unlock(pipe);
53778 @@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
53779 .spd_release = spd_release_page,
53780 };
53781
53782 + pax_track_stack();
53783 +
53784 index = *ppos >> PAGE_CACHE_SHIFT;
53785 loff = *ppos & ~PAGE_CACHE_MASK;
53786 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
53787 @@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
53788 old_fs = get_fs();
53789 set_fs(get_ds());
53790 /* The cast to a user pointer is valid due to the set_fs() */
53791 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
53792 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
53793 set_fs(old_fs);
53794
53795 return res;
53796 @@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
53797 old_fs = get_fs();
53798 set_fs(get_ds());
53799 /* The cast to a user pointer is valid due to the set_fs() */
53800 - res = vfs_write(file, (const char __user *)buf, count, &pos);
53801 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
53802 set_fs(old_fs);
53803
53804 return res;
53805 @@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53806 .spd_release = spd_release_page,
53807 };
53808
53809 + pax_track_stack();
53810 +
53811 index = *ppos >> PAGE_CACHE_SHIFT;
53812 offset = *ppos & ~PAGE_CACHE_MASK;
53813 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
53814 @@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53815 goto err;
53816
53817 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
53818 - vec[i].iov_base = (void __user *) page_address(page);
53819 + vec[i].iov_base = (__force void __user *) page_address(page);
53820 vec[i].iov_len = this_len;
53821 pages[i] = page;
53822 spd.nr_pages++;
53823 @@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
53824 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
53825 {
53826 while (!pipe->nrbufs) {
53827 - if (!pipe->writers)
53828 + if (!atomic_read(&pipe->writers))
53829 return 0;
53830
53831 - if (!pipe->waiting_writers && sd->num_spliced)
53832 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
53833 return 0;
53834
53835 if (sd->flags & SPLICE_F_NONBLOCK)
53836 @@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
53837 * out of the pipe right after the splice_to_pipe(). So set
53838 * PIPE_READERS appropriately.
53839 */
53840 - pipe->readers = 1;
53841 + atomic_set(&pipe->readers, 1);
53842
53843 current->splice_pipe = pipe;
53844 }
53845 @@ -1593,6 +1597,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
53846 .spd_release = spd_release_page,
53847 };
53848
53849 + pax_track_stack();
53850 +
53851 pipe = pipe_info(file->f_path.dentry->d_inode);
53852 if (!pipe)
53853 return -EBADF;
53854 @@ -1701,9 +1707,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53855 ret = -ERESTARTSYS;
53856 break;
53857 }
53858 - if (!pipe->writers)
53859 + if (!atomic_read(&pipe->writers))
53860 break;
53861 - if (!pipe->waiting_writers) {
53862 + if (!atomic_read(&pipe->waiting_writers)) {
53863 if (flags & SPLICE_F_NONBLOCK) {
53864 ret = -EAGAIN;
53865 break;
53866 @@ -1735,7 +1741,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53867 pipe_lock(pipe);
53868
53869 while (pipe->nrbufs >= PIPE_BUFFERS) {
53870 - if (!pipe->readers) {
53871 + if (!atomic_read(&pipe->readers)) {
53872 send_sig(SIGPIPE, current, 0);
53873 ret = -EPIPE;
53874 break;
53875 @@ -1748,9 +1754,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53876 ret = -ERESTARTSYS;
53877 break;
53878 }
53879 - pipe->waiting_writers++;
53880 + atomic_inc(&pipe->waiting_writers);
53881 pipe_wait(pipe);
53882 - pipe->waiting_writers--;
53883 + atomic_dec(&pipe->waiting_writers);
53884 }
53885
53886 pipe_unlock(pipe);
53887 @@ -1786,14 +1792,14 @@ retry:
53888 pipe_double_lock(ipipe, opipe);
53889
53890 do {
53891 - if (!opipe->readers) {
53892 + if (!atomic_read(&opipe->readers)) {
53893 send_sig(SIGPIPE, current, 0);
53894 if (!ret)
53895 ret = -EPIPE;
53896 break;
53897 }
53898
53899 - if (!ipipe->nrbufs && !ipipe->writers)
53900 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53901 break;
53902
53903 /*
53904 @@ -1893,7 +1899,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53905 pipe_double_lock(ipipe, opipe);
53906
53907 do {
53908 - if (!opipe->readers) {
53909 + if (!atomic_read(&opipe->readers)) {
53910 send_sig(SIGPIPE, current, 0);
53911 if (!ret)
53912 ret = -EPIPE;
53913 @@ -1938,7 +1944,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53914 * return EAGAIN if we have the potential of some data in the
53915 * future, otherwise just return 0
53916 */
53917 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53918 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53919 ret = -EAGAIN;
53920
53921 pipe_unlock(ipipe);
53922 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53923 index 7118a38..70af853 100644
53924 --- a/fs/sysfs/file.c
53925 +++ b/fs/sysfs/file.c
53926 @@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53927
53928 struct sysfs_open_dirent {
53929 atomic_t refcnt;
53930 - atomic_t event;
53931 + atomic_unchecked_t event;
53932 wait_queue_head_t poll;
53933 struct list_head buffers; /* goes through sysfs_buffer.list */
53934 };
53935 @@ -53,7 +53,7 @@ struct sysfs_buffer {
53936 size_t count;
53937 loff_t pos;
53938 char * page;
53939 - struct sysfs_ops * ops;
53940 + const struct sysfs_ops * ops;
53941 struct mutex mutex;
53942 int needs_read_fill;
53943 int event;
53944 @@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53945 {
53946 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
53947 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53948 - struct sysfs_ops * ops = buffer->ops;
53949 + const struct sysfs_ops * ops = buffer->ops;
53950 int ret = 0;
53951 ssize_t count;
53952
53953 @@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53954 if (!sysfs_get_active_two(attr_sd))
53955 return -ENODEV;
53956
53957 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53958 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53959 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53960
53961 sysfs_put_active_two(attr_sd);
53962 @@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
53963 {
53964 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
53965 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53966 - struct sysfs_ops * ops = buffer->ops;
53967 + const struct sysfs_ops * ops = buffer->ops;
53968 int rc;
53969
53970 /* need attr_sd for attr and ops, its parent for kobj */
53971 @@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53972 return -ENOMEM;
53973
53974 atomic_set(&new_od->refcnt, 0);
53975 - atomic_set(&new_od->event, 1);
53976 + atomic_set_unchecked(&new_od->event, 1);
53977 init_waitqueue_head(&new_od->poll);
53978 INIT_LIST_HEAD(&new_od->buffers);
53979 goto retry;
53980 @@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
53981 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
53982 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53983 struct sysfs_buffer *buffer;
53984 - struct sysfs_ops *ops;
53985 + const struct sysfs_ops *ops;
53986 int error = -EACCES;
53987 char *p;
53988
53989 @@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53990
53991 sysfs_put_active_two(attr_sd);
53992
53993 - if (buffer->event != atomic_read(&od->event))
53994 + if (buffer->event != atomic_read_unchecked(&od->event))
53995 goto trigger;
53996
53997 return DEFAULT_POLLMASK;
53998 @@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53999
54000 od = sd->s_attr.open;
54001 if (od) {
54002 - atomic_inc(&od->event);
54003 + atomic_inc_unchecked(&od->event);
54004 wake_up_interruptible(&od->poll);
54005 }
54006
54007 diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
54008 index 4974995..c26609c 100644
54009 --- a/fs/sysfs/mount.c
54010 +++ b/fs/sysfs/mount.c
54011 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
54012 .s_name = "",
54013 .s_count = ATOMIC_INIT(1),
54014 .s_flags = SYSFS_DIR,
54015 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54016 + .s_mode = S_IFDIR | S_IRWXU,
54017 +#else
54018 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54019 +#endif
54020 .s_ino = 1,
54021 };
54022
54023 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
54024 index c5081ad..342ea86 100644
54025 --- a/fs/sysfs/symlink.c
54026 +++ b/fs/sysfs/symlink.c
54027 @@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54028
54029 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
54030 {
54031 - char *page = nd_get_link(nd);
54032 + const char *page = nd_get_link(nd);
54033 if (!IS_ERR(page))
54034 free_page((unsigned long)page);
54035 }
54036 diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
54037 index 1e06853..b06d325 100644
54038 --- a/fs/udf/balloc.c
54039 +++ b/fs/udf/balloc.c
54040 @@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
54041
54042 mutex_lock(&sbi->s_alloc_mutex);
54043 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54044 - if (bloc->logicalBlockNum < 0 ||
54045 - (bloc->logicalBlockNum + count) >
54046 - partmap->s_partition_len) {
54047 + if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54048 udf_debug("%d < %d || %d + %d > %d\n",
54049 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
54050 count, partmap->s_partition_len);
54051 @@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct super_block *sb,
54052
54053 mutex_lock(&sbi->s_alloc_mutex);
54054 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54055 - if (bloc->logicalBlockNum < 0 ||
54056 - (bloc->logicalBlockNum + count) >
54057 - partmap->s_partition_len) {
54058 + if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54059 udf_debug("%d < %d || %d + %d > %d\n",
54060 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
54061 partmap->s_partition_len);
54062 diff --git a/fs/udf/inode.c b/fs/udf/inode.c
54063 index 6d24c2c..fff470f 100644
54064 --- a/fs/udf/inode.c
54065 +++ b/fs/udf/inode.c
54066 @@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
54067 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
54068 int lastblock = 0;
54069
54070 + pax_track_stack();
54071 +
54072 prev_epos.offset = udf_file_entry_alloc_offset(inode);
54073 prev_epos.block = iinfo->i_location;
54074 prev_epos.bh = NULL;
54075 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
54076 index 9215700..bf1f68e 100644
54077 --- a/fs/udf/misc.c
54078 +++ b/fs/udf/misc.c
54079 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
54080
54081 u8 udf_tag_checksum(const struct tag *t)
54082 {
54083 - u8 *data = (u8 *)t;
54084 + const u8 *data = (const u8 *)t;
54085 u8 checksum = 0;
54086 int i;
54087 for (i = 0; i < sizeof(struct tag); ++i)
54088 diff --git a/fs/utimes.c b/fs/utimes.c
54089 index e4c75db..b4df0e0 100644
54090 --- a/fs/utimes.c
54091 +++ b/fs/utimes.c
54092 @@ -1,6 +1,7 @@
54093 #include <linux/compiler.h>
54094 #include <linux/file.h>
54095 #include <linux/fs.h>
54096 +#include <linux/security.h>
54097 #include <linux/linkage.h>
54098 #include <linux/mount.h>
54099 #include <linux/namei.h>
54100 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
54101 goto mnt_drop_write_and_out;
54102 }
54103 }
54104 +
54105 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
54106 + error = -EACCES;
54107 + goto mnt_drop_write_and_out;
54108 + }
54109 +
54110 mutex_lock(&inode->i_mutex);
54111 error = notify_change(path->dentry, &newattrs);
54112 mutex_unlock(&inode->i_mutex);
54113 diff --git a/fs/xattr.c b/fs/xattr.c
54114 index 6d4f6d3..cda3958 100644
54115 --- a/fs/xattr.c
54116 +++ b/fs/xattr.c
54117 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
54118 * Extended attribute SET operations
54119 */
54120 static long
54121 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
54122 +setxattr(struct path *path, const char __user *name, const void __user *value,
54123 size_t size, int flags)
54124 {
54125 int error;
54126 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
54127 return PTR_ERR(kvalue);
54128 }
54129
54130 - error = vfs_setxattr(d, kname, kvalue, size, flags);
54131 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
54132 + error = -EACCES;
54133 + goto out;
54134 + }
54135 +
54136 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
54137 +out:
54138 kfree(kvalue);
54139 return error;
54140 }
54141 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
54142 return error;
54143 error = mnt_want_write(path.mnt);
54144 if (!error) {
54145 - error = setxattr(path.dentry, name, value, size, flags);
54146 + error = setxattr(&path, name, value, size, flags);
54147 mnt_drop_write(path.mnt);
54148 }
54149 path_put(&path);
54150 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
54151 return error;
54152 error = mnt_want_write(path.mnt);
54153 if (!error) {
54154 - error = setxattr(path.dentry, name, value, size, flags);
54155 + error = setxattr(&path, name, value, size, flags);
54156 mnt_drop_write(path.mnt);
54157 }
54158 path_put(&path);
54159 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
54160 const void __user *,value, size_t, size, int, flags)
54161 {
54162 struct file *f;
54163 - struct dentry *dentry;
54164 int error = -EBADF;
54165
54166 f = fget(fd);
54167 if (!f)
54168 return error;
54169 - dentry = f->f_path.dentry;
54170 - audit_inode(NULL, dentry);
54171 + audit_inode(NULL, f->f_path.dentry);
54172 error = mnt_want_write_file(f);
54173 if (!error) {
54174 - error = setxattr(dentry, name, value, size, flags);
54175 + error = setxattr(&f->f_path, name, value, size, flags);
54176 mnt_drop_write(f->f_path.mnt);
54177 }
54178 fput(f);
54179 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
54180 index c6ad7c7..f2847a7 100644
54181 --- a/fs/xattr_acl.c
54182 +++ b/fs/xattr_acl.c
54183 @@ -17,8 +17,8 @@
54184 struct posix_acl *
54185 posix_acl_from_xattr(const void *value, size_t size)
54186 {
54187 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
54188 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
54189 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
54190 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
54191 int count;
54192 struct posix_acl *acl;
54193 struct posix_acl_entry *acl_e;
54194 diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
54195 index 942362f..88f96f5 100644
54196 --- a/fs/xfs/linux-2.6/xfs_ioctl.c
54197 +++ b/fs/xfs/linux-2.6/xfs_ioctl.c
54198 @@ -134,7 +134,7 @@ xfs_find_handle(
54199 }
54200
54201 error = -EFAULT;
54202 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
54203 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
54204 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
54205 goto out_put;
54206
54207 @@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
54208 if (IS_ERR(dentry))
54209 return PTR_ERR(dentry);
54210
54211 - kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
54212 + kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
54213 if (!kbuf)
54214 goto out_dput;
54215
54216 @@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
54217 xfs_mount_t *mp,
54218 void __user *arg)
54219 {
54220 - xfs_fsop_geom_t fsgeo;
54221 + xfs_fsop_geom_t fsgeo;
54222 int error;
54223
54224 error = xfs_fs_geometry(mp, &fsgeo, 3);
54225 diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
54226 index bad485a..479bd32 100644
54227 --- a/fs/xfs/linux-2.6/xfs_ioctl32.c
54228 +++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
54229 @@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
54230 xfs_fsop_geom_t fsgeo;
54231 int error;
54232
54233 + memset(&fsgeo, 0, sizeof(fsgeo));
54234 error = xfs_fs_geometry(mp, &fsgeo, 3);
54235 if (error)
54236 return -error;
54237 diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
54238 index 1f3b4b8..6102f6d 100644
54239 --- a/fs/xfs/linux-2.6/xfs_iops.c
54240 +++ b/fs/xfs/linux-2.6/xfs_iops.c
54241 @@ -468,7 +468,7 @@ xfs_vn_put_link(
54242 struct nameidata *nd,
54243 void *p)
54244 {
54245 - char *s = nd_get_link(nd);
54246 + const char *s = nd_get_link(nd);
54247
54248 if (!IS_ERR(s))
54249 kfree(s);
54250 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
54251 index 8971fb0..5fc1eb2 100644
54252 --- a/fs/xfs/xfs_bmap.c
54253 +++ b/fs/xfs/xfs_bmap.c
54254 @@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
54255 int nmap,
54256 int ret_nmap);
54257 #else
54258 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
54259 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
54260 #endif /* DEBUG */
54261
54262 #if defined(XFS_RW_TRACE)
54263 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
54264 index e89734e..5e84d8d 100644
54265 --- a/fs/xfs/xfs_dir2_sf.c
54266 +++ b/fs/xfs/xfs_dir2_sf.c
54267 @@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
54268 }
54269
54270 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
54271 - if (filldir(dirent, sfep->name, sfep->namelen,
54272 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
54273 + char name[sfep->namelen];
54274 + memcpy(name, sfep->name, sfep->namelen);
54275 + if (filldir(dirent, name, sfep->namelen,
54276 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
54277 + *offset = off & 0x7fffffff;
54278 + return 0;
54279 + }
54280 + } else if (filldir(dirent, sfep->name, sfep->namelen,
54281 off & 0x7fffffff, ino, DT_UNKNOWN)) {
54282 *offset = off & 0x7fffffff;
54283 return 0;
54284 diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
54285 index 8f32f50..859e8a3 100644
54286 --- a/fs/xfs/xfs_vnodeops.c
54287 +++ b/fs/xfs/xfs_vnodeops.c
54288 @@ -564,13 +564,17 @@ xfs_readlink(
54289
54290 xfs_ilock(ip, XFS_ILOCK_SHARED);
54291
54292 - ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFLNK);
54293 - ASSERT(ip->i_d.di_size <= MAXPATHLEN);
54294 -
54295 pathlen = ip->i_d.di_size;
54296 if (!pathlen)
54297 goto out;
54298
54299 + if (pathlen > MAXPATHLEN) {
54300 + xfs_fs_cmn_err(CE_ALERT, mp, "%s: inode (%llu) symlink length (%d) too long",
54301 + __func__, (unsigned long long)ip->i_ino, pathlen);
54302 + ASSERT(0);
54303 + return XFS_ERROR(EFSCORRUPTED);
54304 + }
54305 +
54306 if (ip->i_df.if_flags & XFS_IFINLINE) {
54307 memcpy(link, ip->i_df.if_u1.if_data, pathlen);
54308 link[pathlen] = '\0';
54309 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
54310 new file mode 100644
54311 index 0000000..f27a8e8
54312 --- /dev/null
54313 +++ b/grsecurity/Kconfig
54314 @@ -0,0 +1,1036 @@
54315 +#
54316 +# grecurity configuration
54317 +#
54318 +
54319 +menu "Grsecurity"
54320 +
54321 +config GRKERNSEC
54322 + bool "Grsecurity"
54323 + select CRYPTO
54324 + select CRYPTO_SHA256
54325 + help
54326 + If you say Y here, you will be able to configure many features
54327 + that will enhance the security of your system. It is highly
54328 + recommended that you say Y here and read through the help
54329 + for each option so that you fully understand the features and
54330 + can evaluate their usefulness for your machine.
54331 +
54332 +choice
54333 + prompt "Security Level"
54334 + depends on GRKERNSEC
54335 + default GRKERNSEC_CUSTOM
54336 +
54337 +config GRKERNSEC_LOW
54338 + bool "Low"
54339 + select GRKERNSEC_LINK
54340 + select GRKERNSEC_FIFO
54341 + select GRKERNSEC_RANDNET
54342 + select GRKERNSEC_DMESG
54343 + select GRKERNSEC_CHROOT
54344 + select GRKERNSEC_CHROOT_CHDIR
54345 +
54346 + help
54347 + If you choose this option, several of the grsecurity options will
54348 + be enabled that will give you greater protection against a number
54349 + of attacks, while assuring that none of your software will have any
54350 + conflicts with the additional security measures. If you run a lot
54351 + of unusual software, or you are having problems with the higher
54352 + security levels, you should say Y here. With this option, the
54353 + following features are enabled:
54354 +
54355 + - Linking restrictions
54356 + - FIFO restrictions
54357 + - Restricted dmesg
54358 + - Enforced chdir("/") on chroot
54359 + - Runtime module disabling
54360 +
54361 +config GRKERNSEC_MEDIUM
54362 + bool "Medium"
54363 + select PAX
54364 + select PAX_EI_PAX
54365 + select PAX_PT_PAX_FLAGS
54366 + select PAX_HAVE_ACL_FLAGS
54367 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54368 + select GRKERNSEC_CHROOT
54369 + select GRKERNSEC_CHROOT_SYSCTL
54370 + select GRKERNSEC_LINK
54371 + select GRKERNSEC_FIFO
54372 + select GRKERNSEC_DMESG
54373 + select GRKERNSEC_RANDNET
54374 + select GRKERNSEC_FORKFAIL
54375 + select GRKERNSEC_TIME
54376 + select GRKERNSEC_SIGNAL
54377 + select GRKERNSEC_CHROOT
54378 + select GRKERNSEC_CHROOT_UNIX
54379 + select GRKERNSEC_CHROOT_MOUNT
54380 + select GRKERNSEC_CHROOT_PIVOT
54381 + select GRKERNSEC_CHROOT_DOUBLE
54382 + select GRKERNSEC_CHROOT_CHDIR
54383 + select GRKERNSEC_CHROOT_MKNOD
54384 + select GRKERNSEC_PROC
54385 + select GRKERNSEC_PROC_USERGROUP
54386 + select PAX_RANDUSTACK
54387 + select PAX_ASLR
54388 + select PAX_RANDMMAP
54389 + select PAX_REFCOUNT if (X86 || SPARC64)
54390 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54391 +
54392 + help
54393 + If you say Y here, several features in addition to those included
54394 + in the low additional security level will be enabled. These
54395 + features provide even more security to your system, though in rare
54396 + cases they may be incompatible with very old or poorly written
54397 + software. If you enable this option, make sure that your auth
54398 + service (identd) is running as gid 1001. With this option,
54399 + the following features (in addition to those provided in the
54400 + low additional security level) will be enabled:
54401 +
54402 + - Failed fork logging
54403 + - Time change logging
54404 + - Signal logging
54405 + - Deny mounts in chroot
54406 + - Deny double chrooting
54407 + - Deny sysctl writes in chroot
54408 + - Deny mknod in chroot
54409 + - Deny access to abstract AF_UNIX sockets out of chroot
54410 + - Deny pivot_root in chroot
54411 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
54412 + - /proc restrictions with special GID set to 10 (usually wheel)
54413 + - Address Space Layout Randomization (ASLR)
54414 + - Prevent exploitation of most refcount overflows
54415 + - Bounds checking of copying between the kernel and userland
54416 +
54417 +config GRKERNSEC_HIGH
54418 + bool "High"
54419 + select GRKERNSEC_LINK
54420 + select GRKERNSEC_FIFO
54421 + select GRKERNSEC_DMESG
54422 + select GRKERNSEC_FORKFAIL
54423 + select GRKERNSEC_TIME
54424 + select GRKERNSEC_SIGNAL
54425 + select GRKERNSEC_CHROOT
54426 + select GRKERNSEC_CHROOT_SHMAT
54427 + select GRKERNSEC_CHROOT_UNIX
54428 + select GRKERNSEC_CHROOT_MOUNT
54429 + select GRKERNSEC_CHROOT_FCHDIR
54430 + select GRKERNSEC_CHROOT_PIVOT
54431 + select GRKERNSEC_CHROOT_DOUBLE
54432 + select GRKERNSEC_CHROOT_CHDIR
54433 + select GRKERNSEC_CHROOT_MKNOD
54434 + select GRKERNSEC_CHROOT_CAPS
54435 + select GRKERNSEC_CHROOT_SYSCTL
54436 + select GRKERNSEC_CHROOT_FINDTASK
54437 + select GRKERNSEC_SYSFS_RESTRICT
54438 + select GRKERNSEC_PROC
54439 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54440 + select GRKERNSEC_HIDESYM
54441 + select GRKERNSEC_BRUTE
54442 + select GRKERNSEC_PROC_USERGROUP
54443 + select GRKERNSEC_KMEM
54444 + select GRKERNSEC_RESLOG
54445 + select GRKERNSEC_RANDNET
54446 + select GRKERNSEC_PROC_ADD
54447 + select GRKERNSEC_CHROOT_CHMOD
54448 + select GRKERNSEC_CHROOT_NICE
54449 + select GRKERNSEC_AUDIT_MOUNT
54450 + select GRKERNSEC_MODHARDEN if (MODULES)
54451 + select GRKERNSEC_HARDEN_PTRACE
54452 + select GRKERNSEC_VM86 if (X86_32)
54453 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
54454 + select PAX
54455 + select PAX_RANDUSTACK
54456 + select PAX_ASLR
54457 + select PAX_RANDMMAP
54458 + select PAX_NOEXEC
54459 + select PAX_MPROTECT
54460 + select PAX_EI_PAX
54461 + select PAX_PT_PAX_FLAGS
54462 + select PAX_HAVE_ACL_FLAGS
54463 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
54464 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
54465 + select PAX_RANDKSTACK if (X86_TSC && X86)
54466 + select PAX_SEGMEXEC if (X86_32)
54467 + select PAX_PAGEEXEC
54468 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
54469 + select PAX_EMUTRAMP if (PARISC)
54470 + select PAX_EMUSIGRT if (PARISC)
54471 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
54472 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
54473 + select PAX_REFCOUNT if (X86 || SPARC64)
54474 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54475 + help
54476 + If you say Y here, many of the features of grsecurity will be
54477 + enabled, which will protect you against many kinds of attacks
54478 + against your system. The heightened security comes at a cost
54479 + of an increased chance of incompatibilities with rare software
54480 + on your machine. Since this security level enables PaX, you should
54481 + view <http://pax.grsecurity.net> and read about the PaX
54482 + project. While you are there, download chpax and run it on
54483 + binaries that cause problems with PaX. Also remember that
54484 + since the /proc restrictions are enabled, you must run your
54485 + identd as gid 1001. This security level enables the following
54486 + features in addition to those listed in the low and medium
54487 + security levels:
54488 +
54489 + - Additional /proc restrictions
54490 + - Chmod restrictions in chroot
54491 + - No signals, ptrace, or viewing of processes outside of chroot
54492 + - Capability restrictions in chroot
54493 + - Deny fchdir out of chroot
54494 + - Priority restrictions in chroot
54495 + - Segmentation-based implementation of PaX
54496 + - Mprotect restrictions
54497 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
54498 + - Kernel stack randomization
54499 + - Mount/unmount/remount logging
54500 + - Kernel symbol hiding
54501 + - Hardening of module auto-loading
54502 + - Ptrace restrictions
54503 + - Restricted vm86 mode
54504 + - Restricted sysfs/debugfs
54505 + - Active kernel exploit response
54506 +
54507 +config GRKERNSEC_CUSTOM
54508 + bool "Custom"
54509 + help
54510 + If you say Y here, you will be able to configure every grsecurity
54511 + option, which allows you to enable many more features that aren't
54512 + covered in the basic security levels. These additional features
54513 + include TPE, socket restrictions, and the sysctl system for
54514 + grsecurity. It is advised that you read through the help for
54515 + each option to determine its usefulness in your situation.
54516 +
54517 +endchoice
54518 +
54519 +menu "Address Space Protection"
54520 +depends on GRKERNSEC
54521 +
54522 +config GRKERNSEC_KMEM
54523 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
54524 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
54525 + help
54526 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
54527 + be written to or read from to modify or leak the contents of the running
54528 + kernel. /dev/port will also not be allowed to be opened. If you have module
54529 + support disabled, enabling this will close up four ways that are
54530 + currently used to insert malicious code into the running kernel.
54531 + Even with all these features enabled, we still highly recommend that
54532 + you use the RBAC system, as it is still possible for an attacker to
54533 + modify the running kernel through privileged I/O granted by ioperm/iopl.
54534 + If you are not using XFree86, you may be able to stop this additional
54535 + case by enabling the 'Disable privileged I/O' option. Though nothing
54536 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
54537 + but only to video memory, which is the only writing we allow in this
54538 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
54539 + not be allowed to mprotect it with PROT_WRITE later.
54540 + It is highly recommended that you say Y here if you meet all the
54541 + conditions above.
54542 +
54543 +config GRKERNSEC_VM86
54544 + bool "Restrict VM86 mode"
54545 + depends on X86_32
54546 +
54547 + help
54548 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
54549 + make use of a special execution mode on 32bit x86 processors called
54550 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
54551 + video cards and will still work with this option enabled. The purpose
54552 + of the option is to prevent exploitation of emulation errors in
54553 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
54554 + Nearly all users should be able to enable this option.
54555 +
54556 +config GRKERNSEC_IO
54557 + bool "Disable privileged I/O"
54558 + depends on X86
54559 + select RTC_CLASS
54560 + select RTC_INTF_DEV
54561 + select RTC_DRV_CMOS
54562 +
54563 + help
54564 + If you say Y here, all ioperm and iopl calls will return an error.
54565 + Ioperm and iopl can be used to modify the running kernel.
54566 + Unfortunately, some programs need this access to operate properly,
54567 + the most notable of which are XFree86 and hwclock. hwclock can be
54568 + remedied by having RTC support in the kernel, so real-time
54569 + clock support is enabled if this option is enabled, to ensure
54570 + that hwclock operates correctly. XFree86 still will not
54571 + operate correctly with this option enabled, so DO NOT CHOOSE Y
54572 + IF YOU USE XFree86. If you use XFree86 and you still want to
54573 + protect your kernel against modification, use the RBAC system.
54574 +
54575 +config GRKERNSEC_PROC_MEMMAP
54576 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
54577 + default y if (PAX_NOEXEC || PAX_ASLR)
54578 + depends on PAX_NOEXEC || PAX_ASLR
54579 + help
54580 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
54581 + give no information about the addresses of its mappings if
54582 + PaX features that rely on random addresses are enabled on the task.
54583 + If you use PaX it is greatly recommended that you say Y here as it
54584 + closes up a hole that makes the full ASLR useless for suid
54585 + binaries.
54586 +
54587 +config GRKERNSEC_BRUTE
54588 + bool "Deter exploit bruteforcing"
54589 + help
54590 + If you say Y here, attempts to bruteforce exploits against forking
54591 + daemons such as apache or sshd, as well as against suid/sgid binaries
54592 + will be deterred. When a child of a forking daemon is killed by PaX
54593 + or crashes due to an illegal instruction or other suspicious signal,
54594 + the parent process will be delayed 30 seconds upon every subsequent
54595 + fork until the administrator is able to assess the situation and
54596 + restart the daemon.
54597 + In the suid/sgid case, the attempt is logged, the user has all their
54598 + processes terminated, and they are prevented from executing any further
54599 + processes for 15 minutes.
54600 + It is recommended that you also enable signal logging in the auditing
54601 + section so that logs are generated when a process triggers a suspicious
54602 + signal.
54603 + If the sysctl option is enabled, a sysctl option with name
54604 + "deter_bruteforce" is created.
54605 +
54606 +config GRKERNSEC_MODHARDEN
54607 + bool "Harden module auto-loading"
54608 + depends on MODULES
54609 + help
54610 + If you say Y here, module auto-loading in response to use of some
54611 + feature implemented by an unloaded module will be restricted to
54612 + root users. Enabling this option helps defend against attacks
54613 + by unprivileged users who abuse the auto-loading behavior to
54614 + cause a vulnerable module to load that is then exploited.
54615 +
54616 + If this option prevents a legitimate use of auto-loading for a
54617 + non-root user, the administrator can execute modprobe manually
54618 + with the exact name of the module mentioned in the alert log.
54619 + Alternatively, the administrator can add the module to the list
54620 + of modules loaded at boot by modifying init scripts.
54621 +
54622 + Modification of init scripts will most likely be needed on
54623 + Ubuntu servers with encrypted home directory support enabled,
54624 + as the first non-root user logging in will cause the ecb(aes),
54625 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
54626 +
54627 +config GRKERNSEC_HIDESYM
54628 + bool "Hide kernel symbols"
54629 + help
54630 + If you say Y here, getting information on loaded modules, and
54631 + displaying all kernel symbols through a syscall will be restricted
54632 + to users with CAP_SYS_MODULE. For software compatibility reasons,
54633 + /proc/kallsyms will be restricted to the root user. The RBAC
54634 + system can hide that entry even from root.
54635 +
54636 + This option also prevents leaking of kernel addresses through
54637 + several /proc entries.
54638 +
54639 + Note that this option is only effective provided the following
54640 + conditions are met:
54641 + 1) The kernel using grsecurity is not precompiled by some distribution
54642 + 2) You have also enabled GRKERNSEC_DMESG
54643 + 3) You are using the RBAC system and hiding other files such as your
54644 + kernel image and System.map. Alternatively, enabling this option
54645 + causes the permissions on /boot, /lib/modules, and the kernel
54646 + source directory to change at compile time to prevent
54647 + reading by non-root users.
54648 + If the above conditions are met, this option will aid in providing a
54649 + useful protection against local kernel exploitation of overflows
54650 + and arbitrary read/write vulnerabilities.
54651 +
54652 +config GRKERNSEC_KERN_LOCKOUT
54653 + bool "Active kernel exploit response"
54654 + depends on X86 || ARM || PPC || SPARC
54655 + help
54656 + If you say Y here, when a PaX alert is triggered due to suspicious
54657 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
54658 + or an OOPs occurs due to bad memory accesses, instead of just
54659 + terminating the offending process (and potentially allowing
54660 + a subsequent exploit from the same user), we will take one of two
54661 + actions:
54662 + If the user was root, we will panic the system
54663 + If the user was non-root, we will log the attempt, terminate
54664 + all processes owned by the user, then prevent them from creating
54665 + any new processes until the system is restarted
54666 + This deters repeated kernel exploitation/bruteforcing attempts
54667 + and is useful for later forensics.
54668 +
54669 +endmenu
54670 +menu "Role Based Access Control Options"
54671 +depends on GRKERNSEC
54672 +
54673 +config GRKERNSEC_RBAC_DEBUG
54674 + bool
54675 +
54676 +config GRKERNSEC_NO_RBAC
54677 + bool "Disable RBAC system"
54678 + help
54679 + If you say Y here, the /dev/grsec device will be removed from the kernel,
54680 + preventing the RBAC system from being enabled. You should only say Y
54681 + here if you have no intention of using the RBAC system, so as to prevent
54682 + an attacker with root access from misusing the RBAC system to hide files
54683 + and processes when loadable module support and /dev/[k]mem have been
54684 + locked down.
54685 +
54686 +config GRKERNSEC_ACL_HIDEKERN
54687 + bool "Hide kernel processes"
54688 + help
54689 + If you say Y here, all kernel threads will be hidden to all
54690 + processes but those whose subject has the "view hidden processes"
54691 + flag.
54692 +
54693 +config GRKERNSEC_ACL_MAXTRIES
54694 + int "Maximum tries before password lockout"
54695 + default 3
54696 + help
54697 + This option enforces the maximum number of times a user can attempt
54698 + to authorize themselves with the grsecurity RBAC system before being
54699 + denied the ability to attempt authorization again for a specified time.
54700 + The lower the number, the harder it will be to brute-force a password.
54701 +
54702 +config GRKERNSEC_ACL_TIMEOUT
54703 + int "Time to wait after max password tries, in seconds"
54704 + default 30
54705 + help
54706 + This option specifies the time the user must wait after attempting to
54707 + authorize to the RBAC system with the maximum number of invalid
54708 + passwords. The higher the number, the harder it will be to brute-force
54709 + a password.
54710 +
54711 +endmenu
54712 +menu "Filesystem Protections"
54713 +depends on GRKERNSEC
54714 +
54715 +config GRKERNSEC_PROC
54716 + bool "Proc restrictions"
54717 + help
54718 + If you say Y here, the permissions of the /proc filesystem
54719 + will be altered to enhance system security and privacy. You MUST
54720 + choose either a user only restriction or a user and group restriction.
54721 + Depending upon the option you choose, you can either restrict users to
54722 + see only the processes they themselves run, or choose a group that can
54723 + view all processes and files normally restricted to root if you choose
54724 + the "restrict to user only" option. NOTE: If you're running identd as
54725 + a non-root user, you will have to run it as the group you specify here.
54726 +
54727 +config GRKERNSEC_PROC_USER
54728 + bool "Restrict /proc to user only"
54729 + depends on GRKERNSEC_PROC
54730 + help
54731 + If you say Y here, non-root users will only be able to view their own
54732 + processes, and restricts them from viewing network-related information,
54733 + and viewing kernel symbol and module information.
54734 +
54735 +config GRKERNSEC_PROC_USERGROUP
54736 + bool "Allow special group"
54737 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
54738 + help
54739 + If you say Y here, you will be able to select a group that will be
54740 + able to view all processes and network-related information. If you've
54741 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
54742 + remain hidden. This option is useful if you want to run identd as
54743 + a non-root user.
54744 +
54745 +config GRKERNSEC_PROC_GID
54746 + int "GID for special group"
54747 + depends on GRKERNSEC_PROC_USERGROUP
54748 + default 1001
54749 +
54750 +config GRKERNSEC_PROC_ADD
54751 + bool "Additional restrictions"
54752 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
54753 + help
54754 + If you say Y here, additional restrictions will be placed on
54755 + /proc that keep normal users from viewing device information and
54756 + slabinfo information that could be useful for exploits.
54757 +
54758 +config GRKERNSEC_LINK
54759 + bool "Linking restrictions"
54760 + help
54761 + If you say Y here, /tmp race exploits will be prevented, since users
54762 + will no longer be able to follow symlinks owned by other users in
54763 + world-writable +t directories (e.g. /tmp), unless the owner of the
54764 + symlink is the owner of the directory. users will also not be
54765 + able to hardlink to files they do not own. If the sysctl option is
54766 + enabled, a sysctl option with name "linking_restrictions" is created.
54767 +
54768 +config GRKERNSEC_FIFO
54769 + bool "FIFO restrictions"
54770 + help
54771 + If you say Y here, users will not be able to write to FIFOs they don't
54772 + own in world-writable +t directories (e.g. /tmp), unless the owner of
54773 + the FIFO is the same owner of the directory it's held in. If the sysctl
54774 + option is enabled, a sysctl option with name "fifo_restrictions" is
54775 + created.
54776 +
54777 +config GRKERNSEC_SYSFS_RESTRICT
54778 + bool "Sysfs/debugfs restriction"
54779 + depends on SYSFS
54780 + help
54781 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
54782 + any filesystem normally mounted under it (e.g. debugfs) will only
54783 + be accessible by root. These filesystems generally provide access
54784 + to hardware and debug information that isn't appropriate for unprivileged
54785 + users of the system. Sysfs and debugfs have also become a large source
54786 + of new vulnerabilities, ranging from infoleaks to local compromise.
54787 + There has been very little oversight with an eye toward security involved
54788 + in adding new exporters of information to these filesystems, so their
54789 + use is discouraged.
54790 + This option is equivalent to a chmod 0700 of the mount paths.
54791 +
54792 +config GRKERNSEC_ROFS
54793 + bool "Runtime read-only mount protection"
54794 + help
54795 + If you say Y here, a sysctl option with name "romount_protect" will
54796 + be created. By setting this option to 1 at runtime, filesystems
54797 + will be protected in the following ways:
54798 + * No new writable mounts will be allowed
54799 + * Existing read-only mounts won't be able to be remounted read/write
54800 + * Write operations will be denied on all block devices
54801 + This option acts independently of grsec_lock: once it is set to 1,
54802 + it cannot be turned off. Therefore, please be mindful of the resulting
54803 + behavior if this option is enabled in an init script on a read-only
54804 + filesystem. This feature is mainly intended for secure embedded systems.
54805 +
54806 +config GRKERNSEC_CHROOT
54807 + bool "Chroot jail restrictions"
54808 + help
54809 + If you say Y here, you will be able to choose several options that will
54810 + make breaking out of a chrooted jail much more difficult. If you
54811 + encounter no software incompatibilities with the following options, it
54812 + is recommended that you enable each one.
54813 +
54814 +config GRKERNSEC_CHROOT_MOUNT
54815 + bool "Deny mounts"
54816 + depends on GRKERNSEC_CHROOT
54817 + help
54818 + If you say Y here, processes inside a chroot will not be able to
54819 + mount or remount filesystems. If the sysctl option is enabled, a
54820 + sysctl option with name "chroot_deny_mount" is created.
54821 +
54822 +config GRKERNSEC_CHROOT_DOUBLE
54823 + bool "Deny double-chroots"
54824 + depends on GRKERNSEC_CHROOT
54825 + help
54826 + If you say Y here, processes inside a chroot will not be able to chroot
54827 + again outside the chroot. This is a widely used method of breaking
54828 + out of a chroot jail and should not be allowed. If the sysctl
54829 + option is enabled, a sysctl option with name
54830 + "chroot_deny_chroot" is created.
54831 +
54832 +config GRKERNSEC_CHROOT_PIVOT
54833 + bool "Deny pivot_root in chroot"
54834 + depends on GRKERNSEC_CHROOT
54835 + help
54836 + If you say Y here, processes inside a chroot will not be able to use
54837 + a function called pivot_root() that was introduced in Linux 2.3.41. It
54838 + works similar to chroot in that it changes the root filesystem. This
54839 + function could be misused in a chrooted process to attempt to break out
54840 + of the chroot, and therefore should not be allowed. If the sysctl
54841 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
54842 + created.
54843 +
54844 +config GRKERNSEC_CHROOT_CHDIR
54845 + bool "Enforce chdir(\"/\") on all chroots"
54846 + depends on GRKERNSEC_CHROOT
54847 + help
54848 + If you say Y here, the current working directory of all newly-chrooted
54849 + applications will be set to the the root directory of the chroot.
54850 + The man page on chroot(2) states:
54851 + Note that this call does not change the current working
54852 + directory, so that `.' can be outside the tree rooted at
54853 + `/'. In particular, the super-user can escape from a
54854 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
54855 +
54856 + It is recommended that you say Y here, since it's not known to break
54857 + any software. If the sysctl option is enabled, a sysctl option with
54858 + name "chroot_enforce_chdir" is created.
54859 +
54860 +config GRKERNSEC_CHROOT_CHMOD
54861 + bool "Deny (f)chmod +s"
54862 + depends on GRKERNSEC_CHROOT
54863 + help
54864 + If you say Y here, processes inside a chroot will not be able to chmod
54865 + or fchmod files to make them have suid or sgid bits. This protects
54866 + against another published method of breaking a chroot. If the sysctl
54867 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
54868 + created.
54869 +
54870 +config GRKERNSEC_CHROOT_FCHDIR
54871 + bool "Deny fchdir out of chroot"
54872 + depends on GRKERNSEC_CHROOT
54873 + help
54874 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
54875 + to a file descriptor of the chrooting process that points to a directory
54876 + outside the filesystem will be stopped. If the sysctl option
54877 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
54878 +
54879 +config GRKERNSEC_CHROOT_MKNOD
54880 + bool "Deny mknod"
54881 + depends on GRKERNSEC_CHROOT
54882 + help
54883 + If you say Y here, processes inside a chroot will not be allowed to
54884 + mknod. The problem with using mknod inside a chroot is that it
54885 + would allow an attacker to create a device entry that is the same
54886 + as one on the physical root of your system, which could range from
54887 + anything from the console device to a device for your harddrive (which
54888 + they could then use to wipe the drive or steal data). It is recommended
54889 + that you say Y here, unless you run into software incompatibilities.
54890 + If the sysctl option is enabled, a sysctl option with name
54891 + "chroot_deny_mknod" is created.
54892 +
54893 +config GRKERNSEC_CHROOT_SHMAT
54894 + bool "Deny shmat() out of chroot"
54895 + depends on GRKERNSEC_CHROOT
54896 + help
54897 + If you say Y here, processes inside a chroot will not be able to attach
54898 + to shared memory segments that were created outside of the chroot jail.
54899 + It is recommended that you say Y here. If the sysctl option is enabled,
54900 + a sysctl option with name "chroot_deny_shmat" is created.
54901 +
54902 +config GRKERNSEC_CHROOT_UNIX
54903 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
54904 + depends on GRKERNSEC_CHROOT
54905 + help
54906 + If you say Y here, processes inside a chroot will not be able to
54907 + connect to abstract (meaning not belonging to a filesystem) Unix
54908 + domain sockets that were bound outside of a chroot. It is recommended
54909 + that you say Y here. If the sysctl option is enabled, a sysctl option
54910 + with name "chroot_deny_unix" is created.
54911 +
54912 +config GRKERNSEC_CHROOT_FINDTASK
54913 + bool "Protect outside processes"
54914 + depends on GRKERNSEC_CHROOT
54915 + help
54916 + If you say Y here, processes inside a chroot will not be able to
54917 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
54918 + getsid, or view any process outside of the chroot. If the sysctl
54919 + option is enabled, a sysctl option with name "chroot_findtask" is
54920 + created.
54921 +
54922 +config GRKERNSEC_CHROOT_NICE
54923 + bool "Restrict priority changes"
54924 + depends on GRKERNSEC_CHROOT
54925 + help
54926 + If you say Y here, processes inside a chroot will not be able to raise
54927 + the priority of processes in the chroot, or alter the priority of
54928 + processes outside the chroot. This provides more security than simply
54929 + removing CAP_SYS_NICE from the process' capability set. If the
54930 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
54931 + is created.
54932 +
54933 +config GRKERNSEC_CHROOT_SYSCTL
54934 + bool "Deny sysctl writes"
54935 + depends on GRKERNSEC_CHROOT
54936 + help
54937 + If you say Y here, an attacker in a chroot will not be able to
54938 + write to sysctl entries, either by sysctl(2) or through a /proc
54939 + interface. It is strongly recommended that you say Y here. If the
54940 + sysctl option is enabled, a sysctl option with name
54941 + "chroot_deny_sysctl" is created.
54942 +
54943 +config GRKERNSEC_CHROOT_CAPS
54944 + bool "Capability restrictions"
54945 + depends on GRKERNSEC_CHROOT
54946 + help
54947 + If you say Y here, the capabilities on all processes within a
54948 + chroot jail will be lowered to stop module insertion, raw i/o,
54949 + system and net admin tasks, rebooting the system, modifying immutable
54950 + files, modifying IPC owned by another, and changing the system time.
54951 + This is left an option because it can break some apps. Disable this
54952 + if your chrooted apps are having problems performing those kinds of
54953 + tasks. If the sysctl option is enabled, a sysctl option with
54954 + name "chroot_caps" is created.
54955 +
54956 +endmenu
54957 +menu "Kernel Auditing"
54958 +depends on GRKERNSEC
54959 +
54960 +config GRKERNSEC_AUDIT_GROUP
54961 + bool "Single group for auditing"
54962 + help
54963 + If you say Y here, the exec, chdir, and (un)mount logging features
54964 + will only operate on a group you specify. This option is recommended
54965 + if you only want to watch certain users instead of having a large
54966 + amount of logs from the entire system. If the sysctl option is enabled,
54967 + a sysctl option with name "audit_group" is created.
54968 +
54969 +config GRKERNSEC_AUDIT_GID
54970 + int "GID for auditing"
54971 + depends on GRKERNSEC_AUDIT_GROUP
54972 + default 1007
54973 +
54974 +config GRKERNSEC_EXECLOG
54975 + bool "Exec logging"
54976 + help
54977 + If you say Y here, all execve() calls will be logged (since the
54978 + other exec*() calls are frontends to execve(), all execution
54979 + will be logged). Useful for shell-servers that like to keep track
54980 + of their users. If the sysctl option is enabled, a sysctl option with
54981 + name "exec_logging" is created.
54982 + WARNING: This option when enabled will produce a LOT of logs, especially
54983 + on an active system.
54984 +
54985 +config GRKERNSEC_RESLOG
54986 + bool "Resource logging"
54987 + help
54988 + If you say Y here, all attempts to overstep resource limits will
54989 + be logged with the resource name, the requested size, and the current
54990 + limit. It is highly recommended that you say Y here. If the sysctl
54991 + option is enabled, a sysctl option with name "resource_logging" is
54992 + created. If the RBAC system is enabled, the sysctl value is ignored.
54993 +
54994 +config GRKERNSEC_CHROOT_EXECLOG
54995 + bool "Log execs within chroot"
54996 + help
54997 + If you say Y here, all executions inside a chroot jail will be logged
54998 + to syslog. This can cause a large amount of logs if certain
54999 + applications (eg. djb's daemontools) are installed on the system, and
55000 + is therefore left as an option. If the sysctl option is enabled, a
55001 + sysctl option with name "chroot_execlog" is created.
55002 +
55003 +config GRKERNSEC_AUDIT_PTRACE
55004 + bool "Ptrace logging"
55005 + help
55006 + If you say Y here, all attempts to attach to a process via ptrace
55007 + will be logged. If the sysctl option is enabled, a sysctl option
55008 + with name "audit_ptrace" is created.
55009 +
55010 +config GRKERNSEC_AUDIT_CHDIR
55011 + bool "Chdir logging"
55012 + help
55013 + If you say Y here, all chdir() calls will be logged. If the sysctl
55014 + option is enabled, a sysctl option with name "audit_chdir" is created.
55015 +
55016 +config GRKERNSEC_AUDIT_MOUNT
55017 + bool "(Un)Mount logging"
55018 + help
55019 + If you say Y here, all mounts and unmounts will be logged. If the
55020 + sysctl option is enabled, a sysctl option with name "audit_mount" is
55021 + created.
55022 +
55023 +config GRKERNSEC_SIGNAL
55024 + bool "Signal logging"
55025 + help
55026 + If you say Y here, certain important signals will be logged, such as
55027 + SIGSEGV, which will as a result inform you of when a error in a program
55028 + occurred, which in some cases could mean a possible exploit attempt.
55029 + If the sysctl option is enabled, a sysctl option with name
55030 + "signal_logging" is created.
55031 +
55032 +config GRKERNSEC_FORKFAIL
55033 + bool "Fork failure logging"
55034 + help
55035 + If you say Y here, all failed fork() attempts will be logged.
55036 + This could suggest a fork bomb, or someone attempting to overstep
55037 + their process limit. If the sysctl option is enabled, a sysctl option
55038 + with name "forkfail_logging" is created.
55039 +
55040 +config GRKERNSEC_TIME
55041 + bool "Time change logging"
55042 + help
55043 + If you say Y here, any changes of the system clock will be logged.
55044 + If the sysctl option is enabled, a sysctl option with name
55045 + "timechange_logging" is created.
55046 +
55047 +config GRKERNSEC_PROC_IPADDR
55048 + bool "/proc/<pid>/ipaddr support"
55049 + help
55050 + If you say Y here, a new entry will be added to each /proc/<pid>
55051 + directory that contains the IP address of the person using the task.
55052 + The IP is carried across local TCP and AF_UNIX stream sockets.
55053 + This information can be useful for IDS/IPSes to perform remote response
55054 + to a local attack. The entry is readable by only the owner of the
55055 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
55056 + the RBAC system), and thus does not create privacy concerns.
55057 +
55058 +config GRKERNSEC_RWXMAP_LOG
55059 + bool 'Denied RWX mmap/mprotect logging'
55060 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
55061 + help
55062 + If you say Y here, calls to mmap() and mprotect() with explicit
55063 + usage of PROT_WRITE and PROT_EXEC together will be logged when
55064 + denied by the PAX_MPROTECT feature. If the sysctl option is
55065 + enabled, a sysctl option with name "rwxmap_logging" is created.
55066 +
55067 +config GRKERNSEC_AUDIT_TEXTREL
55068 + bool 'ELF text relocations logging (READ HELP)'
55069 + depends on PAX_MPROTECT
55070 + help
55071 + If you say Y here, text relocations will be logged with the filename
55072 + of the offending library or binary. The purpose of the feature is
55073 + to help Linux distribution developers get rid of libraries and
55074 + binaries that need text relocations which hinder the future progress
55075 + of PaX. Only Linux distribution developers should say Y here, and
55076 + never on a production machine, as this option creates an information
55077 + leak that could aid an attacker in defeating the randomization of
55078 + a single memory region. If the sysctl option is enabled, a sysctl
55079 + option with name "audit_textrel" is created.
55080 +
55081 +endmenu
55082 +
55083 +menu "Executable Protections"
55084 +depends on GRKERNSEC
55085 +
55086 +config GRKERNSEC_DMESG
55087 + bool "Dmesg(8) restriction"
55088 + help
55089 + If you say Y here, non-root users will not be able to use dmesg(8)
55090 + to view up to the last 4kb of messages in the kernel's log buffer.
55091 + The kernel's log buffer often contains kernel addresses and other
55092 + identifying information useful to an attacker in fingerprinting a
55093 + system for a targeted exploit.
55094 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
55095 + created.
55096 +
55097 +config GRKERNSEC_HARDEN_PTRACE
55098 + bool "Deter ptrace-based process snooping"
55099 + help
55100 + If you say Y here, TTY sniffers and other malicious monitoring
55101 + programs implemented through ptrace will be defeated. If you
55102 + have been using the RBAC system, this option has already been
55103 + enabled for several years for all users, with the ability to make
55104 + fine-grained exceptions.
55105 +
55106 + This option only affects the ability of non-root users to ptrace
55107 + processes that are not a descendent of the ptracing process.
55108 + This means that strace ./binary and gdb ./binary will still work,
55109 + but attaching to arbitrary processes will not. If the sysctl
55110 + option is enabled, a sysctl option with name "harden_ptrace" is
55111 + created.
55112 +
55113 +config GRKERNSEC_TPE
55114 + bool "Trusted Path Execution (TPE)"
55115 + help
55116 + If you say Y here, you will be able to choose a gid to add to the
55117 + supplementary groups of users you want to mark as "untrusted."
55118 + These users will not be able to execute any files that are not in
55119 + root-owned directories writable only by root. If the sysctl option
55120 + is enabled, a sysctl option with name "tpe" is created.
55121 +
55122 +config GRKERNSEC_TPE_ALL
55123 + bool "Partially restrict all non-root users"
55124 + depends on GRKERNSEC_TPE
55125 + help
55126 + If you say Y here, all non-root users will be covered under
55127 + a weaker TPE restriction. This is separate from, and in addition to,
55128 + the main TPE options that you have selected elsewhere. Thus, if a
55129 + "trusted" GID is chosen, this restriction applies to even that GID.
55130 + Under this restriction, all non-root users will only be allowed to
55131 + execute files in directories they own that are not group or
55132 + world-writable, or in directories owned by root and writable only by
55133 + root. If the sysctl option is enabled, a sysctl option with name
55134 + "tpe_restrict_all" is created.
55135 +
55136 +config GRKERNSEC_TPE_INVERT
55137 + bool "Invert GID option"
55138 + depends on GRKERNSEC_TPE
55139 + help
55140 + If you say Y here, the group you specify in the TPE configuration will
55141 + decide what group TPE restrictions will be *disabled* for. This
55142 + option is useful if you want TPE restrictions to be applied to most
55143 + users on the system. If the sysctl option is enabled, a sysctl option
55144 + with name "tpe_invert" is created. Unlike other sysctl options, this
55145 + entry will default to on for backward-compatibility.
55146 +
55147 +config GRKERNSEC_TPE_GID
55148 + int "GID for untrusted users"
55149 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
55150 + default 1005
55151 + help
55152 + Setting this GID determines what group TPE restrictions will be
55153 + *enabled* for. If the sysctl option is enabled, a sysctl option
55154 + with name "tpe_gid" is created.
55155 +
55156 +config GRKERNSEC_TPE_GID
55157 + int "GID for trusted users"
55158 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
55159 + default 1005
55160 + help
55161 + Setting this GID determines what group TPE restrictions will be
55162 + *disabled* for. If the sysctl option is enabled, a sysctl option
55163 + with name "tpe_gid" is created.
55164 +
55165 +endmenu
55166 +menu "Network Protections"
55167 +depends on GRKERNSEC
55168 +
55169 +config GRKERNSEC_RANDNET
55170 + bool "Larger entropy pools"
55171 + help
55172 + If you say Y here, the entropy pools used for many features of Linux
55173 + and grsecurity will be doubled in size. Since several grsecurity
55174 + features use additional randomness, it is recommended that you say Y
55175 + here. Saying Y here has a similar effect as modifying
55176 + /proc/sys/kernel/random/poolsize.
55177 +
55178 +config GRKERNSEC_BLACKHOLE
55179 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
55180 + depends on NET
55181 + help
55182 + If you say Y here, neither TCP resets nor ICMP
55183 + destination-unreachable packets will be sent in response to packets
55184 + sent to ports for which no associated listening process exists.
55185 + This feature supports both IPV4 and IPV6 and exempts the
55186 + loopback interface from blackholing. Enabling this feature
55187 + makes a host more resilient to DoS attacks and reduces network
55188 + visibility against scanners.
55189 +
55190 + The blackhole feature as-implemented is equivalent to the FreeBSD
55191 + blackhole feature, as it prevents RST responses to all packets, not
55192 + just SYNs. Under most application behavior this causes no
55193 + problems, but applications (like haproxy) may not close certain
55194 + connections in a way that cleanly terminates them on the remote
55195 + end, leaving the remote host in LAST_ACK state. Because of this
55196 + side-effect and to prevent intentional LAST_ACK DoSes, this
55197 + feature also adds automatic mitigation against such attacks.
55198 + The mitigation drastically reduces the amount of time a socket
55199 + can spend in LAST_ACK state. If you're using haproxy and not
55200 + all servers it connects to have this option enabled, consider
55201 + disabling this feature on the haproxy host.
55202 +
55203 + If the sysctl option is enabled, two sysctl options with names
55204 + "ip_blackhole" and "lastack_retries" will be created.
55205 + While "ip_blackhole" takes the standard zero/non-zero on/off
55206 + toggle, "lastack_retries" uses the same kinds of values as
55207 + "tcp_retries1" and "tcp_retries2". The default value of 4
55208 + prevents a socket from lasting more than 45 seconds in LAST_ACK
55209 + state.
55210 +
55211 +config GRKERNSEC_SOCKET
55212 + bool "Socket restrictions"
55213 + depends on NET
55214 + help
55215 + If you say Y here, you will be able to choose from several options.
55216 + If you assign a GID on your system and add it to the supplementary
55217 + groups of users you want to restrict socket access to, this patch
55218 + will perform up to three things, based on the option(s) you choose.
55219 +
55220 +config GRKERNSEC_SOCKET_ALL
55221 + bool "Deny any sockets to group"
55222 + depends on GRKERNSEC_SOCKET
55223 + help
55224 + If you say Y here, you will be able to choose a GID of whose users will
55225 + be unable to connect to other hosts from your machine or run server
55226 + applications from your machine. If the sysctl option is enabled, a
55227 + sysctl option with name "socket_all" is created.
55228 +
55229 +config GRKERNSEC_SOCKET_ALL_GID
55230 + int "GID to deny all sockets for"
55231 + depends on GRKERNSEC_SOCKET_ALL
55232 + default 1004
55233 + help
55234 + Here you can choose the GID to disable socket access for. Remember to
55235 + add the users you want socket access disabled for to the GID
55236 + specified here. If the sysctl option is enabled, a sysctl option
55237 + with name "socket_all_gid" is created.
55238 +
55239 +config GRKERNSEC_SOCKET_CLIENT
55240 + bool "Deny client sockets to group"
55241 + depends on GRKERNSEC_SOCKET
55242 + help
55243 + If you say Y here, you will be able to choose a GID of whose users will
55244 + be unable to connect to other hosts from your machine, but will be
55245 + able to run servers. If this option is enabled, all users in the group
55246 + you specify will have to use passive mode when initiating ftp transfers
55247 + from the shell on your machine. If the sysctl option is enabled, a
55248 + sysctl option with name "socket_client" is created.
55249 +
55250 +config GRKERNSEC_SOCKET_CLIENT_GID
55251 + int "GID to deny client sockets for"
55252 + depends on GRKERNSEC_SOCKET_CLIENT
55253 + default 1003
55254 + help
55255 + Here you can choose the GID to disable client socket access for.
55256 + Remember to add the users you want client socket access disabled for to
55257 + the GID specified here. If the sysctl option is enabled, a sysctl
55258 + option with name "socket_client_gid" is created.
55259 +
55260 +config GRKERNSEC_SOCKET_SERVER
55261 + bool "Deny server sockets to group"
55262 + depends on GRKERNSEC_SOCKET
55263 + help
55264 + If you say Y here, you will be able to choose a GID of whose users will
55265 + be unable to run server applications from your machine. If the sysctl
55266 + option is enabled, a sysctl option with name "socket_server" is created.
55267 +
55268 +config GRKERNSEC_SOCKET_SERVER_GID
55269 + int "GID to deny server sockets for"
55270 + depends on GRKERNSEC_SOCKET_SERVER
55271 + default 1002
55272 + help
55273 + Here you can choose the GID to disable server socket access for.
55274 + Remember to add the users you want server socket access disabled for to
55275 + the GID specified here. If the sysctl option is enabled, a sysctl
55276 + option with name "socket_server_gid" is created.
55277 +
55278 +endmenu
55279 +menu "Sysctl support"
55280 +depends on GRKERNSEC && SYSCTL
55281 +
55282 +config GRKERNSEC_SYSCTL
55283 + bool "Sysctl support"
55284 + help
55285 + If you say Y here, you will be able to change the options that
55286 + grsecurity runs with at bootup, without having to recompile your
55287 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
55288 + to enable (1) or disable (0) various features. All the sysctl entries
55289 + are mutable until the "grsec_lock" entry is set to a non-zero value.
55290 + All features enabled in the kernel configuration are disabled at boot
55291 + if you do not say Y to the "Turn on features by default" option.
55292 + All options should be set at startup, and the grsec_lock entry should
55293 + be set to a non-zero value after all the options are set.
55294 + *THIS IS EXTREMELY IMPORTANT*
55295 +
55296 +config GRKERNSEC_SYSCTL_DISTRO
55297 + bool "Extra sysctl support for distro makers (READ HELP)"
55298 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
55299 + help
55300 + If you say Y here, additional sysctl options will be created
55301 + for features that affect processes running as root. Therefore,
55302 + it is critical when using this option that the grsec_lock entry be
55303 + enabled after boot. Only distros with prebuilt kernel packages
55304 + with this option enabled that can ensure grsec_lock is enabled
55305 + after boot should use this option.
55306 + *Failure to set grsec_lock after boot makes all grsec features
55307 + this option covers useless*
55308 +
55309 + Currently this option creates the following sysctl entries:
55310 + "Disable Privileged I/O": "disable_priv_io"
55311 +
55312 +config GRKERNSEC_SYSCTL_ON
55313 + bool "Turn on features by default"
55314 + depends on GRKERNSEC_SYSCTL
55315 + help
55316 + If you say Y here, instead of having all features enabled in the
55317 + kernel configuration disabled at boot time, the features will be
55318 + enabled at boot time. It is recommended you say Y here unless
55319 + there is some reason you would want all sysctl-tunable features to
55320 + be disabled by default. As mentioned elsewhere, it is important
55321 + to enable the grsec_lock entry once you have finished modifying
55322 + the sysctl entries.
55323 +
55324 +endmenu
55325 +menu "Logging Options"
55326 +depends on GRKERNSEC
55327 +
55328 +config GRKERNSEC_FLOODTIME
55329 + int "Seconds in between log messages (minimum)"
55330 + default 10
55331 + help
55332 + This option allows you to enforce the number of seconds between
55333 + grsecurity log messages. The default should be suitable for most
55334 + people, however, if you choose to change it, choose a value small enough
55335 + to allow informative logs to be produced, but large enough to
55336 + prevent flooding.
55337 +
55338 +config GRKERNSEC_FLOODBURST
55339 + int "Number of messages in a burst (maximum)"
55340 + default 6
55341 + help
55342 + This option allows you to choose the maximum number of messages allowed
55343 + within the flood time interval you chose in a separate option. The
55344 + default should be suitable for most people, however if you find that
55345 + many of your logs are being interpreted as flooding, you may want to
55346 + raise this value.
55347 +
55348 +endmenu
55349 +
55350 +endmenu
55351 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
55352 new file mode 100644
55353 index 0000000..be9ae3a
55354 --- /dev/null
55355 +++ b/grsecurity/Makefile
55356 @@ -0,0 +1,36 @@
55357 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
55358 +# during 2001-2009 it has been completely redesigned by Brad Spengler
55359 +# into an RBAC system
55360 +#
55361 +# All code in this directory and various hooks inserted throughout the kernel
55362 +# are copyright Brad Spengler - Open Source Security, Inc., and released
55363 +# under the GPL v2 or higher
55364 +
55365 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
55366 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
55367 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
55368 +
55369 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
55370 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
55371 + gracl_learn.o grsec_log.o
55372 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
55373 +
55374 +ifdef CONFIG_NET
55375 +obj-y += grsec_sock.o
55376 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
55377 +endif
55378 +
55379 +ifndef CONFIG_GRKERNSEC
55380 +obj-y += grsec_disabled.o
55381 +endif
55382 +
55383 +ifdef CONFIG_GRKERNSEC_HIDESYM
55384 +extra-y := grsec_hidesym.o
55385 +$(obj)/grsec_hidesym.o:
55386 + @-chmod -f 500 /boot
55387 + @-chmod -f 500 /lib/modules
55388 + @-chmod -f 500 /lib64/modules
55389 + @-chmod -f 500 /lib32/modules
55390 + @-chmod -f 700 .
55391 + @echo ' grsec: protected kernel image paths'
55392 +endif
55393 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
55394 new file mode 100644
55395 index 0000000..6bd68d6
55396 --- /dev/null
55397 +++ b/grsecurity/gracl.c
55398 @@ -0,0 +1,4141 @@
55399 +#include <linux/kernel.h>
55400 +#include <linux/module.h>
55401 +#include <linux/sched.h>
55402 +#include <linux/mm.h>
55403 +#include <linux/file.h>
55404 +#include <linux/fs.h>
55405 +#include <linux/namei.h>
55406 +#include <linux/mount.h>
55407 +#include <linux/tty.h>
55408 +#include <linux/proc_fs.h>
55409 +#include <linux/smp_lock.h>
55410 +#include <linux/slab.h>
55411 +#include <linux/vmalloc.h>
55412 +#include <linux/types.h>
55413 +#include <linux/sysctl.h>
55414 +#include <linux/netdevice.h>
55415 +#include <linux/ptrace.h>
55416 +#include <linux/gracl.h>
55417 +#include <linux/gralloc.h>
55418 +#include <linux/grsecurity.h>
55419 +#include <linux/grinternal.h>
55420 +#include <linux/pid_namespace.h>
55421 +#include <linux/fdtable.h>
55422 +#include <linux/percpu.h>
55423 +
55424 +#include <asm/uaccess.h>
55425 +#include <asm/errno.h>
55426 +#include <asm/mman.h>
55427 +
55428 +static struct acl_role_db acl_role_set;
55429 +static struct name_db name_set;
55430 +static struct inodev_db inodev_set;
55431 +
55432 +/* for keeping track of userspace pointers used for subjects, so we
55433 + can share references in the kernel as well
55434 +*/
55435 +
55436 +static struct dentry *real_root;
55437 +static struct vfsmount *real_root_mnt;
55438 +
55439 +static struct acl_subj_map_db subj_map_set;
55440 +
55441 +static struct acl_role_label *default_role;
55442 +
55443 +static struct acl_role_label *role_list;
55444 +
55445 +static u16 acl_sp_role_value;
55446 +
55447 +extern char *gr_shared_page[4];
55448 +static DEFINE_MUTEX(gr_dev_mutex);
55449 +DEFINE_RWLOCK(gr_inode_lock);
55450 +
55451 +struct gr_arg *gr_usermode;
55452 +
55453 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
55454 +
55455 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
55456 +extern void gr_clear_learn_entries(void);
55457 +
55458 +#ifdef CONFIG_GRKERNSEC_RESLOG
55459 +extern void gr_log_resource(const struct task_struct *task,
55460 + const int res, const unsigned long wanted, const int gt);
55461 +#endif
55462 +
55463 +unsigned char *gr_system_salt;
55464 +unsigned char *gr_system_sum;
55465 +
55466 +static struct sprole_pw **acl_special_roles = NULL;
55467 +static __u16 num_sprole_pws = 0;
55468 +
55469 +static struct acl_role_label *kernel_role = NULL;
55470 +
55471 +static unsigned int gr_auth_attempts = 0;
55472 +static unsigned long gr_auth_expires = 0UL;
55473 +
55474 +#ifdef CONFIG_NET
55475 +extern struct vfsmount *sock_mnt;
55476 +#endif
55477 +extern struct vfsmount *pipe_mnt;
55478 +extern struct vfsmount *shm_mnt;
55479 +#ifdef CONFIG_HUGETLBFS
55480 +extern struct vfsmount *hugetlbfs_vfsmount;
55481 +#endif
55482 +
55483 +static struct acl_object_label *fakefs_obj_rw;
55484 +static struct acl_object_label *fakefs_obj_rwx;
55485 +
55486 +extern int gr_init_uidset(void);
55487 +extern void gr_free_uidset(void);
55488 +extern void gr_remove_uid(uid_t uid);
55489 +extern int gr_find_uid(uid_t uid);
55490 +
55491 +__inline__ int
55492 +gr_acl_is_enabled(void)
55493 +{
55494 + return (gr_status & GR_READY);
55495 +}
55496 +
55497 +#ifdef CONFIG_BTRFS_FS
55498 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55499 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55500 +#endif
55501 +
55502 +static inline dev_t __get_dev(const struct dentry *dentry)
55503 +{
55504 +#ifdef CONFIG_BTRFS_FS
55505 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55506 + return get_btrfs_dev_from_inode(dentry->d_inode);
55507 + else
55508 +#endif
55509 + return dentry->d_inode->i_sb->s_dev;
55510 +}
55511 +
55512 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55513 +{
55514 + return __get_dev(dentry);
55515 +}
55516 +
55517 +static char gr_task_roletype_to_char(struct task_struct *task)
55518 +{
55519 + switch (task->role->roletype &
55520 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
55521 + GR_ROLE_SPECIAL)) {
55522 + case GR_ROLE_DEFAULT:
55523 + return 'D';
55524 + case GR_ROLE_USER:
55525 + return 'U';
55526 + case GR_ROLE_GROUP:
55527 + return 'G';
55528 + case GR_ROLE_SPECIAL:
55529 + return 'S';
55530 + }
55531 +
55532 + return 'X';
55533 +}
55534 +
55535 +char gr_roletype_to_char(void)
55536 +{
55537 + return gr_task_roletype_to_char(current);
55538 +}
55539 +
55540 +__inline__ int
55541 +gr_acl_tpe_check(void)
55542 +{
55543 + if (unlikely(!(gr_status & GR_READY)))
55544 + return 0;
55545 + if (current->role->roletype & GR_ROLE_TPE)
55546 + return 1;
55547 + else
55548 + return 0;
55549 +}
55550 +
55551 +int
55552 +gr_handle_rawio(const struct inode *inode)
55553 +{
55554 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55555 + if (inode && S_ISBLK(inode->i_mode) &&
55556 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55557 + !capable(CAP_SYS_RAWIO))
55558 + return 1;
55559 +#endif
55560 + return 0;
55561 +}
55562 +
55563 +static int
55564 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
55565 +{
55566 + if (likely(lena != lenb))
55567 + return 0;
55568 +
55569 + return !memcmp(a, b, lena);
55570 +}
55571 +
55572 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
55573 +{
55574 + *buflen -= namelen;
55575 + if (*buflen < 0)
55576 + return -ENAMETOOLONG;
55577 + *buffer -= namelen;
55578 + memcpy(*buffer, str, namelen);
55579 + return 0;
55580 +}
55581 +
55582 +/* this must be called with vfsmount_lock and dcache_lock held */
55583 +
55584 +static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55585 + struct dentry *root, struct vfsmount *rootmnt,
55586 + char *buffer, int buflen)
55587 +{
55588 + char * end = buffer+buflen;
55589 + char * retval;
55590 + int namelen;
55591 +
55592 + *--end = '\0';
55593 + buflen--;
55594 +
55595 + if (buflen < 1)
55596 + goto Elong;
55597 + /* Get '/' right */
55598 + retval = end-1;
55599 + *retval = '/';
55600 +
55601 + for (;;) {
55602 + struct dentry * parent;
55603 +
55604 + if (dentry == root && vfsmnt == rootmnt)
55605 + break;
55606 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
55607 + /* Global root? */
55608 + if (vfsmnt->mnt_parent == vfsmnt)
55609 + goto global_root;
55610 + dentry = vfsmnt->mnt_mountpoint;
55611 + vfsmnt = vfsmnt->mnt_parent;
55612 + continue;
55613 + }
55614 + parent = dentry->d_parent;
55615 + prefetch(parent);
55616 + namelen = dentry->d_name.len;
55617 + buflen -= namelen + 1;
55618 + if (buflen < 0)
55619 + goto Elong;
55620 + end -= namelen;
55621 + memcpy(end, dentry->d_name.name, namelen);
55622 + *--end = '/';
55623 + retval = end;
55624 + dentry = parent;
55625 + }
55626 +
55627 +out:
55628 + return retval;
55629 +
55630 +global_root:
55631 + namelen = dentry->d_name.len;
55632 + buflen -= namelen;
55633 + if (buflen < 0)
55634 + goto Elong;
55635 + retval -= namelen-1; /* hit the slash */
55636 + memcpy(retval, dentry->d_name.name, namelen);
55637 + goto out;
55638 +Elong:
55639 + retval = ERR_PTR(-ENAMETOOLONG);
55640 + goto out;
55641 +}
55642 +
55643 +static char *
55644 +gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55645 + struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
55646 +{
55647 + char *retval;
55648 +
55649 + retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
55650 + if (unlikely(IS_ERR(retval)))
55651 + retval = strcpy(buf, "<path too long>");
55652 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
55653 + retval[1] = '\0';
55654 +
55655 + return retval;
55656 +}
55657 +
55658 +static char *
55659 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55660 + char *buf, int buflen)
55661 +{
55662 + char *res;
55663 +
55664 + /* we can use real_root, real_root_mnt, because this is only called
55665 + by the RBAC system */
55666 + res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
55667 +
55668 + return res;
55669 +}
55670 +
55671 +static char *
55672 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55673 + char *buf, int buflen)
55674 +{
55675 + char *res;
55676 + struct dentry *root;
55677 + struct vfsmount *rootmnt;
55678 + struct task_struct *reaper = &init_task;
55679 +
55680 + /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
55681 + read_lock(&reaper->fs->lock);
55682 + root = dget(reaper->fs->root.dentry);
55683 + rootmnt = mntget(reaper->fs->root.mnt);
55684 + read_unlock(&reaper->fs->lock);
55685 +
55686 + spin_lock(&dcache_lock);
55687 + spin_lock(&vfsmount_lock);
55688 + res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
55689 + spin_unlock(&vfsmount_lock);
55690 + spin_unlock(&dcache_lock);
55691 +
55692 + dput(root);
55693 + mntput(rootmnt);
55694 + return res;
55695 +}
55696 +
55697 +static char *
55698 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55699 +{
55700 + char *ret;
55701 + spin_lock(&dcache_lock);
55702 + spin_lock(&vfsmount_lock);
55703 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55704 + PAGE_SIZE);
55705 + spin_unlock(&vfsmount_lock);
55706 + spin_unlock(&dcache_lock);
55707 + return ret;
55708 +}
55709 +
55710 +static char *
55711 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55712 +{
55713 + char *ret;
55714 + char *buf;
55715 + int buflen;
55716 +
55717 + spin_lock(&dcache_lock);
55718 + spin_lock(&vfsmount_lock);
55719 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55720 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
55721 + buflen = (int)(ret - buf);
55722 + if (buflen >= 5)
55723 + prepend(&ret, &buflen, "/proc", 5);
55724 + else
55725 + ret = strcpy(buf, "<path too long>");
55726 + spin_unlock(&vfsmount_lock);
55727 + spin_unlock(&dcache_lock);
55728 + return ret;
55729 +}
55730 +
55731 +char *
55732 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
55733 +{
55734 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55735 + PAGE_SIZE);
55736 +}
55737 +
55738 +char *
55739 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
55740 +{
55741 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55742 + PAGE_SIZE);
55743 +}
55744 +
55745 +char *
55746 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
55747 +{
55748 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
55749 + PAGE_SIZE);
55750 +}
55751 +
55752 +char *
55753 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
55754 +{
55755 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
55756 + PAGE_SIZE);
55757 +}
55758 +
55759 +char *
55760 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
55761 +{
55762 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
55763 + PAGE_SIZE);
55764 +}
55765 +
55766 +__inline__ __u32
55767 +to_gr_audit(const __u32 reqmode)
55768 +{
55769 + /* masks off auditable permission flags, then shifts them to create
55770 + auditing flags, and adds the special case of append auditing if
55771 + we're requesting write */
55772 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
55773 +}
55774 +
55775 +struct acl_subject_label *
55776 +lookup_subject_map(const struct acl_subject_label *userp)
55777 +{
55778 + unsigned int index = shash(userp, subj_map_set.s_size);
55779 + struct subject_map *match;
55780 +
55781 + match = subj_map_set.s_hash[index];
55782 +
55783 + while (match && match->user != userp)
55784 + match = match->next;
55785 +
55786 + if (match != NULL)
55787 + return match->kernel;
55788 + else
55789 + return NULL;
55790 +}
55791 +
55792 +static void
55793 +insert_subj_map_entry(struct subject_map *subjmap)
55794 +{
55795 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
55796 + struct subject_map **curr;
55797 +
55798 + subjmap->prev = NULL;
55799 +
55800 + curr = &subj_map_set.s_hash[index];
55801 + if (*curr != NULL)
55802 + (*curr)->prev = subjmap;
55803 +
55804 + subjmap->next = *curr;
55805 + *curr = subjmap;
55806 +
55807 + return;
55808 +}
55809 +
55810 +static struct acl_role_label *
55811 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
55812 + const gid_t gid)
55813 +{
55814 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
55815 + struct acl_role_label *match;
55816 + struct role_allowed_ip *ipp;
55817 + unsigned int x;
55818 + u32 curr_ip = task->signal->curr_ip;
55819 +
55820 + task->signal->saved_ip = curr_ip;
55821 +
55822 + match = acl_role_set.r_hash[index];
55823 +
55824 + while (match) {
55825 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
55826 + for (x = 0; x < match->domain_child_num; x++) {
55827 + if (match->domain_children[x] == uid)
55828 + goto found;
55829 + }
55830 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
55831 + break;
55832 + match = match->next;
55833 + }
55834 +found:
55835 + if (match == NULL) {
55836 + try_group:
55837 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
55838 + match = acl_role_set.r_hash[index];
55839 +
55840 + while (match) {
55841 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
55842 + for (x = 0; x < match->domain_child_num; x++) {
55843 + if (match->domain_children[x] == gid)
55844 + goto found2;
55845 + }
55846 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
55847 + break;
55848 + match = match->next;
55849 + }
55850 +found2:
55851 + if (match == NULL)
55852 + match = default_role;
55853 + if (match->allowed_ips == NULL)
55854 + return match;
55855 + else {
55856 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
55857 + if (likely
55858 + ((ntohl(curr_ip) & ipp->netmask) ==
55859 + (ntohl(ipp->addr) & ipp->netmask)))
55860 + return match;
55861 + }
55862 + match = default_role;
55863 + }
55864 + } else if (match->allowed_ips == NULL) {
55865 + return match;
55866 + } else {
55867 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
55868 + if (likely
55869 + ((ntohl(curr_ip) & ipp->netmask) ==
55870 + (ntohl(ipp->addr) & ipp->netmask)))
55871 + return match;
55872 + }
55873 + goto try_group;
55874 + }
55875 +
55876 + return match;
55877 +}
55878 +
55879 +struct acl_subject_label *
55880 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
55881 + const struct acl_role_label *role)
55882 +{
55883 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
55884 + struct acl_subject_label *match;
55885 +
55886 + match = role->subj_hash[index];
55887 +
55888 + while (match && (match->inode != ino || match->device != dev ||
55889 + (match->mode & GR_DELETED))) {
55890 + match = match->next;
55891 + }
55892 +
55893 + if (match && !(match->mode & GR_DELETED))
55894 + return match;
55895 + else
55896 + return NULL;
55897 +}
55898 +
55899 +struct acl_subject_label *
55900 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
55901 + const struct acl_role_label *role)
55902 +{
55903 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
55904 + struct acl_subject_label *match;
55905 +
55906 + match = role->subj_hash[index];
55907 +
55908 + while (match && (match->inode != ino || match->device != dev ||
55909 + !(match->mode & GR_DELETED))) {
55910 + match = match->next;
55911 + }
55912 +
55913 + if (match && (match->mode & GR_DELETED))
55914 + return match;
55915 + else
55916 + return NULL;
55917 +}
55918 +
55919 +static struct acl_object_label *
55920 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
55921 + const struct acl_subject_label *subj)
55922 +{
55923 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
55924 + struct acl_object_label *match;
55925 +
55926 + match = subj->obj_hash[index];
55927 +
55928 + while (match && (match->inode != ino || match->device != dev ||
55929 + (match->mode & GR_DELETED))) {
55930 + match = match->next;
55931 + }
55932 +
55933 + if (match && !(match->mode & GR_DELETED))
55934 + return match;
55935 + else
55936 + return NULL;
55937 +}
55938 +
55939 +static struct acl_object_label *
55940 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
55941 + const struct acl_subject_label *subj)
55942 +{
55943 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
55944 + struct acl_object_label *match;
55945 +
55946 + match = subj->obj_hash[index];
55947 +
55948 + while (match && (match->inode != ino || match->device != dev ||
55949 + !(match->mode & GR_DELETED))) {
55950 + match = match->next;
55951 + }
55952 +
55953 + if (match && (match->mode & GR_DELETED))
55954 + return match;
55955 +
55956 + match = subj->obj_hash[index];
55957 +
55958 + while (match && (match->inode != ino || match->device != dev ||
55959 + (match->mode & GR_DELETED))) {
55960 + match = match->next;
55961 + }
55962 +
55963 + if (match && !(match->mode & GR_DELETED))
55964 + return match;
55965 + else
55966 + return NULL;
55967 +}
55968 +
55969 +static struct name_entry *
55970 +lookup_name_entry(const char *name)
55971 +{
55972 + unsigned int len = strlen(name);
55973 + unsigned int key = full_name_hash(name, len);
55974 + unsigned int index = key % name_set.n_size;
55975 + struct name_entry *match;
55976 +
55977 + match = name_set.n_hash[index];
55978 +
55979 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55980 + match = match->next;
55981 +
55982 + return match;
55983 +}
55984 +
55985 +static struct name_entry *
55986 +lookup_name_entry_create(const char *name)
55987 +{
55988 + unsigned int len = strlen(name);
55989 + unsigned int key = full_name_hash(name, len);
55990 + unsigned int index = key % name_set.n_size;
55991 + struct name_entry *match;
55992 +
55993 + match = name_set.n_hash[index];
55994 +
55995 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55996 + !match->deleted))
55997 + match = match->next;
55998 +
55999 + if (match && match->deleted)
56000 + return match;
56001 +
56002 + match = name_set.n_hash[index];
56003 +
56004 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56005 + match->deleted))
56006 + match = match->next;
56007 +
56008 + if (match && !match->deleted)
56009 + return match;
56010 + else
56011 + return NULL;
56012 +}
56013 +
56014 +static struct inodev_entry *
56015 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
56016 +{
56017 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
56018 + struct inodev_entry *match;
56019 +
56020 + match = inodev_set.i_hash[index];
56021 +
56022 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
56023 + match = match->next;
56024 +
56025 + return match;
56026 +}
56027 +
56028 +static void
56029 +insert_inodev_entry(struct inodev_entry *entry)
56030 +{
56031 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
56032 + inodev_set.i_size);
56033 + struct inodev_entry **curr;
56034 +
56035 + entry->prev = NULL;
56036 +
56037 + curr = &inodev_set.i_hash[index];
56038 + if (*curr != NULL)
56039 + (*curr)->prev = entry;
56040 +
56041 + entry->next = *curr;
56042 + *curr = entry;
56043 +
56044 + return;
56045 +}
56046 +
56047 +static void
56048 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
56049 +{
56050 + unsigned int index =
56051 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
56052 + struct acl_role_label **curr;
56053 + struct acl_role_label *tmp;
56054 +
56055 + curr = &acl_role_set.r_hash[index];
56056 +
56057 + /* if role was already inserted due to domains and already has
56058 + a role in the same bucket as it attached, then we need to
56059 + combine these two buckets
56060 + */
56061 + if (role->next) {
56062 + tmp = role->next;
56063 + while (tmp->next)
56064 + tmp = tmp->next;
56065 + tmp->next = *curr;
56066 + } else
56067 + role->next = *curr;
56068 + *curr = role;
56069 +
56070 + return;
56071 +}
56072 +
56073 +static void
56074 +insert_acl_role_label(struct acl_role_label *role)
56075 +{
56076 + int i;
56077 +
56078 + if (role_list == NULL) {
56079 + role_list = role;
56080 + role->prev = NULL;
56081 + } else {
56082 + role->prev = role_list;
56083 + role_list = role;
56084 + }
56085 +
56086 + /* used for hash chains */
56087 + role->next = NULL;
56088 +
56089 + if (role->roletype & GR_ROLE_DOMAIN) {
56090 + for (i = 0; i < role->domain_child_num; i++)
56091 + __insert_acl_role_label(role, role->domain_children[i]);
56092 + } else
56093 + __insert_acl_role_label(role, role->uidgid);
56094 +}
56095 +
56096 +static int
56097 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
56098 +{
56099 + struct name_entry **curr, *nentry;
56100 + struct inodev_entry *ientry;
56101 + unsigned int len = strlen(name);
56102 + unsigned int key = full_name_hash(name, len);
56103 + unsigned int index = key % name_set.n_size;
56104 +
56105 + curr = &name_set.n_hash[index];
56106 +
56107 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
56108 + curr = &((*curr)->next);
56109 +
56110 + if (*curr != NULL)
56111 + return 1;
56112 +
56113 + nentry = acl_alloc(sizeof (struct name_entry));
56114 + if (nentry == NULL)
56115 + return 0;
56116 + ientry = acl_alloc(sizeof (struct inodev_entry));
56117 + if (ientry == NULL)
56118 + return 0;
56119 + ientry->nentry = nentry;
56120 +
56121 + nentry->key = key;
56122 + nentry->name = name;
56123 + nentry->inode = inode;
56124 + nentry->device = device;
56125 + nentry->len = len;
56126 + nentry->deleted = deleted;
56127 +
56128 + nentry->prev = NULL;
56129 + curr = &name_set.n_hash[index];
56130 + if (*curr != NULL)
56131 + (*curr)->prev = nentry;
56132 + nentry->next = *curr;
56133 + *curr = nentry;
56134 +
56135 + /* insert us into the table searchable by inode/dev */
56136 + insert_inodev_entry(ientry);
56137 +
56138 + return 1;
56139 +}
56140 +
56141 +static void
56142 +insert_acl_obj_label(struct acl_object_label *obj,
56143 + struct acl_subject_label *subj)
56144 +{
56145 + unsigned int index =
56146 + fhash(obj->inode, obj->device, subj->obj_hash_size);
56147 + struct acl_object_label **curr;
56148 +
56149 +
56150 + obj->prev = NULL;
56151 +
56152 + curr = &subj->obj_hash[index];
56153 + if (*curr != NULL)
56154 + (*curr)->prev = obj;
56155 +
56156 + obj->next = *curr;
56157 + *curr = obj;
56158 +
56159 + return;
56160 +}
56161 +
56162 +static void
56163 +insert_acl_subj_label(struct acl_subject_label *obj,
56164 + struct acl_role_label *role)
56165 +{
56166 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
56167 + struct acl_subject_label **curr;
56168 +
56169 + obj->prev = NULL;
56170 +
56171 + curr = &role->subj_hash[index];
56172 + if (*curr != NULL)
56173 + (*curr)->prev = obj;
56174 +
56175 + obj->next = *curr;
56176 + *curr = obj;
56177 +
56178 + return;
56179 +}
56180 +
56181 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
56182 +
56183 +static void *
56184 +create_table(__u32 * len, int elementsize)
56185 +{
56186 + unsigned int table_sizes[] = {
56187 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
56188 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
56189 + 4194301, 8388593, 16777213, 33554393, 67108859
56190 + };
56191 + void *newtable = NULL;
56192 + unsigned int pwr = 0;
56193 +
56194 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
56195 + table_sizes[pwr] <= *len)
56196 + pwr++;
56197 +
56198 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
56199 + return newtable;
56200 +
56201 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
56202 + newtable =
56203 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
56204 + else
56205 + newtable = vmalloc(table_sizes[pwr] * elementsize);
56206 +
56207 + *len = table_sizes[pwr];
56208 +
56209 + return newtable;
56210 +}
56211 +
56212 +static int
56213 +init_variables(const struct gr_arg *arg)
56214 +{
56215 + struct task_struct *reaper = &init_task;
56216 + unsigned int stacksize;
56217 +
56218 + subj_map_set.s_size = arg->role_db.num_subjects;
56219 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
56220 + name_set.n_size = arg->role_db.num_objects;
56221 + inodev_set.i_size = arg->role_db.num_objects;
56222 +
56223 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
56224 + !name_set.n_size || !inodev_set.i_size)
56225 + return 1;
56226 +
56227 + if (!gr_init_uidset())
56228 + return 1;
56229 +
56230 + /* set up the stack that holds allocation info */
56231 +
56232 + stacksize = arg->role_db.num_pointers + 5;
56233 +
56234 + if (!acl_alloc_stack_init(stacksize))
56235 + return 1;
56236 +
56237 + /* grab reference for the real root dentry and vfsmount */
56238 + read_lock(&reaper->fs->lock);
56239 + real_root = dget(reaper->fs->root.dentry);
56240 + real_root_mnt = mntget(reaper->fs->root.mnt);
56241 + read_unlock(&reaper->fs->lock);
56242 +
56243 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56244 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
56245 +#endif
56246 +
56247 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
56248 + if (fakefs_obj_rw == NULL)
56249 + return 1;
56250 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
56251 +
56252 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
56253 + if (fakefs_obj_rwx == NULL)
56254 + return 1;
56255 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
56256 +
56257 + subj_map_set.s_hash =
56258 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
56259 + acl_role_set.r_hash =
56260 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
56261 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
56262 + inodev_set.i_hash =
56263 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
56264 +
56265 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
56266 + !name_set.n_hash || !inodev_set.i_hash)
56267 + return 1;
56268 +
56269 + memset(subj_map_set.s_hash, 0,
56270 + sizeof(struct subject_map *) * subj_map_set.s_size);
56271 + memset(acl_role_set.r_hash, 0,
56272 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
56273 + memset(name_set.n_hash, 0,
56274 + sizeof (struct name_entry *) * name_set.n_size);
56275 + memset(inodev_set.i_hash, 0,
56276 + sizeof (struct inodev_entry *) * inodev_set.i_size);
56277 +
56278 + return 0;
56279 +}
56280 +
56281 +/* free information not needed after startup
56282 + currently contains user->kernel pointer mappings for subjects
56283 +*/
56284 +
56285 +static void
56286 +free_init_variables(void)
56287 +{
56288 + __u32 i;
56289 +
56290 + if (subj_map_set.s_hash) {
56291 + for (i = 0; i < subj_map_set.s_size; i++) {
56292 + if (subj_map_set.s_hash[i]) {
56293 + kfree(subj_map_set.s_hash[i]);
56294 + subj_map_set.s_hash[i] = NULL;
56295 + }
56296 + }
56297 +
56298 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
56299 + PAGE_SIZE)
56300 + kfree(subj_map_set.s_hash);
56301 + else
56302 + vfree(subj_map_set.s_hash);
56303 + }
56304 +
56305 + return;
56306 +}
56307 +
56308 +static void
56309 +free_variables(void)
56310 +{
56311 + struct acl_subject_label *s;
56312 + struct acl_role_label *r;
56313 + struct task_struct *task, *task2;
56314 + unsigned int x;
56315 +
56316 + gr_clear_learn_entries();
56317 +
56318 + read_lock(&tasklist_lock);
56319 + do_each_thread(task2, task) {
56320 + task->acl_sp_role = 0;
56321 + task->acl_role_id = 0;
56322 + task->acl = NULL;
56323 + task->role = NULL;
56324 + } while_each_thread(task2, task);
56325 + read_unlock(&tasklist_lock);
56326 +
56327 + /* release the reference to the real root dentry and vfsmount */
56328 + if (real_root)
56329 + dput(real_root);
56330 + real_root = NULL;
56331 + if (real_root_mnt)
56332 + mntput(real_root_mnt);
56333 + real_root_mnt = NULL;
56334 +
56335 + /* free all object hash tables */
56336 +
56337 + FOR_EACH_ROLE_START(r)
56338 + if (r->subj_hash == NULL)
56339 + goto next_role;
56340 + FOR_EACH_SUBJECT_START(r, s, x)
56341 + if (s->obj_hash == NULL)
56342 + break;
56343 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56344 + kfree(s->obj_hash);
56345 + else
56346 + vfree(s->obj_hash);
56347 + FOR_EACH_SUBJECT_END(s, x)
56348 + FOR_EACH_NESTED_SUBJECT_START(r, s)
56349 + if (s->obj_hash == NULL)
56350 + break;
56351 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56352 + kfree(s->obj_hash);
56353 + else
56354 + vfree(s->obj_hash);
56355 + FOR_EACH_NESTED_SUBJECT_END(s)
56356 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
56357 + kfree(r->subj_hash);
56358 + else
56359 + vfree(r->subj_hash);
56360 + r->subj_hash = NULL;
56361 +next_role:
56362 + FOR_EACH_ROLE_END(r)
56363 +
56364 + acl_free_all();
56365 +
56366 + if (acl_role_set.r_hash) {
56367 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
56368 + PAGE_SIZE)
56369 + kfree(acl_role_set.r_hash);
56370 + else
56371 + vfree(acl_role_set.r_hash);
56372 + }
56373 + if (name_set.n_hash) {
56374 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
56375 + PAGE_SIZE)
56376 + kfree(name_set.n_hash);
56377 + else
56378 + vfree(name_set.n_hash);
56379 + }
56380 +
56381 + if (inodev_set.i_hash) {
56382 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
56383 + PAGE_SIZE)
56384 + kfree(inodev_set.i_hash);
56385 + else
56386 + vfree(inodev_set.i_hash);
56387 + }
56388 +
56389 + gr_free_uidset();
56390 +
56391 + memset(&name_set, 0, sizeof (struct name_db));
56392 + memset(&inodev_set, 0, sizeof (struct inodev_db));
56393 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
56394 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
56395 +
56396 + default_role = NULL;
56397 + role_list = NULL;
56398 +
56399 + return;
56400 +}
56401 +
56402 +static __u32
56403 +count_user_objs(struct acl_object_label *userp)
56404 +{
56405 + struct acl_object_label o_tmp;
56406 + __u32 num = 0;
56407 +
56408 + while (userp) {
56409 + if (copy_from_user(&o_tmp, userp,
56410 + sizeof (struct acl_object_label)))
56411 + break;
56412 +
56413 + userp = o_tmp.prev;
56414 + num++;
56415 + }
56416 +
56417 + return num;
56418 +}
56419 +
56420 +static struct acl_subject_label *
56421 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
56422 +
56423 +static int
56424 +copy_user_glob(struct acl_object_label *obj)
56425 +{
56426 + struct acl_object_label *g_tmp, **guser;
56427 + unsigned int len;
56428 + char *tmp;
56429 +
56430 + if (obj->globbed == NULL)
56431 + return 0;
56432 +
56433 + guser = &obj->globbed;
56434 + while (*guser) {
56435 + g_tmp = (struct acl_object_label *)
56436 + acl_alloc(sizeof (struct acl_object_label));
56437 + if (g_tmp == NULL)
56438 + return -ENOMEM;
56439 +
56440 + if (copy_from_user(g_tmp, *guser,
56441 + sizeof (struct acl_object_label)))
56442 + return -EFAULT;
56443 +
56444 + len = strnlen_user(g_tmp->filename, PATH_MAX);
56445 +
56446 + if (!len || len >= PATH_MAX)
56447 + return -EINVAL;
56448 +
56449 + if ((tmp = (char *) acl_alloc(len)) == NULL)
56450 + return -ENOMEM;
56451 +
56452 + if (copy_from_user(tmp, g_tmp->filename, len))
56453 + return -EFAULT;
56454 + tmp[len-1] = '\0';
56455 + g_tmp->filename = tmp;
56456 +
56457 + *guser = g_tmp;
56458 + guser = &(g_tmp->next);
56459 + }
56460 +
56461 + return 0;
56462 +}
56463 +
56464 +static int
56465 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
56466 + struct acl_role_label *role)
56467 +{
56468 + struct acl_object_label *o_tmp;
56469 + unsigned int len;
56470 + int ret;
56471 + char *tmp;
56472 +
56473 + while (userp) {
56474 + if ((o_tmp = (struct acl_object_label *)
56475 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
56476 + return -ENOMEM;
56477 +
56478 + if (copy_from_user(o_tmp, userp,
56479 + sizeof (struct acl_object_label)))
56480 + return -EFAULT;
56481 +
56482 + userp = o_tmp->prev;
56483 +
56484 + len = strnlen_user(o_tmp->filename, PATH_MAX);
56485 +
56486 + if (!len || len >= PATH_MAX)
56487 + return -EINVAL;
56488 +
56489 + if ((tmp = (char *) acl_alloc(len)) == NULL)
56490 + return -ENOMEM;
56491 +
56492 + if (copy_from_user(tmp, o_tmp->filename, len))
56493 + return -EFAULT;
56494 + tmp[len-1] = '\0';
56495 + o_tmp->filename = tmp;
56496 +
56497 + insert_acl_obj_label(o_tmp, subj);
56498 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
56499 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
56500 + return -ENOMEM;
56501 +
56502 + ret = copy_user_glob(o_tmp);
56503 + if (ret)
56504 + return ret;
56505 +
56506 + if (o_tmp->nested) {
56507 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
56508 + if (IS_ERR(o_tmp->nested))
56509 + return PTR_ERR(o_tmp->nested);
56510 +
56511 + /* insert into nested subject list */
56512 + o_tmp->nested->next = role->hash->first;
56513 + role->hash->first = o_tmp->nested;
56514 + }
56515 + }
56516 +
56517 + return 0;
56518 +}
56519 +
56520 +static __u32
56521 +count_user_subjs(struct acl_subject_label *userp)
56522 +{
56523 + struct acl_subject_label s_tmp;
56524 + __u32 num = 0;
56525 +
56526 + while (userp) {
56527 + if (copy_from_user(&s_tmp, userp,
56528 + sizeof (struct acl_subject_label)))
56529 + break;
56530 +
56531 + userp = s_tmp.prev;
56532 + /* do not count nested subjects against this count, since
56533 + they are not included in the hash table, but are
56534 + attached to objects. We have already counted
56535 + the subjects in userspace for the allocation
56536 + stack
56537 + */
56538 + if (!(s_tmp.mode & GR_NESTED))
56539 + num++;
56540 + }
56541 +
56542 + return num;
56543 +}
56544 +
56545 +static int
56546 +copy_user_allowedips(struct acl_role_label *rolep)
56547 +{
56548 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
56549 +
56550 + ruserip = rolep->allowed_ips;
56551 +
56552 + while (ruserip) {
56553 + rlast = rtmp;
56554 +
56555 + if ((rtmp = (struct role_allowed_ip *)
56556 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
56557 + return -ENOMEM;
56558 +
56559 + if (copy_from_user(rtmp, ruserip,
56560 + sizeof (struct role_allowed_ip)))
56561 + return -EFAULT;
56562 +
56563 + ruserip = rtmp->prev;
56564 +
56565 + if (!rlast) {
56566 + rtmp->prev = NULL;
56567 + rolep->allowed_ips = rtmp;
56568 + } else {
56569 + rlast->next = rtmp;
56570 + rtmp->prev = rlast;
56571 + }
56572 +
56573 + if (!ruserip)
56574 + rtmp->next = NULL;
56575 + }
56576 +
56577 + return 0;
56578 +}
56579 +
56580 +static int
56581 +copy_user_transitions(struct acl_role_label *rolep)
56582 +{
56583 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
56584 +
56585 + unsigned int len;
56586 + char *tmp;
56587 +
56588 + rusertp = rolep->transitions;
56589 +
56590 + while (rusertp) {
56591 + rlast = rtmp;
56592 +
56593 + if ((rtmp = (struct role_transition *)
56594 + acl_alloc(sizeof (struct role_transition))) == NULL)
56595 + return -ENOMEM;
56596 +
56597 + if (copy_from_user(rtmp, rusertp,
56598 + sizeof (struct role_transition)))
56599 + return -EFAULT;
56600 +
56601 + rusertp = rtmp->prev;
56602 +
56603 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
56604 +
56605 + if (!len || len >= GR_SPROLE_LEN)
56606 + return -EINVAL;
56607 +
56608 + if ((tmp = (char *) acl_alloc(len)) == NULL)
56609 + return -ENOMEM;
56610 +
56611 + if (copy_from_user(tmp, rtmp->rolename, len))
56612 + return -EFAULT;
56613 + tmp[len-1] = '\0';
56614 + rtmp->rolename = tmp;
56615 +
56616 + if (!rlast) {
56617 + rtmp->prev = NULL;
56618 + rolep->transitions = rtmp;
56619 + } else {
56620 + rlast->next = rtmp;
56621 + rtmp->prev = rlast;
56622 + }
56623 +
56624 + if (!rusertp)
56625 + rtmp->next = NULL;
56626 + }
56627 +
56628 + return 0;
56629 +}
56630 +
56631 +static struct acl_subject_label *
56632 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
56633 +{
56634 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
56635 + unsigned int len;
56636 + char *tmp;
56637 + __u32 num_objs;
56638 + struct acl_ip_label **i_tmp, *i_utmp2;
56639 + struct gr_hash_struct ghash;
56640 + struct subject_map *subjmap;
56641 + unsigned int i_num;
56642 + int err;
56643 +
56644 + s_tmp = lookup_subject_map(userp);
56645 +
56646 + /* we've already copied this subject into the kernel, just return
56647 + the reference to it, and don't copy it over again
56648 + */
56649 + if (s_tmp)
56650 + return(s_tmp);
56651 +
56652 + if ((s_tmp = (struct acl_subject_label *)
56653 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
56654 + return ERR_PTR(-ENOMEM);
56655 +
56656 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
56657 + if (subjmap == NULL)
56658 + return ERR_PTR(-ENOMEM);
56659 +
56660 + subjmap->user = userp;
56661 + subjmap->kernel = s_tmp;
56662 + insert_subj_map_entry(subjmap);
56663 +
56664 + if (copy_from_user(s_tmp, userp,
56665 + sizeof (struct acl_subject_label)))
56666 + return ERR_PTR(-EFAULT);
56667 +
56668 + len = strnlen_user(s_tmp->filename, PATH_MAX);
56669 +
56670 + if (!len || len >= PATH_MAX)
56671 + return ERR_PTR(-EINVAL);
56672 +
56673 + if ((tmp = (char *) acl_alloc(len)) == NULL)
56674 + return ERR_PTR(-ENOMEM);
56675 +
56676 + if (copy_from_user(tmp, s_tmp->filename, len))
56677 + return ERR_PTR(-EFAULT);
56678 + tmp[len-1] = '\0';
56679 + s_tmp->filename = tmp;
56680 +
56681 + if (!strcmp(s_tmp->filename, "/"))
56682 + role->root_label = s_tmp;
56683 +
56684 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
56685 + return ERR_PTR(-EFAULT);
56686 +
56687 + /* copy user and group transition tables */
56688 +
56689 + if (s_tmp->user_trans_num) {
56690 + uid_t *uidlist;
56691 +
56692 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
56693 + if (uidlist == NULL)
56694 + return ERR_PTR(-ENOMEM);
56695 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
56696 + return ERR_PTR(-EFAULT);
56697 +
56698 + s_tmp->user_transitions = uidlist;
56699 + }
56700 +
56701 + if (s_tmp->group_trans_num) {
56702 + gid_t *gidlist;
56703 +
56704 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
56705 + if (gidlist == NULL)
56706 + return ERR_PTR(-ENOMEM);
56707 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
56708 + return ERR_PTR(-EFAULT);
56709 +
56710 + s_tmp->group_transitions = gidlist;
56711 + }
56712 +
56713 + /* set up object hash table */
56714 + num_objs = count_user_objs(ghash.first);
56715 +
56716 + s_tmp->obj_hash_size = num_objs;
56717 + s_tmp->obj_hash =
56718 + (struct acl_object_label **)
56719 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
56720 +
56721 + if (!s_tmp->obj_hash)
56722 + return ERR_PTR(-ENOMEM);
56723 +
56724 + memset(s_tmp->obj_hash, 0,
56725 + s_tmp->obj_hash_size *
56726 + sizeof (struct acl_object_label *));
56727 +
56728 + /* add in objects */
56729 + err = copy_user_objs(ghash.first, s_tmp, role);
56730 +
56731 + if (err)
56732 + return ERR_PTR(err);
56733 +
56734 + /* set pointer for parent subject */
56735 + if (s_tmp->parent_subject) {
56736 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
56737 +
56738 + if (IS_ERR(s_tmp2))
56739 + return s_tmp2;
56740 +
56741 + s_tmp->parent_subject = s_tmp2;
56742 + }
56743 +
56744 + /* add in ip acls */
56745 +
56746 + if (!s_tmp->ip_num) {
56747 + s_tmp->ips = NULL;
56748 + goto insert;
56749 + }
56750 +
56751 + i_tmp =
56752 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
56753 + sizeof (struct acl_ip_label *));
56754 +
56755 + if (!i_tmp)
56756 + return ERR_PTR(-ENOMEM);
56757 +
56758 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
56759 + *(i_tmp + i_num) =
56760 + (struct acl_ip_label *)
56761 + acl_alloc(sizeof (struct acl_ip_label));
56762 + if (!*(i_tmp + i_num))
56763 + return ERR_PTR(-ENOMEM);
56764 +
56765 + if (copy_from_user
56766 + (&i_utmp2, s_tmp->ips + i_num,
56767 + sizeof (struct acl_ip_label *)))
56768 + return ERR_PTR(-EFAULT);
56769 +
56770 + if (copy_from_user
56771 + (*(i_tmp + i_num), i_utmp2,
56772 + sizeof (struct acl_ip_label)))
56773 + return ERR_PTR(-EFAULT);
56774 +
56775 + if ((*(i_tmp + i_num))->iface == NULL)
56776 + continue;
56777 +
56778 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
56779 + if (!len || len >= IFNAMSIZ)
56780 + return ERR_PTR(-EINVAL);
56781 + tmp = acl_alloc(len);
56782 + if (tmp == NULL)
56783 + return ERR_PTR(-ENOMEM);
56784 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
56785 + return ERR_PTR(-EFAULT);
56786 + (*(i_tmp + i_num))->iface = tmp;
56787 + }
56788 +
56789 + s_tmp->ips = i_tmp;
56790 +
56791 +insert:
56792 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
56793 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
56794 + return ERR_PTR(-ENOMEM);
56795 +
56796 + return s_tmp;
56797 +}
56798 +
56799 +static int
56800 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
56801 +{
56802 + struct acl_subject_label s_pre;
56803 + struct acl_subject_label * ret;
56804 + int err;
56805 +
56806 + while (userp) {
56807 + if (copy_from_user(&s_pre, userp,
56808 + sizeof (struct acl_subject_label)))
56809 + return -EFAULT;
56810 +
56811 + /* do not add nested subjects here, add
56812 + while parsing objects
56813 + */
56814 +
56815 + if (s_pre.mode & GR_NESTED) {
56816 + userp = s_pre.prev;
56817 + continue;
56818 + }
56819 +
56820 + ret = do_copy_user_subj(userp, role);
56821 +
56822 + err = PTR_ERR(ret);
56823 + if (IS_ERR(ret))
56824 + return err;
56825 +
56826 + insert_acl_subj_label(ret, role);
56827 +
56828 + userp = s_pre.prev;
56829 + }
56830 +
56831 + return 0;
56832 +}
56833 +
56834 +static int
56835 +copy_user_acl(struct gr_arg *arg)
56836 +{
56837 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
56838 + struct sprole_pw *sptmp;
56839 + struct gr_hash_struct *ghash;
56840 + uid_t *domainlist;
56841 + unsigned int r_num;
56842 + unsigned int len;
56843 + char *tmp;
56844 + int err = 0;
56845 + __u16 i;
56846 + __u32 num_subjs;
56847 +
56848 + /* we need a default and kernel role */
56849 + if (arg->role_db.num_roles < 2)
56850 + return -EINVAL;
56851 +
56852 + /* copy special role authentication info from userspace */
56853 +
56854 + num_sprole_pws = arg->num_sprole_pws;
56855 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
56856 +
56857 + if (!acl_special_roles) {
56858 + err = -ENOMEM;
56859 + goto cleanup;
56860 + }
56861 +
56862 + for (i = 0; i < num_sprole_pws; i++) {
56863 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
56864 + if (!sptmp) {
56865 + err = -ENOMEM;
56866 + goto cleanup;
56867 + }
56868 + if (copy_from_user(sptmp, arg->sprole_pws + i,
56869 + sizeof (struct sprole_pw))) {
56870 + err = -EFAULT;
56871 + goto cleanup;
56872 + }
56873 +
56874 + len =
56875 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
56876 +
56877 + if (!len || len >= GR_SPROLE_LEN) {
56878 + err = -EINVAL;
56879 + goto cleanup;
56880 + }
56881 +
56882 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
56883 + err = -ENOMEM;
56884 + goto cleanup;
56885 + }
56886 +
56887 + if (copy_from_user(tmp, sptmp->rolename, len)) {
56888 + err = -EFAULT;
56889 + goto cleanup;
56890 + }
56891 + tmp[len-1] = '\0';
56892 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56893 + printk(KERN_ALERT "Copying special role %s\n", tmp);
56894 +#endif
56895 + sptmp->rolename = tmp;
56896 + acl_special_roles[i] = sptmp;
56897 + }
56898 +
56899 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
56900 +
56901 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
56902 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
56903 +
56904 + if (!r_tmp) {
56905 + err = -ENOMEM;
56906 + goto cleanup;
56907 + }
56908 +
56909 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
56910 + sizeof (struct acl_role_label *))) {
56911 + err = -EFAULT;
56912 + goto cleanup;
56913 + }
56914 +
56915 + if (copy_from_user(r_tmp, r_utmp2,
56916 + sizeof (struct acl_role_label))) {
56917 + err = -EFAULT;
56918 + goto cleanup;
56919 + }
56920 +
56921 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
56922 +
56923 + if (!len || len >= PATH_MAX) {
56924 + err = -EINVAL;
56925 + goto cleanup;
56926 + }
56927 +
56928 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
56929 + err = -ENOMEM;
56930 + goto cleanup;
56931 + }
56932 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
56933 + err = -EFAULT;
56934 + goto cleanup;
56935 + }
56936 + tmp[len-1] = '\0';
56937 + r_tmp->rolename = tmp;
56938 +
56939 + if (!strcmp(r_tmp->rolename, "default")
56940 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
56941 + default_role = r_tmp;
56942 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56943 + kernel_role = r_tmp;
56944 + }
56945 +
56946 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
56947 + err = -ENOMEM;
56948 + goto cleanup;
56949 + }
56950 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
56951 + err = -EFAULT;
56952 + goto cleanup;
56953 + }
56954 +
56955 + r_tmp->hash = ghash;
56956 +
56957 + num_subjs = count_user_subjs(r_tmp->hash->first);
56958 +
56959 + r_tmp->subj_hash_size = num_subjs;
56960 + r_tmp->subj_hash =
56961 + (struct acl_subject_label **)
56962 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56963 +
56964 + if (!r_tmp->subj_hash) {
56965 + err = -ENOMEM;
56966 + goto cleanup;
56967 + }
56968 +
56969 + err = copy_user_allowedips(r_tmp);
56970 + if (err)
56971 + goto cleanup;
56972 +
56973 + /* copy domain info */
56974 + if (r_tmp->domain_children != NULL) {
56975 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56976 + if (domainlist == NULL) {
56977 + err = -ENOMEM;
56978 + goto cleanup;
56979 + }
56980 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
56981 + err = -EFAULT;
56982 + goto cleanup;
56983 + }
56984 + r_tmp->domain_children = domainlist;
56985 + }
56986 +
56987 + err = copy_user_transitions(r_tmp);
56988 + if (err)
56989 + goto cleanup;
56990 +
56991 + memset(r_tmp->subj_hash, 0,
56992 + r_tmp->subj_hash_size *
56993 + sizeof (struct acl_subject_label *));
56994 +
56995 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
56996 +
56997 + if (err)
56998 + goto cleanup;
56999 +
57000 + /* set nested subject list to null */
57001 + r_tmp->hash->first = NULL;
57002 +
57003 + insert_acl_role_label(r_tmp);
57004 + }
57005 +
57006 + goto return_err;
57007 + cleanup:
57008 + free_variables();
57009 + return_err:
57010 + return err;
57011 +
57012 +}
57013 +
57014 +static int
57015 +gracl_init(struct gr_arg *args)
57016 +{
57017 + int error = 0;
57018 +
57019 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
57020 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
57021 +
57022 + if (init_variables(args)) {
57023 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
57024 + error = -ENOMEM;
57025 + free_variables();
57026 + goto out;
57027 + }
57028 +
57029 + error = copy_user_acl(args);
57030 + free_init_variables();
57031 + if (error) {
57032 + free_variables();
57033 + goto out;
57034 + }
57035 +
57036 + if ((error = gr_set_acls(0))) {
57037 + free_variables();
57038 + goto out;
57039 + }
57040 +
57041 + pax_open_kernel();
57042 + gr_status |= GR_READY;
57043 + pax_close_kernel();
57044 +
57045 + out:
57046 + return error;
57047 +}
57048 +
57049 +/* derived from glibc fnmatch() 0: match, 1: no match*/
57050 +
57051 +static int
57052 +glob_match(const char *p, const char *n)
57053 +{
57054 + char c;
57055 +
57056 + while ((c = *p++) != '\0') {
57057 + switch (c) {
57058 + case '?':
57059 + if (*n == '\0')
57060 + return 1;
57061 + else if (*n == '/')
57062 + return 1;
57063 + break;
57064 + case '\\':
57065 + if (*n != c)
57066 + return 1;
57067 + break;
57068 + case '*':
57069 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
57070 + if (*n == '/')
57071 + return 1;
57072 + else if (c == '?') {
57073 + if (*n == '\0')
57074 + return 1;
57075 + else
57076 + ++n;
57077 + }
57078 + }
57079 + if (c == '\0') {
57080 + return 0;
57081 + } else {
57082 + const char *endp;
57083 +
57084 + if ((endp = strchr(n, '/')) == NULL)
57085 + endp = n + strlen(n);
57086 +
57087 + if (c == '[') {
57088 + for (--p; n < endp; ++n)
57089 + if (!glob_match(p, n))
57090 + return 0;
57091 + } else if (c == '/') {
57092 + while (*n != '\0' && *n != '/')
57093 + ++n;
57094 + if (*n == '/' && !glob_match(p, n + 1))
57095 + return 0;
57096 + } else {
57097 + for (--p; n < endp; ++n)
57098 + if (*n == c && !glob_match(p, n))
57099 + return 0;
57100 + }
57101 +
57102 + return 1;
57103 + }
57104 + case '[':
57105 + {
57106 + int not;
57107 + char cold;
57108 +
57109 + if (*n == '\0' || *n == '/')
57110 + return 1;
57111 +
57112 + not = (*p == '!' || *p == '^');
57113 + if (not)
57114 + ++p;
57115 +
57116 + c = *p++;
57117 + for (;;) {
57118 + unsigned char fn = (unsigned char)*n;
57119 +
57120 + if (c == '\0')
57121 + return 1;
57122 + else {
57123 + if (c == fn)
57124 + goto matched;
57125 + cold = c;
57126 + c = *p++;
57127 +
57128 + if (c == '-' && *p != ']') {
57129 + unsigned char cend = *p++;
57130 +
57131 + if (cend == '\0')
57132 + return 1;
57133 +
57134 + if (cold <= fn && fn <= cend)
57135 + goto matched;
57136 +
57137 + c = *p++;
57138 + }
57139 + }
57140 +
57141 + if (c == ']')
57142 + break;
57143 + }
57144 + if (!not)
57145 + return 1;
57146 + break;
57147 + matched:
57148 + while (c != ']') {
57149 + if (c == '\0')
57150 + return 1;
57151 +
57152 + c = *p++;
57153 + }
57154 + if (not)
57155 + return 1;
57156 + }
57157 + break;
57158 + default:
57159 + if (c != *n)
57160 + return 1;
57161 + }
57162 +
57163 + ++n;
57164 + }
57165 +
57166 + if (*n == '\0')
57167 + return 0;
57168 +
57169 + if (*n == '/')
57170 + return 0;
57171 +
57172 + return 1;
57173 +}
57174 +
57175 +static struct acl_object_label *
57176 +chk_glob_label(struct acl_object_label *globbed,
57177 + struct dentry *dentry, struct vfsmount *mnt, char **path)
57178 +{
57179 + struct acl_object_label *tmp;
57180 +
57181 + if (*path == NULL)
57182 + *path = gr_to_filename_nolock(dentry, mnt);
57183 +
57184 + tmp = globbed;
57185 +
57186 + while (tmp) {
57187 + if (!glob_match(tmp->filename, *path))
57188 + return tmp;
57189 + tmp = tmp->next;
57190 + }
57191 +
57192 + return NULL;
57193 +}
57194 +
57195 +static struct acl_object_label *
57196 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57197 + const ino_t curr_ino, const dev_t curr_dev,
57198 + const struct acl_subject_label *subj, char **path, const int checkglob)
57199 +{
57200 + struct acl_subject_label *tmpsubj;
57201 + struct acl_object_label *retval;
57202 + struct acl_object_label *retval2;
57203 +
57204 + tmpsubj = (struct acl_subject_label *) subj;
57205 + read_lock(&gr_inode_lock);
57206 + do {
57207 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
57208 + if (retval) {
57209 + if (checkglob && retval->globbed) {
57210 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
57211 + (struct vfsmount *)orig_mnt, path);
57212 + if (retval2)
57213 + retval = retval2;
57214 + }
57215 + break;
57216 + }
57217 + } while ((tmpsubj = tmpsubj->parent_subject));
57218 + read_unlock(&gr_inode_lock);
57219 +
57220 + return retval;
57221 +}
57222 +
57223 +static __inline__ struct acl_object_label *
57224 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57225 + const struct dentry *curr_dentry,
57226 + const struct acl_subject_label *subj, char **path, const int checkglob)
57227 +{
57228 + int newglob = checkglob;
57229 +
57230 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
57231 + as we don't want a / * rule to match instead of the / object
57232 + don't do this for create lookups that call this function though, since they're looking up
57233 + on the parent and thus need globbing checks on all paths
57234 + */
57235 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
57236 + newglob = GR_NO_GLOB;
57237 +
57238 + return __full_lookup(orig_dentry, orig_mnt,
57239 + curr_dentry->d_inode->i_ino,
57240 + __get_dev(curr_dentry), subj, path, newglob);
57241 +}
57242 +
57243 +static struct acl_object_label *
57244 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57245 + const struct acl_subject_label *subj, char *path, const int checkglob)
57246 +{
57247 + struct dentry *dentry = (struct dentry *) l_dentry;
57248 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57249 + struct acl_object_label *retval;
57250 +
57251 + spin_lock(&dcache_lock);
57252 + spin_lock(&vfsmount_lock);
57253 +
57254 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
57255 +#ifdef CONFIG_NET
57256 + mnt == sock_mnt ||
57257 +#endif
57258 +#ifdef CONFIG_HUGETLBFS
57259 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
57260 +#endif
57261 + /* ignore Eric Biederman */
57262 + IS_PRIVATE(l_dentry->d_inode))) {
57263 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
57264 + goto out;
57265 + }
57266 +
57267 + for (;;) {
57268 + if (dentry == real_root && mnt == real_root_mnt)
57269 + break;
57270 +
57271 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57272 + if (mnt->mnt_parent == mnt)
57273 + break;
57274 +
57275 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57276 + if (retval != NULL)
57277 + goto out;
57278 +
57279 + dentry = mnt->mnt_mountpoint;
57280 + mnt = mnt->mnt_parent;
57281 + continue;
57282 + }
57283 +
57284 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57285 + if (retval != NULL)
57286 + goto out;
57287 +
57288 + dentry = dentry->d_parent;
57289 + }
57290 +
57291 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57292 +
57293 + if (retval == NULL)
57294 + retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
57295 +out:
57296 + spin_unlock(&vfsmount_lock);
57297 + spin_unlock(&dcache_lock);
57298 +
57299 + BUG_ON(retval == NULL);
57300 +
57301 + return retval;
57302 +}
57303 +
57304 +static __inline__ struct acl_object_label *
57305 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57306 + const struct acl_subject_label *subj)
57307 +{
57308 + char *path = NULL;
57309 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
57310 +}
57311 +
57312 +static __inline__ struct acl_object_label *
57313 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57314 + const struct acl_subject_label *subj)
57315 +{
57316 + char *path = NULL;
57317 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
57318 +}
57319 +
57320 +static __inline__ struct acl_object_label *
57321 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57322 + const struct acl_subject_label *subj, char *path)
57323 +{
57324 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
57325 +}
57326 +
57327 +static struct acl_subject_label *
57328 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57329 + const struct acl_role_label *role)
57330 +{
57331 + struct dentry *dentry = (struct dentry *) l_dentry;
57332 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57333 + struct acl_subject_label *retval;
57334 +
57335 + spin_lock(&dcache_lock);
57336 + spin_lock(&vfsmount_lock);
57337 +
57338 + for (;;) {
57339 + if (dentry == real_root && mnt == real_root_mnt)
57340 + break;
57341 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57342 + if (mnt->mnt_parent == mnt)
57343 + break;
57344 +
57345 + read_lock(&gr_inode_lock);
57346 + retval =
57347 + lookup_acl_subj_label(dentry->d_inode->i_ino,
57348 + __get_dev(dentry), role);
57349 + read_unlock(&gr_inode_lock);
57350 + if (retval != NULL)
57351 + goto out;
57352 +
57353 + dentry = mnt->mnt_mountpoint;
57354 + mnt = mnt->mnt_parent;
57355 + continue;
57356 + }
57357 +
57358 + read_lock(&gr_inode_lock);
57359 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57360 + __get_dev(dentry), role);
57361 + read_unlock(&gr_inode_lock);
57362 + if (retval != NULL)
57363 + goto out;
57364 +
57365 + dentry = dentry->d_parent;
57366 + }
57367 +
57368 + read_lock(&gr_inode_lock);
57369 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57370 + __get_dev(dentry), role);
57371 + read_unlock(&gr_inode_lock);
57372 +
57373 + if (unlikely(retval == NULL)) {
57374 + read_lock(&gr_inode_lock);
57375 + retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
57376 + __get_dev(real_root), role);
57377 + read_unlock(&gr_inode_lock);
57378 + }
57379 +out:
57380 + spin_unlock(&vfsmount_lock);
57381 + spin_unlock(&dcache_lock);
57382 +
57383 + BUG_ON(retval == NULL);
57384 +
57385 + return retval;
57386 +}
57387 +
57388 +static void
57389 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
57390 +{
57391 + struct task_struct *task = current;
57392 + const struct cred *cred = current_cred();
57393 +
57394 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57395 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57396 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57397 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
57398 +
57399 + return;
57400 +}
57401 +
57402 +static void
57403 +gr_log_learn_sysctl(const char *path, const __u32 mode)
57404 +{
57405 + struct task_struct *task = current;
57406 + const struct cred *cred = current_cred();
57407 +
57408 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57409 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57410 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57411 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
57412 +
57413 + return;
57414 +}
57415 +
57416 +static void
57417 +gr_log_learn_id_change(const char type, const unsigned int real,
57418 + const unsigned int effective, const unsigned int fs)
57419 +{
57420 + struct task_struct *task = current;
57421 + const struct cred *cred = current_cred();
57422 +
57423 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
57424 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57425 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57426 + type, real, effective, fs, &task->signal->saved_ip);
57427 +
57428 + return;
57429 +}
57430 +
57431 +__u32
57432 +gr_search_file(const struct dentry * dentry, const __u32 mode,
57433 + const struct vfsmount * mnt)
57434 +{
57435 + __u32 retval = mode;
57436 + struct acl_subject_label *curracl;
57437 + struct acl_object_label *currobj;
57438 +
57439 + if (unlikely(!(gr_status & GR_READY)))
57440 + return (mode & ~GR_AUDITS);
57441 +
57442 + curracl = current->acl;
57443 +
57444 + currobj = chk_obj_label(dentry, mnt, curracl);
57445 + retval = currobj->mode & mode;
57446 +
57447 + /* if we're opening a specified transfer file for writing
57448 + (e.g. /dev/initctl), then transfer our role to init
57449 + */
57450 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
57451 + current->role->roletype & GR_ROLE_PERSIST)) {
57452 + struct task_struct *task = init_pid_ns.child_reaper;
57453 +
57454 + if (task->role != current->role) {
57455 + task->acl_sp_role = 0;
57456 + task->acl_role_id = current->acl_role_id;
57457 + task->role = current->role;
57458 + rcu_read_lock();
57459 + read_lock(&grsec_exec_file_lock);
57460 + gr_apply_subject_to_task(task);
57461 + read_unlock(&grsec_exec_file_lock);
57462 + rcu_read_unlock();
57463 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
57464 + }
57465 + }
57466 +
57467 + if (unlikely
57468 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
57469 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
57470 + __u32 new_mode = mode;
57471 +
57472 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57473 +
57474 + retval = new_mode;
57475 +
57476 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
57477 + new_mode |= GR_INHERIT;
57478 +
57479 + if (!(mode & GR_NOLEARN))
57480 + gr_log_learn(dentry, mnt, new_mode);
57481 + }
57482 +
57483 + return retval;
57484 +}
57485 +
57486 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
57487 + const struct dentry *parent,
57488 + const struct vfsmount *mnt)
57489 +{
57490 + struct name_entry *match;
57491 + struct acl_object_label *matchpo;
57492 + struct acl_subject_label *curracl;
57493 + char *path;
57494 +
57495 + if (unlikely(!(gr_status & GR_READY)))
57496 + return NULL;
57497 +
57498 + preempt_disable();
57499 + path = gr_to_filename_rbac(new_dentry, mnt);
57500 + match = lookup_name_entry_create(path);
57501 +
57502 + curracl = current->acl;
57503 +
57504 + if (match) {
57505 + read_lock(&gr_inode_lock);
57506 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
57507 + read_unlock(&gr_inode_lock);
57508 +
57509 + if (matchpo) {
57510 + preempt_enable();
57511 + return matchpo;
57512 + }
57513 + }
57514 +
57515 + // lookup parent
57516 +
57517 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
57518 +
57519 + preempt_enable();
57520 + return matchpo;
57521 +}
57522 +
57523 +__u32
57524 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
57525 + const struct vfsmount * mnt, const __u32 mode)
57526 +{
57527 + struct acl_object_label *matchpo;
57528 + __u32 retval;
57529 +
57530 + if (unlikely(!(gr_status & GR_READY)))
57531 + return (mode & ~GR_AUDITS);
57532 +
57533 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
57534 +
57535 + retval = matchpo->mode & mode;
57536 +
57537 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
57538 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57539 + __u32 new_mode = mode;
57540 +
57541 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57542 +
57543 + gr_log_learn(new_dentry, mnt, new_mode);
57544 + return new_mode;
57545 + }
57546 +
57547 + return retval;
57548 +}
57549 +
57550 +__u32
57551 +gr_check_link(const struct dentry * new_dentry,
57552 + const struct dentry * parent_dentry,
57553 + const struct vfsmount * parent_mnt,
57554 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
57555 +{
57556 + struct acl_object_label *obj;
57557 + __u32 oldmode, newmode;
57558 + __u32 needmode;
57559 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
57560 + GR_DELETE | GR_INHERIT;
57561 +
57562 + if (unlikely(!(gr_status & GR_READY)))
57563 + return (GR_CREATE | GR_LINK);
57564 +
57565 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
57566 + oldmode = obj->mode;
57567 +
57568 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
57569 + newmode = obj->mode;
57570 +
57571 + needmode = newmode & checkmodes;
57572 +
57573 + // old name for hardlink must have at least the permissions of the new name
57574 + if ((oldmode & needmode) != needmode)
57575 + goto bad;
57576 +
57577 + // if old name had restrictions/auditing, make sure the new name does as well
57578 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
57579 +
57580 + // don't allow hardlinking of suid/sgid files without permission
57581 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57582 + needmode |= GR_SETID;
57583 +
57584 + if ((newmode & needmode) != needmode)
57585 + goto bad;
57586 +
57587 + // enforce minimum permissions
57588 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
57589 + return newmode;
57590 +bad:
57591 + needmode = oldmode;
57592 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57593 + needmode |= GR_SETID;
57594 +
57595 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
57596 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
57597 + return (GR_CREATE | GR_LINK);
57598 + } else if (newmode & GR_SUPPRESS)
57599 + return GR_SUPPRESS;
57600 + else
57601 + return 0;
57602 +}
57603 +
57604 +int
57605 +gr_check_hidden_task(const struct task_struct *task)
57606 +{
57607 + if (unlikely(!(gr_status & GR_READY)))
57608 + return 0;
57609 +
57610 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
57611 + return 1;
57612 +
57613 + return 0;
57614 +}
57615 +
57616 +int
57617 +gr_check_protected_task(const struct task_struct *task)
57618 +{
57619 + if (unlikely(!(gr_status & GR_READY) || !task))
57620 + return 0;
57621 +
57622 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57623 + task->acl != current->acl)
57624 + return 1;
57625 +
57626 + return 0;
57627 +}
57628 +
57629 +int
57630 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57631 +{
57632 + struct task_struct *p;
57633 + int ret = 0;
57634 +
57635 + if (unlikely(!(gr_status & GR_READY) || !pid))
57636 + return ret;
57637 +
57638 + read_lock(&tasklist_lock);
57639 + do_each_pid_task(pid, type, p) {
57640 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57641 + p->acl != current->acl) {
57642 + ret = 1;
57643 + goto out;
57644 + }
57645 + } while_each_pid_task(pid, type, p);
57646 +out:
57647 + read_unlock(&tasklist_lock);
57648 +
57649 + return ret;
57650 +}
57651 +
57652 +void
57653 +gr_copy_label(struct task_struct *tsk)
57654 +{
57655 + tsk->signal->used_accept = 0;
57656 + tsk->acl_sp_role = 0;
57657 + tsk->acl_role_id = current->acl_role_id;
57658 + tsk->acl = current->acl;
57659 + tsk->role = current->role;
57660 + tsk->signal->curr_ip = current->signal->curr_ip;
57661 + tsk->signal->saved_ip = current->signal->saved_ip;
57662 + if (current->exec_file)
57663 + get_file(current->exec_file);
57664 + tsk->exec_file = current->exec_file;
57665 + tsk->is_writable = current->is_writable;
57666 + if (unlikely(current->signal->used_accept)) {
57667 + current->signal->curr_ip = 0;
57668 + current->signal->saved_ip = 0;
57669 + }
57670 +
57671 + return;
57672 +}
57673 +
57674 +static void
57675 +gr_set_proc_res(struct task_struct *task)
57676 +{
57677 + struct acl_subject_label *proc;
57678 + unsigned short i;
57679 +
57680 + proc = task->acl;
57681 +
57682 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
57683 + return;
57684 +
57685 + for (i = 0; i < RLIM_NLIMITS; i++) {
57686 + if (!(proc->resmask & (1 << i)))
57687 + continue;
57688 +
57689 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
57690 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
57691 + }
57692 +
57693 + return;
57694 +}
57695 +
57696 +extern int __gr_process_user_ban(struct user_struct *user);
57697 +
57698 +int
57699 +gr_check_user_change(int real, int effective, int fs)
57700 +{
57701 + unsigned int i;
57702 + __u16 num;
57703 + uid_t *uidlist;
57704 + int curuid;
57705 + int realok = 0;
57706 + int effectiveok = 0;
57707 + int fsok = 0;
57708 +
57709 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57710 + struct user_struct *user;
57711 +
57712 + if (real == -1)
57713 + goto skipit;
57714 +
57715 + user = find_user(real);
57716 + if (user == NULL)
57717 + goto skipit;
57718 +
57719 + if (__gr_process_user_ban(user)) {
57720 + /* for find_user */
57721 + free_uid(user);
57722 + return 1;
57723 + }
57724 +
57725 + /* for find_user */
57726 + free_uid(user);
57727 +
57728 +skipit:
57729 +#endif
57730 +
57731 + if (unlikely(!(gr_status & GR_READY)))
57732 + return 0;
57733 +
57734 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57735 + gr_log_learn_id_change('u', real, effective, fs);
57736 +
57737 + num = current->acl->user_trans_num;
57738 + uidlist = current->acl->user_transitions;
57739 +
57740 + if (uidlist == NULL)
57741 + return 0;
57742 +
57743 + if (real == -1)
57744 + realok = 1;
57745 + if (effective == -1)
57746 + effectiveok = 1;
57747 + if (fs == -1)
57748 + fsok = 1;
57749 +
57750 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
57751 + for (i = 0; i < num; i++) {
57752 + curuid = (int)uidlist[i];
57753 + if (real == curuid)
57754 + realok = 1;
57755 + if (effective == curuid)
57756 + effectiveok = 1;
57757 + if (fs == curuid)
57758 + fsok = 1;
57759 + }
57760 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
57761 + for (i = 0; i < num; i++) {
57762 + curuid = (int)uidlist[i];
57763 + if (real == curuid)
57764 + break;
57765 + if (effective == curuid)
57766 + break;
57767 + if (fs == curuid)
57768 + break;
57769 + }
57770 + /* not in deny list */
57771 + if (i == num) {
57772 + realok = 1;
57773 + effectiveok = 1;
57774 + fsok = 1;
57775 + }
57776 + }
57777 +
57778 + if (realok && effectiveok && fsok)
57779 + return 0;
57780 + else {
57781 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
57782 + return 1;
57783 + }
57784 +}
57785 +
57786 +int
57787 +gr_check_group_change(int real, int effective, int fs)
57788 +{
57789 + unsigned int i;
57790 + __u16 num;
57791 + gid_t *gidlist;
57792 + int curgid;
57793 + int realok = 0;
57794 + int effectiveok = 0;
57795 + int fsok = 0;
57796 +
57797 + if (unlikely(!(gr_status & GR_READY)))
57798 + return 0;
57799 +
57800 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57801 + gr_log_learn_id_change('g', real, effective, fs);
57802 +
57803 + num = current->acl->group_trans_num;
57804 + gidlist = current->acl->group_transitions;
57805 +
57806 + if (gidlist == NULL)
57807 + return 0;
57808 +
57809 + if (real == -1)
57810 + realok = 1;
57811 + if (effective == -1)
57812 + effectiveok = 1;
57813 + if (fs == -1)
57814 + fsok = 1;
57815 +
57816 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
57817 + for (i = 0; i < num; i++) {
57818 + curgid = (int)gidlist[i];
57819 + if (real == curgid)
57820 + realok = 1;
57821 + if (effective == curgid)
57822 + effectiveok = 1;
57823 + if (fs == curgid)
57824 + fsok = 1;
57825 + }
57826 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
57827 + for (i = 0; i < num; i++) {
57828 + curgid = (int)gidlist[i];
57829 + if (real == curgid)
57830 + break;
57831 + if (effective == curgid)
57832 + break;
57833 + if (fs == curgid)
57834 + break;
57835 + }
57836 + /* not in deny list */
57837 + if (i == num) {
57838 + realok = 1;
57839 + effectiveok = 1;
57840 + fsok = 1;
57841 + }
57842 + }
57843 +
57844 + if (realok && effectiveok && fsok)
57845 + return 0;
57846 + else {
57847 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
57848 + return 1;
57849 + }
57850 +}
57851 +
57852 +void
57853 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
57854 +{
57855 + struct acl_role_label *role = task->role;
57856 + struct acl_subject_label *subj = NULL;
57857 + struct acl_object_label *obj;
57858 + struct file *filp;
57859 +
57860 + if (unlikely(!(gr_status & GR_READY)))
57861 + return;
57862 +
57863 + filp = task->exec_file;
57864 +
57865 + /* kernel process, we'll give them the kernel role */
57866 + if (unlikely(!filp)) {
57867 + task->role = kernel_role;
57868 + task->acl = kernel_role->root_label;
57869 + return;
57870 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
57871 + role = lookup_acl_role_label(task, uid, gid);
57872 +
57873 + /* perform subject lookup in possibly new role
57874 + we can use this result below in the case where role == task->role
57875 + */
57876 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
57877 +
57878 + /* if we changed uid/gid, but result in the same role
57879 + and are using inheritance, don't lose the inherited subject
57880 + if current subject is other than what normal lookup
57881 + would result in, we arrived via inheritance, don't
57882 + lose subject
57883 + */
57884 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
57885 + (subj == task->acl)))
57886 + task->acl = subj;
57887 +
57888 + task->role = role;
57889 +
57890 + task->is_writable = 0;
57891 +
57892 + /* ignore additional mmap checks for processes that are writable
57893 + by the default ACL */
57894 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57895 + if (unlikely(obj->mode & GR_WRITE))
57896 + task->is_writable = 1;
57897 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57898 + if (unlikely(obj->mode & GR_WRITE))
57899 + task->is_writable = 1;
57900 +
57901 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57902 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57903 +#endif
57904 +
57905 + gr_set_proc_res(task);
57906 +
57907 + return;
57908 +}
57909 +
57910 +int
57911 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57912 + const int unsafe_share)
57913 +{
57914 + struct task_struct *task = current;
57915 + struct acl_subject_label *newacl;
57916 + struct acl_object_label *obj;
57917 + __u32 retmode;
57918 +
57919 + if (unlikely(!(gr_status & GR_READY)))
57920 + return 0;
57921 +
57922 + newacl = chk_subj_label(dentry, mnt, task->role);
57923 +
57924 + task_lock(task);
57925 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
57926 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57927 + !(task->role->roletype & GR_ROLE_GOD) &&
57928 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57929 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
57930 + task_unlock(task);
57931 + if (unsafe_share)
57932 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57933 + else
57934 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57935 + return -EACCES;
57936 + }
57937 + task_unlock(task);
57938 +
57939 + obj = chk_obj_label(dentry, mnt, task->acl);
57940 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57941 +
57942 + if (!(task->acl->mode & GR_INHERITLEARN) &&
57943 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57944 + if (obj->nested)
57945 + task->acl = obj->nested;
57946 + else
57947 + task->acl = newacl;
57948 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57949 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57950 +
57951 + task->is_writable = 0;
57952 +
57953 + /* ignore additional mmap checks for processes that are writable
57954 + by the default ACL */
57955 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
57956 + if (unlikely(obj->mode & GR_WRITE))
57957 + task->is_writable = 1;
57958 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
57959 + if (unlikely(obj->mode & GR_WRITE))
57960 + task->is_writable = 1;
57961 +
57962 + gr_set_proc_res(task);
57963 +
57964 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57965 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57966 +#endif
57967 + return 0;
57968 +}
57969 +
57970 +/* always called with valid inodev ptr */
57971 +static void
57972 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57973 +{
57974 + struct acl_object_label *matchpo;
57975 + struct acl_subject_label *matchps;
57976 + struct acl_subject_label *subj;
57977 + struct acl_role_label *role;
57978 + unsigned int x;
57979 +
57980 + FOR_EACH_ROLE_START(role)
57981 + FOR_EACH_SUBJECT_START(role, subj, x)
57982 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57983 + matchpo->mode |= GR_DELETED;
57984 + FOR_EACH_SUBJECT_END(subj,x)
57985 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
57986 + if (subj->inode == ino && subj->device == dev)
57987 + subj->mode |= GR_DELETED;
57988 + FOR_EACH_NESTED_SUBJECT_END(subj)
57989 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57990 + matchps->mode |= GR_DELETED;
57991 + FOR_EACH_ROLE_END(role)
57992 +
57993 + inodev->nentry->deleted = 1;
57994 +
57995 + return;
57996 +}
57997 +
57998 +void
57999 +gr_handle_delete(const ino_t ino, const dev_t dev)
58000 +{
58001 + struct inodev_entry *inodev;
58002 +
58003 + if (unlikely(!(gr_status & GR_READY)))
58004 + return;
58005 +
58006 + write_lock(&gr_inode_lock);
58007 + inodev = lookup_inodev_entry(ino, dev);
58008 + if (inodev != NULL)
58009 + do_handle_delete(inodev, ino, dev);
58010 + write_unlock(&gr_inode_lock);
58011 +
58012 + return;
58013 +}
58014 +
58015 +static void
58016 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
58017 + const ino_t newinode, const dev_t newdevice,
58018 + struct acl_subject_label *subj)
58019 +{
58020 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
58021 + struct acl_object_label *match;
58022 +
58023 + match = subj->obj_hash[index];
58024 +
58025 + while (match && (match->inode != oldinode ||
58026 + match->device != olddevice ||
58027 + !(match->mode & GR_DELETED)))
58028 + match = match->next;
58029 +
58030 + if (match && (match->inode == oldinode)
58031 + && (match->device == olddevice)
58032 + && (match->mode & GR_DELETED)) {
58033 + if (match->prev == NULL) {
58034 + subj->obj_hash[index] = match->next;
58035 + if (match->next != NULL)
58036 + match->next->prev = NULL;
58037 + } else {
58038 + match->prev->next = match->next;
58039 + if (match->next != NULL)
58040 + match->next->prev = match->prev;
58041 + }
58042 + match->prev = NULL;
58043 + match->next = NULL;
58044 + match->inode = newinode;
58045 + match->device = newdevice;
58046 + match->mode &= ~GR_DELETED;
58047 +
58048 + insert_acl_obj_label(match, subj);
58049 + }
58050 +
58051 + return;
58052 +}
58053 +
58054 +static void
58055 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
58056 + const ino_t newinode, const dev_t newdevice,
58057 + struct acl_role_label *role)
58058 +{
58059 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
58060 + struct acl_subject_label *match;
58061 +
58062 + match = role->subj_hash[index];
58063 +
58064 + while (match && (match->inode != oldinode ||
58065 + match->device != olddevice ||
58066 + !(match->mode & GR_DELETED)))
58067 + match = match->next;
58068 +
58069 + if (match && (match->inode == oldinode)
58070 + && (match->device == olddevice)
58071 + && (match->mode & GR_DELETED)) {
58072 + if (match->prev == NULL) {
58073 + role->subj_hash[index] = match->next;
58074 + if (match->next != NULL)
58075 + match->next->prev = NULL;
58076 + } else {
58077 + match->prev->next = match->next;
58078 + if (match->next != NULL)
58079 + match->next->prev = match->prev;
58080 + }
58081 + match->prev = NULL;
58082 + match->next = NULL;
58083 + match->inode = newinode;
58084 + match->device = newdevice;
58085 + match->mode &= ~GR_DELETED;
58086 +
58087 + insert_acl_subj_label(match, role);
58088 + }
58089 +
58090 + return;
58091 +}
58092 +
58093 +static void
58094 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
58095 + const ino_t newinode, const dev_t newdevice)
58096 +{
58097 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
58098 + struct inodev_entry *match;
58099 +
58100 + match = inodev_set.i_hash[index];
58101 +
58102 + while (match && (match->nentry->inode != oldinode ||
58103 + match->nentry->device != olddevice || !match->nentry->deleted))
58104 + match = match->next;
58105 +
58106 + if (match && (match->nentry->inode == oldinode)
58107 + && (match->nentry->device == olddevice) &&
58108 + match->nentry->deleted) {
58109 + if (match->prev == NULL) {
58110 + inodev_set.i_hash[index] = match->next;
58111 + if (match->next != NULL)
58112 + match->next->prev = NULL;
58113 + } else {
58114 + match->prev->next = match->next;
58115 + if (match->next != NULL)
58116 + match->next->prev = match->prev;
58117 + }
58118 + match->prev = NULL;
58119 + match->next = NULL;
58120 + match->nentry->inode = newinode;
58121 + match->nentry->device = newdevice;
58122 + match->nentry->deleted = 0;
58123 +
58124 + insert_inodev_entry(match);
58125 + }
58126 +
58127 + return;
58128 +}
58129 +
58130 +static void
58131 +__do_handle_create(const struct name_entry *matchn, ino_t inode, dev_t dev)
58132 +{
58133 + struct acl_subject_label *subj;
58134 + struct acl_role_label *role;
58135 + unsigned int x;
58136 +
58137 + FOR_EACH_ROLE_START(role)
58138 + update_acl_subj_label(matchn->inode, matchn->device,
58139 + inode, dev, role);
58140 +
58141 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
58142 + if ((subj->inode == inode) && (subj->device == dev)) {
58143 + subj->inode = inode;
58144 + subj->device = dev;
58145 + }
58146 + FOR_EACH_NESTED_SUBJECT_END(subj)
58147 + FOR_EACH_SUBJECT_START(role, subj, x)
58148 + update_acl_obj_label(matchn->inode, matchn->device,
58149 + inode, dev, subj);
58150 + FOR_EACH_SUBJECT_END(subj,x)
58151 + FOR_EACH_ROLE_END(role)
58152 +
58153 + update_inodev_entry(matchn->inode, matchn->device, inode, dev);
58154 +
58155 + return;
58156 +}
58157 +
58158 +static void
58159 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
58160 + const struct vfsmount *mnt)
58161 +{
58162 + ino_t ino = dentry->d_inode->i_ino;
58163 + dev_t dev = __get_dev(dentry);
58164 +
58165 + __do_handle_create(matchn, ino, dev);
58166 +
58167 + return;
58168 +}
58169 +
58170 +void
58171 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58172 +{
58173 + struct name_entry *matchn;
58174 +
58175 + if (unlikely(!(gr_status & GR_READY)))
58176 + return;
58177 +
58178 + preempt_disable();
58179 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
58180 +
58181 + if (unlikely((unsigned long)matchn)) {
58182 + write_lock(&gr_inode_lock);
58183 + do_handle_create(matchn, dentry, mnt);
58184 + write_unlock(&gr_inode_lock);
58185 + }
58186 + preempt_enable();
58187 +
58188 + return;
58189 +}
58190 +
58191 +void
58192 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58193 +{
58194 + struct name_entry *matchn;
58195 +
58196 + if (unlikely(!(gr_status & GR_READY)))
58197 + return;
58198 +
58199 + preempt_disable();
58200 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
58201 +
58202 + if (unlikely((unsigned long)matchn)) {
58203 + write_lock(&gr_inode_lock);
58204 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
58205 + write_unlock(&gr_inode_lock);
58206 + }
58207 + preempt_enable();
58208 +
58209 + return;
58210 +}
58211 +
58212 +void
58213 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58214 + struct dentry *old_dentry,
58215 + struct dentry *new_dentry,
58216 + struct vfsmount *mnt, const __u8 replace)
58217 +{
58218 + struct name_entry *matchn;
58219 + struct inodev_entry *inodev;
58220 + struct inode *inode = new_dentry->d_inode;
58221 + ino_t oldinode = old_dentry->d_inode->i_ino;
58222 + dev_t olddev = __get_dev(old_dentry);
58223 +
58224 + /* vfs_rename swaps the name and parent link for old_dentry and
58225 + new_dentry
58226 + at this point, old_dentry has the new name, parent link, and inode
58227 + for the renamed file
58228 + if a file is being replaced by a rename, new_dentry has the inode
58229 + and name for the replaced file
58230 + */
58231 +
58232 + if (unlikely(!(gr_status & GR_READY)))
58233 + return;
58234 +
58235 + preempt_disable();
58236 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
58237 +
58238 + /* we wouldn't have to check d_inode if it weren't for
58239 + NFS silly-renaming
58240 + */
58241 +
58242 + write_lock(&gr_inode_lock);
58243 + if (unlikely(replace && inode)) {
58244 + ino_t newinode = inode->i_ino;
58245 + dev_t newdev = __get_dev(new_dentry);
58246 + inodev = lookup_inodev_entry(newinode, newdev);
58247 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
58248 + do_handle_delete(inodev, newinode, newdev);
58249 + }
58250 +
58251 + inodev = lookup_inodev_entry(oldinode, olddev);
58252 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
58253 + do_handle_delete(inodev, oldinode, olddev);
58254 +
58255 + if (unlikely((unsigned long)matchn))
58256 + do_handle_create(matchn, old_dentry, mnt);
58257 +
58258 + write_unlock(&gr_inode_lock);
58259 + preempt_enable();
58260 +
58261 + return;
58262 +}
58263 +
58264 +static int
58265 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
58266 + unsigned char **sum)
58267 +{
58268 + struct acl_role_label *r;
58269 + struct role_allowed_ip *ipp;
58270 + struct role_transition *trans;
58271 + unsigned int i;
58272 + int found = 0;
58273 + u32 curr_ip = current->signal->curr_ip;
58274 +
58275 + current->signal->saved_ip = curr_ip;
58276 +
58277 + /* check transition table */
58278 +
58279 + for (trans = current->role->transitions; trans; trans = trans->next) {
58280 + if (!strcmp(rolename, trans->rolename)) {
58281 + found = 1;
58282 + break;
58283 + }
58284 + }
58285 +
58286 + if (!found)
58287 + return 0;
58288 +
58289 + /* handle special roles that do not require authentication
58290 + and check ip */
58291 +
58292 + FOR_EACH_ROLE_START(r)
58293 + if (!strcmp(rolename, r->rolename) &&
58294 + (r->roletype & GR_ROLE_SPECIAL)) {
58295 + found = 0;
58296 + if (r->allowed_ips != NULL) {
58297 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
58298 + if ((ntohl(curr_ip) & ipp->netmask) ==
58299 + (ntohl(ipp->addr) & ipp->netmask))
58300 + found = 1;
58301 + }
58302 + } else
58303 + found = 2;
58304 + if (!found)
58305 + return 0;
58306 +
58307 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
58308 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
58309 + *salt = NULL;
58310 + *sum = NULL;
58311 + return 1;
58312 + }
58313 + }
58314 + FOR_EACH_ROLE_END(r)
58315 +
58316 + for (i = 0; i < num_sprole_pws; i++) {
58317 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
58318 + *salt = acl_special_roles[i]->salt;
58319 + *sum = acl_special_roles[i]->sum;
58320 + return 1;
58321 + }
58322 + }
58323 +
58324 + return 0;
58325 +}
58326 +
58327 +static void
58328 +assign_special_role(char *rolename)
58329 +{
58330 + struct acl_object_label *obj;
58331 + struct acl_role_label *r;
58332 + struct acl_role_label *assigned = NULL;
58333 + struct task_struct *tsk;
58334 + struct file *filp;
58335 +
58336 + FOR_EACH_ROLE_START(r)
58337 + if (!strcmp(rolename, r->rolename) &&
58338 + (r->roletype & GR_ROLE_SPECIAL)) {
58339 + assigned = r;
58340 + break;
58341 + }
58342 + FOR_EACH_ROLE_END(r)
58343 +
58344 + if (!assigned)
58345 + return;
58346 +
58347 + read_lock(&tasklist_lock);
58348 + read_lock(&grsec_exec_file_lock);
58349 +
58350 + tsk = current->real_parent;
58351 + if (tsk == NULL)
58352 + goto out_unlock;
58353 +
58354 + filp = tsk->exec_file;
58355 + if (filp == NULL)
58356 + goto out_unlock;
58357 +
58358 + tsk->is_writable = 0;
58359 +
58360 + tsk->acl_sp_role = 1;
58361 + tsk->acl_role_id = ++acl_sp_role_value;
58362 + tsk->role = assigned;
58363 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
58364 +
58365 + /* ignore additional mmap checks for processes that are writable
58366 + by the default ACL */
58367 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58368 + if (unlikely(obj->mode & GR_WRITE))
58369 + tsk->is_writable = 1;
58370 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
58371 + if (unlikely(obj->mode & GR_WRITE))
58372 + tsk->is_writable = 1;
58373 +
58374 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58375 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
58376 +#endif
58377 +
58378 +out_unlock:
58379 + read_unlock(&grsec_exec_file_lock);
58380 + read_unlock(&tasklist_lock);
58381 + return;
58382 +}
58383 +
58384 +int gr_check_secure_terminal(struct task_struct *task)
58385 +{
58386 + struct task_struct *p, *p2, *p3;
58387 + struct files_struct *files;
58388 + struct fdtable *fdt;
58389 + struct file *our_file = NULL, *file;
58390 + int i;
58391 +
58392 + if (task->signal->tty == NULL)
58393 + return 1;
58394 +
58395 + files = get_files_struct(task);
58396 + if (files != NULL) {
58397 + rcu_read_lock();
58398 + fdt = files_fdtable(files);
58399 + for (i=0; i < fdt->max_fds; i++) {
58400 + file = fcheck_files(files, i);
58401 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
58402 + get_file(file);
58403 + our_file = file;
58404 + }
58405 + }
58406 + rcu_read_unlock();
58407 + put_files_struct(files);
58408 + }
58409 +
58410 + if (our_file == NULL)
58411 + return 1;
58412 +
58413 + read_lock(&tasklist_lock);
58414 + do_each_thread(p2, p) {
58415 + files = get_files_struct(p);
58416 + if (files == NULL ||
58417 + (p->signal && p->signal->tty == task->signal->tty)) {
58418 + if (files != NULL)
58419 + put_files_struct(files);
58420 + continue;
58421 + }
58422 + rcu_read_lock();
58423 + fdt = files_fdtable(files);
58424 + for (i=0; i < fdt->max_fds; i++) {
58425 + file = fcheck_files(files, i);
58426 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
58427 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
58428 + p3 = task;
58429 + while (p3->pid > 0) {
58430 + if (p3 == p)
58431 + break;
58432 + p3 = p3->real_parent;
58433 + }
58434 + if (p3 == p)
58435 + break;
58436 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
58437 + gr_handle_alertkill(p);
58438 + rcu_read_unlock();
58439 + put_files_struct(files);
58440 + read_unlock(&tasklist_lock);
58441 + fput(our_file);
58442 + return 0;
58443 + }
58444 + }
58445 + rcu_read_unlock();
58446 + put_files_struct(files);
58447 + } while_each_thread(p2, p);
58448 + read_unlock(&tasklist_lock);
58449 +
58450 + fput(our_file);
58451 + return 1;
58452 +}
58453 +
58454 +ssize_t
58455 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
58456 +{
58457 + struct gr_arg_wrapper uwrap;
58458 + unsigned char *sprole_salt = NULL;
58459 + unsigned char *sprole_sum = NULL;
58460 + int error = sizeof (struct gr_arg_wrapper);
58461 + int error2 = 0;
58462 +
58463 + mutex_lock(&gr_dev_mutex);
58464 +
58465 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
58466 + error = -EPERM;
58467 + goto out;
58468 + }
58469 +
58470 + if (count != sizeof (struct gr_arg_wrapper)) {
58471 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
58472 + error = -EINVAL;
58473 + goto out;
58474 + }
58475 +
58476 +
58477 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
58478 + gr_auth_expires = 0;
58479 + gr_auth_attempts = 0;
58480 + }
58481 +
58482 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
58483 + error = -EFAULT;
58484 + goto out;
58485 + }
58486 +
58487 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
58488 + error = -EINVAL;
58489 + goto out;
58490 + }
58491 +
58492 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
58493 + error = -EFAULT;
58494 + goto out;
58495 + }
58496 +
58497 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58498 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58499 + time_after(gr_auth_expires, get_seconds())) {
58500 + error = -EBUSY;
58501 + goto out;
58502 + }
58503 +
58504 + /* if non-root trying to do anything other than use a special role,
58505 + do not attempt authentication, do not count towards authentication
58506 + locking
58507 + */
58508 +
58509 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
58510 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58511 + current_uid()) {
58512 + error = -EPERM;
58513 + goto out;
58514 + }
58515 +
58516 + /* ensure pw and special role name are null terminated */
58517 +
58518 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
58519 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
58520 +
58521 + /* Okay.
58522 + * We have our enough of the argument structure..(we have yet
58523 + * to copy_from_user the tables themselves) . Copy the tables
58524 + * only if we need them, i.e. for loading operations. */
58525 +
58526 + switch (gr_usermode->mode) {
58527 + case GR_STATUS:
58528 + if (gr_status & GR_READY) {
58529 + error = 1;
58530 + if (!gr_check_secure_terminal(current))
58531 + error = 3;
58532 + } else
58533 + error = 2;
58534 + goto out;
58535 + case GR_SHUTDOWN:
58536 + if ((gr_status & GR_READY)
58537 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58538 + pax_open_kernel();
58539 + gr_status &= ~GR_READY;
58540 + pax_close_kernel();
58541 +
58542 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
58543 + free_variables();
58544 + memset(gr_usermode, 0, sizeof (struct gr_arg));
58545 + memset(gr_system_salt, 0, GR_SALT_LEN);
58546 + memset(gr_system_sum, 0, GR_SHA_LEN);
58547 + } else if (gr_status & GR_READY) {
58548 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
58549 + error = -EPERM;
58550 + } else {
58551 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
58552 + error = -EAGAIN;
58553 + }
58554 + break;
58555 + case GR_ENABLE:
58556 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
58557 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
58558 + else {
58559 + if (gr_status & GR_READY)
58560 + error = -EAGAIN;
58561 + else
58562 + error = error2;
58563 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
58564 + }
58565 + break;
58566 + case GR_RELOAD:
58567 + if (!(gr_status & GR_READY)) {
58568 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
58569 + error = -EAGAIN;
58570 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58571 + lock_kernel();
58572 +
58573 + pax_open_kernel();
58574 + gr_status &= ~GR_READY;
58575 + pax_close_kernel();
58576 +
58577 + free_variables();
58578 + if (!(error2 = gracl_init(gr_usermode))) {
58579 + unlock_kernel();
58580 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
58581 + } else {
58582 + unlock_kernel();
58583 + error = error2;
58584 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58585 + }
58586 + } else {
58587 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58588 + error = -EPERM;
58589 + }
58590 + break;
58591 + case GR_SEGVMOD:
58592 + if (unlikely(!(gr_status & GR_READY))) {
58593 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
58594 + error = -EAGAIN;
58595 + break;
58596 + }
58597 +
58598 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58599 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
58600 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
58601 + struct acl_subject_label *segvacl;
58602 + segvacl =
58603 + lookup_acl_subj_label(gr_usermode->segv_inode,
58604 + gr_usermode->segv_device,
58605 + current->role);
58606 + if (segvacl) {
58607 + segvacl->crashes = 0;
58608 + segvacl->expires = 0;
58609 + }
58610 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
58611 + gr_remove_uid(gr_usermode->segv_uid);
58612 + }
58613 + } else {
58614 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
58615 + error = -EPERM;
58616 + }
58617 + break;
58618 + case GR_SPROLE:
58619 + case GR_SPROLEPAM:
58620 + if (unlikely(!(gr_status & GR_READY))) {
58621 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
58622 + error = -EAGAIN;
58623 + break;
58624 + }
58625 +
58626 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
58627 + current->role->expires = 0;
58628 + current->role->auth_attempts = 0;
58629 + }
58630 +
58631 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58632 + time_after(current->role->expires, get_seconds())) {
58633 + error = -EBUSY;
58634 + goto out;
58635 + }
58636 +
58637 + if (lookup_special_role_auth
58638 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
58639 + && ((!sprole_salt && !sprole_sum)
58640 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
58641 + char *p = "";
58642 + assign_special_role(gr_usermode->sp_role);
58643 + read_lock(&tasklist_lock);
58644 + if (current->real_parent)
58645 + p = current->real_parent->role->rolename;
58646 + read_unlock(&tasklist_lock);
58647 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
58648 + p, acl_sp_role_value);
58649 + } else {
58650 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
58651 + error = -EPERM;
58652 + if(!(current->role->auth_attempts++))
58653 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58654 +
58655 + goto out;
58656 + }
58657 + break;
58658 + case GR_UNSPROLE:
58659 + if (unlikely(!(gr_status & GR_READY))) {
58660 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
58661 + error = -EAGAIN;
58662 + break;
58663 + }
58664 +
58665 + if (current->role->roletype & GR_ROLE_SPECIAL) {
58666 + char *p = "";
58667 + int i = 0;
58668 +
58669 + read_lock(&tasklist_lock);
58670 + if (current->real_parent) {
58671 + p = current->real_parent->role->rolename;
58672 + i = current->real_parent->acl_role_id;
58673 + }
58674 + read_unlock(&tasklist_lock);
58675 +
58676 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
58677 + gr_set_acls(1);
58678 + } else {
58679 + error = -EPERM;
58680 + goto out;
58681 + }
58682 + break;
58683 + default:
58684 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
58685 + error = -EINVAL;
58686 + break;
58687 + }
58688 +
58689 + if (error != -EPERM)
58690 + goto out;
58691 +
58692 + if(!(gr_auth_attempts++))
58693 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58694 +
58695 + out:
58696 + mutex_unlock(&gr_dev_mutex);
58697 + return error;
58698 +}
58699 +
58700 +/* must be called with
58701 + rcu_read_lock();
58702 + read_lock(&tasklist_lock);
58703 + read_lock(&grsec_exec_file_lock);
58704 +*/
58705 +int gr_apply_subject_to_task(struct task_struct *task)
58706 +{
58707 + struct acl_object_label *obj;
58708 + char *tmpname;
58709 + struct acl_subject_label *tmpsubj;
58710 + struct file *filp;
58711 + struct name_entry *nmatch;
58712 +
58713 + filp = task->exec_file;
58714 + if (filp == NULL)
58715 + return 0;
58716 +
58717 + /* the following is to apply the correct subject
58718 + on binaries running when the RBAC system
58719 + is enabled, when the binaries have been
58720 + replaced or deleted since their execution
58721 + -----
58722 + when the RBAC system starts, the inode/dev
58723 + from exec_file will be one the RBAC system
58724 + is unaware of. It only knows the inode/dev
58725 + of the present file on disk, or the absence
58726 + of it.
58727 + */
58728 + preempt_disable();
58729 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
58730 +
58731 + nmatch = lookup_name_entry(tmpname);
58732 + preempt_enable();
58733 + tmpsubj = NULL;
58734 + if (nmatch) {
58735 + if (nmatch->deleted)
58736 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
58737 + else
58738 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
58739 + if (tmpsubj != NULL)
58740 + task->acl = tmpsubj;
58741 + }
58742 + if (tmpsubj == NULL)
58743 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
58744 + task->role);
58745 + if (task->acl) {
58746 + task->is_writable = 0;
58747 + /* ignore additional mmap checks for processes that are writable
58748 + by the default ACL */
58749 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58750 + if (unlikely(obj->mode & GR_WRITE))
58751 + task->is_writable = 1;
58752 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
58753 + if (unlikely(obj->mode & GR_WRITE))
58754 + task->is_writable = 1;
58755 +
58756 + gr_set_proc_res(task);
58757 +
58758 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58759 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58760 +#endif
58761 + } else {
58762 + return 1;
58763 + }
58764 +
58765 + return 0;
58766 +}
58767 +
58768 +int
58769 +gr_set_acls(const int type)
58770 +{
58771 + struct task_struct *task, *task2;
58772 + struct acl_role_label *role = current->role;
58773 + __u16 acl_role_id = current->acl_role_id;
58774 + const struct cred *cred;
58775 + int ret;
58776 +
58777 + rcu_read_lock();
58778 + read_lock(&tasklist_lock);
58779 + read_lock(&grsec_exec_file_lock);
58780 + do_each_thread(task2, task) {
58781 + /* check to see if we're called from the exit handler,
58782 + if so, only replace ACLs that have inherited the admin
58783 + ACL */
58784 +
58785 + if (type && (task->role != role ||
58786 + task->acl_role_id != acl_role_id))
58787 + continue;
58788 +
58789 + task->acl_role_id = 0;
58790 + task->acl_sp_role = 0;
58791 +
58792 + if (task->exec_file) {
58793 + cred = __task_cred(task);
58794 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
58795 +
58796 + ret = gr_apply_subject_to_task(task);
58797 + if (ret) {
58798 + read_unlock(&grsec_exec_file_lock);
58799 + read_unlock(&tasklist_lock);
58800 + rcu_read_unlock();
58801 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
58802 + return ret;
58803 + }
58804 + } else {
58805 + // it's a kernel process
58806 + task->role = kernel_role;
58807 + task->acl = kernel_role->root_label;
58808 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
58809 + task->acl->mode &= ~GR_PROCFIND;
58810 +#endif
58811 + }
58812 + } while_each_thread(task2, task);
58813 + read_unlock(&grsec_exec_file_lock);
58814 + read_unlock(&tasklist_lock);
58815 + rcu_read_unlock();
58816 +
58817 + return 0;
58818 +}
58819 +
58820 +void
58821 +gr_learn_resource(const struct task_struct *task,
58822 + const int res, const unsigned long wanted, const int gt)
58823 +{
58824 + struct acl_subject_label *acl;
58825 + const struct cred *cred;
58826 +
58827 + if (unlikely((gr_status & GR_READY) &&
58828 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
58829 + goto skip_reslog;
58830 +
58831 +#ifdef CONFIG_GRKERNSEC_RESLOG
58832 + gr_log_resource(task, res, wanted, gt);
58833 +#endif
58834 + skip_reslog:
58835 +
58836 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
58837 + return;
58838 +
58839 + acl = task->acl;
58840 +
58841 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
58842 + !(acl->resmask & (1 << (unsigned short) res))))
58843 + return;
58844 +
58845 + if (wanted >= acl->res[res].rlim_cur) {
58846 + unsigned long res_add;
58847 +
58848 + res_add = wanted;
58849 + switch (res) {
58850 + case RLIMIT_CPU:
58851 + res_add += GR_RLIM_CPU_BUMP;
58852 + break;
58853 + case RLIMIT_FSIZE:
58854 + res_add += GR_RLIM_FSIZE_BUMP;
58855 + break;
58856 + case RLIMIT_DATA:
58857 + res_add += GR_RLIM_DATA_BUMP;
58858 + break;
58859 + case RLIMIT_STACK:
58860 + res_add += GR_RLIM_STACK_BUMP;
58861 + break;
58862 + case RLIMIT_CORE:
58863 + res_add += GR_RLIM_CORE_BUMP;
58864 + break;
58865 + case RLIMIT_RSS:
58866 + res_add += GR_RLIM_RSS_BUMP;
58867 + break;
58868 + case RLIMIT_NPROC:
58869 + res_add += GR_RLIM_NPROC_BUMP;
58870 + break;
58871 + case RLIMIT_NOFILE:
58872 + res_add += GR_RLIM_NOFILE_BUMP;
58873 + break;
58874 + case RLIMIT_MEMLOCK:
58875 + res_add += GR_RLIM_MEMLOCK_BUMP;
58876 + break;
58877 + case RLIMIT_AS:
58878 + res_add += GR_RLIM_AS_BUMP;
58879 + break;
58880 + case RLIMIT_LOCKS:
58881 + res_add += GR_RLIM_LOCKS_BUMP;
58882 + break;
58883 + case RLIMIT_SIGPENDING:
58884 + res_add += GR_RLIM_SIGPENDING_BUMP;
58885 + break;
58886 + case RLIMIT_MSGQUEUE:
58887 + res_add += GR_RLIM_MSGQUEUE_BUMP;
58888 + break;
58889 + case RLIMIT_NICE:
58890 + res_add += GR_RLIM_NICE_BUMP;
58891 + break;
58892 + case RLIMIT_RTPRIO:
58893 + res_add += GR_RLIM_RTPRIO_BUMP;
58894 + break;
58895 + case RLIMIT_RTTIME:
58896 + res_add += GR_RLIM_RTTIME_BUMP;
58897 + break;
58898 + }
58899 +
58900 + acl->res[res].rlim_cur = res_add;
58901 +
58902 + if (wanted > acl->res[res].rlim_max)
58903 + acl->res[res].rlim_max = res_add;
58904 +
58905 + /* only log the subject filename, since resource logging is supported for
58906 + single-subject learning only */
58907 + rcu_read_lock();
58908 + cred = __task_cred(task);
58909 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58910 + task->role->roletype, cred->uid, cred->gid, acl->filename,
58911 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
58912 + "", (unsigned long) res, &task->signal->saved_ip);
58913 + rcu_read_unlock();
58914 + }
58915 +
58916 + return;
58917 +}
58918 +
58919 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
58920 +void
58921 +pax_set_initial_flags(struct linux_binprm *bprm)
58922 +{
58923 + struct task_struct *task = current;
58924 + struct acl_subject_label *proc;
58925 + unsigned long flags;
58926 +
58927 + if (unlikely(!(gr_status & GR_READY)))
58928 + return;
58929 +
58930 + flags = pax_get_flags(task);
58931 +
58932 + proc = task->acl;
58933 +
58934 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58935 + flags &= ~MF_PAX_PAGEEXEC;
58936 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58937 + flags &= ~MF_PAX_SEGMEXEC;
58938 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58939 + flags &= ~MF_PAX_RANDMMAP;
58940 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58941 + flags &= ~MF_PAX_EMUTRAMP;
58942 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58943 + flags &= ~MF_PAX_MPROTECT;
58944 +
58945 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58946 + flags |= MF_PAX_PAGEEXEC;
58947 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58948 + flags |= MF_PAX_SEGMEXEC;
58949 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58950 + flags |= MF_PAX_RANDMMAP;
58951 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58952 + flags |= MF_PAX_EMUTRAMP;
58953 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58954 + flags |= MF_PAX_MPROTECT;
58955 +
58956 + pax_set_flags(task, flags);
58957 +
58958 + return;
58959 +}
58960 +#endif
58961 +
58962 +#ifdef CONFIG_SYSCTL
58963 +/* Eric Biederman likes breaking userland ABI and every inode-based security
58964 + system to save 35kb of memory */
58965 +
58966 +/* we modify the passed in filename, but adjust it back before returning */
58967 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
58968 +{
58969 + struct name_entry *nmatch;
58970 + char *p, *lastp = NULL;
58971 + struct acl_object_label *obj = NULL, *tmp;
58972 + struct acl_subject_label *tmpsubj;
58973 + char c = '\0';
58974 +
58975 + read_lock(&gr_inode_lock);
58976 +
58977 + p = name + len - 1;
58978 + do {
58979 + nmatch = lookup_name_entry(name);
58980 + if (lastp != NULL)
58981 + *lastp = c;
58982 +
58983 + if (nmatch == NULL)
58984 + goto next_component;
58985 + tmpsubj = current->acl;
58986 + do {
58987 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
58988 + if (obj != NULL) {
58989 + tmp = obj->globbed;
58990 + while (tmp) {
58991 + if (!glob_match(tmp->filename, name)) {
58992 + obj = tmp;
58993 + goto found_obj;
58994 + }
58995 + tmp = tmp->next;
58996 + }
58997 + goto found_obj;
58998 + }
58999 + } while ((tmpsubj = tmpsubj->parent_subject));
59000 +next_component:
59001 + /* end case */
59002 + if (p == name)
59003 + break;
59004 +
59005 + while (*p != '/')
59006 + p--;
59007 + if (p == name)
59008 + lastp = p + 1;
59009 + else {
59010 + lastp = p;
59011 + p--;
59012 + }
59013 + c = *lastp;
59014 + *lastp = '\0';
59015 + } while (1);
59016 +found_obj:
59017 + read_unlock(&gr_inode_lock);
59018 + /* obj returned will always be non-null */
59019 + return obj;
59020 +}
59021 +
59022 +/* returns 0 when allowing, non-zero on error
59023 + op of 0 is used for readdir, so we don't log the names of hidden files
59024 +*/
59025 +__u32
59026 +gr_handle_sysctl(const struct ctl_table *table, const int op)
59027 +{
59028 + ctl_table *tmp;
59029 + const char *proc_sys = "/proc/sys";
59030 + char *path;
59031 + struct acl_object_label *obj;
59032 + unsigned short len = 0, pos = 0, depth = 0, i;
59033 + __u32 err = 0;
59034 + __u32 mode = 0;
59035 +
59036 + if (unlikely(!(gr_status & GR_READY)))
59037 + return 0;
59038 +
59039 + /* for now, ignore operations on non-sysctl entries if it's not a
59040 + readdir*/
59041 + if (table->child != NULL && op != 0)
59042 + return 0;
59043 +
59044 + mode |= GR_FIND;
59045 + /* it's only a read if it's an entry, read on dirs is for readdir */
59046 + if (op & MAY_READ)
59047 + mode |= GR_READ;
59048 + if (op & MAY_WRITE)
59049 + mode |= GR_WRITE;
59050 +
59051 + preempt_disable();
59052 +
59053 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
59054 +
59055 + /* it's only a read/write if it's an actual entry, not a dir
59056 + (which are opened for readdir)
59057 + */
59058 +
59059 + /* convert the requested sysctl entry into a pathname */
59060 +
59061 + for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59062 + len += strlen(tmp->procname);
59063 + len++;
59064 + depth++;
59065 + }
59066 +
59067 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
59068 + /* deny */
59069 + goto out;
59070 + }
59071 +
59072 + memset(path, 0, PAGE_SIZE);
59073 +
59074 + memcpy(path, proc_sys, strlen(proc_sys));
59075 +
59076 + pos += strlen(proc_sys);
59077 +
59078 + for (; depth > 0; depth--) {
59079 + path[pos] = '/';
59080 + pos++;
59081 + for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59082 + if (depth == i) {
59083 + memcpy(path + pos, tmp->procname,
59084 + strlen(tmp->procname));
59085 + pos += strlen(tmp->procname);
59086 + }
59087 + i++;
59088 + }
59089 + }
59090 +
59091 + obj = gr_lookup_by_name(path, pos);
59092 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
59093 +
59094 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
59095 + ((err & mode) != mode))) {
59096 + __u32 new_mode = mode;
59097 +
59098 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59099 +
59100 + err = 0;
59101 + gr_log_learn_sysctl(path, new_mode);
59102 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
59103 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
59104 + err = -ENOENT;
59105 + } else if (!(err & GR_FIND)) {
59106 + err = -ENOENT;
59107 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
59108 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
59109 + path, (mode & GR_READ) ? " reading" : "",
59110 + (mode & GR_WRITE) ? " writing" : "");
59111 + err = -EACCES;
59112 + } else if ((err & mode) != mode) {
59113 + err = -EACCES;
59114 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
59115 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
59116 + path, (mode & GR_READ) ? " reading" : "",
59117 + (mode & GR_WRITE) ? " writing" : "");
59118 + err = 0;
59119 + } else
59120 + err = 0;
59121 +
59122 + out:
59123 + preempt_enable();
59124 +
59125 + return err;
59126 +}
59127 +#endif
59128 +
59129 +int
59130 +gr_handle_proc_ptrace(struct task_struct *task)
59131 +{
59132 + struct file *filp;
59133 + struct task_struct *tmp = task;
59134 + struct task_struct *curtemp = current;
59135 + __u32 retmode;
59136 +
59137 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59138 + if (unlikely(!(gr_status & GR_READY)))
59139 + return 0;
59140 +#endif
59141 +
59142 + read_lock(&tasklist_lock);
59143 + read_lock(&grsec_exec_file_lock);
59144 + filp = task->exec_file;
59145 +
59146 + while (tmp->pid > 0) {
59147 + if (tmp == curtemp)
59148 + break;
59149 + tmp = tmp->real_parent;
59150 + }
59151 +
59152 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59153 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
59154 + read_unlock(&grsec_exec_file_lock);
59155 + read_unlock(&tasklist_lock);
59156 + return 1;
59157 + }
59158 +
59159 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59160 + if (!(gr_status & GR_READY)) {
59161 + read_unlock(&grsec_exec_file_lock);
59162 + read_unlock(&tasklist_lock);
59163 + return 0;
59164 + }
59165 +#endif
59166 +
59167 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
59168 + read_unlock(&grsec_exec_file_lock);
59169 + read_unlock(&tasklist_lock);
59170 +
59171 + if (retmode & GR_NOPTRACE)
59172 + return 1;
59173 +
59174 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
59175 + && (current->acl != task->acl || (current->acl != current->role->root_label
59176 + && current->pid != task->pid)))
59177 + return 1;
59178 +
59179 + return 0;
59180 +}
59181 +
59182 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
59183 +{
59184 + if (unlikely(!(gr_status & GR_READY)))
59185 + return;
59186 +
59187 + if (!(current->role->roletype & GR_ROLE_GOD))
59188 + return;
59189 +
59190 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
59191 + p->role->rolename, gr_task_roletype_to_char(p),
59192 + p->acl->filename);
59193 +}
59194 +
59195 +int
59196 +gr_handle_ptrace(struct task_struct *task, const long request)
59197 +{
59198 + struct task_struct *tmp = task;
59199 + struct task_struct *curtemp = current;
59200 + __u32 retmode;
59201 +
59202 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59203 + if (unlikely(!(gr_status & GR_READY)))
59204 + return 0;
59205 +#endif
59206 +
59207 + read_lock(&tasklist_lock);
59208 + while (tmp->pid > 0) {
59209 + if (tmp == curtemp)
59210 + break;
59211 + tmp = tmp->real_parent;
59212 + }
59213 +
59214 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59215 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
59216 + read_unlock(&tasklist_lock);
59217 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59218 + return 1;
59219 + }
59220 + read_unlock(&tasklist_lock);
59221 +
59222 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59223 + if (!(gr_status & GR_READY))
59224 + return 0;
59225 +#endif
59226 +
59227 + read_lock(&grsec_exec_file_lock);
59228 + if (unlikely(!task->exec_file)) {
59229 + read_unlock(&grsec_exec_file_lock);
59230 + return 0;
59231 + }
59232 +
59233 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
59234 + read_unlock(&grsec_exec_file_lock);
59235 +
59236 + if (retmode & GR_NOPTRACE) {
59237 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59238 + return 1;
59239 + }
59240 +
59241 + if (retmode & GR_PTRACERD) {
59242 + switch (request) {
59243 + case PTRACE_POKETEXT:
59244 + case PTRACE_POKEDATA:
59245 + case PTRACE_POKEUSR:
59246 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
59247 + case PTRACE_SETREGS:
59248 + case PTRACE_SETFPREGS:
59249 +#endif
59250 +#ifdef CONFIG_X86
59251 + case PTRACE_SETFPXREGS:
59252 +#endif
59253 +#ifdef CONFIG_ALTIVEC
59254 + case PTRACE_SETVRREGS:
59255 +#endif
59256 + return 1;
59257 + default:
59258 + return 0;
59259 + }
59260 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
59261 + !(current->role->roletype & GR_ROLE_GOD) &&
59262 + (current->acl != task->acl)) {
59263 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59264 + return 1;
59265 + }
59266 +
59267 + return 0;
59268 +}
59269 +
59270 +static int is_writable_mmap(const struct file *filp)
59271 +{
59272 + struct task_struct *task = current;
59273 + struct acl_object_label *obj, *obj2;
59274 +
59275 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
59276 + !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))) {
59277 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59278 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
59279 + task->role->root_label);
59280 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
59281 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
59282 + return 1;
59283 + }
59284 + }
59285 + return 0;
59286 +}
59287 +
59288 +int
59289 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
59290 +{
59291 + __u32 mode;
59292 +
59293 + if (unlikely(!file || !(prot & PROT_EXEC)))
59294 + return 1;
59295 +
59296 + if (is_writable_mmap(file))
59297 + return 0;
59298 +
59299 + mode =
59300 + gr_search_file(file->f_path.dentry,
59301 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59302 + file->f_path.mnt);
59303 +
59304 + if (!gr_tpe_allow(file))
59305 + return 0;
59306 +
59307 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59308 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59309 + return 0;
59310 + } else if (unlikely(!(mode & GR_EXEC))) {
59311 + return 0;
59312 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59313 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59314 + return 1;
59315 + }
59316 +
59317 + return 1;
59318 +}
59319 +
59320 +int
59321 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59322 +{
59323 + __u32 mode;
59324 +
59325 + if (unlikely(!file || !(prot & PROT_EXEC)))
59326 + return 1;
59327 +
59328 + if (is_writable_mmap(file))
59329 + return 0;
59330 +
59331 + mode =
59332 + gr_search_file(file->f_path.dentry,
59333 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59334 + file->f_path.mnt);
59335 +
59336 + if (!gr_tpe_allow(file))
59337 + return 0;
59338 +
59339 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59340 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59341 + return 0;
59342 + } else if (unlikely(!(mode & GR_EXEC))) {
59343 + return 0;
59344 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59345 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59346 + return 1;
59347 + }
59348 +
59349 + return 1;
59350 +}
59351 +
59352 +void
59353 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59354 +{
59355 + unsigned long runtime;
59356 + unsigned long cputime;
59357 + unsigned int wday, cday;
59358 + __u8 whr, chr;
59359 + __u8 wmin, cmin;
59360 + __u8 wsec, csec;
59361 + struct timespec timeval;
59362 +
59363 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
59364 + !(task->acl->mode & GR_PROCACCT)))
59365 + return;
59366 +
59367 + do_posix_clock_monotonic_gettime(&timeval);
59368 + runtime = timeval.tv_sec - task->start_time.tv_sec;
59369 + wday = runtime / (3600 * 24);
59370 + runtime -= wday * (3600 * 24);
59371 + whr = runtime / 3600;
59372 + runtime -= whr * 3600;
59373 + wmin = runtime / 60;
59374 + runtime -= wmin * 60;
59375 + wsec = runtime;
59376 +
59377 + cputime = (task->utime + task->stime) / HZ;
59378 + cday = cputime / (3600 * 24);
59379 + cputime -= cday * (3600 * 24);
59380 + chr = cputime / 3600;
59381 + cputime -= chr * 3600;
59382 + cmin = cputime / 60;
59383 + cputime -= cmin * 60;
59384 + csec = cputime;
59385 +
59386 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
59387 +
59388 + return;
59389 +}
59390 +
59391 +void gr_set_kernel_label(struct task_struct *task)
59392 +{
59393 + if (gr_status & GR_READY) {
59394 + task->role = kernel_role;
59395 + task->acl = kernel_role->root_label;
59396 + }
59397 + return;
59398 +}
59399 +
59400 +#ifdef CONFIG_TASKSTATS
59401 +int gr_is_taskstats_denied(int pid)
59402 +{
59403 + struct task_struct *task;
59404 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59405 + const struct cred *cred;
59406 +#endif
59407 + int ret = 0;
59408 +
59409 + /* restrict taskstats viewing to un-chrooted root users
59410 + who have the 'view' subject flag if the RBAC system is enabled
59411 + */
59412 +
59413 + rcu_read_lock();
59414 + read_lock(&tasklist_lock);
59415 + task = find_task_by_vpid(pid);
59416 + if (task) {
59417 +#ifdef CONFIG_GRKERNSEC_CHROOT
59418 + if (proc_is_chrooted(task))
59419 + ret = -EACCES;
59420 +#endif
59421 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59422 + cred = __task_cred(task);
59423 +#ifdef CONFIG_GRKERNSEC_PROC_USER
59424 + if (cred->uid != 0)
59425 + ret = -EACCES;
59426 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59427 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
59428 + ret = -EACCES;
59429 +#endif
59430 +#endif
59431 + if (gr_status & GR_READY) {
59432 + if (!(task->acl->mode & GR_VIEW))
59433 + ret = -EACCES;
59434 + }
59435 + } else
59436 + ret = -ENOENT;
59437 +
59438 + read_unlock(&tasklist_lock);
59439 + rcu_read_unlock();
59440 +
59441 + return ret;
59442 +}
59443 +#endif
59444 +
59445 +/* AUXV entries are filled via a descendant of search_binary_handler
59446 + after we've already applied the subject for the target
59447 +*/
59448 +int gr_acl_enable_at_secure(void)
59449 +{
59450 + if (unlikely(!(gr_status & GR_READY)))
59451 + return 0;
59452 +
59453 + if (current->acl->mode & GR_ATSECURE)
59454 + return 1;
59455 +
59456 + return 0;
59457 +}
59458 +
59459 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
59460 +{
59461 + struct task_struct *task = current;
59462 + struct dentry *dentry = file->f_path.dentry;
59463 + struct vfsmount *mnt = file->f_path.mnt;
59464 + struct acl_object_label *obj, *tmp;
59465 + struct acl_subject_label *subj;
59466 + unsigned int bufsize;
59467 + int is_not_root;
59468 + char *path;
59469 + dev_t dev = __get_dev(dentry);
59470 +
59471 + if (unlikely(!(gr_status & GR_READY)))
59472 + return 1;
59473 +
59474 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59475 + return 1;
59476 +
59477 + /* ignore Eric Biederman */
59478 + if (IS_PRIVATE(dentry->d_inode))
59479 + return 1;
59480 +
59481 + subj = task->acl;
59482 + do {
59483 + obj = lookup_acl_obj_label(ino, dev, subj);
59484 + if (obj != NULL)
59485 + return (obj->mode & GR_FIND) ? 1 : 0;
59486 + } while ((subj = subj->parent_subject));
59487 +
59488 + /* this is purely an optimization since we're looking for an object
59489 + for the directory we're doing a readdir on
59490 + if it's possible for any globbed object to match the entry we're
59491 + filling into the directory, then the object we find here will be
59492 + an anchor point with attached globbed objects
59493 + */
59494 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
59495 + if (obj->globbed == NULL)
59496 + return (obj->mode & GR_FIND) ? 1 : 0;
59497 +
59498 + is_not_root = ((obj->filename[0] == '/') &&
59499 + (obj->filename[1] == '\0')) ? 0 : 1;
59500 + bufsize = PAGE_SIZE - namelen - is_not_root;
59501 +
59502 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
59503 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
59504 + return 1;
59505 +
59506 + preempt_disable();
59507 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
59508 + bufsize);
59509 +
59510 + bufsize = strlen(path);
59511 +
59512 + /* if base is "/", don't append an additional slash */
59513 + if (is_not_root)
59514 + *(path + bufsize) = '/';
59515 + memcpy(path + bufsize + is_not_root, name, namelen);
59516 + *(path + bufsize + namelen + is_not_root) = '\0';
59517 +
59518 + tmp = obj->globbed;
59519 + while (tmp) {
59520 + if (!glob_match(tmp->filename, path)) {
59521 + preempt_enable();
59522 + return (tmp->mode & GR_FIND) ? 1 : 0;
59523 + }
59524 + tmp = tmp->next;
59525 + }
59526 + preempt_enable();
59527 + return (obj->mode & GR_FIND) ? 1 : 0;
59528 +}
59529 +
59530 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
59531 +EXPORT_SYMBOL(gr_acl_is_enabled);
59532 +#endif
59533 +EXPORT_SYMBOL(gr_learn_resource);
59534 +EXPORT_SYMBOL(gr_set_kernel_label);
59535 +#ifdef CONFIG_SECURITY
59536 +EXPORT_SYMBOL(gr_check_user_change);
59537 +EXPORT_SYMBOL(gr_check_group_change);
59538 +#endif
59539 +
59540 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
59541 new file mode 100644
59542 index 0000000..34fefda
59543 --- /dev/null
59544 +++ b/grsecurity/gracl_alloc.c
59545 @@ -0,0 +1,105 @@
59546 +#include <linux/kernel.h>
59547 +#include <linux/mm.h>
59548 +#include <linux/slab.h>
59549 +#include <linux/vmalloc.h>
59550 +#include <linux/gracl.h>
59551 +#include <linux/grsecurity.h>
59552 +
59553 +static unsigned long alloc_stack_next = 1;
59554 +static unsigned long alloc_stack_size = 1;
59555 +static void **alloc_stack;
59556 +
59557 +static __inline__ int
59558 +alloc_pop(void)
59559 +{
59560 + if (alloc_stack_next == 1)
59561 + return 0;
59562 +
59563 + kfree(alloc_stack[alloc_stack_next - 2]);
59564 +
59565 + alloc_stack_next--;
59566 +
59567 + return 1;
59568 +}
59569 +
59570 +static __inline__ int
59571 +alloc_push(void *buf)
59572 +{
59573 + if (alloc_stack_next >= alloc_stack_size)
59574 + return 1;
59575 +
59576 + alloc_stack[alloc_stack_next - 1] = buf;
59577 +
59578 + alloc_stack_next++;
59579 +
59580 + return 0;
59581 +}
59582 +
59583 +void *
59584 +acl_alloc(unsigned long len)
59585 +{
59586 + void *ret = NULL;
59587 +
59588 + if (!len || len > PAGE_SIZE)
59589 + goto out;
59590 +
59591 + ret = kmalloc(len, GFP_KERNEL);
59592 +
59593 + if (ret) {
59594 + if (alloc_push(ret)) {
59595 + kfree(ret);
59596 + ret = NULL;
59597 + }
59598 + }
59599 +
59600 +out:
59601 + return ret;
59602 +}
59603 +
59604 +void *
59605 +acl_alloc_num(unsigned long num, unsigned long len)
59606 +{
59607 + if (!len || (num > (PAGE_SIZE / len)))
59608 + return NULL;
59609 +
59610 + return acl_alloc(num * len);
59611 +}
59612 +
59613 +void
59614 +acl_free_all(void)
59615 +{
59616 + if (gr_acl_is_enabled() || !alloc_stack)
59617 + return;
59618 +
59619 + while (alloc_pop()) ;
59620 +
59621 + if (alloc_stack) {
59622 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
59623 + kfree(alloc_stack);
59624 + else
59625 + vfree(alloc_stack);
59626 + }
59627 +
59628 + alloc_stack = NULL;
59629 + alloc_stack_size = 1;
59630 + alloc_stack_next = 1;
59631 +
59632 + return;
59633 +}
59634 +
59635 +int
59636 +acl_alloc_stack_init(unsigned long size)
59637 +{
59638 + if ((size * sizeof (void *)) <= PAGE_SIZE)
59639 + alloc_stack =
59640 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
59641 + else
59642 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
59643 +
59644 + alloc_stack_size = size;
59645 +
59646 + if (!alloc_stack)
59647 + return 0;
59648 + else
59649 + return 1;
59650 +}
59651 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
59652 new file mode 100644
59653 index 0000000..955ddfb
59654 --- /dev/null
59655 +++ b/grsecurity/gracl_cap.c
59656 @@ -0,0 +1,101 @@
59657 +#include <linux/kernel.h>
59658 +#include <linux/module.h>
59659 +#include <linux/sched.h>
59660 +#include <linux/gracl.h>
59661 +#include <linux/grsecurity.h>
59662 +#include <linux/grinternal.h>
59663 +
59664 +extern const char *captab_log[];
59665 +extern int captab_log_entries;
59666 +
59667 +int
59668 +gr_acl_is_capable(const int cap)
59669 +{
59670 + struct task_struct *task = current;
59671 + const struct cred *cred = current_cred();
59672 + struct acl_subject_label *curracl;
59673 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59674 + kernel_cap_t cap_audit = __cap_empty_set;
59675 +
59676 + if (!gr_acl_is_enabled())
59677 + return 1;
59678 +
59679 + curracl = task->acl;
59680 +
59681 + cap_drop = curracl->cap_lower;
59682 + cap_mask = curracl->cap_mask;
59683 + cap_audit = curracl->cap_invert_audit;
59684 +
59685 + while ((curracl = curracl->parent_subject)) {
59686 + /* if the cap isn't specified in the current computed mask but is specified in the
59687 + current level subject, and is lowered in the current level subject, then add
59688 + it to the set of dropped capabilities
59689 + otherwise, add the current level subject's mask to the current computed mask
59690 + */
59691 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59692 + cap_raise(cap_mask, cap);
59693 + if (cap_raised(curracl->cap_lower, cap))
59694 + cap_raise(cap_drop, cap);
59695 + if (cap_raised(curracl->cap_invert_audit, cap))
59696 + cap_raise(cap_audit, cap);
59697 + }
59698 + }
59699 +
59700 + if (!cap_raised(cap_drop, cap)) {
59701 + if (cap_raised(cap_audit, cap))
59702 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
59703 + return 1;
59704 + }
59705 +
59706 + curracl = task->acl;
59707 +
59708 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
59709 + && cap_raised(cred->cap_effective, cap)) {
59710 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
59711 + task->role->roletype, cred->uid,
59712 + cred->gid, task->exec_file ?
59713 + gr_to_filename(task->exec_file->f_path.dentry,
59714 + task->exec_file->f_path.mnt) : curracl->filename,
59715 + curracl->filename, 0UL,
59716 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
59717 + return 1;
59718 + }
59719 +
59720 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
59721 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
59722 + return 0;
59723 +}
59724 +
59725 +int
59726 +gr_acl_is_capable_nolog(const int cap)
59727 +{
59728 + struct acl_subject_label *curracl;
59729 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59730 +
59731 + if (!gr_acl_is_enabled())
59732 + return 1;
59733 +
59734 + curracl = current->acl;
59735 +
59736 + cap_drop = curracl->cap_lower;
59737 + cap_mask = curracl->cap_mask;
59738 +
59739 + while ((curracl = curracl->parent_subject)) {
59740 + /* if the cap isn't specified in the current computed mask but is specified in the
59741 + current level subject, and is lowered in the current level subject, then add
59742 + it to the set of dropped capabilities
59743 + otherwise, add the current level subject's mask to the current computed mask
59744 + */
59745 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59746 + cap_raise(cap_mask, cap);
59747 + if (cap_raised(curracl->cap_lower, cap))
59748 + cap_raise(cap_drop, cap);
59749 + }
59750 + }
59751 +
59752 + if (!cap_raised(cap_drop, cap))
59753 + return 1;
59754 +
59755 + return 0;
59756 +}
59757 +
59758 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
59759 new file mode 100644
59760 index 0000000..d5f210c
59761 --- /dev/null
59762 +++ b/grsecurity/gracl_fs.c
59763 @@ -0,0 +1,433 @@
59764 +#include <linux/kernel.h>
59765 +#include <linux/sched.h>
59766 +#include <linux/types.h>
59767 +#include <linux/fs.h>
59768 +#include <linux/file.h>
59769 +#include <linux/stat.h>
59770 +#include <linux/grsecurity.h>
59771 +#include <linux/grinternal.h>
59772 +#include <linux/gracl.h>
59773 +
59774 +__u32
59775 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59776 + const struct vfsmount * mnt)
59777 +{
59778 + __u32 mode;
59779 +
59780 + if (unlikely(!dentry->d_inode))
59781 + return GR_FIND;
59782 +
59783 + mode =
59784 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
59785 +
59786 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
59787 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
59788 + return mode;
59789 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
59790 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
59791 + return 0;
59792 + } else if (unlikely(!(mode & GR_FIND)))
59793 + return 0;
59794 +
59795 + return GR_FIND;
59796 +}
59797 +
59798 +__u32
59799 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59800 + int acc_mode)
59801 +{
59802 + __u32 reqmode = GR_FIND;
59803 + __u32 mode;
59804 +
59805 + if (unlikely(!dentry->d_inode))
59806 + return reqmode;
59807 +
59808 + if (acc_mode & MAY_APPEND)
59809 + reqmode |= GR_APPEND;
59810 + else if (acc_mode & MAY_WRITE)
59811 + reqmode |= GR_WRITE;
59812 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
59813 + reqmode |= GR_READ;
59814 +
59815 + mode =
59816 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
59817 + mnt);
59818 +
59819 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59820 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
59821 + reqmode & GR_READ ? " reading" : "",
59822 + reqmode & GR_WRITE ? " writing" : reqmode &
59823 + GR_APPEND ? " appending" : "");
59824 + return reqmode;
59825 + } else
59826 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59827 + {
59828 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
59829 + reqmode & GR_READ ? " reading" : "",
59830 + reqmode & GR_WRITE ? " writing" : reqmode &
59831 + GR_APPEND ? " appending" : "");
59832 + return 0;
59833 + } else if (unlikely((mode & reqmode) != reqmode))
59834 + return 0;
59835 +
59836 + return reqmode;
59837 +}
59838 +
59839 +__u32
59840 +gr_acl_handle_creat(const struct dentry * dentry,
59841 + const struct dentry * p_dentry,
59842 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59843 + const int imode)
59844 +{
59845 + __u32 reqmode = GR_WRITE | GR_CREATE;
59846 + __u32 mode;
59847 +
59848 + if (acc_mode & MAY_APPEND)
59849 + reqmode |= GR_APPEND;
59850 + // if a directory was required or the directory already exists, then
59851 + // don't count this open as a read
59852 + if ((acc_mode & MAY_READ) &&
59853 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
59854 + reqmode |= GR_READ;
59855 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
59856 + reqmode |= GR_SETID;
59857 +
59858 + mode =
59859 + gr_check_create(dentry, p_dentry, p_mnt,
59860 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59861 +
59862 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59863 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
59864 + reqmode & GR_READ ? " reading" : "",
59865 + reqmode & GR_WRITE ? " writing" : reqmode &
59866 + GR_APPEND ? " appending" : "");
59867 + return reqmode;
59868 + } else
59869 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59870 + {
59871 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
59872 + reqmode & GR_READ ? " reading" : "",
59873 + reqmode & GR_WRITE ? " writing" : reqmode &
59874 + GR_APPEND ? " appending" : "");
59875 + return 0;
59876 + } else if (unlikely((mode & reqmode) != reqmode))
59877 + return 0;
59878 +
59879 + return reqmode;
59880 +}
59881 +
59882 +__u32
59883 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
59884 + const int fmode)
59885 +{
59886 + __u32 mode, reqmode = GR_FIND;
59887 +
59888 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
59889 + reqmode |= GR_EXEC;
59890 + if (fmode & S_IWOTH)
59891 + reqmode |= GR_WRITE;
59892 + if (fmode & S_IROTH)
59893 + reqmode |= GR_READ;
59894 +
59895 + mode =
59896 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
59897 + mnt);
59898 +
59899 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59900 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
59901 + reqmode & GR_READ ? " reading" : "",
59902 + reqmode & GR_WRITE ? " writing" : "",
59903 + reqmode & GR_EXEC ? " executing" : "");
59904 + return reqmode;
59905 + } else
59906 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59907 + {
59908 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
59909 + reqmode & GR_READ ? " reading" : "",
59910 + reqmode & GR_WRITE ? " writing" : "",
59911 + reqmode & GR_EXEC ? " executing" : "");
59912 + return 0;
59913 + } else if (unlikely((mode & reqmode) != reqmode))
59914 + return 0;
59915 +
59916 + return reqmode;
59917 +}
59918 +
59919 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
59920 +{
59921 + __u32 mode;
59922 +
59923 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
59924 +
59925 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59926 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
59927 + return mode;
59928 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59929 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
59930 + return 0;
59931 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
59932 + return 0;
59933 +
59934 + return (reqmode);
59935 +}
59936 +
59937 +__u32
59938 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59939 +{
59940 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
59941 +}
59942 +
59943 +__u32
59944 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
59945 +{
59946 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
59947 +}
59948 +
59949 +__u32
59950 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
59951 +{
59952 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
59953 +}
59954 +
59955 +__u32
59956 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
59957 +{
59958 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
59959 +}
59960 +
59961 +__u32
59962 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
59963 + mode_t mode)
59964 +{
59965 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
59966 + return 1;
59967 +
59968 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
59969 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
59970 + GR_FCHMOD_ACL_MSG);
59971 + } else {
59972 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
59973 + }
59974 +}
59975 +
59976 +__u32
59977 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
59978 + mode_t mode)
59979 +{
59980 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
59981 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
59982 + GR_CHMOD_ACL_MSG);
59983 + } else {
59984 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
59985 + }
59986 +}
59987 +
59988 +__u32
59989 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
59990 +{
59991 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
59992 +}
59993 +
59994 +__u32
59995 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
59996 +{
59997 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
59998 +}
59999 +
60000 +__u32
60001 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
60002 +{
60003 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
60004 +}
60005 +
60006 +__u32
60007 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
60008 +{
60009 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
60010 + GR_UNIXCONNECT_ACL_MSG);
60011 +}
60012 +
60013 +/* hardlinks require at minimum create and link permission,
60014 + any additional privilege required is based on the
60015 + privilege of the file being linked to
60016 +*/
60017 +__u32
60018 +gr_acl_handle_link(const struct dentry * new_dentry,
60019 + const struct dentry * parent_dentry,
60020 + const struct vfsmount * parent_mnt,
60021 + const struct dentry * old_dentry,
60022 + const struct vfsmount * old_mnt, const char *to)
60023 +{
60024 + __u32 mode;
60025 + __u32 needmode = GR_CREATE | GR_LINK;
60026 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
60027 +
60028 + mode =
60029 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
60030 + old_mnt);
60031 +
60032 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
60033 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60034 + return mode;
60035 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60036 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60037 + return 0;
60038 + } else if (unlikely((mode & needmode) != needmode))
60039 + return 0;
60040 +
60041 + return 1;
60042 +}
60043 +
60044 +__u32
60045 +gr_acl_handle_symlink(const struct dentry * new_dentry,
60046 + const struct dentry * parent_dentry,
60047 + const struct vfsmount * parent_mnt, const char *from)
60048 +{
60049 + __u32 needmode = GR_WRITE | GR_CREATE;
60050 + __u32 mode;
60051 +
60052 + mode =
60053 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
60054 + GR_CREATE | GR_AUDIT_CREATE |
60055 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
60056 +
60057 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
60058 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60059 + return mode;
60060 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60061 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60062 + return 0;
60063 + } else if (unlikely((mode & needmode) != needmode))
60064 + return 0;
60065 +
60066 + return (GR_WRITE | GR_CREATE);
60067 +}
60068 +
60069 +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)
60070 +{
60071 + __u32 mode;
60072 +
60073 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60074 +
60075 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60076 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
60077 + return mode;
60078 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60079 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
60080 + return 0;
60081 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
60082 + return 0;
60083 +
60084 + return (reqmode);
60085 +}
60086 +
60087 +__u32
60088 +gr_acl_handle_mknod(const struct dentry * new_dentry,
60089 + const struct dentry * parent_dentry,
60090 + const struct vfsmount * parent_mnt,
60091 + const int mode)
60092 +{
60093 + __u32 reqmode = GR_WRITE | GR_CREATE;
60094 + if (unlikely(mode & (S_ISUID | S_ISGID)))
60095 + reqmode |= GR_SETID;
60096 +
60097 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60098 + reqmode, GR_MKNOD_ACL_MSG);
60099 +}
60100 +
60101 +__u32
60102 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
60103 + const struct dentry *parent_dentry,
60104 + const struct vfsmount *parent_mnt)
60105 +{
60106 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60107 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
60108 +}
60109 +
60110 +#define RENAME_CHECK_SUCCESS(old, new) \
60111 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
60112 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
60113 +
60114 +int
60115 +gr_acl_handle_rename(struct dentry *new_dentry,
60116 + struct dentry *parent_dentry,
60117 + const struct vfsmount *parent_mnt,
60118 + struct dentry *old_dentry,
60119 + struct inode *old_parent_inode,
60120 + struct vfsmount *old_mnt, const char *newname)
60121 +{
60122 + __u32 comp1, comp2;
60123 + int error = 0;
60124 +
60125 + if (unlikely(!gr_acl_is_enabled()))
60126 + return 0;
60127 +
60128 + if (!new_dentry->d_inode) {
60129 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
60130 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
60131 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
60132 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
60133 + GR_DELETE | GR_AUDIT_DELETE |
60134 + GR_AUDIT_READ | GR_AUDIT_WRITE |
60135 + GR_SUPPRESS, old_mnt);
60136 + } else {
60137 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
60138 + GR_CREATE | GR_DELETE |
60139 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
60140 + GR_AUDIT_READ | GR_AUDIT_WRITE |
60141 + GR_SUPPRESS, parent_mnt);
60142 + comp2 =
60143 + gr_search_file(old_dentry,
60144 + GR_READ | GR_WRITE | GR_AUDIT_READ |
60145 + GR_DELETE | GR_AUDIT_DELETE |
60146 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
60147 + }
60148 +
60149 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
60150 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
60151 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60152 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
60153 + && !(comp2 & GR_SUPPRESS)) {
60154 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60155 + error = -EACCES;
60156 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
60157 + error = -EACCES;
60158 +
60159 + return error;
60160 +}
60161 +
60162 +void
60163 +gr_acl_handle_exit(void)
60164 +{
60165 + u16 id;
60166 + char *rolename;
60167 + struct file *exec_file;
60168 +
60169 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
60170 + !(current->role->roletype & GR_ROLE_PERSIST))) {
60171 + id = current->acl_role_id;
60172 + rolename = current->role->rolename;
60173 + gr_set_acls(1);
60174 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
60175 + }
60176 +
60177 + write_lock(&grsec_exec_file_lock);
60178 + exec_file = current->exec_file;
60179 + current->exec_file = NULL;
60180 + write_unlock(&grsec_exec_file_lock);
60181 +
60182 + if (exec_file)
60183 + fput(exec_file);
60184 +}
60185 +
60186 +int
60187 +gr_acl_handle_procpidmem(const struct task_struct *task)
60188 +{
60189 + if (unlikely(!gr_acl_is_enabled()))
60190 + return 0;
60191 +
60192 + if (task != current && task->acl->mode & GR_PROTPROCFD)
60193 + return -EACCES;
60194 +
60195 + return 0;
60196 +}
60197 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
60198 new file mode 100644
60199 index 0000000..cd07b96
60200 --- /dev/null
60201 +++ b/grsecurity/gracl_ip.c
60202 @@ -0,0 +1,382 @@
60203 +#include <linux/kernel.h>
60204 +#include <asm/uaccess.h>
60205 +#include <asm/errno.h>
60206 +#include <net/sock.h>
60207 +#include <linux/file.h>
60208 +#include <linux/fs.h>
60209 +#include <linux/net.h>
60210 +#include <linux/in.h>
60211 +#include <linux/skbuff.h>
60212 +#include <linux/ip.h>
60213 +#include <linux/udp.h>
60214 +#include <linux/smp_lock.h>
60215 +#include <linux/types.h>
60216 +#include <linux/sched.h>
60217 +#include <linux/netdevice.h>
60218 +#include <linux/inetdevice.h>
60219 +#include <linux/gracl.h>
60220 +#include <linux/grsecurity.h>
60221 +#include <linux/grinternal.h>
60222 +
60223 +#define GR_BIND 0x01
60224 +#define GR_CONNECT 0x02
60225 +#define GR_INVERT 0x04
60226 +#define GR_BINDOVERRIDE 0x08
60227 +#define GR_CONNECTOVERRIDE 0x10
60228 +#define GR_SOCK_FAMILY 0x20
60229 +
60230 +static const char * gr_protocols[IPPROTO_MAX] = {
60231 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
60232 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
60233 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
60234 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
60235 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
60236 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
60237 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
60238 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
60239 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
60240 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
60241 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
60242 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
60243 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
60244 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
60245 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
60246 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
60247 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
60248 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
60249 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
60250 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
60251 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
60252 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
60253 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
60254 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
60255 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
60256 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
60257 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
60258 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
60259 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
60260 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
60261 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
60262 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
60263 + };
60264 +
60265 +static const char * gr_socktypes[SOCK_MAX] = {
60266 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
60267 + "unknown:7", "unknown:8", "unknown:9", "packet"
60268 + };
60269 +
60270 +static const char * gr_sockfamilies[AF_MAX+1] = {
60271 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
60272 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
60273 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
60274 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
60275 + };
60276 +
60277 +const char *
60278 +gr_proto_to_name(unsigned char proto)
60279 +{
60280 + return gr_protocols[proto];
60281 +}
60282 +
60283 +const char *
60284 +gr_socktype_to_name(unsigned char type)
60285 +{
60286 + return gr_socktypes[type];
60287 +}
60288 +
60289 +const char *
60290 +gr_sockfamily_to_name(unsigned char family)
60291 +{
60292 + return gr_sockfamilies[family];
60293 +}
60294 +
60295 +int
60296 +gr_search_socket(const int domain, const int type, const int protocol)
60297 +{
60298 + struct acl_subject_label *curr;
60299 + const struct cred *cred = current_cred();
60300 +
60301 + if (unlikely(!gr_acl_is_enabled()))
60302 + goto exit;
60303 +
60304 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
60305 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
60306 + goto exit; // let the kernel handle it
60307 +
60308 + curr = current->acl;
60309 +
60310 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
60311 + /* the family is allowed, if this is PF_INET allow it only if
60312 + the extra sock type/protocol checks pass */
60313 + if (domain == PF_INET)
60314 + goto inet_check;
60315 + goto exit;
60316 + } else {
60317 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60318 + __u32 fakeip = 0;
60319 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60320 + current->role->roletype, cred->uid,
60321 + cred->gid, current->exec_file ?
60322 + gr_to_filename(current->exec_file->f_path.dentry,
60323 + current->exec_file->f_path.mnt) :
60324 + curr->filename, curr->filename,
60325 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
60326 + &current->signal->saved_ip);
60327 + goto exit;
60328 + }
60329 + goto exit_fail;
60330 + }
60331 +
60332 +inet_check:
60333 + /* the rest of this checking is for IPv4 only */
60334 + if (!curr->ips)
60335 + goto exit;
60336 +
60337 + if ((curr->ip_type & (1 << type)) &&
60338 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
60339 + goto exit;
60340 +
60341 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60342 + /* we don't place acls on raw sockets , and sometimes
60343 + dgram/ip sockets are opened for ioctl and not
60344 + bind/connect, so we'll fake a bind learn log */
60345 + if (type == SOCK_RAW || type == SOCK_PACKET) {
60346 + __u32 fakeip = 0;
60347 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60348 + current->role->roletype, cred->uid,
60349 + cred->gid, current->exec_file ?
60350 + gr_to_filename(current->exec_file->f_path.dentry,
60351 + current->exec_file->f_path.mnt) :
60352 + curr->filename, curr->filename,
60353 + &fakeip, 0, type,
60354 + protocol, GR_CONNECT, &current->signal->saved_ip);
60355 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
60356 + __u32 fakeip = 0;
60357 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60358 + current->role->roletype, cred->uid,
60359 + cred->gid, current->exec_file ?
60360 + gr_to_filename(current->exec_file->f_path.dentry,
60361 + current->exec_file->f_path.mnt) :
60362 + curr->filename, curr->filename,
60363 + &fakeip, 0, type,
60364 + protocol, GR_BIND, &current->signal->saved_ip);
60365 + }
60366 + /* we'll log when they use connect or bind */
60367 + goto exit;
60368 + }
60369 +
60370 +exit_fail:
60371 + if (domain == PF_INET)
60372 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
60373 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
60374 + else
60375 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
60376 + gr_socktype_to_name(type), protocol);
60377 +
60378 + return 0;
60379 +exit:
60380 + return 1;
60381 +}
60382 +
60383 +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)
60384 +{
60385 + if ((ip->mode & mode) &&
60386 + (ip_port >= ip->low) &&
60387 + (ip_port <= ip->high) &&
60388 + ((ntohl(ip_addr) & our_netmask) ==
60389 + (ntohl(our_addr) & our_netmask))
60390 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
60391 + && (ip->type & (1 << type))) {
60392 + if (ip->mode & GR_INVERT)
60393 + return 2; // specifically denied
60394 + else
60395 + return 1; // allowed
60396 + }
60397 +
60398 + return 0; // not specifically allowed, may continue parsing
60399 +}
60400 +
60401 +static int
60402 +gr_search_connectbind(const int full_mode, struct sock *sk,
60403 + struct sockaddr_in *addr, const int type)
60404 +{
60405 + char iface[IFNAMSIZ] = {0};
60406 + struct acl_subject_label *curr;
60407 + struct acl_ip_label *ip;
60408 + struct inet_sock *isk;
60409 + struct net_device *dev;
60410 + struct in_device *idev;
60411 + unsigned long i;
60412 + int ret;
60413 + int mode = full_mode & (GR_BIND | GR_CONNECT);
60414 + __u32 ip_addr = 0;
60415 + __u32 our_addr;
60416 + __u32 our_netmask;
60417 + char *p;
60418 + __u16 ip_port = 0;
60419 + const struct cred *cred = current_cred();
60420 +
60421 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
60422 + return 0;
60423 +
60424 + curr = current->acl;
60425 + isk = inet_sk(sk);
60426 +
60427 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
60428 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
60429 + addr->sin_addr.s_addr = curr->inaddr_any_override;
60430 + if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
60431 + struct sockaddr_in saddr;
60432 + int err;
60433 +
60434 + saddr.sin_family = AF_INET;
60435 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
60436 + saddr.sin_port = isk->sport;
60437 +
60438 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60439 + if (err)
60440 + return err;
60441 +
60442 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60443 + if (err)
60444 + return err;
60445 + }
60446 +
60447 + if (!curr->ips)
60448 + return 0;
60449 +
60450 + ip_addr = addr->sin_addr.s_addr;
60451 + ip_port = ntohs(addr->sin_port);
60452 +
60453 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60454 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60455 + current->role->roletype, cred->uid,
60456 + cred->gid, current->exec_file ?
60457 + gr_to_filename(current->exec_file->f_path.dentry,
60458 + current->exec_file->f_path.mnt) :
60459 + curr->filename, curr->filename,
60460 + &ip_addr, ip_port, type,
60461 + sk->sk_protocol, mode, &current->signal->saved_ip);
60462 + return 0;
60463 + }
60464 +
60465 + for (i = 0; i < curr->ip_num; i++) {
60466 + ip = *(curr->ips + i);
60467 + if (ip->iface != NULL) {
60468 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
60469 + p = strchr(iface, ':');
60470 + if (p != NULL)
60471 + *p = '\0';
60472 + dev = dev_get_by_name(sock_net(sk), iface);
60473 + if (dev == NULL)
60474 + continue;
60475 + idev = in_dev_get(dev);
60476 + if (idev == NULL) {
60477 + dev_put(dev);
60478 + continue;
60479 + }
60480 + rcu_read_lock();
60481 + for_ifa(idev) {
60482 + if (!strcmp(ip->iface, ifa->ifa_label)) {
60483 + our_addr = ifa->ifa_address;
60484 + our_netmask = 0xffffffff;
60485 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60486 + if (ret == 1) {
60487 + rcu_read_unlock();
60488 + in_dev_put(idev);
60489 + dev_put(dev);
60490 + return 0;
60491 + } else if (ret == 2) {
60492 + rcu_read_unlock();
60493 + in_dev_put(idev);
60494 + dev_put(dev);
60495 + goto denied;
60496 + }
60497 + }
60498 + } endfor_ifa(idev);
60499 + rcu_read_unlock();
60500 + in_dev_put(idev);
60501 + dev_put(dev);
60502 + } else {
60503 + our_addr = ip->addr;
60504 + our_netmask = ip->netmask;
60505 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60506 + if (ret == 1)
60507 + return 0;
60508 + else if (ret == 2)
60509 + goto denied;
60510 + }
60511 + }
60512 +
60513 +denied:
60514 + if (mode == GR_BIND)
60515 + 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));
60516 + else if (mode == GR_CONNECT)
60517 + 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));
60518 +
60519 + return -EACCES;
60520 +}
60521 +
60522 +int
60523 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
60524 +{
60525 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
60526 +}
60527 +
60528 +int
60529 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
60530 +{
60531 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
60532 +}
60533 +
60534 +int gr_search_listen(struct socket *sock)
60535 +{
60536 + struct sock *sk = sock->sk;
60537 + struct sockaddr_in addr;
60538 +
60539 + addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60540 + addr.sin_port = inet_sk(sk)->sport;
60541 +
60542 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60543 +}
60544 +
60545 +int gr_search_accept(struct socket *sock)
60546 +{
60547 + struct sock *sk = sock->sk;
60548 + struct sockaddr_in addr;
60549 +
60550 + addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60551 + addr.sin_port = inet_sk(sk)->sport;
60552 +
60553 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60554 +}
60555 +
60556 +int
60557 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
60558 +{
60559 + if (addr)
60560 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
60561 + else {
60562 + struct sockaddr_in sin;
60563 + const struct inet_sock *inet = inet_sk(sk);
60564 +
60565 + sin.sin_addr.s_addr = inet->daddr;
60566 + sin.sin_port = inet->dport;
60567 +
60568 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60569 + }
60570 +}
60571 +
60572 +int
60573 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
60574 +{
60575 + struct sockaddr_in sin;
60576 +
60577 + if (unlikely(skb->len < sizeof (struct udphdr)))
60578 + return 0; // skip this packet
60579 +
60580 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
60581 + sin.sin_port = udp_hdr(skb)->source;
60582 +
60583 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60584 +}
60585 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
60586 new file mode 100644
60587 index 0000000..34bdd46
60588 --- /dev/null
60589 +++ b/grsecurity/gracl_learn.c
60590 @@ -0,0 +1,208 @@
60591 +#include <linux/kernel.h>
60592 +#include <linux/mm.h>
60593 +#include <linux/sched.h>
60594 +#include <linux/poll.h>
60595 +#include <linux/smp_lock.h>
60596 +#include <linux/string.h>
60597 +#include <linux/file.h>
60598 +#include <linux/types.h>
60599 +#include <linux/vmalloc.h>
60600 +#include <linux/grinternal.h>
60601 +
60602 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
60603 + size_t count, loff_t *ppos);
60604 +extern int gr_acl_is_enabled(void);
60605 +
60606 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
60607 +static int gr_learn_attached;
60608 +
60609 +/* use a 512k buffer */
60610 +#define LEARN_BUFFER_SIZE (512 * 1024)
60611 +
60612 +static DEFINE_SPINLOCK(gr_learn_lock);
60613 +static DEFINE_MUTEX(gr_learn_user_mutex);
60614 +
60615 +/* we need to maintain two buffers, so that the kernel context of grlearn
60616 + uses a semaphore around the userspace copying, and the other kernel contexts
60617 + use a spinlock when copying into the buffer, since they cannot sleep
60618 +*/
60619 +static char *learn_buffer;
60620 +static char *learn_buffer_user;
60621 +static int learn_buffer_len;
60622 +static int learn_buffer_user_len;
60623 +
60624 +static ssize_t
60625 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
60626 +{
60627 + DECLARE_WAITQUEUE(wait, current);
60628 + ssize_t retval = 0;
60629 +
60630 + add_wait_queue(&learn_wait, &wait);
60631 + set_current_state(TASK_INTERRUPTIBLE);
60632 + do {
60633 + mutex_lock(&gr_learn_user_mutex);
60634 + spin_lock(&gr_learn_lock);
60635 + if (learn_buffer_len)
60636 + break;
60637 + spin_unlock(&gr_learn_lock);
60638 + mutex_unlock(&gr_learn_user_mutex);
60639 + if (file->f_flags & O_NONBLOCK) {
60640 + retval = -EAGAIN;
60641 + goto out;
60642 + }
60643 + if (signal_pending(current)) {
60644 + retval = -ERESTARTSYS;
60645 + goto out;
60646 + }
60647 +
60648 + schedule();
60649 + } while (1);
60650 +
60651 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
60652 + learn_buffer_user_len = learn_buffer_len;
60653 + retval = learn_buffer_len;
60654 + learn_buffer_len = 0;
60655 +
60656 + spin_unlock(&gr_learn_lock);
60657 +
60658 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
60659 + retval = -EFAULT;
60660 +
60661 + mutex_unlock(&gr_learn_user_mutex);
60662 +out:
60663 + set_current_state(TASK_RUNNING);
60664 + remove_wait_queue(&learn_wait, &wait);
60665 + return retval;
60666 +}
60667 +
60668 +static unsigned int
60669 +poll_learn(struct file * file, poll_table * wait)
60670 +{
60671 + poll_wait(file, &learn_wait, wait);
60672 +
60673 + if (learn_buffer_len)
60674 + return (POLLIN | POLLRDNORM);
60675 +
60676 + return 0;
60677 +}
60678 +
60679 +void
60680 +gr_clear_learn_entries(void)
60681 +{
60682 + char *tmp;
60683 +
60684 + mutex_lock(&gr_learn_user_mutex);
60685 + spin_lock(&gr_learn_lock);
60686 + tmp = learn_buffer;
60687 + learn_buffer = NULL;
60688 + spin_unlock(&gr_learn_lock);
60689 + if (tmp)
60690 + vfree(tmp);
60691 + if (learn_buffer_user != NULL) {
60692 + vfree(learn_buffer_user);
60693 + learn_buffer_user = NULL;
60694 + }
60695 + learn_buffer_len = 0;
60696 + mutex_unlock(&gr_learn_user_mutex);
60697 +
60698 + return;
60699 +}
60700 +
60701 +void
60702 +gr_add_learn_entry(const char *fmt, ...)
60703 +{
60704 + va_list args;
60705 + unsigned int len;
60706 +
60707 + if (!gr_learn_attached)
60708 + return;
60709 +
60710 + spin_lock(&gr_learn_lock);
60711 +
60712 + /* leave a gap at the end so we know when it's "full" but don't have to
60713 + compute the exact length of the string we're trying to append
60714 + */
60715 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
60716 + spin_unlock(&gr_learn_lock);
60717 + wake_up_interruptible(&learn_wait);
60718 + return;
60719 + }
60720 + if (learn_buffer == NULL) {
60721 + spin_unlock(&gr_learn_lock);
60722 + return;
60723 + }
60724 +
60725 + va_start(args, fmt);
60726 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
60727 + va_end(args);
60728 +
60729 + learn_buffer_len += len + 1;
60730 +
60731 + spin_unlock(&gr_learn_lock);
60732 + wake_up_interruptible(&learn_wait);
60733 +
60734 + return;
60735 +}
60736 +
60737 +static int
60738 +open_learn(struct inode *inode, struct file *file)
60739 +{
60740 + if (file->f_mode & FMODE_READ && gr_learn_attached)
60741 + return -EBUSY;
60742 + if (file->f_mode & FMODE_READ) {
60743 + int retval = 0;
60744 + mutex_lock(&gr_learn_user_mutex);
60745 + if (learn_buffer == NULL)
60746 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
60747 + if (learn_buffer_user == NULL)
60748 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
60749 + if (learn_buffer == NULL) {
60750 + retval = -ENOMEM;
60751 + goto out_error;
60752 + }
60753 + if (learn_buffer_user == NULL) {
60754 + retval = -ENOMEM;
60755 + goto out_error;
60756 + }
60757 + learn_buffer_len = 0;
60758 + learn_buffer_user_len = 0;
60759 + gr_learn_attached = 1;
60760 +out_error:
60761 + mutex_unlock(&gr_learn_user_mutex);
60762 + return retval;
60763 + }
60764 + return 0;
60765 +}
60766 +
60767 +static int
60768 +close_learn(struct inode *inode, struct file *file)
60769 +{
60770 + if (file->f_mode & FMODE_READ) {
60771 + char *tmp = NULL;
60772 + mutex_lock(&gr_learn_user_mutex);
60773 + spin_lock(&gr_learn_lock);
60774 + tmp = learn_buffer;
60775 + learn_buffer = NULL;
60776 + spin_unlock(&gr_learn_lock);
60777 + if (tmp)
60778 + vfree(tmp);
60779 + if (learn_buffer_user != NULL) {
60780 + vfree(learn_buffer_user);
60781 + learn_buffer_user = NULL;
60782 + }
60783 + learn_buffer_len = 0;
60784 + learn_buffer_user_len = 0;
60785 + gr_learn_attached = 0;
60786 + mutex_unlock(&gr_learn_user_mutex);
60787 + }
60788 +
60789 + return 0;
60790 +}
60791 +
60792 +const struct file_operations grsec_fops = {
60793 + .read = read_learn,
60794 + .write = write_grsec_handler,
60795 + .open = open_learn,
60796 + .release = close_learn,
60797 + .poll = poll_learn,
60798 +};
60799 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
60800 new file mode 100644
60801 index 0000000..70b2179
60802 --- /dev/null
60803 +++ b/grsecurity/gracl_res.c
60804 @@ -0,0 +1,67 @@
60805 +#include <linux/kernel.h>
60806 +#include <linux/sched.h>
60807 +#include <linux/gracl.h>
60808 +#include <linux/grinternal.h>
60809 +
60810 +static const char *restab_log[] = {
60811 + [RLIMIT_CPU] = "RLIMIT_CPU",
60812 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
60813 + [RLIMIT_DATA] = "RLIMIT_DATA",
60814 + [RLIMIT_STACK] = "RLIMIT_STACK",
60815 + [RLIMIT_CORE] = "RLIMIT_CORE",
60816 + [RLIMIT_RSS] = "RLIMIT_RSS",
60817 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
60818 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
60819 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
60820 + [RLIMIT_AS] = "RLIMIT_AS",
60821 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
60822 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
60823 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
60824 + [RLIMIT_NICE] = "RLIMIT_NICE",
60825 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
60826 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
60827 + [GR_CRASH_RES] = "RLIMIT_CRASH"
60828 +};
60829 +
60830 +void
60831 +gr_log_resource(const struct task_struct *task,
60832 + const int res, const unsigned long wanted, const int gt)
60833 +{
60834 + const struct cred *cred;
60835 + unsigned long rlim;
60836 +
60837 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
60838 + return;
60839 +
60840 + // not yet supported resource
60841 + if (unlikely(!restab_log[res]))
60842 + return;
60843 +
60844 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
60845 + rlim = task->signal->rlim[res].rlim_max;
60846 + else
60847 + rlim = task->signal->rlim[res].rlim_cur;
60848 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
60849 + return;
60850 +
60851 + rcu_read_lock();
60852 + cred = __task_cred(task);
60853 +
60854 + if (res == RLIMIT_NPROC &&
60855 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
60856 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
60857 + goto out_rcu_unlock;
60858 + else if (res == RLIMIT_MEMLOCK &&
60859 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
60860 + goto out_rcu_unlock;
60861 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
60862 + goto out_rcu_unlock;
60863 + rcu_read_unlock();
60864 +
60865 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
60866 +
60867 + return;
60868 +out_rcu_unlock:
60869 + rcu_read_unlock();
60870 + return;
60871 +}
60872 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
60873 new file mode 100644
60874 index 0000000..1d1b734
60875 --- /dev/null
60876 +++ b/grsecurity/gracl_segv.c
60877 @@ -0,0 +1,284 @@
60878 +#include <linux/kernel.h>
60879 +#include <linux/mm.h>
60880 +#include <asm/uaccess.h>
60881 +#include <asm/errno.h>
60882 +#include <asm/mman.h>
60883 +#include <net/sock.h>
60884 +#include <linux/file.h>
60885 +#include <linux/fs.h>
60886 +#include <linux/net.h>
60887 +#include <linux/in.h>
60888 +#include <linux/smp_lock.h>
60889 +#include <linux/slab.h>
60890 +#include <linux/types.h>
60891 +#include <linux/sched.h>
60892 +#include <linux/timer.h>
60893 +#include <linux/gracl.h>
60894 +#include <linux/grsecurity.h>
60895 +#include <linux/grinternal.h>
60896 +
60897 +static struct crash_uid *uid_set;
60898 +static unsigned short uid_used;
60899 +static DEFINE_SPINLOCK(gr_uid_lock);
60900 +extern rwlock_t gr_inode_lock;
60901 +extern struct acl_subject_label *
60902 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
60903 + struct acl_role_label *role);
60904 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
60905 +
60906 +int
60907 +gr_init_uidset(void)
60908 +{
60909 + uid_set =
60910 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
60911 + uid_used = 0;
60912 +
60913 + return uid_set ? 1 : 0;
60914 +}
60915 +
60916 +void
60917 +gr_free_uidset(void)
60918 +{
60919 + if (uid_set)
60920 + kfree(uid_set);
60921 +
60922 + return;
60923 +}
60924 +
60925 +int
60926 +gr_find_uid(const uid_t uid)
60927 +{
60928 + struct crash_uid *tmp = uid_set;
60929 + uid_t buid;
60930 + int low = 0, high = uid_used - 1, mid;
60931 +
60932 + while (high >= low) {
60933 + mid = (low + high) >> 1;
60934 + buid = tmp[mid].uid;
60935 + if (buid == uid)
60936 + return mid;
60937 + if (buid > uid)
60938 + high = mid - 1;
60939 + if (buid < uid)
60940 + low = mid + 1;
60941 + }
60942 +
60943 + return -1;
60944 +}
60945 +
60946 +static __inline__ void
60947 +gr_insertsort(void)
60948 +{
60949 + unsigned short i, j;
60950 + struct crash_uid index;
60951 +
60952 + for (i = 1; i < uid_used; i++) {
60953 + index = uid_set[i];
60954 + j = i;
60955 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
60956 + uid_set[j] = uid_set[j - 1];
60957 + j--;
60958 + }
60959 + uid_set[j] = index;
60960 + }
60961 +
60962 + return;
60963 +}
60964 +
60965 +static __inline__ void
60966 +gr_insert_uid(const uid_t uid, const unsigned long expires)
60967 +{
60968 + int loc;
60969 +
60970 + if (uid_used == GR_UIDTABLE_MAX)
60971 + return;
60972 +
60973 + loc = gr_find_uid(uid);
60974 +
60975 + if (loc >= 0) {
60976 + uid_set[loc].expires = expires;
60977 + return;
60978 + }
60979 +
60980 + uid_set[uid_used].uid = uid;
60981 + uid_set[uid_used].expires = expires;
60982 + uid_used++;
60983 +
60984 + gr_insertsort();
60985 +
60986 + return;
60987 +}
60988 +
60989 +void
60990 +gr_remove_uid(const unsigned short loc)
60991 +{
60992 + unsigned short i;
60993 +
60994 + for (i = loc + 1; i < uid_used; i++)
60995 + uid_set[i - 1] = uid_set[i];
60996 +
60997 + uid_used--;
60998 +
60999 + return;
61000 +}
61001 +
61002 +int
61003 +gr_check_crash_uid(const uid_t uid)
61004 +{
61005 + int loc;
61006 + int ret = 0;
61007 +
61008 + if (unlikely(!gr_acl_is_enabled()))
61009 + return 0;
61010 +
61011 + spin_lock(&gr_uid_lock);
61012 + loc = gr_find_uid(uid);
61013 +
61014 + if (loc < 0)
61015 + goto out_unlock;
61016 +
61017 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
61018 + gr_remove_uid(loc);
61019 + else
61020 + ret = 1;
61021 +
61022 +out_unlock:
61023 + spin_unlock(&gr_uid_lock);
61024 + return ret;
61025 +}
61026 +
61027 +static __inline__ int
61028 +proc_is_setxid(const struct cred *cred)
61029 +{
61030 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
61031 + cred->uid != cred->fsuid)
61032 + return 1;
61033 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
61034 + cred->gid != cred->fsgid)
61035 + return 1;
61036 +
61037 + return 0;
61038 +}
61039 +
61040 +void
61041 +gr_handle_crash(struct task_struct *task, const int sig)
61042 +{
61043 + struct acl_subject_label *curr;
61044 + struct task_struct *tsk, *tsk2;
61045 + const struct cred *cred;
61046 + const struct cred *cred2;
61047 +
61048 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
61049 + return;
61050 +
61051 + if (unlikely(!gr_acl_is_enabled()))
61052 + return;
61053 +
61054 + curr = task->acl;
61055 +
61056 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
61057 + return;
61058 +
61059 + if (time_before_eq(curr->expires, get_seconds())) {
61060 + curr->expires = 0;
61061 + curr->crashes = 0;
61062 + }
61063 +
61064 + curr->crashes++;
61065 +
61066 + if (!curr->expires)
61067 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
61068 +
61069 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61070 + time_after(curr->expires, get_seconds())) {
61071 + rcu_read_lock();
61072 + cred = __task_cred(task);
61073 + if (cred->uid && proc_is_setxid(cred)) {
61074 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61075 + spin_lock(&gr_uid_lock);
61076 + gr_insert_uid(cred->uid, curr->expires);
61077 + spin_unlock(&gr_uid_lock);
61078 + curr->expires = 0;
61079 + curr->crashes = 0;
61080 + read_lock(&tasklist_lock);
61081 + do_each_thread(tsk2, tsk) {
61082 + cred2 = __task_cred(tsk);
61083 + if (tsk != task && cred2->uid == cred->uid)
61084 + gr_fake_force_sig(SIGKILL, tsk);
61085 + } while_each_thread(tsk2, tsk);
61086 + read_unlock(&tasklist_lock);
61087 + } else {
61088 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61089 + read_lock(&tasklist_lock);
61090 + read_lock(&grsec_exec_file_lock);
61091 + do_each_thread(tsk2, tsk) {
61092 + if (likely(tsk != task)) {
61093 + // if this thread has the same subject as the one that triggered
61094 + // RES_CRASH and it's the same binary, kill it
61095 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
61096 + gr_fake_force_sig(SIGKILL, tsk);
61097 + }
61098 + } while_each_thread(tsk2, tsk);
61099 + read_unlock(&grsec_exec_file_lock);
61100 + read_unlock(&tasklist_lock);
61101 + }
61102 + rcu_read_unlock();
61103 + }
61104 +
61105 + return;
61106 +}
61107 +
61108 +int
61109 +gr_check_crash_exec(const struct file *filp)
61110 +{
61111 + struct acl_subject_label *curr;
61112 +
61113 + if (unlikely(!gr_acl_is_enabled()))
61114 + return 0;
61115 +
61116 + read_lock(&gr_inode_lock);
61117 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
61118 + filp->f_path.dentry->d_inode->i_sb->s_dev,
61119 + current->role);
61120 + read_unlock(&gr_inode_lock);
61121 +
61122 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
61123 + (!curr->crashes && !curr->expires))
61124 + return 0;
61125 +
61126 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61127 + time_after(curr->expires, get_seconds()))
61128 + return 1;
61129 + else if (time_before_eq(curr->expires, get_seconds())) {
61130 + curr->crashes = 0;
61131 + curr->expires = 0;
61132 + }
61133 +
61134 + return 0;
61135 +}
61136 +
61137 +void
61138 +gr_handle_alertkill(struct task_struct *task)
61139 +{
61140 + struct acl_subject_label *curracl;
61141 + __u32 curr_ip;
61142 + struct task_struct *p, *p2;
61143 +
61144 + if (unlikely(!gr_acl_is_enabled()))
61145 + return;
61146 +
61147 + curracl = task->acl;
61148 + curr_ip = task->signal->curr_ip;
61149 +
61150 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
61151 + read_lock(&tasklist_lock);
61152 + do_each_thread(p2, p) {
61153 + if (p->signal->curr_ip == curr_ip)
61154 + gr_fake_force_sig(SIGKILL, p);
61155 + } while_each_thread(p2, p);
61156 + read_unlock(&tasklist_lock);
61157 + } else if (curracl->mode & GR_KILLPROC)
61158 + gr_fake_force_sig(SIGKILL, task);
61159 +
61160 + return;
61161 +}
61162 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
61163 new file mode 100644
61164 index 0000000..9d83a69
61165 --- /dev/null
61166 +++ b/grsecurity/gracl_shm.c
61167 @@ -0,0 +1,40 @@
61168 +#include <linux/kernel.h>
61169 +#include <linux/mm.h>
61170 +#include <linux/sched.h>
61171 +#include <linux/file.h>
61172 +#include <linux/ipc.h>
61173 +#include <linux/gracl.h>
61174 +#include <linux/grsecurity.h>
61175 +#include <linux/grinternal.h>
61176 +
61177 +int
61178 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61179 + const time_t shm_createtime, const uid_t cuid, const int shmid)
61180 +{
61181 + struct task_struct *task;
61182 +
61183 + if (!gr_acl_is_enabled())
61184 + return 1;
61185 +
61186 + rcu_read_lock();
61187 + read_lock(&tasklist_lock);
61188 +
61189 + task = find_task_by_vpid(shm_cprid);
61190 +
61191 + if (unlikely(!task))
61192 + task = find_task_by_vpid(shm_lapid);
61193 +
61194 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
61195 + (task->pid == shm_lapid)) &&
61196 + (task->acl->mode & GR_PROTSHM) &&
61197 + (task->acl != current->acl))) {
61198 + read_unlock(&tasklist_lock);
61199 + rcu_read_unlock();
61200 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
61201 + return 0;
61202 + }
61203 + read_unlock(&tasklist_lock);
61204 + rcu_read_unlock();
61205 +
61206 + return 1;
61207 +}
61208 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
61209 new file mode 100644
61210 index 0000000..bc0be01
61211 --- /dev/null
61212 +++ b/grsecurity/grsec_chdir.c
61213 @@ -0,0 +1,19 @@
61214 +#include <linux/kernel.h>
61215 +#include <linux/sched.h>
61216 +#include <linux/fs.h>
61217 +#include <linux/file.h>
61218 +#include <linux/grsecurity.h>
61219 +#include <linux/grinternal.h>
61220 +
61221 +void
61222 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
61223 +{
61224 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61225 + if ((grsec_enable_chdir && grsec_enable_group &&
61226 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
61227 + !grsec_enable_group)) {
61228 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
61229 + }
61230 +#endif
61231 + return;
61232 +}
61233 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
61234 new file mode 100644
61235 index 0000000..197bdd5
61236 --- /dev/null
61237 +++ b/grsecurity/grsec_chroot.c
61238 @@ -0,0 +1,386 @@
61239 +#include <linux/kernel.h>
61240 +#include <linux/module.h>
61241 +#include <linux/sched.h>
61242 +#include <linux/file.h>
61243 +#include <linux/fs.h>
61244 +#include <linux/mount.h>
61245 +#include <linux/types.h>
61246 +#include <linux/pid_namespace.h>
61247 +#include <linux/grsecurity.h>
61248 +#include <linux/grinternal.h>
61249 +
61250 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
61251 +{
61252 +#ifdef CONFIG_GRKERNSEC
61253 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
61254 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
61255 + task->gr_is_chrooted = 1;
61256 + else
61257 + task->gr_is_chrooted = 0;
61258 +
61259 + task->gr_chroot_dentry = path->dentry;
61260 +#endif
61261 + return;
61262 +}
61263 +
61264 +void gr_clear_chroot_entries(struct task_struct *task)
61265 +{
61266 +#ifdef CONFIG_GRKERNSEC
61267 + task->gr_is_chrooted = 0;
61268 + task->gr_chroot_dentry = NULL;
61269 +#endif
61270 + return;
61271 +}
61272 +
61273 +int
61274 +gr_handle_chroot_unix(const pid_t pid)
61275 +{
61276 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61277 + struct task_struct *p;
61278 +
61279 + if (unlikely(!grsec_enable_chroot_unix))
61280 + return 1;
61281 +
61282 + if (likely(!proc_is_chrooted(current)))
61283 + return 1;
61284 +
61285 + rcu_read_lock();
61286 + read_lock(&tasklist_lock);
61287 +
61288 + p = find_task_by_vpid_unrestricted(pid);
61289 + if (unlikely(p && !have_same_root(current, p))) {
61290 + read_unlock(&tasklist_lock);
61291 + rcu_read_unlock();
61292 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
61293 + return 0;
61294 + }
61295 + read_unlock(&tasklist_lock);
61296 + rcu_read_unlock();
61297 +#endif
61298 + return 1;
61299 +}
61300 +
61301 +int
61302 +gr_handle_chroot_nice(void)
61303 +{
61304 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61305 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
61306 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
61307 + return -EPERM;
61308 + }
61309 +#endif
61310 + return 0;
61311 +}
61312 +
61313 +int
61314 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
61315 +{
61316 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61317 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
61318 + && proc_is_chrooted(current)) {
61319 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
61320 + return -EACCES;
61321 + }
61322 +#endif
61323 + return 0;
61324 +}
61325 +
61326 +int
61327 +gr_handle_chroot_rawio(const struct inode *inode)
61328 +{
61329 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61330 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
61331 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
61332 + return 1;
61333 +#endif
61334 + return 0;
61335 +}
61336 +
61337 +int
61338 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
61339 +{
61340 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61341 + struct task_struct *p;
61342 + int ret = 0;
61343 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
61344 + return ret;
61345 +
61346 + read_lock(&tasklist_lock);
61347 + do_each_pid_task(pid, type, p) {
61348 + if (!have_same_root(current, p)) {
61349 + ret = 1;
61350 + goto out;
61351 + }
61352 + } while_each_pid_task(pid, type, p);
61353 +out:
61354 + read_unlock(&tasklist_lock);
61355 + return ret;
61356 +#endif
61357 + return 0;
61358 +}
61359 +
61360 +int
61361 +gr_pid_is_chrooted(struct task_struct *p)
61362 +{
61363 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61364 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
61365 + return 0;
61366 +
61367 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
61368 + !have_same_root(current, p)) {
61369 + return 1;
61370 + }
61371 +#endif
61372 + return 0;
61373 +}
61374 +
61375 +EXPORT_SYMBOL(gr_pid_is_chrooted);
61376 +
61377 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
61378 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
61379 +{
61380 + struct dentry *dentry = (struct dentry *)u_dentry;
61381 + struct vfsmount *mnt = (struct vfsmount *)u_mnt;
61382 + struct dentry *realroot;
61383 + struct vfsmount *realrootmnt;
61384 + struct dentry *currentroot;
61385 + struct vfsmount *currentmnt;
61386 + struct task_struct *reaper = &init_task;
61387 + int ret = 1;
61388 +
61389 + read_lock(&reaper->fs->lock);
61390 + realrootmnt = mntget(reaper->fs->root.mnt);
61391 + realroot = dget(reaper->fs->root.dentry);
61392 + read_unlock(&reaper->fs->lock);
61393 +
61394 + read_lock(&current->fs->lock);
61395 + currentmnt = mntget(current->fs->root.mnt);
61396 + currentroot = dget(current->fs->root.dentry);
61397 + read_unlock(&current->fs->lock);
61398 +
61399 + spin_lock(&dcache_lock);
61400 + for (;;) {
61401 + if (unlikely((dentry == realroot && mnt == realrootmnt)
61402 + || (dentry == currentroot && mnt == currentmnt)))
61403 + break;
61404 + if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
61405 + if (mnt->mnt_parent == mnt)
61406 + break;
61407 + dentry = mnt->mnt_mountpoint;
61408 + mnt = mnt->mnt_parent;
61409 + continue;
61410 + }
61411 + dentry = dentry->d_parent;
61412 + }
61413 + spin_unlock(&dcache_lock);
61414 +
61415 + dput(currentroot);
61416 + mntput(currentmnt);
61417 +
61418 + /* access is outside of chroot */
61419 + if (dentry == realroot && mnt == realrootmnt)
61420 + ret = 0;
61421 +
61422 + dput(realroot);
61423 + mntput(realrootmnt);
61424 + return ret;
61425 +}
61426 +#endif
61427 +
61428 +int
61429 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
61430 +{
61431 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61432 + if (!grsec_enable_chroot_fchdir)
61433 + return 1;
61434 +
61435 + if (!proc_is_chrooted(current))
61436 + return 1;
61437 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
61438 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
61439 + return 0;
61440 + }
61441 +#endif
61442 + return 1;
61443 +}
61444 +
61445 +int
61446 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61447 + const time_t shm_createtime)
61448 +{
61449 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61450 + struct task_struct *p;
61451 + time_t starttime;
61452 +
61453 + if (unlikely(!grsec_enable_chroot_shmat))
61454 + return 1;
61455 +
61456 + if (likely(!proc_is_chrooted(current)))
61457 + return 1;
61458 +
61459 + rcu_read_lock();
61460 + read_lock(&tasklist_lock);
61461 +
61462 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
61463 + starttime = p->start_time.tv_sec;
61464 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
61465 + if (have_same_root(current, p)) {
61466 + goto allow;
61467 + } else {
61468 + read_unlock(&tasklist_lock);
61469 + rcu_read_unlock();
61470 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61471 + return 0;
61472 + }
61473 + }
61474 + /* creator exited, pid reuse, fall through to next check */
61475 + }
61476 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
61477 + if (unlikely(!have_same_root(current, p))) {
61478 + read_unlock(&tasklist_lock);
61479 + rcu_read_unlock();
61480 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61481 + return 0;
61482 + }
61483 + }
61484 +
61485 +allow:
61486 + read_unlock(&tasklist_lock);
61487 + rcu_read_unlock();
61488 +#endif
61489 + return 1;
61490 +}
61491 +
61492 +void
61493 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
61494 +{
61495 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61496 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
61497 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
61498 +#endif
61499 + return;
61500 +}
61501 +
61502 +int
61503 +gr_handle_chroot_mknod(const struct dentry *dentry,
61504 + const struct vfsmount *mnt, const int mode)
61505 +{
61506 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61507 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
61508 + proc_is_chrooted(current)) {
61509 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
61510 + return -EPERM;
61511 + }
61512 +#endif
61513 + return 0;
61514 +}
61515 +
61516 +int
61517 +gr_handle_chroot_mount(const struct dentry *dentry,
61518 + const struct vfsmount *mnt, const char *dev_name)
61519 +{
61520 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61521 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
61522 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
61523 + return -EPERM;
61524 + }
61525 +#endif
61526 + return 0;
61527 +}
61528 +
61529 +int
61530 +gr_handle_chroot_pivot(void)
61531 +{
61532 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61533 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
61534 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
61535 + return -EPERM;
61536 + }
61537 +#endif
61538 + return 0;
61539 +}
61540 +
61541 +int
61542 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
61543 +{
61544 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61545 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
61546 + !gr_is_outside_chroot(dentry, mnt)) {
61547 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
61548 + return -EPERM;
61549 + }
61550 +#endif
61551 + return 0;
61552 +}
61553 +
61554 +extern const char *captab_log[];
61555 +extern int captab_log_entries;
61556 +
61557 +int
61558 +gr_chroot_is_capable(const int cap)
61559 +{
61560 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61561 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61562 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61563 + if (cap_raised(chroot_caps, cap)) {
61564 + const struct cred *creds = current_cred();
61565 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
61566 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
61567 + }
61568 + return 0;
61569 + }
61570 + }
61571 +#endif
61572 + return 1;
61573 +}
61574 +
61575 +int
61576 +gr_chroot_is_capable_nolog(const int cap)
61577 +{
61578 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61579 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61580 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61581 + if (cap_raised(chroot_caps, cap)) {
61582 + return 0;
61583 + }
61584 + }
61585 +#endif
61586 + return 1;
61587 +}
61588 +
61589 +int
61590 +gr_handle_chroot_sysctl(const int op)
61591 +{
61592 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61593 + if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
61594 + && (op & MAY_WRITE))
61595 + return -EACCES;
61596 +#endif
61597 + return 0;
61598 +}
61599 +
61600 +void
61601 +gr_handle_chroot_chdir(struct path *path)
61602 +{
61603 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61604 + if (grsec_enable_chroot_chdir)
61605 + set_fs_pwd(current->fs, path);
61606 +#endif
61607 + return;
61608 +}
61609 +
61610 +int
61611 +gr_handle_chroot_chmod(const struct dentry *dentry,
61612 + const struct vfsmount *mnt, const int mode)
61613 +{
61614 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61615 + /* allow chmod +s on directories, but not on files */
61616 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
61617 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
61618 + proc_is_chrooted(current)) {
61619 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
61620 + return -EPERM;
61621 + }
61622 +#endif
61623 + return 0;
61624 +}
61625 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
61626 new file mode 100644
61627 index 0000000..b81db5b
61628 --- /dev/null
61629 +++ b/grsecurity/grsec_disabled.c
61630 @@ -0,0 +1,439 @@
61631 +#include <linux/kernel.h>
61632 +#include <linux/module.h>
61633 +#include <linux/sched.h>
61634 +#include <linux/file.h>
61635 +#include <linux/fs.h>
61636 +#include <linux/kdev_t.h>
61637 +#include <linux/net.h>
61638 +#include <linux/in.h>
61639 +#include <linux/ip.h>
61640 +#include <linux/skbuff.h>
61641 +#include <linux/sysctl.h>
61642 +
61643 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61644 +void
61645 +pax_set_initial_flags(struct linux_binprm *bprm)
61646 +{
61647 + return;
61648 +}
61649 +#endif
61650 +
61651 +#ifdef CONFIG_SYSCTL
61652 +__u32
61653 +gr_handle_sysctl(const struct ctl_table * table, const int op)
61654 +{
61655 + return 0;
61656 +}
61657 +#endif
61658 +
61659 +#ifdef CONFIG_TASKSTATS
61660 +int gr_is_taskstats_denied(int pid)
61661 +{
61662 + return 0;
61663 +}
61664 +#endif
61665 +
61666 +int
61667 +gr_acl_is_enabled(void)
61668 +{
61669 + return 0;
61670 +}
61671 +
61672 +void
61673 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61674 +{
61675 + return;
61676 +}
61677 +
61678 +int
61679 +gr_handle_rawio(const struct inode *inode)
61680 +{
61681 + return 0;
61682 +}
61683 +
61684 +void
61685 +gr_acl_handle_psacct(struct task_struct *task, const long code)
61686 +{
61687 + return;
61688 +}
61689 +
61690 +int
61691 +gr_handle_ptrace(struct task_struct *task, const long request)
61692 +{
61693 + return 0;
61694 +}
61695 +
61696 +int
61697 +gr_handle_proc_ptrace(struct task_struct *task)
61698 +{
61699 + return 0;
61700 +}
61701 +
61702 +void
61703 +gr_learn_resource(const struct task_struct *task,
61704 + const int res, const unsigned long wanted, const int gt)
61705 +{
61706 + return;
61707 +}
61708 +
61709 +int
61710 +gr_set_acls(const int type)
61711 +{
61712 + return 0;
61713 +}
61714 +
61715 +int
61716 +gr_check_hidden_task(const struct task_struct *tsk)
61717 +{
61718 + return 0;
61719 +}
61720 +
61721 +int
61722 +gr_check_protected_task(const struct task_struct *task)
61723 +{
61724 + return 0;
61725 +}
61726 +
61727 +int
61728 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
61729 +{
61730 + return 0;
61731 +}
61732 +
61733 +void
61734 +gr_copy_label(struct task_struct *tsk)
61735 +{
61736 + return;
61737 +}
61738 +
61739 +void
61740 +gr_set_pax_flags(struct task_struct *task)
61741 +{
61742 + return;
61743 +}
61744 +
61745 +int
61746 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
61747 + const int unsafe_share)
61748 +{
61749 + return 0;
61750 +}
61751 +
61752 +void
61753 +gr_handle_delete(const ino_t ino, const dev_t dev)
61754 +{
61755 + return;
61756 +}
61757 +
61758 +void
61759 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61760 +{
61761 + return;
61762 +}
61763 +
61764 +void
61765 +gr_handle_crash(struct task_struct *task, const int sig)
61766 +{
61767 + return;
61768 +}
61769 +
61770 +int
61771 +gr_check_crash_exec(const struct file *filp)
61772 +{
61773 + return 0;
61774 +}
61775 +
61776 +int
61777 +gr_check_crash_uid(const uid_t uid)
61778 +{
61779 + return 0;
61780 +}
61781 +
61782 +void
61783 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61784 + struct dentry *old_dentry,
61785 + struct dentry *new_dentry,
61786 + struct vfsmount *mnt, const __u8 replace)
61787 +{
61788 + return;
61789 +}
61790 +
61791 +int
61792 +gr_search_socket(const int family, const int type, const int protocol)
61793 +{
61794 + return 1;
61795 +}
61796 +
61797 +int
61798 +gr_search_connectbind(const int mode, const struct socket *sock,
61799 + const struct sockaddr_in *addr)
61800 +{
61801 + return 0;
61802 +}
61803 +
61804 +void
61805 +gr_handle_alertkill(struct task_struct *task)
61806 +{
61807 + return;
61808 +}
61809 +
61810 +__u32
61811 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
61812 +{
61813 + return 1;
61814 +}
61815 +
61816 +__u32
61817 +gr_acl_handle_hidden_file(const struct dentry * dentry,
61818 + const struct vfsmount * mnt)
61819 +{
61820 + return 1;
61821 +}
61822 +
61823 +__u32
61824 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61825 + int acc_mode)
61826 +{
61827 + return 1;
61828 +}
61829 +
61830 +__u32
61831 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61832 +{
61833 + return 1;
61834 +}
61835 +
61836 +__u32
61837 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
61838 +{
61839 + return 1;
61840 +}
61841 +
61842 +int
61843 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
61844 + unsigned int *vm_flags)
61845 +{
61846 + return 1;
61847 +}
61848 +
61849 +__u32
61850 +gr_acl_handle_truncate(const struct dentry * dentry,
61851 + const struct vfsmount * mnt)
61852 +{
61853 + return 1;
61854 +}
61855 +
61856 +__u32
61857 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
61858 +{
61859 + return 1;
61860 +}
61861 +
61862 +__u32
61863 +gr_acl_handle_access(const struct dentry * dentry,
61864 + const struct vfsmount * mnt, const int fmode)
61865 +{
61866 + return 1;
61867 +}
61868 +
61869 +__u32
61870 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
61871 + mode_t mode)
61872 +{
61873 + return 1;
61874 +}
61875 +
61876 +__u32
61877 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
61878 + mode_t mode)
61879 +{
61880 + return 1;
61881 +}
61882 +
61883 +__u32
61884 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
61885 +{
61886 + return 1;
61887 +}
61888 +
61889 +__u32
61890 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
61891 +{
61892 + return 1;
61893 +}
61894 +
61895 +void
61896 +grsecurity_init(void)
61897 +{
61898 + return;
61899 +}
61900 +
61901 +__u32
61902 +gr_acl_handle_mknod(const struct dentry * new_dentry,
61903 + const struct dentry * parent_dentry,
61904 + const struct vfsmount * parent_mnt,
61905 + const int mode)
61906 +{
61907 + return 1;
61908 +}
61909 +
61910 +__u32
61911 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
61912 + const struct dentry * parent_dentry,
61913 + const struct vfsmount * parent_mnt)
61914 +{
61915 + return 1;
61916 +}
61917 +
61918 +__u32
61919 +gr_acl_handle_symlink(const struct dentry * new_dentry,
61920 + const struct dentry * parent_dentry,
61921 + const struct vfsmount * parent_mnt, const char *from)
61922 +{
61923 + return 1;
61924 +}
61925 +
61926 +__u32
61927 +gr_acl_handle_link(const struct dentry * new_dentry,
61928 + const struct dentry * parent_dentry,
61929 + const struct vfsmount * parent_mnt,
61930 + const struct dentry * old_dentry,
61931 + const struct vfsmount * old_mnt, const char *to)
61932 +{
61933 + return 1;
61934 +}
61935 +
61936 +int
61937 +gr_acl_handle_rename(const struct dentry *new_dentry,
61938 + const struct dentry *parent_dentry,
61939 + const struct vfsmount *parent_mnt,
61940 + const struct dentry *old_dentry,
61941 + const struct inode *old_parent_inode,
61942 + const struct vfsmount *old_mnt, const char *newname)
61943 +{
61944 + return 0;
61945 +}
61946 +
61947 +int
61948 +gr_acl_handle_filldir(const struct file *file, const char *name,
61949 + const int namelen, const ino_t ino)
61950 +{
61951 + return 1;
61952 +}
61953 +
61954 +int
61955 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61956 + const time_t shm_createtime, const uid_t cuid, const int shmid)
61957 +{
61958 + return 1;
61959 +}
61960 +
61961 +int
61962 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
61963 +{
61964 + return 0;
61965 +}
61966 +
61967 +int
61968 +gr_search_accept(const struct socket *sock)
61969 +{
61970 + return 0;
61971 +}
61972 +
61973 +int
61974 +gr_search_listen(const struct socket *sock)
61975 +{
61976 + return 0;
61977 +}
61978 +
61979 +int
61980 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
61981 +{
61982 + return 0;
61983 +}
61984 +
61985 +__u32
61986 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
61987 +{
61988 + return 1;
61989 +}
61990 +
61991 +__u32
61992 +gr_acl_handle_creat(const struct dentry * dentry,
61993 + const struct dentry * p_dentry,
61994 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61995 + const int imode)
61996 +{
61997 + return 1;
61998 +}
61999 +
62000 +void
62001 +gr_acl_handle_exit(void)
62002 +{
62003 + return;
62004 +}
62005 +
62006 +int
62007 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62008 +{
62009 + return 1;
62010 +}
62011 +
62012 +void
62013 +gr_set_role_label(const uid_t uid, const gid_t gid)
62014 +{
62015 + return;
62016 +}
62017 +
62018 +int
62019 +gr_acl_handle_procpidmem(const struct task_struct *task)
62020 +{
62021 + return 0;
62022 +}
62023 +
62024 +int
62025 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
62026 +{
62027 + return 0;
62028 +}
62029 +
62030 +int
62031 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
62032 +{
62033 + return 0;
62034 +}
62035 +
62036 +void
62037 +gr_set_kernel_label(struct task_struct *task)
62038 +{
62039 + return;
62040 +}
62041 +
62042 +int
62043 +gr_check_user_change(int real, int effective, int fs)
62044 +{
62045 + return 0;
62046 +}
62047 +
62048 +int
62049 +gr_check_group_change(int real, int effective, int fs)
62050 +{
62051 + return 0;
62052 +}
62053 +
62054 +int gr_acl_enable_at_secure(void)
62055 +{
62056 + return 0;
62057 +}
62058 +
62059 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62060 +{
62061 + return dentry->d_inode->i_sb->s_dev;
62062 +}
62063 +
62064 +EXPORT_SYMBOL(gr_learn_resource);
62065 +EXPORT_SYMBOL(gr_set_kernel_label);
62066 +#ifdef CONFIG_SECURITY
62067 +EXPORT_SYMBOL(gr_check_user_change);
62068 +EXPORT_SYMBOL(gr_check_group_change);
62069 +#endif
62070 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
62071 new file mode 100644
62072 index 0000000..a96e155
62073 --- /dev/null
62074 +++ b/grsecurity/grsec_exec.c
62075 @@ -0,0 +1,204 @@
62076 +#include <linux/kernel.h>
62077 +#include <linux/sched.h>
62078 +#include <linux/file.h>
62079 +#include <linux/binfmts.h>
62080 +#include <linux/smp_lock.h>
62081 +#include <linux/fs.h>
62082 +#include <linux/types.h>
62083 +#include <linux/grdefs.h>
62084 +#include <linux/grinternal.h>
62085 +#include <linux/capability.h>
62086 +#include <linux/compat.h>
62087 +#include <linux/module.h>
62088 +
62089 +#include <asm/uaccess.h>
62090 +
62091 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62092 +static char gr_exec_arg_buf[132];
62093 +static DEFINE_MUTEX(gr_exec_arg_mutex);
62094 +#endif
62095 +
62096 +void
62097 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
62098 +{
62099 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62100 + char *grarg = gr_exec_arg_buf;
62101 + unsigned int i, x, execlen = 0;
62102 + char c;
62103 +
62104 + if (!((grsec_enable_execlog && grsec_enable_group &&
62105 + in_group_p(grsec_audit_gid))
62106 + || (grsec_enable_execlog && !grsec_enable_group)))
62107 + return;
62108 +
62109 + mutex_lock(&gr_exec_arg_mutex);
62110 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
62111 +
62112 + if (unlikely(argv == NULL))
62113 + goto log;
62114 +
62115 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
62116 + const char __user *p;
62117 + unsigned int len;
62118 +
62119 + if (copy_from_user(&p, argv + i, sizeof(p)))
62120 + goto log;
62121 + if (!p)
62122 + goto log;
62123 + len = strnlen_user(p, 128 - execlen);
62124 + if (len > 128 - execlen)
62125 + len = 128 - execlen;
62126 + else if (len > 0)
62127 + len--;
62128 + if (copy_from_user(grarg + execlen, p, len))
62129 + goto log;
62130 +
62131 + /* rewrite unprintable characters */
62132 + for (x = 0; x < len; x++) {
62133 + c = *(grarg + execlen + x);
62134 + if (c < 32 || c > 126)
62135 + *(grarg + execlen + x) = ' ';
62136 + }
62137 +
62138 + execlen += len;
62139 + *(grarg + execlen) = ' ';
62140 + *(grarg + execlen + 1) = '\0';
62141 + execlen++;
62142 + }
62143 +
62144 + log:
62145 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62146 + bprm->file->f_path.mnt, grarg);
62147 + mutex_unlock(&gr_exec_arg_mutex);
62148 +#endif
62149 + return;
62150 +}
62151 +
62152 +#ifdef CONFIG_COMPAT
62153 +void
62154 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
62155 +{
62156 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62157 + char *grarg = gr_exec_arg_buf;
62158 + unsigned int i, x, execlen = 0;
62159 + char c;
62160 +
62161 + if (!((grsec_enable_execlog && grsec_enable_group &&
62162 + in_group_p(grsec_audit_gid))
62163 + || (grsec_enable_execlog && !grsec_enable_group)))
62164 + return;
62165 +
62166 + mutex_lock(&gr_exec_arg_mutex);
62167 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
62168 +
62169 + if (unlikely(argv == NULL))
62170 + goto log;
62171 +
62172 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
62173 + compat_uptr_t p;
62174 + unsigned int len;
62175 +
62176 + if (get_user(p, argv + i))
62177 + goto log;
62178 + len = strnlen_user(compat_ptr(p), 128 - execlen);
62179 + if (len > 128 - execlen)
62180 + len = 128 - execlen;
62181 + else if (len > 0)
62182 + len--;
62183 + else
62184 + goto log;
62185 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
62186 + goto log;
62187 +
62188 + /* rewrite unprintable characters */
62189 + for (x = 0; x < len; x++) {
62190 + c = *(grarg + execlen + x);
62191 + if (c < 32 || c > 126)
62192 + *(grarg + execlen + x) = ' ';
62193 + }
62194 +
62195 + execlen += len;
62196 + *(grarg + execlen) = ' ';
62197 + *(grarg + execlen + 1) = '\0';
62198 + execlen++;
62199 + }
62200 +
62201 + log:
62202 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62203 + bprm->file->f_path.mnt, grarg);
62204 + mutex_unlock(&gr_exec_arg_mutex);
62205 +#endif
62206 + return;
62207 +}
62208 +#endif
62209 +
62210 +#ifdef CONFIG_GRKERNSEC
62211 +extern int gr_acl_is_capable(const int cap);
62212 +extern int gr_acl_is_capable_nolog(const int cap);
62213 +extern int gr_chroot_is_capable(const int cap);
62214 +extern int gr_chroot_is_capable_nolog(const int cap);
62215 +#endif
62216 +
62217 +const char *captab_log[] = {
62218 + "CAP_CHOWN",
62219 + "CAP_DAC_OVERRIDE",
62220 + "CAP_DAC_READ_SEARCH",
62221 + "CAP_FOWNER",
62222 + "CAP_FSETID",
62223 + "CAP_KILL",
62224 + "CAP_SETGID",
62225 + "CAP_SETUID",
62226 + "CAP_SETPCAP",
62227 + "CAP_LINUX_IMMUTABLE",
62228 + "CAP_NET_BIND_SERVICE",
62229 + "CAP_NET_BROADCAST",
62230 + "CAP_NET_ADMIN",
62231 + "CAP_NET_RAW",
62232 + "CAP_IPC_LOCK",
62233 + "CAP_IPC_OWNER",
62234 + "CAP_SYS_MODULE",
62235 + "CAP_SYS_RAWIO",
62236 + "CAP_SYS_CHROOT",
62237 + "CAP_SYS_PTRACE",
62238 + "CAP_SYS_PACCT",
62239 + "CAP_SYS_ADMIN",
62240 + "CAP_SYS_BOOT",
62241 + "CAP_SYS_NICE",
62242 + "CAP_SYS_RESOURCE",
62243 + "CAP_SYS_TIME",
62244 + "CAP_SYS_TTY_CONFIG",
62245 + "CAP_MKNOD",
62246 + "CAP_LEASE",
62247 + "CAP_AUDIT_WRITE",
62248 + "CAP_AUDIT_CONTROL",
62249 + "CAP_SETFCAP",
62250 + "CAP_MAC_OVERRIDE",
62251 + "CAP_MAC_ADMIN"
62252 +};
62253 +
62254 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
62255 +
62256 +int gr_is_capable(const int cap)
62257 +{
62258 +#ifdef CONFIG_GRKERNSEC
62259 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
62260 + return 1;
62261 + return 0;
62262 +#else
62263 + return 1;
62264 +#endif
62265 +}
62266 +
62267 +int gr_is_capable_nolog(const int cap)
62268 +{
62269 +#ifdef CONFIG_GRKERNSEC
62270 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
62271 + return 1;
62272 + return 0;
62273 +#else
62274 + return 1;
62275 +#endif
62276 +}
62277 +
62278 +EXPORT_SYMBOL(gr_is_capable);
62279 +EXPORT_SYMBOL(gr_is_capable_nolog);
62280 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
62281 new file mode 100644
62282 index 0000000..d3ee748
62283 --- /dev/null
62284 +++ b/grsecurity/grsec_fifo.c
62285 @@ -0,0 +1,24 @@
62286 +#include <linux/kernel.h>
62287 +#include <linux/sched.h>
62288 +#include <linux/fs.h>
62289 +#include <linux/file.h>
62290 +#include <linux/grinternal.h>
62291 +
62292 +int
62293 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
62294 + const struct dentry *dir, const int flag, const int acc_mode)
62295 +{
62296 +#ifdef CONFIG_GRKERNSEC_FIFO
62297 + const struct cred *cred = current_cred();
62298 +
62299 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
62300 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
62301 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
62302 + (cred->fsuid != dentry->d_inode->i_uid)) {
62303 + if (!inode_permission(dentry->d_inode, acc_mode))
62304 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
62305 + return -EACCES;
62306 + }
62307 +#endif
62308 + return 0;
62309 +}
62310 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
62311 new file mode 100644
62312 index 0000000..8ca18bf
62313 --- /dev/null
62314 +++ b/grsecurity/grsec_fork.c
62315 @@ -0,0 +1,23 @@
62316 +#include <linux/kernel.h>
62317 +#include <linux/sched.h>
62318 +#include <linux/grsecurity.h>
62319 +#include <linux/grinternal.h>
62320 +#include <linux/errno.h>
62321 +
62322 +void
62323 +gr_log_forkfail(const int retval)
62324 +{
62325 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
62326 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
62327 + switch (retval) {
62328 + case -EAGAIN:
62329 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
62330 + break;
62331 + case -ENOMEM:
62332 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
62333 + break;
62334 + }
62335 + }
62336 +#endif
62337 + return;
62338 +}
62339 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
62340 new file mode 100644
62341 index 0000000..f813c26
62342 --- /dev/null
62343 +++ b/grsecurity/grsec_init.c
62344 @@ -0,0 +1,270 @@
62345 +#include <linux/kernel.h>
62346 +#include <linux/sched.h>
62347 +#include <linux/mm.h>
62348 +#include <linux/smp_lock.h>
62349 +#include <linux/gracl.h>
62350 +#include <linux/slab.h>
62351 +#include <linux/vmalloc.h>
62352 +#include <linux/percpu.h>
62353 +#include <linux/module.h>
62354 +
62355 +int grsec_enable_brute;
62356 +int grsec_enable_link;
62357 +int grsec_enable_dmesg;
62358 +int grsec_enable_harden_ptrace;
62359 +int grsec_enable_fifo;
62360 +int grsec_enable_execlog;
62361 +int grsec_enable_signal;
62362 +int grsec_enable_forkfail;
62363 +int grsec_enable_audit_ptrace;
62364 +int grsec_enable_time;
62365 +int grsec_enable_audit_textrel;
62366 +int grsec_enable_group;
62367 +int grsec_audit_gid;
62368 +int grsec_enable_chdir;
62369 +int grsec_enable_mount;
62370 +int grsec_enable_rofs;
62371 +int grsec_enable_chroot_findtask;
62372 +int grsec_enable_chroot_mount;
62373 +int grsec_enable_chroot_shmat;
62374 +int grsec_enable_chroot_fchdir;
62375 +int grsec_enable_chroot_double;
62376 +int grsec_enable_chroot_pivot;
62377 +int grsec_enable_chroot_chdir;
62378 +int grsec_enable_chroot_chmod;
62379 +int grsec_enable_chroot_mknod;
62380 +int grsec_enable_chroot_nice;
62381 +int grsec_enable_chroot_execlog;
62382 +int grsec_enable_chroot_caps;
62383 +int grsec_enable_chroot_sysctl;
62384 +int grsec_enable_chroot_unix;
62385 +int grsec_enable_tpe;
62386 +int grsec_tpe_gid;
62387 +int grsec_enable_blackhole;
62388 +#ifdef CONFIG_IPV6_MODULE
62389 +EXPORT_SYMBOL(grsec_enable_blackhole);
62390 +#endif
62391 +int grsec_lastack_retries;
62392 +int grsec_enable_tpe_all;
62393 +int grsec_enable_tpe_invert;
62394 +int grsec_enable_socket_all;
62395 +int grsec_socket_all_gid;
62396 +int grsec_enable_socket_client;
62397 +int grsec_socket_client_gid;
62398 +int grsec_enable_socket_server;
62399 +int grsec_socket_server_gid;
62400 +int grsec_resource_logging;
62401 +int grsec_disable_privio;
62402 +int grsec_enable_log_rwxmaps;
62403 +int grsec_lock;
62404 +
62405 +DEFINE_SPINLOCK(grsec_alert_lock);
62406 +unsigned long grsec_alert_wtime = 0;
62407 +unsigned long grsec_alert_fyet = 0;
62408 +
62409 +DEFINE_SPINLOCK(grsec_audit_lock);
62410 +
62411 +DEFINE_RWLOCK(grsec_exec_file_lock);
62412 +
62413 +char *gr_shared_page[4];
62414 +
62415 +char *gr_alert_log_fmt;
62416 +char *gr_audit_log_fmt;
62417 +char *gr_alert_log_buf;
62418 +char *gr_audit_log_buf;
62419 +
62420 +extern struct gr_arg *gr_usermode;
62421 +extern unsigned char *gr_system_salt;
62422 +extern unsigned char *gr_system_sum;
62423 +
62424 +void __init
62425 +grsecurity_init(void)
62426 +{
62427 + int j;
62428 + /* create the per-cpu shared pages */
62429 +
62430 +#ifdef CONFIG_X86
62431 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
62432 +#endif
62433 +
62434 + for (j = 0; j < 4; j++) {
62435 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
62436 + if (gr_shared_page[j] == NULL) {
62437 + panic("Unable to allocate grsecurity shared page");
62438 + return;
62439 + }
62440 + }
62441 +
62442 + /* allocate log buffers */
62443 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
62444 + if (!gr_alert_log_fmt) {
62445 + panic("Unable to allocate grsecurity alert log format buffer");
62446 + return;
62447 + }
62448 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
62449 + if (!gr_audit_log_fmt) {
62450 + panic("Unable to allocate grsecurity audit log format buffer");
62451 + return;
62452 + }
62453 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62454 + if (!gr_alert_log_buf) {
62455 + panic("Unable to allocate grsecurity alert log buffer");
62456 + return;
62457 + }
62458 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62459 + if (!gr_audit_log_buf) {
62460 + panic("Unable to allocate grsecurity audit log buffer");
62461 + return;
62462 + }
62463 +
62464 + /* allocate memory for authentication structure */
62465 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
62466 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
62467 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
62468 +
62469 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
62470 + panic("Unable to allocate grsecurity authentication structure");
62471 + return;
62472 + }
62473 +
62474 +
62475 +#ifdef CONFIG_GRKERNSEC_IO
62476 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
62477 + grsec_disable_privio = 1;
62478 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62479 + grsec_disable_privio = 1;
62480 +#else
62481 + grsec_disable_privio = 0;
62482 +#endif
62483 +#endif
62484 +
62485 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62486 + /* for backward compatibility, tpe_invert always defaults to on if
62487 + enabled in the kernel
62488 + */
62489 + grsec_enable_tpe_invert = 1;
62490 +#endif
62491 +
62492 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62493 +#ifndef CONFIG_GRKERNSEC_SYSCTL
62494 + grsec_lock = 1;
62495 +#endif
62496 +
62497 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62498 + grsec_enable_audit_textrel = 1;
62499 +#endif
62500 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62501 + grsec_enable_log_rwxmaps = 1;
62502 +#endif
62503 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62504 + grsec_enable_group = 1;
62505 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
62506 +#endif
62507 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62508 + grsec_enable_chdir = 1;
62509 +#endif
62510 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62511 + grsec_enable_harden_ptrace = 1;
62512 +#endif
62513 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62514 + grsec_enable_mount = 1;
62515 +#endif
62516 +#ifdef CONFIG_GRKERNSEC_LINK
62517 + grsec_enable_link = 1;
62518 +#endif
62519 +#ifdef CONFIG_GRKERNSEC_BRUTE
62520 + grsec_enable_brute = 1;
62521 +#endif
62522 +#ifdef CONFIG_GRKERNSEC_DMESG
62523 + grsec_enable_dmesg = 1;
62524 +#endif
62525 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62526 + grsec_enable_blackhole = 1;
62527 + grsec_lastack_retries = 4;
62528 +#endif
62529 +#ifdef CONFIG_GRKERNSEC_FIFO
62530 + grsec_enable_fifo = 1;
62531 +#endif
62532 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62533 + grsec_enable_execlog = 1;
62534 +#endif
62535 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62536 + grsec_enable_signal = 1;
62537 +#endif
62538 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
62539 + grsec_enable_forkfail = 1;
62540 +#endif
62541 +#ifdef CONFIG_GRKERNSEC_TIME
62542 + grsec_enable_time = 1;
62543 +#endif
62544 +#ifdef CONFIG_GRKERNSEC_RESLOG
62545 + grsec_resource_logging = 1;
62546 +#endif
62547 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62548 + grsec_enable_chroot_findtask = 1;
62549 +#endif
62550 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62551 + grsec_enable_chroot_unix = 1;
62552 +#endif
62553 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62554 + grsec_enable_chroot_mount = 1;
62555 +#endif
62556 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62557 + grsec_enable_chroot_fchdir = 1;
62558 +#endif
62559 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62560 + grsec_enable_chroot_shmat = 1;
62561 +#endif
62562 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62563 + grsec_enable_audit_ptrace = 1;
62564 +#endif
62565 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62566 + grsec_enable_chroot_double = 1;
62567 +#endif
62568 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62569 + grsec_enable_chroot_pivot = 1;
62570 +#endif
62571 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62572 + grsec_enable_chroot_chdir = 1;
62573 +#endif
62574 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62575 + grsec_enable_chroot_chmod = 1;
62576 +#endif
62577 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62578 + grsec_enable_chroot_mknod = 1;
62579 +#endif
62580 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62581 + grsec_enable_chroot_nice = 1;
62582 +#endif
62583 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62584 + grsec_enable_chroot_execlog = 1;
62585 +#endif
62586 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62587 + grsec_enable_chroot_caps = 1;
62588 +#endif
62589 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62590 + grsec_enable_chroot_sysctl = 1;
62591 +#endif
62592 +#ifdef CONFIG_GRKERNSEC_TPE
62593 + grsec_enable_tpe = 1;
62594 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
62595 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62596 + grsec_enable_tpe_all = 1;
62597 +#endif
62598 +#endif
62599 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62600 + grsec_enable_socket_all = 1;
62601 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
62602 +#endif
62603 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62604 + grsec_enable_socket_client = 1;
62605 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
62606 +#endif
62607 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62608 + grsec_enable_socket_server = 1;
62609 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
62610 +#endif
62611 +#endif
62612 +
62613 + return;
62614 +}
62615 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
62616 new file mode 100644
62617 index 0000000..3efe141
62618 --- /dev/null
62619 +++ b/grsecurity/grsec_link.c
62620 @@ -0,0 +1,43 @@
62621 +#include <linux/kernel.h>
62622 +#include <linux/sched.h>
62623 +#include <linux/fs.h>
62624 +#include <linux/file.h>
62625 +#include <linux/grinternal.h>
62626 +
62627 +int
62628 +gr_handle_follow_link(const struct inode *parent,
62629 + const struct inode *inode,
62630 + const struct dentry *dentry, const struct vfsmount *mnt)
62631 +{
62632 +#ifdef CONFIG_GRKERNSEC_LINK
62633 + const struct cred *cred = current_cred();
62634 +
62635 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
62636 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
62637 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
62638 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
62639 + return -EACCES;
62640 + }
62641 +#endif
62642 + return 0;
62643 +}
62644 +
62645 +int
62646 +gr_handle_hardlink(const struct dentry *dentry,
62647 + const struct vfsmount *mnt,
62648 + struct inode *inode, const int mode, const char *to)
62649 +{
62650 +#ifdef CONFIG_GRKERNSEC_LINK
62651 + const struct cred *cred = current_cred();
62652 +
62653 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
62654 + (!S_ISREG(mode) || (mode & S_ISUID) ||
62655 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
62656 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
62657 + !capable(CAP_FOWNER) && cred->uid) {
62658 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
62659 + return -EPERM;
62660 + }
62661 +#endif
62662 + return 0;
62663 +}
62664 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
62665 new file mode 100644
62666 index 0000000..a45d2e9
62667 --- /dev/null
62668 +++ b/grsecurity/grsec_log.c
62669 @@ -0,0 +1,322 @@
62670 +#include <linux/kernel.h>
62671 +#include <linux/sched.h>
62672 +#include <linux/file.h>
62673 +#include <linux/tty.h>
62674 +#include <linux/fs.h>
62675 +#include <linux/grinternal.h>
62676 +
62677 +#ifdef CONFIG_TREE_PREEMPT_RCU
62678 +#define DISABLE_PREEMPT() preempt_disable()
62679 +#define ENABLE_PREEMPT() preempt_enable()
62680 +#else
62681 +#define DISABLE_PREEMPT()
62682 +#define ENABLE_PREEMPT()
62683 +#endif
62684 +
62685 +#define BEGIN_LOCKS(x) \
62686 + DISABLE_PREEMPT(); \
62687 + rcu_read_lock(); \
62688 + read_lock(&tasklist_lock); \
62689 + read_lock(&grsec_exec_file_lock); \
62690 + if (x != GR_DO_AUDIT) \
62691 + spin_lock(&grsec_alert_lock); \
62692 + else \
62693 + spin_lock(&grsec_audit_lock)
62694 +
62695 +#define END_LOCKS(x) \
62696 + if (x != GR_DO_AUDIT) \
62697 + spin_unlock(&grsec_alert_lock); \
62698 + else \
62699 + spin_unlock(&grsec_audit_lock); \
62700 + read_unlock(&grsec_exec_file_lock); \
62701 + read_unlock(&tasklist_lock); \
62702 + rcu_read_unlock(); \
62703 + ENABLE_PREEMPT(); \
62704 + if (x == GR_DONT_AUDIT) \
62705 + gr_handle_alertkill(current)
62706 +
62707 +enum {
62708 + FLOODING,
62709 + NO_FLOODING
62710 +};
62711 +
62712 +extern char *gr_alert_log_fmt;
62713 +extern char *gr_audit_log_fmt;
62714 +extern char *gr_alert_log_buf;
62715 +extern char *gr_audit_log_buf;
62716 +
62717 +static int gr_log_start(int audit)
62718 +{
62719 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
62720 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
62721 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62722 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
62723 + unsigned long curr_secs = get_seconds();
62724 +
62725 + if (audit == GR_DO_AUDIT)
62726 + goto set_fmt;
62727 +
62728 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
62729 + grsec_alert_wtime = curr_secs;
62730 + grsec_alert_fyet = 0;
62731 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
62732 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
62733 + grsec_alert_fyet++;
62734 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
62735 + grsec_alert_wtime = curr_secs;
62736 + grsec_alert_fyet++;
62737 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
62738 + return FLOODING;
62739 + }
62740 + else return FLOODING;
62741 +
62742 +set_fmt:
62743 +#endif
62744 + memset(buf, 0, PAGE_SIZE);
62745 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
62746 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
62747 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62748 + } else if (current->signal->curr_ip) {
62749 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
62750 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
62751 + } else if (gr_acl_is_enabled()) {
62752 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
62753 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62754 + } else {
62755 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
62756 + strcpy(buf, fmt);
62757 + }
62758 +
62759 + return NO_FLOODING;
62760 +}
62761 +
62762 +static void gr_log_middle(int audit, const char *msg, va_list ap)
62763 + __attribute__ ((format (printf, 2, 0)));
62764 +
62765 +static void gr_log_middle(int audit, const char *msg, va_list ap)
62766 +{
62767 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62768 + unsigned int len = strlen(buf);
62769 +
62770 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
62771 +
62772 + return;
62773 +}
62774 +
62775 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
62776 + __attribute__ ((format (printf, 2, 3)));
62777 +
62778 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
62779 +{
62780 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62781 + unsigned int len = strlen(buf);
62782 + va_list ap;
62783 +
62784 + va_start(ap, msg);
62785 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
62786 + va_end(ap);
62787 +
62788 + return;
62789 +}
62790 +
62791 +static void gr_log_end(int audit, int append_default)
62792 +{
62793 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62794 +
62795 + if (append_default) {
62796 + unsigned int len = strlen(buf);
62797 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
62798 + }
62799 +
62800 + printk("%s\n", buf);
62801 +
62802 + return;
62803 +}
62804 +
62805 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
62806 +{
62807 + int logtype;
62808 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
62809 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
62810 + void *voidptr = NULL;
62811 + int num1 = 0, num2 = 0;
62812 + unsigned long ulong1 = 0, ulong2 = 0;
62813 + struct dentry *dentry = NULL;
62814 + struct vfsmount *mnt = NULL;
62815 + struct file *file = NULL;
62816 + struct task_struct *task = NULL;
62817 + const struct cred *cred, *pcred;
62818 + va_list ap;
62819 +
62820 + BEGIN_LOCKS(audit);
62821 + logtype = gr_log_start(audit);
62822 + if (logtype == FLOODING) {
62823 + END_LOCKS(audit);
62824 + return;
62825 + }
62826 + va_start(ap, argtypes);
62827 + switch (argtypes) {
62828 + case GR_TTYSNIFF:
62829 + task = va_arg(ap, struct task_struct *);
62830 + 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);
62831 + break;
62832 + case GR_SYSCTL_HIDDEN:
62833 + str1 = va_arg(ap, char *);
62834 + gr_log_middle_varargs(audit, msg, result, str1);
62835 + break;
62836 + case GR_RBAC:
62837 + dentry = va_arg(ap, struct dentry *);
62838 + mnt = va_arg(ap, struct vfsmount *);
62839 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
62840 + break;
62841 + case GR_RBAC_STR:
62842 + dentry = va_arg(ap, struct dentry *);
62843 + mnt = va_arg(ap, struct vfsmount *);
62844 + str1 = va_arg(ap, char *);
62845 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
62846 + break;
62847 + case GR_STR_RBAC:
62848 + str1 = va_arg(ap, char *);
62849 + dentry = va_arg(ap, struct dentry *);
62850 + mnt = va_arg(ap, struct vfsmount *);
62851 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
62852 + break;
62853 + case GR_RBAC_MODE2:
62854 + dentry = va_arg(ap, struct dentry *);
62855 + mnt = va_arg(ap, struct vfsmount *);
62856 + str1 = va_arg(ap, char *);
62857 + str2 = va_arg(ap, char *);
62858 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
62859 + break;
62860 + case GR_RBAC_MODE3:
62861 + dentry = va_arg(ap, struct dentry *);
62862 + mnt = va_arg(ap, struct vfsmount *);
62863 + str1 = va_arg(ap, char *);
62864 + str2 = va_arg(ap, char *);
62865 + str3 = va_arg(ap, char *);
62866 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
62867 + break;
62868 + case GR_FILENAME:
62869 + dentry = va_arg(ap, struct dentry *);
62870 + mnt = va_arg(ap, struct vfsmount *);
62871 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
62872 + break;
62873 + case GR_STR_FILENAME:
62874 + str1 = va_arg(ap, char *);
62875 + dentry = va_arg(ap, struct dentry *);
62876 + mnt = va_arg(ap, struct vfsmount *);
62877 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
62878 + break;
62879 + case GR_FILENAME_STR:
62880 + dentry = va_arg(ap, struct dentry *);
62881 + mnt = va_arg(ap, struct vfsmount *);
62882 + str1 = va_arg(ap, char *);
62883 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
62884 + break;
62885 + case GR_FILENAME_TWO_INT:
62886 + dentry = va_arg(ap, struct dentry *);
62887 + mnt = va_arg(ap, struct vfsmount *);
62888 + num1 = va_arg(ap, int);
62889 + num2 = va_arg(ap, int);
62890 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
62891 + break;
62892 + case GR_FILENAME_TWO_INT_STR:
62893 + dentry = va_arg(ap, struct dentry *);
62894 + mnt = va_arg(ap, struct vfsmount *);
62895 + num1 = va_arg(ap, int);
62896 + num2 = va_arg(ap, int);
62897 + str1 = va_arg(ap, char *);
62898 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
62899 + break;
62900 + case GR_TEXTREL:
62901 + file = va_arg(ap, struct file *);
62902 + ulong1 = va_arg(ap, unsigned long);
62903 + ulong2 = va_arg(ap, unsigned long);
62904 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
62905 + break;
62906 + case GR_PTRACE:
62907 + task = va_arg(ap, struct task_struct *);
62908 + 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);
62909 + break;
62910 + case GR_RESOURCE:
62911 + task = va_arg(ap, struct task_struct *);
62912 + cred = __task_cred(task);
62913 + pcred = __task_cred(task->real_parent);
62914 + ulong1 = va_arg(ap, unsigned long);
62915 + str1 = va_arg(ap, char *);
62916 + ulong2 = va_arg(ap, unsigned long);
62917 + 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);
62918 + break;
62919 + case GR_CAP:
62920 + task = va_arg(ap, struct task_struct *);
62921 + cred = __task_cred(task);
62922 + pcred = __task_cred(task->real_parent);
62923 + str1 = va_arg(ap, char *);
62924 + 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);
62925 + break;
62926 + case GR_SIG:
62927 + str1 = va_arg(ap, char *);
62928 + voidptr = va_arg(ap, void *);
62929 + gr_log_middle_varargs(audit, msg, str1, voidptr);
62930 + break;
62931 + case GR_SIG2:
62932 + task = va_arg(ap, struct task_struct *);
62933 + cred = __task_cred(task);
62934 + pcred = __task_cred(task->real_parent);
62935 + num1 = va_arg(ap, int);
62936 + 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);
62937 + break;
62938 + case GR_CRASH1:
62939 + task = va_arg(ap, struct task_struct *);
62940 + cred = __task_cred(task);
62941 + pcred = __task_cred(task->real_parent);
62942 + ulong1 = va_arg(ap, unsigned long);
62943 + 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);
62944 + break;
62945 + case GR_CRASH2:
62946 + task = va_arg(ap, struct task_struct *);
62947 + cred = __task_cred(task);
62948 + pcred = __task_cred(task->real_parent);
62949 + ulong1 = va_arg(ap, unsigned long);
62950 + 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);
62951 + break;
62952 + case GR_RWXMAP:
62953 + file = va_arg(ap, struct file *);
62954 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
62955 + break;
62956 + case GR_PSACCT:
62957 + {
62958 + unsigned int wday, cday;
62959 + __u8 whr, chr;
62960 + __u8 wmin, cmin;
62961 + __u8 wsec, csec;
62962 + char cur_tty[64] = { 0 };
62963 + char parent_tty[64] = { 0 };
62964 +
62965 + task = va_arg(ap, struct task_struct *);
62966 + wday = va_arg(ap, unsigned int);
62967 + cday = va_arg(ap, unsigned int);
62968 + whr = va_arg(ap, int);
62969 + chr = va_arg(ap, int);
62970 + wmin = va_arg(ap, int);
62971 + cmin = va_arg(ap, int);
62972 + wsec = va_arg(ap, int);
62973 + csec = va_arg(ap, int);
62974 + ulong1 = va_arg(ap, unsigned long);
62975 + cred = __task_cred(task);
62976 + pcred = __task_cred(task->real_parent);
62977 +
62978 + 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);
62979 + }
62980 + break;
62981 + default:
62982 + gr_log_middle(audit, msg, ap);
62983 + }
62984 + va_end(ap);
62985 + // these don't need DEFAULTSECARGS printed on the end
62986 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
62987 + gr_log_end(audit, 0);
62988 + else
62989 + gr_log_end(audit, 1);
62990 + END_LOCKS(audit);
62991 +}
62992 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
62993 new file mode 100644
62994 index 0000000..6c0416b
62995 --- /dev/null
62996 +++ b/grsecurity/grsec_mem.c
62997 @@ -0,0 +1,33 @@
62998 +#include <linux/kernel.h>
62999 +#include <linux/sched.h>
63000 +#include <linux/mm.h>
63001 +#include <linux/mman.h>
63002 +#include <linux/grinternal.h>
63003 +
63004 +void
63005 +gr_handle_ioperm(void)
63006 +{
63007 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
63008 + return;
63009 +}
63010 +
63011 +void
63012 +gr_handle_iopl(void)
63013 +{
63014 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
63015 + return;
63016 +}
63017 +
63018 +void
63019 +gr_handle_mem_readwrite(u64 from, u64 to)
63020 +{
63021 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
63022 + return;
63023 +}
63024 +
63025 +void
63026 +gr_handle_vm86(void)
63027 +{
63028 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
63029 + return;
63030 +}
63031 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
63032 new file mode 100644
63033 index 0000000..2131422
63034 --- /dev/null
63035 +++ b/grsecurity/grsec_mount.c
63036 @@ -0,0 +1,62 @@
63037 +#include <linux/kernel.h>
63038 +#include <linux/sched.h>
63039 +#include <linux/mount.h>
63040 +#include <linux/grsecurity.h>
63041 +#include <linux/grinternal.h>
63042 +
63043 +void
63044 +gr_log_remount(const char *devname, const int retval)
63045 +{
63046 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63047 + if (grsec_enable_mount && (retval >= 0))
63048 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
63049 +#endif
63050 + return;
63051 +}
63052 +
63053 +void
63054 +gr_log_unmount(const char *devname, const int retval)
63055 +{
63056 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63057 + if (grsec_enable_mount && (retval >= 0))
63058 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
63059 +#endif
63060 + return;
63061 +}
63062 +
63063 +void
63064 +gr_log_mount(const char *from, const char *to, const int retval)
63065 +{
63066 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63067 + if (grsec_enable_mount && (retval >= 0))
63068 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
63069 +#endif
63070 + return;
63071 +}
63072 +
63073 +int
63074 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
63075 +{
63076 +#ifdef CONFIG_GRKERNSEC_ROFS
63077 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
63078 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
63079 + return -EPERM;
63080 + } else
63081 + return 0;
63082 +#endif
63083 + return 0;
63084 +}
63085 +
63086 +int
63087 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
63088 +{
63089 +#ifdef CONFIG_GRKERNSEC_ROFS
63090 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
63091 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
63092 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
63093 + return -EPERM;
63094 + } else
63095 + return 0;
63096 +#endif
63097 + return 0;
63098 +}
63099 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
63100 new file mode 100644
63101 index 0000000..a3b12a0
63102 --- /dev/null
63103 +++ b/grsecurity/grsec_pax.c
63104 @@ -0,0 +1,36 @@
63105 +#include <linux/kernel.h>
63106 +#include <linux/sched.h>
63107 +#include <linux/mm.h>
63108 +#include <linux/file.h>
63109 +#include <linux/grinternal.h>
63110 +#include <linux/grsecurity.h>
63111 +
63112 +void
63113 +gr_log_textrel(struct vm_area_struct * vma)
63114 +{
63115 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63116 + if (grsec_enable_audit_textrel)
63117 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
63118 +#endif
63119 + return;
63120 +}
63121 +
63122 +void
63123 +gr_log_rwxmmap(struct file *file)
63124 +{
63125 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63126 + if (grsec_enable_log_rwxmaps)
63127 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
63128 +#endif
63129 + return;
63130 +}
63131 +
63132 +void
63133 +gr_log_rwxmprotect(struct file *file)
63134 +{
63135 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63136 + if (grsec_enable_log_rwxmaps)
63137 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
63138 +#endif
63139 + return;
63140 +}
63141 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
63142 new file mode 100644
63143 index 0000000..472c1d6
63144 --- /dev/null
63145 +++ b/grsecurity/grsec_ptrace.c
63146 @@ -0,0 +1,14 @@
63147 +#include <linux/kernel.h>
63148 +#include <linux/sched.h>
63149 +#include <linux/grinternal.h>
63150 +#include <linux/grsecurity.h>
63151 +
63152 +void
63153 +gr_audit_ptrace(struct task_struct *task)
63154 +{
63155 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63156 + if (grsec_enable_audit_ptrace)
63157 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
63158 +#endif
63159 + return;
63160 +}
63161 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
63162 new file mode 100644
63163 index 0000000..dc73fe9
63164 --- /dev/null
63165 +++ b/grsecurity/grsec_sig.c
63166 @@ -0,0 +1,205 @@
63167 +#include <linux/kernel.h>
63168 +#include <linux/sched.h>
63169 +#include <linux/delay.h>
63170 +#include <linux/grsecurity.h>
63171 +#include <linux/grinternal.h>
63172 +#include <linux/hardirq.h>
63173 +
63174 +char *signames[] = {
63175 + [SIGSEGV] = "Segmentation fault",
63176 + [SIGILL] = "Illegal instruction",
63177 + [SIGABRT] = "Abort",
63178 + [SIGBUS] = "Invalid alignment/Bus error"
63179 +};
63180 +
63181 +void
63182 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
63183 +{
63184 +#ifdef CONFIG_GRKERNSEC_SIGNAL
63185 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
63186 + (sig == SIGABRT) || (sig == SIGBUS))) {
63187 + if (t->pid == current->pid) {
63188 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
63189 + } else {
63190 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
63191 + }
63192 + }
63193 +#endif
63194 + return;
63195 +}
63196 +
63197 +int
63198 +gr_handle_signal(const struct task_struct *p, const int sig)
63199 +{
63200 +#ifdef CONFIG_GRKERNSEC
63201 + if (current->pid > 1 && gr_check_protected_task(p)) {
63202 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
63203 + return -EPERM;
63204 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
63205 + return -EPERM;
63206 + }
63207 +#endif
63208 + return 0;
63209 +}
63210 +
63211 +#ifdef CONFIG_GRKERNSEC
63212 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
63213 +
63214 +int gr_fake_force_sig(int sig, struct task_struct *t)
63215 +{
63216 + unsigned long int flags;
63217 + int ret, blocked, ignored;
63218 + struct k_sigaction *action;
63219 +
63220 + spin_lock_irqsave(&t->sighand->siglock, flags);
63221 + action = &t->sighand->action[sig-1];
63222 + ignored = action->sa.sa_handler == SIG_IGN;
63223 + blocked = sigismember(&t->blocked, sig);
63224 + if (blocked || ignored) {
63225 + action->sa.sa_handler = SIG_DFL;
63226 + if (blocked) {
63227 + sigdelset(&t->blocked, sig);
63228 + recalc_sigpending_and_wake(t);
63229 + }
63230 + }
63231 + if (action->sa.sa_handler == SIG_DFL)
63232 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
63233 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
63234 +
63235 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
63236 +
63237 + return ret;
63238 +}
63239 +#endif
63240 +
63241 +#ifdef CONFIG_GRKERNSEC_BRUTE
63242 +#define GR_USER_BAN_TIME (15 * 60)
63243 +
63244 +static int __get_dumpable(unsigned long mm_flags)
63245 +{
63246 + int ret;
63247 +
63248 + ret = mm_flags & MMF_DUMPABLE_MASK;
63249 + return (ret >= 2) ? 2 : ret;
63250 +}
63251 +#endif
63252 +
63253 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
63254 +{
63255 +#ifdef CONFIG_GRKERNSEC_BRUTE
63256 + uid_t uid = 0;
63257 +
63258 + if (!grsec_enable_brute)
63259 + return;
63260 +
63261 + rcu_read_lock();
63262 + read_lock(&tasklist_lock);
63263 + read_lock(&grsec_exec_file_lock);
63264 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
63265 + p->real_parent->brute = 1;
63266 + else {
63267 + const struct cred *cred = __task_cred(p), *cred2;
63268 + struct task_struct *tsk, *tsk2;
63269 +
63270 + if (!__get_dumpable(mm_flags) && cred->uid) {
63271 + struct user_struct *user;
63272 +
63273 + uid = cred->uid;
63274 +
63275 + /* this is put upon execution past expiration */
63276 + user = find_user(uid);
63277 + if (user == NULL)
63278 + goto unlock;
63279 + user->banned = 1;
63280 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
63281 + if (user->ban_expires == ~0UL)
63282 + user->ban_expires--;
63283 +
63284 + do_each_thread(tsk2, tsk) {
63285 + cred2 = __task_cred(tsk);
63286 + if (tsk != p && cred2->uid == uid)
63287 + gr_fake_force_sig(SIGKILL, tsk);
63288 + } while_each_thread(tsk2, tsk);
63289 + }
63290 + }
63291 +unlock:
63292 + read_unlock(&grsec_exec_file_lock);
63293 + read_unlock(&tasklist_lock);
63294 + rcu_read_unlock();
63295 +
63296 + if (uid)
63297 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
63298 +#endif
63299 + return;
63300 +}
63301 +
63302 +void gr_handle_brute_check(void)
63303 +{
63304 +#ifdef CONFIG_GRKERNSEC_BRUTE
63305 + if (current->brute)
63306 + msleep(30 * 1000);
63307 +#endif
63308 + return;
63309 +}
63310 +
63311 +void gr_handle_kernel_exploit(void)
63312 +{
63313 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
63314 + const struct cred *cred;
63315 + struct task_struct *tsk, *tsk2;
63316 + struct user_struct *user;
63317 + uid_t uid;
63318 +
63319 + if (in_irq() || in_serving_softirq() || in_nmi())
63320 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
63321 +
63322 + uid = current_uid();
63323 +
63324 + if (uid == 0)
63325 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
63326 + else {
63327 + /* kill all the processes of this user, hold a reference
63328 + to their creds struct, and prevent them from creating
63329 + another process until system reset
63330 + */
63331 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
63332 + /* we intentionally leak this ref */
63333 + user = get_uid(current->cred->user);
63334 + if (user) {
63335 + user->banned = 1;
63336 + user->ban_expires = ~0UL;
63337 + }
63338 +
63339 + read_lock(&tasklist_lock);
63340 + do_each_thread(tsk2, tsk) {
63341 + cred = __task_cred(tsk);
63342 + if (cred->uid == uid)
63343 + gr_fake_force_sig(SIGKILL, tsk);
63344 + } while_each_thread(tsk2, tsk);
63345 + read_unlock(&tasklist_lock);
63346 + }
63347 +#endif
63348 +}
63349 +
63350 +int __gr_process_user_ban(struct user_struct *user)
63351 +{
63352 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63353 + if (unlikely(user->banned)) {
63354 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
63355 + user->banned = 0;
63356 + user->ban_expires = 0;
63357 + free_uid(user);
63358 + } else
63359 + return -EPERM;
63360 + }
63361 +#endif
63362 + return 0;
63363 +}
63364 +
63365 +int gr_process_user_ban(void)
63366 +{
63367 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63368 + return __gr_process_user_ban(current->cred->user);
63369 +#endif
63370 + return 0;
63371 +}
63372 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
63373 new file mode 100644
63374 index 0000000..7512ea9
63375 --- /dev/null
63376 +++ b/grsecurity/grsec_sock.c
63377 @@ -0,0 +1,275 @@
63378 +#include <linux/kernel.h>
63379 +#include <linux/module.h>
63380 +#include <linux/sched.h>
63381 +#include <linux/file.h>
63382 +#include <linux/net.h>
63383 +#include <linux/in.h>
63384 +#include <linux/ip.h>
63385 +#include <net/sock.h>
63386 +#include <net/inet_sock.h>
63387 +#include <linux/grsecurity.h>
63388 +#include <linux/grinternal.h>
63389 +#include <linux/gracl.h>
63390 +
63391 +kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
63392 +EXPORT_SYMBOL(gr_cap_rtnetlink);
63393 +
63394 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
63395 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
63396 +
63397 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
63398 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
63399 +
63400 +#ifdef CONFIG_UNIX_MODULE
63401 +EXPORT_SYMBOL(gr_acl_handle_unix);
63402 +EXPORT_SYMBOL(gr_acl_handle_mknod);
63403 +EXPORT_SYMBOL(gr_handle_chroot_unix);
63404 +EXPORT_SYMBOL(gr_handle_create);
63405 +#endif
63406 +
63407 +#ifdef CONFIG_GRKERNSEC
63408 +#define gr_conn_table_size 32749
63409 +struct conn_table_entry {
63410 + struct conn_table_entry *next;
63411 + struct signal_struct *sig;
63412 +};
63413 +
63414 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
63415 +DEFINE_SPINLOCK(gr_conn_table_lock);
63416 +
63417 +extern const char * gr_socktype_to_name(unsigned char type);
63418 +extern const char * gr_proto_to_name(unsigned char proto);
63419 +extern const char * gr_sockfamily_to_name(unsigned char family);
63420 +
63421 +static __inline__ int
63422 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
63423 +{
63424 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
63425 +}
63426 +
63427 +static __inline__ int
63428 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
63429 + __u16 sport, __u16 dport)
63430 +{
63431 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
63432 + sig->gr_sport == sport && sig->gr_dport == dport))
63433 + return 1;
63434 + else
63435 + return 0;
63436 +}
63437 +
63438 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
63439 +{
63440 + struct conn_table_entry **match;
63441 + unsigned int index;
63442 +
63443 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63444 + sig->gr_sport, sig->gr_dport,
63445 + gr_conn_table_size);
63446 +
63447 + newent->sig = sig;
63448 +
63449 + match = &gr_conn_table[index];
63450 + newent->next = *match;
63451 + *match = newent;
63452 +
63453 + return;
63454 +}
63455 +
63456 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
63457 +{
63458 + struct conn_table_entry *match, *last = NULL;
63459 + unsigned int index;
63460 +
63461 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63462 + sig->gr_sport, sig->gr_dport,
63463 + gr_conn_table_size);
63464 +
63465 + match = gr_conn_table[index];
63466 + while (match && !conn_match(match->sig,
63467 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
63468 + sig->gr_dport)) {
63469 + last = match;
63470 + match = match->next;
63471 + }
63472 +
63473 + if (match) {
63474 + if (last)
63475 + last->next = match->next;
63476 + else
63477 + gr_conn_table[index] = NULL;
63478 + kfree(match);
63479 + }
63480 +
63481 + return;
63482 +}
63483 +
63484 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
63485 + __u16 sport, __u16 dport)
63486 +{
63487 + struct conn_table_entry *match;
63488 + unsigned int index;
63489 +
63490 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
63491 +
63492 + match = gr_conn_table[index];
63493 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
63494 + match = match->next;
63495 +
63496 + if (match)
63497 + return match->sig;
63498 + else
63499 + return NULL;
63500 +}
63501 +
63502 +#endif
63503 +
63504 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
63505 +{
63506 +#ifdef CONFIG_GRKERNSEC
63507 + struct signal_struct *sig = task->signal;
63508 + struct conn_table_entry *newent;
63509 +
63510 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
63511 + if (newent == NULL)
63512 + return;
63513 + /* no bh lock needed since we are called with bh disabled */
63514 + spin_lock(&gr_conn_table_lock);
63515 + gr_del_task_from_ip_table_nolock(sig);
63516 + sig->gr_saddr = inet->rcv_saddr;
63517 + sig->gr_daddr = inet->daddr;
63518 + sig->gr_sport = inet->sport;
63519 + sig->gr_dport = inet->dport;
63520 + gr_add_to_task_ip_table_nolock(sig, newent);
63521 + spin_unlock(&gr_conn_table_lock);
63522 +#endif
63523 + return;
63524 +}
63525 +
63526 +void gr_del_task_from_ip_table(struct task_struct *task)
63527 +{
63528 +#ifdef CONFIG_GRKERNSEC
63529 + spin_lock_bh(&gr_conn_table_lock);
63530 + gr_del_task_from_ip_table_nolock(task->signal);
63531 + spin_unlock_bh(&gr_conn_table_lock);
63532 +#endif
63533 + return;
63534 +}
63535 +
63536 +void
63537 +gr_attach_curr_ip(const struct sock *sk)
63538 +{
63539 +#ifdef CONFIG_GRKERNSEC
63540 + struct signal_struct *p, *set;
63541 + const struct inet_sock *inet = inet_sk(sk);
63542 +
63543 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
63544 + return;
63545 +
63546 + set = current->signal;
63547 +
63548 + spin_lock_bh(&gr_conn_table_lock);
63549 + p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
63550 + inet->dport, inet->sport);
63551 + if (unlikely(p != NULL)) {
63552 + set->curr_ip = p->curr_ip;
63553 + set->used_accept = 1;
63554 + gr_del_task_from_ip_table_nolock(p);
63555 + spin_unlock_bh(&gr_conn_table_lock);
63556 + return;
63557 + }
63558 + spin_unlock_bh(&gr_conn_table_lock);
63559 +
63560 + set->curr_ip = inet->daddr;
63561 + set->used_accept = 1;
63562 +#endif
63563 + return;
63564 +}
63565 +
63566 +int
63567 +gr_handle_sock_all(const int family, const int type, const int protocol)
63568 +{
63569 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63570 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
63571 + (family != AF_UNIX)) {
63572 + if (family == AF_INET)
63573 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
63574 + else
63575 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
63576 + return -EACCES;
63577 + }
63578 +#endif
63579 + return 0;
63580 +}
63581 +
63582 +int
63583 +gr_handle_sock_server(const struct sockaddr *sck)
63584 +{
63585 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63586 + if (grsec_enable_socket_server &&
63587 + in_group_p(grsec_socket_server_gid) &&
63588 + sck && (sck->sa_family != AF_UNIX) &&
63589 + (sck->sa_family != AF_LOCAL)) {
63590 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63591 + return -EACCES;
63592 + }
63593 +#endif
63594 + return 0;
63595 +}
63596 +
63597 +int
63598 +gr_handle_sock_server_other(const struct sock *sck)
63599 +{
63600 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63601 + if (grsec_enable_socket_server &&
63602 + in_group_p(grsec_socket_server_gid) &&
63603 + sck && (sck->sk_family != AF_UNIX) &&
63604 + (sck->sk_family != AF_LOCAL)) {
63605 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63606 + return -EACCES;
63607 + }
63608 +#endif
63609 + return 0;
63610 +}
63611 +
63612 +int
63613 +gr_handle_sock_client(const struct sockaddr *sck)
63614 +{
63615 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63616 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
63617 + sck && (sck->sa_family != AF_UNIX) &&
63618 + (sck->sa_family != AF_LOCAL)) {
63619 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
63620 + return -EACCES;
63621 + }
63622 +#endif
63623 + return 0;
63624 +}
63625 +
63626 +kernel_cap_t
63627 +gr_cap_rtnetlink(struct sock *sock)
63628 +{
63629 +#ifdef CONFIG_GRKERNSEC
63630 + if (!gr_acl_is_enabled())
63631 + return current_cap();
63632 + else if (sock->sk_protocol == NETLINK_ISCSI &&
63633 + cap_raised(current_cap(), CAP_SYS_ADMIN) &&
63634 + gr_is_capable(CAP_SYS_ADMIN))
63635 + return current_cap();
63636 + else if (sock->sk_protocol == NETLINK_AUDIT &&
63637 + cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
63638 + gr_is_capable(CAP_AUDIT_WRITE) &&
63639 + cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
63640 + gr_is_capable(CAP_AUDIT_CONTROL))
63641 + return current_cap();
63642 + else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
63643 + ((sock->sk_protocol == NETLINK_ROUTE) ?
63644 + gr_is_capable_nolog(CAP_NET_ADMIN) :
63645 + gr_is_capable(CAP_NET_ADMIN)))
63646 + return current_cap();
63647 + else
63648 + return __cap_empty_set;
63649 +#else
63650 + return current_cap();
63651 +#endif
63652 +}
63653 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
63654 new file mode 100644
63655 index 0000000..2753505
63656 --- /dev/null
63657 +++ b/grsecurity/grsec_sysctl.c
63658 @@ -0,0 +1,479 @@
63659 +#include <linux/kernel.h>
63660 +#include <linux/sched.h>
63661 +#include <linux/sysctl.h>
63662 +#include <linux/grsecurity.h>
63663 +#include <linux/grinternal.h>
63664 +
63665 +int
63666 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
63667 +{
63668 +#ifdef CONFIG_GRKERNSEC_SYSCTL
63669 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
63670 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
63671 + return -EACCES;
63672 + }
63673 +#endif
63674 + return 0;
63675 +}
63676 +
63677 +#ifdef CONFIG_GRKERNSEC_ROFS
63678 +static int __maybe_unused one = 1;
63679 +#endif
63680 +
63681 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
63682 +ctl_table grsecurity_table[] = {
63683 +#ifdef CONFIG_GRKERNSEC_SYSCTL
63684 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
63685 +#ifdef CONFIG_GRKERNSEC_IO
63686 + {
63687 + .ctl_name = CTL_UNNUMBERED,
63688 + .procname = "disable_priv_io",
63689 + .data = &grsec_disable_privio,
63690 + .maxlen = sizeof(int),
63691 + .mode = 0600,
63692 + .proc_handler = &proc_dointvec,
63693 + },
63694 +#endif
63695 +#endif
63696 +#ifdef CONFIG_GRKERNSEC_LINK
63697 + {
63698 + .ctl_name = CTL_UNNUMBERED,
63699 + .procname = "linking_restrictions",
63700 + .data = &grsec_enable_link,
63701 + .maxlen = sizeof(int),
63702 + .mode = 0600,
63703 + .proc_handler = &proc_dointvec,
63704 + },
63705 +#endif
63706 +#ifdef CONFIG_GRKERNSEC_BRUTE
63707 + {
63708 + .ctl_name = CTL_UNNUMBERED,
63709 + .procname = "deter_bruteforce",
63710 + .data = &grsec_enable_brute,
63711 + .maxlen = sizeof(int),
63712 + .mode = 0600,
63713 + .proc_handler = &proc_dointvec,
63714 + },
63715 +#endif
63716 +#ifdef CONFIG_GRKERNSEC_FIFO
63717 + {
63718 + .ctl_name = CTL_UNNUMBERED,
63719 + .procname = "fifo_restrictions",
63720 + .data = &grsec_enable_fifo,
63721 + .maxlen = sizeof(int),
63722 + .mode = 0600,
63723 + .proc_handler = &proc_dointvec,
63724 + },
63725 +#endif
63726 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63727 + {
63728 + .ctl_name = CTL_UNNUMBERED,
63729 + .procname = "ip_blackhole",
63730 + .data = &grsec_enable_blackhole,
63731 + .maxlen = sizeof(int),
63732 + .mode = 0600,
63733 + .proc_handler = &proc_dointvec,
63734 + },
63735 + {
63736 + .ctl_name = CTL_UNNUMBERED,
63737 + .procname = "lastack_retries",
63738 + .data = &grsec_lastack_retries,
63739 + .maxlen = sizeof(int),
63740 + .mode = 0600,
63741 + .proc_handler = &proc_dointvec,
63742 + },
63743 +#endif
63744 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63745 + {
63746 + .ctl_name = CTL_UNNUMBERED,
63747 + .procname = "exec_logging",
63748 + .data = &grsec_enable_execlog,
63749 + .maxlen = sizeof(int),
63750 + .mode = 0600,
63751 + .proc_handler = &proc_dointvec,
63752 + },
63753 +#endif
63754 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63755 + {
63756 + .ctl_name = CTL_UNNUMBERED,
63757 + .procname = "rwxmap_logging",
63758 + .data = &grsec_enable_log_rwxmaps,
63759 + .maxlen = sizeof(int),
63760 + .mode = 0600,
63761 + .proc_handler = &proc_dointvec,
63762 + },
63763 +#endif
63764 +#ifdef CONFIG_GRKERNSEC_SIGNAL
63765 + {
63766 + .ctl_name = CTL_UNNUMBERED,
63767 + .procname = "signal_logging",
63768 + .data = &grsec_enable_signal,
63769 + .maxlen = sizeof(int),
63770 + .mode = 0600,
63771 + .proc_handler = &proc_dointvec,
63772 + },
63773 +#endif
63774 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63775 + {
63776 + .ctl_name = CTL_UNNUMBERED,
63777 + .procname = "forkfail_logging",
63778 + .data = &grsec_enable_forkfail,
63779 + .maxlen = sizeof(int),
63780 + .mode = 0600,
63781 + .proc_handler = &proc_dointvec,
63782 + },
63783 +#endif
63784 +#ifdef CONFIG_GRKERNSEC_TIME
63785 + {
63786 + .ctl_name = CTL_UNNUMBERED,
63787 + .procname = "timechange_logging",
63788 + .data = &grsec_enable_time,
63789 + .maxlen = sizeof(int),
63790 + .mode = 0600,
63791 + .proc_handler = &proc_dointvec,
63792 + },
63793 +#endif
63794 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63795 + {
63796 + .ctl_name = CTL_UNNUMBERED,
63797 + .procname = "chroot_deny_shmat",
63798 + .data = &grsec_enable_chroot_shmat,
63799 + .maxlen = sizeof(int),
63800 + .mode = 0600,
63801 + .proc_handler = &proc_dointvec,
63802 + },
63803 +#endif
63804 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63805 + {
63806 + .ctl_name = CTL_UNNUMBERED,
63807 + .procname = "chroot_deny_unix",
63808 + .data = &grsec_enable_chroot_unix,
63809 + .maxlen = sizeof(int),
63810 + .mode = 0600,
63811 + .proc_handler = &proc_dointvec,
63812 + },
63813 +#endif
63814 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63815 + {
63816 + .ctl_name = CTL_UNNUMBERED,
63817 + .procname = "chroot_deny_mount",
63818 + .data = &grsec_enable_chroot_mount,
63819 + .maxlen = sizeof(int),
63820 + .mode = 0600,
63821 + .proc_handler = &proc_dointvec,
63822 + },
63823 +#endif
63824 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63825 + {
63826 + .ctl_name = CTL_UNNUMBERED,
63827 + .procname = "chroot_deny_fchdir",
63828 + .data = &grsec_enable_chroot_fchdir,
63829 + .maxlen = sizeof(int),
63830 + .mode = 0600,
63831 + .proc_handler = &proc_dointvec,
63832 + },
63833 +#endif
63834 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63835 + {
63836 + .ctl_name = CTL_UNNUMBERED,
63837 + .procname = "chroot_deny_chroot",
63838 + .data = &grsec_enable_chroot_double,
63839 + .maxlen = sizeof(int),
63840 + .mode = 0600,
63841 + .proc_handler = &proc_dointvec,
63842 + },
63843 +#endif
63844 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63845 + {
63846 + .ctl_name = CTL_UNNUMBERED,
63847 + .procname = "chroot_deny_pivot",
63848 + .data = &grsec_enable_chroot_pivot,
63849 + .maxlen = sizeof(int),
63850 + .mode = 0600,
63851 + .proc_handler = &proc_dointvec,
63852 + },
63853 +#endif
63854 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63855 + {
63856 + .ctl_name = CTL_UNNUMBERED,
63857 + .procname = "chroot_enforce_chdir",
63858 + .data = &grsec_enable_chroot_chdir,
63859 + .maxlen = sizeof(int),
63860 + .mode = 0600,
63861 + .proc_handler = &proc_dointvec,
63862 + },
63863 +#endif
63864 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63865 + {
63866 + .ctl_name = CTL_UNNUMBERED,
63867 + .procname = "chroot_deny_chmod",
63868 + .data = &grsec_enable_chroot_chmod,
63869 + .maxlen = sizeof(int),
63870 + .mode = 0600,
63871 + .proc_handler = &proc_dointvec,
63872 + },
63873 +#endif
63874 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63875 + {
63876 + .ctl_name = CTL_UNNUMBERED,
63877 + .procname = "chroot_deny_mknod",
63878 + .data = &grsec_enable_chroot_mknod,
63879 + .maxlen = sizeof(int),
63880 + .mode = 0600,
63881 + .proc_handler = &proc_dointvec,
63882 + },
63883 +#endif
63884 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63885 + {
63886 + .ctl_name = CTL_UNNUMBERED,
63887 + .procname = "chroot_restrict_nice",
63888 + .data = &grsec_enable_chroot_nice,
63889 + .maxlen = sizeof(int),
63890 + .mode = 0600,
63891 + .proc_handler = &proc_dointvec,
63892 + },
63893 +#endif
63894 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63895 + {
63896 + .ctl_name = CTL_UNNUMBERED,
63897 + .procname = "chroot_execlog",
63898 + .data = &grsec_enable_chroot_execlog,
63899 + .maxlen = sizeof(int),
63900 + .mode = 0600,
63901 + .proc_handler = &proc_dointvec,
63902 + },
63903 +#endif
63904 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63905 + {
63906 + .ctl_name = CTL_UNNUMBERED,
63907 + .procname = "chroot_caps",
63908 + .data = &grsec_enable_chroot_caps,
63909 + .maxlen = sizeof(int),
63910 + .mode = 0600,
63911 + .proc_handler = &proc_dointvec,
63912 + },
63913 +#endif
63914 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63915 + {
63916 + .ctl_name = CTL_UNNUMBERED,
63917 + .procname = "chroot_deny_sysctl",
63918 + .data = &grsec_enable_chroot_sysctl,
63919 + .maxlen = sizeof(int),
63920 + .mode = 0600,
63921 + .proc_handler = &proc_dointvec,
63922 + },
63923 +#endif
63924 +#ifdef CONFIG_GRKERNSEC_TPE
63925 + {
63926 + .ctl_name = CTL_UNNUMBERED,
63927 + .procname = "tpe",
63928 + .data = &grsec_enable_tpe,
63929 + .maxlen = sizeof(int),
63930 + .mode = 0600,
63931 + .proc_handler = &proc_dointvec,
63932 + },
63933 + {
63934 + .ctl_name = CTL_UNNUMBERED,
63935 + .procname = "tpe_gid",
63936 + .data = &grsec_tpe_gid,
63937 + .maxlen = sizeof(int),
63938 + .mode = 0600,
63939 + .proc_handler = &proc_dointvec,
63940 + },
63941 +#endif
63942 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63943 + {
63944 + .ctl_name = CTL_UNNUMBERED,
63945 + .procname = "tpe_invert",
63946 + .data = &grsec_enable_tpe_invert,
63947 + .maxlen = sizeof(int),
63948 + .mode = 0600,
63949 + .proc_handler = &proc_dointvec,
63950 + },
63951 +#endif
63952 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63953 + {
63954 + .ctl_name = CTL_UNNUMBERED,
63955 + .procname = "tpe_restrict_all",
63956 + .data = &grsec_enable_tpe_all,
63957 + .maxlen = sizeof(int),
63958 + .mode = 0600,
63959 + .proc_handler = &proc_dointvec,
63960 + },
63961 +#endif
63962 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63963 + {
63964 + .ctl_name = CTL_UNNUMBERED,
63965 + .procname = "socket_all",
63966 + .data = &grsec_enable_socket_all,
63967 + .maxlen = sizeof(int),
63968 + .mode = 0600,
63969 + .proc_handler = &proc_dointvec,
63970 + },
63971 + {
63972 + .ctl_name = CTL_UNNUMBERED,
63973 + .procname = "socket_all_gid",
63974 + .data = &grsec_socket_all_gid,
63975 + .maxlen = sizeof(int),
63976 + .mode = 0600,
63977 + .proc_handler = &proc_dointvec,
63978 + },
63979 +#endif
63980 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63981 + {
63982 + .ctl_name = CTL_UNNUMBERED,
63983 + .procname = "socket_client",
63984 + .data = &grsec_enable_socket_client,
63985 + .maxlen = sizeof(int),
63986 + .mode = 0600,
63987 + .proc_handler = &proc_dointvec,
63988 + },
63989 + {
63990 + .ctl_name = CTL_UNNUMBERED,
63991 + .procname = "socket_client_gid",
63992 + .data = &grsec_socket_client_gid,
63993 + .maxlen = sizeof(int),
63994 + .mode = 0600,
63995 + .proc_handler = &proc_dointvec,
63996 + },
63997 +#endif
63998 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63999 + {
64000 + .ctl_name = CTL_UNNUMBERED,
64001 + .procname = "socket_server",
64002 + .data = &grsec_enable_socket_server,
64003 + .maxlen = sizeof(int),
64004 + .mode = 0600,
64005 + .proc_handler = &proc_dointvec,
64006 + },
64007 + {
64008 + .ctl_name = CTL_UNNUMBERED,
64009 + .procname = "socket_server_gid",
64010 + .data = &grsec_socket_server_gid,
64011 + .maxlen = sizeof(int),
64012 + .mode = 0600,
64013 + .proc_handler = &proc_dointvec,
64014 + },
64015 +#endif
64016 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64017 + {
64018 + .ctl_name = CTL_UNNUMBERED,
64019 + .procname = "audit_group",
64020 + .data = &grsec_enable_group,
64021 + .maxlen = sizeof(int),
64022 + .mode = 0600,
64023 + .proc_handler = &proc_dointvec,
64024 + },
64025 + {
64026 + .ctl_name = CTL_UNNUMBERED,
64027 + .procname = "audit_gid",
64028 + .data = &grsec_audit_gid,
64029 + .maxlen = sizeof(int),
64030 + .mode = 0600,
64031 + .proc_handler = &proc_dointvec,
64032 + },
64033 +#endif
64034 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64035 + {
64036 + .ctl_name = CTL_UNNUMBERED,
64037 + .procname = "audit_chdir",
64038 + .data = &grsec_enable_chdir,
64039 + .maxlen = sizeof(int),
64040 + .mode = 0600,
64041 + .proc_handler = &proc_dointvec,
64042 + },
64043 +#endif
64044 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64045 + {
64046 + .ctl_name = CTL_UNNUMBERED,
64047 + .procname = "audit_mount",
64048 + .data = &grsec_enable_mount,
64049 + .maxlen = sizeof(int),
64050 + .mode = 0600,
64051 + .proc_handler = &proc_dointvec,
64052 + },
64053 +#endif
64054 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64055 + {
64056 + .ctl_name = CTL_UNNUMBERED,
64057 + .procname = "audit_textrel",
64058 + .data = &grsec_enable_audit_textrel,
64059 + .maxlen = sizeof(int),
64060 + .mode = 0600,
64061 + .proc_handler = &proc_dointvec,
64062 + },
64063 +#endif
64064 +#ifdef CONFIG_GRKERNSEC_DMESG
64065 + {
64066 + .ctl_name = CTL_UNNUMBERED,
64067 + .procname = "dmesg",
64068 + .data = &grsec_enable_dmesg,
64069 + .maxlen = sizeof(int),
64070 + .mode = 0600,
64071 + .proc_handler = &proc_dointvec,
64072 + },
64073 +#endif
64074 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64075 + {
64076 + .ctl_name = CTL_UNNUMBERED,
64077 + .procname = "chroot_findtask",
64078 + .data = &grsec_enable_chroot_findtask,
64079 + .maxlen = sizeof(int),
64080 + .mode = 0600,
64081 + .proc_handler = &proc_dointvec,
64082 + },
64083 +#endif
64084 +#ifdef CONFIG_GRKERNSEC_RESLOG
64085 + {
64086 + .ctl_name = CTL_UNNUMBERED,
64087 + .procname = "resource_logging",
64088 + .data = &grsec_resource_logging,
64089 + .maxlen = sizeof(int),
64090 + .mode = 0600,
64091 + .proc_handler = &proc_dointvec,
64092 + },
64093 +#endif
64094 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64095 + {
64096 + .ctl_name = CTL_UNNUMBERED,
64097 + .procname = "audit_ptrace",
64098 + .data = &grsec_enable_audit_ptrace,
64099 + .maxlen = sizeof(int),
64100 + .mode = 0600,
64101 + .proc_handler = &proc_dointvec,
64102 + },
64103 +#endif
64104 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64105 + {
64106 + .ctl_name = CTL_UNNUMBERED,
64107 + .procname = "harden_ptrace",
64108 + .data = &grsec_enable_harden_ptrace,
64109 + .maxlen = sizeof(int),
64110 + .mode = 0600,
64111 + .proc_handler = &proc_dointvec,
64112 + },
64113 +#endif
64114 + {
64115 + .ctl_name = CTL_UNNUMBERED,
64116 + .procname = "grsec_lock",
64117 + .data = &grsec_lock,
64118 + .maxlen = sizeof(int),
64119 + .mode = 0600,
64120 + .proc_handler = &proc_dointvec,
64121 + },
64122 +#endif
64123 +#ifdef CONFIG_GRKERNSEC_ROFS
64124 + {
64125 + .ctl_name = CTL_UNNUMBERED,
64126 + .procname = "romount_protect",
64127 + .data = &grsec_enable_rofs,
64128 + .maxlen = sizeof(int),
64129 + .mode = 0600,
64130 + .proc_handler = &proc_dointvec_minmax,
64131 + .extra1 = &one,
64132 + .extra2 = &one,
64133 + },
64134 +#endif
64135 + { .ctl_name = 0 }
64136 +};
64137 +#endif
64138 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
64139 new file mode 100644
64140 index 0000000..0dc13c3
64141 --- /dev/null
64142 +++ b/grsecurity/grsec_time.c
64143 @@ -0,0 +1,16 @@
64144 +#include <linux/kernel.h>
64145 +#include <linux/sched.h>
64146 +#include <linux/grinternal.h>
64147 +#include <linux/module.h>
64148 +
64149 +void
64150 +gr_log_timechange(void)
64151 +{
64152 +#ifdef CONFIG_GRKERNSEC_TIME
64153 + if (grsec_enable_time)
64154 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
64155 +#endif
64156 + return;
64157 +}
64158 +
64159 +EXPORT_SYMBOL(gr_log_timechange);
64160 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
64161 new file mode 100644
64162 index 0000000..4a78774
64163 --- /dev/null
64164 +++ b/grsecurity/grsec_tpe.c
64165 @@ -0,0 +1,39 @@
64166 +#include <linux/kernel.h>
64167 +#include <linux/sched.h>
64168 +#include <linux/file.h>
64169 +#include <linux/fs.h>
64170 +#include <linux/grinternal.h>
64171 +
64172 +extern int gr_acl_tpe_check(void);
64173 +
64174 +int
64175 +gr_tpe_allow(const struct file *file)
64176 +{
64177 +#ifdef CONFIG_GRKERNSEC
64178 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
64179 + const struct cred *cred = current_cred();
64180 +
64181 + if (cred->uid && ((grsec_enable_tpe &&
64182 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64183 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
64184 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
64185 +#else
64186 + in_group_p(grsec_tpe_gid)
64187 +#endif
64188 + ) || gr_acl_tpe_check()) &&
64189 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
64190 + (inode->i_mode & S_IWOTH))))) {
64191 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64192 + return 0;
64193 + }
64194 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
64195 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
64196 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
64197 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
64198 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64199 + return 0;
64200 + }
64201 +#endif
64202 +#endif
64203 + return 1;
64204 +}
64205 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
64206 new file mode 100644
64207 index 0000000..9f7b1ac
64208 --- /dev/null
64209 +++ b/grsecurity/grsum.c
64210 @@ -0,0 +1,61 @@
64211 +#include <linux/err.h>
64212 +#include <linux/kernel.h>
64213 +#include <linux/sched.h>
64214 +#include <linux/mm.h>
64215 +#include <linux/scatterlist.h>
64216 +#include <linux/crypto.h>
64217 +#include <linux/gracl.h>
64218 +
64219 +
64220 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
64221 +#error "crypto and sha256 must be built into the kernel"
64222 +#endif
64223 +
64224 +int
64225 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
64226 +{
64227 + char *p;
64228 + struct crypto_hash *tfm;
64229 + struct hash_desc desc;
64230 + struct scatterlist sg;
64231 + unsigned char temp_sum[GR_SHA_LEN];
64232 + volatile int retval = 0;
64233 + volatile int dummy = 0;
64234 + unsigned int i;
64235 +
64236 + sg_init_table(&sg, 1);
64237 +
64238 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
64239 + if (IS_ERR(tfm)) {
64240 + /* should never happen, since sha256 should be built in */
64241 + return 1;
64242 + }
64243 +
64244 + desc.tfm = tfm;
64245 + desc.flags = 0;
64246 +
64247 + crypto_hash_init(&desc);
64248 +
64249 + p = salt;
64250 + sg_set_buf(&sg, p, GR_SALT_LEN);
64251 + crypto_hash_update(&desc, &sg, sg.length);
64252 +
64253 + p = entry->pw;
64254 + sg_set_buf(&sg, p, strlen(p));
64255 +
64256 + crypto_hash_update(&desc, &sg, sg.length);
64257 +
64258 + crypto_hash_final(&desc, temp_sum);
64259 +
64260 + memset(entry->pw, 0, GR_PW_LEN);
64261 +
64262 + for (i = 0; i < GR_SHA_LEN; i++)
64263 + if (sum[i] != temp_sum[i])
64264 + retval = 1;
64265 + else
64266 + dummy = 1; // waste a cycle
64267 +
64268 + crypto_free_hash(tfm);
64269 +
64270 + return retval;
64271 +}
64272 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
64273 index 3cd9ccd..fe16d47 100644
64274 --- a/include/acpi/acpi_bus.h
64275 +++ b/include/acpi/acpi_bus.h
64276 @@ -107,7 +107,7 @@ struct acpi_device_ops {
64277 acpi_op_bind bind;
64278 acpi_op_unbind unbind;
64279 acpi_op_notify notify;
64280 -};
64281 +} __no_const;
64282
64283 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
64284
64285 diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
64286 index f4906f6..71feb73 100644
64287 --- a/include/acpi/acpi_drivers.h
64288 +++ b/include/acpi/acpi_drivers.h
64289 @@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type);
64290 Dock Station
64291 -------------------------------------------------------------------------- */
64292 struct acpi_dock_ops {
64293 - acpi_notify_handler handler;
64294 - acpi_notify_handler uevent;
64295 + const acpi_notify_handler handler;
64296 + const acpi_notify_handler uevent;
64297 };
64298
64299 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
64300 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle handle);
64301 extern int register_dock_notifier(struct notifier_block *nb);
64302 extern void unregister_dock_notifier(struct notifier_block *nb);
64303 extern int register_hotplug_dock_device(acpi_handle handle,
64304 - struct acpi_dock_ops *ops,
64305 + const struct acpi_dock_ops *ops,
64306 void *context);
64307 extern void unregister_hotplug_dock_device(acpi_handle handle);
64308 #else
64309 @@ -144,7 +144,7 @@ static inline void unregister_dock_notifier(struct notifier_block *nb)
64310 {
64311 }
64312 static inline int register_hotplug_dock_device(acpi_handle handle,
64313 - struct acpi_dock_ops *ops,
64314 + const struct acpi_dock_ops *ops,
64315 void *context)
64316 {
64317 return -ENODEV;
64318 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
64319 index b7babf0..a9ac9fc 100644
64320 --- a/include/asm-generic/atomic-long.h
64321 +++ b/include/asm-generic/atomic-long.h
64322 @@ -22,6 +22,12 @@
64323
64324 typedef atomic64_t atomic_long_t;
64325
64326 +#ifdef CONFIG_PAX_REFCOUNT
64327 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
64328 +#else
64329 +typedef atomic64_t atomic_long_unchecked_t;
64330 +#endif
64331 +
64332 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
64333
64334 static inline long atomic_long_read(atomic_long_t *l)
64335 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64336 return (long)atomic64_read(v);
64337 }
64338
64339 +#ifdef CONFIG_PAX_REFCOUNT
64340 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64341 +{
64342 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64343 +
64344 + return (long)atomic64_read_unchecked(v);
64345 +}
64346 +#endif
64347 +
64348 static inline void atomic_long_set(atomic_long_t *l, long i)
64349 {
64350 atomic64_t *v = (atomic64_t *)l;
64351 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64352 atomic64_set(v, i);
64353 }
64354
64355 +#ifdef CONFIG_PAX_REFCOUNT
64356 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64357 +{
64358 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64359 +
64360 + atomic64_set_unchecked(v, i);
64361 +}
64362 +#endif
64363 +
64364 static inline void atomic_long_inc(atomic_long_t *l)
64365 {
64366 atomic64_t *v = (atomic64_t *)l;
64367 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64368 atomic64_inc(v);
64369 }
64370
64371 +#ifdef CONFIG_PAX_REFCOUNT
64372 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64373 +{
64374 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64375 +
64376 + atomic64_inc_unchecked(v);
64377 +}
64378 +#endif
64379 +
64380 static inline void atomic_long_dec(atomic_long_t *l)
64381 {
64382 atomic64_t *v = (atomic64_t *)l;
64383 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64384 atomic64_dec(v);
64385 }
64386
64387 +#ifdef CONFIG_PAX_REFCOUNT
64388 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64389 +{
64390 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64391 +
64392 + atomic64_dec_unchecked(v);
64393 +}
64394 +#endif
64395 +
64396 static inline void atomic_long_add(long i, atomic_long_t *l)
64397 {
64398 atomic64_t *v = (atomic64_t *)l;
64399 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64400 atomic64_add(i, v);
64401 }
64402
64403 +#ifdef CONFIG_PAX_REFCOUNT
64404 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64405 +{
64406 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64407 +
64408 + atomic64_add_unchecked(i, v);
64409 +}
64410 +#endif
64411 +
64412 static inline void atomic_long_sub(long i, atomic_long_t *l)
64413 {
64414 atomic64_t *v = (atomic64_t *)l;
64415 @@ -115,6 +166,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64416 return (long)atomic64_inc_return(v);
64417 }
64418
64419 +#ifdef CONFIG_PAX_REFCOUNT
64420 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64421 +{
64422 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64423 +
64424 + return (long)atomic64_inc_return_unchecked(v);
64425 +}
64426 +#endif
64427 +
64428 static inline long atomic_long_dec_return(atomic_long_t *l)
64429 {
64430 atomic64_t *v = (atomic64_t *)l;
64431 @@ -140,6 +200,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64432
64433 typedef atomic_t atomic_long_t;
64434
64435 +#ifdef CONFIG_PAX_REFCOUNT
64436 +typedef atomic_unchecked_t atomic_long_unchecked_t;
64437 +#else
64438 +typedef atomic_t atomic_long_unchecked_t;
64439 +#endif
64440 +
64441 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
64442 static inline long atomic_long_read(atomic_long_t *l)
64443 {
64444 @@ -148,6 +214,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64445 return (long)atomic_read(v);
64446 }
64447
64448 +#ifdef CONFIG_PAX_REFCOUNT
64449 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64450 +{
64451 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64452 +
64453 + return (long)atomic_read_unchecked(v);
64454 +}
64455 +#endif
64456 +
64457 static inline void atomic_long_set(atomic_long_t *l, long i)
64458 {
64459 atomic_t *v = (atomic_t *)l;
64460 @@ -155,6 +230,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64461 atomic_set(v, i);
64462 }
64463
64464 +#ifdef CONFIG_PAX_REFCOUNT
64465 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64466 +{
64467 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64468 +
64469 + atomic_set_unchecked(v, i);
64470 +}
64471 +#endif
64472 +
64473 static inline void atomic_long_inc(atomic_long_t *l)
64474 {
64475 atomic_t *v = (atomic_t *)l;
64476 @@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64477 atomic_inc(v);
64478 }
64479
64480 +#ifdef CONFIG_PAX_REFCOUNT
64481 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64482 +{
64483 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64484 +
64485 + atomic_inc_unchecked(v);
64486 +}
64487 +#endif
64488 +
64489 static inline void atomic_long_dec(atomic_long_t *l)
64490 {
64491 atomic_t *v = (atomic_t *)l;
64492 @@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64493 atomic_dec(v);
64494 }
64495
64496 +#ifdef CONFIG_PAX_REFCOUNT
64497 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64498 +{
64499 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64500 +
64501 + atomic_dec_unchecked(v);
64502 +}
64503 +#endif
64504 +
64505 static inline void atomic_long_add(long i, atomic_long_t *l)
64506 {
64507 atomic_t *v = (atomic_t *)l;
64508 @@ -176,6 +278,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64509 atomic_add(i, v);
64510 }
64511
64512 +#ifdef CONFIG_PAX_REFCOUNT
64513 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64514 +{
64515 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64516 +
64517 + atomic_add_unchecked(i, v);
64518 +}
64519 +#endif
64520 +
64521 static inline void atomic_long_sub(long i, atomic_long_t *l)
64522 {
64523 atomic_t *v = (atomic_t *)l;
64524 @@ -232,6 +343,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64525 return (long)atomic_inc_return(v);
64526 }
64527
64528 +#ifdef CONFIG_PAX_REFCOUNT
64529 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64530 +{
64531 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64532 +
64533 + return (long)atomic_inc_return_unchecked(v);
64534 +}
64535 +#endif
64536 +
64537 static inline long atomic_long_dec_return(atomic_long_t *l)
64538 {
64539 atomic_t *v = (atomic_t *)l;
64540 @@ -255,4 +375,47 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64541
64542 #endif /* BITS_PER_LONG == 64 */
64543
64544 +#ifdef CONFIG_PAX_REFCOUNT
64545 +static inline void pax_refcount_needs_these_functions(void)
64546 +{
64547 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
64548 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
64549 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
64550 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
64551 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
64552 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
64553 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
64554 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
64555 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
64556 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
64557 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
64558 +
64559 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
64560 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
64561 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
64562 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
64563 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
64564 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
64565 +}
64566 +#else
64567 +#define atomic_read_unchecked(v) atomic_read(v)
64568 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
64569 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
64570 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
64571 +#define atomic_inc_unchecked(v) atomic_inc(v)
64572 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
64573 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
64574 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
64575 +#define atomic_dec_unchecked(v) atomic_dec(v)
64576 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
64577 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
64578 +
64579 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
64580 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
64581 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
64582 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
64583 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
64584 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
64585 +#endif
64586 +
64587 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
64588 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
64589 index b18ce4f..2ee2843 100644
64590 --- a/include/asm-generic/atomic64.h
64591 +++ b/include/asm-generic/atomic64.h
64592 @@ -16,6 +16,8 @@ typedef struct {
64593 long long counter;
64594 } atomic64_t;
64595
64596 +typedef atomic64_t atomic64_unchecked_t;
64597 +
64598 #define ATOMIC64_INIT(i) { (i) }
64599
64600 extern long long atomic64_read(const atomic64_t *v);
64601 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
64602 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
64603 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
64604
64605 +#define atomic64_read_unchecked(v) atomic64_read(v)
64606 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
64607 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
64608 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
64609 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
64610 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
64611 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
64612 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
64613 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
64614 +
64615 #endif /* _ASM_GENERIC_ATOMIC64_H */
64616 diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
64617 index d48ddf0..656a0ac 100644
64618 --- a/include/asm-generic/bug.h
64619 +++ b/include/asm-generic/bug.h
64620 @@ -105,11 +105,11 @@ extern void warn_slowpath_null(const char *file, const int line);
64621
64622 #else /* !CONFIG_BUG */
64623 #ifndef HAVE_ARCH_BUG
64624 -#define BUG() do {} while(0)
64625 +#define BUG() do { for (;;) ; } while(0)
64626 #endif
64627
64628 #ifndef HAVE_ARCH_BUG_ON
64629 -#define BUG_ON(condition) do { if (condition) ; } while(0)
64630 +#define BUG_ON(condition) do { if (condition) for (;;) ; } while(0)
64631 #endif
64632
64633 #ifndef HAVE_ARCH_WARN_ON
64634 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
64635 index 1bfcfe5..e04c5c9 100644
64636 --- a/include/asm-generic/cache.h
64637 +++ b/include/asm-generic/cache.h
64638 @@ -6,7 +6,7 @@
64639 * cache lines need to provide their own cache.h.
64640 */
64641
64642 -#define L1_CACHE_SHIFT 5
64643 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
64644 +#define L1_CACHE_SHIFT 5UL
64645 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
64646
64647 #endif /* __ASM_GENERIC_CACHE_H */
64648 diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
64649 index 6920695..41038bc 100644
64650 --- a/include/asm-generic/dma-mapping-common.h
64651 +++ b/include/asm-generic/dma-mapping-common.h
64652 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
64653 enum dma_data_direction dir,
64654 struct dma_attrs *attrs)
64655 {
64656 - struct dma_map_ops *ops = get_dma_ops(dev);
64657 + const struct dma_map_ops *ops = get_dma_ops(dev);
64658 dma_addr_t addr;
64659
64660 kmemcheck_mark_initialized(ptr, size);
64661 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
64662 enum dma_data_direction dir,
64663 struct dma_attrs *attrs)
64664 {
64665 - struct dma_map_ops *ops = get_dma_ops(dev);
64666 + const struct dma_map_ops *ops = get_dma_ops(dev);
64667
64668 BUG_ON(!valid_dma_direction(dir));
64669 if (ops->unmap_page)
64670 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
64671 int nents, enum dma_data_direction dir,
64672 struct dma_attrs *attrs)
64673 {
64674 - struct dma_map_ops *ops = get_dma_ops(dev);
64675 + const struct dma_map_ops *ops = get_dma_ops(dev);
64676 int i, ents;
64677 struct scatterlist *s;
64678
64679 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg
64680 int nents, enum dma_data_direction dir,
64681 struct dma_attrs *attrs)
64682 {
64683 - struct dma_map_ops *ops = get_dma_ops(dev);
64684 + const struct dma_map_ops *ops = get_dma_ops(dev);
64685
64686 BUG_ON(!valid_dma_direction(dir));
64687 debug_dma_unmap_sg(dev, sg, nents, dir);
64688 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64689 size_t offset, size_t size,
64690 enum dma_data_direction dir)
64691 {
64692 - struct dma_map_ops *ops = get_dma_ops(dev);
64693 + const struct dma_map_ops *ops = get_dma_ops(dev);
64694 dma_addr_t addr;
64695
64696 kmemcheck_mark_initialized(page_address(page) + offset, size);
64697 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64698 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
64699 size_t size, enum dma_data_direction dir)
64700 {
64701 - struct dma_map_ops *ops = get_dma_ops(dev);
64702 + const struct dma_map_ops *ops = get_dma_ops(dev);
64703
64704 BUG_ON(!valid_dma_direction(dir));
64705 if (ops->unmap_page)
64706 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
64707 size_t size,
64708 enum dma_data_direction dir)
64709 {
64710 - struct dma_map_ops *ops = get_dma_ops(dev);
64711 + const struct dma_map_ops *ops = get_dma_ops(dev);
64712
64713 BUG_ON(!valid_dma_direction(dir));
64714 if (ops->sync_single_for_cpu)
64715 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_device(struct device *dev,
64716 dma_addr_t addr, size_t size,
64717 enum dma_data_direction dir)
64718 {
64719 - struct dma_map_ops *ops = get_dma_ops(dev);
64720 + const struct dma_map_ops *ops = get_dma_ops(dev);
64721
64722 BUG_ON(!valid_dma_direction(dir));
64723 if (ops->sync_single_for_device)
64724 @@ -123,7 +123,7 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
64725 size_t size,
64726 enum dma_data_direction dir)
64727 {
64728 - struct dma_map_ops *ops = get_dma_ops(dev);
64729 + const struct dma_map_ops *ops = get_dma_ops(dev);
64730
64731 BUG_ON(!valid_dma_direction(dir));
64732 if (ops->sync_single_range_for_cpu) {
64733 @@ -140,7 +140,7 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
64734 size_t size,
64735 enum dma_data_direction dir)
64736 {
64737 - struct dma_map_ops *ops = get_dma_ops(dev);
64738 + const struct dma_map_ops *ops = get_dma_ops(dev);
64739
64740 BUG_ON(!valid_dma_direction(dir));
64741 if (ops->sync_single_range_for_device) {
64742 @@ -155,7 +155,7 @@ static inline void
64743 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
64744 int nelems, enum dma_data_direction dir)
64745 {
64746 - struct dma_map_ops *ops = get_dma_ops(dev);
64747 + const struct dma_map_ops *ops = get_dma_ops(dev);
64748
64749 BUG_ON(!valid_dma_direction(dir));
64750 if (ops->sync_sg_for_cpu)
64751 @@ -167,7 +167,7 @@ static inline void
64752 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
64753 int nelems, enum dma_data_direction dir)
64754 {
64755 - struct dma_map_ops *ops = get_dma_ops(dev);
64756 + const struct dma_map_ops *ops = get_dma_ops(dev);
64757
64758 BUG_ON(!valid_dma_direction(dir));
64759 if (ops->sync_sg_for_device)
64760 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
64761 index 0d68a1e..b74a761 100644
64762 --- a/include/asm-generic/emergency-restart.h
64763 +++ b/include/asm-generic/emergency-restart.h
64764 @@ -1,7 +1,7 @@
64765 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
64766 #define _ASM_GENERIC_EMERGENCY_RESTART_H
64767
64768 -static inline void machine_emergency_restart(void)
64769 +static inline __noreturn void machine_emergency_restart(void)
64770 {
64771 machine_restart(NULL);
64772 }
64773 diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
64774 index 3c2344f..4590a7d 100644
64775 --- a/include/asm-generic/futex.h
64776 +++ b/include/asm-generic/futex.h
64777 @@ -6,7 +6,7 @@
64778 #include <asm/errno.h>
64779
64780 static inline int
64781 -futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
64782 +futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
64783 {
64784 int op = (encoded_op >> 28) & 7;
64785 int cmp = (encoded_op >> 24) & 15;
64786 @@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
64787 }
64788
64789 static inline int
64790 -futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
64791 +futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
64792 {
64793 return -ENOSYS;
64794 }
64795 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
64796 index 1ca3efc..e3dc852 100644
64797 --- a/include/asm-generic/int-l64.h
64798 +++ b/include/asm-generic/int-l64.h
64799 @@ -46,6 +46,8 @@ typedef unsigned int u32;
64800 typedef signed long s64;
64801 typedef unsigned long u64;
64802
64803 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
64804 +
64805 #define S8_C(x) x
64806 #define U8_C(x) x ## U
64807 #define S16_C(x) x
64808 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
64809 index f394147..b6152b9 100644
64810 --- a/include/asm-generic/int-ll64.h
64811 +++ b/include/asm-generic/int-ll64.h
64812 @@ -51,6 +51,8 @@ typedef unsigned int u32;
64813 typedef signed long long s64;
64814 typedef unsigned long long u64;
64815
64816 +typedef unsigned long long intoverflow_t;
64817 +
64818 #define S8_C(x) x
64819 #define U8_C(x) x ## U
64820 #define S16_C(x) x
64821 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
64822 index e5f234a..cdb16b3 100644
64823 --- a/include/asm-generic/kmap_types.h
64824 +++ b/include/asm-generic/kmap_types.h
64825 @@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
64826 KMAP_D(16) KM_IRQ_PTE,
64827 KMAP_D(17) KM_NMI,
64828 KMAP_D(18) KM_NMI_PTE,
64829 -KMAP_D(19) KM_TYPE_NR
64830 +KMAP_D(19) KM_CLEARPAGE,
64831 +KMAP_D(20) KM_TYPE_NR
64832 };
64833
64834 #undef KMAP_D
64835 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
64836 index 725612b..9cc513a 100644
64837 --- a/include/asm-generic/pgtable-nopmd.h
64838 +++ b/include/asm-generic/pgtable-nopmd.h
64839 @@ -1,14 +1,19 @@
64840 #ifndef _PGTABLE_NOPMD_H
64841 #define _PGTABLE_NOPMD_H
64842
64843 -#ifndef __ASSEMBLY__
64844 -
64845 #include <asm-generic/pgtable-nopud.h>
64846
64847 -struct mm_struct;
64848 -
64849 #define __PAGETABLE_PMD_FOLDED
64850
64851 +#define PMD_SHIFT PUD_SHIFT
64852 +#define PTRS_PER_PMD 1
64853 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
64854 +#define PMD_MASK (~(PMD_SIZE-1))
64855 +
64856 +#ifndef __ASSEMBLY__
64857 +
64858 +struct mm_struct;
64859 +
64860 /*
64861 * Having the pmd type consist of a pud gets the size right, and allows
64862 * us to conceptually access the pud entry that this pmd is folded into
64863 @@ -16,11 +21,6 @@ struct mm_struct;
64864 */
64865 typedef struct { pud_t pud; } pmd_t;
64866
64867 -#define PMD_SHIFT PUD_SHIFT
64868 -#define PTRS_PER_PMD 1
64869 -#define PMD_SIZE (1UL << PMD_SHIFT)
64870 -#define PMD_MASK (~(PMD_SIZE-1))
64871 -
64872 /*
64873 * The "pud_xxx()" functions here are trivial for a folded two-level
64874 * setup: the pmd is never bad, and a pmd always exists (as it's folded
64875 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
64876 index 810431d..ccc3638 100644
64877 --- a/include/asm-generic/pgtable-nopud.h
64878 +++ b/include/asm-generic/pgtable-nopud.h
64879 @@ -1,10 +1,15 @@
64880 #ifndef _PGTABLE_NOPUD_H
64881 #define _PGTABLE_NOPUD_H
64882
64883 -#ifndef __ASSEMBLY__
64884 -
64885 #define __PAGETABLE_PUD_FOLDED
64886
64887 +#define PUD_SHIFT PGDIR_SHIFT
64888 +#define PTRS_PER_PUD 1
64889 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
64890 +#define PUD_MASK (~(PUD_SIZE-1))
64891 +
64892 +#ifndef __ASSEMBLY__
64893 +
64894 /*
64895 * Having the pud type consist of a pgd gets the size right, and allows
64896 * us to conceptually access the pgd entry that this pud is folded into
64897 @@ -12,11 +17,6 @@
64898 */
64899 typedef struct { pgd_t pgd; } pud_t;
64900
64901 -#define PUD_SHIFT PGDIR_SHIFT
64902 -#define PTRS_PER_PUD 1
64903 -#define PUD_SIZE (1UL << PUD_SHIFT)
64904 -#define PUD_MASK (~(PUD_SIZE-1))
64905 -
64906 /*
64907 * The "pgd_xxx()" functions here are trivial for a folded two-level
64908 * setup: the pud is never bad, and a pud always exists (as it's folded
64909 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
64910 index e2bd73e..fea8ed3 100644
64911 --- a/include/asm-generic/pgtable.h
64912 +++ b/include/asm-generic/pgtable.h
64913 @@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_area_struct *vma, unsigned long pfn,
64914 unsigned long size);
64915 #endif
64916
64917 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
64918 +static inline unsigned long pax_open_kernel(void) { return 0; }
64919 +#endif
64920 +
64921 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
64922 +static inline unsigned long pax_close_kernel(void) { return 0; }
64923 +#endif
64924 +
64925 #endif /* !__ASSEMBLY__ */
64926
64927 #endif /* _ASM_GENERIC_PGTABLE_H */
64928 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
64929 index b6e818f..21aa58a 100644
64930 --- a/include/asm-generic/vmlinux.lds.h
64931 +++ b/include/asm-generic/vmlinux.lds.h
64932 @@ -199,6 +199,7 @@
64933 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
64934 VMLINUX_SYMBOL(__start_rodata) = .; \
64935 *(.rodata) *(.rodata.*) \
64936 + *(.data.read_only) \
64937 *(__vermagic) /* Kernel version magic */ \
64938 *(__markers_strings) /* Markers: strings */ \
64939 *(__tracepoints_strings)/* Tracepoints: strings */ \
64940 @@ -656,22 +657,24 @@
64941 * section in the linker script will go there too. @phdr should have
64942 * a leading colon.
64943 *
64944 - * Note that this macros defines __per_cpu_load as an absolute symbol.
64945 + * Note that this macros defines per_cpu_load as an absolute symbol.
64946 * If there is no need to put the percpu section at a predetermined
64947 * address, use PERCPU().
64948 */
64949 #define PERCPU_VADDR(vaddr, phdr) \
64950 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
64951 - .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
64952 + per_cpu_load = .; \
64953 + .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
64954 - LOAD_OFFSET) { \
64955 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
64956 VMLINUX_SYMBOL(__per_cpu_start) = .; \
64957 *(.data.percpu.first) \
64958 - *(.data.percpu.page_aligned) \
64959 *(.data.percpu) \
64960 + . = ALIGN(PAGE_SIZE); \
64961 + *(.data.percpu.page_aligned) \
64962 *(.data.percpu.shared_aligned) \
64963 VMLINUX_SYMBOL(__per_cpu_end) = .; \
64964 } phdr \
64965 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
64966 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
64967
64968 /**
64969 * PERCPU - define output section for percpu area, simple version
64970 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
64971 index 66713c6..98c0460 100644
64972 --- a/include/drm/drmP.h
64973 +++ b/include/drm/drmP.h
64974 @@ -71,6 +71,7 @@
64975 #include <linux/workqueue.h>
64976 #include <linux/poll.h>
64977 #include <asm/pgalloc.h>
64978 +#include <asm/local.h>
64979 #include "drm.h"
64980
64981 #include <linux/idr.h>
64982 @@ -814,7 +815,7 @@ struct drm_driver {
64983 void (*vgaarb_irq)(struct drm_device *dev, bool state);
64984
64985 /* Driver private ops for this object */
64986 - struct vm_operations_struct *gem_vm_ops;
64987 + const struct vm_operations_struct *gem_vm_ops;
64988
64989 int major;
64990 int minor;
64991 @@ -917,7 +918,7 @@ struct drm_device {
64992
64993 /** \name Usage Counters */
64994 /*@{ */
64995 - int open_count; /**< Outstanding files open */
64996 + local_t open_count; /**< Outstanding files open */
64997 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
64998 atomic_t vma_count; /**< Outstanding vma areas open */
64999 int buf_use; /**< Buffers in use -- cannot alloc */
65000 @@ -928,7 +929,7 @@ struct drm_device {
65001 /*@{ */
65002 unsigned long counters;
65003 enum drm_stat_type types[15];
65004 - atomic_t counts[15];
65005 + atomic_unchecked_t counts[15];
65006 /*@} */
65007
65008 struct list_head filelist;
65009 @@ -1016,7 +1017,7 @@ struct drm_device {
65010 struct pci_controller *hose;
65011 #endif
65012 struct drm_sg_mem *sg; /**< Scatter gather memory */
65013 - unsigned int num_crtcs; /**< Number of CRTCs on this device */
65014 + unsigned int num_crtcs; /**< Number of CRTCs on this device */
65015 void *dev_private; /**< device private data */
65016 void *mm_private;
65017 struct address_space *dev_mapping;
65018 @@ -1042,11 +1043,11 @@ struct drm_device {
65019 spinlock_t object_name_lock;
65020 struct idr object_name_idr;
65021 atomic_t object_count;
65022 - atomic_t object_memory;
65023 + atomic_unchecked_t object_memory;
65024 atomic_t pin_count;
65025 - atomic_t pin_memory;
65026 + atomic_unchecked_t pin_memory;
65027 atomic_t gtt_count;
65028 - atomic_t gtt_memory;
65029 + atomic_unchecked_t gtt_memory;
65030 uint32_t gtt_total;
65031 uint32_t invalidate_domains; /* domains pending invalidation */
65032 uint32_t flush_domains; /* domains pending flush */
65033 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
65034 index b29e201..3413cc9 100644
65035 --- a/include/drm/drm_crtc_helper.h
65036 +++ b/include/drm/drm_crtc_helper.h
65037 @@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
65038
65039 /* reload the current crtc LUT */
65040 void (*load_lut)(struct drm_crtc *crtc);
65041 -};
65042 +} __no_const;
65043
65044 struct drm_encoder_helper_funcs {
65045 void (*dpms)(struct drm_encoder *encoder, int mode);
65046 @@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
65047 struct drm_connector *connector);
65048 /* disable encoder when not in use - more explicit than dpms off */
65049 void (*disable)(struct drm_encoder *encoder);
65050 -};
65051 +} __no_const;
65052
65053 struct drm_connector_helper_funcs {
65054 int (*get_modes)(struct drm_connector *connector);
65055 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
65056 index b199170..6f9e64c 100644
65057 --- a/include/drm/ttm/ttm_memory.h
65058 +++ b/include/drm/ttm/ttm_memory.h
65059 @@ -47,7 +47,7 @@
65060
65061 struct ttm_mem_shrink {
65062 int (*do_shrink) (struct ttm_mem_shrink *);
65063 -};
65064 +} __no_const;
65065
65066 /**
65067 * struct ttm_mem_global - Global memory accounting structure.
65068 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
65069 index e86dfca..40cc55f 100644
65070 --- a/include/linux/a.out.h
65071 +++ b/include/linux/a.out.h
65072 @@ -39,6 +39,14 @@ enum machine_type {
65073 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65074 };
65075
65076 +/* Constants for the N_FLAGS field */
65077 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65078 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65079 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65080 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65081 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65082 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65083 +
65084 #if !defined (N_MAGIC)
65085 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65086 #endif
65087 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
65088 index 817b237..62c10bc 100644
65089 --- a/include/linux/atmdev.h
65090 +++ b/include/linux/atmdev.h
65091 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
65092 #endif
65093
65094 struct k_atm_aal_stats {
65095 -#define __HANDLE_ITEM(i) atomic_t i
65096 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65097 __AAL_STAT_ITEMS
65098 #undef __HANDLE_ITEM
65099 };
65100 diff --git a/include/linux/backlight.h b/include/linux/backlight.h
65101 index 0f5f578..8c4f884 100644
65102 --- a/include/linux/backlight.h
65103 +++ b/include/linux/backlight.h
65104 @@ -36,18 +36,18 @@ struct backlight_device;
65105 struct fb_info;
65106
65107 struct backlight_ops {
65108 - unsigned int options;
65109 + const unsigned int options;
65110
65111 #define BL_CORE_SUSPENDRESUME (1 << 0)
65112
65113 /* Notify the backlight driver some property has changed */
65114 - int (*update_status)(struct backlight_device *);
65115 + int (* const update_status)(struct backlight_device *);
65116 /* Return the current backlight brightness (accounting for power,
65117 fb_blank etc.) */
65118 - int (*get_brightness)(struct backlight_device *);
65119 + int (* const get_brightness)(struct backlight_device *);
65120 /* Check if given framebuffer device is the one bound to this backlight;
65121 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
65122 - int (*check_fb)(struct fb_info *);
65123 + int (* const check_fb)(struct fb_info *);
65124 };
65125
65126 /* This structure defines all the properties of a backlight */
65127 @@ -86,7 +86,7 @@ struct backlight_device {
65128 registered this device has been unloaded, and if class_get_devdata()
65129 points to something in the body of that driver, it is also invalid. */
65130 struct mutex ops_lock;
65131 - struct backlight_ops *ops;
65132 + const struct backlight_ops *ops;
65133
65134 /* The framebuffer notifier block */
65135 struct notifier_block fb_notif;
65136 @@ -103,7 +103,7 @@ static inline void backlight_update_status(struct backlight_device *bd)
65137 }
65138
65139 extern struct backlight_device *backlight_device_register(const char *name,
65140 - struct device *dev, void *devdata, struct backlight_ops *ops);
65141 + struct device *dev, void *devdata, const struct backlight_ops *ops);
65142 extern void backlight_device_unregister(struct backlight_device *bd);
65143 extern void backlight_force_update(struct backlight_device *bd,
65144 enum backlight_update_reason reason);
65145 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
65146 index a3d802e..482f69c 100644
65147 --- a/include/linux/binfmts.h
65148 +++ b/include/linux/binfmts.h
65149 @@ -83,6 +83,7 @@ struct linux_binfmt {
65150 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
65151 int (*load_shlib)(struct file *);
65152 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
65153 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
65154 unsigned long min_coredump; /* minimal dump size */
65155 int hasvdso;
65156 };
65157 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
65158 index a06bfab..4fa38bb 100644
65159 --- a/include/linux/blkdev.h
65160 +++ b/include/linux/blkdev.h
65161 @@ -1278,7 +1278,7 @@ struct block_device_operations {
65162 int (*revalidate_disk) (struct gendisk *);
65163 int (*getgeo)(struct block_device *, struct hd_geometry *);
65164 struct module *owner;
65165 -};
65166 +} __do_const;
65167
65168 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
65169 unsigned long);
65170 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
65171 index 3b73b99..629d21b 100644
65172 --- a/include/linux/blktrace_api.h
65173 +++ b/include/linux/blktrace_api.h
65174 @@ -160,7 +160,7 @@ struct blk_trace {
65175 struct dentry *dir;
65176 struct dentry *dropped_file;
65177 struct dentry *msg_file;
65178 - atomic_t dropped;
65179 + atomic_unchecked_t dropped;
65180 };
65181
65182 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
65183 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
65184 index 83195fb..0b0f77d 100644
65185 --- a/include/linux/byteorder/little_endian.h
65186 +++ b/include/linux/byteorder/little_endian.h
65187 @@ -42,51 +42,51 @@
65188
65189 static inline __le64 __cpu_to_le64p(const __u64 *p)
65190 {
65191 - return (__force __le64)*p;
65192 + return (__force const __le64)*p;
65193 }
65194 static inline __u64 __le64_to_cpup(const __le64 *p)
65195 {
65196 - return (__force __u64)*p;
65197 + return (__force const __u64)*p;
65198 }
65199 static inline __le32 __cpu_to_le32p(const __u32 *p)
65200 {
65201 - return (__force __le32)*p;
65202 + return (__force const __le32)*p;
65203 }
65204 static inline __u32 __le32_to_cpup(const __le32 *p)
65205 {
65206 - return (__force __u32)*p;
65207 + return (__force const __u32)*p;
65208 }
65209 static inline __le16 __cpu_to_le16p(const __u16 *p)
65210 {
65211 - return (__force __le16)*p;
65212 + return (__force const __le16)*p;
65213 }
65214 static inline __u16 __le16_to_cpup(const __le16 *p)
65215 {
65216 - return (__force __u16)*p;
65217 + return (__force const __u16)*p;
65218 }
65219 static inline __be64 __cpu_to_be64p(const __u64 *p)
65220 {
65221 - return (__force __be64)__swab64p(p);
65222 + return (__force const __be64)__swab64p(p);
65223 }
65224 static inline __u64 __be64_to_cpup(const __be64 *p)
65225 {
65226 - return __swab64p((__u64 *)p);
65227 + return __swab64p((const __u64 *)p);
65228 }
65229 static inline __be32 __cpu_to_be32p(const __u32 *p)
65230 {
65231 - return (__force __be32)__swab32p(p);
65232 + return (__force const __be32)__swab32p(p);
65233 }
65234 static inline __u32 __be32_to_cpup(const __be32 *p)
65235 {
65236 - return __swab32p((__u32 *)p);
65237 + return __swab32p((const __u32 *)p);
65238 }
65239 static inline __be16 __cpu_to_be16p(const __u16 *p)
65240 {
65241 - return (__force __be16)__swab16p(p);
65242 + return (__force const __be16)__swab16p(p);
65243 }
65244 static inline __u16 __be16_to_cpup(const __be16 *p)
65245 {
65246 - return __swab16p((__u16 *)p);
65247 + return __swab16p((const __u16 *)p);
65248 }
65249 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65250 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65251 diff --git a/include/linux/cache.h b/include/linux/cache.h
65252 index 97e2488..e7576b9 100644
65253 --- a/include/linux/cache.h
65254 +++ b/include/linux/cache.h
65255 @@ -16,6 +16,10 @@
65256 #define __read_mostly
65257 #endif
65258
65259 +#ifndef __read_only
65260 +#define __read_only __read_mostly
65261 +#endif
65262 +
65263 #ifndef ____cacheline_aligned
65264 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
65265 #endif
65266 diff --git a/include/linux/capability.h b/include/linux/capability.h
65267 index c8f2a5f7..1618a5c 100644
65268 --- a/include/linux/capability.h
65269 +++ b/include/linux/capability.h
65270 @@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff_set;
65271 (security_real_capable_noaudit((t), (cap)) == 0)
65272
65273 extern int capable(int cap);
65274 +int capable_nolog(int cap);
65275
65276 /* audit system wants to get cap info from files as well */
65277 struct dentry;
65278 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
65279 index 450fa59..86019fb 100644
65280 --- a/include/linux/compiler-gcc4.h
65281 +++ b/include/linux/compiler-gcc4.h
65282 @@ -36,4 +36,16 @@
65283 the kernel context */
65284 #define __cold __attribute__((__cold__))
65285
65286 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
65287 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
65288 +#define __bos0(ptr) __bos((ptr), 0)
65289 +#define __bos1(ptr) __bos((ptr), 1)
65290 +
65291 +#if __GNUC_MINOR__ >= 5
65292 +#ifdef CONSTIFY_PLUGIN
65293 +#define __no_const __attribute__((no_const))
65294 +#define __do_const __attribute__((do_const))
65295 +#endif
65296 +#endif
65297 +
65298 #endif
65299 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
65300 index 04fb513..fd6477b 100644
65301 --- a/include/linux/compiler.h
65302 +++ b/include/linux/compiler.h
65303 @@ -5,11 +5,14 @@
65304
65305 #ifdef __CHECKER__
65306 # define __user __attribute__((noderef, address_space(1)))
65307 +# define __force_user __force __user
65308 # define __kernel /* default address space */
65309 +# define __force_kernel __force __kernel
65310 # define __safe __attribute__((safe))
65311 # define __force __attribute__((force))
65312 # define __nocast __attribute__((nocast))
65313 # define __iomem __attribute__((noderef, address_space(2)))
65314 +# define __force_iomem __force __iomem
65315 # define __acquires(x) __attribute__((context(x,0,1)))
65316 # define __releases(x) __attribute__((context(x,1,0)))
65317 # define __acquire(x) __context__(x,1)
65318 @@ -17,13 +20,34 @@
65319 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
65320 extern void __chk_user_ptr(const volatile void __user *);
65321 extern void __chk_io_ptr(const volatile void __iomem *);
65322 +#elif defined(CHECKER_PLUGIN)
65323 +//# define __user
65324 +//# define __force_user
65325 +//# define __kernel
65326 +//# define __force_kernel
65327 +# define __safe
65328 +# define __force
65329 +# define __nocast
65330 +# define __iomem
65331 +# define __force_iomem
65332 +# define __chk_user_ptr(x) (void)0
65333 +# define __chk_io_ptr(x) (void)0
65334 +# define __builtin_warning(x, y...) (1)
65335 +# define __acquires(x)
65336 +# define __releases(x)
65337 +# define __acquire(x) (void)0
65338 +# define __release(x) (void)0
65339 +# define __cond_lock(x,c) (c)
65340 #else
65341 # define __user
65342 +# define __force_user
65343 # define __kernel
65344 +# define __force_kernel
65345 # define __safe
65346 # define __force
65347 # define __nocast
65348 # define __iomem
65349 +# define __force_iomem
65350 # define __chk_user_ptr(x) (void)0
65351 # define __chk_io_ptr(x) (void)0
65352 # define __builtin_warning(x, y...) (1)
65353 @@ -247,6 +271,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65354 # define __attribute_const__ /* unimplemented */
65355 #endif
65356
65357 +#ifndef __no_const
65358 +# define __no_const
65359 +#endif
65360 +
65361 +#ifndef __do_const
65362 +# define __do_const
65363 +#endif
65364 +
65365 /*
65366 * Tell gcc if a function is cold. The compiler will assume any path
65367 * directly leading to the call is unlikely.
65368 @@ -256,6 +288,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65369 #define __cold
65370 #endif
65371
65372 +#ifndef __alloc_size
65373 +#define __alloc_size(...)
65374 +#endif
65375 +
65376 +#ifndef __bos
65377 +#define __bos(ptr, arg)
65378 +#endif
65379 +
65380 +#ifndef __bos0
65381 +#define __bos0(ptr)
65382 +#endif
65383 +
65384 +#ifndef __bos1
65385 +#define __bos1(ptr)
65386 +#endif
65387 +
65388 /* Simple shorthand for a section definition */
65389 #ifndef __section
65390 # define __section(S) __attribute__ ((__section__(#S)))
65391 @@ -278,6 +326,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65392 * use is to mediate communication between process-level code and irq/NMI
65393 * handlers, all running on the same CPU.
65394 */
65395 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
65396 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
65397 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
65398
65399 #endif /* __LINUX_COMPILER_H */
65400 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
65401 index fd92988..a3164bd 100644
65402 --- a/include/linux/crypto.h
65403 +++ b/include/linux/crypto.h
65404 @@ -394,7 +394,7 @@ struct cipher_tfm {
65405 const u8 *key, unsigned int keylen);
65406 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65407 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65408 -};
65409 +} __no_const;
65410
65411 struct hash_tfm {
65412 int (*init)(struct hash_desc *desc);
65413 @@ -415,13 +415,13 @@ struct compress_tfm {
65414 int (*cot_decompress)(struct crypto_tfm *tfm,
65415 const u8 *src, unsigned int slen,
65416 u8 *dst, unsigned int *dlen);
65417 -};
65418 +} __no_const;
65419
65420 struct rng_tfm {
65421 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
65422 unsigned int dlen);
65423 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
65424 -};
65425 +} __no_const;
65426
65427 #define crt_ablkcipher crt_u.ablkcipher
65428 #define crt_aead crt_u.aead
65429 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
65430 index 30b93b2..cd7a8db 100644
65431 --- a/include/linux/dcache.h
65432 +++ b/include/linux/dcache.h
65433 @@ -119,6 +119,8 @@ struct dentry {
65434 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
65435 };
65436
65437 +#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
65438 +
65439 /*
65440 * dentry->d_lock spinlock nesting subclasses:
65441 *
65442 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
65443 index 3e9bd6a..f4e1aa0 100644
65444 --- a/include/linux/decompress/mm.h
65445 +++ b/include/linux/decompress/mm.h
65446 @@ -78,7 +78,7 @@ static void free(void *where)
65447 * warnings when not needed (indeed large_malloc / large_free are not
65448 * needed by inflate */
65449
65450 -#define malloc(a) kmalloc(a, GFP_KERNEL)
65451 +#define malloc(a) kmalloc((a), GFP_KERNEL)
65452 #define free(a) kfree(a)
65453
65454 #define large_malloc(a) vmalloc(a)
65455 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
65456 index 91b7618..92a93d32 100644
65457 --- a/include/linux/dma-mapping.h
65458 +++ b/include/linux/dma-mapping.h
65459 @@ -16,51 +16,51 @@ enum dma_data_direction {
65460 };
65461
65462 struct dma_map_ops {
65463 - void* (*alloc_coherent)(struct device *dev, size_t size,
65464 + void* (* const alloc_coherent)(struct device *dev, size_t size,
65465 dma_addr_t *dma_handle, gfp_t gfp);
65466 - void (*free_coherent)(struct device *dev, size_t size,
65467 + void (* const free_coherent)(struct device *dev, size_t size,
65468 void *vaddr, dma_addr_t dma_handle);
65469 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
65470 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
65471 unsigned long offset, size_t size,
65472 enum dma_data_direction dir,
65473 struct dma_attrs *attrs);
65474 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
65475 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
65476 size_t size, enum dma_data_direction dir,
65477 struct dma_attrs *attrs);
65478 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
65479 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
65480 int nents, enum dma_data_direction dir,
65481 struct dma_attrs *attrs);
65482 - void (*unmap_sg)(struct device *dev,
65483 + void (* const unmap_sg)(struct device *dev,
65484 struct scatterlist *sg, int nents,
65485 enum dma_data_direction dir,
65486 struct dma_attrs *attrs);
65487 - void (*sync_single_for_cpu)(struct device *dev,
65488 + void (* const sync_single_for_cpu)(struct device *dev,
65489 dma_addr_t dma_handle, size_t size,
65490 enum dma_data_direction dir);
65491 - void (*sync_single_for_device)(struct device *dev,
65492 + void (* const sync_single_for_device)(struct device *dev,
65493 dma_addr_t dma_handle, size_t size,
65494 enum dma_data_direction dir);
65495 - void (*sync_single_range_for_cpu)(struct device *dev,
65496 + void (* const sync_single_range_for_cpu)(struct device *dev,
65497 dma_addr_t dma_handle,
65498 unsigned long offset,
65499 size_t size,
65500 enum dma_data_direction dir);
65501 - void (*sync_single_range_for_device)(struct device *dev,
65502 + void (* const sync_single_range_for_device)(struct device *dev,
65503 dma_addr_t dma_handle,
65504 unsigned long offset,
65505 size_t size,
65506 enum dma_data_direction dir);
65507 - void (*sync_sg_for_cpu)(struct device *dev,
65508 + void (* const sync_sg_for_cpu)(struct device *dev,
65509 struct scatterlist *sg, int nents,
65510 enum dma_data_direction dir);
65511 - void (*sync_sg_for_device)(struct device *dev,
65512 + void (* const sync_sg_for_device)(struct device *dev,
65513 struct scatterlist *sg, int nents,
65514 enum dma_data_direction dir);
65515 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
65516 - int (*dma_supported)(struct device *dev, u64 mask);
65517 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
65518 + int (* const dma_supported)(struct device *dev, u64 mask);
65519 int (*set_dma_mask)(struct device *dev, u64 mask);
65520 int is_phys;
65521 -};
65522 +} __do_const;
65523
65524 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
65525
65526 diff --git a/include/linux/dst.h b/include/linux/dst.h
65527 index e26fed8..b976d9f 100644
65528 --- a/include/linux/dst.h
65529 +++ b/include/linux/dst.h
65530 @@ -380,7 +380,7 @@ struct dst_node
65531 struct thread_pool *pool;
65532
65533 /* Transaction IDs live here */
65534 - atomic_long_t gen;
65535 + atomic_long_unchecked_t gen;
65536
65537 /*
65538 * How frequently and how many times transaction
65539 diff --git a/include/linux/elf.h b/include/linux/elf.h
65540 index 90a4ed0..d652617 100644
65541 --- a/include/linux/elf.h
65542 +++ b/include/linux/elf.h
65543 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
65544 #define PT_GNU_EH_FRAME 0x6474e550
65545
65546 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65547 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65548 +
65549 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65550 +
65551 +/* Constants for the e_flags field */
65552 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65553 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65554 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65555 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65556 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65557 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65558
65559 /* These constants define the different elf file types */
65560 #define ET_NONE 0
65561 @@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
65562 #define DT_DEBUG 21
65563 #define DT_TEXTREL 22
65564 #define DT_JMPREL 23
65565 +#define DT_FLAGS 30
65566 + #define DF_TEXTREL 0x00000004
65567 #define DT_ENCODING 32
65568 #define OLD_DT_LOOS 0x60000000
65569 #define DT_LOOS 0x6000000d
65570 @@ -230,6 +243,19 @@ typedef struct elf64_hdr {
65571 #define PF_W 0x2
65572 #define PF_X 0x1
65573
65574 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65575 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65576 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65577 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65578 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65579 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65580 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65581 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65582 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65583 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65584 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65585 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65586 +
65587 typedef struct elf32_phdr{
65588 Elf32_Word p_type;
65589 Elf32_Off p_offset;
65590 @@ -322,6 +348,8 @@ typedef struct elf64_shdr {
65591 #define EI_OSABI 7
65592 #define EI_PAD 8
65593
65594 +#define EI_PAX 14
65595 +
65596 #define ELFMAG0 0x7f /* EI_MAG */
65597 #define ELFMAG1 'E'
65598 #define ELFMAG2 'L'
65599 @@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
65600 #define elf_phdr elf32_phdr
65601 #define elf_note elf32_note
65602 #define elf_addr_t Elf32_Off
65603 +#define elf_dyn Elf32_Dyn
65604
65605 #else
65606
65607 @@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
65608 #define elf_phdr elf64_phdr
65609 #define elf_note elf64_note
65610 #define elf_addr_t Elf64_Off
65611 +#define elf_dyn Elf64_Dyn
65612
65613 #endif
65614
65615 diff --git a/include/linux/fs.h b/include/linux/fs.h
65616 index 1b9a47a..6fe2934 100644
65617 --- a/include/linux/fs.h
65618 +++ b/include/linux/fs.h
65619 @@ -568,41 +568,41 @@ typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
65620 unsigned long, unsigned long);
65621
65622 struct address_space_operations {
65623 - int (*writepage)(struct page *page, struct writeback_control *wbc);
65624 - int (*readpage)(struct file *, struct page *);
65625 - void (*sync_page)(struct page *);
65626 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
65627 + int (* const readpage)(struct file *, struct page *);
65628 + void (* const sync_page)(struct page *);
65629
65630 /* Write back some dirty pages from this mapping. */
65631 - int (*writepages)(struct address_space *, struct writeback_control *);
65632 + int (* const writepages)(struct address_space *, struct writeback_control *);
65633
65634 /* Set a page dirty. Return true if this dirtied it */
65635 - int (*set_page_dirty)(struct page *page);
65636 + int (* const set_page_dirty)(struct page *page);
65637
65638 - int (*readpages)(struct file *filp, struct address_space *mapping,
65639 + int (* const readpages)(struct file *filp, struct address_space *mapping,
65640 struct list_head *pages, unsigned nr_pages);
65641
65642 - int (*write_begin)(struct file *, struct address_space *mapping,
65643 + int (* const write_begin)(struct file *, struct address_space *mapping,
65644 loff_t pos, unsigned len, unsigned flags,
65645 struct page **pagep, void **fsdata);
65646 - int (*write_end)(struct file *, struct address_space *mapping,
65647 + int (* const write_end)(struct file *, struct address_space *mapping,
65648 loff_t pos, unsigned len, unsigned copied,
65649 struct page *page, void *fsdata);
65650
65651 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
65652 - sector_t (*bmap)(struct address_space *, sector_t);
65653 - void (*invalidatepage) (struct page *, unsigned long);
65654 - int (*releasepage) (struct page *, gfp_t);
65655 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
65656 + sector_t (* const bmap)(struct address_space *, sector_t);
65657 + void (* const invalidatepage) (struct page *, unsigned long);
65658 + int (* const releasepage) (struct page *, gfp_t);
65659 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
65660 loff_t offset, unsigned long nr_segs);
65661 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
65662 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
65663 void **, unsigned long *);
65664 /* migrate the contents of a page to the specified target */
65665 - int (*migratepage) (struct address_space *,
65666 + int (* const migratepage) (struct address_space *,
65667 struct page *, struct page *);
65668 - int (*launder_page) (struct page *);
65669 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
65670 + int (* const launder_page) (struct page *);
65671 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
65672 unsigned long);
65673 - int (*error_remove_page)(struct address_space *, struct page *);
65674 + int (* const error_remove_page)(struct address_space *, struct page *);
65675 };
65676
65677 /*
65678 @@ -1031,19 +1031,19 @@ static inline int file_check_writeable(struct file *filp)
65679 typedef struct files_struct *fl_owner_t;
65680
65681 struct file_lock_operations {
65682 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65683 - void (*fl_release_private)(struct file_lock *);
65684 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65685 + void (* const fl_release_private)(struct file_lock *);
65686 };
65687
65688 struct lock_manager_operations {
65689 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
65690 - void (*fl_notify)(struct file_lock *); /* unblock callback */
65691 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
65692 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65693 - void (*fl_release_private)(struct file_lock *);
65694 - void (*fl_break)(struct file_lock *);
65695 - int (*fl_mylease)(struct file_lock *, struct file_lock *);
65696 - int (*fl_change)(struct file_lock **, int);
65697 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
65698 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
65699 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
65700 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65701 + void (* const fl_release_private)(struct file_lock *);
65702 + void (* const fl_break)(struct file_lock *);
65703 + int (* const fl_mylease)(struct file_lock *, struct file_lock *);
65704 + int (* const fl_change)(struct file_lock **, int);
65705 };
65706
65707 struct lock_manager {
65708 @@ -1442,7 +1442,7 @@ struct fiemap_extent_info {
65709 unsigned int fi_flags; /* Flags as passed from user */
65710 unsigned int fi_extents_mapped; /* Number of mapped extents */
65711 unsigned int fi_extents_max; /* Size of fiemap_extent array */
65712 - struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
65713 + struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
65714 * array */
65715 };
65716 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
65717 @@ -1512,7 +1512,8 @@ struct file_operations {
65718 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
65719 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
65720 int (*setlease)(struct file *, long, struct file_lock **);
65721 -};
65722 +} __do_const;
65723 +typedef struct file_operations __no_const file_operations_no_const;
65724
65725 struct inode_operations {
65726 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
65727 @@ -1559,30 +1560,30 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
65728 unsigned long, loff_t *);
65729
65730 struct super_operations {
65731 - struct inode *(*alloc_inode)(struct super_block *sb);
65732 - void (*destroy_inode)(struct inode *);
65733 + struct inode *(* const alloc_inode)(struct super_block *sb);
65734 + void (* const destroy_inode)(struct inode *);
65735
65736 - void (*dirty_inode) (struct inode *);
65737 - int (*write_inode) (struct inode *, int);
65738 - void (*drop_inode) (struct inode *);
65739 - void (*delete_inode) (struct inode *);
65740 - void (*put_super) (struct super_block *);
65741 - void (*write_super) (struct super_block *);
65742 - int (*sync_fs)(struct super_block *sb, int wait);
65743 - int (*freeze_fs) (struct super_block *);
65744 - int (*unfreeze_fs) (struct super_block *);
65745 - int (*statfs) (struct dentry *, struct kstatfs *);
65746 - int (*remount_fs) (struct super_block *, int *, char *);
65747 - void (*clear_inode) (struct inode *);
65748 - void (*umount_begin) (struct super_block *);
65749 + void (* const dirty_inode) (struct inode *);
65750 + int (* const write_inode) (struct inode *, int);
65751 + void (* const drop_inode) (struct inode *);
65752 + void (* const delete_inode) (struct inode *);
65753 + void (* const put_super) (struct super_block *);
65754 + void (* const write_super) (struct super_block *);
65755 + int (* const sync_fs)(struct super_block *sb, int wait);
65756 + int (* const freeze_fs) (struct super_block *);
65757 + int (* const unfreeze_fs) (struct super_block *);
65758 + int (* const statfs) (struct dentry *, struct kstatfs *);
65759 + int (* const remount_fs) (struct super_block *, int *, char *);
65760 + void (* const clear_inode) (struct inode *);
65761 + void (* const umount_begin) (struct super_block *);
65762
65763 - int (*show_options)(struct seq_file *, struct vfsmount *);
65764 - int (*show_stats)(struct seq_file *, struct vfsmount *);
65765 + int (* const show_options)(struct seq_file *, struct vfsmount *);
65766 + int (* const show_stats)(struct seq_file *, struct vfsmount *);
65767 #ifdef CONFIG_QUOTA
65768 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
65769 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
65770 + ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
65771 + ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
65772 #endif
65773 - int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
65774 + int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
65775 };
65776
65777 /*
65778 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
65779 index 78a05bf..2a7d3e1 100644
65780 --- a/include/linux/fs_struct.h
65781 +++ b/include/linux/fs_struct.h
65782 @@ -4,7 +4,7 @@
65783 #include <linux/path.h>
65784
65785 struct fs_struct {
65786 - int users;
65787 + atomic_t users;
65788 rwlock_t lock;
65789 int umask;
65790 int in_exec;
65791 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
65792 index 7be0c6f..2f63a2b 100644
65793 --- a/include/linux/fscache-cache.h
65794 +++ b/include/linux/fscache-cache.h
65795 @@ -116,7 +116,7 @@ struct fscache_operation {
65796 #endif
65797 };
65798
65799 -extern atomic_t fscache_op_debug_id;
65800 +extern atomic_unchecked_t fscache_op_debug_id;
65801 extern const struct slow_work_ops fscache_op_slow_work_ops;
65802
65803 extern void fscache_enqueue_operation(struct fscache_operation *);
65804 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
65805 fscache_operation_release_t release)
65806 {
65807 atomic_set(&op->usage, 1);
65808 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
65809 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
65810 op->release = release;
65811 INIT_LIST_HEAD(&op->pend_link);
65812 fscache_set_op_state(op, "Init");
65813 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
65814 index 4ec5e67..42f1eb9 100644
65815 --- a/include/linux/ftrace_event.h
65816 +++ b/include/linux/ftrace_event.h
65817 @@ -163,7 +163,7 @@ extern int trace_define_field(struct ftrace_event_call *call,
65818 int filter_type);
65819 extern int trace_define_common_fields(struct ftrace_event_call *call);
65820
65821 -#define is_signed_type(type) (((type)(-1)) < 0)
65822 +#define is_signed_type(type) (((type)(-1)) < (type)1)
65823
65824 int trace_set_clr_event(const char *system, const char *event, int set);
65825
65826 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
65827 index 297df45..b6a74ff 100644
65828 --- a/include/linux/genhd.h
65829 +++ b/include/linux/genhd.h
65830 @@ -161,7 +161,7 @@ struct gendisk {
65831
65832 struct timer_rand_state *random;
65833
65834 - atomic_t sync_io; /* RAID */
65835 + atomic_unchecked_t sync_io; /* RAID */
65836 struct work_struct async_notify;
65837 #ifdef CONFIG_BLK_DEV_INTEGRITY
65838 struct blk_integrity *integrity;
65839 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
65840 new file mode 100644
65841 index 0000000..0dc3943
65842 --- /dev/null
65843 +++ b/include/linux/gracl.h
65844 @@ -0,0 +1,317 @@
65845 +#ifndef GR_ACL_H
65846 +#define GR_ACL_H
65847 +
65848 +#include <linux/grdefs.h>
65849 +#include <linux/resource.h>
65850 +#include <linux/capability.h>
65851 +#include <linux/dcache.h>
65852 +#include <asm/resource.h>
65853 +
65854 +/* Major status information */
65855 +
65856 +#define GR_VERSION "grsecurity 2.2.2"
65857 +#define GRSECURITY_VERSION 0x2202
65858 +
65859 +enum {
65860 + GR_SHUTDOWN = 0,
65861 + GR_ENABLE = 1,
65862 + GR_SPROLE = 2,
65863 + GR_RELOAD = 3,
65864 + GR_SEGVMOD = 4,
65865 + GR_STATUS = 5,
65866 + GR_UNSPROLE = 6,
65867 + GR_PASSSET = 7,
65868 + GR_SPROLEPAM = 8,
65869 +};
65870 +
65871 +/* Password setup definitions
65872 + * kernel/grhash.c */
65873 +enum {
65874 + GR_PW_LEN = 128,
65875 + GR_SALT_LEN = 16,
65876 + GR_SHA_LEN = 32,
65877 +};
65878 +
65879 +enum {
65880 + GR_SPROLE_LEN = 64,
65881 +};
65882 +
65883 +enum {
65884 + GR_NO_GLOB = 0,
65885 + GR_REG_GLOB,
65886 + GR_CREATE_GLOB
65887 +};
65888 +
65889 +#define GR_NLIMITS 32
65890 +
65891 +/* Begin Data Structures */
65892 +
65893 +struct sprole_pw {
65894 + unsigned char *rolename;
65895 + unsigned char salt[GR_SALT_LEN];
65896 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
65897 +};
65898 +
65899 +struct name_entry {
65900 + __u32 key;
65901 + ino_t inode;
65902 + dev_t device;
65903 + char *name;
65904 + __u16 len;
65905 + __u8 deleted;
65906 + struct name_entry *prev;
65907 + struct name_entry *next;
65908 +};
65909 +
65910 +struct inodev_entry {
65911 + struct name_entry *nentry;
65912 + struct inodev_entry *prev;
65913 + struct inodev_entry *next;
65914 +};
65915 +
65916 +struct acl_role_db {
65917 + struct acl_role_label **r_hash;
65918 + __u32 r_size;
65919 +};
65920 +
65921 +struct inodev_db {
65922 + struct inodev_entry **i_hash;
65923 + __u32 i_size;
65924 +};
65925 +
65926 +struct name_db {
65927 + struct name_entry **n_hash;
65928 + __u32 n_size;
65929 +};
65930 +
65931 +struct crash_uid {
65932 + uid_t uid;
65933 + unsigned long expires;
65934 +};
65935 +
65936 +struct gr_hash_struct {
65937 + void **table;
65938 + void **nametable;
65939 + void *first;
65940 + __u32 table_size;
65941 + __u32 used_size;
65942 + int type;
65943 +};
65944 +
65945 +/* Userspace Grsecurity ACL data structures */
65946 +
65947 +struct acl_subject_label {
65948 + char *filename;
65949 + ino_t inode;
65950 + dev_t device;
65951 + __u32 mode;
65952 + kernel_cap_t cap_mask;
65953 + kernel_cap_t cap_lower;
65954 + kernel_cap_t cap_invert_audit;
65955 +
65956 + struct rlimit res[GR_NLIMITS];
65957 + __u32 resmask;
65958 +
65959 + __u8 user_trans_type;
65960 + __u8 group_trans_type;
65961 + uid_t *user_transitions;
65962 + gid_t *group_transitions;
65963 + __u16 user_trans_num;
65964 + __u16 group_trans_num;
65965 +
65966 + __u32 sock_families[2];
65967 + __u32 ip_proto[8];
65968 + __u32 ip_type;
65969 + struct acl_ip_label **ips;
65970 + __u32 ip_num;
65971 + __u32 inaddr_any_override;
65972 +
65973 + __u32 crashes;
65974 + unsigned long expires;
65975 +
65976 + struct acl_subject_label *parent_subject;
65977 + struct gr_hash_struct *hash;
65978 + struct acl_subject_label *prev;
65979 + struct acl_subject_label *next;
65980 +
65981 + struct acl_object_label **obj_hash;
65982 + __u32 obj_hash_size;
65983 + __u16 pax_flags;
65984 +};
65985 +
65986 +struct role_allowed_ip {
65987 + __u32 addr;
65988 + __u32 netmask;
65989 +
65990 + struct role_allowed_ip *prev;
65991 + struct role_allowed_ip *next;
65992 +};
65993 +
65994 +struct role_transition {
65995 + char *rolename;
65996 +
65997 + struct role_transition *prev;
65998 + struct role_transition *next;
65999 +};
66000 +
66001 +struct acl_role_label {
66002 + char *rolename;
66003 + uid_t uidgid;
66004 + __u16 roletype;
66005 +
66006 + __u16 auth_attempts;
66007 + unsigned long expires;
66008 +
66009 + struct acl_subject_label *root_label;
66010 + struct gr_hash_struct *hash;
66011 +
66012 + struct acl_role_label *prev;
66013 + struct acl_role_label *next;
66014 +
66015 + struct role_transition *transitions;
66016 + struct role_allowed_ip *allowed_ips;
66017 + uid_t *domain_children;
66018 + __u16 domain_child_num;
66019 +
66020 + struct acl_subject_label **subj_hash;
66021 + __u32 subj_hash_size;
66022 +};
66023 +
66024 +struct user_acl_role_db {
66025 + struct acl_role_label **r_table;
66026 + __u32 num_pointers; /* Number of allocations to track */
66027 + __u32 num_roles; /* Number of roles */
66028 + __u32 num_domain_children; /* Number of domain children */
66029 + __u32 num_subjects; /* Number of subjects */
66030 + __u32 num_objects; /* Number of objects */
66031 +};
66032 +
66033 +struct acl_object_label {
66034 + char *filename;
66035 + ino_t inode;
66036 + dev_t device;
66037 + __u32 mode;
66038 +
66039 + struct acl_subject_label *nested;
66040 + struct acl_object_label *globbed;
66041 +
66042 + /* next two structures not used */
66043 +
66044 + struct acl_object_label *prev;
66045 + struct acl_object_label *next;
66046 +};
66047 +
66048 +struct acl_ip_label {
66049 + char *iface;
66050 + __u32 addr;
66051 + __u32 netmask;
66052 + __u16 low, high;
66053 + __u8 mode;
66054 + __u32 type;
66055 + __u32 proto[8];
66056 +
66057 + /* next two structures not used */
66058 +
66059 + struct acl_ip_label *prev;
66060 + struct acl_ip_label *next;
66061 +};
66062 +
66063 +struct gr_arg {
66064 + struct user_acl_role_db role_db;
66065 + unsigned char pw[GR_PW_LEN];
66066 + unsigned char salt[GR_SALT_LEN];
66067 + unsigned char sum[GR_SHA_LEN];
66068 + unsigned char sp_role[GR_SPROLE_LEN];
66069 + struct sprole_pw *sprole_pws;
66070 + dev_t segv_device;
66071 + ino_t segv_inode;
66072 + uid_t segv_uid;
66073 + __u16 num_sprole_pws;
66074 + __u16 mode;
66075 +};
66076 +
66077 +struct gr_arg_wrapper {
66078 + struct gr_arg *arg;
66079 + __u32 version;
66080 + __u32 size;
66081 +};
66082 +
66083 +struct subject_map {
66084 + struct acl_subject_label *user;
66085 + struct acl_subject_label *kernel;
66086 + struct subject_map *prev;
66087 + struct subject_map *next;
66088 +};
66089 +
66090 +struct acl_subj_map_db {
66091 + struct subject_map **s_hash;
66092 + __u32 s_size;
66093 +};
66094 +
66095 +/* End Data Structures Section */
66096 +
66097 +/* Hash functions generated by empirical testing by Brad Spengler
66098 + Makes good use of the low bits of the inode. Generally 0-1 times
66099 + in loop for successful match. 0-3 for unsuccessful match.
66100 + Shift/add algorithm with modulus of table size and an XOR*/
66101 +
66102 +static __inline__ unsigned int
66103 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
66104 +{
66105 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
66106 +}
66107 +
66108 + static __inline__ unsigned int
66109 +shash(const struct acl_subject_label *userp, const unsigned int sz)
66110 +{
66111 + return ((const unsigned long)userp % sz);
66112 +}
66113 +
66114 +static __inline__ unsigned int
66115 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
66116 +{
66117 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
66118 +}
66119 +
66120 +static __inline__ unsigned int
66121 +nhash(const char *name, const __u16 len, const unsigned int sz)
66122 +{
66123 + return full_name_hash((const unsigned char *)name, len) % sz;
66124 +}
66125 +
66126 +#define FOR_EACH_ROLE_START(role) \
66127 + role = role_list; \
66128 + while (role) {
66129 +
66130 +#define FOR_EACH_ROLE_END(role) \
66131 + role = role->prev; \
66132 + }
66133 +
66134 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
66135 + subj = NULL; \
66136 + iter = 0; \
66137 + while (iter < role->subj_hash_size) { \
66138 + if (subj == NULL) \
66139 + subj = role->subj_hash[iter]; \
66140 + if (subj == NULL) { \
66141 + iter++; \
66142 + continue; \
66143 + }
66144 +
66145 +#define FOR_EACH_SUBJECT_END(subj,iter) \
66146 + subj = subj->next; \
66147 + if (subj == NULL) \
66148 + iter++; \
66149 + }
66150 +
66151 +
66152 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
66153 + subj = role->hash->first; \
66154 + while (subj != NULL) {
66155 +
66156 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
66157 + subj = subj->next; \
66158 + }
66159 +
66160 +#endif
66161 +
66162 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
66163 new file mode 100644
66164 index 0000000..323ecf2
66165 --- /dev/null
66166 +++ b/include/linux/gralloc.h
66167 @@ -0,0 +1,9 @@
66168 +#ifndef __GRALLOC_H
66169 +#define __GRALLOC_H
66170 +
66171 +void acl_free_all(void);
66172 +int acl_alloc_stack_init(unsigned long size);
66173 +void *acl_alloc(unsigned long len);
66174 +void *acl_alloc_num(unsigned long num, unsigned long len);
66175 +
66176 +#endif
66177 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
66178 new file mode 100644
66179 index 0000000..70d6cd5
66180 --- /dev/null
66181 +++ b/include/linux/grdefs.h
66182 @@ -0,0 +1,140 @@
66183 +#ifndef GRDEFS_H
66184 +#define GRDEFS_H
66185 +
66186 +/* Begin grsecurity status declarations */
66187 +
66188 +enum {
66189 + GR_READY = 0x01,
66190 + GR_STATUS_INIT = 0x00 // disabled state
66191 +};
66192 +
66193 +/* Begin ACL declarations */
66194 +
66195 +/* Role flags */
66196 +
66197 +enum {
66198 + GR_ROLE_USER = 0x0001,
66199 + GR_ROLE_GROUP = 0x0002,
66200 + GR_ROLE_DEFAULT = 0x0004,
66201 + GR_ROLE_SPECIAL = 0x0008,
66202 + GR_ROLE_AUTH = 0x0010,
66203 + GR_ROLE_NOPW = 0x0020,
66204 + GR_ROLE_GOD = 0x0040,
66205 + GR_ROLE_LEARN = 0x0080,
66206 + GR_ROLE_TPE = 0x0100,
66207 + GR_ROLE_DOMAIN = 0x0200,
66208 + GR_ROLE_PAM = 0x0400,
66209 + GR_ROLE_PERSIST = 0x800
66210 +};
66211 +
66212 +/* ACL Subject and Object mode flags */
66213 +enum {
66214 + GR_DELETED = 0x80000000
66215 +};
66216 +
66217 +/* ACL Object-only mode flags */
66218 +enum {
66219 + GR_READ = 0x00000001,
66220 + GR_APPEND = 0x00000002,
66221 + GR_WRITE = 0x00000004,
66222 + GR_EXEC = 0x00000008,
66223 + GR_FIND = 0x00000010,
66224 + GR_INHERIT = 0x00000020,
66225 + GR_SETID = 0x00000040,
66226 + GR_CREATE = 0x00000080,
66227 + GR_DELETE = 0x00000100,
66228 + GR_LINK = 0x00000200,
66229 + GR_AUDIT_READ = 0x00000400,
66230 + GR_AUDIT_APPEND = 0x00000800,
66231 + GR_AUDIT_WRITE = 0x00001000,
66232 + GR_AUDIT_EXEC = 0x00002000,
66233 + GR_AUDIT_FIND = 0x00004000,
66234 + GR_AUDIT_INHERIT= 0x00008000,
66235 + GR_AUDIT_SETID = 0x00010000,
66236 + GR_AUDIT_CREATE = 0x00020000,
66237 + GR_AUDIT_DELETE = 0x00040000,
66238 + GR_AUDIT_LINK = 0x00080000,
66239 + GR_PTRACERD = 0x00100000,
66240 + GR_NOPTRACE = 0x00200000,
66241 + GR_SUPPRESS = 0x00400000,
66242 + GR_NOLEARN = 0x00800000,
66243 + GR_INIT_TRANSFER= 0x01000000
66244 +};
66245 +
66246 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
66247 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
66248 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
66249 +
66250 +/* ACL subject-only mode flags */
66251 +enum {
66252 + GR_KILL = 0x00000001,
66253 + GR_VIEW = 0x00000002,
66254 + GR_PROTECTED = 0x00000004,
66255 + GR_LEARN = 0x00000008,
66256 + GR_OVERRIDE = 0x00000010,
66257 + /* just a placeholder, this mode is only used in userspace */
66258 + GR_DUMMY = 0x00000020,
66259 + GR_PROTSHM = 0x00000040,
66260 + GR_KILLPROC = 0x00000080,
66261 + GR_KILLIPPROC = 0x00000100,
66262 + /* just a placeholder, this mode is only used in userspace */
66263 + GR_NOTROJAN = 0x00000200,
66264 + GR_PROTPROCFD = 0x00000400,
66265 + GR_PROCACCT = 0x00000800,
66266 + GR_RELAXPTRACE = 0x00001000,
66267 + GR_NESTED = 0x00002000,
66268 + GR_INHERITLEARN = 0x00004000,
66269 + GR_PROCFIND = 0x00008000,
66270 + GR_POVERRIDE = 0x00010000,
66271 + GR_KERNELAUTH = 0x00020000,
66272 + GR_ATSECURE = 0x00040000,
66273 + GR_SHMEXEC = 0x00080000
66274 +};
66275 +
66276 +enum {
66277 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
66278 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
66279 + GR_PAX_ENABLE_MPROTECT = 0x0004,
66280 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
66281 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
66282 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
66283 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
66284 + GR_PAX_DISABLE_MPROTECT = 0x0400,
66285 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
66286 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
66287 +};
66288 +
66289 +enum {
66290 + GR_ID_USER = 0x01,
66291 + GR_ID_GROUP = 0x02,
66292 +};
66293 +
66294 +enum {
66295 + GR_ID_ALLOW = 0x01,
66296 + GR_ID_DENY = 0x02,
66297 +};
66298 +
66299 +#define GR_CRASH_RES 31
66300 +#define GR_UIDTABLE_MAX 500
66301 +
66302 +/* begin resource learning section */
66303 +enum {
66304 + GR_RLIM_CPU_BUMP = 60,
66305 + GR_RLIM_FSIZE_BUMP = 50000,
66306 + GR_RLIM_DATA_BUMP = 10000,
66307 + GR_RLIM_STACK_BUMP = 1000,
66308 + GR_RLIM_CORE_BUMP = 10000,
66309 + GR_RLIM_RSS_BUMP = 500000,
66310 + GR_RLIM_NPROC_BUMP = 1,
66311 + GR_RLIM_NOFILE_BUMP = 5,
66312 + GR_RLIM_MEMLOCK_BUMP = 50000,
66313 + GR_RLIM_AS_BUMP = 500000,
66314 + GR_RLIM_LOCKS_BUMP = 2,
66315 + GR_RLIM_SIGPENDING_BUMP = 5,
66316 + GR_RLIM_MSGQUEUE_BUMP = 10000,
66317 + GR_RLIM_NICE_BUMP = 1,
66318 + GR_RLIM_RTPRIO_BUMP = 1,
66319 + GR_RLIM_RTTIME_BUMP = 1000000
66320 +};
66321 +
66322 +#endif
66323 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
66324 new file mode 100644
66325 index 0000000..e5817d7
66326 --- /dev/null
66327 +++ b/include/linux/grinternal.h
66328 @@ -0,0 +1,218 @@
66329 +#ifndef __GRINTERNAL_H
66330 +#define __GRINTERNAL_H
66331 +
66332 +#ifdef CONFIG_GRKERNSEC
66333 +
66334 +#include <linux/fs.h>
66335 +#include <linux/mnt_namespace.h>
66336 +#include <linux/nsproxy.h>
66337 +#include <linux/gracl.h>
66338 +#include <linux/grdefs.h>
66339 +#include <linux/grmsg.h>
66340 +
66341 +void gr_add_learn_entry(const char *fmt, ...)
66342 + __attribute__ ((format (printf, 1, 2)));
66343 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
66344 + const struct vfsmount *mnt);
66345 +__u32 gr_check_create(const struct dentry *new_dentry,
66346 + const struct dentry *parent,
66347 + const struct vfsmount *mnt, const __u32 mode);
66348 +int gr_check_protected_task(const struct task_struct *task);
66349 +__u32 to_gr_audit(const __u32 reqmode);
66350 +int gr_set_acls(const int type);
66351 +int gr_apply_subject_to_task(struct task_struct *task);
66352 +int gr_acl_is_enabled(void);
66353 +char gr_roletype_to_char(void);
66354 +
66355 +void gr_handle_alertkill(struct task_struct *task);
66356 +char *gr_to_filename(const struct dentry *dentry,
66357 + const struct vfsmount *mnt);
66358 +char *gr_to_filename1(const struct dentry *dentry,
66359 + const struct vfsmount *mnt);
66360 +char *gr_to_filename2(const struct dentry *dentry,
66361 + const struct vfsmount *mnt);
66362 +char *gr_to_filename3(const struct dentry *dentry,
66363 + const struct vfsmount *mnt);
66364 +
66365 +extern int grsec_enable_harden_ptrace;
66366 +extern int grsec_enable_link;
66367 +extern int grsec_enable_fifo;
66368 +extern int grsec_enable_shm;
66369 +extern int grsec_enable_execlog;
66370 +extern int grsec_enable_signal;
66371 +extern int grsec_enable_audit_ptrace;
66372 +extern int grsec_enable_forkfail;
66373 +extern int grsec_enable_time;
66374 +extern int grsec_enable_rofs;
66375 +extern int grsec_enable_chroot_shmat;
66376 +extern int grsec_enable_chroot_mount;
66377 +extern int grsec_enable_chroot_double;
66378 +extern int grsec_enable_chroot_pivot;
66379 +extern int grsec_enable_chroot_chdir;
66380 +extern int grsec_enable_chroot_chmod;
66381 +extern int grsec_enable_chroot_mknod;
66382 +extern int grsec_enable_chroot_fchdir;
66383 +extern int grsec_enable_chroot_nice;
66384 +extern int grsec_enable_chroot_execlog;
66385 +extern int grsec_enable_chroot_caps;
66386 +extern int grsec_enable_chroot_sysctl;
66387 +extern int grsec_enable_chroot_unix;
66388 +extern int grsec_enable_tpe;
66389 +extern int grsec_tpe_gid;
66390 +extern int grsec_enable_tpe_all;
66391 +extern int grsec_enable_tpe_invert;
66392 +extern int grsec_enable_socket_all;
66393 +extern int grsec_socket_all_gid;
66394 +extern int grsec_enable_socket_client;
66395 +extern int grsec_socket_client_gid;
66396 +extern int grsec_enable_socket_server;
66397 +extern int grsec_socket_server_gid;
66398 +extern int grsec_audit_gid;
66399 +extern int grsec_enable_group;
66400 +extern int grsec_enable_audit_textrel;
66401 +extern int grsec_enable_log_rwxmaps;
66402 +extern int grsec_enable_mount;
66403 +extern int grsec_enable_chdir;
66404 +extern int grsec_resource_logging;
66405 +extern int grsec_enable_blackhole;
66406 +extern int grsec_lastack_retries;
66407 +extern int grsec_enable_brute;
66408 +extern int grsec_lock;
66409 +
66410 +extern spinlock_t grsec_alert_lock;
66411 +extern unsigned long grsec_alert_wtime;
66412 +extern unsigned long grsec_alert_fyet;
66413 +
66414 +extern spinlock_t grsec_audit_lock;
66415 +
66416 +extern rwlock_t grsec_exec_file_lock;
66417 +
66418 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
66419 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
66420 + (tsk)->exec_file->f_vfsmnt) : "/")
66421 +
66422 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
66423 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
66424 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66425 +
66426 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
66427 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
66428 + (tsk)->exec_file->f_vfsmnt) : "/")
66429 +
66430 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
66431 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
66432 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66433 +
66434 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
66435 +
66436 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
66437 +
66438 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
66439 + (task)->pid, (cred)->uid, \
66440 + (cred)->euid, (cred)->gid, (cred)->egid, \
66441 + gr_parent_task_fullpath(task), \
66442 + (task)->real_parent->comm, (task)->real_parent->pid, \
66443 + (pcred)->uid, (pcred)->euid, \
66444 + (pcred)->gid, (pcred)->egid
66445 +
66446 +#define GR_CHROOT_CAPS {{ \
66447 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
66448 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
66449 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
66450 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
66451 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
66452 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
66453 + CAP_TO_MASK(CAP_MAC_ADMIN) }}
66454 +
66455 +#define security_learn(normal_msg,args...) \
66456 +({ \
66457 + read_lock(&grsec_exec_file_lock); \
66458 + gr_add_learn_entry(normal_msg "\n", ## args); \
66459 + read_unlock(&grsec_exec_file_lock); \
66460 +})
66461 +
66462 +enum {
66463 + GR_DO_AUDIT,
66464 + GR_DONT_AUDIT,
66465 + GR_DONT_AUDIT_GOOD
66466 +};
66467 +
66468 +enum {
66469 + GR_TTYSNIFF,
66470 + GR_RBAC,
66471 + GR_RBAC_STR,
66472 + GR_STR_RBAC,
66473 + GR_RBAC_MODE2,
66474 + GR_RBAC_MODE3,
66475 + GR_FILENAME,
66476 + GR_SYSCTL_HIDDEN,
66477 + GR_NOARGS,
66478 + GR_ONE_INT,
66479 + GR_ONE_INT_TWO_STR,
66480 + GR_ONE_STR,
66481 + GR_STR_INT,
66482 + GR_TWO_STR_INT,
66483 + GR_TWO_INT,
66484 + GR_TWO_U64,
66485 + GR_THREE_INT,
66486 + GR_FIVE_INT_TWO_STR,
66487 + GR_TWO_STR,
66488 + GR_THREE_STR,
66489 + GR_FOUR_STR,
66490 + GR_STR_FILENAME,
66491 + GR_FILENAME_STR,
66492 + GR_FILENAME_TWO_INT,
66493 + GR_FILENAME_TWO_INT_STR,
66494 + GR_TEXTREL,
66495 + GR_PTRACE,
66496 + GR_RESOURCE,
66497 + GR_CAP,
66498 + GR_SIG,
66499 + GR_SIG2,
66500 + GR_CRASH1,
66501 + GR_CRASH2,
66502 + GR_PSACCT,
66503 + GR_RWXMAP
66504 +};
66505 +
66506 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
66507 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
66508 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
66509 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
66510 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
66511 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
66512 +#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)
66513 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
66514 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
66515 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
66516 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
66517 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
66518 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
66519 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
66520 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
66521 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
66522 +#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)
66523 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
66524 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
66525 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
66526 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
66527 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
66528 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
66529 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
66530 +#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)
66531 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
66532 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
66533 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
66534 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
66535 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
66536 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
66537 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
66538 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
66539 +#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)
66540 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
66541 +
66542 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
66543 +
66544 +#endif
66545 +
66546 +#endif
66547 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
66548 new file mode 100644
66549 index 0000000..9d5fd4a
66550 --- /dev/null
66551 +++ b/include/linux/grmsg.h
66552 @@ -0,0 +1,108 @@
66553 +#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"
66554 +#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"
66555 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
66556 +#define GR_STOPMOD_MSG "denied modification of module state by "
66557 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
66558 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
66559 +#define GR_IOPERM_MSG "denied use of ioperm() by "
66560 +#define GR_IOPL_MSG "denied use of iopl() by "
66561 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
66562 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
66563 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
66564 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
66565 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
66566 +#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"
66567 +#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"
66568 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
66569 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
66570 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
66571 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
66572 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
66573 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
66574 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
66575 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
66576 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
66577 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
66578 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
66579 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
66580 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
66581 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
66582 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
66583 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
66584 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
66585 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
66586 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
66587 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
66588 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
66589 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
66590 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
66591 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
66592 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
66593 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
66594 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
66595 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
66596 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
66597 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
66598 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
66599 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
66600 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
66601 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
66602 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
66603 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
66604 +#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"
66605 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
66606 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
66607 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
66608 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
66609 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
66610 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
66611 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
66612 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
66613 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
66614 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
66615 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
66616 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
66617 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
66618 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
66619 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
66620 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
66621 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
66622 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
66623 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
66624 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
66625 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
66626 +#define GR_NICE_CHROOT_MSG "denied priority change by "
66627 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
66628 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
66629 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
66630 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
66631 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
66632 +#define GR_TIME_MSG "time set by "
66633 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
66634 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
66635 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
66636 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
66637 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
66638 +#define GR_BIND_MSG "denied bind() by "
66639 +#define GR_CONNECT_MSG "denied connect() by "
66640 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
66641 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
66642 +#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"
66643 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
66644 +#define GR_CAP_ACL_MSG "use of %s denied for "
66645 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
66646 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
66647 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
66648 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
66649 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
66650 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
66651 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
66652 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
66653 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
66654 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
66655 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
66656 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
66657 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
66658 +#define GR_VM86_MSG "denied use of vm86 by "
66659 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
66660 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
66661 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
66662 new file mode 100644
66663 index 0000000..24676f4
66664 --- /dev/null
66665 +++ b/include/linux/grsecurity.h
66666 @@ -0,0 +1,218 @@
66667 +#ifndef GR_SECURITY_H
66668 +#define GR_SECURITY_H
66669 +#include <linux/fs.h>
66670 +#include <linux/fs_struct.h>
66671 +#include <linux/binfmts.h>
66672 +#include <linux/gracl.h>
66673 +#include <linux/compat.h>
66674 +
66675 +/* notify of brain-dead configs */
66676 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66677 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
66678 +#endif
66679 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
66680 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
66681 +#endif
66682 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66683 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66684 +#endif
66685 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66686 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66687 +#endif
66688 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
66689 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
66690 +#endif
66691 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
66692 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
66693 +#endif
66694 +
66695 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
66696 +void gr_handle_brute_check(void);
66697 +void gr_handle_kernel_exploit(void);
66698 +int gr_process_user_ban(void);
66699 +
66700 +char gr_roletype_to_char(void);
66701 +
66702 +int gr_acl_enable_at_secure(void);
66703 +
66704 +int gr_check_user_change(int real, int effective, int fs);
66705 +int gr_check_group_change(int real, int effective, int fs);
66706 +
66707 +void gr_del_task_from_ip_table(struct task_struct *p);
66708 +
66709 +int gr_pid_is_chrooted(struct task_struct *p);
66710 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
66711 +int gr_handle_chroot_nice(void);
66712 +int gr_handle_chroot_sysctl(const int op);
66713 +int gr_handle_chroot_setpriority(struct task_struct *p,
66714 + const int niceval);
66715 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
66716 +int gr_handle_chroot_chroot(const struct dentry *dentry,
66717 + const struct vfsmount *mnt);
66718 +void gr_handle_chroot_chdir(struct path *path);
66719 +int gr_handle_chroot_chmod(const struct dentry *dentry,
66720 + const struct vfsmount *mnt, const int mode);
66721 +int gr_handle_chroot_mknod(const struct dentry *dentry,
66722 + const struct vfsmount *mnt, const int mode);
66723 +int gr_handle_chroot_mount(const struct dentry *dentry,
66724 + const struct vfsmount *mnt,
66725 + const char *dev_name);
66726 +int gr_handle_chroot_pivot(void);
66727 +int gr_handle_chroot_unix(const pid_t pid);
66728 +
66729 +int gr_handle_rawio(const struct inode *inode);
66730 +
66731 +void gr_handle_ioperm(void);
66732 +void gr_handle_iopl(void);
66733 +
66734 +int gr_tpe_allow(const struct file *file);
66735 +
66736 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
66737 +void gr_clear_chroot_entries(struct task_struct *task);
66738 +
66739 +void gr_log_forkfail(const int retval);
66740 +void gr_log_timechange(void);
66741 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
66742 +void gr_log_chdir(const struct dentry *dentry,
66743 + const struct vfsmount *mnt);
66744 +void gr_log_chroot_exec(const struct dentry *dentry,
66745 + const struct vfsmount *mnt);
66746 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
66747 +#ifdef CONFIG_COMPAT
66748 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
66749 +#endif
66750 +void gr_log_remount(const char *devname, const int retval);
66751 +void gr_log_unmount(const char *devname, const int retval);
66752 +void gr_log_mount(const char *from, const char *to, const int retval);
66753 +void gr_log_textrel(struct vm_area_struct *vma);
66754 +void gr_log_rwxmmap(struct file *file);
66755 +void gr_log_rwxmprotect(struct file *file);
66756 +
66757 +int gr_handle_follow_link(const struct inode *parent,
66758 + const struct inode *inode,
66759 + const struct dentry *dentry,
66760 + const struct vfsmount *mnt);
66761 +int gr_handle_fifo(const struct dentry *dentry,
66762 + const struct vfsmount *mnt,
66763 + const struct dentry *dir, const int flag,
66764 + const int acc_mode);
66765 +int gr_handle_hardlink(const struct dentry *dentry,
66766 + const struct vfsmount *mnt,
66767 + struct inode *inode,
66768 + const int mode, const char *to);
66769 +
66770 +int gr_is_capable(const int cap);
66771 +int gr_is_capable_nolog(const int cap);
66772 +void gr_learn_resource(const struct task_struct *task, const int limit,
66773 + const unsigned long wanted, const int gt);
66774 +void gr_copy_label(struct task_struct *tsk);
66775 +void gr_handle_crash(struct task_struct *task, const int sig);
66776 +int gr_handle_signal(const struct task_struct *p, const int sig);
66777 +int gr_check_crash_uid(const uid_t uid);
66778 +int gr_check_protected_task(const struct task_struct *task);
66779 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
66780 +int gr_acl_handle_mmap(const struct file *file,
66781 + const unsigned long prot);
66782 +int gr_acl_handle_mprotect(const struct file *file,
66783 + const unsigned long prot);
66784 +int gr_check_hidden_task(const struct task_struct *tsk);
66785 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
66786 + const struct vfsmount *mnt);
66787 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
66788 + const struct vfsmount *mnt);
66789 +__u32 gr_acl_handle_access(const struct dentry *dentry,
66790 + const struct vfsmount *mnt, const int fmode);
66791 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
66792 + const struct vfsmount *mnt, mode_t mode);
66793 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
66794 + const struct vfsmount *mnt, mode_t mode);
66795 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
66796 + const struct vfsmount *mnt);
66797 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
66798 + const struct vfsmount *mnt);
66799 +int gr_handle_ptrace(struct task_struct *task, const long request);
66800 +int gr_handle_proc_ptrace(struct task_struct *task);
66801 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
66802 + const struct vfsmount *mnt);
66803 +int gr_check_crash_exec(const struct file *filp);
66804 +int gr_acl_is_enabled(void);
66805 +void gr_set_kernel_label(struct task_struct *task);
66806 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
66807 + const gid_t gid);
66808 +int gr_set_proc_label(const struct dentry *dentry,
66809 + const struct vfsmount *mnt,
66810 + const int unsafe_share);
66811 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
66812 + const struct vfsmount *mnt);
66813 +__u32 gr_acl_handle_open(const struct dentry *dentry,
66814 + const struct vfsmount *mnt, int acc_mode);
66815 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
66816 + const struct dentry *p_dentry,
66817 + const struct vfsmount *p_mnt,
66818 + int open_flags, int acc_mode, const int imode);
66819 +void gr_handle_create(const struct dentry *dentry,
66820 + const struct vfsmount *mnt);
66821 +void gr_handle_proc_create(const struct dentry *dentry,
66822 + const struct inode *inode);
66823 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
66824 + const struct dentry *parent_dentry,
66825 + const struct vfsmount *parent_mnt,
66826 + const int mode);
66827 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
66828 + const struct dentry *parent_dentry,
66829 + const struct vfsmount *parent_mnt);
66830 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
66831 + const struct vfsmount *mnt);
66832 +void gr_handle_delete(const ino_t ino, const dev_t dev);
66833 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
66834 + const struct vfsmount *mnt);
66835 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
66836 + const struct dentry *parent_dentry,
66837 + const struct vfsmount *parent_mnt,
66838 + const char *from);
66839 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
66840 + const struct dentry *parent_dentry,
66841 + const struct vfsmount *parent_mnt,
66842 + const struct dentry *old_dentry,
66843 + const struct vfsmount *old_mnt, const char *to);
66844 +int gr_acl_handle_rename(struct dentry *new_dentry,
66845 + struct dentry *parent_dentry,
66846 + const struct vfsmount *parent_mnt,
66847 + struct dentry *old_dentry,
66848 + struct inode *old_parent_inode,
66849 + struct vfsmount *old_mnt, const char *newname);
66850 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
66851 + struct dentry *old_dentry,
66852 + struct dentry *new_dentry,
66853 + struct vfsmount *mnt, const __u8 replace);
66854 +__u32 gr_check_link(const struct dentry *new_dentry,
66855 + const struct dentry *parent_dentry,
66856 + const struct vfsmount *parent_mnt,
66857 + const struct dentry *old_dentry,
66858 + const struct vfsmount *old_mnt);
66859 +int gr_acl_handle_filldir(const struct file *file, const char *name,
66860 + const unsigned int namelen, const ino_t ino);
66861 +
66862 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
66863 + const struct vfsmount *mnt);
66864 +void gr_acl_handle_exit(void);
66865 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
66866 +int gr_acl_handle_procpidmem(const struct task_struct *task);
66867 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
66868 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
66869 +void gr_audit_ptrace(struct task_struct *task);
66870 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
66871 +
66872 +#ifdef CONFIG_GRKERNSEC
66873 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
66874 +void gr_handle_vm86(void);
66875 +void gr_handle_mem_readwrite(u64 from, u64 to);
66876 +
66877 +extern int grsec_enable_dmesg;
66878 +extern int grsec_disable_privio;
66879 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66880 +extern int grsec_enable_chroot_findtask;
66881 +#endif
66882 +#endif
66883 +
66884 +#endif
66885 diff --git a/include/linux/hdpu_features.h b/include/linux/hdpu_features.h
66886 index 6a87154..a3ce57b 100644
66887 --- a/include/linux/hdpu_features.h
66888 +++ b/include/linux/hdpu_features.h
66889 @@ -3,7 +3,7 @@
66890 struct cpustate_t {
66891 spinlock_t lock;
66892 int excl;
66893 - int open_count;
66894 + atomic_t open_count;
66895 unsigned char cached_val;
66896 int inited;
66897 unsigned long *set_addr;
66898 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
66899 index 211ff44..00ab6d7 100644
66900 --- a/include/linux/highmem.h
66901 +++ b/include/linux/highmem.h
66902 @@ -137,6 +137,18 @@ static inline void clear_highpage(struct page *page)
66903 kunmap_atomic(kaddr, KM_USER0);
66904 }
66905
66906 +static inline void sanitize_highpage(struct page *page)
66907 +{
66908 + void *kaddr;
66909 + unsigned long flags;
66910 +
66911 + local_irq_save(flags);
66912 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
66913 + clear_page(kaddr);
66914 + kunmap_atomic(kaddr, KM_CLEARPAGE);
66915 + local_irq_restore(flags);
66916 +}
66917 +
66918 static inline void zero_user_segments(struct page *page,
66919 unsigned start1, unsigned end1,
66920 unsigned start2, unsigned end2)
66921 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
66922 index 7b40cda..24eb44e 100644
66923 --- a/include/linux/i2c.h
66924 +++ b/include/linux/i2c.h
66925 @@ -325,6 +325,7 @@ struct i2c_algorithm {
66926 /* To determine what the adapter supports */
66927 u32 (*functionality) (struct i2c_adapter *);
66928 };
66929 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
66930
66931 /*
66932 * i2c_adapter is the structure used to identify a physical i2c bus along
66933 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
66934 index 4c4e57d..f3c5303 100644
66935 --- a/include/linux/i2o.h
66936 +++ b/include/linux/i2o.h
66937 @@ -564,7 +564,7 @@ struct i2o_controller {
66938 struct i2o_device *exec; /* Executive */
66939 #if BITS_PER_LONG == 64
66940 spinlock_t context_list_lock; /* lock for context_list */
66941 - atomic_t context_list_counter; /* needed for unique contexts */
66942 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
66943 struct list_head context_list; /* list of context id's
66944 and pointers */
66945 #endif
66946 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
66947 index 21a6f5d..dc42eab 100644
66948 --- a/include/linux/init_task.h
66949 +++ b/include/linux/init_task.h
66950 @@ -83,6 +83,12 @@ extern struct group_info init_groups;
66951 #define INIT_IDS
66952 #endif
66953
66954 +#ifdef CONFIG_X86
66955 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
66956 +#else
66957 +#define INIT_TASK_THREAD_INFO
66958 +#endif
66959 +
66960 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
66961 /*
66962 * Because of the reduced scope of CAP_SETPCAP when filesystem
66963 @@ -156,6 +162,7 @@ extern struct cred init_cred;
66964 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
66965 .comm = "swapper", \
66966 .thread = INIT_THREAD, \
66967 + INIT_TASK_THREAD_INFO \
66968 .fs = &init_fs, \
66969 .files = &init_files, \
66970 .signal = &init_signals, \
66971 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
66972 index 4f0a72a..a849599 100644
66973 --- a/include/linux/intel-iommu.h
66974 +++ b/include/linux/intel-iommu.h
66975 @@ -296,7 +296,7 @@ struct iommu_flush {
66976 u8 fm, u64 type);
66977 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
66978 unsigned int size_order, u64 type);
66979 -};
66980 +} __no_const;
66981
66982 enum {
66983 SR_DMAR_FECTL_REG,
66984 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
66985 index c739150..be577b5 100644
66986 --- a/include/linux/interrupt.h
66987 +++ b/include/linux/interrupt.h
66988 @@ -369,7 +369,7 @@ enum
66989 /* map softirq index to softirq name. update 'softirq_to_name' in
66990 * kernel/softirq.c when adding a new softirq.
66991 */
66992 -extern char *softirq_to_name[NR_SOFTIRQS];
66993 +extern const char * const softirq_to_name[NR_SOFTIRQS];
66994
66995 /* softirq mask and active fields moved to irq_cpustat_t in
66996 * asm/hardirq.h to get better cache usage. KAO
66997 @@ -377,12 +377,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
66998
66999 struct softirq_action
67000 {
67001 - void (*action)(struct softirq_action *);
67002 + void (*action)(void);
67003 };
67004
67005 asmlinkage void do_softirq(void);
67006 asmlinkage void __do_softirq(void);
67007 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
67008 +extern void open_softirq(int nr, void (*action)(void));
67009 extern void softirq_init(void);
67010 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
67011 extern void raise_softirq_irqoff(unsigned int nr);
67012 diff --git a/include/linux/irq.h b/include/linux/irq.h
67013 index 9e5f45a..025865b 100644
67014 --- a/include/linux/irq.h
67015 +++ b/include/linux/irq.h
67016 @@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
67017 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
67018 bool boot)
67019 {
67020 +#ifdef CONFIG_CPUMASK_OFFSTACK
67021 gfp_t gfp = GFP_ATOMIC;
67022
67023 if (boot)
67024 gfp = GFP_NOWAIT;
67025
67026 -#ifdef CONFIG_CPUMASK_OFFSTACK
67027 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
67028 return false;
67029
67030 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
67031 index 7922742..27306a2 100644
67032 --- a/include/linux/kallsyms.h
67033 +++ b/include/linux/kallsyms.h
67034 @@ -15,7 +15,8 @@
67035
67036 struct module;
67037
67038 -#ifdef CONFIG_KALLSYMS
67039 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
67040 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67041 /* Lookup the address for a symbol. Returns 0 if not found. */
67042 unsigned long kallsyms_lookup_name(const char *name);
67043
67044 @@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
67045 /* Stupid that this does nothing, but I didn't create this mess. */
67046 #define __print_symbol(fmt, addr)
67047 #endif /*CONFIG_KALLSYMS*/
67048 +#else /* when included by kallsyms.c, vsnprintf.c, or
67049 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
67050 +extern void __print_symbol(const char *fmt, unsigned long address);
67051 +extern int sprint_symbol(char *buffer, unsigned long address);
67052 +const char *kallsyms_lookup(unsigned long addr,
67053 + unsigned long *symbolsize,
67054 + unsigned long *offset,
67055 + char **modname, char *namebuf);
67056 +#endif
67057
67058 /* This macro allows us to keep printk typechecking */
67059 static void __check_printsym_format(const char *fmt, ...)
67060 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
67061 index 6adcc29..13369e8 100644
67062 --- a/include/linux/kgdb.h
67063 +++ b/include/linux/kgdb.h
67064 @@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
67065
67066 extern int kgdb_connected;
67067
67068 -extern atomic_t kgdb_setting_breakpoint;
67069 -extern atomic_t kgdb_cpu_doing_single_step;
67070 +extern atomic_unchecked_t kgdb_setting_breakpoint;
67071 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
67072
67073 extern struct task_struct *kgdb_usethread;
67074 extern struct task_struct *kgdb_contthread;
67075 @@ -235,7 +235,7 @@ struct kgdb_arch {
67076 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
67077 void (*remove_all_hw_break)(void);
67078 void (*correct_hw_break)(void);
67079 -};
67080 +} __do_const;
67081
67082 /**
67083 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
67084 @@ -257,14 +257,14 @@ struct kgdb_io {
67085 int (*init) (void);
67086 void (*pre_exception) (void);
67087 void (*post_exception) (void);
67088 -};
67089 +} __do_const;
67090
67091 -extern struct kgdb_arch arch_kgdb_ops;
67092 +extern const struct kgdb_arch arch_kgdb_ops;
67093
67094 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
67095
67096 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
67097 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
67098 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
67099 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
67100
67101 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
67102 extern int kgdb_mem2hex(char *mem, char *buf, int count);
67103 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
67104 index 384ca8b..83dd97d 100644
67105 --- a/include/linux/kmod.h
67106 +++ b/include/linux/kmod.h
67107 @@ -31,6 +31,8 @@
67108 * usually useless though. */
67109 extern int __request_module(bool wait, const char *name, ...) \
67110 __attribute__((format(printf, 2, 3)));
67111 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
67112 + __attribute__((format(printf, 3, 4)));
67113 #define request_module(mod...) __request_module(true, mod)
67114 #define request_module_nowait(mod...) __request_module(false, mod)
67115 #define try_then_request_module(x, mod...) \
67116 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
67117 index 58ae8e0..3950d3c 100644
67118 --- a/include/linux/kobject.h
67119 +++ b/include/linux/kobject.h
67120 @@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
67121
67122 struct kobj_type {
67123 void (*release)(struct kobject *kobj);
67124 - struct sysfs_ops *sysfs_ops;
67125 + const struct sysfs_ops *sysfs_ops;
67126 struct attribute **default_attrs;
67127 };
67128
67129 @@ -118,9 +118,9 @@ struct kobj_uevent_env {
67130 };
67131
67132 struct kset_uevent_ops {
67133 - int (*filter)(struct kset *kset, struct kobject *kobj);
67134 - const char *(*name)(struct kset *kset, struct kobject *kobj);
67135 - int (*uevent)(struct kset *kset, struct kobject *kobj,
67136 + int (* const filter)(struct kset *kset, struct kobject *kobj);
67137 + const char *(* const name)(struct kset *kset, struct kobject *kobj);
67138 + int (* const uevent)(struct kset *kset, struct kobject *kobj,
67139 struct kobj_uevent_env *env);
67140 };
67141
67142 @@ -132,7 +132,7 @@ struct kobj_attribute {
67143 const char *buf, size_t count);
67144 };
67145
67146 -extern struct sysfs_ops kobj_sysfs_ops;
67147 +extern const struct sysfs_ops kobj_sysfs_ops;
67148
67149 /**
67150 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
67151 @@ -155,14 +155,14 @@ struct kset {
67152 struct list_head list;
67153 spinlock_t list_lock;
67154 struct kobject kobj;
67155 - struct kset_uevent_ops *uevent_ops;
67156 + const struct kset_uevent_ops *uevent_ops;
67157 };
67158
67159 extern void kset_init(struct kset *kset);
67160 extern int __must_check kset_register(struct kset *kset);
67161 extern void kset_unregister(struct kset *kset);
67162 extern struct kset * __must_check kset_create_and_add(const char *name,
67163 - struct kset_uevent_ops *u,
67164 + const struct kset_uevent_ops *u,
67165 struct kobject *parent_kobj);
67166
67167 static inline struct kset *to_kset(struct kobject *kobj)
67168 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
67169 index c728a50..752d821 100644
67170 --- a/include/linux/kvm_host.h
67171 +++ b/include/linux/kvm_host.h
67172 @@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
67173 void vcpu_load(struct kvm_vcpu *vcpu);
67174 void vcpu_put(struct kvm_vcpu *vcpu);
67175
67176 -int kvm_init(void *opaque, unsigned int vcpu_size,
67177 +int kvm_init(const void *opaque, unsigned int vcpu_size,
67178 struct module *module);
67179 void kvm_exit(void);
67180
67181 @@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
67182 struct kvm_guest_debug *dbg);
67183 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
67184
67185 -int kvm_arch_init(void *opaque);
67186 +int kvm_arch_init(const void *opaque);
67187 void kvm_arch_exit(void);
67188
67189 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
67190 diff --git a/include/linux/libata.h b/include/linux/libata.h
67191 index a069916..223edde 100644
67192 --- a/include/linux/libata.h
67193 +++ b/include/linux/libata.h
67194 @@ -525,11 +525,11 @@ struct ata_ioports {
67195
67196 struct ata_host {
67197 spinlock_t lock;
67198 - struct device *dev;
67199 + struct device *dev;
67200 void __iomem * const *iomap;
67201 unsigned int n_ports;
67202 void *private_data;
67203 - struct ata_port_operations *ops;
67204 + const struct ata_port_operations *ops;
67205 unsigned long flags;
67206 #ifdef CONFIG_ATA_ACPI
67207 acpi_handle acpi_handle;
67208 @@ -710,7 +710,7 @@ struct ata_link {
67209
67210 struct ata_port {
67211 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
67212 - struct ata_port_operations *ops;
67213 + const struct ata_port_operations *ops;
67214 spinlock_t *lock;
67215 /* Flags owned by the EH context. Only EH should touch these once the
67216 port is active */
67217 @@ -884,7 +884,7 @@ struct ata_port_operations {
67218 * fields must be pointers.
67219 */
67220 const struct ata_port_operations *inherits;
67221 -};
67222 +} __do_const;
67223
67224 struct ata_port_info {
67225 unsigned long flags;
67226 @@ -892,7 +892,7 @@ struct ata_port_info {
67227 unsigned long pio_mask;
67228 unsigned long mwdma_mask;
67229 unsigned long udma_mask;
67230 - struct ata_port_operations *port_ops;
67231 + const struct ata_port_operations *port_ops;
67232 void *private_data;
67233 };
67234
67235 @@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timing_normal[];
67236 extern const unsigned long sata_deb_timing_hotplug[];
67237 extern const unsigned long sata_deb_timing_long[];
67238
67239 -extern struct ata_port_operations ata_dummy_port_ops;
67240 +extern const struct ata_port_operations ata_dummy_port_ops;
67241 extern const struct ata_port_info ata_dummy_port_info;
67242
67243 static inline const unsigned long *
67244 @@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_host *host, int irq,
67245 struct scsi_host_template *sht);
67246 extern void ata_host_detach(struct ata_host *host);
67247 extern void ata_host_init(struct ata_host *, struct device *,
67248 - unsigned long, struct ata_port_operations *);
67249 + unsigned long, const struct ata_port_operations *);
67250 extern int ata_scsi_detect(struct scsi_host_template *sht);
67251 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
67252 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
67253 diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h
67254 index fbc48f8..0886e57 100644
67255 --- a/include/linux/lockd/bind.h
67256 +++ b/include/linux/lockd/bind.h
67257 @@ -23,13 +23,13 @@ struct svc_rqst;
67258 * This is the set of functions for lockd->nfsd communication
67259 */
67260 struct nlmsvc_binding {
67261 - __be32 (*fopen)(struct svc_rqst *,
67262 + __be32 (* const fopen)(struct svc_rqst *,
67263 struct nfs_fh *,
67264 struct file **);
67265 - void (*fclose)(struct file *);
67266 + void (* const fclose)(struct file *);
67267 };
67268
67269 -extern struct nlmsvc_binding * nlmsvc_ops;
67270 +extern const struct nlmsvc_binding * nlmsvc_ops;
67271
67272 /*
67273 * Similar to nfs_client_initdata, but without the NFS-specific
67274 diff --git a/include/linux/mca.h b/include/linux/mca.h
67275 index 3797270..7765ede 100644
67276 --- a/include/linux/mca.h
67277 +++ b/include/linux/mca.h
67278 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
67279 int region);
67280 void * (*mca_transform_memory)(struct mca_device *,
67281 void *memory);
67282 -};
67283 +} __no_const;
67284
67285 struct mca_bus {
67286 u64 default_dma_mask;
67287 diff --git a/include/linux/memory.h b/include/linux/memory.h
67288 index 37fa19b..b597c85 100644
67289 --- a/include/linux/memory.h
67290 +++ b/include/linux/memory.h
67291 @@ -108,7 +108,7 @@ struct memory_accessor {
67292 size_t count);
67293 ssize_t (*write)(struct memory_accessor *, const char *buf,
67294 off_t offset, size_t count);
67295 -};
67296 +} __no_const;
67297
67298 /*
67299 * Kernel text modification mutex, used for code patching. Users of this lock
67300 diff --git a/include/linux/mm.h b/include/linux/mm.h
67301 index 11e5be6..1ff2423 100644
67302 --- a/include/linux/mm.h
67303 +++ b/include/linux/mm.h
67304 @@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void *objp);
67305
67306 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
67307 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
67308 +
67309 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
67310 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
67311 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
67312 +#else
67313 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
67314 +#endif
67315 +
67316 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
67317 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
67318
67319 @@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
67320 int set_page_dirty_lock(struct page *page);
67321 int clear_page_dirty_for_io(struct page *page);
67322
67323 -/* Is the vma a continuation of the stack vma above it? */
67324 -static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
67325 -{
67326 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
67327 -}
67328 -
67329 extern unsigned long move_page_tables(struct vm_area_struct *vma,
67330 unsigned long old_addr, struct vm_area_struct *new_vma,
67331 unsigned long new_addr, unsigned long len);
67332 @@ -890,6 +891,8 @@ struct shrinker {
67333 extern void register_shrinker(struct shrinker *);
67334 extern void unregister_shrinker(struct shrinker *);
67335
67336 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
67337 +
67338 int vma_wants_writenotify(struct vm_area_struct *vma);
67339
67340 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
67341 @@ -1162,6 +1165,7 @@ out:
67342 }
67343
67344 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
67345 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
67346
67347 extern unsigned long do_brk(unsigned long, unsigned long);
67348
67349 @@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
67350 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
67351 struct vm_area_struct **pprev);
67352
67353 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
67354 +extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
67355 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
67356 +
67357 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
67358 NULL if none. Assume start_addr < end_addr. */
67359 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
67360 @@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
67361 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
67362 }
67363
67364 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
67365 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
67366 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
67367 unsigned long pfn, unsigned long size, pgprot_t);
67368 @@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long pfn, int trapno);
67369 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
67370 extern int sysctl_memory_failure_early_kill;
67371 extern int sysctl_memory_failure_recovery;
67372 -extern atomic_long_t mce_bad_pages;
67373 +extern atomic_long_unchecked_t mce_bad_pages;
67374 +
67375 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67376 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
67377 +#else
67378 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
67379 +#endif
67380
67381 #endif /* __KERNEL__ */
67382 #endif /* _LINUX_MM_H */
67383 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
67384 index 9d12ed5..8023125 100644
67385 --- a/include/linux/mm_types.h
67386 +++ b/include/linux/mm_types.h
67387 @@ -186,6 +186,8 @@ struct vm_area_struct {
67388 #ifdef CONFIG_NUMA
67389 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
67390 #endif
67391 +
67392 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
67393 };
67394
67395 struct core_thread {
67396 @@ -287,6 +289,24 @@ struct mm_struct {
67397 #ifdef CONFIG_MMU_NOTIFIER
67398 struct mmu_notifier_mm *mmu_notifier_mm;
67399 #endif
67400 +
67401 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67402 + unsigned long pax_flags;
67403 +#endif
67404 +
67405 +#ifdef CONFIG_PAX_DLRESOLVE
67406 + unsigned long call_dl_resolve;
67407 +#endif
67408 +
67409 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
67410 + unsigned long call_syscall;
67411 +#endif
67412 +
67413 +#ifdef CONFIG_PAX_ASLR
67414 + unsigned long delta_mmap; /* randomized offset */
67415 + unsigned long delta_stack; /* randomized offset */
67416 +#endif
67417 +
67418 };
67419
67420 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
67421 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
67422 index 4e02ee2..afb159e 100644
67423 --- a/include/linux/mmu_notifier.h
67424 +++ b/include/linux/mmu_notifier.h
67425 @@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
67426 */
67427 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
67428 ({ \
67429 - pte_t __pte; \
67430 + pte_t ___pte; \
67431 struct vm_area_struct *___vma = __vma; \
67432 unsigned long ___address = __address; \
67433 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
67434 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
67435 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
67436 - __pte; \
67437 + ___pte; \
67438 })
67439
67440 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
67441 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
67442 index 6c31a2a..4b0e930 100644
67443 --- a/include/linux/mmzone.h
67444 +++ b/include/linux/mmzone.h
67445 @@ -350,7 +350,7 @@ struct zone {
67446 unsigned long flags; /* zone flags, see below */
67447
67448 /* Zone statistics */
67449 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67450 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67451
67452 /*
67453 * prev_priority holds the scanning priority for this zone. It is
67454 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
67455 index f58e9d8..3503935 100644
67456 --- a/include/linux/mod_devicetable.h
67457 +++ b/include/linux/mod_devicetable.h
67458 @@ -12,7 +12,7 @@
67459 typedef unsigned long kernel_ulong_t;
67460 #endif
67461
67462 -#define PCI_ANY_ID (~0)
67463 +#define PCI_ANY_ID ((__u16)~0)
67464
67465 struct pci_device_id {
67466 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
67467 @@ -131,7 +131,7 @@ struct usb_device_id {
67468 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
67469 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
67470
67471 -#define HID_ANY_ID (~0)
67472 +#define HID_ANY_ID (~0U)
67473
67474 struct hid_device_id {
67475 __u16 bus;
67476 diff --git a/include/linux/module.h b/include/linux/module.h
67477 index 482efc8..642032b 100644
67478 --- a/include/linux/module.h
67479 +++ b/include/linux/module.h
67480 @@ -16,6 +16,7 @@
67481 #include <linux/kobject.h>
67482 #include <linux/moduleparam.h>
67483 #include <linux/tracepoint.h>
67484 +#include <linux/fs.h>
67485
67486 #include <asm/local.h>
67487 #include <asm/module.h>
67488 @@ -287,16 +288,16 @@ struct module
67489 int (*init)(void);
67490
67491 /* If this is non-NULL, vfree after init() returns */
67492 - void *module_init;
67493 + void *module_init_rx, *module_init_rw;
67494
67495 /* Here is the actual code + data, vfree'd on unload. */
67496 - void *module_core;
67497 + void *module_core_rx, *module_core_rw;
67498
67499 /* Here are the sizes of the init and core sections */
67500 - unsigned int init_size, core_size;
67501 + unsigned int init_size_rw, core_size_rw;
67502
67503 /* The size of the executable code in each section. */
67504 - unsigned int init_text_size, core_text_size;
67505 + unsigned int init_size_rx, core_size_rx;
67506
67507 /* Arch-specific module values */
67508 struct mod_arch_specific arch;
67509 @@ -345,6 +346,10 @@ struct module
67510 #ifdef CONFIG_EVENT_TRACING
67511 struct ftrace_event_call *trace_events;
67512 unsigned int num_trace_events;
67513 + struct file_operations trace_id;
67514 + struct file_operations trace_enable;
67515 + struct file_operations trace_format;
67516 + struct file_operations trace_filter;
67517 #endif
67518 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
67519 unsigned long *ftrace_callsites;
67520 @@ -393,16 +398,46 @@ struct module *__module_address(unsigned long addr);
67521 bool is_module_address(unsigned long addr);
67522 bool is_module_text_address(unsigned long addr);
67523
67524 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
67525 +{
67526 +
67527 +#ifdef CONFIG_PAX_KERNEXEC
67528 + if (ktla_ktva(addr) >= (unsigned long)start &&
67529 + ktla_ktva(addr) < (unsigned long)start + size)
67530 + return 1;
67531 +#endif
67532 +
67533 + return ((void *)addr >= start && (void *)addr < start + size);
67534 +}
67535 +
67536 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
67537 +{
67538 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
67539 +}
67540 +
67541 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
67542 +{
67543 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
67544 +}
67545 +
67546 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
67547 +{
67548 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
67549 +}
67550 +
67551 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
67552 +{
67553 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
67554 +}
67555 +
67556 static inline int within_module_core(unsigned long addr, struct module *mod)
67557 {
67558 - return (unsigned long)mod->module_core <= addr &&
67559 - addr < (unsigned long)mod->module_core + mod->core_size;
67560 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
67561 }
67562
67563 static inline int within_module_init(unsigned long addr, struct module *mod)
67564 {
67565 - return (unsigned long)mod->module_init <= addr &&
67566 - addr < (unsigned long)mod->module_init + mod->init_size;
67567 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
67568 }
67569
67570 /* Search for module by name: must hold module_mutex. */
67571 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
67572 index c1f40c2..682ca53 100644
67573 --- a/include/linux/moduleloader.h
67574 +++ b/include/linux/moduleloader.h
67575 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
67576 sections. Returns NULL on failure. */
67577 void *module_alloc(unsigned long size);
67578
67579 +#ifdef CONFIG_PAX_KERNEXEC
67580 +void *module_alloc_exec(unsigned long size);
67581 +#else
67582 +#define module_alloc_exec(x) module_alloc(x)
67583 +#endif
67584 +
67585 /* Free memory returned from module_alloc. */
67586 void module_free(struct module *mod, void *module_region);
67587
67588 +#ifdef CONFIG_PAX_KERNEXEC
67589 +void module_free_exec(struct module *mod, void *module_region);
67590 +#else
67591 +#define module_free_exec(x, y) module_free((x), (y))
67592 +#endif
67593 +
67594 /* Apply the given relocation to the (simplified) ELF. Return -error
67595 or 0. */
67596 int apply_relocate(Elf_Shdr *sechdrs,
67597 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
67598 index 82a9124..8a5f622 100644
67599 --- a/include/linux/moduleparam.h
67600 +++ b/include/linux/moduleparam.h
67601 @@ -132,7 +132,7 @@ struct kparam_array
67602
67603 /* Actually copy string: maxlen param is usually sizeof(string). */
67604 #define module_param_string(name, string, len, perm) \
67605 - static const struct kparam_string __param_string_##name \
67606 + static const struct kparam_string __param_string_##name __used \
67607 = { len, string }; \
67608 __module_param_call(MODULE_PARAM_PREFIX, name, \
67609 param_set_copystring, param_get_string, \
67610 @@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp);
67611
67612 /* Comma-separated array: *nump is set to number they actually specified. */
67613 #define module_param_array_named(name, array, type, nump, perm) \
67614 - static const struct kparam_array __param_arr_##name \
67615 + static const struct kparam_array __param_arr_##name __used \
67616 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
67617 sizeof(array[0]), array }; \
67618 __module_param_call(MODULE_PARAM_PREFIX, name, \
67619 diff --git a/include/linux/mutex.h b/include/linux/mutex.h
67620 index 878cab4..c92cb3e 100644
67621 --- a/include/linux/mutex.h
67622 +++ b/include/linux/mutex.h
67623 @@ -51,7 +51,7 @@ struct mutex {
67624 spinlock_t wait_lock;
67625 struct list_head wait_list;
67626 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
67627 - struct thread_info *owner;
67628 + struct task_struct *owner;
67629 #endif
67630 #ifdef CONFIG_DEBUG_MUTEXES
67631 const char *name;
67632 diff --git a/include/linux/namei.h b/include/linux/namei.h
67633 index ec0f607..d19e675 100644
67634 --- a/include/linux/namei.h
67635 +++ b/include/linux/namei.h
67636 @@ -22,7 +22,7 @@ struct nameidata {
67637 unsigned int flags;
67638 int last_type;
67639 unsigned depth;
67640 - char *saved_names[MAX_NESTED_LINKS + 1];
67641 + const char *saved_names[MAX_NESTED_LINKS + 1];
67642
67643 /* Intent data */
67644 union {
67645 @@ -84,12 +84,12 @@ extern int follow_up(struct path *);
67646 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
67647 extern void unlock_rename(struct dentry *, struct dentry *);
67648
67649 -static inline void nd_set_link(struct nameidata *nd, char *path)
67650 +static inline void nd_set_link(struct nameidata *nd, const char *path)
67651 {
67652 nd->saved_names[nd->depth] = path;
67653 }
67654
67655 -static inline char *nd_get_link(struct nameidata *nd)
67656 +static inline const char *nd_get_link(const struct nameidata *nd)
67657 {
67658 return nd->saved_names[nd->depth];
67659 }
67660 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
67661 index 9d7e8f7..04428c5 100644
67662 --- a/include/linux/netdevice.h
67663 +++ b/include/linux/netdevice.h
67664 @@ -637,6 +637,7 @@ struct net_device_ops {
67665 u16 xid);
67666 #endif
67667 };
67668 +typedef struct net_device_ops __no_const net_device_ops_no_const;
67669
67670 /*
67671 * The DEVICE structure.
67672 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
67673 new file mode 100644
67674 index 0000000..33f4af8
67675 --- /dev/null
67676 +++ b/include/linux/netfilter/xt_gradm.h
67677 @@ -0,0 +1,9 @@
67678 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
67679 +#define _LINUX_NETFILTER_XT_GRADM_H 1
67680 +
67681 +struct xt_gradm_mtinfo {
67682 + __u16 flags;
67683 + __u16 invflags;
67684 +};
67685 +
67686 +#endif
67687 diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
67688 index b359c4a..c08b334 100644
67689 --- a/include/linux/nodemask.h
67690 +++ b/include/linux/nodemask.h
67691 @@ -464,11 +464,11 @@ static inline int num_node_state(enum node_states state)
67692
67693 #define any_online_node(mask) \
67694 ({ \
67695 - int node; \
67696 - for_each_node_mask(node, (mask)) \
67697 - if (node_online(node)) \
67698 + int __node; \
67699 + for_each_node_mask(__node, (mask)) \
67700 + if (node_online(__node)) \
67701 break; \
67702 - node; \
67703 + __node; \
67704 })
67705
67706 #define num_online_nodes() num_node_state(N_ONLINE)
67707 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
67708 index 5171639..7cf4235 100644
67709 --- a/include/linux/oprofile.h
67710 +++ b/include/linux/oprofile.h
67711 @@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
67712 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
67713 char const * name, ulong * val);
67714
67715 -/** Create a file for read-only access to an atomic_t. */
67716 +/** Create a file for read-only access to an atomic_unchecked_t. */
67717 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
67718 - char const * name, atomic_t * val);
67719 + char const * name, atomic_unchecked_t * val);
67720
67721 /** create a directory */
67722 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
67723 diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
67724 index 3c62ed4..8924c7c 100644
67725 --- a/include/linux/pagemap.h
67726 +++ b/include/linux/pagemap.h
67727 @@ -425,7 +425,9 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)
67728 if (((unsigned long)uaddr & PAGE_MASK) !=
67729 ((unsigned long)end & PAGE_MASK))
67730 ret = __get_user(c, end);
67731 + (void)c;
67732 }
67733 + (void)c;
67734 return ret;
67735 }
67736
67737 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
67738 index 81c9689..a567a55 100644
67739 --- a/include/linux/perf_event.h
67740 +++ b/include/linux/perf_event.h
67741 @@ -476,7 +476,7 @@ struct hw_perf_event {
67742 struct hrtimer hrtimer;
67743 };
67744 };
67745 - atomic64_t prev_count;
67746 + atomic64_unchecked_t prev_count;
67747 u64 sample_period;
67748 u64 last_period;
67749 atomic64_t period_left;
67750 @@ -557,7 +557,7 @@ struct perf_event {
67751 const struct pmu *pmu;
67752
67753 enum perf_event_active_state state;
67754 - atomic64_t count;
67755 + atomic64_unchecked_t count;
67756
67757 /*
67758 * These are the total time in nanoseconds that the event
67759 @@ -595,8 +595,8 @@ struct perf_event {
67760 * These accumulate total time (in nanoseconds) that children
67761 * events have been enabled and running, respectively.
67762 */
67763 - atomic64_t child_total_time_enabled;
67764 - atomic64_t child_total_time_running;
67765 + atomic64_unchecked_t child_total_time_enabled;
67766 + atomic64_unchecked_t child_total_time_running;
67767
67768 /*
67769 * Protect attach/detach and child_list:
67770 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
67771 index b43a9e0..b77d869 100644
67772 --- a/include/linux/pipe_fs_i.h
67773 +++ b/include/linux/pipe_fs_i.h
67774 @@ -46,9 +46,9 @@ struct pipe_inode_info {
67775 wait_queue_head_t wait;
67776 unsigned int nrbufs, curbuf;
67777 struct page *tmp_page;
67778 - unsigned int readers;
67779 - unsigned int writers;
67780 - unsigned int waiting_writers;
67781 + atomic_t readers;
67782 + atomic_t writers;
67783 + atomic_t waiting_writers;
67784 unsigned int r_counter;
67785 unsigned int w_counter;
67786 struct fasync_struct *fasync_readers;
67787 diff --git a/include/linux/poison.h b/include/linux/poison.h
67788 index 34066ff..e95d744 100644
67789 --- a/include/linux/poison.h
67790 +++ b/include/linux/poison.h
67791 @@ -19,8 +19,8 @@
67792 * under normal circumstances, used to verify that nobody uses
67793 * non-initialized list entries.
67794 */
67795 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
67796 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
67797 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
67798 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
67799
67800 /********** include/linux/timer.h **********/
67801 /*
67802 diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
67803 index 4f71bf4..77ffa64 100644
67804 --- a/include/linux/posix-timers.h
67805 +++ b/include/linux/posix-timers.h
67806 @@ -67,7 +67,7 @@ struct k_itimer {
67807 };
67808
67809 struct k_clock {
67810 - int res; /* in nanoseconds */
67811 + const int res; /* in nanoseconds */
67812 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
67813 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
67814 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
67815 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
67816 index 72b1a10..13303a9 100644
67817 --- a/include/linux/preempt.h
67818 +++ b/include/linux/preempt.h
67819 @@ -110,7 +110,7 @@ struct preempt_ops {
67820 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
67821 void (*sched_out)(struct preempt_notifier *notifier,
67822 struct task_struct *next);
67823 -};
67824 +} __no_const;
67825
67826 /**
67827 * preempt_notifier - key for installing preemption notifiers
67828 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
67829 index 379eaed..1bf73e3 100644
67830 --- a/include/linux/proc_fs.h
67831 +++ b/include/linux/proc_fs.h
67832 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
67833 return proc_create_data(name, mode, parent, proc_fops, NULL);
67834 }
67835
67836 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
67837 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
67838 +{
67839 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67840 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
67841 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67842 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
67843 +#else
67844 + return proc_create_data(name, mode, parent, proc_fops, NULL);
67845 +#endif
67846 +}
67847 +
67848 +
67849 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
67850 mode_t mode, struct proc_dir_entry *base,
67851 read_proc_t *read_proc, void * data)
67852 @@ -256,7 +269,7 @@ union proc_op {
67853 int (*proc_show)(struct seq_file *m,
67854 struct pid_namespace *ns, struct pid *pid,
67855 struct task_struct *task);
67856 -};
67857 +} __no_const;
67858
67859 struct ctl_table_header;
67860 struct ctl_table;
67861 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
67862 index 7456d7d..6c1cfc9 100644
67863 --- a/include/linux/ptrace.h
67864 +++ b/include/linux/ptrace.h
67865 @@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_struct *child);
67866 extern void exit_ptrace(struct task_struct *tracer);
67867 #define PTRACE_MODE_READ 1
67868 #define PTRACE_MODE_ATTACH 2
67869 -/* Returns 0 on success, -errno on denial. */
67870 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
67871 /* Returns true on success, false on denial. */
67872 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
67873 +/* Returns true on success, false on denial. */
67874 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
67875
67876 static inline int ptrace_reparented(struct task_struct *child)
67877 {
67878 diff --git a/include/linux/random.h b/include/linux/random.h
67879 index 2948046..3262567 100644
67880 --- a/include/linux/random.h
67881 +++ b/include/linux/random.h
67882 @@ -63,6 +63,11 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
67883 u32 random32(void);
67884 void srandom32(u32 seed);
67885
67886 +static inline unsigned long pax_get_random_long(void)
67887 +{
67888 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
67889 +}
67890 +
67891 #endif /* __KERNEL___ */
67892
67893 #endif /* _LINUX_RANDOM_H */
67894 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
67895 index 988e55f..17cb4ef 100644
67896 --- a/include/linux/reboot.h
67897 +++ b/include/linux/reboot.h
67898 @@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
67899 * Architecture-specific implementations of sys_reboot commands.
67900 */
67901
67902 -extern void machine_restart(char *cmd);
67903 -extern void machine_halt(void);
67904 -extern void machine_power_off(void);
67905 +extern void machine_restart(char *cmd) __noreturn;
67906 +extern void machine_halt(void) __noreturn;
67907 +extern void machine_power_off(void) __noreturn;
67908
67909 extern void machine_shutdown(void);
67910 struct pt_regs;
67911 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
67912 */
67913
67914 extern void kernel_restart_prepare(char *cmd);
67915 -extern void kernel_restart(char *cmd);
67916 -extern void kernel_halt(void);
67917 -extern void kernel_power_off(void);
67918 +extern void kernel_restart(char *cmd) __noreturn;
67919 +extern void kernel_halt(void) __noreturn;
67920 +extern void kernel_power_off(void) __noreturn;
67921
67922 void ctrl_alt_del(void);
67923
67924 @@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
67925 * Emergency restart, callable from an interrupt handler.
67926 */
67927
67928 -extern void emergency_restart(void);
67929 +extern void emergency_restart(void) __noreturn;
67930 #include <asm/emergency-restart.h>
67931
67932 #endif
67933 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
67934 index dd31e7b..5b03c5c 100644
67935 --- a/include/linux/reiserfs_fs.h
67936 +++ b/include/linux/reiserfs_fs.h
67937 @@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67938 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
67939
67940 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67941 -#define get_generation(s) atomic_read (&fs_generation(s))
67942 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67943 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67944 #define __fs_changed(gen,s) (gen != get_generation (s))
67945 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
67946 @@ -1534,24 +1534,24 @@ static inline struct super_block *sb_from_bi(struct buffer_info *bi)
67947 */
67948
67949 struct item_operations {
67950 - int (*bytes_number) (struct item_head * ih, int block_size);
67951 - void (*decrement_key) (struct cpu_key *);
67952 - int (*is_left_mergeable) (struct reiserfs_key * ih,
67953 + int (* const bytes_number) (struct item_head * ih, int block_size);
67954 + void (* const decrement_key) (struct cpu_key *);
67955 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
67956 unsigned long bsize);
67957 - void (*print_item) (struct item_head *, char *item);
67958 - void (*check_item) (struct item_head *, char *item);
67959 + void (* const print_item) (struct item_head *, char *item);
67960 + void (* const check_item) (struct item_head *, char *item);
67961
67962 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
67963 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
67964 int is_affected, int insert_size);
67965 - int (*check_left) (struct virtual_item * vi, int free,
67966 + int (* const check_left) (struct virtual_item * vi, int free,
67967 int start_skip, int end_skip);
67968 - int (*check_right) (struct virtual_item * vi, int free);
67969 - int (*part_size) (struct virtual_item * vi, int from, int to);
67970 - int (*unit_num) (struct virtual_item * vi);
67971 - void (*print_vi) (struct virtual_item * vi);
67972 + int (* const check_right) (struct virtual_item * vi, int free);
67973 + int (* const part_size) (struct virtual_item * vi, int from, int to);
67974 + int (* const unit_num) (struct virtual_item * vi);
67975 + void (* const print_vi) (struct virtual_item * vi);
67976 };
67977
67978 -extern struct item_operations *item_ops[TYPE_ANY + 1];
67979 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
67980
67981 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
67982 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
67983 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
67984 index dab68bb..0688727 100644
67985 --- a/include/linux/reiserfs_fs_sb.h
67986 +++ b/include/linux/reiserfs_fs_sb.h
67987 @@ -377,7 +377,7 @@ struct reiserfs_sb_info {
67988 /* Comment? -Hans */
67989 wait_queue_head_t s_wait;
67990 /* To be obsoleted soon by per buffer seals.. -Hans */
67991 - atomic_t s_generation_counter; // increased by one every time the
67992 + atomic_unchecked_t s_generation_counter; // increased by one every time the
67993 // tree gets re-balanced
67994 unsigned long s_properties; /* File system properties. Currently holds
67995 on-disk FS format */
67996 diff --git a/include/linux/relay.h b/include/linux/relay.h
67997 index 14a86bc..17d0700 100644
67998 --- a/include/linux/relay.h
67999 +++ b/include/linux/relay.h
68000 @@ -159,7 +159,7 @@ struct rchan_callbacks
68001 * The callback should return 0 if successful, negative if not.
68002 */
68003 int (*remove_buf_file)(struct dentry *dentry);
68004 -};
68005 +} __no_const;
68006
68007 /*
68008 * CONFIG_RELAY kernel API, kernel/relay.c
68009 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
68010 index 3392c59..a746428 100644
68011 --- a/include/linux/rfkill.h
68012 +++ b/include/linux/rfkill.h
68013 @@ -144,6 +144,7 @@ struct rfkill_ops {
68014 void (*query)(struct rfkill *rfkill, void *data);
68015 int (*set_block)(void *data, bool blocked);
68016 };
68017 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
68018
68019 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
68020 /**
68021 diff --git a/include/linux/sched.h b/include/linux/sched.h
68022 index 71849bf..40217dc 100644
68023 --- a/include/linux/sched.h
68024 +++ b/include/linux/sched.h
68025 @@ -101,6 +101,7 @@ struct bio;
68026 struct fs_struct;
68027 struct bts_context;
68028 struct perf_event_context;
68029 +struct linux_binprm;
68030
68031 /*
68032 * List of flags we want to share for kernel threads,
68033 @@ -350,7 +351,7 @@ extern signed long schedule_timeout_killable(signed long timeout);
68034 extern signed long schedule_timeout_uninterruptible(signed long timeout);
68035 asmlinkage void __schedule(void);
68036 asmlinkage void schedule(void);
68037 -extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
68038 +extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
68039
68040 struct nsproxy;
68041 struct user_namespace;
68042 @@ -371,9 +372,12 @@ struct user_namespace;
68043 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
68044
68045 extern int sysctl_max_map_count;
68046 +extern unsigned long sysctl_heap_stack_gap;
68047
68048 #include <linux/aio.h>
68049
68050 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
68051 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
68052 extern unsigned long
68053 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
68054 unsigned long, unsigned long);
68055 @@ -666,6 +670,16 @@ struct signal_struct {
68056 struct tty_audit_buf *tty_audit_buf;
68057 #endif
68058
68059 +#ifdef CONFIG_GRKERNSEC
68060 + u32 curr_ip;
68061 + u32 saved_ip;
68062 + u32 gr_saddr;
68063 + u32 gr_daddr;
68064 + u16 gr_sport;
68065 + u16 gr_dport;
68066 + u8 used_accept:1;
68067 +#endif
68068 +
68069 int oom_adj; /* OOM kill score adjustment (bit shift) */
68070 };
68071
68072 @@ -723,6 +737,11 @@ struct user_struct {
68073 struct key *session_keyring; /* UID's default session keyring */
68074 #endif
68075
68076 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
68077 + unsigned int banned;
68078 + unsigned long ban_expires;
68079 +#endif
68080 +
68081 /* Hash table maintenance information */
68082 struct hlist_node uidhash_node;
68083 uid_t uid;
68084 @@ -1328,8 +1347,8 @@ struct task_struct {
68085 struct list_head thread_group;
68086
68087 struct completion *vfork_done; /* for vfork() */
68088 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
68089 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68090 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
68091 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68092
68093 cputime_t utime, stime, utimescaled, stimescaled;
68094 cputime_t gtime;
68095 @@ -1343,16 +1362,6 @@ struct task_struct {
68096 struct task_cputime cputime_expires;
68097 struct list_head cpu_timers[3];
68098
68099 -/* process credentials */
68100 - const struct cred *real_cred; /* objective and real subjective task
68101 - * credentials (COW) */
68102 - const struct cred *cred; /* effective (overridable) subjective task
68103 - * credentials (COW) */
68104 - struct mutex cred_guard_mutex; /* guard against foreign influences on
68105 - * credential calculations
68106 - * (notably. ptrace) */
68107 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68108 -
68109 char comm[TASK_COMM_LEN]; /* executable name excluding path
68110 - access with [gs]et_task_comm (which lock
68111 it with task_lock())
68112 @@ -1369,6 +1378,10 @@ struct task_struct {
68113 #endif
68114 /* CPU-specific state of this task */
68115 struct thread_struct thread;
68116 +/* thread_info moved to task_struct */
68117 +#ifdef CONFIG_X86
68118 + struct thread_info tinfo;
68119 +#endif
68120 /* filesystem information */
68121 struct fs_struct *fs;
68122 /* open file information */
68123 @@ -1436,6 +1449,15 @@ struct task_struct {
68124 int hardirq_context;
68125 int softirq_context;
68126 #endif
68127 +
68128 +/* process credentials */
68129 + const struct cred *real_cred; /* objective and real subjective task
68130 + * credentials (COW) */
68131 + struct mutex cred_guard_mutex; /* guard against foreign influences on
68132 + * credential calculations
68133 + * (notably. ptrace) */
68134 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68135 +
68136 #ifdef CONFIG_LOCKDEP
68137 # define MAX_LOCK_DEPTH 48UL
68138 u64 curr_chain_key;
68139 @@ -1456,6 +1478,9 @@ struct task_struct {
68140
68141 struct backing_dev_info *backing_dev_info;
68142
68143 + const struct cred *cred; /* effective (overridable) subjective task
68144 + * credentials (COW) */
68145 +
68146 struct io_context *io_context;
68147
68148 unsigned long ptrace_message;
68149 @@ -1519,6 +1544,21 @@ struct task_struct {
68150 unsigned long default_timer_slack_ns;
68151
68152 struct list_head *scm_work_list;
68153 +
68154 +#ifdef CONFIG_GRKERNSEC
68155 + /* grsecurity */
68156 + struct dentry *gr_chroot_dentry;
68157 + struct acl_subject_label *acl;
68158 + struct acl_role_label *role;
68159 + struct file *exec_file;
68160 + u16 acl_role_id;
68161 + /* is this the task that authenticated to the special role */
68162 + u8 acl_sp_role;
68163 + u8 is_writable;
68164 + u8 brute;
68165 + u8 gr_is_chrooted;
68166 +#endif
68167 +
68168 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
68169 /* Index of current stored adress in ret_stack */
68170 int curr_ret_stack;
68171 @@ -1542,6 +1582,57 @@ struct task_struct {
68172 #endif /* CONFIG_TRACING */
68173 };
68174
68175 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
68176 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
68177 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
68178 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
68179 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
68180 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
68181 +
68182 +#ifdef CONFIG_PAX_SOFTMODE
68183 +extern int pax_softmode;
68184 +#endif
68185 +
68186 +extern int pax_check_flags(unsigned long *);
68187 +
68188 +/* if tsk != current then task_lock must be held on it */
68189 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68190 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
68191 +{
68192 + if (likely(tsk->mm))
68193 + return tsk->mm->pax_flags;
68194 + else
68195 + return 0UL;
68196 +}
68197 +
68198 +/* if tsk != current then task_lock must be held on it */
68199 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
68200 +{
68201 + if (likely(tsk->mm)) {
68202 + tsk->mm->pax_flags = flags;
68203 + return 0;
68204 + }
68205 + return -EINVAL;
68206 +}
68207 +#endif
68208 +
68209 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68210 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
68211 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
68212 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
68213 +#endif
68214 +
68215 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
68216 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
68217 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
68218 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
68219 +
68220 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
68221 +extern void pax_track_stack(void);
68222 +#else
68223 +static inline void pax_track_stack(void) {}
68224 +#endif
68225 +
68226 /* Future-safe accessor for struct task_struct's cpus_allowed. */
68227 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
68228
68229 @@ -1740,7 +1831,7 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
68230 #define PF_DUMPCORE 0x00000200 /* dumped core */
68231 #define PF_SIGNALED 0x00000400 /* killed by a signal */
68232 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
68233 -#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
68234 +#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
68235 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
68236 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
68237 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
68238 @@ -1978,7 +2069,9 @@ void yield(void);
68239 extern struct exec_domain default_exec_domain;
68240
68241 union thread_union {
68242 +#ifndef CONFIG_X86
68243 struct thread_info thread_info;
68244 +#endif
68245 unsigned long stack[THREAD_SIZE/sizeof(long)];
68246 };
68247
68248 @@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
68249 */
68250
68251 extern struct task_struct *find_task_by_vpid(pid_t nr);
68252 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
68253 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
68254 struct pid_namespace *ns);
68255
68256 @@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
68257 extern void exit_itimers(struct signal_struct *);
68258 extern void flush_itimer_signals(void);
68259
68260 -extern NORET_TYPE void do_group_exit(int);
68261 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
68262
68263 extern void daemonize(const char *, ...);
68264 extern int allow_signal(int);
68265 @@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
68266
68267 #endif
68268
68269 -static inline int object_is_on_stack(void *obj)
68270 +static inline int object_starts_on_stack(void *obj)
68271 {
68272 - void *stack = task_stack_page(current);
68273 + const void *stack = task_stack_page(current);
68274
68275 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
68276 }
68277
68278 +#ifdef CONFIG_PAX_USERCOPY
68279 +extern int object_is_on_stack(const void *obj, unsigned long len);
68280 +#endif
68281 +
68282 extern void thread_info_cache_init(void);
68283
68284 #ifdef CONFIG_DEBUG_STACK_USAGE
68285 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
68286 index 1ee2c05..81b7ec4 100644
68287 --- a/include/linux/screen_info.h
68288 +++ b/include/linux/screen_info.h
68289 @@ -42,7 +42,8 @@ struct screen_info {
68290 __u16 pages; /* 0x32 */
68291 __u16 vesa_attributes; /* 0x34 */
68292 __u32 capabilities; /* 0x36 */
68293 - __u8 _reserved[6]; /* 0x3a */
68294 + __u16 vesapm_size; /* 0x3a */
68295 + __u8 _reserved[4]; /* 0x3c */
68296 } __attribute__((packed));
68297
68298 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68299 diff --git a/include/linux/security.h b/include/linux/security.h
68300 index d40d23f..d739b08 100644
68301 --- a/include/linux/security.h
68302 +++ b/include/linux/security.h
68303 @@ -34,6 +34,7 @@
68304 #include <linux/key.h>
68305 #include <linux/xfrm.h>
68306 #include <linux/gfp.h>
68307 +#include <linux/grsecurity.h>
68308 #include <net/flow.h>
68309
68310 /* Maximum number of letters for an LSM name string */
68311 @@ -76,7 +77,7 @@ extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
68312 extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
68313 extern int cap_task_setioprio(struct task_struct *p, int ioprio);
68314 extern int cap_task_setnice(struct task_struct *p, int nice);
68315 -extern int cap_syslog(int type);
68316 +extern int cap_syslog(int type, bool from_file);
68317 extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
68318
68319 struct msghdr;
68320 @@ -1331,6 +1332,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
68321 * logging to the console.
68322 * See the syslog(2) manual page for an explanation of the @type values.
68323 * @type contains the type of action.
68324 + * @from_file indicates the context of action (if it came from /proc).
68325 * Return 0 if permission is granted.
68326 * @settime:
68327 * Check permission to change the system time.
68328 @@ -1445,7 +1447,7 @@ struct security_operations {
68329 int (*sysctl) (struct ctl_table *table, int op);
68330 int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
68331 int (*quota_on) (struct dentry *dentry);
68332 - int (*syslog) (int type);
68333 + int (*syslog) (int type, bool from_file);
68334 int (*settime) (struct timespec *ts, struct timezone *tz);
68335 int (*vm_enough_memory) (struct mm_struct *mm, long pages);
68336
68337 @@ -1740,7 +1742,7 @@ int security_acct(struct file *file);
68338 int security_sysctl(struct ctl_table *table, int op);
68339 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
68340 int security_quota_on(struct dentry *dentry);
68341 -int security_syslog(int type);
68342 +int security_syslog(int type, bool from_file);
68343 int security_settime(struct timespec *ts, struct timezone *tz);
68344 int security_vm_enough_memory(long pages);
68345 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
68346 @@ -1986,9 +1988,9 @@ static inline int security_quota_on(struct dentry *dentry)
68347 return 0;
68348 }
68349
68350 -static inline int security_syslog(int type)
68351 +static inline int security_syslog(int type, bool from_file)
68352 {
68353 - return cap_syslog(type);
68354 + return cap_syslog(type, from_file);
68355 }
68356
68357 static inline int security_settime(struct timespec *ts, struct timezone *tz)
68358 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
68359 index 8366d8f..2307490 100644
68360 --- a/include/linux/seq_file.h
68361 +++ b/include/linux/seq_file.h
68362 @@ -32,6 +32,7 @@ struct seq_operations {
68363 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
68364 int (*show) (struct seq_file *m, void *v);
68365 };
68366 +typedef struct seq_operations __no_const seq_operations_no_const;
68367
68368 #define SEQ_SKIP 1
68369
68370 diff --git a/include/linux/shm.h b/include/linux/shm.h
68371 index eca6235..c7417ed 100644
68372 --- a/include/linux/shm.h
68373 +++ b/include/linux/shm.h
68374 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the kernel */
68375 pid_t shm_cprid;
68376 pid_t shm_lprid;
68377 struct user_struct *mlock_user;
68378 +#ifdef CONFIG_GRKERNSEC
68379 + time_t shm_createtime;
68380 + pid_t shm_lapid;
68381 +#endif
68382 };
68383
68384 /* shm_mode upper byte flags */
68385 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
68386 index bcdd660..6e12e11 100644
68387 --- a/include/linux/skbuff.h
68388 +++ b/include/linux/skbuff.h
68389 @@ -14,6 +14,7 @@
68390 #ifndef _LINUX_SKBUFF_H
68391 #define _LINUX_SKBUFF_H
68392
68393 +#include <linux/const.h>
68394 #include <linux/kernel.h>
68395 #include <linux/kmemcheck.h>
68396 #include <linux/compiler.h>
68397 @@ -544,7 +545,7 @@ static inline union skb_shared_tx *skb_tx(struct sk_buff *skb)
68398 */
68399 static inline int skb_queue_empty(const struct sk_buff_head *list)
68400 {
68401 - return list->next == (struct sk_buff *)list;
68402 + return list->next == (const struct sk_buff *)list;
68403 }
68404
68405 /**
68406 @@ -557,7 +558,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
68407 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68408 const struct sk_buff *skb)
68409 {
68410 - return (skb->next == (struct sk_buff *) list);
68411 + return (skb->next == (const struct sk_buff *) list);
68412 }
68413
68414 /**
68415 @@ -570,7 +571,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68416 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
68417 const struct sk_buff *skb)
68418 {
68419 - return (skb->prev == (struct sk_buff *) list);
68420 + return (skb->prev == (const struct sk_buff *) list);
68421 }
68422
68423 /**
68424 @@ -1367,7 +1368,7 @@ static inline int skb_network_offset(const struct sk_buff *skb)
68425 * headroom, you should not reduce this.
68426 */
68427 #ifndef NET_SKB_PAD
68428 -#define NET_SKB_PAD 32
68429 +#define NET_SKB_PAD (_AC(32,UL))
68430 #endif
68431
68432 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
68433 diff --git a/include/linux/slab.h b/include/linux/slab.h
68434 index 2da8372..a3be824 100644
68435 --- a/include/linux/slab.h
68436 +++ b/include/linux/slab.h
68437 @@ -11,12 +11,20 @@
68438
68439 #include <linux/gfp.h>
68440 #include <linux/types.h>
68441 +#include <linux/err.h>
68442
68443 /*
68444 * Flags to pass to kmem_cache_create().
68445 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
68446 */
68447 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
68448 +
68449 +#ifdef CONFIG_PAX_USERCOPY
68450 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
68451 +#else
68452 +#define SLAB_USERCOPY 0x00000000UL
68453 +#endif
68454 +
68455 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
68456 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
68457 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
68458 @@ -82,10 +90,13 @@
68459 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
68460 * Both make kfree a no-op.
68461 */
68462 -#define ZERO_SIZE_PTR ((void *)16)
68463 +#define ZERO_SIZE_PTR \
68464 +({ \
68465 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
68466 + (void *)(-MAX_ERRNO-1L); \
68467 +})
68468
68469 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
68470 - (unsigned long)ZERO_SIZE_PTR)
68471 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
68472
68473 /*
68474 * struct kmem_cache related prototypes
68475 @@ -138,6 +149,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
68476 void kfree(const void *);
68477 void kzfree(const void *);
68478 size_t ksize(const void *);
68479 +void check_object_size(const void *ptr, unsigned long n, bool to);
68480
68481 /*
68482 * Allocator specific definitions. These are mainly used to establish optimized
68483 @@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
68484
68485 void __init kmem_cache_init_late(void);
68486
68487 +#define kmalloc(x, y) \
68488 +({ \
68489 + void *___retval; \
68490 + intoverflow_t ___x = (intoverflow_t)x; \
68491 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
68492 + ___retval = NULL; \
68493 + else \
68494 + ___retval = kmalloc((size_t)___x, (y)); \
68495 + ___retval; \
68496 +})
68497 +
68498 +#define kmalloc_node(x, y, z) \
68499 +({ \
68500 + void *___retval; \
68501 + intoverflow_t ___x = (intoverflow_t)x; \
68502 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
68503 + ___retval = NULL; \
68504 + else \
68505 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
68506 + ___retval; \
68507 +})
68508 +
68509 +#define kzalloc(x, y) \
68510 +({ \
68511 + void *___retval; \
68512 + intoverflow_t ___x = (intoverflow_t)x; \
68513 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
68514 + ___retval = NULL; \
68515 + else \
68516 + ___retval = kzalloc((size_t)___x, (y)); \
68517 + ___retval; \
68518 +})
68519 +
68520 #endif /* _LINUX_SLAB_H */
68521 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
68522 index 850d057..d9dfe3c 100644
68523 --- a/include/linux/slab_def.h
68524 +++ b/include/linux/slab_def.h
68525 @@ -69,10 +69,10 @@ struct kmem_cache {
68526 unsigned long node_allocs;
68527 unsigned long node_frees;
68528 unsigned long node_overflow;
68529 - atomic_t allochit;
68530 - atomic_t allocmiss;
68531 - atomic_t freehit;
68532 - atomic_t freemiss;
68533 + atomic_unchecked_t allochit;
68534 + atomic_unchecked_t allocmiss;
68535 + atomic_unchecked_t freehit;
68536 + atomic_unchecked_t freemiss;
68537
68538 /*
68539 * If debugging is enabled, then the allocator can add additional
68540 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
68541 index 5ad70a6..57f9f65 100644
68542 --- a/include/linux/slub_def.h
68543 +++ b/include/linux/slub_def.h
68544 @@ -86,7 +86,7 @@ struct kmem_cache {
68545 struct kmem_cache_order_objects max;
68546 struct kmem_cache_order_objects min;
68547 gfp_t allocflags; /* gfp flags to use on each alloc */
68548 - int refcount; /* Refcount for slab cache destroy */
68549 + atomic_t refcount; /* Refcount for slab cache destroy */
68550 void (*ctor)(void *);
68551 int inuse; /* Offset to metadata */
68552 int align; /* Alignment */
68553 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
68554 #endif
68555
68556 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
68557 -void *__kmalloc(size_t size, gfp_t flags);
68558 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
68559
68560 #ifdef CONFIG_KMEMTRACE
68561 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
68562 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
68563 index 67ad11f..0bbd8af 100644
68564 --- a/include/linux/sonet.h
68565 +++ b/include/linux/sonet.h
68566 @@ -61,7 +61,7 @@ struct sonet_stats {
68567 #include <asm/atomic.h>
68568
68569 struct k_sonet_stats {
68570 -#define __HANDLE_ITEM(i) atomic_t i
68571 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
68572 __SONET_ITEMS
68573 #undef __HANDLE_ITEM
68574 };
68575 diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
68576 index 6f52b4d..5500323 100644
68577 --- a/include/linux/sunrpc/cache.h
68578 +++ b/include/linux/sunrpc/cache.h
68579 @@ -125,7 +125,7 @@ struct cache_detail {
68580 */
68581 struct cache_req {
68582 struct cache_deferred_req *(*defer)(struct cache_req *req);
68583 -};
68584 +} __no_const;
68585 /* this must be embedded in a deferred_request that is being
68586 * delayed awaiting cache-fill
68587 */
68588 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
68589 index 8ed9642..101ceab 100644
68590 --- a/include/linux/sunrpc/clnt.h
68591 +++ b/include/linux/sunrpc/clnt.h
68592 @@ -167,9 +167,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
68593 {
68594 switch (sap->sa_family) {
68595 case AF_INET:
68596 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
68597 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
68598 case AF_INET6:
68599 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
68600 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
68601 }
68602 return 0;
68603 }
68604 @@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
68605 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
68606 const struct sockaddr *src)
68607 {
68608 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
68609 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
68610 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
68611
68612 dsin->sin_family = ssin->sin_family;
68613 @@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
68614 if (sa->sa_family != AF_INET6)
68615 return 0;
68616
68617 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
68618 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
68619 }
68620
68621 #endif /* __KERNEL__ */
68622 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
68623 index c14fe86..393245e 100644
68624 --- a/include/linux/sunrpc/svc_rdma.h
68625 +++ b/include/linux/sunrpc/svc_rdma.h
68626 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
68627 extern unsigned int svcrdma_max_requests;
68628 extern unsigned int svcrdma_max_req_size;
68629
68630 -extern atomic_t rdma_stat_recv;
68631 -extern atomic_t rdma_stat_read;
68632 -extern atomic_t rdma_stat_write;
68633 -extern atomic_t rdma_stat_sq_starve;
68634 -extern atomic_t rdma_stat_rq_starve;
68635 -extern atomic_t rdma_stat_rq_poll;
68636 -extern atomic_t rdma_stat_rq_prod;
68637 -extern atomic_t rdma_stat_sq_poll;
68638 -extern atomic_t rdma_stat_sq_prod;
68639 +extern atomic_unchecked_t rdma_stat_recv;
68640 +extern atomic_unchecked_t rdma_stat_read;
68641 +extern atomic_unchecked_t rdma_stat_write;
68642 +extern atomic_unchecked_t rdma_stat_sq_starve;
68643 +extern atomic_unchecked_t rdma_stat_rq_starve;
68644 +extern atomic_unchecked_t rdma_stat_rq_poll;
68645 +extern atomic_unchecked_t rdma_stat_rq_prod;
68646 +extern atomic_unchecked_t rdma_stat_sq_poll;
68647 +extern atomic_unchecked_t rdma_stat_sq_prod;
68648
68649 #define RPCRDMA_VERSION 1
68650
68651 diff --git a/include/linux/suspend.h b/include/linux/suspend.h
68652 index 5e781d8..1e62818 100644
68653 --- a/include/linux/suspend.h
68654 +++ b/include/linux/suspend.h
68655 @@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
68656 * which require special recovery actions in that situation.
68657 */
68658 struct platform_suspend_ops {
68659 - int (*valid)(suspend_state_t state);
68660 - int (*begin)(suspend_state_t state);
68661 - int (*prepare)(void);
68662 - int (*prepare_late)(void);
68663 - int (*enter)(suspend_state_t state);
68664 - void (*wake)(void);
68665 - void (*finish)(void);
68666 - void (*end)(void);
68667 - void (*recover)(void);
68668 + int (* const valid)(suspend_state_t state);
68669 + int (* const begin)(suspend_state_t state);
68670 + int (* const prepare)(void);
68671 + int (* const prepare_late)(void);
68672 + int (* const enter)(suspend_state_t state);
68673 + void (* const wake)(void);
68674 + void (* const finish)(void);
68675 + void (* const end)(void);
68676 + void (* const recover)(void);
68677 };
68678
68679 #ifdef CONFIG_SUSPEND
68680 @@ -120,7 +120,7 @@ struct platform_suspend_ops {
68681 * suspend_set_ops - set platform dependent suspend operations
68682 * @ops: The new suspend operations to set.
68683 */
68684 -extern void suspend_set_ops(struct platform_suspend_ops *ops);
68685 +extern void suspend_set_ops(const struct platform_suspend_ops *ops);
68686 extern int suspend_valid_only_mem(suspend_state_t state);
68687
68688 /**
68689 @@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t state);
68690 #else /* !CONFIG_SUSPEND */
68691 #define suspend_valid_only_mem NULL
68692
68693 -static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
68694 +static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
68695 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
68696 #endif /* !CONFIG_SUSPEND */
68697
68698 @@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone *zone);
68699 * platforms which require special recovery actions in that situation.
68700 */
68701 struct platform_hibernation_ops {
68702 - int (*begin)(void);
68703 - void (*end)(void);
68704 - int (*pre_snapshot)(void);
68705 - void (*finish)(void);
68706 - int (*prepare)(void);
68707 - int (*enter)(void);
68708 - void (*leave)(void);
68709 - int (*pre_restore)(void);
68710 - void (*restore_cleanup)(void);
68711 - void (*recover)(void);
68712 + int (* const begin)(void);
68713 + void (* const end)(void);
68714 + int (* const pre_snapshot)(void);
68715 + void (* const finish)(void);
68716 + int (* const prepare)(void);
68717 + int (* const enter)(void);
68718 + void (* const leave)(void);
68719 + int (* const pre_restore)(void);
68720 + void (* const restore_cleanup)(void);
68721 + void (* const recover)(void);
68722 };
68723
68724 #ifdef CONFIG_HIBERNATION
68725 @@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct page *);
68726 extern void swsusp_unset_page_free(struct page *);
68727 extern unsigned long get_safe_page(gfp_t gfp_mask);
68728
68729 -extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
68730 +extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
68731 extern int hibernate(void);
68732 extern bool system_entering_hibernation(void);
68733 #else /* CONFIG_HIBERNATION */
68734 @@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
68735 static inline void swsusp_set_page_free(struct page *p) {}
68736 static inline void swsusp_unset_page_free(struct page *p) {}
68737
68738 -static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
68739 +static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
68740 static inline int hibernate(void) { return -ENOSYS; }
68741 static inline bool system_entering_hibernation(void) { return false; }
68742 #endif /* CONFIG_HIBERNATION */
68743 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
68744 index 0eb6942..a805cb6 100644
68745 --- a/include/linux/sysctl.h
68746 +++ b/include/linux/sysctl.h
68747 @@ -164,7 +164,11 @@ enum
68748 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68749 };
68750
68751 -
68752 +#ifdef CONFIG_PAX_SOFTMODE
68753 +enum {
68754 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68755 +};
68756 +#endif
68757
68758 /* CTL_VM names: */
68759 enum
68760 @@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
68761
68762 extern int proc_dostring(struct ctl_table *, int,
68763 void __user *, size_t *, loff_t *);
68764 +extern int proc_dostring_modpriv(struct ctl_table *, int,
68765 + void __user *, size_t *, loff_t *);
68766 extern int proc_dointvec(struct ctl_table *, int,
68767 void __user *, size_t *, loff_t *);
68768 extern int proc_dointvec_minmax(struct ctl_table *, int,
68769 @@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name, int nlen,
68770
68771 extern ctl_handler sysctl_data;
68772 extern ctl_handler sysctl_string;
68773 +extern ctl_handler sysctl_string_modpriv;
68774 extern ctl_handler sysctl_intvec;
68775 extern ctl_handler sysctl_jiffies;
68776 extern ctl_handler sysctl_ms_jiffies;
68777 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
68778 index 9d68fed..71f02cc 100644
68779 --- a/include/linux/sysfs.h
68780 +++ b/include/linux/sysfs.h
68781 @@ -75,8 +75,8 @@ struct bin_attribute {
68782 };
68783
68784 struct sysfs_ops {
68785 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
68786 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
68787 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
68788 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
68789 };
68790
68791 struct sysfs_dirent;
68792 diff --git a/include/linux/syslog.h b/include/linux/syslog.h
68793 new file mode 100644
68794 index 0000000..3891139
68795 --- /dev/null
68796 +++ b/include/linux/syslog.h
68797 @@ -0,0 +1,52 @@
68798 +/* Syslog internals
68799 + *
68800 + * Copyright 2010 Canonical, Ltd.
68801 + * Author: Kees Cook <kees.cook@canonical.com>
68802 + *
68803 + * This program is free software; you can redistribute it and/or modify
68804 + * it under the terms of the GNU General Public License as published by
68805 + * the Free Software Foundation; either version 2, or (at your option)
68806 + * any later version.
68807 + *
68808 + * This program is distributed in the hope that it will be useful,
68809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
68810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68811 + * GNU General Public License for more details.
68812 + *
68813 + * You should have received a copy of the GNU General Public License
68814 + * along with this program; see the file COPYING. If not, write to
68815 + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
68816 + */
68817 +
68818 +#ifndef _LINUX_SYSLOG_H
68819 +#define _LINUX_SYSLOG_H
68820 +
68821 +/* Close the log. Currently a NOP. */
68822 +#define SYSLOG_ACTION_CLOSE 0
68823 +/* Open the log. Currently a NOP. */
68824 +#define SYSLOG_ACTION_OPEN 1
68825 +/* Read from the log. */
68826 +#define SYSLOG_ACTION_READ 2
68827 +/* Read all messages remaining in the ring buffer. */
68828 +#define SYSLOG_ACTION_READ_ALL 3
68829 +/* Read and clear all messages remaining in the ring buffer */
68830 +#define SYSLOG_ACTION_READ_CLEAR 4
68831 +/* Clear ring buffer. */
68832 +#define SYSLOG_ACTION_CLEAR 5
68833 +/* Disable printk's to console */
68834 +#define SYSLOG_ACTION_CONSOLE_OFF 6
68835 +/* Enable printk's to console */
68836 +#define SYSLOG_ACTION_CONSOLE_ON 7
68837 +/* Set level of messages printed to console */
68838 +#define SYSLOG_ACTION_CONSOLE_LEVEL 8
68839 +/* Return number of unread characters in the log buffer */
68840 +#define SYSLOG_ACTION_SIZE_UNREAD 9
68841 +/* Return size of the log buffer */
68842 +#define SYSLOG_ACTION_SIZE_BUFFER 10
68843 +
68844 +#define SYSLOG_FROM_CALL 0
68845 +#define SYSLOG_FROM_FILE 1
68846 +
68847 +int do_syslog(int type, char __user *buf, int count, bool from_file);
68848 +
68849 +#endif /* _LINUX_SYSLOG_H */
68850 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
68851 index a8cc4e1..98d3b85 100644
68852 --- a/include/linux/thread_info.h
68853 +++ b/include/linux/thread_info.h
68854 @@ -23,7 +23,7 @@ struct restart_block {
68855 };
68856 /* For futex_wait and futex_wait_requeue_pi */
68857 struct {
68858 - u32 *uaddr;
68859 + u32 __user *uaddr;
68860 u32 val;
68861 u32 flags;
68862 u32 bitset;
68863 diff --git a/include/linux/tty.h b/include/linux/tty.h
68864 index e9c57e9..ee6d489 100644
68865 --- a/include/linux/tty.h
68866 +++ b/include/linux/tty.h
68867 @@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
68868 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
68869 extern void tty_ldisc_enable(struct tty_struct *tty);
68870
68871 -
68872 /* n_tty.c */
68873 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
68874
68875 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
68876 index 0c4ee9b..9f7c426 100644
68877 --- a/include/linux/tty_ldisc.h
68878 +++ b/include/linux/tty_ldisc.h
68879 @@ -139,7 +139,7 @@ struct tty_ldisc_ops {
68880
68881 struct module *owner;
68882
68883 - int refcount;
68884 + atomic_t refcount;
68885 };
68886
68887 struct tty_ldisc {
68888 diff --git a/include/linux/types.h b/include/linux/types.h
68889 index c42724f..d190eee 100644
68890 --- a/include/linux/types.h
68891 +++ b/include/linux/types.h
68892 @@ -191,10 +191,26 @@ typedef struct {
68893 volatile int counter;
68894 } atomic_t;
68895
68896 +#ifdef CONFIG_PAX_REFCOUNT
68897 +typedef struct {
68898 + volatile int counter;
68899 +} atomic_unchecked_t;
68900 +#else
68901 +typedef atomic_t atomic_unchecked_t;
68902 +#endif
68903 +
68904 #ifdef CONFIG_64BIT
68905 typedef struct {
68906 volatile long counter;
68907 } atomic64_t;
68908 +
68909 +#ifdef CONFIG_PAX_REFCOUNT
68910 +typedef struct {
68911 + volatile long counter;
68912 +} atomic64_unchecked_t;
68913 +#else
68914 +typedef atomic64_t atomic64_unchecked_t;
68915 +#endif
68916 #endif
68917
68918 struct ustat {
68919 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
68920 index 6b58367..53a3e8e 100644
68921 --- a/include/linux/uaccess.h
68922 +++ b/include/linux/uaccess.h
68923 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
68924 long ret; \
68925 mm_segment_t old_fs = get_fs(); \
68926 \
68927 - set_fs(KERNEL_DS); \
68928 pagefault_disable(); \
68929 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
68930 - pagefault_enable(); \
68931 + set_fs(KERNEL_DS); \
68932 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
68933 set_fs(old_fs); \
68934 + pagefault_enable(); \
68935 ret; \
68936 })
68937
68938 @@ -93,7 +93,7 @@ static inline unsigned long __copy_from_user_nocache(void *to,
68939 * Safely read from address @src to the buffer at @dst. If a kernel fault
68940 * happens, handle that and return -EFAULT.
68941 */
68942 -extern long probe_kernel_read(void *dst, void *src, size_t size);
68943 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
68944
68945 /*
68946 * probe_kernel_write(): safely attempt to write to a location
68947 @@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst, void *src, size_t size);
68948 * Safely write to address @dst from the buffer at @src. If a kernel fault
68949 * happens, handle that and return -EFAULT.
68950 */
68951 -extern long probe_kernel_write(void *dst, void *src, size_t size);
68952 +extern long probe_kernel_write(void *dst, const void *src, size_t size);
68953
68954 #endif /* __LINUX_UACCESS_H__ */
68955 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
68956 index 99c1b4d..bb94261 100644
68957 --- a/include/linux/unaligned/access_ok.h
68958 +++ b/include/linux/unaligned/access_ok.h
68959 @@ -6,32 +6,32 @@
68960
68961 static inline u16 get_unaligned_le16(const void *p)
68962 {
68963 - return le16_to_cpup((__le16 *)p);
68964 + return le16_to_cpup((const __le16 *)p);
68965 }
68966
68967 static inline u32 get_unaligned_le32(const void *p)
68968 {
68969 - return le32_to_cpup((__le32 *)p);
68970 + return le32_to_cpup((const __le32 *)p);
68971 }
68972
68973 static inline u64 get_unaligned_le64(const void *p)
68974 {
68975 - return le64_to_cpup((__le64 *)p);
68976 + return le64_to_cpup((const __le64 *)p);
68977 }
68978
68979 static inline u16 get_unaligned_be16(const void *p)
68980 {
68981 - return be16_to_cpup((__be16 *)p);
68982 + return be16_to_cpup((const __be16 *)p);
68983 }
68984
68985 static inline u32 get_unaligned_be32(const void *p)
68986 {
68987 - return be32_to_cpup((__be32 *)p);
68988 + return be32_to_cpup((const __be32 *)p);
68989 }
68990
68991 static inline u64 get_unaligned_be64(const void *p)
68992 {
68993 - return be64_to_cpup((__be64 *)p);
68994 + return be64_to_cpup((const __be64 *)p);
68995 }
68996
68997 static inline void put_unaligned_le16(u16 val, void *p)
68998 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
68999 index 79b9837..b5a56f9 100644
69000 --- a/include/linux/vermagic.h
69001 +++ b/include/linux/vermagic.h
69002 @@ -26,9 +26,35 @@
69003 #define MODULE_ARCH_VERMAGIC ""
69004 #endif
69005
69006 +#ifdef CONFIG_PAX_REFCOUNT
69007 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
69008 +#else
69009 +#define MODULE_PAX_REFCOUNT ""
69010 +#endif
69011 +
69012 +#ifdef CONSTIFY_PLUGIN
69013 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
69014 +#else
69015 +#define MODULE_CONSTIFY_PLUGIN ""
69016 +#endif
69017 +
69018 +#ifdef STACKLEAK_PLUGIN
69019 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
69020 +#else
69021 +#define MODULE_STACKLEAK_PLUGIN ""
69022 +#endif
69023 +
69024 +#ifdef CONFIG_GRKERNSEC
69025 +#define MODULE_GRSEC "GRSEC "
69026 +#else
69027 +#define MODULE_GRSEC ""
69028 +#endif
69029 +
69030 #define VERMAGIC_STRING \
69031 UTS_RELEASE " " \
69032 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
69033 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
69034 - MODULE_ARCH_VERMAGIC
69035 + MODULE_ARCH_VERMAGIC \
69036 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
69037 + MODULE_GRSEC
69038
69039 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
69040 index 819a634..462ac12 100644
69041 --- a/include/linux/vmalloc.h
69042 +++ b/include/linux/vmalloc.h
69043 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
69044 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
69045 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
69046 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
69047 +
69048 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
69049 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
69050 +#endif
69051 +
69052 /* bits [20..32] reserved for arch specific ioremap internals */
69053
69054 /*
69055 @@ -124,4 +129,81 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
69056
69057 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
69058
69059 +#define vmalloc(x) \
69060 +({ \
69061 + void *___retval; \
69062 + intoverflow_t ___x = (intoverflow_t)x; \
69063 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
69064 + ___retval = NULL; \
69065 + else \
69066 + ___retval = vmalloc((unsigned long)___x); \
69067 + ___retval; \
69068 +})
69069 +
69070 +#define __vmalloc(x, y, z) \
69071 +({ \
69072 + void *___retval; \
69073 + intoverflow_t ___x = (intoverflow_t)x; \
69074 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
69075 + ___retval = NULL; \
69076 + else \
69077 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
69078 + ___retval; \
69079 +})
69080 +
69081 +#define vmalloc_user(x) \
69082 +({ \
69083 + void *___retval; \
69084 + intoverflow_t ___x = (intoverflow_t)x; \
69085 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
69086 + ___retval = NULL; \
69087 + else \
69088 + ___retval = vmalloc_user((unsigned long)___x); \
69089 + ___retval; \
69090 +})
69091 +
69092 +#define vmalloc_exec(x) \
69093 +({ \
69094 + void *___retval; \
69095 + intoverflow_t ___x = (intoverflow_t)x; \
69096 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
69097 + ___retval = NULL; \
69098 + else \
69099 + ___retval = vmalloc_exec((unsigned long)___x); \
69100 + ___retval; \
69101 +})
69102 +
69103 +#define vmalloc_node(x, y) \
69104 +({ \
69105 + void *___retval; \
69106 + intoverflow_t ___x = (intoverflow_t)x; \
69107 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
69108 + ___retval = NULL; \
69109 + else \
69110 + ___retval = vmalloc_node((unsigned long)___x, (y));\
69111 + ___retval; \
69112 +})
69113 +
69114 +#define vmalloc_32(x) \
69115 +({ \
69116 + void *___retval; \
69117 + intoverflow_t ___x = (intoverflow_t)x; \
69118 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
69119 + ___retval = NULL; \
69120 + else \
69121 + ___retval = vmalloc_32((unsigned long)___x); \
69122 + ___retval; \
69123 +})
69124 +
69125 +#define vmalloc_32_user(x) \
69126 +({ \
69127 + void *___retval; \
69128 + intoverflow_t ___x = (intoverflow_t)x; \
69129 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
69130 + ___retval = NULL; \
69131 + else \
69132 + ___retval = vmalloc_32_user((unsigned long)___x);\
69133 + ___retval; \
69134 +})
69135 +
69136 #endif /* _LINUX_VMALLOC_H */
69137 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
69138 index 13070d6..aa4159a 100644
69139 --- a/include/linux/vmstat.h
69140 +++ b/include/linux/vmstat.h
69141 @@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(int cpu)
69142 /*
69143 * Zone based page accounting with per cpu differentials.
69144 */
69145 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69146 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69147
69148 static inline void zone_page_state_add(long x, struct zone *zone,
69149 enum zone_stat_item item)
69150 {
69151 - atomic_long_add(x, &zone->vm_stat[item]);
69152 - atomic_long_add(x, &vm_stat[item]);
69153 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
69154 + atomic_long_add_unchecked(x, &vm_stat[item]);
69155 }
69156
69157 static inline unsigned long global_page_state(enum zone_stat_item item)
69158 {
69159 - long x = atomic_long_read(&vm_stat[item]);
69160 + long x = atomic_long_read_unchecked(&vm_stat[item]);
69161 #ifdef CONFIG_SMP
69162 if (x < 0)
69163 x = 0;
69164 @@ -158,7 +158,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
69165 static inline unsigned long zone_page_state(struct zone *zone,
69166 enum zone_stat_item item)
69167 {
69168 - long x = atomic_long_read(&zone->vm_stat[item]);
69169 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69170 #ifdef CONFIG_SMP
69171 if (x < 0)
69172 x = 0;
69173 @@ -175,7 +175,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
69174 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
69175 enum zone_stat_item item)
69176 {
69177 - long x = atomic_long_read(&zone->vm_stat[item]);
69178 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69179
69180 #ifdef CONFIG_SMP
69181 int cpu;
69182 @@ -264,8 +264,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
69183
69184 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
69185 {
69186 - atomic_long_inc(&zone->vm_stat[item]);
69187 - atomic_long_inc(&vm_stat[item]);
69188 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
69189 + atomic_long_inc_unchecked(&vm_stat[item]);
69190 }
69191
69192 static inline void __inc_zone_page_state(struct page *page,
69193 @@ -276,8 +276,8 @@ static inline void __inc_zone_page_state(struct page *page,
69194
69195 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
69196 {
69197 - atomic_long_dec(&zone->vm_stat[item]);
69198 - atomic_long_dec(&vm_stat[item]);
69199 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
69200 + atomic_long_dec_unchecked(&vm_stat[item]);
69201 }
69202
69203 static inline void __dec_zone_page_state(struct page *page,
69204 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
69205 index eed5fcc..5080d24 100644
69206 --- a/include/media/saa7146_vv.h
69207 +++ b/include/media/saa7146_vv.h
69208 @@ -167,7 +167,7 @@ struct saa7146_ext_vv
69209 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
69210
69211 /* the extension can override this */
69212 - struct v4l2_ioctl_ops ops;
69213 + v4l2_ioctl_ops_no_const ops;
69214 /* pointer to the saa7146 core ops */
69215 const struct v4l2_ioctl_ops *core_ops;
69216
69217 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
69218 index 73c9867..2da8837 100644
69219 --- a/include/media/v4l2-dev.h
69220 +++ b/include/media/v4l2-dev.h
69221 @@ -34,7 +34,7 @@ struct v4l2_device;
69222 #define V4L2_FL_UNREGISTERED (0)
69223
69224 struct v4l2_file_operations {
69225 - struct module *owner;
69226 + struct module * const owner;
69227 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
69228 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
69229 unsigned int (*poll) (struct file *, struct poll_table_struct *);
69230 @@ -46,6 +46,7 @@ struct v4l2_file_operations {
69231 int (*open) (struct file *);
69232 int (*release) (struct file *);
69233 };
69234 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
69235
69236 /*
69237 * Newer version of video_device, handled by videodev2.c
69238 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
69239 index 5d5d550..f559ef1 100644
69240 --- a/include/media/v4l2-device.h
69241 +++ b/include/media/v4l2-device.h
69242 @@ -71,7 +71,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
69243 this function returns 0. If the name ends with a digit (e.g. cx18),
69244 then the name will be set to cx18-0 since cx180 looks really odd. */
69245 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
69246 - atomic_t *instance);
69247 + atomic_unchecked_t *instance);
69248
69249 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
69250 Since the parent disappears this ensures that v4l2_dev doesn't have an
69251 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
69252 index 7a4529d..7244290 100644
69253 --- a/include/media/v4l2-ioctl.h
69254 +++ b/include/media/v4l2-ioctl.h
69255 @@ -243,6 +243,7 @@ struct v4l2_ioctl_ops {
69256 long (*vidioc_default) (struct file *file, void *fh,
69257 int cmd, void *arg);
69258 };
69259 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
69260
69261
69262 /* v4l debugging and diagnostics */
69263 diff --git a/include/net/flow.h b/include/net/flow.h
69264 index 809970b..c3df4f3 100644
69265 --- a/include/net/flow.h
69266 +++ b/include/net/flow.h
69267 @@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net *net, struct flowi *key, u16 family,
69268 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
69269 u8 dir, flow_resolve_t resolver);
69270 extern void flow_cache_flush(void);
69271 -extern atomic_t flow_cache_genid;
69272 +extern atomic_unchecked_t flow_cache_genid;
69273
69274 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
69275 {
69276 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
69277 index 15e1f8fe..668837c 100644
69278 --- a/include/net/inetpeer.h
69279 +++ b/include/net/inetpeer.h
69280 @@ -24,7 +24,7 @@ struct inet_peer
69281 __u32 dtime; /* the time of last use of not
69282 * referenced entries */
69283 atomic_t refcnt;
69284 - atomic_t rid; /* Frag reception counter */
69285 + atomic_unchecked_t rid; /* Frag reception counter */
69286 __u32 tcp_ts;
69287 unsigned long tcp_ts_stamp;
69288 };
69289 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
69290 index 98978e7..2243a3d 100644
69291 --- a/include/net/ip_vs.h
69292 +++ b/include/net/ip_vs.h
69293 @@ -365,7 +365,7 @@ struct ip_vs_conn {
69294 struct ip_vs_conn *control; /* Master control connection */
69295 atomic_t n_control; /* Number of controlled ones */
69296 struct ip_vs_dest *dest; /* real server */
69297 - atomic_t in_pkts; /* incoming packet counter */
69298 + atomic_unchecked_t in_pkts; /* incoming packet counter */
69299
69300 /* packet transmitter for different forwarding methods. If it
69301 mangles the packet, it must return NF_DROP or better NF_STOLEN,
69302 @@ -466,7 +466,7 @@ struct ip_vs_dest {
69303 union nf_inet_addr addr; /* IP address of the server */
69304 __be16 port; /* port number of the server */
69305 volatile unsigned flags; /* dest status flags */
69306 - atomic_t conn_flags; /* flags to copy to conn */
69307 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
69308 atomic_t weight; /* server weight */
69309
69310 atomic_t refcnt; /* reference counter */
69311 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
69312 index 69b610a..fe3962c 100644
69313 --- a/include/net/irda/ircomm_core.h
69314 +++ b/include/net/irda/ircomm_core.h
69315 @@ -51,7 +51,7 @@ typedef struct {
69316 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
69317 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
69318 struct ircomm_info *);
69319 -} call_t;
69320 +} __no_const call_t;
69321
69322 struct ircomm_cb {
69323 irda_queue_t queue;
69324 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
69325 index eea2e61..08c692d 100644
69326 --- a/include/net/irda/ircomm_tty.h
69327 +++ b/include/net/irda/ircomm_tty.h
69328 @@ -35,6 +35,7 @@
69329 #include <linux/termios.h>
69330 #include <linux/timer.h>
69331 #include <linux/tty.h> /* struct tty_struct */
69332 +#include <asm/local.h>
69333
69334 #include <net/irda/irias_object.h>
69335 #include <net/irda/ircomm_core.h>
69336 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
69337 unsigned short close_delay;
69338 unsigned short closing_wait; /* time to wait before closing */
69339
69340 - int open_count;
69341 - int blocked_open; /* # of blocked opens */
69342 + local_t open_count;
69343 + local_t blocked_open; /* # of blocked opens */
69344
69345 /* Protect concurent access to :
69346 * o self->open_count
69347 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
69348 index f82a1e8..82d81e8 100644
69349 --- a/include/net/iucv/af_iucv.h
69350 +++ b/include/net/iucv/af_iucv.h
69351 @@ -87,7 +87,7 @@ struct iucv_sock {
69352 struct iucv_sock_list {
69353 struct hlist_head head;
69354 rwlock_t lock;
69355 - atomic_t autobind_name;
69356 + atomic_unchecked_t autobind_name;
69357 };
69358
69359 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
69360 diff --git a/include/net/lapb.h b/include/net/lapb.h
69361 index 96cb5dd..25e8d4f 100644
69362 --- a/include/net/lapb.h
69363 +++ b/include/net/lapb.h
69364 @@ -95,7 +95,7 @@ struct lapb_cb {
69365 struct sk_buff_head write_queue;
69366 struct sk_buff_head ack_queue;
69367 unsigned char window;
69368 - struct lapb_register_struct callbacks;
69369 + struct lapb_register_struct *callbacks;
69370
69371 /* FRMR control information */
69372 struct lapb_frame frmr_data;
69373 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
69374 index 3817fda..cdb2343 100644
69375 --- a/include/net/neighbour.h
69376 +++ b/include/net/neighbour.h
69377 @@ -131,7 +131,7 @@ struct neigh_ops
69378 int (*connected_output)(struct sk_buff*);
69379 int (*hh_output)(struct sk_buff*);
69380 int (*queue_xmit)(struct sk_buff*);
69381 -};
69382 +} __do_const;
69383
69384 struct pneigh_entry
69385 {
69386 diff --git a/include/net/netlink.h b/include/net/netlink.h
69387 index c344646..4778c71 100644
69388 --- a/include/net/netlink.h
69389 +++ b/include/net/netlink.h
69390 @@ -335,7 +335,7 @@ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
69391 {
69392 return (remaining >= (int) sizeof(struct nlmsghdr) &&
69393 nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
69394 - nlh->nlmsg_len <= remaining);
69395 + nlh->nlmsg_len <= (unsigned int)remaining);
69396 }
69397
69398 /**
69399 @@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
69400 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
69401 {
69402 if (mark)
69403 - skb_trim(skb, (unsigned char *) mark - skb->data);
69404 + skb_trim(skb, (const unsigned char *) mark - skb->data);
69405 }
69406
69407 /**
69408 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
69409 index 9a4b8b7..e49e077 100644
69410 --- a/include/net/netns/ipv4.h
69411 +++ b/include/net/netns/ipv4.h
69412 @@ -54,7 +54,7 @@ struct netns_ipv4 {
69413 int current_rt_cache_rebuild_count;
69414
69415 struct timer_list rt_secret_timer;
69416 - atomic_t rt_genid;
69417 + atomic_unchecked_t rt_genid;
69418
69419 #ifdef CONFIG_IP_MROUTE
69420 struct sock *mroute_sk;
69421 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
69422 index 8a6d529..171f401 100644
69423 --- a/include/net/sctp/sctp.h
69424 +++ b/include/net/sctp/sctp.h
69425 @@ -305,8 +305,8 @@ extern int sctp_debug_flag;
69426
69427 #else /* SCTP_DEBUG */
69428
69429 -#define SCTP_DEBUG_PRINTK(whatever...)
69430 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
69431 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
69432 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
69433 #define SCTP_ENABLE_DEBUG
69434 #define SCTP_DISABLE_DEBUG
69435 #define SCTP_ASSERT(expr, str, func)
69436 diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
69437 index d97f689..f3b90ab 100644
69438 --- a/include/net/secure_seq.h
69439 +++ b/include/net/secure_seq.h
69440 @@ -7,14 +7,14 @@ extern __u32 secure_ip_id(__be32 daddr);
69441 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
69442 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
69443 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
69444 - __be16 dport);
69445 + __be16 dport);
69446 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
69447 __be16 sport, __be16 dport);
69448 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69449 - __be16 sport, __be16 dport);
69450 + __be16 sport, __be16 dport);
69451 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
69452 - __be16 sport, __be16 dport);
69453 + __be16 sport, __be16 dport);
69454 extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69455 - __be16 sport, __be16 dport);
69456 + __be16 sport, __be16 dport);
69457
69458 #endif /* _NET_SECURE_SEQ */
69459 diff --git a/include/net/sock.h b/include/net/sock.h
69460 index 9f96394..76fc9c7 100644
69461 --- a/include/net/sock.h
69462 +++ b/include/net/sock.h
69463 @@ -272,7 +272,7 @@ struct sock {
69464 rwlock_t sk_callback_lock;
69465 int sk_err,
69466 sk_err_soft;
69467 - atomic_t sk_drops;
69468 + atomic_unchecked_t sk_drops;
69469 unsigned short sk_ack_backlog;
69470 unsigned short sk_max_ack_backlog;
69471 __u32 sk_priority;
69472 @@ -737,7 +737,7 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
69473 extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
69474 extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
69475 #else
69476 -static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
69477 +static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
69478 int inc)
69479 {
69480 }
69481 diff --git a/include/net/tcp.h b/include/net/tcp.h
69482 index 6cfe18b..dd21acb 100644
69483 --- a/include/net/tcp.h
69484 +++ b/include/net/tcp.h
69485 @@ -1444,8 +1444,8 @@ enum tcp_seq_states {
69486 struct tcp_seq_afinfo {
69487 char *name;
69488 sa_family_t family;
69489 - struct file_operations seq_fops;
69490 - struct seq_operations seq_ops;
69491 + file_operations_no_const seq_fops;
69492 + seq_operations_no_const seq_ops;
69493 };
69494
69495 struct tcp_iter_state {
69496 diff --git a/include/net/udp.h b/include/net/udp.h
69497 index f98abd2..b4b042f 100644
69498 --- a/include/net/udp.h
69499 +++ b/include/net/udp.h
69500 @@ -187,8 +187,8 @@ struct udp_seq_afinfo {
69501 char *name;
69502 sa_family_t family;
69503 struct udp_table *udp_table;
69504 - struct file_operations seq_fops;
69505 - struct seq_operations seq_ops;
69506 + file_operations_no_const seq_fops;
69507 + seq_operations_no_const seq_ops;
69508 };
69509
69510 struct udp_iter_state {
69511 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
69512 index cbb822e..e9c1cbe 100644
69513 --- a/include/rdma/iw_cm.h
69514 +++ b/include/rdma/iw_cm.h
69515 @@ -129,7 +129,7 @@ struct iw_cm_verbs {
69516 int backlog);
69517
69518 int (*destroy_listen)(struct iw_cm_id *cm_id);
69519 -};
69520 +} __no_const;
69521
69522 /**
69523 * iw_create_cm_id - Create an IW CM identifier.
69524 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
69525 index 09a124b..caa8ca8 100644
69526 --- a/include/scsi/libfc.h
69527 +++ b/include/scsi/libfc.h
69528 @@ -675,6 +675,7 @@ struct libfc_function_template {
69529 */
69530 void (*disc_stop_final) (struct fc_lport *);
69531 };
69532 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
69533
69534 /* information used by the discovery layer */
69535 struct fc_disc {
69536 @@ -707,7 +708,7 @@ struct fc_lport {
69537 struct fc_disc disc;
69538
69539 /* Operational Information */
69540 - struct libfc_function_template tt;
69541 + libfc_function_template_no_const tt;
69542 u8 link_up;
69543 u8 qfull;
69544 enum fc_lport_state state;
69545 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
69546 index de8e180..f15e0d7 100644
69547 --- a/include/scsi/scsi_device.h
69548 +++ b/include/scsi/scsi_device.h
69549 @@ -156,9 +156,9 @@ struct scsi_device {
69550 unsigned int max_device_blocked; /* what device_blocked counts down from */
69551 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
69552
69553 - atomic_t iorequest_cnt;
69554 - atomic_t iodone_cnt;
69555 - atomic_t ioerr_cnt;
69556 + atomic_unchecked_t iorequest_cnt;
69557 + atomic_unchecked_t iodone_cnt;
69558 + atomic_unchecked_t ioerr_cnt;
69559
69560 struct device sdev_gendev,
69561 sdev_dev;
69562 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
69563 index fc50bd6..81ba9cb 100644
69564 --- a/include/scsi/scsi_transport_fc.h
69565 +++ b/include/scsi/scsi_transport_fc.h
69566 @@ -708,7 +708,7 @@ struct fc_function_template {
69567 unsigned long show_host_system_hostname:1;
69568
69569 unsigned long disable_target_scan:1;
69570 -};
69571 +} __do_const;
69572
69573
69574 /**
69575 diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
69576 index 3dae3f7..8440d6f 100644
69577 --- a/include/sound/ac97_codec.h
69578 +++ b/include/sound/ac97_codec.h
69579 @@ -419,15 +419,15 @@
69580 struct snd_ac97;
69581
69582 struct snd_ac97_build_ops {
69583 - int (*build_3d) (struct snd_ac97 *ac97);
69584 - int (*build_specific) (struct snd_ac97 *ac97);
69585 - int (*build_spdif) (struct snd_ac97 *ac97);
69586 - int (*build_post_spdif) (struct snd_ac97 *ac97);
69587 + int (* const build_3d) (struct snd_ac97 *ac97);
69588 + int (* const build_specific) (struct snd_ac97 *ac97);
69589 + int (* const build_spdif) (struct snd_ac97 *ac97);
69590 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
69591 #ifdef CONFIG_PM
69592 - void (*suspend) (struct snd_ac97 *ac97);
69593 - void (*resume) (struct snd_ac97 *ac97);
69594 + void (* const suspend) (struct snd_ac97 *ac97);
69595 + void (* const resume) (struct snd_ac97 *ac97);
69596 #endif
69597 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69598 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69599 };
69600
69601 struct snd_ac97_bus_ops {
69602 @@ -477,7 +477,7 @@ struct snd_ac97_template {
69603
69604 struct snd_ac97 {
69605 /* -- lowlevel (hardware) driver specific -- */
69606 - struct snd_ac97_build_ops * build_ops;
69607 + const struct snd_ac97_build_ops * build_ops;
69608 void *private_data;
69609 void (*private_free) (struct snd_ac97 *ac97);
69610 /* --- */
69611 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
69612 index 891cf1a..a94ba2b 100644
69613 --- a/include/sound/ak4xxx-adda.h
69614 +++ b/include/sound/ak4xxx-adda.h
69615 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
69616 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
69617 unsigned char val);
69618 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
69619 -};
69620 +} __no_const;
69621
69622 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
69623
69624 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
69625 index 8c05e47..2b5df97 100644
69626 --- a/include/sound/hwdep.h
69627 +++ b/include/sound/hwdep.h
69628 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
69629 struct snd_hwdep_dsp_status *status);
69630 int (*dsp_load)(struct snd_hwdep *hw,
69631 struct snd_hwdep_dsp_image *image);
69632 -};
69633 +} __no_const;
69634
69635 struct snd_hwdep {
69636 struct snd_card *card;
69637 diff --git a/include/sound/info.h b/include/sound/info.h
69638 index 112e894..6fda5b5 100644
69639 --- a/include/sound/info.h
69640 +++ b/include/sound/info.h
69641 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
69642 struct snd_info_buffer *buffer);
69643 void (*write)(struct snd_info_entry *entry,
69644 struct snd_info_buffer *buffer);
69645 -};
69646 +} __no_const;
69647
69648 struct snd_info_entry_ops {
69649 int (*open)(struct snd_info_entry *entry,
69650 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
69651 index de6d981..590a550 100644
69652 --- a/include/sound/pcm.h
69653 +++ b/include/sound/pcm.h
69654 @@ -80,6 +80,7 @@ struct snd_pcm_ops {
69655 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
69656 int (*ack)(struct snd_pcm_substream *substream);
69657 };
69658 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
69659
69660 /*
69661 *
69662 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
69663 index 736eac7..fe8a80f 100644
69664 --- a/include/sound/sb16_csp.h
69665 +++ b/include/sound/sb16_csp.h
69666 @@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
69667 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
69668 int (*csp_stop) (struct snd_sb_csp * p);
69669 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
69670 -};
69671 +} __no_const;
69672
69673 /*
69674 * CSP private data
69675 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
69676 index 444cd6b..3327cc5 100644
69677 --- a/include/sound/ymfpci.h
69678 +++ b/include/sound/ymfpci.h
69679 @@ -358,7 +358,7 @@ struct snd_ymfpci {
69680 spinlock_t reg_lock;
69681 spinlock_t voice_lock;
69682 wait_queue_head_t interrupt_sleep;
69683 - atomic_t interrupt_sleep_count;
69684 + atomic_unchecked_t interrupt_sleep_count;
69685 struct snd_info_entry *proc_entry;
69686 const struct firmware *dsp_microcode;
69687 const struct firmware *controller_microcode;
69688 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
69689 index b89f9db..f097b38 100644
69690 --- a/include/trace/events/irq.h
69691 +++ b/include/trace/events/irq.h
69692 @@ -34,7 +34,7 @@
69693 */
69694 TRACE_EVENT(irq_handler_entry,
69695
69696 - TP_PROTO(int irq, struct irqaction *action),
69697 + TP_PROTO(int irq, const struct irqaction *action),
69698
69699 TP_ARGS(irq, action),
69700
69701 @@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
69702 */
69703 TRACE_EVENT(irq_handler_exit,
69704
69705 - TP_PROTO(int irq, struct irqaction *action, int ret),
69706 + TP_PROTO(int irq, const struct irqaction *action, int ret),
69707
69708 TP_ARGS(irq, action, ret),
69709
69710 @@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
69711 */
69712 TRACE_EVENT(softirq_entry,
69713
69714 - TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69715 + TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69716
69717 TP_ARGS(h, vec),
69718
69719 @@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
69720 */
69721 TRACE_EVENT(softirq_exit,
69722
69723 - TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69724 + TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69725
69726 TP_ARGS(h, vec),
69727
69728 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
69729 index 0993a22..32ba2fe 100644
69730 --- a/include/video/uvesafb.h
69731 +++ b/include/video/uvesafb.h
69732 @@ -177,6 +177,7 @@ struct uvesafb_par {
69733 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
69734 u8 pmi_setpal; /* PMI for palette changes */
69735 u16 *pmi_base; /* protected mode interface location */
69736 + u8 *pmi_code; /* protected mode code location */
69737 void *pmi_start;
69738 void *pmi_pal;
69739 u8 *vbe_state_orig; /*
69740 diff --git a/init/Kconfig b/init/Kconfig
69741 index d72691b..3996e54 100644
69742 --- a/init/Kconfig
69743 +++ b/init/Kconfig
69744 @@ -1004,7 +1004,7 @@ config SLUB_DEBUG
69745
69746 config COMPAT_BRK
69747 bool "Disable heap randomization"
69748 - default y
69749 + default n
69750 help
69751 Randomizing heap placement makes heap exploits harder, but it
69752 also breaks ancient binaries (including anything libc5 based).
69753 diff --git a/init/do_mounts.c b/init/do_mounts.c
69754 index bb008d0..4fa3933 100644
69755 --- a/init/do_mounts.c
69756 +++ b/init/do_mounts.c
69757 @@ -216,11 +216,11 @@ static void __init get_fs_names(char *page)
69758
69759 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
69760 {
69761 - int err = sys_mount(name, "/root", fs, flags, data);
69762 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
69763 if (err)
69764 return err;
69765
69766 - sys_chdir("/root");
69767 + sys_chdir((__force const char __user *)"/root");
69768 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
69769 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
69770 current->fs->pwd.mnt->mnt_sb->s_type->name,
69771 @@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...)
69772 va_start(args, fmt);
69773 vsprintf(buf, fmt, args);
69774 va_end(args);
69775 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
69776 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
69777 if (fd >= 0) {
69778 sys_ioctl(fd, FDEJECT, 0);
69779 sys_close(fd);
69780 }
69781 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
69782 - fd = sys_open("/dev/console", O_RDWR, 0);
69783 + fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
69784 if (fd >= 0) {
69785 sys_ioctl(fd, TCGETS, (long)&termios);
69786 termios.c_lflag &= ~ICANON;
69787 sys_ioctl(fd, TCSETSF, (long)&termios);
69788 - sys_read(fd, &c, 1);
69789 + sys_read(fd, (char __user *)&c, 1);
69790 termios.c_lflag |= ICANON;
69791 sys_ioctl(fd, TCSETSF, (long)&termios);
69792 sys_close(fd);
69793 @@ -416,6 +416,6 @@ void __init prepare_namespace(void)
69794 mount_root();
69795 out:
69796 devtmpfs_mount("dev");
69797 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
69798 - sys_chroot(".");
69799 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
69800 + sys_chroot((__force char __user *)".");
69801 }
69802 diff --git a/init/do_mounts.h b/init/do_mounts.h
69803 index f5b978a..69dbfe8 100644
69804 --- a/init/do_mounts.h
69805 +++ b/init/do_mounts.h
69806 @@ -15,15 +15,15 @@ extern int root_mountflags;
69807
69808 static inline int create_dev(char *name, dev_t dev)
69809 {
69810 - sys_unlink(name);
69811 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
69812 + sys_unlink((char __force_user *)name);
69813 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
69814 }
69815
69816 #if BITS_PER_LONG == 32
69817 static inline u32 bstat(char *name)
69818 {
69819 struct stat64 stat;
69820 - if (sys_stat64(name, &stat) != 0)
69821 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
69822 return 0;
69823 if (!S_ISBLK(stat.st_mode))
69824 return 0;
69825 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
69826 static inline u32 bstat(char *name)
69827 {
69828 struct stat stat;
69829 - if (sys_newstat(name, &stat) != 0)
69830 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
69831 return 0;
69832 if (!S_ISBLK(stat.st_mode))
69833 return 0;
69834 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
69835 index 614241b..4da046b 100644
69836 --- a/init/do_mounts_initrd.c
69837 +++ b/init/do_mounts_initrd.c
69838 @@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shell)
69839 sys_close(old_fd);sys_close(root_fd);
69840 sys_close(0);sys_close(1);sys_close(2);
69841 sys_setsid();
69842 - (void) sys_open("/dev/console",O_RDWR,0);
69843 + (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
69844 (void) sys_dup(0);
69845 (void) sys_dup(0);
69846 return kernel_execve(shell, argv, envp_init);
69847 @@ -47,13 +47,13 @@ static void __init handle_initrd(void)
69848 create_dev("/dev/root.old", Root_RAM0);
69849 /* mount initrd on rootfs' /root */
69850 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
69851 - sys_mkdir("/old", 0700);
69852 - root_fd = sys_open("/", 0, 0);
69853 - old_fd = sys_open("/old", 0, 0);
69854 + sys_mkdir((const char __force_user *)"/old", 0700);
69855 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
69856 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
69857 /* move initrd over / and chdir/chroot in initrd root */
69858 - sys_chdir("/root");
69859 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
69860 - sys_chroot(".");
69861 + sys_chdir((const char __force_user *)"/root");
69862 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
69863 + sys_chroot((const char __force_user *)".");
69864
69865 /*
69866 * In case that a resume from disk is carried out by linuxrc or one of
69867 @@ -70,15 +70,15 @@ static void __init handle_initrd(void)
69868
69869 /* move initrd to rootfs' /old */
69870 sys_fchdir(old_fd);
69871 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
69872 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
69873 /* switch root and cwd back to / of rootfs */
69874 sys_fchdir(root_fd);
69875 - sys_chroot(".");
69876 + sys_chroot((const char __force_user *)".");
69877 sys_close(old_fd);
69878 sys_close(root_fd);
69879
69880 if (new_decode_dev(real_root_dev) == Root_RAM0) {
69881 - sys_chdir("/old");
69882 + sys_chdir((const char __force_user *)"/old");
69883 return;
69884 }
69885
69886 @@ -86,17 +86,17 @@ static void __init handle_initrd(void)
69887 mount_root();
69888
69889 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
69890 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
69891 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
69892 if (!error)
69893 printk("okay\n");
69894 else {
69895 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
69896 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
69897 if (error == -ENOENT)
69898 printk("/initrd does not exist. Ignored.\n");
69899 else
69900 printk("failed\n");
69901 printk(KERN_NOTICE "Unmounting old root\n");
69902 - sys_umount("/old", MNT_DETACH);
69903 + sys_umount((char __force_user *)"/old", MNT_DETACH);
69904 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
69905 if (fd < 0) {
69906 error = fd;
69907 @@ -119,11 +119,11 @@ int __init initrd_load(void)
69908 * mounted in the normal path.
69909 */
69910 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
69911 - sys_unlink("/initrd.image");
69912 + sys_unlink((const char __force_user *)"/initrd.image");
69913 handle_initrd();
69914 return 1;
69915 }
69916 }
69917 - sys_unlink("/initrd.image");
69918 + sys_unlink((const char __force_user *)"/initrd.image");
69919 return 0;
69920 }
69921 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
69922 index 69aebbf..c0bf6a7 100644
69923 --- a/init/do_mounts_md.c
69924 +++ b/init/do_mounts_md.c
69925 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
69926 partitioned ? "_d" : "", minor,
69927 md_setup_args[ent].device_names);
69928
69929 - fd = sys_open(name, 0, 0);
69930 + fd = sys_open((char __force_user *)name, 0, 0);
69931 if (fd < 0) {
69932 printk(KERN_ERR "md: open failed - cannot start "
69933 "array %s\n", name);
69934 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
69935 * array without it
69936 */
69937 sys_close(fd);
69938 - fd = sys_open(name, 0, 0);
69939 + fd = sys_open((char __force_user *)name, 0, 0);
69940 sys_ioctl(fd, BLKRRPART, 0);
69941 }
69942 sys_close(fd);
69943 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
69944
69945 wait_for_device_probe();
69946
69947 - fd = sys_open("/dev/md0", 0, 0);
69948 + fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
69949 if (fd >= 0) {
69950 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
69951 sys_close(fd);
69952 diff --git a/init/initramfs.c b/init/initramfs.c
69953 index 1fd59b8..a01b079 100644
69954 --- a/init/initramfs.c
69955 +++ b/init/initramfs.c
69956 @@ -74,7 +74,7 @@ static void __init free_hash(void)
69957 }
69958 }
69959
69960 -static long __init do_utime(char __user *filename, time_t mtime)
69961 +static long __init do_utime(__force char __user *filename, time_t mtime)
69962 {
69963 struct timespec t[2];
69964
69965 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
69966 struct dir_entry *de, *tmp;
69967 list_for_each_entry_safe(de, tmp, &dir_list, list) {
69968 list_del(&de->list);
69969 - do_utime(de->name, de->mtime);
69970 + do_utime((char __force_user *)de->name, de->mtime);
69971 kfree(de->name);
69972 kfree(de);
69973 }
69974 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
69975 if (nlink >= 2) {
69976 char *old = find_link(major, minor, ino, mode, collected);
69977 if (old)
69978 - return (sys_link(old, collected) < 0) ? -1 : 1;
69979 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
69980 }
69981 return 0;
69982 }
69983 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
69984 {
69985 struct stat st;
69986
69987 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
69988 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
69989 if (S_ISDIR(st.st_mode))
69990 - sys_rmdir(path);
69991 + sys_rmdir((char __force_user *)path);
69992 else
69993 - sys_unlink(path);
69994 + sys_unlink((char __force_user *)path);
69995 }
69996 }
69997
69998 @@ -305,7 +305,7 @@ static int __init do_name(void)
69999 int openflags = O_WRONLY|O_CREAT;
70000 if (ml != 1)
70001 openflags |= O_TRUNC;
70002 - wfd = sys_open(collected, openflags, mode);
70003 + wfd = sys_open((char __force_user *)collected, openflags, mode);
70004
70005 if (wfd >= 0) {
70006 sys_fchown(wfd, uid, gid);
70007 @@ -317,17 +317,17 @@ static int __init do_name(void)
70008 }
70009 }
70010 } else if (S_ISDIR(mode)) {
70011 - sys_mkdir(collected, mode);
70012 - sys_chown(collected, uid, gid);
70013 - sys_chmod(collected, mode);
70014 + sys_mkdir((char __force_user *)collected, mode);
70015 + sys_chown((char __force_user *)collected, uid, gid);
70016 + sys_chmod((char __force_user *)collected, mode);
70017 dir_add(collected, mtime);
70018 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
70019 S_ISFIFO(mode) || S_ISSOCK(mode)) {
70020 if (maybe_link() == 0) {
70021 - sys_mknod(collected, mode, rdev);
70022 - sys_chown(collected, uid, gid);
70023 - sys_chmod(collected, mode);
70024 - do_utime(collected, mtime);
70025 + sys_mknod((char __force_user *)collected, mode, rdev);
70026 + sys_chown((char __force_user *)collected, uid, gid);
70027 + sys_chmod((char __force_user *)collected, mode);
70028 + do_utime((char __force_user *)collected, mtime);
70029 }
70030 }
70031 return 0;
70032 @@ -336,15 +336,15 @@ static int __init do_name(void)
70033 static int __init do_copy(void)
70034 {
70035 if (count >= body_len) {
70036 - sys_write(wfd, victim, body_len);
70037 + sys_write(wfd, (char __force_user *)victim, body_len);
70038 sys_close(wfd);
70039 - do_utime(vcollected, mtime);
70040 + do_utime((char __force_user *)vcollected, mtime);
70041 kfree(vcollected);
70042 eat(body_len);
70043 state = SkipIt;
70044 return 0;
70045 } else {
70046 - sys_write(wfd, victim, count);
70047 + sys_write(wfd, (char __force_user *)victim, count);
70048 body_len -= count;
70049 eat(count);
70050 return 1;
70051 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
70052 {
70053 collected[N_ALIGN(name_len) + body_len] = '\0';
70054 clean_path(collected, 0);
70055 - sys_symlink(collected + N_ALIGN(name_len), collected);
70056 - sys_lchown(collected, uid, gid);
70057 - do_utime(collected, mtime);
70058 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
70059 + sys_lchown((char __force_user *)collected, uid, gid);
70060 + do_utime((char __force_user *)collected, mtime);
70061 state = SkipIt;
70062 next_state = Reset;
70063 return 0;
70064 diff --git a/init/main.c b/init/main.c
70065 index 1eb4bd5..da8c6f5 100644
70066 --- a/init/main.c
70067 +++ b/init/main.c
70068 @@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void) { }
70069 #ifdef CONFIG_TC
70070 extern void tc_init(void);
70071 #endif
70072 +extern void grsecurity_init(void);
70073
70074 enum system_states system_state __read_mostly;
70075 EXPORT_SYMBOL(system_state);
70076 @@ -183,6 +184,49 @@ static int __init set_reset_devices(char *str)
70077
70078 __setup("reset_devices", set_reset_devices);
70079
70080 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
70081 +extern char pax_enter_kernel_user[];
70082 +extern char pax_exit_kernel_user[];
70083 +extern pgdval_t clone_pgd_mask;
70084 +#endif
70085 +
70086 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
70087 +static int __init setup_pax_nouderef(char *str)
70088 +{
70089 +#ifdef CONFIG_X86_32
70090 + unsigned int cpu;
70091 + struct desc_struct *gdt;
70092 +
70093 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
70094 + gdt = get_cpu_gdt_table(cpu);
70095 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
70096 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
70097 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
70098 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
70099 + }
70100 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
70101 +#else
70102 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
70103 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
70104 + clone_pgd_mask = ~(pgdval_t)0UL;
70105 +#endif
70106 +
70107 + return 0;
70108 +}
70109 +early_param("pax_nouderef", setup_pax_nouderef);
70110 +#endif
70111 +
70112 +#ifdef CONFIG_PAX_SOFTMODE
70113 +int pax_softmode;
70114 +
70115 +static int __init setup_pax_softmode(char *str)
70116 +{
70117 + get_option(&str, &pax_softmode);
70118 + return 1;
70119 +}
70120 +__setup("pax_softmode=", setup_pax_softmode);
70121 +#endif
70122 +
70123 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
70124 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
70125 static const char *panic_later, *panic_param;
70126 @@ -705,52 +749,53 @@ int initcall_debug;
70127 core_param(initcall_debug, initcall_debug, bool, 0644);
70128
70129 static char msgbuf[64];
70130 -static struct boot_trace_call call;
70131 -static struct boot_trace_ret ret;
70132 +static struct boot_trace_call trace_call;
70133 +static struct boot_trace_ret trace_ret;
70134
70135 int do_one_initcall(initcall_t fn)
70136 {
70137 int count = preempt_count();
70138 ktime_t calltime, delta, rettime;
70139 + const char *msg1 = "", *msg2 = "";
70140
70141 if (initcall_debug) {
70142 - call.caller = task_pid_nr(current);
70143 - printk("calling %pF @ %i\n", fn, call.caller);
70144 + trace_call.caller = task_pid_nr(current);
70145 + printk("calling %pF @ %i\n", fn, trace_call.caller);
70146 calltime = ktime_get();
70147 - trace_boot_call(&call, fn);
70148 + trace_boot_call(&trace_call, fn);
70149 enable_boot_trace();
70150 }
70151
70152 - ret.result = fn();
70153 + trace_ret.result = fn();
70154
70155 if (initcall_debug) {
70156 disable_boot_trace();
70157 rettime = ktime_get();
70158 delta = ktime_sub(rettime, calltime);
70159 - ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70160 - trace_boot_ret(&ret, fn);
70161 + trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70162 + trace_boot_ret(&trace_ret, fn);
70163 printk("initcall %pF returned %d after %Ld usecs\n", fn,
70164 - ret.result, ret.duration);
70165 + trace_ret.result, trace_ret.duration);
70166 }
70167
70168 msgbuf[0] = 0;
70169
70170 - if (ret.result && ret.result != -ENODEV && initcall_debug)
70171 - sprintf(msgbuf, "error code %d ", ret.result);
70172 + if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
70173 + sprintf(msgbuf, "error code %d ", trace_ret.result);
70174
70175 if (preempt_count() != count) {
70176 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
70177 + msg1 = " preemption imbalance";
70178 preempt_count() = count;
70179 }
70180 if (irqs_disabled()) {
70181 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
70182 + msg2 = " disabled interrupts";
70183 local_irq_enable();
70184 }
70185 - if (msgbuf[0]) {
70186 - printk("initcall %pF returned with %s\n", fn, msgbuf);
70187 + if (msgbuf[0] || *msg1 || *msg2) {
70188 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
70189 }
70190
70191 - return ret.result;
70192 + return trace_ret.result;
70193 }
70194
70195
70196 @@ -893,11 +938,13 @@ static int __init kernel_init(void * unused)
70197 if (!ramdisk_execute_command)
70198 ramdisk_execute_command = "/init";
70199
70200 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
70201 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
70202 ramdisk_execute_command = NULL;
70203 prepare_namespace();
70204 }
70205
70206 + grsecurity_init();
70207 +
70208 /*
70209 * Ok, we have completed the initial bootup, and
70210 * we're essentially up and running. Get rid of the
70211 diff --git a/init/noinitramfs.c b/init/noinitramfs.c
70212 index f4c1a3a..96c19bd 100644
70213 --- a/init/noinitramfs.c
70214 +++ b/init/noinitramfs.c
70215 @@ -29,7 +29,7 @@ static int __init default_rootfs(void)
70216 {
70217 int err;
70218
70219 - err = sys_mkdir("/dev", 0755);
70220 + err = sys_mkdir((const char __user *)"/dev", 0755);
70221 if (err < 0)
70222 goto out;
70223
70224 @@ -39,7 +39,7 @@ static int __init default_rootfs(void)
70225 if (err < 0)
70226 goto out;
70227
70228 - err = sys_mkdir("/root", 0700);
70229 + err = sys_mkdir((const char __user *)"/root", 0700);
70230 if (err < 0)
70231 goto out;
70232
70233 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
70234 index d01bc14..8df81db 100644
70235 --- a/ipc/mqueue.c
70236 +++ b/ipc/mqueue.c
70237 @@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
70238 mq_bytes = (mq_msg_tblsz +
70239 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
70240
70241 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
70242 spin_lock(&mq_lock);
70243 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
70244 u->mq_bytes + mq_bytes >
70245 diff --git a/ipc/msg.c b/ipc/msg.c
70246 index 779f762..4af9e36 100644
70247 --- a/ipc/msg.c
70248 +++ b/ipc/msg.c
70249 @@ -310,18 +310,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
70250 return security_msg_queue_associate(msq, msgflg);
70251 }
70252
70253 +static struct ipc_ops msg_ops = {
70254 + .getnew = newque,
70255 + .associate = msg_security,
70256 + .more_checks = NULL
70257 +};
70258 +
70259 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
70260 {
70261 struct ipc_namespace *ns;
70262 - struct ipc_ops msg_ops;
70263 struct ipc_params msg_params;
70264
70265 ns = current->nsproxy->ipc_ns;
70266
70267 - msg_ops.getnew = newque;
70268 - msg_ops.associate = msg_security;
70269 - msg_ops.more_checks = NULL;
70270 -
70271 msg_params.key = key;
70272 msg_params.flg = msgflg;
70273
70274 diff --git a/ipc/sem.c b/ipc/sem.c
70275 index b781007..f738b04 100644
70276 --- a/ipc/sem.c
70277 +++ b/ipc/sem.c
70278 @@ -309,10 +309,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
70279 return 0;
70280 }
70281
70282 +static struct ipc_ops sem_ops = {
70283 + .getnew = newary,
70284 + .associate = sem_security,
70285 + .more_checks = sem_more_checks
70286 +};
70287 +
70288 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70289 {
70290 struct ipc_namespace *ns;
70291 - struct ipc_ops sem_ops;
70292 struct ipc_params sem_params;
70293
70294 ns = current->nsproxy->ipc_ns;
70295 @@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70296 if (nsems < 0 || nsems > ns->sc_semmsl)
70297 return -EINVAL;
70298
70299 - sem_ops.getnew = newary;
70300 - sem_ops.associate = sem_security;
70301 - sem_ops.more_checks = sem_more_checks;
70302 -
70303 sem_params.key = key;
70304 sem_params.flg = semflg;
70305 sem_params.u.nsems = nsems;
70306 @@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
70307 ushort* sem_io = fast_sem_io;
70308 int nsems;
70309
70310 + pax_track_stack();
70311 +
70312 sma = sem_lock_check(ns, semid);
70313 if (IS_ERR(sma))
70314 return PTR_ERR(sma);
70315 @@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
70316 unsigned long jiffies_left = 0;
70317 struct ipc_namespace *ns;
70318
70319 + pax_track_stack();
70320 +
70321 ns = current->nsproxy->ipc_ns;
70322
70323 if (nsops < 1 || semid < 0)
70324 diff --git a/ipc/shm.c b/ipc/shm.c
70325 index d30732c..7379456 100644
70326 --- a/ipc/shm.c
70327 +++ b/ipc/shm.c
70328 @@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
70329 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
70330 #endif
70331
70332 +#ifdef CONFIG_GRKERNSEC
70333 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70334 + const time_t shm_createtime, const uid_t cuid,
70335 + const int shmid);
70336 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70337 + const time_t shm_createtime);
70338 +#endif
70339 +
70340 void shm_init_ns(struct ipc_namespace *ns)
70341 {
70342 ns->shm_ctlmax = SHMMAX;
70343 @@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
70344 shp->shm_lprid = 0;
70345 shp->shm_atim = shp->shm_dtim = 0;
70346 shp->shm_ctim = get_seconds();
70347 +#ifdef CONFIG_GRKERNSEC
70348 + {
70349 + struct timespec timeval;
70350 + do_posix_clock_monotonic_gettime(&timeval);
70351 +
70352 + shp->shm_createtime = timeval.tv_sec;
70353 + }
70354 +#endif
70355 shp->shm_segsz = size;
70356 shp->shm_nattch = 0;
70357 shp->shm_file = file;
70358 @@ -446,18 +462,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
70359 return 0;
70360 }
70361
70362 +static struct ipc_ops shm_ops = {
70363 + .getnew = newseg,
70364 + .associate = shm_security,
70365 + .more_checks = shm_more_checks
70366 +};
70367 +
70368 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
70369 {
70370 struct ipc_namespace *ns;
70371 - struct ipc_ops shm_ops;
70372 struct ipc_params shm_params;
70373
70374 ns = current->nsproxy->ipc_ns;
70375
70376 - shm_ops.getnew = newseg;
70377 - shm_ops.associate = shm_security;
70378 - shm_ops.more_checks = shm_more_checks;
70379 -
70380 shm_params.key = key;
70381 shm_params.flg = shmflg;
70382 shm_params.u.size = size;
70383 @@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
70384 if (err)
70385 goto out_unlock;
70386
70387 +#ifdef CONFIG_GRKERNSEC
70388 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
70389 + shp->shm_perm.cuid, shmid) ||
70390 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
70391 + err = -EACCES;
70392 + goto out_unlock;
70393 + }
70394 +#endif
70395 +
70396 path.dentry = dget(shp->shm_file->f_path.dentry);
70397 path.mnt = shp->shm_file->f_path.mnt;
70398 shp->shm_nattch++;
70399 +#ifdef CONFIG_GRKERNSEC
70400 + shp->shm_lapid = current->pid;
70401 +#endif
70402 size = i_size_read(path.dentry->d_inode);
70403 shm_unlock(shp);
70404
70405 diff --git a/kernel/acct.c b/kernel/acct.c
70406 index a6605ca..ca91111 100644
70407 --- a/kernel/acct.c
70408 +++ b/kernel/acct.c
70409 @@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
70410 */
70411 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
70412 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
70413 - file->f_op->write(file, (char *)&ac,
70414 + file->f_op->write(file, (char __force_user *)&ac,
70415 sizeof(acct_t), &file->f_pos);
70416 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
70417 set_fs(fs);
70418 diff --git a/kernel/audit.c b/kernel/audit.c
70419 index 5feed23..513b02c 100644
70420 --- a/kernel/audit.c
70421 +++ b/kernel/audit.c
70422 @@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
70423 3) suppressed due to audit_rate_limit
70424 4) suppressed due to audit_backlog_limit
70425 */
70426 -static atomic_t audit_lost = ATOMIC_INIT(0);
70427 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
70428
70429 /* The netlink socket. */
70430 static struct sock *audit_sock;
70431 @@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
70432 unsigned long now;
70433 int print;
70434
70435 - atomic_inc(&audit_lost);
70436 + atomic_inc_unchecked(&audit_lost);
70437
70438 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
70439
70440 @@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
70441 printk(KERN_WARNING
70442 "audit: audit_lost=%d audit_rate_limit=%d "
70443 "audit_backlog_limit=%d\n",
70444 - atomic_read(&audit_lost),
70445 + atomic_read_unchecked(&audit_lost),
70446 audit_rate_limit,
70447 audit_backlog_limit);
70448 audit_panic(message);
70449 @@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70450 status_set.pid = audit_pid;
70451 status_set.rate_limit = audit_rate_limit;
70452 status_set.backlog_limit = audit_backlog_limit;
70453 - status_set.lost = atomic_read(&audit_lost);
70454 + status_set.lost = atomic_read_unchecked(&audit_lost);
70455 status_set.backlog = skb_queue_len(&audit_skb_queue);
70456 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
70457 &status_set, sizeof(status_set));
70458 @@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70459 spin_unlock_irq(&tsk->sighand->siglock);
70460 }
70461 read_unlock(&tasklist_lock);
70462 - audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
70463 - &s, sizeof(s));
70464 +
70465 + if (!err)
70466 + audit_send_reply(NETLINK_CB(skb).pid, seq,
70467 + AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
70468 break;
70469 }
70470 case AUDIT_TTY_SET: {
70471 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
70472 index 267e484..f8e295a 100644
70473 --- a/kernel/auditsc.c
70474 +++ b/kernel/auditsc.c
70475 @@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
70476 }
70477
70478 /* global counter which is incremented every time something logs in */
70479 -static atomic_t session_id = ATOMIC_INIT(0);
70480 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
70481
70482 /**
70483 * audit_set_loginuid - set a task's audit_context loginuid
70484 @@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
70485 */
70486 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
70487 {
70488 - unsigned int sessionid = atomic_inc_return(&session_id);
70489 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
70490 struct audit_context *context = task->audit_context;
70491
70492 if (context && context->in_syscall) {
70493 diff --git a/kernel/capability.c b/kernel/capability.c
70494 index 8a944f5..db5001e 100644
70495 --- a/kernel/capability.c
70496 +++ b/kernel/capability.c
70497 @@ -305,10 +305,26 @@ int capable(int cap)
70498 BUG();
70499 }
70500
70501 - if (security_capable(cap) == 0) {
70502 + if (security_capable(cap) == 0 && gr_is_capable(cap)) {
70503 current->flags |= PF_SUPERPRIV;
70504 return 1;
70505 }
70506 return 0;
70507 }
70508 +
70509 +int capable_nolog(int cap)
70510 +{
70511 + if (unlikely(!cap_valid(cap))) {
70512 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
70513 + BUG();
70514 + }
70515 +
70516 + if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
70517 + current->flags |= PF_SUPERPRIV;
70518 + return 1;
70519 + }
70520 + return 0;
70521 +}
70522 +
70523 EXPORT_SYMBOL(capable);
70524 +EXPORT_SYMBOL(capable_nolog);
70525 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
70526 index 1fbcc74..7000012 100644
70527 --- a/kernel/cgroup.c
70528 +++ b/kernel/cgroup.c
70529 @@ -536,6 +536,8 @@ static struct css_set *find_css_set(
70530 struct hlist_head *hhead;
70531 struct cg_cgroup_link *link;
70532
70533 + pax_track_stack();
70534 +
70535 /* First see if we already have a cgroup group that matches
70536 * the desired set */
70537 read_lock(&css_set_lock);
70538 diff --git a/kernel/compat.c b/kernel/compat.c
70539 index 8bc5578..186e44a 100644
70540 --- a/kernel/compat.c
70541 +++ b/kernel/compat.c
70542 @@ -108,7 +108,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
70543 mm_segment_t oldfs;
70544 long ret;
70545
70546 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
70547 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
70548 oldfs = get_fs();
70549 set_fs(KERNEL_DS);
70550 ret = hrtimer_nanosleep_restart(restart);
70551 @@ -140,7 +140,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
70552 oldfs = get_fs();
70553 set_fs(KERNEL_DS);
70554 ret = hrtimer_nanosleep(&tu,
70555 - rmtp ? (struct timespec __user *)&rmt : NULL,
70556 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
70557 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
70558 set_fs(oldfs);
70559
70560 @@ -247,7 +247,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
70561 mm_segment_t old_fs = get_fs();
70562
70563 set_fs(KERNEL_DS);
70564 - ret = sys_sigpending((old_sigset_t __user *) &s);
70565 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
70566 set_fs(old_fs);
70567 if (ret == 0)
70568 ret = put_user(s, set);
70569 @@ -266,8 +266,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
70570 old_fs = get_fs();
70571 set_fs(KERNEL_DS);
70572 ret = sys_sigprocmask(how,
70573 - set ? (old_sigset_t __user *) &s : NULL,
70574 - oset ? (old_sigset_t __user *) &s : NULL);
70575 + set ? (old_sigset_t __force_user *) &s : NULL,
70576 + oset ? (old_sigset_t __force_user *) &s : NULL);
70577 set_fs(old_fs);
70578 if (ret == 0)
70579 if (oset)
70580 @@ -310,7 +310,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
70581 mm_segment_t old_fs = get_fs();
70582
70583 set_fs(KERNEL_DS);
70584 - ret = sys_old_getrlimit(resource, &r);
70585 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
70586 set_fs(old_fs);
70587
70588 if (!ret) {
70589 @@ -385,7 +385,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
70590 mm_segment_t old_fs = get_fs();
70591
70592 set_fs(KERNEL_DS);
70593 - ret = sys_getrusage(who, (struct rusage __user *) &r);
70594 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
70595 set_fs(old_fs);
70596
70597 if (ret)
70598 @@ -412,8 +412,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
70599 set_fs (KERNEL_DS);
70600 ret = sys_wait4(pid,
70601 (stat_addr ?
70602 - (unsigned int __user *) &status : NULL),
70603 - options, (struct rusage __user *) &r);
70604 + (unsigned int __force_user *) &status : NULL),
70605 + options, (struct rusage __force_user *) &r);
70606 set_fs (old_fs);
70607
70608 if (ret > 0) {
70609 @@ -438,8 +438,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
70610 memset(&info, 0, sizeof(info));
70611
70612 set_fs(KERNEL_DS);
70613 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
70614 - uru ? (struct rusage __user *)&ru : NULL);
70615 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
70616 + uru ? (struct rusage __force_user *)&ru : NULL);
70617 set_fs(old_fs);
70618
70619 if ((ret < 0) || (info.si_signo == 0))
70620 @@ -569,8 +569,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
70621 oldfs = get_fs();
70622 set_fs(KERNEL_DS);
70623 err = sys_timer_settime(timer_id, flags,
70624 - (struct itimerspec __user *) &newts,
70625 - (struct itimerspec __user *) &oldts);
70626 + (struct itimerspec __force_user *) &newts,
70627 + (struct itimerspec __force_user *) &oldts);
70628 set_fs(oldfs);
70629 if (!err && old && put_compat_itimerspec(old, &oldts))
70630 return -EFAULT;
70631 @@ -587,7 +587,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
70632 oldfs = get_fs();
70633 set_fs(KERNEL_DS);
70634 err = sys_timer_gettime(timer_id,
70635 - (struct itimerspec __user *) &ts);
70636 + (struct itimerspec __force_user *) &ts);
70637 set_fs(oldfs);
70638 if (!err && put_compat_itimerspec(setting, &ts))
70639 return -EFAULT;
70640 @@ -606,7 +606,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
70641 oldfs = get_fs();
70642 set_fs(KERNEL_DS);
70643 err = sys_clock_settime(which_clock,
70644 - (struct timespec __user *) &ts);
70645 + (struct timespec __force_user *) &ts);
70646 set_fs(oldfs);
70647 return err;
70648 }
70649 @@ -621,7 +621,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
70650 oldfs = get_fs();
70651 set_fs(KERNEL_DS);
70652 err = sys_clock_gettime(which_clock,
70653 - (struct timespec __user *) &ts);
70654 + (struct timespec __force_user *) &ts);
70655 set_fs(oldfs);
70656 if (!err && put_compat_timespec(&ts, tp))
70657 return -EFAULT;
70658 @@ -638,7 +638,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
70659 oldfs = get_fs();
70660 set_fs(KERNEL_DS);
70661 err = sys_clock_getres(which_clock,
70662 - (struct timespec __user *) &ts);
70663 + (struct timespec __force_user *) &ts);
70664 set_fs(oldfs);
70665 if (!err && tp && put_compat_timespec(&ts, tp))
70666 return -EFAULT;
70667 @@ -650,9 +650,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
70668 long err;
70669 mm_segment_t oldfs;
70670 struct timespec tu;
70671 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
70672 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
70673
70674 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
70675 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
70676 oldfs = get_fs();
70677 set_fs(KERNEL_DS);
70678 err = clock_nanosleep_restart(restart);
70679 @@ -684,8 +684,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
70680 oldfs = get_fs();
70681 set_fs(KERNEL_DS);
70682 err = sys_clock_nanosleep(which_clock, flags,
70683 - (struct timespec __user *) &in,
70684 - (struct timespec __user *) &out);
70685 + (struct timespec __force_user *) &in,
70686 + (struct timespec __force_user *) &out);
70687 set_fs(oldfs);
70688
70689 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
70690 diff --git a/kernel/configs.c b/kernel/configs.c
70691 index abaee68..047facd 100644
70692 --- a/kernel/configs.c
70693 +++ b/kernel/configs.c
70694 @@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
70695 struct proc_dir_entry *entry;
70696
70697 /* create the current config file */
70698 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
70699 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
70700 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
70701 + &ikconfig_file_ops);
70702 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70703 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
70704 + &ikconfig_file_ops);
70705 +#endif
70706 +#else
70707 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
70708 &ikconfig_file_ops);
70709 +#endif
70710 +
70711 if (!entry)
70712 return -ENOMEM;
70713
70714 diff --git a/kernel/cpu.c b/kernel/cpu.c
70715 index 7e8b6ac..8921388 100644
70716 --- a/kernel/cpu.c
70717 +++ b/kernel/cpu.c
70718 @@ -19,7 +19,7 @@
70719 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
70720 static DEFINE_MUTEX(cpu_add_remove_lock);
70721
70722 -static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
70723 +static RAW_NOTIFIER_HEAD(cpu_chain);
70724
70725 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
70726 * Should always be manipulated under cpu_add_remove_lock
70727 diff --git a/kernel/cred.c b/kernel/cred.c
70728 index 0b5b5fc..419b86a 100644
70729 --- a/kernel/cred.c
70730 +++ b/kernel/cred.c
70731 @@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
70732 */
70733 void __put_cred(struct cred *cred)
70734 {
70735 + pax_track_stack();
70736 +
70737 kdebug("__put_cred(%p{%d,%d})", cred,
70738 atomic_read(&cred->usage),
70739 read_cred_subscribers(cred));
70740 @@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
70741 {
70742 struct cred *cred;
70743
70744 + pax_track_stack();
70745 +
70746 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
70747 atomic_read(&tsk->cred->usage),
70748 read_cred_subscribers(tsk->cred));
70749 @@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct task_struct *task)
70750 {
70751 const struct cred *cred;
70752
70753 + pax_track_stack();
70754 +
70755 rcu_read_lock();
70756
70757 do {
70758 @@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
70759 {
70760 struct cred *new;
70761
70762 + pax_track_stack();
70763 +
70764 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
70765 if (!new)
70766 return NULL;
70767 @@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
70768 const struct cred *old;
70769 struct cred *new;
70770
70771 + pax_track_stack();
70772 +
70773 validate_process_creds();
70774
70775 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
70776 @@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
70777 struct thread_group_cred *tgcred = NULL;
70778 struct cred *new;
70779
70780 + pax_track_stack();
70781 +
70782 #ifdef CONFIG_KEYS
70783 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
70784 if (!tgcred)
70785 @@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
70786 struct cred *new;
70787 int ret;
70788
70789 + pax_track_stack();
70790 +
70791 mutex_init(&p->cred_guard_mutex);
70792
70793 if (
70794 @@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
70795 struct task_struct *task = current;
70796 const struct cred *old = task->real_cred;
70797
70798 + pax_track_stack();
70799 +
70800 kdebug("commit_creds(%p{%d,%d})", new,
70801 atomic_read(&new->usage),
70802 read_cred_subscribers(new));
70803 @@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
70804
70805 get_cred(new); /* we will require a ref for the subj creds too */
70806
70807 + gr_set_role_label(task, new->uid, new->gid);
70808 +
70809 /* dumpability changes */
70810 if (old->euid != new->euid ||
70811 old->egid != new->egid ||
70812 @@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
70813 key_fsgid_changed(task);
70814
70815 /* do it
70816 - * - What if a process setreuid()'s and this brings the
70817 - * new uid over his NPROC rlimit? We can check this now
70818 - * cheaply with the new uid cache, so if it matters
70819 - * we should be checking for it. -DaveM
70820 + * RLIMIT_NPROC limits on user->processes have already been checked
70821 + * in set_user().
70822 */
70823 alter_cred_subscribers(new, 2);
70824 if (new->user != old->user)
70825 @@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
70826 */
70827 void abort_creds(struct cred *new)
70828 {
70829 + pax_track_stack();
70830 +
70831 kdebug("abort_creds(%p{%d,%d})", new,
70832 atomic_read(&new->usage),
70833 read_cred_subscribers(new));
70834 @@ -629,6 +647,8 @@ const struct cred *override_creds(const struct cred *new)
70835 {
70836 const struct cred *old = current->cred;
70837
70838 + pax_track_stack();
70839 +
70840 kdebug("override_creds(%p{%d,%d})", new,
70841 atomic_read(&new->usage),
70842 read_cred_subscribers(new));
70843 @@ -658,6 +678,8 @@ void revert_creds(const struct cred *old)
70844 {
70845 const struct cred *override = current->cred;
70846
70847 + pax_track_stack();
70848 +
70849 kdebug("revert_creds(%p{%d,%d})", old,
70850 atomic_read(&old->usage),
70851 read_cred_subscribers(old));
70852 @@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
70853 const struct cred *old;
70854 struct cred *new;
70855
70856 + pax_track_stack();
70857 +
70858 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
70859 if (!new)
70860 return NULL;
70861 @@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
70862 */
70863 int set_security_override(struct cred *new, u32 secid)
70864 {
70865 + pax_track_stack();
70866 +
70867 return security_kernel_act_as(new, secid);
70868 }
70869 EXPORT_SYMBOL(set_security_override);
70870 @@ -777,6 +803,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
70871 u32 secid;
70872 int ret;
70873
70874 + pax_track_stack();
70875 +
70876 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
70877 if (ret < 0)
70878 return ret;
70879 diff --git a/kernel/exit.c b/kernel/exit.c
70880 index 0f8fae3..9344a56 100644
70881 --- a/kernel/exit.c
70882 +++ b/kernel/exit.c
70883 @@ -55,6 +55,10 @@
70884 #include <asm/pgtable.h>
70885 #include <asm/mmu_context.h>
70886
70887 +#ifdef CONFIG_GRKERNSEC
70888 +extern rwlock_t grsec_exec_file_lock;
70889 +#endif
70890 +
70891 static void exit_mm(struct task_struct * tsk);
70892
70893 static void __unhash_process(struct task_struct *p)
70894 @@ -174,6 +178,10 @@ void release_task(struct task_struct * p)
70895 struct task_struct *leader;
70896 int zap_leader;
70897 repeat:
70898 +#ifdef CONFIG_NET
70899 + gr_del_task_from_ip_table(p);
70900 +#endif
70901 +
70902 tracehook_prepare_release_task(p);
70903 /* don't need to get the RCU readlock here - the process is dead and
70904 * can't be modifying its own credentials */
70905 @@ -397,7 +405,7 @@ int allow_signal(int sig)
70906 * know it'll be handled, so that they don't get converted to
70907 * SIGKILL or just silently dropped.
70908 */
70909 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70910 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70911 recalc_sigpending();
70912 spin_unlock_irq(&current->sighand->siglock);
70913 return 0;
70914 @@ -433,6 +441,17 @@ void daemonize(const char *name, ...)
70915 vsnprintf(current->comm, sizeof(current->comm), name, args);
70916 va_end(args);
70917
70918 +#ifdef CONFIG_GRKERNSEC
70919 + write_lock(&grsec_exec_file_lock);
70920 + if (current->exec_file) {
70921 + fput(current->exec_file);
70922 + current->exec_file = NULL;
70923 + }
70924 + write_unlock(&grsec_exec_file_lock);
70925 +#endif
70926 +
70927 + gr_set_kernel_label(current);
70928 +
70929 /*
70930 * If we were started as result of loading a module, close all of the
70931 * user space pages. We don't need them, and if we didn't close them
70932 @@ -897,17 +916,17 @@ NORET_TYPE void do_exit(long code)
70933 struct task_struct *tsk = current;
70934 int group_dead;
70935
70936 - profile_task_exit(tsk);
70937 -
70938 - WARN_ON(atomic_read(&tsk->fs_excl));
70939 -
70940 + /*
70941 + * Check this first since set_fs() below depends on
70942 + * current_thread_info(), which we better not access when we're in
70943 + * interrupt context. Other than that, we want to do the set_fs()
70944 + * as early as possible.
70945 + */
70946 if (unlikely(in_interrupt()))
70947 panic("Aiee, killing interrupt handler!");
70948 - if (unlikely(!tsk->pid))
70949 - panic("Attempted to kill the idle task!");
70950
70951 /*
70952 - * If do_exit is called because this processes oopsed, it's possible
70953 + * If do_exit is called because this processes Oops'ed, it's possible
70954 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
70955 * continuing. Amongst other possible reasons, this is to prevent
70956 * mm_release()->clear_child_tid() from writing to a user-controlled
70957 @@ -915,6 +934,13 @@ NORET_TYPE void do_exit(long code)
70958 */
70959 set_fs(USER_DS);
70960
70961 + profile_task_exit(tsk);
70962 +
70963 + WARN_ON(atomic_read(&tsk->fs_excl));
70964 +
70965 + if (unlikely(!tsk->pid))
70966 + panic("Attempted to kill the idle task!");
70967 +
70968 tracehook_report_exit(&code);
70969
70970 validate_creds_for_do_exit(tsk);
70971 @@ -973,6 +999,9 @@ NORET_TYPE void do_exit(long code)
70972 tsk->exit_code = code;
70973 taskstats_exit(tsk, group_dead);
70974
70975 + gr_acl_handle_psacct(tsk, code);
70976 + gr_acl_handle_exit();
70977 +
70978 exit_mm(tsk);
70979
70980 if (group_dead)
70981 @@ -1188,7 +1217,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
70982
70983 if (unlikely(wo->wo_flags & WNOWAIT)) {
70984 int exit_code = p->exit_code;
70985 - int why, status;
70986 + int why;
70987
70988 get_task_struct(p);
70989 read_unlock(&tasklist_lock);
70990 diff --git a/kernel/fork.c b/kernel/fork.c
70991 index 4bde56f..29a9bab 100644
70992 --- a/kernel/fork.c
70993 +++ b/kernel/fork.c
70994 @@ -253,7 +253,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70995 *stackend = STACK_END_MAGIC; /* for overflow detection */
70996
70997 #ifdef CONFIG_CC_STACKPROTECTOR
70998 - tsk->stack_canary = get_random_int();
70999 + tsk->stack_canary = pax_get_random_long();
71000 #endif
71001
71002 /* One for us, one for whoever does the "release_task()" (usually parent) */
71003 @@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71004 mm->locked_vm = 0;
71005 mm->mmap = NULL;
71006 mm->mmap_cache = NULL;
71007 - mm->free_area_cache = oldmm->mmap_base;
71008 - mm->cached_hole_size = ~0UL;
71009 + mm->free_area_cache = oldmm->free_area_cache;
71010 + mm->cached_hole_size = oldmm->cached_hole_size;
71011 mm->map_count = 0;
71012 cpumask_clear(mm_cpumask(mm));
71013 mm->mm_rb = RB_ROOT;
71014 @@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71015 tmp->vm_flags &= ~VM_LOCKED;
71016 tmp->vm_mm = mm;
71017 tmp->vm_next = tmp->vm_prev = NULL;
71018 + tmp->vm_mirror = NULL;
71019 anon_vma_link(tmp);
71020 file = tmp->vm_file;
71021 if (file) {
71022 @@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71023 if (retval)
71024 goto out;
71025 }
71026 +
71027 +#ifdef CONFIG_PAX_SEGMEXEC
71028 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
71029 + struct vm_area_struct *mpnt_m;
71030 +
71031 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
71032 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
71033 +
71034 + if (!mpnt->vm_mirror)
71035 + continue;
71036 +
71037 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
71038 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
71039 + mpnt->vm_mirror = mpnt_m;
71040 + } else {
71041 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
71042 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
71043 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
71044 + mpnt->vm_mirror->vm_mirror = mpnt;
71045 + }
71046 + }
71047 + BUG_ON(mpnt_m);
71048 + }
71049 +#endif
71050 +
71051 /* a new mm has just been created */
71052 arch_dup_mmap(oldmm, mm);
71053 retval = 0;
71054 @@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
71055 write_unlock(&fs->lock);
71056 return -EAGAIN;
71057 }
71058 - fs->users++;
71059 + atomic_inc(&fs->users);
71060 write_unlock(&fs->lock);
71061 return 0;
71062 }
71063 tsk->fs = copy_fs_struct(fs);
71064 if (!tsk->fs)
71065 return -ENOMEM;
71066 + gr_set_chroot_entries(tsk, &tsk->fs->root);
71067 return 0;
71068 }
71069
71070 @@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
71071 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
71072 #endif
71073 retval = -EAGAIN;
71074 +
71075 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
71076 +
71077 if (atomic_read(&p->real_cred->user->processes) >=
71078 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
71079 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
71080 - p->real_cred->user != INIT_USER)
71081 + if (p->real_cred->user != INIT_USER &&
71082 + !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
71083 goto bad_fork_free;
71084 }
71085 + current->flags &= ~PF_NPROC_EXCEEDED;
71086
71087 retval = copy_creds(p, clone_flags);
71088 if (retval < 0)
71089 @@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
71090 goto bad_fork_free_pid;
71091 }
71092
71093 + gr_copy_label(p);
71094 +
71095 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
71096 /*
71097 * Clear TID on mm_release()?
71098 @@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
71099 bad_fork_free:
71100 free_task(p);
71101 fork_out:
71102 + gr_log_forkfail(retval);
71103 +
71104 return ERR_PTR(retval);
71105 }
71106
71107 @@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
71108 if (clone_flags & CLONE_PARENT_SETTID)
71109 put_user(nr, parent_tidptr);
71110
71111 + gr_handle_brute_check();
71112 +
71113 if (clone_flags & CLONE_VFORK) {
71114 p->vfork_done = &vfork;
71115 init_completion(&vfork);
71116 @@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
71117 return 0;
71118
71119 /* don't need lock here; in the worst case we'll do useless copy */
71120 - if (fs->users == 1)
71121 + if (atomic_read(&fs->users) == 1)
71122 return 0;
71123
71124 *new_fsp = copy_fs_struct(fs);
71125 @@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
71126 fs = current->fs;
71127 write_lock(&fs->lock);
71128 current->fs = new_fs;
71129 - if (--fs->users)
71130 + gr_set_chroot_entries(current, &current->fs->root);
71131 + if (atomic_dec_return(&fs->users))
71132 new_fs = NULL;
71133 else
71134 new_fs = fs;
71135 diff --git a/kernel/futex.c b/kernel/futex.c
71136 index fb98c9f..333faec 100644
71137 --- a/kernel/futex.c
71138 +++ b/kernel/futex.c
71139 @@ -54,6 +54,7 @@
71140 #include <linux/mount.h>
71141 #include <linux/pagemap.h>
71142 #include <linux/syscalls.h>
71143 +#include <linux/ptrace.h>
71144 #include <linux/signal.h>
71145 #include <linux/module.h>
71146 #include <linux/magic.h>
71147 @@ -223,6 +224,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
71148 struct page *page;
71149 int err, ro = 0;
71150
71151 +#ifdef CONFIG_PAX_SEGMEXEC
71152 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
71153 + return -EFAULT;
71154 +#endif
71155 +
71156 /*
71157 * The futex address must be "naturally" aligned.
71158 */
71159 @@ -1819,6 +1825,8 @@ static int futex_wait(u32 __user *uaddr, int fshared,
71160 struct futex_q q;
71161 int ret;
71162
71163 + pax_track_stack();
71164 +
71165 if (!bitset)
71166 return -EINVAL;
71167
71168 @@ -1871,7 +1879,7 @@ retry:
71169
71170 restart = &current_thread_info()->restart_block;
71171 restart->fn = futex_wait_restart;
71172 - restart->futex.uaddr = (u32 *)uaddr;
71173 + restart->futex.uaddr = uaddr;
71174 restart->futex.val = val;
71175 restart->futex.time = abs_time->tv64;
71176 restart->futex.bitset = bitset;
71177 @@ -2233,6 +2241,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared,
71178 struct futex_q q;
71179 int res, ret;
71180
71181 + pax_track_stack();
71182 +
71183 if (!bitset)
71184 return -EINVAL;
71185
71186 @@ -2423,6 +2433,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
71187 if (!p)
71188 goto err_unlock;
71189 ret = -EPERM;
71190 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71191 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
71192 + goto err_unlock;
71193 +#endif
71194 pcred = __task_cred(p);
71195 if (cred->euid != pcred->euid &&
71196 cred->euid != pcred->uid &&
71197 @@ -2489,7 +2503,7 @@ retry:
71198 */
71199 static inline int fetch_robust_entry(struct robust_list __user **entry,
71200 struct robust_list __user * __user *head,
71201 - int *pi)
71202 + unsigned int *pi)
71203 {
71204 unsigned long uentry;
71205
71206 @@ -2670,6 +2684,7 @@ static int __init futex_init(void)
71207 {
71208 u32 curval;
71209 int i;
71210 + mm_segment_t oldfs;
71211
71212 /*
71213 * This will fail and we want it. Some arch implementations do
71214 @@ -2681,7 +2696,10 @@ static int __init futex_init(void)
71215 * implementation, the non functional ones will return
71216 * -ENOSYS.
71217 */
71218 + oldfs = get_fs();
71219 + set_fs(USER_DS);
71220 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
71221 + set_fs(oldfs);
71222 if (curval == -EFAULT)
71223 futex_cmpxchg_enabled = 1;
71224
71225 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
71226 index 2357165..eb25501 100644
71227 --- a/kernel/futex_compat.c
71228 +++ b/kernel/futex_compat.c
71229 @@ -10,6 +10,7 @@
71230 #include <linux/compat.h>
71231 #include <linux/nsproxy.h>
71232 #include <linux/futex.h>
71233 +#include <linux/ptrace.h>
71234
71235 #include <asm/uaccess.h>
71236
71237 @@ -135,7 +136,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71238 {
71239 struct compat_robust_list_head __user *head;
71240 unsigned long ret;
71241 - const struct cred *cred = current_cred(), *pcred;
71242 + const struct cred *cred = current_cred();
71243 + const struct cred *pcred;
71244
71245 if (!futex_cmpxchg_enabled)
71246 return -ENOSYS;
71247 @@ -151,6 +153,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71248 if (!p)
71249 goto err_unlock;
71250 ret = -EPERM;
71251 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71252 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
71253 + goto err_unlock;
71254 +#endif
71255 pcred = __task_cred(p);
71256 if (cred->euid != pcred->euid &&
71257 cred->euid != pcred->uid &&
71258 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
71259 index 9b22d03..6295b62 100644
71260 --- a/kernel/gcov/base.c
71261 +++ b/kernel/gcov/base.c
71262 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
71263 }
71264
71265 #ifdef CONFIG_MODULES
71266 -static inline int within(void *addr, void *start, unsigned long size)
71267 -{
71268 - return ((addr >= start) && (addr < start + size));
71269 -}
71270 -
71271 /* Update list and generate events when modules are unloaded. */
71272 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71273 void *data)
71274 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71275 prev = NULL;
71276 /* Remove entries located in module from linked list. */
71277 for (info = gcov_info_head; info; info = info->next) {
71278 - if (within(info, mod->module_core, mod->core_size)) {
71279 + if (within_module_core_rw((unsigned long)info, mod)) {
71280 if (prev)
71281 prev->next = info->next;
71282 else
71283 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
71284 index a6e9d00..a0da4f9 100644
71285 --- a/kernel/hrtimer.c
71286 +++ b/kernel/hrtimer.c
71287 @@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
71288 local_irq_restore(flags);
71289 }
71290
71291 -static void run_hrtimer_softirq(struct softirq_action *h)
71292 +static void run_hrtimer_softirq(void)
71293 {
71294 hrtimer_peek_ahead_timers();
71295 }
71296 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
71297 index 8b6b8b6..6bc87df 100644
71298 --- a/kernel/kallsyms.c
71299 +++ b/kernel/kallsyms.c
71300 @@ -11,6 +11,9 @@
71301 * Changed the compression method from stem compression to "table lookup"
71302 * compression (see scripts/kallsyms.c for a more complete description)
71303 */
71304 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71305 +#define __INCLUDED_BY_HIDESYM 1
71306 +#endif
71307 #include <linux/kallsyms.h>
71308 #include <linux/module.h>
71309 #include <linux/init.h>
71310 @@ -51,12 +54,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
71311
71312 static inline int is_kernel_inittext(unsigned long addr)
71313 {
71314 + if (system_state != SYSTEM_BOOTING)
71315 + return 0;
71316 +
71317 if (addr >= (unsigned long)_sinittext
71318 && addr <= (unsigned long)_einittext)
71319 return 1;
71320 return 0;
71321 }
71322
71323 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71324 +#ifdef CONFIG_MODULES
71325 +static inline int is_module_text(unsigned long addr)
71326 +{
71327 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
71328 + return 1;
71329 +
71330 + addr = ktla_ktva(addr);
71331 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
71332 +}
71333 +#else
71334 +static inline int is_module_text(unsigned long addr)
71335 +{
71336 + return 0;
71337 +}
71338 +#endif
71339 +#endif
71340 +
71341 static inline int is_kernel_text(unsigned long addr)
71342 {
71343 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
71344 @@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigned long addr)
71345
71346 static inline int is_kernel(unsigned long addr)
71347 {
71348 +
71349 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71350 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
71351 + return 1;
71352 +
71353 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
71354 +#else
71355 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
71356 +#endif
71357 +
71358 return 1;
71359 return in_gate_area_no_task(addr);
71360 }
71361
71362 static int is_ksym_addr(unsigned long addr)
71363 {
71364 +
71365 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71366 + if (is_module_text(addr))
71367 + return 0;
71368 +#endif
71369 +
71370 if (all_var)
71371 return is_kernel(addr);
71372
71373 @@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
71374
71375 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
71376 {
71377 - iter->name[0] = '\0';
71378 iter->nameoff = get_symbol_offset(new_pos);
71379 iter->pos = new_pos;
71380 }
71381 @@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, void *p)
71382 {
71383 struct kallsym_iter *iter = m->private;
71384
71385 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71386 + if (current_uid())
71387 + return 0;
71388 +#endif
71389 +
71390 /* Some debugging symbols have no name. Ignore them. */
71391 if (!iter->name[0])
71392 return 0;
71393 @@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
71394 struct kallsym_iter *iter;
71395 int ret;
71396
71397 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
71398 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
71399 if (!iter)
71400 return -ENOMEM;
71401 reset_iter(iter, 0);
71402 diff --git a/kernel/kexec.c b/kernel/kexec.c
71403 index f336e21..9c1c20b 100644
71404 --- a/kernel/kexec.c
71405 +++ b/kernel/kexec.c
71406 @@ -1028,7 +1028,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
71407 unsigned long flags)
71408 {
71409 struct compat_kexec_segment in;
71410 - struct kexec_segment out, __user *ksegments;
71411 + struct kexec_segment out;
71412 + struct kexec_segment __user *ksegments;
71413 unsigned long i, result;
71414
71415 /* Don't allow clients that don't understand the native
71416 diff --git a/kernel/kgdb.c b/kernel/kgdb.c
71417 index 53dae4b..9ba3743 100644
71418 --- a/kernel/kgdb.c
71419 +++ b/kernel/kgdb.c
71420 @@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
71421 /* Guard for recursive entry */
71422 static int exception_level;
71423
71424 -static struct kgdb_io *kgdb_io_ops;
71425 +static const struct kgdb_io *kgdb_io_ops;
71426 static DEFINE_SPINLOCK(kgdb_registration_lock);
71427
71428 /* kgdb console driver is loaded */
71429 @@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1);
71430 */
71431 static atomic_t passive_cpu_wait[NR_CPUS];
71432 static atomic_t cpu_in_kgdb[NR_CPUS];
71433 -atomic_t kgdb_setting_breakpoint;
71434 +atomic_unchecked_t kgdb_setting_breakpoint;
71435
71436 struct task_struct *kgdb_usethread;
71437 struct task_struct *kgdb_contthread;
71438 @@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBYTES +
71439 sizeof(unsigned long)];
71440
71441 /* to keep track of the CPU which is doing the single stepping*/
71442 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71443 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71444
71445 /*
71446 * If you are debugging a problem where roundup (the collection of
71447 @@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
71448 return 0;
71449 if (kgdb_connected)
71450 return 1;
71451 - if (atomic_read(&kgdb_setting_breakpoint))
71452 + if (atomic_read_unchecked(&kgdb_setting_breakpoint))
71453 return 1;
71454 if (print_wait)
71455 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
71456 @@ -1426,8 +1426,8 @@ acquirelock:
71457 * instance of the exception handler wanted to come into the
71458 * debugger on a different CPU via a single step
71459 */
71460 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
71461 - atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
71462 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
71463 + atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
71464
71465 atomic_set(&kgdb_active, -1);
71466 touch_softlockup_watchdog();
71467 @@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void)
71468 *
71469 * Register it with the KGDB core.
71470 */
71471 -int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
71472 +int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
71473 {
71474 int err;
71475
71476 @@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_module);
71477 *
71478 * Unregister it with the KGDB core.
71479 */
71480 -void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
71481 +void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
71482 {
71483 BUG_ON(kgdb_connected);
71484
71485 @@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
71486 */
71487 void kgdb_breakpoint(void)
71488 {
71489 - atomic_set(&kgdb_setting_breakpoint, 1);
71490 + atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
71491 wmb(); /* Sync point before breakpoint */
71492 arch_kgdb_breakpoint();
71493 wmb(); /* Sync point after breakpoint */
71494 - atomic_set(&kgdb_setting_breakpoint, 0);
71495 + atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
71496 }
71497 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
71498
71499 diff --git a/kernel/kmod.c b/kernel/kmod.c
71500 index d206078..e27ba6a 100644
71501 --- a/kernel/kmod.c
71502 +++ b/kernel/kmod.c
71503 @@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
71504 * If module auto-loading support is disabled then this function
71505 * becomes a no-operation.
71506 */
71507 -int __request_module(bool wait, const char *fmt, ...)
71508 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
71509 {
71510 - va_list args;
71511 char module_name[MODULE_NAME_LEN];
71512 unsigned int max_modprobes;
71513 int ret;
71514 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
71515 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
71516 static char *envp[] = { "HOME=/",
71517 "TERM=linux",
71518 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
71519 @@ -84,12 +83,24 @@ int __request_module(bool wait, const char *fmt, ...)
71520 if (ret)
71521 return ret;
71522
71523 - va_start(args, fmt);
71524 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
71525 - va_end(args);
71526 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
71527 if (ret >= MODULE_NAME_LEN)
71528 return -ENAMETOOLONG;
71529
71530 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71531 + if (!current_uid()) {
71532 + /* hack to workaround consolekit/udisks stupidity */
71533 + read_lock(&tasklist_lock);
71534 + if (!strcmp(current->comm, "mount") &&
71535 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
71536 + read_unlock(&tasklist_lock);
71537 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
71538 + return -EPERM;
71539 + }
71540 + read_unlock(&tasklist_lock);
71541 + }
71542 +#endif
71543 +
71544 /* If modprobe needs a service that is in a module, we get a recursive
71545 * loop. Limit the number of running kmod threads to max_threads/2 or
71546 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
71547 @@ -123,6 +134,48 @@ int __request_module(bool wait, const char *fmt, ...)
71548 atomic_dec(&kmod_concurrent);
71549 return ret;
71550 }
71551 +
71552 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
71553 +{
71554 + va_list args;
71555 + int ret;
71556 +
71557 + va_start(args, fmt);
71558 + ret = ____request_module(wait, module_param, fmt, args);
71559 + va_end(args);
71560 +
71561 + return ret;
71562 +}
71563 +
71564 +int __request_module(bool wait, const char *fmt, ...)
71565 +{
71566 + va_list args;
71567 + int ret;
71568 +
71569 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71570 + if (current_uid()) {
71571 + char module_param[MODULE_NAME_LEN];
71572 +
71573 + memset(module_param, 0, sizeof(module_param));
71574 +
71575 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
71576 +
71577 + va_start(args, fmt);
71578 + ret = ____request_module(wait, module_param, fmt, args);
71579 + va_end(args);
71580 +
71581 + return ret;
71582 + }
71583 +#endif
71584 +
71585 + va_start(args, fmt);
71586 + ret = ____request_module(wait, NULL, fmt, args);
71587 + va_end(args);
71588 +
71589 + return ret;
71590 +}
71591 +
71592 +
71593 EXPORT_SYMBOL(__request_module);
71594 #endif /* CONFIG_MODULES */
71595
71596 @@ -228,7 +281,7 @@ static int wait_for_helper(void *data)
71597 *
71598 * Thus the __user pointer cast is valid here.
71599 */
71600 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
71601 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
71602
71603 /*
71604 * If ret is 0, either ____call_usermodehelper failed and the
71605 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
71606 index 5240d75..5a6fb33 100644
71607 --- a/kernel/kprobes.c
71608 +++ b/kernel/kprobes.c
71609 @@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void)
71610 * kernel image and loaded module images reside. This is required
71611 * so x86_64 can correctly handle the %rip-relative fixups.
71612 */
71613 - kip->insns = module_alloc(PAGE_SIZE);
71614 + kip->insns = module_alloc_exec(PAGE_SIZE);
71615 if (!kip->insns) {
71616 kfree(kip);
71617 return NULL;
71618 @@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
71619 */
71620 if (!list_is_singular(&kprobe_insn_pages)) {
71621 list_del(&kip->list);
71622 - module_free(NULL, kip->insns);
71623 + module_free_exec(NULL, kip->insns);
71624 kfree(kip);
71625 }
71626 return 1;
71627 @@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
71628 {
71629 int i, err = 0;
71630 unsigned long offset = 0, size = 0;
71631 - char *modname, namebuf[128];
71632 + char *modname, namebuf[KSYM_NAME_LEN];
71633 const char *symbol_name;
71634 void *addr;
71635 struct kprobe_blackpoint *kb;
71636 @@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
71637 const char *sym = NULL;
71638 unsigned int i = *(loff_t *) v;
71639 unsigned long offset = 0;
71640 - char *modname, namebuf[128];
71641 + char *modname, namebuf[KSYM_NAME_LEN];
71642
71643 head = &kprobe_table[i];
71644 preempt_disable();
71645 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
71646 index d86fe89..d12fc66 100644
71647 --- a/kernel/lockdep.c
71648 +++ b/kernel/lockdep.c
71649 @@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_trace = {
71650 /*
71651 * Various lockdep statistics:
71652 */
71653 -atomic_t chain_lookup_hits;
71654 -atomic_t chain_lookup_misses;
71655 -atomic_t hardirqs_on_events;
71656 -atomic_t hardirqs_off_events;
71657 -atomic_t redundant_hardirqs_on;
71658 -atomic_t redundant_hardirqs_off;
71659 -atomic_t softirqs_on_events;
71660 -atomic_t softirqs_off_events;
71661 -atomic_t redundant_softirqs_on;
71662 -atomic_t redundant_softirqs_off;
71663 -atomic_t nr_unused_locks;
71664 -atomic_t nr_cyclic_checks;
71665 -atomic_t nr_find_usage_forwards_checks;
71666 -atomic_t nr_find_usage_backwards_checks;
71667 +atomic_unchecked_t chain_lookup_hits;
71668 +atomic_unchecked_t chain_lookup_misses;
71669 +atomic_unchecked_t hardirqs_on_events;
71670 +atomic_unchecked_t hardirqs_off_events;
71671 +atomic_unchecked_t redundant_hardirqs_on;
71672 +atomic_unchecked_t redundant_hardirqs_off;
71673 +atomic_unchecked_t softirqs_on_events;
71674 +atomic_unchecked_t softirqs_off_events;
71675 +atomic_unchecked_t redundant_softirqs_on;
71676 +atomic_unchecked_t redundant_softirqs_off;
71677 +atomic_unchecked_t nr_unused_locks;
71678 +atomic_unchecked_t nr_cyclic_checks;
71679 +atomic_unchecked_t nr_find_usage_forwards_checks;
71680 +atomic_unchecked_t nr_find_usage_backwards_checks;
71681 #endif
71682
71683 /*
71684 @@ -577,6 +577,10 @@ static int static_obj(void *obj)
71685 int i;
71686 #endif
71687
71688 +#ifdef CONFIG_PAX_KERNEXEC
71689 + start = ktla_ktva(start);
71690 +#endif
71691 +
71692 /*
71693 * static variable?
71694 */
71695 @@ -592,8 +596,7 @@ static int static_obj(void *obj)
71696 */
71697 for_each_possible_cpu(i) {
71698 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
71699 - end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
71700 - + per_cpu_offset(i);
71701 + end = start + PERCPU_ENOUGH_ROOM;
71702
71703 if ((addr >= start) && (addr < end))
71704 return 1;
71705 @@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
71706 if (!static_obj(lock->key)) {
71707 debug_locks_off();
71708 printk("INFO: trying to register non-static key.\n");
71709 + printk("lock:%pS key:%pS.\n", lock, lock->key);
71710 printk("the code is fine but needs lockdep annotation.\n");
71711 printk("turning off the locking correctness validator.\n");
71712 dump_stack();
71713 @@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71714 if (!class)
71715 return 0;
71716 }
71717 - debug_atomic_inc((atomic_t *)&class->ops);
71718 + debug_atomic_inc((atomic_unchecked_t *)&class->ops);
71719 if (very_verbose(class)) {
71720 printk("\nacquire class [%p] %s", class->key, class->name);
71721 if (class->name_version > 1)
71722 diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h
71723 index a2ee95a..092f0f2 100644
71724 --- a/kernel/lockdep_internals.h
71725 +++ b/kernel/lockdep_internals.h
71726 @@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_class *class)
71727 /*
71728 * Various lockdep statistics:
71729 */
71730 -extern atomic_t chain_lookup_hits;
71731 -extern atomic_t chain_lookup_misses;
71732 -extern atomic_t hardirqs_on_events;
71733 -extern atomic_t hardirqs_off_events;
71734 -extern atomic_t redundant_hardirqs_on;
71735 -extern atomic_t redundant_hardirqs_off;
71736 -extern atomic_t softirqs_on_events;
71737 -extern atomic_t softirqs_off_events;
71738 -extern atomic_t redundant_softirqs_on;
71739 -extern atomic_t redundant_softirqs_off;
71740 -extern atomic_t nr_unused_locks;
71741 -extern atomic_t nr_cyclic_checks;
71742 -extern atomic_t nr_cyclic_check_recursions;
71743 -extern atomic_t nr_find_usage_forwards_checks;
71744 -extern atomic_t nr_find_usage_forwards_recursions;
71745 -extern atomic_t nr_find_usage_backwards_checks;
71746 -extern atomic_t nr_find_usage_backwards_recursions;
71747 -# define debug_atomic_inc(ptr) atomic_inc(ptr)
71748 -# define debug_atomic_dec(ptr) atomic_dec(ptr)
71749 -# define debug_atomic_read(ptr) atomic_read(ptr)
71750 +extern atomic_unchecked_t chain_lookup_hits;
71751 +extern atomic_unchecked_t chain_lookup_misses;
71752 +extern atomic_unchecked_t hardirqs_on_events;
71753 +extern atomic_unchecked_t hardirqs_off_events;
71754 +extern atomic_unchecked_t redundant_hardirqs_on;
71755 +extern atomic_unchecked_t redundant_hardirqs_off;
71756 +extern atomic_unchecked_t softirqs_on_events;
71757 +extern atomic_unchecked_t softirqs_off_events;
71758 +extern atomic_unchecked_t redundant_softirqs_on;
71759 +extern atomic_unchecked_t redundant_softirqs_off;
71760 +extern atomic_unchecked_t nr_unused_locks;
71761 +extern atomic_unchecked_t nr_cyclic_checks;
71762 +extern atomic_unchecked_t nr_cyclic_check_recursions;
71763 +extern atomic_unchecked_t nr_find_usage_forwards_checks;
71764 +extern atomic_unchecked_t nr_find_usage_forwards_recursions;
71765 +extern atomic_unchecked_t nr_find_usage_backwards_checks;
71766 +extern atomic_unchecked_t nr_find_usage_backwards_recursions;
71767 +# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
71768 +# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
71769 +# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
71770 #else
71771 # define debug_atomic_inc(ptr) do { } while (0)
71772 # define debug_atomic_dec(ptr) do { } while (0)
71773 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
71774 index d4aba4f..02a353f 100644
71775 --- a/kernel/lockdep_proc.c
71776 +++ b/kernel/lockdep_proc.c
71777 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
71778
71779 static void print_name(struct seq_file *m, struct lock_class *class)
71780 {
71781 - char str[128];
71782 + char str[KSYM_NAME_LEN];
71783 const char *name = class->name;
71784
71785 if (!name) {
71786 diff --git a/kernel/module.c b/kernel/module.c
71787 index 4b270e6..2226274 100644
71788 --- a/kernel/module.c
71789 +++ b/kernel/module.c
71790 @@ -55,6 +55,7 @@
71791 #include <linux/async.h>
71792 #include <linux/percpu.h>
71793 #include <linux/kmemleak.h>
71794 +#include <linux/grsecurity.h>
71795
71796 #define CREATE_TRACE_POINTS
71797 #include <trace/events/module.h>
71798 @@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
71799 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71800
71801 /* Bounds of module allocation, for speeding __module_address */
71802 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71803 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71804 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71805
71806 int register_module_notifier(struct notifier_block * nb)
71807 {
71808 @@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
71809 return true;
71810
71811 list_for_each_entry_rcu(mod, &modules, list) {
71812 - struct symsearch arr[] = {
71813 + struct symsearch modarr[] = {
71814 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71815 NOT_GPL_ONLY, false },
71816 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71817 @@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
71818 #endif
71819 };
71820
71821 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71822 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71823 return true;
71824 }
71825 return false;
71826 @@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned long size, unsigned long align,
71827 void *ptr;
71828 int cpu;
71829
71830 - if (align > PAGE_SIZE) {
71831 + if (align-1 >= PAGE_SIZE) {
71832 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71833 name, align, PAGE_SIZE);
71834 align = PAGE_SIZE;
71835 @@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
71836 * /sys/module/foo/sections stuff
71837 * J. Corbet <corbet@lwn.net>
71838 */
71839 -#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
71840 +#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71841
71842 static inline bool sect_empty(const Elf_Shdr *sect)
71843 {
71844 @@ -1545,7 +1547,8 @@ static void free_module(struct module *mod)
71845 destroy_params(mod->kp, mod->num_kp);
71846
71847 /* This may be NULL, but that's OK */
71848 - module_free(mod, mod->module_init);
71849 + module_free(mod, mod->module_init_rw);
71850 + module_free_exec(mod, mod->module_init_rx);
71851 kfree(mod->args);
71852 if (mod->percpu)
71853 percpu_modfree(mod->percpu);
71854 @@ -1554,10 +1557,12 @@ static void free_module(struct module *mod)
71855 percpu_modfree(mod->refptr);
71856 #endif
71857 /* Free lock-classes: */
71858 - lockdep_free_key_range(mod->module_core, mod->core_size);
71859 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71860 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71861
71862 /* Finally, free the core (containing the module structure) */
71863 - module_free(mod, mod->module_core);
71864 + module_free_exec(mod, mod->module_core_rx);
71865 + module_free(mod, mod->module_core_rw);
71866
71867 #ifdef CONFIG_MPU
71868 update_protections(current->mm);
71869 @@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71870 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
71871 int ret = 0;
71872 const struct kernel_symbol *ksym;
71873 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71874 + int is_fs_load = 0;
71875 + int register_filesystem_found = 0;
71876 + char *p;
71877 +
71878 + p = strstr(mod->args, "grsec_modharden_fs");
71879 +
71880 + if (p) {
71881 + char *endptr = p + strlen("grsec_modharden_fs");
71882 + /* copy \0 as well */
71883 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71884 + is_fs_load = 1;
71885 + }
71886 +#endif
71887 +
71888
71889 for (i = 1; i < n; i++) {
71890 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71891 + const char *name = strtab + sym[i].st_name;
71892 +
71893 + /* it's a real shame this will never get ripped and copied
71894 + upstream! ;(
71895 + */
71896 + if (is_fs_load && !strcmp(name, "register_filesystem"))
71897 + register_filesystem_found = 1;
71898 +#endif
71899 switch (sym[i].st_shndx) {
71900 case SHN_COMMON:
71901 /* We compiled with -fno-common. These are not
71902 @@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71903 strtab + sym[i].st_name, mod);
71904 /* Ok if resolved. */
71905 if (ksym) {
71906 + pax_open_kernel();
71907 sym[i].st_value = ksym->value;
71908 + pax_close_kernel();
71909 break;
71910 }
71911
71912 @@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71913 secbase = (unsigned long)mod->percpu;
71914 else
71915 secbase = sechdrs[sym[i].st_shndx].sh_addr;
71916 + pax_open_kernel();
71917 sym[i].st_value += secbase;
71918 + pax_close_kernel();
71919 break;
71920 }
71921 }
71922
71923 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71924 + if (is_fs_load && !register_filesystem_found) {
71925 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71926 + ret = -EPERM;
71927 + }
71928 +#endif
71929 +
71930 return ret;
71931 }
71932
71933 @@ -1731,11 +1771,12 @@ static void layout_sections(struct module *mod,
71934 || s->sh_entsize != ~0UL
71935 || strstarts(secstrings + s->sh_name, ".init"))
71936 continue;
71937 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71938 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71939 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71940 + else
71941 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71942 DEBUGP("\t%s\n", secstrings + s->sh_name);
71943 }
71944 - if (m == 0)
71945 - mod->core_text_size = mod->core_size;
71946 }
71947
71948 DEBUGP("Init section allocation order:\n");
71949 @@ -1748,12 +1789,13 @@ static void layout_sections(struct module *mod,
71950 || s->sh_entsize != ~0UL
71951 || !strstarts(secstrings + s->sh_name, ".init"))
71952 continue;
71953 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71954 - | INIT_OFFSET_MASK);
71955 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71956 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71957 + else
71958 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71959 + s->sh_entsize |= INIT_OFFSET_MASK;
71960 DEBUGP("\t%s\n", secstrings + s->sh_name);
71961 }
71962 - if (m == 0)
71963 - mod->init_text_size = mod->init_size;
71964 }
71965 }
71966
71967 @@ -1857,9 +1899,8 @@ static int is_exported(const char *name, unsigned long value,
71968
71969 /* As per nm */
71970 static char elf_type(const Elf_Sym *sym,
71971 - Elf_Shdr *sechdrs,
71972 - const char *secstrings,
71973 - struct module *mod)
71974 + const Elf_Shdr *sechdrs,
71975 + const char *secstrings)
71976 {
71977 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
71978 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
71979 @@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struct module *mod,
71980
71981 /* Put symbol section at end of init part of module. */
71982 symsect->sh_flags |= SHF_ALLOC;
71983 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71984 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71985 symindex) | INIT_OFFSET_MASK;
71986 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
71987
71988 @@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struct module *mod,
71989 }
71990
71991 /* Append room for core symbols at end of core part. */
71992 - symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71993 - mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
71994 + symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71995 + mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
71996
71997 /* Put string table section at end of init part of module. */
71998 strsect->sh_flags |= SHF_ALLOC;
71999 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
72000 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
72001 strindex) | INIT_OFFSET_MASK;
72002 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
72003
72004 /* Append room for core symbols' strings at end of core part. */
72005 - *pstroffs = mod->core_size;
72006 + *pstroffs = mod->core_size_rx;
72007 __set_bit(0, strmap);
72008 - mod->core_size += bitmap_weight(strmap, strsect->sh_size);
72009 + mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
72010
72011 return symoffs;
72012 }
72013 @@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *mod,
72014 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
72015 mod->strtab = (void *)sechdrs[strindex].sh_addr;
72016
72017 + pax_open_kernel();
72018 +
72019 /* Set types up while we still have access to sections. */
72020 for (i = 0; i < mod->num_symtab; i++)
72021 mod->symtab[i].st_info
72022 - = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
72023 + = elf_type(&mod->symtab[i], sechdrs, secstrings);
72024
72025 - mod->core_symtab = dst = mod->module_core + symoffs;
72026 + mod->core_symtab = dst = mod->module_core_rx + symoffs;
72027 src = mod->symtab;
72028 *dst = *src;
72029 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
72030 @@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *mod,
72031 }
72032 mod->core_num_syms = ndst;
72033
72034 - mod->core_strtab = s = mod->module_core + stroffs;
72035 + mod->core_strtab = s = mod->module_core_rx + stroffs;
72036 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
72037 if (test_bit(i, strmap))
72038 *++s = mod->strtab[i];
72039 +
72040 + pax_close_kernel();
72041 }
72042 #else
72043 static inline unsigned long layout_symtab(struct module *mod,
72044 @@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
72045 #endif
72046 }
72047
72048 -static void *module_alloc_update_bounds(unsigned long size)
72049 +static void *module_alloc_update_bounds_rw(unsigned long size)
72050 {
72051 void *ret = module_alloc(size);
72052
72053 if (ret) {
72054 /* Update module bounds. */
72055 - if ((unsigned long)ret < module_addr_min)
72056 - module_addr_min = (unsigned long)ret;
72057 - if ((unsigned long)ret + size > module_addr_max)
72058 - module_addr_max = (unsigned long)ret + size;
72059 + if ((unsigned long)ret < module_addr_min_rw)
72060 + module_addr_min_rw = (unsigned long)ret;
72061 + if ((unsigned long)ret + size > module_addr_max_rw)
72062 + module_addr_max_rw = (unsigned long)ret + size;
72063 + }
72064 + return ret;
72065 +}
72066 +
72067 +static void *module_alloc_update_bounds_rx(unsigned long size)
72068 +{
72069 + void *ret = module_alloc_exec(size);
72070 +
72071 + if (ret) {
72072 + /* Update module bounds. */
72073 + if ((unsigned long)ret < module_addr_min_rx)
72074 + module_addr_min_rx = (unsigned long)ret;
72075 + if ((unsigned long)ret + size > module_addr_max_rx)
72076 + module_addr_max_rx = (unsigned long)ret + size;
72077 }
72078 return ret;
72079 }
72080 @@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72081 unsigned int i;
72082
72083 /* only scan the sections containing data */
72084 - kmemleak_scan_area(mod->module_core, (unsigned long)mod -
72085 - (unsigned long)mod->module_core,
72086 + kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
72087 + (unsigned long)mod->module_core_rw,
72088 sizeof(struct module), GFP_KERNEL);
72089
72090 for (i = 1; i < hdr->e_shnum; i++) {
72091 @@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72092 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
72093 continue;
72094
72095 - kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
72096 - (unsigned long)mod->module_core,
72097 + kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
72098 + (unsigned long)mod->module_core_rw,
72099 sechdrs[i].sh_size, GFP_KERNEL);
72100 }
72101 }
72102 @@ -2097,7 +2156,7 @@ static noinline struct module *load_module(void __user *umod,
72103 Elf_Ehdr *hdr;
72104 Elf_Shdr *sechdrs;
72105 char *secstrings, *args, *modmagic, *strtab = NULL;
72106 - char *staging;
72107 + char *staging, *license;
72108 unsigned int i;
72109 unsigned int symindex = 0;
72110 unsigned int strindex = 0;
72111 @@ -2195,6 +2254,14 @@ static noinline struct module *load_module(void __user *umod,
72112 goto free_hdr;
72113 }
72114
72115 + license = get_modinfo(sechdrs, infoindex, "license");
72116 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
72117 + if (!license || !license_is_gpl_compatible(license)) {
72118 + err -ENOEXEC;
72119 + goto free_hdr;
72120 + }
72121 +#endif
72122 +
72123 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
72124 /* This is allowed: modprobe --force will invalidate it. */
72125 if (!modmagic) {
72126 @@ -2263,7 +2330,7 @@ static noinline struct module *load_module(void __user *umod,
72127 secstrings, &stroffs, strmap);
72128
72129 /* Do the allocs. */
72130 - ptr = module_alloc_update_bounds(mod->core_size);
72131 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
72132 /*
72133 * The pointer to this block is stored in the module structure
72134 * which is inside the block. Just mark it as not being a
72135 @@ -2274,23 +2341,47 @@ static noinline struct module *load_module(void __user *umod,
72136 err = -ENOMEM;
72137 goto free_percpu;
72138 }
72139 - memset(ptr, 0, mod->core_size);
72140 - mod->module_core = ptr;
72141 + memset(ptr, 0, mod->core_size_rw);
72142 + mod->module_core_rw = ptr;
72143
72144 - ptr = module_alloc_update_bounds(mod->init_size);
72145 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
72146 /*
72147 * The pointer to this block is stored in the module structure
72148 * which is inside the block. This block doesn't need to be
72149 * scanned as it contains data and code that will be freed
72150 * after the module is initialized.
72151 */
72152 - kmemleak_ignore(ptr);
72153 - if (!ptr && mod->init_size) {
72154 + kmemleak_not_leak(ptr);
72155 + if (!ptr && mod->init_size_rw) {
72156 err = -ENOMEM;
72157 - goto free_core;
72158 + goto free_core_rw;
72159 }
72160 - memset(ptr, 0, mod->init_size);
72161 - mod->module_init = ptr;
72162 + memset(ptr, 0, mod->init_size_rw);
72163 + mod->module_init_rw = ptr;
72164 +
72165 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
72166 + kmemleak_not_leak(ptr);
72167 + if (!ptr) {
72168 + err = -ENOMEM;
72169 + goto free_init_rw;
72170 + }
72171 +
72172 + pax_open_kernel();
72173 + memset(ptr, 0, mod->core_size_rx);
72174 + pax_close_kernel();
72175 + mod->module_core_rx = ptr;
72176 +
72177 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
72178 + kmemleak_not_leak(ptr);
72179 + if (!ptr && mod->init_size_rx) {
72180 + err = -ENOMEM;
72181 + goto free_core_rx;
72182 + }
72183 +
72184 + pax_open_kernel();
72185 + memset(ptr, 0, mod->init_size_rx);
72186 + pax_close_kernel();
72187 + mod->module_init_rx = ptr;
72188
72189 /* Transfer each section which specifies SHF_ALLOC */
72190 DEBUGP("final section addresses:\n");
72191 @@ -2300,17 +2391,45 @@ static noinline struct module *load_module(void __user *umod,
72192 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
72193 continue;
72194
72195 - if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
72196 - dest = mod->module_init
72197 - + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72198 - else
72199 - dest = mod->module_core + sechdrs[i].sh_entsize;
72200 + if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
72201 + if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72202 + dest = mod->module_init_rw
72203 + + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72204 + else
72205 + dest = mod->module_init_rx
72206 + + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72207 + } else {
72208 + if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72209 + dest = mod->module_core_rw + sechdrs[i].sh_entsize;
72210 + else
72211 + dest = mod->module_core_rx + sechdrs[i].sh_entsize;
72212 + }
72213
72214 - if (sechdrs[i].sh_type != SHT_NOBITS)
72215 - memcpy(dest, (void *)sechdrs[i].sh_addr,
72216 - sechdrs[i].sh_size);
72217 + if (sechdrs[i].sh_type != SHT_NOBITS) {
72218 +
72219 +#ifdef CONFIG_PAX_KERNEXEC
72220 +#ifdef CONFIG_X86_64
72221 + if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
72222 + set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
72223 +#endif
72224 + if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
72225 + pax_open_kernel();
72226 + memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72227 + pax_close_kernel();
72228 + } else
72229 +#endif
72230 +
72231 + memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72232 + }
72233 /* Update sh_addr to point to copy in image. */
72234 - sechdrs[i].sh_addr = (unsigned long)dest;
72235 +
72236 +#ifdef CONFIG_PAX_KERNEXEC
72237 + if (sechdrs[i].sh_flags & SHF_EXECINSTR)
72238 + sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
72239 + else
72240 +#endif
72241 +
72242 + sechdrs[i].sh_addr = (unsigned long)dest;
72243 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
72244 }
72245 /* Module has been moved. */
72246 @@ -2322,7 +2441,7 @@ static noinline struct module *load_module(void __user *umod,
72247 mod->name);
72248 if (!mod->refptr) {
72249 err = -ENOMEM;
72250 - goto free_init;
72251 + goto free_init_rx;
72252 }
72253 #endif
72254 /* Now we've moved module, initialize linked lists, etc. */
72255 @@ -2334,7 +2453,7 @@ static noinline struct module *load_module(void __user *umod,
72256 goto free_unload;
72257
72258 /* Set up license info based on the info section */
72259 - set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
72260 + set_license(mod, license);
72261
72262 /*
72263 * ndiswrapper is under GPL by itself, but loads proprietary modules.
72264 @@ -2351,6 +2470,31 @@ static noinline struct module *load_module(void __user *umod,
72265 /* Set up MODINFO_ATTR fields */
72266 setup_modinfo(mod, sechdrs, infoindex);
72267
72268 + mod->args = args;
72269 +
72270 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
72271 + {
72272 + char *p, *p2;
72273 +
72274 + if (strstr(mod->args, "grsec_modharden_netdev")) {
72275 + 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);
72276 + err = -EPERM;
72277 + goto cleanup;
72278 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
72279 + p += strlen("grsec_modharden_normal");
72280 + p2 = strstr(p, "_");
72281 + if (p2) {
72282 + *p2 = '\0';
72283 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
72284 + *p2 = '_';
72285 + }
72286 + err = -EPERM;
72287 + goto cleanup;
72288 + }
72289 + }
72290 +#endif
72291 +
72292 +
72293 /* Fix up syms, so that st_value is a pointer to location. */
72294 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
72295 mod);
72296 @@ -2431,8 +2575,8 @@ static noinline struct module *load_module(void __user *umod,
72297
72298 /* Now do relocations. */
72299 for (i = 1; i < hdr->e_shnum; i++) {
72300 - const char *strtab = (char *)sechdrs[strindex].sh_addr;
72301 unsigned int info = sechdrs[i].sh_info;
72302 + strtab = (char *)sechdrs[strindex].sh_addr;
72303
72304 /* Not a valid relocation section? */
72305 if (info >= hdr->e_shnum)
72306 @@ -2493,16 +2637,15 @@ static noinline struct module *load_module(void __user *umod,
72307 * Do it before processing of module parameters, so the module
72308 * can provide parameter accessor functions of its own.
72309 */
72310 - if (mod->module_init)
72311 - flush_icache_range((unsigned long)mod->module_init,
72312 - (unsigned long)mod->module_init
72313 - + mod->init_size);
72314 - flush_icache_range((unsigned long)mod->module_core,
72315 - (unsigned long)mod->module_core + mod->core_size);
72316 + if (mod->module_init_rx)
72317 + flush_icache_range((unsigned long)mod->module_init_rx,
72318 + (unsigned long)mod->module_init_rx
72319 + + mod->init_size_rx);
72320 + flush_icache_range((unsigned long)mod->module_core_rx,
72321 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
72322
72323 set_fs(old_fs);
72324
72325 - mod->args = args;
72326 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
72327 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
72328 mod->name);
72329 @@ -2546,12 +2689,16 @@ static noinline struct module *load_module(void __user *umod,
72330 free_unload:
72331 module_unload_free(mod);
72332 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
72333 + free_init_rx:
72334 percpu_modfree(mod->refptr);
72335 - free_init:
72336 #endif
72337 - module_free(mod, mod->module_init);
72338 - free_core:
72339 - module_free(mod, mod->module_core);
72340 + module_free_exec(mod, mod->module_init_rx);
72341 + free_core_rx:
72342 + module_free_exec(mod, mod->module_core_rx);
72343 + free_init_rw:
72344 + module_free(mod, mod->module_init_rw);
72345 + free_core_rw:
72346 + module_free(mod, mod->module_core_rw);
72347 /* mod will be freed with core. Don't access it beyond this line! */
72348 free_percpu:
72349 if (percpu)
72350 @@ -2653,10 +2800,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
72351 mod->symtab = mod->core_symtab;
72352 mod->strtab = mod->core_strtab;
72353 #endif
72354 - module_free(mod, mod->module_init);
72355 - mod->module_init = NULL;
72356 - mod->init_size = 0;
72357 - mod->init_text_size = 0;
72358 + module_free(mod, mod->module_init_rw);
72359 + module_free_exec(mod, mod->module_init_rx);
72360 + mod->module_init_rw = NULL;
72361 + mod->module_init_rx = NULL;
72362 + mod->init_size_rw = 0;
72363 + mod->init_size_rx = 0;
72364 mutex_unlock(&module_mutex);
72365
72366 return 0;
72367 @@ -2687,10 +2836,16 @@ static const char *get_ksymbol(struct module *mod,
72368 unsigned long nextval;
72369
72370 /* At worse, next value is at end of module */
72371 - if (within_module_init(addr, mod))
72372 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
72373 + if (within_module_init_rx(addr, mod))
72374 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
72375 + else if (within_module_init_rw(addr, mod))
72376 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
72377 + else if (within_module_core_rx(addr, mod))
72378 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
72379 + else if (within_module_core_rw(addr, mod))
72380 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
72381 else
72382 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
72383 + return NULL;
72384
72385 /* Scan for closest preceeding symbol, and next symbol. (ELF
72386 starts real symbols at 1). */
72387 @@ -2936,7 +3091,7 @@ static int m_show(struct seq_file *m, void *p)
72388 char buf[8];
72389
72390 seq_printf(m, "%s %u",
72391 - mod->name, mod->init_size + mod->core_size);
72392 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
72393 print_unload_info(m, mod);
72394
72395 /* Informative for users. */
72396 @@ -2945,7 +3100,7 @@ static int m_show(struct seq_file *m, void *p)
72397 mod->state == MODULE_STATE_COMING ? "Loading":
72398 "Live");
72399 /* Used by oprofile and other similar tools. */
72400 - seq_printf(m, " 0x%p", mod->module_core);
72401 + seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
72402
72403 /* Taints info */
72404 if (mod->taints)
72405 @@ -2981,7 +3136,17 @@ static const struct file_operations proc_modules_operations = {
72406
72407 static int __init proc_modules_init(void)
72408 {
72409 +#ifndef CONFIG_GRKERNSEC_HIDESYM
72410 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72411 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72412 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72413 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
72414 +#else
72415 proc_create("modules", 0, NULL, &proc_modules_operations);
72416 +#endif
72417 +#else
72418 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72419 +#endif
72420 return 0;
72421 }
72422 module_init(proc_modules_init);
72423 @@ -3040,12 +3205,12 @@ struct module *__module_address(unsigned long addr)
72424 {
72425 struct module *mod;
72426
72427 - if (addr < module_addr_min || addr > module_addr_max)
72428 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
72429 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
72430 return NULL;
72431
72432 list_for_each_entry_rcu(mod, &modules, list)
72433 - if (within_module_core(addr, mod)
72434 - || within_module_init(addr, mod))
72435 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
72436 return mod;
72437 return NULL;
72438 }
72439 @@ -3079,11 +3244,20 @@ bool is_module_text_address(unsigned long addr)
72440 */
72441 struct module *__module_text_address(unsigned long addr)
72442 {
72443 - struct module *mod = __module_address(addr);
72444 + struct module *mod;
72445 +
72446 +#ifdef CONFIG_X86_32
72447 + addr = ktla_ktva(addr);
72448 +#endif
72449 +
72450 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
72451 + return NULL;
72452 +
72453 + mod = __module_address(addr);
72454 +
72455 if (mod) {
72456 /* Make sure it's within the text section. */
72457 - if (!within(addr, mod->module_init, mod->init_text_size)
72458 - && !within(addr, mod->module_core, mod->core_text_size))
72459 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
72460 mod = NULL;
72461 }
72462 return mod;
72463 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
72464 index ec815a9..fe46e99 100644
72465 --- a/kernel/mutex-debug.c
72466 +++ b/kernel/mutex-debug.c
72467 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
72468 }
72469
72470 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72471 - struct thread_info *ti)
72472 + struct task_struct *task)
72473 {
72474 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
72475
72476 /* Mark the current thread as blocked on the lock: */
72477 - ti->task->blocked_on = waiter;
72478 + task->blocked_on = waiter;
72479 }
72480
72481 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72482 - struct thread_info *ti)
72483 + struct task_struct *task)
72484 {
72485 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
72486 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
72487 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
72488 - ti->task->blocked_on = NULL;
72489 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
72490 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
72491 + task->blocked_on = NULL;
72492
72493 list_del_init(&waiter->list);
72494 waiter->task = NULL;
72495 @@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lock)
72496 return;
72497
72498 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
72499 - DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
72500 + DEBUG_LOCKS_WARN_ON(lock->owner != current);
72501 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
72502 mutex_clear_owner(lock);
72503 }
72504 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
72505 index 6b2d735..372d3c4 100644
72506 --- a/kernel/mutex-debug.h
72507 +++ b/kernel/mutex-debug.h
72508 @@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
72509 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
72510 extern void debug_mutex_add_waiter(struct mutex *lock,
72511 struct mutex_waiter *waiter,
72512 - struct thread_info *ti);
72513 + struct task_struct *task);
72514 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72515 - struct thread_info *ti);
72516 + struct task_struct *task);
72517 extern void debug_mutex_unlock(struct mutex *lock);
72518 extern void debug_mutex_init(struct mutex *lock, const char *name,
72519 struct lock_class_key *key);
72520
72521 static inline void mutex_set_owner(struct mutex *lock)
72522 {
72523 - lock->owner = current_thread_info();
72524 + lock->owner = current;
72525 }
72526
72527 static inline void mutex_clear_owner(struct mutex *lock)
72528 diff --git a/kernel/mutex.c b/kernel/mutex.c
72529 index f85644c..5ee9f77 100644
72530 --- a/kernel/mutex.c
72531 +++ b/kernel/mutex.c
72532 @@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72533 */
72534
72535 for (;;) {
72536 - struct thread_info *owner;
72537 + struct task_struct *owner;
72538
72539 /*
72540 * If we own the BKL, then don't spin. The owner of
72541 @@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72542 spin_lock_mutex(&lock->wait_lock, flags);
72543
72544 debug_mutex_lock_common(lock, &waiter);
72545 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
72546 + debug_mutex_add_waiter(lock, &waiter, task);
72547
72548 /* add waiting tasks to the end of the waitqueue (FIFO): */
72549 list_add_tail(&waiter.list, &lock->wait_list);
72550 @@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72551 * TASK_UNINTERRUPTIBLE case.)
72552 */
72553 if (unlikely(signal_pending_state(state, task))) {
72554 - mutex_remove_waiter(lock, &waiter,
72555 - task_thread_info(task));
72556 + mutex_remove_waiter(lock, &waiter, task);
72557 mutex_release(&lock->dep_map, 1, ip);
72558 spin_unlock_mutex(&lock->wait_lock, flags);
72559
72560 @@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72561 done:
72562 lock_acquired(&lock->dep_map, ip);
72563 /* got the lock - rejoice! */
72564 - mutex_remove_waiter(lock, &waiter, current_thread_info());
72565 + mutex_remove_waiter(lock, &waiter, task);
72566 mutex_set_owner(lock);
72567
72568 /* set it to 0 if there are no waiters left: */
72569 diff --git a/kernel/mutex.h b/kernel/mutex.h
72570 index 67578ca..4115fbf 100644
72571 --- a/kernel/mutex.h
72572 +++ b/kernel/mutex.h
72573 @@ -19,7 +19,7 @@
72574 #ifdef CONFIG_SMP
72575 static inline void mutex_set_owner(struct mutex *lock)
72576 {
72577 - lock->owner = current_thread_info();
72578 + lock->owner = current;
72579 }
72580
72581 static inline void mutex_clear_owner(struct mutex *lock)
72582 diff --git a/kernel/panic.c b/kernel/panic.c
72583 index 96b45d0..45c447a 100644
72584 --- a/kernel/panic.c
72585 +++ b/kernel/panic.c
72586 @@ -352,7 +352,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
72587 const char *board;
72588
72589 printk(KERN_WARNING "------------[ cut here ]------------\n");
72590 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
72591 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
72592 board = dmi_get_system_info(DMI_PRODUCT_NAME);
72593 if (board)
72594 printk(KERN_WARNING "Hardware name: %s\n", board);
72595 @@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
72596 */
72597 void __stack_chk_fail(void)
72598 {
72599 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
72600 + dump_stack();
72601 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
72602 __builtin_return_address(0));
72603 }
72604 EXPORT_SYMBOL(__stack_chk_fail);
72605 diff --git a/kernel/params.c b/kernel/params.c
72606 index d656c27..21e452c 100644
72607 --- a/kernel/params.c
72608 +++ b/kernel/params.c
72609 @@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
72610 return ret;
72611 }
72612
72613 -static struct sysfs_ops module_sysfs_ops = {
72614 +static const struct sysfs_ops module_sysfs_ops = {
72615 .show = module_attr_show,
72616 .store = module_attr_store,
72617 };
72618 @@ -739,7 +739,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
72619 return 0;
72620 }
72621
72622 -static struct kset_uevent_ops module_uevent_ops = {
72623 +static const struct kset_uevent_ops module_uevent_ops = {
72624 .filter = uevent_filter,
72625 };
72626
72627 diff --git a/kernel/perf_event.c b/kernel/perf_event.c
72628 index 37ebc14..9c121d9 100644
72629 --- a/kernel/perf_event.c
72630 +++ b/kernel/perf_event.c
72631 @@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostly = 516; /* 'free' kb per user */
72632 */
72633 int sysctl_perf_event_sample_rate __read_mostly = 100000;
72634
72635 -static atomic64_t perf_event_id;
72636 +static atomic64_unchecked_t perf_event_id;
72637
72638 /*
72639 * Lock for (sysadmin-configurable) event reservations:
72640 @@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struct perf_event *event,
72641 * In order to keep per-task stats reliable we need to flip the event
72642 * values when we flip the contexts.
72643 */
72644 - value = atomic64_read(&next_event->count);
72645 - value = atomic64_xchg(&event->count, value);
72646 - atomic64_set(&next_event->count, value);
72647 + value = atomic64_read_unchecked(&next_event->count);
72648 + value = atomic64_xchg_unchecked(&event->count, value);
72649 + atomic64_set_unchecked(&next_event->count, value);
72650
72651 swap(event->total_time_enabled, next_event->total_time_enabled);
72652 swap(event->total_time_running, next_event->total_time_running);
72653 @@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_event *event)
72654 update_event_times(event);
72655 }
72656
72657 - return atomic64_read(&event->count);
72658 + return atomic64_read_unchecked(&event->count);
72659 }
72660
72661 /*
72662 @@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct perf_event *event,
72663 values[n++] = 1 + leader->nr_siblings;
72664 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72665 values[n++] = leader->total_time_enabled +
72666 - atomic64_read(&leader->child_total_time_enabled);
72667 + atomic64_read_unchecked(&leader->child_total_time_enabled);
72668 }
72669 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72670 values[n++] = leader->total_time_running +
72671 - atomic64_read(&leader->child_total_time_running);
72672 + atomic64_read_unchecked(&leader->child_total_time_running);
72673 }
72674
72675 size = n * sizeof(u64);
72676 @@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct perf_event *event,
72677 values[n++] = perf_event_read_value(event);
72678 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72679 values[n++] = event->total_time_enabled +
72680 - atomic64_read(&event->child_total_time_enabled);
72681 + atomic64_read_unchecked(&event->child_total_time_enabled);
72682 }
72683 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72684 values[n++] = event->total_time_running +
72685 - atomic64_read(&event->child_total_time_running);
72686 + atomic64_read_unchecked(&event->child_total_time_running);
72687 }
72688 if (read_format & PERF_FORMAT_ID)
72689 values[n++] = primary_event_id(event);
72690 @@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)
72691 static void perf_event_reset(struct perf_event *event)
72692 {
72693 (void)perf_event_read(event);
72694 - atomic64_set(&event->count, 0);
72695 + atomic64_set_unchecked(&event->count, 0);
72696 perf_event_update_userpage(event);
72697 }
72698
72699 @@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct perf_event *event)
72700 ++userpg->lock;
72701 barrier();
72702 userpg->index = perf_event_index(event);
72703 - userpg->offset = atomic64_read(&event->count);
72704 + userpg->offset = atomic64_read_unchecked(&event->count);
72705 if (event->state == PERF_EVENT_STATE_ACTIVE)
72706 - userpg->offset -= atomic64_read(&event->hw.prev_count);
72707 + userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
72708
72709 userpg->time_enabled = event->total_time_enabled +
72710 - atomic64_read(&event->child_total_time_enabled);
72711 + atomic64_read_unchecked(&event->child_total_time_enabled);
72712
72713 userpg->time_running = event->total_time_running +
72714 - atomic64_read(&event->child_total_time_running);
72715 + atomic64_read_unchecked(&event->child_total_time_running);
72716
72717 barrier();
72718 ++userpg->lock;
72719 @@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct perf_output_handle *handle,
72720 u64 values[4];
72721 int n = 0;
72722
72723 - values[n++] = atomic64_read(&event->count);
72724 + values[n++] = atomic64_read_unchecked(&event->count);
72725 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72726 values[n++] = event->total_time_enabled +
72727 - atomic64_read(&event->child_total_time_enabled);
72728 + atomic64_read_unchecked(&event->child_total_time_enabled);
72729 }
72730 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72731 values[n++] = event->total_time_running +
72732 - atomic64_read(&event->child_total_time_running);
72733 + atomic64_read_unchecked(&event->child_total_time_running);
72734 }
72735 if (read_format & PERF_FORMAT_ID)
72736 values[n++] = primary_event_id(event);
72737 @@ -2940,7 +2940,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
72738 if (leader != event)
72739 leader->pmu->read(leader);
72740
72741 - values[n++] = atomic64_read(&leader->count);
72742 + values[n++] = atomic64_read_unchecked(&leader->count);
72743 if (read_format & PERF_FORMAT_ID)
72744 values[n++] = primary_event_id(leader);
72745
72746 @@ -2952,7 +2952,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
72747 if (sub != event)
72748 sub->pmu->read(sub);
72749
72750 - values[n++] = atomic64_read(&sub->count);
72751 + values[n++] = atomic64_read_unchecked(&sub->count);
72752 if (read_format & PERF_FORMAT_ID)
72753 values[n++] = primary_event_id(sub);
72754
72755 @@ -3525,12 +3525,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
72756 * need to add enough zero bytes after the string to handle
72757 * the 64bit alignment we do later.
72758 */
72759 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
72760 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
72761 if (!buf) {
72762 name = strncpy(tmp, "//enomem", sizeof(tmp));
72763 goto got_name;
72764 }
72765 - name = d_path(&file->f_path, buf, PATH_MAX);
72766 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
72767 if (IS_ERR(name)) {
72768 name = strncpy(tmp, "//toolong", sizeof(tmp));
72769 goto got_name;
72770 @@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
72771 {
72772 struct hw_perf_event *hwc = &event->hw;
72773
72774 - atomic64_add(nr, &event->count);
72775 + atomic64_add_unchecked(nr, &event->count);
72776
72777 if (!hwc->sample_period)
72778 return;
72779 @@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(struct perf_event *event)
72780 u64 now;
72781
72782 now = cpu_clock(cpu);
72783 - prev = atomic64_read(&event->hw.prev_count);
72784 - atomic64_set(&event->hw.prev_count, now);
72785 - atomic64_add(now - prev, &event->count);
72786 + prev = atomic64_read_unchecked(&event->hw.prev_count);
72787 + atomic64_set_unchecked(&event->hw.prev_count, now);
72788 + atomic64_add_unchecked(now - prev, &event->count);
72789 }
72790
72791 static int cpu_clock_perf_event_enable(struct perf_event *event)
72792 @@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(struct perf_event *event)
72793 struct hw_perf_event *hwc = &event->hw;
72794 int cpu = raw_smp_processor_id();
72795
72796 - atomic64_set(&hwc->prev_count, cpu_clock(cpu));
72797 + atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
72798 perf_swevent_start_hrtimer(event);
72799
72800 return 0;
72801 @@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update(struct perf_event *event, u64 now)
72802 u64 prev;
72803 s64 delta;
72804
72805 - prev = atomic64_xchg(&event->hw.prev_count, now);
72806 + prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
72807 delta = now - prev;
72808 - atomic64_add(delta, &event->count);
72809 + atomic64_add_unchecked(delta, &event->count);
72810 }
72811
72812 static int task_clock_perf_event_enable(struct perf_event *event)
72813 @@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(struct perf_event *event)
72814
72815 now = event->ctx->time;
72816
72817 - atomic64_set(&hwc->prev_count, now);
72818 + atomic64_set_unchecked(&hwc->prev_count, now);
72819
72820 perf_swevent_start_hrtimer(event);
72821
72822 @@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr *attr,
72823 event->parent = parent_event;
72824
72825 event->ns = get_pid_ns(current->nsproxy->pid_ns);
72826 - event->id = atomic64_inc_return(&perf_event_id);
72827 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
72828
72829 event->state = PERF_EVENT_STATE_INACTIVE;
72830
72831 @@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf_event *child_event,
72832 if (child_event->attr.inherit_stat)
72833 perf_event_read_event(child_event, child);
72834
72835 - child_val = atomic64_read(&child_event->count);
72836 + child_val = atomic64_read_unchecked(&child_event->count);
72837
72838 /*
72839 * Add back the child's count to the parent's count:
72840 */
72841 - atomic64_add(child_val, &parent_event->count);
72842 - atomic64_add(child_event->total_time_enabled,
72843 + atomic64_add_unchecked(child_val, &parent_event->count);
72844 + atomic64_add_unchecked(child_event->total_time_enabled,
72845 &parent_event->child_total_time_enabled);
72846 - atomic64_add(child_event->total_time_running,
72847 + atomic64_add_unchecked(child_event->total_time_running,
72848 &parent_event->child_total_time_running);
72849
72850 /*
72851 diff --git a/kernel/pid.c b/kernel/pid.c
72852 index fce7198..4f23a7e 100644
72853 --- a/kernel/pid.c
72854 +++ b/kernel/pid.c
72855 @@ -33,6 +33,7 @@
72856 #include <linux/rculist.h>
72857 #include <linux/bootmem.h>
72858 #include <linux/hash.h>
72859 +#include <linux/security.h>
72860 #include <linux/pid_namespace.h>
72861 #include <linux/init_task.h>
72862 #include <linux/syscalls.h>
72863 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
72864
72865 int pid_max = PID_MAX_DEFAULT;
72866
72867 -#define RESERVED_PIDS 300
72868 +#define RESERVED_PIDS 500
72869
72870 int pid_max_min = RESERVED_PIDS + 1;
72871 int pid_max_max = PID_MAX_LIMIT;
72872 @@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
72873 */
72874 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
72875 {
72876 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72877 + struct task_struct *task;
72878 +
72879 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72880 +
72881 + if (gr_pid_is_chrooted(task))
72882 + return NULL;
72883 +
72884 + return task;
72885 }
72886
72887 struct task_struct *find_task_by_vpid(pid_t vnr)
72888 @@ -391,6 +399,11 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
72889 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
72890 }
72891
72892 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
72893 +{
72894 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
72895 +}
72896 +
72897 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
72898 {
72899 struct pid *pid;
72900 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
72901 index 5c9dc22..d271117 100644
72902 --- a/kernel/posix-cpu-timers.c
72903 +++ b/kernel/posix-cpu-timers.c
72904 @@ -6,6 +6,7 @@
72905 #include <linux/posix-timers.h>
72906 #include <linux/errno.h>
72907 #include <linux/math64.h>
72908 +#include <linux/security.h>
72909 #include <asm/uaccess.h>
72910 #include <linux/kernel_stat.h>
72911 #include <trace/events/timer.h>
72912 @@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
72913
72914 static __init int init_posix_cpu_timers(void)
72915 {
72916 - struct k_clock process = {
72917 + static struct k_clock process = {
72918 .clock_getres = process_cpu_clock_getres,
72919 .clock_get = process_cpu_clock_get,
72920 .clock_set = do_posix_clock_nosettime,
72921 @@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(void)
72922 .nsleep = process_cpu_nsleep,
72923 .nsleep_restart = process_cpu_nsleep_restart,
72924 };
72925 - struct k_clock thread = {
72926 + static struct k_clock thread = {
72927 .clock_getres = thread_cpu_clock_getres,
72928 .clock_get = thread_cpu_clock_get,
72929 .clock_set = do_posix_clock_nosettime,
72930 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72931 index 5e76d22..cf1baeb 100644
72932 --- a/kernel/posix-timers.c
72933 +++ b/kernel/posix-timers.c
72934 @@ -42,6 +42,7 @@
72935 #include <linux/compiler.h>
72936 #include <linux/idr.h>
72937 #include <linux/posix-timers.h>
72938 +#include <linux/grsecurity.h>
72939 #include <linux/syscalls.h>
72940 #include <linux/wait.h>
72941 #include <linux/workqueue.h>
72942 @@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
72943 * which we beg off on and pass to do_sys_settimeofday().
72944 */
72945
72946 -static struct k_clock posix_clocks[MAX_CLOCKS];
72947 +static struct k_clock *posix_clocks[MAX_CLOCKS];
72948
72949 /*
72950 * These ones are defined below.
72951 @@ -157,8 +158,8 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
72952 */
72953 #define CLOCK_DISPATCH(clock, call, arglist) \
72954 ((clock) < 0 ? posix_cpu_##call arglist : \
72955 - (posix_clocks[clock].call != NULL \
72956 - ? (*posix_clocks[clock].call) arglist : common_##call arglist))
72957 + (posix_clocks[clock]->call != NULL \
72958 + ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
72959
72960 /*
72961 * Default clock hook functions when the struct k_clock passed
72962 @@ -172,7 +173,7 @@ static inline int common_clock_getres(const clockid_t which_clock,
72963 struct timespec *tp)
72964 {
72965 tp->tv_sec = 0;
72966 - tp->tv_nsec = posix_clocks[which_clock].res;
72967 + tp->tv_nsec = posix_clocks[which_clock]->res;
72968 return 0;
72969 }
72970
72971 @@ -217,9 +218,11 @@ static inline int invalid_clockid(const clockid_t which_clock)
72972 return 0;
72973 if ((unsigned) which_clock >= MAX_CLOCKS)
72974 return 1;
72975 - if (posix_clocks[which_clock].clock_getres != NULL)
72976 + if (posix_clocks[which_clock] == NULL)
72977 return 0;
72978 - if (posix_clocks[which_clock].res != 0)
72979 + if (posix_clocks[which_clock]->clock_getres != NULL)
72980 + return 0;
72981 + if (posix_clocks[which_clock]->res != 0)
72982 return 0;
72983 return 1;
72984 }
72985 @@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
72986 */
72987 static __init int init_posix_timers(void)
72988 {
72989 - struct k_clock clock_realtime = {
72990 + static struct k_clock clock_realtime = {
72991 .clock_getres = hrtimer_get_res,
72992 };
72993 - struct k_clock clock_monotonic = {
72994 + static struct k_clock clock_monotonic = {
72995 .clock_getres = hrtimer_get_res,
72996 .clock_get = posix_ktime_get_ts,
72997 .clock_set = do_posix_clock_nosettime,
72998 };
72999 - struct k_clock clock_monotonic_raw = {
73000 + static struct k_clock clock_monotonic_raw = {
73001 .clock_getres = hrtimer_get_res,
73002 .clock_get = posix_get_monotonic_raw,
73003 .clock_set = do_posix_clock_nosettime,
73004 .timer_create = no_timer_create,
73005 .nsleep = no_nsleep,
73006 };
73007 - struct k_clock clock_realtime_coarse = {
73008 + static struct k_clock clock_realtime_coarse = {
73009 .clock_getres = posix_get_coarse_res,
73010 .clock_get = posix_get_realtime_coarse,
73011 .clock_set = do_posix_clock_nosettime,
73012 .timer_create = no_timer_create,
73013 .nsleep = no_nsleep,
73014 };
73015 - struct k_clock clock_monotonic_coarse = {
73016 + static struct k_clock clock_monotonic_coarse = {
73017 .clock_getres = posix_get_coarse_res,
73018 .clock_get = posix_get_monotonic_coarse,
73019 .clock_set = do_posix_clock_nosettime,
73020 @@ -296,6 +299,8 @@ static __init int init_posix_timers(void)
73021 .nsleep = no_nsleep,
73022 };
73023
73024 + pax_track_stack();
73025 +
73026 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
73027 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
73028 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
73029 @@ -484,7 +489,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
73030 return;
73031 }
73032
73033 - posix_clocks[clock_id] = *new_clock;
73034 + posix_clocks[clock_id] = new_clock;
73035 }
73036 EXPORT_SYMBOL_GPL(register_posix_clock);
73037
73038 @@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
73039 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
73040 return -EFAULT;
73041
73042 + /* only the CLOCK_REALTIME clock can be set, all other clocks
73043 + have their clock_set fptr set to a nosettime dummy function
73044 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
73045 + call common_clock_set, which calls do_sys_settimeofday, which
73046 + we hook
73047 + */
73048 +
73049 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
73050 }
73051
73052 diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
73053 index 04a9e90..bc355aa 100644
73054 --- a/kernel/power/hibernate.c
73055 +++ b/kernel/power/hibernate.c
73056 @@ -48,14 +48,14 @@ enum {
73057
73058 static int hibernation_mode = HIBERNATION_SHUTDOWN;
73059
73060 -static struct platform_hibernation_ops *hibernation_ops;
73061 +static const struct platform_hibernation_ops *hibernation_ops;
73062
73063 /**
73064 * hibernation_set_ops - set the global hibernate operations
73065 * @ops: the hibernation operations to use in subsequent hibernation transitions
73066 */
73067
73068 -void hibernation_set_ops(struct platform_hibernation_ops *ops)
73069 +void hibernation_set_ops(const struct platform_hibernation_ops *ops)
73070 {
73071 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
73072 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
73073 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
73074 index e8b3370..484c2e4 100644
73075 --- a/kernel/power/poweroff.c
73076 +++ b/kernel/power/poweroff.c
73077 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
73078 .enable_mask = SYSRQ_ENABLE_BOOT,
73079 };
73080
73081 -static int pm_sysrq_init(void)
73082 +static int __init pm_sysrq_init(void)
73083 {
73084 register_sysrq_key('o', &sysrq_poweroff_op);
73085 return 0;
73086 diff --git a/kernel/power/process.c b/kernel/power/process.c
73087 index e7cd671..56d5f459 100644
73088 --- a/kernel/power/process.c
73089 +++ b/kernel/power/process.c
73090 @@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_only)
73091 struct timeval start, end;
73092 u64 elapsed_csecs64;
73093 unsigned int elapsed_csecs;
73094 + bool timedout = false;
73095
73096 do_gettimeofday(&start);
73097
73098 end_time = jiffies + TIMEOUT;
73099 do {
73100 todo = 0;
73101 + if (time_after(jiffies, end_time))
73102 + timedout = true;
73103 read_lock(&tasklist_lock);
73104 do_each_thread(g, p) {
73105 if (frozen(p) || !freezeable(p))
73106 @@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_only)
73107 * It is "frozen enough". If the task does wake
73108 * up, it will immediately call try_to_freeze.
73109 */
73110 - if (!task_is_stopped_or_traced(p) &&
73111 - !freezer_should_skip(p))
73112 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
73113 todo++;
73114 + if (timedout) {
73115 + printk(KERN_ERR "Task refusing to freeze:\n");
73116 + sched_show_task(p);
73117 + }
73118 + }
73119 } while_each_thread(g, p);
73120 read_unlock(&tasklist_lock);
73121 yield(); /* Yield is okay here */
73122 - if (time_after(jiffies, end_time))
73123 - break;
73124 - } while (todo);
73125 + } while (todo && !timedout);
73126
73127 do_gettimeofday(&end);
73128 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
73129 diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
73130 index 40dd021..fb30ceb 100644
73131 --- a/kernel/power/suspend.c
73132 +++ b/kernel/power/suspend.c
73133 @@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_MAX] = {
73134 [PM_SUSPEND_MEM] = "mem",
73135 };
73136
73137 -static struct platform_suspend_ops *suspend_ops;
73138 +static const struct platform_suspend_ops *suspend_ops;
73139
73140 /**
73141 * suspend_set_ops - Set the global suspend method table.
73142 * @ops: Pointer to ops structure.
73143 */
73144 -void suspend_set_ops(struct platform_suspend_ops *ops)
73145 +void suspend_set_ops(const struct platform_suspend_ops *ops)
73146 {
73147 mutex_lock(&pm_mutex);
73148 suspend_ops = ops;
73149 diff --git a/kernel/printk.c b/kernel/printk.c
73150 index 4cade47..4d17900 100644
73151 --- a/kernel/printk.c
73152 +++ b/kernel/printk.c
73153 @@ -33,6 +33,7 @@
73154 #include <linux/bootmem.h>
73155 #include <linux/syscalls.h>
73156 #include <linux/kexec.h>
73157 +#include <linux/syslog.h>
73158
73159 #include <asm/uaccess.h>
73160
73161 @@ -256,38 +257,30 @@ static inline void boot_delay_msec(void)
73162 }
73163 #endif
73164
73165 -/*
73166 - * Commands to do_syslog:
73167 - *
73168 - * 0 -- Close the log. Currently a NOP.
73169 - * 1 -- Open the log. Currently a NOP.
73170 - * 2 -- Read from the log.
73171 - * 3 -- Read all messages remaining in the ring buffer.
73172 - * 4 -- Read and clear all messages remaining in the ring buffer
73173 - * 5 -- Clear ring buffer.
73174 - * 6 -- Disable printk's to console
73175 - * 7 -- Enable printk's to console
73176 - * 8 -- Set level of messages printed to console
73177 - * 9 -- Return number of unread characters in the log buffer
73178 - * 10 -- Return size of the log buffer
73179 - */
73180 -int do_syslog(int type, char __user *buf, int len)
73181 +int do_syslog(int type, char __user *buf, int len, bool from_file)
73182 {
73183 unsigned i, j, limit, count;
73184 int do_clear = 0;
73185 char c;
73186 int error = 0;
73187
73188 - error = security_syslog(type);
73189 +#ifdef CONFIG_GRKERNSEC_DMESG
73190 + if (grsec_enable_dmesg &&
73191 + (!from_file || (from_file && type == SYSLOG_ACTION_OPEN)) &&
73192 + !capable(CAP_SYS_ADMIN))
73193 + return -EPERM;
73194 +#endif
73195 +
73196 + error = security_syslog(type, from_file);
73197 if (error)
73198 return error;
73199
73200 switch (type) {
73201 - case 0: /* Close log */
73202 + case SYSLOG_ACTION_CLOSE: /* Close log */
73203 break;
73204 - case 1: /* Open log */
73205 + case SYSLOG_ACTION_OPEN: /* Open log */
73206 break;
73207 - case 2: /* Read from log */
73208 + case SYSLOG_ACTION_READ: /* Read from log */
73209 error = -EINVAL;
73210 if (!buf || len < 0)
73211 goto out;
73212 @@ -318,10 +311,12 @@ int do_syslog(int type, char __user *buf, int len)
73213 if (!error)
73214 error = i;
73215 break;
73216 - case 4: /* Read/clear last kernel messages */
73217 + /* Read/clear last kernel messages */
73218 + case SYSLOG_ACTION_READ_CLEAR:
73219 do_clear = 1;
73220 /* FALL THRU */
73221 - case 3: /* Read last kernel messages */
73222 + /* Read last kernel messages */
73223 + case SYSLOG_ACTION_READ_ALL:
73224 error = -EINVAL;
73225 if (!buf || len < 0)
73226 goto out;
73227 @@ -374,21 +369,25 @@ int do_syslog(int type, char __user *buf, int len)
73228 }
73229 }
73230 break;
73231 - case 5: /* Clear ring buffer */
73232 + /* Clear ring buffer */
73233 + case SYSLOG_ACTION_CLEAR:
73234 logged_chars = 0;
73235 break;
73236 - case 6: /* Disable logging to console */
73237 + /* Disable logging to console */
73238 + case SYSLOG_ACTION_CONSOLE_OFF:
73239 if (saved_console_loglevel == -1)
73240 saved_console_loglevel = console_loglevel;
73241 console_loglevel = minimum_console_loglevel;
73242 break;
73243 - case 7: /* Enable logging to console */
73244 + /* Enable logging to console */
73245 + case SYSLOG_ACTION_CONSOLE_ON:
73246 if (saved_console_loglevel != -1) {
73247 console_loglevel = saved_console_loglevel;
73248 saved_console_loglevel = -1;
73249 }
73250 break;
73251 - case 8: /* Set level of messages printed to console */
73252 + /* Set level of messages printed to console */
73253 + case SYSLOG_ACTION_CONSOLE_LEVEL:
73254 error = -EINVAL;
73255 if (len < 1 || len > 8)
73256 goto out;
73257 @@ -399,10 +398,12 @@ int do_syslog(int type, char __user *buf, int len)
73258 saved_console_loglevel = -1;
73259 error = 0;
73260 break;
73261 - case 9: /* Number of chars in the log buffer */
73262 + /* Number of chars in the log buffer */
73263 + case SYSLOG_ACTION_SIZE_UNREAD:
73264 error = log_end - log_start;
73265 break;
73266 - case 10: /* Size of the log buffer */
73267 + /* Size of the log buffer */
73268 + case SYSLOG_ACTION_SIZE_BUFFER:
73269 error = log_buf_len;
73270 break;
73271 default:
73272 @@ -415,7 +416,7 @@ out:
73273
73274 SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
73275 {
73276 - return do_syslog(type, buf, len);
73277 + return do_syslog(type, buf, len, SYSLOG_FROM_CALL);
73278 }
73279
73280 /*
73281 diff --git a/kernel/profile.c b/kernel/profile.c
73282 index dfadc5b..7f59404 100644
73283 --- a/kernel/profile.c
73284 +++ b/kernel/profile.c
73285 @@ -39,7 +39,7 @@ struct profile_hit {
73286 /* Oprofile timer tick hook */
73287 static int (*timer_hook)(struct pt_regs *) __read_mostly;
73288
73289 -static atomic_t *prof_buffer;
73290 +static atomic_unchecked_t *prof_buffer;
73291 static unsigned long prof_len, prof_shift;
73292
73293 int prof_on __read_mostly;
73294 @@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
73295 hits[i].pc = 0;
73296 continue;
73297 }
73298 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73299 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73300 hits[i].hits = hits[i].pc = 0;
73301 }
73302 }
73303 @@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73304 * Add the current hit(s) and flush the write-queue out
73305 * to the global buffer:
73306 */
73307 - atomic_add(nr_hits, &prof_buffer[pc]);
73308 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
73309 for (i = 0; i < NR_PROFILE_HIT; ++i) {
73310 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73311 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73312 hits[i].pc = hits[i].hits = 0;
73313 }
73314 out:
73315 @@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73316 if (prof_on != type || !prof_buffer)
73317 return;
73318 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
73319 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73320 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73321 }
73322 #endif /* !CONFIG_SMP */
73323 EXPORT_SYMBOL_GPL(profile_hits);
73324 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
73325 return -EFAULT;
73326 buf++; p++; count--; read++;
73327 }
73328 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
73329 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
73330 if (copy_to_user(buf, (void *)pnt, count))
73331 return -EFAULT;
73332 read += count;
73333 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
73334 }
73335 #endif
73336 profile_discard_flip_buffers();
73337 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
73338 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
73339 return count;
73340 }
73341
73342 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
73343 index 05625f6..733bf70 100644
73344 --- a/kernel/ptrace.c
73345 +++ b/kernel/ptrace.c
73346 @@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_struct *child, int kill)
73347 return ret;
73348 }
73349
73350 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73351 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
73352 + unsigned int log)
73353 {
73354 const struct cred *cred = current_cred(), *tcred;
73355
73356 @@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73357 cred->gid != tcred->egid ||
73358 cred->gid != tcred->sgid ||
73359 cred->gid != tcred->gid) &&
73360 - !capable(CAP_SYS_PTRACE)) {
73361 + ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73362 + (log && !capable(CAP_SYS_PTRACE)))
73363 + ) {
73364 rcu_read_unlock();
73365 return -EPERM;
73366 }
73367 @@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73368 smp_rmb();
73369 if (task->mm)
73370 dumpable = get_dumpable(task->mm);
73371 - if (!dumpable && !capable(CAP_SYS_PTRACE))
73372 + if (!dumpable &&
73373 + ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73374 + (log && !capable(CAP_SYS_PTRACE))))
73375 return -EPERM;
73376
73377 return security_ptrace_access_check(task, mode);
73378 @@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
73379 {
73380 int err;
73381 task_lock(task);
73382 - err = __ptrace_may_access(task, mode);
73383 + err = __ptrace_may_access(task, mode, 0);
73384 + task_unlock(task);
73385 + return !err;
73386 +}
73387 +
73388 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
73389 +{
73390 + int err;
73391 + task_lock(task);
73392 + err = __ptrace_may_access(task, mode, 1);
73393 task_unlock(task);
73394 return !err;
73395 }
73396 @@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *task)
73397 goto out;
73398
73399 task_lock(task);
73400 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
73401 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
73402 task_unlock(task);
73403 if (retval)
73404 goto unlock_creds;
73405 @@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *task)
73406 goto unlock_tasklist;
73407
73408 task->ptrace = PT_PTRACED;
73409 - if (capable(CAP_SYS_PTRACE))
73410 + if (capable_nolog(CAP_SYS_PTRACE))
73411 task->ptrace |= PT_PTRACE_CAP;
73412
73413 __ptrace_link(task, current);
73414 @@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
73415 {
73416 int copied = 0;
73417
73418 + pax_track_stack();
73419 +
73420 while (len > 0) {
73421 char buf[128];
73422 int this_len, retval;
73423 @@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
73424 {
73425 int copied = 0;
73426
73427 + pax_track_stack();
73428 +
73429 while (len > 0) {
73430 char buf[128];
73431 int this_len, retval;
73432 @@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *child, long request,
73433 int ret = -EIO;
73434 siginfo_t siginfo;
73435
73436 + pax_track_stack();
73437 +
73438 switch (request) {
73439 case PTRACE_PEEKTEXT:
73440 case PTRACE_PEEKDATA:
73441 @@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *child, long request,
73442 ret = ptrace_setoptions(child, data);
73443 break;
73444 case PTRACE_GETEVENTMSG:
73445 - ret = put_user(child->ptrace_message, (unsigned long __user *) data);
73446 + ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
73447 break;
73448
73449 case PTRACE_GETSIGINFO:
73450 ret = ptrace_getsiginfo(child, &siginfo);
73451 if (!ret)
73452 - ret = copy_siginfo_to_user((siginfo_t __user *) data,
73453 + ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
73454 &siginfo);
73455 break;
73456
73457 case PTRACE_SETSIGINFO:
73458 - if (copy_from_user(&siginfo, (siginfo_t __user *) data,
73459 + if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
73460 sizeof siginfo))
73461 ret = -EFAULT;
73462 else
73463 @@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
73464 goto out;
73465 }
73466
73467 + if (gr_handle_ptrace(child, request)) {
73468 + ret = -EPERM;
73469 + goto out_put_task_struct;
73470 + }
73471 +
73472 if (request == PTRACE_ATTACH) {
73473 ret = ptrace_attach(child);
73474 /*
73475 * Some architectures need to do book-keeping after
73476 * a ptrace attach.
73477 */
73478 - if (!ret)
73479 + if (!ret) {
73480 arch_ptrace_attach(child);
73481 + gr_audit_ptrace(child);
73482 + }
73483 goto out_put_task_struct;
73484 }
73485
73486 @@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
73487 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
73488 if (copied != sizeof(tmp))
73489 return -EIO;
73490 - return put_user(tmp, (unsigned long __user *)data);
73491 + return put_user(tmp, (__force unsigned long __user *)data);
73492 }
73493
73494 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
73495 @@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
73496 siginfo_t siginfo;
73497 int ret;
73498
73499 + pax_track_stack();
73500 +
73501 switch (request) {
73502 case PTRACE_PEEKTEXT:
73503 case PTRACE_PEEKDATA:
73504 @@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73505 goto out;
73506 }
73507
73508 + if (gr_handle_ptrace(child, request)) {
73509 + ret = -EPERM;
73510 + goto out_put_task_struct;
73511 + }
73512 +
73513 if (request == PTRACE_ATTACH) {
73514 ret = ptrace_attach(child);
73515 /*
73516 * Some architectures need to do book-keeping after
73517 * a ptrace attach.
73518 */
73519 - if (!ret)
73520 + if (!ret) {
73521 arch_ptrace_attach(child);
73522 + gr_audit_ptrace(child);
73523 + }
73524 goto out_put_task_struct;
73525 }
73526
73527 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
73528 index 697c0a0..2402696 100644
73529 --- a/kernel/rcutorture.c
73530 +++ b/kernel/rcutorture.c
73531 @@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
73532 { 0 };
73533 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
73534 { 0 };
73535 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73536 -static atomic_t n_rcu_torture_alloc;
73537 -static atomic_t n_rcu_torture_alloc_fail;
73538 -static atomic_t n_rcu_torture_free;
73539 -static atomic_t n_rcu_torture_mberror;
73540 -static atomic_t n_rcu_torture_error;
73541 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73542 +static atomic_unchecked_t n_rcu_torture_alloc;
73543 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
73544 +static atomic_unchecked_t n_rcu_torture_free;
73545 +static atomic_unchecked_t n_rcu_torture_mberror;
73546 +static atomic_unchecked_t n_rcu_torture_error;
73547 static long n_rcu_torture_timers;
73548 static struct list_head rcu_torture_removed;
73549 static cpumask_var_t shuffle_tmp_mask;
73550 @@ -187,11 +187,11 @@ rcu_torture_alloc(void)
73551
73552 spin_lock_bh(&rcu_torture_lock);
73553 if (list_empty(&rcu_torture_freelist)) {
73554 - atomic_inc(&n_rcu_torture_alloc_fail);
73555 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
73556 spin_unlock_bh(&rcu_torture_lock);
73557 return NULL;
73558 }
73559 - atomic_inc(&n_rcu_torture_alloc);
73560 + atomic_inc_unchecked(&n_rcu_torture_alloc);
73561 p = rcu_torture_freelist.next;
73562 list_del_init(p);
73563 spin_unlock_bh(&rcu_torture_lock);
73564 @@ -204,7 +204,7 @@ rcu_torture_alloc(void)
73565 static void
73566 rcu_torture_free(struct rcu_torture *p)
73567 {
73568 - atomic_inc(&n_rcu_torture_free);
73569 + atomic_inc_unchecked(&n_rcu_torture_free);
73570 spin_lock_bh(&rcu_torture_lock);
73571 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
73572 spin_unlock_bh(&rcu_torture_lock);
73573 @@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
73574 i = rp->rtort_pipe_count;
73575 if (i > RCU_TORTURE_PIPE_LEN)
73576 i = RCU_TORTURE_PIPE_LEN;
73577 - atomic_inc(&rcu_torture_wcount[i]);
73578 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
73579 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73580 rp->rtort_mbtest = 0;
73581 rcu_torture_free(rp);
73582 @@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
73583 i = rp->rtort_pipe_count;
73584 if (i > RCU_TORTURE_PIPE_LEN)
73585 i = RCU_TORTURE_PIPE_LEN;
73586 - atomic_inc(&rcu_torture_wcount[i]);
73587 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
73588 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73589 rp->rtort_mbtest = 0;
73590 list_del(&rp->rtort_free);
73591 @@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
73592 i = old_rp->rtort_pipe_count;
73593 if (i > RCU_TORTURE_PIPE_LEN)
73594 i = RCU_TORTURE_PIPE_LEN;
73595 - atomic_inc(&rcu_torture_wcount[i]);
73596 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
73597 old_rp->rtort_pipe_count++;
73598 cur_ops->deferred_free(old_rp);
73599 }
73600 @@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned long unused)
73601 return;
73602 }
73603 if (p->rtort_mbtest == 0)
73604 - atomic_inc(&n_rcu_torture_mberror);
73605 + atomic_inc_unchecked(&n_rcu_torture_mberror);
73606 spin_lock(&rand_lock);
73607 cur_ops->read_delay(&rand);
73608 n_rcu_torture_timers++;
73609 @@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
73610 continue;
73611 }
73612 if (p->rtort_mbtest == 0)
73613 - atomic_inc(&n_rcu_torture_mberror);
73614 + atomic_inc_unchecked(&n_rcu_torture_mberror);
73615 cur_ops->read_delay(&rand);
73616 preempt_disable();
73617 pipe_count = p->rtort_pipe_count;
73618 @@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
73619 rcu_torture_current,
73620 rcu_torture_current_version,
73621 list_empty(&rcu_torture_freelist),
73622 - atomic_read(&n_rcu_torture_alloc),
73623 - atomic_read(&n_rcu_torture_alloc_fail),
73624 - atomic_read(&n_rcu_torture_free),
73625 - atomic_read(&n_rcu_torture_mberror),
73626 + atomic_read_unchecked(&n_rcu_torture_alloc),
73627 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
73628 + atomic_read_unchecked(&n_rcu_torture_free),
73629 + atomic_read_unchecked(&n_rcu_torture_mberror),
73630 n_rcu_torture_timers);
73631 - if (atomic_read(&n_rcu_torture_mberror) != 0)
73632 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
73633 cnt += sprintf(&page[cnt], " !!!");
73634 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
73635 if (i > 1) {
73636 cnt += sprintf(&page[cnt], "!!! ");
73637 - atomic_inc(&n_rcu_torture_error);
73638 + atomic_inc_unchecked(&n_rcu_torture_error);
73639 WARN_ON_ONCE(1);
73640 }
73641 cnt += sprintf(&page[cnt], "Reader Pipe: ");
73642 @@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
73643 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
73644 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73645 cnt += sprintf(&page[cnt], " %d",
73646 - atomic_read(&rcu_torture_wcount[i]));
73647 + atomic_read_unchecked(&rcu_torture_wcount[i]));
73648 }
73649 cnt += sprintf(&page[cnt], "\n");
73650 if (cur_ops->stats)
73651 @@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
73652
73653 if (cur_ops->cleanup)
73654 cur_ops->cleanup();
73655 - if (atomic_read(&n_rcu_torture_error))
73656 + if (atomic_read_unchecked(&n_rcu_torture_error))
73657 rcu_torture_print_module_parms("End of test: FAILURE");
73658 else
73659 rcu_torture_print_module_parms("End of test: SUCCESS");
73660 @@ -1138,13 +1138,13 @@ rcu_torture_init(void)
73661
73662 rcu_torture_current = NULL;
73663 rcu_torture_current_version = 0;
73664 - atomic_set(&n_rcu_torture_alloc, 0);
73665 - atomic_set(&n_rcu_torture_alloc_fail, 0);
73666 - atomic_set(&n_rcu_torture_free, 0);
73667 - atomic_set(&n_rcu_torture_mberror, 0);
73668 - atomic_set(&n_rcu_torture_error, 0);
73669 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
73670 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
73671 + atomic_set_unchecked(&n_rcu_torture_free, 0);
73672 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
73673 + atomic_set_unchecked(&n_rcu_torture_error, 0);
73674 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
73675 - atomic_set(&rcu_torture_wcount[i], 0);
73676 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
73677 for_each_possible_cpu(cpu) {
73678 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73679 per_cpu(rcu_torture_count, cpu)[i] = 0;
73680 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
73681 index 683c4f3..97f54c6 100644
73682 --- a/kernel/rcutree.c
73683 +++ b/kernel/rcutree.c
73684 @@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
73685 /*
73686 * Do softirq processing for the current CPU.
73687 */
73688 -static void rcu_process_callbacks(struct softirq_action *unused)
73689 +static void rcu_process_callbacks(void)
73690 {
73691 /*
73692 * Memory references from any prior RCU read-side critical sections
73693 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
73694 index c03edf7..ac1b341 100644
73695 --- a/kernel/rcutree_plugin.h
73696 +++ b/kernel/rcutree_plugin.h
73697 @@ -145,7 +145,7 @@ static void rcu_preempt_note_context_switch(int cpu)
73698 */
73699 void __rcu_read_lock(void)
73700 {
73701 - ACCESS_ONCE(current->rcu_read_lock_nesting)++;
73702 + ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
73703 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
73704 }
73705 EXPORT_SYMBOL_GPL(__rcu_read_lock);
73706 @@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
73707 struct task_struct *t = current;
73708
73709 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
73710 - if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
73711 + if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
73712 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
73713 rcu_read_unlock_special(t);
73714 }
73715 diff --git a/kernel/relay.c b/kernel/relay.c
73716 index 760c262..a9fd241 100644
73717 --- a/kernel/relay.c
73718 +++ b/kernel/relay.c
73719 @@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct file *in,
73720 unsigned int flags,
73721 int *nonpad_ret)
73722 {
73723 - unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
73724 + unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
73725 struct rchan_buf *rbuf = in->private_data;
73726 unsigned int subbuf_size = rbuf->chan->subbuf_size;
73727 uint64_t pos = (uint64_t) *ppos;
73728 @@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct file *in,
73729 .ops = &relay_pipe_buf_ops,
73730 .spd_release = relay_page_release,
73731 };
73732 + ssize_t ret;
73733 +
73734 + pax_track_stack();
73735
73736 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
73737 return 0;
73738 diff --git a/kernel/resource.c b/kernel/resource.c
73739 index fb11a58..4e61ae1 100644
73740 --- a/kernel/resource.c
73741 +++ b/kernel/resource.c
73742 @@ -132,8 +132,18 @@ static const struct file_operations proc_iomem_operations = {
73743
73744 static int __init ioresources_init(void)
73745 {
73746 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73747 +#ifdef CONFIG_GRKERNSEC_PROC_USER
73748 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
73749 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
73750 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73751 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
73752 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
73753 +#endif
73754 +#else
73755 proc_create("ioports", 0, NULL, &proc_ioports_operations);
73756 proc_create("iomem", 0, NULL, &proc_iomem_operations);
73757 +#endif
73758 return 0;
73759 }
73760 __initcall(ioresources_init);
73761 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
73762 index a56f629..1fc4989 100644
73763 --- a/kernel/rtmutex-tester.c
73764 +++ b/kernel/rtmutex-tester.c
73765 @@ -21,7 +21,7 @@
73766 #define MAX_RT_TEST_MUTEXES 8
73767
73768 static spinlock_t rttest_lock;
73769 -static atomic_t rttest_event;
73770 +static atomic_unchecked_t rttest_event;
73771
73772 struct test_thread_data {
73773 int opcode;
73774 @@ -64,7 +64,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73775
73776 case RTTEST_LOCKCONT:
73777 td->mutexes[td->opdata] = 1;
73778 - td->event = atomic_add_return(1, &rttest_event);
73779 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73780 return 0;
73781
73782 case RTTEST_RESET:
73783 @@ -82,7 +82,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73784 return 0;
73785
73786 case RTTEST_RESETEVENT:
73787 - atomic_set(&rttest_event, 0);
73788 + atomic_set_unchecked(&rttest_event, 0);
73789 return 0;
73790
73791 default:
73792 @@ -99,9 +99,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73793 return ret;
73794
73795 td->mutexes[id] = 1;
73796 - td->event = atomic_add_return(1, &rttest_event);
73797 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73798 rt_mutex_lock(&mutexes[id]);
73799 - td->event = atomic_add_return(1, &rttest_event);
73800 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73801 td->mutexes[id] = 4;
73802 return 0;
73803
73804 @@ -112,9 +112,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73805 return ret;
73806
73807 td->mutexes[id] = 1;
73808 - td->event = atomic_add_return(1, &rttest_event);
73809 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73810 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73811 - td->event = atomic_add_return(1, &rttest_event);
73812 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73813 td->mutexes[id] = ret ? 0 : 4;
73814 return ret ? -EINTR : 0;
73815
73816 @@ -123,9 +123,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73817 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73818 return ret;
73819
73820 - td->event = atomic_add_return(1, &rttest_event);
73821 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73822 rt_mutex_unlock(&mutexes[id]);
73823 - td->event = atomic_add_return(1, &rttest_event);
73824 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73825 td->mutexes[id] = 0;
73826 return 0;
73827
73828 @@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73829 break;
73830
73831 td->mutexes[dat] = 2;
73832 - td->event = atomic_add_return(1, &rttest_event);
73833 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73834 break;
73835
73836 case RTTEST_LOCKBKL:
73837 @@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73838 return;
73839
73840 td->mutexes[dat] = 3;
73841 - td->event = atomic_add_return(1, &rttest_event);
73842 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73843 break;
73844
73845 case RTTEST_LOCKNOWAIT:
73846 @@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73847 return;
73848
73849 td->mutexes[dat] = 1;
73850 - td->event = atomic_add_return(1, &rttest_event);
73851 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73852 return;
73853
73854 case RTTEST_LOCKBKL:
73855 diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
73856 index 29bd4ba..8c5de90 100644
73857 --- a/kernel/rtmutex.c
73858 +++ b/kernel/rtmutex.c
73859 @@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
73860 */
73861 spin_lock_irqsave(&pendowner->pi_lock, flags);
73862
73863 - WARN_ON(!pendowner->pi_blocked_on);
73864 + BUG_ON(!pendowner->pi_blocked_on);
73865 WARN_ON(pendowner->pi_blocked_on != waiter);
73866 WARN_ON(pendowner->pi_blocked_on->lock != lock);
73867
73868 diff --git a/kernel/sched.c b/kernel/sched.c
73869 index 0591df8..6e343c3 100644
73870 --- a/kernel/sched.c
73871 +++ b/kernel/sched.c
73872 @@ -2764,9 +2764,10 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
73873 {
73874 unsigned long flags;
73875 struct rq *rq;
73876 - int cpu = get_cpu();
73877
73878 #ifdef CONFIG_SMP
73879 + int cpu = get_cpu();
73880 +
73881 rq = task_rq_lock(p, &flags);
73882 p->state = TASK_WAKING;
73883
73884 @@ -5043,7 +5044,7 @@ out:
73885 * In CONFIG_NO_HZ case, the idle load balance owner will do the
73886 * rebalancing for all the cpus for whom scheduler ticks are stopped.
73887 */
73888 -static void run_rebalance_domains(struct softirq_action *h)
73889 +static void run_rebalance_domains(void)
73890 {
73891 int this_cpu = smp_processor_id();
73892 struct rq *this_rq = cpu_rq(this_cpu);
73893 @@ -5700,6 +5701,8 @@ asmlinkage void __sched schedule(void)
73894 struct rq *rq;
73895 int cpu;
73896
73897 + pax_track_stack();
73898 +
73899 need_resched:
73900 preempt_disable();
73901 cpu = smp_processor_id();
73902 @@ -5770,7 +5773,7 @@ EXPORT_SYMBOL(schedule);
73903 * Look out! "owner" is an entirely speculative pointer
73904 * access and not reliable.
73905 */
73906 -int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73907 +int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
73908 {
73909 unsigned int cpu;
73910 struct rq *rq;
73911 @@ -5784,10 +5787,10 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73912 * DEBUG_PAGEALLOC could have unmapped it if
73913 * the mutex owner just released it and exited.
73914 */
73915 - if (probe_kernel_address(&owner->cpu, cpu))
73916 + if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
73917 return 0;
73918 #else
73919 - cpu = owner->cpu;
73920 + cpu = task_thread_info(owner)->cpu;
73921 #endif
73922
73923 /*
73924 @@ -5816,7 +5819,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73925 /*
73926 * Is that owner really running on that cpu?
73927 */
73928 - if (task_thread_info(rq->curr) != owner || need_resched())
73929 + if (rq->curr != owner || need_resched())
73930 return 0;
73931
73932 cpu_relax();
73933 @@ -6359,6 +6362,8 @@ int can_nice(const struct task_struct *p, const int nice)
73934 /* convert nice value [19,-20] to rlimit style value [1,40] */
73935 int nice_rlim = 20 - nice;
73936
73937 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73938 +
73939 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
73940 capable(CAP_SYS_NICE));
73941 }
73942 @@ -6392,7 +6397,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73943 if (nice > 19)
73944 nice = 19;
73945
73946 - if (increment < 0 && !can_nice(current, nice))
73947 + if (increment < 0 && (!can_nice(current, nice) ||
73948 + gr_handle_chroot_nice()))
73949 return -EPERM;
73950
73951 retval = security_task_setnice(current, nice);
73952 @@ -8774,7 +8780,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
73953 long power;
73954 int weight;
73955
73956 - WARN_ON(!sd || !sd->groups);
73957 + BUG_ON(!sd || !sd->groups);
73958
73959 if (cpu != group_first_cpu(sd->groups))
73960 return;
73961 diff --git a/kernel/signal.c b/kernel/signal.c
73962 index 2494827..cda80a0 100644
73963 --- a/kernel/signal.c
73964 +++ b/kernel/signal.c
73965 @@ -41,12 +41,12 @@
73966
73967 static struct kmem_cache *sigqueue_cachep;
73968
73969 -static void __user *sig_handler(struct task_struct *t, int sig)
73970 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
73971 {
73972 return t->sighand->action[sig - 1].sa.sa_handler;
73973 }
73974
73975 -static int sig_handler_ignored(void __user *handler, int sig)
73976 +static int sig_handler_ignored(__sighandler_t handler, int sig)
73977 {
73978 /* Is it explicitly or implicitly ignored? */
73979 return handler == SIG_IGN ||
73980 @@ -56,7 +56,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73981 static int sig_task_ignored(struct task_struct *t, int sig,
73982 int from_ancestor_ns)
73983 {
73984 - void __user *handler;
73985 + __sighandler_t handler;
73986
73987 handler = sig_handler(t, sig);
73988
73989 @@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
73990 */
73991 user = get_uid(__task_cred(t)->user);
73992 atomic_inc(&user->sigpending);
73993 +
73994 + if (!override_rlimit)
73995 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73996 if (override_rlimit ||
73997 atomic_read(&user->sigpending) <=
73998 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
73999 @@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
74000
74001 int unhandled_signal(struct task_struct *tsk, int sig)
74002 {
74003 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
74004 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
74005 if (is_global_init(tsk))
74006 return 1;
74007 if (handler != SIG_IGN && handler != SIG_DFL)
74008 @@ -627,6 +630,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
74009 }
74010 }
74011
74012 + /* allow glibc communication via tgkill to other threads in our
74013 + thread group */
74014 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
74015 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
74016 + && gr_handle_signal(t, sig))
74017 + return -EPERM;
74018 +
74019 return security_task_kill(t, info, sig, 0);
74020 }
74021
74022 @@ -968,7 +978,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
74023 return send_signal(sig, info, p, 1);
74024 }
74025
74026 -static int
74027 +int
74028 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74029 {
74030 return send_signal(sig, info, t, 0);
74031 @@ -1005,6 +1015,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74032 unsigned long int flags;
74033 int ret, blocked, ignored;
74034 struct k_sigaction *action;
74035 + int is_unhandled = 0;
74036
74037 spin_lock_irqsave(&t->sighand->siglock, flags);
74038 action = &t->sighand->action[sig-1];
74039 @@ -1019,9 +1030,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74040 }
74041 if (action->sa.sa_handler == SIG_DFL)
74042 t->signal->flags &= ~SIGNAL_UNKILLABLE;
74043 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
74044 + is_unhandled = 1;
74045 ret = specific_send_sig_info(sig, info, t);
74046 spin_unlock_irqrestore(&t->sighand->siglock, flags);
74047
74048 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
74049 + normal operation */
74050 + if (is_unhandled) {
74051 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
74052 + gr_handle_crash(t, sig);
74053 + }
74054 +
74055 return ret;
74056 }
74057
74058 @@ -1081,8 +1101,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
74059 {
74060 int ret = check_kill_permission(sig, info, p);
74061
74062 - if (!ret && sig)
74063 + if (!ret && sig) {
74064 ret = do_send_sig_info(sig, info, p, true);
74065 + if (!ret)
74066 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
74067 + }
74068
74069 return ret;
74070 }
74071 @@ -1644,6 +1667,8 @@ void ptrace_notify(int exit_code)
74072 {
74073 siginfo_t info;
74074
74075 + pax_track_stack();
74076 +
74077 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
74078
74079 memset(&info, 0, sizeof info);
74080 @@ -2275,7 +2300,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
74081 int error = -ESRCH;
74082
74083 rcu_read_lock();
74084 - p = find_task_by_vpid(pid);
74085 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74086 + /* allow glibc communication via tgkill to other threads in our
74087 + thread group */
74088 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
74089 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
74090 + p = find_task_by_vpid_unrestricted(pid);
74091 + else
74092 +#endif
74093 + p = find_task_by_vpid(pid);
74094 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
74095 error = check_kill_permission(sig, info, p);
74096 /*
74097 diff --git a/kernel/smp.c b/kernel/smp.c
74098 index aa9cff3..631a0de 100644
74099 --- a/kernel/smp.c
74100 +++ b/kernel/smp.c
74101 @@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void *), void *info, int wait)
74102 }
74103 EXPORT_SYMBOL(smp_call_function);
74104
74105 -void ipi_call_lock(void)
74106 +void ipi_call_lock(void) __acquires(call_function.lock)
74107 {
74108 spin_lock(&call_function.lock);
74109 }
74110
74111 -void ipi_call_unlock(void)
74112 +void ipi_call_unlock(void) __releases(call_function.lock)
74113 {
74114 spin_unlock(&call_function.lock);
74115 }
74116
74117 -void ipi_call_lock_irq(void)
74118 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
74119 {
74120 spin_lock_irq(&call_function.lock);
74121 }
74122
74123 -void ipi_call_unlock_irq(void)
74124 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
74125 {
74126 spin_unlock_irq(&call_function.lock);
74127 }
74128 diff --git a/kernel/softirq.c b/kernel/softirq.c
74129 index 04a0252..580c512 100644
74130 --- a/kernel/softirq.c
74131 +++ b/kernel/softirq.c
74132 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
74133
74134 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
74135
74136 -char *softirq_to_name[NR_SOFTIRQS] = {
74137 +const char * const softirq_to_name[NR_SOFTIRQS] = {
74138 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
74139 "TASKLET", "SCHED", "HRTIMER", "RCU"
74140 };
74141 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
74142
74143 asmlinkage void __do_softirq(void)
74144 {
74145 - struct softirq_action *h;
74146 + const struct softirq_action *h;
74147 __u32 pending;
74148 int max_restart = MAX_SOFTIRQ_RESTART;
74149 int cpu;
74150 @@ -233,7 +233,7 @@ restart:
74151 kstat_incr_softirqs_this_cpu(h - softirq_vec);
74152
74153 trace_softirq_entry(h, softirq_vec);
74154 - h->action(h);
74155 + h->action();
74156 trace_softirq_exit(h, softirq_vec);
74157 if (unlikely(prev_count != preempt_count())) {
74158 printk(KERN_ERR "huh, entered softirq %td %s %p"
74159 @@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
74160 local_irq_restore(flags);
74161 }
74162
74163 -void open_softirq(int nr, void (*action)(struct softirq_action *))
74164 +void open_softirq(int nr, void (*action)(void))
74165 {
74166 - softirq_vec[nr].action = action;
74167 + pax_open_kernel();
74168 + *(void **)&softirq_vec[nr].action = action;
74169 + pax_close_kernel();
74170 }
74171
74172 /*
74173 @@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
74174
74175 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
74176
74177 -static void tasklet_action(struct softirq_action *a)
74178 +static void tasklet_action(void)
74179 {
74180 struct tasklet_struct *list;
74181
74182 @@ -454,7 +456,7 @@ static void tasklet_action(struct softirq_action *a)
74183 }
74184 }
74185
74186 -static void tasklet_hi_action(struct softirq_action *a)
74187 +static void tasklet_hi_action(void)
74188 {
74189 struct tasklet_struct *list;
74190
74191 diff --git a/kernel/sys.c b/kernel/sys.c
74192 index e9512b1..3c265de 100644
74193 --- a/kernel/sys.c
74194 +++ b/kernel/sys.c
74195 @@ -133,6 +133,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
74196 error = -EACCES;
74197 goto out;
74198 }
74199 +
74200 + if (gr_handle_chroot_setpriority(p, niceval)) {
74201 + error = -EACCES;
74202 + goto out;
74203 + }
74204 +
74205 no_nice = security_task_setnice(p, niceval);
74206 if (no_nice) {
74207 error = no_nice;
74208 @@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
74209 !(user = find_user(who)))
74210 goto out_unlock; /* No processes for this user */
74211
74212 - do_each_thread(g, p)
74213 + do_each_thread(g, p) {
74214 if (__task_cred(p)->uid == who)
74215 error = set_one_prio(p, niceval, error);
74216 - while_each_thread(g, p);
74217 + } while_each_thread(g, p);
74218 if (who != cred->uid)
74219 free_uid(user); /* For find_user() */
74220 break;
74221 @@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
74222 !(user = find_user(who)))
74223 goto out_unlock; /* No processes for this user */
74224
74225 - do_each_thread(g, p)
74226 + do_each_thread(g, p) {
74227 if (__task_cred(p)->uid == who) {
74228 niceval = 20 - task_nice(p);
74229 if (niceval > retval)
74230 retval = niceval;
74231 }
74232 - while_each_thread(g, p);
74233 + } while_each_thread(g, p);
74234 if (who != cred->uid)
74235 free_uid(user); /* for find_user() */
74236 break;
74237 @@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
74238 goto error;
74239 }
74240
74241 + if (gr_check_group_change(new->gid, new->egid, -1))
74242 + goto error;
74243 +
74244 if (rgid != (gid_t) -1 ||
74245 (egid != (gid_t) -1 && egid != old->gid))
74246 new->sgid = new->egid;
74247 @@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
74248 goto error;
74249
74250 retval = -EPERM;
74251 +
74252 + if (gr_check_group_change(gid, gid, gid))
74253 + goto error;
74254 +
74255 if (capable(CAP_SETGID))
74256 new->gid = new->egid = new->sgid = new->fsgid = gid;
74257 else if (gid == old->gid || gid == old->sgid)
74258 @@ -567,12 +580,19 @@ static int set_user(struct cred *new)
74259 if (!new_user)
74260 return -EAGAIN;
74261
74262 + /*
74263 + * We don't fail in case of NPROC limit excess here because too many
74264 + * poorly written programs don't check set*uid() return code, assuming
74265 + * it never fails if called by root. We may still enforce NPROC limit
74266 + * for programs doing set*uid()+execve() by harmlessly deferring the
74267 + * failure to the execve() stage.
74268 + */
74269 if (atomic_read(&new_user->processes) >=
74270 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
74271 - new_user != INIT_USER) {
74272 - free_uid(new_user);
74273 - return -EAGAIN;
74274 - }
74275 + new_user != INIT_USER)
74276 + current->flags |= PF_NPROC_EXCEEDED;
74277 + else
74278 + current->flags &= ~PF_NPROC_EXCEEDED;
74279
74280 free_uid(new->user);
74281 new->user = new_user;
74282 @@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
74283 goto error;
74284 }
74285
74286 + if (gr_check_user_change(new->uid, new->euid, -1))
74287 + goto error;
74288 +
74289 if (new->uid != old->uid) {
74290 retval = set_user(new);
74291 if (retval < 0)
74292 @@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
74293 goto error;
74294
74295 retval = -EPERM;
74296 +
74297 + if (gr_check_crash_uid(uid))
74298 + goto error;
74299 + if (gr_check_user_change(uid, uid, uid))
74300 + goto error;
74301 +
74302 if (capable(CAP_SETUID)) {
74303 new->suid = new->uid = uid;
74304 if (uid != old->uid) {
74305 @@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
74306 goto error;
74307 }
74308
74309 + if (gr_check_user_change(ruid, euid, -1))
74310 + goto error;
74311 +
74312 if (ruid != (uid_t) -1) {
74313 new->uid = ruid;
74314 if (ruid != old->uid) {
74315 @@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
74316 goto error;
74317 }
74318
74319 + if (gr_check_group_change(rgid, egid, -1))
74320 + goto error;
74321 +
74322 if (rgid != (gid_t) -1)
74323 new->gid = rgid;
74324 if (egid != (gid_t) -1)
74325 @@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
74326 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
74327 goto error;
74328
74329 + if (gr_check_user_change(-1, -1, uid))
74330 + goto error;
74331 +
74332 if (uid == old->uid || uid == old->euid ||
74333 uid == old->suid || uid == old->fsuid ||
74334 capable(CAP_SETUID)) {
74335 @@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
74336 if (gid == old->gid || gid == old->egid ||
74337 gid == old->sgid || gid == old->fsgid ||
74338 capable(CAP_SETGID)) {
74339 + if (gr_check_group_change(-1, -1, gid))
74340 + goto error;
74341 +
74342 if (gid != old_fsgid) {
74343 new->fsgid = gid;
74344 goto change_okay;
74345 @@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
74346 error = get_dumpable(me->mm);
74347 break;
74348 case PR_SET_DUMPABLE:
74349 - if (arg2 < 0 || arg2 > 1) {
74350 + if (arg2 > 1) {
74351 error = -EINVAL;
74352 break;
74353 }
74354 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
74355 index b8bd058..ab6a76be 100644
74356 --- a/kernel/sysctl.c
74357 +++ b/kernel/sysctl.c
74358 @@ -63,6 +63,13 @@
74359 static int deprecated_sysctl_warning(struct __sysctl_args *args);
74360
74361 #if defined(CONFIG_SYSCTL)
74362 +#include <linux/grsecurity.h>
74363 +#include <linux/grinternal.h>
74364 +
74365 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
74366 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
74367 + const int op);
74368 +extern int gr_handle_chroot_sysctl(const int op);
74369
74370 /* External variables not in a header file. */
74371 extern int C_A_D;
74372 @@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
74373 static int proc_taint(struct ctl_table *table, int write,
74374 void __user *buffer, size_t *lenp, loff_t *ppos);
74375 #endif
74376 +extern ctl_table grsecurity_table[];
74377
74378 static struct ctl_table root_table[];
74379 static struct ctl_table_root sysctl_table_root;
74380 @@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
74381 int sysctl_legacy_va_layout;
74382 #endif
74383
74384 +#ifdef CONFIG_PAX_SOFTMODE
74385 +static ctl_table pax_table[] = {
74386 + {
74387 + .ctl_name = CTL_UNNUMBERED,
74388 + .procname = "softmode",
74389 + .data = &pax_softmode,
74390 + .maxlen = sizeof(unsigned int),
74391 + .mode = 0600,
74392 + .proc_handler = &proc_dointvec,
74393 + },
74394 +
74395 + { .ctl_name = 0 }
74396 +};
74397 +#endif
74398 +
74399 extern int prove_locking;
74400 extern int lock_stat;
74401
74402 @@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
74403 #endif
74404
74405 static struct ctl_table kern_table[] = {
74406 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
74407 + {
74408 + .ctl_name = CTL_UNNUMBERED,
74409 + .procname = "grsecurity",
74410 + .mode = 0500,
74411 + .child = grsecurity_table,
74412 + },
74413 +#endif
74414 +
74415 +#ifdef CONFIG_PAX_SOFTMODE
74416 + {
74417 + .ctl_name = CTL_UNNUMBERED,
74418 + .procname = "pax",
74419 + .mode = 0500,
74420 + .child = pax_table,
74421 + },
74422 +#endif
74423 +
74424 {
74425 .ctl_name = CTL_UNNUMBERED,
74426 .procname = "sched_child_runs_first",
74427 @@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
74428 .data = &modprobe_path,
74429 .maxlen = KMOD_PATH_LEN,
74430 .mode = 0644,
74431 - .proc_handler = &proc_dostring,
74432 - .strategy = &sysctl_string,
74433 + .proc_handler = &proc_dostring_modpriv,
74434 + .strategy = &sysctl_string_modpriv,
74435 },
74436 {
74437 .ctl_name = CTL_UNNUMBERED,
74438 @@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
74439 .mode = 0644,
74440 .proc_handler = &proc_dointvec
74441 },
74442 + {
74443 + .procname = "heap_stack_gap",
74444 + .data = &sysctl_heap_stack_gap,
74445 + .maxlen = sizeof(sysctl_heap_stack_gap),
74446 + .mode = 0644,
74447 + .proc_handler = proc_doulongvec_minmax,
74448 + },
74449 #else
74450 {
74451 .ctl_name = CTL_UNNUMBERED,
74452 @@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
74453 return 0;
74454 }
74455
74456 +static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
74457 +
74458 static int parse_table(int __user *name, int nlen,
74459 void __user *oldval, size_t __user *oldlenp,
74460 void __user *newval, size_t newlen,
74461 @@ -1821,7 +1871,7 @@ repeat:
74462 if (n == table->ctl_name) {
74463 int error;
74464 if (table->child) {
74465 - if (sysctl_perm(root, table, MAY_EXEC))
74466 + if (sysctl_perm_nochk(root, table, MAY_EXEC))
74467 return -EPERM;
74468 name++;
74469 nlen--;
74470 @@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
74471 int error;
74472 int mode;
74473
74474 + if (table->parent != NULL && table->parent->procname != NULL &&
74475 + table->procname != NULL &&
74476 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
74477 + return -EACCES;
74478 + if (gr_handle_chroot_sysctl(op))
74479 + return -EACCES;
74480 + error = gr_handle_sysctl(table, op);
74481 + if (error)
74482 + return error;
74483 +
74484 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74485 + if (error)
74486 + return error;
74487 +
74488 + if (root->permissions)
74489 + mode = root->permissions(root, current->nsproxy, table);
74490 + else
74491 + mode = table->mode;
74492 +
74493 + return test_perm(mode, op);
74494 +}
74495 +
74496 +int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
74497 +{
74498 + int error;
74499 + int mode;
74500 +
74501 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74502 if (error)
74503 return error;
74504 @@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *table, int write,
74505 buffer, lenp, ppos);
74506 }
74507
74508 +int proc_dostring_modpriv(struct ctl_table *table, int write,
74509 + void __user *buffer, size_t *lenp, loff_t *ppos)
74510 +{
74511 + if (write && !capable(CAP_SYS_MODULE))
74512 + return -EPERM;
74513 +
74514 + return _proc_do_string(table->data, table->maxlen, write,
74515 + buffer, lenp, ppos);
74516 +}
74517 +
74518
74519 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
74520 int *valp,
74521 @@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
74522 vleft = table->maxlen / sizeof(unsigned long);
74523 left = *lenp;
74524
74525 - for (; left && vleft--; i++, min++, max++, first=0) {
74526 + for (; left && vleft--; i++, first=0) {
74527 if (write) {
74528 while (left) {
74529 char c;
74530 @@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *table, int write,
74531 return -ENOSYS;
74532 }
74533
74534 +int proc_dostring_modpriv(struct ctl_table *table, int write,
74535 + void __user *buffer, size_t *lenp, loff_t *ppos)
74536 +{
74537 + return -ENOSYS;
74538 +}
74539 +
74540 int proc_dointvec(struct ctl_table *table, int write,
74541 void __user *buffer, size_t *lenp, loff_t *ppos)
74542 {
74543 @@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *table,
74544 return 1;
74545 }
74546
74547 +int sysctl_string_modpriv(struct ctl_table *table,
74548 + void __user *oldval, size_t __user *oldlenp,
74549 + void __user *newval, size_t newlen)
74550 +{
74551 + if (newval && newlen && !capable(CAP_SYS_MODULE))
74552 + return -EPERM;
74553 +
74554 + return sysctl_string(table, oldval, oldlenp, newval, newlen);
74555 +}
74556 +
74557 /*
74558 * This function makes sure that all of the integers in the vector
74559 * are between the minimum and maximum values given in the arrays
74560 @@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *table,
74561 return -ENOSYS;
74562 }
74563
74564 +int sysctl_string_modpriv(struct ctl_table *table,
74565 + void __user *oldval, size_t __user *oldlenp,
74566 + void __user *newval, size_t newlen)
74567 +{
74568 + return -ENOSYS;
74569 +}
74570 +
74571 int sysctl_intvec(struct ctl_table *table,
74572 void __user *oldval, size_t __user *oldlenp,
74573 void __user *newval, size_t newlen)
74574 @@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
74575 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
74576 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
74577 EXPORT_SYMBOL(proc_dostring);
74578 +EXPORT_SYMBOL(proc_dostring_modpriv);
74579 EXPORT_SYMBOL(proc_doulongvec_minmax);
74580 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
74581 EXPORT_SYMBOL(register_sysctl_table);
74582 @@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
74583 EXPORT_SYMBOL(sysctl_jiffies);
74584 EXPORT_SYMBOL(sysctl_ms_jiffies);
74585 EXPORT_SYMBOL(sysctl_string);
74586 +EXPORT_SYMBOL(sysctl_string_modpriv);
74587 EXPORT_SYMBOL(sysctl_data);
74588 EXPORT_SYMBOL(unregister_sysctl_table);
74589 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
74590 index 469193c..ea3ecb2 100644
74591 --- a/kernel/sysctl_check.c
74592 +++ b/kernel/sysctl_check.c
74593 @@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
74594 } else {
74595 if ((table->strategy == sysctl_data) ||
74596 (table->strategy == sysctl_string) ||
74597 + (table->strategy == sysctl_string_modpriv) ||
74598 (table->strategy == sysctl_intvec) ||
74599 (table->strategy == sysctl_jiffies) ||
74600 (table->strategy == sysctl_ms_jiffies) ||
74601 (table->proc_handler == proc_dostring) ||
74602 + (table->proc_handler == proc_dostring_modpriv) ||
74603 (table->proc_handler == proc_dointvec) ||
74604 (table->proc_handler == proc_dointvec_minmax) ||
74605 (table->proc_handler == proc_dointvec_jiffies) ||
74606 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
74607 index a4ef542..798bcd7 100644
74608 --- a/kernel/taskstats.c
74609 +++ b/kernel/taskstats.c
74610 @@ -26,9 +26,12 @@
74611 #include <linux/cgroup.h>
74612 #include <linux/fs.h>
74613 #include <linux/file.h>
74614 +#include <linux/grsecurity.h>
74615 #include <net/genetlink.h>
74616 #include <asm/atomic.h>
74617
74618 +extern int gr_is_taskstats_denied(int pid);
74619 +
74620 /*
74621 * Maximum length of a cpumask that can be specified in
74622 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
74623 @@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
74624 size_t size;
74625 cpumask_var_t mask;
74626
74627 + if (gr_is_taskstats_denied(current->pid))
74628 + return -EACCES;
74629 +
74630 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
74631 return -ENOMEM;
74632
74633 diff --git a/kernel/time.c b/kernel/time.c
74634 index 33df60e..ca768bd 100644
74635 --- a/kernel/time.c
74636 +++ b/kernel/time.c
74637 @@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
74638 return error;
74639
74640 if (tz) {
74641 + /* we log in do_settimeofday called below, so don't log twice
74642 + */
74643 + if (!tv)
74644 + gr_log_timechange();
74645 +
74646 /* SMP safe, global irq locking makes it work. */
74647 sys_tz = *tz;
74648 update_vsyscall_tz();
74649 @@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
74650 * Avoid unnecessary multiplications/divisions in the
74651 * two most common HZ cases:
74652 */
74653 -unsigned int inline jiffies_to_msecs(const unsigned long j)
74654 +inline unsigned int jiffies_to_msecs(const unsigned long j)
74655 {
74656 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
74657 return (MSEC_PER_SEC / HZ) * j;
74658 @@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
74659 }
74660 EXPORT_SYMBOL(jiffies_to_msecs);
74661
74662 -unsigned int inline jiffies_to_usecs(const unsigned long j)
74663 +inline unsigned int jiffies_to_usecs(const unsigned long j)
74664 {
74665 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
74666 return (USEC_PER_SEC / HZ) * j;
74667 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
74668 index 57b953f..06f149f 100644
74669 --- a/kernel/time/tick-broadcast.c
74670 +++ b/kernel/time/tick-broadcast.c
74671 @@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
74672 * then clear the broadcast bit.
74673 */
74674 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
74675 - int cpu = smp_processor_id();
74676 + cpu = smp_processor_id();
74677
74678 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
74679 tick_broadcast_clear_oneshot(cpu);
74680 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
74681 index 4a71cff..ffb5548 100644
74682 --- a/kernel/time/timekeeping.c
74683 +++ b/kernel/time/timekeeping.c
74684 @@ -14,6 +14,7 @@
74685 #include <linux/init.h>
74686 #include <linux/mm.h>
74687 #include <linux/sched.h>
74688 +#include <linux/grsecurity.h>
74689 #include <linux/sysdev.h>
74690 #include <linux/clocksource.h>
74691 #include <linux/jiffies.h>
74692 @@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
74693 */
74694 struct timespec ts = xtime;
74695 timespec_add_ns(&ts, nsec);
74696 - ACCESS_ONCE(xtime_cache) = ts;
74697 + ACCESS_ONCE_RW(xtime_cache) = ts;
74698 }
74699
74700 /* must hold xtime_lock */
74701 @@ -337,6 +338,8 @@ int do_settimeofday(struct timespec *tv)
74702 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
74703 return -EINVAL;
74704
74705 + gr_log_timechange();
74706 +
74707 write_seqlock_irqsave(&xtime_lock, flags);
74708
74709 timekeeping_forward_now();
74710 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74711 index 54c0dda..e9095d9 100644
74712 --- a/kernel/time/timer_list.c
74713 +++ b/kernel/time/timer_list.c
74714 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74715
74716 static void print_name_offset(struct seq_file *m, void *sym)
74717 {
74718 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74719 + SEQ_printf(m, "<%p>", NULL);
74720 +#else
74721 char symname[KSYM_NAME_LEN];
74722
74723 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74724 SEQ_printf(m, "<%p>", sym);
74725 else
74726 SEQ_printf(m, "%s", symname);
74727 +#endif
74728 }
74729
74730 static void
74731 @@ -112,7 +116,11 @@ next_one:
74732 static void
74733 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
74734 {
74735 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74736 + SEQ_printf(m, " .base: %p\n", NULL);
74737 +#else
74738 SEQ_printf(m, " .base: %p\n", base);
74739 +#endif
74740 SEQ_printf(m, " .index: %d\n",
74741 base->index);
74742 SEQ_printf(m, " .resolution: %Lu nsecs\n",
74743 @@ -289,7 +297,11 @@ static int __init init_timer_list_procfs(void)
74744 {
74745 struct proc_dir_entry *pe;
74746
74747 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74748 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
74749 +#else
74750 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
74751 +#endif
74752 if (!pe)
74753 return -ENOMEM;
74754 return 0;
74755 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
74756 index ee5681f..634089b 100644
74757 --- a/kernel/time/timer_stats.c
74758 +++ b/kernel/time/timer_stats.c
74759 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74760 static unsigned long nr_entries;
74761 static struct entry entries[MAX_ENTRIES];
74762
74763 -static atomic_t overflow_count;
74764 +static atomic_unchecked_t overflow_count;
74765
74766 /*
74767 * The entries are in a hash-table, for fast lookup:
74768 @@ -140,7 +140,7 @@ static void reset_entries(void)
74769 nr_entries = 0;
74770 memset(entries, 0, sizeof(entries));
74771 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74772 - atomic_set(&overflow_count, 0);
74773 + atomic_set_unchecked(&overflow_count, 0);
74774 }
74775
74776 static struct entry *alloc_entry(void)
74777 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74778 if (likely(entry))
74779 entry->count++;
74780 else
74781 - atomic_inc(&overflow_count);
74782 + atomic_inc_unchecked(&overflow_count);
74783
74784 out_unlock:
74785 spin_unlock_irqrestore(lock, flags);
74786 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74787
74788 static void print_name_offset(struct seq_file *m, unsigned long addr)
74789 {
74790 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74791 + seq_printf(m, "<%p>", NULL);
74792 +#else
74793 char symname[KSYM_NAME_LEN];
74794
74795 if (lookup_symbol_name(addr, symname) < 0)
74796 seq_printf(m, "<%p>", (void *)addr);
74797 else
74798 seq_printf(m, "%s", symname);
74799 +#endif
74800 }
74801
74802 static int tstats_show(struct seq_file *m, void *v)
74803 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74804
74805 seq_puts(m, "Timer Stats Version: v0.2\n");
74806 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74807 - if (atomic_read(&overflow_count))
74808 + if (atomic_read_unchecked(&overflow_count))
74809 seq_printf(m, "Overflow: %d entries\n",
74810 - atomic_read(&overflow_count));
74811 + atomic_read_unchecked(&overflow_count));
74812
74813 for (i = 0; i < nr_entries; i++) {
74814 entry = entries + i;
74815 @@ -415,7 +419,11 @@ static int __init init_tstats_procfs(void)
74816 {
74817 struct proc_dir_entry *pe;
74818
74819 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74820 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74821 +#else
74822 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74823 +#endif
74824 if (!pe)
74825 return -ENOMEM;
74826 return 0;
74827 diff --git a/kernel/timer.c b/kernel/timer.c
74828 index cb3c1f1..8bf5526 100644
74829 --- a/kernel/timer.c
74830 +++ b/kernel/timer.c
74831 @@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
74832 /*
74833 * This function runs timers and the timer-tq in bottom half context.
74834 */
74835 -static void run_timer_softirq(struct softirq_action *h)
74836 +static void run_timer_softirq(void)
74837 {
74838 struct tvec_base *base = __get_cpu_var(tvec_bases);
74839
74840 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74841 index d9d6206..f19467e 100644
74842 --- a/kernel/trace/blktrace.c
74843 +++ b/kernel/trace/blktrace.c
74844 @@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74845 struct blk_trace *bt = filp->private_data;
74846 char buf[16];
74847
74848 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74849 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74850
74851 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74852 }
74853 @@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74854 return 1;
74855
74856 bt = buf->chan->private_data;
74857 - atomic_inc(&bt->dropped);
74858 + atomic_inc_unchecked(&bt->dropped);
74859 return 0;
74860 }
74861
74862 @@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74863
74864 bt->dir = dir;
74865 bt->dev = dev;
74866 - atomic_set(&bt->dropped, 0);
74867 + atomic_set_unchecked(&bt->dropped, 0);
74868
74869 ret = -EIO;
74870 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74871 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74872 index 4872937..c794d40 100644
74873 --- a/kernel/trace/ftrace.c
74874 +++ b/kernel/trace/ftrace.c
74875 @@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74876
74877 ip = rec->ip;
74878
74879 + ret = ftrace_arch_code_modify_prepare();
74880 + FTRACE_WARN_ON(ret);
74881 + if (ret)
74882 + return 0;
74883 +
74884 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74885 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74886 if (ret) {
74887 ftrace_bug(ret, ip);
74888 rec->flags |= FTRACE_FL_FAILED;
74889 - return 0;
74890 }
74891 - return 1;
74892 + return ret ? 0 : 1;
74893 }
74894
74895 /*
74896 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74897 index e749a05..19c6e94 100644
74898 --- a/kernel/trace/ring_buffer.c
74899 +++ b/kernel/trace/ring_buffer.c
74900 @@ -606,7 +606,7 @@ static struct list_head *rb_list_head(struct list_head *list)
74901 * the reader page). But if the next page is a header page,
74902 * its flags will be non zero.
74903 */
74904 -static int inline
74905 +static inline int
74906 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74907 struct buffer_page *page, struct list_head *list)
74908 {
74909 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74910 index a2a2d1f..7f32b09 100644
74911 --- a/kernel/trace/trace.c
74912 +++ b/kernel/trace/trace.c
74913 @@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
74914 size_t rem;
74915 unsigned int i;
74916
74917 + pax_track_stack();
74918 +
74919 /* copy the tracer to avoid using a global lock all around */
74920 mutex_lock(&trace_types_lock);
74921 if (unlikely(old_tracer != current_trace && current_trace)) {
74922 @@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
74923 int entries, size, i;
74924 size_t ret;
74925
74926 + pax_track_stack();
74927 +
74928 if (*ppos & (PAGE_SIZE - 1)) {
74929 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
74930 return -EINVAL;
74931 @@ -3816,10 +3820,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74932 };
74933 #endif
74934
74935 -static struct dentry *d_tracer;
74936 -
74937 struct dentry *tracing_init_dentry(void)
74938 {
74939 + static struct dentry *d_tracer;
74940 static int once;
74941
74942 if (d_tracer)
74943 @@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
74944 return d_tracer;
74945 }
74946
74947 -static struct dentry *d_percpu;
74948 -
74949 struct dentry *tracing_dentry_percpu(void)
74950 {
74951 + static struct dentry *d_percpu;
74952 static int once;
74953 struct dentry *d_tracer;
74954
74955 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74956 index d128f65..f37b4af 100644
74957 --- a/kernel/trace/trace_events.c
74958 +++ b/kernel/trace/trace_events.c
74959 @@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list);
74960 * Modules must own their file_operations to keep up with
74961 * reference counting.
74962 */
74963 +
74964 struct ftrace_module_file_ops {
74965 struct list_head list;
74966 struct module *mod;
74967 - struct file_operations id;
74968 - struct file_operations enable;
74969 - struct file_operations format;
74970 - struct file_operations filter;
74971 };
74972
74973 static void remove_subsystem_dir(const char *name)
74974 @@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod)
74975
74976 file_ops->mod = mod;
74977
74978 - file_ops->id = ftrace_event_id_fops;
74979 - file_ops->id.owner = mod;
74980 -
74981 - file_ops->enable = ftrace_enable_fops;
74982 - file_ops->enable.owner = mod;
74983 -
74984 - file_ops->filter = ftrace_event_filter_fops;
74985 - file_ops->filter.owner = mod;
74986 -
74987 - file_ops->format = ftrace_event_format_fops;
74988 - file_ops->format.owner = mod;
74989 + pax_open_kernel();
74990 + *(void **)&mod->trace_id.owner = mod;
74991 + *(void **)&mod->trace_enable.owner = mod;
74992 + *(void **)&mod->trace_filter.owner = mod;
74993 + *(void **)&mod->trace_format.owner = mod;
74994 + pax_close_kernel();
74995
74996 list_add(&file_ops->list, &ftrace_module_file_list);
74997
74998 @@ -1063,8 +1055,8 @@ static void trace_module_add_events(struct module *mod)
74999 call->mod = mod;
75000 list_add(&call->list, &ftrace_events);
75001 event_create_dir(call, d_events,
75002 - &file_ops->id, &file_ops->enable,
75003 - &file_ops->filter, &file_ops->format);
75004 + &mod->trace_id, &mod->trace_enable,
75005 + &mod->trace_filter, &mod->trace_format);
75006 }
75007 }
75008
75009 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
75010 index 0acd834..b800b56 100644
75011 --- a/kernel/trace/trace_mmiotrace.c
75012 +++ b/kernel/trace/trace_mmiotrace.c
75013 @@ -23,7 +23,7 @@ struct header_iter {
75014 static struct trace_array *mmio_trace_array;
75015 static bool overrun_detected;
75016 static unsigned long prev_overruns;
75017 -static atomic_t dropped_count;
75018 +static atomic_unchecked_t dropped_count;
75019
75020 static void mmio_reset_data(struct trace_array *tr)
75021 {
75022 @@ -126,7 +126,7 @@ static void mmio_close(struct trace_iterator *iter)
75023
75024 static unsigned long count_overruns(struct trace_iterator *iter)
75025 {
75026 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
75027 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
75028 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
75029
75030 if (over > prev_overruns)
75031 @@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
75032 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
75033 sizeof(*entry), 0, pc);
75034 if (!event) {
75035 - atomic_inc(&dropped_count);
75036 + atomic_inc_unchecked(&dropped_count);
75037 return;
75038 }
75039 entry = ring_buffer_event_data(event);
75040 @@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
75041 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
75042 sizeof(*entry), 0, pc);
75043 if (!event) {
75044 - atomic_inc(&dropped_count);
75045 + atomic_inc_unchecked(&dropped_count);
75046 return;
75047 }
75048 entry = ring_buffer_event_data(event);
75049 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
75050 index b6c12c6..41fdc53 100644
75051 --- a/kernel/trace/trace_output.c
75052 +++ b/kernel/trace/trace_output.c
75053 @@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
75054 return 0;
75055 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
75056 if (!IS_ERR(p)) {
75057 - p = mangle_path(s->buffer + s->len, p, "\n");
75058 + p = mangle_path(s->buffer + s->len, p, "\n\\");
75059 if (p) {
75060 s->len = p - s->buffer;
75061 return 1;
75062 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
75063 index 8504ac7..ecf0adb 100644
75064 --- a/kernel/trace/trace_stack.c
75065 +++ b/kernel/trace/trace_stack.c
75066 @@ -50,7 +50,7 @@ static inline void check_stack(void)
75067 return;
75068
75069 /* we do not handle interrupt stacks yet */
75070 - if (!object_is_on_stack(&this_size))
75071 + if (!object_starts_on_stack(&this_size))
75072 return;
75073
75074 local_irq_save(flags);
75075 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
75076 index 40cafb0..d5ead43 100644
75077 --- a/kernel/trace/trace_workqueue.c
75078 +++ b/kernel/trace/trace_workqueue.c
75079 @@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
75080 int cpu;
75081 pid_t pid;
75082 /* Can be inserted from interrupt or user context, need to be atomic */
75083 - atomic_t inserted;
75084 + atomic_unchecked_t inserted;
75085 /*
75086 * Don't need to be atomic, works are serialized in a single workqueue thread
75087 * on a single CPU.
75088 @@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_struct *wq_thread,
75089 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
75090 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
75091 if (node->pid == wq_thread->pid) {
75092 - atomic_inc(&node->inserted);
75093 + atomic_inc_unchecked(&node->inserted);
75094 goto found;
75095 }
75096 }
75097 @@ -205,7 +205,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
75098 tsk = get_pid_task(pid, PIDTYPE_PID);
75099 if (tsk) {
75100 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
75101 - atomic_read(&cws->inserted), cws->executed,
75102 + atomic_read_unchecked(&cws->inserted), cws->executed,
75103 tsk->comm);
75104 put_task_struct(tsk);
75105 }
75106 diff --git a/kernel/user.c b/kernel/user.c
75107 index 1b91701..8795237 100644
75108 --- a/kernel/user.c
75109 +++ b/kernel/user.c
75110 @@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
75111 spin_lock_irq(&uidhash_lock);
75112 up = uid_hash_find(uid, hashent);
75113 if (up) {
75114 + put_user_ns(ns);
75115 key_put(new->uid_keyring);
75116 key_put(new->session_keyring);
75117 kmem_cache_free(uid_cachep, new);
75118 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
75119 index 234ceb1..ad74049 100644
75120 --- a/lib/Kconfig.debug
75121 +++ b/lib/Kconfig.debug
75122 @@ -905,7 +905,7 @@ config LATENCYTOP
75123 select STACKTRACE
75124 select SCHEDSTATS
75125 select SCHED_DEBUG
75126 - depends on HAVE_LATENCYTOP_SUPPORT
75127 + depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
75128 help
75129 Enable this option if you want to use the LatencyTOP tool
75130 to find out which userspace is blocking on what kernel operations.
75131 diff --git a/lib/bitmap.c b/lib/bitmap.c
75132 index 7025658..8d14cab 100644
75133 --- a/lib/bitmap.c
75134 +++ b/lib/bitmap.c
75135 @@ -341,7 +341,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
75136 {
75137 int c, old_c, totaldigits, ndigits, nchunks, nbits;
75138 u32 chunk;
75139 - const char __user *ubuf = buf;
75140 + const char __user *ubuf = (const char __force_user *)buf;
75141
75142 bitmap_zero(maskp, nmaskbits);
75143
75144 @@ -426,7 +426,7 @@ int bitmap_parse_user(const char __user *ubuf,
75145 {
75146 if (!access_ok(VERIFY_READ, ubuf, ulen))
75147 return -EFAULT;
75148 - return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
75149 + return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
75150 }
75151 EXPORT_SYMBOL(bitmap_parse_user);
75152
75153 diff --git a/lib/bug.c b/lib/bug.c
75154 index 300e41a..2779eb0 100644
75155 --- a/lib/bug.c
75156 +++ b/lib/bug.c
75157 @@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
75158 return BUG_TRAP_TYPE_NONE;
75159
75160 bug = find_bug(bugaddr);
75161 + if (!bug)
75162 + return BUG_TRAP_TYPE_NONE;
75163
75164 printk(KERN_EMERG "------------[ cut here ]------------\n");
75165
75166 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
75167 index 2b413db..e21d207 100644
75168 --- a/lib/debugobjects.c
75169 +++ b/lib/debugobjects.c
75170 @@ -277,7 +277,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
75171 if (limit > 4)
75172 return;
75173
75174 - is_on_stack = object_is_on_stack(addr);
75175 + is_on_stack = object_starts_on_stack(addr);
75176 if (is_on_stack == onstack)
75177 return;
75178
75179 diff --git a/lib/devres.c b/lib/devres.c
75180 index 72c8909..7543868 100644
75181 --- a/lib/devres.c
75182 +++ b/lib/devres.c
75183 @@ -80,7 +80,7 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
75184 {
75185 iounmap(addr);
75186 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
75187 - (void *)addr));
75188 + (void __force *)addr));
75189 }
75190 EXPORT_SYMBOL(devm_iounmap);
75191
75192 @@ -140,7 +140,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
75193 {
75194 ioport_unmap(addr);
75195 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
75196 - devm_ioport_map_match, (void *)addr));
75197 + devm_ioport_map_match, (void __force *)addr));
75198 }
75199 EXPORT_SYMBOL(devm_ioport_unmap);
75200
75201 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
75202 index 084e879..0674448 100644
75203 --- a/lib/dma-debug.c
75204 +++ b/lib/dma-debug.c
75205 @@ -861,7 +861,7 @@ out:
75206
75207 static void check_for_stack(struct device *dev, void *addr)
75208 {
75209 - if (object_is_on_stack(addr))
75210 + if (object_starts_on_stack(addr))
75211 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
75212 "stack [addr=%p]\n", addr);
75213 }
75214 diff --git a/lib/idr.c b/lib/idr.c
75215 index eda7ba3..915dfae 100644
75216 --- a/lib/idr.c
75217 +++ b/lib/idr.c
75218 @@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
75219 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
75220
75221 /* if already at the top layer, we need to grow */
75222 - if (id >= 1 << (idp->layers * IDR_BITS)) {
75223 + if (id >= (1 << (idp->layers * IDR_BITS))) {
75224 *starting_id = id;
75225 return IDR_NEED_TO_GROW;
75226 }
75227 diff --git a/lib/inflate.c b/lib/inflate.c
75228 index d102559..4215f31 100644
75229 --- a/lib/inflate.c
75230 +++ b/lib/inflate.c
75231 @@ -266,7 +266,7 @@ static void free(void *where)
75232 malloc_ptr = free_mem_ptr;
75233 }
75234 #else
75235 -#define malloc(a) kmalloc(a, GFP_KERNEL)
75236 +#define malloc(a) kmalloc((a), GFP_KERNEL)
75237 #define free(a) kfree(a)
75238 #endif
75239
75240 diff --git a/lib/kobject.c b/lib/kobject.c
75241 index b512b74..8115eb1 100644
75242 --- a/lib/kobject.c
75243 +++ b/lib/kobject.c
75244 @@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
75245 return ret;
75246 }
75247
75248 -struct sysfs_ops kobj_sysfs_ops = {
75249 +const struct sysfs_ops kobj_sysfs_ops = {
75250 .show = kobj_attr_show,
75251 .store = kobj_attr_store,
75252 };
75253 @@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
75254 * If the kset was not able to be created, NULL will be returned.
75255 */
75256 static struct kset *kset_create(const char *name,
75257 - struct kset_uevent_ops *uevent_ops,
75258 + const struct kset_uevent_ops *uevent_ops,
75259 struct kobject *parent_kobj)
75260 {
75261 struct kset *kset;
75262 @@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
75263 * If the kset was not able to be created, NULL will be returned.
75264 */
75265 struct kset *kset_create_and_add(const char *name,
75266 - struct kset_uevent_ops *uevent_ops,
75267 + const struct kset_uevent_ops *uevent_ops,
75268 struct kobject *parent_kobj)
75269 {
75270 struct kset *kset;
75271 diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
75272 index 507b821..0bf8ed0 100644
75273 --- a/lib/kobject_uevent.c
75274 +++ b/lib/kobject_uevent.c
75275 @@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
75276 const char *subsystem;
75277 struct kobject *top_kobj;
75278 struct kset *kset;
75279 - struct kset_uevent_ops *uevent_ops;
75280 + const struct kset_uevent_ops *uevent_ops;
75281 u64 seq;
75282 int i = 0;
75283 int retval = 0;
75284 diff --git a/lib/kref.c b/lib/kref.c
75285 index 9ecd6e8..12c94c1 100644
75286 --- a/lib/kref.c
75287 +++ b/lib/kref.c
75288 @@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
75289 */
75290 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
75291 {
75292 - WARN_ON(release == NULL);
75293 + BUG_ON(release == NULL);
75294 WARN_ON(release == (void (*)(struct kref *))kfree);
75295
75296 if (atomic_dec_and_test(&kref->refcount)) {
75297 diff --git a/lib/parser.c b/lib/parser.c
75298 index b00d020..1b34325 100644
75299 --- a/lib/parser.c
75300 +++ b/lib/parser.c
75301 @@ -126,7 +126,7 @@ static int match_number(substring_t *s, int *result, int base)
75302 char *buf;
75303 int ret;
75304
75305 - buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
75306 + buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
75307 if (!buf)
75308 return -ENOMEM;
75309 memcpy(buf, s->from, s->to - s->from);
75310 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75311 index 92cdd99..a8149d7 100644
75312 --- a/lib/radix-tree.c
75313 +++ b/lib/radix-tree.c
75314 @@ -81,7 +81,7 @@ struct radix_tree_preload {
75315 int nr;
75316 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
75317 };
75318 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75319 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75320
75321 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
75322 {
75323 diff --git a/lib/random32.c b/lib/random32.c
75324 index 217d5c4..45aba8a 100644
75325 --- a/lib/random32.c
75326 +++ b/lib/random32.c
75327 @@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *state)
75328 */
75329 static inline u32 __seed(u32 x, u32 m)
75330 {
75331 - return (x < m) ? x + m : x;
75332 + return (x <= m) ? x + m + 1 : x;
75333 }
75334
75335 /**
75336 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75337 index 33bed5e..1477e46 100644
75338 --- a/lib/vsprintf.c
75339 +++ b/lib/vsprintf.c
75340 @@ -16,6 +16,9 @@
75341 * - scnprintf and vscnprintf
75342 */
75343
75344 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75345 +#define __INCLUDED_BY_HIDESYM 1
75346 +#endif
75347 #include <stdarg.h>
75348 #include <linux/module.h>
75349 #include <linux/types.h>
75350 @@ -546,12 +549,12 @@ static char *number(char *buf, char *end, unsigned long long num,
75351 return buf;
75352 }
75353
75354 -static char *string(char *buf, char *end, char *s, struct printf_spec spec)
75355 +static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
75356 {
75357 int len, i;
75358
75359 if ((unsigned long)s < PAGE_SIZE)
75360 - s = "<NULL>";
75361 + s = "(null)";
75362
75363 len = strnlen(s, spec.precision);
75364
75365 @@ -581,7 +584,7 @@ static char *symbol_string(char *buf, char *end, void *ptr,
75366 unsigned long value = (unsigned long) ptr;
75367 #ifdef CONFIG_KALLSYMS
75368 char sym[KSYM_SYMBOL_LEN];
75369 - if (ext != 'f' && ext != 's')
75370 + if (ext != 'f' && ext != 's' && ext != 'a')
75371 sprint_symbol(sym, value);
75372 else
75373 kallsyms_lookup(value, NULL, NULL, NULL, sym);
75374 @@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
75375 * - 'f' For simple symbolic function names without offset
75376 * - 'S' For symbolic direct pointers with offset
75377 * - 's' For symbolic direct pointers without offset
75378 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75379 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75380 * - 'R' For a struct resource pointer, it prints the range of
75381 * addresses (not the name nor the flags)
75382 * - 'M' For a 6-byte MAC address, it prints the address in the
75383 @@ -822,7 +827,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75384 struct printf_spec spec)
75385 {
75386 if (!ptr)
75387 - return string(buf, end, "(null)", spec);
75388 + return string(buf, end, "(nil)", spec);
75389
75390 switch (*fmt) {
75391 case 'F':
75392 @@ -831,6 +836,14 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75393 case 's':
75394 /* Fallthrough */
75395 case 'S':
75396 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75397 + break;
75398 +#else
75399 + return symbol_string(buf, end, ptr, spec, *fmt);
75400 +#endif
75401 + case 'a':
75402 + /* Fallthrough */
75403 + case 'A':
75404 return symbol_string(buf, end, ptr, spec, *fmt);
75405 case 'R':
75406 return resource_string(buf, end, ptr, spec);
75407 @@ -1445,7 +1458,7 @@ do { \
75408 size_t len;
75409 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
75410 || (unsigned long)save_str < PAGE_SIZE)
75411 - save_str = "<NULL>";
75412 + save_str = "(null)";
75413 len = strlen(save_str);
75414 if (str + len + 1 < end)
75415 memcpy(str, save_str, len + 1);
75416 @@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75417 typeof(type) value; \
75418 if (sizeof(type) == 8) { \
75419 args = PTR_ALIGN(args, sizeof(u32)); \
75420 - *(u32 *)&value = *(u32 *)args; \
75421 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75422 + *(u32 *)&value = *(const u32 *)args; \
75423 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75424 } else { \
75425 args = PTR_ALIGN(args, sizeof(type)); \
75426 - value = *(typeof(type) *)args; \
75427 + value = *(const typeof(type) *)args; \
75428 } \
75429 args += sizeof(type); \
75430 value; \
75431 @@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75432 const char *str_arg = args;
75433 size_t len = strlen(str_arg);
75434 args += len + 1;
75435 - str = string(str, end, (char *)str_arg, spec);
75436 + str = string(str, end, str_arg, spec);
75437 break;
75438 }
75439
75440 diff --git a/localversion-grsec b/localversion-grsec
75441 new file mode 100644
75442 index 0000000..7cd6065
75443 --- /dev/null
75444 +++ b/localversion-grsec
75445 @@ -0,0 +1 @@
75446 +-grsec
75447 diff --git a/mm/Kconfig b/mm/Kconfig
75448 index 2c19c0b..f3c3f83 100644
75449 --- a/mm/Kconfig
75450 +++ b/mm/Kconfig
75451 @@ -228,7 +228,7 @@ config KSM
75452 config DEFAULT_MMAP_MIN_ADDR
75453 int "Low address space to protect from user allocation"
75454 depends on MMU
75455 - default 4096
75456 + default 65536
75457 help
75458 This is the portion of low virtual memory which should be protected
75459 from userspace allocation. Keeping a user from writing to low pages
75460 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
75461 index 67a33a5..094dcf1 100644
75462 --- a/mm/backing-dev.c
75463 +++ b/mm/backing-dev.c
75464 @@ -272,7 +272,7 @@ static void bdi_task_init(struct backing_dev_info *bdi,
75465 list_add_tail_rcu(&wb->list, &bdi->wb_list);
75466 spin_unlock(&bdi->wb_lock);
75467
75468 - tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
75469 + tsk->flags |= PF_SWAPWRITE;
75470 set_freezable();
75471
75472 /*
75473 @@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rcu_head *head)
75474 * Add the default flusher task that gets created for any bdi
75475 * that has dirty data pending writeout
75476 */
75477 -void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75478 +static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75479 {
75480 if (!bdi_cap_writeback_dirty(bdi))
75481 return;
75482 diff --git a/mm/filemap.c b/mm/filemap.c
75483 index 9e0826e..4ee8f13 100644
75484 --- a/mm/filemap.c
75485 +++ b/mm/filemap.c
75486 @@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75487 struct address_space *mapping = file->f_mapping;
75488
75489 if (!mapping->a_ops->readpage)
75490 - return -ENOEXEC;
75491 + return -ENODEV;
75492 file_accessed(file);
75493 vma->vm_ops = &generic_file_vm_ops;
75494 vma->vm_flags |= VM_CAN_NONLINEAR;
75495 @@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75496 *pos = i_size_read(inode);
75497
75498 if (limit != RLIM_INFINITY) {
75499 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75500 if (*pos >= limit) {
75501 send_sig(SIGXFSZ, current, 0);
75502 return -EFBIG;
75503 diff --git a/mm/fremap.c b/mm/fremap.c
75504 index b6ec85a..a24ac22 100644
75505 --- a/mm/fremap.c
75506 +++ b/mm/fremap.c
75507 @@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75508 retry:
75509 vma = find_vma(mm, start);
75510
75511 +#ifdef CONFIG_PAX_SEGMEXEC
75512 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75513 + goto out;
75514 +#endif
75515 +
75516 /*
75517 * Make sure the vma is shared, that it supports prefaulting,
75518 * and that the remapped range is valid and fully within
75519 @@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75520 /*
75521 * drop PG_Mlocked flag for over-mapped range
75522 */
75523 - unsigned int saved_flags = vma->vm_flags;
75524 + unsigned long saved_flags = vma->vm_flags;
75525 munlock_vma_pages_range(vma, start, start + size);
75526 vma->vm_flags = saved_flags;
75527 }
75528 diff --git a/mm/highmem.c b/mm/highmem.c
75529 index 9c1e627..5ca9447 100644
75530 --- a/mm/highmem.c
75531 +++ b/mm/highmem.c
75532 @@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
75533 * So no dangers, even with speculative execution.
75534 */
75535 page = pte_page(pkmap_page_table[i]);
75536 + pax_open_kernel();
75537 pte_clear(&init_mm, (unsigned long)page_address(page),
75538 &pkmap_page_table[i]);
75539 -
75540 + pax_close_kernel();
75541 set_page_address(page, NULL);
75542 need_flush = 1;
75543 }
75544 @@ -177,9 +178,11 @@ start:
75545 }
75546 }
75547 vaddr = PKMAP_ADDR(last_pkmap_nr);
75548 +
75549 + pax_open_kernel();
75550 set_pte_at(&init_mm, vaddr,
75551 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75552 -
75553 + pax_close_kernel();
75554 pkmap_count[last_pkmap_nr] = 1;
75555 set_page_address(page, (void *)vaddr);
75556
75557 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75558 index 5e1e508..9f0ebad 100644
75559 --- a/mm/hugetlb.c
75560 +++ b/mm/hugetlb.c
75561 @@ -1933,6 +1933,26 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75562 return 1;
75563 }
75564
75565 +#ifdef CONFIG_PAX_SEGMEXEC
75566 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75567 +{
75568 + struct mm_struct *mm = vma->vm_mm;
75569 + struct vm_area_struct *vma_m;
75570 + unsigned long address_m;
75571 + pte_t *ptep_m;
75572 +
75573 + vma_m = pax_find_mirror_vma(vma);
75574 + if (!vma_m)
75575 + return;
75576 +
75577 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75578 + address_m = address + SEGMEXEC_TASK_SIZE;
75579 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75580 + get_page(page_m);
75581 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75582 +}
75583 +#endif
75584 +
75585 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
75586 unsigned long address, pte_t *ptep, pte_t pte,
75587 struct page *pagecache_page)
75588 @@ -2004,6 +2024,11 @@ retry_avoidcopy:
75589 huge_ptep_clear_flush(vma, address, ptep);
75590 set_huge_pte_at(mm, address, ptep,
75591 make_huge_pte(vma, new_page, 1));
75592 +
75593 +#ifdef CONFIG_PAX_SEGMEXEC
75594 + pax_mirror_huge_pte(vma, address, new_page);
75595 +#endif
75596 +
75597 /* Make the old page be freed below */
75598 new_page = old_page;
75599 }
75600 @@ -2135,6 +2160,10 @@ retry:
75601 && (vma->vm_flags & VM_SHARED)));
75602 set_huge_pte_at(mm, address, ptep, new_pte);
75603
75604 +#ifdef CONFIG_PAX_SEGMEXEC
75605 + pax_mirror_huge_pte(vma, address, page);
75606 +#endif
75607 +
75608 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75609 /* Optimization, do the COW without a second fault */
75610 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75611 @@ -2163,6 +2192,28 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75612 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75613 struct hstate *h = hstate_vma(vma);
75614
75615 +#ifdef CONFIG_PAX_SEGMEXEC
75616 + struct vm_area_struct *vma_m;
75617 +
75618 + vma_m = pax_find_mirror_vma(vma);
75619 + if (vma_m) {
75620 + unsigned long address_m;
75621 +
75622 + if (vma->vm_start > vma_m->vm_start) {
75623 + address_m = address;
75624 + address -= SEGMEXEC_TASK_SIZE;
75625 + vma = vma_m;
75626 + h = hstate_vma(vma);
75627 + } else
75628 + address_m = address + SEGMEXEC_TASK_SIZE;
75629 +
75630 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75631 + return VM_FAULT_OOM;
75632 + address_m &= HPAGE_MASK;
75633 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75634 + }
75635 +#endif
75636 +
75637 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75638 if (!ptep)
75639 return VM_FAULT_OOM;
75640 diff --git a/mm/internal.h b/mm/internal.h
75641 index f03e8e2..7354343 100644
75642 --- a/mm/internal.h
75643 +++ b/mm/internal.h
75644 @@ -49,6 +49,7 @@ extern void putback_lru_page(struct page *page);
75645 * in mm/page_alloc.c
75646 */
75647 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75648 +extern void free_compound_page(struct page *page);
75649 extern void prep_compound_page(struct page *page, unsigned long order);
75650
75651
75652 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75653 index c346660..b47382f 100644
75654 --- a/mm/kmemleak.c
75655 +++ b/mm/kmemleak.c
75656 @@ -358,7 +358,7 @@ static void print_unreferenced(struct seq_file *seq,
75657
75658 for (i = 0; i < object->trace_len; i++) {
75659 void *ptr = (void *)object->trace[i];
75660 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75661 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
75662 }
75663 }
75664
75665 diff --git a/mm/maccess.c b/mm/maccess.c
75666 index 9073695..1127f348 100644
75667 --- a/mm/maccess.c
75668 +++ b/mm/maccess.c
75669 @@ -14,7 +14,7 @@
75670 * Safely read from address @src to the buffer at @dst. If a kernel fault
75671 * happens, handle that and return -EFAULT.
75672 */
75673 -long probe_kernel_read(void *dst, void *src, size_t size)
75674 +long probe_kernel_read(void *dst, const void *src, size_t size)
75675 {
75676 long ret;
75677 mm_segment_t old_fs = get_fs();
75678 @@ -22,7 +22,7 @@ long probe_kernel_read(void *dst, void *src, size_t size)
75679 set_fs(KERNEL_DS);
75680 pagefault_disable();
75681 ret = __copy_from_user_inatomic(dst,
75682 - (__force const void __user *)src, size);
75683 + (const void __force_user *)src, size);
75684 pagefault_enable();
75685 set_fs(old_fs);
75686
75687 @@ -39,14 +39,14 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
75688 * Safely write to address @dst from the buffer at @src. If a kernel fault
75689 * happens, handle that and return -EFAULT.
75690 */
75691 -long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
75692 +long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
75693 {
75694 long ret;
75695 mm_segment_t old_fs = get_fs();
75696
75697 set_fs(KERNEL_DS);
75698 pagefault_disable();
75699 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75700 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75701 pagefault_enable();
75702 set_fs(old_fs);
75703
75704 diff --git a/mm/madvise.c b/mm/madvise.c
75705 index 35b1479..499f7d4 100644
75706 --- a/mm/madvise.c
75707 +++ b/mm/madvise.c
75708 @@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75709 pgoff_t pgoff;
75710 unsigned long new_flags = vma->vm_flags;
75711
75712 +#ifdef CONFIG_PAX_SEGMEXEC
75713 + struct vm_area_struct *vma_m;
75714 +#endif
75715 +
75716 switch (behavior) {
75717 case MADV_NORMAL:
75718 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75719 @@ -103,6 +107,13 @@ success:
75720 /*
75721 * vm_flags is protected by the mmap_sem held in write mode.
75722 */
75723 +
75724 +#ifdef CONFIG_PAX_SEGMEXEC
75725 + vma_m = pax_find_mirror_vma(vma);
75726 + if (vma_m)
75727 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75728 +#endif
75729 +
75730 vma->vm_flags = new_flags;
75731
75732 out:
75733 @@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75734 struct vm_area_struct ** prev,
75735 unsigned long start, unsigned long end)
75736 {
75737 +
75738 +#ifdef CONFIG_PAX_SEGMEXEC
75739 + struct vm_area_struct *vma_m;
75740 +#endif
75741 +
75742 *prev = vma;
75743 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75744 return -EINVAL;
75745 @@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75746 zap_page_range(vma, start, end - start, &details);
75747 } else
75748 zap_page_range(vma, start, end - start, NULL);
75749 +
75750 +#ifdef CONFIG_PAX_SEGMEXEC
75751 + vma_m = pax_find_mirror_vma(vma);
75752 + if (vma_m) {
75753 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75754 + struct zap_details details = {
75755 + .nonlinear_vma = vma_m,
75756 + .last_index = ULONG_MAX,
75757 + };
75758 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75759 + } else
75760 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75761 + }
75762 +#endif
75763 +
75764 return 0;
75765 }
75766
75767 @@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75768 if (end < start)
75769 goto out;
75770
75771 +#ifdef CONFIG_PAX_SEGMEXEC
75772 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75773 + if (end > SEGMEXEC_TASK_SIZE)
75774 + goto out;
75775 + } else
75776 +#endif
75777 +
75778 + if (end > TASK_SIZE)
75779 + goto out;
75780 +
75781 error = 0;
75782 if (end == start)
75783 goto out;
75784 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75785 index 8aeba53..b4a4198 100644
75786 --- a/mm/memory-failure.c
75787 +++ b/mm/memory-failure.c
75788 @@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75789
75790 int sysctl_memory_failure_recovery __read_mostly = 1;
75791
75792 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75793 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75794
75795 /*
75796 * Send all the processes who have the page mapped an ``action optional''
75797 @@ -64,7 +64,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
75798 si.si_signo = SIGBUS;
75799 si.si_errno = 0;
75800 si.si_code = BUS_MCEERR_AO;
75801 - si.si_addr = (void *)addr;
75802 + si.si_addr = (void __user *)addr;
75803 #ifdef __ARCH_SI_TRAPNO
75804 si.si_trapno = trapno;
75805 #endif
75806 @@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref)
75807 return 0;
75808 }
75809
75810 - atomic_long_add(1, &mce_bad_pages);
75811 + atomic_long_add_unchecked(1, &mce_bad_pages);
75812
75813 /*
75814 * We need/can do nothing about count=0 pages.
75815 diff --git a/mm/memory.c b/mm/memory.c
75816 index 6c836d3..48f3264 100644
75817 --- a/mm/memory.c
75818 +++ b/mm/memory.c
75819 @@ -187,8 +187,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75820 return;
75821
75822 pmd = pmd_offset(pud, start);
75823 +
75824 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75825 pud_clear(pud);
75826 pmd_free_tlb(tlb, pmd, start);
75827 +#endif
75828 +
75829 }
75830
75831 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75832 @@ -219,9 +223,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75833 if (end - 1 > ceiling - 1)
75834 return;
75835
75836 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75837 pud = pud_offset(pgd, start);
75838 pgd_clear(pgd);
75839 pud_free_tlb(tlb, pud, start);
75840 +#endif
75841 +
75842 }
75843
75844 /*
75845 @@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75846 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
75847 i = 0;
75848
75849 - do {
75850 + while (nr_pages) {
75851 struct vm_area_struct *vma;
75852
75853 - vma = find_extend_vma(mm, start);
75854 + vma = find_vma(mm, start);
75855 if (!vma && in_gate_area(tsk, start)) {
75856 unsigned long pg = start & PAGE_MASK;
75857 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
75858 @@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75859 continue;
75860 }
75861
75862 - if (!vma ||
75863 + if (!vma || start < vma->vm_start ||
75864 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75865 !(vm_flags & vma->vm_flags))
75866 return i ? : -EFAULT;
75867 @@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75868 start += PAGE_SIZE;
75869 nr_pages--;
75870 } while (nr_pages && start < vma->vm_end);
75871 - } while (nr_pages);
75872 + }
75873 return i;
75874 }
75875
75876 @@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75877 page_add_file_rmap(page);
75878 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75879
75880 +#ifdef CONFIG_PAX_SEGMEXEC
75881 + pax_mirror_file_pte(vma, addr, page, ptl);
75882 +#endif
75883 +
75884 retval = 0;
75885 pte_unmap_unlock(pte, ptl);
75886 return retval;
75887 @@ -1560,10 +1571,22 @@ out:
75888 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75889 struct page *page)
75890 {
75891 +
75892 +#ifdef CONFIG_PAX_SEGMEXEC
75893 + struct vm_area_struct *vma_m;
75894 +#endif
75895 +
75896 if (addr < vma->vm_start || addr >= vma->vm_end)
75897 return -EFAULT;
75898 if (!page_count(page))
75899 return -EINVAL;
75900 +
75901 +#ifdef CONFIG_PAX_SEGMEXEC
75902 + vma_m = pax_find_mirror_vma(vma);
75903 + if (vma_m)
75904 + vma_m->vm_flags |= VM_INSERTPAGE;
75905 +#endif
75906 +
75907 vma->vm_flags |= VM_INSERTPAGE;
75908 return insert_page(vma, addr, page, vma->vm_page_prot);
75909 }
75910 @@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75911 unsigned long pfn)
75912 {
75913 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75914 + BUG_ON(vma->vm_mirror);
75915
75916 if (addr < vma->vm_start || addr >= vma->vm_end)
75917 return -EFAULT;
75918 @@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75919 copy_user_highpage(dst, src, va, vma);
75920 }
75921
75922 +#ifdef CONFIG_PAX_SEGMEXEC
75923 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75924 +{
75925 + struct mm_struct *mm = vma->vm_mm;
75926 + spinlock_t *ptl;
75927 + pte_t *pte, entry;
75928 +
75929 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75930 + entry = *pte;
75931 + if (!pte_present(entry)) {
75932 + if (!pte_none(entry)) {
75933 + BUG_ON(pte_file(entry));
75934 + free_swap_and_cache(pte_to_swp_entry(entry));
75935 + pte_clear_not_present_full(mm, address, pte, 0);
75936 + }
75937 + } else {
75938 + struct page *page;
75939 +
75940 + flush_cache_page(vma, address, pte_pfn(entry));
75941 + entry = ptep_clear_flush(vma, address, pte);
75942 + BUG_ON(pte_dirty(entry));
75943 + page = vm_normal_page(vma, address, entry);
75944 + if (page) {
75945 + update_hiwater_rss(mm);
75946 + if (PageAnon(page))
75947 + dec_mm_counter(mm, anon_rss);
75948 + else
75949 + dec_mm_counter(mm, file_rss);
75950 + page_remove_rmap(page);
75951 + page_cache_release(page);
75952 + }
75953 + }
75954 + pte_unmap_unlock(pte, ptl);
75955 +}
75956 +
75957 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
75958 + *
75959 + * the ptl of the lower mapped page is held on entry and is not released on exit
75960 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75961 + */
75962 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75963 +{
75964 + struct mm_struct *mm = vma->vm_mm;
75965 + unsigned long address_m;
75966 + spinlock_t *ptl_m;
75967 + struct vm_area_struct *vma_m;
75968 + pmd_t *pmd_m;
75969 + pte_t *pte_m, entry_m;
75970 +
75971 + BUG_ON(!page_m || !PageAnon(page_m));
75972 +
75973 + vma_m = pax_find_mirror_vma(vma);
75974 + if (!vma_m)
75975 + return;
75976 +
75977 + BUG_ON(!PageLocked(page_m));
75978 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75979 + address_m = address + SEGMEXEC_TASK_SIZE;
75980 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75981 + pte_m = pte_offset_map_nested(pmd_m, address_m);
75982 + ptl_m = pte_lockptr(mm, pmd_m);
75983 + if (ptl != ptl_m) {
75984 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75985 + if (!pte_none(*pte_m))
75986 + goto out;
75987 + }
75988 +
75989 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75990 + page_cache_get(page_m);
75991 + page_add_anon_rmap(page_m, vma_m, address_m);
75992 + inc_mm_counter(mm, anon_rss);
75993 + set_pte_at(mm, address_m, pte_m, entry_m);
75994 + update_mmu_cache(vma_m, address_m, entry_m);
75995 +out:
75996 + if (ptl != ptl_m)
75997 + spin_unlock(ptl_m);
75998 + pte_unmap_nested(pte_m);
75999 + unlock_page(page_m);
76000 +}
76001 +
76002 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
76003 +{
76004 + struct mm_struct *mm = vma->vm_mm;
76005 + unsigned long address_m;
76006 + spinlock_t *ptl_m;
76007 + struct vm_area_struct *vma_m;
76008 + pmd_t *pmd_m;
76009 + pte_t *pte_m, entry_m;
76010 +
76011 + BUG_ON(!page_m || PageAnon(page_m));
76012 +
76013 + vma_m = pax_find_mirror_vma(vma);
76014 + if (!vma_m)
76015 + return;
76016 +
76017 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76018 + address_m = address + SEGMEXEC_TASK_SIZE;
76019 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76020 + pte_m = pte_offset_map_nested(pmd_m, address_m);
76021 + ptl_m = pte_lockptr(mm, pmd_m);
76022 + if (ptl != ptl_m) {
76023 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76024 + if (!pte_none(*pte_m))
76025 + goto out;
76026 + }
76027 +
76028 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
76029 + page_cache_get(page_m);
76030 + page_add_file_rmap(page_m);
76031 + inc_mm_counter(mm, file_rss);
76032 + set_pte_at(mm, address_m, pte_m, entry_m);
76033 + update_mmu_cache(vma_m, address_m, entry_m);
76034 +out:
76035 + if (ptl != ptl_m)
76036 + spin_unlock(ptl_m);
76037 + pte_unmap_nested(pte_m);
76038 +}
76039 +
76040 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
76041 +{
76042 + struct mm_struct *mm = vma->vm_mm;
76043 + unsigned long address_m;
76044 + spinlock_t *ptl_m;
76045 + struct vm_area_struct *vma_m;
76046 + pmd_t *pmd_m;
76047 + pte_t *pte_m, entry_m;
76048 +
76049 + vma_m = pax_find_mirror_vma(vma);
76050 + if (!vma_m)
76051 + return;
76052 +
76053 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76054 + address_m = address + SEGMEXEC_TASK_SIZE;
76055 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76056 + pte_m = pte_offset_map_nested(pmd_m, address_m);
76057 + ptl_m = pte_lockptr(mm, pmd_m);
76058 + if (ptl != ptl_m) {
76059 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76060 + if (!pte_none(*pte_m))
76061 + goto out;
76062 + }
76063 +
76064 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
76065 + set_pte_at(mm, address_m, pte_m, entry_m);
76066 +out:
76067 + if (ptl != ptl_m)
76068 + spin_unlock(ptl_m);
76069 + pte_unmap_nested(pte_m);
76070 +}
76071 +
76072 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
76073 +{
76074 + struct page *page_m;
76075 + pte_t entry;
76076 +
76077 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
76078 + goto out;
76079 +
76080 + entry = *pte;
76081 + page_m = vm_normal_page(vma, address, entry);
76082 + if (!page_m)
76083 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
76084 + else if (PageAnon(page_m)) {
76085 + if (pax_find_mirror_vma(vma)) {
76086 + pte_unmap_unlock(pte, ptl);
76087 + lock_page(page_m);
76088 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
76089 + if (pte_same(entry, *pte))
76090 + pax_mirror_anon_pte(vma, address, page_m, ptl);
76091 + else
76092 + unlock_page(page_m);
76093 + }
76094 + } else
76095 + pax_mirror_file_pte(vma, address, page_m, ptl);
76096 +
76097 +out:
76098 + pte_unmap_unlock(pte, ptl);
76099 +}
76100 +#endif
76101 +
76102 /*
76103 * This routine handles present pages, when users try to write
76104 * to a shared page. It is done by copying the page to a new address
76105 @@ -2156,6 +2360,12 @@ gotten:
76106 */
76107 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76108 if (likely(pte_same(*page_table, orig_pte))) {
76109 +
76110 +#ifdef CONFIG_PAX_SEGMEXEC
76111 + if (pax_find_mirror_vma(vma))
76112 + BUG_ON(!trylock_page(new_page));
76113 +#endif
76114 +
76115 if (old_page) {
76116 if (!PageAnon(old_page)) {
76117 dec_mm_counter(mm, file_rss);
76118 @@ -2207,6 +2417,10 @@ gotten:
76119 page_remove_rmap(old_page);
76120 }
76121
76122 +#ifdef CONFIG_PAX_SEGMEXEC
76123 + pax_mirror_anon_pte(vma, address, new_page, ptl);
76124 +#endif
76125 +
76126 /* Free the old page.. */
76127 new_page = old_page;
76128 ret |= VM_FAULT_WRITE;
76129 @@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76130 swap_free(entry);
76131 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
76132 try_to_free_swap(page);
76133 +
76134 +#ifdef CONFIG_PAX_SEGMEXEC
76135 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
76136 +#endif
76137 +
76138 unlock_page(page);
76139
76140 if (flags & FAULT_FLAG_WRITE) {
76141 @@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76142
76143 /* No need to invalidate - it was non-present before */
76144 update_mmu_cache(vma, address, pte);
76145 +
76146 +#ifdef CONFIG_PAX_SEGMEXEC
76147 + pax_mirror_anon_pte(vma, address, page, ptl);
76148 +#endif
76149 +
76150 unlock:
76151 pte_unmap_unlock(page_table, ptl);
76152 out:
76153 @@ -2632,40 +2856,6 @@ out_release:
76154 }
76155
76156 /*
76157 - * This is like a special single-page "expand_{down|up}wards()",
76158 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
76159 - * doesn't hit another vma.
76160 - */
76161 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76162 -{
76163 - address &= PAGE_MASK;
76164 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76165 - struct vm_area_struct *prev = vma->vm_prev;
76166 -
76167 - /*
76168 - * Is there a mapping abutting this one below?
76169 - *
76170 - * That's only ok if it's the same stack mapping
76171 - * that has gotten split..
76172 - */
76173 - if (prev && prev->vm_end == address)
76174 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76175 -
76176 - expand_stack(vma, address - PAGE_SIZE);
76177 - }
76178 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76179 - struct vm_area_struct *next = vma->vm_next;
76180 -
76181 - /* As VM_GROWSDOWN but s/below/above/ */
76182 - if (next && next->vm_start == address + PAGE_SIZE)
76183 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76184 -
76185 - expand_upwards(vma, address + PAGE_SIZE);
76186 - }
76187 - return 0;
76188 -}
76189 -
76190 -/*
76191 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76192 * but allow concurrent faults), and pte mapped but not yet locked.
76193 * We return with mmap_sem still held, but pte unmapped and unlocked.
76194 @@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76195 unsigned long address, pte_t *page_table, pmd_t *pmd,
76196 unsigned int flags)
76197 {
76198 - struct page *page;
76199 + struct page *page = NULL;
76200 spinlock_t *ptl;
76201 pte_t entry;
76202
76203 - pte_unmap(page_table);
76204 -
76205 - /* Check if we need to add a guard page to the stack */
76206 - if (check_stack_guard_page(vma, address) < 0)
76207 - return VM_FAULT_SIGBUS;
76208 -
76209 - /* Use the zero-page for reads */
76210 if (!(flags & FAULT_FLAG_WRITE)) {
76211 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76212 vma->vm_page_prot));
76213 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76214 + ptl = pte_lockptr(mm, pmd);
76215 + spin_lock(ptl);
76216 if (!pte_none(*page_table))
76217 goto unlock;
76218 goto setpte;
76219 }
76220
76221 /* Allocate our own private page. */
76222 + pte_unmap(page_table);
76223 +
76224 if (unlikely(anon_vma_prepare(vma)))
76225 goto oom;
76226 page = alloc_zeroed_user_highpage_movable(vma, address);
76227 @@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76228 if (!pte_none(*page_table))
76229 goto release;
76230
76231 +#ifdef CONFIG_PAX_SEGMEXEC
76232 + if (pax_find_mirror_vma(vma))
76233 + BUG_ON(!trylock_page(page));
76234 +#endif
76235 +
76236 inc_mm_counter(mm, anon_rss);
76237 page_add_new_anon_rmap(page, vma, address);
76238 setpte:
76239 @@ -2720,6 +2911,12 @@ setpte:
76240
76241 /* No need to invalidate - it was non-present before */
76242 update_mmu_cache(vma, address, entry);
76243 +
76244 +#ifdef CONFIG_PAX_SEGMEXEC
76245 + if (page)
76246 + pax_mirror_anon_pte(vma, address, page, ptl);
76247 +#endif
76248 +
76249 unlock:
76250 pte_unmap_unlock(page_table, ptl);
76251 return 0;
76252 @@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76253 */
76254 /* Only go through if we didn't race with anybody else... */
76255 if (likely(pte_same(*page_table, orig_pte))) {
76256 +
76257 +#ifdef CONFIG_PAX_SEGMEXEC
76258 + if (anon && pax_find_mirror_vma(vma))
76259 + BUG_ON(!trylock_page(page));
76260 +#endif
76261 +
76262 flush_icache_page(vma, page);
76263 entry = mk_pte(page, vma->vm_page_prot);
76264 if (flags & FAULT_FLAG_WRITE)
76265 @@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76266
76267 /* no need to invalidate: a not-present page won't be cached */
76268 update_mmu_cache(vma, address, entry);
76269 +
76270 +#ifdef CONFIG_PAX_SEGMEXEC
76271 + if (anon)
76272 + pax_mirror_anon_pte(vma, address, page, ptl);
76273 + else
76274 + pax_mirror_file_pte(vma, address, page, ptl);
76275 +#endif
76276 +
76277 } else {
76278 if (charged)
76279 mem_cgroup_uncharge_page(page);
76280 @@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struct mm_struct *mm,
76281 if (flags & FAULT_FLAG_WRITE)
76282 flush_tlb_page(vma, address);
76283 }
76284 +
76285 +#ifdef CONFIG_PAX_SEGMEXEC
76286 + pax_mirror_pte(vma, address, pte, pmd, ptl);
76287 + return 0;
76288 +#endif
76289 +
76290 unlock:
76291 pte_unmap_unlock(pte, ptl);
76292 return 0;
76293 @@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76294 pmd_t *pmd;
76295 pte_t *pte;
76296
76297 +#ifdef CONFIG_PAX_SEGMEXEC
76298 + struct vm_area_struct *vma_m;
76299 +#endif
76300 +
76301 __set_current_state(TASK_RUNNING);
76302
76303 count_vm_event(PGFAULT);
76304 @@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76305 if (unlikely(is_vm_hugetlb_page(vma)))
76306 return hugetlb_fault(mm, vma, address, flags);
76307
76308 +#ifdef CONFIG_PAX_SEGMEXEC
76309 + vma_m = pax_find_mirror_vma(vma);
76310 + if (vma_m) {
76311 + unsigned long address_m;
76312 + pgd_t *pgd_m;
76313 + pud_t *pud_m;
76314 + pmd_t *pmd_m;
76315 +
76316 + if (vma->vm_start > vma_m->vm_start) {
76317 + address_m = address;
76318 + address -= SEGMEXEC_TASK_SIZE;
76319 + vma = vma_m;
76320 + } else
76321 + address_m = address + SEGMEXEC_TASK_SIZE;
76322 +
76323 + pgd_m = pgd_offset(mm, address_m);
76324 + pud_m = pud_alloc(mm, pgd_m, address_m);
76325 + if (!pud_m)
76326 + return VM_FAULT_OOM;
76327 + pmd_m = pmd_alloc(mm, pud_m, address_m);
76328 + if (!pmd_m)
76329 + return VM_FAULT_OOM;
76330 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
76331 + return VM_FAULT_OOM;
76332 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76333 + }
76334 +#endif
76335 +
76336 pgd = pgd_offset(mm, address);
76337 pud = pud_alloc(mm, pgd, address);
76338 if (!pud)
76339 @@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
76340 gate_vma.vm_start = FIXADDR_USER_START;
76341 gate_vma.vm_end = FIXADDR_USER_END;
76342 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76343 - gate_vma.vm_page_prot = __P101;
76344 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76345 /*
76346 * Make sure the vDSO gets into every core dump.
76347 * Dumping its contents makes post-mortem fully interpretable later
76348 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76349 index 3c6e3e2..ad9871c 100644
76350 --- a/mm/mempolicy.c
76351 +++ b/mm/mempolicy.c
76352 @@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76353 struct vm_area_struct *next;
76354 int err;
76355
76356 +#ifdef CONFIG_PAX_SEGMEXEC
76357 + struct vm_area_struct *vma_m;
76358 +#endif
76359 +
76360 err = 0;
76361 for (; vma && vma->vm_start < end; vma = next) {
76362 next = vma->vm_next;
76363 @@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76364 err = policy_vma(vma, new);
76365 if (err)
76366 break;
76367 +
76368 +#ifdef CONFIG_PAX_SEGMEXEC
76369 + vma_m = pax_find_mirror_vma(vma);
76370 + if (vma_m) {
76371 + err = policy_vma(vma_m, new);
76372 + if (err)
76373 + break;
76374 + }
76375 +#endif
76376 +
76377 }
76378 return err;
76379 }
76380 @@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76381
76382 if (end < start)
76383 return -EINVAL;
76384 +
76385 +#ifdef CONFIG_PAX_SEGMEXEC
76386 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76387 + if (end > SEGMEXEC_TASK_SIZE)
76388 + return -EINVAL;
76389 + } else
76390 +#endif
76391 +
76392 + if (end > TASK_SIZE)
76393 + return -EINVAL;
76394 +
76395 if (end == start)
76396 return 0;
76397
76398 @@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76399 if (!mm)
76400 return -EINVAL;
76401
76402 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76403 + if (mm != current->mm &&
76404 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76405 + err = -EPERM;
76406 + goto out;
76407 + }
76408 +#endif
76409 +
76410 /*
76411 * Check if this process has the right to modify the specified
76412 * process. The right exists if the process has administrative
76413 @@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76414 rcu_read_lock();
76415 tcred = __task_cred(task);
76416 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76417 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
76418 - !capable(CAP_SYS_NICE)) {
76419 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76420 rcu_read_unlock();
76421 err = -EPERM;
76422 goto out;
76423 @@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, void *v)
76424
76425 if (file) {
76426 seq_printf(m, " file=");
76427 - seq_path(m, &file->f_path, "\n\t= ");
76428 + seq_path(m, &file->f_path, "\n\t\\= ");
76429 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
76430 seq_printf(m, " heap");
76431 } else if (vma->vm_start <= mm->start_stack &&
76432 diff --git a/mm/migrate.c b/mm/migrate.c
76433 index aaca868..2ebecdc 100644
76434 --- a/mm/migrate.c
76435 +++ b/mm/migrate.c
76436 @@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
76437 unsigned long chunk_start;
76438 int err;
76439
76440 + pax_track_stack();
76441 +
76442 task_nodes = cpuset_mems_allowed(task);
76443
76444 err = -ENOMEM;
76445 @@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76446 if (!mm)
76447 return -EINVAL;
76448
76449 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76450 + if (mm != current->mm &&
76451 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76452 + err = -EPERM;
76453 + goto out;
76454 + }
76455 +#endif
76456 +
76457 /*
76458 * Check if this process has the right to modify the specified
76459 * process. The right exists if the process has administrative
76460 @@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76461 rcu_read_lock();
76462 tcred = __task_cred(task);
76463 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76464 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
76465 - !capable(CAP_SYS_NICE)) {
76466 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76467 rcu_read_unlock();
76468 err = -EPERM;
76469 goto out;
76470 diff --git a/mm/mlock.c b/mm/mlock.c
76471 index 2d846cf..98134d2 100644
76472 --- a/mm/mlock.c
76473 +++ b/mm/mlock.c
76474 @@ -13,6 +13,7 @@
76475 #include <linux/pagemap.h>
76476 #include <linux/mempolicy.h>
76477 #include <linux/syscalls.h>
76478 +#include <linux/security.h>
76479 #include <linux/sched.h>
76480 #include <linux/module.h>
76481 #include <linux/rmap.h>
76482 @@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
76483 }
76484 }
76485
76486 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
76487 -{
76488 - return (vma->vm_flags & VM_GROWSDOWN) &&
76489 - (vma->vm_start == addr) &&
76490 - !vma_stack_continue(vma->vm_prev, addr);
76491 -}
76492 -
76493 /**
76494 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
76495 * @vma: target vma
76496 @@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
76497 if (vma->vm_flags & VM_WRITE)
76498 gup_flags |= FOLL_WRITE;
76499
76500 - /* We don't try to access the guard page of a stack vma */
76501 - if (stack_guard_page(vma, start)) {
76502 - addr += PAGE_SIZE;
76503 - nr_pages--;
76504 - }
76505 -
76506 while (nr_pages > 0) {
76507 int i;
76508
76509 @@ -440,7 +428,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76510 {
76511 unsigned long nstart, end, tmp;
76512 struct vm_area_struct * vma, * prev;
76513 - int error;
76514 + int error = -EINVAL;
76515
76516 len = PAGE_ALIGN(len);
76517 end = start + len;
76518 @@ -448,6 +436,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76519 return -EINVAL;
76520 if (end == start)
76521 return 0;
76522 + if (end > TASK_SIZE)
76523 + return -EINVAL;
76524 +
76525 vma = find_vma_prev(current->mm, start, &prev);
76526 if (!vma || vma->vm_start > start)
76527 return -ENOMEM;
76528 @@ -458,6 +449,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76529 for (nstart = start ; ; ) {
76530 unsigned int newflags;
76531
76532 +#ifdef CONFIG_PAX_SEGMEXEC
76533 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76534 + break;
76535 +#endif
76536 +
76537 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76538
76539 newflags = vma->vm_flags | VM_LOCKED;
76540 @@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76541 lock_limit >>= PAGE_SHIFT;
76542
76543 /* check against resource limits */
76544 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76545 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76546 error = do_mlock(start, len, 1);
76547 up_write(&current->mm->mmap_sem);
76548 @@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
76549 static int do_mlockall(int flags)
76550 {
76551 struct vm_area_struct * vma, * prev = NULL;
76552 - unsigned int def_flags = 0;
76553
76554 if (flags & MCL_FUTURE)
76555 - def_flags = VM_LOCKED;
76556 - current->mm->def_flags = def_flags;
76557 + current->mm->def_flags |= VM_LOCKED;
76558 + else
76559 + current->mm->def_flags &= ~VM_LOCKED;
76560 if (flags == MCL_FUTURE)
76561 goto out;
76562
76563 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76564 - unsigned int newflags;
76565 + unsigned long newflags;
76566
76567 +#ifdef CONFIG_PAX_SEGMEXEC
76568 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76569 + break;
76570 +#endif
76571 +
76572 + BUG_ON(vma->vm_end > TASK_SIZE);
76573 newflags = vma->vm_flags | VM_LOCKED;
76574 if (!(flags & MCL_CURRENT))
76575 newflags &= ~VM_LOCKED;
76576 @@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76577 lock_limit >>= PAGE_SHIFT;
76578
76579 ret = -ENOMEM;
76580 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76581 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76582 capable(CAP_IPC_LOCK))
76583 ret = do_mlockall(flags);
76584 diff --git a/mm/mmap.c b/mm/mmap.c
76585 index 4b80cbf..c5ce1df 100644
76586 --- a/mm/mmap.c
76587 +++ b/mm/mmap.c
76588 @@ -45,6 +45,16 @@
76589 #define arch_rebalance_pgtables(addr, len) (addr)
76590 #endif
76591
76592 +static inline void verify_mm_writelocked(struct mm_struct *mm)
76593 +{
76594 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76595 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76596 + up_read(&mm->mmap_sem);
76597 + BUG();
76598 + }
76599 +#endif
76600 +}
76601 +
76602 static void unmap_region(struct mm_struct *mm,
76603 struct vm_area_struct *vma, struct vm_area_struct *prev,
76604 unsigned long start, unsigned long end);
76605 @@ -70,22 +80,32 @@ static void unmap_region(struct mm_struct *mm,
76606 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76607 *
76608 */
76609 -pgprot_t protection_map[16] = {
76610 +pgprot_t protection_map[16] __read_only = {
76611 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76612 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76613 };
76614
76615 pgprot_t vm_get_page_prot(unsigned long vm_flags)
76616 {
76617 - return __pgprot(pgprot_val(protection_map[vm_flags &
76618 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76619 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76620 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76621 +
76622 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76623 + if (!nx_enabled &&
76624 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76625 + (vm_flags & (VM_READ | VM_WRITE)))
76626 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76627 +#endif
76628 +
76629 + return prot;
76630 }
76631 EXPORT_SYMBOL(vm_get_page_prot);
76632
76633 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76634 int sysctl_overcommit_ratio = 50; /* default is 50% */
76635 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76636 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76637 struct percpu_counter vm_committed_as;
76638
76639 /*
76640 @@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76641 struct vm_area_struct *next = vma->vm_next;
76642
76643 might_sleep();
76644 + BUG_ON(vma->vm_mirror);
76645 if (vma->vm_ops && vma->vm_ops->close)
76646 vma->vm_ops->close(vma);
76647 if (vma->vm_file) {
76648 @@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76649 * not page aligned -Ram Gupta
76650 */
76651 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
76652 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76653 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76654 (mm->end_data - mm->start_data) > rlim)
76655 goto out;
76656 @@ -704,6 +726,12 @@ static int
76657 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76658 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76659 {
76660 +
76661 +#ifdef CONFIG_PAX_SEGMEXEC
76662 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76663 + return 0;
76664 +#endif
76665 +
76666 if (is_mergeable_vma(vma, file, vm_flags) &&
76667 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76668 if (vma->vm_pgoff == vm_pgoff)
76669 @@ -723,6 +751,12 @@ static int
76670 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76671 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76672 {
76673 +
76674 +#ifdef CONFIG_PAX_SEGMEXEC
76675 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76676 + return 0;
76677 +#endif
76678 +
76679 if (is_mergeable_vma(vma, file, vm_flags) &&
76680 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76681 pgoff_t vm_pglen;
76682 @@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76683 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76684 struct vm_area_struct *prev, unsigned long addr,
76685 unsigned long end, unsigned long vm_flags,
76686 - struct anon_vma *anon_vma, struct file *file,
76687 + struct anon_vma *anon_vma, struct file *file,
76688 pgoff_t pgoff, struct mempolicy *policy)
76689 {
76690 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76691 struct vm_area_struct *area, *next;
76692
76693 +#ifdef CONFIG_PAX_SEGMEXEC
76694 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76695 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76696 +
76697 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76698 +#endif
76699 +
76700 /*
76701 * We later require that vma->vm_flags == vm_flags,
76702 * so this tests vma->vm_flags & VM_SPECIAL, too.
76703 @@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76704 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76705 next = next->vm_next;
76706
76707 +#ifdef CONFIG_PAX_SEGMEXEC
76708 + if (prev)
76709 + prev_m = pax_find_mirror_vma(prev);
76710 + if (area)
76711 + area_m = pax_find_mirror_vma(area);
76712 + if (next)
76713 + next_m = pax_find_mirror_vma(next);
76714 +#endif
76715 +
76716 /*
76717 * Can it merge with the predecessor?
76718 */
76719 @@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76720 /* cases 1, 6 */
76721 vma_adjust(prev, prev->vm_start,
76722 next->vm_end, prev->vm_pgoff, NULL);
76723 - } else /* cases 2, 5, 7 */
76724 +
76725 +#ifdef CONFIG_PAX_SEGMEXEC
76726 + if (prev_m)
76727 + vma_adjust(prev_m, prev_m->vm_start,
76728 + next_m->vm_end, prev_m->vm_pgoff, NULL);
76729 +#endif
76730 +
76731 + } else { /* cases 2, 5, 7 */
76732 vma_adjust(prev, prev->vm_start,
76733 end, prev->vm_pgoff, NULL);
76734 +
76735 +#ifdef CONFIG_PAX_SEGMEXEC
76736 + if (prev_m)
76737 + vma_adjust(prev_m, prev_m->vm_start,
76738 + end_m, prev_m->vm_pgoff, NULL);
76739 +#endif
76740 +
76741 + }
76742 return prev;
76743 }
76744
76745 @@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76746 mpol_equal(policy, vma_policy(next)) &&
76747 can_vma_merge_before(next, vm_flags,
76748 anon_vma, file, pgoff+pglen)) {
76749 - if (prev && addr < prev->vm_end) /* case 4 */
76750 + if (prev && addr < prev->vm_end) { /* case 4 */
76751 vma_adjust(prev, prev->vm_start,
76752 addr, prev->vm_pgoff, NULL);
76753 - else /* cases 3, 8 */
76754 +
76755 +#ifdef CONFIG_PAX_SEGMEXEC
76756 + if (prev_m)
76757 + vma_adjust(prev_m, prev_m->vm_start,
76758 + addr_m, prev_m->vm_pgoff, NULL);
76759 +#endif
76760 +
76761 + } else { /* cases 3, 8 */
76762 vma_adjust(area, addr, next->vm_end,
76763 next->vm_pgoff - pglen, NULL);
76764 +
76765 +#ifdef CONFIG_PAX_SEGMEXEC
76766 + if (area_m)
76767 + vma_adjust(area_m, addr_m, next_m->vm_end,
76768 + next_m->vm_pgoff - pglen, NULL);
76769 +#endif
76770 +
76771 + }
76772 return area;
76773 }
76774
76775 @@ -898,14 +978,11 @@ none:
76776 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76777 struct file *file, long pages)
76778 {
76779 - const unsigned long stack_flags
76780 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76781 -
76782 if (file) {
76783 mm->shared_vm += pages;
76784 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76785 mm->exec_vm += pages;
76786 - } else if (flags & stack_flags)
76787 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76788 mm->stack_vm += pages;
76789 if (flags & (VM_RESERVED|VM_IO))
76790 mm->reserved_vm += pages;
76791 @@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76792 * (the exception is when the underlying filesystem is noexec
76793 * mounted, in which case we dont add PROT_EXEC.)
76794 */
76795 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76796 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76797 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76798 prot |= PROT_EXEC;
76799
76800 @@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76801 /* Obtain the address to map to. we verify (or select) it and ensure
76802 * that it represents a valid section of the address space.
76803 */
76804 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
76805 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76806 if (addr & ~PAGE_MASK)
76807 return addr;
76808
76809 @@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76810 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76811 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76812
76813 +#ifdef CONFIG_PAX_MPROTECT
76814 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76815 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76816 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76817 + gr_log_rwxmmap(file);
76818 +
76819 +#ifdef CONFIG_PAX_EMUPLT
76820 + vm_flags &= ~VM_EXEC;
76821 +#else
76822 + return -EPERM;
76823 +#endif
76824 +
76825 + }
76826 +
76827 + if (!(vm_flags & VM_EXEC))
76828 + vm_flags &= ~VM_MAYEXEC;
76829 +#else
76830 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76831 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76832 +#endif
76833 + else
76834 + vm_flags &= ~VM_MAYWRITE;
76835 + }
76836 +#endif
76837 +
76838 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76839 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76840 + vm_flags &= ~VM_PAGEEXEC;
76841 +#endif
76842 +
76843 if (flags & MAP_LOCKED)
76844 if (!can_do_mlock())
76845 return -EPERM;
76846 @@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76847 locked += mm->locked_vm;
76848 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
76849 lock_limit >>= PAGE_SHIFT;
76850 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76851 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76852 return -EAGAIN;
76853 }
76854 @@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76855 if (error)
76856 return error;
76857
76858 + if (!gr_acl_handle_mmap(file, prot))
76859 + return -EACCES;
76860 +
76861 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76862 }
76863 EXPORT_SYMBOL(do_mmap_pgoff);
76864 @@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
76865 */
76866 int vma_wants_writenotify(struct vm_area_struct *vma)
76867 {
76868 - unsigned int vm_flags = vma->vm_flags;
76869 + unsigned long vm_flags = vma->vm_flags;
76870
76871 /* If it was private or non-writable, the write bit is already clear */
76872 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76873 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76874 return 0;
76875
76876 /* The backer wishes to know when pages are first written to? */
76877 @@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76878 unsigned long charged = 0;
76879 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76880
76881 +#ifdef CONFIG_PAX_SEGMEXEC
76882 + struct vm_area_struct *vma_m = NULL;
76883 +#endif
76884 +
76885 + /*
76886 + * mm->mmap_sem is required to protect against another thread
76887 + * changing the mappings in case we sleep.
76888 + */
76889 + verify_mm_writelocked(mm);
76890 +
76891 /* Clear old maps */
76892 error = -ENOMEM;
76893 -munmap_back:
76894 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
76895 if (vma && vma->vm_start < addr + len) {
76896 if (do_munmap(mm, addr, len))
76897 return -ENOMEM;
76898 - goto munmap_back;
76899 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
76900 + BUG_ON(vma && vma->vm_start < addr + len);
76901 }
76902
76903 /* Check against address space limit. */
76904 @@ -1173,6 +1294,16 @@ munmap_back:
76905 goto unacct_error;
76906 }
76907
76908 +#ifdef CONFIG_PAX_SEGMEXEC
76909 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76910 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76911 + if (!vma_m) {
76912 + error = -ENOMEM;
76913 + goto free_vma;
76914 + }
76915 + }
76916 +#endif
76917 +
76918 vma->vm_mm = mm;
76919 vma->vm_start = addr;
76920 vma->vm_end = addr + len;
76921 @@ -1195,6 +1326,19 @@ munmap_back:
76922 error = file->f_op->mmap(file, vma);
76923 if (error)
76924 goto unmap_and_free_vma;
76925 +
76926 +#ifdef CONFIG_PAX_SEGMEXEC
76927 + if (vma_m && (vm_flags & VM_EXECUTABLE))
76928 + added_exe_file_vma(mm);
76929 +#endif
76930 +
76931 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76932 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76933 + vma->vm_flags |= VM_PAGEEXEC;
76934 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76935 + }
76936 +#endif
76937 +
76938 if (vm_flags & VM_EXECUTABLE)
76939 added_exe_file_vma(mm);
76940
76941 @@ -1218,6 +1362,11 @@ munmap_back:
76942 vma_link(mm, vma, prev, rb_link, rb_parent);
76943 file = vma->vm_file;
76944
76945 +#ifdef CONFIG_PAX_SEGMEXEC
76946 + if (vma_m)
76947 + pax_mirror_vma(vma_m, vma);
76948 +#endif
76949 +
76950 /* Once vma denies write, undo our temporary denial count */
76951 if (correct_wcount)
76952 atomic_inc(&inode->i_writecount);
76953 @@ -1226,6 +1375,7 @@ out:
76954
76955 mm->total_vm += len >> PAGE_SHIFT;
76956 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76957 + track_exec_limit(mm, addr, addr + len, vm_flags);
76958 if (vm_flags & VM_LOCKED) {
76959 /*
76960 * makes pages present; downgrades, drops, reacquires mmap_sem
76961 @@ -1248,6 +1398,12 @@ unmap_and_free_vma:
76962 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76963 charged = 0;
76964 free_vma:
76965 +
76966 +#ifdef CONFIG_PAX_SEGMEXEC
76967 + if (vma_m)
76968 + kmem_cache_free(vm_area_cachep, vma_m);
76969 +#endif
76970 +
76971 kmem_cache_free(vm_area_cachep, vma);
76972 unacct_error:
76973 if (charged)
76974 @@ -1255,6 +1411,44 @@ unacct_error:
76975 return error;
76976 }
76977
76978 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
76979 +{
76980 + if (!vma) {
76981 +#ifdef CONFIG_STACK_GROWSUP
76982 + if (addr > sysctl_heap_stack_gap)
76983 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76984 + else
76985 + vma = find_vma(current->mm, 0);
76986 + if (vma && (vma->vm_flags & VM_GROWSUP))
76987 + return false;
76988 +#endif
76989 + return true;
76990 + }
76991 +
76992 + if (addr + len > vma->vm_start)
76993 + return false;
76994 +
76995 + if (vma->vm_flags & VM_GROWSDOWN)
76996 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76997 +#ifdef CONFIG_STACK_GROWSUP
76998 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76999 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
77000 +#endif
77001 +
77002 + return true;
77003 +}
77004 +
77005 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
77006 +{
77007 + if (vma->vm_start < len)
77008 + return -ENOMEM;
77009 + if (!(vma->vm_flags & VM_GROWSDOWN))
77010 + return vma->vm_start - len;
77011 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
77012 + return vma->vm_start - len - sysctl_heap_stack_gap;
77013 + return -ENOMEM;
77014 +}
77015 +
77016 /* Get an address range which is currently unmapped.
77017 * For shmat() with addr=0.
77018 *
77019 @@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77020 if (flags & MAP_FIXED)
77021 return addr;
77022
77023 +#ifdef CONFIG_PAX_RANDMMAP
77024 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77025 +#endif
77026 +
77027 if (addr) {
77028 addr = PAGE_ALIGN(addr);
77029 - vma = find_vma(mm, addr);
77030 - if (TASK_SIZE - len >= addr &&
77031 - (!vma || addr + len <= vma->vm_start))
77032 - return addr;
77033 + if (TASK_SIZE - len >= addr) {
77034 + vma = find_vma(mm, addr);
77035 + if (check_heap_stack_gap(vma, addr, len))
77036 + return addr;
77037 + }
77038 }
77039 if (len > mm->cached_hole_size) {
77040 - start_addr = addr = mm->free_area_cache;
77041 + start_addr = addr = mm->free_area_cache;
77042 } else {
77043 - start_addr = addr = TASK_UNMAPPED_BASE;
77044 - mm->cached_hole_size = 0;
77045 + start_addr = addr = mm->mmap_base;
77046 + mm->cached_hole_size = 0;
77047 }
77048
77049 full_search:
77050 @@ -1303,34 +1502,40 @@ full_search:
77051 * Start a new search - just in case we missed
77052 * some holes.
77053 */
77054 - if (start_addr != TASK_UNMAPPED_BASE) {
77055 - addr = TASK_UNMAPPED_BASE;
77056 - start_addr = addr;
77057 + if (start_addr != mm->mmap_base) {
77058 + start_addr = addr = mm->mmap_base;
77059 mm->cached_hole_size = 0;
77060 goto full_search;
77061 }
77062 return -ENOMEM;
77063 }
77064 - if (!vma || addr + len <= vma->vm_start) {
77065 - /*
77066 - * Remember the place where we stopped the search:
77067 - */
77068 - mm->free_area_cache = addr + len;
77069 - return addr;
77070 - }
77071 + if (check_heap_stack_gap(vma, addr, len))
77072 + break;
77073 if (addr + mm->cached_hole_size < vma->vm_start)
77074 mm->cached_hole_size = vma->vm_start - addr;
77075 addr = vma->vm_end;
77076 }
77077 +
77078 + /*
77079 + * Remember the place where we stopped the search:
77080 + */
77081 + mm->free_area_cache = addr + len;
77082 + return addr;
77083 }
77084 #endif
77085
77086 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
77087 {
77088 +
77089 +#ifdef CONFIG_PAX_SEGMEXEC
77090 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77091 + return;
77092 +#endif
77093 +
77094 /*
77095 * Is this a new hole at the lowest possible address?
77096 */
77097 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
77098 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
77099 mm->free_area_cache = addr;
77100 mm->cached_hole_size = ~0UL;
77101 }
77102 @@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77103 {
77104 struct vm_area_struct *vma;
77105 struct mm_struct *mm = current->mm;
77106 - unsigned long addr = addr0;
77107 + unsigned long base = mm->mmap_base, addr = addr0;
77108
77109 /* requested length too big for entire address space */
77110 if (len > TASK_SIZE)
77111 @@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77112 if (flags & MAP_FIXED)
77113 return addr;
77114
77115 +#ifdef CONFIG_PAX_RANDMMAP
77116 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77117 +#endif
77118 +
77119 /* requesting a specific address */
77120 if (addr) {
77121 addr = PAGE_ALIGN(addr);
77122 - vma = find_vma(mm, addr);
77123 - if (TASK_SIZE - len >= addr &&
77124 - (!vma || addr + len <= vma->vm_start))
77125 - return addr;
77126 + if (TASK_SIZE - len >= addr) {
77127 + vma = find_vma(mm, addr);
77128 + if (check_heap_stack_gap(vma, addr, len))
77129 + return addr;
77130 + }
77131 }
77132
77133 /* check if free_area_cache is useful for us */
77134 @@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77135 /* make sure it can fit in the remaining address space */
77136 if (addr > len) {
77137 vma = find_vma(mm, addr-len);
77138 - if (!vma || addr <= vma->vm_start)
77139 + if (check_heap_stack_gap(vma, addr - len, len))
77140 /* remember the address as a hint for next time */
77141 return (mm->free_area_cache = addr-len);
77142 }
77143 @@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77144 * return with success:
77145 */
77146 vma = find_vma(mm, addr);
77147 - if (!vma || addr+len <= vma->vm_start)
77148 + if (check_heap_stack_gap(vma, addr, len))
77149 /* remember the address as a hint for next time */
77150 return (mm->free_area_cache = addr);
77151
77152 @@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77153 mm->cached_hole_size = vma->vm_start - addr;
77154
77155 /* try just below the current vma->vm_start */
77156 - addr = vma->vm_start-len;
77157 - } while (len < vma->vm_start);
77158 + addr = skip_heap_stack_gap(vma, len);
77159 + } while (!IS_ERR_VALUE(addr));
77160
77161 bottomup:
77162 /*
77163 @@ -1414,13 +1624,21 @@ bottomup:
77164 * can happen with large stack limits and large mmap()
77165 * allocations.
77166 */
77167 + mm->mmap_base = TASK_UNMAPPED_BASE;
77168 +
77169 +#ifdef CONFIG_PAX_RANDMMAP
77170 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77171 + mm->mmap_base += mm->delta_mmap;
77172 +#endif
77173 +
77174 + mm->free_area_cache = mm->mmap_base;
77175 mm->cached_hole_size = ~0UL;
77176 - mm->free_area_cache = TASK_UNMAPPED_BASE;
77177 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
77178 /*
77179 * Restore the topdown base:
77180 */
77181 - mm->free_area_cache = mm->mmap_base;
77182 + mm->mmap_base = base;
77183 + mm->free_area_cache = base;
77184 mm->cached_hole_size = ~0UL;
77185
77186 return addr;
77187 @@ -1429,6 +1647,12 @@ bottomup:
77188
77189 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77190 {
77191 +
77192 +#ifdef CONFIG_PAX_SEGMEXEC
77193 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77194 + return;
77195 +#endif
77196 +
77197 /*
77198 * Is this a new hole at the highest possible address?
77199 */
77200 @@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77201 mm->free_area_cache = addr;
77202
77203 /* dont allow allocations above current base */
77204 - if (mm->free_area_cache > mm->mmap_base)
77205 + if (mm->free_area_cache > mm->mmap_base) {
77206 mm->free_area_cache = mm->mmap_base;
77207 + mm->cached_hole_size = ~0UL;
77208 + }
77209 }
77210
77211 unsigned long
77212 @@ -1545,6 +1771,27 @@ out:
77213 return prev ? prev->vm_next : vma;
77214 }
77215
77216 +#ifdef CONFIG_PAX_SEGMEXEC
77217 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77218 +{
77219 + struct vm_area_struct *vma_m;
77220 +
77221 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77222 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77223 + BUG_ON(vma->vm_mirror);
77224 + return NULL;
77225 + }
77226 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77227 + vma_m = vma->vm_mirror;
77228 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77229 + BUG_ON(vma->vm_file != vma_m->vm_file);
77230 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77231 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
77232 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
77233 + return vma_m;
77234 +}
77235 +#endif
77236 +
77237 /*
77238 * Verify that the stack growth is acceptable and
77239 * update accounting. This is shared with both the
77240 @@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77241 return -ENOMEM;
77242
77243 /* Stack limit test */
77244 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
77245 if (size > rlim[RLIMIT_STACK].rlim_cur)
77246 return -ENOMEM;
77247
77248 @@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77249 unsigned long limit;
77250 locked = mm->locked_vm + grow;
77251 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
77252 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77253 if (locked > limit && !capable(CAP_IPC_LOCK))
77254 return -ENOMEM;
77255 }
77256 @@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77257 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77258 * vma is the last one with address > vma->vm_end. Have to extend vma.
77259 */
77260 +#ifndef CONFIG_IA64
77261 +static
77262 +#endif
77263 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77264 {
77265 int error;
77266 + bool locknext;
77267
77268 if (!(vma->vm_flags & VM_GROWSUP))
77269 return -EFAULT;
77270
77271 + /* Also guard against wrapping around to address 0. */
77272 + if (address < PAGE_ALIGN(address+1))
77273 + address = PAGE_ALIGN(address+1);
77274 + else
77275 + return -ENOMEM;
77276 +
77277 /*
77278 * We must make sure the anon_vma is allocated
77279 * so that the anon_vma locking is not a noop.
77280 */
77281 if (unlikely(anon_vma_prepare(vma)))
77282 return -ENOMEM;
77283 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77284 + if (locknext && anon_vma_prepare(vma->vm_next))
77285 + return -ENOMEM;
77286 anon_vma_lock(vma);
77287 + if (locknext)
77288 + anon_vma_lock(vma->vm_next);
77289
77290 /*
77291 * vma->vm_start/vm_end cannot change under us because the caller
77292 * is required to hold the mmap_sem in read mode. We need the
77293 - * anon_vma lock to serialize against concurrent expand_stacks.
77294 - * Also guard against wrapping around to address 0.
77295 + * anon_vma locks to serialize against concurrent expand_stacks
77296 + * and expand_upwards.
77297 */
77298 - if (address < PAGE_ALIGN(address+4))
77299 - address = PAGE_ALIGN(address+4);
77300 - else {
77301 - anon_vma_unlock(vma);
77302 - return -ENOMEM;
77303 - }
77304 error = 0;
77305
77306 /* Somebody else might have raced and expanded it already */
77307 - if (address > vma->vm_end) {
77308 + 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)
77309 + error = -ENOMEM;
77310 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77311 unsigned long size, grow;
77312
77313 size = address - vma->vm_start;
77314 @@ -1643,6 +1903,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77315 vma->vm_end = address;
77316 }
77317 }
77318 + if (locknext)
77319 + anon_vma_unlock(vma->vm_next);
77320 anon_vma_unlock(vma);
77321 return error;
77322 }
77323 @@ -1655,6 +1917,8 @@ static int expand_downwards(struct vm_area_struct *vma,
77324 unsigned long address)
77325 {
77326 int error;
77327 + bool lockprev = false;
77328 + struct vm_area_struct *prev;
77329
77330 /*
77331 * We must make sure the anon_vma is allocated
77332 @@ -1668,6 +1932,15 @@ static int expand_downwards(struct vm_area_struct *vma,
77333 if (error)
77334 return error;
77335
77336 + prev = vma->vm_prev;
77337 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77338 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77339 +#endif
77340 + if (lockprev && anon_vma_prepare(prev))
77341 + return -ENOMEM;
77342 + if (lockprev)
77343 + anon_vma_lock(prev);
77344 +
77345 anon_vma_lock(vma);
77346
77347 /*
77348 @@ -1677,9 +1950,17 @@ static int expand_downwards(struct vm_area_struct *vma,
77349 */
77350
77351 /* Somebody else might have raced and expanded it already */
77352 - if (address < vma->vm_start) {
77353 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77354 + error = -ENOMEM;
77355 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77356 unsigned long size, grow;
77357
77358 +#ifdef CONFIG_PAX_SEGMEXEC
77359 + struct vm_area_struct *vma_m;
77360 +
77361 + vma_m = pax_find_mirror_vma(vma);
77362 +#endif
77363 +
77364 size = vma->vm_end - address;
77365 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77366
77367 @@ -1689,10 +1970,22 @@ static int expand_downwards(struct vm_area_struct *vma,
77368 if (!error) {
77369 vma->vm_start = address;
77370 vma->vm_pgoff -= grow;
77371 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77372 +
77373 +#ifdef CONFIG_PAX_SEGMEXEC
77374 + if (vma_m) {
77375 + vma_m->vm_start -= grow << PAGE_SHIFT;
77376 + vma_m->vm_pgoff -= grow;
77377 + }
77378 +#endif
77379 +
77380 +
77381 }
77382 }
77383 }
77384 anon_vma_unlock(vma);
77385 + if (lockprev)
77386 + anon_vma_unlock(prev);
77387 return error;
77388 }
77389
77390 @@ -1768,6 +2061,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77391 do {
77392 long nrpages = vma_pages(vma);
77393
77394 +#ifdef CONFIG_PAX_SEGMEXEC
77395 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77396 + vma = remove_vma(vma);
77397 + continue;
77398 + }
77399 +#endif
77400 +
77401 mm->total_vm -= nrpages;
77402 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77403 vma = remove_vma(vma);
77404 @@ -1813,6 +2113,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77405 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77406 vma->vm_prev = NULL;
77407 do {
77408 +
77409 +#ifdef CONFIG_PAX_SEGMEXEC
77410 + if (vma->vm_mirror) {
77411 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77412 + vma->vm_mirror->vm_mirror = NULL;
77413 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
77414 + vma->vm_mirror = NULL;
77415 + }
77416 +#endif
77417 +
77418 rb_erase(&vma->vm_rb, &mm->mm_rb);
77419 mm->map_count--;
77420 tail_vma = vma;
77421 @@ -1840,10 +2150,25 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77422 struct mempolicy *pol;
77423 struct vm_area_struct *new;
77424
77425 +#ifdef CONFIG_PAX_SEGMEXEC
77426 + struct vm_area_struct *vma_m, *new_m = NULL;
77427 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77428 +#endif
77429 +
77430 if (is_vm_hugetlb_page(vma) && (addr &
77431 ~(huge_page_mask(hstate_vma(vma)))))
77432 return -EINVAL;
77433
77434 +#ifdef CONFIG_PAX_SEGMEXEC
77435 + vma_m = pax_find_mirror_vma(vma);
77436 +
77437 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77438 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77439 + if (mm->map_count >= sysctl_max_map_count-1)
77440 + return -ENOMEM;
77441 + } else
77442 +#endif
77443 +
77444 if (mm->map_count >= sysctl_max_map_count)
77445 return -ENOMEM;
77446
77447 @@ -1851,6 +2176,16 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77448 if (!new)
77449 return -ENOMEM;
77450
77451 +#ifdef CONFIG_PAX_SEGMEXEC
77452 + if (vma_m) {
77453 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77454 + if (!new_m) {
77455 + kmem_cache_free(vm_area_cachep, new);
77456 + return -ENOMEM;
77457 + }
77458 + }
77459 +#endif
77460 +
77461 /* most fields are the same, copy all, and then fixup */
77462 *new = *vma;
77463
77464 @@ -1861,8 +2196,29 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77465 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77466 }
77467
77468 +#ifdef CONFIG_PAX_SEGMEXEC
77469 + if (vma_m) {
77470 + *new_m = *vma_m;
77471 + new_m->vm_mirror = new;
77472 + new->vm_mirror = new_m;
77473 +
77474 + if (new_below)
77475 + new_m->vm_end = addr_m;
77476 + else {
77477 + new_m->vm_start = addr_m;
77478 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77479 + }
77480 + }
77481 +#endif
77482 +
77483 pol = mpol_dup(vma_policy(vma));
77484 if (IS_ERR(pol)) {
77485 +
77486 +#ifdef CONFIG_PAX_SEGMEXEC
77487 + if (new_m)
77488 + kmem_cache_free(vm_area_cachep, new_m);
77489 +#endif
77490 +
77491 kmem_cache_free(vm_area_cachep, new);
77492 return PTR_ERR(pol);
77493 }
77494 @@ -1883,6 +2239,28 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77495 else
77496 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77497
77498 +#ifdef CONFIG_PAX_SEGMEXEC
77499 + if (vma_m) {
77500 + mpol_get(pol);
77501 + vma_set_policy(new_m, pol);
77502 +
77503 + if (new_m->vm_file) {
77504 + get_file(new_m->vm_file);
77505 + if (vma_m->vm_flags & VM_EXECUTABLE)
77506 + added_exe_file_vma(mm);
77507 + }
77508 +
77509 + if (new_m->vm_ops && new_m->vm_ops->open)
77510 + new_m->vm_ops->open(new_m);
77511 +
77512 + if (new_below)
77513 + vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77514 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77515 + else
77516 + vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77517 + }
77518 +#endif
77519 +
77520 return 0;
77521 }
77522
77523 @@ -1891,11 +2269,30 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77524 * work. This now handles partial unmappings.
77525 * Jeremy Fitzhardinge <jeremy@goop.org>
77526 */
77527 +#ifdef CONFIG_PAX_SEGMEXEC
77528 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77529 {
77530 + int ret = __do_munmap(mm, start, len);
77531 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77532 + return ret;
77533 +
77534 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77535 +}
77536 +
77537 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77538 +#else
77539 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77540 +#endif
77541 +{
77542 unsigned long end;
77543 struct vm_area_struct *vma, *prev, *last;
77544
77545 + /*
77546 + * mm->mmap_sem is required to protect against another thread
77547 + * changing the mappings in case we sleep.
77548 + */
77549 + verify_mm_writelocked(mm);
77550 +
77551 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77552 return -EINVAL;
77553
77554 @@ -1959,6 +2356,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77555 /* Fix up all other VM information */
77556 remove_vma_list(mm, vma);
77557
77558 + track_exec_limit(mm, start, end, 0UL);
77559 +
77560 return 0;
77561 }
77562
77563 @@ -1971,22 +2370,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77564
77565 profile_munmap(addr);
77566
77567 +#ifdef CONFIG_PAX_SEGMEXEC
77568 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77569 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
77570 + return -EINVAL;
77571 +#endif
77572 +
77573 down_write(&mm->mmap_sem);
77574 ret = do_munmap(mm, addr, len);
77575 up_write(&mm->mmap_sem);
77576 return ret;
77577 }
77578
77579 -static inline void verify_mm_writelocked(struct mm_struct *mm)
77580 -{
77581 -#ifdef CONFIG_DEBUG_VM
77582 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77583 - WARN_ON(1);
77584 - up_read(&mm->mmap_sem);
77585 - }
77586 -#endif
77587 -}
77588 -
77589 /*
77590 * this is really a simplified "do_mmap". it only handles
77591 * anonymous maps. eventually we may be able to do some
77592 @@ -2000,6 +2395,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77593 struct rb_node ** rb_link, * rb_parent;
77594 pgoff_t pgoff = addr >> PAGE_SHIFT;
77595 int error;
77596 + unsigned long charged;
77597
77598 len = PAGE_ALIGN(len);
77599 if (!len)
77600 @@ -2011,16 +2407,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77601
77602 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77603
77604 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77605 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77606 + flags &= ~VM_EXEC;
77607 +
77608 +#ifdef CONFIG_PAX_MPROTECT
77609 + if (mm->pax_flags & MF_PAX_MPROTECT)
77610 + flags &= ~VM_MAYEXEC;
77611 +#endif
77612 +
77613 + }
77614 +#endif
77615 +
77616 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77617 if (error & ~PAGE_MASK)
77618 return error;
77619
77620 + charged = len >> PAGE_SHIFT;
77621 +
77622 /*
77623 * mlock MCL_FUTURE?
77624 */
77625 if (mm->def_flags & VM_LOCKED) {
77626 unsigned long locked, lock_limit;
77627 - locked = len >> PAGE_SHIFT;
77628 + locked = charged;
77629 locked += mm->locked_vm;
77630 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
77631 lock_limit >>= PAGE_SHIFT;
77632 @@ -2037,22 +2447,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77633 /*
77634 * Clear old maps. this also does some error checking for us
77635 */
77636 - munmap_back:
77637 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77638 if (vma && vma->vm_start < addr + len) {
77639 if (do_munmap(mm, addr, len))
77640 return -ENOMEM;
77641 - goto munmap_back;
77642 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77643 + BUG_ON(vma && vma->vm_start < addr + len);
77644 }
77645
77646 /* Check against address space limits *after* clearing old maps... */
77647 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77648 + if (!may_expand_vm(mm, charged))
77649 return -ENOMEM;
77650
77651 if (mm->map_count > sysctl_max_map_count)
77652 return -ENOMEM;
77653
77654 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
77655 + if (security_vm_enough_memory(charged))
77656 return -ENOMEM;
77657
77658 /* Can we just expand an old private anonymous mapping? */
77659 @@ -2066,7 +2476,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77660 */
77661 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77662 if (!vma) {
77663 - vm_unacct_memory(len >> PAGE_SHIFT);
77664 + vm_unacct_memory(charged);
77665 return -ENOMEM;
77666 }
77667
77668 @@ -2078,11 +2488,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77669 vma->vm_page_prot = vm_get_page_prot(flags);
77670 vma_link(mm, vma, prev, rb_link, rb_parent);
77671 out:
77672 - mm->total_vm += len >> PAGE_SHIFT;
77673 + mm->total_vm += charged;
77674 if (flags & VM_LOCKED) {
77675 if (!mlock_vma_pages_range(vma, addr, addr + len))
77676 - mm->locked_vm += (len >> PAGE_SHIFT);
77677 + mm->locked_vm += charged;
77678 }
77679 + track_exec_limit(mm, addr, addr + len, flags);
77680 return addr;
77681 }
77682
77683 @@ -2129,8 +2540,10 @@ void exit_mmap(struct mm_struct *mm)
77684 * Walk the list again, actually closing and freeing it,
77685 * with preemption enabled, without holding any MM locks.
77686 */
77687 - while (vma)
77688 + while (vma) {
77689 + vma->vm_mirror = NULL;
77690 vma = remove_vma(vma);
77691 + }
77692
77693 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
77694 }
77695 @@ -2144,6 +2557,10 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77696 struct vm_area_struct * __vma, * prev;
77697 struct rb_node ** rb_link, * rb_parent;
77698
77699 +#ifdef CONFIG_PAX_SEGMEXEC
77700 + struct vm_area_struct *vma_m = NULL;
77701 +#endif
77702 +
77703 /*
77704 * The vm_pgoff of a purely anonymous vma should be irrelevant
77705 * until its first write fault, when page's anon_vma and index
77706 @@ -2166,7 +2583,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77707 if ((vma->vm_flags & VM_ACCOUNT) &&
77708 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77709 return -ENOMEM;
77710 +
77711 +#ifdef CONFIG_PAX_SEGMEXEC
77712 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77713 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77714 + if (!vma_m)
77715 + return -ENOMEM;
77716 + }
77717 +#endif
77718 +
77719 vma_link(mm, vma, prev, rb_link, rb_parent);
77720 +
77721 +#ifdef CONFIG_PAX_SEGMEXEC
77722 + if (vma_m)
77723 + pax_mirror_vma(vma_m, vma);
77724 +#endif
77725 +
77726 return 0;
77727 }
77728
77729 @@ -2184,6 +2616,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77730 struct rb_node **rb_link, *rb_parent;
77731 struct mempolicy *pol;
77732
77733 + BUG_ON(vma->vm_mirror);
77734 +
77735 /*
77736 * If anonymous vma has not yet been faulted, update new pgoff
77737 * to match new location, to increase its chance of merging.
77738 @@ -2227,6 +2661,35 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77739 return new_vma;
77740 }
77741
77742 +#ifdef CONFIG_PAX_SEGMEXEC
77743 +void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77744 +{
77745 + struct vm_area_struct *prev_m;
77746 + struct rb_node **rb_link_m, *rb_parent_m;
77747 + struct mempolicy *pol_m;
77748 +
77749 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77750 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77751 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77752 + *vma_m = *vma;
77753 + pol_m = vma_policy(vma_m);
77754 + mpol_get(pol_m);
77755 + vma_set_policy(vma_m, pol_m);
77756 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77757 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77758 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77759 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77760 + if (vma_m->vm_file)
77761 + get_file(vma_m->vm_file);
77762 + if (vma_m->vm_ops && vma_m->vm_ops->open)
77763 + vma_m->vm_ops->open(vma_m);
77764 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
77765 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77766 + vma_m->vm_mirror = vma;
77767 + vma->vm_mirror = vma_m;
77768 +}
77769 +#endif
77770 +
77771 /*
77772 * Return true if the calling process may expand its vm space by the passed
77773 * number of pages
77774 @@ -2237,7 +2700,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77775 unsigned long lim;
77776
77777 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
77778 -
77779 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77780 if (cur + npages > lim)
77781 return 0;
77782 return 1;
77783 @@ -2307,6 +2770,22 @@ int install_special_mapping(struct mm_struct *mm,
77784 vma->vm_start = addr;
77785 vma->vm_end = addr + len;
77786
77787 +#ifdef CONFIG_PAX_MPROTECT
77788 + if (mm->pax_flags & MF_PAX_MPROTECT) {
77789 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
77790 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77791 + return -EPERM;
77792 + if (!(vm_flags & VM_EXEC))
77793 + vm_flags &= ~VM_MAYEXEC;
77794 +#else
77795 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77796 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77797 +#endif
77798 + else
77799 + vm_flags &= ~VM_MAYWRITE;
77800 + }
77801 +#endif
77802 +
77803 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77804 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77805
77806 diff --git a/mm/mprotect.c b/mm/mprotect.c
77807 index 1737c7e..c7faeb4 100644
77808 --- a/mm/mprotect.c
77809 +++ b/mm/mprotect.c
77810 @@ -24,10 +24,16 @@
77811 #include <linux/mmu_notifier.h>
77812 #include <linux/migrate.h>
77813 #include <linux/perf_event.h>
77814 +
77815 +#ifdef CONFIG_PAX_MPROTECT
77816 +#include <linux/elf.h>
77817 +#endif
77818 +
77819 #include <asm/uaccess.h>
77820 #include <asm/pgtable.h>
77821 #include <asm/cacheflush.h>
77822 #include <asm/tlbflush.h>
77823 +#include <asm/mmu_context.h>
77824
77825 #ifndef pgprot_modify
77826 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77827 @@ -132,6 +138,48 @@ static void change_protection(struct vm_area_struct *vma,
77828 flush_tlb_range(vma, start, end);
77829 }
77830
77831 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77832 +/* called while holding the mmap semaphor for writing except stack expansion */
77833 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77834 +{
77835 + unsigned long oldlimit, newlimit = 0UL;
77836 +
77837 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
77838 + return;
77839 +
77840 + spin_lock(&mm->page_table_lock);
77841 + oldlimit = mm->context.user_cs_limit;
77842 + if ((prot & VM_EXEC) && oldlimit < end)
77843 + /* USER_CS limit moved up */
77844 + newlimit = end;
77845 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77846 + /* USER_CS limit moved down */
77847 + newlimit = start;
77848 +
77849 + if (newlimit) {
77850 + mm->context.user_cs_limit = newlimit;
77851 +
77852 +#ifdef CONFIG_SMP
77853 + wmb();
77854 + cpus_clear(mm->context.cpu_user_cs_mask);
77855 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77856 +#endif
77857 +
77858 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77859 + }
77860 + spin_unlock(&mm->page_table_lock);
77861 + if (newlimit == end) {
77862 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
77863 +
77864 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
77865 + if (is_vm_hugetlb_page(vma))
77866 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77867 + else
77868 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
77869 + }
77870 +}
77871 +#endif
77872 +
77873 int
77874 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77875 unsigned long start, unsigned long end, unsigned long newflags)
77876 @@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77877 int error;
77878 int dirty_accountable = 0;
77879
77880 +#ifdef CONFIG_PAX_SEGMEXEC
77881 + struct vm_area_struct *vma_m = NULL;
77882 + unsigned long start_m, end_m;
77883 +
77884 + start_m = start + SEGMEXEC_TASK_SIZE;
77885 + end_m = end + SEGMEXEC_TASK_SIZE;
77886 +#endif
77887 +
77888 if (newflags == oldflags) {
77889 *pprev = vma;
77890 return 0;
77891 }
77892
77893 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77894 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77895 +
77896 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77897 + return -ENOMEM;
77898 +
77899 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77900 + return -ENOMEM;
77901 + }
77902 +
77903 /*
77904 * If we make a private mapping writable we increase our commit;
77905 * but (without finer accounting) cannot reduce our commit if we
77906 @@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77907 }
77908 }
77909
77910 +#ifdef CONFIG_PAX_SEGMEXEC
77911 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77912 + if (start != vma->vm_start) {
77913 + error = split_vma(mm, vma, start, 1);
77914 + if (error)
77915 + goto fail;
77916 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77917 + *pprev = (*pprev)->vm_next;
77918 + }
77919 +
77920 + if (end != vma->vm_end) {
77921 + error = split_vma(mm, vma, end, 0);
77922 + if (error)
77923 + goto fail;
77924 + }
77925 +
77926 + if (pax_find_mirror_vma(vma)) {
77927 + error = __do_munmap(mm, start_m, end_m - start_m);
77928 + if (error)
77929 + goto fail;
77930 + } else {
77931 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77932 + if (!vma_m) {
77933 + error = -ENOMEM;
77934 + goto fail;
77935 + }
77936 + vma->vm_flags = newflags;
77937 + pax_mirror_vma(vma_m, vma);
77938 + }
77939 + }
77940 +#endif
77941 +
77942 /*
77943 * First try to merge with previous and/or next vma.
77944 */
77945 @@ -195,9 +293,21 @@ success:
77946 * vm_flags and vm_page_prot are protected by the mmap_sem
77947 * held in write mode.
77948 */
77949 +
77950 +#ifdef CONFIG_PAX_SEGMEXEC
77951 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77952 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77953 +#endif
77954 +
77955 vma->vm_flags = newflags;
77956 +
77957 +#ifdef CONFIG_PAX_MPROTECT
77958 + if (mm->binfmt && mm->binfmt->handle_mprotect)
77959 + mm->binfmt->handle_mprotect(vma, newflags);
77960 +#endif
77961 +
77962 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77963 - vm_get_page_prot(newflags));
77964 + vm_get_page_prot(vma->vm_flags));
77965
77966 if (vma_wants_writenotify(vma)) {
77967 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77968 @@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77969 end = start + len;
77970 if (end <= start)
77971 return -ENOMEM;
77972 +
77973 +#ifdef CONFIG_PAX_SEGMEXEC
77974 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77975 + if (end > SEGMEXEC_TASK_SIZE)
77976 + return -EINVAL;
77977 + } else
77978 +#endif
77979 +
77980 + if (end > TASK_SIZE)
77981 + return -EINVAL;
77982 +
77983 if (!arch_validate_prot(prot))
77984 return -EINVAL;
77985
77986 @@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77987 /*
77988 * Does the application expect PROT_READ to imply PROT_EXEC:
77989 */
77990 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77991 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77992 prot |= PROT_EXEC;
77993
77994 vm_flags = calc_vm_prot_bits(prot);
77995 @@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77996 if (start > vma->vm_start)
77997 prev = vma;
77998
77999 +#ifdef CONFIG_PAX_MPROTECT
78000 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
78001 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
78002 +#endif
78003 +
78004 for (nstart = start ; ; ) {
78005 unsigned long newflags;
78006
78007 @@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78008
78009 /* newflags >> 4 shift VM_MAY% in place of VM_% */
78010 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
78011 + if (prot & (PROT_WRITE | PROT_EXEC))
78012 + gr_log_rwxmprotect(vma->vm_file);
78013 +
78014 + error = -EACCES;
78015 + goto out;
78016 + }
78017 +
78018 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
78019 error = -EACCES;
78020 goto out;
78021 }
78022 @@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78023 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
78024 if (error)
78025 goto out;
78026 +
78027 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
78028 +
78029 nstart = tmp;
78030
78031 if (nstart < prev->vm_end)
78032 diff --git a/mm/mremap.c b/mm/mremap.c
78033 index 3e98d79..1706cec 100644
78034 --- a/mm/mremap.c
78035 +++ b/mm/mremap.c
78036 @@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
78037 continue;
78038 pte = ptep_clear_flush(vma, old_addr, old_pte);
78039 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
78040 +
78041 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78042 + if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
78043 + pte = pte_exprotect(pte);
78044 +#endif
78045 +
78046 set_pte_at(mm, new_addr, new_pte, pte);
78047 }
78048
78049 @@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
78050 if (is_vm_hugetlb_page(vma))
78051 goto Einval;
78052
78053 +#ifdef CONFIG_PAX_SEGMEXEC
78054 + if (pax_find_mirror_vma(vma))
78055 + goto Einval;
78056 +#endif
78057 +
78058 /* We can't remap across vm area boundaries */
78059 if (old_len > vma->vm_end - addr)
78060 goto Efault;
78061 @@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned long addr,
78062 unsigned long ret = -EINVAL;
78063 unsigned long charged = 0;
78064 unsigned long map_flags;
78065 + unsigned long pax_task_size = TASK_SIZE;
78066
78067 if (new_addr & ~PAGE_MASK)
78068 goto out;
78069
78070 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
78071 +#ifdef CONFIG_PAX_SEGMEXEC
78072 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
78073 + pax_task_size = SEGMEXEC_TASK_SIZE;
78074 +#endif
78075 +
78076 + pax_task_size -= PAGE_SIZE;
78077 +
78078 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
78079 goto out;
78080
78081 /* Check if the location we're moving into overlaps the
78082 * old location at all, and fail if it does.
78083 */
78084 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
78085 - goto out;
78086 -
78087 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
78088 + if (addr + old_len > new_addr && new_addr + new_len > addr)
78089 goto out;
78090
78091 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
78092 @@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long addr,
78093 struct vm_area_struct *vma;
78094 unsigned long ret = -EINVAL;
78095 unsigned long charged = 0;
78096 + unsigned long pax_task_size = TASK_SIZE;
78097
78098 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
78099 goto out;
78100 @@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long addr,
78101 if (!new_len)
78102 goto out;
78103
78104 +#ifdef CONFIG_PAX_SEGMEXEC
78105 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
78106 + pax_task_size = SEGMEXEC_TASK_SIZE;
78107 +#endif
78108 +
78109 + pax_task_size -= PAGE_SIZE;
78110 +
78111 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
78112 + old_len > pax_task_size || addr > pax_task_size-old_len)
78113 + goto out;
78114 +
78115 if (flags & MREMAP_FIXED) {
78116 if (flags & MREMAP_MAYMOVE)
78117 ret = mremap_to(addr, old_len, new_addr, new_len);
78118 @@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long addr,
78119 addr + new_len);
78120 }
78121 ret = addr;
78122 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
78123 goto out;
78124 }
78125 }
78126 @@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long addr,
78127 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
78128 if (ret)
78129 goto out;
78130 +
78131 + map_flags = vma->vm_flags;
78132 ret = move_vma(vma, addr, old_len, new_len, new_addr);
78133 + if (!(ret & ~PAGE_MASK)) {
78134 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
78135 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
78136 + }
78137 }
78138 out:
78139 if (ret & ~PAGE_MASK)
78140 diff --git a/mm/nommu.c b/mm/nommu.c
78141 index 406e8d4..53970d3 100644
78142 --- a/mm/nommu.c
78143 +++ b/mm/nommu.c
78144 @@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
78145 int sysctl_overcommit_ratio = 50; /* default is 50% */
78146 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
78147 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
78148 -int heap_stack_gap = 0;
78149
78150 atomic_long_t mmap_pages_allocated;
78151
78152 @@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
78153 EXPORT_SYMBOL(find_vma);
78154
78155 /*
78156 - * find a VMA
78157 - * - we don't extend stack VMAs under NOMMU conditions
78158 - */
78159 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
78160 -{
78161 - return find_vma(mm, addr);
78162 -}
78163 -
78164 -/*
78165 * expand a stack to a given address
78166 * - not supported under NOMMU conditions
78167 */
78168 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78169 index 3ecab7e..594a471 100644
78170 --- a/mm/page_alloc.c
78171 +++ b/mm/page_alloc.c
78172 @@ -289,7 +289,7 @@ out:
78173 * This usage means that zero-order pages may not be compound.
78174 */
78175
78176 -static void free_compound_page(struct page *page)
78177 +void free_compound_page(struct page *page)
78178 {
78179 __free_pages_ok(page, compound_order(page));
78180 }
78181 @@ -587,6 +587,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78182 int bad = 0;
78183 int wasMlocked = __TestClearPageMlocked(page);
78184
78185 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
78186 + unsigned long index = 1UL << order;
78187 +#endif
78188 +
78189 kmemcheck_free_shadow(page, order);
78190
78191 for (i = 0 ; i < (1 << order) ; ++i)
78192 @@ -599,6 +603,12 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78193 debug_check_no_obj_freed(page_address(page),
78194 PAGE_SIZE << order);
78195 }
78196 +
78197 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
78198 + for (; index; --index)
78199 + sanitize_highpage(page + index - 1);
78200 +#endif
78201 +
78202 arch_free_page(page, order);
78203 kernel_map_pages(page, 1 << order, 0);
78204
78205 @@ -702,8 +712,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78206 arch_alloc_page(page, order);
78207 kernel_map_pages(page, 1 << order, 1);
78208
78209 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
78210 if (gfp_flags & __GFP_ZERO)
78211 prep_zero_page(page, order, gfp_flags);
78212 +#endif
78213
78214 if (order && (gfp_flags & __GFP_COMP))
78215 prep_compound_page(page, order);
78216 @@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct page *page, int cold)
78217 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
78218 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
78219 }
78220 +
78221 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
78222 + sanitize_highpage(page);
78223 +#endif
78224 +
78225 arch_free_page(page, 0);
78226 kernel_map_pages(page, 1, 0);
78227
78228 @@ -2179,6 +2196,8 @@ void show_free_areas(void)
78229 int cpu;
78230 struct zone *zone;
78231
78232 + pax_track_stack();
78233 +
78234 for_each_populated_zone(zone) {
78235 show_node(zone);
78236 printk("%s per-cpu:\n", zone->name);
78237 @@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct pglist_data *pgdat,
78238 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
78239 }
78240 #else
78241 -static void inline setup_usemap(struct pglist_data *pgdat,
78242 +static inline void setup_usemap(struct pglist_data *pgdat,
78243 struct zone *zone, unsigned long zonesize) {}
78244 #endif /* CONFIG_SPARSEMEM */
78245
78246 diff --git a/mm/percpu.c b/mm/percpu.c
78247 index c90614a..5f7b7b8 100644
78248 --- a/mm/percpu.c
78249 +++ b/mm/percpu.c
78250 @@ -115,7 +115,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78251 static unsigned int pcpu_high_unit_cpu __read_mostly;
78252
78253 /* the address of the first chunk which starts with the kernel static area */
78254 -void *pcpu_base_addr __read_mostly;
78255 +void *pcpu_base_addr __read_only;
78256 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78257
78258 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78259 diff --git a/mm/rmap.c b/mm/rmap.c
78260 index dd43373..d848cd7 100644
78261 --- a/mm/rmap.c
78262 +++ b/mm/rmap.c
78263 @@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78264 /* page_table_lock to protect against threads */
78265 spin_lock(&mm->page_table_lock);
78266 if (likely(!vma->anon_vma)) {
78267 +
78268 +#ifdef CONFIG_PAX_SEGMEXEC
78269 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78270 +
78271 + if (vma_m) {
78272 + BUG_ON(vma_m->anon_vma);
78273 + vma_m->anon_vma = anon_vma;
78274 + list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
78275 + }
78276 +#endif
78277 +
78278 vma->anon_vma = anon_vma;
78279 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
78280 allocated = NULL;
78281 diff --git a/mm/shmem.c b/mm/shmem.c
78282 index 3e0005b..1d659a8 100644
78283 --- a/mm/shmem.c
78284 +++ b/mm/shmem.c
78285 @@ -31,7 +31,7 @@
78286 #include <linux/swap.h>
78287 #include <linux/ima.h>
78288
78289 -static struct vfsmount *shm_mnt;
78290 +struct vfsmount *shm_mnt;
78291
78292 #ifdef CONFIG_SHMEM
78293 /*
78294 @@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
78295 goto unlock;
78296 }
78297 entry = shmem_swp_entry(info, index, NULL);
78298 + if (!entry)
78299 + goto unlock;
78300 if (entry->val) {
78301 /*
78302 * The more uptodate page coming down from a stacked
78303 @@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
78304 struct vm_area_struct pvma;
78305 struct page *page;
78306
78307 + pax_track_stack();
78308 +
78309 spol = mpol_cond_copy(&mpol,
78310 mpol_shared_policy_lookup(&info->policy, idx));
78311
78312 @@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
78313
78314 info = SHMEM_I(inode);
78315 inode->i_size = len-1;
78316 - if (len <= (char *)inode - (char *)info) {
78317 + if (len <= (char *)inode - (char *)info && len <= 64) {
78318 /* do it inline */
78319 memcpy(info, symname, len);
78320 inode->i_op = &shmem_symlink_inline_operations;
78321 @@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78322 int err = -ENOMEM;
78323
78324 /* Round up to L1_CACHE_BYTES to resist false sharing */
78325 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78326 - L1_CACHE_BYTES), GFP_KERNEL);
78327 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78328 if (!sbinfo)
78329 return -ENOMEM;
78330
78331 diff --git a/mm/slab.c b/mm/slab.c
78332 index c8d466a..909e01e 100644
78333 --- a/mm/slab.c
78334 +++ b/mm/slab.c
78335 @@ -174,7 +174,7 @@
78336
78337 /* Legal flag mask for kmem_cache_create(). */
78338 #if DEBUG
78339 -# define CREATE_MASK (SLAB_RED_ZONE | \
78340 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
78341 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
78342 SLAB_CACHE_DMA | \
78343 SLAB_STORE_USER | \
78344 @@ -182,7 +182,7 @@
78345 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78346 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
78347 #else
78348 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
78349 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
78350 SLAB_CACHE_DMA | \
78351 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
78352 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78353 @@ -308,7 +308,7 @@ struct kmem_list3 {
78354 * Need this for bootstrapping a per node allocator.
78355 */
78356 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78357 -struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78358 +struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78359 #define CACHE_CACHE 0
78360 #define SIZE_AC MAX_NUMNODES
78361 #define SIZE_L3 (2 * MAX_NUMNODES)
78362 @@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78363 if ((x)->max_freeable < i) \
78364 (x)->max_freeable = i; \
78365 } while (0)
78366 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78367 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78368 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78369 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78370 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78371 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78372 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78373 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78374 #else
78375 #define STATS_INC_ACTIVE(x) do { } while (0)
78376 #define STATS_DEC_ACTIVE(x) do { } while (0)
78377 @@ -558,7 +558,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78378 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78379 */
78380 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78381 - const struct slab *slab, void *obj)
78382 + const struct slab *slab, const void *obj)
78383 {
78384 u32 offset = (obj - slab->s_mem);
78385 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78386 @@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
78387 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
78388 sizes[INDEX_AC].cs_size,
78389 ARCH_KMALLOC_MINALIGN,
78390 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78391 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78392 NULL);
78393
78394 if (INDEX_AC != INDEX_L3) {
78395 @@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
78396 kmem_cache_create(names[INDEX_L3].name,
78397 sizes[INDEX_L3].cs_size,
78398 ARCH_KMALLOC_MINALIGN,
78399 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78400 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78401 NULL);
78402 }
78403
78404 @@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
78405 sizes->cs_cachep = kmem_cache_create(names->name,
78406 sizes->cs_size,
78407 ARCH_KMALLOC_MINALIGN,
78408 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78409 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78410 NULL);
78411 }
78412 #ifdef CONFIG_ZONE_DMA
78413 @@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, void *p)
78414 }
78415 /* cpu stats */
78416 {
78417 - unsigned long allochit = atomic_read(&cachep->allochit);
78418 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78419 - unsigned long freehit = atomic_read(&cachep->freehit);
78420 - unsigned long freemiss = atomic_read(&cachep->freemiss);
78421 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78422 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78423 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78424 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78425
78426 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78427 allochit, allocmiss, freehit, freemiss);
78428 @@ -4471,15 +4471,70 @@ static const struct file_operations proc_slabstats_operations = {
78429
78430 static int __init slab_proc_init(void)
78431 {
78432 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
78433 + mode_t gr_mode = S_IRUGO;
78434 +
78435 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78436 + gr_mode = S_IRUSR;
78437 +#endif
78438 +
78439 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
78440 #ifdef CONFIG_DEBUG_SLAB_LEAK
78441 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78442 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
78443 #endif
78444 return 0;
78445 }
78446 module_init(slab_proc_init);
78447 #endif
78448
78449 +void check_object_size(const void *ptr, unsigned long n, bool to)
78450 +{
78451 +
78452 +#ifdef CONFIG_PAX_USERCOPY
78453 + struct page *page;
78454 + struct kmem_cache *cachep = NULL;
78455 + struct slab *slabp;
78456 + unsigned int objnr;
78457 + unsigned long offset;
78458 + const char *type;
78459 +
78460 + if (!n)
78461 + return;
78462 +
78463 + type = "<null>";
78464 + if (ZERO_OR_NULL_PTR(ptr))
78465 + goto report;
78466 +
78467 + if (!virt_addr_valid(ptr))
78468 + return;
78469 +
78470 + page = virt_to_head_page(ptr);
78471 +
78472 + type = "<process stack>";
78473 + if (!PageSlab(page)) {
78474 + if (object_is_on_stack(ptr, n) == -1)
78475 + goto report;
78476 + return;
78477 + }
78478 +
78479 + cachep = page_get_cache(page);
78480 + type = cachep->name;
78481 + if (!(cachep->flags & SLAB_USERCOPY))
78482 + goto report;
78483 +
78484 + slabp = page_get_slab(page);
78485 + objnr = obj_to_index(cachep, slabp, ptr);
78486 + BUG_ON(objnr >= cachep->num);
78487 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78488 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
78489 + return;
78490 +
78491 +report:
78492 + pax_report_usercopy(ptr, n, to, type);
78493 +#endif
78494 +
78495 +}
78496 +EXPORT_SYMBOL(check_object_size);
78497 +
78498 /**
78499 * ksize - get the actual amount of memory allocated for a given object
78500 * @objp: Pointer to the object
78501 diff --git a/mm/slob.c b/mm/slob.c
78502 index 837ebd6..4712174 100644
78503 --- a/mm/slob.c
78504 +++ b/mm/slob.c
78505 @@ -29,7 +29,7 @@
78506 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
78507 * alloc_pages() directly, allocating compound pages so the page order
78508 * does not have to be separately tracked, and also stores the exact
78509 - * allocation size in page->private so that it can be used to accurately
78510 + * allocation size in slob_page->size so that it can be used to accurately
78511 * provide ksize(). These objects are detected in kfree() because slob_page()
78512 * is false for them.
78513 *
78514 @@ -58,6 +58,7 @@
78515 */
78516
78517 #include <linux/kernel.h>
78518 +#include <linux/sched.h>
78519 #include <linux/slab.h>
78520 #include <linux/mm.h>
78521 #include <linux/swap.h> /* struct reclaim_state */
78522 @@ -100,7 +101,8 @@ struct slob_page {
78523 unsigned long flags; /* mandatory */
78524 atomic_t _count; /* mandatory */
78525 slobidx_t units; /* free units left in page */
78526 - unsigned long pad[2];
78527 + unsigned long pad[1];
78528 + unsigned long size; /* size when >=PAGE_SIZE */
78529 slob_t *free; /* first free slob_t in page */
78530 struct list_head list; /* linked list of free pages */
78531 };
78532 @@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
78533 */
78534 static inline int is_slob_page(struct slob_page *sp)
78535 {
78536 - return PageSlab((struct page *)sp);
78537 + return PageSlab((struct page *)sp) && !sp->size;
78538 }
78539
78540 static inline void set_slob_page(struct slob_page *sp)
78541 @@ -148,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
78542
78543 static inline struct slob_page *slob_page(const void *addr)
78544 {
78545 - return (struct slob_page *)virt_to_page(addr);
78546 + return (struct slob_page *)virt_to_head_page(addr);
78547 }
78548
78549 /*
78550 @@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78551 /*
78552 * Return the size of a slob block.
78553 */
78554 -static slobidx_t slob_units(slob_t *s)
78555 +static slobidx_t slob_units(const slob_t *s)
78556 {
78557 if (s->units > 0)
78558 return s->units;
78559 @@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
78560 /*
78561 * Return the next free slob block pointer after this one.
78562 */
78563 -static slob_t *slob_next(slob_t *s)
78564 +static slob_t *slob_next(const slob_t *s)
78565 {
78566 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78567 slobidx_t next;
78568 @@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
78569 /*
78570 * Returns true if s is the last free block in its page.
78571 */
78572 -static int slob_last(slob_t *s)
78573 +static int slob_last(const slob_t *s)
78574 {
78575 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78576 }
78577 @@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78578 if (!page)
78579 return NULL;
78580
78581 + set_slob_page(page);
78582 return page_address(page);
78583 }
78584
78585 @@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78586 if (!b)
78587 return NULL;
78588 sp = slob_page(b);
78589 - set_slob_page(sp);
78590
78591 spin_lock_irqsave(&slob_lock, flags);
78592 sp->units = SLOB_UNITS(PAGE_SIZE);
78593 sp->free = b;
78594 + sp->size = 0;
78595 INIT_LIST_HEAD(&sp->list);
78596 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78597 set_slob_page_free(sp, slob_list);
78598 @@ -475,10 +478,9 @@ out:
78599 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
78600 #endif
78601
78602 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78603 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
78604 {
78605 - unsigned int *m;
78606 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78607 + slob_t *m;
78608 void *ret;
78609
78610 lockdep_trace_alloc(gfp);
78611 @@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78612
78613 if (!m)
78614 return NULL;
78615 - *m = size;
78616 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78617 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78618 + m[0].units = size;
78619 + m[1].units = align;
78620 ret = (void *)m + align;
78621
78622 trace_kmalloc_node(_RET_IP_, ret,
78623 @@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78624
78625 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
78626 if (ret) {
78627 - struct page *page;
78628 - page = virt_to_page(ret);
78629 - page->private = size;
78630 + struct slob_page *sp;
78631 + sp = slob_page(ret);
78632 + sp->size = size;
78633 }
78634
78635 trace_kmalloc_node(_RET_IP_, ret,
78636 size, PAGE_SIZE << order, gfp, node);
78637 }
78638
78639 - kmemleak_alloc(ret, size, 1, gfp);
78640 + return ret;
78641 +}
78642 +
78643 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78644 +{
78645 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78646 + void *ret = __kmalloc_node_align(size, gfp, node, align);
78647 +
78648 + if (!ZERO_OR_NULL_PTR(ret))
78649 + kmemleak_alloc(ret, size, 1, gfp);
78650 return ret;
78651 }
78652 EXPORT_SYMBOL(__kmalloc_node);
78653 @@ -528,13 +542,92 @@ void kfree(const void *block)
78654 sp = slob_page(block);
78655 if (is_slob_page(sp)) {
78656 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78657 - unsigned int *m = (unsigned int *)(block - align);
78658 - slob_free(m, *m + align);
78659 - } else
78660 + slob_t *m = (slob_t *)(block - align);
78661 + slob_free(m, m[0].units + align);
78662 + } else {
78663 + clear_slob_page(sp);
78664 + free_slob_page(sp);
78665 + sp->size = 0;
78666 put_page(&sp->page);
78667 + }
78668 }
78669 EXPORT_SYMBOL(kfree);
78670
78671 +void check_object_size(const void *ptr, unsigned long n, bool to)
78672 +{
78673 +
78674 +#ifdef CONFIG_PAX_USERCOPY
78675 + struct slob_page *sp;
78676 + const slob_t *free;
78677 + const void *base;
78678 + unsigned long flags;
78679 + const char *type;
78680 +
78681 + if (!n)
78682 + return;
78683 +
78684 + type = "<null>";
78685 + if (ZERO_OR_NULL_PTR(ptr))
78686 + goto report;
78687 +
78688 + if (!virt_addr_valid(ptr))
78689 + return;
78690 +
78691 + type = "<process stack>";
78692 + sp = slob_page(ptr);
78693 + if (!PageSlab((struct page*)sp)) {
78694 + if (object_is_on_stack(ptr, n) == -1)
78695 + goto report;
78696 + return;
78697 + }
78698 +
78699 + type = "<slob>";
78700 + if (sp->size) {
78701 + base = page_address(&sp->page);
78702 + if (base <= ptr && n <= sp->size - (ptr - base))
78703 + return;
78704 + goto report;
78705 + }
78706 +
78707 + /* some tricky double walking to find the chunk */
78708 + spin_lock_irqsave(&slob_lock, flags);
78709 + base = (void *)((unsigned long)ptr & PAGE_MASK);
78710 + free = sp->free;
78711 +
78712 + while (!slob_last(free) && (void *)free <= ptr) {
78713 + base = free + slob_units(free);
78714 + free = slob_next(free);
78715 + }
78716 +
78717 + while (base < (void *)free) {
78718 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78719 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
78720 + int offset;
78721 +
78722 + if (ptr < base + align)
78723 + break;
78724 +
78725 + offset = ptr - base - align;
78726 + if (offset >= m) {
78727 + base += size;
78728 + continue;
78729 + }
78730 +
78731 + if (n > m - offset)
78732 + break;
78733 +
78734 + spin_unlock_irqrestore(&slob_lock, flags);
78735 + return;
78736 + }
78737 +
78738 + spin_unlock_irqrestore(&slob_lock, flags);
78739 +report:
78740 + pax_report_usercopy(ptr, n, to, type);
78741 +#endif
78742 +
78743 +}
78744 +EXPORT_SYMBOL(check_object_size);
78745 +
78746 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78747 size_t ksize(const void *block)
78748 {
78749 @@ -547,10 +640,10 @@ size_t ksize(const void *block)
78750 sp = slob_page(block);
78751 if (is_slob_page(sp)) {
78752 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78753 - unsigned int *m = (unsigned int *)(block - align);
78754 - return SLOB_UNITS(*m) * SLOB_UNIT;
78755 + slob_t *m = (slob_t *)(block - align);
78756 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78757 } else
78758 - return sp->page.private;
78759 + return sp->size;
78760 }
78761 EXPORT_SYMBOL(ksize);
78762
78763 @@ -566,8 +659,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78764 {
78765 struct kmem_cache *c;
78766
78767 +#ifdef CONFIG_PAX_USERCOPY
78768 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
78769 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
78770 +#else
78771 c = slob_alloc(sizeof(struct kmem_cache),
78772 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
78773 +#endif
78774
78775 if (c) {
78776 c->name = name;
78777 @@ -605,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78778 {
78779 void *b;
78780
78781 +#ifdef CONFIG_PAX_USERCOPY
78782 + b = __kmalloc_node_align(c->size, flags, node, c->align);
78783 +#else
78784 if (c->size < PAGE_SIZE) {
78785 b = slob_alloc(c->size, flags, c->align, node);
78786 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
78787 SLOB_UNITS(c->size) * SLOB_UNIT,
78788 flags, node);
78789 } else {
78790 + struct slob_page *sp;
78791 +
78792 b = slob_new_pages(flags, get_order(c->size), node);
78793 + sp = slob_page(b);
78794 + sp->size = c->size;
78795 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
78796 PAGE_SIZE << get_order(c->size),
78797 flags, node);
78798 }
78799 +#endif
78800
78801 if (c->ctor)
78802 c->ctor(b);
78803 @@ -627,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78804
78805 static void __kmem_cache_free(void *b, int size)
78806 {
78807 - if (size < PAGE_SIZE)
78808 + struct slob_page *sp = slob_page(b);
78809 +
78810 + if (is_slob_page(sp))
78811 slob_free(b, size);
78812 - else
78813 + else {
78814 + clear_slob_page(sp);
78815 + free_slob_page(sp);
78816 + sp->size = 0;
78817 slob_free_pages(b, get_order(size));
78818 + }
78819 }
78820
78821 static void kmem_rcu_free(struct rcu_head *head)
78822 @@ -643,18 +755,32 @@ static void kmem_rcu_free(struct rcu_head *head)
78823
78824 void kmem_cache_free(struct kmem_cache *c, void *b)
78825 {
78826 + int size = c->size;
78827 +
78828 +#ifdef CONFIG_PAX_USERCOPY
78829 + if (size + c->align < PAGE_SIZE) {
78830 + size += c->align;
78831 + b -= c->align;
78832 + }
78833 +#endif
78834 +
78835 kmemleak_free_recursive(b, c->flags);
78836 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78837 struct slob_rcu *slob_rcu;
78838 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78839 + slob_rcu = b + (size - sizeof(struct slob_rcu));
78840 INIT_RCU_HEAD(&slob_rcu->head);
78841 - slob_rcu->size = c->size;
78842 + slob_rcu->size = size;
78843 call_rcu(&slob_rcu->head, kmem_rcu_free);
78844 } else {
78845 - __kmem_cache_free(b, c->size);
78846 + __kmem_cache_free(b, size);
78847 }
78848
78849 +#ifdef CONFIG_PAX_USERCOPY
78850 + trace_kfree(_RET_IP_, b);
78851 +#else
78852 trace_kmem_cache_free(_RET_IP_, b);
78853 +#endif
78854 +
78855 }
78856 EXPORT_SYMBOL(kmem_cache_free);
78857
78858 diff --git a/mm/slub.c b/mm/slub.c
78859 index 4996fc7..87e01d0 100644
78860 --- a/mm/slub.c
78861 +++ b/mm/slub.c
78862 @@ -201,7 +201,7 @@ struct track {
78863
78864 enum track_item { TRACK_ALLOC, TRACK_FREE };
78865
78866 -#ifdef CONFIG_SLUB_DEBUG
78867 +#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78868 static int sysfs_slab_add(struct kmem_cache *);
78869 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78870 static void sysfs_slab_remove(struct kmem_cache *);
78871 @@ -410,7 +410,7 @@ static void print_track(const char *s, struct track *t)
78872 if (!t->addr)
78873 return;
78874
78875 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78876 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78877 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78878 }
78879
78880 @@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
78881
78882 page = virt_to_head_page(x);
78883
78884 + BUG_ON(!PageSlab(page));
78885 +
78886 slab_free(s, page, x, _RET_IP_);
78887
78888 trace_kmem_cache_free(_RET_IP_, x);
78889 @@ -1937,7 +1939,7 @@ static int slub_min_objects;
78890 * Merge control. If this is set then no merging of slab caches will occur.
78891 * (Could be removed. This was introduced to pacify the merge skeptics.)
78892 */
78893 -static int slub_nomerge;
78894 +static int slub_nomerge = 1;
78895
78896 /*
78897 * Calculate the order of allocation given an slab object size.
78898 @@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
78899 * list to avoid pounding the page allocator excessively.
78900 */
78901 set_min_partial(s, ilog2(s->size));
78902 - s->refcount = 1;
78903 + atomic_set(&s->refcount, 1);
78904 #ifdef CONFIG_NUMA
78905 s->remote_node_defrag_ratio = 1000;
78906 #endif
78907 @@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
78908 void kmem_cache_destroy(struct kmem_cache *s)
78909 {
78910 down_write(&slub_lock);
78911 - s->refcount--;
78912 - if (!s->refcount) {
78913 + if (atomic_dec_and_test(&s->refcount)) {
78914 list_del(&s->list);
78915 up_write(&slub_lock);
78916 if (kmem_cache_close(s)) {
78917 @@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(char *str)
78918 __setup("slub_nomerge", setup_slub_nomerge);
78919
78920 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
78921 - const char *name, int size, gfp_t gfp_flags)
78922 + const char *name, int size, gfp_t gfp_flags, unsigned int flags)
78923 {
78924 - unsigned int flags = 0;
78925 -
78926 if (gfp_flags & SLUB_DMA)
78927 - flags = SLAB_CACHE_DMA;
78928 + flags |= SLAB_CACHE_DMA;
78929
78930 /*
78931 * This function is called with IRQs disabled during early-boot on
78932 @@ -2915,6 +2914,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78933 EXPORT_SYMBOL(__kmalloc_node);
78934 #endif
78935
78936 +void check_object_size(const void *ptr, unsigned long n, bool to)
78937 +{
78938 +
78939 +#ifdef CONFIG_PAX_USERCOPY
78940 + struct page *page;
78941 + struct kmem_cache *s = NULL;
78942 + unsigned long offset;
78943 + const char *type;
78944 +
78945 + if (!n)
78946 + return;
78947 +
78948 + type = "<null>";
78949 + if (ZERO_OR_NULL_PTR(ptr))
78950 + goto report;
78951 +
78952 + if (!virt_addr_valid(ptr))
78953 + return;
78954 +
78955 + page = get_object_page(ptr);
78956 +
78957 + type = "<process stack>";
78958 + if (!page) {
78959 + if (object_is_on_stack(ptr, n) == -1)
78960 + goto report;
78961 + return;
78962 + }
78963 +
78964 + s = page->slab;
78965 + type = s->name;
78966 + if (!(s->flags & SLAB_USERCOPY))
78967 + goto report;
78968 +
78969 + offset = (ptr - page_address(page)) % s->size;
78970 + if (offset <= s->objsize && n <= s->objsize - offset)
78971 + return;
78972 +
78973 +report:
78974 + pax_report_usercopy(ptr, n, to, type);
78975 +#endif
78976 +
78977 +}
78978 +EXPORT_SYMBOL(check_object_size);
78979 +
78980 size_t ksize(const void *object)
78981 {
78982 struct page *page;
78983 @@ -3185,8 +3228,8 @@ void __init kmem_cache_init(void)
78984 * kmem_cache_open for slab_state == DOWN.
78985 */
78986 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
78987 - sizeof(struct kmem_cache_node), GFP_NOWAIT);
78988 - kmalloc_caches[0].refcount = -1;
78989 + sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
78990 + atomic_set(&kmalloc_caches[0].refcount, -1);
78991 caches++;
78992
78993 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
78994 @@ -3198,18 +3241,18 @@ void __init kmem_cache_init(void)
78995 /* Caches that are not of the two-to-the-power-of size */
78996 if (KMALLOC_MIN_SIZE <= 32) {
78997 create_kmalloc_cache(&kmalloc_caches[1],
78998 - "kmalloc-96", 96, GFP_NOWAIT);
78999 + "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
79000 caches++;
79001 }
79002 if (KMALLOC_MIN_SIZE <= 64) {
79003 create_kmalloc_cache(&kmalloc_caches[2],
79004 - "kmalloc-192", 192, GFP_NOWAIT);
79005 + "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
79006 caches++;
79007 }
79008
79009 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79010 create_kmalloc_cache(&kmalloc_caches[i],
79011 - "kmalloc", 1 << i, GFP_NOWAIT);
79012 + "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
79013 caches++;
79014 }
79015
79016 @@ -3293,7 +3336,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79017 /*
79018 * We may have set a slab to be unmergeable during bootstrap.
79019 */
79020 - if (s->refcount < 0)
79021 + if (atomic_read(&s->refcount) < 0)
79022 return 1;
79023
79024 return 0;
79025 @@ -3353,7 +3396,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79026 if (s) {
79027 int cpu;
79028
79029 - s->refcount++;
79030 + atomic_inc(&s->refcount);
79031 /*
79032 * Adjust the object sizes so that we clear
79033 * the complete object on kzalloc.
79034 @@ -3372,7 +3415,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79035
79036 if (sysfs_slab_alias(s, name)) {
79037 down_write(&slub_lock);
79038 - s->refcount--;
79039 + atomic_dec(&s->refcount);
79040 up_write(&slub_lock);
79041 goto err;
79042 }
79043 @@ -4101,7 +4144,7 @@ SLAB_ATTR_RO(ctor);
79044
79045 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79046 {
79047 - return sprintf(buf, "%d\n", s->refcount - 1);
79048 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79049 }
79050 SLAB_ATTR_RO(aliases);
79051
79052 @@ -4503,7 +4546,7 @@ static void kmem_cache_release(struct kobject *kobj)
79053 kfree(s);
79054 }
79055
79056 -static struct sysfs_ops slab_sysfs_ops = {
79057 +static const struct sysfs_ops slab_sysfs_ops = {
79058 .show = slab_attr_show,
79059 .store = slab_attr_store,
79060 };
79061 @@ -4522,7 +4565,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
79062 return 0;
79063 }
79064
79065 -static struct kset_uevent_ops slab_uevent_ops = {
79066 +static const struct kset_uevent_ops slab_uevent_ops = {
79067 .filter = uevent_filter,
79068 };
79069
79070 @@ -4564,6 +4607,7 @@ static char *create_unique_id(struct kmem_cache *s)
79071 return name;
79072 }
79073
79074 +#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79075 static int sysfs_slab_add(struct kmem_cache *s)
79076 {
79077 int err;
79078 @@ -4619,6 +4663,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79079 kobject_del(&s->kobj);
79080 kobject_put(&s->kobj);
79081 }
79082 +#endif
79083
79084 /*
79085 * Need to buffer aliases during bootup until sysfs becomes
79086 @@ -4632,6 +4677,7 @@ struct saved_alias {
79087
79088 static struct saved_alias *alias_list;
79089
79090 +#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79091 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79092 {
79093 struct saved_alias *al;
79094 @@ -4654,6 +4700,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79095 alias_list = al;
79096 return 0;
79097 }
79098 +#endif
79099
79100 static int __init slab_sysfs_init(void)
79101 {
79102 @@ -4785,7 +4832,13 @@ static const struct file_operations proc_slabinfo_operations = {
79103
79104 static int __init slab_proc_init(void)
79105 {
79106 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
79107 + mode_t gr_mode = S_IRUGO;
79108 +
79109 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
79110 + gr_mode = S_IRUSR;
79111 +#endif
79112 +
79113 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
79114 return 0;
79115 }
79116 module_init(slab_proc_init);
79117 diff --git a/mm/swap.c b/mm/swap.c
79118 index 308e57d..5de19c0 100644
79119 --- a/mm/swap.c
79120 +++ b/mm/swap.c
79121 @@ -30,6 +30,7 @@
79122 #include <linux/notifier.h>
79123 #include <linux/backing-dev.h>
79124 #include <linux/memcontrol.h>
79125 +#include <linux/hugetlb.h>
79126
79127 #include "internal.h"
79128
79129 @@ -65,6 +66,8 @@ static void put_compound_page(struct page *page)
79130 compound_page_dtor *dtor;
79131
79132 dtor = get_compound_page_dtor(page);
79133 + if (!PageHuge(page))
79134 + BUG_ON(dtor != free_compound_page);
79135 (*dtor)(page);
79136 }
79137 }
79138 diff --git a/mm/util.c b/mm/util.c
79139 index e48b493..24a601d 100644
79140 --- a/mm/util.c
79141 +++ b/mm/util.c
79142 @@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
79143 void arch_pick_mmap_layout(struct mm_struct *mm)
79144 {
79145 mm->mmap_base = TASK_UNMAPPED_BASE;
79146 +
79147 +#ifdef CONFIG_PAX_RANDMMAP
79148 + if (mm->pax_flags & MF_PAX_RANDMMAP)
79149 + mm->mmap_base += mm->delta_mmap;
79150 +#endif
79151 +
79152 mm->get_unmapped_area = arch_get_unmapped_area;
79153 mm->unmap_area = arch_unmap_area;
79154 }
79155 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79156 index f34ffd0..e60c44f 100644
79157 --- a/mm/vmalloc.c
79158 +++ b/mm/vmalloc.c
79159 @@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79160
79161 pte = pte_offset_kernel(pmd, addr);
79162 do {
79163 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79164 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79165 +
79166 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79167 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79168 + BUG_ON(!pte_exec(*pte));
79169 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79170 + continue;
79171 + }
79172 +#endif
79173 +
79174 + {
79175 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79176 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79177 + }
79178 } while (pte++, addr += PAGE_SIZE, addr != end);
79179 }
79180
79181 @@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79182 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
79183 {
79184 pte_t *pte;
79185 + int ret = -ENOMEM;
79186
79187 /*
79188 * nr is a running index into the array which helps higher level
79189 @@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79190 pte = pte_alloc_kernel(pmd, addr);
79191 if (!pte)
79192 return -ENOMEM;
79193 +
79194 + pax_open_kernel();
79195 do {
79196 struct page *page = pages[*nr];
79197
79198 - if (WARN_ON(!pte_none(*pte)))
79199 - return -EBUSY;
79200 - if (WARN_ON(!page))
79201 - return -ENOMEM;
79202 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79203 + if (!(pgprot_val(prot) & _PAGE_NX))
79204 + BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
79205 + else
79206 +#endif
79207 +
79208 + if (WARN_ON(!pte_none(*pte))) {
79209 + ret = -EBUSY;
79210 + goto out;
79211 + }
79212 + if (WARN_ON(!page)) {
79213 + ret = -ENOMEM;
79214 + goto out;
79215 + }
79216 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79217 (*nr)++;
79218 } while (pte++, addr += PAGE_SIZE, addr != end);
79219 - return 0;
79220 + ret = 0;
79221 +out:
79222 + pax_close_kernel();
79223 + return ret;
79224 }
79225
79226 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79227 @@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void *x)
79228 * and fall back on vmalloc() if that fails. Others
79229 * just put it in the vmalloc space.
79230 */
79231 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79232 +#ifdef CONFIG_MODULES
79233 +#ifdef MODULES_VADDR
79234 unsigned long addr = (unsigned long)x;
79235 if (addr >= MODULES_VADDR && addr < MODULES_END)
79236 return 1;
79237 #endif
79238 +
79239 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79240 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79241 + return 1;
79242 +#endif
79243 +
79244 +#endif
79245 +
79246 return is_vmalloc_addr(x);
79247 }
79248
79249 @@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79250
79251 if (!pgd_none(*pgd)) {
79252 pud_t *pud = pud_offset(pgd, addr);
79253 +#ifdef CONFIG_X86
79254 + if (!pud_large(*pud))
79255 +#endif
79256 if (!pud_none(*pud)) {
79257 pmd_t *pmd = pmd_offset(pud, addr);
79258 +#ifdef CONFIG_X86
79259 + if (!pmd_large(*pmd))
79260 +#endif
79261 if (!pmd_none(*pmd)) {
79262 pte_t *ptep, pte;
79263
79264 @@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vmap_area *va)
79265 struct rb_node *tmp;
79266
79267 while (*p) {
79268 - struct vmap_area *tmp;
79269 + struct vmap_area *varea;
79270
79271 parent = *p;
79272 - tmp = rb_entry(parent, struct vmap_area, rb_node);
79273 - if (va->va_start < tmp->va_end)
79274 + varea = rb_entry(parent, struct vmap_area, rb_node);
79275 + if (va->va_start < varea->va_end)
79276 p = &(*p)->rb_left;
79277 - else if (va->va_end > tmp->va_start)
79278 + else if (va->va_end > varea->va_start)
79279 p = &(*p)->rb_right;
79280 else
79281 BUG();
79282 @@ -1245,6 +1287,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79283 struct vm_struct *area;
79284
79285 BUG_ON(in_interrupt());
79286 +
79287 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79288 + if (flags & VM_KERNEXEC) {
79289 + if (start != VMALLOC_START || end != VMALLOC_END)
79290 + return NULL;
79291 + start = (unsigned long)MODULES_EXEC_VADDR;
79292 + end = (unsigned long)MODULES_EXEC_END;
79293 + }
79294 +#endif
79295 +
79296 if (flags & VM_IOREMAP) {
79297 int bit = fls(size);
79298
79299 @@ -1484,6 +1536,11 @@ void *vmap(struct page **pages, unsigned int count,
79300 if (count > totalram_pages)
79301 return NULL;
79302
79303 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79304 + if (!(pgprot_val(prot) & _PAGE_NX))
79305 + flags |= VM_KERNEXEC;
79306 +#endif
79307 +
79308 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79309 __builtin_return_address(0));
79310 if (!area)
79311 @@ -1594,6 +1651,14 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79312 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79313 return NULL;
79314
79315 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79316 + if (!(pgprot_val(prot) & _PAGE_NX))
79317 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79318 + VMALLOC_START, VMALLOC_END, node,
79319 + gfp_mask, caller);
79320 + else
79321 +#endif
79322 +
79323 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79324 VMALLOC_START, VMALLOC_END, node,
79325 gfp_mask, caller);
79326 @@ -1619,6 +1684,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79327 return addr;
79328 }
79329
79330 +#undef __vmalloc
79331 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
79332 {
79333 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
79334 @@ -1635,6 +1701,7 @@ EXPORT_SYMBOL(__vmalloc);
79335 * For tight control over page level allocator and protection flags
79336 * use __vmalloc() instead.
79337 */
79338 +#undef vmalloc
79339 void *vmalloc(unsigned long size)
79340 {
79341 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79342 @@ -1649,6 +1716,7 @@ EXPORT_SYMBOL(vmalloc);
79343 * The resulting memory area is zeroed so it can be mapped to userspace
79344 * without leaking data.
79345 */
79346 +#undef vmalloc_user
79347 void *vmalloc_user(unsigned long size)
79348 {
79349 struct vm_struct *area;
79350 @@ -1676,6 +1744,7 @@ EXPORT_SYMBOL(vmalloc_user);
79351 * For tight control over page level allocator and protection flags
79352 * use __vmalloc() instead.
79353 */
79354 +#undef vmalloc_node
79355 void *vmalloc_node(unsigned long size, int node)
79356 {
79357 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79358 @@ -1698,10 +1767,10 @@ EXPORT_SYMBOL(vmalloc_node);
79359 * For tight control over page level allocator and protection flags
79360 * use __vmalloc() instead.
79361 */
79362 -
79363 +#undef vmalloc_exec
79364 void *vmalloc_exec(unsigned long size)
79365 {
79366 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79367 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79368 -1, __builtin_return_address(0));
79369 }
79370
79371 @@ -1720,6 +1789,7 @@ void *vmalloc_exec(unsigned long size)
79372 * Allocate enough 32bit PA addressable pages to cover @size from the
79373 * page level allocator and map them into contiguous kernel virtual space.
79374 */
79375 +#undef vmalloc_32
79376 void *vmalloc_32(unsigned long size)
79377 {
79378 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
79379 @@ -1734,6 +1804,7 @@ EXPORT_SYMBOL(vmalloc_32);
79380 * The resulting memory area is 32bit addressable and zeroed so it can be
79381 * mapped to userspace without leaking data.
79382 */
79383 +#undef vmalloc_32_user
79384 void *vmalloc_32_user(unsigned long size)
79385 {
79386 struct vm_struct *area;
79387 @@ -1998,6 +2069,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79388 unsigned long uaddr = vma->vm_start;
79389 unsigned long usize = vma->vm_end - vma->vm_start;
79390
79391 + BUG_ON(vma->vm_mirror);
79392 +
79393 if ((PAGE_SIZE-1) & (unsigned long)addr)
79394 return -EINVAL;
79395
79396 diff --git a/mm/vmstat.c b/mm/vmstat.c
79397 index 42d76c6..5643dc4 100644
79398 --- a/mm/vmstat.c
79399 +++ b/mm/vmstat.c
79400 @@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
79401 *
79402 * vm_stat contains the global counters
79403 */
79404 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79405 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79406 EXPORT_SYMBOL(vm_stat);
79407
79408 #ifdef CONFIG_SMP
79409 @@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
79410 v = p->vm_stat_diff[i];
79411 p->vm_stat_diff[i] = 0;
79412 local_irq_restore(flags);
79413 - atomic_long_add(v, &zone->vm_stat[i]);
79414 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79415 global_diff[i] += v;
79416 #ifdef CONFIG_NUMA
79417 /* 3 seconds idle till flush */
79418 @@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
79419
79420 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79421 if (global_diff[i])
79422 - atomic_long_add(global_diff[i], &vm_stat[i]);
79423 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79424 }
79425
79426 #endif
79427 @@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
79428 start_cpu_timer(cpu);
79429 #endif
79430 #ifdef CONFIG_PROC_FS
79431 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79432 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79433 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79434 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79435 + {
79436 + mode_t gr_mode = S_IRUGO;
79437 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
79438 + gr_mode = S_IRUSR;
79439 +#endif
79440 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79441 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79442 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79443 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79444 +#else
79445 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79446 +#endif
79447 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79448 + }
79449 #endif
79450 return 0;
79451 }
79452 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79453 index a29c5ab..6143f20 100644
79454 --- a/net/8021q/vlan.c
79455 +++ b/net/8021q/vlan.c
79456 @@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79457 err = -EPERM;
79458 if (!capable(CAP_NET_ADMIN))
79459 break;
79460 - if ((args.u.name_type >= 0) &&
79461 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79462 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79463 struct vlan_net *vn;
79464
79465 vn = net_generic(net, vlan_net_id);
79466 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79467 index a2d2984..f9eb711 100644
79468 --- a/net/9p/trans_fd.c
79469 +++ b/net/9p/trans_fd.c
79470 @@ -419,7 +419,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79471 oldfs = get_fs();
79472 set_fs(get_ds());
79473 /* The cast to a user pointer is valid due to the set_fs() */
79474 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79475 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79476 set_fs(oldfs);
79477
79478 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79479 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79480 index 02cc7e7..4514f1b 100644
79481 --- a/net/atm/atm_misc.c
79482 +++ b/net/atm/atm_misc.c
79483 @@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int truesize)
79484 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79485 return 1;
79486 atm_return(vcc,truesize);
79487 - atomic_inc(&vcc->stats->rx_drop);
79488 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79489 return 0;
79490 }
79491
79492 @@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
79493 }
79494 }
79495 atm_return(vcc,guess);
79496 - atomic_inc(&vcc->stats->rx_drop);
79497 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79498 return NULL;
79499 }
79500
79501 @@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafprm *tp)
79502
79503 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79504 {
79505 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79506 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79507 __SONET_ITEMS
79508 #undef __HANDLE_ITEM
79509 }
79510 @@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79511
79512 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79513 {
79514 -#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
79515 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79516 __SONET_ITEMS
79517 #undef __HANDLE_ITEM
79518 }
79519 diff --git a/net/atm/lec.h b/net/atm/lec.h
79520 index 9d14d19..5c145f3 100644
79521 --- a/net/atm/lec.h
79522 +++ b/net/atm/lec.h
79523 @@ -48,7 +48,7 @@ struct lane2_ops {
79524 const u8 *tlvs, u32 sizeoftlvs);
79525 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79526 const u8 *tlvs, u32 sizeoftlvs);
79527 -};
79528 +} __no_const;
79529
79530 /*
79531 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79532 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
79533 index 0919a88..a23d54e 100644
79534 --- a/net/atm/mpc.h
79535 +++ b/net/atm/mpc.h
79536 @@ -33,7 +33,7 @@ struct mpoa_client {
79537 struct mpc_parameters parameters; /* parameters for this client */
79538
79539 const struct net_device_ops *old_ops;
79540 - struct net_device_ops new_ops;
79541 + net_device_ops_no_const new_ops;
79542 };
79543
79544
79545 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
79546 index 4504a4b..1733f1e 100644
79547 --- a/net/atm/mpoa_caches.c
79548 +++ b/net/atm/mpoa_caches.c
79549 @@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_client *client)
79550 struct timeval now;
79551 struct k_message msg;
79552
79553 + pax_track_stack();
79554 +
79555 do_gettimeofday(&now);
79556
79557 write_lock_irq(&client->egress_lock);
79558 diff --git a/net/atm/proc.c b/net/atm/proc.c
79559 index ab8419a..aa91497 100644
79560 --- a/net/atm/proc.c
79561 +++ b/net/atm/proc.c
79562 @@ -43,9 +43,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79563 const struct k_atm_aal_stats *stats)
79564 {
79565 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79566 - atomic_read(&stats->tx),atomic_read(&stats->tx_err),
79567 - atomic_read(&stats->rx),atomic_read(&stats->rx_err),
79568 - atomic_read(&stats->rx_drop));
79569 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79570 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79571 + atomic_read_unchecked(&stats->rx_drop));
79572 }
79573
79574 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79575 @@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
79576 {
79577 struct sock *sk = sk_atm(vcc);
79578
79579 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79580 + seq_printf(seq, "%p ", NULL);
79581 +#else
79582 seq_printf(seq, "%p ", vcc);
79583 +#endif
79584 +
79585 if (!vcc->dev)
79586 seq_printf(seq, "Unassigned ");
79587 else
79588 @@ -214,7 +219,11 @@ static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
79589 {
79590 if (!vcc->dev)
79591 seq_printf(seq, sizeof(void *) == 4 ?
79592 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79593 + "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
79594 +#else
79595 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
79596 +#endif
79597 else
79598 seq_printf(seq, "%3d %3d %5d ",
79599 vcc->dev->number, vcc->vpi, vcc->vci);
79600 diff --git a/net/atm/resources.c b/net/atm/resources.c
79601 index 56b7322..c48b84e 100644
79602 --- a/net/atm/resources.c
79603 +++ b/net/atm/resources.c
79604 @@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *dev)
79605 static void copy_aal_stats(struct k_atm_aal_stats *from,
79606 struct atm_aal_stats *to)
79607 {
79608 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79609 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79610 __AAL_STAT_ITEMS
79611 #undef __HANDLE_ITEM
79612 }
79613 @@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79614 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79615 struct atm_aal_stats *to)
79616 {
79617 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79618 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79619 __AAL_STAT_ITEMS
79620 #undef __HANDLE_ITEM
79621 }
79622 diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
79623 index 8567d47..bba2292 100644
79624 --- a/net/bridge/br_private.h
79625 +++ b/net/bridge/br_private.h
79626 @@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
79627
79628 #ifdef CONFIG_SYSFS
79629 /* br_sysfs_if.c */
79630 -extern struct sysfs_ops brport_sysfs_ops;
79631 +extern const struct sysfs_ops brport_sysfs_ops;
79632 extern int br_sysfs_addif(struct net_bridge_port *p);
79633
79634 /* br_sysfs_br.c */
79635 diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
79636 index 9a52ac5..c97538e 100644
79637 --- a/net/bridge/br_stp_if.c
79638 +++ b/net/bridge/br_stp_if.c
79639 @@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridge *br)
79640 char *envp[] = { NULL };
79641
79642 if (br->stp_enabled == BR_USER_STP) {
79643 - r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
79644 + r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
79645 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
79646 br->dev->name, r);
79647
79648 diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
79649 index 820643a..ce77fb3 100644
79650 --- a/net/bridge/br_sysfs_if.c
79651 +++ b/net/bridge/br_sysfs_if.c
79652 @@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobject * kobj,
79653 return ret;
79654 }
79655
79656 -struct sysfs_ops brport_sysfs_ops = {
79657 +const struct sysfs_ops brport_sysfs_ops = {
79658 .show = brport_show,
79659 .store = brport_store,
79660 };
79661 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79662 index d73d47f..72df42a 100644
79663 --- a/net/bridge/netfilter/ebtables.c
79664 +++ b/net/bridge/netfilter/ebtables.c
79665 @@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
79666 unsigned int entries_size, nentries;
79667 char *entries;
79668
79669 + pax_track_stack();
79670 +
79671 if (cmd == EBT_SO_GET_ENTRIES) {
79672 entries_size = t->private->entries_size;
79673 nentries = t->private->nentries;
79674 diff --git a/net/can/bcm.c b/net/can/bcm.c
79675 index 2ffd2e0..72a7486 100644
79676 --- a/net/can/bcm.c
79677 +++ b/net/can/bcm.c
79678 @@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file *m, void *v)
79679 struct bcm_sock *bo = bcm_sk(sk);
79680 struct bcm_op *op;
79681
79682 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79683 + seq_printf(m, ">>> socket %p", NULL);
79684 + seq_printf(m, " / sk %p", NULL);
79685 + seq_printf(m, " / bo %p", NULL);
79686 +#else
79687 seq_printf(m, ">>> socket %p", sk->sk_socket);
79688 seq_printf(m, " / sk %p", sk);
79689 seq_printf(m, " / bo %p", bo);
79690 +#endif
79691 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
79692 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
79693 seq_printf(m, " <<<\n");
79694 diff --git a/net/compat.c b/net/compat.c
79695 index 9559afc..ccd74e1 100644
79696 --- a/net/compat.c
79697 +++ b/net/compat.c
79698 @@ -69,9 +69,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79699 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79700 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79701 return -EFAULT;
79702 - kmsg->msg_name = compat_ptr(tmp1);
79703 - kmsg->msg_iov = compat_ptr(tmp2);
79704 - kmsg->msg_control = compat_ptr(tmp3);
79705 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79706 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79707 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79708 return 0;
79709 }
79710
79711 @@ -94,7 +94,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79712 kern_msg->msg_name = NULL;
79713
79714 tot_len = iov_from_user_compat_to_kern(kern_iov,
79715 - (struct compat_iovec __user *)kern_msg->msg_iov,
79716 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
79717 kern_msg->msg_iovlen);
79718 if (tot_len >= 0)
79719 kern_msg->msg_iov = kern_iov;
79720 @@ -114,20 +114,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79721
79722 #define CMSG_COMPAT_FIRSTHDR(msg) \
79723 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79724 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79725 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79726 (struct compat_cmsghdr __user *)NULL)
79727
79728 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79729 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79730 (ucmlen) <= (unsigned long) \
79731 ((mhdr)->msg_controllen - \
79732 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79733 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79734
79735 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79736 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79737 {
79738 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79739 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79740 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79741 msg->msg_controllen)
79742 return NULL;
79743 return (struct compat_cmsghdr __user *)ptr;
79744 @@ -219,7 +219,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79745 {
79746 struct compat_timeval ctv;
79747 struct compat_timespec cts[3];
79748 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79749 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79750 struct compat_cmsghdr cmhdr;
79751 int cmlen;
79752
79753 @@ -271,7 +271,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79754
79755 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79756 {
79757 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79758 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79759 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79760 int fdnum = scm->fp->count;
79761 struct file **fp = scm->fp->fp;
79762 @@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79763 len = sizeof(ktime);
79764 old_fs = get_fs();
79765 set_fs(KERNEL_DS);
79766 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79767 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79768 set_fs(old_fs);
79769
79770 if (!err) {
79771 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79772 case MCAST_JOIN_GROUP:
79773 case MCAST_LEAVE_GROUP:
79774 {
79775 - struct compat_group_req __user *gr32 = (void *)optval;
79776 + struct compat_group_req __user *gr32 = (void __user *)optval;
79777 struct group_req __user *kgr =
79778 compat_alloc_user_space(sizeof(struct group_req));
79779 u32 interface;
79780 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79781 case MCAST_BLOCK_SOURCE:
79782 case MCAST_UNBLOCK_SOURCE:
79783 {
79784 - struct compat_group_source_req __user *gsr32 = (void *)optval;
79785 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79786 struct group_source_req __user *kgsr = compat_alloc_user_space(
79787 sizeof(struct group_source_req));
79788 u32 interface;
79789 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79790 }
79791 case MCAST_MSFILTER:
79792 {
79793 - struct compat_group_filter __user *gf32 = (void *)optval;
79794 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79795 struct group_filter __user *kgf;
79796 u32 interface, fmode, numsrc;
79797
79798 diff --git a/net/core/dev.c b/net/core/dev.c
79799 index 84a0705..575db4c 100644
79800 --- a/net/core/dev.c
79801 +++ b/net/core/dev.c
79802 @@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const char *name)
79803 if (no_module && capable(CAP_NET_ADMIN))
79804 no_module = request_module("netdev-%s", name);
79805 if (no_module && capable(CAP_SYS_MODULE)) {
79806 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
79807 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
79808 +#else
79809 if (!request_module("%s", name))
79810 pr_err("Loading kernel module for a network device "
79811 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
79812 "instead\n", name);
79813 +#endif
79814 }
79815 }
79816 EXPORT_SYMBOL(dev_load);
79817 @@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79818
79819 struct dev_gso_cb {
79820 void (*destructor)(struct sk_buff *skb);
79821 -};
79822 +} __no_const;
79823
79824 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79825
79826 @@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
79827 }
79828 EXPORT_SYMBOL(netif_rx_ni);
79829
79830 -static void net_tx_action(struct softirq_action *h)
79831 +static void net_tx_action(void)
79832 {
79833 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79834
79835 @@ -2827,7 +2831,7 @@ void netif_napi_del(struct napi_struct *napi)
79836 EXPORT_SYMBOL(netif_napi_del);
79837
79838
79839 -static void net_rx_action(struct softirq_action *h)
79840 +static void net_rx_action(void)
79841 {
79842 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
79843 unsigned long time_limit = jiffies + 2;
79844 diff --git a/net/core/flow.c b/net/core/flow.c
79845 index 9601587..8c4824e 100644
79846 --- a/net/core/flow.c
79847 +++ b/net/core/flow.c
79848 @@ -35,11 +35,11 @@ struct flow_cache_entry {
79849 atomic_t *object_ref;
79850 };
79851
79852 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
79853 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79854
79855 static u32 flow_hash_shift;
79856 #define flow_hash_size (1 << flow_hash_shift)
79857 -static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
79858 +static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
79859
79860 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
79861
79862 @@ -52,7 +52,7 @@ struct flow_percpu_info {
79863 u32 hash_rnd;
79864 int count;
79865 };
79866 -static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
79867 +static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
79868
79869 #define flow_hash_rnd_recalc(cpu) \
79870 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
79871 @@ -69,7 +69,7 @@ struct flow_flush_info {
79872 atomic_t cpuleft;
79873 struct completion completion;
79874 };
79875 -static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
79876 +static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
79877
79878 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
79879
79880 @@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir,
79881 if (fle->family == family &&
79882 fle->dir == dir &&
79883 flow_key_compare(key, &fle->key) == 0) {
79884 - if (fle->genid == atomic_read(&flow_cache_genid)) {
79885 + if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
79886 void *ret = fle->object;
79887
79888 if (ret)
79889 @@ -228,7 +228,7 @@ nocache:
79890 err = resolver(net, key, family, dir, &obj, &obj_ref);
79891
79892 if (fle && !err) {
79893 - fle->genid = atomic_read(&flow_cache_genid);
79894 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
79895
79896 if (fle->object)
79897 atomic_dec(fle->object_ref);
79898 @@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(unsigned long data)
79899
79900 fle = flow_table(cpu)[i];
79901 for (; fle; fle = fle->next) {
79902 - unsigned genid = atomic_read(&flow_cache_genid);
79903 + unsigned genid = atomic_read_unchecked(&flow_cache_genid);
79904
79905 if (!fle->object || fle->genid == genid)
79906 continue;
79907 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79908 index d4fd895..ac9b1e6 100644
79909 --- a/net/core/rtnetlink.c
79910 +++ b/net/core/rtnetlink.c
79911 @@ -57,7 +57,7 @@ struct rtnl_link
79912 {
79913 rtnl_doit_func doit;
79914 rtnl_dumpit_func dumpit;
79915 -};
79916 +} __no_const;
79917
79918 static DEFINE_MUTEX(rtnl_mutex);
79919
79920 diff --git a/net/core/scm.c b/net/core/scm.c
79921 index d98eafc..1a190a9 100644
79922 --- a/net/core/scm.c
79923 +++ b/net/core/scm.c
79924 @@ -191,7 +191,7 @@ error:
79925 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79926 {
79927 struct cmsghdr __user *cm
79928 - = (__force struct cmsghdr __user *)msg->msg_control;
79929 + = (struct cmsghdr __force_user *)msg->msg_control;
79930 struct cmsghdr cmhdr;
79931 int cmlen = CMSG_LEN(len);
79932 int err;
79933 @@ -214,7 +214,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79934 err = -EFAULT;
79935 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79936 goto out;
79937 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79938 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79939 goto out;
79940 cmlen = CMSG_SPACE(len);
79941 if (msg->msg_controllen < cmlen)
79942 @@ -229,7 +229,7 @@ out:
79943 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79944 {
79945 struct cmsghdr __user *cm
79946 - = (__force struct cmsghdr __user*)msg->msg_control;
79947 + = (struct cmsghdr __force_user *)msg->msg_control;
79948
79949 int fdmax = 0;
79950 int fdnum = scm->fp->count;
79951 @@ -249,7 +249,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79952 if (fdnum < fdmax)
79953 fdmax = fdnum;
79954
79955 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79956 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79957 i++, cmfptr++)
79958 {
79959 int new_fd;
79960 diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
79961 index 45329d7..626aaa6 100644
79962 --- a/net/core/secure_seq.c
79963 +++ b/net/core/secure_seq.c
79964 @@ -57,7 +57,7 @@ __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
79965 EXPORT_SYMBOL(secure_tcpv6_sequence_number);
79966
79967 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
79968 - __be16 dport)
79969 + __be16 dport)
79970 {
79971 u32 secret[MD5_MESSAGE_BYTES / 4];
79972 u32 hash[MD5_DIGEST_WORDS];
79973 @@ -71,7 +71,6 @@ u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
79974 secret[i] = net_secret[i];
79975
79976 md5_transform(hash, secret);
79977 -
79978 return hash[0];
79979 }
79980 #endif
79981 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
79982 index a807f8c..65f906f 100644
79983 --- a/net/core/skbuff.c
79984 +++ b/net/core/skbuff.c
79985 @@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
79986 struct sk_buff *frag_iter;
79987 struct sock *sk = skb->sk;
79988
79989 + pax_track_stack();
79990 +
79991 /*
79992 * __skb_splice_bits() only fails if the output has no room left,
79993 * so no point in going over the frag_list for the error case.
79994 diff --git a/net/core/sock.c b/net/core/sock.c
79995 index 6605e75..3acebda 100644
79996 --- a/net/core/sock.c
79997 +++ b/net/core/sock.c
79998 @@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79999 break;
80000
80001 case SO_PEERCRED:
80002 + {
80003 + struct ucred peercred;
80004 if (len > sizeof(sk->sk_peercred))
80005 len = sizeof(sk->sk_peercred);
80006 - if (copy_to_user(optval, &sk->sk_peercred, len))
80007 + peercred = sk->sk_peercred;
80008 + if (copy_to_user(optval, &peercred, len))
80009 return -EFAULT;
80010 goto lenout;
80011 + }
80012
80013 case SO_PEERNAME:
80014 {
80015 @@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80016 */
80017 smp_wmb();
80018 atomic_set(&sk->sk_refcnt, 1);
80019 - atomic_set(&sk->sk_drops, 0);
80020 + atomic_set_unchecked(&sk->sk_drops, 0);
80021 }
80022 EXPORT_SYMBOL(sock_init_data);
80023
80024 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80025 index 2036568..c55883d 100644
80026 --- a/net/decnet/sysctl_net_decnet.c
80027 +++ b/net/decnet/sysctl_net_decnet.c
80028 @@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80029
80030 if (len > *lenp) len = *lenp;
80031
80032 - if (copy_to_user(buffer, addr, len))
80033 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
80034 return -EFAULT;
80035
80036 *lenp = len;
80037 @@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80038
80039 if (len > *lenp) len = *lenp;
80040
80041 - if (copy_to_user(buffer, devname, len))
80042 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
80043 return -EFAULT;
80044
80045 *lenp = len;
80046 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
80047 index 39a2d29..f39c0fe 100644
80048 --- a/net/econet/Kconfig
80049 +++ b/net/econet/Kconfig
80050 @@ -4,7 +4,7 @@
80051
80052 config ECONET
80053 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
80054 - depends on EXPERIMENTAL && INET
80055 + depends on EXPERIMENTAL && INET && BROKEN
80056 ---help---
80057 Econet is a fairly old and slow networking protocol mainly used by
80058 Acorn computers to access file and print servers. It uses native
80059 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
80060 index a413b1b..380849c 100644
80061 --- a/net/ieee802154/dgram.c
80062 +++ b/net/ieee802154/dgram.c
80063 @@ -318,7 +318,7 @@ out:
80064 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
80065 {
80066 if (sock_queue_rcv_skb(sk, skb) < 0) {
80067 - atomic_inc(&sk->sk_drops);
80068 + atomic_inc_unchecked(&sk->sk_drops);
80069 kfree_skb(skb);
80070 return NET_RX_DROP;
80071 }
80072 diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
80073 index 30e74ee..bfc6ee0 100644
80074 --- a/net/ieee802154/raw.c
80075 +++ b/net/ieee802154/raw.c
80076 @@ -206,7 +206,7 @@ out:
80077 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80078 {
80079 if (sock_queue_rcv_skb(sk, skb) < 0) {
80080 - atomic_inc(&sk->sk_drops);
80081 + atomic_inc_unchecked(&sk->sk_drops);
80082 kfree_skb(skb);
80083 return NET_RX_DROP;
80084 }
80085 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
80086 index dba56d2..acee5d6 100644
80087 --- a/net/ipv4/inet_diag.c
80088 +++ b/net/ipv4/inet_diag.c
80089 @@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct sock *sk,
80090 r->idiag_retrans = 0;
80091
80092 r->id.idiag_if = sk->sk_bound_dev_if;
80093 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80094 + r->id.idiag_cookie[0] = 0;
80095 + r->id.idiag_cookie[1] = 0;
80096 +#else
80097 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
80098 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80099 +#endif
80100
80101 r->id.idiag_sport = inet->sport;
80102 r->id.idiag_dport = inet->dport;
80103 @@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
80104 r->idiag_family = tw->tw_family;
80105 r->idiag_retrans = 0;
80106 r->id.idiag_if = tw->tw_bound_dev_if;
80107 +
80108 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80109 + r->id.idiag_cookie[0] = 0;
80110 + r->id.idiag_cookie[1] = 0;
80111 +#else
80112 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
80113 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
80114 +#endif
80115 +
80116 r->id.idiag_sport = tw->tw_sport;
80117 r->id.idiag_dport = tw->tw_dport;
80118 r->id.idiag_src[0] = tw->tw_rcv_saddr;
80119 @@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
80120 if (sk == NULL)
80121 goto unlock;
80122
80123 +#ifndef CONFIG_GRKERNSEC_HIDESYM
80124 err = -ESTALE;
80125 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
80126 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
80127 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
80128 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
80129 goto out;
80130 +#endif
80131
80132 err = -ENOMEM;
80133 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
80134 @@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
80135 r->idiag_retrans = req->retrans;
80136
80137 r->id.idiag_if = sk->sk_bound_dev_if;
80138 +
80139 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80140 + r->id.idiag_cookie[0] = 0;
80141 + r->id.idiag_cookie[1] = 0;
80142 +#else
80143 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
80144 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
80145 +#endif
80146
80147 tmo = req->expires - jiffies;
80148 if (tmo < 0)
80149 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80150 index d717267..56de7e7 100644
80151 --- a/net/ipv4/inet_hashtables.c
80152 +++ b/net/ipv4/inet_hashtables.c
80153 @@ -18,12 +18,15 @@
80154 #include <linux/sched.h>
80155 #include <linux/slab.h>
80156 #include <linux/wait.h>
80157 +#include <linux/security.h>
80158
80159 #include <net/inet_connection_sock.h>
80160 #include <net/inet_hashtables.h>
80161 #include <net/secure_seq.h>
80162 #include <net/ip.h>
80163
80164 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80165 +
80166 /*
80167 * Allocate and initialize a new local port bind bucket.
80168 * The bindhash mutex for snum's hash chain must be held here.
80169 @@ -491,6 +494,8 @@ ok:
80170 }
80171 spin_unlock(&head->lock);
80172
80173 + gr_update_task_in_ip_table(current, inet_sk(sk));
80174 +
80175 if (tw) {
80176 inet_twsk_deschedule(tw, death_row);
80177 inet_twsk_put(tw);
80178 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80179 index 13b229f..6956484 100644
80180 --- a/net/ipv4/inetpeer.c
80181 +++ b/net/ipv4/inetpeer.c
80182 @@ -367,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
80183 struct inet_peer *p, *n;
80184 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
80185
80186 + pax_track_stack();
80187 +
80188 /* Look up for the address quickly. */
80189 read_lock_bh(&peer_pool_lock);
80190 p = lookup(daddr, NULL);
80191 @@ -390,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
80192 return NULL;
80193 n->v4daddr = daddr;
80194 atomic_set(&n->refcnt, 1);
80195 - atomic_set(&n->rid, 0);
80196 + atomic_set_unchecked(&n->rid, 0);
80197 n->ip_id_count = secure_ip_id(daddr);
80198 n->tcp_ts_stamp = 0;
80199
80200 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80201 index d3fe10b..feeafc9 100644
80202 --- a/net/ipv4/ip_fragment.c
80203 +++ b/net/ipv4/ip_fragment.c
80204 @@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80205 return 0;
80206
80207 start = qp->rid;
80208 - end = atomic_inc_return(&peer->rid);
80209 + end = atomic_inc_return_unchecked(&peer->rid);
80210 qp->rid = end;
80211
80212 rc = qp->q.fragments && (end - start) > max;
80213 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80214 index e982b5c..f079d75 100644
80215 --- a/net/ipv4/ip_sockglue.c
80216 +++ b/net/ipv4/ip_sockglue.c
80217 @@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80218 int val;
80219 int len;
80220
80221 + pax_track_stack();
80222 +
80223 if (level != SOL_IP)
80224 return -EOPNOTSUPP;
80225
80226 @@ -1173,7 +1175,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80227 if (sk->sk_type != SOCK_STREAM)
80228 return -ENOPROTOOPT;
80229
80230 - msg.msg_control = optval;
80231 + msg.msg_control = (void __force_kernel *)optval;
80232 msg.msg_controllen = len;
80233 msg.msg_flags = 0;
80234
80235 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80236 index f8d04c2..c1188f2 100644
80237 --- a/net/ipv4/ipconfig.c
80238 +++ b/net/ipv4/ipconfig.c
80239 @@ -295,7 +295,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80240
80241 mm_segment_t oldfs = get_fs();
80242 set_fs(get_ds());
80243 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80244 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80245 set_fs(oldfs);
80246 return res;
80247 }
80248 @@ -306,7 +306,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80249
80250 mm_segment_t oldfs = get_fs();
80251 set_fs(get_ds());
80252 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80253 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80254 set_fs(oldfs);
80255 return res;
80256 }
80257 @@ -317,7 +317,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80258
80259 mm_segment_t oldfs = get_fs();
80260 set_fs(get_ds());
80261 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80262 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80263 set_fs(oldfs);
80264 return res;
80265 }
80266 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80267 index c8b0cc3..4da5ae2 100644
80268 --- a/net/ipv4/netfilter/arp_tables.c
80269 +++ b/net/ipv4/netfilter/arp_tables.c
80270 @@ -934,6 +934,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80271 private = &tmp;
80272 }
80273 #endif
80274 + memset(&info, 0, sizeof(info));
80275 info.valid_hooks = t->valid_hooks;
80276 memcpy(info.hook_entry, private->hook_entry,
80277 sizeof(info.hook_entry));
80278 diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
80279 index c156db2..e772975 100644
80280 --- a/net/ipv4/netfilter/ip_queue.c
80281 +++ b/net/ipv4/netfilter/ip_queue.c
80282 @@ -286,6 +286,9 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80283
80284 if (v->data_len < sizeof(*user_iph))
80285 return 0;
80286 + if (v->data_len > 65535)
80287 + return -EMSGSIZE;
80288 +
80289 diff = v->data_len - e->skb->len;
80290 if (diff < 0) {
80291 if (pskb_trim(e->skb, v->data_len))
80292 @@ -409,7 +412,8 @@ ipq_dev_drop(int ifindex)
80293 static inline void
80294 __ipq_rcv_skb(struct sk_buff *skb)
80295 {
80296 - int status, type, pid, flags, nlmsglen, skblen;
80297 + int status, type, pid, flags;
80298 + unsigned int nlmsglen, skblen;
80299 struct nlmsghdr *nlh;
80300
80301 skblen = skb->len;
80302 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80303 index 0606db1..02e7e4c 100644
80304 --- a/net/ipv4/netfilter/ip_tables.c
80305 +++ b/net/ipv4/netfilter/ip_tables.c
80306 @@ -1141,6 +1141,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80307 private = &tmp;
80308 }
80309 #endif
80310 + memset(&info, 0, sizeof(info));
80311 info.valid_hooks = t->valid_hooks;
80312 memcpy(info.hook_entry, private->hook_entry,
80313 sizeof(info.hook_entry));
80314 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80315 index d9521f6..3c3eb25 100644
80316 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
80317 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80318 @@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
80319
80320 *len = 0;
80321
80322 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
80323 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
80324 if (*octets == NULL) {
80325 if (net_ratelimit())
80326 printk("OOM in bsalg (%d)\n", __LINE__);
80327 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80328 index ab996f9..3da5f96 100644
80329 --- a/net/ipv4/raw.c
80330 +++ b/net/ipv4/raw.c
80331 @@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80332 /* Charge it to the socket. */
80333
80334 if (sock_queue_rcv_skb(sk, skb) < 0) {
80335 - atomic_inc(&sk->sk_drops);
80336 + atomic_inc_unchecked(&sk->sk_drops);
80337 kfree_skb(skb);
80338 return NET_RX_DROP;
80339 }
80340 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80341 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80342 {
80343 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80344 - atomic_inc(&sk->sk_drops);
80345 + atomic_inc_unchecked(&sk->sk_drops);
80346 kfree_skb(skb);
80347 return NET_RX_DROP;
80348 }
80349 @@ -724,16 +724,23 @@ static int raw_init(struct sock *sk)
80350
80351 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80352 {
80353 + struct icmp_filter filter;
80354 +
80355 + if (optlen < 0)
80356 + return -EINVAL;
80357 if (optlen > sizeof(struct icmp_filter))
80358 optlen = sizeof(struct icmp_filter);
80359 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80360 + if (copy_from_user(&filter, optval, optlen))
80361 return -EFAULT;
80362 + raw_sk(sk)->filter = filter;
80363 +
80364 return 0;
80365 }
80366
80367 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80368 {
80369 int len, ret = -EFAULT;
80370 + struct icmp_filter filter;
80371
80372 if (get_user(len, optlen))
80373 goto out;
80374 @@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80375 if (len > sizeof(struct icmp_filter))
80376 len = sizeof(struct icmp_filter);
80377 ret = -EFAULT;
80378 - if (put_user(len, optlen) ||
80379 - copy_to_user(optval, &raw_sk(sk)->filter, len))
80380 + filter = raw_sk(sk)->filter;
80381 + if (put_user(len, optlen) || len > sizeof filter ||
80382 + copy_to_user(optval, &filter, len))
80383 goto out;
80384 ret = 0;
80385 out: return ret;
80386 @@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80387 sk_wmem_alloc_get(sp),
80388 sk_rmem_alloc_get(sp),
80389 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80390 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80391 + atomic_read(&sp->sk_refcnt),
80392 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80393 + NULL,
80394 +#else
80395 + sp,
80396 +#endif
80397 + atomic_read_unchecked(&sp->sk_drops));
80398 }
80399
80400 static int raw_seq_show(struct seq_file *seq, void *v)
80401 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80402 index 58f141b..b759702 100644
80403 --- a/net/ipv4/route.c
80404 +++ b/net/ipv4/route.c
80405 @@ -269,7 +269,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
80406
80407 static inline int rt_genid(struct net *net)
80408 {
80409 - return atomic_read(&net->ipv4.rt_genid);
80410 + return atomic_read_unchecked(&net->ipv4.rt_genid);
80411 }
80412
80413 #ifdef CONFIG_PROC_FS
80414 @@ -889,7 +889,7 @@ static void rt_cache_invalidate(struct net *net)
80415 unsigned char shuffle;
80416
80417 get_random_bytes(&shuffle, sizeof(shuffle));
80418 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
80419 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
80420 }
80421
80422 /*
80423 @@ -3357,7 +3357,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80424
80425 static __net_init int rt_secret_timer_init(struct net *net)
80426 {
80427 - atomic_set(&net->ipv4.rt_genid,
80428 + atomic_set_unchecked(&net->ipv4.rt_genid,
80429 (int) ((num_physpages ^ (num_physpages>>8)) ^
80430 (jiffies ^ (jiffies >> 7))));
80431
80432 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
80433 index f095659..adc892a 100644
80434 --- a/net/ipv4/tcp.c
80435 +++ b/net/ipv4/tcp.c
80436 @@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
80437 int val;
80438 int err = 0;
80439
80440 + pax_track_stack();
80441 +
80442 /* This is a string value all the others are int's */
80443 if (optname == TCP_CONGESTION) {
80444 char name[TCP_CA_NAME_MAX];
80445 @@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
80446 struct tcp_sock *tp = tcp_sk(sk);
80447 int val, len;
80448
80449 + pax_track_stack();
80450 +
80451 if (get_user(len, optlen))
80452 return -EFAULT;
80453
80454 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80455 index 6fc7961..33bad4a 100644
80456 --- a/net/ipv4/tcp_ipv4.c
80457 +++ b/net/ipv4/tcp_ipv4.c
80458 @@ -85,6 +85,9 @@
80459 int sysctl_tcp_tw_reuse __read_mostly;
80460 int sysctl_tcp_low_latency __read_mostly;
80461
80462 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80463 +extern int grsec_enable_blackhole;
80464 +#endif
80465
80466 #ifdef CONFIG_TCP_MD5SIG
80467 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
80468 @@ -1543,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80469 return 0;
80470
80471 reset:
80472 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80473 + if (!grsec_enable_blackhole)
80474 +#endif
80475 tcp_v4_send_reset(rsk, skb);
80476 discard:
80477 kfree_skb(skb);
80478 @@ -1604,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
80479 TCP_SKB_CB(skb)->sacked = 0;
80480
80481 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80482 - if (!sk)
80483 + if (!sk) {
80484 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80485 + ret = 1;
80486 +#endif
80487 goto no_tcp_socket;
80488 + }
80489
80490 process:
80491 - if (sk->sk_state == TCP_TIME_WAIT)
80492 + if (sk->sk_state == TCP_TIME_WAIT) {
80493 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80494 + ret = 2;
80495 +#endif
80496 goto do_time_wait;
80497 + }
80498
80499 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
80500 goto discard_and_relse;
80501 @@ -1651,6 +1665,10 @@ no_tcp_socket:
80502 bad_packet:
80503 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80504 } else {
80505 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80506 + if (!grsec_enable_blackhole || (ret == 1 &&
80507 + (skb->dev->flags & IFF_LOOPBACK)))
80508 +#endif
80509 tcp_v4_send_reset(NULL, skb);
80510 }
80511
80512 @@ -2238,7 +2256,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
80513 0, /* non standard timer */
80514 0, /* open_requests have no inode */
80515 atomic_read(&sk->sk_refcnt),
80516 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80517 + NULL,
80518 +#else
80519 req,
80520 +#endif
80521 len);
80522 }
80523
80524 @@ -2280,7 +2302,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
80525 sock_i_uid(sk),
80526 icsk->icsk_probes_out,
80527 sock_i_ino(sk),
80528 - atomic_read(&sk->sk_refcnt), sk,
80529 + atomic_read(&sk->sk_refcnt),
80530 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80531 + NULL,
80532 +#else
80533 + sk,
80534 +#endif
80535 jiffies_to_clock_t(icsk->icsk_rto),
80536 jiffies_to_clock_t(icsk->icsk_ack.ato),
80537 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
80538 @@ -2308,7 +2335,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
80539 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
80540 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
80541 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
80542 - atomic_read(&tw->tw_refcnt), tw, len);
80543 + atomic_read(&tw->tw_refcnt),
80544 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80545 + NULL,
80546 +#else
80547 + tw,
80548 +#endif
80549 + len);
80550 }
80551
80552 #define TMPSZ 150
80553 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80554 index 4c03598..e09a8e8 100644
80555 --- a/net/ipv4/tcp_minisocks.c
80556 +++ b/net/ipv4/tcp_minisocks.c
80557 @@ -26,6 +26,10 @@
80558 #include <net/inet_common.h>
80559 #include <net/xfrm.h>
80560
80561 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80562 +extern int grsec_enable_blackhole;
80563 +#endif
80564 +
80565 #ifdef CONFIG_SYSCTL
80566 #define SYNC_INIT 0 /* let the user enable it */
80567 #else
80568 @@ -672,6 +676,10 @@ listen_overflow:
80569
80570 embryonic_reset:
80571 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
80572 +
80573 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80574 + if (!grsec_enable_blackhole)
80575 +#endif
80576 if (!(flg & TCP_FLAG_RST))
80577 req->rsk_ops->send_reset(sk, skb);
80578
80579 diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
80580 index af83bdf..ec91cb2 100644
80581 --- a/net/ipv4/tcp_output.c
80582 +++ b/net/ipv4/tcp_output.c
80583 @@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
80584 __u8 *md5_hash_location;
80585 int mss;
80586
80587 + pax_track_stack();
80588 +
80589 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
80590 if (skb == NULL)
80591 return NULL;
80592 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80593 index 59f5b5e..193860f 100644
80594 --- a/net/ipv4/tcp_probe.c
80595 +++ b/net/ipv4/tcp_probe.c
80596 @@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80597 if (cnt + width >= len)
80598 break;
80599
80600 - if (copy_to_user(buf + cnt, tbuf, width))
80601 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80602 return -EFAULT;
80603 cnt += width;
80604 }
80605 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80606 index 57d5501..a9ed13a 100644
80607 --- a/net/ipv4/tcp_timer.c
80608 +++ b/net/ipv4/tcp_timer.c
80609 @@ -21,6 +21,10 @@
80610 #include <linux/module.h>
80611 #include <net/tcp.h>
80612
80613 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80614 +extern int grsec_lastack_retries;
80615 +#endif
80616 +
80617 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80618 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80619 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80620 @@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock *sk)
80621 }
80622 }
80623
80624 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80625 + if ((sk->sk_state == TCP_LAST_ACK) &&
80626 + (grsec_lastack_retries > 0) &&
80627 + (grsec_lastack_retries < retry_until))
80628 + retry_until = grsec_lastack_retries;
80629 +#endif
80630 +
80631 if (retransmits_timed_out(sk, retry_until)) {
80632 /* Has it gone just too far? */
80633 tcp_write_err(sk);
80634 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80635 index 0ac8833..58d8c43 100644
80636 --- a/net/ipv4/udp.c
80637 +++ b/net/ipv4/udp.c
80638 @@ -86,6 +86,7 @@
80639 #include <linux/types.h>
80640 #include <linux/fcntl.h>
80641 #include <linux/module.h>
80642 +#include <linux/security.h>
80643 #include <linux/socket.h>
80644 #include <linux/sockios.h>
80645 #include <linux/igmp.h>
80646 @@ -106,6 +107,10 @@
80647 #include <net/xfrm.h>
80648 #include "udp_impl.h"
80649
80650 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80651 +extern int grsec_enable_blackhole;
80652 +#endif
80653 +
80654 struct udp_table udp_table;
80655 EXPORT_SYMBOL(udp_table);
80656
80657 @@ -371,6 +376,9 @@ found:
80658 return s;
80659 }
80660
80661 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80662 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80663 +
80664 /*
80665 * This routine is called by the ICMP module when it gets some
80666 * sort of error condition. If err < 0 then the socket should
80667 @@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80668 dport = usin->sin_port;
80669 if (dport == 0)
80670 return -EINVAL;
80671 +
80672 + err = gr_search_udp_sendmsg(sk, usin);
80673 + if (err)
80674 + return err;
80675 } else {
80676 if (sk->sk_state != TCP_ESTABLISHED)
80677 return -EDESTADDRREQ;
80678 +
80679 + err = gr_search_udp_sendmsg(sk, NULL);
80680 + if (err)
80681 + return err;
80682 +
80683 daddr = inet->daddr;
80684 dport = inet->dport;
80685 /* Open fast path for connected socket.
80686 @@ -945,6 +962,10 @@ try_again:
80687 if (!skb)
80688 goto out;
80689
80690 + err = gr_search_udp_recvmsg(sk, skb);
80691 + if (err)
80692 + goto out_free;
80693 +
80694 ulen = skb->len - sizeof(struct udphdr);
80695 copied = len;
80696 if (copied > ulen)
80697 @@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80698 if (rc == -ENOMEM) {
80699 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80700 is_udplite);
80701 - atomic_inc(&sk->sk_drops);
80702 + atomic_inc_unchecked(&sk->sk_drops);
80703 }
80704 goto drop;
80705 }
80706 @@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80707 goto csum_error;
80708
80709 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80710 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80711 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80712 +#endif
80713 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80714
80715 /*
80716 @@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80717 sk_wmem_alloc_get(sp),
80718 sk_rmem_alloc_get(sp),
80719 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80720 - atomic_read(&sp->sk_refcnt), sp,
80721 - atomic_read(&sp->sk_drops), len);
80722 + atomic_read(&sp->sk_refcnt),
80723 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80724 + NULL,
80725 +#else
80726 + sp,
80727 +#endif
80728 + atomic_read_unchecked(&sp->sk_drops), len);
80729 }
80730
80731 int udp4_seq_show(struct seq_file *seq, void *v)
80732 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80733 index 8ac3d09..fc58c5f 100644
80734 --- a/net/ipv6/addrconf.c
80735 +++ b/net/ipv6/addrconf.c
80736 @@ -2053,7 +2053,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80737 p.iph.ihl = 5;
80738 p.iph.protocol = IPPROTO_IPV6;
80739 p.iph.ttl = 64;
80740 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80741 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80742
80743 if (ops->ndo_do_ioctl) {
80744 mm_segment_t oldfs = get_fs();
80745 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
80746 index cc4797d..7cfdfcc 100644
80747 --- a/net/ipv6/inet6_connection_sock.c
80748 +++ b/net/ipv6/inet6_connection_sock.c
80749 @@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
80750 #ifdef CONFIG_XFRM
80751 {
80752 struct rt6_info *rt = (struct rt6_info *)dst;
80753 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
80754 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
80755 }
80756 #endif
80757 }
80758 @@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
80759 #ifdef CONFIG_XFRM
80760 if (dst) {
80761 struct rt6_info *rt = (struct rt6_info *)dst;
80762 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
80763 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
80764 sk->sk_dst_cache = NULL;
80765 dst_release(dst);
80766 dst = NULL;
80767 diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
80768 index 093e9b2..f72cddb 100644
80769 --- a/net/ipv6/inet6_hashtables.c
80770 +++ b/net/ipv6/inet6_hashtables.c
80771 @@ -119,7 +119,7 @@ out:
80772 }
80773 EXPORT_SYMBOL(__inet6_lookup_established);
80774
80775 -static int inline compute_score(struct sock *sk, struct net *net,
80776 +static inline int compute_score(struct sock *sk, struct net *net,
80777 const unsigned short hnum,
80778 const struct in6_addr *daddr,
80779 const int dif)
80780 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80781 index 4f7aaf6..f7acf45 100644
80782 --- a/net/ipv6/ipv6_sockglue.c
80783 +++ b/net/ipv6/ipv6_sockglue.c
80784 @@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
80785 int val, valbool;
80786 int retv = -ENOPROTOOPT;
80787
80788 + pax_track_stack();
80789 +
80790 if (optval == NULL)
80791 val=0;
80792 else {
80793 @@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80794 int len;
80795 int val;
80796
80797 + pax_track_stack();
80798 +
80799 if (ip6_mroute_opt(optname))
80800 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
80801
80802 @@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80803 if (sk->sk_type != SOCK_STREAM)
80804 return -ENOPROTOOPT;
80805
80806 - msg.msg_control = optval;
80807 + msg.msg_control = (void __force_kernel *)optval;
80808 msg.msg_controllen = len;
80809 msg.msg_flags = 0;
80810
80811 diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
80812 index 1cf3f0c..1d4376f 100644
80813 --- a/net/ipv6/netfilter/ip6_queue.c
80814 +++ b/net/ipv6/netfilter/ip6_queue.c
80815 @@ -287,6 +287,9 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80816
80817 if (v->data_len < sizeof(*user_iph))
80818 return 0;
80819 + if (v->data_len > 65535)
80820 + return -EMSGSIZE;
80821 +
80822 diff = v->data_len - e->skb->len;
80823 if (diff < 0) {
80824 if (pskb_trim(e->skb, v->data_len))
80825 @@ -411,7 +414,8 @@ ipq_dev_drop(int ifindex)
80826 static inline void
80827 __ipq_rcv_skb(struct sk_buff *skb)
80828 {
80829 - int status, type, pid, flags, nlmsglen, skblen;
80830 + int status, type, pid, flags;
80831 + unsigned int nlmsglen, skblen;
80832 struct nlmsghdr *nlh;
80833
80834 skblen = skb->len;
80835 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80836 index 78b5a36..7f37433 100644
80837 --- a/net/ipv6/netfilter/ip6_tables.c
80838 +++ b/net/ipv6/netfilter/ip6_tables.c
80839 @@ -1173,6 +1173,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80840 private = &tmp;
80841 }
80842 #endif
80843 + memset(&info, 0, sizeof(info));
80844 info.valid_hooks = t->valid_hooks;
80845 memcpy(info.hook_entry, private->hook_entry,
80846 sizeof(info.hook_entry));
80847 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80848 index 4f24570..b813b34 100644
80849 --- a/net/ipv6/raw.c
80850 +++ b/net/ipv6/raw.c
80851 @@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
80852 {
80853 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
80854 skb_checksum_complete(skb)) {
80855 - atomic_inc(&sk->sk_drops);
80856 + atomic_inc_unchecked(&sk->sk_drops);
80857 kfree_skb(skb);
80858 return NET_RX_DROP;
80859 }
80860
80861 /* Charge it to the socket. */
80862 if (sock_queue_rcv_skb(sk,skb)<0) {
80863 - atomic_inc(&sk->sk_drops);
80864 + atomic_inc_unchecked(&sk->sk_drops);
80865 kfree_skb(skb);
80866 return NET_RX_DROP;
80867 }
80868 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80869 struct raw6_sock *rp = raw6_sk(sk);
80870
80871 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80872 - atomic_inc(&sk->sk_drops);
80873 + atomic_inc_unchecked(&sk->sk_drops);
80874 kfree_skb(skb);
80875 return NET_RX_DROP;
80876 }
80877 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80878
80879 if (inet->hdrincl) {
80880 if (skb_checksum_complete(skb)) {
80881 - atomic_inc(&sk->sk_drops);
80882 + atomic_inc_unchecked(&sk->sk_drops);
80883 kfree_skb(skb);
80884 return NET_RX_DROP;
80885 }
80886 @@ -518,7 +518,7 @@ csum_copy_err:
80887 as some normal condition.
80888 */
80889 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
80890 - atomic_inc(&sk->sk_drops);
80891 + atomic_inc_unchecked(&sk->sk_drops);
80892 goto out;
80893 }
80894
80895 @@ -600,7 +600,7 @@ out:
80896 return err;
80897 }
80898
80899 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80900 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80901 struct flowi *fl, struct rt6_info *rt,
80902 unsigned int flags)
80903 {
80904 @@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
80905 u16 proto;
80906 int err;
80907
80908 + pax_track_stack();
80909 +
80910 /* Rough check on arithmetic overflow,
80911 better check is made in ip6_append_data().
80912 */
80913 @@ -916,12 +918,17 @@ do_confirm:
80914 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80915 char __user *optval, int optlen)
80916 {
80917 + struct icmp6_filter filter;
80918 +
80919 switch (optname) {
80920 case ICMPV6_FILTER:
80921 + if (optlen < 0)
80922 + return -EINVAL;
80923 if (optlen > sizeof(struct icmp6_filter))
80924 optlen = sizeof(struct icmp6_filter);
80925 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80926 + if (copy_from_user(&filter, optval, optlen))
80927 return -EFAULT;
80928 + raw6_sk(sk)->filter = filter;
80929 return 0;
80930 default:
80931 return -ENOPROTOOPT;
80932 @@ -934,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80933 char __user *optval, int __user *optlen)
80934 {
80935 int len;
80936 + struct icmp6_filter filter;
80937
80938 switch (optname) {
80939 case ICMPV6_FILTER:
80940 @@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80941 len = sizeof(struct icmp6_filter);
80942 if (put_user(len, optlen))
80943 return -EFAULT;
80944 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80945 + filter = raw6_sk(sk)->filter;
80946 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80947 return -EFAULT;
80948 return 0;
80949 default:
80950 @@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80951 0, 0L, 0,
80952 sock_i_uid(sp), 0,
80953 sock_i_ino(sp),
80954 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80955 + atomic_read(&sp->sk_refcnt),
80956 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80957 + NULL,
80958 +#else
80959 + sp,
80960 +#endif
80961 + atomic_read_unchecked(&sp->sk_drops));
80962 }
80963
80964 static int raw6_seq_show(struct seq_file *seq, void *v)
80965 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80966 index faae6df..d4430c1 100644
80967 --- a/net/ipv6/tcp_ipv6.c
80968 +++ b/net/ipv6/tcp_ipv6.c
80969 @@ -89,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
80970 }
80971 #endif
80972
80973 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80974 +extern int grsec_enable_blackhole;
80975 +#endif
80976 +
80977 static void tcp_v6_hash(struct sock *sk)
80978 {
80979 if (sk->sk_state != TCP_CLOSE) {
80980 @@ -1579,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80981 return 0;
80982
80983 reset:
80984 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80985 + if (!grsec_enable_blackhole)
80986 +#endif
80987 tcp_v6_send_reset(sk, skb);
80988 discard:
80989 if (opt_skb)
80990 @@ -1656,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80991 TCP_SKB_CB(skb)->sacked = 0;
80992
80993 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80994 - if (!sk)
80995 + if (!sk) {
80996 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80997 + ret = 1;
80998 +#endif
80999 goto no_tcp_socket;
81000 + }
81001
81002 process:
81003 - if (sk->sk_state == TCP_TIME_WAIT)
81004 + if (sk->sk_state == TCP_TIME_WAIT) {
81005 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81006 + ret = 2;
81007 +#endif
81008 goto do_time_wait;
81009 + }
81010
81011 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
81012 goto discard_and_relse;
81013 @@ -1701,6 +1716,10 @@ no_tcp_socket:
81014 bad_packet:
81015 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81016 } else {
81017 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81018 + if (!grsec_enable_blackhole || (ret == 1 &&
81019 + (skb->dev->flags & IFF_LOOPBACK)))
81020 +#endif
81021 tcp_v6_send_reset(NULL, skb);
81022 }
81023
81024 @@ -1916,7 +1935,13 @@ static void get_openreq6(struct seq_file *seq,
81025 uid,
81026 0, /* non standard timer */
81027 0, /* open_requests have no inode */
81028 - 0, req);
81029 + 0,
81030 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81031 + NULL
81032 +#else
81033 + req
81034 +#endif
81035 + );
81036 }
81037
81038 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
81039 @@ -1966,7 +1991,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
81040 sock_i_uid(sp),
81041 icsk->icsk_probes_out,
81042 sock_i_ino(sp),
81043 - atomic_read(&sp->sk_refcnt), sp,
81044 + atomic_read(&sp->sk_refcnt),
81045 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81046 + NULL,
81047 +#else
81048 + sp,
81049 +#endif
81050 jiffies_to_clock_t(icsk->icsk_rto),
81051 jiffies_to_clock_t(icsk->icsk_ack.ato),
81052 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
81053 @@ -2001,7 +2031,13 @@ static void get_timewait6_sock(struct seq_file *seq,
81054 dest->s6_addr32[2], dest->s6_addr32[3], destp,
81055 tw->tw_substate, 0, 0,
81056 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
81057 - atomic_read(&tw->tw_refcnt), tw);
81058 + atomic_read(&tw->tw_refcnt),
81059 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81060 + NULL
81061 +#else
81062 + tw
81063 +#endif
81064 + );
81065 }
81066
81067 static int tcp6_seq_show(struct seq_file *seq, void *v)
81068 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81069 index 9cc6289..052c521 100644
81070 --- a/net/ipv6/udp.c
81071 +++ b/net/ipv6/udp.c
81072 @@ -49,6 +49,10 @@
81073 #include <linux/seq_file.h>
81074 #include "udp_impl.h"
81075
81076 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81077 +extern int grsec_enable_blackhole;
81078 +#endif
81079 +
81080 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81081 {
81082 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81083 @@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
81084 if (rc == -ENOMEM) {
81085 UDP6_INC_STATS_BH(sock_net(sk),
81086 UDP_MIB_RCVBUFERRORS, is_udplite);
81087 - atomic_inc(&sk->sk_drops);
81088 + atomic_inc_unchecked(&sk->sk_drops);
81089 }
81090 goto drop;
81091 }
81092 @@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81093 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
81094 proto == IPPROTO_UDPLITE);
81095
81096 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81097 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81098 +#endif
81099 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
81100
81101 kfree_skb(skb);
81102 @@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81103 0, 0L, 0,
81104 sock_i_uid(sp), 0,
81105 sock_i_ino(sp),
81106 - atomic_read(&sp->sk_refcnt), sp,
81107 - atomic_read(&sp->sk_drops));
81108 + atomic_read(&sp->sk_refcnt),
81109 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81110 + NULL,
81111 +#else
81112 + sp,
81113 +#endif
81114 + atomic_read_unchecked(&sp->sk_drops));
81115 }
81116
81117 int udp6_seq_show(struct seq_file *seq, void *v)
81118 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81119 index 811984d..11f59b7 100644
81120 --- a/net/irda/ircomm/ircomm_tty.c
81121 +++ b/net/irda/ircomm/ircomm_tty.c
81122 @@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81123 add_wait_queue(&self->open_wait, &wait);
81124
81125 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81126 - __FILE__,__LINE__, tty->driver->name, self->open_count );
81127 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
81128
81129 /* As far as I can see, we protect open_count - Jean II */
81130 spin_lock_irqsave(&self->spinlock, flags);
81131 if (!tty_hung_up_p(filp)) {
81132 extra_count = 1;
81133 - self->open_count--;
81134 + local_dec(&self->open_count);
81135 }
81136 spin_unlock_irqrestore(&self->spinlock, flags);
81137 - self->blocked_open++;
81138 + local_inc(&self->blocked_open);
81139
81140 while (1) {
81141 if (tty->termios->c_cflag & CBAUD) {
81142 @@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81143 }
81144
81145 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81146 - __FILE__,__LINE__, tty->driver->name, self->open_count );
81147 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
81148
81149 schedule();
81150 }
81151 @@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81152 if (extra_count) {
81153 /* ++ is not atomic, so this should be protected - Jean II */
81154 spin_lock_irqsave(&self->spinlock, flags);
81155 - self->open_count++;
81156 + local_inc(&self->open_count);
81157 spin_unlock_irqrestore(&self->spinlock, flags);
81158 }
81159 - self->blocked_open--;
81160 + local_dec(&self->blocked_open);
81161
81162 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81163 - __FILE__,__LINE__, tty->driver->name, self->open_count);
81164 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
81165
81166 if (!retval)
81167 self->flags |= ASYNC_NORMAL_ACTIVE;
81168 @@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81169 }
81170 /* ++ is not atomic, so this should be protected - Jean II */
81171 spin_lock_irqsave(&self->spinlock, flags);
81172 - self->open_count++;
81173 + local_inc(&self->open_count);
81174
81175 tty->driver_data = self;
81176 self->tty = tty;
81177 spin_unlock_irqrestore(&self->spinlock, flags);
81178
81179 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81180 - self->line, self->open_count);
81181 + self->line, local_read(&self->open_count));
81182
81183 /* Not really used by us, but lets do it anyway */
81184 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81185 @@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81186 return;
81187 }
81188
81189 - if ((tty->count == 1) && (self->open_count != 1)) {
81190 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
81191 /*
81192 * Uh, oh. tty->count is 1, which means that the tty
81193 * structure will be freed. state->count should always
81194 @@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81195 */
81196 IRDA_DEBUG(0, "%s(), bad serial port count; "
81197 "tty->count is 1, state->count is %d\n", __func__ ,
81198 - self->open_count);
81199 - self->open_count = 1;
81200 + local_read(&self->open_count));
81201 + local_set(&self->open_count, 1);
81202 }
81203
81204 - if (--self->open_count < 0) {
81205 + if (local_dec_return(&self->open_count) < 0) {
81206 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
81207 - __func__, self->line, self->open_count);
81208 - self->open_count = 0;
81209 + __func__, self->line, local_read(&self->open_count));
81210 + local_set(&self->open_count, 0);
81211 }
81212 - if (self->open_count) {
81213 + if (local_read(&self->open_count)) {
81214 spin_unlock_irqrestore(&self->spinlock, flags);
81215
81216 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
81217 @@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81218 tty->closing = 0;
81219 self->tty = NULL;
81220
81221 - if (self->blocked_open) {
81222 + if (local_read(&self->blocked_open)) {
81223 if (self->close_delay)
81224 schedule_timeout_interruptible(self->close_delay);
81225 wake_up_interruptible(&self->open_wait);
81226 @@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81227 spin_lock_irqsave(&self->spinlock, flags);
81228 self->flags &= ~ASYNC_NORMAL_ACTIVE;
81229 self->tty = NULL;
81230 - self->open_count = 0;
81231 + local_set(&self->open_count, 0);
81232 spin_unlock_irqrestore(&self->spinlock, flags);
81233
81234 wake_up_interruptible(&self->open_wait);
81235 @@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81236 seq_putc(m, '\n');
81237
81238 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81239 - seq_printf(m, "Open count: %d\n", self->open_count);
81240 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
81241 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81242 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81243
81244 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81245 index bada1b9..f325943 100644
81246 --- a/net/iucv/af_iucv.c
81247 +++ b/net/iucv/af_iucv.c
81248 @@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct sock *sk)
81249
81250 write_lock_bh(&iucv_sk_list.lock);
81251
81252 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81253 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81254 while (__iucv_get_sock_by_name(name)) {
81255 sprintf(name, "%08x",
81256 - atomic_inc_return(&iucv_sk_list.autobind_name));
81257 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81258 }
81259
81260 write_unlock_bh(&iucv_sk_list.lock);
81261 diff --git a/net/key/af_key.c b/net/key/af_key.c
81262 index 4e98193..439b449 100644
81263 --- a/net/key/af_key.c
81264 +++ b/net/key/af_key.c
81265 @@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
81266 struct xfrm_migrate m[XFRM_MAX_DEPTH];
81267 struct xfrm_kmaddress k;
81268
81269 + pax_track_stack();
81270 +
81271 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
81272 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
81273 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
81274 @@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
81275 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
81276 else
81277 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
81278 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81279 + NULL,
81280 +#else
81281 s,
81282 +#endif
81283 atomic_read(&s->sk_refcnt),
81284 sk_rmem_alloc_get(s),
81285 sk_wmem_alloc_get(s),
81286 diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
81287 index bda96d1..c038b72 100644
81288 --- a/net/lapb/lapb_iface.c
81289 +++ b/net/lapb/lapb_iface.c
81290 @@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
81291 goto out;
81292
81293 lapb->dev = dev;
81294 - lapb->callbacks = *callbacks;
81295 + lapb->callbacks = callbacks;
81296
81297 __lapb_insert_cb(lapb);
81298
81299 @@ -379,32 +379,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
81300
81301 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
81302 {
81303 - if (lapb->callbacks.connect_confirmation)
81304 - lapb->callbacks.connect_confirmation(lapb->dev, reason);
81305 + if (lapb->callbacks->connect_confirmation)
81306 + lapb->callbacks->connect_confirmation(lapb->dev, reason);
81307 }
81308
81309 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
81310 {
81311 - if (lapb->callbacks.connect_indication)
81312 - lapb->callbacks.connect_indication(lapb->dev, reason);
81313 + if (lapb->callbacks->connect_indication)
81314 + lapb->callbacks->connect_indication(lapb->dev, reason);
81315 }
81316
81317 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
81318 {
81319 - if (lapb->callbacks.disconnect_confirmation)
81320 - lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
81321 + if (lapb->callbacks->disconnect_confirmation)
81322 + lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
81323 }
81324
81325 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
81326 {
81327 - if (lapb->callbacks.disconnect_indication)
81328 - lapb->callbacks.disconnect_indication(lapb->dev, reason);
81329 + if (lapb->callbacks->disconnect_indication)
81330 + lapb->callbacks->disconnect_indication(lapb->dev, reason);
81331 }
81332
81333 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
81334 {
81335 - if (lapb->callbacks.data_indication)
81336 - return lapb->callbacks.data_indication(lapb->dev, skb);
81337 + if (lapb->callbacks->data_indication)
81338 + return lapb->callbacks->data_indication(lapb->dev, skb);
81339
81340 kfree_skb(skb);
81341 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
81342 @@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
81343 {
81344 int used = 0;
81345
81346 - if (lapb->callbacks.data_transmit) {
81347 - lapb->callbacks.data_transmit(lapb->dev, skb);
81348 + if (lapb->callbacks->data_transmit) {
81349 + lapb->callbacks->data_transmit(lapb->dev, skb);
81350 used = 1;
81351 }
81352
81353 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81354 index fe2d3f8..e57f683 100644
81355 --- a/net/mac80211/cfg.c
81356 +++ b/net/mac80211/cfg.c
81357 @@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
81358 return err;
81359 }
81360
81361 -struct cfg80211_ops mac80211_config_ops = {
81362 +const struct cfg80211_ops mac80211_config_ops = {
81363 .add_virtual_intf = ieee80211_add_iface,
81364 .del_virtual_intf = ieee80211_del_iface,
81365 .change_virtual_intf = ieee80211_change_iface,
81366 diff --git a/net/mac80211/cfg.h b/net/mac80211/cfg.h
81367 index 7d7879f..2d51f62 100644
81368 --- a/net/mac80211/cfg.h
81369 +++ b/net/mac80211/cfg.h
81370 @@ -4,6 +4,6 @@
81371 #ifndef __CFG_H
81372 #define __CFG_H
81373
81374 -extern struct cfg80211_ops mac80211_config_ops;
81375 +extern const struct cfg80211_ops mac80211_config_ops;
81376
81377 #endif /* __CFG_H */
81378 diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
81379 index 99c7525..9cb4937 100644
81380 --- a/net/mac80211/debugfs_key.c
81381 +++ b/net/mac80211/debugfs_key.c
81382 @@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
81383 size_t count, loff_t *ppos)
81384 {
81385 struct ieee80211_key *key = file->private_data;
81386 - int i, res, bufsize = 2 * key->conf.keylen + 2;
81387 + int i, bufsize = 2 * key->conf.keylen + 2;
81388 char *buf = kmalloc(bufsize, GFP_KERNEL);
81389 char *p = buf;
81390 + ssize_t res;
81391 +
81392 + if (buf == NULL)
81393 + return -ENOMEM;
81394
81395 for (i = 0; i < key->conf.keylen; i++)
81396 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
81397 diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
81398 index 33a2e89..08650c8 100644
81399 --- a/net/mac80211/debugfs_sta.c
81400 +++ b/net/mac80211/debugfs_sta.c
81401 @@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
81402 int i;
81403 struct sta_info *sta = file->private_data;
81404
81405 + pax_track_stack();
81406 +
81407 spin_lock_bh(&sta->lock);
81408 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
81409 sta->ampdu_mlme.dialog_token_allocator + 1);
81410 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81411 index ca62bfe..6657a03 100644
81412 --- a/net/mac80211/ieee80211_i.h
81413 +++ b/net/mac80211/ieee80211_i.h
81414 @@ -25,6 +25,7 @@
81415 #include <linux/etherdevice.h>
81416 #include <net/cfg80211.h>
81417 #include <net/mac80211.h>
81418 +#include <asm/local.h>
81419 #include "key.h"
81420 #include "sta_info.h"
81421
81422 @@ -635,7 +636,7 @@ struct ieee80211_local {
81423 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81424 spinlock_t queue_stop_reason_lock;
81425
81426 - int open_count;
81427 + local_t open_count;
81428 int monitors, cooked_mntrs;
81429 /* number of interfaces with corresponding FIF_ flags */
81430 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
81431 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81432 index 079c500..eb3c6d4 100644
81433 --- a/net/mac80211/iface.c
81434 +++ b/net/mac80211/iface.c
81435 @@ -166,7 +166,7 @@ static int ieee80211_open(struct net_device *dev)
81436 break;
81437 }
81438
81439 - if (local->open_count == 0) {
81440 + if (local_read(&local->open_count) == 0) {
81441 res = drv_start(local);
81442 if (res)
81443 goto err_del_bss;
81444 @@ -196,7 +196,7 @@ static int ieee80211_open(struct net_device *dev)
81445 * Validate the MAC address for this device.
81446 */
81447 if (!is_valid_ether_addr(dev->dev_addr)) {
81448 - if (!local->open_count)
81449 + if (!local_read(&local->open_count))
81450 drv_stop(local);
81451 return -EADDRNOTAVAIL;
81452 }
81453 @@ -292,7 +292,7 @@ static int ieee80211_open(struct net_device *dev)
81454
81455 hw_reconf_flags |= __ieee80211_recalc_idle(local);
81456
81457 - local->open_count++;
81458 + local_inc(&local->open_count);
81459 if (hw_reconf_flags) {
81460 ieee80211_hw_config(local, hw_reconf_flags);
81461 /*
81462 @@ -320,7 +320,7 @@ static int ieee80211_open(struct net_device *dev)
81463 err_del_interface:
81464 drv_remove_interface(local, &conf);
81465 err_stop:
81466 - if (!local->open_count)
81467 + if (!local_read(&local->open_count))
81468 drv_stop(local);
81469 err_del_bss:
81470 sdata->bss = NULL;
81471 @@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_device *dev)
81472 WARN_ON(!list_empty(&sdata->u.ap.vlans));
81473 }
81474
81475 - local->open_count--;
81476 + local_dec(&local->open_count);
81477
81478 switch (sdata->vif.type) {
81479 case NL80211_IFTYPE_AP_VLAN:
81480 @@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_device *dev)
81481
81482 ieee80211_recalc_ps(local, -1);
81483
81484 - if (local->open_count == 0) {
81485 + if (local_read(&local->open_count) == 0) {
81486 ieee80211_clear_tx_pending(local);
81487 ieee80211_stop_device(local);
81488
81489 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81490 index 2dfe176..74e4388 100644
81491 --- a/net/mac80211/main.c
81492 +++ b/net/mac80211/main.c
81493 @@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81494 local->hw.conf.power_level = power;
81495 }
81496
81497 - if (changed && local->open_count) {
81498 + if (changed && local_read(&local->open_count)) {
81499 ret = drv_config(local, changed);
81500 /*
81501 * Goal:
81502 diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
81503 index e67eea7..fcc227e 100644
81504 --- a/net/mac80211/mlme.c
81505 +++ b/net/mac80211/mlme.c
81506 @@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
81507 bool have_higher_than_11mbit = false, newsta = false;
81508 u16 ap_ht_cap_flags;
81509
81510 + pax_track_stack();
81511 +
81512 /*
81513 * AssocResp and ReassocResp have identical structure, so process both
81514 * of them in this function.
81515 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81516 index e535f1c..4d733d1 100644
81517 --- a/net/mac80211/pm.c
81518 +++ b/net/mac80211/pm.c
81519 @@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
81520 }
81521
81522 /* stop hardware - this must stop RX */
81523 - if (local->open_count)
81524 + if (local_read(&local->open_count))
81525 ieee80211_stop_device(local);
81526
81527 local->suspended = true;
81528 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81529 index b33efc4..0a2efb6 100644
81530 --- a/net/mac80211/rate.c
81531 +++ b/net/mac80211/rate.c
81532 @@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81533 struct rate_control_ref *ref, *old;
81534
81535 ASSERT_RTNL();
81536 - if (local->open_count)
81537 + if (local_read(&local->open_count))
81538 return -EBUSY;
81539
81540 ref = rate_control_alloc(name, local);
81541 diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
81542 index b1d7904..57e4da7 100644
81543 --- a/net/mac80211/tx.c
81544 +++ b/net/mac80211/tx.c
81545 @@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
81546 return cpu_to_le16(dur);
81547 }
81548
81549 -static int inline is_ieee80211_device(struct ieee80211_local *local,
81550 +static inline int is_ieee80211_device(struct ieee80211_local *local,
81551 struct net_device *dev)
81552 {
81553 return local == wdev_priv(dev->ieee80211_ptr);
81554 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81555 index 31b1085..48fb26d 100644
81556 --- a/net/mac80211/util.c
81557 +++ b/net/mac80211/util.c
81558 @@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81559 local->resuming = true;
81560
81561 /* restart hardware */
81562 - if (local->open_count) {
81563 + if (local_read(&local->open_count)) {
81564 /*
81565 * Upon resume hardware can sometimes be goofy due to
81566 * various platform / driver / bus issues, so restarting
81567 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81568 index 634d14a..b35a608 100644
81569 --- a/net/netfilter/Kconfig
81570 +++ b/net/netfilter/Kconfig
81571 @@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
81572
81573 To compile it as a module, choose M here. If unsure, say N.
81574
81575 +config NETFILTER_XT_MATCH_GRADM
81576 + tristate '"gradm" match support'
81577 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81578 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81579 + ---help---
81580 + The gradm match allows to match on grsecurity RBAC being enabled.
81581 + It is useful when iptables rules are applied early on bootup to
81582 + prevent connections to the machine (except from a trusted host)
81583 + while the RBAC system is disabled.
81584 +
81585 config NETFILTER_XT_MATCH_HASHLIMIT
81586 tristate '"hashlimit" match support'
81587 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81588 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81589 index 49f62ee..a17b2c6 100644
81590 --- a/net/netfilter/Makefile
81591 +++ b/net/netfilter/Makefile
81592 @@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
81593 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
81594 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81595 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81596 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81597 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81598 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81599 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81600 diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
81601 index 3c7e427..724043c 100644
81602 --- a/net/netfilter/ipvs/ip_vs_app.c
81603 +++ b/net/netfilter/ipvs/ip_vs_app.c
81604 @@ -564,7 +564,7 @@ static const struct file_operations ip_vs_app_fops = {
81605 .open = ip_vs_app_open,
81606 .read = seq_read,
81607 .llseek = seq_lseek,
81608 - .release = seq_release,
81609 + .release = seq_release_net,
81610 };
81611 #endif
81612
81613 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81614 index 95682e5..457dbac 100644
81615 --- a/net/netfilter/ipvs/ip_vs_conn.c
81616 +++ b/net/netfilter/ipvs/ip_vs_conn.c
81617 @@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81618 /* if the connection is not template and is created
81619 * by sync, preserve the activity flag.
81620 */
81621 - cp->flags |= atomic_read(&dest->conn_flags) &
81622 + cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
81623 (~IP_VS_CONN_F_INACTIVE);
81624 else
81625 - cp->flags |= atomic_read(&dest->conn_flags);
81626 + cp->flags |= atomic_read_unchecked(&dest->conn_flags);
81627 cp->dest = dest;
81628
81629 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
81630 @@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
81631 atomic_set(&cp->refcnt, 1);
81632
81633 atomic_set(&cp->n_control, 0);
81634 - atomic_set(&cp->in_pkts, 0);
81635 + atomic_set_unchecked(&cp->in_pkts, 0);
81636
81637 atomic_inc(&ip_vs_conn_count);
81638 if (flags & IP_VS_CONN_F_NO_CPORT)
81639 @@ -871,7 +871,7 @@ static const struct file_operations ip_vs_conn_fops = {
81640 .open = ip_vs_conn_open,
81641 .read = seq_read,
81642 .llseek = seq_lseek,
81643 - .release = seq_release,
81644 + .release = seq_release_net,
81645 };
81646
81647 static const char *ip_vs_origin_name(unsigned flags)
81648 @@ -934,7 +934,7 @@ static const struct file_operations ip_vs_conn_sync_fops = {
81649 .open = ip_vs_conn_sync_open,
81650 .read = seq_read,
81651 .llseek = seq_lseek,
81652 - .release = seq_release,
81653 + .release = seq_release_net,
81654 };
81655
81656 #endif
81657 @@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81658
81659 /* Don't drop the entry if its number of incoming packets is not
81660 located in [0, 8] */
81661 - i = atomic_read(&cp->in_pkts);
81662 + i = atomic_read_unchecked(&cp->in_pkts);
81663 if (i > 8 || i < 0) return 0;
81664
81665 if (!todrop_rate[i]) return 0;
81666 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81667 index b95699f..5fee919 100644
81668 --- a/net/netfilter/ipvs/ip_vs_core.c
81669 +++ b/net/netfilter/ipvs/ip_vs_core.c
81670 @@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81671 ret = cp->packet_xmit(skb, cp, pp);
81672 /* do not touch skb anymore */
81673
81674 - atomic_inc(&cp->in_pkts);
81675 + atomic_inc_unchecked(&cp->in_pkts);
81676 ip_vs_conn_put(cp);
81677 return ret;
81678 }
81679 @@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
81680 * Sync connection if it is about to close to
81681 * encorage the standby servers to update the connections timeout
81682 */
81683 - pkts = atomic_add_return(1, &cp->in_pkts);
81684 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81685 if (af == AF_INET &&
81686 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
81687 (((cp->protocol != IPPROTO_TCP ||
81688 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81689 index 02b2610..2d89424 100644
81690 --- a/net/netfilter/ipvs/ip_vs_ctl.c
81691 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
81692 @@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc,
81693 ip_vs_rs_hash(dest);
81694 write_unlock_bh(&__ip_vs_rs_lock);
81695 }
81696 - atomic_set(&dest->conn_flags, conn_flags);
81697 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
81698
81699 /* bind the service */
81700 if (!dest->svc) {
81701 @@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81702 " %-7s %-6d %-10d %-10d\n",
81703 &dest->addr.in6,
81704 ntohs(dest->port),
81705 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81706 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81707 atomic_read(&dest->weight),
81708 atomic_read(&dest->activeconns),
81709 atomic_read(&dest->inactconns));
81710 @@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81711 "%-7s %-6d %-10d %-10d\n",
81712 ntohl(dest->addr.ip),
81713 ntohs(dest->port),
81714 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81715 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81716 atomic_read(&dest->weight),
81717 atomic_read(&dest->activeconns),
81718 atomic_read(&dest->inactconns));
81719 @@ -1927,7 +1927,7 @@ static const struct file_operations ip_vs_info_fops = {
81720 .open = ip_vs_info_open,
81721 .read = seq_read,
81722 .llseek = seq_lseek,
81723 - .release = seq_release_private,
81724 + .release = seq_release_net,
81725 };
81726
81727 #endif
81728 @@ -1976,7 +1976,7 @@ static const struct file_operations ip_vs_stats_fops = {
81729 .open = ip_vs_stats_seq_open,
81730 .read = seq_read,
81731 .llseek = seq_lseek,
81732 - .release = single_release,
81733 + .release = single_release_net,
81734 };
81735
81736 #endif
81737 @@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip_vs_get_dests *get,
81738
81739 entry.addr = dest->addr.ip;
81740 entry.port = dest->port;
81741 - entry.conn_flags = atomic_read(&dest->conn_flags);
81742 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81743 entry.weight = atomic_read(&dest->weight);
81744 entry.u_threshold = dest->u_threshold;
81745 entry.l_threshold = dest->l_threshold;
81746 @@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81747 unsigned char arg[128];
81748 int ret = 0;
81749
81750 + pax_track_stack();
81751 +
81752 if (!capable(CAP_NET_ADMIN))
81753 return -EPERM;
81754
81755 @@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81756 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
81757
81758 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81759 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
81760 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
81761 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
81762 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
81763 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
81764 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81765 index e177f0d..55e8581 100644
81766 --- a/net/netfilter/ipvs/ip_vs_sync.c
81767 +++ b/net/netfilter/ipvs/ip_vs_sync.c
81768 @@ -438,7 +438,7 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
81769
81770 if (opt)
81771 memcpy(&cp->in_seq, opt, sizeof(*opt));
81772 - atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
81773 + atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
81774 cp->state = state;
81775 cp->old_state = cp->state;
81776 /*
81777 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81778 index 30b3189..e2e4b55 100644
81779 --- a/net/netfilter/ipvs/ip_vs_xmit.c
81780 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
81781 @@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81782 else
81783 rc = NF_ACCEPT;
81784 /* do not touch skb anymore */
81785 - atomic_inc(&cp->in_pkts);
81786 + atomic_inc_unchecked(&cp->in_pkts);
81787 goto out;
81788 }
81789
81790 @@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81791 else
81792 rc = NF_ACCEPT;
81793 /* do not touch skb anymore */
81794 - atomic_inc(&cp->in_pkts);
81795 + atomic_inc_unchecked(&cp->in_pkts);
81796 goto out;
81797 }
81798
81799 diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
81800 index d521718..d0fd7a1 100644
81801 --- a/net/netfilter/nf_conntrack_netlink.c
81802 +++ b/net/netfilter/nf_conntrack_netlink.c
81803 @@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
81804 static int
81805 ctnetlink_parse_tuple(const struct nlattr * const cda[],
81806 struct nf_conntrack_tuple *tuple,
81807 - enum ctattr_tuple type, u_int8_t l3num)
81808 + enum ctattr_type type, u_int8_t l3num)
81809 {
81810 struct nlattr *tb[CTA_TUPLE_MAX+1];
81811 int err;
81812 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81813 index f900dc3..5e45346 100644
81814 --- a/net/netfilter/nfnetlink_log.c
81815 +++ b/net/netfilter/nfnetlink_log.c
81816 @@ -68,7 +68,7 @@ struct nfulnl_instance {
81817 };
81818
81819 static DEFINE_RWLOCK(instances_lock);
81820 -static atomic_t global_seq;
81821 +static atomic_unchecked_t global_seq;
81822
81823 #define INSTANCE_BUCKETS 16
81824 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81825 @@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81826 /* global sequence number */
81827 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
81828 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
81829 - htonl(atomic_inc_return(&global_seq)));
81830 + htonl(atomic_inc_return_unchecked(&global_seq)));
81831
81832 if (data_len) {
81833 struct nlattr *nla;
81834 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81835 new file mode 100644
81836 index 0000000..b1bac76
81837 --- /dev/null
81838 +++ b/net/netfilter/xt_gradm.c
81839 @@ -0,0 +1,51 @@
81840 +/*
81841 + * gradm match for netfilter
81842 + * Copyright © Zbigniew Krzystolik, 2010
81843 + *
81844 + * This program is free software; you can redistribute it and/or modify
81845 + * it under the terms of the GNU General Public License; either version
81846 + * 2 or 3 as published by the Free Software Foundation.
81847 + */
81848 +#include <linux/module.h>
81849 +#include <linux/moduleparam.h>
81850 +#include <linux/skbuff.h>
81851 +#include <linux/netfilter/x_tables.h>
81852 +#include <linux/grsecurity.h>
81853 +#include <linux/netfilter/xt_gradm.h>
81854 +
81855 +static bool
81856 +gradm_mt(const struct sk_buff *skb, const struct xt_match_param *par)
81857 +{
81858 + const struct xt_gradm_mtinfo *info = par->matchinfo;
81859 + bool retval = false;
81860 + if (gr_acl_is_enabled())
81861 + retval = true;
81862 + return retval ^ info->invflags;
81863 +}
81864 +
81865 +static struct xt_match gradm_mt_reg __read_mostly = {
81866 + .name = "gradm",
81867 + .revision = 0,
81868 + .family = NFPROTO_UNSPEC,
81869 + .match = gradm_mt,
81870 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
81871 + .me = THIS_MODULE,
81872 +};
81873 +
81874 +static int __init gradm_mt_init(void)
81875 +{
81876 + return xt_register_match(&gradm_mt_reg);
81877 +}
81878 +
81879 +static void __exit gradm_mt_exit(void)
81880 +{
81881 + xt_unregister_match(&gradm_mt_reg);
81882 +}
81883 +
81884 +module_init(gradm_mt_init);
81885 +module_exit(gradm_mt_exit);
81886 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
81887 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
81888 +MODULE_LICENSE("GPL");
81889 +MODULE_ALIAS("ipt_gradm");
81890 +MODULE_ALIAS("ip6t_gradm");
81891 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
81892 index 5a7dcdf..24a3578 100644
81893 --- a/net/netlink/af_netlink.c
81894 +++ b/net/netlink/af_netlink.c
81895 @@ -733,7 +733,7 @@ static void netlink_overrun(struct sock *sk)
81896 sk->sk_error_report(sk);
81897 }
81898 }
81899 - atomic_inc(&sk->sk_drops);
81900 + atomic_inc_unchecked(&sk->sk_drops);
81901 }
81902
81903 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
81904 @@ -1964,15 +1964,23 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
81905 struct netlink_sock *nlk = nlk_sk(s);
81906
81907 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d\n",
81908 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81909 + NULL,
81910 +#else
81911 s,
81912 +#endif
81913 s->sk_protocol,
81914 nlk->pid,
81915 nlk->groups ? (u32)nlk->groups[0] : 0,
81916 sk_rmem_alloc_get(s),
81917 sk_wmem_alloc_get(s),
81918 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81919 + NULL,
81920 +#else
81921 nlk->cb,
81922 +#endif
81923 atomic_read(&s->sk_refcnt),
81924 - atomic_read(&s->sk_drops)
81925 + atomic_read_unchecked(&s->sk_drops)
81926 );
81927
81928 }
81929 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
81930 index 7a83495..ab0062f 100644
81931 --- a/net/netrom/af_netrom.c
81932 +++ b/net/netrom/af_netrom.c
81933 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81934 struct sock *sk = sock->sk;
81935 struct nr_sock *nr = nr_sk(sk);
81936
81937 + memset(sax, 0, sizeof(*sax));
81938 lock_sock(sk);
81939 if (peer != 0) {
81940 if (sk->sk_state != TCP_ESTABLISHED) {
81941 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81942 *uaddr_len = sizeof(struct full_sockaddr_ax25);
81943 } else {
81944 sax->fsa_ax25.sax25_family = AF_NETROM;
81945 - sax->fsa_ax25.sax25_ndigis = 0;
81946 sax->fsa_ax25.sax25_call = nr->source_addr;
81947 *uaddr_len = sizeof(struct sockaddr_ax25);
81948 }
81949 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
81950 index 35cfa79..4e78ff7 100644
81951 --- a/net/packet/af_packet.c
81952 +++ b/net/packet/af_packet.c
81953 @@ -2429,7 +2429,11 @@ static int packet_seq_show(struct seq_file *seq, void *v)
81954
81955 seq_printf(seq,
81956 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
81957 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81958 + NULL,
81959 +#else
81960 s,
81961 +#endif
81962 atomic_read(&s->sk_refcnt),
81963 s->sk_type,
81964 ntohs(po->num),
81965 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
81966 index 519ff9d..a422a90 100644
81967 --- a/net/phonet/af_phonet.c
81968 +++ b/net/phonet/af_phonet.c
81969 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(int protocol)
81970 {
81971 struct phonet_protocol *pp;
81972
81973 - if (protocol >= PHONET_NPROTO)
81974 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81975 return NULL;
81976
81977 spin_lock(&proto_tab_lock);
81978 @@ -402,7 +402,7 @@ int __init_or_module phonet_proto_register(int protocol,
81979 {
81980 int err = 0;
81981
81982 - if (protocol >= PHONET_NPROTO)
81983 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81984 return -EINVAL;
81985
81986 err = proto_register(pp->prot, 1);
81987 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
81988 index ef5c75c..2b6c2fa 100644
81989 --- a/net/phonet/datagram.c
81990 +++ b/net/phonet/datagram.c
81991 @@ -162,7 +162,7 @@ static int pn_backlog_rcv(struct sock *sk, struct sk_buff *skb)
81992 if (err < 0) {
81993 kfree_skb(skb);
81994 if (err == -ENOMEM)
81995 - atomic_inc(&sk->sk_drops);
81996 + atomic_inc_unchecked(&sk->sk_drops);
81997 }
81998 return err ? NET_RX_DROP : NET_RX_SUCCESS;
81999 }
82000 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
82001 index 9cdd35e..16cd850 100644
82002 --- a/net/phonet/pep.c
82003 +++ b/net/phonet/pep.c
82004 @@ -348,7 +348,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82005
82006 case PNS_PEP_CTRL_REQ:
82007 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
82008 - atomic_inc(&sk->sk_drops);
82009 + atomic_inc_unchecked(&sk->sk_drops);
82010 break;
82011 }
82012 __skb_pull(skb, 4);
82013 @@ -362,12 +362,12 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82014 if (!err)
82015 return 0;
82016 if (err == -ENOMEM)
82017 - atomic_inc(&sk->sk_drops);
82018 + atomic_inc_unchecked(&sk->sk_drops);
82019 break;
82020 }
82021
82022 if (pn->rx_credits == 0) {
82023 - atomic_inc(&sk->sk_drops);
82024 + atomic_inc_unchecked(&sk->sk_drops);
82025 err = -ENOBUFS;
82026 break;
82027 }
82028 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
82029 index aa5b5a9..c09b4f8 100644
82030 --- a/net/phonet/socket.c
82031 +++ b/net/phonet/socket.c
82032 @@ -482,8 +482,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
82033 sk->sk_state,
82034 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
82035 sock_i_uid(sk), sock_i_ino(sk),
82036 - atomic_read(&sk->sk_refcnt), sk,
82037 - atomic_read(&sk->sk_drops), &len);
82038 + atomic_read(&sk->sk_refcnt),
82039 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82040 + NULL,
82041 +#else
82042 + sk,
82043 +#endif
82044 + atomic_read_unchecked(&sk->sk_drops), &len);
82045 }
82046 seq_printf(seq, "%*s\n", 127 - len, "");
82047 return 0;
82048 diff --git a/net/rds/Kconfig b/net/rds/Kconfig
82049 index ec753b3..821187c 100644
82050 --- a/net/rds/Kconfig
82051 +++ b/net/rds/Kconfig
82052 @@ -1,7 +1,7 @@
82053
82054 config RDS
82055 tristate "The RDS Protocol (EXPERIMENTAL)"
82056 - depends on INET && EXPERIMENTAL
82057 + depends on INET && EXPERIMENTAL && BROKEN
82058 ---help---
82059 The RDS (Reliable Datagram Sockets) protocol provides reliable,
82060 sequenced delivery of datagrams over Infiniband, iWARP,
82061 diff --git a/net/rds/cong.c b/net/rds/cong.c
82062 index dd2711d..1c7ed12 100644
82063 --- a/net/rds/cong.c
82064 +++ b/net/rds/cong.c
82065 @@ -77,7 +77,7 @@
82066 * finds that the saved generation number is smaller than the global generation
82067 * number, it wakes up the process.
82068 */
82069 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
82070 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
82071
82072 /*
82073 * Congestion monitoring
82074 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
82075 rdsdebug("waking map %p for %pI4\n",
82076 map, &map->m_addr);
82077 rds_stats_inc(s_cong_update_received);
82078 - atomic_inc(&rds_cong_generation);
82079 + atomic_inc_unchecked(&rds_cong_generation);
82080 if (waitqueue_active(&map->m_waitq))
82081 wake_up(&map->m_waitq);
82082 if (waitqueue_active(&rds_poll_waitq))
82083 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
82084
82085 int rds_cong_updated_since(unsigned long *recent)
82086 {
82087 - unsigned long gen = atomic_read(&rds_cong_generation);
82088 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
82089
82090 if (likely(*recent == gen))
82091 return 0;
82092 diff --git a/net/rds/iw_rdma.c b/net/rds/iw_rdma.c
82093 index de4a1b1..94ec861 100644
82094 --- a/net/rds/iw_rdma.c
82095 +++ b/net/rds/iw_rdma.c
82096 @@ -181,6 +181,8 @@ int rds_iw_update_cm_id(struct rds_iw_device *rds_iwdev, struct rdma_cm_id *cm_i
82097 struct rdma_cm_id *pcm_id;
82098 int rc;
82099
82100 + pax_track_stack();
82101 +
82102 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
82103 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
82104
82105 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
82106 index b5198ae..8b9fb90 100644
82107 --- a/net/rds/tcp.c
82108 +++ b/net/rds/tcp.c
82109 @@ -57,7 +57,7 @@ void rds_tcp_nonagle(struct socket *sock)
82110 int val = 1;
82111
82112 set_fs(KERNEL_DS);
82113 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
82114 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
82115 sizeof(val));
82116 set_fs(oldfs);
82117 }
82118 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
82119 index ab545e0..4079b3b 100644
82120 --- a/net/rds/tcp_send.c
82121 +++ b/net/rds/tcp_send.c
82122 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
82123
82124 oldfs = get_fs();
82125 set_fs(KERNEL_DS);
82126 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
82127 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
82128 sizeof(val));
82129 set_fs(oldfs);
82130 }
82131 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
82132 index a86afce..8657bce 100644
82133 --- a/net/rxrpc/af_rxrpc.c
82134 +++ b/net/rxrpc/af_rxrpc.c
82135 @@ -38,7 +38,7 @@ static const struct proto_ops rxrpc_rpc_ops;
82136 __be32 rxrpc_epoch;
82137
82138 /* current debugging ID */
82139 -atomic_t rxrpc_debug_id;
82140 +atomic_unchecked_t rxrpc_debug_id;
82141
82142 /* count of skbs currently in use */
82143 atomic_t rxrpc_n_skbs;
82144 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
82145 index b4a2209..539106c 100644
82146 --- a/net/rxrpc/ar-ack.c
82147 +++ b/net/rxrpc/ar-ack.c
82148 @@ -174,7 +174,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82149
82150 _enter("{%d,%d,%d,%d},",
82151 call->acks_hard, call->acks_unacked,
82152 - atomic_read(&call->sequence),
82153 + atomic_read_unchecked(&call->sequence),
82154 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
82155
82156 stop = 0;
82157 @@ -198,7 +198,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82158
82159 /* each Tx packet has a new serial number */
82160 sp->hdr.serial =
82161 - htonl(atomic_inc_return(&call->conn->serial));
82162 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
82163
82164 hdr = (struct rxrpc_header *) txb->head;
82165 hdr->serial = sp->hdr.serial;
82166 @@ -401,7 +401,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
82167 */
82168 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
82169 {
82170 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
82171 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
82172 }
82173
82174 /*
82175 @@ -627,7 +627,7 @@ process_further:
82176
82177 latest = ntohl(sp->hdr.serial);
82178 hard = ntohl(ack.firstPacket);
82179 - tx = atomic_read(&call->sequence);
82180 + tx = atomic_read_unchecked(&call->sequence);
82181
82182 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82183 latest,
82184 @@ -840,6 +840,8 @@ void rxrpc_process_call(struct work_struct *work)
82185 u32 abort_code = RX_PROTOCOL_ERROR;
82186 u8 *acks = NULL;
82187
82188 + pax_track_stack();
82189 +
82190 //printk("\n--------------------\n");
82191 _enter("{%d,%s,%lx} [%lu]",
82192 call->debug_id, rxrpc_call_states[call->state], call->events,
82193 @@ -1159,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
82194 goto maybe_reschedule;
82195
82196 send_ACK_with_skew:
82197 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
82198 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
82199 ntohl(ack.serial));
82200 send_ACK:
82201 mtu = call->conn->trans->peer->if_mtu;
82202 @@ -1171,7 +1173,7 @@ send_ACK:
82203 ackinfo.rxMTU = htonl(5692);
82204 ackinfo.jumbo_max = htonl(4);
82205
82206 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82207 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82208 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82209 ntohl(hdr.serial),
82210 ntohs(ack.maxSkew),
82211 @@ -1189,7 +1191,7 @@ send_ACK:
82212 send_message:
82213 _debug("send message");
82214
82215 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82216 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82217 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
82218 send_message_2:
82219
82220 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
82221 index bc0019f..e1b4b24 100644
82222 --- a/net/rxrpc/ar-call.c
82223 +++ b/net/rxrpc/ar-call.c
82224 @@ -82,7 +82,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
82225 spin_lock_init(&call->lock);
82226 rwlock_init(&call->state_lock);
82227 atomic_set(&call->usage, 1);
82228 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
82229 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82230 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
82231
82232 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
82233 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
82234 index 9f1ce84..ff8d061 100644
82235 --- a/net/rxrpc/ar-connection.c
82236 +++ b/net/rxrpc/ar-connection.c
82237 @@ -205,7 +205,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
82238 rwlock_init(&conn->lock);
82239 spin_lock_init(&conn->state_lock);
82240 atomic_set(&conn->usage, 1);
82241 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
82242 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82243 conn->avail_calls = RXRPC_MAXCALLS;
82244 conn->size_align = 4;
82245 conn->header_size = sizeof(struct rxrpc_header);
82246 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
82247 index 0505cdc..f0748ce 100644
82248 --- a/net/rxrpc/ar-connevent.c
82249 +++ b/net/rxrpc/ar-connevent.c
82250 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
82251
82252 len = iov[0].iov_len + iov[1].iov_len;
82253
82254 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82255 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82256 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
82257
82258 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82259 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
82260 index f98c802..9e8488e 100644
82261 --- a/net/rxrpc/ar-input.c
82262 +++ b/net/rxrpc/ar-input.c
82263 @@ -339,9 +339,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
82264 /* track the latest serial number on this connection for ACK packet
82265 * information */
82266 serial = ntohl(sp->hdr.serial);
82267 - hi_serial = atomic_read(&call->conn->hi_serial);
82268 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
82269 while (serial > hi_serial)
82270 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
82271 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
82272 serial);
82273
82274 /* request ACK generation for any ACK or DATA packet that requests
82275 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
82276 index 7043b29..06edcdf 100644
82277 --- a/net/rxrpc/ar-internal.h
82278 +++ b/net/rxrpc/ar-internal.h
82279 @@ -272,8 +272,8 @@ struct rxrpc_connection {
82280 int error; /* error code for local abort */
82281 int debug_id; /* debug ID for printks */
82282 unsigned call_counter; /* call ID counter */
82283 - atomic_t serial; /* packet serial number counter */
82284 - atomic_t hi_serial; /* highest serial number received */
82285 + atomic_unchecked_t serial; /* packet serial number counter */
82286 + atomic_unchecked_t hi_serial; /* highest serial number received */
82287 u8 avail_calls; /* number of calls available */
82288 u8 size_align; /* data size alignment (for security) */
82289 u8 header_size; /* rxrpc + security header size */
82290 @@ -346,7 +346,7 @@ struct rxrpc_call {
82291 spinlock_t lock;
82292 rwlock_t state_lock; /* lock for state transition */
82293 atomic_t usage;
82294 - atomic_t sequence; /* Tx data packet sequence counter */
82295 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
82296 u32 abort_code; /* local/remote abort code */
82297 enum { /* current state of call */
82298 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
82299 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
82300 */
82301 extern atomic_t rxrpc_n_skbs;
82302 extern __be32 rxrpc_epoch;
82303 -extern atomic_t rxrpc_debug_id;
82304 +extern atomic_unchecked_t rxrpc_debug_id;
82305 extern struct workqueue_struct *rxrpc_workqueue;
82306
82307 /*
82308 diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
82309 index 74697b2..10f9b77 100644
82310 --- a/net/rxrpc/ar-key.c
82311 +++ b/net/rxrpc/ar-key.c
82312 @@ -88,11 +88,11 @@ static int rxrpc_instantiate_xdr_rxkad(struct key *key, const __be32 *xdr,
82313 return ret;
82314
82315 plen -= sizeof(*token);
82316 - token = kmalloc(sizeof(*token), GFP_KERNEL);
82317 + token = kzalloc(sizeof(*token), GFP_KERNEL);
82318 if (!token)
82319 return -ENOMEM;
82320
82321 - token->kad = kmalloc(plen, GFP_KERNEL);
82322 + token->kad = kzalloc(plen, GFP_KERNEL);
82323 if (!token->kad) {
82324 kfree(token);
82325 return -ENOMEM;
82326 @@ -730,10 +730,10 @@ static int rxrpc_instantiate(struct key *key, const void *data, size_t datalen)
82327 goto error;
82328
82329 ret = -ENOMEM;
82330 - token = kmalloc(sizeof(*token), GFP_KERNEL);
82331 + token = kzalloc(sizeof(*token), GFP_KERNEL);
82332 if (!token)
82333 goto error;
82334 - token->kad = kmalloc(plen, GFP_KERNEL);
82335 + token->kad = kzalloc(plen, GFP_KERNEL);
82336 if (!token->kad)
82337 goto error_free;
82338
82339 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
82340 index 807535f..5b7f19e 100644
82341 --- a/net/rxrpc/ar-local.c
82342 +++ b/net/rxrpc/ar-local.c
82343 @@ -44,7 +44,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
82344 spin_lock_init(&local->lock);
82345 rwlock_init(&local->services_lock);
82346 atomic_set(&local->usage, 1);
82347 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
82348 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82349 memcpy(&local->srx, srx, sizeof(*srx));
82350 }
82351
82352 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
82353 index cc9102c..7d3888e 100644
82354 --- a/net/rxrpc/ar-output.c
82355 +++ b/net/rxrpc/ar-output.c
82356 @@ -680,9 +680,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
82357 sp->hdr.cid = call->cid;
82358 sp->hdr.callNumber = call->call_id;
82359 sp->hdr.seq =
82360 - htonl(atomic_inc_return(&call->sequence));
82361 + htonl(atomic_inc_return_unchecked(&call->sequence));
82362 sp->hdr.serial =
82363 - htonl(atomic_inc_return(&conn->serial));
82364 + htonl(atomic_inc_return_unchecked(&conn->serial));
82365 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
82366 sp->hdr.userStatus = 0;
82367 sp->hdr.securityIndex = conn->security_ix;
82368 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
82369 index edc026c..4bd4e2d 100644
82370 --- a/net/rxrpc/ar-peer.c
82371 +++ b/net/rxrpc/ar-peer.c
82372 @@ -86,7 +86,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
82373 INIT_LIST_HEAD(&peer->error_targets);
82374 spin_lock_init(&peer->lock);
82375 atomic_set(&peer->usage, 1);
82376 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
82377 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82378 memcpy(&peer->srx, srx, sizeof(*srx));
82379
82380 rxrpc_assess_MTU_size(peer);
82381 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
82382 index 38047f7..9f48511 100644
82383 --- a/net/rxrpc/ar-proc.c
82384 +++ b/net/rxrpc/ar-proc.c
82385 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
82386 atomic_read(&conn->usage),
82387 rxrpc_conn_states[conn->state],
82388 key_serial(conn->key),
82389 - atomic_read(&conn->serial),
82390 - atomic_read(&conn->hi_serial));
82391 + atomic_read_unchecked(&conn->serial),
82392 + atomic_read_unchecked(&conn->hi_serial));
82393
82394 return 0;
82395 }
82396 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
82397 index 0936e1a..437c640 100644
82398 --- a/net/rxrpc/ar-transport.c
82399 +++ b/net/rxrpc/ar-transport.c
82400 @@ -46,7 +46,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
82401 spin_lock_init(&trans->client_lock);
82402 rwlock_init(&trans->conn_lock);
82403 atomic_set(&trans->usage, 1);
82404 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
82405 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82406
82407 if (peer->srx.transport.family == AF_INET) {
82408 switch (peer->srx.transport_type) {
82409 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
82410 index 713ac59..306f6ae 100644
82411 --- a/net/rxrpc/rxkad.c
82412 +++ b/net/rxrpc/rxkad.c
82413 @@ -210,6 +210,8 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
82414 u16 check;
82415 int nsg;
82416
82417 + pax_track_stack();
82418 +
82419 sp = rxrpc_skb(skb);
82420
82421 _enter("");
82422 @@ -337,6 +339,8 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call,
82423 u16 check;
82424 int nsg;
82425
82426 + pax_track_stack();
82427 +
82428 _enter("");
82429
82430 sp = rxrpc_skb(skb);
82431 @@ -609,7 +613,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
82432
82433 len = iov[0].iov_len + iov[1].iov_len;
82434
82435 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82436 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82437 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
82438
82439 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82440 @@ -659,7 +663,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
82441
82442 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
82443
82444 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
82445 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82446 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
82447
82448 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
82449 diff --git a/net/sctp/auth.c b/net/sctp/auth.c
82450 index 914c419..7a16d2c 100644
82451 --- a/net/sctp/auth.c
82452 +++ b/net/sctp/auth.c
82453 @@ -81,7 +81,7 @@ static struct sctp_auth_bytes *sctp_auth_create_key(__u32 key_len, gfp_t gfp)
82454 struct sctp_auth_bytes *key;
82455
82456 /* Verify that we are not going to overflow INT_MAX */
82457 - if ((INT_MAX - key_len) < sizeof(struct sctp_auth_bytes))
82458 + if (key_len > (INT_MAX - sizeof(struct sctp_auth_bytes)))
82459 return NULL;
82460
82461 /* Allocate the shared key */
82462 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
82463 index d093cbf..9fc36fc 100644
82464 --- a/net/sctp/proc.c
82465 +++ b/net/sctp/proc.c
82466 @@ -213,7 +213,12 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
82467 sctp_for_each_hentry(epb, node, &head->chain) {
82468 ep = sctp_ep(epb);
82469 sk = epb->sk;
82470 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
82471 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
82472 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82473 + NULL, NULL,
82474 +#else
82475 + ep, sk,
82476 +#endif
82477 sctp_sk(sk)->type, sk->sk_state, hash,
82478 epb->bind_addr.port,
82479 sock_i_uid(sk), sock_i_ino(sk));
82480 @@ -320,7 +325,12 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
82481 seq_printf(seq,
82482 "%8p %8p %-3d %-3d %-2d %-4d "
82483 "%4d %8d %8d %7d %5lu %-5d %5d ",
82484 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
82485 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82486 + NULL, NULL,
82487 +#else
82488 + assoc, sk,
82489 +#endif
82490 + sctp_sk(sk)->type, sk->sk_state,
82491 assoc->state, hash,
82492 assoc->assoc_id,
82493 assoc->sndbuf_used,
82494 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
82495 index 3a95fcb..c40fc1d 100644
82496 --- a/net/sctp/socket.c
82497 +++ b/net/sctp/socket.c
82498 @@ -5802,7 +5802,6 @@ pp_found:
82499 */
82500 int reuse = sk->sk_reuse;
82501 struct sock *sk2;
82502 - struct hlist_node *node;
82503
82504 SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
82505 if (pp->fastreuse && sk->sk_reuse &&
82506 diff --git a/net/socket.c b/net/socket.c
82507 index d449812..4ac08d3c 100644
82508 --- a/net/socket.c
82509 +++ b/net/socket.c
82510 @@ -87,6 +87,7 @@
82511 #include <linux/wireless.h>
82512 #include <linux/nsproxy.h>
82513 #include <linux/magic.h>
82514 +#include <linux/in.h>
82515
82516 #include <asm/uaccess.h>
82517 #include <asm/unistd.h>
82518 @@ -97,6 +98,21 @@
82519 #include <net/sock.h>
82520 #include <linux/netfilter.h>
82521
82522 +extern void gr_attach_curr_ip(const struct sock *sk);
82523 +extern int gr_handle_sock_all(const int family, const int type,
82524 + const int protocol);
82525 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82526 +extern int gr_handle_sock_server_other(const struct sock *sck);
82527 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82528 +extern int gr_search_connect(struct socket * sock,
82529 + struct sockaddr_in * addr);
82530 +extern int gr_search_bind(struct socket * sock,
82531 + struct sockaddr_in * addr);
82532 +extern int gr_search_listen(struct socket * sock);
82533 +extern int gr_search_accept(struct socket * sock);
82534 +extern int gr_search_socket(const int domain, const int type,
82535 + const int protocol);
82536 +
82537 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
82538 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
82539 unsigned long nr_segs, loff_t pos);
82540 @@ -298,7 +314,7 @@ static int sockfs_get_sb(struct file_system_type *fs_type,
82541 mnt);
82542 }
82543
82544 -static struct vfsmount *sock_mnt __read_mostly;
82545 +struct vfsmount *sock_mnt __read_mostly;
82546
82547 static struct file_system_type sock_fs_type = {
82548 .name = "sockfs",
82549 @@ -1154,6 +1170,8 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
82550 return -EAFNOSUPPORT;
82551 if (type < 0 || type >= SOCK_MAX)
82552 return -EINVAL;
82553 + if (protocol < 0)
82554 + return -EINVAL;
82555
82556 /* Compatibility.
82557
82558 @@ -1283,6 +1301,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
82559 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
82560 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
82561
82562 + if(!gr_search_socket(family, type, protocol)) {
82563 + retval = -EACCES;
82564 + goto out;
82565 + }
82566 +
82567 + if (gr_handle_sock_all(family, type, protocol)) {
82568 + retval = -EACCES;
82569 + goto out;
82570 + }
82571 +
82572 retval = sock_create(family, type, protocol, &sock);
82573 if (retval < 0)
82574 goto out;
82575 @@ -1415,6 +1443,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82576 if (sock) {
82577 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
82578 if (err >= 0) {
82579 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
82580 + err = -EACCES;
82581 + goto error;
82582 + }
82583 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
82584 + if (err)
82585 + goto error;
82586 +
82587 err = security_socket_bind(sock,
82588 (struct sockaddr *)&address,
82589 addrlen);
82590 @@ -1423,6 +1459,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82591 (struct sockaddr *)
82592 &address, addrlen);
82593 }
82594 +error:
82595 fput_light(sock->file, fput_needed);
82596 }
82597 return err;
82598 @@ -1446,10 +1483,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
82599 if ((unsigned)backlog > somaxconn)
82600 backlog = somaxconn;
82601
82602 + if (gr_handle_sock_server_other(sock->sk)) {
82603 + err = -EPERM;
82604 + goto error;
82605 + }
82606 +
82607 + err = gr_search_listen(sock);
82608 + if (err)
82609 + goto error;
82610 +
82611 err = security_socket_listen(sock, backlog);
82612 if (!err)
82613 err = sock->ops->listen(sock, backlog);
82614
82615 +error:
82616 fput_light(sock->file, fput_needed);
82617 }
82618 return err;
82619 @@ -1492,6 +1539,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82620 newsock->type = sock->type;
82621 newsock->ops = sock->ops;
82622
82623 + if (gr_handle_sock_server_other(sock->sk)) {
82624 + err = -EPERM;
82625 + sock_release(newsock);
82626 + goto out_put;
82627 + }
82628 +
82629 + err = gr_search_accept(sock);
82630 + if (err) {
82631 + sock_release(newsock);
82632 + goto out_put;
82633 + }
82634 +
82635 /*
82636 * We don't need try_module_get here, as the listening socket (sock)
82637 * has the protocol module (sock->ops->owner) held.
82638 @@ -1534,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82639 fd_install(newfd, newfile);
82640 err = newfd;
82641
82642 + gr_attach_curr_ip(newsock->sk);
82643 +
82644 out_put:
82645 fput_light(sock->file, fput_needed);
82646 out:
82647 @@ -1571,6 +1632,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82648 int, addrlen)
82649 {
82650 struct socket *sock;
82651 + struct sockaddr *sck;
82652 struct sockaddr_storage address;
82653 int err, fput_needed;
82654
82655 @@ -1581,6 +1643,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82656 if (err < 0)
82657 goto out_put;
82658
82659 + sck = (struct sockaddr *)&address;
82660 +
82661 + if (gr_handle_sock_client(sck)) {
82662 + err = -EACCES;
82663 + goto out_put;
82664 + }
82665 +
82666 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
82667 + if (err)
82668 + goto out_put;
82669 +
82670 err =
82671 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
82672 if (err)
82673 @@ -1882,6 +1955,8 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct msghdr __user *, msg, unsigned, flags)
82674 int err, ctl_len, iov_size, total_len;
82675 int fput_needed;
82676
82677 + pax_track_stack();
82678 +
82679 err = -EFAULT;
82680 if (MSG_CMSG_COMPAT & flags) {
82681 if (get_compat_msghdr(&msg_sys, msg_compat))
82682 @@ -2022,7 +2097,7 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg,
82683 * kernel msghdr to use the kernel address space)
82684 */
82685
82686 - uaddr = (__force void __user *)msg_sys.msg_name;
82687 + uaddr = (void __force_user *)msg_sys.msg_name;
82688 uaddr_len = COMPAT_NAMELEN(msg);
82689 if (MSG_CMSG_COMPAT & flags) {
82690 err = verify_compat_iovec(&msg_sys, iov,
82691 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
82692 index ac94477..8afe5c3 100644
82693 --- a/net/sunrpc/sched.c
82694 +++ b/net/sunrpc/sched.c
82695 @@ -234,10 +234,10 @@ static int rpc_wait_bit_killable(void *word)
82696 #ifdef RPC_DEBUG
82697 static void rpc_task_set_debuginfo(struct rpc_task *task)
82698 {
82699 - static atomic_t rpc_pid;
82700 + static atomic_unchecked_t rpc_pid;
82701
82702 task->tk_magic = RPC_TASK_MAGIC_ID;
82703 - task->tk_pid = atomic_inc_return(&rpc_pid);
82704 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
82705 }
82706 #else
82707 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
82708 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
82709 index 35fb68b..236a8bf 100644
82710 --- a/net/sunrpc/xprtrdma/svc_rdma.c
82711 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
82712 @@ -59,15 +59,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
82713 static unsigned int min_max_inline = 4096;
82714 static unsigned int max_max_inline = 65536;
82715
82716 -atomic_t rdma_stat_recv;
82717 -atomic_t rdma_stat_read;
82718 -atomic_t rdma_stat_write;
82719 -atomic_t rdma_stat_sq_starve;
82720 -atomic_t rdma_stat_rq_starve;
82721 -atomic_t rdma_stat_rq_poll;
82722 -atomic_t rdma_stat_rq_prod;
82723 -atomic_t rdma_stat_sq_poll;
82724 -atomic_t rdma_stat_sq_prod;
82725 +atomic_unchecked_t rdma_stat_recv;
82726 +atomic_unchecked_t rdma_stat_read;
82727 +atomic_unchecked_t rdma_stat_write;
82728 +atomic_unchecked_t rdma_stat_sq_starve;
82729 +atomic_unchecked_t rdma_stat_rq_starve;
82730 +atomic_unchecked_t rdma_stat_rq_poll;
82731 +atomic_unchecked_t rdma_stat_rq_prod;
82732 +atomic_unchecked_t rdma_stat_sq_poll;
82733 +atomic_unchecked_t rdma_stat_sq_prod;
82734
82735 /* Temporary NFS request map and context caches */
82736 struct kmem_cache *svc_rdma_map_cachep;
82737 @@ -105,7 +105,7 @@ static int read_reset_stat(ctl_table *table, int write,
82738 len -= *ppos;
82739 if (len > *lenp)
82740 len = *lenp;
82741 - if (len && copy_to_user(buffer, str_buf, len))
82742 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
82743 return -EFAULT;
82744 *lenp = len;
82745 *ppos += len;
82746 @@ -149,63 +149,63 @@ static ctl_table svcrdma_parm_table[] = {
82747 {
82748 .procname = "rdma_stat_read",
82749 .data = &rdma_stat_read,
82750 - .maxlen = sizeof(atomic_t),
82751 + .maxlen = sizeof(atomic_unchecked_t),
82752 .mode = 0644,
82753 .proc_handler = &read_reset_stat,
82754 },
82755 {
82756 .procname = "rdma_stat_recv",
82757 .data = &rdma_stat_recv,
82758 - .maxlen = sizeof(atomic_t),
82759 + .maxlen = sizeof(atomic_unchecked_t),
82760 .mode = 0644,
82761 .proc_handler = &read_reset_stat,
82762 },
82763 {
82764 .procname = "rdma_stat_write",
82765 .data = &rdma_stat_write,
82766 - .maxlen = sizeof(atomic_t),
82767 + .maxlen = sizeof(atomic_unchecked_t),
82768 .mode = 0644,
82769 .proc_handler = &read_reset_stat,
82770 },
82771 {
82772 .procname = "rdma_stat_sq_starve",
82773 .data = &rdma_stat_sq_starve,
82774 - .maxlen = sizeof(atomic_t),
82775 + .maxlen = sizeof(atomic_unchecked_t),
82776 .mode = 0644,
82777 .proc_handler = &read_reset_stat,
82778 },
82779 {
82780 .procname = "rdma_stat_rq_starve",
82781 .data = &rdma_stat_rq_starve,
82782 - .maxlen = sizeof(atomic_t),
82783 + .maxlen = sizeof(atomic_unchecked_t),
82784 .mode = 0644,
82785 .proc_handler = &read_reset_stat,
82786 },
82787 {
82788 .procname = "rdma_stat_rq_poll",
82789 .data = &rdma_stat_rq_poll,
82790 - .maxlen = sizeof(atomic_t),
82791 + .maxlen = sizeof(atomic_unchecked_t),
82792 .mode = 0644,
82793 .proc_handler = &read_reset_stat,
82794 },
82795 {
82796 .procname = "rdma_stat_rq_prod",
82797 .data = &rdma_stat_rq_prod,
82798 - .maxlen = sizeof(atomic_t),
82799 + .maxlen = sizeof(atomic_unchecked_t),
82800 .mode = 0644,
82801 .proc_handler = &read_reset_stat,
82802 },
82803 {
82804 .procname = "rdma_stat_sq_poll",
82805 .data = &rdma_stat_sq_poll,
82806 - .maxlen = sizeof(atomic_t),
82807 + .maxlen = sizeof(atomic_unchecked_t),
82808 .mode = 0644,
82809 .proc_handler = &read_reset_stat,
82810 },
82811 {
82812 .procname = "rdma_stat_sq_prod",
82813 .data = &rdma_stat_sq_prod,
82814 - .maxlen = sizeof(atomic_t),
82815 + .maxlen = sizeof(atomic_unchecked_t),
82816 .mode = 0644,
82817 .proc_handler = &read_reset_stat,
82818 },
82819 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82820 index 9e88438..8ed5cf0 100644
82821 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82822 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82823 @@ -495,7 +495,7 @@ next_sge:
82824 svc_rdma_put_context(ctxt, 0);
82825 goto out;
82826 }
82827 - atomic_inc(&rdma_stat_read);
82828 + atomic_inc_unchecked(&rdma_stat_read);
82829
82830 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
82831 chl_map->ch[ch_no].count -= read_wr.num_sge;
82832 @@ -606,7 +606,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82833 dto_q);
82834 list_del_init(&ctxt->dto_q);
82835 } else {
82836 - atomic_inc(&rdma_stat_rq_starve);
82837 + atomic_inc_unchecked(&rdma_stat_rq_starve);
82838 clear_bit(XPT_DATA, &xprt->xpt_flags);
82839 ctxt = NULL;
82840 }
82841 @@ -626,7 +626,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82842 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
82843 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
82844 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
82845 - atomic_inc(&rdma_stat_recv);
82846 + atomic_inc_unchecked(&rdma_stat_recv);
82847
82848 /* Build up the XDR from the receive buffers. */
82849 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
82850 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82851 index f11be72..7aad4e8 100644
82852 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82853 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82854 @@ -328,7 +328,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
82855 write_wr.wr.rdma.remote_addr = to;
82856
82857 /* Post It */
82858 - atomic_inc(&rdma_stat_write);
82859 + atomic_inc_unchecked(&rdma_stat_write);
82860 if (svc_rdma_send(xprt, &write_wr))
82861 goto err;
82862 return 0;
82863 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82864 index 3fa5751..030ba89 100644
82865 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
82866 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82867 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82868 return;
82869
82870 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
82871 - atomic_inc(&rdma_stat_rq_poll);
82872 + atomic_inc_unchecked(&rdma_stat_rq_poll);
82873
82874 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
82875 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
82876 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82877 }
82878
82879 if (ctxt)
82880 - atomic_inc(&rdma_stat_rq_prod);
82881 + atomic_inc_unchecked(&rdma_stat_rq_prod);
82882
82883 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
82884 /*
82885 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82886 return;
82887
82888 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
82889 - atomic_inc(&rdma_stat_sq_poll);
82890 + atomic_inc_unchecked(&rdma_stat_sq_poll);
82891 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
82892 if (wc.status != IB_WC_SUCCESS)
82893 /* Close the transport */
82894 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82895 }
82896
82897 if (ctxt)
82898 - atomic_inc(&rdma_stat_sq_prod);
82899 + atomic_inc_unchecked(&rdma_stat_sq_prod);
82900 }
82901
82902 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
82903 @@ -1260,7 +1260,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
82904 spin_lock_bh(&xprt->sc_lock);
82905 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
82906 spin_unlock_bh(&xprt->sc_lock);
82907 - atomic_inc(&rdma_stat_sq_starve);
82908 + atomic_inc_unchecked(&rdma_stat_sq_starve);
82909
82910 /* See if we can opportunistically reap SQ WR to make room */
82911 sq_cq_reap(xprt);
82912 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
82913 index 0b15d72..7934fbb 100644
82914 --- a/net/sysctl_net.c
82915 +++ b/net/sysctl_net.c
82916 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
82917 struct ctl_table *table)
82918 {
82919 /* Allow network administrator to have same access as root. */
82920 - if (capable(CAP_NET_ADMIN)) {
82921 + if (capable_nolog(CAP_NET_ADMIN)) {
82922 int mode = (table->mode >> 6) & 7;
82923 return (mode << 6) | (mode << 3) | mode;
82924 }
82925 diff --git a/net/tipc/link.c b/net/tipc/link.c
82926 index dd4c18b..f40d38d 100644
82927 --- a/net/tipc/link.c
82928 +++ b/net/tipc/link.c
82929 @@ -1418,7 +1418,7 @@ again:
82930
82931 if (!sect_rest) {
82932 sect_rest = msg_sect[++curr_sect].iov_len;
82933 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
82934 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
82935 }
82936
82937 if (sect_rest < fragm_rest)
82938 @@ -1437,7 +1437,7 @@ error:
82939 }
82940 } else
82941 skb_copy_to_linear_data_offset(buf, fragm_crs,
82942 - sect_crs, sz);
82943 + (const void __force_kernel *)sect_crs, sz);
82944 sect_crs += sz;
82945 sect_rest -= sz;
82946 fragm_crs += sz;
82947 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
82948 index 0747d8a..e8bf3f3 100644
82949 --- a/net/tipc/subscr.c
82950 +++ b/net/tipc/subscr.c
82951 @@ -104,7 +104,7 @@ static void subscr_send_event(struct subscription *sub,
82952 {
82953 struct iovec msg_sect;
82954
82955 - msg_sect.iov_base = (void *)&sub->evt;
82956 + msg_sect.iov_base = (void __force_user *)&sub->evt;
82957 msg_sect.iov_len = sizeof(struct tipc_event);
82958
82959 sub->evt.event = htohl(event, sub->swap);
82960 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82961 index db8d51a..608692d 100644
82962 --- a/net/unix/af_unix.c
82963 +++ b/net/unix/af_unix.c
82964 @@ -745,6 +745,12 @@ static struct sock *unix_find_other(struct net *net,
82965 err = -ECONNREFUSED;
82966 if (!S_ISSOCK(inode->i_mode))
82967 goto put_fail;
82968 +
82969 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82970 + err = -EACCES;
82971 + goto put_fail;
82972 + }
82973 +
82974 u = unix_find_socket_byinode(net, inode);
82975 if (!u)
82976 goto put_fail;
82977 @@ -765,6 +771,13 @@ static struct sock *unix_find_other(struct net *net,
82978 if (u) {
82979 struct dentry *dentry;
82980 dentry = unix_sk(u)->dentry;
82981 +
82982 + if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
82983 + err = -EPERM;
82984 + sock_put(u);
82985 + goto fail;
82986 + }
82987 +
82988 if (dentry)
82989 touch_atime(unix_sk(u)->mnt, dentry);
82990 } else
82991 @@ -850,11 +863,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
82992 err = security_path_mknod(&nd.path, dentry, mode, 0);
82993 if (err)
82994 goto out_mknod_drop_write;
82995 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
82996 + err = -EACCES;
82997 + goto out_mknod_drop_write;
82998 + }
82999 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
83000 out_mknod_drop_write:
83001 mnt_drop_write(nd.path.mnt);
83002 if (err)
83003 goto out_mknod_dput;
83004 +
83005 + gr_handle_create(dentry, nd.path.mnt);
83006 +
83007 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
83008 dput(nd.path.dentry);
83009 nd.path.dentry = dentry;
83010 @@ -2211,7 +2231,11 @@ static int unix_seq_show(struct seq_file *seq, void *v)
83011 unix_state_lock(s);
83012
83013 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
83014 +#ifdef CONFIG_GRKERNSEC_HIDESYM
83015 + NULL,
83016 +#else
83017 s,
83018 +#endif
83019 atomic_read(&s->sk_refcnt),
83020 0,
83021 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
83022 diff --git a/net/wireless/core.h b/net/wireless/core.h
83023 index 376798f..109a61f 100644
83024 --- a/net/wireless/core.h
83025 +++ b/net/wireless/core.h
83026 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
83027 struct mutex mtx;
83028
83029 /* rfkill support */
83030 - struct rfkill_ops rfkill_ops;
83031 + rfkill_ops_no_const rfkill_ops;
83032 struct rfkill *rfkill;
83033 struct work_struct rfkill_sync;
83034
83035 diff --git a/net/wireless/wext.c b/net/wireless/wext.c
83036 index a2e4c60..0979cbe 100644
83037 --- a/net/wireless/wext.c
83038 +++ b/net/wireless/wext.c
83039 @@ -816,8 +816,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83040 */
83041
83042 /* Support for very large requests */
83043 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
83044 - (user_length > descr->max_tokens)) {
83045 + if (user_length > descr->max_tokens) {
83046 /* Allow userspace to GET more than max so
83047 * we can support any size GET requests.
83048 * There is still a limit : -ENOMEM.
83049 @@ -854,22 +853,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83050 }
83051 }
83052
83053 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
83054 - /*
83055 - * If this is a GET, but not NOMAX, it means that the extra
83056 - * data is not bounded by userspace, but by max_tokens. Thus
83057 - * set the length to max_tokens. This matches the extra data
83058 - * allocation.
83059 - * The driver should fill it with the number of tokens it
83060 - * provided, and it may check iwp->length rather than having
83061 - * knowledge of max_tokens. If the driver doesn't change the
83062 - * iwp->length, this ioctl just copies back max_token tokens
83063 - * filled with zeroes. Hopefully the driver isn't claiming
83064 - * them to be valid data.
83065 - */
83066 - iwp->length = descr->max_tokens;
83067 - }
83068 -
83069 err = handler(dev, info, (union iwreq_data *) iwp, extra);
83070
83071 iwp->length += essid_compat;
83072 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
83073 index cb81ca3..e15d49a 100644
83074 --- a/net/xfrm/xfrm_policy.c
83075 +++ b/net/xfrm/xfrm_policy.c
83076 @@ -586,7 +586,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
83077 hlist_add_head(&policy->bydst, chain);
83078 xfrm_pol_hold(policy);
83079 net->xfrm.policy_count[dir]++;
83080 - atomic_inc(&flow_cache_genid);
83081 + atomic_inc_unchecked(&flow_cache_genid);
83082 if (delpol)
83083 __xfrm_policy_unlink(delpol, dir);
83084 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
83085 @@ -669,7 +669,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u8 type, int dir,
83086 write_unlock_bh(&xfrm_policy_lock);
83087
83088 if (ret && delete) {
83089 - atomic_inc(&flow_cache_genid);
83090 + atomic_inc_unchecked(&flow_cache_genid);
83091 xfrm_policy_kill(ret);
83092 }
83093 return ret;
83094 @@ -710,7 +710,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u8 type, int dir, u32 id,
83095 write_unlock_bh(&xfrm_policy_lock);
83096
83097 if (ret && delete) {
83098 - atomic_inc(&flow_cache_genid);
83099 + atomic_inc_unchecked(&flow_cache_genid);
83100 xfrm_policy_kill(ret);
83101 }
83102 return ret;
83103 @@ -824,7 +824,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
83104 }
83105
83106 }
83107 - atomic_inc(&flow_cache_genid);
83108 + atomic_inc_unchecked(&flow_cache_genid);
83109 out:
83110 write_unlock_bh(&xfrm_policy_lock);
83111 return err;
83112 @@ -1088,7 +1088,7 @@ int xfrm_policy_delete(struct xfrm_policy *pol, int dir)
83113 write_unlock_bh(&xfrm_policy_lock);
83114 if (pol) {
83115 if (dir < XFRM_POLICY_MAX)
83116 - atomic_inc(&flow_cache_genid);
83117 + atomic_inc_unchecked(&flow_cache_genid);
83118 xfrm_policy_kill(pol);
83119 return 0;
83120 }
83121 @@ -1477,7 +1477,7 @@ free_dst:
83122 goto out;
83123 }
83124
83125 -static int inline
83126 +static inline int
83127 xfrm_dst_alloc_copy(void **target, void *src, int size)
83128 {
83129 if (!*target) {
83130 @@ -1489,7 +1489,7 @@ xfrm_dst_alloc_copy(void **target, void *src, int size)
83131 return 0;
83132 }
83133
83134 -static int inline
83135 +static inline int
83136 xfrm_dst_update_parent(struct dst_entry *dst, struct xfrm_selector *sel)
83137 {
83138 #ifdef CONFIG_XFRM_SUB_POLICY
83139 @@ -1501,7 +1501,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, struct xfrm_selector *sel)
83140 #endif
83141 }
83142
83143 -static int inline
83144 +static inline int
83145 xfrm_dst_update_origin(struct dst_entry *dst, struct flowi *fl)
83146 {
83147 #ifdef CONFIG_XFRM_SUB_POLICY
83148 @@ -1537,7 +1537,7 @@ int __xfrm_lookup(struct net *net, struct dst_entry **dst_p, struct flowi *fl,
83149 u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT);
83150
83151 restart:
83152 - genid = atomic_read(&flow_cache_genid);
83153 + genid = atomic_read_unchecked(&flow_cache_genid);
83154 policy = NULL;
83155 for (pi = 0; pi < ARRAY_SIZE(pols); pi++)
83156 pols[pi] = NULL;
83157 @@ -1680,7 +1680,7 @@ restart:
83158 goto error;
83159 }
83160 if (nx == -EAGAIN ||
83161 - genid != atomic_read(&flow_cache_genid)) {
83162 + genid != atomic_read_unchecked(&flow_cache_genid)) {
83163 xfrm_pols_put(pols, npols);
83164 goto restart;
83165 }
83166 diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
83167 index b95a2d6..85c4d78 100644
83168 --- a/net/xfrm/xfrm_user.c
83169 +++ b/net/xfrm/xfrm_user.c
83170 @@ -1169,6 +1169,8 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
83171 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
83172 int i;
83173
83174 + pax_track_stack();
83175 +
83176 if (xp->xfrm_nr == 0)
83177 return 0;
83178
83179 @@ -1784,6 +1786,8 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
83180 int err;
83181 int n = 0;
83182
83183 + pax_track_stack();
83184 +
83185 if (attrs[XFRMA_MIGRATE] == NULL)
83186 return -EINVAL;
83187
83188 diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
83189 index 45b7d56..19e828c 100644
83190 --- a/samples/kobject/kset-example.c
83191 +++ b/samples/kobject/kset-example.c
83192 @@ -87,7 +87,7 @@ static ssize_t foo_attr_store(struct kobject *kobj,
83193 }
83194
83195 /* Our custom sysfs_ops that we will associate with our ktype later on */
83196 -static struct sysfs_ops foo_sysfs_ops = {
83197 +static const struct sysfs_ops foo_sysfs_ops = {
83198 .show = foo_attr_show,
83199 .store = foo_attr_store,
83200 };
83201 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
83202 index 341b589..405aed3 100644
83203 --- a/scripts/Makefile.build
83204 +++ b/scripts/Makefile.build
83205 @@ -59,7 +59,7 @@ endif
83206 endif
83207
83208 # Do not include host rules unless needed
83209 -ifneq ($(hostprogs-y)$(hostprogs-m),)
83210 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
83211 include scripts/Makefile.host
83212 endif
83213
83214 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
83215 index 6f89fbb..53adc9c 100644
83216 --- a/scripts/Makefile.clean
83217 +++ b/scripts/Makefile.clean
83218 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
83219 __clean-files := $(extra-y) $(always) \
83220 $(targets) $(clean-files) \
83221 $(host-progs) \
83222 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
83223 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
83224 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
83225
83226 # as clean-files is given relative to the current directory, this adds
83227 # a $(obj) prefix, except for absolute paths
83228 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
83229 index 1ac414f..a1c1451 100644
83230 --- a/scripts/Makefile.host
83231 +++ b/scripts/Makefile.host
83232 @@ -31,6 +31,7 @@
83233 # Note: Shared libraries consisting of C++ files are not supported
83234
83235 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
83236 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
83237
83238 # C code
83239 # Executables compiled from a single .c file
83240 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
83241 # Shared libaries (only .c supported)
83242 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
83243 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
83244 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
83245 # Remove .so files from "xxx-objs"
83246 host-cobjs := $(filter-out %.so,$(host-cobjs))
83247
83248 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
83249 index 6bf21f8..c0546b3 100644
83250 --- a/scripts/basic/fixdep.c
83251 +++ b/scripts/basic/fixdep.c
83252 @@ -162,7 +162,7 @@ static void grow_config(int len)
83253 /*
83254 * Lookup a value in the configuration string.
83255 */
83256 -static int is_defined_config(const char * name, int len)
83257 +static int is_defined_config(const char * name, unsigned int len)
83258 {
83259 const char * pconfig;
83260 const char * plast = str_config + len_config - len;
83261 @@ -199,7 +199,7 @@ static void clear_config(void)
83262 /*
83263 * Record the use of a CONFIG_* word.
83264 */
83265 -static void use_config(char *m, int slen)
83266 +static void use_config(char *m, unsigned int slen)
83267 {
83268 char s[PATH_MAX];
83269 char *p;
83270 @@ -222,9 +222,9 @@ static void use_config(char *m, int slen)
83271
83272 static void parse_config_file(char *map, size_t len)
83273 {
83274 - int *end = (int *) (map + len);
83275 + unsigned int *end = (unsigned int *) (map + len);
83276 /* start at +1, so that p can never be < map */
83277 - int *m = (int *) map + 1;
83278 + unsigned int *m = (unsigned int *) map + 1;
83279 char *p, *q;
83280
83281 for (; m < end; m++) {
83282 @@ -371,7 +371,7 @@ static void print_deps(void)
83283 static void traps(void)
83284 {
83285 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
83286 - int *p = (int *)test;
83287 + unsigned int *p = (unsigned int *)test;
83288
83289 if (*p != INT_CONF) {
83290 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
83291 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
83292 new file mode 100644
83293 index 0000000..8729101
83294 --- /dev/null
83295 +++ b/scripts/gcc-plugin.sh
83296 @@ -0,0 +1,2 @@
83297 +#!/bin/sh
83298 +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"
83299 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
83300 index 62a9025..65b82ad 100644
83301 --- a/scripts/mod/file2alias.c
83302 +++ b/scripts/mod/file2alias.c
83303 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
83304 unsigned long size, unsigned long id_size,
83305 void *symval)
83306 {
83307 - int i;
83308 + unsigned int i;
83309
83310 if (size % id_size || size < id_size) {
83311 if (cross_build != 0)
83312 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
83313 /* USB is special because the bcdDevice can be matched against a numeric range */
83314 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
83315 static void do_usb_entry(struct usb_device_id *id,
83316 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
83317 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
83318 unsigned char range_lo, unsigned char range_hi,
83319 struct module *mod)
83320 {
83321 @@ -151,7 +151,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
83322 {
83323 unsigned int devlo, devhi;
83324 unsigned char chi, clo;
83325 - int ndigits;
83326 + unsigned int ndigits;
83327
83328 id->match_flags = TO_NATIVE(id->match_flags);
83329 id->idVendor = TO_NATIVE(id->idVendor);
83330 @@ -368,7 +368,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
83331 for (i = 0; i < count; i++) {
83332 const char *id = (char *)devs[i].id;
83333 char acpi_id[sizeof(devs[0].id)];
83334 - int j;
83335 + unsigned int j;
83336
83337 buf_printf(&mod->dev_table_buf,
83338 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
83339 @@ -398,7 +398,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
83340
83341 for (j = 0; j < PNP_MAX_DEVICES; j++) {
83342 const char *id = (char *)card->devs[j].id;
83343 - int i2, j2;
83344 + unsigned int i2, j2;
83345 int dup = 0;
83346
83347 if (!id[0])
83348 @@ -424,7 +424,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
83349 /* add an individual alias for every device entry */
83350 if (!dup) {
83351 char acpi_id[sizeof(card->devs[0].id)];
83352 - int k;
83353 + unsigned int k;
83354
83355 buf_printf(&mod->dev_table_buf,
83356 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
83357 @@ -699,7 +699,7 @@ static void dmi_ascii_filter(char *d, const char *s)
83358 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
83359 char *alias)
83360 {
83361 - int i, j;
83362 + unsigned int i, j;
83363
83364 sprintf(alias, "dmi*");
83365
83366 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
83367 index 03efeab..0888989 100644
83368 --- a/scripts/mod/modpost.c
83369 +++ b/scripts/mod/modpost.c
83370 @@ -835,6 +835,7 @@ enum mismatch {
83371 INIT_TO_EXIT,
83372 EXIT_TO_INIT,
83373 EXPORT_TO_INIT_EXIT,
83374 + DATA_TO_TEXT
83375 };
83376
83377 struct sectioncheck {
83378 @@ -920,6 +921,12 @@ const struct sectioncheck sectioncheck[] = {
83379 .fromsec = { "__ksymtab*", NULL },
83380 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
83381 .mismatch = EXPORT_TO_INIT_EXIT
83382 +},
83383 +/* Do not reference code from writable data */
83384 +{
83385 + .fromsec = { DATA_SECTIONS, NULL },
83386 + .tosec = { TEXT_SECTIONS, NULL },
83387 + .mismatch = DATA_TO_TEXT
83388 }
83389 };
83390
83391 @@ -1024,10 +1031,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
83392 continue;
83393 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
83394 continue;
83395 - if (sym->st_value == addr)
83396 - return sym;
83397 /* Find a symbol nearby - addr are maybe negative */
83398 d = sym->st_value - addr;
83399 + if (d == 0)
83400 + return sym;
83401 if (d < 0)
83402 d = addr - sym->st_value;
83403 if (d < distance) {
83404 @@ -1268,6 +1275,14 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
83405 "Fix this by removing the %sannotation of %s "
83406 "or drop the export.\n",
83407 tosym, sec2annotation(tosec), sec2annotation(tosec), tosym);
83408 + case DATA_TO_TEXT:
83409 +/*
83410 + fprintf(stderr,
83411 + "The variable %s references\n"
83412 + "the %s %s%s%s\n",
83413 + fromsym, to, sec2annotation(tosec), tosym, to_p);
83414 +*/
83415 + break;
83416 case NO_MISMATCH:
83417 /* To get warnings on missing members */
83418 break;
83419 @@ -1495,7 +1510,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
83420 static void check_sec_ref(struct module *mod, const char *modname,
83421 struct elf_info *elf)
83422 {
83423 - int i;
83424 + unsigned int i;
83425 Elf_Shdr *sechdrs = elf->sechdrs;
83426
83427 /* Walk through all sections */
83428 @@ -1651,7 +1666,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
83429 va_end(ap);
83430 }
83431
83432 -void buf_write(struct buffer *buf, const char *s, int len)
83433 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
83434 {
83435 if (buf->size - buf->pos < len) {
83436 buf->size += len + SZ;
83437 @@ -1863,7 +1878,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
83438 if (fstat(fileno(file), &st) < 0)
83439 goto close_write;
83440
83441 - if (st.st_size != b->pos)
83442 + if (st.st_size != (off_t)b->pos)
83443 goto close_write;
83444
83445 tmp = NOFAIL(malloc(b->pos));
83446 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
83447 index 09f58e3..4b66092 100644
83448 --- a/scripts/mod/modpost.h
83449 +++ b/scripts/mod/modpost.h
83450 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
83451
83452 struct buffer {
83453 char *p;
83454 - int pos;
83455 - int size;
83456 + unsigned int pos;
83457 + unsigned int size;
83458 };
83459
83460 void __attribute__((format(printf, 2, 3)))
83461 buf_printf(struct buffer *buf, const char *fmt, ...);
83462
83463 void
83464 -buf_write(struct buffer *buf, const char *s, int len);
83465 +buf_write(struct buffer *buf, const char *s, unsigned int len);
83466
83467 struct module {
83468 struct module *next;
83469 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
83470 index ecf9c7d..d52b38e 100644
83471 --- a/scripts/mod/sumversion.c
83472 +++ b/scripts/mod/sumversion.c
83473 @@ -455,7 +455,7 @@ static void write_version(const char *filename, const char *sum,
83474 goto out;
83475 }
83476
83477 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
83478 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
83479 warn("writing sum in %s failed: %s\n",
83480 filename, strerror(errno));
83481 goto out;
83482 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
83483 index 47bdd2f..d4d4e93 100755
83484 --- a/scripts/package/mkspec
83485 +++ b/scripts/package/mkspec
83486 @@ -70,7 +70,7 @@ echo 'mkdir -p $RPM_BUILD_ROOT/boot $RPM_BUILD_ROOT/lib/modules'
83487 echo 'mkdir -p $RPM_BUILD_ROOT/lib/firmware'
83488 echo "%endif"
83489
83490 -echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{_smp_mflags} KBUILD_SRC= modules_install'
83491 +echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{?_smp_mflags} KBUILD_SRC= modules_install'
83492 echo "%ifarch ia64"
83493 echo 'cp $KBUILD_IMAGE $RPM_BUILD_ROOT'"/boot/efi/vmlinuz-$KERNELRELEASE"
83494 echo 'ln -s '"efi/vmlinuz-$KERNELRELEASE" '$RPM_BUILD_ROOT'"/boot/"
83495 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
83496 index 5c11312..72742b5 100644
83497 --- a/scripts/pnmtologo.c
83498 +++ b/scripts/pnmtologo.c
83499 @@ -237,14 +237,14 @@ static void write_header(void)
83500 fprintf(out, " * Linux logo %s\n", logoname);
83501 fputs(" */\n\n", out);
83502 fputs("#include <linux/linux_logo.h>\n\n", out);
83503 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
83504 + fprintf(out, "static unsigned char %s_data[] = {\n",
83505 logoname);
83506 }
83507
83508 static void write_footer(void)
83509 {
83510 fputs("\n};\n\n", out);
83511 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
83512 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
83513 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
83514 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
83515 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
83516 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
83517 fputs("\n};\n\n", out);
83518
83519 /* write logo clut */
83520 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
83521 + fprintf(out, "static unsigned char %s_clut[] = {\n",
83522 logoname);
83523 write_hex_cnt = 0;
83524 for (i = 0; i < logo_clutsize; i++) {
83525 diff --git a/scripts/tags.sh b/scripts/tags.sh
83526 index d52f7a0..269eb1b 100755
83527 --- a/scripts/tags.sh
83528 +++ b/scripts/tags.sh
83529 @@ -93,6 +93,11 @@ docscope()
83530 cscope -b -f cscope.out
83531 }
83532
83533 +dogtags()
83534 +{
83535 + all_sources | gtags -f -
83536 +}
83537 +
83538 exuberant()
83539 {
83540 all_sources | xargs $1 -a \
83541 @@ -164,6 +169,10 @@ case "$1" in
83542 docscope
83543 ;;
83544
83545 + "gtags")
83546 + dogtags
83547 + ;;
83548 +
83549 "tags")
83550 rm -f tags
83551 xtags ctags
83552 diff --git a/security/Kconfig b/security/Kconfig
83553 index fb363cd..14c747b 100644
83554 --- a/security/Kconfig
83555 +++ b/security/Kconfig
83556 @@ -4,6 +4,587 @@
83557
83558 menu "Security options"
83559
83560 +source grsecurity/Kconfig
83561 +
83562 +menu "PaX"
83563 +
83564 + config ARCH_TRACK_EXEC_LIMIT
83565 + bool
83566 +
83567 + config PAX_KERNEXEC_PLUGIN
83568 + bool
83569 +
83570 + config PAX_PER_CPU_PGD
83571 + bool
83572 +
83573 + config TASK_SIZE_MAX_SHIFT
83574 + int
83575 + depends on X86_64
83576 + default 47 if !PAX_PER_CPU_PGD
83577 + default 42 if PAX_PER_CPU_PGD
83578 +
83579 + config PAX_ENABLE_PAE
83580 + bool
83581 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
83582 +
83583 +config PAX
83584 + bool "Enable various PaX features"
83585 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
83586 + help
83587 + This allows you to enable various PaX features. PaX adds
83588 + intrusion prevention mechanisms to the kernel that reduce
83589 + the risks posed by exploitable memory corruption bugs.
83590 +
83591 +menu "PaX Control"
83592 + depends on PAX
83593 +
83594 +config PAX_SOFTMODE
83595 + bool 'Support soft mode'
83596 + select PAX_PT_PAX_FLAGS
83597 + help
83598 + Enabling this option will allow you to run PaX in soft mode, that
83599 + is, PaX features will not be enforced by default, only on executables
83600 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
83601 + is the only way to mark executables for soft mode use.
83602 +
83603 + Soft mode can be activated by using the "pax_softmode=1" kernel command
83604 + line option on boot. Furthermore you can control various PaX features
83605 + at runtime via the entries in /proc/sys/kernel/pax.
83606 +
83607 +config PAX_EI_PAX
83608 + bool 'Use legacy ELF header marking'
83609 + help
83610 + Enabling this option will allow you to control PaX features on
83611 + a per executable basis via the 'chpax' utility available at
83612 + http://pax.grsecurity.net/. The control flags will be read from
83613 + an otherwise reserved part of the ELF header. This marking has
83614 + numerous drawbacks (no support for soft-mode, toolchain does not
83615 + know about the non-standard use of the ELF header) therefore it
83616 + has been deprecated in favour of PT_PAX_FLAGS support.
83617 +
83618 + Note that if you enable PT_PAX_FLAGS marking support as well,
83619 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
83620 +
83621 +config PAX_PT_PAX_FLAGS
83622 + bool 'Use ELF program header marking'
83623 + help
83624 + Enabling this option will allow you to control PaX features on
83625 + a per executable basis via the 'paxctl' utility available at
83626 + http://pax.grsecurity.net/. The control flags will be read from
83627 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
83628 + has the benefits of supporting both soft mode and being fully
83629 + integrated into the toolchain (the binutils patch is available
83630 + from http://pax.grsecurity.net).
83631 +
83632 + If your toolchain does not support PT_PAX_FLAGS markings,
83633 + you can create one in most cases with 'paxctl -C'.
83634 +
83635 + Note that if you enable the legacy EI_PAX marking support as well,
83636 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
83637 +
83638 +choice
83639 + prompt 'MAC system integration'
83640 + default PAX_HAVE_ACL_FLAGS
83641 + help
83642 + Mandatory Access Control systems have the option of controlling
83643 + PaX flags on a per executable basis, choose the method supported
83644 + by your particular system.
83645 +
83646 + - "none": if your MAC system does not interact with PaX,
83647 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
83648 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
83649 +
83650 + NOTE: this option is for developers/integrators only.
83651 +
83652 + config PAX_NO_ACL_FLAGS
83653 + bool 'none'
83654 +
83655 + config PAX_HAVE_ACL_FLAGS
83656 + bool 'direct'
83657 +
83658 + config PAX_HOOK_ACL_FLAGS
83659 + bool 'hook'
83660 +endchoice
83661 +
83662 +endmenu
83663 +
83664 +menu "Non-executable pages"
83665 + depends on PAX
83666 +
83667 +config PAX_NOEXEC
83668 + bool "Enforce non-executable pages"
83669 + depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
83670 + help
83671 + By design some architectures do not allow for protecting memory
83672 + pages against execution or even if they do, Linux does not make
83673 + use of this feature. In practice this means that if a page is
83674 + readable (such as the stack or heap) it is also executable.
83675 +
83676 + There is a well known exploit technique that makes use of this
83677 + fact and a common programming mistake where an attacker can
83678 + introduce code of his choice somewhere in the attacked program's
83679 + memory (typically the stack or the heap) and then execute it.
83680 +
83681 + If the attacked program was running with different (typically
83682 + higher) privileges than that of the attacker, then he can elevate
83683 + his own privilege level (e.g. get a root shell, write to files for
83684 + which he does not have write access to, etc).
83685 +
83686 + Enabling this option will let you choose from various features
83687 + that prevent the injection and execution of 'foreign' code in
83688 + a program.
83689 +
83690 + This will also break programs that rely on the old behaviour and
83691 + expect that dynamically allocated memory via the malloc() family
83692 + of functions is executable (which it is not). Notable examples
83693 + are the XFree86 4.x server, the java runtime and wine.
83694 +
83695 +config PAX_PAGEEXEC
83696 + bool "Paging based non-executable pages"
83697 + 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)
83698 + select S390_SWITCH_AMODE if S390
83699 + select S390_EXEC_PROTECT if S390
83700 + select ARCH_TRACK_EXEC_LIMIT if X86_32
83701 + help
83702 + This implementation is based on the paging feature of the CPU.
83703 + On i386 without hardware non-executable bit support there is a
83704 + variable but usually low performance impact, however on Intel's
83705 + P4 core based CPUs it is very high so you should not enable this
83706 + for kernels meant to be used on such CPUs.
83707 +
83708 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
83709 + with hardware non-executable bit support there is no performance
83710 + impact, on ppc the impact is negligible.
83711 +
83712 + Note that several architectures require various emulations due to
83713 + badly designed userland ABIs, this will cause a performance impact
83714 + but will disappear as soon as userland is fixed. For example, ppc
83715 + userland MUST have been built with secure-plt by a recent toolchain.
83716 +
83717 +config PAX_SEGMEXEC
83718 + bool "Segmentation based non-executable pages"
83719 + depends on PAX_NOEXEC && X86_32
83720 + help
83721 + This implementation is based on the segmentation feature of the
83722 + CPU and has a very small performance impact, however applications
83723 + will be limited to a 1.5 GB address space instead of the normal
83724 + 3 GB.
83725 +
83726 +config PAX_EMUTRAMP
83727 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83728 + default y if PARISC
83729 + help
83730 + There are some programs and libraries that for one reason or
83731 + another attempt to execute special small code snippets from
83732 + non-executable memory pages. Most notable examples are the
83733 + signal handler return code generated by the kernel itself and
83734 + the GCC trampolines.
83735 +
83736 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83737 + such programs will no longer work under your kernel.
83738 +
83739 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83740 + utilities to enable trampoline emulation for the affected programs
83741 + yet still have the protection provided by the non-executable pages.
83742 +
83743 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83744 + your system will not even boot.
83745 +
83746 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83747 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83748 + for the affected files.
83749 +
83750 + NOTE: enabling this feature *may* open up a loophole in the
83751 + protection provided by non-executable pages that an attacker
83752 + could abuse. Therefore the best solution is to not have any
83753 + files on your system that would require this option. This can
83754 + be achieved by not using libc5 (which relies on the kernel
83755 + signal handler return code) and not using or rewriting programs
83756 + that make use of the nested function implementation of GCC.
83757 + Skilled users can just fix GCC itself so that it implements
83758 + nested function calls in a way that does not interfere with PaX.
83759 +
83760 +config PAX_EMUSIGRT
83761 + bool "Automatically emulate sigreturn trampolines"
83762 + depends on PAX_EMUTRAMP && PARISC
83763 + default y
83764 + help
83765 + Enabling this option will have the kernel automatically detect
83766 + and emulate signal return trampolines executing on the stack
83767 + that would otherwise lead to task termination.
83768 +
83769 + This solution is intended as a temporary one for users with
83770 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83771 + Modula-3 runtime, etc) or executables linked to such, basically
83772 + everything that does not specify its own SA_RESTORER function in
83773 + normal executable memory like glibc 2.1+ does.
83774 +
83775 + On parisc you MUST enable this option, otherwise your system will
83776 + not even boot.
83777 +
83778 + NOTE: this feature cannot be disabled on a per executable basis
83779 + and since it *does* open up a loophole in the protection provided
83780 + by non-executable pages, the best solution is to not have any
83781 + files on your system that would require this option.
83782 +
83783 +config PAX_MPROTECT
83784 + bool "Restrict mprotect()"
83785 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83786 + help
83787 + Enabling this option will prevent programs from
83788 + - changing the executable status of memory pages that were
83789 + not originally created as executable,
83790 + - making read-only executable pages writable again,
83791 + - creating executable pages from anonymous memory,
83792 + - making read-only-after-relocations (RELRO) data pages writable again.
83793 +
83794 + You should say Y here to complete the protection provided by
83795 + the enforcement of non-executable pages.
83796 +
83797 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83798 + this feature on a per file basis.
83799 +
83800 +config PAX_MPROTECT_COMPAT
83801 + bool "Use legacy/compat protection demoting (read help)"
83802 + depends on PAX_MPROTECT
83803 + default n
83804 + help
83805 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83806 + by sending the proper error code to the application. For some broken
83807 + userland, this can cause problems with Python or other applications. The
83808 + current implementation however allows for applications like clamav to
83809 + detect if JIT compilation/execution is allowed and to fall back gracefully
83810 + to an interpreter-based mode if it does not. While we encourage everyone
83811 + to use the current implementation as-is and push upstream to fix broken
83812 + userland (note that the RWX logging option can assist with this), in some
83813 + environments this may not be possible. Having to disable MPROTECT
83814 + completely on certain binaries reduces the security benefit of PaX,
83815 + so this option is provided for those environments to revert to the old
83816 + behavior.
83817 +
83818 +config PAX_ELFRELOCS
83819 + bool "Allow ELF text relocations (read help)"
83820 + depends on PAX_MPROTECT
83821 + default n
83822 + help
83823 + Non-executable pages and mprotect() restrictions are effective
83824 + in preventing the introduction of new executable code into an
83825 + attacked task's address space. There remain only two venues
83826 + for this kind of attack: if the attacker can execute already
83827 + existing code in the attacked task then he can either have it
83828 + create and mmap() a file containing his code or have it mmap()
83829 + an already existing ELF library that does not have position
83830 + independent code in it and use mprotect() on it to make it
83831 + writable and copy his code there. While protecting against
83832 + the former approach is beyond PaX, the latter can be prevented
83833 + by having only PIC ELF libraries on one's system (which do not
83834 + need to relocate their code). If you are sure this is your case,
83835 + as is the case with all modern Linux distributions, then leave
83836 + this option disabled. You should say 'n' here.
83837 +
83838 +config PAX_ETEXECRELOCS
83839 + bool "Allow ELF ET_EXEC text relocations"
83840 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83841 + select PAX_ELFRELOCS
83842 + default y
83843 + help
83844 + On some architectures there are incorrectly created applications
83845 + that require text relocations and would not work without enabling
83846 + this option. If you are an alpha, ia64 or parisc user, you should
83847 + enable this option and disable it once you have made sure that
83848 + none of your applications need it.
83849 +
83850 +config PAX_EMUPLT
83851 + bool "Automatically emulate ELF PLT"
83852 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83853 + default y
83854 + help
83855 + Enabling this option will have the kernel automatically detect
83856 + and emulate the Procedure Linkage Table entries in ELF files.
83857 + On some architectures such entries are in writable memory, and
83858 + become non-executable leading to task termination. Therefore
83859 + it is mandatory that you enable this option on alpha, parisc,
83860 + sparc and sparc64, otherwise your system would not even boot.
83861 +
83862 + NOTE: this feature *does* open up a loophole in the protection
83863 + provided by the non-executable pages, therefore the proper
83864 + solution is to modify the toolchain to produce a PLT that does
83865 + not need to be writable.
83866 +
83867 +config PAX_DLRESOLVE
83868 + bool 'Emulate old glibc resolver stub'
83869 + depends on PAX_EMUPLT && SPARC
83870 + default n
83871 + help
83872 + This option is needed if userland has an old glibc (before 2.4)
83873 + that puts a 'save' instruction into the runtime generated resolver
83874 + stub that needs special emulation.
83875 +
83876 +config PAX_KERNEXEC
83877 + bool "Enforce non-executable kernel pages"
83878 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83879 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83880 + select PAX_KERNEXEC_PLUGIN if X86_64
83881 + help
83882 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83883 + that is, enabling this option will make it harder to inject
83884 + and execute 'foreign' code in kernel memory itself.
83885 +
83886 + Note that on x86_64 kernels there is a known regression when
83887 + this feature and KVM/VMX are both enabled in the host kernel.
83888 +
83889 +choice
83890 + prompt "Return Address Instrumentation Method"
83891 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83892 + depends on PAX_KERNEXEC_PLUGIN
83893 + help
83894 + Select the method used to instrument function pointer dereferences.
83895 + Note that binary modules cannot be instrumented by this approach.
83896 +
83897 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83898 + bool "bts"
83899 + help
83900 + This method is compatible with binary only modules but has
83901 + a higher runtime overhead.
83902 +
83903 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83904 + bool "or"
83905 + depends on !PARAVIRT
83906 + help
83907 + This method is incompatible with binary only modules but has
83908 + a lower runtime overhead.
83909 +endchoice
83910 +
83911 +config PAX_KERNEXEC_PLUGIN_METHOD
83912 + string
83913 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83914 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83915 + default ""
83916 +
83917 +config PAX_KERNEXEC_MODULE_TEXT
83918 + int "Minimum amount of memory reserved for module code"
83919 + default "4"
83920 + depends on PAX_KERNEXEC && X86_32 && MODULES
83921 + help
83922 + Due to implementation details the kernel must reserve a fixed
83923 + amount of memory for module code at compile time that cannot be
83924 + changed at runtime. Here you can specify the minimum amount
83925 + in MB that will be reserved. Due to the same implementation
83926 + details this size will always be rounded up to the next 2/4 MB
83927 + boundary (depends on PAE) so the actually available memory for
83928 + module code will usually be more than this minimum.
83929 +
83930 + The default 4 MB should be enough for most users but if you have
83931 + an excessive number of modules (e.g., most distribution configs
83932 + compile many drivers as modules) or use huge modules such as
83933 + nvidia's kernel driver, you will need to adjust this amount.
83934 + A good rule of thumb is to look at your currently loaded kernel
83935 + modules and add up their sizes.
83936 +
83937 +endmenu
83938 +
83939 +menu "Address Space Layout Randomization"
83940 + depends on PAX
83941 +
83942 +config PAX_ASLR
83943 + bool "Address Space Layout Randomization"
83944 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
83945 + help
83946 + Many if not most exploit techniques rely on the knowledge of
83947 + certain addresses in the attacked program. The following options
83948 + will allow the kernel to apply a certain amount of randomization
83949 + to specific parts of the program thereby forcing an attacker to
83950 + guess them in most cases. Any failed guess will most likely crash
83951 + the attacked program which allows the kernel to detect such attempts
83952 + and react on them. PaX itself provides no reaction mechanisms,
83953 + instead it is strongly encouraged that you make use of Nergal's
83954 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83955 + (http://www.grsecurity.net/) built-in crash detection features or
83956 + develop one yourself.
83957 +
83958 + By saying Y here you can choose to randomize the following areas:
83959 + - top of the task's kernel stack
83960 + - top of the task's userland stack
83961 + - base address for mmap() requests that do not specify one
83962 + (this includes all libraries)
83963 + - base address of the main executable
83964 +
83965 + It is strongly recommended to say Y here as address space layout
83966 + randomization has negligible impact on performance yet it provides
83967 + a very effective protection.
83968 +
83969 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83970 + this feature on a per file basis.
83971 +
83972 +config PAX_RANDKSTACK
83973 + bool "Randomize kernel stack base"
83974 + depends on X86_TSC && X86
83975 + help
83976 + By saying Y here the kernel will randomize every task's kernel
83977 + stack on every system call. This will not only force an attacker
83978 + to guess it but also prevent him from making use of possible
83979 + leaked information about it.
83980 +
83981 + Since the kernel stack is a rather scarce resource, randomization
83982 + may cause unexpected stack overflows, therefore you should very
83983 + carefully test your system. Note that once enabled in the kernel
83984 + configuration, this feature cannot be disabled on a per file basis.
83985 +
83986 +config PAX_RANDUSTACK
83987 + bool "Randomize user stack base"
83988 + depends on PAX_ASLR
83989 + help
83990 + By saying Y here the kernel will randomize every task's userland
83991 + stack. The randomization is done in two steps where the second
83992 + one may apply a big amount of shift to the top of the stack and
83993 + cause problems for programs that want to use lots of memory (more
83994 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83995 + For this reason the second step can be controlled by 'chpax' or
83996 + 'paxctl' on a per file basis.
83997 +
83998 +config PAX_RANDMMAP
83999 + bool "Randomize mmap() base"
84000 + depends on PAX_ASLR
84001 + help
84002 + By saying Y here the kernel will use a randomized base address for
84003 + mmap() requests that do not specify one themselves. As a result
84004 + all dynamically loaded libraries will appear at random addresses
84005 + and therefore be harder to exploit by a technique where an attacker
84006 + attempts to execute library code for his purposes (e.g. spawn a
84007 + shell from an exploited program that is running at an elevated
84008 + privilege level).
84009 +
84010 + Furthermore, if a program is relinked as a dynamic ELF file, its
84011 + base address will be randomized as well, completing the full
84012 + randomization of the address space layout. Attacking such programs
84013 + becomes a guess game. You can find an example of doing this at
84014 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
84015 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
84016 +
84017 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
84018 + feature on a per file basis.
84019 +
84020 +endmenu
84021 +
84022 +menu "Miscellaneous hardening features"
84023 +
84024 +config PAX_MEMORY_SANITIZE
84025 + bool "Sanitize all freed memory"
84026 + help
84027 + By saying Y here the kernel will erase memory pages as soon as they
84028 + are freed. This in turn reduces the lifetime of data stored in the
84029 + pages, making it less likely that sensitive information such as
84030 + passwords, cryptographic secrets, etc stay in memory for too long.
84031 +
84032 + This is especially useful for programs whose runtime is short, long
84033 + lived processes and the kernel itself benefit from this as long as
84034 + they operate on whole memory pages and ensure timely freeing of pages
84035 + that may hold sensitive information.
84036 +
84037 + The tradeoff is performance impact, on a single CPU system kernel
84038 + compilation sees a 3% slowdown, other systems and workloads may vary
84039 + and you are advised to test this feature on your expected workload
84040 + before deploying it.
84041 +
84042 + Note that this feature does not protect data stored in live pages,
84043 + e.g., process memory swapped to disk may stay there for a long time.
84044 +
84045 +config PAX_MEMORY_STACKLEAK
84046 + bool "Sanitize kernel stack"
84047 + depends on X86
84048 + help
84049 + By saying Y here the kernel will erase the kernel stack before it
84050 + returns from a system call. This in turn reduces the information
84051 + that a kernel stack leak bug can reveal.
84052 +
84053 + Note that such a bug can still leak information that was put on
84054 + the stack by the current system call (the one eventually triggering
84055 + the bug) but traces of earlier system calls on the kernel stack
84056 + cannot leak anymore.
84057 +
84058 + The tradeoff is performance impact, on a single CPU system kernel
84059 + compilation sees a 1% slowdown, other systems and workloads may vary
84060 + and you are advised to test this feature on your expected workload
84061 + before deploying it.
84062 +
84063 + Note: full support for this feature requires gcc with plugin support
84064 + so make sure your compiler is at least gcc 4.5.0 (cross compilation
84065 + is not supported). Using older gcc versions means that functions
84066 + with large enough stack frames may leave uninitialized memory behind
84067 + that may be exposed to a later syscall leaking the stack.
84068 +
84069 +config PAX_MEMORY_UDEREF
84070 + bool "Prevent invalid userland pointer dereference"
84071 + depends on X86 && !UML_X86 && !XEN
84072 + select PAX_PER_CPU_PGD if X86_64
84073 + help
84074 + By saying Y here the kernel will be prevented from dereferencing
84075 + userland pointers in contexts where the kernel expects only kernel
84076 + pointers. This is both a useful runtime debugging feature and a
84077 + security measure that prevents exploiting a class of kernel bugs.
84078 +
84079 + The tradeoff is that some virtualization solutions may experience
84080 + a huge slowdown and therefore you should not enable this feature
84081 + for kernels meant to run in such environments. Whether a given VM
84082 + solution is affected or not is best determined by simply trying it
84083 + out, the performance impact will be obvious right on boot as this
84084 + mechanism engages from very early on. A good rule of thumb is that
84085 + VMs running on CPUs without hardware virtualization support (i.e.,
84086 + the majority of IA-32 CPUs) will likely experience the slowdown.
84087 +
84088 +config PAX_REFCOUNT
84089 + bool "Prevent various kernel object reference counter overflows"
84090 + depends on GRKERNSEC && (X86 || SPARC64)
84091 + help
84092 + By saying Y here the kernel will detect and prevent overflowing
84093 + various (but not all) kinds of object reference counters. Such
84094 + overflows can normally occur due to bugs only and are often, if
84095 + not always, exploitable.
84096 +
84097 + The tradeoff is that data structures protected by an overflowed
84098 + refcount will never be freed and therefore will leak memory. Note
84099 + that this leak also happens even without this protection but in
84100 + that case the overflow can eventually trigger the freeing of the
84101 + data structure while it is still being used elsewhere, resulting
84102 + in the exploitable situation that this feature prevents.
84103 +
84104 + Since this has a negligible performance impact, you should enable
84105 + this feature.
84106 +
84107 +config PAX_USERCOPY
84108 + bool "Harden heap object copies between kernel and userland"
84109 + depends on X86 || PPC || SPARC || ARM
84110 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
84111 + help
84112 + By saying Y here the kernel will enforce the size of heap objects
84113 + when they are copied in either direction between the kernel and
84114 + userland, even if only a part of the heap object is copied.
84115 +
84116 + Specifically, this checking prevents information leaking from the
84117 + kernel heap during kernel to userland copies (if the kernel heap
84118 + object is otherwise fully initialized) and prevents kernel heap
84119 + overflows during userland to kernel copies.
84120 +
84121 + Note that the current implementation provides the strictest bounds
84122 + checks for the SLUB allocator.
84123 +
84124 + Enabling this option also enables per-slab cache protection against
84125 + data in a given cache being copied into/out of via userland
84126 + accessors. Though the whitelist of regions will be reduced over
84127 + time, it notably protects important data structures like task structs.
84128 +
84129 +
84130 + If frame pointers are enabled on x86, this option will also
84131 + restrict copies into and out of the kernel stack to local variables
84132 + within a single frame.
84133 +
84134 + Since this has a negligible performance impact, you should enable
84135 + this feature.
84136 +
84137 +endmenu
84138 +
84139 +endmenu
84140 +
84141 config KEYS
84142 bool "Enable access key retention support"
84143 help
84144 @@ -146,7 +727,7 @@ config INTEL_TXT
84145 config LSM_MMAP_MIN_ADDR
84146 int "Low address space for LSM to protect from user allocation"
84147 depends on SECURITY && SECURITY_SELINUX
84148 - default 65536
84149 + default 32768
84150 help
84151 This is the portion of low virtual memory which should be protected
84152 from userspace allocation. Keeping a user from writing to low pages
84153 diff --git a/security/capability.c b/security/capability.c
84154 index fce07a7..5f12858 100644
84155 --- a/security/capability.c
84156 +++ b/security/capability.c
84157 @@ -890,7 +890,7 @@ static void cap_audit_rule_free(void *lsmrule)
84158 }
84159 #endif /* CONFIG_AUDIT */
84160
84161 -struct security_operations default_security_ops = {
84162 +struct security_operations default_security_ops __read_only = {
84163 .name = "default",
84164 };
84165
84166 diff --git a/security/commoncap.c b/security/commoncap.c
84167 index fe30751..aaba312 100644
84168 --- a/security/commoncap.c
84169 +++ b/security/commoncap.c
84170 @@ -27,6 +27,8 @@
84171 #include <linux/sched.h>
84172 #include <linux/prctl.h>
84173 #include <linux/securebits.h>
84174 +#include <linux/syslog.h>
84175 +#include <net/sock.h>
84176
84177 /*
84178 * If a non-root user executes a setuid-root binary in
84179 @@ -50,9 +52,18 @@ static void warn_setuid_and_fcaps_mixed(char *fname)
84180 }
84181 }
84182
84183 +#ifdef CONFIG_NET
84184 +extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
84185 +#endif
84186 +
84187 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
84188 {
84189 +#ifdef CONFIG_NET
84190 + NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
84191 +#else
84192 NETLINK_CB(skb).eff_cap = current_cap();
84193 +#endif
84194 +
84195 return 0;
84196 }
84197
84198 @@ -582,6 +593,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
84199 {
84200 const struct cred *cred = current_cred();
84201
84202 + if (gr_acl_enable_at_secure())
84203 + return 1;
84204 +
84205 if (cred->uid != 0) {
84206 if (bprm->cap_effective)
84207 return 1;
84208 @@ -956,13 +970,18 @@ error:
84209 /**
84210 * cap_syslog - Determine whether syslog function is permitted
84211 * @type: Function requested
84212 + * @from_file: Whether this request came from an open file (i.e. /proc)
84213 *
84214 * Determine whether the current process is permitted to use a particular
84215 * syslog function, returning 0 if permission is granted, -ve if not.
84216 */
84217 -int cap_syslog(int type)
84218 +int cap_syslog(int type, bool from_file)
84219 {
84220 - if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
84221 + /* /proc/kmsg can open be opened by CAP_SYS_ADMIN */
84222 + if (type != SYSLOG_ACTION_OPEN && from_file)
84223 + return 0;
84224 + if ((type != SYSLOG_ACTION_READ_ALL &&
84225 + type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
84226 return -EPERM;
84227 return 0;
84228 }
84229 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
84230 index 165eb53..b1db4eb 100644
84231 --- a/security/integrity/ima/ima.h
84232 +++ b/security/integrity/ima/ima.h
84233 @@ -84,8 +84,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84234 extern spinlock_t ima_queue_lock;
84235
84236 struct ima_h_table {
84237 - atomic_long_t len; /* number of stored measurements in the list */
84238 - atomic_long_t violations;
84239 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
84240 + atomic_long_unchecked_t violations;
84241 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
84242 };
84243 extern struct ima_h_table ima_htable;
84244 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
84245 index 3cd58b6..b4c284f 100644
84246 --- a/security/integrity/ima/ima_api.c
84247 +++ b/security/integrity/ima/ima_api.c
84248 @@ -74,7 +74,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84249 int result;
84250
84251 /* can overflow, only indicator */
84252 - atomic_long_inc(&ima_htable.violations);
84253 + atomic_long_inc_unchecked(&ima_htable.violations);
84254
84255 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
84256 if (!entry) {
84257 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
84258 index 0c72c9c..433e29b 100644
84259 --- a/security/integrity/ima/ima_fs.c
84260 +++ b/security/integrity/ima/ima_fs.c
84261 @@ -27,12 +27,12 @@
84262 static int valid_policy = 1;
84263 #define TMPBUFLEN 12
84264 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
84265 - loff_t *ppos, atomic_long_t *val)
84266 + loff_t *ppos, atomic_long_unchecked_t *val)
84267 {
84268 char tmpbuf[TMPBUFLEN];
84269 ssize_t len;
84270
84271 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
84272 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
84273 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
84274 }
84275
84276 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
84277 index a0880e9..93e4ebb 100644
84278 --- a/security/integrity/ima/ima_queue.c
84279 +++ b/security/integrity/ima/ima_queue.c
84280 @@ -78,7 +78,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
84281 INIT_LIST_HEAD(&qe->later);
84282 list_add_tail_rcu(&qe->later, &ima_measurements);
84283
84284 - atomic_long_inc(&ima_htable.len);
84285 + atomic_long_inc_unchecked(&ima_htable.len);
84286 key = ima_hash_key(entry->digest);
84287 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
84288 return 0;
84289 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
84290 index e031952..c9a535d 100644
84291 --- a/security/keys/keyring.c
84292 +++ b/security/keys/keyring.c
84293 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
84294 ret = -EFAULT;
84295
84296 for (loop = 0; loop < klist->nkeys; loop++) {
84297 + key_serial_t serial;
84298 key = klist->keys[loop];
84299 + serial = key->serial;
84300
84301 tmp = sizeof(key_serial_t);
84302 if (tmp > buflen)
84303 tmp = buflen;
84304
84305 - if (copy_to_user(buffer,
84306 - &key->serial,
84307 - tmp) != 0)
84308 + if (copy_to_user(buffer, &serial, tmp))
84309 goto error;
84310
84311 buflen -= tmp;
84312 diff --git a/security/min_addr.c b/security/min_addr.c
84313 index d9f9425..c28cef4 100644
84314 --- a/security/min_addr.c
84315 +++ b/security/min_addr.c
84316 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
84317 */
84318 static void update_mmap_min_addr(void)
84319 {
84320 +#ifndef SPARC
84321 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
84322 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
84323 mmap_min_addr = dac_mmap_min_addr;
84324 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
84325 #else
84326 mmap_min_addr = dac_mmap_min_addr;
84327 #endif
84328 +#endif
84329 }
84330
84331 /*
84332 diff --git a/security/root_plug.c b/security/root_plug.c
84333 index 2f7ffa6..0455400 100644
84334 --- a/security/root_plug.c
84335 +++ b/security/root_plug.c
84336 @@ -70,7 +70,7 @@ static int rootplug_bprm_check_security (struct linux_binprm *bprm)
84337 return 0;
84338 }
84339
84340 -static struct security_operations rootplug_security_ops = {
84341 +static struct security_operations rootplug_security_ops __read_only = {
84342 .bprm_check_security = rootplug_bprm_check_security,
84343 };
84344
84345 diff --git a/security/security.c b/security/security.c
84346 index c4c6732..7abf13b 100644
84347 --- a/security/security.c
84348 +++ b/security/security.c
84349 @@ -24,7 +24,7 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1];
84350 extern struct security_operations default_security_ops;
84351 extern void security_fixup_ops(struct security_operations *ops);
84352
84353 -struct security_operations *security_ops; /* Initialized to NULL */
84354 +struct security_operations *security_ops __read_only; /* Initialized to NULL */
84355
84356 static inline int verify(struct security_operations *ops)
84357 {
84358 @@ -106,7 +106,7 @@ int __init security_module_enable(struct security_operations *ops)
84359 * If there is already a security module registered with the kernel,
84360 * an error will be returned. Otherwise %0 is returned on success.
84361 */
84362 -int register_security(struct security_operations *ops)
84363 +int __init register_security(struct security_operations *ops)
84364 {
84365 if (verify(ops)) {
84366 printk(KERN_DEBUG "%s could not verify "
84367 @@ -199,9 +199,9 @@ int security_quota_on(struct dentry *dentry)
84368 return security_ops->quota_on(dentry);
84369 }
84370
84371 -int security_syslog(int type)
84372 +int security_syslog(int type, bool from_file)
84373 {
84374 - return security_ops->syslog(type);
84375 + return security_ops->syslog(type, from_file);
84376 }
84377
84378 int security_settime(struct timespec *ts, struct timezone *tz)
84379 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
84380 index a106754..ca3a589 100644
84381 --- a/security/selinux/hooks.c
84382 +++ b/security/selinux/hooks.c
84383 @@ -76,6 +76,7 @@
84384 #include <linux/selinux.h>
84385 #include <linux/mutex.h>
84386 #include <linux/posix-timers.h>
84387 +#include <linux/syslog.h>
84388
84389 #include "avc.h"
84390 #include "objsec.h"
84391 @@ -131,7 +132,7 @@ int selinux_enabled = 1;
84392 * Minimal support for a secondary security module,
84393 * just to allow the use of the capability module.
84394 */
84395 -static struct security_operations *secondary_ops;
84396 +static struct security_operations *secondary_ops __read_only;
84397
84398 /* Lists of inode and superblock security structures initialized
84399 before the policy was loaded. */
84400 @@ -2050,29 +2051,30 @@ static int selinux_quota_on(struct dentry *dentry)
84401 return dentry_has_perm(cred, NULL, dentry, FILE__QUOTAON);
84402 }
84403
84404 -static int selinux_syslog(int type)
84405 +static int selinux_syslog(int type, bool from_file)
84406 {
84407 int rc;
84408
84409 - rc = cap_syslog(type);
84410 + rc = cap_syslog(type, from_file);
84411 if (rc)
84412 return rc;
84413
84414 switch (type) {
84415 - case 3: /* Read last kernel messages */
84416 - case 10: /* Return size of the log buffer */
84417 + case SYSLOG_ACTION_READ_ALL: /* Read last kernel messages */
84418 + case SYSLOG_ACTION_SIZE_BUFFER: /* Return size of the log buffer */
84419 rc = task_has_system(current, SYSTEM__SYSLOG_READ);
84420 break;
84421 - case 6: /* Disable logging to console */
84422 - case 7: /* Enable logging to console */
84423 - case 8: /* Set level of messages printed to console */
84424 + case SYSLOG_ACTION_CONSOLE_OFF: /* Disable logging to console */
84425 + case SYSLOG_ACTION_CONSOLE_ON: /* Enable logging to console */
84426 + /* Set level of messages printed to console */
84427 + case SYSLOG_ACTION_CONSOLE_LEVEL:
84428 rc = task_has_system(current, SYSTEM__SYSLOG_CONSOLE);
84429 break;
84430 - case 0: /* Close log */
84431 - case 1: /* Open log */
84432 - case 2: /* Read from log */
84433 - case 4: /* Read/clear last kernel messages */
84434 - case 5: /* Clear ring buffer */
84435 + case SYSLOG_ACTION_CLOSE: /* Close log */
84436 + case SYSLOG_ACTION_OPEN: /* Open log */
84437 + case SYSLOG_ACTION_READ: /* Read from log */
84438 + case SYSLOG_ACTION_READ_CLEAR: /* Read/clear last kernel messages */
84439 + case SYSLOG_ACTION_CLEAR: /* Clear ring buffer */
84440 default:
84441 rc = task_has_system(current, SYSTEM__SYSLOG_MOD);
84442 break;
84443 @@ -5457,7 +5459,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
84444
84445 #endif
84446
84447 -static struct security_operations selinux_ops = {
84448 +static struct security_operations selinux_ops __read_only = {
84449 .name = "selinux",
84450
84451 .ptrace_access_check = selinux_ptrace_access_check,
84452 @@ -5841,7 +5843,9 @@ int selinux_disable(void)
84453 avc_disable();
84454
84455 /* Reset security_ops to the secondary module, dummy or capability. */
84456 + pax_open_kernel();
84457 security_ops = secondary_ops;
84458 + pax_close_kernel();
84459
84460 /* Unregister netfilter hooks. */
84461 selinux_nf_ip_exit();
84462 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
84463 index 13128f9..c23c736 100644
84464 --- a/security/selinux/include/xfrm.h
84465 +++ b/security/selinux/include/xfrm.h
84466 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
84467
84468 static inline void selinux_xfrm_notify_policyload(void)
84469 {
84470 - atomic_inc(&flow_cache_genid);
84471 + atomic_inc_unchecked(&flow_cache_genid);
84472 }
84473 #else
84474 static inline int selinux_xfrm_enabled(void)
84475 diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
84476 index ff17820..d68084c 100644
84477 --- a/security/selinux/ss/services.c
84478 +++ b/security/selinux/ss/services.c
84479 @@ -1715,6 +1715,8 @@ int security_load_policy(void *data, size_t len)
84480 int rc = 0;
84481 struct policy_file file = { data, len }, *fp = &file;
84482
84483 + pax_track_stack();
84484 +
84485 if (!ss_initialized) {
84486 avtab_cache_init();
84487 if (policydb_read(&policydb, fp)) {
84488 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
84489 index c33b6bb..b51f19e 100644
84490 --- a/security/smack/smack_lsm.c
84491 +++ b/security/smack/smack_lsm.c
84492 @@ -157,12 +157,12 @@ static int smack_ptrace_traceme(struct task_struct *ptp)
84493 *
84494 * Returns 0 on success, error code otherwise.
84495 */
84496 -static int smack_syslog(int type)
84497 +static int smack_syslog(int type, bool from_file)
84498 {
84499 int rc;
84500 char *sp = current_security();
84501
84502 - rc = cap_syslog(type);
84503 + rc = cap_syslog(type, from_file);
84504 if (rc != 0)
84505 return rc;
84506
84507 @@ -3073,7 +3073,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
84508 return 0;
84509 }
84510
84511 -struct security_operations smack_ops = {
84512 +struct security_operations smack_ops __read_only = {
84513 .name = "smack",
84514
84515 .ptrace_access_check = smack_ptrace_access_check,
84516 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
84517 index 9548a09..9a5f384 100644
84518 --- a/security/tomoyo/tomoyo.c
84519 +++ b/security/tomoyo/tomoyo.c
84520 @@ -275,7 +275,7 @@ static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
84521 * tomoyo_security_ops is a "struct security_operations" which is used for
84522 * registering TOMOYO.
84523 */
84524 -static struct security_operations tomoyo_security_ops = {
84525 +static struct security_operations tomoyo_security_ops __read_only = {
84526 .name = "tomoyo",
84527 .cred_alloc_blank = tomoyo_cred_alloc_blank,
84528 .cred_prepare = tomoyo_cred_prepare,
84529 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
84530 index 84bb07d..c2ab6b6 100644
84531 --- a/sound/aoa/codecs/onyx.c
84532 +++ b/sound/aoa/codecs/onyx.c
84533 @@ -53,7 +53,7 @@ struct onyx {
84534 spdif_locked:1,
84535 analog_locked:1,
84536 original_mute:2;
84537 - int open_count;
84538 + local_t open_count;
84539 struct codec_info *codec_info;
84540
84541 /* mutex serializes concurrent access to the device
84542 @@ -752,7 +752,7 @@ static int onyx_open(struct codec_info_item *cii,
84543 struct onyx *onyx = cii->codec_data;
84544
84545 mutex_lock(&onyx->mutex);
84546 - onyx->open_count++;
84547 + local_inc(&onyx->open_count);
84548 mutex_unlock(&onyx->mutex);
84549
84550 return 0;
84551 @@ -764,8 +764,7 @@ static int onyx_close(struct codec_info_item *cii,
84552 struct onyx *onyx = cii->codec_data;
84553
84554 mutex_lock(&onyx->mutex);
84555 - onyx->open_count--;
84556 - if (!onyx->open_count)
84557 + if (local_dec_and_test(&onyx->open_count))
84558 onyx->spdif_locked = onyx->analog_locked = 0;
84559 mutex_unlock(&onyx->mutex);
84560
84561 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
84562 index ffd2025..df062c9 100644
84563 --- a/sound/aoa/codecs/onyx.h
84564 +++ b/sound/aoa/codecs/onyx.h
84565 @@ -11,6 +11,7 @@
84566 #include <linux/i2c.h>
84567 #include <asm/pmac_low_i2c.h>
84568 #include <asm/prom.h>
84569 +#include <asm/local.h>
84570
84571 /* PCM3052 register definitions */
84572
84573 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
84574 index d9c9635..bc0a5a2 100644
84575 --- a/sound/core/oss/pcm_oss.c
84576 +++ b/sound/core/oss/pcm_oss.c
84577 @@ -1395,7 +1395,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
84578 }
84579 } else {
84580 tmp = snd_pcm_oss_write2(substream,
84581 - (const char __force *)buf,
84582 + (const char __force_kernel *)buf,
84583 runtime->oss.period_bytes, 0);
84584 if (tmp <= 0)
84585 goto err;
84586 @@ -1483,7 +1483,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
84587 xfer += tmp;
84588 runtime->oss.buffer_used -= tmp;
84589 } else {
84590 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
84591 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
84592 runtime->oss.period_bytes, 0);
84593 if (tmp <= 0)
84594 goto err;
84595 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
84596 index 038232d..7dd9e5c 100644
84597 --- a/sound/core/pcm_compat.c
84598 +++ b/sound/core/pcm_compat.c
84599 @@ -30,7 +30,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
84600 int err;
84601
84602 fs = snd_enter_user();
84603 - err = snd_pcm_delay(substream, &delay);
84604 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
84605 snd_leave_user(fs);
84606 if (err < 0)
84607 return err;
84608 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
84609 index e6d2d97..4843949 100644
84610 --- a/sound/core/pcm_native.c
84611 +++ b/sound/core/pcm_native.c
84612 @@ -2747,11 +2747,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
84613 switch (substream->stream) {
84614 case SNDRV_PCM_STREAM_PLAYBACK:
84615 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
84616 - (void __user *)arg);
84617 + (void __force_user *)arg);
84618 break;
84619 case SNDRV_PCM_STREAM_CAPTURE:
84620 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
84621 - (void __user *)arg);
84622 + (void __force_user *)arg);
84623 break;
84624 default:
84625 result = -EINVAL;
84626 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
84627 index 1f99767..14636533 100644
84628 --- a/sound/core/seq/seq_device.c
84629 +++ b/sound/core/seq/seq_device.c
84630 @@ -63,7 +63,7 @@ struct ops_list {
84631 int argsize; /* argument size */
84632
84633 /* operators */
84634 - struct snd_seq_dev_ops ops;
84635 + struct snd_seq_dev_ops *ops;
84636
84637 /* registred devices */
84638 struct list_head dev_list; /* list of devices */
84639 @@ -332,7 +332,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
84640
84641 mutex_lock(&ops->reg_mutex);
84642 /* copy driver operators */
84643 - ops->ops = *entry;
84644 + ops->ops = entry;
84645 ops->driver |= DRIVER_LOADED;
84646 ops->argsize = argsize;
84647
84648 @@ -462,7 +462,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
84649 dev->name, ops->id, ops->argsize, dev->argsize);
84650 return -EINVAL;
84651 }
84652 - if (ops->ops.init_device(dev) >= 0) {
84653 + if (ops->ops->init_device(dev) >= 0) {
84654 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
84655 ops->num_init_devices++;
84656 } else {
84657 @@ -489,7 +489,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
84658 dev->name, ops->id, ops->argsize, dev->argsize);
84659 return -EINVAL;
84660 }
84661 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
84662 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
84663 dev->status = SNDRV_SEQ_DEVICE_FREE;
84664 dev->driver_data = NULL;
84665 ops->num_init_devices--;
84666 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
84667 index 9284829..ac8e8b2 100644
84668 --- a/sound/drivers/mts64.c
84669 +++ b/sound/drivers/mts64.c
84670 @@ -27,6 +27,7 @@
84671 #include <sound/initval.h>
84672 #include <sound/rawmidi.h>
84673 #include <sound/control.h>
84674 +#include <asm/local.h>
84675
84676 #define CARD_NAME "Miditerminal 4140"
84677 #define DRIVER_NAME "MTS64"
84678 @@ -65,7 +66,7 @@ struct mts64 {
84679 struct pardevice *pardev;
84680 int pardev_claimed;
84681
84682 - int open_count;
84683 + local_t open_count;
84684 int current_midi_output_port;
84685 int current_midi_input_port;
84686 u8 mode[MTS64_NUM_INPUT_PORTS];
84687 @@ -695,7 +696,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84688 {
84689 struct mts64 *mts = substream->rmidi->private_data;
84690
84691 - if (mts->open_count == 0) {
84692 + if (local_read(&mts->open_count) == 0) {
84693 /* We don't need a spinlock here, because this is just called
84694 if the device has not been opened before.
84695 So there aren't any IRQs from the device */
84696 @@ -703,7 +704,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84697
84698 msleep(50);
84699 }
84700 - ++(mts->open_count);
84701 + local_inc(&mts->open_count);
84702
84703 return 0;
84704 }
84705 @@ -713,8 +714,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84706 struct mts64 *mts = substream->rmidi->private_data;
84707 unsigned long flags;
84708
84709 - --(mts->open_count);
84710 - if (mts->open_count == 0) {
84711 + if (local_dec_return(&mts->open_count) == 0) {
84712 /* We need the spinlock_irqsave here because we can still
84713 have IRQs at this point */
84714 spin_lock_irqsave(&mts->lock, flags);
84715 @@ -723,8 +723,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84716
84717 msleep(500);
84718
84719 - } else if (mts->open_count < 0)
84720 - mts->open_count = 0;
84721 + } else if (local_read(&mts->open_count) < 0)
84722 + local_set(&mts->open_count, 0);
84723
84724 return 0;
84725 }
84726 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84727 index 01997f2..cbc1195 100644
84728 --- a/sound/drivers/opl4/opl4_lib.c
84729 +++ b/sound/drivers/opl4/opl4_lib.c
84730 @@ -27,7 +27,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84731 MODULE_DESCRIPTION("OPL4 driver");
84732 MODULE_LICENSE("GPL");
84733
84734 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84735 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84736 {
84737 int timeout = 10;
84738 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84739 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84740 index 60158e2..0a0cc1a 100644
84741 --- a/sound/drivers/portman2x4.c
84742 +++ b/sound/drivers/portman2x4.c
84743 @@ -46,6 +46,7 @@
84744 #include <sound/initval.h>
84745 #include <sound/rawmidi.h>
84746 #include <sound/control.h>
84747 +#include <asm/local.h>
84748
84749 #define CARD_NAME "Portman 2x4"
84750 #define DRIVER_NAME "portman"
84751 @@ -83,7 +84,7 @@ struct portman {
84752 struct pardevice *pardev;
84753 int pardev_claimed;
84754
84755 - int open_count;
84756 + local_t open_count;
84757 int mode[PORTMAN_NUM_INPUT_PORTS];
84758 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84759 };
84760 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
84761 index 02f79d2..8691d43 100644
84762 --- a/sound/isa/cmi8330.c
84763 +++ b/sound/isa/cmi8330.c
84764 @@ -173,7 +173,7 @@ struct snd_cmi8330 {
84765
84766 struct snd_pcm *pcm;
84767 struct snd_cmi8330_stream {
84768 - struct snd_pcm_ops ops;
84769 + snd_pcm_ops_no_const ops;
84770 snd_pcm_open_callback_t open;
84771 void *private_data; /* sb or wss */
84772 } streams[2];
84773 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84774 index 733b014..56ce96f 100644
84775 --- a/sound/oss/sb_audio.c
84776 +++ b/sound/oss/sb_audio.c
84777 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
84778 buf16 = (signed short *)(localbuf + localoffs);
84779 while (c)
84780 {
84781 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84782 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84783 if (copy_from_user(lbuf8,
84784 userbuf+useroffs + p,
84785 locallen))
84786 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84787 index 3136c88..28ad950 100644
84788 --- a/sound/oss/swarm_cs4297a.c
84789 +++ b/sound/oss/swarm_cs4297a.c
84790 @@ -2577,7 +2577,6 @@ static int __init cs4297a_init(void)
84791 {
84792 struct cs4297a_state *s;
84793 u32 pwr, id;
84794 - mm_segment_t fs;
84795 int rval;
84796 #ifndef CONFIG_BCM_CS4297A_CSWARM
84797 u64 cfg;
84798 @@ -2667,22 +2666,23 @@ static int __init cs4297a_init(void)
84799 if (!rval) {
84800 char *sb1250_duart_present;
84801
84802 +#if 0
84803 + mm_segment_t fs;
84804 fs = get_fs();
84805 set_fs(KERNEL_DS);
84806 -#if 0
84807 val = SOUND_MASK_LINE;
84808 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84809 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84810 val = initvol[i].vol;
84811 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84812 }
84813 + set_fs(fs);
84814 // cs4297a_write_ac97(s, 0x18, 0x0808);
84815 #else
84816 // cs4297a_write_ac97(s, 0x5e, 0x180);
84817 cs4297a_write_ac97(s, 0x02, 0x0808);
84818 cs4297a_write_ac97(s, 0x18, 0x0808);
84819 #endif
84820 - set_fs(fs);
84821
84822 list_add(&s->list, &cs4297a_devs);
84823
84824 diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
84825 index 78288db..0406809 100644
84826 --- a/sound/pci/ac97/ac97_codec.c
84827 +++ b/sound/pci/ac97/ac97_codec.c
84828 @@ -1952,7 +1952,7 @@ static int snd_ac97_dev_disconnect(struct snd_device *device)
84829 }
84830
84831 /* build_ops to do nothing */
84832 -static struct snd_ac97_build_ops null_build_ops;
84833 +static const struct snd_ac97_build_ops null_build_ops;
84834
84835 #ifdef CONFIG_SND_AC97_POWER_SAVE
84836 static void do_update_power(struct work_struct *work)
84837 diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
84838 index eeb2e23..82bf625 100644
84839 --- a/sound/pci/ac97/ac97_patch.c
84840 +++ b/sound/pci/ac97/ac97_patch.c
84841 @@ -371,7 +371,7 @@ static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
84842 return 0;
84843 }
84844
84845 -static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
84846 +static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
84847 .build_spdif = patch_yamaha_ymf743_build_spdif,
84848 .build_3d = patch_yamaha_ymf7x3_3d,
84849 };
84850 @@ -455,7 +455,7 @@ static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
84851 return 0;
84852 }
84853
84854 -static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
84855 +static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
84856 .build_3d = patch_yamaha_ymf7x3_3d,
84857 .build_post_spdif = patch_yamaha_ymf753_post_spdif
84858 };
84859 @@ -502,7 +502,7 @@ static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
84860 return 0;
84861 }
84862
84863 -static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
84864 +static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
84865 .build_specific = patch_wolfson_wm9703_specific,
84866 };
84867
84868 @@ -533,7 +533,7 @@ static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
84869 return 0;
84870 }
84871
84872 -static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
84873 +static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
84874 .build_specific = patch_wolfson_wm9704_specific,
84875 };
84876
84877 @@ -555,7 +555,7 @@ static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
84878 return 0;
84879 }
84880
84881 -static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
84882 +static const struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
84883 .build_specific = patch_wolfson_wm9705_specific,
84884 };
84885
84886 @@ -692,7 +692,7 @@ static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
84887 return 0;
84888 }
84889
84890 -static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
84891 +static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
84892 .build_specific = patch_wolfson_wm9711_specific,
84893 };
84894
84895 @@ -886,7 +886,7 @@ static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
84896 }
84897 #endif
84898
84899 -static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
84900 +static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
84901 .build_specific = patch_wolfson_wm9713_specific,
84902 .build_3d = patch_wolfson_wm9713_3d,
84903 #ifdef CONFIG_PM
84904 @@ -991,7 +991,7 @@ static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
84905 return 0;
84906 }
84907
84908 -static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
84909 +static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
84910 .build_3d = patch_sigmatel_stac9700_3d,
84911 .build_specific = patch_sigmatel_stac97xx_specific
84912 };
84913 @@ -1038,7 +1038,7 @@ static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
84914 return patch_sigmatel_stac97xx_specific(ac97);
84915 }
84916
84917 -static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
84918 +static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
84919 .build_3d = patch_sigmatel_stac9708_3d,
84920 .build_specific = patch_sigmatel_stac9708_specific
84921 };
84922 @@ -1267,7 +1267,7 @@ static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
84923 return 0;
84924 }
84925
84926 -static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
84927 +static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
84928 .build_3d = patch_sigmatel_stac9700_3d,
84929 .build_specific = patch_sigmatel_stac9758_specific
84930 };
84931 @@ -1342,7 +1342,7 @@ static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
84932 return 0;
84933 }
84934
84935 -static struct snd_ac97_build_ops patch_cirrus_ops = {
84936 +static const struct snd_ac97_build_ops patch_cirrus_ops = {
84937 .build_spdif = patch_cirrus_build_spdif
84938 };
84939
84940 @@ -1399,7 +1399,7 @@ static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
84941 return 0;
84942 }
84943
84944 -static struct snd_ac97_build_ops patch_conexant_ops = {
84945 +static const struct snd_ac97_build_ops patch_conexant_ops = {
84946 .build_spdif = patch_conexant_build_spdif
84947 };
84948
84949 @@ -1575,7 +1575,7 @@ static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int
84950 }
84951 }
84952
84953 -static struct snd_ac97_build_ops patch_ad1881_build_ops = {
84954 +static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
84955 #ifdef CONFIG_PM
84956 .resume = ad18xx_resume
84957 #endif
84958 @@ -1662,7 +1662,7 @@ static int patch_ad1885_specific(struct snd_ac97 * ac97)
84959 return 0;
84960 }
84961
84962 -static struct snd_ac97_build_ops patch_ad1885_build_ops = {
84963 +static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
84964 .build_specific = &patch_ad1885_specific,
84965 #ifdef CONFIG_PM
84966 .resume = ad18xx_resume
84967 @@ -1689,7 +1689,7 @@ static int patch_ad1886_specific(struct snd_ac97 * ac97)
84968 return 0;
84969 }
84970
84971 -static struct snd_ac97_build_ops patch_ad1886_build_ops = {
84972 +static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
84973 .build_specific = &patch_ad1886_specific,
84974 #ifdef CONFIG_PM
84975 .resume = ad18xx_resume
84976 @@ -1896,7 +1896,7 @@ static int patch_ad1981a_specific(struct snd_ac97 * ac97)
84977 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
84978 }
84979
84980 -static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
84981 +static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
84982 .build_post_spdif = patch_ad198x_post_spdif,
84983 .build_specific = patch_ad1981a_specific,
84984 #ifdef CONFIG_PM
84985 @@ -1952,7 +1952,7 @@ static int patch_ad1981b_specific(struct snd_ac97 *ac97)
84986 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
84987 }
84988
84989 -static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
84990 +static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
84991 .build_post_spdif = patch_ad198x_post_spdif,
84992 .build_specific = patch_ad1981b_specific,
84993 #ifdef CONFIG_PM
84994 @@ -2091,7 +2091,7 @@ static int patch_ad1888_specific(struct snd_ac97 *ac97)
84995 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
84996 }
84997
84998 -static struct snd_ac97_build_ops patch_ad1888_build_ops = {
84999 +static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
85000 .build_post_spdif = patch_ad198x_post_spdif,
85001 .build_specific = patch_ad1888_specific,
85002 #ifdef CONFIG_PM
85003 @@ -2140,7 +2140,7 @@ static int patch_ad1980_specific(struct snd_ac97 *ac97)
85004 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
85005 }
85006
85007 -static struct snd_ac97_build_ops patch_ad1980_build_ops = {
85008 +static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
85009 .build_post_spdif = patch_ad198x_post_spdif,
85010 .build_specific = patch_ad1980_specific,
85011 #ifdef CONFIG_PM
85012 @@ -2255,7 +2255,7 @@ static int patch_ad1985_specific(struct snd_ac97 *ac97)
85013 ARRAY_SIZE(snd_ac97_ad1985_controls));
85014 }
85015
85016 -static struct snd_ac97_build_ops patch_ad1985_build_ops = {
85017 +static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
85018 .build_post_spdif = patch_ad198x_post_spdif,
85019 .build_specific = patch_ad1985_specific,
85020 #ifdef CONFIG_PM
85021 @@ -2547,7 +2547,7 @@ static int patch_ad1986_specific(struct snd_ac97 *ac97)
85022 ARRAY_SIZE(snd_ac97_ad1985_controls));
85023 }
85024
85025 -static struct snd_ac97_build_ops patch_ad1986_build_ops = {
85026 +static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
85027 .build_post_spdif = patch_ad198x_post_spdif,
85028 .build_specific = patch_ad1986_specific,
85029 #ifdef CONFIG_PM
85030 @@ -2652,7 +2652,7 @@ static int patch_alc650_specific(struct snd_ac97 * ac97)
85031 return 0;
85032 }
85033
85034 -static struct snd_ac97_build_ops patch_alc650_ops = {
85035 +static const struct snd_ac97_build_ops patch_alc650_ops = {
85036 .build_specific = patch_alc650_specific,
85037 .update_jacks = alc650_update_jacks
85038 };
85039 @@ -2804,7 +2804,7 @@ static int patch_alc655_specific(struct snd_ac97 * ac97)
85040 return 0;
85041 }
85042
85043 -static struct snd_ac97_build_ops patch_alc655_ops = {
85044 +static const struct snd_ac97_build_ops patch_alc655_ops = {
85045 .build_specific = patch_alc655_specific,
85046 .update_jacks = alc655_update_jacks
85047 };
85048 @@ -2916,7 +2916,7 @@ static int patch_alc850_specific(struct snd_ac97 *ac97)
85049 return 0;
85050 }
85051
85052 -static struct snd_ac97_build_ops patch_alc850_ops = {
85053 +static const struct snd_ac97_build_ops patch_alc850_ops = {
85054 .build_specific = patch_alc850_specific,
85055 .update_jacks = alc850_update_jacks
85056 };
85057 @@ -2978,7 +2978,7 @@ static int patch_cm9738_specific(struct snd_ac97 * ac97)
85058 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
85059 }
85060
85061 -static struct snd_ac97_build_ops patch_cm9738_ops = {
85062 +static const struct snd_ac97_build_ops patch_cm9738_ops = {
85063 .build_specific = patch_cm9738_specific,
85064 .update_jacks = cm9738_update_jacks
85065 };
85066 @@ -3069,7 +3069,7 @@ static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
85067 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
85068 }
85069
85070 -static struct snd_ac97_build_ops patch_cm9739_ops = {
85071 +static const struct snd_ac97_build_ops patch_cm9739_ops = {
85072 .build_specific = patch_cm9739_specific,
85073 .build_post_spdif = patch_cm9739_post_spdif,
85074 .update_jacks = cm9739_update_jacks
85075 @@ -3243,7 +3243,7 @@ static int patch_cm9761_specific(struct snd_ac97 * ac97)
85076 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
85077 }
85078
85079 -static struct snd_ac97_build_ops patch_cm9761_ops = {
85080 +static const struct snd_ac97_build_ops patch_cm9761_ops = {
85081 .build_specific = patch_cm9761_specific,
85082 .build_post_spdif = patch_cm9761_post_spdif,
85083 .update_jacks = cm9761_update_jacks
85084 @@ -3339,7 +3339,7 @@ static int patch_cm9780_specific(struct snd_ac97 *ac97)
85085 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
85086 }
85087
85088 -static struct snd_ac97_build_ops patch_cm9780_ops = {
85089 +static const struct snd_ac97_build_ops patch_cm9780_ops = {
85090 .build_specific = patch_cm9780_specific,
85091 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
85092 };
85093 @@ -3459,7 +3459,7 @@ static int patch_vt1616_specific(struct snd_ac97 * ac97)
85094 return 0;
85095 }
85096
85097 -static struct snd_ac97_build_ops patch_vt1616_ops = {
85098 +static const struct snd_ac97_build_ops patch_vt1616_ops = {
85099 .build_specific = patch_vt1616_specific
85100 };
85101
85102 @@ -3813,7 +3813,7 @@ static int patch_it2646_specific(struct snd_ac97 * ac97)
85103 return 0;
85104 }
85105
85106 -static struct snd_ac97_build_ops patch_it2646_ops = {
85107 +static const struct snd_ac97_build_ops patch_it2646_ops = {
85108 .build_specific = patch_it2646_specific,
85109 .update_jacks = it2646_update_jacks
85110 };
85111 @@ -3847,7 +3847,7 @@ static int patch_si3036_specific(struct snd_ac97 * ac97)
85112 return 0;
85113 }
85114
85115 -static struct snd_ac97_build_ops patch_si3036_ops = {
85116 +static const struct snd_ac97_build_ops patch_si3036_ops = {
85117 .build_specific = patch_si3036_specific,
85118 };
85119
85120 @@ -3914,7 +3914,7 @@ static int patch_ucb1400_specific(struct snd_ac97 * ac97)
85121 return 0;
85122 }
85123
85124 -static struct snd_ac97_build_ops patch_ucb1400_ops = {
85125 +static const struct snd_ac97_build_ops patch_ucb1400_ops = {
85126 .build_specific = patch_ucb1400_specific,
85127 };
85128
85129 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
85130 index 99552fb..4dcc2c5 100644
85131 --- a/sound/pci/hda/hda_codec.h
85132 +++ b/sound/pci/hda/hda_codec.h
85133 @@ -580,7 +580,7 @@ struct hda_bus_ops {
85134 /* notify power-up/down from codec to controller */
85135 void (*pm_notify)(struct hda_bus *bus);
85136 #endif
85137 -};
85138 +} __no_const;
85139
85140 /* template to pass to the bus constructor */
85141 struct hda_bus_template {
85142 @@ -675,6 +675,7 @@ struct hda_codec_ops {
85143 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
85144 #endif
85145 };
85146 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
85147
85148 /* record for amp information cache */
85149 struct hda_cache_head {
85150 @@ -705,7 +706,7 @@ struct hda_pcm_ops {
85151 struct snd_pcm_substream *substream);
85152 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
85153 struct snd_pcm_substream *substream);
85154 -};
85155 +} __no_const;
85156
85157 /* PCM information for each substream */
85158 struct hda_pcm_stream {
85159 @@ -760,7 +761,7 @@ struct hda_codec {
85160 const char *modelname; /* model name for preset */
85161
85162 /* set by patch */
85163 - struct hda_codec_ops patch_ops;
85164 + hda_codec_ops_no_const patch_ops;
85165
85166 /* PCM to create, set by patch_ops.build_pcms callback */
85167 unsigned int num_pcms;
85168 diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
85169 index fb684f0..2b11cea 100644
85170 --- a/sound/pci/hda/patch_atihdmi.c
85171 +++ b/sound/pci/hda/patch_atihdmi.c
85172 @@ -177,7 +177,7 @@ static int patch_atihdmi(struct hda_codec *codec)
85173 */
85174 spec->multiout.dig_out_nid = CVT_NID;
85175
85176 - codec->patch_ops = atihdmi_patch_ops;
85177 + memcpy((void *)&codec->patch_ops, &atihdmi_patch_ops, sizeof(atihdmi_patch_ops));
85178
85179 return 0;
85180 }
85181 diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
85182 index 7c23016..c5bfdd7 100644
85183 --- a/sound/pci/hda/patch_intelhdmi.c
85184 +++ b/sound/pci/hda/patch_intelhdmi.c
85185 @@ -511,10 +511,10 @@ static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
85186 cp_ready);
85187
85188 /* TODO */
85189 - if (cp_state)
85190 - ;
85191 - if (cp_ready)
85192 - ;
85193 + if (cp_state) {
85194 + }
85195 + if (cp_ready) {
85196 + }
85197 }
85198
85199
85200 @@ -656,7 +656,7 @@ static int do_patch_intel_hdmi(struct hda_codec *codec)
85201 spec->multiout.dig_out_nid = cvt_nid;
85202
85203 codec->spec = spec;
85204 - codec->patch_ops = intel_hdmi_patch_ops;
85205 + memcpy((void *)&codec->patch_ops, &intel_hdmi_patch_ops, sizeof(intel_hdmi_patch_ops));
85206
85207 snd_hda_eld_proc_new(codec, &spec->sink_eld);
85208
85209 diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
85210 index 6afdab0..68ed352 100644
85211 --- a/sound/pci/hda/patch_nvhdmi.c
85212 +++ b/sound/pci/hda/patch_nvhdmi.c
85213 @@ -367,7 +367,7 @@ static int patch_nvhdmi_8ch(struct hda_codec *codec)
85214 spec->multiout.max_channels = 8;
85215 spec->multiout.dig_out_nid = Nv_Master_Convert_nid;
85216
85217 - codec->patch_ops = nvhdmi_patch_ops_8ch;
85218 + memcpy((void *)&codec->patch_ops, &nvhdmi_patch_ops_8ch, sizeof(nvhdmi_patch_ops_8ch));
85219
85220 return 0;
85221 }
85222 @@ -386,7 +386,7 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
85223 spec->multiout.max_channels = 2;
85224 spec->multiout.dig_out_nid = Nv_Master_Convert_nid;
85225
85226 - codec->patch_ops = nvhdmi_patch_ops_2ch;
85227 + memcpy((void *)&codec->patch_ops, &nvhdmi_patch_ops_2ch, sizeof(nvhdmi_patch_ops_2ch));
85228
85229 return 0;
85230 }
85231 diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
85232 index 01da10b..01bd71f 100644
85233 --- a/sound/pci/hda/patch_sigmatel.c
85234 +++ b/sound/pci/hda/patch_sigmatel.c
85235 @@ -5220,7 +5220,7 @@ again:
85236 snd_hda_codec_write_cache(codec, nid, 0,
85237 AC_VERB_SET_CONNECT_SEL, num_dacs);
85238
85239 - codec->patch_ops = stac92xx_patch_ops;
85240 + memcpy((void *)&codec->patch_ops, &stac92xx_patch_ops, sizeof(stac92xx_patch_ops));
85241
85242 codec->proc_widget_hook = stac92hd_proc_hook;
85243
85244 @@ -5294,7 +5294,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
85245 return -ENOMEM;
85246
85247 codec->spec = spec;
85248 - codec->patch_ops = stac92xx_patch_ops;
85249 + memcpy((void *)&codec->patch_ops, &stac92xx_patch_ops, sizeof(stac92xx_patch_ops));
85250 spec->num_pins = STAC92HD71BXX_NUM_PINS;
85251 switch (codec->vendor_id) {
85252 case 0x111d76b6:
85253 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
85254 index d063149..01599a4 100644
85255 --- a/sound/pci/ice1712/ice1712.h
85256 +++ b/sound/pci/ice1712/ice1712.h
85257 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
85258 unsigned int mask_flags; /* total mask bits */
85259 struct snd_akm4xxx_ops {
85260 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
85261 - } ops;
85262 + } __no_const ops;
85263 };
85264
85265 struct snd_ice1712_spdif {
85266 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
85267 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
85268 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
85269 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
85270 - } ops;
85271 + } __no_const ops;
85272 };
85273
85274
85275 diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
85276 index 9e7d12e..3e3bc64 100644
85277 --- a/sound/pci/intel8x0m.c
85278 +++ b/sound/pci/intel8x0m.c
85279 @@ -1264,7 +1264,7 @@ static struct shortname_table {
85280 { 0x5455, "ALi M5455" },
85281 { 0x746d, "AMD AMD8111" },
85282 #endif
85283 - { 0 },
85284 + { 0, },
85285 };
85286
85287 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
85288 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
85289 index 5518371..45cf7ac 100644
85290 --- a/sound/pci/ymfpci/ymfpci_main.c
85291 +++ b/sound/pci/ymfpci/ymfpci_main.c
85292 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
85293 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
85294 break;
85295 }
85296 - if (atomic_read(&chip->interrupt_sleep_count)) {
85297 - atomic_set(&chip->interrupt_sleep_count, 0);
85298 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85299 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85300 wake_up(&chip->interrupt_sleep);
85301 }
85302 __end:
85303 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
85304 continue;
85305 init_waitqueue_entry(&wait, current);
85306 add_wait_queue(&chip->interrupt_sleep, &wait);
85307 - atomic_inc(&chip->interrupt_sleep_count);
85308 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
85309 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
85310 remove_wait_queue(&chip->interrupt_sleep, &wait);
85311 }
85312 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
85313 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
85314 spin_unlock(&chip->reg_lock);
85315
85316 - if (atomic_read(&chip->interrupt_sleep_count)) {
85317 - atomic_set(&chip->interrupt_sleep_count, 0);
85318 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85319 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85320 wake_up(&chip->interrupt_sleep);
85321 }
85322 }
85323 @@ -2369,7 +2369,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
85324 spin_lock_init(&chip->reg_lock);
85325 spin_lock_init(&chip->voice_lock);
85326 init_waitqueue_head(&chip->interrupt_sleep);
85327 - atomic_set(&chip->interrupt_sleep_count, 0);
85328 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85329 chip->card = card;
85330 chip->pci = pci;
85331 chip->irq = -1;
85332 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
85333 index 0a1b2f6..776bb19 100644
85334 --- a/sound/soc/soc-core.c
85335 +++ b/sound/soc/soc-core.c
85336 @@ -609,7 +609,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
85337 }
85338
85339 /* ASoC PCM operations */
85340 -static struct snd_pcm_ops soc_pcm_ops = {
85341 +static snd_pcm_ops_no_const soc_pcm_ops = {
85342 .open = soc_pcm_open,
85343 .close = soc_codec_close,
85344 .hw_params = soc_pcm_hw_params,
85345 diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
85346 index 79633ea..9732e90 100644
85347 --- a/sound/usb/usbaudio.c
85348 +++ b/sound/usb/usbaudio.c
85349 @@ -963,12 +963,12 @@ static int snd_usb_pcm_playback_trigger(struct snd_pcm_substream *substream,
85350 switch (cmd) {
85351 case SNDRV_PCM_TRIGGER_START:
85352 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
85353 - subs->ops.prepare = prepare_playback_urb;
85354 + *(void **)&subs->ops.prepare = prepare_playback_urb;
85355 return 0;
85356 case SNDRV_PCM_TRIGGER_STOP:
85357 return deactivate_urbs(subs, 0, 0);
85358 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
85359 - subs->ops.prepare = prepare_nodata_playback_urb;
85360 + *(void **)&subs->ops.prepare = prepare_nodata_playback_urb;
85361 return 0;
85362 default:
85363 return -EINVAL;
85364 @@ -985,15 +985,15 @@ static int snd_usb_pcm_capture_trigger(struct snd_pcm_substream *substream,
85365
85366 switch (cmd) {
85367 case SNDRV_PCM_TRIGGER_START:
85368 - subs->ops.retire = retire_capture_urb;
85369 + *(void **)&subs->ops.retire = retire_capture_urb;
85370 return start_urbs(subs, substream->runtime);
85371 case SNDRV_PCM_TRIGGER_STOP:
85372 return deactivate_urbs(subs, 0, 0);
85373 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
85374 - subs->ops.retire = retire_paused_capture_urb;
85375 + *(void **)&subs->ops.retire = retire_paused_capture_urb;
85376 return 0;
85377 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
85378 - subs->ops.retire = retire_capture_urb;
85379 + *(void **)&subs->ops.retire = retire_capture_urb;
85380 return 0;
85381 default:
85382 return -EINVAL;
85383 @@ -1542,7 +1542,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
85384 /* for playback, submit the URBs now; otherwise, the first hwptr_done
85385 * updates for all URBs would happen at the same time when starting */
85386 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
85387 - subs->ops.prepare = prepare_nodata_playback_urb;
85388 + *(void **)&subs->ops.prepare = prepare_nodata_playback_urb;
85389 return start_urbs(subs, runtime);
85390 } else
85391 return 0;
85392 @@ -2228,14 +2228,14 @@ static void init_substream(struct snd_usb_stream *as, int stream, struct audiofo
85393 subs->direction = stream;
85394 subs->dev = as->chip->dev;
85395 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) {
85396 - subs->ops = audio_urb_ops[stream];
85397 + memcpy((void *)&subs->ops, &audio_urb_ops[stream], sizeof(subs->ops));
85398 } else {
85399 - subs->ops = audio_urb_ops_high_speed[stream];
85400 + memcpy((void *)&subs->ops, &audio_urb_ops_high_speed[stream], sizeof(subs->ops));
85401 switch (as->chip->usb_id) {
85402 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
85403 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
85404 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
85405 - subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
85406 + *(void **)&subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
85407 break;
85408 }
85409 }
85410 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
85411 new file mode 100644
85412 index 0000000..b044b80
85413 --- /dev/null
85414 +++ b/tools/gcc/Makefile
85415 @@ -0,0 +1,21 @@
85416 +#CC := gcc
85417 +#PLUGIN_SOURCE_FILES := pax_plugin.c
85418 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
85419 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
85420 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
85421 +
85422 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
85423 +
85424 +hostlibs-y := constify_plugin.so
85425 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
85426 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
85427 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
85428 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
85429 +
85430 +always := $(hostlibs-y)
85431 +
85432 +constify_plugin-objs := constify_plugin.o
85433 +stackleak_plugin-objs := stackleak_plugin.o
85434 +kallocstat_plugin-objs := kallocstat_plugin.o
85435 +kernexec_plugin-objs := kernexec_plugin.o
85436 +checker_plugin-objs := checker_plugin.o
85437 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
85438 new file mode 100644
85439 index 0000000..d41b5af
85440 --- /dev/null
85441 +++ b/tools/gcc/checker_plugin.c
85442 @@ -0,0 +1,171 @@
85443 +/*
85444 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85445 + * Licensed under the GPL v2
85446 + *
85447 + * Note: the choice of the license means that the compilation process is
85448 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85449 + * but for the kernel it doesn't matter since it doesn't link against
85450 + * any of the gcc libraries
85451 + *
85452 + * gcc plugin to implement various sparse (source code checker) features
85453 + *
85454 + * TODO:
85455 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
85456 + *
85457 + * BUGS:
85458 + * - none known
85459 + */
85460 +#include "gcc-plugin.h"
85461 +#include "config.h"
85462 +#include "system.h"
85463 +#include "coretypes.h"
85464 +#include "tree.h"
85465 +#include "tree-pass.h"
85466 +#include "flags.h"
85467 +#include "intl.h"
85468 +#include "toplev.h"
85469 +#include "plugin.h"
85470 +//#include "expr.h" where are you...
85471 +#include "diagnostic.h"
85472 +#include "plugin-version.h"
85473 +#include "tm.h"
85474 +#include "function.h"
85475 +#include "basic-block.h"
85476 +#include "gimple.h"
85477 +#include "rtl.h"
85478 +#include "emit-rtl.h"
85479 +#include "tree-flow.h"
85480 +#include "target.h"
85481 +
85482 +extern void c_register_addr_space (const char *str, addr_space_t as);
85483 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
85484 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
85485 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
85486 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
85487 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
85488 +
85489 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85490 +extern rtx emit_move_insn(rtx x, rtx y);
85491 +
85492 +int plugin_is_GPL_compatible;
85493 +
85494 +static struct plugin_info checker_plugin_info = {
85495 + .version = "201111150100",
85496 +};
85497 +
85498 +#define ADDR_SPACE_KERNEL 0
85499 +#define ADDR_SPACE_FORCE_KERNEL 1
85500 +#define ADDR_SPACE_USER 2
85501 +#define ADDR_SPACE_FORCE_USER 3
85502 +#define ADDR_SPACE_IOMEM 0
85503 +#define ADDR_SPACE_FORCE_IOMEM 0
85504 +#define ADDR_SPACE_PERCPU 0
85505 +#define ADDR_SPACE_FORCE_PERCPU 0
85506 +#define ADDR_SPACE_RCU 0
85507 +#define ADDR_SPACE_FORCE_RCU 0
85508 +
85509 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
85510 +{
85511 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
85512 +}
85513 +
85514 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
85515 +{
85516 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
85517 +}
85518 +
85519 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
85520 +{
85521 + return default_addr_space_valid_pointer_mode(mode, as);
85522 +}
85523 +
85524 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
85525 +{
85526 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
85527 +}
85528 +
85529 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
85530 +{
85531 + return default_addr_space_legitimize_address(x, oldx, mode, as);
85532 +}
85533 +
85534 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
85535 +{
85536 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
85537 + return true;
85538 +
85539 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
85540 + return true;
85541 +
85542 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
85543 + return true;
85544 +
85545 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
85546 + return true;
85547 +
85548 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
85549 + return true;
85550 +
85551 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
85552 + return true;
85553 +
85554 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
85555 + return true;
85556 +
85557 + return subset == superset;
85558 +}
85559 +
85560 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
85561 +{
85562 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
85563 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
85564 +
85565 + return op;
85566 +}
85567 +
85568 +static void register_checker_address_spaces(void *event_data, void *data)
85569 +{
85570 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
85571 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
85572 + c_register_addr_space("__user", ADDR_SPACE_USER);
85573 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
85574 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
85575 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
85576 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
85577 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
85578 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
85579 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
85580 +
85581 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
85582 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
85583 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
85584 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
85585 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
85586 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
85587 + targetm.addr_space.convert = checker_addr_space_convert;
85588 +}
85589 +
85590 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85591 +{
85592 + const char * const plugin_name = plugin_info->base_name;
85593 + const int argc = plugin_info->argc;
85594 + const struct plugin_argument * const argv = plugin_info->argv;
85595 + int i;
85596 +
85597 + if (!plugin_default_version_check(version, &gcc_version)) {
85598 + error(G_("incompatible gcc/plugin versions"));
85599 + return 1;
85600 + }
85601 +
85602 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
85603 +
85604 + for (i = 0; i < argc; ++i)
85605 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85606 +
85607 + if (TARGET_64BIT == 0)
85608 + return 0;
85609 +
85610 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
85611 +
85612 + return 0;
85613 +}
85614 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
85615 new file mode 100644
85616 index 0000000..704a564
85617 --- /dev/null
85618 +++ b/tools/gcc/constify_plugin.c
85619 @@ -0,0 +1,303 @@
85620 +/*
85621 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
85622 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
85623 + * Licensed under the GPL v2, or (at your option) v3
85624 + *
85625 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
85626 + *
85627 + * Homepage:
85628 + * http://www.grsecurity.net/~ephox/const_plugin/
85629 + *
85630 + * Usage:
85631 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
85632 + * $ gcc -fplugin=constify_plugin.so test.c -O2
85633 + */
85634 +
85635 +#include "gcc-plugin.h"
85636 +#include "config.h"
85637 +#include "system.h"
85638 +#include "coretypes.h"
85639 +#include "tree.h"
85640 +#include "tree-pass.h"
85641 +#include "flags.h"
85642 +#include "intl.h"
85643 +#include "toplev.h"
85644 +#include "plugin.h"
85645 +#include "diagnostic.h"
85646 +#include "plugin-version.h"
85647 +#include "tm.h"
85648 +#include "function.h"
85649 +#include "basic-block.h"
85650 +#include "gimple.h"
85651 +#include "rtl.h"
85652 +#include "emit-rtl.h"
85653 +#include "tree-flow.h"
85654 +
85655 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
85656 +
85657 +int plugin_is_GPL_compatible;
85658 +
85659 +static struct plugin_info const_plugin_info = {
85660 + .version = "201111150100",
85661 + .help = "no-constify\tturn off constification\n",
85662 +};
85663 +
85664 +static void constify_type(tree type);
85665 +static bool walk_struct(tree node);
85666 +
85667 +static tree deconstify_type(tree old_type)
85668 +{
85669 + tree new_type, field;
85670 +
85671 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
85672 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
85673 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
85674 + DECL_FIELD_CONTEXT(field) = new_type;
85675 + TYPE_READONLY(new_type) = 0;
85676 + C_TYPE_FIELDS_READONLY(new_type) = 0;
85677 + return new_type;
85678 +}
85679 +
85680 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85681 +{
85682 + tree type;
85683 +
85684 + *no_add_attrs = true;
85685 + if (TREE_CODE(*node) == FUNCTION_DECL) {
85686 + error("%qE attribute does not apply to functions", name);
85687 + return NULL_TREE;
85688 + }
85689 +
85690 + if (TREE_CODE(*node) == VAR_DECL) {
85691 + error("%qE attribute does not apply to variables", name);
85692 + return NULL_TREE;
85693 + }
85694 +
85695 + if (TYPE_P(*node)) {
85696 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
85697 + *no_add_attrs = false;
85698 + else
85699 + error("%qE attribute applies to struct and union types only", name);
85700 + return NULL_TREE;
85701 + }
85702 +
85703 + type = TREE_TYPE(*node);
85704 +
85705 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
85706 + error("%qE attribute applies to struct and union types only", name);
85707 + return NULL_TREE;
85708 + }
85709 +
85710 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
85711 + error("%qE attribute is already applied to the type", name);
85712 + return NULL_TREE;
85713 + }
85714 +
85715 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
85716 + error("%qE attribute used on type that is not constified", name);
85717 + return NULL_TREE;
85718 + }
85719 +
85720 + if (TREE_CODE(*node) == TYPE_DECL) {
85721 + TREE_TYPE(*node) = deconstify_type(type);
85722 + TREE_READONLY(*node) = 0;
85723 + return NULL_TREE;
85724 + }
85725 +
85726 + return NULL_TREE;
85727 +}
85728 +
85729 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85730 +{
85731 + *no_add_attrs = true;
85732 + if (!TYPE_P(*node)) {
85733 + error("%qE attribute applies to types only", name);
85734 + return NULL_TREE;
85735 + }
85736 +
85737 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
85738 + error("%qE attribute applies to struct and union types only", name);
85739 + return NULL_TREE;
85740 + }
85741 +
85742 + *no_add_attrs = false;
85743 + constify_type(*node);
85744 + return NULL_TREE;
85745 +}
85746 +
85747 +static struct attribute_spec no_const_attr = {
85748 + .name = "no_const",
85749 + .min_length = 0,
85750 + .max_length = 0,
85751 + .decl_required = false,
85752 + .type_required = false,
85753 + .function_type_required = false,
85754 + .handler = handle_no_const_attribute,
85755 +#if BUILDING_GCC_VERSION >= 4007
85756 + .affects_type_identity = true
85757 +#endif
85758 +};
85759 +
85760 +static struct attribute_spec do_const_attr = {
85761 + .name = "do_const",
85762 + .min_length = 0,
85763 + .max_length = 0,
85764 + .decl_required = false,
85765 + .type_required = false,
85766 + .function_type_required = false,
85767 + .handler = handle_do_const_attribute,
85768 +#if BUILDING_GCC_VERSION >= 4007
85769 + .affects_type_identity = true
85770 +#endif
85771 +};
85772 +
85773 +static void register_attributes(void *event_data, void *data)
85774 +{
85775 + register_attribute(&no_const_attr);
85776 + register_attribute(&do_const_attr);
85777 +}
85778 +
85779 +static void constify_type(tree type)
85780 +{
85781 + TYPE_READONLY(type) = 1;
85782 + C_TYPE_FIELDS_READONLY(type) = 1;
85783 +}
85784 +
85785 +static bool is_fptr(tree field)
85786 +{
85787 + tree ptr = TREE_TYPE(field);
85788 +
85789 + if (TREE_CODE(ptr) != POINTER_TYPE)
85790 + return false;
85791 +
85792 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
85793 +}
85794 +
85795 +static bool walk_struct(tree node)
85796 +{
85797 + tree field;
85798 +
85799 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
85800 + return false;
85801 +
85802 + if (TYPE_FIELDS(node) == NULL_TREE)
85803 + return false;
85804 +
85805 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
85806 + tree type = TREE_TYPE(field);
85807 + enum tree_code code = TREE_CODE(type);
85808 + if (code == RECORD_TYPE || code == UNION_TYPE) {
85809 + if (!(walk_struct(type)))
85810 + return false;
85811 + } else if (!is_fptr(field) && !TREE_READONLY(field))
85812 + return false;
85813 + }
85814 + return true;
85815 +}
85816 +
85817 +static void finish_type(void *event_data, void *data)
85818 +{
85819 + tree type = (tree)event_data;
85820 +
85821 + if (type == NULL_TREE)
85822 + return;
85823 +
85824 + if (TYPE_READONLY(type))
85825 + return;
85826 +
85827 + if (walk_struct(type))
85828 + constify_type(type);
85829 +}
85830 +
85831 +static unsigned int check_local_variables(void);
85832 +
85833 +struct gimple_opt_pass pass_local_variable = {
85834 + {
85835 + .type = GIMPLE_PASS,
85836 + .name = "check_local_variables",
85837 + .gate = NULL,
85838 + .execute = check_local_variables,
85839 + .sub = NULL,
85840 + .next = NULL,
85841 + .static_pass_number = 0,
85842 + .tv_id = TV_NONE,
85843 + .properties_required = 0,
85844 + .properties_provided = 0,
85845 + .properties_destroyed = 0,
85846 + .todo_flags_start = 0,
85847 + .todo_flags_finish = 0
85848 + }
85849 +};
85850 +
85851 +static unsigned int check_local_variables(void)
85852 +{
85853 + tree var;
85854 + referenced_var_iterator rvi;
85855 +
85856 +#if BUILDING_GCC_VERSION == 4005
85857 + FOR_EACH_REFERENCED_VAR(var, rvi) {
85858 +#else
85859 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
85860 +#endif
85861 + tree type = TREE_TYPE(var);
85862 +
85863 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
85864 + continue;
85865 +
85866 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
85867 + continue;
85868 +
85869 + if (!TYPE_READONLY(type))
85870 + continue;
85871 +
85872 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
85873 +// continue;
85874 +
85875 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
85876 +// continue;
85877 +
85878 + if (walk_struct(type)) {
85879 + error("constified variable %qE cannot be local", var);
85880 + return 1;
85881 + }
85882 + }
85883 + return 0;
85884 +}
85885 +
85886 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85887 +{
85888 + const char * const plugin_name = plugin_info->base_name;
85889 + const int argc = plugin_info->argc;
85890 + const struct plugin_argument * const argv = plugin_info->argv;
85891 + int i;
85892 + bool constify = true;
85893 +
85894 + struct register_pass_info local_variable_pass_info = {
85895 + .pass = &pass_local_variable.pass,
85896 + .reference_pass_name = "*referenced_vars",
85897 + .ref_pass_instance_number = 0,
85898 + .pos_op = PASS_POS_INSERT_AFTER
85899 + };
85900 +
85901 + if (!plugin_default_version_check(version, &gcc_version)) {
85902 + error(G_("incompatible gcc/plugin versions"));
85903 + return 1;
85904 + }
85905 +
85906 + for (i = 0; i < argc; ++i) {
85907 + if (!(strcmp(argv[i].key, "no-constify"))) {
85908 + constify = false;
85909 + continue;
85910 + }
85911 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85912 + }
85913 +
85914 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85915 + if (constify) {
85916 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85917 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85918 + }
85919 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85920 +
85921 + return 0;
85922 +}
85923 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85924 new file mode 100644
85925 index 0000000..a5eabce
85926 --- /dev/null
85927 +++ b/tools/gcc/kallocstat_plugin.c
85928 @@ -0,0 +1,167 @@
85929 +/*
85930 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85931 + * Licensed under the GPL v2
85932 + *
85933 + * Note: the choice of the license means that the compilation process is
85934 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85935 + * but for the kernel it doesn't matter since it doesn't link against
85936 + * any of the gcc libraries
85937 + *
85938 + * gcc plugin to find the distribution of k*alloc sizes
85939 + *
85940 + * TODO:
85941 + *
85942 + * BUGS:
85943 + * - none known
85944 + */
85945 +#include "gcc-plugin.h"
85946 +#include "config.h"
85947 +#include "system.h"
85948 +#include "coretypes.h"
85949 +#include "tree.h"
85950 +#include "tree-pass.h"
85951 +#include "flags.h"
85952 +#include "intl.h"
85953 +#include "toplev.h"
85954 +#include "plugin.h"
85955 +//#include "expr.h" where are you...
85956 +#include "diagnostic.h"
85957 +#include "plugin-version.h"
85958 +#include "tm.h"
85959 +#include "function.h"
85960 +#include "basic-block.h"
85961 +#include "gimple.h"
85962 +#include "rtl.h"
85963 +#include "emit-rtl.h"
85964 +
85965 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85966 +
85967 +int plugin_is_GPL_compatible;
85968 +
85969 +static const char * const kalloc_functions[] = {
85970 + "__kmalloc",
85971 + "kmalloc",
85972 + "kmalloc_large",
85973 + "kmalloc_node",
85974 + "kmalloc_order",
85975 + "kmalloc_order_trace",
85976 + "kmalloc_slab",
85977 + "kzalloc",
85978 + "kzalloc_node",
85979 +};
85980 +
85981 +static struct plugin_info kallocstat_plugin_info = {
85982 + .version = "201111150100",
85983 +};
85984 +
85985 +static unsigned int execute_kallocstat(void);
85986 +
85987 +static struct gimple_opt_pass kallocstat_pass = {
85988 + .pass = {
85989 + .type = GIMPLE_PASS,
85990 + .name = "kallocstat",
85991 + .gate = NULL,
85992 + .execute = execute_kallocstat,
85993 + .sub = NULL,
85994 + .next = NULL,
85995 + .static_pass_number = 0,
85996 + .tv_id = TV_NONE,
85997 + .properties_required = 0,
85998 + .properties_provided = 0,
85999 + .properties_destroyed = 0,
86000 + .todo_flags_start = 0,
86001 + .todo_flags_finish = 0
86002 + }
86003 +};
86004 +
86005 +static bool is_kalloc(const char *fnname)
86006 +{
86007 + size_t i;
86008 +
86009 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
86010 + if (!strcmp(fnname, kalloc_functions[i]))
86011 + return true;
86012 + return false;
86013 +}
86014 +
86015 +static unsigned int execute_kallocstat(void)
86016 +{
86017 + basic_block bb;
86018 +
86019 + // 1. loop through BBs and GIMPLE statements
86020 + FOR_EACH_BB(bb) {
86021 + gimple_stmt_iterator gsi;
86022 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86023 + // gimple match:
86024 + tree fndecl, size;
86025 + gimple call_stmt;
86026 + const char *fnname;
86027 +
86028 + // is it a call
86029 + call_stmt = gsi_stmt(gsi);
86030 + if (!is_gimple_call(call_stmt))
86031 + continue;
86032 + fndecl = gimple_call_fndecl(call_stmt);
86033 + if (fndecl == NULL_TREE)
86034 + continue;
86035 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
86036 + continue;
86037 +
86038 + // is it a call to k*alloc
86039 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
86040 + if (!is_kalloc(fnname))
86041 + continue;
86042 +
86043 + // is the size arg the result of a simple const assignment
86044 + size = gimple_call_arg(call_stmt, 0);
86045 + while (true) {
86046 + gimple def_stmt;
86047 + expanded_location xloc;
86048 + size_t size_val;
86049 +
86050 + if (TREE_CODE(size) != SSA_NAME)
86051 + break;
86052 + def_stmt = SSA_NAME_DEF_STMT(size);
86053 + if (!def_stmt || !is_gimple_assign(def_stmt))
86054 + break;
86055 + if (gimple_num_ops(def_stmt) != 2)
86056 + break;
86057 + size = gimple_assign_rhs1(def_stmt);
86058 + if (!TREE_CONSTANT(size))
86059 + continue;
86060 + xloc = expand_location(gimple_location(def_stmt));
86061 + if (!xloc.file)
86062 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
86063 + size_val = TREE_INT_CST_LOW(size);
86064 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
86065 + break;
86066 + }
86067 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86068 +//debug_tree(gimple_call_fn(call_stmt));
86069 +//print_node(stderr, "pax", fndecl, 4);
86070 + }
86071 + }
86072 +
86073 + return 0;
86074 +}
86075 +
86076 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86077 +{
86078 + const char * const plugin_name = plugin_info->base_name;
86079 + struct register_pass_info kallocstat_pass_info = {
86080 + .pass = &kallocstat_pass.pass,
86081 + .reference_pass_name = "ssa",
86082 + .ref_pass_instance_number = 0,
86083 + .pos_op = PASS_POS_INSERT_AFTER
86084 + };
86085 +
86086 + if (!plugin_default_version_check(version, &gcc_version)) {
86087 + error(G_("incompatible gcc/plugin versions"));
86088 + return 1;
86089 + }
86090 +
86091 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
86092 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
86093 +
86094 + return 0;
86095 +}
86096 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
86097 new file mode 100644
86098 index 0000000..51f747e
86099 --- /dev/null
86100 +++ b/tools/gcc/kernexec_plugin.c
86101 @@ -0,0 +1,348 @@
86102 +/*
86103 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86104 + * Licensed under the GPL v2
86105 + *
86106 + * Note: the choice of the license means that the compilation process is
86107 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86108 + * but for the kernel it doesn't matter since it doesn't link against
86109 + * any of the gcc libraries
86110 + *
86111 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
86112 + *
86113 + * TODO:
86114 + *
86115 + * BUGS:
86116 + * - none known
86117 + */
86118 +#include "gcc-plugin.h"
86119 +#include "config.h"
86120 +#include "system.h"
86121 +#include "coretypes.h"
86122 +#include "tree.h"
86123 +#include "tree-pass.h"
86124 +#include "flags.h"
86125 +#include "intl.h"
86126 +#include "toplev.h"
86127 +#include "plugin.h"
86128 +//#include "expr.h" where are you...
86129 +#include "diagnostic.h"
86130 +#include "plugin-version.h"
86131 +#include "tm.h"
86132 +#include "function.h"
86133 +#include "basic-block.h"
86134 +#include "gimple.h"
86135 +#include "rtl.h"
86136 +#include "emit-rtl.h"
86137 +#include "tree-flow.h"
86138 +
86139 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86140 +extern rtx emit_move_insn(rtx x, rtx y);
86141 +
86142 +int plugin_is_GPL_compatible;
86143 +
86144 +static struct plugin_info kernexec_plugin_info = {
86145 + .version = "201111291120",
86146 + .help = "method=[bts|or]\tinstrumentation method\n"
86147 +};
86148 +
86149 +static unsigned int execute_kernexec_fptr(void);
86150 +static unsigned int execute_kernexec_retaddr(void);
86151 +static bool kernexec_cmodel_check(void);
86152 +
86153 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator);
86154 +static void (*kernexec_instrument_retaddr)(rtx);
86155 +
86156 +static struct gimple_opt_pass kernexec_fptr_pass = {
86157 + .pass = {
86158 + .type = GIMPLE_PASS,
86159 + .name = "kernexec_fptr",
86160 + .gate = kernexec_cmodel_check,
86161 + .execute = execute_kernexec_fptr,
86162 + .sub = NULL,
86163 + .next = NULL,
86164 + .static_pass_number = 0,
86165 + .tv_id = TV_NONE,
86166 + .properties_required = 0,
86167 + .properties_provided = 0,
86168 + .properties_destroyed = 0,
86169 + .todo_flags_start = 0,
86170 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
86171 + }
86172 +};
86173 +
86174 +static struct rtl_opt_pass kernexec_retaddr_pass = {
86175 + .pass = {
86176 + .type = RTL_PASS,
86177 + .name = "kernexec_retaddr",
86178 + .gate = kernexec_cmodel_check,
86179 + .execute = execute_kernexec_retaddr,
86180 + .sub = NULL,
86181 + .next = NULL,
86182 + .static_pass_number = 0,
86183 + .tv_id = TV_NONE,
86184 + .properties_required = 0,
86185 + .properties_provided = 0,
86186 + .properties_destroyed = 0,
86187 + .todo_flags_start = 0,
86188 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
86189 + }
86190 +};
86191 +
86192 +static bool kernexec_cmodel_check(void)
86193 +{
86194 + tree section;
86195 +
86196 + if (ix86_cmodel != CM_KERNEL)
86197 + return false;
86198 +
86199 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
86200 + if (!section || !TREE_VALUE(section))
86201 + return true;
86202 +
86203 + section = TREE_VALUE(TREE_VALUE(section));
86204 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
86205 + return true;
86206 +
86207 + return false;
86208 +}
86209 +
86210 +/*
86211 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
86212 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
86213 + */
86214 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator gsi)
86215 +{
86216 + gimple assign_intptr, assign_new_fptr, call_stmt;
86217 + tree intptr, old_fptr, new_fptr, kernexec_mask;
86218 +
86219 + call_stmt = gsi_stmt(gsi);
86220 + old_fptr = gimple_call_fn(call_stmt);
86221 +
86222 + // create temporary unsigned long variable used for bitops and cast fptr to it
86223 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
86224 + add_referenced_var(intptr);
86225 + mark_sym_for_renaming(intptr);
86226 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
86227 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
86228 + update_stmt(assign_intptr);
86229 +
86230 + // apply logical or to temporary unsigned long and bitmask
86231 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
86232 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
86233 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
86234 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
86235 + update_stmt(assign_intptr);
86236 +
86237 + // cast temporary unsigned long back to a temporary fptr variable
86238 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
86239 + add_referenced_var(new_fptr);
86240 + mark_sym_for_renaming(new_fptr);
86241 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
86242 + gsi_insert_before(&gsi, assign_new_fptr, GSI_SAME_STMT);
86243 + update_stmt(assign_new_fptr);
86244 +
86245 + // replace call stmt fn with the new fptr
86246 + gimple_call_set_fn(call_stmt, new_fptr);
86247 + update_stmt(call_stmt);
86248 +}
86249 +
86250 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator gsi)
86251 +{
86252 + gimple asm_or_stmt, call_stmt;
86253 + tree old_fptr, new_fptr, input, output;
86254 + VEC(tree, gc) *inputs = NULL;
86255 + VEC(tree, gc) *outputs = NULL;
86256 +
86257 + call_stmt = gsi_stmt(gsi);
86258 + old_fptr = gimple_call_fn(call_stmt);
86259 +
86260 + // create temporary fptr variable
86261 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
86262 + add_referenced_var(new_fptr);
86263 + mark_sym_for_renaming(new_fptr);
86264 +
86265 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
86266 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
86267 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
86268 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
86269 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
86270 + VEC_safe_push(tree, gc, inputs, input);
86271 + VEC_safe_push(tree, gc, outputs, output);
86272 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
86273 + gimple_asm_set_volatile(asm_or_stmt, true);
86274 + gsi_insert_before(&gsi, asm_or_stmt, GSI_SAME_STMT);
86275 + update_stmt(asm_or_stmt);
86276 +
86277 + // replace call stmt fn with the new fptr
86278 + gimple_call_set_fn(call_stmt, new_fptr);
86279 + update_stmt(call_stmt);
86280 +}
86281 +
86282 +/*
86283 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
86284 + */
86285 +static unsigned int execute_kernexec_fptr(void)
86286 +{
86287 + basic_block bb;
86288 + gimple_stmt_iterator gsi;
86289 +
86290 + // 1. loop through BBs and GIMPLE statements
86291 + FOR_EACH_BB(bb) {
86292 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86293 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
86294 + tree fn;
86295 + gimple call_stmt;
86296 +
86297 + // is it a call ...
86298 + call_stmt = gsi_stmt(gsi);
86299 + if (!is_gimple_call(call_stmt))
86300 + continue;
86301 + fn = gimple_call_fn(call_stmt);
86302 + if (TREE_CODE(fn) == ADDR_EXPR)
86303 + continue;
86304 + if (TREE_CODE(fn) != SSA_NAME)
86305 + gcc_unreachable();
86306 +
86307 + // ... through a function pointer
86308 + fn = SSA_NAME_VAR(fn);
86309 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
86310 + continue;
86311 + fn = TREE_TYPE(fn);
86312 + if (TREE_CODE(fn) != POINTER_TYPE)
86313 + continue;
86314 + fn = TREE_TYPE(fn);
86315 + if (TREE_CODE(fn) != FUNCTION_TYPE)
86316 + continue;
86317 +
86318 + kernexec_instrument_fptr(gsi);
86319 +
86320 +//debug_tree(gimple_call_fn(call_stmt));
86321 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86322 + }
86323 + }
86324 +
86325 + return 0;
86326 +}
86327 +
86328 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
86329 +static void kernexec_instrument_retaddr_bts(rtx insn)
86330 +{
86331 + rtx btsq;
86332 + rtvec argvec, constraintvec, labelvec;
86333 + int line;
86334 +
86335 + // create asm volatile("btsq $63,(%%rsp)":::)
86336 + argvec = rtvec_alloc(0);
86337 + constraintvec = rtvec_alloc(0);
86338 + labelvec = rtvec_alloc(0);
86339 + line = expand_location(RTL_LOCATION(insn)).line;
86340 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86341 + MEM_VOLATILE_P(btsq) = 1;
86342 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
86343 + emit_insn_before(btsq, insn);
86344 +}
86345 +
86346 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
86347 +static void kernexec_instrument_retaddr_or(rtx insn)
86348 +{
86349 + rtx orq;
86350 + rtvec argvec, constraintvec, labelvec;
86351 + int line;
86352 +
86353 + // create asm volatile("orq %%r10,(%%rsp)":::)
86354 + argvec = rtvec_alloc(0);
86355 + constraintvec = rtvec_alloc(0);
86356 + labelvec = rtvec_alloc(0);
86357 + line = expand_location(RTL_LOCATION(insn)).line;
86358 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86359 + MEM_VOLATILE_P(orq) = 1;
86360 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
86361 + emit_insn_before(orq, insn);
86362 +}
86363 +
86364 +/*
86365 + * find all asm level function returns and forcibly set the highest bit of the return address
86366 + */
86367 +static unsigned int execute_kernexec_retaddr(void)
86368 +{
86369 + rtx insn;
86370 +
86371 + // 1. find function returns
86372 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86373 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
86374 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
86375 + rtx body;
86376 +
86377 + // is it a retn
86378 + if (!JUMP_P(insn))
86379 + continue;
86380 + body = PATTERN(insn);
86381 + if (GET_CODE(body) == PARALLEL)
86382 + body = XVECEXP(body, 0, 0);
86383 + if (GET_CODE(body) != RETURN)
86384 + continue;
86385 + kernexec_instrument_retaddr(insn);
86386 + }
86387 +
86388 +// print_simple_rtl(stderr, get_insns());
86389 +// print_rtl(stderr, get_insns());
86390 +
86391 + return 0;
86392 +}
86393 +
86394 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86395 +{
86396 + const char * const plugin_name = plugin_info->base_name;
86397 + const int argc = plugin_info->argc;
86398 + const struct plugin_argument * const argv = plugin_info->argv;
86399 + int i;
86400 + struct register_pass_info kernexec_fptr_pass_info = {
86401 + .pass = &kernexec_fptr_pass.pass,
86402 + .reference_pass_name = "ssa",
86403 + .ref_pass_instance_number = 0,
86404 + .pos_op = PASS_POS_INSERT_AFTER
86405 + };
86406 + struct register_pass_info kernexec_retaddr_pass_info = {
86407 + .pass = &kernexec_retaddr_pass.pass,
86408 + .reference_pass_name = "pro_and_epilogue",
86409 + .ref_pass_instance_number = 0,
86410 + .pos_op = PASS_POS_INSERT_AFTER
86411 + };
86412 +
86413 + if (!plugin_default_version_check(version, &gcc_version)) {
86414 + error(G_("incompatible gcc/plugin versions"));
86415 + return 1;
86416 + }
86417 +
86418 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
86419 +
86420 + if (TARGET_64BIT == 0)
86421 + return 0;
86422 +
86423 + for (i = 0; i < argc; ++i) {
86424 + if (!strcmp(argv[i].key, "method")) {
86425 + if (!argv[i].value) {
86426 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86427 + continue;
86428 + }
86429 + if (!strcmp(argv[i].value, "bts")) {
86430 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
86431 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
86432 + } else if (!strcmp(argv[i].value, "or")) {
86433 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
86434 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
86435 + fix_register("r10", 1, 1);
86436 + } else
86437 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86438 + continue;
86439 + }
86440 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86441 + }
86442 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
86443 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
86444 +
86445 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
86446 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
86447 +
86448 + return 0;
86449 +}
86450 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
86451 new file mode 100644
86452 index 0000000..d44f37c
86453 --- /dev/null
86454 +++ b/tools/gcc/stackleak_plugin.c
86455 @@ -0,0 +1,291 @@
86456 +/*
86457 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86458 + * Licensed under the GPL v2
86459 + *
86460 + * Note: the choice of the license means that the compilation process is
86461 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86462 + * but for the kernel it doesn't matter since it doesn't link against
86463 + * any of the gcc libraries
86464 + *
86465 + * gcc plugin to help implement various PaX features
86466 + *
86467 + * - track lowest stack pointer
86468 + *
86469 + * TODO:
86470 + * - initialize all local variables
86471 + *
86472 + * BUGS:
86473 + * - none known
86474 + */
86475 +#include "gcc-plugin.h"
86476 +#include "config.h"
86477 +#include "system.h"
86478 +#include "coretypes.h"
86479 +#include "tree.h"
86480 +#include "tree-pass.h"
86481 +#include "flags.h"
86482 +#include "intl.h"
86483 +#include "toplev.h"
86484 +#include "plugin.h"
86485 +//#include "expr.h" where are you...
86486 +#include "diagnostic.h"
86487 +#include "plugin-version.h"
86488 +#include "tm.h"
86489 +#include "function.h"
86490 +#include "basic-block.h"
86491 +#include "gimple.h"
86492 +#include "rtl.h"
86493 +#include "emit-rtl.h"
86494 +
86495 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86496 +
86497 +int plugin_is_GPL_compatible;
86498 +
86499 +static int track_frame_size = -1;
86500 +static const char track_function[] = "pax_track_stack";
86501 +static const char check_function[] = "pax_check_alloca";
86502 +static bool init_locals;
86503 +
86504 +static struct plugin_info stackleak_plugin_info = {
86505 + .version = "201111150100",
86506 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
86507 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
86508 +};
86509 +
86510 +static bool gate_stackleak_track_stack(void);
86511 +static unsigned int execute_stackleak_tree_instrument(void);
86512 +static unsigned int execute_stackleak_final(void);
86513 +
86514 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
86515 + .pass = {
86516 + .type = GIMPLE_PASS,
86517 + .name = "stackleak_tree_instrument",
86518 + .gate = gate_stackleak_track_stack,
86519 + .execute = execute_stackleak_tree_instrument,
86520 + .sub = NULL,
86521 + .next = NULL,
86522 + .static_pass_number = 0,
86523 + .tv_id = TV_NONE,
86524 + .properties_required = PROP_gimple_leh | PROP_cfg,
86525 + .properties_provided = 0,
86526 + .properties_destroyed = 0,
86527 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86528 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86529 + }
86530 +};
86531 +
86532 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
86533 + .pass = {
86534 + .type = RTL_PASS,
86535 + .name = "stackleak_final",
86536 + .gate = gate_stackleak_track_stack,
86537 + .execute = execute_stackleak_final,
86538 + .sub = NULL,
86539 + .next = NULL,
86540 + .static_pass_number = 0,
86541 + .tv_id = TV_NONE,
86542 + .properties_required = 0,
86543 + .properties_provided = 0,
86544 + .properties_destroyed = 0,
86545 + .todo_flags_start = 0,
86546 + .todo_flags_finish = TODO_dump_func
86547 + }
86548 +};
86549 +
86550 +static bool gate_stackleak_track_stack(void)
86551 +{
86552 + return track_frame_size >= 0;
86553 +}
86554 +
86555 +static void stackleak_check_alloca(gimple_stmt_iterator gsi)
86556 +{
86557 + gimple check_alloca;
86558 + tree fndecl, fntype, alloca_size;
86559 +
86560 + // insert call to void pax_check_alloca(unsigned long size)
86561 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
86562 + fndecl = build_fn_decl(check_function, fntype);
86563 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86564 + alloca_size = gimple_call_arg(gsi_stmt(gsi), 0);
86565 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
86566 + gsi_insert_before(&gsi, check_alloca, GSI_CONTINUE_LINKING);
86567 +}
86568 +
86569 +static void stackleak_add_instrumentation(gimple_stmt_iterator gsi)
86570 +{
86571 + gimple track_stack;
86572 + tree fndecl, fntype;
86573 +
86574 + // insert call to void pax_track_stack(void)
86575 + fntype = build_function_type_list(void_type_node, NULL_TREE);
86576 + fndecl = build_fn_decl(track_function, fntype);
86577 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86578 + track_stack = gimple_build_call(fndecl, 0);
86579 + gsi_insert_after(&gsi, track_stack, GSI_CONTINUE_LINKING);
86580 +}
86581 +
86582 +#if BUILDING_GCC_VERSION == 4005
86583 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
86584 +{
86585 + tree fndecl;
86586 +
86587 + if (!is_gimple_call(stmt))
86588 + return false;
86589 + fndecl = gimple_call_fndecl(stmt);
86590 + if (!fndecl)
86591 + return false;
86592 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
86593 + return false;
86594 +// print_node(stderr, "pax", fndecl, 4);
86595 + return DECL_FUNCTION_CODE(fndecl) == code;
86596 +}
86597 +#endif
86598 +
86599 +static bool is_alloca(gimple stmt)
86600 +{
86601 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
86602 + return true;
86603 +
86604 +#if BUILDING_GCC_VERSION >= 4007
86605 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
86606 + return true;
86607 +#endif
86608 +
86609 + return false;
86610 +}
86611 +
86612 +static unsigned int execute_stackleak_tree_instrument(void)
86613 +{
86614 + basic_block bb, entry_bb;
86615 + bool prologue_instrumented = false;
86616 +
86617 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
86618 +
86619 + // 1. loop through BBs and GIMPLE statements
86620 + FOR_EACH_BB(bb) {
86621 + gimple_stmt_iterator gsi;
86622 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86623 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
86624 + if (!is_alloca(gsi_stmt(gsi)))
86625 + continue;
86626 +
86627 + // 2. insert stack overflow check before each __builtin_alloca call
86628 + stackleak_check_alloca(gsi);
86629 +
86630 + // 3. insert track call after each __builtin_alloca call
86631 + stackleak_add_instrumentation(gsi);
86632 + if (bb == entry_bb)
86633 + prologue_instrumented = true;
86634 + }
86635 + }
86636 +
86637 + // 4. insert track call at the beginning
86638 + if (!prologue_instrumented) {
86639 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86640 + if (dom_info_available_p(CDI_DOMINATORS))
86641 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86642 + stackleak_add_instrumentation(gsi_start_bb(bb));
86643 + }
86644 +
86645 + return 0;
86646 +}
86647 +
86648 +static unsigned int execute_stackleak_final(void)
86649 +{
86650 + rtx insn;
86651 +
86652 + if (cfun->calls_alloca)
86653 + return 0;
86654 +
86655 + // keep calls only if function frame is big enough
86656 + if (get_frame_size() >= track_frame_size)
86657 + return 0;
86658 +
86659 + // 1. find pax_track_stack calls
86660 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86661 + // 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))
86662 + rtx body;
86663 +
86664 + if (!CALL_P(insn))
86665 + continue;
86666 + body = PATTERN(insn);
86667 + if (GET_CODE(body) != CALL)
86668 + continue;
86669 + body = XEXP(body, 0);
86670 + if (GET_CODE(body) != MEM)
86671 + continue;
86672 + body = XEXP(body, 0);
86673 + if (GET_CODE(body) != SYMBOL_REF)
86674 + continue;
86675 + if (strcmp(XSTR(body, 0), track_function))
86676 + continue;
86677 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86678 + // 2. delete call
86679 + insn = delete_insn_and_edges(insn);
86680 +#if BUILDING_GCC_VERSION >= 4007
86681 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
86682 + insn = delete_insn_and_edges(insn);
86683 +#endif
86684 + }
86685 +
86686 +// print_simple_rtl(stderr, get_insns());
86687 +// print_rtl(stderr, get_insns());
86688 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86689 +
86690 + return 0;
86691 +}
86692 +
86693 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86694 +{
86695 + const char * const plugin_name = plugin_info->base_name;
86696 + const int argc = plugin_info->argc;
86697 + const struct plugin_argument * const argv = plugin_info->argv;
86698 + int i;
86699 + struct register_pass_info stackleak_tree_instrument_pass_info = {
86700 + .pass = &stackleak_tree_instrument_pass.pass,
86701 +// .reference_pass_name = "tree_profile",
86702 + .reference_pass_name = "optimized",
86703 + .ref_pass_instance_number = 0,
86704 + .pos_op = PASS_POS_INSERT_AFTER
86705 + };
86706 + struct register_pass_info stackleak_final_pass_info = {
86707 + .pass = &stackleak_final_rtl_opt_pass.pass,
86708 + .reference_pass_name = "final",
86709 + .ref_pass_instance_number = 0,
86710 + .pos_op = PASS_POS_INSERT_BEFORE
86711 + };
86712 +
86713 + if (!plugin_default_version_check(version, &gcc_version)) {
86714 + error(G_("incompatible gcc/plugin versions"));
86715 + return 1;
86716 + }
86717 +
86718 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
86719 +
86720 + for (i = 0; i < argc; ++i) {
86721 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
86722 + if (!argv[i].value) {
86723 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86724 + continue;
86725 + }
86726 + track_frame_size = atoi(argv[i].value);
86727 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
86728 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86729 + continue;
86730 + }
86731 + if (!strcmp(argv[i].key, "initialize-locals")) {
86732 + if (argv[i].value) {
86733 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86734 + continue;
86735 + }
86736 + init_locals = true;
86737 + continue;
86738 + }
86739 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86740 + }
86741 +
86742 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
86743 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
86744 +
86745 + return 0;
86746 +}
86747 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
86748 index 83b3dde..835bee7 100644
86749 --- a/usr/gen_init_cpio.c
86750 +++ b/usr/gen_init_cpio.c
86751 @@ -299,7 +299,7 @@ static int cpio_mkfile(const char *name, const char *location,
86752 int retval;
86753 int rc = -1;
86754 int namesize;
86755 - int i;
86756 + unsigned int i;
86757
86758 mode |= S_IFREG;
86759
86760 @@ -383,9 +383,10 @@ static char *cpio_replace_env(char *new_location)
86761 *env_var = *expanded = '\0';
86762 strncat(env_var, start + 2, end - start - 2);
86763 strncat(expanded, new_location, start - new_location);
86764 - strncat(expanded, getenv(env_var), PATH_MAX);
86765 - strncat(expanded, end + 1, PATH_MAX);
86766 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86767 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86768 strncpy(new_location, expanded, PATH_MAX);
86769 + new_location[PATH_MAX] = 0;
86770 } else
86771 break;
86772 }
86773 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86774 index 4f3434f..159bc3e 100644
86775 --- a/virt/kvm/kvm_main.c
86776 +++ b/virt/kvm/kvm_main.c
86777 @@ -2494,7 +2494,7 @@ asmlinkage void kvm_handle_fault_on_reboot(void)
86778 if (kvm_rebooting)
86779 /* spin while reset goes on */
86780 while (true)
86781 - ;
86782 + cpu_relax();
86783 /* Fault while not rebooting. We want the trace. */
86784 BUG();
86785 }
86786 @@ -2714,7 +2714,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86787 kvm_arch_vcpu_put(vcpu);
86788 }
86789
86790 -int kvm_init(void *opaque, unsigned int vcpu_size,
86791 +int kvm_init(const void *opaque, unsigned int vcpu_size,
86792 struct module *module)
86793 {
86794 int r;
86795 @@ -2767,15 +2767,17 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
86796 /* A kmem cache lets us meet the alignment requirements of fx_save. */
86797 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size,
86798 __alignof__(struct kvm_vcpu),
86799 - 0, NULL);
86800 + SLAB_USERCOPY, NULL);
86801 if (!kvm_vcpu_cache) {
86802 r = -ENOMEM;
86803 goto out_free_5;
86804 }
86805
86806 - kvm_chardev_ops.owner = module;
86807 - kvm_vm_fops.owner = module;
86808 - kvm_vcpu_fops.owner = module;
86809 + pax_open_kernel();
86810 + *(void **)&kvm_chardev_ops.owner = module;
86811 + *(void **)&kvm_vm_fops.owner = module;
86812 + *(void **)&kvm_vcpu_fops.owner = module;
86813 + pax_close_kernel();
86814
86815 r = misc_register(&kvm_dev);
86816 if (r) {