]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.50-201112102010.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.50-201112102010.patch
CommitLineData
9cb0b03d
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 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
169diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
170index 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]
187diff --git a/Makefile b/Makefile
188index f38986c..46a251b 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)
400diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
401index 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
418diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
419index 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))
440diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
441index 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++) {
453diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
454index 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
488diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
489index 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)))
648diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
649index 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
668diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
669index 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
680diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
681index 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;
739diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
740index 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);
754diff --git a/arch/arm/kernel/kgdb.c b/arch/arm/kernel/kgdb.c
755index 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__ */
767diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
768index 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
789diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
790index 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
816diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
817index 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
843diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
844index 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
900diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
901index 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
913diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
914index 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,
926diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
927index 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,
939diff --git a/arch/arm/mach-omap2/pm24xx.c b/arch/arm/mach-omap2/pm24xx.c
940index 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,
952diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
953index 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,
965diff --git a/arch/arm/mach-pnx4008/pm.c b/arch/arm/mach-pnx4008/pm.c
966index 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 };
978diff --git a/arch/arm/mach-pxa/pm.c b/arch/arm/mach-pxa/pm.c
979index 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,
991diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
992index 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,
1004diff --git a/arch/arm/mach-sa1100/pm.c b/arch/arm/mach-sa1100/pm.c
1005index 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 };
1017diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1018index 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 *
1069diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1070index 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 */
1122diff --git a/arch/arm/plat-s3c/pm.c b/arch/arm/plat-s3c/pm.c
1123index 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,
1135diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1136index 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,
1155diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1156index 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
1169diff --git a/arch/avr32/mach-at32ap/pm.c b/arch/avr32/mach-at32ap/pm.c
1170index 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 };
1182diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1183index 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",
1227diff --git a/arch/blackfin/kernel/kgdb.c b/arch/blackfin/kernel/kgdb.c
1228index 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,
1240diff --git a/arch/blackfin/mach-common/pm.c b/arch/blackfin/mach-common/pm.c
1241index 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 };
1253diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1254index 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
1265diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1266index 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 }
1297diff --git a/arch/ia64/hp/common/hwsw_iommu.c b/arch/ia64/hp/common/hwsw_iommu.c
1298index 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;
1319diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
1320index 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,
1341diff --git a/arch/ia64/ia32/binfmt_elf32.c b/arch/ia64/ia32/binfmt_elf32.c
1342index 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
1359diff --git a/arch/ia64/ia32/ia32priv.h b/arch/ia64/ia32/ia32priv.h
1360index 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
1379diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
1380index 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
1426diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1427index 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: */
1444diff --git a/arch/ia64/include/asm/machvec.h b/arch/ia64/include/asm/machvec.h
1445index 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
1466diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1467index 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)
1497diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1498index 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)
1510diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1511index 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 })
1532diff --git a/arch/ia64/kernel/dma-mapping.c b/arch/ia64/kernel/dma-mapping.c
1533index 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 }
1554diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1555index 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 }
1646diff --git a/arch/ia64/kernel/pci-dma.c b/arch/ia64/kernel/pci-dma.c
1647index 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
1701diff --git a/arch/ia64/kernel/pci-swiotlb.c b/arch/ia64/kernel/pci-swiotlb.c
1702index 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,
1714diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1715index 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;
1750diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
1751index 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
1763diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1764index 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 */
1776diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1777index 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
1829diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1830index 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 }
1842diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1843index 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)) {
1866diff --git a/arch/ia64/sn/pci/pci_dma.c b/arch/ia64/sn/pci/pci_dma.c
1867index 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,
1879diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1880index 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);
1903diff --git a/arch/mips/Makefile b/arch/mips/Makefile
1904index 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
1916diff --git a/arch/mips/alchemy/devboards/pm.c b/arch/mips/alchemy/devboards/pm.c
1917index 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,
1929diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1930index 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 */
1945diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1946index 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)
1958diff --git a/arch/mips/include/asm/reboot.h b/arch/mips/include/asm/reboot.h
1959index 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 */
1972diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1973index 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 */
1984diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1985index 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>
2002diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2003index 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 /*
2020diff --git a/arch/mips/kernel/kgdb.c b/arch/mips/kernel/kgdb.c
2021index 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 /*
2032diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2033index 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-}
2052diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
2053index 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 }
2087diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
2088index 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)
2125diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2126index 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
2153diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2154index 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. */
2171diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2172index 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)
2193diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
2194index 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);
2296diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
2297index 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);
2327diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
2328index 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
2342diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
2343index 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
2515diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
2516index 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)
2528diff --git a/arch/powerpc/include/asm/device.h b/arch/powerpc/include/asm/device.h
2529index 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
2541diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
2542index 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);
2611diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2612index 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 /*
2647diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
2648index 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);
2661diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2662index 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
2673diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2674index 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
2699diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2700index 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
2724diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
2725index 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
2739diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2740index 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>
2751diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2752index 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 */
2763diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
2764index 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
2776diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2777index 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 */
2788diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
2789index 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
2801diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2802index 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);
2814diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2815index 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)
2995diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
2996index 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
3008diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
3009index 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
3021diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
3022index 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,
3034diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
3035index 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,
3047diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3048index 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
3069diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3070index 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)
3085diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
3086index 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,
3098diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
3099index 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
3120diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
3121index 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)
3163diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3164index 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]) {
3196diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
3197index 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 }
3218diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3219index 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-}
3314diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
3315index 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)
3336diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3337index 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;
3349diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3350index 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]);
3362diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
3363index 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 }
3379diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3380index 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
3401diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3402index 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;
3431diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
3432index 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
3457diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3458index 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
3492diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
3493index 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 }
3600diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
3601index 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 =
3613diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
3614index 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 }
3640diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
3641index 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);
3710diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platforms/52xx/lite5200_pm.c
3711index 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,
3723diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pm.c b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3724index 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,
3736diff --git a/arch/powerpc/platforms/83xx/suspend.c b/arch/powerpc/platforms/83xx/suspend.c
3737index 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,
3749diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
3750index 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,
3762diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
3763index 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,
3784diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
3785index 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
3797diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
3798index 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
3838diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
3839index 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
3856diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
3857index 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
3876diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
3877index 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
3912diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
3913index 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;
3987diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
3988index 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) {
4044diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4045index 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 }
4094diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4095index 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()
4107diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4108index 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-}
4120diff --git a/arch/sh/boards/mach-hp6xx/pm.c b/arch/sh/boards/mach-hp6xx/pm.c
4121index 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 };
4133diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
4134index 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 };
4146diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c
4147index 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 };
4159diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
4160index 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 },
4172diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4173index 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 /*
4250diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4251index 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
4263diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4264index 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)
4459diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4460index 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
4472diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h
4473index 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);
4507diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4508index 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. */
4525diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4526index 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. */
4542diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4543index 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
4577diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4578index 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
4595diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4596index 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
4696diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
4697index 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 /*
4709diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
4710index 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
4722diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
4723index 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
4740diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
4741index 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
4795diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
4796index 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;
4841diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
4842index 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
4854diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
4855index 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);
4876diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
4877index 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,
4907diff --git a/arch/sparc/kernel/kgdb_32.c b/arch/sparc/kernel/kgdb_32.c
4908index 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 };
4920diff --git a/arch/sparc/kernel/kgdb_64.c b/arch/sparc/kernel/kgdb_64.c
4921index 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 };
4933diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
4934index 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,
4946diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
4947index 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");
4985diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
4986index 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,
5024diff --git a/arch/sparc/kernel/sigutil_64.c b/arch/sparc/kernel/sigutil_64.c
5025index 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>
5036diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5037index 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)
5058diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5059index 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 }
5209diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5210index 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
5242diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5243index 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);
5377diff --git a/arch/sparc/kernel/una_asm_64.S b/arch/sparc/kernel/una_asm_64.S
5378index 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
5390diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5391index 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 }
5403diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5404index 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
5416diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5417index 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
5654diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5655index 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. */
5677diff --git a/arch/sparc/lib/rwsem_64.S b/arch/sparc/lib/rwsem_64.S
5678index 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
5779diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5780index 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
5792diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5793index 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;
6099diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6100index 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
6609diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6610index 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)
6672diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6673index 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;
6710diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6711index 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
6728diff --git a/arch/um/Makefile b/arch/um/Makefile
6729index 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.
6743diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6744index 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
6755diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6756index 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;
6769diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6770index 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;
6796diff --git a/arch/um/sys-i386/shared/sysdep/system.h b/arch/um/sys-i386/shared/sysdep/system.h
6797index 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
6809diff --git a/arch/um/sys-i386/syscalls.c b/arch/um/sys-i386/syscalls.c
6810index 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
6835diff --git a/arch/um/sys-x86_64/shared/sysdep/system.h b/arch/um/sys-x86_64/shared/sysdep/system.h
6836index 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
6848diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
6849index 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---
6924diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
6925index 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
6955diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
6956index 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
6968diff --git a/arch/x86/Makefile b/arch/x86/Makefile
6969index 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)))
6993diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
6994index 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
7007diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7008index 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 */
7029diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7030index 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 }
7051diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7052index 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
7065diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7066index 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:
7097diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7098index 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 */
7128diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7129index 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
7150diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
7151index 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");
7163diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7164index 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);
7367diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7368index 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 }
7466diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7467index 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)
7479diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7480index 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 */
7492diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7493index 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 /*
7504diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7505index 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
7517diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7518index 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; \
7539diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7540index 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)
7682diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7683index 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
7714diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
7715index 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
7740diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
7741index 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;
7766diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
7767index 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)
7846diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
7847index 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
8157diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8158index 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
8219diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8220index 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__ */
8267diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8268index 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
8280diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8281index 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;
8293diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8294index 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"
8315diff --git a/arch/x86/include/asm/atomic_32.h b/arch/x86/include/asm/atomic_32.h
8316index 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 *
8832diff --git a/arch/x86/include/asm/atomic_64.h b/arch/x86/include/asm/atomic_64.h
8833index 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 /**
9500diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9501index 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 /**
9513diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9514index 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
9534diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9535index 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 */
9550diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9551index 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;
9572diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
9573index 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
9630diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9631index 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)
9667diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9668index 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 */
9851diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9852index 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
9868diff --git a/arch/x86/include/asm/device.h b/arch/x86/include/asm/device.h
9869index 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 */
9881diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
9882index 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
9924diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9925index 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__
9937diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9938index 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 */
9995diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
9996index 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 */
10007diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10008index 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 );
10086diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10087index 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);
10101diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10102index 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 }
10154diff --git a/arch/x86/include/asm/io_32.h b/arch/x86/include/asm/io_32.h
10155index 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>
10184diff --git a/arch/x86/include/asm/io_64.h b/arch/x86/include/asm/io_64.h
10185index 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);
10206diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
10207index 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;
10219diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10220index 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
10235diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10236index 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
10255diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10256index 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);
10271diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10272index 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;
10427diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
10428index 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 }
10471diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10472index 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 */
10490diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10491index 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
10520diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10521index 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) \
10644diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10645index 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 */
10690diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10691index 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)
10703diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10704index 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__ */
10779diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10780index 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
10854diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
10855index 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 */
10880diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
10881index 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: \
10892diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10893index 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
10910diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10911index 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)
10924diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10925index 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 /*
10945diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10946index 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__ */
11126diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11127index 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
11173diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11174index 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)
11206diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11207index 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
11251diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11252index 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 */
11266diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11267index 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);
11390diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11391index 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 */
11496diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11497index 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
11536diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11537index 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);
11566diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11567index 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
11694diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11695index 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)
11773diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11774index 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
11824diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11825index 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
11890diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11891index 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 }
11912diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11913index 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.
11958diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11959index 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 */
12120diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12121index 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
12351diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12352index 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,
12495diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12496index 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 */
12889diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12890index 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
12902diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
12903index 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;
12914diff --git a/arch/x86/include/asm/vmi.h b/arch/x86/include/asm/vmi.h
12915index 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 {
12926diff --git a/arch/x86/include/asm/vmi_time.h b/arch/x86/include/asm/vmi_time.h
12927index 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);
12939diff --git a/arch/x86/include/asm/vsyscall.h b/arch/x86/include/asm/vsyscall.h
12940index 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 */
12973diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
12974index 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;
13058diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13059index 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"
13092diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13093index 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
13106diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13107index 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
13137diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13138index 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
13187diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13188index 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
13207diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13208index 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 }
13293diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
13294index 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,
13306diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13307index 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
13337diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13338index 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);
13395diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13396index 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
13479diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
13480index 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
13520diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13521index 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);
13568diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13569index 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
13583diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13584index 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;
13596diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13597index 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)) {
13744diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13745index 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
13757diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
13758index 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 };
13770diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13771index 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 }
13785diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13786index 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);
13909diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13910index 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 };
13922diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13923index 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
13936diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13937index 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
13950diff --git a/arch/x86/kernel/cpu/mtrr/amd.c b/arch/x86/kernel/cpu/mtrr/amd.c
13951index 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,
13963diff --git a/arch/x86/kernel/cpu/mtrr/centaur.c b/arch/x86/kernel/cpu/mtrr/centaur.c
13964index 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,
13976diff --git a/arch/x86/kernel/cpu/mtrr/cyrix.c b/arch/x86/kernel/cpu/mtrr/cyrix.c
13977index 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,
13989diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
13990index 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,
14002diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14003index 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;
14024diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14025index 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)
14058diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14059index 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
14102diff --git a/arch/x86/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c
14103index 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,
14139diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14140index 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 }
14152diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14153index 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),
14187diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14188index 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))
14307diff --git a/arch/x86/kernel/dumpstack.h b/arch/x86/kernel/dumpstack.h
14308index 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);
14320diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14321index 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))
14405diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14406index 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
14510diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
14511index 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)
14523diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14524index 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);
14544diff --git a/arch/x86/kernel/efi_32.c b/arch/x86/kernel/efi_32.c
14545index 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.
14645diff --git a/arch/x86/kernel/efi_stub_32.S b/arch/x86/kernel/efi_stub_32.S
14646index 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:
14757diff --git a/arch/x86/kernel/efi_stub_64.S b/arch/x86/kernel/efi_stub_64.S
14758index 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)
14824diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14825index 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
15592diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15593index 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
16595diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16596index 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
16684diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16685index 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 */
16705diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16706index 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
17230diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17231index 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
17524diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17525index 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
17549diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17550index 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
17562diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17563index 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);
17584diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17585index 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 }
17631diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17632index 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 }
17669diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17670index 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 */
17813diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17814index 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,
17851diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17852index 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) {
17966diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17967index 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;
17978diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17979index 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;
18046diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18047index 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);
18077diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
18078index 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 }
18099diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
18100index 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.
18112diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18113index 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 }
18150diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18151index 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;
18294diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18295index 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,
18307diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18308index 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);
18458diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
18459index 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,
18471diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
18472index 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) {
18493diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
18494index 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,
18506diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
18507index 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,
18519diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
18520index 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,
18532diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18533index 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
18650diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18651index 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-
18754diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18755index 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))
18831diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18832index 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);
18921diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18922index 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 = {
19051diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19052index 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:
19071diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19072index 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;
19095diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19096index 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.
19162diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19163index 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)
19249diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19250index 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) {
19322diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19323index 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 */
19368diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19369index 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-}
19643diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19644index 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;
19784diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
19785index 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
19793diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19794index 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 }
19845diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19846index 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 }
19887diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19888index 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;
19903diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19904index 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
19929diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19930index 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
19960diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19961index 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();
20150diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20151new file mode 100644
20152index 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
20296diff --git a/arch/x86/kernel/verify_cpu_64.S b/arch/x86/kernel/verify_cpu_64.S
20297deleted file mode 100644
20298index 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
20407diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20408index 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)
20475diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c
20476index 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);
20641diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20642index 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
20937diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20938index 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 */
20958diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20959index 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);
20971diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20972index 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 /*
21002diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21003index 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"); \
21042diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21043index 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*/
21055diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21056index 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
21076diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21077index 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,
21101diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21102index 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,
21195diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21196index 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");
21278diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21279index 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
21294diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
21295index 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 *
21520diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21521index 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
21784diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21785index 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:
21820diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21821index 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:
21892diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21893index 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"
22012diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22013index 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"
22079diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22080index 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
22099diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22100index 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);
22133diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22134index 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)
22260diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22261index 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)
22280diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22281index 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:
22317diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22318index 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:
22371diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22372index 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;
22690diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22691index 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
22736diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22737index 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
22879diff --git a/arch/x86/lib/rwlock_64.S b/arch/x86/lib/rwlock_64.S
22880index 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)
22961diff --git a/arch/x86/lib/rwsem_64.S b/arch/x86/lib/rwsem_64.S
22962index 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)
22998diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22999index 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
23027diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23028index 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
23636diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23637index 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;
23701diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23702index 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;
23778diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23779index 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+}
24497diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24498index 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
24510diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24511index 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 }
24525diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24526index 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)
24736diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24737index 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));
24877diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24878index 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);
25184diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25185index 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]";
25248diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25249index 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;
25264diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25265index 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
25314diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25315index 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);
25330diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25331index 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 }
25415diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25416index 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
25446diff --git a/arch/x86/mm/numa_32.c b/arch/x86/mm/numa_32.c
25447index 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)
25458diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25459index 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 {
25471diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25472index 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
25551diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25552index 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),
25602diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25603index 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++)
25651diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25652index 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);
25901diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25902index 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.
25919diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25920index 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
25988diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25989index 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
26004diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26005index 044897b..a195924 100644
26006--- a/arch/x86/oprofile/backtrace.c
26007+++ b/arch/x86/oprofile/backtrace.c
26008@@ -57,7 +57,7 @@ static struct frame_head *dump_user_backtrace(struct frame_head *head)
26009 struct frame_head bufhead[2];
26010
26011 /* Also check accessibility of one struct frame_head beyond */
26012- if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
26013+ if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
26014 return NULL;
26015 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
26016 return NULL;
26017@@ -77,7 +77,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26018 {
26019 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
26020
26021- if (!user_mode_vm(regs)) {
26022+ if (!user_mode(regs)) {
26023 unsigned long stack = kernel_stack_pointer(regs);
26024 if (depth)
26025 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26026diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
26027index e6a160a..36deff6 100644
26028--- a/arch/x86/oprofile/op_model_p4.c
26029+++ b/arch/x86/oprofile/op_model_p4.c
26030@@ -50,7 +50,7 @@ static inline void setup_num_counters(void)
26031 #endif
26032 }
26033
26034-static int inline addr_increment(void)
26035+static inline int addr_increment(void)
26036 {
26037 #ifdef CONFIG_SMP
26038 return smp_num_siblings == 2 ? 2 : 1;
26039diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
26040index 1331fcf..03901b2 100644
26041--- a/arch/x86/pci/common.c
26042+++ b/arch/x86/pci/common.c
26043@@ -31,8 +31,8 @@ int noioapicreroute = 1;
26044 int pcibios_last_bus = -1;
26045 unsigned long pirq_table_addr;
26046 struct pci_bus *pci_root_bus;
26047-struct pci_raw_ops *raw_pci_ops;
26048-struct pci_raw_ops *raw_pci_ext_ops;
26049+const struct pci_raw_ops *raw_pci_ops;
26050+const struct pci_raw_ops *raw_pci_ext_ops;
26051
26052 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
26053 int reg, int len, u32 *val)
26054diff --git a/arch/x86/pci/direct.c b/arch/x86/pci/direct.c
26055index 347d882..4baf6b6 100644
26056--- a/arch/x86/pci/direct.c
26057+++ b/arch/x86/pci/direct.c
26058@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
26059
26060 #undef PCI_CONF1_ADDRESS
26061
26062-struct pci_raw_ops pci_direct_conf1 = {
26063+const struct pci_raw_ops pci_direct_conf1 = {
26064 .read = pci_conf1_read,
26065 .write = pci_conf1_write,
26066 };
26067@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
26068
26069 #undef PCI_CONF2_ADDRESS
26070
26071-struct pci_raw_ops pci_direct_conf2 = {
26072+const struct pci_raw_ops pci_direct_conf2 = {
26073 .read = pci_conf2_read,
26074 .write = pci_conf2_write,
26075 };
26076@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
26077 * This should be close to trivial, but it isn't, because there are buggy
26078 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
26079 */
26080-static int __init pci_sanity_check(struct pci_raw_ops *o)
26081+static int __init pci_sanity_check(const struct pci_raw_ops *o)
26082 {
26083 u32 x = 0;
26084 int year, devfn;
26085diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c
26086index f10a7e9..0425342 100644
26087--- a/arch/x86/pci/mmconfig_32.c
26088+++ b/arch/x86/pci/mmconfig_32.c
26089@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26090 return 0;
26091 }
26092
26093-static struct pci_raw_ops pci_mmcfg = {
26094+static const struct pci_raw_ops pci_mmcfg = {
26095 .read = pci_mmcfg_read,
26096 .write = pci_mmcfg_write,
26097 };
26098diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c
26099index 94349f8..41600a7 100644
26100--- a/arch/x86/pci/mmconfig_64.c
26101+++ b/arch/x86/pci/mmconfig_64.c
26102@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26103 return 0;
26104 }
26105
26106-static struct pci_raw_ops pci_mmcfg = {
26107+static const struct pci_raw_ops pci_mmcfg = {
26108 .read = pci_mmcfg_read,
26109 .write = pci_mmcfg_write,
26110 };
26111diff --git a/arch/x86/pci/numaq_32.c b/arch/x86/pci/numaq_32.c
26112index 8eb295e..86bd657 100644
26113--- a/arch/x86/pci/numaq_32.c
26114+++ b/arch/x86/pci/numaq_32.c
26115@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
26116
26117 #undef PCI_CONF1_MQ_ADDRESS
26118
26119-static struct pci_raw_ops pci_direct_conf1_mq = {
26120+static const struct pci_raw_ops pci_direct_conf1_mq = {
26121 .read = pci_conf1_mq_read,
26122 .write = pci_conf1_mq_write
26123 };
26124diff --git a/arch/x86/pci/olpc.c b/arch/x86/pci/olpc.c
26125index b889d82..5a58a0a 100644
26126--- a/arch/x86/pci/olpc.c
26127+++ b/arch/x86/pci/olpc.c
26128@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int seg, unsigned int bus,
26129 return 0;
26130 }
26131
26132-static struct pci_raw_ops pci_olpc_conf = {
26133+static const struct pci_raw_ops pci_olpc_conf = {
26134 .read = pci_olpc_read,
26135 .write = pci_olpc_write,
26136 };
26137diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26138index 1c975cc..ffd0536 100644
26139--- a/arch/x86/pci/pcbios.c
26140+++ b/arch/x86/pci/pcbios.c
26141@@ -56,50 +56,93 @@ union bios32 {
26142 static struct {
26143 unsigned long address;
26144 unsigned short segment;
26145-} bios32_indirect = { 0, __KERNEL_CS };
26146+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26147
26148 /*
26149 * Returns the entry point for the given service, NULL on error
26150 */
26151
26152-static unsigned long bios32_service(unsigned long service)
26153+static unsigned long __devinit bios32_service(unsigned long service)
26154 {
26155 unsigned char return_code; /* %al */
26156 unsigned long address; /* %ebx */
26157 unsigned long length; /* %ecx */
26158 unsigned long entry; /* %edx */
26159 unsigned long flags;
26160+ struct desc_struct d, *gdt;
26161
26162 local_irq_save(flags);
26163- __asm__("lcall *(%%edi); cld"
26164+
26165+ gdt = get_cpu_gdt_table(smp_processor_id());
26166+
26167+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26168+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26169+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26170+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26171+
26172+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26173 : "=a" (return_code),
26174 "=b" (address),
26175 "=c" (length),
26176 "=d" (entry)
26177 : "0" (service),
26178 "1" (0),
26179- "D" (&bios32_indirect));
26180+ "D" (&bios32_indirect),
26181+ "r"(__PCIBIOS_DS)
26182+ : "memory");
26183+
26184+ pax_open_kernel();
26185+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26186+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26187+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26188+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26189+ pax_close_kernel();
26190+
26191 local_irq_restore(flags);
26192
26193 switch (return_code) {
26194- case 0:
26195- return address + entry;
26196- case 0x80: /* Not present */
26197- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26198- return 0;
26199- default: /* Shouldn't happen */
26200- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26201- service, return_code);
26202+ case 0: {
26203+ int cpu;
26204+ unsigned char flags;
26205+
26206+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26207+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26208+ printk(KERN_WARNING "bios32_service: not valid\n");
26209 return 0;
26210+ }
26211+ address = address + PAGE_OFFSET;
26212+ length += 16UL; /* some BIOSs underreport this... */
26213+ flags = 4;
26214+ if (length >= 64*1024*1024) {
26215+ length >>= PAGE_SHIFT;
26216+ flags |= 8;
26217+ }
26218+
26219+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
26220+ gdt = get_cpu_gdt_table(cpu);
26221+ pack_descriptor(&d, address, length, 0x9b, flags);
26222+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26223+ pack_descriptor(&d, address, length, 0x93, flags);
26224+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26225+ }
26226+ return entry;
26227+ }
26228+ case 0x80: /* Not present */
26229+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26230+ return 0;
26231+ default: /* Shouldn't happen */
26232+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26233+ service, return_code);
26234+ return 0;
26235 }
26236 }
26237
26238 static struct {
26239 unsigned long address;
26240 unsigned short segment;
26241-} pci_indirect = { 0, __KERNEL_CS };
26242+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26243
26244-static int pci_bios_present;
26245+static int pci_bios_present __read_only;
26246
26247 static int __devinit check_pcibios(void)
26248 {
26249@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
26250 unsigned long flags, pcibios_entry;
26251
26252 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26253- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26254+ pci_indirect.address = pcibios_entry;
26255
26256 local_irq_save(flags);
26257- __asm__(
26258- "lcall *(%%edi); cld\n\t"
26259+ __asm__("movw %w6, %%ds\n\t"
26260+ "lcall *%%ss:(%%edi); cld\n\t"
26261+ "push %%ss\n\t"
26262+ "pop %%ds\n\t"
26263 "jc 1f\n\t"
26264 "xor %%ah, %%ah\n"
26265 "1:"
26266@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
26267 "=b" (ebx),
26268 "=c" (ecx)
26269 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26270- "D" (&pci_indirect)
26271+ "D" (&pci_indirect),
26272+ "r" (__PCIBIOS_DS)
26273 : "memory");
26274 local_irq_restore(flags);
26275
26276@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26277
26278 switch (len) {
26279 case 1:
26280- __asm__("lcall *(%%esi); cld\n\t"
26281+ __asm__("movw %w6, %%ds\n\t"
26282+ "lcall *%%ss:(%%esi); cld\n\t"
26283+ "push %%ss\n\t"
26284+ "pop %%ds\n\t"
26285 "jc 1f\n\t"
26286 "xor %%ah, %%ah\n"
26287 "1:"
26288@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26289 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26290 "b" (bx),
26291 "D" ((long)reg),
26292- "S" (&pci_indirect));
26293+ "S" (&pci_indirect),
26294+ "r" (__PCIBIOS_DS));
26295 /*
26296 * Zero-extend the result beyond 8 bits, do not trust the
26297 * BIOS having done it:
26298@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26299 *value &= 0xff;
26300 break;
26301 case 2:
26302- __asm__("lcall *(%%esi); cld\n\t"
26303+ __asm__("movw %w6, %%ds\n\t"
26304+ "lcall *%%ss:(%%esi); cld\n\t"
26305+ "push %%ss\n\t"
26306+ "pop %%ds\n\t"
26307 "jc 1f\n\t"
26308 "xor %%ah, %%ah\n"
26309 "1:"
26310@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26311 : "1" (PCIBIOS_READ_CONFIG_WORD),
26312 "b" (bx),
26313 "D" ((long)reg),
26314- "S" (&pci_indirect));
26315+ "S" (&pci_indirect),
26316+ "r" (__PCIBIOS_DS));
26317 /*
26318 * Zero-extend the result beyond 16 bits, do not trust the
26319 * BIOS having done it:
26320@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26321 *value &= 0xffff;
26322 break;
26323 case 4:
26324- __asm__("lcall *(%%esi); cld\n\t"
26325+ __asm__("movw %w6, %%ds\n\t"
26326+ "lcall *%%ss:(%%esi); cld\n\t"
26327+ "push %%ss\n\t"
26328+ "pop %%ds\n\t"
26329 "jc 1f\n\t"
26330 "xor %%ah, %%ah\n"
26331 "1:"
26332@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26333 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26334 "b" (bx),
26335 "D" ((long)reg),
26336- "S" (&pci_indirect));
26337+ "S" (&pci_indirect),
26338+ "r" (__PCIBIOS_DS));
26339 break;
26340 }
26341
26342@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26343
26344 switch (len) {
26345 case 1:
26346- __asm__("lcall *(%%esi); cld\n\t"
26347+ __asm__("movw %w6, %%ds\n\t"
26348+ "lcall *%%ss:(%%esi); cld\n\t"
26349+ "push %%ss\n\t"
26350+ "pop %%ds\n\t"
26351 "jc 1f\n\t"
26352 "xor %%ah, %%ah\n"
26353 "1:"
26354@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26355 "c" (value),
26356 "b" (bx),
26357 "D" ((long)reg),
26358- "S" (&pci_indirect));
26359+ "S" (&pci_indirect),
26360+ "r" (__PCIBIOS_DS));
26361 break;
26362 case 2:
26363- __asm__("lcall *(%%esi); cld\n\t"
26364+ __asm__("movw %w6, %%ds\n\t"
26365+ "lcall *%%ss:(%%esi); cld\n\t"
26366+ "push %%ss\n\t"
26367+ "pop %%ds\n\t"
26368 "jc 1f\n\t"
26369 "xor %%ah, %%ah\n"
26370 "1:"
26371@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26372 "c" (value),
26373 "b" (bx),
26374 "D" ((long)reg),
26375- "S" (&pci_indirect));
26376+ "S" (&pci_indirect),
26377+ "r" (__PCIBIOS_DS));
26378 break;
26379 case 4:
26380- __asm__("lcall *(%%esi); cld\n\t"
26381+ __asm__("movw %w6, %%ds\n\t"
26382+ "lcall *%%ss:(%%esi); cld\n\t"
26383+ "push %%ss\n\t"
26384+ "pop %%ds\n\t"
26385 "jc 1f\n\t"
26386 "xor %%ah, %%ah\n"
26387 "1:"
26388@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26389 "c" (value),
26390 "b" (bx),
26391 "D" ((long)reg),
26392- "S" (&pci_indirect));
26393+ "S" (&pci_indirect),
26394+ "r" (__PCIBIOS_DS));
26395 break;
26396 }
26397
26398@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26399 * Function table for BIOS32 access
26400 */
26401
26402-static struct pci_raw_ops pci_bios_access = {
26403+static const struct pci_raw_ops pci_bios_access = {
26404 .read = pci_bios_read,
26405 .write = pci_bios_write
26406 };
26407@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_access = {
26408 * Try to find PCI BIOS.
26409 */
26410
26411-static struct pci_raw_ops * __devinit pci_find_bios(void)
26412+static const struct pci_raw_ops * __devinit pci_find_bios(void)
26413 {
26414 union bios32 *check;
26415 unsigned char sum;
26416@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26417
26418 DBG("PCI: Fetching IRQ routing table... ");
26419 __asm__("push %%es\n\t"
26420+ "movw %w8, %%ds\n\t"
26421 "push %%ds\n\t"
26422 "pop %%es\n\t"
26423- "lcall *(%%esi); cld\n\t"
26424+ "lcall *%%ss:(%%esi); cld\n\t"
26425 "pop %%es\n\t"
26426+ "push %%ss\n\t"
26427+ "pop %%ds\n"
26428 "jc 1f\n\t"
26429 "xor %%ah, %%ah\n"
26430 "1:"
26431@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26432 "1" (0),
26433 "D" ((long) &opt),
26434 "S" (&pci_indirect),
26435- "m" (opt)
26436+ "m" (opt),
26437+ "r" (__PCIBIOS_DS)
26438 : "memory");
26439 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26440 if (ret & 0xff00)
26441@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26442 {
26443 int ret;
26444
26445- __asm__("lcall *(%%esi); cld\n\t"
26446+ __asm__("movw %w5, %%ds\n\t"
26447+ "lcall *%%ss:(%%esi); cld\n\t"
26448+ "push %%ss\n\t"
26449+ "pop %%ds\n"
26450 "jc 1f\n\t"
26451 "xor %%ah, %%ah\n"
26452 "1:"
26453@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26454 : "0" (PCIBIOS_SET_PCI_HW_INT),
26455 "b" ((dev->bus->number << 8) | dev->devfn),
26456 "c" ((irq << 8) | (pin + 10)),
26457- "S" (&pci_indirect));
26458+ "S" (&pci_indirect),
26459+ "r" (__PCIBIOS_DS));
26460 return !(ret & 0xff00);
26461 }
26462 EXPORT_SYMBOL(pcibios_set_irq_routing);
26463diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26464index fa0f651..9d8f3d9 100644
26465--- a/arch/x86/power/cpu.c
26466+++ b/arch/x86/power/cpu.c
26467@@ -129,7 +129,7 @@ static void do_fpu_end(void)
26468 static void fix_processor_context(void)
26469 {
26470 int cpu = smp_processor_id();
26471- struct tss_struct *t = &per_cpu(init_tss, cpu);
26472+ struct tss_struct *t = init_tss + cpu;
26473
26474 set_tss_desc(cpu, t); /*
26475 * This just modifies memory; should not be
26476@@ -139,7 +139,9 @@ static void fix_processor_context(void)
26477 */
26478
26479 #ifdef CONFIG_X86_64
26480+ pax_open_kernel();
26481 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26482+ pax_close_kernel();
26483
26484 syscall_init(); /* This sets MSR_*STAR and related */
26485 #endif
26486diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26487index dd78ef6..f9d928d 100644
26488--- a/arch/x86/vdso/Makefile
26489+++ b/arch/x86/vdso/Makefile
26490@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
26491 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
26492 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
26493
26494-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26495+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26496 GCOV_PROFILE := n
26497
26498 #
26499diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
26500index ee55754..0013b2e 100644
26501--- a/arch/x86/vdso/vclock_gettime.c
26502+++ b/arch/x86/vdso/vclock_gettime.c
26503@@ -22,24 +22,48 @@
26504 #include <asm/hpet.h>
26505 #include <asm/unistd.h>
26506 #include <asm/io.h>
26507+#include <asm/fixmap.h>
26508 #include "vextern.h"
26509
26510 #define gtod vdso_vsyscall_gtod_data
26511
26512+notrace noinline long __vdso_fallback_time(long *t)
26513+{
26514+ long secs;
26515+ asm volatile("syscall"
26516+ : "=a" (secs)
26517+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
26518+ return secs;
26519+}
26520+
26521 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
26522 {
26523 long ret;
26524 asm("syscall" : "=a" (ret) :
26525- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
26526+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
26527 return ret;
26528 }
26529
26530+notrace static inline cycle_t __vdso_vread_hpet(void)
26531+{
26532+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
26533+}
26534+
26535+notrace static inline cycle_t __vdso_vread_tsc(void)
26536+{
26537+ cycle_t ret = (cycle_t)vget_cycles();
26538+
26539+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
26540+}
26541+
26542 notrace static inline long vgetns(void)
26543 {
26544 long v;
26545- cycles_t (*vread)(void);
26546- vread = gtod->clock.vread;
26547- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
26548+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
26549+ v = __vdso_vread_tsc();
26550+ else
26551+ v = __vdso_vread_hpet();
26552+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
26553 return (v * gtod->clock.mult) >> gtod->clock.shift;
26554 }
26555
26556@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic_coarse(struct timespec *ts)
26557
26558 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26559 {
26560- if (likely(gtod->sysctl_enabled))
26561+ if (likely(gtod->sysctl_enabled &&
26562+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26563+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26564 switch (clock) {
26565 case CLOCK_REALTIME:
26566 if (likely(gtod->clock.vread))
26567@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26568 int clock_gettime(clockid_t, struct timespec *)
26569 __attribute__((weak, alias("__vdso_clock_gettime")));
26570
26571+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
26572+{
26573+ long ret;
26574+ asm("syscall" : "=a" (ret) :
26575+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
26576+ return ret;
26577+}
26578+
26579 notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26580 {
26581- long ret;
26582- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
26583+ if (likely(gtod->sysctl_enabled &&
26584+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26585+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26586+ {
26587 if (likely(tv != NULL)) {
26588 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
26589 offsetof(struct timespec, tv_nsec) ||
26590@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26591 }
26592 return 0;
26593 }
26594- asm("syscall" : "=a" (ret) :
26595- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
26596- return ret;
26597+ return __vdso_fallback_gettimeofday(tv, tz);
26598 }
26599 int gettimeofday(struct timeval *, struct timezone *)
26600 __attribute__((weak, alias("__vdso_gettimeofday")));
26601diff --git a/arch/x86/vdso/vdso.lds.S b/arch/x86/vdso/vdso.lds.S
26602index 4e5dd3b..00ba15e 100644
26603--- a/arch/x86/vdso/vdso.lds.S
26604+++ b/arch/x86/vdso/vdso.lds.S
26605@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
26606 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
26607 #include "vextern.h"
26608 #undef VEXTERN
26609+
26610+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
26611+VEXTERN(fallback_gettimeofday)
26612+VEXTERN(fallback_time)
26613+VEXTERN(getcpu)
26614+#undef VEXTERN
26615diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26616index 58bc00f..d53fb48 100644
26617--- a/arch/x86/vdso/vdso32-setup.c
26618+++ b/arch/x86/vdso/vdso32-setup.c
26619@@ -25,6 +25,7 @@
26620 #include <asm/tlbflush.h>
26621 #include <asm/vdso.h>
26622 #include <asm/proto.h>
26623+#include <asm/mman.h>
26624
26625 enum {
26626 VDSO_DISABLED = 0,
26627@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26628 void enable_sep_cpu(void)
26629 {
26630 int cpu = get_cpu();
26631- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26632+ struct tss_struct *tss = init_tss + cpu;
26633
26634 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26635 put_cpu();
26636@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26637 gate_vma.vm_start = FIXADDR_USER_START;
26638 gate_vma.vm_end = FIXADDR_USER_END;
26639 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26640- gate_vma.vm_page_prot = __P101;
26641+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26642 /*
26643 * Make sure the vDSO gets into every core dump.
26644 * Dumping its contents makes post-mortem fully interpretable later
26645@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26646 if (compat)
26647 addr = VDSO_HIGH_BASE;
26648 else {
26649- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26650+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26651 if (IS_ERR_VALUE(addr)) {
26652 ret = addr;
26653 goto up_fail;
26654 }
26655 }
26656
26657- current->mm->context.vdso = (void *)addr;
26658+ current->mm->context.vdso = addr;
26659
26660 if (compat_uses_vma || !compat) {
26661 /*
26662@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26663 }
26664
26665 current_thread_info()->sysenter_return =
26666- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26667+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26668
26669 up_fail:
26670 if (ret)
26671- current->mm->context.vdso = NULL;
26672+ current->mm->context.vdso = 0;
26673
26674 up_write(&mm->mmap_sem);
26675
26676@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
26677
26678 const char *arch_vma_name(struct vm_area_struct *vma)
26679 {
26680- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26681+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26682 return "[vdso]";
26683+
26684+#ifdef CONFIG_PAX_SEGMEXEC
26685+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26686+ return "[vdso]";
26687+#endif
26688+
26689 return NULL;
26690 }
26691
26692@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
26693 struct mm_struct *mm = tsk->mm;
26694
26695 /* Check to see if this task was created in compat vdso mode */
26696- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26697+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26698 return &gate_vma;
26699 return NULL;
26700 }
26701diff --git a/arch/x86/vdso/vextern.h b/arch/x86/vdso/vextern.h
26702index 1683ba2..48d07f3 100644
26703--- a/arch/x86/vdso/vextern.h
26704+++ b/arch/x86/vdso/vextern.h
26705@@ -11,6 +11,5 @@
26706 put into vextern.h and be referenced as a pointer with vdso prefix.
26707 The main kernel later fills in the values. */
26708
26709-VEXTERN(jiffies)
26710 VEXTERN(vgetcpu_mode)
26711 VEXTERN(vsyscall_gtod_data)
26712diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26713index 21e1aeb..2c0b3c4 100644
26714--- a/arch/x86/vdso/vma.c
26715+++ b/arch/x86/vdso/vma.c
26716@@ -17,8 +17,6 @@
26717 #include "vextern.h" /* Just for VMAGIC. */
26718 #undef VEXTERN
26719
26720-unsigned int __read_mostly vdso_enabled = 1;
26721-
26722 extern char vdso_start[], vdso_end[];
26723 extern unsigned short vdso_sync_cpuid;
26724
26725@@ -27,10 +25,8 @@ static unsigned vdso_size;
26726
26727 static inline void *var_ref(void *p, char *name)
26728 {
26729- if (*(void **)p != (void *)VMAGIC) {
26730- printk("VDSO: variable %s broken\n", name);
26731- vdso_enabled = 0;
26732- }
26733+ if (*(void **)p != (void *)VMAGIC)
26734+ panic("VDSO: variable %s broken\n", name);
26735 return p;
26736 }
26737
26738@@ -57,21 +53,18 @@ static int __init init_vdso_vars(void)
26739 if (!vbase)
26740 goto oom;
26741
26742- if (memcmp(vbase, "\177ELF", 4)) {
26743- printk("VDSO: I'm broken; not ELF\n");
26744- vdso_enabled = 0;
26745- }
26746+ if (memcmp(vbase, ELFMAG, SELFMAG))
26747+ panic("VDSO: I'm broken; not ELF\n");
26748
26749 #define VEXTERN(x) \
26750 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
26751 #include "vextern.h"
26752 #undef VEXTERN
26753+ vunmap(vbase);
26754 return 0;
26755
26756 oom:
26757- printk("Cannot allocate vdso\n");
26758- vdso_enabled = 0;
26759- return -ENOMEM;
26760+ panic("Cannot allocate vdso\n");
26761 }
26762 __initcall(init_vdso_vars);
26763
26764@@ -102,13 +95,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26765 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26766 {
26767 struct mm_struct *mm = current->mm;
26768- unsigned long addr;
26769+ unsigned long addr = 0;
26770 int ret;
26771
26772- if (!vdso_enabled)
26773- return 0;
26774-
26775 down_write(&mm->mmap_sem);
26776+
26777+#ifdef CONFIG_PAX_RANDMMAP
26778+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26779+#endif
26780+
26781 addr = vdso_addr(mm->start_stack, vdso_size);
26782 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26783 if (IS_ERR_VALUE(addr)) {
26784@@ -116,7 +111,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26785 goto up_fail;
26786 }
26787
26788- current->mm->context.vdso = (void *)addr;
26789+ current->mm->context.vdso = addr;
26790
26791 ret = install_special_mapping(mm, addr, vdso_size,
26792 VM_READ|VM_EXEC|
26793@@ -124,7 +119,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26794 VM_ALWAYSDUMP,
26795 vdso_pages);
26796 if (ret) {
26797- current->mm->context.vdso = NULL;
26798+ current->mm->context.vdso = 0;
26799 goto up_fail;
26800 }
26801
26802@@ -132,10 +127,3 @@ up_fail:
26803 up_write(&mm->mmap_sem);
26804 return ret;
26805 }
26806-
26807-static __init int vdso_setup(char *s)
26808-{
26809- vdso_enabled = simple_strtoul(s, NULL, 0);
26810- return 0;
26811-}
26812-__setup("vdso=", vdso_setup);
26813diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26814index 0087b00..eecb34f 100644
26815--- a/arch/x86/xen/enlighten.c
26816+++ b/arch/x86/xen/enlighten.c
26817@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26818
26819 struct shared_info xen_dummy_shared_info;
26820
26821-void *xen_initial_gdt;
26822-
26823 /*
26824 * Point at some empty memory to start with. We map the real shared_info
26825 * page as soon as fixmap is up and running.
26826@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g)
26827
26828 preempt_disable();
26829
26830- start = __get_cpu_var(idt_desc).address;
26831+ start = (unsigned long)__get_cpu_var(idt_desc).address;
26832 end = start + __get_cpu_var(idt_desc).size + 1;
26833
26834 xen_mc_flush();
26835@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic_ops __initdata = {
26836 #endif
26837 };
26838
26839-static void xen_reboot(int reason)
26840+static __noreturn void xen_reboot(int reason)
26841 {
26842 struct sched_shutdown r = { .reason = reason };
26843
26844@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
26845 BUG();
26846 }
26847
26848-static void xen_restart(char *msg)
26849+static __noreturn void xen_restart(char *msg)
26850 {
26851 xen_reboot(SHUTDOWN_reboot);
26852 }
26853
26854-static void xen_emergency_restart(void)
26855+static __noreturn void xen_emergency_restart(void)
26856 {
26857 xen_reboot(SHUTDOWN_reboot);
26858 }
26859
26860-static void xen_machine_halt(void)
26861+static __noreturn void xen_machine_halt(void)
26862 {
26863 xen_reboot(SHUTDOWN_poweroff);
26864 }
26865@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(void)
26866 */
26867 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26868
26869-#ifdef CONFIG_X86_64
26870 /* Work out if we support NX */
26871- check_efer();
26872+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26873+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26874+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26875+ unsigned l, h;
26876+
26877+#ifdef CONFIG_X86_PAE
26878+ nx_enabled = 1;
26879+#endif
26880+ __supported_pte_mask |= _PAGE_NX;
26881+ rdmsr(MSR_EFER, l, h);
26882+ l |= EFER_NX;
26883+ wrmsr(MSR_EFER, l, h);
26884+ }
26885 #endif
26886
26887 xen_setup_features();
26888@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(void)
26889
26890 machine_ops = xen_machine_ops;
26891
26892- /*
26893- * The only reliable way to retain the initial address of the
26894- * percpu gdt_page is to remember it here, so we can go and
26895- * mark it RW later, when the initial percpu area is freed.
26896- */
26897- xen_initial_gdt = &per_cpu(gdt_page, 0);
26898-
26899 xen_smp_init();
26900
26901 pgd = (pgd_t *)xen_start_info->pt_base;
26902diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26903index 3f90a2c..2c2ad84 100644
26904--- a/arch/x86/xen/mmu.c
26905+++ b/arch/x86/xen/mmu.c
26906@@ -1719,6 +1719,9 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26907 convert_pfn_mfn(init_level4_pgt);
26908 convert_pfn_mfn(level3_ident_pgt);
26909 convert_pfn_mfn(level3_kernel_pgt);
26910+ convert_pfn_mfn(level3_vmalloc_start_pgt);
26911+ convert_pfn_mfn(level3_vmalloc_end_pgt);
26912+ convert_pfn_mfn(level3_vmemmap_pgt);
26913
26914 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26915 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26916@@ -1737,7 +1740,11 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26917 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26918 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26919 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26920+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26921+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26922+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26923 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26924+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26925 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26926 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26927
26928@@ -1860,6 +1867,7 @@ static __init void xen_post_allocator_init(void)
26929 pv_mmu_ops.set_pud = xen_set_pud;
26930 #if PAGETABLE_LEVELS == 4
26931 pv_mmu_ops.set_pgd = xen_set_pgd;
26932+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26933 #endif
26934
26935 /* This will work as long as patching hasn't happened yet
26936@@ -1946,6 +1954,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
26937 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26938 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26939 .set_pgd = xen_set_pgd_hyper,
26940+ .set_pgd_batched = xen_set_pgd_hyper,
26941
26942 .alloc_pud = xen_alloc_pmd_init,
26943 .release_pud = xen_release_pmd_init,
26944diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26945index a96204a..fca9b8e 100644
26946--- a/arch/x86/xen/smp.c
26947+++ b/arch/x86/xen/smp.c
26948@@ -168,11 +168,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26949 {
26950 BUG_ON(smp_processor_id() != 0);
26951 native_smp_prepare_boot_cpu();
26952-
26953- /* We've switched to the "real" per-cpu gdt, so make sure the
26954- old memory can be recycled */
26955- make_lowmem_page_readwrite(xen_initial_gdt);
26956-
26957 xen_setup_vcpu_info_placement();
26958 }
26959
26960@@ -241,12 +236,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26961 gdt = get_cpu_gdt_table(cpu);
26962
26963 ctxt->flags = VGCF_IN_KERNEL;
26964- ctxt->user_regs.ds = __USER_DS;
26965- ctxt->user_regs.es = __USER_DS;
26966+ ctxt->user_regs.ds = __KERNEL_DS;
26967+ ctxt->user_regs.es = __KERNEL_DS;
26968 ctxt->user_regs.ss = __KERNEL_DS;
26969 #ifdef CONFIG_X86_32
26970 ctxt->user_regs.fs = __KERNEL_PERCPU;
26971- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26972+ savesegment(gs, ctxt->user_regs.gs);
26973 #else
26974 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26975 #endif
26976@@ -297,13 +292,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26977 int rc;
26978
26979 per_cpu(current_task, cpu) = idle;
26980+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26981 #ifdef CONFIG_X86_32
26982 irq_ctx_init(cpu);
26983 #else
26984 clear_tsk_thread_flag(idle, TIF_FORK);
26985- per_cpu(kernel_stack, cpu) =
26986- (unsigned long)task_stack_page(idle) -
26987- KERNEL_STACK_OFFSET + THREAD_SIZE;
26988+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26989 #endif
26990 xen_setup_runstate_info(cpu);
26991 xen_setup_timer(cpu);
26992diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26993index 9a95a9c..4f39e774 100644
26994--- a/arch/x86/xen/xen-asm_32.S
26995+++ b/arch/x86/xen/xen-asm_32.S
26996@@ -83,14 +83,14 @@ ENTRY(xen_iret)
26997 ESP_OFFSET=4 # bytes pushed onto stack
26998
26999 /*
27000- * Store vcpu_info pointer for easy access. Do it this way to
27001- * avoid having to reload %fs
27002+ * Store vcpu_info pointer for easy access.
27003 */
27004 #ifdef CONFIG_SMP
27005- GET_THREAD_INFO(%eax)
27006- movl TI_cpu(%eax), %eax
27007- movl __per_cpu_offset(,%eax,4), %eax
27008- mov per_cpu__xen_vcpu(%eax), %eax
27009+ push %fs
27010+ mov $(__KERNEL_PERCPU), %eax
27011+ mov %eax, %fs
27012+ mov PER_CPU_VAR(xen_vcpu), %eax
27013+ pop %fs
27014 #else
27015 movl per_cpu__xen_vcpu, %eax
27016 #endif
27017diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27018index 1a5ff24..a187d40 100644
27019--- a/arch/x86/xen/xen-head.S
27020+++ b/arch/x86/xen/xen-head.S
27021@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27022 #ifdef CONFIG_X86_32
27023 mov %esi,xen_start_info
27024 mov $init_thread_union+THREAD_SIZE,%esp
27025+#ifdef CONFIG_SMP
27026+ movl $cpu_gdt_table,%edi
27027+ movl $__per_cpu_load,%eax
27028+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27029+ rorl $16,%eax
27030+ movb %al,__KERNEL_PERCPU + 4(%edi)
27031+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27032+ movl $__per_cpu_end - 1,%eax
27033+ subl $__per_cpu_start,%eax
27034+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27035+#endif
27036 #else
27037 mov %rsi,xen_start_info
27038 mov $init_thread_union+THREAD_SIZE,%rsp
27039diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27040index f9153a3..51eab3d 100644
27041--- a/arch/x86/xen/xen-ops.h
27042+++ b/arch/x86/xen/xen-ops.h
27043@@ -10,8 +10,6 @@
27044 extern const char xen_hypervisor_callback[];
27045 extern const char xen_failsafe_callback[];
27046
27047-extern void *xen_initial_gdt;
27048-
27049 struct trap_info;
27050 void xen_copy_trap_info(struct trap_info *traps);
27051
27052diff --git a/block/blk-integrity.c b/block/blk-integrity.c
27053index 15c6308..96e83c2 100644
27054--- a/block/blk-integrity.c
27055+++ b/block/blk-integrity.c
27056@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs[] = {
27057 NULL,
27058 };
27059
27060-static struct sysfs_ops integrity_ops = {
27061+static const struct sysfs_ops integrity_ops = {
27062 .show = &integrity_attr_show,
27063 .store = &integrity_attr_store,
27064 };
27065diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27066index ca56420..f2fc409 100644
27067--- a/block/blk-iopoll.c
27068+++ b/block/blk-iopoll.c
27069@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27070 }
27071 EXPORT_SYMBOL(blk_iopoll_complete);
27072
27073-static void blk_iopoll_softirq(struct softirq_action *h)
27074+static void blk_iopoll_softirq(void)
27075 {
27076 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27077 int rearm = 0, budget = blk_iopoll_budget;
27078diff --git a/block/blk-map.c b/block/blk-map.c
27079index 30a7e51..0aeec6a 100644
27080--- a/block/blk-map.c
27081+++ b/block/blk-map.c
27082@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
27083 * direct dma. else, set up kernel bounce buffers
27084 */
27085 uaddr = (unsigned long) ubuf;
27086- if (blk_rq_aligned(q, ubuf, len) && !map_data)
27087+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
27088 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
27089 else
27090 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
27091@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
27092 for (i = 0; i < iov_count; i++) {
27093 unsigned long uaddr = (unsigned long)iov[i].iov_base;
27094
27095+ if (!iov[i].iov_len)
27096+ return -EINVAL;
27097+
27098 if (uaddr & queue_dma_alignment(q)) {
27099 unaligned = 1;
27100 break;
27101 }
27102- if (!iov[i].iov_len)
27103- return -EINVAL;
27104 }
27105
27106 if (unaligned || (q->dma_pad_mask & len) || map_data)
27107@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27108 if (!len || !kbuf)
27109 return -EINVAL;
27110
27111- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
27112+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
27113 if (do_copy)
27114 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27115 else
27116diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27117index ee9c216..58d410a 100644
27118--- a/block/blk-softirq.c
27119+++ b/block/blk-softirq.c
27120@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27121 * Softirq action handler - move entries to local list and loop over them
27122 * while passing them to the queue registered handler.
27123 */
27124-static void blk_done_softirq(struct softirq_action *h)
27125+static void blk_done_softirq(void)
27126 {
27127 struct list_head *cpu_list, local_list;
27128
27129diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
27130index bb9c5ea..5330d48 100644
27131--- a/block/blk-sysfs.c
27132+++ b/block/blk-sysfs.c
27133@@ -414,7 +414,7 @@ static void blk_release_queue(struct kobject *kobj)
27134 kmem_cache_free(blk_requestq_cachep, q);
27135 }
27136
27137-static struct sysfs_ops queue_sysfs_ops = {
27138+static const struct sysfs_ops queue_sysfs_ops = {
27139 .show = queue_attr_show,
27140 .store = queue_attr_store,
27141 };
27142diff --git a/block/bsg.c b/block/bsg.c
27143index 7154a7a..08ac2f0 100644
27144--- a/block/bsg.c
27145+++ b/block/bsg.c
27146@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27147 struct sg_io_v4 *hdr, struct bsg_device *bd,
27148 fmode_t has_write_perm)
27149 {
27150+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27151+ unsigned char *cmdptr;
27152+
27153 if (hdr->request_len > BLK_MAX_CDB) {
27154 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27155 if (!rq->cmd)
27156 return -ENOMEM;
27157- }
27158+ cmdptr = rq->cmd;
27159+ } else
27160+ cmdptr = tmpcmd;
27161
27162- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
27163+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27164 hdr->request_len))
27165 return -EFAULT;
27166
27167+ if (cmdptr != rq->cmd)
27168+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27169+
27170 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27171 if (blk_verify_command(rq->cmd, has_write_perm))
27172 return -EPERM;
27173@@ -282,7 +290,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27174 rq->next_rq = next_rq;
27175 next_rq->cmd_type = rq->cmd_type;
27176
27177- dxferp = (void*)(unsigned long)hdr->din_xferp;
27178+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27179 ret = blk_rq_map_user(q, next_rq, NULL, dxferp,
27180 hdr->din_xfer_len, GFP_KERNEL);
27181 if (ret)
27182@@ -291,10 +299,10 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27183
27184 if (hdr->dout_xfer_len) {
27185 dxfer_len = hdr->dout_xfer_len;
27186- dxferp = (void*)(unsigned long)hdr->dout_xferp;
27187+ dxferp = (void __user *)(unsigned long)hdr->dout_xferp;
27188 } else if (hdr->din_xfer_len) {
27189 dxfer_len = hdr->din_xfer_len;
27190- dxferp = (void*)(unsigned long)hdr->din_xferp;
27191+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27192 } else
27193 dxfer_len = 0;
27194
27195@@ -436,7 +444,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
27196 int len = min_t(unsigned int, hdr->max_response_len,
27197 rq->sense_len);
27198
27199- ret = copy_to_user((void*)(unsigned long)hdr->response,
27200+ ret = copy_to_user((void __user *)(unsigned long)hdr->response,
27201 rq->sense, len);
27202 if (!ret)
27203 hdr->response_len = len;
27204diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27205index 9bd086c..ca1fc22 100644
27206--- a/block/compat_ioctl.c
27207+++ b/block/compat_ioctl.c
27208@@ -354,7 +354,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27209 err |= __get_user(f->spec1, &uf->spec1);
27210 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27211 err |= __get_user(name, &uf->name);
27212- f->name = compat_ptr(name);
27213+ f->name = (void __force_kernel *)compat_ptr(name);
27214 if (err) {
27215 err = -EFAULT;
27216 goto out;
27217diff --git a/block/elevator.c b/block/elevator.c
27218index a847046..75a1746 100644
27219--- a/block/elevator.c
27220+++ b/block/elevator.c
27221@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
27222 return error;
27223 }
27224
27225-static struct sysfs_ops elv_sysfs_ops = {
27226+static const struct sysfs_ops elv_sysfs_ops = {
27227 .show = elv_attr_show,
27228 .store = elv_attr_store,
27229 };
27230diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27231index 1d5a780..0e2fb8c 100644
27232--- a/block/scsi_ioctl.c
27233+++ b/block/scsi_ioctl.c
27234@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
27235 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27236 struct sg_io_hdr *hdr, fmode_t mode)
27237 {
27238- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27239+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27240+ unsigned char *cmdptr;
27241+
27242+ if (rq->cmd != rq->__cmd)
27243+ cmdptr = rq->cmd;
27244+ else
27245+ cmdptr = tmpcmd;
27246+
27247+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27248 return -EFAULT;
27249+
27250+ if (cmdptr != rq->cmd)
27251+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27252+
27253 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27254 return -EPERM;
27255
27256@@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27257 int err;
27258 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27259 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27260+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27261+ unsigned char *cmdptr;
27262
27263 if (!sic)
27264 return -EINVAL;
27265@@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27266 */
27267 err = -EFAULT;
27268 rq->cmd_len = cmdlen;
27269- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27270+
27271+ if (rq->cmd != rq->__cmd)
27272+ cmdptr = rq->cmd;
27273+ else
27274+ cmdptr = tmpcmd;
27275+
27276+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27277 goto error;
27278
27279+ if (rq->cmd != cmdptr)
27280+ memcpy(rq->cmd, cmdptr, cmdlen);
27281+
27282 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27283 goto error;
27284
27285diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27286index 3533582..f143117 100644
27287--- a/crypto/cryptd.c
27288+++ b/crypto/cryptd.c
27289@@ -50,7 +50,7 @@ struct cryptd_blkcipher_ctx {
27290
27291 struct cryptd_blkcipher_request_ctx {
27292 crypto_completion_t complete;
27293-};
27294+} __no_const;
27295
27296 struct cryptd_hash_ctx {
27297 struct crypto_shash *child;
27298diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c
27299index a90d260..7a9765e 100644
27300--- a/crypto/gf128mul.c
27301+++ b/crypto/gf128mul.c
27302@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128 *b)
27303 for (i = 0; i < 7; ++i)
27304 gf128mul_x_lle(&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)[15 - i];
27310
27311@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128 *b)
27312 for (i = 0; i < 7; ++i)
27313 gf128mul_x_bbe(&p[i + 1], &p[i]);
27314
27315- memset(r, 0, sizeof(r));
27316+ memset(r, 0, sizeof(*r));
27317 for (i = 0;;) {
27318 u8 ch = ((u8 *)b)[i];
27319
27320diff --git a/crypto/serpent.c b/crypto/serpent.c
27321index b651a55..023297d 100644
27322--- a/crypto/serpent.c
27323+++ b/crypto/serpent.c
27324@@ -21,6 +21,7 @@
27325 #include <asm/byteorder.h>
27326 #include <linux/crypto.h>
27327 #include <linux/types.h>
27328+#include <linux/sched.h>
27329
27330 /* Key is padded to the maximum of 256 bits before round key generation.
27331 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
27332@@ -224,6 +225,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
27333 u32 r0,r1,r2,r3,r4;
27334 int i;
27335
27336+ pax_track_stack();
27337+
27338 /* Copy key, add padding */
27339
27340 for (i = 0; i < keylen; ++i)
27341diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
27342index 0d2cdb8..d8de48d 100644
27343--- a/drivers/acpi/acpi_pad.c
27344+++ b/drivers/acpi/acpi_pad.c
27345@@ -30,7 +30,7 @@
27346 #include <acpi/acpi_bus.h>
27347 #include <acpi/acpi_drivers.h>
27348
27349-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
27350+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
27351 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
27352 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
27353 static DEFINE_MUTEX(isolated_cpus_lock);
27354diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27355index 3f4602b..2e41d36 100644
27356--- a/drivers/acpi/battery.c
27357+++ b/drivers/acpi/battery.c
27358@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
27359 }
27360
27361 static struct battery_file {
27362- struct file_operations ops;
27363+ const struct file_operations ops;
27364 mode_t mode;
27365 const char *name;
27366 } acpi_battery_file[] = {
27367diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
27368index 7338b6a..82f0257 100644
27369--- a/drivers/acpi/dock.c
27370+++ b/drivers/acpi/dock.c
27371@@ -77,7 +77,7 @@ struct dock_dependent_device {
27372 struct list_head list;
27373 struct list_head hotplug_list;
27374 acpi_handle handle;
27375- struct acpi_dock_ops *ops;
27376+ const struct acpi_dock_ops *ops;
27377 void *context;
27378 };
27379
27380@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
27381 * the dock driver after _DCK is executed.
27382 */
27383 int
27384-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
27385+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
27386 void *context)
27387 {
27388 struct dock_dependent_device *dd;
27389diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
27390index 7c1c59e..2993595 100644
27391--- a/drivers/acpi/osl.c
27392+++ b/drivers/acpi/osl.c
27393@@ -523,6 +523,8 @@ acpi_os_read_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 if (!value)
27400 value = &dummy;
27401
27402@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
27403 void __iomem *virt_addr;
27404
27405 virt_addr = ioremap(phys_addr, width);
27406+ if (!virt_addr)
27407+ return AE_NO_MEMORY;
27408
27409 switch (width) {
27410 case 8:
27411diff --git a/drivers/acpi/power_meter.c b/drivers/acpi/power_meter.c
27412index c216062..eec10d2 100644
27413--- a/drivers/acpi/power_meter.c
27414+++ b/drivers/acpi/power_meter.c
27415@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
27416 return res;
27417
27418 temp /= 1000;
27419- if (temp < 0)
27420- return -EINVAL;
27421
27422 mutex_lock(&resource->lock);
27423 resource->trip[attr->index - 7] = temp;
27424diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27425index d0d25e2..961643d 100644
27426--- a/drivers/acpi/proc.c
27427+++ b/drivers/acpi/proc.c
27428@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct file *file,
27429 size_t count, loff_t * ppos)
27430 {
27431 struct list_head *node, *next;
27432- char strbuf[5];
27433- char str[5] = "";
27434- unsigned int len = count;
27435+ char strbuf[5] = {0};
27436 struct acpi_device *found_dev = NULL;
27437
27438- if (len > 4)
27439- len = 4;
27440- if (len < 0)
27441- return -EFAULT;
27442+ if (count > 4)
27443+ count = 4;
27444
27445- if (copy_from_user(strbuf, buffer, len))
27446+ if (copy_from_user(strbuf, buffer, count))
27447 return -EFAULT;
27448- strbuf[len] = '\0';
27449- sscanf(strbuf, "%s", str);
27450+ strbuf[count] = '\0';
27451
27452 mutex_lock(&acpi_device_lock);
27453 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27454@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct file *file,
27455 if (!dev->wakeup.flags.valid)
27456 continue;
27457
27458- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27459+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27460 dev->wakeup.state.enabled =
27461 dev->wakeup.state.enabled ? 0 : 1;
27462 found_dev = dev;
27463diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
27464index 7102474..de8ad22 100644
27465--- a/drivers/acpi/processor_core.c
27466+++ b/drivers/acpi/processor_core.c
27467@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27468 return 0;
27469 }
27470
27471- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27472+ BUG_ON(pr->id >= nr_cpu_ids);
27473
27474 /*
27475 * Buggy BIOS check
27476diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
27477index d933980..5761f13 100644
27478--- a/drivers/acpi/sbshc.c
27479+++ b/drivers/acpi/sbshc.c
27480@@ -17,7 +17,7 @@
27481
27482 #define PREFIX "ACPI: "
27483
27484-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
27485+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
27486 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
27487
27488 struct acpi_smb_hc {
27489diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
27490index 0458094..6978e7b 100644
27491--- a/drivers/acpi/sleep.c
27492+++ b/drivers/acpi/sleep.c
27493@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
27494 }
27495 }
27496
27497-static struct platform_suspend_ops acpi_suspend_ops = {
27498+static const struct platform_suspend_ops acpi_suspend_ops = {
27499 .valid = acpi_suspend_state_valid,
27500 .begin = acpi_suspend_begin,
27501 .prepare_late = acpi_pm_prepare,
27502@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
27503 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27504 * been requested.
27505 */
27506-static struct platform_suspend_ops acpi_suspend_ops_old = {
27507+static const struct platform_suspend_ops acpi_suspend_ops_old = {
27508 .valid = acpi_suspend_state_valid,
27509 .begin = acpi_suspend_begin_old,
27510 .prepare_late = acpi_pm_disable_gpes,
27511@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
27512 acpi_enable_all_runtime_gpes();
27513 }
27514
27515-static struct platform_hibernation_ops acpi_hibernation_ops = {
27516+static const struct platform_hibernation_ops acpi_hibernation_ops = {
27517 .begin = acpi_hibernation_begin,
27518 .end = acpi_pm_end,
27519 .pre_snapshot = acpi_hibernation_pre_snapshot,
27520@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
27521 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27522 * been requested.
27523 */
27524-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
27525+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
27526 .begin = acpi_hibernation_begin_old,
27527 .end = acpi_pm_end,
27528 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
27529diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
27530index 05dff63..b662ab7 100644
27531--- a/drivers/acpi/video.c
27532+++ b/drivers/acpi/video.c
27533@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
27534 vd->brightness->levels[request_level]);
27535 }
27536
27537-static struct backlight_ops acpi_backlight_ops = {
27538+static const struct backlight_ops acpi_backlight_ops = {
27539 .get_brightness = acpi_video_get_brightness,
27540 .update_status = acpi_video_set_brightness,
27541 };
27542diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
27543index 6787aab..23ffb0e 100644
27544--- a/drivers/ata/ahci.c
27545+++ b/drivers/ata/ahci.c
27546@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sht = {
27547 .sdev_attrs = ahci_sdev_attrs,
27548 };
27549
27550-static struct ata_port_operations ahci_ops = {
27551+static const struct ata_port_operations ahci_ops = {
27552 .inherits = &sata_pmp_port_ops,
27553
27554 .qc_defer = sata_pmp_qc_defer_cmd_switch,
27555@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_ops = {
27556 .port_stop = ahci_port_stop,
27557 };
27558
27559-static struct ata_port_operations ahci_vt8251_ops = {
27560+static const struct ata_port_operations ahci_vt8251_ops = {
27561 .inherits = &ahci_ops,
27562 .hardreset = ahci_vt8251_hardreset,
27563 };
27564
27565-static struct ata_port_operations ahci_p5wdh_ops = {
27566+static const struct ata_port_operations ahci_p5wdh_ops = {
27567 .inherits = &ahci_ops,
27568 .hardreset = ahci_p5wdh_hardreset,
27569 };
27570
27571-static struct ata_port_operations ahci_sb600_ops = {
27572+static const struct ata_port_operations ahci_sb600_ops = {
27573 .inherits = &ahci_ops,
27574 .softreset = ahci_sb600_softreset,
27575 .pmp_softreset = ahci_sb600_softreset,
27576diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
27577index 99e7196..4968c77 100644
27578--- a/drivers/ata/ata_generic.c
27579+++ b/drivers/ata/ata_generic.c
27580@@ -104,7 +104,7 @@ static struct scsi_host_template generic_sht = {
27581 ATA_BMDMA_SHT(DRV_NAME),
27582 };
27583
27584-static struct ata_port_operations generic_port_ops = {
27585+static const struct ata_port_operations generic_port_ops = {
27586 .inherits = &ata_bmdma_port_ops,
27587 .cable_detect = ata_cable_unknown,
27588 .set_mode = generic_set_mode,
27589diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
27590index c33591d..000c121 100644
27591--- a/drivers/ata/ata_piix.c
27592+++ b/drivers/ata/ata_piix.c
27593@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sht = {
27594 ATA_BMDMA_SHT(DRV_NAME),
27595 };
27596
27597-static struct ata_port_operations piix_pata_ops = {
27598+static const struct ata_port_operations piix_pata_ops = {
27599 .inherits = &ata_bmdma32_port_ops,
27600 .cable_detect = ata_cable_40wire,
27601 .set_piomode = piix_set_piomode,
27602@@ -326,22 +326,22 @@ static struct ata_port_operations piix_pata_ops = {
27603 .prereset = piix_pata_prereset,
27604 };
27605
27606-static struct ata_port_operations piix_vmw_ops = {
27607+static const struct ata_port_operations piix_vmw_ops = {
27608 .inherits = &piix_pata_ops,
27609 .bmdma_status = piix_vmw_bmdma_status,
27610 };
27611
27612-static struct ata_port_operations ich_pata_ops = {
27613+static const struct ata_port_operations ich_pata_ops = {
27614 .inherits = &piix_pata_ops,
27615 .cable_detect = ich_pata_cable_detect,
27616 .set_dmamode = ich_set_dmamode,
27617 };
27618
27619-static struct ata_port_operations piix_sata_ops = {
27620+static const struct ata_port_operations piix_sata_ops = {
27621 .inherits = &ata_bmdma_port_ops,
27622 };
27623
27624-static struct ata_port_operations piix_sidpr_sata_ops = {
27625+static const struct ata_port_operations piix_sidpr_sata_ops = {
27626 .inherits = &piix_sata_ops,
27627 .hardreset = sata_std_hardreset,
27628 .scr_read = piix_sidpr_scr_read,
27629diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
27630index b0882cd..c295d65 100644
27631--- a/drivers/ata/libata-acpi.c
27632+++ b/drivers/ata/libata-acpi.c
27633@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_handle handle, u32 event, void *data)
27634 ata_acpi_uevent(dev->link->ap, dev, event);
27635 }
27636
27637-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27638+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27639 .handler = ata_acpi_dev_notify_dock,
27640 .uevent = ata_acpi_dev_uevent,
27641 };
27642
27643-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27644+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27645 .handler = ata_acpi_ap_notify_dock,
27646 .uevent = ata_acpi_ap_uevent,
27647 };
27648diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27649index d4f7f99..94f603e 100644
27650--- a/drivers/ata/libata-core.c
27651+++ b/drivers/ata/libata-core.c
27652@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27653 struct ata_port *ap;
27654 unsigned int tag;
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 ap = qc->ap;
27659
27660 qc->flags = 0;
27661@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27662 struct ata_port *ap;
27663 struct ata_link *link;
27664
27665- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27666+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27667 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27668 ap = qc->ap;
27669 link = qc->dev->link;
27670@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device *gendev, void *res)
27671 * LOCKING:
27672 * None.
27673 */
27674-static void ata_finalize_port_ops(struct ata_port_operations *ops)
27675+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
27676 {
27677 static DEFINE_SPINLOCK(lock);
27678 const struct ata_port_operations *cur;
27679@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27680 return;
27681
27682 spin_lock(&lock);
27683+ pax_open_kernel();
27684
27685 for (cur = ops->inherits; cur; cur = cur->inherits) {
27686 void **inherit = (void **)cur;
27687@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27688 if (IS_ERR(*pp))
27689 *pp = NULL;
27690
27691- ops->inherits = NULL;
27692+ *(struct ata_port_operations **)&ops->inherits = NULL;
27693
27694+ pax_close_kernel();
27695 spin_unlock(&lock);
27696 }
27697
27698@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host)
27699 */
27700 /* KILLME - the only user left is ipr */
27701 void ata_host_init(struct ata_host *host, struct device *dev,
27702- unsigned long flags, struct ata_port_operations *ops)
27703+ unsigned long flags, const struct ata_port_operations *ops)
27704 {
27705 spin_lock_init(&host->lock);
27706 host->dev = dev;
27707@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(struct ata_port *ap)
27708 /* truly dummy */
27709 }
27710
27711-struct ata_port_operations ata_dummy_port_ops = {
27712+const struct ata_port_operations ata_dummy_port_ops = {
27713 .qc_prep = ata_noop_qc_prep,
27714 .qc_issue = ata_dummy_qc_issue,
27715 .error_handler = ata_dummy_error_handler,
27716diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
27717index e5bdb9b..45a8e72 100644
27718--- a/drivers/ata/libata-eh.c
27719+++ b/drivers/ata/libata-eh.c
27720@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
27721 {
27722 struct ata_link *link;
27723
27724+ pax_track_stack();
27725+
27726 ata_for_each_link(link, ap, HOST_FIRST)
27727 ata_eh_link_report(link);
27728 }
27729@@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
27730 */
27731 void ata_std_error_handler(struct ata_port *ap)
27732 {
27733- struct ata_port_operations *ops = ap->ops;
27734+ const struct ata_port_operations *ops = ap->ops;
27735 ata_reset_fn_t hardreset = ops->hardreset;
27736
27737 /* ignore built-in hardreset if SCR access is not available */
27738diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
27739index 51f0ffb..19ce3e3 100644
27740--- a/drivers/ata/libata-pmp.c
27741+++ b/drivers/ata/libata-pmp.c
27742@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
27743 */
27744 static int sata_pmp_eh_recover(struct ata_port *ap)
27745 {
27746- struct ata_port_operations *ops = ap->ops;
27747+ const struct ata_port_operations *ops = ap->ops;
27748 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
27749 struct ata_link *pmp_link = &ap->link;
27750 struct ata_device *pmp_dev = pmp_link->device;
27751diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
27752index d8f35fe..288180a 100644
27753--- a/drivers/ata/pata_acpi.c
27754+++ b/drivers/ata/pata_acpi.c
27755@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_sht = {
27756 ATA_BMDMA_SHT(DRV_NAME),
27757 };
27758
27759-static struct ata_port_operations pacpi_ops = {
27760+static const struct ata_port_operations pacpi_ops = {
27761 .inherits = &ata_bmdma_port_ops,
27762 .qc_issue = pacpi_qc_issue,
27763 .cable_detect = pacpi_cable_detect,
27764diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
27765index 9434114..1f2f364 100644
27766--- a/drivers/ata/pata_ali.c
27767+++ b/drivers/ata/pata_ali.c
27768@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht = {
27769 * Port operations for PIO only ALi
27770 */
27771
27772-static struct ata_port_operations ali_early_port_ops = {
27773+static const struct ata_port_operations ali_early_port_ops = {
27774 .inherits = &ata_sff_port_ops,
27775 .cable_detect = ata_cable_40wire,
27776 .set_piomode = ali_set_piomode,
27777@@ -382,7 +382,7 @@ static const struct ata_port_operations ali_dma_base_ops = {
27778 * Port operations for DMA capable ALi without cable
27779 * detect
27780 */
27781-static struct ata_port_operations ali_20_port_ops = {
27782+static const struct ata_port_operations ali_20_port_ops = {
27783 .inherits = &ali_dma_base_ops,
27784 .cable_detect = ata_cable_40wire,
27785 .mode_filter = ali_20_filter,
27786@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20_port_ops = {
27787 /*
27788 * Port operations for DMA capable ALi with cable detect
27789 */
27790-static struct ata_port_operations ali_c2_port_ops = {
27791+static const struct ata_port_operations ali_c2_port_ops = {
27792 .inherits = &ali_dma_base_ops,
27793 .check_atapi_dma = ali_check_atapi_dma,
27794 .cable_detect = ali_c2_cable_detect,
27795@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2_port_ops = {
27796 /*
27797 * Port operations for DMA capable ALi with cable detect
27798 */
27799-static struct ata_port_operations ali_c4_port_ops = {
27800+static const struct ata_port_operations ali_c4_port_ops = {
27801 .inherits = &ali_dma_base_ops,
27802 .check_atapi_dma = ali_check_atapi_dma,
27803 .cable_detect = ali_c2_cable_detect,
27804@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4_port_ops = {
27805 /*
27806 * Port operations for DMA capable ALi with cable detect and LBA48
27807 */
27808-static struct ata_port_operations ali_c5_port_ops = {
27809+static const struct ata_port_operations ali_c5_port_ops = {
27810 .inherits = &ali_dma_base_ops,
27811 .check_atapi_dma = ali_check_atapi_dma,
27812 .dev_config = ali_warn_atapi_dma,
27813diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
27814index 567f3f7..c8ee0da 100644
27815--- a/drivers/ata/pata_amd.c
27816+++ b/drivers/ata/pata_amd.c
27817@@ -397,28 +397,28 @@ static const struct ata_port_operations amd_base_port_ops = {
27818 .prereset = amd_pre_reset,
27819 };
27820
27821-static struct ata_port_operations amd33_port_ops = {
27822+static const struct ata_port_operations amd33_port_ops = {
27823 .inherits = &amd_base_port_ops,
27824 .cable_detect = ata_cable_40wire,
27825 .set_piomode = amd33_set_piomode,
27826 .set_dmamode = amd33_set_dmamode,
27827 };
27828
27829-static struct ata_port_operations amd66_port_ops = {
27830+static const struct ata_port_operations amd66_port_ops = {
27831 .inherits = &amd_base_port_ops,
27832 .cable_detect = ata_cable_unknown,
27833 .set_piomode = amd66_set_piomode,
27834 .set_dmamode = amd66_set_dmamode,
27835 };
27836
27837-static struct ata_port_operations amd100_port_ops = {
27838+static const struct ata_port_operations amd100_port_ops = {
27839 .inherits = &amd_base_port_ops,
27840 .cable_detect = ata_cable_unknown,
27841 .set_piomode = amd100_set_piomode,
27842 .set_dmamode = amd100_set_dmamode,
27843 };
27844
27845-static struct ata_port_operations amd133_port_ops = {
27846+static const struct ata_port_operations amd133_port_ops = {
27847 .inherits = &amd_base_port_ops,
27848 .cable_detect = amd_cable_detect,
27849 .set_piomode = amd133_set_piomode,
27850@@ -433,13 +433,13 @@ static const struct ata_port_operations nv_base_port_ops = {
27851 .host_stop = nv_host_stop,
27852 };
27853
27854-static struct ata_port_operations nv100_port_ops = {
27855+static const struct ata_port_operations nv100_port_ops = {
27856 .inherits = &nv_base_port_ops,
27857 .set_piomode = nv100_set_piomode,
27858 .set_dmamode = nv100_set_dmamode,
27859 };
27860
27861-static struct ata_port_operations nv133_port_ops = {
27862+static const struct ata_port_operations nv133_port_ops = {
27863 .inherits = &nv_base_port_ops,
27864 .set_piomode = nv133_set_piomode,
27865 .set_dmamode = nv133_set_dmamode,
27866diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
27867index d332cfd..4b7eaae 100644
27868--- a/drivers/ata/pata_artop.c
27869+++ b/drivers/ata/pata_artop.c
27870@@ -311,7 +311,7 @@ static struct scsi_host_template artop_sht = {
27871 ATA_BMDMA_SHT(DRV_NAME),
27872 };
27873
27874-static struct ata_port_operations artop6210_ops = {
27875+static const struct ata_port_operations artop6210_ops = {
27876 .inherits = &ata_bmdma_port_ops,
27877 .cable_detect = ata_cable_40wire,
27878 .set_piomode = artop6210_set_piomode,
27879@@ -320,7 +320,7 @@ static struct ata_port_operations artop6210_ops = {
27880 .qc_defer = artop6210_qc_defer,
27881 };
27882
27883-static struct ata_port_operations artop6260_ops = {
27884+static const struct ata_port_operations artop6260_ops = {
27885 .inherits = &ata_bmdma_port_ops,
27886 .cable_detect = artop6260_cable_detect,
27887 .set_piomode = artop6260_set_piomode,
27888diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
27889index 5c129f9..7bb7ccb 100644
27890--- a/drivers/ata/pata_at32.c
27891+++ b/drivers/ata/pata_at32.c
27892@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sht = {
27893 ATA_PIO_SHT(DRV_NAME),
27894 };
27895
27896-static struct ata_port_operations at32_port_ops = {
27897+static const struct ata_port_operations at32_port_ops = {
27898 .inherits = &ata_sff_port_ops,
27899 .cable_detect = ata_cable_40wire,
27900 .set_piomode = pata_at32_set_piomode,
27901diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
27902index 41c94b1..829006d 100644
27903--- a/drivers/ata/pata_at91.c
27904+++ b/drivers/ata/pata_at91.c
27905@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at91_sht = {
27906 ATA_PIO_SHT(DRV_NAME),
27907 };
27908
27909-static struct ata_port_operations pata_at91_port_ops = {
27910+static const struct ata_port_operations pata_at91_port_ops = {
27911 .inherits = &ata_sff_port_ops,
27912
27913 .sff_data_xfer = pata_at91_data_xfer_noirq,
27914diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
27915index ae4454d..d391eb4 100644
27916--- a/drivers/ata/pata_atiixp.c
27917+++ b/drivers/ata/pata_atiixp.c
27918@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_sht = {
27919 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27920 };
27921
27922-static struct ata_port_operations atiixp_port_ops = {
27923+static const struct ata_port_operations atiixp_port_ops = {
27924 .inherits = &ata_bmdma_port_ops,
27925
27926 .qc_prep = ata_sff_dumb_qc_prep,
27927diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c
27928index 6fe7ded..2a425dc 100644
27929--- a/drivers/ata/pata_atp867x.c
27930+++ b/drivers/ata/pata_atp867x.c
27931@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x_sht = {
27932 ATA_BMDMA_SHT(DRV_NAME),
27933 };
27934
27935-static struct ata_port_operations atp867x_ops = {
27936+static const struct ata_port_operations atp867x_ops = {
27937 .inherits = &ata_bmdma_port_ops,
27938 .cable_detect = atp867x_cable_detect,
27939 .set_piomode = atp867x_set_piomode,
27940diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
27941index c4b47a3..b27a367 100644
27942--- a/drivers/ata/pata_bf54x.c
27943+++ b/drivers/ata/pata_bf54x.c
27944@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sht = {
27945 .dma_boundary = ATA_DMA_BOUNDARY,
27946 };
27947
27948-static struct ata_port_operations bfin_pata_ops = {
27949+static const struct ata_port_operations bfin_pata_ops = {
27950 .inherits = &ata_sff_port_ops,
27951
27952 .set_piomode = bfin_set_piomode,
27953diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
27954index 5acf9fa..84248be 100644
27955--- a/drivers/ata/pata_cmd640.c
27956+++ b/drivers/ata/pata_cmd640.c
27957@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_sht = {
27958 ATA_BMDMA_SHT(DRV_NAME),
27959 };
27960
27961-static struct ata_port_operations cmd640_port_ops = {
27962+static const struct ata_port_operations cmd640_port_ops = {
27963 .inherits = &ata_bmdma_port_ops,
27964 /* In theory xfer_noirq is not needed once we kill the prefetcher */
27965 .sff_data_xfer = ata_sff_data_xfer_noirq,
27966diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
27967index ccd2694..c869c3d 100644
27968--- a/drivers/ata/pata_cmd64x.c
27969+++ b/drivers/ata/pata_cmd64x.c
27970@@ -271,18 +271,18 @@ static const struct ata_port_operations cmd64x_base_ops = {
27971 .set_dmamode = cmd64x_set_dmamode,
27972 };
27973
27974-static struct ata_port_operations cmd64x_port_ops = {
27975+static const struct ata_port_operations cmd64x_port_ops = {
27976 .inherits = &cmd64x_base_ops,
27977 .cable_detect = ata_cable_40wire,
27978 };
27979
27980-static struct ata_port_operations cmd646r1_port_ops = {
27981+static const struct ata_port_operations cmd646r1_port_ops = {
27982 .inherits = &cmd64x_base_ops,
27983 .bmdma_stop = cmd646r1_bmdma_stop,
27984 .cable_detect = ata_cable_40wire,
27985 };
27986
27987-static struct ata_port_operations cmd648_port_ops = {
27988+static const struct ata_port_operations cmd648_port_ops = {
27989 .inherits = &cmd64x_base_ops,
27990 .bmdma_stop = cmd648_bmdma_stop,
27991 .cable_detect = cmd648_cable_detect,
27992diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
27993index 0df83cf..d7595b0 100644
27994--- a/drivers/ata/pata_cs5520.c
27995+++ b/drivers/ata/pata_cs5520.c
27996@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_sht = {
27997 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27998 };
27999
28000-static struct ata_port_operations cs5520_port_ops = {
28001+static const struct ata_port_operations cs5520_port_ops = {
28002 .inherits = &ata_bmdma_port_ops,
28003 .qc_prep = ata_sff_dumb_qc_prep,
28004 .cable_detect = ata_cable_40wire,
28005diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
28006index c974b05..6d26b11 100644
28007--- a/drivers/ata/pata_cs5530.c
28008+++ b/drivers/ata/pata_cs5530.c
28009@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_sht = {
28010 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28011 };
28012
28013-static struct ata_port_operations cs5530_port_ops = {
28014+static const struct ata_port_operations cs5530_port_ops = {
28015 .inherits = &ata_bmdma_port_ops,
28016
28017 .qc_prep = ata_sff_dumb_qc_prep,
28018diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
28019index 403f561..aacd26b 100644
28020--- a/drivers/ata/pata_cs5535.c
28021+++ b/drivers/ata/pata_cs5535.c
28022@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_sht = {
28023 ATA_BMDMA_SHT(DRV_NAME),
28024 };
28025
28026-static struct ata_port_operations cs5535_port_ops = {
28027+static const struct ata_port_operations cs5535_port_ops = {
28028 .inherits = &ata_bmdma_port_ops,
28029 .cable_detect = cs5535_cable_detect,
28030 .set_piomode = cs5535_set_piomode,
28031diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
28032index 6da4cb4..de24a25 100644
28033--- a/drivers/ata/pata_cs5536.c
28034+++ b/drivers/ata/pata_cs5536.c
28035@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_sht = {
28036 ATA_BMDMA_SHT(DRV_NAME),
28037 };
28038
28039-static struct ata_port_operations cs5536_port_ops = {
28040+static const struct ata_port_operations cs5536_port_ops = {
28041 .inherits = &ata_bmdma_port_ops,
28042 .cable_detect = cs5536_cable_detect,
28043 .set_piomode = cs5536_set_piomode,
28044diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
28045index 8fb040b..b16a9c9 100644
28046--- a/drivers/ata/pata_cypress.c
28047+++ b/drivers/ata/pata_cypress.c
28048@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c693_sht = {
28049 ATA_BMDMA_SHT(DRV_NAME),
28050 };
28051
28052-static struct ata_port_operations cy82c693_port_ops = {
28053+static const struct ata_port_operations cy82c693_port_ops = {
28054 .inherits = &ata_bmdma_port_ops,
28055 .cable_detect = ata_cable_40wire,
28056 .set_piomode = cy82c693_set_piomode,
28057diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
28058index 2a6412f..555ee11 100644
28059--- a/drivers/ata/pata_efar.c
28060+++ b/drivers/ata/pata_efar.c
28061@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sht = {
28062 ATA_BMDMA_SHT(DRV_NAME),
28063 };
28064
28065-static struct ata_port_operations efar_ops = {
28066+static const struct ata_port_operations efar_ops = {
28067 .inherits = &ata_bmdma_port_ops,
28068 .cable_detect = efar_cable_detect,
28069 .set_piomode = efar_set_piomode,
28070diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
28071index b9d8836..0b92030 100644
28072--- a/drivers/ata/pata_hpt366.c
28073+++ b/drivers/ata/pata_hpt366.c
28074@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_sht = {
28075 * Configuration for HPT366/68
28076 */
28077
28078-static struct ata_port_operations hpt366_port_ops = {
28079+static const struct ata_port_operations hpt366_port_ops = {
28080 .inherits = &ata_bmdma_port_ops,
28081 .cable_detect = hpt36x_cable_detect,
28082 .mode_filter = hpt366_filter,
28083diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
28084index 5af7f19..00c4980 100644
28085--- a/drivers/ata/pata_hpt37x.c
28086+++ b/drivers/ata/pata_hpt37x.c
28087@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_sht = {
28088 * Configuration for HPT370
28089 */
28090
28091-static struct ata_port_operations hpt370_port_ops = {
28092+static const struct ata_port_operations hpt370_port_ops = {
28093 .inherits = &ata_bmdma_port_ops,
28094
28095 .bmdma_stop = hpt370_bmdma_stop,
28096@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370_port_ops = {
28097 * Configuration for HPT370A. Close to 370 but less filters
28098 */
28099
28100-static struct ata_port_operations hpt370a_port_ops = {
28101+static const struct ata_port_operations hpt370a_port_ops = {
28102 .inherits = &hpt370_port_ops,
28103 .mode_filter = hpt370a_filter,
28104 };
28105@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370a_port_ops = {
28106 * and DMA mode setting functionality.
28107 */
28108
28109-static struct ata_port_operations hpt372_port_ops = {
28110+static const struct ata_port_operations hpt372_port_ops = {
28111 .inherits = &ata_bmdma_port_ops,
28112
28113 .bmdma_stop = hpt37x_bmdma_stop,
28114@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372_port_ops = {
28115 * but we have a different cable detection procedure for function 1.
28116 */
28117
28118-static struct ata_port_operations hpt374_fn1_port_ops = {
28119+static const struct ata_port_operations hpt374_fn1_port_ops = {
28120 .inherits = &hpt372_port_ops,
28121 .prereset = hpt374_fn1_pre_reset,
28122 };
28123diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
28124index 100f227..2e39382 100644
28125--- a/drivers/ata/pata_hpt3x2n.c
28126+++ b/drivers/ata/pata_hpt3x2n.c
28127@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n_sht = {
28128 * Configuration for HPT3x2n.
28129 */
28130
28131-static struct ata_port_operations hpt3x2n_port_ops = {
28132+static const struct ata_port_operations hpt3x2n_port_ops = {
28133 .inherits = &ata_bmdma_port_ops,
28134
28135 .bmdma_stop = hpt3x2n_bmdma_stop,
28136diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
28137index 7e31025..6fca8f4 100644
28138--- a/drivers/ata/pata_hpt3x3.c
28139+++ b/drivers/ata/pata_hpt3x3.c
28140@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_sht = {
28141 ATA_BMDMA_SHT(DRV_NAME),
28142 };
28143
28144-static struct ata_port_operations hpt3x3_port_ops = {
28145+static const struct ata_port_operations hpt3x3_port_ops = {
28146 .inherits = &ata_bmdma_port_ops,
28147 .cable_detect = ata_cable_40wire,
28148 .set_piomode = hpt3x3_set_piomode,
28149diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
28150index b663b7f..9a26c2a 100644
28151--- a/drivers/ata/pata_icside.c
28152+++ b/drivers/ata/pata_icside.c
28153@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct ata_link *link, unsigned int *classes)
28154 }
28155 }
28156
28157-static struct ata_port_operations pata_icside_port_ops = {
28158+static const struct ata_port_operations pata_icside_port_ops = {
28159 .inherits = &ata_sff_port_ops,
28160 /* no need to build any PRD tables for DMA */
28161 .qc_prep = ata_noop_qc_prep,
28162diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
28163index 4bceb88..457dfb6 100644
28164--- a/drivers/ata/pata_isapnp.c
28165+++ b/drivers/ata/pata_isapnp.c
28166@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_sht = {
28167 ATA_PIO_SHT(DRV_NAME),
28168 };
28169
28170-static struct ata_port_operations isapnp_port_ops = {
28171+static const struct ata_port_operations isapnp_port_ops = {
28172 .inherits = &ata_sff_port_ops,
28173 .cable_detect = ata_cable_40wire,
28174 };
28175
28176-static struct ata_port_operations isapnp_noalt_port_ops = {
28177+static const struct ata_port_operations isapnp_noalt_port_ops = {
28178 .inherits = &ata_sff_port_ops,
28179 .cable_detect = ata_cable_40wire,
28180 /* No altstatus so we don't want to use the lost interrupt poll */
28181diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
28182index f156da8..24976e2 100644
28183--- a/drivers/ata/pata_it8213.c
28184+++ b/drivers/ata/pata_it8213.c
28185@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_sht = {
28186 };
28187
28188
28189-static struct ata_port_operations it8213_ops = {
28190+static const struct ata_port_operations it8213_ops = {
28191 .inherits = &ata_bmdma_port_ops,
28192 .cable_detect = it8213_cable_detect,
28193 .set_piomode = it8213_set_piomode,
28194diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
28195index 188bc2f..ca9e785 100644
28196--- a/drivers/ata/pata_it821x.c
28197+++ b/drivers/ata/pata_it821x.c
28198@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_sht = {
28199 ATA_BMDMA_SHT(DRV_NAME),
28200 };
28201
28202-static struct ata_port_operations it821x_smart_port_ops = {
28203+static const struct ata_port_operations it821x_smart_port_ops = {
28204 .inherits = &ata_bmdma_port_ops,
28205
28206 .check_atapi_dma= it821x_check_atapi_dma,
28207@@ -814,7 +814,7 @@ static struct ata_port_operations it821x_smart_port_ops = {
28208 .port_start = it821x_port_start,
28209 };
28210
28211-static struct ata_port_operations it821x_passthru_port_ops = {
28212+static const struct ata_port_operations it821x_passthru_port_ops = {
28213 .inherits = &ata_bmdma_port_ops,
28214
28215 .check_atapi_dma= it821x_check_atapi_dma,
28216@@ -830,7 +830,7 @@ static struct ata_port_operations it821x_passthru_port_ops = {
28217 .port_start = it821x_port_start,
28218 };
28219
28220-static struct ata_port_operations it821x_rdc_port_ops = {
28221+static const struct ata_port_operations it821x_rdc_port_ops = {
28222 .inherits = &ata_bmdma_port_ops,
28223
28224 .check_atapi_dma= it821x_check_atapi_dma,
28225diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
28226index ba54b08..4b952b7 100644
28227--- a/drivers/ata/pata_ixp4xx_cf.c
28228+++ b/drivers/ata/pata_ixp4xx_cf.c
28229@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_sht = {
28230 ATA_PIO_SHT(DRV_NAME),
28231 };
28232
28233-static struct ata_port_operations ixp4xx_port_ops = {
28234+static const struct ata_port_operations ixp4xx_port_ops = {
28235 .inherits = &ata_sff_port_ops,
28236 .sff_data_xfer = ixp4xx_mmio_data_xfer,
28237 .cable_detect = ata_cable_40wire,
28238diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
28239index 3a1474a..434b0ff 100644
28240--- a/drivers/ata/pata_jmicron.c
28241+++ b/drivers/ata/pata_jmicron.c
28242@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron_sht = {
28243 ATA_BMDMA_SHT(DRV_NAME),
28244 };
28245
28246-static struct ata_port_operations jmicron_ops = {
28247+static const struct ata_port_operations jmicron_ops = {
28248 .inherits = &ata_bmdma_port_ops,
28249 .prereset = jmicron_pre_reset,
28250 };
28251diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
28252index 6932e56..220e71d 100644
28253--- a/drivers/ata/pata_legacy.c
28254+++ b/drivers/ata/pata_legacy.c
28255@@ -106,7 +106,7 @@ struct legacy_probe {
28256
28257 struct legacy_controller {
28258 const char *name;
28259- struct ata_port_operations *ops;
28260+ const struct ata_port_operations *ops;
28261 unsigned int pio_mask;
28262 unsigned int flags;
28263 unsigned int pflags;
28264@@ -223,12 +223,12 @@ static const struct ata_port_operations legacy_base_port_ops = {
28265 * pio_mask as well.
28266 */
28267
28268-static struct ata_port_operations simple_port_ops = {
28269+static const struct ata_port_operations simple_port_ops = {
28270 .inherits = &legacy_base_port_ops,
28271 .sff_data_xfer = ata_sff_data_xfer_noirq,
28272 };
28273
28274-static struct ata_port_operations legacy_port_ops = {
28275+static const struct ata_port_operations legacy_port_ops = {
28276 .inherits = &legacy_base_port_ops,
28277 .sff_data_xfer = ata_sff_data_xfer_noirq,
28278 .set_mode = legacy_set_mode,
28279@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
28280 return buflen;
28281 }
28282
28283-static struct ata_port_operations pdc20230_port_ops = {
28284+static const struct ata_port_operations pdc20230_port_ops = {
28285 .inherits = &legacy_base_port_ops,
28286 .set_piomode = pdc20230_set_piomode,
28287 .sff_data_xfer = pdc_data_xfer_vlb,
28288@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
28289 ioread8(ap->ioaddr.status_addr);
28290 }
28291
28292-static struct ata_port_operations ht6560a_port_ops = {
28293+static const struct ata_port_operations ht6560a_port_ops = {
28294 .inherits = &legacy_base_port_ops,
28295 .set_piomode = ht6560a_set_piomode,
28296 };
28297@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
28298 ioread8(ap->ioaddr.status_addr);
28299 }
28300
28301-static struct ata_port_operations ht6560b_port_ops = {
28302+static const struct ata_port_operations ht6560b_port_ops = {
28303 .inherits = &legacy_base_port_ops,
28304 .set_piomode = ht6560b_set_piomode,
28305 };
28306@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(struct ata_port *ap,
28307 }
28308
28309
28310-static struct ata_port_operations opti82c611a_port_ops = {
28311+static const struct ata_port_operations opti82c611a_port_ops = {
28312 .inherits = &legacy_base_port_ops,
28313 .set_piomode = opti82c611a_set_piomode,
28314 };
28315@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(struct ata_queued_cmd *qc)
28316 return ata_sff_qc_issue(qc);
28317 }
28318
28319-static struct ata_port_operations opti82c46x_port_ops = {
28320+static const struct ata_port_operations opti82c46x_port_ops = {
28321 .inherits = &legacy_base_port_ops,
28322 .set_piomode = opti82c46x_set_piomode,
28323 .qc_issue = opti82c46x_qc_issue,
28324@@ -771,20 +771,20 @@ static int qdi_port(struct platform_device *dev,
28325 return 0;
28326 }
28327
28328-static struct ata_port_operations qdi6500_port_ops = {
28329+static const struct ata_port_operations qdi6500_port_ops = {
28330 .inherits = &legacy_base_port_ops,
28331 .set_piomode = qdi6500_set_piomode,
28332 .qc_issue = qdi_qc_issue,
28333 .sff_data_xfer = vlb32_data_xfer,
28334 };
28335
28336-static struct ata_port_operations qdi6580_port_ops = {
28337+static const struct ata_port_operations qdi6580_port_ops = {
28338 .inherits = &legacy_base_port_ops,
28339 .set_piomode = qdi6580_set_piomode,
28340 .sff_data_xfer = vlb32_data_xfer,
28341 };
28342
28343-static struct ata_port_operations qdi6580dp_port_ops = {
28344+static const struct ata_port_operations qdi6580dp_port_ops = {
28345 .inherits = &legacy_base_port_ops,
28346 .set_piomode = qdi6580dp_set_piomode,
28347 .sff_data_xfer = vlb32_data_xfer,
28348@@ -855,7 +855,7 @@ static int winbond_port(struct platform_device *dev,
28349 return 0;
28350 }
28351
28352-static struct ata_port_operations winbond_port_ops = {
28353+static const struct ata_port_operations winbond_port_ops = {
28354 .inherits = &legacy_base_port_ops,
28355 .set_piomode = winbond_set_piomode,
28356 .sff_data_xfer = vlb32_data_xfer,
28357@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
28358 int pio_modes = controller->pio_mask;
28359 unsigned long io = probe->port;
28360 u32 mask = (1 << probe->slot);
28361- struct ata_port_operations *ops = controller->ops;
28362+ const struct ata_port_operations *ops = controller->ops;
28363 struct legacy_data *ld = &legacy_data[probe->slot];
28364 struct ata_host *host = NULL;
28365 struct ata_port *ap;
28366diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
28367index 2096fb7..4d090fc 100644
28368--- a/drivers/ata/pata_marvell.c
28369+++ b/drivers/ata/pata_marvell.c
28370@@ -100,7 +100,7 @@ static struct scsi_host_template marvell_sht = {
28371 ATA_BMDMA_SHT(DRV_NAME),
28372 };
28373
28374-static struct ata_port_operations marvell_ops = {
28375+static const struct ata_port_operations marvell_ops = {
28376 .inherits = &ata_bmdma_port_ops,
28377 .cable_detect = marvell_cable_detect,
28378 .prereset = marvell_pre_reset,
28379diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
28380index 99d41be..7d56aa8 100644
28381--- a/drivers/ata/pata_mpc52xx.c
28382+++ b/drivers/ata/pata_mpc52xx.c
28383@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx_ata_sht = {
28384 ATA_PIO_SHT(DRV_NAME),
28385 };
28386
28387-static struct ata_port_operations mpc52xx_ata_port_ops = {
28388+static const struct ata_port_operations mpc52xx_ata_port_ops = {
28389 .inherits = &ata_bmdma_port_ops,
28390 .sff_dev_select = mpc52xx_ata_dev_select,
28391 .set_piomode = mpc52xx_ata_set_piomode,
28392diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
28393index b21f002..0a27e7f 100644
28394--- a/drivers/ata/pata_mpiix.c
28395+++ b/drivers/ata/pata_mpiix.c
28396@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_sht = {
28397 ATA_PIO_SHT(DRV_NAME),
28398 };
28399
28400-static struct ata_port_operations mpiix_port_ops = {
28401+static const struct ata_port_operations mpiix_port_ops = {
28402 .inherits = &ata_sff_port_ops,
28403 .qc_issue = mpiix_qc_issue,
28404 .cable_detect = ata_cable_40wire,
28405diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
28406index f0d52f7..89c3be3 100644
28407--- a/drivers/ata/pata_netcell.c
28408+++ b/drivers/ata/pata_netcell.c
28409@@ -34,7 +34,7 @@ static struct scsi_host_template netcell_sht = {
28410 ATA_BMDMA_SHT(DRV_NAME),
28411 };
28412
28413-static struct ata_port_operations netcell_ops = {
28414+static const struct ata_port_operations netcell_ops = {
28415 .inherits = &ata_bmdma_port_ops,
28416 .cable_detect = ata_cable_80wire,
28417 .read_id = netcell_read_id,
28418diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
28419index dd53a66..a3f4317 100644
28420--- a/drivers/ata/pata_ninja32.c
28421+++ b/drivers/ata/pata_ninja32.c
28422@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32_sht = {
28423 ATA_BMDMA_SHT(DRV_NAME),
28424 };
28425
28426-static struct ata_port_operations ninja32_port_ops = {
28427+static const struct ata_port_operations ninja32_port_ops = {
28428 .inherits = &ata_bmdma_port_ops,
28429 .sff_dev_select = ninja32_dev_select,
28430 .cable_detect = ata_cable_40wire,
28431diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
28432index ca53fac..9aa93ef 100644
28433--- a/drivers/ata/pata_ns87410.c
28434+++ b/drivers/ata/pata_ns87410.c
28435@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410_sht = {
28436 ATA_PIO_SHT(DRV_NAME),
28437 };
28438
28439-static struct ata_port_operations ns87410_port_ops = {
28440+static const struct ata_port_operations ns87410_port_ops = {
28441 .inherits = &ata_sff_port_ops,
28442 .qc_issue = ns87410_qc_issue,
28443 .cable_detect = ata_cable_40wire,
28444diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
28445index 773b159..55f454e 100644
28446--- a/drivers/ata/pata_ns87415.c
28447+++ b/drivers/ata/pata_ns87415.c
28448@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct ata_port *ap)
28449 }
28450 #endif /* 87560 SuperIO Support */
28451
28452-static struct ata_port_operations ns87415_pata_ops = {
28453+static const struct ata_port_operations ns87415_pata_ops = {
28454 .inherits = &ata_bmdma_port_ops,
28455
28456 .check_atapi_dma = ns87415_check_atapi_dma,
28457@@ -313,7 +313,7 @@ static struct ata_port_operations ns87415_pata_ops = {
28458 };
28459
28460 #if defined(CONFIG_SUPERIO)
28461-static struct ata_port_operations ns87560_pata_ops = {
28462+static const struct ata_port_operations ns87560_pata_ops = {
28463 .inherits = &ns87415_pata_ops,
28464 .sff_tf_read = ns87560_tf_read,
28465 .sff_check_status = ns87560_check_status,
28466diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
28467index d6f6956..639295b 100644
28468--- a/drivers/ata/pata_octeon_cf.c
28469+++ b/drivers/ata/pata_octeon_cf.c
28470@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(struct ata_queued_cmd *qc)
28471 return 0;
28472 }
28473
28474+/* cannot be const */
28475 static struct ata_port_operations octeon_cf_ops = {
28476 .inherits = &ata_sff_port_ops,
28477 .check_atapi_dma = octeon_cf_check_atapi_dma,
28478diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
28479index 84ac503..adee1cd 100644
28480--- a/drivers/ata/pata_oldpiix.c
28481+++ b/drivers/ata/pata_oldpiix.c
28482@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix_sht = {
28483 ATA_BMDMA_SHT(DRV_NAME),
28484 };
28485
28486-static struct ata_port_operations oldpiix_pata_ops = {
28487+static const struct ata_port_operations oldpiix_pata_ops = {
28488 .inherits = &ata_bmdma_port_ops,
28489 .qc_issue = oldpiix_qc_issue,
28490 .cable_detect = ata_cable_40wire,
28491diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
28492index 99eddda..3a4c0aa 100644
28493--- a/drivers/ata/pata_opti.c
28494+++ b/drivers/ata/pata_opti.c
28495@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sht = {
28496 ATA_PIO_SHT(DRV_NAME),
28497 };
28498
28499-static struct ata_port_operations opti_port_ops = {
28500+static const struct ata_port_operations opti_port_ops = {
28501 .inherits = &ata_sff_port_ops,
28502 .cable_detect = ata_cable_40wire,
28503 .set_piomode = opti_set_piomode,
28504diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
28505index 86885a4..8e9968d 100644
28506--- a/drivers/ata/pata_optidma.c
28507+++ b/drivers/ata/pata_optidma.c
28508@@ -337,7 +337,7 @@ static struct scsi_host_template optidma_sht = {
28509 ATA_BMDMA_SHT(DRV_NAME),
28510 };
28511
28512-static struct ata_port_operations optidma_port_ops = {
28513+static const struct ata_port_operations optidma_port_ops = {
28514 .inherits = &ata_bmdma_port_ops,
28515 .cable_detect = ata_cable_40wire,
28516 .set_piomode = optidma_set_pio_mode,
28517@@ -346,7 +346,7 @@ static struct ata_port_operations optidma_port_ops = {
28518 .prereset = optidma_pre_reset,
28519 };
28520
28521-static struct ata_port_operations optiplus_port_ops = {
28522+static const struct ata_port_operations optiplus_port_ops = {
28523 .inherits = &optidma_port_ops,
28524 .set_piomode = optiplus_set_pio_mode,
28525 .set_dmamode = optiplus_set_dma_mode,
28526diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c
28527index 11fb4cc..1a14022 100644
28528--- a/drivers/ata/pata_palmld.c
28529+++ b/drivers/ata/pata_palmld.c
28530@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_sht = {
28531 ATA_PIO_SHT(DRV_NAME),
28532 };
28533
28534-static struct ata_port_operations palmld_port_ops = {
28535+static const struct ata_port_operations palmld_port_ops = {
28536 .inherits = &ata_sff_port_ops,
28537 .sff_data_xfer = ata_sff_data_xfer_noirq,
28538 .cable_detect = ata_cable_40wire,
28539diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
28540index dc99e26..7f4b1e4 100644
28541--- a/drivers/ata/pata_pcmcia.c
28542+++ b/drivers/ata/pata_pcmcia.c
28543@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_sht = {
28544 ATA_PIO_SHT(DRV_NAME),
28545 };
28546
28547-static struct ata_port_operations pcmcia_port_ops = {
28548+static const struct ata_port_operations pcmcia_port_ops = {
28549 .inherits = &ata_sff_port_ops,
28550 .sff_data_xfer = ata_sff_data_xfer_noirq,
28551 .cable_detect = ata_cable_40wire,
28552 .set_mode = pcmcia_set_mode,
28553 };
28554
28555-static struct ata_port_operations pcmcia_8bit_port_ops = {
28556+static const struct ata_port_operations pcmcia_8bit_port_ops = {
28557 .inherits = &ata_sff_port_ops,
28558 .sff_data_xfer = ata_data_xfer_8bit,
28559 .cable_detect = ata_cable_40wire,
28560@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
28561 unsigned long io_base, ctl_base;
28562 void __iomem *io_addr, *ctl_addr;
28563 int n_ports = 1;
28564- struct ata_port_operations *ops = &pcmcia_port_ops;
28565+ const struct ata_port_operations *ops = &pcmcia_port_ops;
28566
28567 info = kzalloc(sizeof(*info), GFP_KERNEL);
28568 if (info == NULL)
28569diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
28570index ca5cad0..3a1f125 100644
28571--- a/drivers/ata/pata_pdc2027x.c
28572+++ b/drivers/ata/pata_pdc2027x.c
28573@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027x_sht = {
28574 ATA_BMDMA_SHT(DRV_NAME),
28575 };
28576
28577-static struct ata_port_operations pdc2027x_pata100_ops = {
28578+static const struct ata_port_operations pdc2027x_pata100_ops = {
28579 .inherits = &ata_bmdma_port_ops,
28580 .check_atapi_dma = pdc2027x_check_atapi_dma,
28581 .cable_detect = pdc2027x_cable_detect,
28582 .prereset = pdc2027x_prereset,
28583 };
28584
28585-static struct ata_port_operations pdc2027x_pata133_ops = {
28586+static const struct ata_port_operations pdc2027x_pata133_ops = {
28587 .inherits = &pdc2027x_pata100_ops,
28588 .mode_filter = pdc2027x_mode_filter,
28589 .set_piomode = pdc2027x_set_piomode,
28590diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
28591index 2911120..4bf62aa 100644
28592--- a/drivers/ata/pata_pdc202xx_old.c
28593+++ b/drivers/ata/pata_pdc202xx_old.c
28594@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202xx_sht = {
28595 ATA_BMDMA_SHT(DRV_NAME),
28596 };
28597
28598-static struct ata_port_operations pdc2024x_port_ops = {
28599+static const struct ata_port_operations pdc2024x_port_ops = {
28600 .inherits = &ata_bmdma_port_ops,
28601
28602 .cable_detect = ata_cable_40wire,
28603@@ -284,7 +284,7 @@ static struct ata_port_operations pdc2024x_port_ops = {
28604 .sff_exec_command = pdc202xx_exec_command,
28605 };
28606
28607-static struct ata_port_operations pdc2026x_port_ops = {
28608+static const struct ata_port_operations pdc2026x_port_ops = {
28609 .inherits = &pdc2024x_port_ops,
28610
28611 .check_atapi_dma = pdc2026x_check_atapi_dma,
28612diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
28613index 3f6ebc6..a18c358 100644
28614--- a/drivers/ata/pata_platform.c
28615+++ b/drivers/ata/pata_platform.c
28616@@ -48,7 +48,7 @@ static struct scsi_host_template pata_platform_sht = {
28617 ATA_PIO_SHT(DRV_NAME),
28618 };
28619
28620-static struct ata_port_operations pata_platform_port_ops = {
28621+static const struct ata_port_operations pata_platform_port_ops = {
28622 .inherits = &ata_sff_port_ops,
28623 .sff_data_xfer = ata_sff_data_xfer_noirq,
28624 .cable_detect = ata_cable_unknown,
28625diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
28626index 45879dc..165a9f9 100644
28627--- a/drivers/ata/pata_qdi.c
28628+++ b/drivers/ata/pata_qdi.c
28629@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht = {
28630 ATA_PIO_SHT(DRV_NAME),
28631 };
28632
28633-static struct ata_port_operations qdi6500_port_ops = {
28634+static const struct ata_port_operations qdi6500_port_ops = {
28635 .inherits = &ata_sff_port_ops,
28636 .qc_issue = qdi_qc_issue,
28637 .sff_data_xfer = qdi_data_xfer,
28638@@ -165,7 +165,7 @@ static struct ata_port_operations qdi6500_port_ops = {
28639 .set_piomode = qdi6500_set_piomode,
28640 };
28641
28642-static struct ata_port_operations qdi6580_port_ops = {
28643+static const struct ata_port_operations qdi6580_port_ops = {
28644 .inherits = &qdi6500_port_ops,
28645 .set_piomode = qdi6580_set_piomode,
28646 };
28647diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
28648index 4401b33..716c5cc 100644
28649--- a/drivers/ata/pata_radisys.c
28650+++ b/drivers/ata/pata_radisys.c
28651@@ -187,7 +187,7 @@ static struct scsi_host_template radisys_sht = {
28652 ATA_BMDMA_SHT(DRV_NAME),
28653 };
28654
28655-static struct ata_port_operations radisys_pata_ops = {
28656+static const struct ata_port_operations radisys_pata_ops = {
28657 .inherits = &ata_bmdma_port_ops,
28658 .qc_issue = radisys_qc_issue,
28659 .cable_detect = ata_cable_unknown,
28660diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
28661index 45f1e10..fab6bca 100644
28662--- a/drivers/ata/pata_rb532_cf.c
28663+++ b/drivers/ata/pata_rb532_cf.c
28664@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
28665 return IRQ_HANDLED;
28666 }
28667
28668-static struct ata_port_operations rb532_pata_port_ops = {
28669+static const struct ata_port_operations rb532_pata_port_ops = {
28670 .inherits = &ata_sff_port_ops,
28671 .sff_data_xfer = ata_sff_data_xfer32,
28672 };
28673diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c
28674index c843a1e..b5853c3 100644
28675--- a/drivers/ata/pata_rdc.c
28676+++ b/drivers/ata/pata_rdc.c
28677@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
28678 pci_write_config_byte(dev, 0x48, udma_enable);
28679 }
28680
28681-static struct ata_port_operations rdc_pata_ops = {
28682+static const struct ata_port_operations rdc_pata_ops = {
28683 .inherits = &ata_bmdma32_port_ops,
28684 .cable_detect = rdc_pata_cable_detect,
28685 .set_piomode = rdc_set_piomode,
28686diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
28687index a5e4dfe..080c8c9 100644
28688--- a/drivers/ata/pata_rz1000.c
28689+++ b/drivers/ata/pata_rz1000.c
28690@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_sht = {
28691 ATA_PIO_SHT(DRV_NAME),
28692 };
28693
28694-static struct ata_port_operations rz1000_port_ops = {
28695+static const struct ata_port_operations rz1000_port_ops = {
28696 .inherits = &ata_sff_port_ops,
28697 .cable_detect = ata_cable_40wire,
28698 .set_mode = rz1000_set_mode,
28699diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
28700index 3bbed83..e309daf 100644
28701--- a/drivers/ata/pata_sc1200.c
28702+++ b/drivers/ata/pata_sc1200.c
28703@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_sht = {
28704 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28705 };
28706
28707-static struct ata_port_operations sc1200_port_ops = {
28708+static const struct ata_port_operations sc1200_port_ops = {
28709 .inherits = &ata_bmdma_port_ops,
28710 .qc_prep = ata_sff_dumb_qc_prep,
28711 .qc_issue = sc1200_qc_issue,
28712diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
28713index 4257d6b..4c1d9d5 100644
28714--- a/drivers/ata/pata_scc.c
28715+++ b/drivers/ata/pata_scc.c
28716@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht = {
28717 ATA_BMDMA_SHT(DRV_NAME),
28718 };
28719
28720-static struct ata_port_operations scc_pata_ops = {
28721+static const struct ata_port_operations scc_pata_ops = {
28722 .inherits = &ata_bmdma_port_ops,
28723
28724 .set_piomode = scc_set_piomode,
28725diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
28726index 99cceb4..e2e0a87 100644
28727--- a/drivers/ata/pata_sch.c
28728+++ b/drivers/ata/pata_sch.c
28729@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht = {
28730 ATA_BMDMA_SHT(DRV_NAME),
28731 };
28732
28733-static struct ata_port_operations sch_pata_ops = {
28734+static const struct ata_port_operations sch_pata_ops = {
28735 .inherits = &ata_bmdma_port_ops,
28736 .cable_detect = ata_cable_unknown,
28737 .set_piomode = sch_set_piomode,
28738diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
28739index beaed12..39969f1 100644
28740--- a/drivers/ata/pata_serverworks.c
28741+++ b/drivers/ata/pata_serverworks.c
28742@@ -299,7 +299,7 @@ static struct scsi_host_template serverworks_sht = {
28743 ATA_BMDMA_SHT(DRV_NAME),
28744 };
28745
28746-static struct ata_port_operations serverworks_osb4_port_ops = {
28747+static const struct ata_port_operations serverworks_osb4_port_ops = {
28748 .inherits = &ata_bmdma_port_ops,
28749 .cable_detect = serverworks_cable_detect,
28750 .mode_filter = serverworks_osb4_filter,
28751@@ -307,7 +307,7 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
28752 .set_dmamode = serverworks_set_dmamode,
28753 };
28754
28755-static struct ata_port_operations serverworks_csb_port_ops = {
28756+static const struct ata_port_operations serverworks_csb_port_ops = {
28757 .inherits = &serverworks_osb4_port_ops,
28758 .mode_filter = serverworks_csb_filter,
28759 };
28760diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
28761index a2ace48..0463b44 100644
28762--- a/drivers/ata/pata_sil680.c
28763+++ b/drivers/ata/pata_sil680.c
28764@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_sht = {
28765 ATA_BMDMA_SHT(DRV_NAME),
28766 };
28767
28768-static struct ata_port_operations sil680_port_ops = {
28769+static const struct ata_port_operations sil680_port_ops = {
28770 .inherits = &ata_bmdma32_port_ops,
28771 .cable_detect = sil680_cable_detect,
28772 .set_piomode = sil680_set_piomode,
28773diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
28774index 488e77b..b3724d5 100644
28775--- a/drivers/ata/pata_sis.c
28776+++ b/drivers/ata/pata_sis.c
28777@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht = {
28778 ATA_BMDMA_SHT(DRV_NAME),
28779 };
28780
28781-static struct ata_port_operations sis_133_for_sata_ops = {
28782+static const struct ata_port_operations sis_133_for_sata_ops = {
28783 .inherits = &ata_bmdma_port_ops,
28784 .set_piomode = sis_133_set_piomode,
28785 .set_dmamode = sis_133_set_dmamode,
28786 .cable_detect = sis_133_cable_detect,
28787 };
28788
28789-static struct ata_port_operations sis_base_ops = {
28790+static const struct ata_port_operations sis_base_ops = {
28791 .inherits = &ata_bmdma_port_ops,
28792 .prereset = sis_pre_reset,
28793 };
28794
28795-static struct ata_port_operations sis_133_ops = {
28796+static const struct ata_port_operations sis_133_ops = {
28797 .inherits = &sis_base_ops,
28798 .set_piomode = sis_133_set_piomode,
28799 .set_dmamode = sis_133_set_dmamode,
28800 .cable_detect = sis_133_cable_detect,
28801 };
28802
28803-static struct ata_port_operations sis_133_early_ops = {
28804+static const struct ata_port_operations sis_133_early_ops = {
28805 .inherits = &sis_base_ops,
28806 .set_piomode = sis_100_set_piomode,
28807 .set_dmamode = sis_133_early_set_dmamode,
28808 .cable_detect = sis_66_cable_detect,
28809 };
28810
28811-static struct ata_port_operations sis_100_ops = {
28812+static const struct ata_port_operations sis_100_ops = {
28813 .inherits = &sis_base_ops,
28814 .set_piomode = sis_100_set_piomode,
28815 .set_dmamode = sis_100_set_dmamode,
28816 .cable_detect = sis_66_cable_detect,
28817 };
28818
28819-static struct ata_port_operations sis_66_ops = {
28820+static const struct ata_port_operations sis_66_ops = {
28821 .inherits = &sis_base_ops,
28822 .set_piomode = sis_old_set_piomode,
28823 .set_dmamode = sis_66_set_dmamode,
28824 .cable_detect = sis_66_cable_detect,
28825 };
28826
28827-static struct ata_port_operations sis_old_ops = {
28828+static const struct ata_port_operations sis_old_ops = {
28829 .inherits = &sis_base_ops,
28830 .set_piomode = sis_old_set_piomode,
28831 .set_dmamode = sis_old_set_dmamode,
28832diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
28833index 29f733c..43e9ca0 100644
28834--- a/drivers/ata/pata_sl82c105.c
28835+++ b/drivers/ata/pata_sl82c105.c
28836@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c105_sht = {
28837 ATA_BMDMA_SHT(DRV_NAME),
28838 };
28839
28840-static struct ata_port_operations sl82c105_port_ops = {
28841+static const struct ata_port_operations sl82c105_port_ops = {
28842 .inherits = &ata_bmdma_port_ops,
28843 .qc_defer = sl82c105_qc_defer,
28844 .bmdma_start = sl82c105_bmdma_start,
28845diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
28846index f1f13ff..df39e99 100644
28847--- a/drivers/ata/pata_triflex.c
28848+++ b/drivers/ata/pata_triflex.c
28849@@ -178,7 +178,7 @@ static struct scsi_host_template triflex_sht = {
28850 ATA_BMDMA_SHT(DRV_NAME),
28851 };
28852
28853-static struct ata_port_operations triflex_port_ops = {
28854+static const struct ata_port_operations triflex_port_ops = {
28855 .inherits = &ata_bmdma_port_ops,
28856 .bmdma_start = triflex_bmdma_start,
28857 .bmdma_stop = triflex_bmdma_stop,
28858diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
28859index 1d73b8d..98a4b29 100644
28860--- a/drivers/ata/pata_via.c
28861+++ b/drivers/ata/pata_via.c
28862@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht = {
28863 ATA_BMDMA_SHT(DRV_NAME),
28864 };
28865
28866-static struct ata_port_operations via_port_ops = {
28867+static const struct ata_port_operations via_port_ops = {
28868 .inherits = &ata_bmdma_port_ops,
28869 .cable_detect = via_cable_detect,
28870 .set_piomode = via_set_piomode,
28871@@ -429,7 +429,7 @@ static struct ata_port_operations via_port_ops = {
28872 .port_start = via_port_start,
28873 };
28874
28875-static struct ata_port_operations via_port_ops_noirq = {
28876+static const struct ata_port_operations via_port_ops_noirq = {
28877 .inherits = &via_port_ops,
28878 .sff_data_xfer = ata_sff_data_xfer_noirq,
28879 };
28880diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
28881index 6d8619b..ad511c4 100644
28882--- a/drivers/ata/pata_winbond.c
28883+++ b/drivers/ata/pata_winbond.c
28884@@ -125,7 +125,7 @@ static struct scsi_host_template winbond_sht = {
28885 ATA_PIO_SHT(DRV_NAME),
28886 };
28887
28888-static struct ata_port_operations winbond_port_ops = {
28889+static const struct ata_port_operations winbond_port_ops = {
28890 .inherits = &ata_sff_port_ops,
28891 .sff_data_xfer = winbond_data_xfer,
28892 .cable_detect = ata_cable_40wire,
28893diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
28894index 6c65b07..f996ec7 100644
28895--- a/drivers/ata/pdc_adma.c
28896+++ b/drivers/ata/pdc_adma.c
28897@@ -145,7 +145,7 @@ static struct scsi_host_template adma_ata_sht = {
28898 .dma_boundary = ADMA_DMA_BOUNDARY,
28899 };
28900
28901-static struct ata_port_operations adma_ata_ops = {
28902+static const struct ata_port_operations adma_ata_ops = {
28903 .inherits = &ata_sff_port_ops,
28904
28905 .lost_interrupt = ATA_OP_NULL,
28906diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
28907index 172b57e..c49bc1e 100644
28908--- a/drivers/ata/sata_fsl.c
28909+++ b/drivers/ata/sata_fsl.c
28910@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fsl_sht = {
28911 .dma_boundary = ATA_DMA_BOUNDARY,
28912 };
28913
28914-static struct ata_port_operations sata_fsl_ops = {
28915+static const struct ata_port_operations sata_fsl_ops = {
28916 .inherits = &sata_pmp_port_ops,
28917
28918 .qc_defer = ata_std_qc_defer,
28919diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
28920index 4406902..60603ef 100644
28921--- a/drivers/ata/sata_inic162x.c
28922+++ b/drivers/ata/sata_inic162x.c
28923@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_port *ap)
28924 return 0;
28925 }
28926
28927-static struct ata_port_operations inic_port_ops = {
28928+static const struct ata_port_operations inic_port_ops = {
28929 .inherits = &sata_port_ops,
28930
28931 .check_atapi_dma = inic_check_atapi_dma,
28932diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
28933index cf41126..8107be6 100644
28934--- a/drivers/ata/sata_mv.c
28935+++ b/drivers/ata/sata_mv.c
28936@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht = {
28937 .dma_boundary = MV_DMA_BOUNDARY,
28938 };
28939
28940-static struct ata_port_operations mv5_ops = {
28941+static const struct ata_port_operations mv5_ops = {
28942 .inherits = &ata_sff_port_ops,
28943
28944 .lost_interrupt = ATA_OP_NULL,
28945@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_ops = {
28946 .port_stop = mv_port_stop,
28947 };
28948
28949-static struct ata_port_operations mv6_ops = {
28950+static const struct ata_port_operations mv6_ops = {
28951 .inherits = &mv5_ops,
28952 .dev_config = mv6_dev_config,
28953 .scr_read = mv_scr_read,
28954@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_ops = {
28955 .bmdma_status = mv_bmdma_status,
28956 };
28957
28958-static struct ata_port_operations mv_iie_ops = {
28959+static const struct ata_port_operations mv_iie_ops = {
28960 .inherits = &mv6_ops,
28961 .dev_config = ATA_OP_NULL,
28962 .qc_prep = mv_qc_prep_iie,
28963diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
28964index ae2297c..d5c9c33 100644
28965--- a/drivers/ata/sata_nv.c
28966+++ b/drivers/ata/sata_nv.c
28967@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swncq_sht = {
28968 * cases. Define nv_hardreset() which only kicks in for post-boot
28969 * probing and use it for all variants.
28970 */
28971-static struct ata_port_operations nv_generic_ops = {
28972+static const struct ata_port_operations nv_generic_ops = {
28973 .inherits = &ata_bmdma_port_ops,
28974 .lost_interrupt = ATA_OP_NULL,
28975 .scr_read = nv_scr_read,
28976@@ -472,20 +472,20 @@ static struct ata_port_operations nv_generic_ops = {
28977 .hardreset = nv_hardreset,
28978 };
28979
28980-static struct ata_port_operations nv_nf2_ops = {
28981+static const struct ata_port_operations nv_nf2_ops = {
28982 .inherits = &nv_generic_ops,
28983 .freeze = nv_nf2_freeze,
28984 .thaw = nv_nf2_thaw,
28985 };
28986
28987-static struct ata_port_operations nv_ck804_ops = {
28988+static const struct ata_port_operations nv_ck804_ops = {
28989 .inherits = &nv_generic_ops,
28990 .freeze = nv_ck804_freeze,
28991 .thaw = nv_ck804_thaw,
28992 .host_stop = nv_ck804_host_stop,
28993 };
28994
28995-static struct ata_port_operations nv_adma_ops = {
28996+static const struct ata_port_operations nv_adma_ops = {
28997 .inherits = &nv_ck804_ops,
28998
28999 .check_atapi_dma = nv_adma_check_atapi_dma,
29000@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adma_ops = {
29001 .host_stop = nv_adma_host_stop,
29002 };
29003
29004-static struct ata_port_operations nv_swncq_ops = {
29005+static const struct ata_port_operations nv_swncq_ops = {
29006 .inherits = &nv_generic_ops,
29007
29008 .qc_defer = ata_std_qc_defer,
29009diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
29010index 07d8d00..6cc70bb 100644
29011--- a/drivers/ata/sata_promise.c
29012+++ b/drivers/ata/sata_promise.c
29013@@ -195,7 +195,7 @@ static const struct ata_port_operations pdc_common_ops = {
29014 .error_handler = pdc_error_handler,
29015 };
29016
29017-static struct ata_port_operations pdc_sata_ops = {
29018+static const struct ata_port_operations pdc_sata_ops = {
29019 .inherits = &pdc_common_ops,
29020 .cable_detect = pdc_sata_cable_detect,
29021 .freeze = pdc_sata_freeze,
29022@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sata_ops = {
29023
29024 /* First-generation chips need a more restrictive ->check_atapi_dma op,
29025 and ->freeze/thaw that ignore the hotplug controls. */
29026-static struct ata_port_operations pdc_old_sata_ops = {
29027+static const struct ata_port_operations pdc_old_sata_ops = {
29028 .inherits = &pdc_sata_ops,
29029 .freeze = pdc_freeze,
29030 .thaw = pdc_thaw,
29031 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
29032 };
29033
29034-static struct ata_port_operations pdc_pata_ops = {
29035+static const struct ata_port_operations pdc_pata_ops = {
29036 .inherits = &pdc_common_ops,
29037 .cable_detect = pdc_pata_cable_detect,
29038 .freeze = pdc_freeze,
29039diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
29040index 326c0cf..36ecebe 100644
29041--- a/drivers/ata/sata_qstor.c
29042+++ b/drivers/ata/sata_qstor.c
29043@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_sht = {
29044 .dma_boundary = QS_DMA_BOUNDARY,
29045 };
29046
29047-static struct ata_port_operations qs_ata_ops = {
29048+static const struct ata_port_operations qs_ata_ops = {
29049 .inherits = &ata_sff_port_ops,
29050
29051 .check_atapi_dma = qs_check_atapi_dma,
29052diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
29053index 3cb69d5..0871d3c 100644
29054--- a/drivers/ata/sata_sil.c
29055+++ b/drivers/ata/sata_sil.c
29056@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht = {
29057 .sg_tablesize = ATA_MAX_PRD
29058 };
29059
29060-static struct ata_port_operations sil_ops = {
29061+static const struct ata_port_operations sil_ops = {
29062 .inherits = &ata_bmdma32_port_ops,
29063 .dev_config = sil_dev_config,
29064 .set_mode = sil_set_mode,
29065diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
29066index e6946fc..eddb794 100644
29067--- a/drivers/ata/sata_sil24.c
29068+++ b/drivers/ata/sata_sil24.c
29069@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_sht = {
29070 .dma_boundary = ATA_DMA_BOUNDARY,
29071 };
29072
29073-static struct ata_port_operations sil24_ops = {
29074+static const struct ata_port_operations sil24_ops = {
29075 .inherits = &sata_pmp_port_ops,
29076
29077 .qc_defer = sil24_qc_defer,
29078diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
29079index f8a91bf..9cb06b6 100644
29080--- a/drivers/ata/sata_sis.c
29081+++ b/drivers/ata/sata_sis.c
29082@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht = {
29083 ATA_BMDMA_SHT(DRV_NAME),
29084 };
29085
29086-static struct ata_port_operations sis_ops = {
29087+static const struct ata_port_operations sis_ops = {
29088 .inherits = &ata_bmdma_port_ops,
29089 .scr_read = sis_scr_read,
29090 .scr_write = sis_scr_write,
29091diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
29092index 7257f2d..d04c6f5 100644
29093--- a/drivers/ata/sata_svw.c
29094+++ b/drivers/ata/sata_svw.c
29095@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata_sht = {
29096 };
29097
29098
29099-static struct ata_port_operations k2_sata_ops = {
29100+static const struct ata_port_operations k2_sata_ops = {
29101 .inherits = &ata_bmdma_port_ops,
29102 .sff_tf_load = k2_sata_tf_load,
29103 .sff_tf_read = k2_sata_tf_read,
29104diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
29105index bbcf970..cd0df0d 100644
29106--- a/drivers/ata/sata_sx4.c
29107+++ b/drivers/ata/sata_sx4.c
29108@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sata_sht = {
29109 };
29110
29111 /* TODO: inherit from base port_ops after converting to new EH */
29112-static struct ata_port_operations pdc_20621_ops = {
29113+static const struct ata_port_operations pdc_20621_ops = {
29114 .inherits = &ata_sff_port_ops,
29115
29116 .check_atapi_dma = pdc_check_atapi_dma,
29117diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
29118index e5bff47..089d859 100644
29119--- a/drivers/ata/sata_uli.c
29120+++ b/drivers/ata/sata_uli.c
29121@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht = {
29122 ATA_BMDMA_SHT(DRV_NAME),
29123 };
29124
29125-static struct ata_port_operations uli_ops = {
29126+static const struct ata_port_operations uli_ops = {
29127 .inherits = &ata_bmdma_port_ops,
29128 .scr_read = uli_scr_read,
29129 .scr_write = uli_scr_write,
29130diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
29131index f5dcca7..77b94eb 100644
29132--- a/drivers/ata/sata_via.c
29133+++ b/drivers/ata/sata_via.c
29134@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sht = {
29135 ATA_BMDMA_SHT(DRV_NAME),
29136 };
29137
29138-static struct ata_port_operations svia_base_ops = {
29139+static const struct ata_port_operations svia_base_ops = {
29140 .inherits = &ata_bmdma_port_ops,
29141 .sff_tf_load = svia_tf_load,
29142 };
29143
29144-static struct ata_port_operations vt6420_sata_ops = {
29145+static const struct ata_port_operations vt6420_sata_ops = {
29146 .inherits = &svia_base_ops,
29147 .freeze = svia_noop_freeze,
29148 .prereset = vt6420_prereset,
29149 .bmdma_start = vt6420_bmdma_start,
29150 };
29151
29152-static struct ata_port_operations vt6421_pata_ops = {
29153+static const struct ata_port_operations vt6421_pata_ops = {
29154 .inherits = &svia_base_ops,
29155 .cable_detect = vt6421_pata_cable_detect,
29156 .set_piomode = vt6421_set_pio_mode,
29157 .set_dmamode = vt6421_set_dma_mode,
29158 };
29159
29160-static struct ata_port_operations vt6421_sata_ops = {
29161+static const struct ata_port_operations vt6421_sata_ops = {
29162 .inherits = &svia_base_ops,
29163 .scr_read = svia_scr_read,
29164 .scr_write = svia_scr_write,
29165 };
29166
29167-static struct ata_port_operations vt8251_ops = {
29168+static const struct ata_port_operations vt8251_ops = {
29169 .inherits = &svia_base_ops,
29170 .hardreset = sata_std_hardreset,
29171 .scr_read = vt8251_scr_read,
29172diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
29173index 8b2a278..51e65d3 100644
29174--- a/drivers/ata/sata_vsc.c
29175+++ b/drivers/ata/sata_vsc.c
29176@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sata_sht = {
29177 };
29178
29179
29180-static struct ata_port_operations vsc_sata_ops = {
29181+static const struct ata_port_operations vsc_sata_ops = {
29182 .inherits = &ata_bmdma_port_ops,
29183 /* The IRQ handling is not quite standard SFF behaviour so we
29184 cannot use the default lost interrupt handler */
29185diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29186index 5effec6..7e4019a 100644
29187--- a/drivers/atm/adummy.c
29188+++ b/drivers/atm/adummy.c
29189@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29190 vcc->pop(vcc, skb);
29191 else
29192 dev_kfree_skb_any(skb);
29193- atomic_inc(&vcc->stats->tx);
29194+ atomic_inc_unchecked(&vcc->stats->tx);
29195
29196 return 0;
29197 }
29198diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29199index 66e1813..26a27c6 100644
29200--- a/drivers/atm/ambassador.c
29201+++ b/drivers/atm/ambassador.c
29202@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29203 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29204
29205 // VC layer stats
29206- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29207+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29208
29209 // free the descriptor
29210 kfree (tx_descr);
29211@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29212 dump_skb ("<<<", vc, skb);
29213
29214 // VC layer stats
29215- atomic_inc(&atm_vcc->stats->rx);
29216+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29217 __net_timestamp(skb);
29218 // end of our responsability
29219 atm_vcc->push (atm_vcc, skb);
29220@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29221 } else {
29222 PRINTK (KERN_INFO, "dropped over-size frame");
29223 // should we count this?
29224- atomic_inc(&atm_vcc->stats->rx_drop);
29225+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29226 }
29227
29228 } else {
29229@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29230 }
29231
29232 if (check_area (skb->data, skb->len)) {
29233- atomic_inc(&atm_vcc->stats->tx_err);
29234+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29235 return -ENOMEM; // ?
29236 }
29237
29238diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29239index 02ad83d..6daffeb 100644
29240--- a/drivers/atm/atmtcp.c
29241+++ b/drivers/atm/atmtcp.c
29242@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29243 if (vcc->pop) vcc->pop(vcc,skb);
29244 else dev_kfree_skb(skb);
29245 if (dev_data) return 0;
29246- atomic_inc(&vcc->stats->tx_err);
29247+ atomic_inc_unchecked(&vcc->stats->tx_err);
29248 return -ENOLINK;
29249 }
29250 size = skb->len+sizeof(struct atmtcp_hdr);
29251@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29252 if (!new_skb) {
29253 if (vcc->pop) vcc->pop(vcc,skb);
29254 else dev_kfree_skb(skb);
29255- atomic_inc(&vcc->stats->tx_err);
29256+ atomic_inc_unchecked(&vcc->stats->tx_err);
29257 return -ENOBUFS;
29258 }
29259 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29260@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29261 if (vcc->pop) vcc->pop(vcc,skb);
29262 else dev_kfree_skb(skb);
29263 out_vcc->push(out_vcc,new_skb);
29264- atomic_inc(&vcc->stats->tx);
29265- atomic_inc(&out_vcc->stats->rx);
29266+ atomic_inc_unchecked(&vcc->stats->tx);
29267+ atomic_inc_unchecked(&out_vcc->stats->rx);
29268 return 0;
29269 }
29270
29271@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29272 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29273 read_unlock(&vcc_sklist_lock);
29274 if (!out_vcc) {
29275- atomic_inc(&vcc->stats->tx_err);
29276+ atomic_inc_unchecked(&vcc->stats->tx_err);
29277 goto done;
29278 }
29279 skb_pull(skb,sizeof(struct atmtcp_hdr));
29280@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29281 __net_timestamp(new_skb);
29282 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29283 out_vcc->push(out_vcc,new_skb);
29284- atomic_inc(&vcc->stats->tx);
29285- atomic_inc(&out_vcc->stats->rx);
29286+ atomic_inc_unchecked(&vcc->stats->tx);
29287+ atomic_inc_unchecked(&out_vcc->stats->rx);
29288 done:
29289 if (vcc->pop) vcc->pop(vcc,skb);
29290 else dev_kfree_skb(skb);
29291diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29292index 0c30261..3da356e 100644
29293--- a/drivers/atm/eni.c
29294+++ b/drivers/atm/eni.c
29295@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29296 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29297 vcc->dev->number);
29298 length = 0;
29299- atomic_inc(&vcc->stats->rx_err);
29300+ atomic_inc_unchecked(&vcc->stats->rx_err);
29301 }
29302 else {
29303 length = ATM_CELL_SIZE-1; /* no HEC */
29304@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29305 size);
29306 }
29307 eff = length = 0;
29308- atomic_inc(&vcc->stats->rx_err);
29309+ atomic_inc_unchecked(&vcc->stats->rx_err);
29310 }
29311 else {
29312 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29313@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29314 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29315 vcc->dev->number,vcc->vci,length,size << 2,descr);
29316 length = eff = 0;
29317- atomic_inc(&vcc->stats->rx_err);
29318+ atomic_inc_unchecked(&vcc->stats->rx_err);
29319 }
29320 }
29321 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29322@@ -770,7 +770,7 @@ rx_dequeued++;
29323 vcc->push(vcc,skb);
29324 pushed++;
29325 }
29326- atomic_inc(&vcc->stats->rx);
29327+ atomic_inc_unchecked(&vcc->stats->rx);
29328 }
29329 wake_up(&eni_dev->rx_wait);
29330 }
29331@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29332 PCI_DMA_TODEVICE);
29333 if (vcc->pop) vcc->pop(vcc,skb);
29334 else dev_kfree_skb_irq(skb);
29335- atomic_inc(&vcc->stats->tx);
29336+ atomic_inc_unchecked(&vcc->stats->tx);
29337 wake_up(&eni_dev->tx_wait);
29338 dma_complete++;
29339 }
29340@@ -1570,7 +1570,7 @@ tx_complete++;
29341 /*--------------------------------- entries ---------------------------------*/
29342
29343
29344-static const char *media_name[] __devinitdata = {
29345+static const char *media_name[] __devinitconst = {
29346 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
29347 "UTP", "05?", "06?", "07?", /* 4- 7 */
29348 "TAXI","09?", "10?", "11?", /* 8-11 */
29349diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29350index cd5049a..a51209f 100644
29351--- a/drivers/atm/firestream.c
29352+++ b/drivers/atm/firestream.c
29353@@ -748,7 +748,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29354 }
29355 }
29356
29357- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29358+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29359
29360 fs_dprintk (FS_DEBUG_TXMEM, "i");
29361 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29362@@ -815,7 +815,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29363 #endif
29364 skb_put (skb, qe->p1 & 0xffff);
29365 ATM_SKB(skb)->vcc = atm_vcc;
29366- atomic_inc(&atm_vcc->stats->rx);
29367+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29368 __net_timestamp(skb);
29369 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29370 atm_vcc->push (atm_vcc, skb);
29371@@ -836,12 +836,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29372 kfree (pe);
29373 }
29374 if (atm_vcc)
29375- atomic_inc(&atm_vcc->stats->rx_drop);
29376+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29377 break;
29378 case 0x1f: /* Reassembly abort: no buffers. */
29379 /* Silently increment error counter. */
29380 if (atm_vcc)
29381- atomic_inc(&atm_vcc->stats->rx_drop);
29382+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29383 break;
29384 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29385 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29386diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29387index f766cc4..a34002e 100644
29388--- a/drivers/atm/fore200e.c
29389+++ b/drivers/atm/fore200e.c
29390@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29391 #endif
29392 /* check error condition */
29393 if (*entry->status & STATUS_ERROR)
29394- atomic_inc(&vcc->stats->tx_err);
29395+ atomic_inc_unchecked(&vcc->stats->tx_err);
29396 else
29397- atomic_inc(&vcc->stats->tx);
29398+ atomic_inc_unchecked(&vcc->stats->tx);
29399 }
29400 }
29401
29402@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29403 if (skb == NULL) {
29404 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29405
29406- atomic_inc(&vcc->stats->rx_drop);
29407+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29408 return -ENOMEM;
29409 }
29410
29411@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29412
29413 dev_kfree_skb_any(skb);
29414
29415- atomic_inc(&vcc->stats->rx_drop);
29416+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29417 return -ENOMEM;
29418 }
29419
29420 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29421
29422 vcc->push(vcc, skb);
29423- atomic_inc(&vcc->stats->rx);
29424+ atomic_inc_unchecked(&vcc->stats->rx);
29425
29426 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29427
29428@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29429 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29430 fore200e->atm_dev->number,
29431 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29432- atomic_inc(&vcc->stats->rx_err);
29433+ atomic_inc_unchecked(&vcc->stats->rx_err);
29434 }
29435 }
29436
29437@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29438 goto retry_here;
29439 }
29440
29441- atomic_inc(&vcc->stats->tx_err);
29442+ atomic_inc_unchecked(&vcc->stats->tx_err);
29443
29444 fore200e->tx_sat++;
29445 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29446diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29447index 7066703..2b130de 100644
29448--- a/drivers/atm/he.c
29449+++ b/drivers/atm/he.c
29450@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29451
29452 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29453 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29454- atomic_inc(&vcc->stats->rx_drop);
29455+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29456 goto return_host_buffers;
29457 }
29458
29459@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29460 RBRQ_LEN_ERR(he_dev->rbrq_head)
29461 ? "LEN_ERR" : "",
29462 vcc->vpi, vcc->vci);
29463- atomic_inc(&vcc->stats->rx_err);
29464+ atomic_inc_unchecked(&vcc->stats->rx_err);
29465 goto return_host_buffers;
29466 }
29467
29468@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29469 vcc->push(vcc, skb);
29470 spin_lock(&he_dev->global_lock);
29471
29472- atomic_inc(&vcc->stats->rx);
29473+ atomic_inc_unchecked(&vcc->stats->rx);
29474
29475 return_host_buffers:
29476 ++pdus_assembled;
29477@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
29478 tpd->vcc->pop(tpd->vcc, tpd->skb);
29479 else
29480 dev_kfree_skb_any(tpd->skb);
29481- atomic_inc(&tpd->vcc->stats->tx_err);
29482+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
29483 }
29484 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
29485 return;
29486@@ -2618,7 +2618,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
29495@@ -2629,7 +2629,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 return -EINVAL;
29502 }
29503 #endif
29504@@ -2641,7 +2641,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@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29514 vcc->pop(vcc, skb);
29515 else
29516 dev_kfree_skb_any(skb);
29517- atomic_inc(&vcc->stats->tx_err);
29518+ atomic_inc_unchecked(&vcc->stats->tx_err);
29519 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29520 return -ENOMEM;
29521 }
29522@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29523 __enqueue_tpd(he_dev, tpd, cid);
29524 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29525
29526- atomic_inc(&vcc->stats->tx);
29527+ atomic_inc_unchecked(&vcc->stats->tx);
29528
29529 return 0;
29530 }
29531diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
29532index 4e49021..01b1512 100644
29533--- a/drivers/atm/horizon.c
29534+++ b/drivers/atm/horizon.c
29535@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
29536 {
29537 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
29538 // VC layer stats
29539- atomic_inc(&vcc->stats->rx);
29540+ atomic_inc_unchecked(&vcc->stats->rx);
29541 __net_timestamp(skb);
29542 // end of our responsability
29543 vcc->push (vcc, skb);
29544@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
29545 dev->tx_iovec = NULL;
29546
29547 // VC layer stats
29548- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29549+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29550
29551 // free the skb
29552 hrz_kfree_skb (skb);
29553diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
29554index e33ae00..9deb4ab 100644
29555--- a/drivers/atm/idt77252.c
29556+++ b/drivers/atm/idt77252.c
29557@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
29558 else
29559 dev_kfree_skb(skb);
29560
29561- atomic_inc(&vcc->stats->tx);
29562+ atomic_inc_unchecked(&vcc->stats->tx);
29563 }
29564
29565 atomic_dec(&scq->used);
29566@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29567 if ((sb = dev_alloc_skb(64)) == NULL) {
29568 printk("%s: Can't allocate buffers for aal0.\n",
29569 card->name);
29570- atomic_add(i, &vcc->stats->rx_drop);
29571+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
29572 break;
29573 }
29574 if (!atm_charge(vcc, sb->truesize)) {
29575 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
29576 card->name);
29577- atomic_add(i - 1, &vcc->stats->rx_drop);
29578+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
29579 dev_kfree_skb(sb);
29580 break;
29581 }
29582@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29583 ATM_SKB(sb)->vcc = vcc;
29584 __net_timestamp(sb);
29585 vcc->push(vcc, sb);
29586- atomic_inc(&vcc->stats->rx);
29587+ atomic_inc_unchecked(&vcc->stats->rx);
29588
29589 cell += ATM_CELL_PAYLOAD;
29590 }
29591@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29592 "(CDC: %08x)\n",
29593 card->name, len, rpp->len, readl(SAR_REG_CDC));
29594 recycle_rx_pool_skb(card, rpp);
29595- atomic_inc(&vcc->stats->rx_err);
29596+ atomic_inc_unchecked(&vcc->stats->rx_err);
29597 return;
29598 }
29599 if (stat & SAR_RSQE_CRC) {
29600 RXPRINTK("%s: AAL5 CRC error.\n", 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 (skb_queue_len(&rpp->queue) > 1) {
29607@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29608 RXPRINTK("%s: Can't alloc RX skb.\n",
29609 card->name);
29610 recycle_rx_pool_skb(card, rpp);
29611- atomic_inc(&vcc->stats->rx_err);
29612+ atomic_inc_unchecked(&vcc->stats->rx_err);
29613 return;
29614 }
29615 if (!atm_charge(vcc, skb->truesize)) {
29616@@ -1169,7 +1169,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 return;
29624 }
29625@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29626 __net_timestamp(skb);
29627
29628 vcc->push(vcc, skb);
29629- atomic_inc(&vcc->stats->rx);
29630+ atomic_inc_unchecked(&vcc->stats->rx);
29631
29632 if (skb->truesize > SAR_FB_SIZE_3)
29633 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
29634@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
29635 if (vcc->qos.aal != ATM_AAL0) {
29636 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
29637 card->name, vpi, vci);
29638- atomic_inc(&vcc->stats->rx_drop);
29639+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29640 goto drop;
29641 }
29642
29643 if ((sb = dev_alloc_skb(64)) == NULL) {
29644 printk("%s: Can't allocate buffers for AAL0.\n",
29645 card->name);
29646- atomic_inc(&vcc->stats->rx_err);
29647+ atomic_inc_unchecked(&vcc->stats->rx_err);
29648 goto drop;
29649 }
29650
29651@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
29652 ATM_SKB(sb)->vcc = vcc;
29653 __net_timestamp(sb);
29654 vcc->push(vcc, sb);
29655- atomic_inc(&vcc->stats->rx);
29656+ atomic_inc_unchecked(&vcc->stats->rx);
29657
29658 drop:
29659 skb_pull(queue, 64);
29660@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29661
29662 if (vc == NULL) {
29663 printk("%s: NULL connection in send().\n", card->name);
29664- atomic_inc(&vcc->stats->tx_err);
29665+ atomic_inc_unchecked(&vcc->stats->tx_err);
29666 dev_kfree_skb(skb);
29667 return -EINVAL;
29668 }
29669 if (!test_bit(VCF_TX, &vc->flags)) {
29670 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
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@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29677 break;
29678 default:
29679 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
29680- atomic_inc(&vcc->stats->tx_err);
29681+ atomic_inc_unchecked(&vcc->stats->tx_err);
29682 dev_kfree_skb(skb);
29683 return -EINVAL;
29684 }
29685
29686 if (skb_shinfo(skb)->nr_frags != 0) {
29687 printk("%s: No scatter-gather yet.\n", card->name);
29688- atomic_inc(&vcc->stats->tx_err);
29689+ atomic_inc_unchecked(&vcc->stats->tx_err);
29690 dev_kfree_skb(skb);
29691 return -EINVAL;
29692 }
29693@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29694
29695 err = queue_skb(card, vc, skb, oam);
29696 if (err) {
29697- atomic_inc(&vcc->stats->tx_err);
29698+ atomic_inc_unchecked(&vcc->stats->tx_err);
29699 dev_kfree_skb(skb);
29700 return err;
29701 }
29702@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
29703 skb = dev_alloc_skb(64);
29704 if (!skb) {
29705 printk("%s: Out of memory in send_oam().\n", card->name);
29706- atomic_inc(&vcc->stats->tx_err);
29707+ atomic_inc_unchecked(&vcc->stats->tx_err);
29708 return -ENOMEM;
29709 }
29710 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
29711diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
29712index b2c1b37..faa672b 100644
29713--- a/drivers/atm/iphase.c
29714+++ b/drivers/atm/iphase.c
29715@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
29716 status = (u_short) (buf_desc_ptr->desc_mode);
29717 if (status & (RX_CER | RX_PTE | RX_OFL))
29718 {
29719- atomic_inc(&vcc->stats->rx_err);
29720+ atomic_inc_unchecked(&vcc->stats->rx_err);
29721 IF_ERR(printk("IA: bad packet, dropping it");)
29722 if (status & RX_CER) {
29723 IF_ERR(printk(" cause: packet CRC error\n");)
29724@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
29725 len = dma_addr - buf_addr;
29726 if (len > iadev->rx_buf_sz) {
29727 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
29728- atomic_inc(&vcc->stats->rx_err);
29729+ atomic_inc_unchecked(&vcc->stats->rx_err);
29730 goto out_free_desc;
29731 }
29732
29733@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29734 ia_vcc = INPH_IA_VCC(vcc);
29735 if (ia_vcc == NULL)
29736 {
29737- atomic_inc(&vcc->stats->rx_err);
29738+ atomic_inc_unchecked(&vcc->stats->rx_err);
29739 dev_kfree_skb_any(skb);
29740 atm_return(vcc, atm_guess_pdu2truesize(len));
29741 goto INCR_DLE;
29742@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29743 if ((length > iadev->rx_buf_sz) || (length >
29744 (skb->len - sizeof(struct cpcs_trailer))))
29745 {
29746- atomic_inc(&vcc->stats->rx_err);
29747+ atomic_inc_unchecked(&vcc->stats->rx_err);
29748 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
29749 length, skb->len);)
29750 dev_kfree_skb_any(skb);
29751@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29752
29753 IF_RX(printk("rx_dle_intr: skb push");)
29754 vcc->push(vcc,skb);
29755- atomic_inc(&vcc->stats->rx);
29756+ atomic_inc_unchecked(&vcc->stats->rx);
29757 iadev->rx_pkt_cnt++;
29758 }
29759 INCR_DLE:
29760@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
29761 {
29762 struct k_sonet_stats *stats;
29763 stats = &PRIV(_ia_dev[board])->sonet_stats;
29764- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
29765- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
29766- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
29767- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
29768- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
29769- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
29770- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
29771- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
29772- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
29773+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
29774+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
29775+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
29776+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
29777+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
29778+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
29779+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
29780+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
29781+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
29782 }
29783 ia_cmds.status = 0;
29784 break;
29785@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29786 if ((desc == 0) || (desc > iadev->num_tx_desc))
29787 {
29788 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
29789- atomic_inc(&vcc->stats->tx);
29790+ atomic_inc_unchecked(&vcc->stats->tx);
29791 if (vcc->pop)
29792 vcc->pop(vcc, skb);
29793 else
29794@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29795 ATM_DESC(skb) = vcc->vci;
29796 skb_queue_tail(&iadev->tx_dma_q, skb);
29797
29798- atomic_inc(&vcc->stats->tx);
29799+ atomic_inc_unchecked(&vcc->stats->tx);
29800 iadev->tx_pkt_cnt++;
29801 /* Increment transaction counter */
29802 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29803
29804 #if 0
29805 /* add flow control logic */
29806- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29807+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29808 if (iavcc->vc_desc_cnt > 10) {
29809 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29810 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29811diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29812index cf97c34..8d30655 100644
29813--- a/drivers/atm/lanai.c
29814+++ b/drivers/atm/lanai.c
29815@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29816 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29817 lanai_endtx(lanai, lvcc);
29818 lanai_free_skb(lvcc->tx.atmvcc, skb);
29819- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29820+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29821 }
29822
29823 /* Try to fill the buffer - don't call unless there is backlog */
29824@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29825 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29826 __net_timestamp(skb);
29827 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29828- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29829+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29830 out:
29831 lvcc->rx.buf.ptr = end;
29832 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29833@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29834 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29835 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29836 lanai->stats.service_rxnotaal5++;
29837- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29838+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29839 return 0;
29840 }
29841 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29842@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29843 int bytes;
29844 read_unlock(&vcc_sklist_lock);
29845 DPRINTK("got trashed rx pdu on vci %d\n", vci);
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_trash++;
29849 bytes = (SERVICE_GET_END(s) * 16) -
29850 (((unsigned long) lvcc->rx.buf.ptr) -
29851@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29852 }
29853 if (s & SERVICE_STREAM) {
29854 read_unlock(&vcc_sklist_lock);
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_stream++;
29858 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29859 "PDU on VCI %d!\n", lanai->number, vci);
29860@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29861 return 0;
29862 }
29863 DPRINTK("got rx crc error on vci %d\n", vci);
29864- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29865+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29866 lvcc->stats.x.aal5.service_rxcrc++;
29867 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29868 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29869diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29870index 3da804b..d3b0eed 100644
29871--- a/drivers/atm/nicstar.c
29872+++ b/drivers/atm/nicstar.c
29873@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29874 if ((vc = (vc_map *) vcc->dev_data) == NULL)
29875 {
29876 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\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@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29883 if (!vc->tx)
29884 {
29885 printk("nicstar%d: Trying to transmit on a non-tx VC.\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@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29892 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
29893 {
29894 printk("nicstar%d: Only AAL0 and AAL5 are supported.\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@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29901 if (skb_shinfo(skb)->nr_frags != 0)
29902 {
29903 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29904- atomic_inc(&vcc->stats->tx_err);
29905+ atomic_inc_unchecked(&vcc->stats->tx_err);
29906 dev_kfree_skb_any(skb);
29907 return -EINVAL;
29908 }
29909@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29910
29911 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
29912 {
29913- atomic_inc(&vcc->stats->tx_err);
29914+ atomic_inc_unchecked(&vcc->stats->tx_err);
29915 dev_kfree_skb_any(skb);
29916 return -EIO;
29917 }
29918- atomic_inc(&vcc->stats->tx);
29919+ atomic_inc_unchecked(&vcc->stats->tx);
29920
29921 return 0;
29922 }
29923@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29924 {
29925 printk("nicstar%d: Can't allocate buffers for aal0.\n",
29926 card->index);
29927- atomic_add(i,&vcc->stats->rx_drop);
29928+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
29929 break;
29930 }
29931 if (!atm_charge(vcc, sb->truesize))
29932 {
29933 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
29934 card->index);
29935- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
29936+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
29937 dev_kfree_skb_any(sb);
29938 break;
29939 }
29940@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29941 ATM_SKB(sb)->vcc = vcc;
29942 __net_timestamp(sb);
29943 vcc->push(vcc, sb);
29944- atomic_inc(&vcc->stats->rx);
29945+ atomic_inc_unchecked(&vcc->stats->rx);
29946 cell += ATM_CELL_PAYLOAD;
29947 }
29948
29949@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29950 if (iovb == NULL)
29951 {
29952 printk("nicstar%d: Out of iovec buffers.\n", card->index);
29953- atomic_inc(&vcc->stats->rx_drop);
29954+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29955 recycle_rx_buf(card, skb);
29956 return;
29957 }
29958@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29959 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
29960 {
29961 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29962- atomic_inc(&vcc->stats->rx_err);
29963+ atomic_inc_unchecked(&vcc->stats->rx_err);
29964 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
29965 NS_SKB(iovb)->iovcnt = 0;
29966 iovb->len = 0;
29967@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29968 printk("nicstar%d: Expected a small 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_rx_buf(card, skb);
29974 vc->rx_iov = NULL;
29975 recycle_iov_buf(card, iovb);
29976@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29977 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
29978 card->index);
29979 which_list(card, skb);
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@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29986 printk(" - PDU size mismatch.\n");
29987 else
29988 printk(".\n");
29989- atomic_inc(&vcc->stats->rx_err);
29990+ atomic_inc_unchecked(&vcc->stats->rx_err);
29991 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
29992 NS_SKB(iovb)->iovcnt);
29993 vc->rx_iov = NULL;
29994@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29995 if (!atm_charge(vcc, skb->truesize))
29996 {
29997 push_rxbufs(card, skb);
29998- atomic_inc(&vcc->stats->rx_drop);
29999+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30000 }
30001 else
30002 {
30003@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30004 ATM_SKB(skb)->vcc = vcc;
30005 __net_timestamp(skb);
30006 vcc->push(vcc, skb);
30007- atomic_inc(&vcc->stats->rx);
30008+ atomic_inc_unchecked(&vcc->stats->rx);
30009 }
30010 }
30011 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
30012@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30013 if (!atm_charge(vcc, sb->truesize))
30014 {
30015 push_rxbufs(card, sb);
30016- atomic_inc(&vcc->stats->rx_drop);
30017+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30018 }
30019 else
30020 {
30021@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30022 ATM_SKB(sb)->vcc = vcc;
30023 __net_timestamp(sb);
30024 vcc->push(vcc, sb);
30025- atomic_inc(&vcc->stats->rx);
30026+ atomic_inc_unchecked(&vcc->stats->rx);
30027 }
30028
30029 push_rxbufs(card, skb);
30030@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30031 if (!atm_charge(vcc, skb->truesize))
30032 {
30033 push_rxbufs(card, skb);
30034- atomic_inc(&vcc->stats->rx_drop);
30035+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30036 }
30037 else
30038 {
30039@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30040 ATM_SKB(skb)->vcc = vcc;
30041 __net_timestamp(skb);
30042 vcc->push(vcc, skb);
30043- atomic_inc(&vcc->stats->rx);
30044+ atomic_inc_unchecked(&vcc->stats->rx);
30045 }
30046
30047 push_rxbufs(card, sb);
30048@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30049 if (hb == NULL)
30050 {
30051 printk("nicstar%d: Out of huge buffers.\n", card->index);
30052- atomic_inc(&vcc->stats->rx_drop);
30053+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30054 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30055 NS_SKB(iovb)->iovcnt);
30056 vc->rx_iov = NULL;
30057@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30058 }
30059 else
30060 dev_kfree_skb_any(hb);
30061- atomic_inc(&vcc->stats->rx_drop);
30062+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30063 }
30064 else
30065 {
30066@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30067 #endif /* NS_USE_DESTRUCTORS */
30068 __net_timestamp(hb);
30069 vcc->push(vcc, hb);
30070- atomic_inc(&vcc->stats->rx);
30071+ atomic_inc_unchecked(&vcc->stats->rx);
30072 }
30073 }
30074
30075diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30076index 84c93ff..e6ed269 100644
30077--- a/drivers/atm/solos-pci.c
30078+++ b/drivers/atm/solos-pci.c
30079@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
30080 }
30081 atm_charge(vcc, skb->truesize);
30082 vcc->push(vcc, skb);
30083- atomic_inc(&vcc->stats->rx);
30084+ atomic_inc_unchecked(&vcc->stats->rx);
30085 break;
30086
30087 case PKT_STATUS:
30088@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *buf)
30089 char msg[500];
30090 char item[10];
30091
30092+ pax_track_stack();
30093+
30094 len = buf->len;
30095 for (i = 0; i < len; i++){
30096 if(i % 8 == 0)
30097@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30098 vcc = SKB_CB(oldskb)->vcc;
30099
30100 if (vcc) {
30101- atomic_inc(&vcc->stats->tx);
30102+ atomic_inc_unchecked(&vcc->stats->tx);
30103 solos_pop(vcc, oldskb);
30104 } else
30105 dev_kfree_skb_irq(oldskb);
30106diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30107index 6dd3f59..ee377f3 100644
30108--- a/drivers/atm/suni.c
30109+++ b/drivers/atm/suni.c
30110@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30111
30112
30113 #define ADD_LIMITED(s,v) \
30114- atomic_add((v),&stats->s); \
30115- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30116+ atomic_add_unchecked((v),&stats->s); \
30117+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30118
30119
30120 static void suni_hz(unsigned long from_timer)
30121diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30122index fc8cb07..4a80e53 100644
30123--- a/drivers/atm/uPD98402.c
30124+++ b/drivers/atm/uPD98402.c
30125@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30126 struct sonet_stats tmp;
30127 int error = 0;
30128
30129- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30130+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30131 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30132 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30133 if (zero && !error) {
30134@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30135
30136
30137 #define ADD_LIMITED(s,v) \
30138- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30139- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30140- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30141+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30142+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30143+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30144
30145
30146 static void stat_event(struct atm_dev *dev)
30147@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev *dev)
30148 if (reason & uPD98402_INT_PFM) stat_event(dev);
30149 if (reason & uPD98402_INT_PCO) {
30150 (void) GET(PCOCR); /* clear interrupt cause */
30151- atomic_add(GET(HECCT),
30152+ atomic_add_unchecked(GET(HECCT),
30153 &PRIV(dev)->sonet_stats.uncorr_hcs);
30154 }
30155 if ((reason & uPD98402_INT_RFO) &&
30156@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev *dev)
30157 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30158 uPD98402_INT_LOS),PIMR); /* enable them */
30159 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30160- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30161- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30162- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30163+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30164+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30165+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30166 return 0;
30167 }
30168
30169diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30170index 2e9635b..32927b4 100644
30171--- a/drivers/atm/zatm.c
30172+++ b/drivers/atm/zatm.c
30173@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30174 }
30175 if (!size) {
30176 dev_kfree_skb_irq(skb);
30177- if (vcc) atomic_inc(&vcc->stats->rx_err);
30178+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30179 continue;
30180 }
30181 if (!atm_charge(vcc,skb->truesize)) {
30182@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30183 skb->len = size;
30184 ATM_SKB(skb)->vcc = vcc;
30185 vcc->push(vcc,skb);
30186- atomic_inc(&vcc->stats->rx);
30187+ atomic_inc_unchecked(&vcc->stats->rx);
30188 }
30189 zout(pos & 0xffff,MTA(mbx));
30190 #if 0 /* probably a stupid idea */
30191@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30192 skb_queue_head(&zatm_vcc->backlog,skb);
30193 break;
30194 }
30195- atomic_inc(&vcc->stats->tx);
30196+ atomic_inc_unchecked(&vcc->stats->tx);
30197 wake_up(&zatm_vcc->tx_wait);
30198 }
30199
30200diff --git a/drivers/base/bus.c b/drivers/base/bus.c
30201index 63c143e..fece183 100644
30202--- a/drivers/base/bus.c
30203+++ b/drivers/base/bus.c
30204@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
30205 return ret;
30206 }
30207
30208-static struct sysfs_ops driver_sysfs_ops = {
30209+static const struct sysfs_ops driver_sysfs_ops = {
30210 .show = drv_attr_show,
30211 .store = drv_attr_store,
30212 };
30213@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
30214 return ret;
30215 }
30216
30217-static struct sysfs_ops bus_sysfs_ops = {
30218+static const struct sysfs_ops bus_sysfs_ops = {
30219 .show = bus_attr_show,
30220 .store = bus_attr_store,
30221 };
30222@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
30223 return 0;
30224 }
30225
30226-static struct kset_uevent_ops bus_uevent_ops = {
30227+static const struct kset_uevent_ops bus_uevent_ops = {
30228 .filter = bus_uevent_filter,
30229 };
30230
30231diff --git a/drivers/base/class.c b/drivers/base/class.c
30232index 6e2c3b0..cb61871 100644
30233--- a/drivers/base/class.c
30234+++ b/drivers/base/class.c
30235@@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj)
30236 kfree(cp);
30237 }
30238
30239-static struct sysfs_ops class_sysfs_ops = {
30240+static const struct sysfs_ops class_sysfs_ops = {
30241 .show = class_attr_show,
30242 .store = class_attr_store,
30243 };
30244diff --git a/drivers/base/core.c b/drivers/base/core.c
30245index f33d768..a9358d0 100644
30246--- a/drivers/base/core.c
30247+++ b/drivers/base/core.c
30248@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
30249 return ret;
30250 }
30251
30252-static struct sysfs_ops dev_sysfs_ops = {
30253+static const struct sysfs_ops dev_sysfs_ops = {
30254 .show = dev_attr_show,
30255 .store = dev_attr_store,
30256 };
30257@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
30258 return retval;
30259 }
30260
30261-static struct kset_uevent_ops device_uevent_ops = {
30262+static const struct kset_uevent_ops device_uevent_ops = {
30263 .filter = dev_uevent_filter,
30264 .name = dev_uevent_name,
30265 .uevent = dev_uevent,
30266diff --git a/drivers/base/memory.c b/drivers/base/memory.c
30267index 989429c..2272b00 100644
30268--- a/drivers/base/memory.c
30269+++ b/drivers/base/memory.c
30270@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
30271 return retval;
30272 }
30273
30274-static struct kset_uevent_ops memory_uevent_ops = {
30275+static const struct kset_uevent_ops memory_uevent_ops = {
30276 .name = memory_uevent_name,
30277 .uevent = memory_uevent,
30278 };
30279diff --git a/drivers/base/sys.c b/drivers/base/sys.c
30280index 3f202f7..61c4a6f 100644
30281--- a/drivers/base/sys.c
30282+++ b/drivers/base/sys.c
30283@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr,
30284 return -EIO;
30285 }
30286
30287-static struct sysfs_ops sysfs_ops = {
30288+static const struct sysfs_ops sysfs_ops = {
30289 .show = sysdev_show,
30290 .store = sysdev_store,
30291 };
30292@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
30293 return -EIO;
30294 }
30295
30296-static struct sysfs_ops sysfs_class_ops = {
30297+static const struct sysfs_ops sysfs_class_ops = {
30298 .show = sysdev_class_show,
30299 .store = sysdev_class_store,
30300 };
30301diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
30302index eb4fa19..1954777 100644
30303--- a/drivers/block/DAC960.c
30304+++ b/drivers/block/DAC960.c
30305@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
30306 unsigned long flags;
30307 int Channel, TargetID;
30308
30309+ pax_track_stack();
30310+
30311 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
30312 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
30313 sizeof(DAC960_SCSI_Inquiry_T) +
30314diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30315index ca9c548..ca6899c 100644
30316--- a/drivers/block/cciss.c
30317+++ b/drivers/block/cciss.c
30318@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30319 int err;
30320 u32 cp;
30321
30322+ memset(&arg64, 0, sizeof(arg64));
30323+
30324 err = 0;
30325 err |=
30326 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30327@@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ctlr)
30328 /* Wait (up to 20 seconds) for a command to complete */
30329
30330 for (i = 20 * HZ; i > 0; i--) {
30331- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30332+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30333 if (done == FIFO_EMPTY)
30334 schedule_timeout_uninterruptible(1);
30335 else
30336@@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
30337 resend_cmd1:
30338
30339 /* Disable interrupt on the board. */
30340- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30341+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30342
30343 /* Make sure there is room in the command FIFO */
30344 /* Actually it should be completely empty at this time */
30345@@ -2884,13 +2886,13 @@ resend_cmd1:
30346 /* tape side of the driver. */
30347 for (i = 200000; i > 0; i--) {
30348 /* if fifo isn't full go */
30349- if (!(h->access.fifo_full(h)))
30350+ if (!(h->access->fifo_full(h)))
30351 break;
30352 udelay(10);
30353 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
30354 " waiting!\n", h->ctlr);
30355 }
30356- h->access.submit_command(h, c); /* Send the cmd */
30357+ h->access->submit_command(h, c); /* Send the cmd */
30358 do {
30359 complete = pollcomplete(h->ctlr);
30360
30361@@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
30362 while (!hlist_empty(&h->reqQ)) {
30363 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
30364 /* can't do anything if fifo is full */
30365- if ((h->access.fifo_full(h))) {
30366+ if ((h->access->fifo_full(h))) {
30367 printk(KERN_WARNING "cciss: fifo full\n");
30368 break;
30369 }
30370@@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
30371 h->Qdepth--;
30372
30373 /* Tell the controller execute command */
30374- h->access.submit_command(h, c);
30375+ h->access->submit_command(h, c);
30376
30377 /* Put job onto the completed Q */
30378 addQ(&h->cmpQ, c);
30379@@ -3393,17 +3395,17 @@ startio:
30380
30381 static inline unsigned long get_next_completion(ctlr_info_t *h)
30382 {
30383- return h->access.command_completed(h);
30384+ return h->access->command_completed(h);
30385 }
30386
30387 static inline int interrupt_pending(ctlr_info_t *h)
30388 {
30389- return h->access.intr_pending(h);
30390+ return h->access->intr_pending(h);
30391 }
30392
30393 static inline long interrupt_not_for_us(ctlr_info_t *h)
30394 {
30395- return (((h->access.intr_pending(h) == 0) ||
30396+ return (((h->access->intr_pending(h) == 0) ||
30397 (h->interrupts_enabled == 0)));
30398 }
30399
30400@@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
30401 */
30402 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
30403 c->product_name = products[prod_index].product_name;
30404- c->access = *(products[prod_index].access);
30405+ c->access = products[prod_index].access;
30406 c->nr_cmds = c->max_commands - 4;
30407 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
30408 (readb(&c->cfgtable->Signature[1]) != 'I') ||
30409@@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30410 }
30411
30412 /* make sure the board interrupts are off */
30413- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
30414+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
30415 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
30416 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
30417 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
30418@@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30419 cciss_scsi_setup(i);
30420
30421 /* Turn the interrupts on so we can service requests */
30422- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
30423+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
30424
30425 /* Get the firmware version */
30426 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30427diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30428index 04d6bf8..36e712d 100644
30429--- a/drivers/block/cciss.h
30430+++ b/drivers/block/cciss.h
30431@@ -90,7 +90,7 @@ struct ctlr_info
30432 // information about each logical volume
30433 drive_info_struct *drv[CISS_MAX_LUN];
30434
30435- struct access_method access;
30436+ struct access_method *access;
30437
30438 /* queue and queue Info */
30439 struct hlist_head reqQ;
30440diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30441index 6422651..bb1bdef 100644
30442--- a/drivers/block/cpqarray.c
30443+++ b/drivers/block/cpqarray.c
30444@@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30445 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30446 goto Enomem4;
30447 }
30448- hba[i]->access.set_intr_mask(hba[i], 0);
30449+ hba[i]->access->set_intr_mask(hba[i], 0);
30450 if (request_irq(hba[i]->intr, do_ida_intr,
30451 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30452 {
30453@@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30454 add_timer(&hba[i]->timer);
30455
30456 /* Enable IRQ now that spinlock and rate limit timer are set up */
30457- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30458+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30459
30460 for(j=0; j<NWD; j++) {
30461 struct gendisk *disk = ida_gendisk[i][j];
30462@@ -695,7 +695,7 @@ DBGINFO(
30463 for(i=0; i<NR_PRODUCTS; i++) {
30464 if (board_id == products[i].board_id) {
30465 c->product_name = products[i].product_name;
30466- c->access = *(products[i].access);
30467+ c->access = products[i].access;
30468 break;
30469 }
30470 }
30471@@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(void)
30472 hba[ctlr]->intr = intr;
30473 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30474 hba[ctlr]->product_name = products[j].product_name;
30475- hba[ctlr]->access = *(products[j].access);
30476+ hba[ctlr]->access = products[j].access;
30477 hba[ctlr]->ctlr = ctlr;
30478 hba[ctlr]->board_id = board_id;
30479 hba[ctlr]->pci_dev = NULL; /* not PCI */
30480@@ -896,6 +896,8 @@ static void do_ida_request(struct request_queue *q)
30481 struct scatterlist tmp_sg[SG_MAX];
30482 int i, dir, seg;
30483
30484+ pax_track_stack();
30485+
30486 if (blk_queue_plugged(q))
30487 goto startio;
30488
30489@@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
30490
30491 while((c = h->reqQ) != NULL) {
30492 /* Can't do anything if we're busy */
30493- if (h->access.fifo_full(h) == 0)
30494+ if (h->access->fifo_full(h) == 0)
30495 return;
30496
30497 /* Get the first entry from the request Q */
30498@@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
30499 h->Qdepth--;
30500
30501 /* Tell the controller to do our bidding */
30502- h->access.submit_command(h, c);
30503+ h->access->submit_command(h, c);
30504
30505 /* Get onto the completion Q */
30506 addQ(&h->cmpQ, c);
30507@@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30508 unsigned long flags;
30509 __u32 a,a1;
30510
30511- istat = h->access.intr_pending(h);
30512+ istat = h->access->intr_pending(h);
30513 /* Is this interrupt for us? */
30514 if (istat == 0)
30515 return IRQ_NONE;
30516@@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30517 */
30518 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30519 if (istat & FIFO_NOT_EMPTY) {
30520- while((a = h->access.command_completed(h))) {
30521+ while((a = h->access->command_completed(h))) {
30522 a1 = a; a &= ~3;
30523 if ((c = h->cmpQ) == NULL)
30524 {
30525@@ -1434,11 +1436,11 @@ static int sendcmd(
30526 /*
30527 * Disable interrupt
30528 */
30529- info_p->access.set_intr_mask(info_p, 0);
30530+ info_p->access->set_intr_mask(info_p, 0);
30531 /* Make sure there is room in the command FIFO */
30532 /* Actually it should be completely empty at this time. */
30533 for (i = 200000; i > 0; i--) {
30534- temp = info_p->access.fifo_full(info_p);
30535+ temp = info_p->access->fifo_full(info_p);
30536 if (temp != 0) {
30537 break;
30538 }
30539@@ -1451,7 +1453,7 @@ DBG(
30540 /*
30541 * Send the cmd
30542 */
30543- info_p->access.submit_command(info_p, c);
30544+ info_p->access->submit_command(info_p, c);
30545 complete = pollcomplete(ctlr);
30546
30547 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
30548@@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t *host)
30549 * we check the new geometry. Then turn interrupts back on when
30550 * we're done.
30551 */
30552- host->access.set_intr_mask(host, 0);
30553+ host->access->set_intr_mask(host, 0);
30554 getgeometry(ctlr);
30555- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
30556+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
30557
30558 for(i=0; i<NWD; i++) {
30559 struct gendisk *disk = ida_gendisk[ctlr][i];
30560@@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
30561 /* Wait (up to 2 seconds) for a command to complete */
30562
30563 for (i = 200000; i > 0; i--) {
30564- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30565+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30566 if (done == 0) {
30567 udelay(10); /* a short fixed delay */
30568 } else
30569diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
30570index be73e9d..7fbf140 100644
30571--- a/drivers/block/cpqarray.h
30572+++ b/drivers/block/cpqarray.h
30573@@ -99,7 +99,7 @@ struct ctlr_info {
30574 drv_info_t drv[NWD];
30575 struct proc_dir_entry *proc;
30576
30577- struct access_method access;
30578+ struct access_method *access;
30579
30580 cmdlist_t *reqQ;
30581 cmdlist_t *cmpQ;
30582diff --git a/drivers/block/loop.c b/drivers/block/loop.c
30583index 8ec2d70..2804b30 100644
30584--- a/drivers/block/loop.c
30585+++ b/drivers/block/loop.c
30586@@ -282,7 +282,7 @@ static int __do_lo_send_write(struct file *file,
30587 mm_segment_t old_fs = get_fs();
30588
30589 set_fs(get_ds());
30590- bw = file->f_op->write(file, buf, len, &pos);
30591+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
30592 set_fs(old_fs);
30593 if (likely(bw == len))
30594 return 0;
30595diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
30596index 26ada47..083c480 100644
30597--- a/drivers/block/nbd.c
30598+++ b/drivers/block/nbd.c
30599@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
30600 struct kvec iov;
30601 sigset_t blocked, oldset;
30602
30603+ pax_track_stack();
30604+
30605 if (unlikely(!sock)) {
30606 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
30607 lo->disk->disk_name, (send ? "send" : "recv"));
30608@@ -569,6 +571,8 @@ static void do_nbd_request(struct request_queue *q)
30609 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
30610 unsigned int cmd, unsigned long arg)
30611 {
30612+ pax_track_stack();
30613+
30614 switch (cmd) {
30615 case NBD_DISCONNECT: {
30616 struct request sreq;
30617diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
30618index a5d585d..d087be3 100644
30619--- a/drivers/block/pktcdvd.c
30620+++ b/drivers/block/pktcdvd.c
30621@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
30622 return len;
30623 }
30624
30625-static struct sysfs_ops kobj_pkt_ops = {
30626+static const struct sysfs_ops kobj_pkt_ops = {
30627 .show = kobj_pkt_show,
30628 .store = kobj_pkt_store
30629 };
30630diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
30631index 6aad99e..89cd142 100644
30632--- a/drivers/char/Kconfig
30633+++ b/drivers/char/Kconfig
30634@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
30635
30636 config DEVKMEM
30637 bool "/dev/kmem virtual device support"
30638- default y
30639+ default n
30640+ depends on !GRKERNSEC_KMEM
30641 help
30642 Say Y here if you want to support the /dev/kmem device. The
30643 /dev/kmem device is rarely used, but can be used for certain
30644@@ -1114,6 +1115,7 @@ config DEVPORT
30645 bool
30646 depends on !M68K
30647 depends on ISA || PCI
30648+ depends on !GRKERNSEC_KMEM
30649 default y
30650
30651 source "drivers/s390/char/Kconfig"
30652diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
30653index a96f319..a778a5b 100644
30654--- a/drivers/char/agp/frontend.c
30655+++ b/drivers/char/agp/frontend.c
30656@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
30657 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
30658 return -EFAULT;
30659
30660- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
30661+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
30662 return -EFAULT;
30663
30664 client = agp_find_client_by_pid(reserve.pid);
30665diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
30666index d8cff90..9628e70 100644
30667--- a/drivers/char/briq_panel.c
30668+++ b/drivers/char/briq_panel.c
30669@@ -10,6 +10,7 @@
30670 #include <linux/types.h>
30671 #include <linux/errno.h>
30672 #include <linux/tty.h>
30673+#include <linux/mutex.h>
30674 #include <linux/timer.h>
30675 #include <linux/kernel.h>
30676 #include <linux/wait.h>
30677@@ -36,6 +37,7 @@ static int vfd_is_open;
30678 static unsigned char vfd[40];
30679 static int vfd_cursor;
30680 static unsigned char ledpb, led;
30681+static DEFINE_MUTEX(vfd_mutex);
30682
30683 static void update_vfd(void)
30684 {
30685@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30686 if (!vfd_is_open)
30687 return -EBUSY;
30688
30689+ mutex_lock(&vfd_mutex);
30690 for (;;) {
30691 char c;
30692 if (!indx)
30693 break;
30694- if (get_user(c, buf))
30695+ if (get_user(c, buf)) {
30696+ mutex_unlock(&vfd_mutex);
30697 return -EFAULT;
30698+ }
30699 if (esc) {
30700 set_led(c);
30701 esc = 0;
30702@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30703 buf++;
30704 }
30705 update_vfd();
30706+ mutex_unlock(&vfd_mutex);
30707
30708 return len;
30709 }
30710diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
30711index 31e7c91..161afc0 100644
30712--- a/drivers/char/genrtc.c
30713+++ b/drivers/char/genrtc.c
30714@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
30715 switch (cmd) {
30716
30717 case RTC_PLL_GET:
30718+ memset(&pll, 0, sizeof(pll));
30719 if (get_rtc_pll(&pll))
30720 return -EINVAL;
30721 else
30722diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
30723index 006466d..a2bb21c 100644
30724--- a/drivers/char/hpet.c
30725+++ b/drivers/char/hpet.c
30726@@ -430,7 +430,7 @@ static int hpet_release(struct inode *inode, struct file *file)
30727 return 0;
30728 }
30729
30730-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
30731+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
30732
30733 static int
30734 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
30735@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
30736 }
30737
30738 static int
30739-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30740+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
30741 {
30742 struct hpet_timer __iomem *timer;
30743 struct hpet __iomem *hpet;
30744@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30745 {
30746 struct hpet_info info;
30747
30748+ memset(&info, 0, sizeof(info));
30749+
30750 if (devp->hd_ireqfreq)
30751 info.hi_ireqfreq =
30752 hpet_time_div(hpetp, devp->hd_ireqfreq);
30753- else
30754- info.hi_ireqfreq = 0;
30755 info.hi_flags =
30756 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
30757 info.hi_hpet = hpetp->hp_which;
30758diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c
30759index 0afc8b8..6913fc3 100644
30760--- a/drivers/char/hvc_beat.c
30761+++ b/drivers/char/hvc_beat.c
30762@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
30763 return cnt;
30764 }
30765
30766-static struct hv_ops hvc_beat_get_put_ops = {
30767+static const struct hv_ops hvc_beat_get_put_ops = {
30768 .get_chars = hvc_beat_get_chars,
30769 .put_chars = hvc_beat_put_chars,
30770 };
30771diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
30772index 98097f2..407dddc 100644
30773--- a/drivers/char/hvc_console.c
30774+++ b/drivers/char/hvc_console.c
30775@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
30776 * console interfaces but can still be used as a tty device. This has to be
30777 * static because kmalloc will not work during early console init.
30778 */
30779-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30780+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30781 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
30782 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
30783
30784@@ -249,7 +249,7 @@ static void destroy_hvc_struct(struct kref *kref)
30785 * vty adapters do NOT get an hvc_instantiate() callback since they
30786 * appear after early console init.
30787 */
30788-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
30789+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
30790 {
30791 struct hvc_struct *hp;
30792
30793@@ -758,7 +758,7 @@ static const struct tty_operations hvc_ops = {
30794 };
30795
30796 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
30797- struct hv_ops *ops, int outbuf_size)
30798+ const struct hv_ops *ops, int outbuf_size)
30799 {
30800 struct hvc_struct *hp;
30801 int i;
30802diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
30803index 10950ca..ed176c3 100644
30804--- a/drivers/char/hvc_console.h
30805+++ b/drivers/char/hvc_console.h
30806@@ -55,7 +55,7 @@ struct hvc_struct {
30807 int outbuf_size;
30808 int n_outbuf;
30809 uint32_t vtermno;
30810- struct hv_ops *ops;
30811+ const struct hv_ops *ops;
30812 int irq_requested;
30813 int data;
30814 struct winsize ws;
30815@@ -76,11 +76,11 @@ struct hv_ops {
30816 };
30817
30818 /* Register a vterm and a slot index for use as a console (console_init) */
30819-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
30820+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
30821
30822 /* register a vterm for hvc tty operation (module_init or hotplug add) */
30823 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
30824- struct hv_ops *ops, int outbuf_size);
30825+ const struct hv_ops *ops, int outbuf_size);
30826 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
30827 extern int hvc_remove(struct hvc_struct *hp);
30828
30829diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
30830index 936d05b..fd02426 100644
30831--- a/drivers/char/hvc_iseries.c
30832+++ b/drivers/char/hvc_iseries.c
30833@@ -197,7 +197,7 @@ done:
30834 return sent;
30835 }
30836
30837-static struct hv_ops hvc_get_put_ops = {
30838+static const struct hv_ops hvc_get_put_ops = {
30839 .get_chars = get_chars,
30840 .put_chars = put_chars,
30841 .notifier_add = notifier_add_irq,
30842diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
30843index b0e168f..69cda2a 100644
30844--- a/drivers/char/hvc_iucv.c
30845+++ b/drivers/char/hvc_iucv.c
30846@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
30847
30848
30849 /* HVC operations */
30850-static struct hv_ops hvc_iucv_ops = {
30851+static const struct hv_ops hvc_iucv_ops = {
30852 .get_chars = hvc_iucv_get_chars,
30853 .put_chars = hvc_iucv_put_chars,
30854 .notifier_add = hvc_iucv_notifier_add,
30855diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
30856index 88590d0..61c4a61 100644
30857--- a/drivers/char/hvc_rtas.c
30858+++ b/drivers/char/hvc_rtas.c
30859@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
30860 return i;
30861 }
30862
30863-static struct hv_ops hvc_rtas_get_put_ops = {
30864+static const struct hv_ops hvc_rtas_get_put_ops = {
30865 .get_chars = hvc_rtas_read_console,
30866 .put_chars = hvc_rtas_write_console,
30867 };
30868diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
30869index bd63ba8..b0957e6 100644
30870--- a/drivers/char/hvc_udbg.c
30871+++ b/drivers/char/hvc_udbg.c
30872@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
30873 return i;
30874 }
30875
30876-static struct hv_ops hvc_udbg_ops = {
30877+static const struct hv_ops hvc_udbg_ops = {
30878 .get_chars = hvc_udbg_get,
30879 .put_chars = hvc_udbg_put,
30880 };
30881diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
30882index 10be343..27370e9 100644
30883--- a/drivers/char/hvc_vio.c
30884+++ b/drivers/char/hvc_vio.c
30885@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
30886 return got;
30887 }
30888
30889-static struct hv_ops hvc_get_put_ops = {
30890+static const struct hv_ops hvc_get_put_ops = {
30891 .get_chars = filtered_get_chars,
30892 .put_chars = hvc_put_chars,
30893 .notifier_add = notifier_add_irq,
30894diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
30895index a6ee32b..94f8c26 100644
30896--- a/drivers/char/hvc_xen.c
30897+++ b/drivers/char/hvc_xen.c
30898@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
30899 return recv;
30900 }
30901
30902-static struct hv_ops hvc_ops = {
30903+static const struct hv_ops hvc_ops = {
30904 .get_chars = read_console,
30905 .put_chars = write_console,
30906 .notifier_add = notifier_add_irq,
30907diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
30908index 266b858..f3ee0bb 100644
30909--- a/drivers/char/hvcs.c
30910+++ b/drivers/char/hvcs.c
30911@@ -82,6 +82,7 @@
30912 #include <asm/hvcserver.h>
30913 #include <asm/uaccess.h>
30914 #include <asm/vio.h>
30915+#include <asm/local.h>
30916
30917 /*
30918 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
30919@@ -269,7 +270,7 @@ struct hvcs_struct {
30920 unsigned int index;
30921
30922 struct tty_struct *tty;
30923- int open_count;
30924+ local_t open_count;
30925
30926 /*
30927 * Used to tell the driver kernel_thread what operations need to take
30928@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
30929
30930 spin_lock_irqsave(&hvcsd->lock, flags);
30931
30932- if (hvcsd->open_count > 0) {
30933+ if (local_read(&hvcsd->open_count) > 0) {
30934 spin_unlock_irqrestore(&hvcsd->lock, flags);
30935 printk(KERN_INFO "HVCS: vterm state unchanged. "
30936 "The hvcs device node is still in use.\n");
30937@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
30938 if ((retval = hvcs_partner_connect(hvcsd)))
30939 goto error_release;
30940
30941- hvcsd->open_count = 1;
30942+ local_set(&hvcsd->open_count, 1);
30943 hvcsd->tty = tty;
30944 tty->driver_data = hvcsd;
30945
30946@@ -1169,7 +1170,7 @@ fast_open:
30947
30948 spin_lock_irqsave(&hvcsd->lock, flags);
30949 kref_get(&hvcsd->kref);
30950- hvcsd->open_count++;
30951+ local_inc(&hvcsd->open_count);
30952 hvcsd->todo_mask |= HVCS_SCHED_READ;
30953 spin_unlock_irqrestore(&hvcsd->lock, flags);
30954
30955@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
30956 hvcsd = tty->driver_data;
30957
30958 spin_lock_irqsave(&hvcsd->lock, flags);
30959- if (--hvcsd->open_count == 0) {
30960+ if (local_dec_and_test(&hvcsd->open_count)) {
30961
30962 vio_disable_interrupts(hvcsd->vdev);
30963
30964@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
30965 free_irq(irq, hvcsd);
30966 kref_put(&hvcsd->kref, destroy_hvcs_struct);
30967 return;
30968- } else if (hvcsd->open_count < 0) {
30969+ } else if (local_read(&hvcsd->open_count) < 0) {
30970 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
30971 " is missmanaged.\n",
30972- hvcsd->vdev->unit_address, hvcsd->open_count);
30973+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
30974 }
30975
30976 spin_unlock_irqrestore(&hvcsd->lock, flags);
30977@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struct * tty)
30978
30979 spin_lock_irqsave(&hvcsd->lock, flags);
30980 /* Preserve this so that we know how many kref refs to put */
30981- temp_open_count = hvcsd->open_count;
30982+ temp_open_count = local_read(&hvcsd->open_count);
30983
30984 /*
30985 * Don't kref put inside the spinlock because the destruction
30986@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struct * tty)
30987 hvcsd->tty->driver_data = NULL;
30988 hvcsd->tty = NULL;
30989
30990- hvcsd->open_count = 0;
30991+ local_set(&hvcsd->open_count, 0);
30992
30993 /* This will drop any buffered data on the floor which is OK in a hangup
30994 * scenario. */
30995@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct *tty,
30996 * the middle of a write operation? This is a crummy place to do this
30997 * but we want to keep it all in the spinlock.
30998 */
30999- if (hvcsd->open_count <= 0) {
31000+ if (local_read(&hvcsd->open_count) <= 0) {
31001 spin_unlock_irqrestore(&hvcsd->lock, flags);
31002 return -ENODEV;
31003 }
31004@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_struct *tty)
31005 {
31006 struct hvcs_struct *hvcsd = tty->driver_data;
31007
31008- if (!hvcsd || hvcsd->open_count <= 0)
31009+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
31010 return 0;
31011
31012 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
31013diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31014index ec5e3f8..02455ba 100644
31015--- a/drivers/char/ipmi/ipmi_msghandler.c
31016+++ b/drivers/char/ipmi/ipmi_msghandler.c
31017@@ -414,7 +414,7 @@ struct ipmi_smi {
31018 struct proc_dir_entry *proc_dir;
31019 char proc_dir_name[10];
31020
31021- atomic_t stats[IPMI_NUM_STATS];
31022+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31023
31024 /*
31025 * run_to_completion duplicate of smb_info, smi_info
31026@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31027
31028
31029 #define ipmi_inc_stat(intf, stat) \
31030- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31031+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31032 #define ipmi_get_stat(intf, stat) \
31033- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31034+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31035
31036 static int is_lan_addr(struct ipmi_addr *addr)
31037 {
31038@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31039 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31040 init_waitqueue_head(&intf->waitq);
31041 for (i = 0; i < IPMI_NUM_STATS; i++)
31042- atomic_set(&intf->stats[i], 0);
31043+ atomic_set_unchecked(&intf->stats[i], 0);
31044
31045 intf->proc_dir = NULL;
31046
31047@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
31048 struct ipmi_smi_msg smi_msg;
31049 struct ipmi_recv_msg recv_msg;
31050
31051+ pax_track_stack();
31052+
31053 si = (struct ipmi_system_interface_addr *) &addr;
31054 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
31055 si->channel = IPMI_BMC_CHANNEL;
31056diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31057index abae8c9..8021979 100644
31058--- a/drivers/char/ipmi/ipmi_si_intf.c
31059+++ b/drivers/char/ipmi/ipmi_si_intf.c
31060@@ -277,7 +277,7 @@ struct smi_info {
31061 unsigned char slave_addr;
31062
31063 /* Counters and things for the proc filesystem. */
31064- atomic_t stats[SI_NUM_STATS];
31065+ atomic_unchecked_t stats[SI_NUM_STATS];
31066
31067 struct task_struct *thread;
31068
31069@@ -285,9 +285,9 @@ struct smi_info {
31070 };
31071
31072 #define smi_inc_stat(smi, stat) \
31073- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31074+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31075 #define smi_get_stat(smi, stat) \
31076- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31077+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31078
31079 #define SI_MAX_PARMS 4
31080
31081@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info *new_smi)
31082 atomic_set(&new_smi->req_events, 0);
31083 new_smi->run_to_completion = 0;
31084 for (i = 0; i < SI_NUM_STATS; i++)
31085- atomic_set(&new_smi->stats[i], 0);
31086+ atomic_set_unchecked(&new_smi->stats[i], 0);
31087
31088 new_smi->interrupt_disabled = 0;
31089 atomic_set(&new_smi->stop_operation, 0);
31090diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
31091index 402838f..55e2200 100644
31092--- a/drivers/char/istallion.c
31093+++ b/drivers/char/istallion.c
31094@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios = {
31095 * re-used for each stats call.
31096 */
31097 static comstats_t stli_comstats;
31098-static combrd_t stli_brdstats;
31099 static struct asystats stli_cdkstats;
31100
31101 /*****************************************************************************/
31102@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
31103 {
31104 struct stlibrd *brdp;
31105 unsigned int i;
31106+ combrd_t stli_brdstats;
31107
31108 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
31109 return -EFAULT;
31110@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stliport __user *arg)
31111 struct stliport stli_dummyport;
31112 struct stliport *portp;
31113
31114+ pax_track_stack();
31115+
31116 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
31117 return -EFAULT;
31118 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
31119@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stlibrd __user *arg)
31120 struct stlibrd stli_dummybrd;
31121 struct stlibrd *brdp;
31122
31123+ pax_track_stack();
31124+
31125 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
31126 return -EFAULT;
31127 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
31128diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
31129index 950837c..e55a288 100644
31130--- a/drivers/char/keyboard.c
31131+++ b/drivers/char/keyboard.c
31132@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
31133 kbd->kbdmode == VC_MEDIUMRAW) &&
31134 value != KVAL(K_SAK))
31135 return; /* SAK is allowed even in raw mode */
31136+
31137+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
31138+ {
31139+ void *func = fn_handler[value];
31140+ if (func == fn_show_state || func == fn_show_ptregs ||
31141+ func == fn_show_mem)
31142+ return;
31143+ }
31144+#endif
31145+
31146 fn_handler[value](vc);
31147 }
31148
31149@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_ids[] = {
31150 .evbit = { BIT_MASK(EV_SND) },
31151 },
31152
31153- { }, /* Terminating entry */
31154+ { 0 }, /* Terminating entry */
31155 };
31156
31157 MODULE_DEVICE_TABLE(input, kbd_ids);
31158diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
31159index 87c67b4..230527a 100644
31160--- a/drivers/char/mbcs.c
31161+++ b/drivers/char/mbcs.c
31162@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
31163 return 0;
31164 }
31165
31166-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
31167+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
31168 {
31169 .part_num = MBCS_PART_NUM,
31170 .mfg_num = MBCS_MFG_NUM,
31171diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31172index 1270f64..8495f49 100644
31173--- a/drivers/char/mem.c
31174+++ b/drivers/char/mem.c
31175@@ -18,6 +18,7 @@
31176 #include <linux/raw.h>
31177 #include <linux/tty.h>
31178 #include <linux/capability.h>
31179+#include <linux/security.h>
31180 #include <linux/ptrace.h>
31181 #include <linux/device.h>
31182 #include <linux/highmem.h>
31183@@ -35,6 +36,10 @@
31184 # include <linux/efi.h>
31185 #endif
31186
31187+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31188+extern struct file_operations grsec_fops;
31189+#endif
31190+
31191 static inline unsigned long size_inside_page(unsigned long start,
31192 unsigned long size)
31193 {
31194@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31195
31196 while (cursor < to) {
31197 if (!devmem_is_allowed(pfn)) {
31198+#ifdef CONFIG_GRKERNSEC_KMEM
31199+ gr_handle_mem_readwrite(from, to);
31200+#else
31201 printk(KERN_INFO
31202 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31203 current->comm, from, to);
31204+#endif
31205 return 0;
31206 }
31207 cursor += PAGE_SIZE;
31208@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31209 }
31210 return 1;
31211 }
31212+#elif defined(CONFIG_GRKERNSEC_KMEM)
31213+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31214+{
31215+ return 0;
31216+}
31217 #else
31218 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31219 {
31220@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31221 #endif
31222
31223 while (count > 0) {
31224+ char *temp;
31225+
31226 /*
31227 * Handle first page in case it's not aligned
31228 */
31229@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31230 if (!ptr)
31231 return -EFAULT;
31232
31233- if (copy_to_user(buf, ptr, sz)) {
31234+#ifdef CONFIG_PAX_USERCOPY
31235+ temp = kmalloc(sz, GFP_KERNEL);
31236+ if (!temp) {
31237+ unxlate_dev_mem_ptr(p, ptr);
31238+ return -ENOMEM;
31239+ }
31240+ memcpy(temp, ptr, sz);
31241+#else
31242+ temp = ptr;
31243+#endif
31244+
31245+ if (copy_to_user(buf, temp, sz)) {
31246+
31247+#ifdef CONFIG_PAX_USERCOPY
31248+ kfree(temp);
31249+#endif
31250+
31251 unxlate_dev_mem_ptr(p, ptr);
31252 return -EFAULT;
31253 }
31254
31255+#ifdef CONFIG_PAX_USERCOPY
31256+ kfree(temp);
31257+#endif
31258+
31259 unxlate_dev_mem_ptr(p, ptr);
31260
31261 buf += sz;
31262@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31263 size_t count, loff_t *ppos)
31264 {
31265 unsigned long p = *ppos;
31266- ssize_t low_count, read, sz;
31267+ ssize_t low_count, read, sz, err = 0;
31268 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31269- int err = 0;
31270
31271 read = 0;
31272 if (p < (unsigned long) high_memory) {
31273@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31274 }
31275 #endif
31276 while (low_count > 0) {
31277+ char *temp;
31278+
31279 sz = size_inside_page(p, low_count);
31280
31281 /*
31282@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31283 */
31284 kbuf = xlate_dev_kmem_ptr((char *)p);
31285
31286- if (copy_to_user(buf, kbuf, sz))
31287+#ifdef CONFIG_PAX_USERCOPY
31288+ temp = kmalloc(sz, GFP_KERNEL);
31289+ if (!temp)
31290+ return -ENOMEM;
31291+ memcpy(temp, kbuf, sz);
31292+#else
31293+ temp = kbuf;
31294+#endif
31295+
31296+ err = copy_to_user(buf, temp, sz);
31297+
31298+#ifdef CONFIG_PAX_USERCOPY
31299+ kfree(temp);
31300+#endif
31301+
31302+ if (err)
31303 return -EFAULT;
31304 buf += sz;
31305 p += sz;
31306@@ -889,6 +941,9 @@ static const struct memdev {
31307 #ifdef CONFIG_CRASH_DUMP
31308 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31309 #endif
31310+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31311+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31312+#endif
31313 };
31314
31315 static int memory_open(struct inode *inode, struct file *filp)
31316diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
31317index 674b3ab..a8d1970 100644
31318--- a/drivers/char/pcmcia/ipwireless/tty.c
31319+++ b/drivers/char/pcmcia/ipwireless/tty.c
31320@@ -29,6 +29,7 @@
31321 #include <linux/tty_driver.h>
31322 #include <linux/tty_flip.h>
31323 #include <linux/uaccess.h>
31324+#include <asm/local.h>
31325
31326 #include "tty.h"
31327 #include "network.h"
31328@@ -51,7 +52,7 @@ struct ipw_tty {
31329 int tty_type;
31330 struct ipw_network *network;
31331 struct tty_struct *linux_tty;
31332- int open_count;
31333+ local_t open_count;
31334 unsigned int control_lines;
31335 struct mutex ipw_tty_mutex;
31336 int tx_bytes_queued;
31337@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31338 mutex_unlock(&tty->ipw_tty_mutex);
31339 return -ENODEV;
31340 }
31341- if (tty->open_count == 0)
31342+ if (local_read(&tty->open_count) == 0)
31343 tty->tx_bytes_queued = 0;
31344
31345- tty->open_count++;
31346+ local_inc(&tty->open_count);
31347
31348 tty->linux_tty = linux_tty;
31349 linux_tty->driver_data = tty;
31350@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31351
31352 static void do_ipw_close(struct ipw_tty *tty)
31353 {
31354- tty->open_count--;
31355-
31356- if (tty->open_count == 0) {
31357+ if (local_dec_return(&tty->open_count) == 0) {
31358 struct tty_struct *linux_tty = tty->linux_tty;
31359
31360 if (linux_tty != NULL) {
31361@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
31362 return;
31363
31364 mutex_lock(&tty->ipw_tty_mutex);
31365- if (tty->open_count == 0) {
31366+ if (local_read(&tty->open_count) == 0) {
31367 mutex_unlock(&tty->ipw_tty_mutex);
31368 return;
31369 }
31370@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
31371 return;
31372 }
31373
31374- if (!tty->open_count) {
31375+ if (!local_read(&tty->open_count)) {
31376 mutex_unlock(&tty->ipw_tty_mutex);
31377 return;
31378 }
31379@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
31380 return -ENODEV;
31381
31382 mutex_lock(&tty->ipw_tty_mutex);
31383- if (!tty->open_count) {
31384+ if (!local_read(&tty->open_count)) {
31385 mutex_unlock(&tty->ipw_tty_mutex);
31386 return -EINVAL;
31387 }
31388@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
31389 if (!tty)
31390 return -ENODEV;
31391
31392- if (!tty->open_count)
31393+ if (!local_read(&tty->open_count))
31394 return -EINVAL;
31395
31396 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
31397@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
31398 if (!tty)
31399 return 0;
31400
31401- if (!tty->open_count)
31402+ if (!local_read(&tty->open_count))
31403 return 0;
31404
31405 return tty->tx_bytes_queued;
31406@@ -403,7 +402,7 @@ static int ipw_tiocmget(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 get_control_lines(tty);
31415@@ -419,7 +418,7 @@ ipw_tiocmset(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 return set_control_lines(tty, set, clear);
31424@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
31425 if (!tty)
31426 return -ENODEV;
31427
31428- if (!tty->open_count)
31429+ if (!local_read(&tty->open_count))
31430 return -EINVAL;
31431
31432 /* FIXME: Exactly how is the tty object locked here .. */
31433@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
31434 against a parallel ioctl etc */
31435 mutex_lock(&ttyj->ipw_tty_mutex);
31436 }
31437- while (ttyj->open_count)
31438+ while (local_read(&ttyj->open_count))
31439 do_ipw_close(ttyj);
31440 ipwireless_disassociate_network_ttys(network,
31441 ttyj->channel_idx);
31442diff --git a/drivers/char/pty.c b/drivers/char/pty.c
31443index 62f282e..e45c45c 100644
31444--- a/drivers/char/pty.c
31445+++ b/drivers/char/pty.c
31446@@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
31447 register_sysctl_table(pty_root_table);
31448
31449 /* Now create the /dev/ptmx special device */
31450+ pax_open_kernel();
31451 tty_default_fops(&ptmx_fops);
31452- ptmx_fops.open = ptmx_open;
31453+ *(void **)&ptmx_fops.open = ptmx_open;
31454+ pax_close_kernel();
31455
31456 cdev_init(&ptmx_cdev, &ptmx_fops);
31457 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
31458diff --git a/drivers/char/random.c b/drivers/char/random.c
31459index 3a19e2d..6ed09d3 100644
31460--- a/drivers/char/random.c
31461+++ b/drivers/char/random.c
31462@@ -254,8 +254,13 @@
31463 /*
31464 * Configuration information
31465 */
31466+#ifdef CONFIG_GRKERNSEC_RANDNET
31467+#define INPUT_POOL_WORDS 512
31468+#define OUTPUT_POOL_WORDS 128
31469+#else
31470 #define INPUT_POOL_WORDS 128
31471 #define OUTPUT_POOL_WORDS 32
31472+#endif
31473 #define SEC_XFER_SIZE 512
31474
31475 /*
31476@@ -292,10 +297,17 @@ static struct poolinfo {
31477 int poolwords;
31478 int tap1, tap2, tap3, tap4, tap5;
31479 } poolinfo_table[] = {
31480+#ifdef CONFIG_GRKERNSEC_RANDNET
31481+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31482+ { 512, 411, 308, 208, 104, 1 },
31483+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31484+ { 128, 103, 76, 51, 25, 1 },
31485+#else
31486 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31487 { 128, 103, 76, 51, 25, 1 },
31488 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31489 { 32, 26, 20, 14, 7, 1 },
31490+#endif
31491 #if 0
31492 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31493 { 2048, 1638, 1231, 819, 411, 1 },
31494@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31495 #include <linux/sysctl.h>
31496
31497 static int min_read_thresh = 8, min_write_thresh;
31498-static int max_read_thresh = INPUT_POOL_WORDS * 32;
31499+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31500 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31501 static char sysctl_bootid[16];
31502
31503diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
31504index 0e29a23..0efc2c2 100644
31505--- a/drivers/char/rocket.c
31506+++ b/drivers/char/rocket.c
31507@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
31508 struct rocket_ports tmp;
31509 int board;
31510
31511+ pax_track_stack();
31512+
31513 if (!retports)
31514 return -EFAULT;
31515 memset(&tmp, 0, sizeof (tmp));
31516diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31517index 8c262aa..4d3b058 100644
31518--- a/drivers/char/sonypi.c
31519+++ b/drivers/char/sonypi.c
31520@@ -55,6 +55,7 @@
31521 #include <asm/uaccess.h>
31522 #include <asm/io.h>
31523 #include <asm/system.h>
31524+#include <asm/local.h>
31525
31526 #include <linux/sonypi.h>
31527
31528@@ -491,7 +492,7 @@ static struct sonypi_device {
31529 spinlock_t fifo_lock;
31530 wait_queue_head_t fifo_proc_list;
31531 struct fasync_struct *fifo_async;
31532- int open_count;
31533+ local_t open_count;
31534 int model;
31535 struct input_dev *input_jog_dev;
31536 struct input_dev *input_key_dev;
31537@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31538 static int sonypi_misc_release(struct inode *inode, struct file *file)
31539 {
31540 mutex_lock(&sonypi_device.lock);
31541- sonypi_device.open_count--;
31542+ local_dec(&sonypi_device.open_count);
31543 mutex_unlock(&sonypi_device.lock);
31544 return 0;
31545 }
31546@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31547 lock_kernel();
31548 mutex_lock(&sonypi_device.lock);
31549 /* Flush input queue on first open */
31550- if (!sonypi_device.open_count)
31551+ if (!local_read(&sonypi_device.open_count))
31552 kfifo_reset(sonypi_device.fifo);
31553- sonypi_device.open_count++;
31554+ local_inc(&sonypi_device.open_count);
31555 mutex_unlock(&sonypi_device.lock);
31556 unlock_kernel();
31557 return 0;
31558diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
31559index db6dcfa..13834cb 100644
31560--- a/drivers/char/stallion.c
31561+++ b/drivers/char/stallion.c
31562@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlport __user *arg)
31563 struct stlport stl_dummyport;
31564 struct stlport *portp;
31565
31566+ pax_track_stack();
31567+
31568 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
31569 return -EFAULT;
31570 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
31571diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31572index a0789f6..cea3902 100644
31573--- a/drivers/char/tpm/tpm.c
31574+++ b/drivers/char/tpm/tpm.c
31575@@ -405,7 +405,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31576 chip->vendor.req_complete_val)
31577 goto out_recv;
31578
31579- if ((status == chip->vendor.req_canceled)) {
31580+ if (status == chip->vendor.req_canceled) {
31581 dev_err(chip->dev, "Operation Canceled\n");
31582 rc = -ECANCELED;
31583 goto out;
31584@@ -824,6 +824,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
31585
31586 struct tpm_chip *chip = dev_get_drvdata(dev);
31587
31588+ pax_track_stack();
31589+
31590 tpm_cmd.header.in = tpm_readpubek_header;
31591 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
31592 "attempting to read the PUBEK");
31593diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
31594index bf2170f..ce8cab9 100644
31595--- a/drivers/char/tpm/tpm_bios.c
31596+++ b/drivers/char/tpm/tpm_bios.c
31597@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31598 event = addr;
31599
31600 if ((event->event_type == 0 && event->event_size == 0) ||
31601- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31602+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31603 return NULL;
31604
31605 return addr;
31606@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31607 return NULL;
31608
31609 if ((event->event_type == 0 && event->event_size == 0) ||
31610- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31611+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31612 return NULL;
31613
31614 (*pos)++;
31615@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31616 int i;
31617
31618 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31619- seq_putc(m, data[i]);
31620+ if (!seq_putc(m, data[i]))
31621+ return -EFAULT;
31622
31623 return 0;
31624 }
31625@@ -409,8 +410,13 @@ static int read_log(struct tpm_bios_log *log)
31626 log->bios_event_log_end = log->bios_event_log + len;
31627
31628 virt = acpi_os_map_memory(start, len);
31629+ if (!virt) {
31630+ kfree(log->bios_event_log);
31631+ log->bios_event_log = NULL;
31632+ return -EFAULT;
31633+ }
31634
31635- memcpy(log->bios_event_log, virt, len);
31636+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
31637
31638 acpi_os_unmap_memory(virt, len);
31639 return 0;
31640diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
31641index 123cedf..137edef 100644
31642--- a/drivers/char/tty_io.c
31643+++ b/drivers/char/tty_io.c
31644@@ -1774,6 +1774,7 @@ got_driver:
31645
31646 if (IS_ERR(tty)) {
31647 mutex_unlock(&tty_mutex);
31648+ tty_driver_kref_put(driver);
31649 return PTR_ERR(tty);
31650 }
31651 }
31652@@ -2603,8 +2604,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31653 return retval;
31654 }
31655
31656+EXPORT_SYMBOL(tty_ioctl);
31657+
31658 #ifdef CONFIG_COMPAT
31659-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31660+long tty_compat_ioctl(struct file *file, unsigned int cmd,
31661 unsigned long arg)
31662 {
31663 struct inode *inode = file->f_dentry->d_inode;
31664@@ -2628,6 +2631,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31665
31666 return retval;
31667 }
31668+
31669+EXPORT_SYMBOL(tty_compat_ioctl);
31670 #endif
31671
31672 /*
31673@@ -3073,7 +3078,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
31674
31675 void tty_default_fops(struct file_operations *fops)
31676 {
31677- *fops = tty_fops;
31678+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
31679 }
31680
31681 /*
31682diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
31683index d814a3d..b55b9c9 100644
31684--- a/drivers/char/tty_ldisc.c
31685+++ b/drivers/char/tty_ldisc.c
31686@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *ld)
31687 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
31688 struct tty_ldisc_ops *ldo = ld->ops;
31689
31690- ldo->refcount--;
31691+ atomic_dec(&ldo->refcount);
31692 module_put(ldo->owner);
31693 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31694
31695@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
31696 spin_lock_irqsave(&tty_ldisc_lock, flags);
31697 tty_ldiscs[disc] = new_ldisc;
31698 new_ldisc->num = disc;
31699- new_ldisc->refcount = 0;
31700+ atomic_set(&new_ldisc->refcount, 0);
31701 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31702
31703 return ret;
31704@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
31705 return -EINVAL;
31706
31707 spin_lock_irqsave(&tty_ldisc_lock, flags);
31708- if (tty_ldiscs[disc]->refcount)
31709+ if (atomic_read(&tty_ldiscs[disc]->refcount))
31710 ret = -EBUSY;
31711 else
31712 tty_ldiscs[disc] = NULL;
31713@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
31714 if (ldops) {
31715 ret = ERR_PTR(-EAGAIN);
31716 if (try_module_get(ldops->owner)) {
31717- ldops->refcount++;
31718+ atomic_inc(&ldops->refcount);
31719 ret = ldops;
31720 }
31721 }
31722@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
31723 unsigned long flags;
31724
31725 spin_lock_irqsave(&tty_ldisc_lock, flags);
31726- ldops->refcount--;
31727+ atomic_dec(&ldops->refcount);
31728 module_put(ldops->owner);
31729 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31730 }
31731diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31732index a035ae3..c27fe2c 100644
31733--- a/drivers/char/virtio_console.c
31734+++ b/drivers/char/virtio_console.c
31735@@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *buf, int count)
31736 * virtqueue, so we let the drivers do some boutique early-output thing. */
31737 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
31738 {
31739- virtio_cons.put_chars = put_chars;
31740+ pax_open_kernel();
31741+ *(void **)&virtio_cons.put_chars = put_chars;
31742+ pax_close_kernel();
31743 return hvc_instantiate(0, 0, &virtio_cons);
31744 }
31745
31746@@ -213,11 +215,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
31747 out_vq = vqs[1];
31748
31749 /* Start using the new console output. */
31750- virtio_cons.get_chars = get_chars;
31751- virtio_cons.put_chars = put_chars;
31752- virtio_cons.notifier_add = notifier_add_vio;
31753- virtio_cons.notifier_del = notifier_del_vio;
31754- virtio_cons.notifier_hangup = notifier_del_vio;
31755+ pax_open_kernel();
31756+ *(void **)&virtio_cons.get_chars = get_chars;
31757+ *(void **)&virtio_cons.put_chars = put_chars;
31758+ *(void **)&virtio_cons.notifier_add = notifier_add_vio;
31759+ *(void **)&virtio_cons.notifier_del = notifier_del_vio;
31760+ *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
31761+ pax_close_kernel();
31762
31763 /* The first argument of hvc_alloc() is the virtual console number, so
31764 * we use zero. The second argument is the parameter for the
31765diff --git a/drivers/char/vt.c b/drivers/char/vt.c
31766index 0c80c68..53d59c1 100644
31767--- a/drivers/char/vt.c
31768+++ b/drivers/char/vt.c
31769@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
31770
31771 static void notify_write(struct vc_data *vc, unsigned int unicode)
31772 {
31773- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
31774+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
31775 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
31776 }
31777
31778diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
31779index 6351a26..999af95 100644
31780--- a/drivers/char/vt_ioctl.c
31781+++ b/drivers/char/vt_ioctl.c
31782@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31783 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
31784 return -EFAULT;
31785
31786- if (!capable(CAP_SYS_TTY_CONFIG))
31787- perm = 0;
31788-
31789 switch (cmd) {
31790 case KDGKBENT:
31791 key_map = key_maps[s];
31792@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31793 val = (i ? K_HOLE : K_NOSUCHMAP);
31794 return put_user(val, &user_kbe->kb_value);
31795 case KDSKBENT:
31796+ if (!capable(CAP_SYS_TTY_CONFIG))
31797+ perm = 0;
31798+
31799 if (!perm)
31800 return -EPERM;
31801+
31802 if (!i && v == K_NOSUCHMAP) {
31803 /* deallocate map */
31804 key_map = key_maps[s];
31805@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31806 int i, j, k;
31807 int ret;
31808
31809- if (!capable(CAP_SYS_TTY_CONFIG))
31810- perm = 0;
31811-
31812 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
31813 if (!kbs) {
31814 ret = -ENOMEM;
31815@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31816 kfree(kbs);
31817 return ((p && *p) ? -EOVERFLOW : 0);
31818 case KDSKBSENT:
31819+ if (!capable(CAP_SYS_TTY_CONFIG))
31820+ perm = 0;
31821+
31822 if (!perm) {
31823 ret = -EPERM;
31824 goto reterr;
31825diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
31826index c7ae026..1769c1d 100644
31827--- a/drivers/cpufreq/cpufreq.c
31828+++ b/drivers/cpufreq/cpufreq.c
31829@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct kobject *kobj)
31830 complete(&policy->kobj_unregister);
31831 }
31832
31833-static struct sysfs_ops sysfs_ops = {
31834+static const struct sysfs_ops sysfs_ops = {
31835 .show = show,
31836 .store = store,
31837 };
31838diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
31839index 97b0038..2056670 100644
31840--- a/drivers/cpuidle/sysfs.c
31841+++ b/drivers/cpuidle/sysfs.c
31842@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
31843 return ret;
31844 }
31845
31846-static struct sysfs_ops cpuidle_sysfs_ops = {
31847+static const struct sysfs_ops cpuidle_sysfs_ops = {
31848 .show = cpuidle_show,
31849 .store = cpuidle_store,
31850 };
31851@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct kobject * kobj,
31852 return ret;
31853 }
31854
31855-static struct sysfs_ops cpuidle_state_sysfs_ops = {
31856+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
31857 .show = cpuidle_state_show,
31858 };
31859
31860@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpuidle = {
31861 .release = cpuidle_state_sysfs_release,
31862 };
31863
31864-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31865+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31866 {
31867 kobject_put(&device->kobjs[i]->kobj);
31868 wait_for_completion(&device->kobjs[i]->kobj_unregister);
31869diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
31870index 5f753fc..0377ae9 100644
31871--- a/drivers/crypto/hifn_795x.c
31872+++ b/drivers/crypto/hifn_795x.c
31873@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
31874 0xCA, 0x34, 0x2B, 0x2E};
31875 struct scatterlist sg;
31876
31877+ pax_track_stack();
31878+
31879 memset(src, 0, sizeof(src));
31880 memset(ctx.key, 0, sizeof(ctx.key));
31881
31882diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
31883index 71e6482..de8d96c 100644
31884--- a/drivers/crypto/padlock-aes.c
31885+++ b/drivers/crypto/padlock-aes.c
31886@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
31887 struct crypto_aes_ctx gen_aes;
31888 int cpu;
31889
31890+ pax_track_stack();
31891+
31892 if (key_len % 8) {
31893 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
31894 return -EINVAL;
31895diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
31896index dcc4ab7..cc834bb 100644
31897--- a/drivers/dma/ioat/dma.c
31898+++ b/drivers/dma/ioat/dma.c
31899@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
31900 return entry->show(&chan->common, page);
31901 }
31902
31903-struct sysfs_ops ioat_sysfs_ops = {
31904+const struct sysfs_ops ioat_sysfs_ops = {
31905 .show = ioat_attr_show,
31906 };
31907
31908diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
31909index bbc3e78..f2db62c 100644
31910--- a/drivers/dma/ioat/dma.h
31911+++ b/drivers/dma/ioat/dma.h
31912@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
31913 unsigned long *phys_complete);
31914 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
31915 void ioat_kobject_del(struct ioatdma_device *device);
31916-extern struct sysfs_ops ioat_sysfs_ops;
31917+extern const struct sysfs_ops ioat_sysfs_ops;
31918 extern struct ioat_sysfs_entry ioat_version_attr;
31919 extern struct ioat_sysfs_entry ioat_cap_attr;
31920 #endif /* IOATDMA_H */
31921diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
31922index 9908c9e..3ceb0e5 100644
31923--- a/drivers/dma/ioat/dma_v3.c
31924+++ b/drivers/dma/ioat/dma_v3.c
31925@@ -71,10 +71,10 @@
31926 /* provide a lookup table for setting the source address in the base or
31927 * extended descriptor of an xor or pq descriptor
31928 */
31929-static const u8 xor_idx_to_desc __read_mostly = 0xd0;
31930-static const u8 xor_idx_to_field[] __read_mostly = { 1, 4, 5, 6, 7, 0, 1, 2 };
31931-static const u8 pq_idx_to_desc __read_mostly = 0xf8;
31932-static const u8 pq_idx_to_field[] __read_mostly = { 1, 4, 5, 0, 1, 2, 4, 5 };
31933+static const u8 xor_idx_to_desc = 0xd0;
31934+static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
31935+static const u8 pq_idx_to_desc = 0xf8;
31936+static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
31937
31938 static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
31939 {
31940diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
31941index 85c464a..afd1e73 100644
31942--- a/drivers/edac/amd64_edac.c
31943+++ b/drivers/edac/amd64_edac.c
31944@@ -3099,7 +3099,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
31945 * PCI core identifies what devices are on a system during boot, and then
31946 * inquiry this table to see if this driver is for a given device found.
31947 */
31948-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
31949+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
31950 {
31951 .vendor = PCI_VENDOR_ID_AMD,
31952 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
31953diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
31954index 2b95f1a..4f52793 100644
31955--- a/drivers/edac/amd76x_edac.c
31956+++ b/drivers/edac/amd76x_edac.c
31957@@ -322,7 +322,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
31958 edac_mc_free(mci);
31959 }
31960
31961-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
31962+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
31963 {
31964 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31965 AMD762},
31966diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
31967index d205d49..74c9672 100644
31968--- a/drivers/edac/e752x_edac.c
31969+++ b/drivers/edac/e752x_edac.c
31970@@ -1282,7 +1282,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
31971 edac_mc_free(mci);
31972 }
31973
31974-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
31975+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
31976 {
31977 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31978 E7520},
31979diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
31980index c7d11cc..c59c1ca 100644
31981--- a/drivers/edac/e7xxx_edac.c
31982+++ b/drivers/edac/e7xxx_edac.c
31983@@ -526,7 +526,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
31984 edac_mc_free(mci);
31985 }
31986
31987-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
31988+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
31989 {
31990 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31991 E7205},
31992diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
31993index 5376457..5fdedbc 100644
31994--- a/drivers/edac/edac_device_sysfs.c
31995+++ b/drivers/edac/edac_device_sysfs.c
31996@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
31997 }
31998
31999 /* edac_dev file operations for an 'ctl_info' */
32000-static struct sysfs_ops device_ctl_info_ops = {
32001+static const struct sysfs_ops device_ctl_info_ops = {
32002 .show = edac_dev_ctl_info_show,
32003 .store = edac_dev_ctl_info_store
32004 };
32005@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(struct kobject *kobj,
32006 }
32007
32008 /* edac_dev file operations for an 'instance' */
32009-static struct sysfs_ops device_instance_ops = {
32010+static const struct sysfs_ops device_instance_ops = {
32011 .show = edac_dev_instance_show,
32012 .store = edac_dev_instance_store
32013 };
32014@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(struct kobject *kobj,
32015 }
32016
32017 /* edac_dev file operations for a 'block' */
32018-static struct sysfs_ops device_block_ops = {
32019+static const struct sysfs_ops device_block_ops = {
32020 .show = edac_dev_block_show,
32021 .store = edac_dev_block_store
32022 };
32023diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
32024index e1d4ce0..88840e9 100644
32025--- a/drivers/edac/edac_mc_sysfs.c
32026+++ b/drivers/edac/edac_mc_sysfs.c
32027@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
32028 return -EIO;
32029 }
32030
32031-static struct sysfs_ops csrowfs_ops = {
32032+static const struct sysfs_ops csrowfs_ops = {
32033 .show = csrowdev_show,
32034 .store = csrowdev_store
32035 };
32036@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
32037 }
32038
32039 /* Intermediate show/store table */
32040-static struct sysfs_ops mci_ops = {
32041+static const struct sysfs_ops mci_ops = {
32042 .show = mcidev_show,
32043 .store = mcidev_store
32044 };
32045diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32046index 422728c..d8d9c88 100644
32047--- a/drivers/edac/edac_pci_sysfs.c
32048+++ b/drivers/edac/edac_pci_sysfs.c
32049@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32050 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32051 static int edac_pci_poll_msec = 1000; /* one second workq period */
32052
32053-static atomic_t pci_parity_count = ATOMIC_INIT(0);
32054-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32055+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32056+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32057
32058 static struct kobject *edac_pci_top_main_kobj;
32059 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32060@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
32061 }
32062
32063 /* fs_ops table */
32064-static struct sysfs_ops pci_instance_ops = {
32065+static const struct sysfs_ops pci_instance_ops = {
32066 .show = edac_pci_instance_show,
32067 .store = edac_pci_instance_store
32068 };
32069@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct kobject *kobj,
32070 return -EIO;
32071 }
32072
32073-static struct sysfs_ops edac_pci_sysfs_ops = {
32074+static const struct sysfs_ops edac_pci_sysfs_ops = {
32075 .show = edac_pci_dev_show,
32076 .store = edac_pci_dev_store
32077 };
32078@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32079 edac_printk(KERN_CRIT, EDAC_PCI,
32080 "Signaled System Error on %s\n",
32081 pci_name(dev));
32082- atomic_inc(&pci_nonparity_count);
32083+ atomic_inc_unchecked(&pci_nonparity_count);
32084 }
32085
32086 if (status & (PCI_STATUS_PARITY)) {
32087@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32088 "Master Data 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 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32096@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32097 "Detected Parity Error on %s\n",
32098 pci_name(dev));
32099
32100- atomic_inc(&pci_parity_count);
32101+ atomic_inc_unchecked(&pci_parity_count);
32102 }
32103 }
32104
32105@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32106 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32107 "Signaled System Error on %s\n",
32108 pci_name(dev));
32109- atomic_inc(&pci_nonparity_count);
32110+ atomic_inc_unchecked(&pci_nonparity_count);
32111 }
32112
32113 if (status & (PCI_STATUS_PARITY)) {
32114@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32115 "Master Data Parity Error on "
32116 "%s\n", pci_name(dev));
32117
32118- atomic_inc(&pci_parity_count);
32119+ atomic_inc_unchecked(&pci_parity_count);
32120 }
32121
32122 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32123@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32124 "Detected Parity Error on %s\n",
32125 pci_name(dev));
32126
32127- atomic_inc(&pci_parity_count);
32128+ atomic_inc_unchecked(&pci_parity_count);
32129 }
32130 }
32131 }
32132@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
32133 if (!check_pci_errors)
32134 return;
32135
32136- before_count = atomic_read(&pci_parity_count);
32137+ before_count = atomic_read_unchecked(&pci_parity_count);
32138
32139 /* scan all PCI devices looking for a Parity Error on devices and
32140 * bridges.
32141@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
32142 /* Only if operator has selected panic on PCI Error */
32143 if (edac_pci_get_panic_on_pe()) {
32144 /* If the count is different 'after' from 'before' */
32145- if (before_count != atomic_read(&pci_parity_count))
32146+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32147 panic("EDAC: PCI Parity Error");
32148 }
32149 }
32150diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
32151index 6c9a0f2..9c1cf7e 100644
32152--- a/drivers/edac/i3000_edac.c
32153+++ b/drivers/edac/i3000_edac.c
32154@@ -471,7 +471,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
32155 edac_mc_free(mci);
32156 }
32157
32158-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
32159+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
32160 {
32161 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32162 I3000},
32163diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
32164index fde4db9..fe108f9 100644
32165--- a/drivers/edac/i3200_edac.c
32166+++ b/drivers/edac/i3200_edac.c
32167@@ -444,7 +444,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
32168 edac_mc_free(mci);
32169 }
32170
32171-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
32172+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
32173 {
32174 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32175 I3200},
32176diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
32177index adc10a2..57d4ccf 100644
32178--- a/drivers/edac/i5000_edac.c
32179+++ b/drivers/edac/i5000_edac.c
32180@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
32181 *
32182 * The "E500P" device is the first device supported.
32183 */
32184-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
32185+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
32186 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
32187 .driver_data = I5000P},
32188
32189diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
32190index 22db05a..b2b5503 100644
32191--- a/drivers/edac/i5100_edac.c
32192+++ b/drivers/edac/i5100_edac.c
32193@@ -944,7 +944,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
32194 edac_mc_free(mci);
32195 }
32196
32197-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
32198+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
32199 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
32200 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
32201 { 0, }
32202diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
32203index f99d106..f050710 100644
32204--- a/drivers/edac/i5400_edac.c
32205+++ b/drivers/edac/i5400_edac.c
32206@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
32207 *
32208 * The "E500P" device is the first device supported.
32209 */
32210-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
32211+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
32212 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
32213 {0,} /* 0 terminated list. */
32214 };
32215diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
32216index 577760a..9ce16ce 100644
32217--- a/drivers/edac/i82443bxgx_edac.c
32218+++ b/drivers/edac/i82443bxgx_edac.c
32219@@ -381,7 +381,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
32220
32221 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
32222
32223-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
32224+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
32225 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
32226 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
32227 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
32228diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
32229index c0088ba..64a7b98 100644
32230--- a/drivers/edac/i82860_edac.c
32231+++ b/drivers/edac/i82860_edac.c
32232@@ -271,7 +271,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
32233 edac_mc_free(mci);
32234 }
32235
32236-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
32237+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
32238 {
32239 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32240 I82860},
32241diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
32242index b2d83b9..a34357b 100644
32243--- a/drivers/edac/i82875p_edac.c
32244+++ b/drivers/edac/i82875p_edac.c
32245@@ -512,7 +512,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
32246 edac_mc_free(mci);
32247 }
32248
32249-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
32250+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
32251 {
32252 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32253 I82875P},
32254diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
32255index 2eed3ea..87bbbd1 100644
32256--- a/drivers/edac/i82975x_edac.c
32257+++ b/drivers/edac/i82975x_edac.c
32258@@ -586,7 +586,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
32259 edac_mc_free(mci);
32260 }
32261
32262-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
32263+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
32264 {
32265 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32266 I82975X
32267diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
32268index 9900675..78ac2b6 100644
32269--- a/drivers/edac/r82600_edac.c
32270+++ b/drivers/edac/r82600_edac.c
32271@@ -374,7 +374,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
32272 edac_mc_free(mci);
32273 }
32274
32275-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
32276+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
32277 {
32278 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
32279 },
32280diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
32281index d4ec605..4cfec4e 100644
32282--- a/drivers/edac/x38_edac.c
32283+++ b/drivers/edac/x38_edac.c
32284@@ -441,7 +441,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
32285 edac_mc_free(mci);
32286 }
32287
32288-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
32289+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
32290 {
32291 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32292 X38},
32293diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32294index 3fc2ceb..daf098f 100644
32295--- a/drivers/firewire/core-card.c
32296+++ b/drivers/firewire/core-card.c
32297@@ -558,7 +558,7 @@ void fw_card_release(struct kref *kref)
32298
32299 void fw_core_remove_card(struct fw_card *card)
32300 {
32301- struct fw_card_driver dummy_driver = dummy_driver_template;
32302+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32303
32304 card->driver->update_phy_reg(card, 4,
32305 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32306diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32307index 4560d8f..36db24a 100644
32308--- a/drivers/firewire/core-cdev.c
32309+++ b/drivers/firewire/core-cdev.c
32310@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct client *client,
32311 int ret;
32312
32313 if ((request->channels == 0 && request->bandwidth == 0) ||
32314- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32315- request->bandwidth < 0)
32316+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32317 return -EINVAL;
32318
32319 r = kmalloc(sizeof(*r), GFP_KERNEL);
32320diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32321index da628c7..cf54a2c 100644
32322--- a/drivers/firewire/core-transaction.c
32323+++ b/drivers/firewire/core-transaction.c
32324@@ -36,6 +36,7 @@
32325 #include <linux/string.h>
32326 #include <linux/timer.h>
32327 #include <linux/types.h>
32328+#include <linux/sched.h>
32329
32330 #include <asm/byteorder.h>
32331
32332@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
32333 struct transaction_callback_data d;
32334 struct fw_transaction t;
32335
32336+ pax_track_stack();
32337+
32338 init_completion(&d.done);
32339 d.payload = payload;
32340 fw_send_request(card, &t, tcode, destination_id, generation, speed,
32341diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32342index 7ff6e75..a2965d9 100644
32343--- a/drivers/firewire/core.h
32344+++ b/drivers/firewire/core.h
32345@@ -86,6 +86,7 @@ struct fw_card_driver {
32346
32347 int (*stop_iso)(struct fw_iso_context *ctx);
32348 };
32349+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32350
32351 void fw_card_initialize(struct fw_card *card,
32352 const struct fw_card_driver *driver, struct device *device);
32353diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32354index 3a2ccb0..82fd7c4 100644
32355--- a/drivers/firmware/dmi_scan.c
32356+++ b/drivers/firmware/dmi_scan.c
32357@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
32358 }
32359 }
32360 else {
32361- /*
32362- * no iounmap() for that ioremap(); it would be a no-op, but
32363- * it's so early in setup that sucker gets confused into doing
32364- * what it shouldn't if we actually call it.
32365- */
32366 p = dmi_ioremap(0xF0000, 0x10000);
32367 if (p == NULL)
32368 goto error;
32369@@ -667,7 +662,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32370 if (buf == NULL)
32371 return -1;
32372
32373- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32374+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32375
32376 iounmap(buf);
32377 return 0;
32378diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
32379index 9e4f59d..110e24e 100644
32380--- a/drivers/firmware/edd.c
32381+++ b/drivers/firmware/edd.c
32382@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
32383 return ret;
32384 }
32385
32386-static struct sysfs_ops edd_attr_ops = {
32387+static const struct sysfs_ops edd_attr_ops = {
32388 .show = edd_attr_show,
32389 };
32390
32391diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32392index f4f709d..082f06e 100644
32393--- a/drivers/firmware/efivars.c
32394+++ b/drivers/firmware/efivars.c
32395@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
32396 return ret;
32397 }
32398
32399-static struct sysfs_ops efivar_attr_ops = {
32400+static const struct sysfs_ops efivar_attr_ops = {
32401 .show = efivar_attr_show,
32402 .store = efivar_attr_store,
32403 };
32404diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
32405index 051d1eb..0a5d4e7 100644
32406--- a/drivers/firmware/iscsi_ibft.c
32407+++ b/drivers/firmware/iscsi_ibft.c
32408@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struct kobject *kobj,
32409 return ret;
32410 }
32411
32412-static struct sysfs_ops ibft_attr_ops = {
32413+static const struct sysfs_ops ibft_attr_ops = {
32414 .show = ibft_show_attribute,
32415 };
32416
32417diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
32418index 56f9234..8c58c7b 100644
32419--- a/drivers/firmware/memmap.c
32420+++ b/drivers/firmware/memmap.c
32421@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
32422 NULL
32423 };
32424
32425-static struct sysfs_ops memmap_attr_ops = {
32426+static const struct sysfs_ops memmap_attr_ops = {
32427 .show = memmap_attr_show,
32428 };
32429
32430diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
32431index b16c9a8..2af7d3f 100644
32432--- a/drivers/gpio/vr41xx_giu.c
32433+++ b/drivers/gpio/vr41xx_giu.c
32434@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32435 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32436 maskl, pendl, maskh, pendh);
32437
32438- atomic_inc(&irq_err_count);
32439+ atomic_inc_unchecked(&irq_err_count);
32440
32441 return -EINVAL;
32442 }
32443diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
32444index bea6efc..3dc0f42 100644
32445--- a/drivers/gpu/drm/drm_crtc.c
32446+++ b/drivers/gpu/drm/drm_crtc.c
32447@@ -1323,7 +1323,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32448 */
32449 if ((out_resp->count_modes >= mode_count) && mode_count) {
32450 copied = 0;
32451- mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
32452+ mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
32453 list_for_each_entry(mode, &connector->modes, head) {
32454 drm_crtc_convert_to_umode(&u_mode, mode);
32455 if (copy_to_user(mode_ptr + copied,
32456@@ -1338,8 +1338,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32457
32458 if ((out_resp->count_props >= props_count) && props_count) {
32459 copied = 0;
32460- prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
32461- prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
32462+ prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
32463+ prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
32464 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
32465 if (connector->property_ids[i] != 0) {
32466 if (put_user(connector->property_ids[i],
32467@@ -1361,7 +1361,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32468
32469 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
32470 copied = 0;
32471- encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
32472+ encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
32473 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
32474 if (connector->encoder_ids[i] != 0) {
32475 if (put_user(connector->encoder_ids[i],
32476@@ -1513,7 +1513,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
32477 }
32478
32479 for (i = 0; i < crtc_req->count_connectors; i++) {
32480- set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
32481+ set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
32482 if (get_user(out_id, &set_connectors_ptr[i])) {
32483 ret = -EFAULT;
32484 goto out;
32485@@ -2118,7 +2118,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32486 out_resp->flags = property->flags;
32487
32488 if ((out_resp->count_values >= value_count) && value_count) {
32489- values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
32490+ values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
32491 for (i = 0; i < value_count; i++) {
32492 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
32493 ret = -EFAULT;
32494@@ -2131,7 +2131,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32495 if (property->flags & DRM_MODE_PROP_ENUM) {
32496 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
32497 copied = 0;
32498- enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
32499+ enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
32500 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
32501
32502 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
32503@@ -2154,7 +2154,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32504 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
32505 copied = 0;
32506 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
32507- blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
32508+ blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
32509
32510 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
32511 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
32512@@ -2226,7 +2226,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
32513 blob = obj_to_blob(obj);
32514
32515 if (out_resp->length == blob->length) {
32516- blob_ptr = (void *)(unsigned long)out_resp->data;
32517+ blob_ptr = (void __user *)(unsigned long)out_resp->data;
32518 if (copy_to_user(blob_ptr, blob->data, blob->length)){
32519 ret = -EFAULT;
32520 goto done;
32521diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32522index 1b8745d..92fdbf6 100644
32523--- a/drivers/gpu/drm/drm_crtc_helper.c
32524+++ b/drivers/gpu/drm/drm_crtc_helper.c
32525@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32526 struct drm_crtc *tmp;
32527 int crtc_mask = 1;
32528
32529- WARN(!crtc, "checking null crtc?");
32530+ BUG_ON(!crtc);
32531
32532 dev = crtc->dev;
32533
32534@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
32535
32536 adjusted_mode = drm_mode_duplicate(dev, mode);
32537
32538+ pax_track_stack();
32539+
32540 crtc->enabled = drm_helper_crtc_in_use(crtc);
32541
32542 if (!crtc->enabled)
32543diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32544index 0e27d98..dec8768 100644
32545--- a/drivers/gpu/drm/drm_drv.c
32546+++ b/drivers/gpu/drm/drm_drv.c
32547@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
32548 char *kdata = NULL;
32549
32550 atomic_inc(&dev->ioctl_count);
32551- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32552+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32553 ++file_priv->ioctl_count;
32554
32555 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32556diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32557index ba14553..182d0bb 100644
32558--- a/drivers/gpu/drm/drm_fops.c
32559+++ b/drivers/gpu/drm/drm_fops.c
32560@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device * dev)
32561 }
32562
32563 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32564- atomic_set(&dev->counts[i], 0);
32565+ atomic_set_unchecked(&dev->counts[i], 0);
32566
32567 dev->sigdata.lock = NULL;
32568
32569@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct file *filp)
32570
32571 retcode = drm_open_helper(inode, filp, dev);
32572 if (!retcode) {
32573- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32574+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32575 spin_lock(&dev->count_lock);
32576- if (!dev->open_count++) {
32577+ if (local_inc_return(&dev->open_count) == 1) {
32578 spin_unlock(&dev->count_lock);
32579 retcode = drm_setup(dev);
32580 goto out;
32581@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, struct file *filp)
32582
32583 lock_kernel();
32584
32585- DRM_DEBUG("open_count = %d\n", dev->open_count);
32586+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
32587
32588 if (dev->driver->preclose)
32589 dev->driver->preclose(dev, file_priv);
32590@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, struct file *filp)
32591 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32592 task_pid_nr(current),
32593 (long)old_encode_dev(file_priv->minor->device),
32594- dev->open_count);
32595+ local_read(&dev->open_count));
32596
32597 /* if the master has gone away we can't do anything with the lock */
32598 if (file_priv->minor->master)
32599@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, struct file *filp)
32600 * End inline drm_release
32601 */
32602
32603- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32604+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32605 spin_lock(&dev->count_lock);
32606- if (!--dev->open_count) {
32607+ if (local_dec_and_test(&dev->open_count)) {
32608 if (atomic_read(&dev->ioctl_count)) {
32609 DRM_ERROR("Device busy: %d\n",
32610 atomic_read(&dev->ioctl_count));
32611diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
32612index 8bf3770..7942280 100644
32613--- a/drivers/gpu/drm/drm_gem.c
32614+++ b/drivers/gpu/drm/drm_gem.c
32615@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
32616 spin_lock_init(&dev->object_name_lock);
32617 idr_init(&dev->object_name_idr);
32618 atomic_set(&dev->object_count, 0);
32619- atomic_set(&dev->object_memory, 0);
32620+ atomic_set_unchecked(&dev->object_memory, 0);
32621 atomic_set(&dev->pin_count, 0);
32622- atomic_set(&dev->pin_memory, 0);
32623+ atomic_set_unchecked(&dev->pin_memory, 0);
32624 atomic_set(&dev->gtt_count, 0);
32625- atomic_set(&dev->gtt_memory, 0);
32626+ atomic_set_unchecked(&dev->gtt_memory, 0);
32627
32628 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
32629 if (!mm) {
32630@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
32631 goto fput;
32632 }
32633 atomic_inc(&dev->object_count);
32634- atomic_add(obj->size, &dev->object_memory);
32635+ atomic_add_unchecked(obj->size, &dev->object_memory);
32636 return obj;
32637 fput:
32638 fput(obj->filp);
32639@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
32640
32641 fput(obj->filp);
32642 atomic_dec(&dev->object_count);
32643- atomic_sub(obj->size, &dev->object_memory);
32644+ atomic_sub_unchecked(obj->size, &dev->object_memory);
32645 kfree(obj);
32646 }
32647 EXPORT_SYMBOL(drm_gem_object_free);
32648diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32649index f0f6c6b..34af322 100644
32650--- a/drivers/gpu/drm/drm_info.c
32651+++ b/drivers/gpu/drm/drm_info.c
32652@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32653 struct drm_local_map *map;
32654 struct drm_map_list *r_list;
32655
32656- /* Hardcoded from _DRM_FRAME_BUFFER,
32657- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32658- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32659- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32660+ static const char * const types[] = {
32661+ [_DRM_FRAME_BUFFER] = "FB",
32662+ [_DRM_REGISTERS] = "REG",
32663+ [_DRM_SHM] = "SHM",
32664+ [_DRM_AGP] = "AGP",
32665+ [_DRM_SCATTER_GATHER] = "SG",
32666+ [_DRM_CONSISTENT] = "PCI",
32667+ [_DRM_GEM] = "GEM" };
32668 const char *type;
32669 int i;
32670
32671@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32672 map = r_list->map;
32673 if (!map)
32674 continue;
32675- if (map->type < 0 || map->type > 5)
32676+ if (map->type >= ARRAY_SIZE(types))
32677 type = "??";
32678 else
32679 type = types[map->type];
32680@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file *m, void* data)
32681 struct drm_device *dev = node->minor->dev;
32682
32683 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
32684- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
32685+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
32686 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
32687- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
32688- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
32689+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
32690+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
32691 seq_printf(m, "%d gtt total\n", dev->gtt_total);
32692 return 0;
32693 }
32694@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32695 mutex_lock(&dev->struct_mutex);
32696 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
32697 atomic_read(&dev->vma_count),
32698+#ifdef CONFIG_GRKERNSEC_HIDESYM
32699+ NULL, 0);
32700+#else
32701 high_memory, (u64)virt_to_phys(high_memory));
32702+#endif
32703
32704 list_for_each_entry(pt, &dev->vmalist, head) {
32705 vma = pt->vma;
32706@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, void *data)
32707 continue;
32708 seq_printf(m,
32709 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
32710- pt->pid, vma->vm_start, vma->vm_end,
32711+ pt->pid,
32712+#ifdef CONFIG_GRKERNSEC_HIDESYM
32713+ 0, 0,
32714+#else
32715+ vma->vm_start, vma->vm_end,
32716+#endif
32717 vma->vm_flags & VM_READ ? 'r' : '-',
32718 vma->vm_flags & VM_WRITE ? 'w' : '-',
32719 vma->vm_flags & VM_EXEC ? 'x' : '-',
32720 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32721 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32722 vma->vm_flags & VM_IO ? 'i' : '-',
32723+#ifdef CONFIG_GRKERNSEC_HIDESYM
32724+ 0);
32725+#else
32726 vma->vm_pgoff);
32727+#endif
32728
32729 #if defined(__i386__)
32730 pgprot = pgprot_val(vma->vm_page_prot);
32731diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32732index 282d9fd..71e5f11 100644
32733--- a/drivers/gpu/drm/drm_ioc32.c
32734+++ b/drivers/gpu/drm/drm_ioc32.c
32735@@ -463,7 +463,7 @@ static int compat_drm_infobufs(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_desc *) (request + 1);
32740+ list = (struct drm_buf_desc __user *) (request + 1);
32741
32742 if (__put_user(count, &request->count)
32743 || __put_user(list, &request->list))
32744@@ -525,7 +525,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32745 request = compat_alloc_user_space(nbytes);
32746 if (!access_ok(VERIFY_WRITE, request, nbytes))
32747 return -EFAULT;
32748- list = (struct drm_buf_pub *) (request + 1);
32749+ list = (struct drm_buf_pub __user *) (request + 1);
32750
32751 if (__put_user(count, &request->count)
32752 || __put_user(list, &request->list))
32753diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32754index 9b9ff46..4ea724c 100644
32755--- a/drivers/gpu/drm/drm_ioctl.c
32756+++ b/drivers/gpu/drm/drm_ioctl.c
32757@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32758 stats->data[i].value =
32759 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32760 else
32761- stats->data[i].value = atomic_read(&dev->counts[i]);
32762+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32763 stats->data[i].type = dev->types[i];
32764 }
32765
32766diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32767index e2f70a5..c703e86 100644
32768--- a/drivers/gpu/drm/drm_lock.c
32769+++ b/drivers/gpu/drm/drm_lock.c
32770@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32771 if (drm_lock_take(&master->lock, lock->context)) {
32772 master->lock.file_priv = file_priv;
32773 master->lock.lock_time = jiffies;
32774- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32775+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32776 break; /* Got lock */
32777 }
32778
32779@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32780 return -EINVAL;
32781 }
32782
32783- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32784+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32785
32786 /* kernel_context_switch isn't used by any of the x86 drm
32787 * modules but is required by the Sparc driver.
32788diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32789index 7d1d88c..b9131b2 100644
32790--- a/drivers/gpu/drm/i810/i810_dma.c
32791+++ b/drivers/gpu/drm/i810/i810_dma.c
32792@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32793 dma->buflist[vertex->idx],
32794 vertex->discard, vertex->used);
32795
32796- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32797- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32798+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32799+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32800 sarea_priv->last_enqueue = dev_priv->counter - 1;
32801 sarea_priv->last_dispatch = (int)hw_status[5];
32802
32803@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32804 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32805 mc->last_render);
32806
32807- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32808- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32809+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32810+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32811 sarea_priv->last_enqueue = dev_priv->counter - 1;
32812 sarea_priv->last_dispatch = (int)hw_status[5];
32813
32814diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32815index 21e2691..7321edd 100644
32816--- a/drivers/gpu/drm/i810/i810_drv.h
32817+++ b/drivers/gpu/drm/i810/i810_drv.h
32818@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32819 int page_flipping;
32820
32821 wait_queue_head_t irq_queue;
32822- atomic_t irq_received;
32823- atomic_t irq_emitted;
32824+ atomic_unchecked_t irq_received;
32825+ atomic_unchecked_t irq_emitted;
32826
32827 int front_offset;
32828 } drm_i810_private_t;
32829diff --git a/drivers/gpu/drm/i830/i830_drv.h b/drivers/gpu/drm/i830/i830_drv.h
32830index da82afe..48a45de 100644
32831--- a/drivers/gpu/drm/i830/i830_drv.h
32832+++ b/drivers/gpu/drm/i830/i830_drv.h
32833@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
32834 int page_flipping;
32835
32836 wait_queue_head_t irq_queue;
32837- atomic_t irq_received;
32838- atomic_t irq_emitted;
32839+ atomic_unchecked_t irq_received;
32840+ atomic_unchecked_t irq_emitted;
32841
32842 int use_mi_batchbuffer_start;
32843
32844diff --git a/drivers/gpu/drm/i830/i830_irq.c b/drivers/gpu/drm/i830/i830_irq.c
32845index 91ec2bb..6f21fab 100644
32846--- a/drivers/gpu/drm/i830/i830_irq.c
32847+++ b/drivers/gpu/drm/i830/i830_irq.c
32848@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
32849
32850 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
32851
32852- atomic_inc(&dev_priv->irq_received);
32853+ atomic_inc_unchecked(&dev_priv->irq_received);
32854 wake_up_interruptible(&dev_priv->irq_queue);
32855
32856 return IRQ_HANDLED;
32857@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_device * dev)
32858
32859 DRM_DEBUG("%s\n", __func__);
32860
32861- atomic_inc(&dev_priv->irq_emitted);
32862+ atomic_inc_unchecked(&dev_priv->irq_emitted);
32863
32864 BEGIN_LP_RING(2);
32865 OUT_RING(0);
32866 OUT_RING(GFX_OP_USER_INTERRUPT);
32867 ADVANCE_LP_RING();
32868
32869- return atomic_read(&dev_priv->irq_emitted);
32870+ return atomic_read_unchecked(&dev_priv->irq_emitted);
32871 }
32872
32873 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32874@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32875
32876 DRM_DEBUG("%s\n", __func__);
32877
32878- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32879+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32880 return 0;
32881
32882 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
32883@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32884
32885 for (;;) {
32886 __set_current_state(TASK_INTERRUPTIBLE);
32887- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32888+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32889 break;
32890 if ((signed)(end - jiffies) <= 0) {
32891 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
32892@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct drm_device * dev)
32893 I830_WRITE16(I830REG_HWSTAM, 0xffff);
32894 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
32895 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
32896- atomic_set(&dev_priv->irq_received, 0);
32897- atomic_set(&dev_priv->irq_emitted, 0);
32898+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32899+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
32900 init_waitqueue_head(&dev_priv->irq_queue);
32901 }
32902
32903diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
32904index 288fc50..c6092055 100644
32905--- a/drivers/gpu/drm/i915/dvo.h
32906+++ b/drivers/gpu/drm/i915/dvo.h
32907@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
32908 *
32909 * \return singly-linked list of modes or NULL if no modes found.
32910 */
32911- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
32912+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
32913
32914 /**
32915 * Clean up driver-specific bits of the output
32916 */
32917- void (*destroy) (struct intel_dvo_device *dvo);
32918+ void (* const destroy) (struct intel_dvo_device *dvo);
32919
32920 /**
32921 * Debugging hook to dump device registers to log file
32922 */
32923- void (*dump_regs)(struct intel_dvo_device *dvo);
32924+ void (* const dump_regs)(struct intel_dvo_device *dvo);
32925 };
32926
32927-extern struct intel_dvo_dev_ops sil164_ops;
32928-extern struct intel_dvo_dev_ops ch7xxx_ops;
32929-extern struct intel_dvo_dev_ops ivch_ops;
32930-extern struct intel_dvo_dev_ops tfp410_ops;
32931-extern struct intel_dvo_dev_ops ch7017_ops;
32932+extern const struct intel_dvo_dev_ops sil164_ops;
32933+extern const struct intel_dvo_dev_ops ch7xxx_ops;
32934+extern const struct intel_dvo_dev_ops ivch_ops;
32935+extern const struct intel_dvo_dev_ops tfp410_ops;
32936+extern const struct intel_dvo_dev_ops ch7017_ops;
32937
32938 #endif /* _INTEL_DVO_H */
32939diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
32940index 621815b..499d82e 100644
32941--- a/drivers/gpu/drm/i915/dvo_ch7017.c
32942+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
32943@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_dvo_device *dvo)
32944 }
32945 }
32946
32947-struct intel_dvo_dev_ops ch7017_ops = {
32948+const struct intel_dvo_dev_ops ch7017_ops = {
32949 .init = ch7017_init,
32950 .detect = ch7017_detect,
32951 .mode_valid = ch7017_mode_valid,
32952diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
32953index a9b8962..ac769ba 100644
32954--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
32955+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
32956@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_dvo_device *dvo)
32957 }
32958 }
32959
32960-struct intel_dvo_dev_ops ch7xxx_ops = {
32961+const struct intel_dvo_dev_ops ch7xxx_ops = {
32962 .init = ch7xxx_init,
32963 .detect = ch7xxx_detect,
32964 .mode_valid = ch7xxx_mode_valid,
32965diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
32966index aa176f9..ed2930c 100644
32967--- a/drivers/gpu/drm/i915/dvo_ivch.c
32968+++ b/drivers/gpu/drm/i915/dvo_ivch.c
32969@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dvo_device *dvo)
32970 }
32971 }
32972
32973-struct intel_dvo_dev_ops ivch_ops= {
32974+const struct intel_dvo_dev_ops ivch_ops= {
32975 .init = ivch_init,
32976 .dpms = ivch_dpms,
32977 .save = ivch_save,
32978diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
32979index e1c1f73..7dbebcf 100644
32980--- a/drivers/gpu/drm/i915/dvo_sil164.c
32981+++ b/drivers/gpu/drm/i915/dvo_sil164.c
32982@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_dvo_device *dvo)
32983 }
32984 }
32985
32986-struct intel_dvo_dev_ops sil164_ops = {
32987+const struct intel_dvo_dev_ops sil164_ops = {
32988 .init = sil164_init,
32989 .detect = sil164_detect,
32990 .mode_valid = sil164_mode_valid,
32991diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
32992index 16dce84..7e1b6f8 100644
32993--- a/drivers/gpu/drm/i915/dvo_tfp410.c
32994+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
32995@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_dvo_device *dvo)
32996 }
32997 }
32998
32999-struct intel_dvo_dev_ops tfp410_ops = {
33000+const struct intel_dvo_dev_ops tfp410_ops = {
33001 .init = tfp410_init,
33002 .detect = tfp410_detect,
33003 .mode_valid = tfp410_mode_valid,
33004diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33005index 7e859d6..7d1cf2b 100644
33006--- a/drivers/gpu/drm/i915/i915_debugfs.c
33007+++ b/drivers/gpu/drm/i915/i915_debugfs.c
33008@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33009 I915_READ(GTIMR));
33010 }
33011 seq_printf(m, "Interrupts received: %d\n",
33012- atomic_read(&dev_priv->irq_received));
33013+ atomic_read_unchecked(&dev_priv->irq_received));
33014 if (dev_priv->hw_status_page != NULL) {
33015 seq_printf(m, "Current sequence: %d\n",
33016 i915_get_gem_seqno(dev));
33017diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
33018index 5449239..7e4f68d 100644
33019--- a/drivers/gpu/drm/i915/i915_drv.c
33020+++ b/drivers/gpu/drm/i915/i915_drv.c
33021@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
33022 return i915_resume(dev);
33023 }
33024
33025-static struct vm_operations_struct i915_gem_vm_ops = {
33026+static const struct vm_operations_struct i915_gem_vm_ops = {
33027 .fault = i915_gem_fault,
33028 .open = drm_gem_vm_open,
33029 .close = drm_gem_vm_close,
33030diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33031index 97163f7..c24c7c7 100644
33032--- a/drivers/gpu/drm/i915/i915_drv.h
33033+++ b/drivers/gpu/drm/i915/i915_drv.h
33034@@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
33035 /* display clock increase/decrease */
33036 /* pll clock increase/decrease */
33037 /* clock gating init */
33038-};
33039+} __no_const;
33040
33041 typedef struct drm_i915_private {
33042 struct drm_device *dev;
33043@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
33044 int page_flipping;
33045
33046 wait_queue_head_t irq_queue;
33047- atomic_t irq_received;
33048+ atomic_unchecked_t irq_received;
33049 /** Protects user_irq_refcount and irq_mask_reg */
33050 spinlock_t user_irq_lock;
33051 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
33052diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
33053index 27a3074..eb3f959 100644
33054--- a/drivers/gpu/drm/i915/i915_gem.c
33055+++ b/drivers/gpu/drm/i915/i915_gem.c
33056@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
33057
33058 args->aper_size = dev->gtt_total;
33059 args->aper_available_size = (args->aper_size -
33060- atomic_read(&dev->pin_memory));
33061+ atomic_read_unchecked(&dev->pin_memory));
33062
33063 return 0;
33064 }
33065@@ -2058,7 +2058,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
33066
33067 if (obj_priv->gtt_space) {
33068 atomic_dec(&dev->gtt_count);
33069- atomic_sub(obj->size, &dev->gtt_memory);
33070+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
33071
33072 drm_mm_put_block(obj_priv->gtt_space);
33073 obj_priv->gtt_space = NULL;
33074@@ -2701,7 +2701,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
33075 goto search_free;
33076 }
33077 atomic_inc(&dev->gtt_count);
33078- atomic_add(obj->size, &dev->gtt_memory);
33079+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
33080
33081 /* Assert that the object is not currently in any GPU domain. As it
33082 * wasn't in the GTT, there shouldn't be any way it could have been in
33083@@ -3755,9 +3755,9 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
33084 "%d/%d gtt bytes\n",
33085 atomic_read(&dev->object_count),
33086 atomic_read(&dev->pin_count),
33087- atomic_read(&dev->object_memory),
33088- atomic_read(&dev->pin_memory),
33089- atomic_read(&dev->gtt_memory),
33090+ atomic_read_unchecked(&dev->object_memory),
33091+ atomic_read_unchecked(&dev->pin_memory),
33092+ atomic_read_unchecked(&dev->gtt_memory),
33093 dev->gtt_total);
33094 }
33095 goto err;
33096@@ -3989,7 +3989,7 @@ i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment)
33097 */
33098 if (obj_priv->pin_count == 1) {
33099 atomic_inc(&dev->pin_count);
33100- atomic_add(obj->size, &dev->pin_memory);
33101+ atomic_add_unchecked(obj->size, &dev->pin_memory);
33102 if (!obj_priv->active &&
33103 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
33104 !list_empty(&obj_priv->list))
33105@@ -4022,7 +4022,7 @@ i915_gem_object_unpin(struct drm_gem_object *obj)
33106 list_move_tail(&obj_priv->list,
33107 &dev_priv->mm.inactive_list);
33108 atomic_dec(&dev->pin_count);
33109- atomic_sub(obj->size, &dev->pin_memory);
33110+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
33111 }
33112 i915_verify_inactive(dev, __FILE__, __LINE__);
33113 }
33114diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33115index 63f28ad..f5469da 100644
33116--- a/drivers/gpu/drm/i915/i915_irq.c
33117+++ b/drivers/gpu/drm/i915/i915_irq.c
33118@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
33119 int irq_received;
33120 int ret = IRQ_NONE;
33121
33122- atomic_inc(&dev_priv->irq_received);
33123+ atomic_inc_unchecked(&dev_priv->irq_received);
33124
33125 if (IS_IGDNG(dev))
33126 return igdng_irq_handler(dev);
33127@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct drm_device * dev)
33128 {
33129 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33130
33131- atomic_set(&dev_priv->irq_received, 0);
33132+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33133
33134 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
33135 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
33136diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
33137index 5d9c6a7..d1b0e29 100644
33138--- a/drivers/gpu/drm/i915/intel_sdvo.c
33139+++ b/drivers/gpu/drm/i915/intel_sdvo.c
33140@@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
33141 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
33142
33143 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
33144- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33145+ pax_open_kernel();
33146+ *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33147+ pax_close_kernel();
33148
33149 /* Read the regs to test if we can talk to the device */
33150 for (i = 0; i < 0x40; i++) {
33151diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33152index be6c6b9..8615d9c 100644
33153--- a/drivers/gpu/drm/mga/mga_drv.h
33154+++ b/drivers/gpu/drm/mga/mga_drv.h
33155@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33156 u32 clear_cmd;
33157 u32 maccess;
33158
33159- atomic_t vbl_received; /**< Number of vblanks received. */
33160+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33161 wait_queue_head_t fence_queue;
33162- atomic_t last_fence_retired;
33163+ atomic_unchecked_t last_fence_retired;
33164 u32 next_fence_to_post;
33165
33166 unsigned int fb_cpp;
33167diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33168index daa6041..a28a5da 100644
33169--- a/drivers/gpu/drm/mga/mga_irq.c
33170+++ b/drivers/gpu/drm/mga/mga_irq.c
33171@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33172 if (crtc != 0)
33173 return 0;
33174
33175- return atomic_read(&dev_priv->vbl_received);
33176+ return atomic_read_unchecked(&dev_priv->vbl_received);
33177 }
33178
33179
33180@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33181 /* VBLANK interrupt */
33182 if (status & MGA_VLINEPEN) {
33183 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33184- atomic_inc(&dev_priv->vbl_received);
33185+ atomic_inc_unchecked(&dev_priv->vbl_received);
33186 drm_handle_vblank(dev, 0);
33187 handled = 1;
33188 }
33189@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33190 MGA_WRITE(MGA_PRIMEND, prim_end);
33191 }
33192
33193- atomic_inc(&dev_priv->last_fence_retired);
33194+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33195 DRM_WAKEUP(&dev_priv->fence_queue);
33196 handled = 1;
33197 }
33198@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
33199 * using fences.
33200 */
33201 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33202- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33203+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33204 - *sequence) <= (1 << 23)));
33205
33206 *sequence = cur_fence;
33207diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33208index 4c39a40..b22a9ea 100644
33209--- a/drivers/gpu/drm/r128/r128_cce.c
33210+++ b/drivers/gpu/drm/r128/r128_cce.c
33211@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
33212
33213 /* GH: Simple idle check.
33214 */
33215- atomic_set(&dev_priv->idle_count, 0);
33216+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33217
33218 /* We don't support anything other than bus-mastering ring mode,
33219 * but the ring can be in either AGP or PCI space for the ring
33220diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33221index 3c60829..4faf484 100644
33222--- a/drivers/gpu/drm/r128/r128_drv.h
33223+++ b/drivers/gpu/drm/r128/r128_drv.h
33224@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33225 int is_pci;
33226 unsigned long cce_buffers_offset;
33227
33228- atomic_t idle_count;
33229+ atomic_unchecked_t idle_count;
33230
33231 int page_flipping;
33232 int current_page;
33233 u32 crtc_offset;
33234 u32 crtc_offset_cntl;
33235
33236- atomic_t vbl_received;
33237+ atomic_unchecked_t vbl_received;
33238
33239 u32 color_fmt;
33240 unsigned int front_offset;
33241diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33242index 69810fb..97bf17a 100644
33243--- a/drivers/gpu/drm/r128/r128_irq.c
33244+++ b/drivers/gpu/drm/r128/r128_irq.c
33245@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33246 if (crtc != 0)
33247 return 0;
33248
33249- return atomic_read(&dev_priv->vbl_received);
33250+ return atomic_read_unchecked(&dev_priv->vbl_received);
33251 }
33252
33253 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33254@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33255 /* VBLANK interrupt */
33256 if (status & R128_CRTC_VBLANK_INT) {
33257 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33258- atomic_inc(&dev_priv->vbl_received);
33259+ atomic_inc_unchecked(&dev_priv->vbl_received);
33260 drm_handle_vblank(dev, 0);
33261 return IRQ_HANDLED;
33262 }
33263diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33264index af2665c..51922d2 100644
33265--- a/drivers/gpu/drm/r128/r128_state.c
33266+++ b/drivers/gpu/drm/r128/r128_state.c
33267@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_private_t * dev_priv,
33268
33269 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
33270 {
33271- if (atomic_read(&dev_priv->idle_count) == 0) {
33272+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
33273 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33274 } else {
33275- atomic_set(&dev_priv->idle_count, 0);
33276+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33277 }
33278 }
33279
33280diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
33281index dd72b91..8644b3c 100644
33282--- a/drivers/gpu/drm/radeon/atom.c
33283+++ b/drivers/gpu/drm/radeon/atom.c
33284@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
33285 char name[512];
33286 int i;
33287
33288+ pax_track_stack();
33289+
33290 ctx->card = card;
33291 ctx->bios = bios;
33292
33293diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33294index 0d79577..efaa7a5 100644
33295--- a/drivers/gpu/drm/radeon/mkregtable.c
33296+++ b/drivers/gpu/drm/radeon/mkregtable.c
33297@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33298 regex_t mask_rex;
33299 regmatch_t match[4];
33300 char buf[1024];
33301- size_t end;
33302+ long end;
33303 int len;
33304 int done = 0;
33305 int r;
33306 unsigned o;
33307 struct offset *offset;
33308 char last_reg_s[10];
33309- int last_reg;
33310+ unsigned long last_reg;
33311
33312 if (regcomp
33313 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33314diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
33315index 6735213..38c2c67 100644
33316--- a/drivers/gpu/drm/radeon/radeon.h
33317+++ b/drivers/gpu/drm/radeon/radeon.h
33318@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device *rdev);
33319 */
33320 struct radeon_fence_driver {
33321 uint32_t scratch_reg;
33322- atomic_t seq;
33323+ atomic_unchecked_t seq;
33324 uint32_t last_seq;
33325 unsigned long count_timeout;
33326 wait_queue_head_t queue;
33327@@ -640,7 +640,7 @@ struct radeon_asic {
33328 uint32_t offset, uint32_t obj_size);
33329 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
33330 void (*bandwidth_update)(struct radeon_device *rdev);
33331-};
33332+} __no_const;
33333
33334 /*
33335 * Asic structures
33336diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
33337index 4e928b9..d8b6008 100644
33338--- a/drivers/gpu/drm/radeon/radeon_atombios.c
33339+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
33340@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
33341 bool linkb;
33342 struct radeon_i2c_bus_rec ddc_bus;
33343
33344+ pax_track_stack();
33345+
33346 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33347
33348 if (data_offset == 0)
33349@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
33350 }
33351 }
33352
33353-struct bios_connector {
33354+static struct bios_connector {
33355 bool valid;
33356 uint16_t line_mux;
33357 uint16_t devices;
33358 int connector_type;
33359 struct radeon_i2c_bus_rec ddc_bus;
33360-};
33361+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33362
33363 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33364 drm_device
33365@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33366 uint8_t dac;
33367 union atom_supported_devices *supported_devices;
33368 int i, j;
33369- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33370
33371 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33372
33373diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
33374index 083a181..ccccae0 100644
33375--- a/drivers/gpu/drm/radeon/radeon_display.c
33376+++ b/drivers/gpu/drm/radeon/radeon_display.c
33377@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pll *pll,
33378
33379 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
33380 error = freq - current_freq;
33381- error = error < 0 ? 0xffffffff : error;
33382+ error = (int32_t)error < 0 ? 0xffffffff : error;
33383 } else
33384 error = abs(current_freq - freq);
33385 vco_diff = abs(vco - best_vco);
33386diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33387index 76e4070..193fa7f 100644
33388--- a/drivers/gpu/drm/radeon/radeon_drv.h
33389+++ b/drivers/gpu/drm/radeon/radeon_drv.h
33390@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
33391
33392 /* SW interrupt */
33393 wait_queue_head_t swi_queue;
33394- atomic_t swi_emitted;
33395+ atomic_unchecked_t swi_emitted;
33396 int vblank_crtc;
33397 uint32_t irq_enable_reg;
33398 uint32_t r500_disp_irq_reg;
33399diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
33400index 3beb26d..6ce9c4a 100644
33401--- a/drivers/gpu/drm/radeon/radeon_fence.c
33402+++ b/drivers/gpu/drm/radeon/radeon_fence.c
33403@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
33404 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
33405 return 0;
33406 }
33407- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
33408+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
33409 if (!rdev->cp.ready) {
33410 /* FIXME: cp is not running assume everythings is done right
33411 * away
33412@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
33413 return r;
33414 }
33415 WREG32(rdev->fence_drv.scratch_reg, 0);
33416- atomic_set(&rdev->fence_drv.seq, 0);
33417+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
33418 INIT_LIST_HEAD(&rdev->fence_drv.created);
33419 INIT_LIST_HEAD(&rdev->fence_drv.emited);
33420 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
33421diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33422index a1bf11d..4a123c0 100644
33423--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33424+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33425@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33426 request = compat_alloc_user_space(sizeof(*request));
33427 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33428 || __put_user(req32.param, &request->param)
33429- || __put_user((void __user *)(unsigned long)req32.value,
33430+ || __put_user((unsigned long)req32.value,
33431 &request->value))
33432 return -EFAULT;
33433
33434diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33435index b79ecc4..8dab92d 100644
33436--- a/drivers/gpu/drm/radeon/radeon_irq.c
33437+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33438@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33439 unsigned int ret;
33440 RING_LOCALS;
33441
33442- atomic_inc(&dev_priv->swi_emitted);
33443- ret = atomic_read(&dev_priv->swi_emitted);
33444+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33445+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33446
33447 BEGIN_RING(4);
33448 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33449@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33450 drm_radeon_private_t *dev_priv =
33451 (drm_radeon_private_t *) dev->dev_private;
33452
33453- atomic_set(&dev_priv->swi_emitted, 0);
33454+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33455 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33456
33457 dev->max_vblank_count = 0x001fffff;
33458diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33459index 4747910..48ca4b3 100644
33460--- a/drivers/gpu/drm/radeon/radeon_state.c
33461+++ b/drivers/gpu/drm/radeon/radeon_state.c
33462@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33463 {
33464 drm_radeon_private_t *dev_priv = dev->dev_private;
33465 drm_radeon_getparam_t *param = data;
33466- int value;
33467+ int value = 0;
33468
33469 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33470
33471diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33472index 1381e06..0e53b17 100644
33473--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33474+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33475@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_device *rdev)
33476 DRM_INFO("radeon: ttm finalized\n");
33477 }
33478
33479-static struct vm_operations_struct radeon_ttm_vm_ops;
33480-static const struct vm_operations_struct *ttm_vm_ops = NULL;
33481-
33482-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33483-{
33484- struct ttm_buffer_object *bo;
33485- int r;
33486-
33487- bo = (struct ttm_buffer_object *)vma->vm_private_data;
33488- if (bo == NULL) {
33489- return VM_FAULT_NOPAGE;
33490- }
33491- r = ttm_vm_ops->fault(vma, vmf);
33492- return r;
33493-}
33494-
33495 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33496 {
33497 struct drm_file *file_priv;
33498 struct radeon_device *rdev;
33499- int r;
33500
33501 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
33502 return drm_mmap(filp, vma);
33503@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33504
33505 file_priv = (struct drm_file *)filp->private_data;
33506 rdev = file_priv->minor->dev->dev_private;
33507- if (rdev == NULL) {
33508+ if (!rdev)
33509 return -EINVAL;
33510- }
33511- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33512- if (unlikely(r != 0)) {
33513- return r;
33514- }
33515- if (unlikely(ttm_vm_ops == NULL)) {
33516- ttm_vm_ops = vma->vm_ops;
33517- radeon_ttm_vm_ops = *ttm_vm_ops;
33518- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33519- }
33520- vma->vm_ops = &radeon_ttm_vm_ops;
33521- return 0;
33522+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33523 }
33524
33525
33526diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33527index b12ff76..0bd0c6e 100644
33528--- a/drivers/gpu/drm/radeon/rs690.c
33529+++ b/drivers/gpu/drm/radeon/rs690.c
33530@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33531 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33532 rdev->pm.sideport_bandwidth.full)
33533 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33534- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
33535+ read_delay_latency.full = rfixed_const(800 * 1000);
33536 read_delay_latency.full = rfixed_div(read_delay_latency,
33537 rdev->pm.igp_sideport_mclk);
33538+ a.full = rfixed_const(370);
33539+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
33540 } else {
33541 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33542 rdev->pm.k8_bandwidth.full)
33543diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
33544index 0ed436e..e6e7ce3 100644
33545--- a/drivers/gpu/drm/ttm/ttm_bo.c
33546+++ b/drivers/gpu/drm/ttm/ttm_bo.c
33547@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_attrs[] = {
33548 NULL
33549 };
33550
33551-static struct sysfs_ops ttm_bo_global_ops = {
33552+static const struct sysfs_ops ttm_bo_global_ops = {
33553 .show = &ttm_bo_global_show
33554 };
33555
33556diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33557index 1c040d0..f9e4af8 100644
33558--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
33559+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33560@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33561 {
33562 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
33563 vma->vm_private_data;
33564- struct ttm_bo_device *bdev = bo->bdev;
33565+ struct ttm_bo_device *bdev;
33566 unsigned long bus_base;
33567 unsigned long bus_offset;
33568 unsigned long bus_size;
33569@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33570 unsigned long address = (unsigned long)vmf->virtual_address;
33571 int retval = VM_FAULT_NOPAGE;
33572
33573+ if (!bo)
33574+ return VM_FAULT_NOPAGE;
33575+ bdev = bo->bdev;
33576+
33577 /*
33578 * Work around locking order reversal in fault / nopfn
33579 * between mmap_sem and bo_reserve: Perform a trylock operation
33580diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
33581index b170071..28ae90e 100644
33582--- a/drivers/gpu/drm/ttm/ttm_global.c
33583+++ b/drivers/gpu/drm/ttm/ttm_global.c
33584@@ -36,7 +36,7 @@
33585 struct ttm_global_item {
33586 struct mutex mutex;
33587 void *object;
33588- int refcount;
33589+ atomic_t refcount;
33590 };
33591
33592 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
33593@@ -49,7 +49,7 @@ void ttm_global_init(void)
33594 struct ttm_global_item *item = &glob[i];
33595 mutex_init(&item->mutex);
33596 item->object = NULL;
33597- item->refcount = 0;
33598+ atomic_set(&item->refcount, 0);
33599 }
33600 }
33601
33602@@ -59,7 +59,7 @@ void ttm_global_release(void)
33603 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
33604 struct ttm_global_item *item = &glob[i];
33605 BUG_ON(item->object != NULL);
33606- BUG_ON(item->refcount != 0);
33607+ BUG_ON(atomic_read(&item->refcount) != 0);
33608 }
33609 }
33610
33611@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33612 void *object;
33613
33614 mutex_lock(&item->mutex);
33615- if (item->refcount == 0) {
33616+ if (atomic_read(&item->refcount) == 0) {
33617 item->object = kzalloc(ref->size, GFP_KERNEL);
33618 if (unlikely(item->object == NULL)) {
33619 ret = -ENOMEM;
33620@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33621 goto out_err;
33622
33623 }
33624- ++item->refcount;
33625+ atomic_inc(&item->refcount);
33626 ref->object = item->object;
33627 object = item->object;
33628 mutex_unlock(&item->mutex);
33629@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_global_reference *ref)
33630 struct ttm_global_item *item = &glob[ref->global_type];
33631
33632 mutex_lock(&item->mutex);
33633- BUG_ON(item->refcount == 0);
33634+ BUG_ON(atomic_read(&item->refcount) == 0);
33635 BUG_ON(ref->object != item->object);
33636- if (--item->refcount == 0) {
33637+ if (atomic_dec_and_test(&item->refcount)) {
33638 ref->release(ref);
33639 item->object = NULL;
33640 }
33641diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
33642index 072c281..d8ef483 100644
33643--- a/drivers/gpu/drm/ttm/ttm_memory.c
33644+++ b/drivers/gpu/drm/ttm/ttm_memory.c
33645@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_attrs[] = {
33646 NULL
33647 };
33648
33649-static struct sysfs_ops ttm_mem_zone_ops = {
33650+static const struct sysfs_ops ttm_mem_zone_ops = {
33651 .show = &ttm_mem_zone_show,
33652 .store = &ttm_mem_zone_store
33653 };
33654diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33655index cafcb84..b8e66cc 100644
33656--- a/drivers/gpu/drm/via/via_drv.h
33657+++ b/drivers/gpu/drm/via/via_drv.h
33658@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33659 typedef uint32_t maskarray_t[5];
33660
33661 typedef struct drm_via_irq {
33662- atomic_t irq_received;
33663+ atomic_unchecked_t irq_received;
33664 uint32_t pending_mask;
33665 uint32_t enable_mask;
33666 wait_queue_head_t irq_queue;
33667@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33668 struct timeval last_vblank;
33669 int last_vblank_valid;
33670 unsigned usec_per_vblank;
33671- atomic_t vbl_received;
33672+ atomic_unchecked_t vbl_received;
33673 drm_via_state_t hc_state;
33674 char pci_buf[VIA_PCI_BUF_SIZE];
33675 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33676diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33677index 5935b88..127a8a6 100644
33678--- a/drivers/gpu/drm/via/via_irq.c
33679+++ b/drivers/gpu/drm/via/via_irq.c
33680@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33681 if (crtc != 0)
33682 return 0;
33683
33684- return atomic_read(&dev_priv->vbl_received);
33685+ return atomic_read_unchecked(&dev_priv->vbl_received);
33686 }
33687
33688 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33689@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33690
33691 status = VIA_READ(VIA_REG_INTERRUPT);
33692 if (status & VIA_IRQ_VBLANK_PENDING) {
33693- atomic_inc(&dev_priv->vbl_received);
33694- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33695+ atomic_inc_unchecked(&dev_priv->vbl_received);
33696+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33697 do_gettimeofday(&cur_vblank);
33698 if (dev_priv->last_vblank_valid) {
33699 dev_priv->usec_per_vblank =
33700@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33701 dev_priv->last_vblank = cur_vblank;
33702 dev_priv->last_vblank_valid = 1;
33703 }
33704- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33705+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33706 DRM_DEBUG("US per vblank is: %u\n",
33707 dev_priv->usec_per_vblank);
33708 }
33709@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33710
33711 for (i = 0; i < dev_priv->num_irqs; ++i) {
33712 if (status & cur_irq->pending_mask) {
33713- atomic_inc(&cur_irq->irq_received);
33714+ atomic_inc_unchecked(&cur_irq->irq_received);
33715 DRM_WAKEUP(&cur_irq->irq_queue);
33716 handled = 1;
33717 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
33718@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequenc
33719 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33720 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33721 masks[irq][4]));
33722- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33723+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33724 } else {
33725 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33726 (((cur_irq_sequence =
33727- atomic_read(&cur_irq->irq_received)) -
33728+ atomic_read_unchecked(&cur_irq->irq_received)) -
33729 *sequence) <= (1 << 23)));
33730 }
33731 *sequence = cur_irq_sequence;
33732@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct drm_device * dev)
33733 }
33734
33735 for (i = 0; i < dev_priv->num_irqs; ++i) {
33736- atomic_set(&cur_irq->irq_received, 0);
33737+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33738 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33739 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33740 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33741@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33742 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33743 case VIA_IRQ_RELATIVE:
33744 irqwait->request.sequence +=
33745- atomic_read(&cur_irq->irq_received);
33746+ atomic_read_unchecked(&cur_irq->irq_received);
33747 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33748 case VIA_IRQ_ABSOLUTE:
33749 break;
33750diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
33751index aa8688d..6a0140c 100644
33752--- a/drivers/gpu/vga/vgaarb.c
33753+++ b/drivers/gpu/vga/vgaarb.c
33754@@ -894,14 +894,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
33755 uc = &priv->cards[i];
33756 }
33757
33758- if (!uc)
33759- return -EINVAL;
33760+ if (!uc) {
33761+ ret_val = -EINVAL;
33762+ goto done;
33763+ }
33764
33765- if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
33766- return -EINVAL;
33767+ if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
33768+ ret_val = -EINVAL;
33769+ goto done;
33770+ }
33771
33772- if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
33773- return -EINVAL;
33774+ if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
33775+ ret_val = -EINVAL;
33776+ goto done;
33777+ }
33778
33779 vga_put(pdev, io_state);
33780
33781diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33782index f3f1415..e561d90 100644
33783--- a/drivers/hid/hid-core.c
33784+++ b/drivers/hid/hid-core.c
33785@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device *hdev)
33786
33787 int hid_add_device(struct hid_device *hdev)
33788 {
33789- static atomic_t id = ATOMIC_INIT(0);
33790+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33791 int ret;
33792
33793 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33794@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hdev)
33795 /* XXX hack, any other cleaner solution after the driver core
33796 * is converted to allow more than 20 bytes as the device name? */
33797 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33798- hdev->vendor, hdev->product, atomic_inc_return(&id));
33799+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33800
33801 ret = device_add(&hdev->dev);
33802 if (!ret)
33803diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33804index 8b6ee24..70f657d 100644
33805--- a/drivers/hid/usbhid/hiddev.c
33806+++ b/drivers/hid/usbhid/hiddev.c
33807@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33808 return put_user(HID_VERSION, (int __user *)arg);
33809
33810 case HIDIOCAPPLICATION:
33811- if (arg < 0 || arg >= hid->maxapplication)
33812+ if (arg >= hid->maxapplication)
33813 return -EINVAL;
33814
33815 for (i = 0; i < hid->maxcollection; i++)
33816diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
33817index 5d5ed69..f40533e 100644
33818--- a/drivers/hwmon/lis3lv02d.c
33819+++ b/drivers/hwmon/lis3lv02d.c
33820@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
33821 * the lid is closed. This leads to interrupts as soon as a little move
33822 * is done.
33823 */
33824- atomic_inc(&lis3_dev.count);
33825+ atomic_inc_unchecked(&lis3_dev.count);
33826
33827 wake_up_interruptible(&lis3_dev.misc_wait);
33828 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33829@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33830 if (test_and_set_bit(0, &lis3_dev.misc_opened))
33831 return -EBUSY; /* already open */
33832
33833- atomic_set(&lis3_dev.count, 0);
33834+ atomic_set_unchecked(&lis3_dev.count, 0);
33835
33836 /*
33837 * The sensor can generate interrupts for free-fall and direction
33838@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33839 add_wait_queue(&lis3_dev.misc_wait, &wait);
33840 while (true) {
33841 set_current_state(TASK_INTERRUPTIBLE);
33842- data = atomic_xchg(&lis3_dev.count, 0);
33843+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33844 if (data)
33845 break;
33846
33847@@ -244,7 +244,7 @@ out:
33848 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33849 {
33850 poll_wait(file, &lis3_dev.misc_wait, wait);
33851- if (atomic_read(&lis3_dev.count))
33852+ if (atomic_read_unchecked(&lis3_dev.count))
33853 return POLLIN | POLLRDNORM;
33854 return 0;
33855 }
33856diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
33857index 7cdd76f..fe0efdf 100644
33858--- a/drivers/hwmon/lis3lv02d.h
33859+++ b/drivers/hwmon/lis3lv02d.h
33860@@ -201,7 +201,7 @@ struct lis3lv02d {
33861
33862 struct input_polled_dev *idev; /* input device */
33863 struct platform_device *pdev; /* platform device */
33864- atomic_t count; /* interrupt count after last read */
33865+ atomic_unchecked_t count; /* interrupt count after last read */
33866 int xcalib; /* calibrated null value for x */
33867 int ycalib; /* calibrated null value for y */
33868 int zcalib; /* calibrated null value for z */
33869diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33870index 2040507..706ec1e 100644
33871--- a/drivers/hwmon/sht15.c
33872+++ b/drivers/hwmon/sht15.c
33873@@ -112,7 +112,7 @@ struct sht15_data {
33874 int supply_uV;
33875 int supply_uV_valid;
33876 struct work_struct update_supply_work;
33877- atomic_t interrupt_handled;
33878+ atomic_unchecked_t interrupt_handled;
33879 };
33880
33881 /**
33882@@ -245,13 +245,13 @@ static inline int sht15_update_single_val(struct sht15_data *data,
33883 return ret;
33884
33885 gpio_direction_input(data->pdata->gpio_data);
33886- atomic_set(&data->interrupt_handled, 0);
33887+ atomic_set_unchecked(&data->interrupt_handled, 0);
33888
33889 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33890 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33891 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33892 /* Only relevant if the interrupt hasn't occured. */
33893- if (!atomic_read(&data->interrupt_handled))
33894+ if (!atomic_read_unchecked(&data->interrupt_handled))
33895 schedule_work(&data->read_work);
33896 }
33897 ret = wait_event_timeout(data->wait_queue,
33898@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33899 struct sht15_data *data = d;
33900 /* First disable the interrupt */
33901 disable_irq_nosync(irq);
33902- atomic_inc(&data->interrupt_handled);
33903+ atomic_inc_unchecked(&data->interrupt_handled);
33904 /* Then schedule a reading work struct */
33905 if (data->flag != SHT15_READING_NOTHING)
33906 schedule_work(&data->read_work);
33907@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33908 here as could have gone low in meantime so verify
33909 it hasn't!
33910 */
33911- atomic_set(&data->interrupt_handled, 0);
33912+ atomic_set_unchecked(&data->interrupt_handled, 0);
33913 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33914 /* If still not occured or another handler has been scheduled */
33915 if (gpio_get_value(data->pdata->gpio_data)
33916- || atomic_read(&data->interrupt_handled))
33917+ || atomic_read_unchecked(&data->interrupt_handled))
33918 return;
33919 }
33920 /* Read the data back from the device */
33921diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
33922index 97851c5..cb40626 100644
33923--- a/drivers/hwmon/w83791d.c
33924+++ b/drivers/hwmon/w83791d.c
33925@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_client *client, int kind,
33926 struct i2c_board_info *info);
33927 static int w83791d_remove(struct i2c_client *client);
33928
33929-static int w83791d_read(struct i2c_client *client, u8 register);
33930-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
33931+static int w83791d_read(struct i2c_client *client, u8 reg);
33932+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
33933 static struct w83791d_data *w83791d_update_device(struct device *dev);
33934
33935 #ifdef DEBUG
33936diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33937index 378fcb5..5e91fa8 100644
33938--- a/drivers/i2c/busses/i2c-amd756-s4882.c
33939+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33940@@ -43,7 +43,7 @@
33941 extern struct i2c_adapter amd756_smbus;
33942
33943 static struct i2c_adapter *s4882_adapter;
33944-static struct i2c_algorithm *s4882_algo;
33945+static i2c_algorithm_no_const *s4882_algo;
33946
33947 /* Wrapper access functions for multiplexed SMBus */
33948 static DEFINE_MUTEX(amd756_lock);
33949diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33950index 29015eb..af2d8e9 100644
33951--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33952+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33953@@ -41,7 +41,7 @@
33954 extern struct i2c_adapter *nforce2_smbus;
33955
33956 static struct i2c_adapter *s4985_adapter;
33957-static struct i2c_algorithm *s4985_algo;
33958+static i2c_algorithm_no_const *s4985_algo;
33959
33960 /* Wrapper access functions for multiplexed SMBus */
33961 static DEFINE_MUTEX(nforce2_lock);
33962diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
33963index 878f8ec..12376fc 100644
33964--- a/drivers/ide/aec62xx.c
33965+++ b/drivers/ide/aec62xx.c
33966@@ -180,7 +180,7 @@ static const struct ide_port_ops atp86x_port_ops = {
33967 .cable_detect = atp86x_cable_detect,
33968 };
33969
33970-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
33971+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
33972 { /* 0: AEC6210 */
33973 .name = DRV_NAME,
33974 .init_chipset = init_chipset_aec62xx,
33975diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
33976index e59b6de..4b4fc65 100644
33977--- a/drivers/ide/alim15x3.c
33978+++ b/drivers/ide/alim15x3.c
33979@@ -509,7 +509,7 @@ static const struct ide_dma_ops ali_dma_ops = {
33980 .dma_sff_read_status = ide_dma_sff_read_status,
33981 };
33982
33983-static const struct ide_port_info ali15x3_chipset __devinitdata = {
33984+static const struct ide_port_info ali15x3_chipset __devinitconst = {
33985 .name = DRV_NAME,
33986 .init_chipset = init_chipset_ali15x3,
33987 .init_hwif = init_hwif_ali15x3,
33988diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
33989index 628cd2e..087a414 100644
33990--- a/drivers/ide/amd74xx.c
33991+++ b/drivers/ide/amd74xx.c
33992@@ -221,7 +221,7 @@ static const struct ide_port_ops amd_port_ops = {
33993 .udma_mask = udma, \
33994 }
33995
33996-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
33997+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
33998 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
33999 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
34000 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
34001diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
34002index 837322b..837fd71 100644
34003--- a/drivers/ide/atiixp.c
34004+++ b/drivers/ide/atiixp.c
34005@@ -137,7 +137,7 @@ static const struct ide_port_ops atiixp_port_ops = {
34006 .cable_detect = atiixp_cable_detect,
34007 };
34008
34009-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
34010+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
34011 { /* 0: IXP200/300/400/700 */
34012 .name = DRV_NAME,
34013 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
34014diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
34015index ca0c46f..d55318a 100644
34016--- a/drivers/ide/cmd64x.c
34017+++ b/drivers/ide/cmd64x.c
34018@@ -372,7 +372,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
34019 .dma_sff_read_status = ide_dma_sff_read_status,
34020 };
34021
34022-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
34023+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
34024 { /* 0: CMD643 */
34025 .name = DRV_NAME,
34026 .init_chipset = init_chipset_cmd64x,
34027diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
34028index 09f98ed..cebc5bc 100644
34029--- a/drivers/ide/cs5520.c
34030+++ b/drivers/ide/cs5520.c
34031@@ -93,7 +93,7 @@ static const struct ide_port_ops cs5520_port_ops = {
34032 .set_dma_mode = cs5520_set_dma_mode,
34033 };
34034
34035-static const struct ide_port_info cyrix_chipset __devinitdata = {
34036+static const struct ide_port_info cyrix_chipset __devinitconst = {
34037 .name = DRV_NAME,
34038 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
34039 .port_ops = &cs5520_port_ops,
34040diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
34041index 40bf05e..7d58ca0 100644
34042--- a/drivers/ide/cs5530.c
34043+++ b/drivers/ide/cs5530.c
34044@@ -244,7 +244,7 @@ static const struct ide_port_ops cs5530_port_ops = {
34045 .udma_filter = cs5530_udma_filter,
34046 };
34047
34048-static const struct ide_port_info cs5530_chipset __devinitdata = {
34049+static const struct ide_port_info cs5530_chipset __devinitconst = {
34050 .name = DRV_NAME,
34051 .init_chipset = init_chipset_cs5530,
34052 .init_hwif = init_hwif_cs5530,
34053diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
34054index 983d957..53e6172 100644
34055--- a/drivers/ide/cs5535.c
34056+++ b/drivers/ide/cs5535.c
34057@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
34058 .cable_detect = cs5535_cable_detect,
34059 };
34060
34061-static const struct ide_port_info cs5535_chipset __devinitdata = {
34062+static const struct ide_port_info cs5535_chipset __devinitconst = {
34063 .name = DRV_NAME,
34064 .port_ops = &cs5535_port_ops,
34065 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
34066diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
34067index 74fc540..8e933d8 100644
34068--- a/drivers/ide/cy82c693.c
34069+++ b/drivers/ide/cy82c693.c
34070@@ -288,7 +288,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
34071 .set_dma_mode = cy82c693_set_dma_mode,
34072 };
34073
34074-static const struct ide_port_info cy82c693_chipset __devinitdata = {
34075+static const struct ide_port_info cy82c693_chipset __devinitconst = {
34076 .name = DRV_NAME,
34077 .init_iops = init_iops_cy82c693,
34078 .port_ops = &cy82c693_port_ops,
34079diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
34080index 7ce68ef..e78197d 100644
34081--- a/drivers/ide/hpt366.c
34082+++ b/drivers/ide/hpt366.c
34083@@ -507,7 +507,7 @@ static struct hpt_timings hpt37x_timings = {
34084 }
34085 };
34086
34087-static const struct hpt_info hpt36x __devinitdata = {
34088+static const struct hpt_info hpt36x __devinitconst = {
34089 .chip_name = "HPT36x",
34090 .chip_type = HPT36x,
34091 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
34092@@ -515,7 +515,7 @@ static const struct hpt_info hpt36x __devinitdata = {
34093 .timings = &hpt36x_timings
34094 };
34095
34096-static const struct hpt_info hpt370 __devinitdata = {
34097+static const struct hpt_info hpt370 __devinitconst = {
34098 .chip_name = "HPT370",
34099 .chip_type = HPT370,
34100 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34101@@ -523,7 +523,7 @@ static const struct hpt_info hpt370 __devinitdata = {
34102 .timings = &hpt37x_timings
34103 };
34104
34105-static const struct hpt_info hpt370a __devinitdata = {
34106+static const struct hpt_info hpt370a __devinitconst = {
34107 .chip_name = "HPT370A",
34108 .chip_type = HPT370A,
34109 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34110@@ -531,7 +531,7 @@ static const struct hpt_info hpt370a __devinitdata = {
34111 .timings = &hpt37x_timings
34112 };
34113
34114-static const struct hpt_info hpt374 __devinitdata = {
34115+static const struct hpt_info hpt374 __devinitconst = {
34116 .chip_name = "HPT374",
34117 .chip_type = HPT374,
34118 .udma_mask = ATA_UDMA5,
34119@@ -539,7 +539,7 @@ static const struct hpt_info hpt374 __devinitdata = {
34120 .timings = &hpt37x_timings
34121 };
34122
34123-static const struct hpt_info hpt372 __devinitdata = {
34124+static const struct hpt_info hpt372 __devinitconst = {
34125 .chip_name = "HPT372",
34126 .chip_type = HPT372,
34127 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34128@@ -547,7 +547,7 @@ static const struct hpt_info hpt372 __devinitdata = {
34129 .timings = &hpt37x_timings
34130 };
34131
34132-static const struct hpt_info hpt372a __devinitdata = {
34133+static const struct hpt_info hpt372a __devinitconst = {
34134 .chip_name = "HPT372A",
34135 .chip_type = HPT372A,
34136 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34137@@ -555,7 +555,7 @@ static const struct hpt_info hpt372a __devinitdata = {
34138 .timings = &hpt37x_timings
34139 };
34140
34141-static const struct hpt_info hpt302 __devinitdata = {
34142+static const struct hpt_info hpt302 __devinitconst = {
34143 .chip_name = "HPT302",
34144 .chip_type = HPT302,
34145 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34146@@ -563,7 +563,7 @@ static const struct hpt_info hpt302 __devinitdata = {
34147 .timings = &hpt37x_timings
34148 };
34149
34150-static const struct hpt_info hpt371 __devinitdata = {
34151+static const struct hpt_info hpt371 __devinitconst = {
34152 .chip_name = "HPT371",
34153 .chip_type = HPT371,
34154 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34155@@ -571,7 +571,7 @@ static const struct hpt_info hpt371 __devinitdata = {
34156 .timings = &hpt37x_timings
34157 };
34158
34159-static const struct hpt_info hpt372n __devinitdata = {
34160+static const struct hpt_info hpt372n __devinitconst = {
34161 .chip_name = "HPT372N",
34162 .chip_type = HPT372N,
34163 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34164@@ -579,7 +579,7 @@ static const struct hpt_info hpt372n __devinitdata = {
34165 .timings = &hpt37x_timings
34166 };
34167
34168-static const struct hpt_info hpt302n __devinitdata = {
34169+static const struct hpt_info hpt302n __devinitconst = {
34170 .chip_name = "HPT302N",
34171 .chip_type = HPT302N,
34172 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34173@@ -587,7 +587,7 @@ static const struct hpt_info hpt302n __devinitdata = {
34174 .timings = &hpt37x_timings
34175 };
34176
34177-static const struct hpt_info hpt371n __devinitdata = {
34178+static const struct hpt_info hpt371n __devinitconst = {
34179 .chip_name = "HPT371N",
34180 .chip_type = HPT371N,
34181 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34182@@ -1422,7 +1422,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
34183 .dma_sff_read_status = ide_dma_sff_read_status,
34184 };
34185
34186-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
34187+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
34188 { /* 0: HPT36x */
34189 .name = DRV_NAME,
34190 .init_chipset = init_chipset_hpt366,
34191diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34192index 2de76cc..74186a1 100644
34193--- a/drivers/ide/ide-cd.c
34194+++ b/drivers/ide/ide-cd.c
34195@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34196 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34197 if ((unsigned long)buf & alignment
34198 || blk_rq_bytes(rq) & q->dma_pad_mask
34199- || object_is_on_stack(buf))
34200+ || object_starts_on_stack(buf))
34201 drive->dma = 0;
34202 }
34203 }
34204diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
34205index fefbdfc..62ff465 100644
34206--- a/drivers/ide/ide-floppy.c
34207+++ b/drivers/ide/ide-floppy.c
34208@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
34209 u8 pc_buf[256], header_len, desc_cnt;
34210 int i, rc = 1, blocks, length;
34211
34212+ pax_track_stack();
34213+
34214 ide_debug_log(IDE_DBG_FUNC, "enter");
34215
34216 drive->bios_cyl = 0;
34217diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
34218index 39d4e01..11538ce 100644
34219--- a/drivers/ide/ide-pci-generic.c
34220+++ b/drivers/ide/ide-pci-generic.c
34221@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
34222 .udma_mask = ATA_UDMA6, \
34223 }
34224
34225-static const struct ide_port_info generic_chipsets[] __devinitdata = {
34226+static const struct ide_port_info generic_chipsets[] __devinitconst = {
34227 /* 0: Unknown */
34228 DECLARE_GENERIC_PCI_DEV(0),
34229
34230diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
34231index 0d266a5..aaca790 100644
34232--- a/drivers/ide/it8172.c
34233+++ b/drivers/ide/it8172.c
34234@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
34235 .set_dma_mode = it8172_set_dma_mode,
34236 };
34237
34238-static const struct ide_port_info it8172_port_info __devinitdata = {
34239+static const struct ide_port_info it8172_port_info __devinitconst = {
34240 .name = DRV_NAME,
34241 .port_ops = &it8172_port_ops,
34242 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
34243diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
34244index 4797616..4be488a 100644
34245--- a/drivers/ide/it8213.c
34246+++ b/drivers/ide/it8213.c
34247@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
34248 .cable_detect = it8213_cable_detect,
34249 };
34250
34251-static const struct ide_port_info it8213_chipset __devinitdata = {
34252+static const struct ide_port_info it8213_chipset __devinitconst = {
34253 .name = DRV_NAME,
34254 .enablebits = { {0x41, 0x80, 0x80} },
34255 .port_ops = &it8213_port_ops,
34256diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
34257index 51aa745..146ee60 100644
34258--- a/drivers/ide/it821x.c
34259+++ b/drivers/ide/it821x.c
34260@@ -627,7 +627,7 @@ static const struct ide_port_ops it821x_port_ops = {
34261 .cable_detect = it821x_cable_detect,
34262 };
34263
34264-static const struct ide_port_info it821x_chipset __devinitdata = {
34265+static const struct ide_port_info it821x_chipset __devinitconst = {
34266 .name = DRV_NAME,
34267 .init_chipset = init_chipset_it821x,
34268 .init_hwif = init_hwif_it821x,
34269diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
34270index bf2be64..9270098 100644
34271--- a/drivers/ide/jmicron.c
34272+++ b/drivers/ide/jmicron.c
34273@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
34274 .cable_detect = jmicron_cable_detect,
34275 };
34276
34277-static const struct ide_port_info jmicron_chipset __devinitdata = {
34278+static const struct ide_port_info jmicron_chipset __devinitconst = {
34279 .name = DRV_NAME,
34280 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
34281 .port_ops = &jmicron_port_ops,
34282diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
34283index 95327a2..73f78d8 100644
34284--- a/drivers/ide/ns87415.c
34285+++ b/drivers/ide/ns87415.c
34286@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
34287 .dma_sff_read_status = superio_dma_sff_read_status,
34288 };
34289
34290-static const struct ide_port_info ns87415_chipset __devinitdata = {
34291+static const struct ide_port_info ns87415_chipset __devinitconst = {
34292 .name = DRV_NAME,
34293 .init_hwif = init_hwif_ns87415,
34294 .tp_ops = &ns87415_tp_ops,
34295diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
34296index f1d70d6..e1de05b 100644
34297--- a/drivers/ide/opti621.c
34298+++ b/drivers/ide/opti621.c
34299@@ -202,7 +202,7 @@ static const struct ide_port_ops opti621_port_ops = {
34300 .set_pio_mode = opti621_set_pio_mode,
34301 };
34302
34303-static const struct ide_port_info opti621_chipset __devinitdata = {
34304+static const struct ide_port_info opti621_chipset __devinitconst = {
34305 .name = DRV_NAME,
34306 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
34307 .port_ops = &opti621_port_ops,
34308diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
34309index 65ba823..7311f4d 100644
34310--- a/drivers/ide/pdc202xx_new.c
34311+++ b/drivers/ide/pdc202xx_new.c
34312@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
34313 .udma_mask = udma, \
34314 }
34315
34316-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
34317+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
34318 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
34319 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
34320 };
34321diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
34322index cb812f3..af816ef 100644
34323--- a/drivers/ide/pdc202xx_old.c
34324+++ b/drivers/ide/pdc202xx_old.c
34325@@ -285,7 +285,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
34326 .max_sectors = sectors, \
34327 }
34328
34329-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
34330+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
34331 { /* 0: PDC20246 */
34332 .name = DRV_NAME,
34333 .init_chipset = init_chipset_pdc202xx,
34334diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
34335index bf14f39..15c4b98 100644
34336--- a/drivers/ide/piix.c
34337+++ b/drivers/ide/piix.c
34338@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
34339 .udma_mask = udma, \
34340 }
34341
34342-static const struct ide_port_info piix_pci_info[] __devinitdata = {
34343+static const struct ide_port_info piix_pci_info[] __devinitconst = {
34344 /* 0: MPIIX */
34345 { /*
34346 * MPIIX actually has only a single IDE channel mapped to
34347diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
34348index a6414a8..c04173e 100644
34349--- a/drivers/ide/rz1000.c
34350+++ b/drivers/ide/rz1000.c
34351@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
34352 }
34353 }
34354
34355-static const struct ide_port_info rz1000_chipset __devinitdata = {
34356+static const struct ide_port_info rz1000_chipset __devinitconst = {
34357 .name = DRV_NAME,
34358 .host_flags = IDE_HFLAG_NO_DMA,
34359 };
34360diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
34361index d467478..9203942 100644
34362--- a/drivers/ide/sc1200.c
34363+++ b/drivers/ide/sc1200.c
34364@@ -290,7 +290,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
34365 .dma_sff_read_status = ide_dma_sff_read_status,
34366 };
34367
34368-static const struct ide_port_info sc1200_chipset __devinitdata = {
34369+static const struct ide_port_info sc1200_chipset __devinitconst = {
34370 .name = DRV_NAME,
34371 .port_ops = &sc1200_port_ops,
34372 .dma_ops = &sc1200_dma_ops,
34373diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
34374index 1104bb3..59c5194 100644
34375--- a/drivers/ide/scc_pata.c
34376+++ b/drivers/ide/scc_pata.c
34377@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
34378 .dma_sff_read_status = scc_dma_sff_read_status,
34379 };
34380
34381-static const struct ide_port_info scc_chipset __devinitdata = {
34382+static const struct ide_port_info scc_chipset __devinitconst = {
34383 .name = "sccIDE",
34384 .init_iops = init_iops_scc,
34385 .init_dma = scc_init_dma,
34386diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
34387index b6554ef..6cc2cc3 100644
34388--- a/drivers/ide/serverworks.c
34389+++ b/drivers/ide/serverworks.c
34390@@ -353,7 +353,7 @@ static const struct ide_port_ops svwks_port_ops = {
34391 .cable_detect = svwks_cable_detect,
34392 };
34393
34394-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
34395+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
34396 { /* 0: OSB4 */
34397 .name = DRV_NAME,
34398 .init_chipset = init_chipset_svwks,
34399diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
34400index ab3db61..afed580 100644
34401--- a/drivers/ide/setup-pci.c
34402+++ b/drivers/ide/setup-pci.c
34403@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
34404 int ret, i, n_ports = dev2 ? 4 : 2;
34405 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
34406
34407+ pax_track_stack();
34408+
34409 for (i = 0; i < n_ports / 2; i++) {
34410 ret = ide_setup_pci_controller(pdev[i], d, !i);
34411 if (ret < 0)
34412diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
34413index d95df52..0b03a39 100644
34414--- a/drivers/ide/siimage.c
34415+++ b/drivers/ide/siimage.c
34416@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
34417 .udma_mask = ATA_UDMA6, \
34418 }
34419
34420-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
34421+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
34422 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
34423 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
34424 };
34425diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
34426index 3b88eba..ca8699d 100644
34427--- a/drivers/ide/sis5513.c
34428+++ b/drivers/ide/sis5513.c
34429@@ -561,7 +561,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
34430 .cable_detect = sis_cable_detect,
34431 };
34432
34433-static const struct ide_port_info sis5513_chipset __devinitdata = {
34434+static const struct ide_port_info sis5513_chipset __devinitconst = {
34435 .name = DRV_NAME,
34436 .init_chipset = init_chipset_sis5513,
34437 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
34438diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
34439index d698da4..fca42a4 100644
34440--- a/drivers/ide/sl82c105.c
34441+++ b/drivers/ide/sl82c105.c
34442@@ -319,7 +319,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
34443 .dma_sff_read_status = ide_dma_sff_read_status,
34444 };
34445
34446-static const struct ide_port_info sl82c105_chipset __devinitdata = {
34447+static const struct ide_port_info sl82c105_chipset __devinitconst = {
34448 .name = DRV_NAME,
34449 .init_chipset = init_chipset_sl82c105,
34450 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
34451diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
34452index 1ccfb40..83d5779 100644
34453--- a/drivers/ide/slc90e66.c
34454+++ b/drivers/ide/slc90e66.c
34455@@ -131,7 +131,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
34456 .cable_detect = slc90e66_cable_detect,
34457 };
34458
34459-static const struct ide_port_info slc90e66_chipset __devinitdata = {
34460+static const struct ide_port_info slc90e66_chipset __devinitconst = {
34461 .name = DRV_NAME,
34462 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
34463 .port_ops = &slc90e66_port_ops,
34464diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
34465index 05a93d6..5f9e325 100644
34466--- a/drivers/ide/tc86c001.c
34467+++ b/drivers/ide/tc86c001.c
34468@@ -190,7 +190,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
34469 .dma_sff_read_status = ide_dma_sff_read_status,
34470 };
34471
34472-static const struct ide_port_info tc86c001_chipset __devinitdata = {
34473+static const struct ide_port_info tc86c001_chipset __devinitconst = {
34474 .name = DRV_NAME,
34475 .init_hwif = init_hwif_tc86c001,
34476 .port_ops = &tc86c001_port_ops,
34477diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
34478index 8773c3b..7907d6c 100644
34479--- a/drivers/ide/triflex.c
34480+++ b/drivers/ide/triflex.c
34481@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
34482 .set_dma_mode = triflex_set_mode,
34483 };
34484
34485-static const struct ide_port_info triflex_device __devinitdata = {
34486+static const struct ide_port_info triflex_device __devinitconst = {
34487 .name = DRV_NAME,
34488 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
34489 .port_ops = &triflex_port_ops,
34490diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
34491index 4b42ca0..e494a98 100644
34492--- a/drivers/ide/trm290.c
34493+++ b/drivers/ide/trm290.c
34494@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
34495 .dma_check = trm290_dma_check,
34496 };
34497
34498-static const struct ide_port_info trm290_chipset __devinitdata = {
34499+static const struct ide_port_info trm290_chipset __devinitconst = {
34500 .name = DRV_NAME,
34501 .init_hwif = init_hwif_trm290,
34502 .tp_ops = &trm290_tp_ops,
34503diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
34504index 028de26..520d5d5 100644
34505--- a/drivers/ide/via82cxxx.c
34506+++ b/drivers/ide/via82cxxx.c
34507@@ -374,7 +374,7 @@ static const struct ide_port_ops via_port_ops = {
34508 .cable_detect = via82cxxx_cable_detect,
34509 };
34510
34511-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
34512+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
34513 .name = DRV_NAME,
34514 .init_chipset = init_chipset_via82cxxx,
34515 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
34516diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
34517index 2cd00b5..14de699 100644
34518--- a/drivers/ieee1394/dv1394.c
34519+++ b/drivers/ieee1394/dv1394.c
34520@@ -739,7 +739,7 @@ static void frame_prepare(struct video_card *video, unsigned int this_frame)
34521 based upon DIF section and sequence
34522 */
34523
34524-static void inline
34525+static inline void
34526 frame_put_packet (struct frame *f, struct packet *p)
34527 {
34528 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
34529diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
34530index e947d8f..6a966b9 100644
34531--- a/drivers/ieee1394/hosts.c
34532+++ b/drivers/ieee1394/hosts.c
34533@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command,
34534 }
34535
34536 static struct hpsb_host_driver dummy_driver = {
34537+ .name = "dummy",
34538 .transmit_packet = dummy_transmit_packet,
34539 .devctl = dummy_devctl,
34540 .isoctl = dummy_isoctl
34541diff --git a/drivers/ieee1394/init_ohci1394_dma.c b/drivers/ieee1394/init_ohci1394_dma.c
34542index ddaab6e..8d37435 100644
34543--- a/drivers/ieee1394/init_ohci1394_dma.c
34544+++ b/drivers/ieee1394/init_ohci1394_dma.c
34545@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_controllers(void)
34546 for (func = 0; func < 8; func++) {
34547 u32 class = read_pci_config(num,slot,func,
34548 PCI_CLASS_REVISION);
34549- if ((class == 0xffffffff))
34550+ if (class == 0xffffffff)
34551 continue; /* No device at this func */
34552
34553 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
34554diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
34555index 65c1429..5d8c11f 100644
34556--- a/drivers/ieee1394/ohci1394.c
34557+++ b/drivers/ieee1394/ohci1394.c
34558@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
34559 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
34560
34561 /* Module Parameters */
34562-static int phys_dma = 1;
34563+static int phys_dma;
34564 module_param(phys_dma, int, 0444);
34565-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
34566+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
34567
34568 static void dma_trm_tasklet(unsigned long data);
34569 static void dma_trm_reset(struct dma_trm_ctx *d);
34570diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
34571index f199896..78c9fc8 100644
34572--- a/drivers/ieee1394/sbp2.c
34573+++ b/drivers/ieee1394/sbp2.c
34574@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
34575 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
34576 MODULE_LICENSE("GPL");
34577
34578-static int sbp2_module_init(void)
34579+static int __init sbp2_module_init(void)
34580 {
34581 int ret;
34582
34583diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34584index a5dea6b..0cefe8f 100644
34585--- a/drivers/infiniband/core/cm.c
34586+++ b/drivers/infiniband/core/cm.c
34587@@ -112,7 +112,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34588
34589 struct cm_counter_group {
34590 struct kobject obj;
34591- atomic_long_t counter[CM_ATTR_COUNT];
34592+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34593 };
34594
34595 struct cm_counter_attribute {
34596@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34597 struct ib_mad_send_buf *msg = NULL;
34598 int ret;
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_REQ_COUNTER]);
34603
34604 /* Quick state check to discard duplicate REQs. */
34605@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34606 if (!cm_id_priv)
34607 return;
34608
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_REP_COUNTER]);
34612 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34613 if (ret)
34614@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work *work)
34615 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34616 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34617 spin_unlock_irq(&cm_id_priv->lock);
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_RTU_COUNTER]);
34621 goto out;
34622 }
34623@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_work *work)
34624 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34625 dreq_msg->local_comm_id);
34626 if (!cm_id_priv) {
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 cm_issue_drep(work->port, work->mad_recv_wc);
34631 return -EINVAL;
34632@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_work *work)
34633 case IB_CM_MRA_REP_RCVD:
34634 break;
34635 case IB_CM_TIMEWAIT:
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 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34640 goto unlock;
34641@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_work *work)
34642 cm_free_msg(msg);
34643 goto deref;
34644 case IB_CM_DREQ_RCVD:
34645- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34646+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34647 counter[CM_DREQ_COUNTER]);
34648 goto unlock;
34649 default:
34650@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work *work)
34651 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34652 cm_id_priv->msg, timeout)) {
34653 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34654- atomic_long_inc(&work->port->
34655+ atomic_long_inc_unchecked(&work->port->
34656 counter_group[CM_RECV_DUPLICATES].
34657 counter[CM_MRA_COUNTER]);
34658 goto out;
34659@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work *work)
34660 break;
34661 case IB_CM_MRA_REQ_RCVD:
34662 case IB_CM_MRA_REP_RCVD:
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_MRA_COUNTER]);
34666 /* fall through */
34667 default:
34668@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work *work)
34669 case IB_CM_LAP_IDLE:
34670 break;
34671 case IB_CM_MRA_LAP_SENT:
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 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34676 goto unlock;
34677@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work *work)
34678 cm_free_msg(msg);
34679 goto deref;
34680 case IB_CM_LAP_RCVD:
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_LAP_COUNTER]);
34684 goto unlock;
34685 default:
34686@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34687 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34688 if (cur_cm_id_priv) {
34689 spin_unlock_irq(&cm.lock);
34690- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34691+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34692 counter[CM_SIDR_REQ_COUNTER]);
34693 goto out; /* Duplicate message. */
34694 }
34695@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34696 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34697 msg->retries = 1;
34698
34699- atomic_long_add(1 + msg->retries,
34700+ atomic_long_add_unchecked(1 + msg->retries,
34701 &port->counter_group[CM_XMIT].counter[attr_index]);
34702 if (msg->retries)
34703- atomic_long_add(msg->retries,
34704+ atomic_long_add_unchecked(msg->retries,
34705 &port->counter_group[CM_XMIT_RETRIES].
34706 counter[attr_index]);
34707
34708@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34709 }
34710
34711 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34712- atomic_long_inc(&port->counter_group[CM_RECV].
34713+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34714 counter[attr_id - CM_ATTR_ID_OFFSET]);
34715
34716 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34717@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34718 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34719
34720 return sprintf(buf, "%ld\n",
34721- atomic_long_read(&group->counter[cm_attr->index]));
34722+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34723 }
34724
34725-static struct sysfs_ops cm_counter_ops = {
34726+static const struct sysfs_ops cm_counter_ops = {
34727 .show = cm_show_counter
34728 };
34729
34730diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34731index 4507043..14ad522 100644
34732--- a/drivers/infiniband/core/fmr_pool.c
34733+++ b/drivers/infiniband/core/fmr_pool.c
34734@@ -97,8 +97,8 @@ struct ib_fmr_pool {
34735
34736 struct task_struct *thread;
34737
34738- atomic_t req_ser;
34739- atomic_t flush_ser;
34740+ atomic_unchecked_t req_ser;
34741+ atomic_unchecked_t flush_ser;
34742
34743 wait_queue_head_t force_wait;
34744 };
34745@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34746 struct ib_fmr_pool *pool = pool_ptr;
34747
34748 do {
34749- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34750+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34751 ib_fmr_batch_release(pool);
34752
34753- atomic_inc(&pool->flush_ser);
34754+ atomic_inc_unchecked(&pool->flush_ser);
34755 wake_up_interruptible(&pool->force_wait);
34756
34757 if (pool->flush_function)
34758@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34759 }
34760
34761 set_current_state(TASK_INTERRUPTIBLE);
34762- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34763+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34764 !kthread_should_stop())
34765 schedule();
34766 __set_current_state(TASK_RUNNING);
34767@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34768 pool->dirty_watermark = params->dirty_watermark;
34769 pool->dirty_len = 0;
34770 spin_lock_init(&pool->pool_lock);
34771- atomic_set(&pool->req_ser, 0);
34772- atomic_set(&pool->flush_ser, 0);
34773+ atomic_set_unchecked(&pool->req_ser, 0);
34774+ atomic_set_unchecked(&pool->flush_ser, 0);
34775 init_waitqueue_head(&pool->force_wait);
34776
34777 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34778@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34779 }
34780 spin_unlock_irq(&pool->pool_lock);
34781
34782- serial = atomic_inc_return(&pool->req_ser);
34783+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34784 wake_up_process(pool->thread);
34785
34786 if (wait_event_interruptible(pool->force_wait,
34787- atomic_read(&pool->flush_ser) - serial >= 0))
34788+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34789 return -EINTR;
34790
34791 return 0;
34792@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34793 } else {
34794 list_add_tail(&fmr->list, &pool->dirty_list);
34795 if (++pool->dirty_len >= pool->dirty_watermark) {
34796- atomic_inc(&pool->req_ser);
34797+ atomic_inc_unchecked(&pool->req_ser);
34798 wake_up_process(pool->thread);
34799 }
34800 }
34801diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
34802index 158a214..1558bb7 100644
34803--- a/drivers/infiniband/core/sysfs.c
34804+++ b/drivers/infiniband/core/sysfs.c
34805@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kobject *kobj,
34806 return port_attr->show(p, port_attr, buf);
34807 }
34808
34809-static struct sysfs_ops port_sysfs_ops = {
34810+static const struct sysfs_ops port_sysfs_ops = {
34811 .show = port_attr_show
34812 };
34813
34814diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
34815index 5440da0..1194ecb 100644
34816--- a/drivers/infiniband/core/uverbs_marshall.c
34817+++ b/drivers/infiniband/core/uverbs_marshall.c
34818@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
34819 dst->grh.sgid_index = src->grh.sgid_index;
34820 dst->grh.hop_limit = src->grh.hop_limit;
34821 dst->grh.traffic_class = src->grh.traffic_class;
34822+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
34823 dst->dlid = src->dlid;
34824 dst->sl = src->sl;
34825 dst->src_path_bits = src->src_path_bits;
34826 dst->static_rate = src->static_rate;
34827 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
34828 dst->port_num = src->port_num;
34829+ dst->reserved = 0;
34830 }
34831 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
34832
34833 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34834 struct ib_qp_attr *src)
34835 {
34836+ dst->qp_state = src->qp_state;
34837 dst->cur_qp_state = src->cur_qp_state;
34838 dst->path_mtu = src->path_mtu;
34839 dst->path_mig_state = src->path_mig_state;
34840@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34841 dst->rnr_retry = src->rnr_retry;
34842 dst->alt_port_num = src->alt_port_num;
34843 dst->alt_timeout = src->alt_timeout;
34844+ memset(dst->reserved, 0, sizeof(dst->reserved));
34845 }
34846 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
34847
34848diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
34849index 100da85..62e6b88 100644
34850--- a/drivers/infiniband/hw/ipath/ipath_fs.c
34851+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
34852@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
34853 struct infinipath_counters counters;
34854 struct ipath_devdata *dd;
34855
34856+ pax_track_stack();
34857+
34858 dd = file->f_path.dentry->d_inode->i_private;
34859 dd->ipath_f_read_counters(dd, &counters);
34860
34861diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34862index cbde0cf..afaf55c 100644
34863--- a/drivers/infiniband/hw/nes/nes.c
34864+++ b/drivers/infiniband/hw/nes/nes.c
34865@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34866 LIST_HEAD(nes_adapter_list);
34867 static LIST_HEAD(nes_dev_list);
34868
34869-atomic_t qps_destroyed;
34870+atomic_unchecked_t qps_destroyed;
34871
34872 static unsigned int ee_flsh_adapter;
34873 static unsigned int sysfs_nonidx_addr;
34874@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34875 struct nes_adapter *nesadapter = nesdev->nesadapter;
34876 u32 qp_id;
34877
34878- atomic_inc(&qps_destroyed);
34879+ atomic_inc_unchecked(&qps_destroyed);
34880
34881 /* Free the control structures */
34882
34883diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34884index bcc6abc..9c76b2f 100644
34885--- a/drivers/infiniband/hw/nes/nes.h
34886+++ b/drivers/infiniband/hw/nes/nes.h
34887@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
34888 extern unsigned int wqm_quanta;
34889 extern struct list_head nes_adapter_list;
34890
34891-extern atomic_t cm_connects;
34892-extern atomic_t cm_accepts;
34893-extern atomic_t cm_disconnects;
34894-extern atomic_t cm_closes;
34895-extern atomic_t cm_connecteds;
34896-extern atomic_t cm_connect_reqs;
34897-extern atomic_t cm_rejects;
34898-extern atomic_t mod_qp_timouts;
34899-extern atomic_t qps_created;
34900-extern atomic_t qps_destroyed;
34901-extern atomic_t sw_qps_destroyed;
34902+extern atomic_unchecked_t cm_connects;
34903+extern atomic_unchecked_t cm_accepts;
34904+extern atomic_unchecked_t cm_disconnects;
34905+extern atomic_unchecked_t cm_closes;
34906+extern atomic_unchecked_t cm_connecteds;
34907+extern atomic_unchecked_t cm_connect_reqs;
34908+extern atomic_unchecked_t cm_rejects;
34909+extern atomic_unchecked_t mod_qp_timouts;
34910+extern atomic_unchecked_t qps_created;
34911+extern atomic_unchecked_t qps_destroyed;
34912+extern atomic_unchecked_t sw_qps_destroyed;
34913 extern u32 mh_detected;
34914 extern u32 mh_pauses_sent;
34915 extern u32 cm_packets_sent;
34916@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
34917 extern u32 cm_listens_created;
34918 extern u32 cm_listens_destroyed;
34919 extern u32 cm_backlog_drops;
34920-extern atomic_t cm_loopbacks;
34921-extern atomic_t cm_nodes_created;
34922-extern atomic_t cm_nodes_destroyed;
34923-extern atomic_t cm_accel_dropped_pkts;
34924-extern atomic_t cm_resets_recvd;
34925+extern atomic_unchecked_t cm_loopbacks;
34926+extern atomic_unchecked_t cm_nodes_created;
34927+extern atomic_unchecked_t cm_nodes_destroyed;
34928+extern atomic_unchecked_t cm_accel_dropped_pkts;
34929+extern atomic_unchecked_t cm_resets_recvd;
34930
34931 extern u32 int_mod_timer_init;
34932 extern u32 int_mod_cq_depth_256;
34933diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34934index 73473db..5ed06e8 100644
34935--- a/drivers/infiniband/hw/nes/nes_cm.c
34936+++ b/drivers/infiniband/hw/nes/nes_cm.c
34937@@ -69,11 +69,11 @@ u32 cm_packets_received;
34938 u32 cm_listens_created;
34939 u32 cm_listens_destroyed;
34940 u32 cm_backlog_drops;
34941-atomic_t cm_loopbacks;
34942-atomic_t cm_nodes_created;
34943-atomic_t cm_nodes_destroyed;
34944-atomic_t cm_accel_dropped_pkts;
34945-atomic_t cm_resets_recvd;
34946+atomic_unchecked_t cm_loopbacks;
34947+atomic_unchecked_t cm_nodes_created;
34948+atomic_unchecked_t cm_nodes_destroyed;
34949+atomic_unchecked_t cm_accel_dropped_pkts;
34950+atomic_unchecked_t cm_resets_recvd;
34951
34952 static inline int mini_cm_accelerated(struct nes_cm_core *,
34953 struct nes_cm_node *);
34954@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
34955
34956 static struct nes_cm_core *g_cm_core;
34957
34958-atomic_t cm_connects;
34959-atomic_t cm_accepts;
34960-atomic_t cm_disconnects;
34961-atomic_t cm_closes;
34962-atomic_t cm_connecteds;
34963-atomic_t cm_connect_reqs;
34964-atomic_t cm_rejects;
34965+atomic_unchecked_t cm_connects;
34966+atomic_unchecked_t cm_accepts;
34967+atomic_unchecked_t cm_disconnects;
34968+atomic_unchecked_t cm_closes;
34969+atomic_unchecked_t cm_connecteds;
34970+atomic_unchecked_t cm_connect_reqs;
34971+atomic_unchecked_t cm_rejects;
34972
34973
34974 /**
34975@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34976 cm_node->rem_mac);
34977
34978 add_hte_node(cm_core, cm_node);
34979- atomic_inc(&cm_nodes_created);
34980+ atomic_inc_unchecked(&cm_nodes_created);
34981
34982 return cm_node;
34983 }
34984@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34985 }
34986
34987 atomic_dec(&cm_core->node_cnt);
34988- atomic_inc(&cm_nodes_destroyed);
34989+ atomic_inc_unchecked(&cm_nodes_destroyed);
34990 nesqp = cm_node->nesqp;
34991 if (nesqp) {
34992 nesqp->cm_node = NULL;
34993@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34994
34995 static void drop_packet(struct sk_buff *skb)
34996 {
34997- atomic_inc(&cm_accel_dropped_pkts);
34998+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
34999 dev_kfree_skb_any(skb);
35000 }
35001
35002@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35003
35004 int reset = 0; /* whether to send reset in case of err.. */
35005 int passive_state;
35006- atomic_inc(&cm_resets_recvd);
35007+ atomic_inc_unchecked(&cm_resets_recvd);
35008 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35009 " refcnt=%d\n", cm_node, cm_node->state,
35010 atomic_read(&cm_node->ref_count));
35011@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35012 rem_ref_cm_node(cm_node->cm_core, cm_node);
35013 return NULL;
35014 }
35015- atomic_inc(&cm_loopbacks);
35016+ atomic_inc_unchecked(&cm_loopbacks);
35017 loopbackremotenode->loopbackpartner = cm_node;
35018 loopbackremotenode->tcp_cntxt.rcv_wscale =
35019 NES_CM_DEFAULT_RCV_WND_SCALE;
35020@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35021 add_ref_cm_node(cm_node);
35022 } else if (cm_node->state == NES_CM_STATE_TSA) {
35023 rem_ref_cm_node(cm_core, cm_node);
35024- atomic_inc(&cm_accel_dropped_pkts);
35025+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35026 dev_kfree_skb_any(skb);
35027 break;
35028 }
35029@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35030
35031 if ((cm_id) && (cm_id->event_handler)) {
35032 if (issue_disconn) {
35033- atomic_inc(&cm_disconnects);
35034+ atomic_inc_unchecked(&cm_disconnects);
35035 cm_event.event = IW_CM_EVENT_DISCONNECT;
35036 cm_event.status = disconn_status;
35037 cm_event.local_addr = cm_id->local_addr;
35038@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35039 }
35040
35041 if (issue_close) {
35042- atomic_inc(&cm_closes);
35043+ atomic_inc_unchecked(&cm_closes);
35044 nes_disconnect(nesqp, 1);
35045
35046 cm_id->provider_data = nesqp;
35047@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35048
35049 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35050 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35051- atomic_inc(&cm_accepts);
35052+ atomic_inc_unchecked(&cm_accepts);
35053
35054 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35055 atomic_read(&nesvnic->netdev->refcnt));
35056@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35057
35058 struct nes_cm_core *cm_core;
35059
35060- atomic_inc(&cm_rejects);
35061+ atomic_inc_unchecked(&cm_rejects);
35062 cm_node = (struct nes_cm_node *) cm_id->provider_data;
35063 loopback = cm_node->loopbackpartner;
35064 cm_core = cm_node->cm_core;
35065@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35066 ntohl(cm_id->local_addr.sin_addr.s_addr),
35067 ntohs(cm_id->local_addr.sin_port));
35068
35069- atomic_inc(&cm_connects);
35070+ atomic_inc_unchecked(&cm_connects);
35071 nesqp->active_conn = 1;
35072
35073 /* cache the cm_id in the qp */
35074@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35075 if (nesqp->destroyed) {
35076 return;
35077 }
35078- atomic_inc(&cm_connecteds);
35079+ atomic_inc_unchecked(&cm_connecteds);
35080 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35081 " local port 0x%04X. jiffies = %lu.\n",
35082 nesqp->hwqp.qp_id,
35083@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35084
35085 ret = cm_id->event_handler(cm_id, &cm_event);
35086 cm_id->add_ref(cm_id);
35087- atomic_inc(&cm_closes);
35088+ atomic_inc_unchecked(&cm_closes);
35089 cm_event.event = IW_CM_EVENT_CLOSE;
35090 cm_event.status = IW_CM_EVENT_STATUS_OK;
35091 cm_event.provider_data = cm_id->provider_data;
35092@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(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@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35102 return;
35103 cm_id = cm_node->cm_id;
35104
35105- atomic_inc(&cm_connect_reqs);
35106+ atomic_inc_unchecked(&cm_connect_reqs);
35107 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35108 cm_node, cm_id, jiffies);
35109
35110diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35111index e593af3..870694a 100644
35112--- a/drivers/infiniband/hw/nes/nes_nic.c
35113+++ b/drivers/infiniband/hw/nes/nes_nic.c
35114@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35115 target_stat_values[++index] = mh_detected;
35116 target_stat_values[++index] = mh_pauses_sent;
35117 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35118- target_stat_values[++index] = atomic_read(&cm_connects);
35119- target_stat_values[++index] = atomic_read(&cm_accepts);
35120- target_stat_values[++index] = atomic_read(&cm_disconnects);
35121- target_stat_values[++index] = atomic_read(&cm_connecteds);
35122- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35123- target_stat_values[++index] = atomic_read(&cm_rejects);
35124- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35125- target_stat_values[++index] = atomic_read(&qps_created);
35126- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35127- target_stat_values[++index] = atomic_read(&qps_destroyed);
35128- target_stat_values[++index] = atomic_read(&cm_closes);
35129+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35130+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35131+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35132+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35133+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35134+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35135+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35136+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35137+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35138+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35139+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35140 target_stat_values[++index] = cm_packets_sent;
35141 target_stat_values[++index] = cm_packets_bounced;
35142 target_stat_values[++index] = cm_packets_created;
35143@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35144 target_stat_values[++index] = cm_listens_created;
35145 target_stat_values[++index] = cm_listens_destroyed;
35146 target_stat_values[++index] = cm_backlog_drops;
35147- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35148- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35149- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35150- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35151- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35152+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35153+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35154+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35155+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35156+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35157 target_stat_values[++index] = int_mod_timer_init;
35158 target_stat_values[++index] = int_mod_cq_depth_1;
35159 target_stat_values[++index] = int_mod_cq_depth_4;
35160diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35161index a680c42..f914deb 100644
35162--- a/drivers/infiniband/hw/nes/nes_verbs.c
35163+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35164@@ -45,9 +45,9 @@
35165
35166 #include <rdma/ib_umem.h>
35167
35168-atomic_t mod_qp_timouts;
35169-atomic_t qps_created;
35170-atomic_t sw_qps_destroyed;
35171+atomic_unchecked_t mod_qp_timouts;
35172+atomic_unchecked_t qps_created;
35173+atomic_unchecked_t sw_qps_destroyed;
35174
35175 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35176
35177@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35178 if (init_attr->create_flags)
35179 return ERR_PTR(-EINVAL);
35180
35181- atomic_inc(&qps_created);
35182+ atomic_inc_unchecked(&qps_created);
35183 switch (init_attr->qp_type) {
35184 case IB_QPT_RC:
35185 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35186@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35187 struct iw_cm_event cm_event;
35188 int ret;
35189
35190- atomic_inc(&sw_qps_destroyed);
35191+ atomic_inc_unchecked(&sw_qps_destroyed);
35192 nesqp->destroyed = 1;
35193
35194 /* Blow away the connection if it exists. */
35195diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35196index ac11be0..3883c04 100644
35197--- a/drivers/input/gameport/gameport.c
35198+++ b/drivers/input/gameport/gameport.c
35199@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
35200 */
35201 static void gameport_init_port(struct gameport *gameport)
35202 {
35203- static atomic_t gameport_no = ATOMIC_INIT(0);
35204+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35205
35206 __module_get(THIS_MODULE);
35207
35208 mutex_init(&gameport->drv_mutex);
35209 device_initialize(&gameport->dev);
35210- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
35211+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35212 gameport->dev.bus = &gameport_bus;
35213 gameport->dev.release = gameport_release_port;
35214 if (gameport->parent)
35215diff --git a/drivers/input/input.c b/drivers/input/input.c
35216index c82ae82..8cfb9cb 100644
35217--- a/drivers/input/input.c
35218+++ b/drivers/input/input.c
35219@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
35220 */
35221 int input_register_device(struct input_dev *dev)
35222 {
35223- static atomic_t input_no = ATOMIC_INIT(0);
35224+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35225 struct input_handler *handler;
35226 const char *path;
35227 int error;
35228@@ -1585,7 +1585,7 @@ int input_register_device(struct input_dev *dev)
35229 dev->setkeycode = input_default_setkeycode;
35230
35231 dev_set_name(&dev->dev, "input%ld",
35232- (unsigned long) atomic_inc_return(&input_no) - 1);
35233+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35234
35235 error = device_add(&dev->dev);
35236 if (error)
35237diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35238index ca13a6b..b032b0c 100644
35239--- a/drivers/input/joystick/sidewinder.c
35240+++ b/drivers/input/joystick/sidewinder.c
35241@@ -30,6 +30,7 @@
35242 #include <linux/kernel.h>
35243 #include <linux/module.h>
35244 #include <linux/slab.h>
35245+#include <linux/sched.h>
35246 #include <linux/init.h>
35247 #include <linux/input.h>
35248 #include <linux/gameport.h>
35249@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
35250 unsigned char buf[SW_LENGTH];
35251 int i;
35252
35253+ pax_track_stack();
35254+
35255 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
35256
35257 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
35258diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35259index 79e3edc..01412b9 100644
35260--- a/drivers/input/joystick/xpad.c
35261+++ b/drivers/input/joystick/xpad.c
35262@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35263
35264 static int xpad_led_probe(struct usb_xpad *xpad)
35265 {
35266- static atomic_t led_seq = ATOMIC_INIT(0);
35267+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35268 long led_no;
35269 struct xpad_led *led;
35270 struct led_classdev *led_cdev;
35271@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35272 if (!led)
35273 return -ENOMEM;
35274
35275- led_no = (long)atomic_inc_return(&led_seq) - 1;
35276+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35277
35278 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35279 led->xpad = xpad;
35280diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35281index 0236f0d..c7327f1 100644
35282--- a/drivers/input/serio/serio.c
35283+++ b/drivers/input/serio/serio.c
35284@@ -527,7 +527,7 @@ static void serio_release_port(struct device *dev)
35285 */
35286 static void serio_init_port(struct serio *serio)
35287 {
35288- static atomic_t serio_no = ATOMIC_INIT(0);
35289+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35290
35291 __module_get(THIS_MODULE);
35292
35293@@ -536,7 +536,7 @@ static void serio_init_port(struct serio *serio)
35294 mutex_init(&serio->drv_mutex);
35295 device_initialize(&serio->dev);
35296 dev_set_name(&serio->dev, "serio%ld",
35297- (long)atomic_inc_return(&serio_no) - 1);
35298+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35299 serio->dev.bus = &serio_bus;
35300 serio->dev.release = serio_release_port;
35301 if (serio->parent) {
35302diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
35303index 33dcd8d..2783d25 100644
35304--- a/drivers/isdn/gigaset/common.c
35305+++ b/drivers/isdn/gigaset/common.c
35306@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
35307 cs->commands_pending = 0;
35308 cs->cur_at_seq = 0;
35309 cs->gotfwver = -1;
35310- cs->open_count = 0;
35311+ local_set(&cs->open_count, 0);
35312 cs->dev = NULL;
35313 cs->tty = NULL;
35314 cs->tty_dev = NULL;
35315diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
35316index a2f6125..6a70677 100644
35317--- a/drivers/isdn/gigaset/gigaset.h
35318+++ b/drivers/isdn/gigaset/gigaset.h
35319@@ -34,6 +34,7 @@
35320 #include <linux/tty_driver.h>
35321 #include <linux/list.h>
35322 #include <asm/atomic.h>
35323+#include <asm/local.h>
35324
35325 #define GIG_VERSION {0,5,0,0}
35326 #define GIG_COMPAT {0,4,0,0}
35327@@ -446,7 +447,7 @@ struct cardstate {
35328 spinlock_t cmdlock;
35329 unsigned curlen, cmdbytes;
35330
35331- unsigned open_count;
35332+ local_t open_count;
35333 struct tty_struct *tty;
35334 struct tasklet_struct if_wake_tasklet;
35335 unsigned control_state;
35336diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35337index b3065b8..c7e8cc9 100644
35338--- a/drivers/isdn/gigaset/interface.c
35339+++ b/drivers/isdn/gigaset/interface.c
35340@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35341 return -ERESTARTSYS; // FIXME -EINTR?
35342 tty->driver_data = cs;
35343
35344- ++cs->open_count;
35345-
35346- if (cs->open_count == 1) {
35347+ if (local_inc_return(&cs->open_count) == 1) {
35348 spin_lock_irqsave(&cs->lock, flags);
35349 cs->tty = tty;
35350 spin_unlock_irqrestore(&cs->lock, flags);
35351@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35352
35353 if (!cs->connected)
35354 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35355- else if (!cs->open_count)
35356+ else if (!local_read(&cs->open_count))
35357 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35358 else {
35359- if (!--cs->open_count) {
35360+ if (!local_dec_return(&cs->open_count)) {
35361 spin_lock_irqsave(&cs->lock, flags);
35362 cs->tty = NULL;
35363 spin_unlock_irqrestore(&cs->lock, flags);
35364@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
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 {
35372 retval = 0;
35373@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
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@@ -395,7 +393,7 @@ static int if_write_room(struct tty_struct *tty)
35383 if (!cs->connected) {
35384 gig_dbg(DEBUG_IF, "not connected");
35385 retval = -ENODEV;
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@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
35392
35393 if (!cs->connected)
35394 gig_dbg(DEBUG_IF, "not connected");
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 if (cs->mstate != MS_LOCKED)
35399 dev_warn(cs->dev, "can't write to unlocked device\n");
35400@@ -453,7 +451,7 @@ static void if_throttle(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@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_struct *tty)
35410
35411 if (!cs->connected)
35412 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35413- else if (!cs->open_count)
35414+ else if (!local_read(&cs->open_count))
35415 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35416 else {
35417 //FIXME
35418@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
35419 goto out;
35420 }
35421
35422- if (!cs->open_count) {
35423+ if (!local_read(&cs->open_count)) {
35424 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35425 goto out;
35426 }
35427diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35428index a7c0083..62a7cb6 100644
35429--- a/drivers/isdn/hardware/avm/b1.c
35430+++ b/drivers/isdn/hardware/avm/b1.c
35431@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
35432 }
35433 if (left) {
35434 if (t4file->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@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
35441 }
35442 if (left) {
35443 if (config->user) {
35444- if (copy_from_user(buf, dp, left))
35445+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35446 return -EFAULT;
35447 } else {
35448 memcpy(buf, dp, left);
35449diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
35450index f130724..c373c68 100644
35451--- a/drivers/isdn/hardware/eicon/capidtmf.c
35452+++ b/drivers/isdn/hardware/eicon/capidtmf.c
35453@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
35454 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
35455 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
35456
35457+ pax_track_stack();
35458
35459 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
35460 {
35461diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
35462index 4d425c6..a9be6c4 100644
35463--- a/drivers/isdn/hardware/eicon/capifunc.c
35464+++ b/drivers/isdn/hardware/eicon/capifunc.c
35465@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
35466 IDI_SYNC_REQ req;
35467 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35468
35469+ pax_track_stack();
35470+
35471 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35472
35473 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35474diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
35475index 3029234..ef0d9e2 100644
35476--- a/drivers/isdn/hardware/eicon/diddfunc.c
35477+++ b/drivers/isdn/hardware/eicon/diddfunc.c
35478@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35479 IDI_SYNC_REQ req;
35480 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35481
35482+ pax_track_stack();
35483+
35484 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35485
35486 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35487diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
35488index d36a4c0..11e7d1a 100644
35489--- a/drivers/isdn/hardware/eicon/divasfunc.c
35490+++ b/drivers/isdn/hardware/eicon/divasfunc.c
35491@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35492 IDI_SYNC_REQ req;
35493 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35494
35495+ pax_track_stack();
35496+
35497 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35498
35499 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35500diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
35501index 85784a7..a19ca98 100644
35502--- a/drivers/isdn/hardware/eicon/divasync.h
35503+++ b/drivers/isdn/hardware/eicon/divasync.h
35504@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
35505 } diva_didd_add_adapter_t;
35506 typedef struct _diva_didd_remove_adapter {
35507 IDI_CALL p_request;
35508-} diva_didd_remove_adapter_t;
35509+} __no_const diva_didd_remove_adapter_t;
35510 typedef struct _diva_didd_read_adapter_array {
35511 void * buffer;
35512 dword length;
35513diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
35514index db87d51..7d09acf 100644
35515--- a/drivers/isdn/hardware/eicon/idifunc.c
35516+++ b/drivers/isdn/hardware/eicon/idifunc.c
35517@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35518 IDI_SYNC_REQ req;
35519 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35520
35521+ pax_track_stack();
35522+
35523 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35524
35525 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35526diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
35527index ae89fb8..0fab299 100644
35528--- a/drivers/isdn/hardware/eicon/message.c
35529+++ b/drivers/isdn/hardware/eicon/message.c
35530@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
35531 dword d;
35532 word w;
35533
35534+ pax_track_stack();
35535+
35536 a = plci->adapter;
35537 Id = ((word)plci->Id<<8)|a->Id;
35538 PUT_WORD(&SS_Ind[4],0x0000);
35539@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
35540 word j, n, w;
35541 dword d;
35542
35543+ pax_track_stack();
35544+
35545
35546 for(i=0;i<8;i++) bp_parms[i].length = 0;
35547 for(i=0;i<2;i++) global_config[i].length = 0;
35548@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
35549 const byte llc3[] = {4,3,2,2,6,6,0};
35550 const byte header[] = {0,2,3,3,0,0,0};
35551
35552+ pax_track_stack();
35553+
35554 for(i=0;i<8;i++) bp_parms[i].length = 0;
35555 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
35556 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
35557@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
35558 word appl_number_group_type[MAX_APPL];
35559 PLCI *auxplci;
35560
35561+ pax_track_stack();
35562+
35563 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
35564
35565 if(!a->group_optimization_enabled)
35566diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
35567index a564b75..f3cf8b5 100644
35568--- a/drivers/isdn/hardware/eicon/mntfunc.c
35569+++ b/drivers/isdn/hardware/eicon/mntfunc.c
35570@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35571 IDI_SYNC_REQ req;
35572 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35573
35574+ pax_track_stack();
35575+
35576 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35577
35578 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35579diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
35580index a3bd163..8956575 100644
35581--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
35582+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
35583@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
35584 typedef struct _diva_os_idi_adapter_interface {
35585 diva_init_card_proc_t cleanup_adapter_proc;
35586 diva_cmd_card_proc_t cmd_proc;
35587-} diva_os_idi_adapter_interface_t;
35588+} __no_const diva_os_idi_adapter_interface_t;
35589
35590 typedef struct _diva_os_xdi_adapter {
35591 struct list_head link;
35592diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
35593index adb1e8c..21b590b 100644
35594--- a/drivers/isdn/i4l/isdn_common.c
35595+++ b/drivers/isdn/i4l/isdn_common.c
35596@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
35597 } iocpar;
35598 void __user *argp = (void __user *)arg;
35599
35600+ pax_track_stack();
35601+
35602 #define name iocpar.name
35603 #define bname iocpar.bname
35604 #define iocts iocpar.iocts
35605diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35606index bf7997a..cf091db 100644
35607--- a/drivers/isdn/icn/icn.c
35608+++ b/drivers/isdn/icn/icn.c
35609@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
35610 if (count > len)
35611 count = len;
35612 if (user) {
35613- if (copy_from_user(msg, buf, count))
35614+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35615 return -EFAULT;
35616 } else
35617 memcpy(msg, buf, count);
35618diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
35619index feb0fa4..f76f830 100644
35620--- a/drivers/isdn/mISDN/socket.c
35621+++ b/drivers/isdn/mISDN/socket.c
35622@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35623 if (dev) {
35624 struct mISDN_devinfo di;
35625
35626+ memset(&di, 0, sizeof(di));
35627 di.id = dev->id;
35628 di.Dprotocols = dev->Dprotocols;
35629 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35630@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35631 if (dev) {
35632 struct mISDN_devinfo di;
35633
35634+ memset(&di, 0, sizeof(di));
35635 di.id = dev->id;
35636 di.Dprotocols = dev->Dprotocols;
35637 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35638diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
35639index 485be8b..f0225bc 100644
35640--- a/drivers/isdn/sc/interrupt.c
35641+++ b/drivers/isdn/sc/interrupt.c
35642@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35643 }
35644 else if(callid>=0x0000 && callid<=0x7FFF)
35645 {
35646+ int len;
35647+
35648 pr_debug("%s: Got Incoming Call\n",
35649 sc_adapter[card]->devicename);
35650- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
35651- strcpy(setup.eazmsn,
35652- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
35653+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
35654+ sizeof(setup.phone));
35655+ if (len >= sizeof(setup.phone))
35656+ continue;
35657+ len = strlcpy(setup.eazmsn,
35658+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35659+ sizeof(setup.eazmsn));
35660+ if (len >= sizeof(setup.eazmsn))
35661+ continue;
35662 setup.si1 = 7;
35663 setup.si2 = 0;
35664 setup.plan = 0;
35665@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35666 * Handle a GetMyNumber Rsp
35667 */
35668 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
35669- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
35670+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35671+ rcvmsg.msg_data.byte_array,
35672+ sizeof(rcvmsg.msg_data.byte_array));
35673 continue;
35674 }
35675
35676diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35677index 8744d24..d1f9a9a 100644
35678--- a/drivers/lguest/core.c
35679+++ b/drivers/lguest/core.c
35680@@ -91,9 +91,17 @@ static __init int map_switcher(void)
35681 * it's worked so far. The end address needs +1 because __get_vm_area
35682 * allocates an extra guard page, so we need space for that.
35683 */
35684+
35685+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35686+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35687+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35688+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35689+#else
35690 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35691 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35692 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35693+#endif
35694+
35695 if (!switcher_vma) {
35696 err = -ENOMEM;
35697 printk("lguest: could not map switcher pages high\n");
35698@@ -118,7 +126,7 @@ static __init int map_switcher(void)
35699 * Now the Switcher is mapped at the right address, we can't fail!
35700 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
35701 */
35702- memcpy(switcher_vma->addr, start_switcher_text,
35703+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35704 end_switcher_text - start_switcher_text);
35705
35706 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35707diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35708index 6ae3888..8b38145 100644
35709--- a/drivers/lguest/x86/core.c
35710+++ b/drivers/lguest/x86/core.c
35711@@ -59,7 +59,7 @@ static struct {
35712 /* Offset from where switcher.S was compiled to where we've copied it */
35713 static unsigned long switcher_offset(void)
35714 {
35715- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35716+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35717 }
35718
35719 /* This cpu's struct lguest_pages. */
35720@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35721 * These copies are pretty cheap, so we do them unconditionally: */
35722 /* Save the current Host top-level page directory.
35723 */
35724+
35725+#ifdef CONFIG_PAX_PER_CPU_PGD
35726+ pages->state.host_cr3 = read_cr3();
35727+#else
35728 pages->state.host_cr3 = __pa(current->mm->pgd);
35729+#endif
35730+
35731 /*
35732 * Set up the Guest's page tables to see this CPU's pages (and no
35733 * other CPU's pages).
35734@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
35735 * compiled-in switcher code and the high-mapped copy we just made.
35736 */
35737 for (i = 0; i < IDT_ENTRIES; i++)
35738- default_idt_entries[i] += switcher_offset();
35739+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35740
35741 /*
35742 * Set up the Switcher's per-cpu areas.
35743@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
35744 * it will be undisturbed when we switch. To change %cs and jump we
35745 * need this structure to feed to Intel's "lcall" instruction.
35746 */
35747- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35748+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35749 lguest_entry.segment = LGUEST_CS;
35750
35751 /*
35752diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35753index 40634b0..4f5855e 100644
35754--- a/drivers/lguest/x86/switcher_32.S
35755+++ b/drivers/lguest/x86/switcher_32.S
35756@@ -87,6 +87,7 @@
35757 #include <asm/page.h>
35758 #include <asm/segment.h>
35759 #include <asm/lguest.h>
35760+#include <asm/processor-flags.h>
35761
35762 // We mark the start of the code to copy
35763 // It's placed in .text tho it's never run here
35764@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35765 // Changes type when we load it: damn Intel!
35766 // For after we switch over our page tables
35767 // That entry will be read-only: we'd crash.
35768+
35769+#ifdef CONFIG_PAX_KERNEXEC
35770+ mov %cr0, %edx
35771+ xor $X86_CR0_WP, %edx
35772+ mov %edx, %cr0
35773+#endif
35774+
35775 movl $(GDT_ENTRY_TSS*8), %edx
35776 ltr %dx
35777
35778@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35779 // Let's clear it again for our return.
35780 // The GDT descriptor of the Host
35781 // Points to the table after two "size" bytes
35782- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35783+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35784 // Clear "used" from type field (byte 5, bit 2)
35785- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35786+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35787+
35788+#ifdef CONFIG_PAX_KERNEXEC
35789+ mov %cr0, %eax
35790+ xor $X86_CR0_WP, %eax
35791+ mov %eax, %cr0
35792+#endif
35793
35794 // Once our page table's switched, the Guest is live!
35795 // The Host fades as we run this final step.
35796@@ -295,13 +309,12 @@ deliver_to_host:
35797 // I consulted gcc, and it gave
35798 // These instructions, which I gladly credit:
35799 leal (%edx,%ebx,8), %eax
35800- movzwl (%eax),%edx
35801- movl 4(%eax), %eax
35802- xorw %ax, %ax
35803- orl %eax, %edx
35804+ movl 4(%eax), %edx
35805+ movw (%eax), %dx
35806 // Now the address of the handler's in %edx
35807 // We call it now: its "iret" drops us home.
35808- jmp *%edx
35809+ ljmp $__KERNEL_CS, $1f
35810+1: jmp *%edx
35811
35812 // Every interrupt can come to us here
35813 // But we must truly tell each apart.
35814diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
35815index 588a5b0..b71db89 100644
35816--- a/drivers/macintosh/macio_asic.c
35817+++ b/drivers/macintosh/macio_asic.c
35818@@ -701,7 +701,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
35819 * MacIO is matched against any Apple ID, it's probe() function
35820 * will then decide wether it applies or not
35821 */
35822-static const struct pci_device_id __devinitdata pci_ids [] = { {
35823+static const struct pci_device_id __devinitconst pci_ids [] = { {
35824 .vendor = PCI_VENDOR_ID_APPLE,
35825 .device = PCI_ANY_ID,
35826 .subvendor = PCI_ANY_ID,
35827diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
35828index a348bb0..ecd9b3f 100644
35829--- a/drivers/macintosh/via-pmu-backlight.c
35830+++ b/drivers/macintosh/via-pmu-backlight.c
35831@@ -15,7 +15,7 @@
35832
35833 #define MAX_PMU_LEVEL 0xFF
35834
35835-static struct backlight_ops pmu_backlight_data;
35836+static const struct backlight_ops pmu_backlight_data;
35837 static DEFINE_SPINLOCK(pmu_backlight_lock);
35838 static int sleeping, uses_pmu_bl;
35839 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
35840@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(struct backlight_device *bd)
35841 return bd->props.brightness;
35842 }
35843
35844-static struct backlight_ops pmu_backlight_data = {
35845+static const struct backlight_ops pmu_backlight_data = {
35846 .get_brightness = pmu_backlight_get_brightness,
35847 .update_status = pmu_backlight_update_status,
35848
35849diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
35850index 6f308a4..b5f7ff7 100644
35851--- a/drivers/macintosh/via-pmu.c
35852+++ b/drivers/macintosh/via-pmu.c
35853@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state_t state)
35854 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
35855 }
35856
35857-static struct platform_suspend_ops pmu_pm_ops = {
35858+static const struct platform_suspend_ops pmu_pm_ops = {
35859 .enter = powerbook_sleep,
35860 .valid = pmu_sleep_valid,
35861 };
35862diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35863index 818b617..4656e38 100644
35864--- a/drivers/md/dm-ioctl.c
35865+++ b/drivers/md/dm-ioctl.c
35866@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35867 cmd == DM_LIST_VERSIONS_CMD)
35868 return 0;
35869
35870- if ((cmd == DM_DEV_CREATE_CMD)) {
35871+ if (cmd == DM_DEV_CREATE_CMD) {
35872 if (!*param->name) {
35873 DMWARN("name not supplied when creating device");
35874 return -EINVAL;
35875diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35876index 6021d0a..a878643 100644
35877--- a/drivers/md/dm-raid1.c
35878+++ b/drivers/md/dm-raid1.c
35879@@ -41,7 +41,7 @@ enum dm_raid1_error {
35880
35881 struct mirror {
35882 struct mirror_set *ms;
35883- atomic_t error_count;
35884+ atomic_unchecked_t error_count;
35885 unsigned long error_type;
35886 struct dm_dev *dev;
35887 sector_t offset;
35888@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35889 * simple way to tell if a device has encountered
35890 * errors.
35891 */
35892- atomic_inc(&m->error_count);
35893+ atomic_inc_unchecked(&m->error_count);
35894
35895 if (test_and_set_bit(error_type, &m->error_type))
35896 return;
35897@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35898 }
35899
35900 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
35901- if (!atomic_read(&new->error_count)) {
35902+ if (!atomic_read_unchecked(&new->error_count)) {
35903 set_default_mirror(new);
35904 break;
35905 }
35906@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35907 struct mirror *m = get_default_mirror(ms);
35908
35909 do {
35910- if (likely(!atomic_read(&m->error_count)))
35911+ if (likely(!atomic_read_unchecked(&m->error_count)))
35912 return m;
35913
35914 if (m-- == ms->mirror)
35915@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
35916 {
35917 struct mirror *default_mirror = get_default_mirror(m->ms);
35918
35919- return !atomic_read(&default_mirror->error_count);
35920+ return !atomic_read_unchecked(&default_mirror->error_count);
35921 }
35922
35923 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35924@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35925 */
35926 if (likely(region_in_sync(ms, region, 1)))
35927 m = choose_mirror(ms, bio->bi_sector);
35928- else if (m && atomic_read(&m->error_count))
35929+ else if (m && atomic_read_unchecked(&m->error_count))
35930 m = NULL;
35931
35932 if (likely(m))
35933@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35934 }
35935
35936 ms->mirror[mirror].ms = ms;
35937- atomic_set(&(ms->mirror[mirror].error_count), 0);
35938+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35939 ms->mirror[mirror].error_type = 0;
35940 ms->mirror[mirror].offset = offset;
35941
35942@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_target *ti)
35943 */
35944 static char device_status_char(struct mirror *m)
35945 {
35946- if (!atomic_read(&(m->error_count)))
35947+ if (!atomic_read_unchecked(&(m->error_count)))
35948 return 'A';
35949
35950 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
35951diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35952index bd58703..9f26571 100644
35953--- a/drivers/md/dm-stripe.c
35954+++ b/drivers/md/dm-stripe.c
35955@@ -20,7 +20,7 @@ struct stripe {
35956 struct dm_dev *dev;
35957 sector_t physical_start;
35958
35959- atomic_t error_count;
35960+ atomic_unchecked_t error_count;
35961 };
35962
35963 struct stripe_c {
35964@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35965 kfree(sc);
35966 return r;
35967 }
35968- atomic_set(&(sc->stripe[i].error_count), 0);
35969+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35970 }
35971
35972 ti->private = sc;
35973@@ -257,7 +257,7 @@ static int stripe_status(struct dm_target *ti,
35974 DMEMIT("%d ", sc->stripes);
35975 for (i = 0; i < sc->stripes; i++) {
35976 DMEMIT("%s ", sc->stripe[i].dev->name);
35977- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35978+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35979 'D' : 'A';
35980 }
35981 buffer[i] = '\0';
35982@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35983 */
35984 for (i = 0; i < sc->stripes; i++)
35985 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35986- atomic_inc(&(sc->stripe[i].error_count));
35987- if (atomic_read(&(sc->stripe[i].error_count)) <
35988+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
35989+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35990 DM_IO_ERROR_THRESHOLD)
35991 queue_work(kstriped, &sc->kstriped_ws);
35992 }
35993diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c
35994index 4b04590..13a77b2 100644
35995--- a/drivers/md/dm-sysfs.c
35996+++ b/drivers/md/dm-sysfs.c
35997@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
35998 NULL,
35999 };
36000
36001-static struct sysfs_ops dm_sysfs_ops = {
36002+static const struct sysfs_ops dm_sysfs_ops = {
36003 .show = dm_attr_show,
36004 };
36005
36006diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
36007index 03345bb..332250d 100644
36008--- a/drivers/md/dm-table.c
36009+++ b/drivers/md/dm-table.c
36010@@ -376,7 +376,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
36011 if (!dev_size)
36012 return 0;
36013
36014- if ((start >= dev_size) || (start + len > dev_size)) {
36015+ if ((start >= dev_size) || (len > dev_size - start)) {
36016 DMWARN("%s: %s too small for target: "
36017 "start=%llu, len=%llu, dev_size=%llu",
36018 dm_device_name(ti->table->md), bdevname(bdev, b),
36019diff --git a/drivers/md/dm.c b/drivers/md/dm.c
36020index c988ac2..c418141 100644
36021--- a/drivers/md/dm.c
36022+++ b/drivers/md/dm.c
36023@@ -165,9 +165,9 @@ struct mapped_device {
36024 /*
36025 * Event handling.
36026 */
36027- atomic_t event_nr;
36028+ atomic_unchecked_t event_nr;
36029 wait_queue_head_t eventq;
36030- atomic_t uevent_seq;
36031+ atomic_unchecked_t uevent_seq;
36032 struct list_head uevent_list;
36033 spinlock_t uevent_lock; /* Protect access to uevent_list */
36034
36035@@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(int minor)
36036 rwlock_init(&md->map_lock);
36037 atomic_set(&md->holders, 1);
36038 atomic_set(&md->open_count, 0);
36039- atomic_set(&md->event_nr, 0);
36040- atomic_set(&md->uevent_seq, 0);
36041+ atomic_set_unchecked(&md->event_nr, 0);
36042+ atomic_set_unchecked(&md->uevent_seq, 0);
36043 INIT_LIST_HEAD(&md->uevent_list);
36044 spin_lock_init(&md->uevent_lock);
36045
36046@@ -1927,7 +1927,7 @@ static void event_callback(void *context)
36047
36048 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36049
36050- atomic_inc(&md->event_nr);
36051+ atomic_inc_unchecked(&md->event_nr);
36052 wake_up(&md->eventq);
36053 }
36054
36055@@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36056
36057 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36058 {
36059- return atomic_add_return(1, &md->uevent_seq);
36060+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36061 }
36062
36063 uint32_t dm_get_event_nr(struct mapped_device *md)
36064 {
36065- return atomic_read(&md->event_nr);
36066+ return atomic_read_unchecked(&md->event_nr);
36067 }
36068
36069 int dm_wait_event(struct mapped_device *md, int event_nr)
36070 {
36071 return wait_event_interruptible(md->eventq,
36072- (event_nr != atomic_read(&md->event_nr)));
36073+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36074 }
36075
36076 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36077diff --git a/drivers/md/md.c b/drivers/md/md.c
36078index 4ce6e2f..7a9530a 100644
36079--- a/drivers/md/md.c
36080+++ b/drivers/md/md.c
36081@@ -153,10 +153,10 @@ static int start_readonly;
36082 * start build, activate spare
36083 */
36084 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36085-static atomic_t md_event_count;
36086+static atomic_unchecked_t md_event_count;
36087 void md_new_event(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 EXPORT_SYMBOL_GPL(md_new_event);
36094@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36095 */
36096 static void md_new_event_inintr(mddev_t *mddev)
36097 {
36098- atomic_inc(&md_event_count);
36099+ atomic_inc_unchecked(&md_event_count);
36100 wake_up(&md_event_waiters);
36101 }
36102
36103@@ -1226,7 +1226,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
36104
36105 rdev->preferred_minor = 0xffff;
36106 rdev->data_offset = le64_to_cpu(sb->data_offset);
36107- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36108+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36109
36110 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36111 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36112@@ -1400,7 +1400,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
36113 else
36114 sb->resync_offset = cpu_to_le64(0);
36115
36116- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36117+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36118
36119 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36120 sb->size = cpu_to_le64(mddev->dev_sectors);
36121@@ -2222,7 +2222,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36122 static ssize_t
36123 errors_show(mdk_rdev_t *rdev, char *page)
36124 {
36125- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36126+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36127 }
36128
36129 static ssize_t
36130@@ -2231,7 +2231,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
36131 char *e;
36132 unsigned long n = simple_strtoul(buf, &e, 10);
36133 if (*buf && (*e == 0 || *e == '\n')) {
36134- atomic_set(&rdev->corrected_errors, n);
36135+ atomic_set_unchecked(&rdev->corrected_errors, n);
36136 return len;
36137 }
36138 return -EINVAL;
36139@@ -2525,7 +2525,7 @@ static void rdev_free(struct kobject *ko)
36140 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
36141 kfree(rdev);
36142 }
36143-static struct sysfs_ops rdev_sysfs_ops = {
36144+static const struct sysfs_ops rdev_sysfs_ops = {
36145 .show = rdev_attr_show,
36146 .store = rdev_attr_store,
36147 };
36148@@ -2574,8 +2574,8 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
36149 rdev->data_offset = 0;
36150 rdev->sb_events = 0;
36151 atomic_set(&rdev->nr_pending, 0);
36152- atomic_set(&rdev->read_errors, 0);
36153- atomic_set(&rdev->corrected_errors, 0);
36154+ atomic_set_unchecked(&rdev->read_errors, 0);
36155+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36156
36157 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
36158 if (!size) {
36159@@ -3895,7 +3895,7 @@ static void md_free(struct kobject *ko)
36160 kfree(mddev);
36161 }
36162
36163-static struct sysfs_ops md_sysfs_ops = {
36164+static const struct sysfs_ops md_sysfs_ops = {
36165 .show = md_attr_show,
36166 .store = md_attr_store,
36167 };
36168@@ -4482,7 +4482,8 @@ out:
36169 err = 0;
36170 blk_integrity_unregister(disk);
36171 md_new_event(mddev);
36172- sysfs_notify_dirent(mddev->sysfs_state);
36173+ if (mddev->sysfs_state)
36174+ sysfs_notify_dirent(mddev->sysfs_state);
36175 return err;
36176 }
36177
36178@@ -5962,7 +5963,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36179
36180 spin_unlock(&pers_lock);
36181 seq_printf(seq, "\n");
36182- mi->event = atomic_read(&md_event_count);
36183+ mi->event = atomic_read_unchecked(&md_event_count);
36184 return 0;
36185 }
36186 if (v == (void*)2) {
36187@@ -6051,7 +6052,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36188 chunk_kb ? "KB" : "B");
36189 if (bitmap->file) {
36190 seq_printf(seq, ", file: ");
36191- seq_path(seq, &bitmap->file->f_path, " \t\n");
36192+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
36193 }
36194
36195 seq_printf(seq, "\n");
36196@@ -6085,7 +6086,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36197 else {
36198 struct seq_file *p = file->private_data;
36199 p->private = mi;
36200- mi->event = atomic_read(&md_event_count);
36201+ mi->event = atomic_read_unchecked(&md_event_count);
36202 }
36203 return error;
36204 }
36205@@ -6101,7 +6102,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36206 /* always allow read */
36207 mask = POLLIN | POLLRDNORM;
36208
36209- if (mi->event != atomic_read(&md_event_count))
36210+ if (mi->event != atomic_read_unchecked(&md_event_count))
36211 mask |= POLLERR | POLLPRI;
36212 return mask;
36213 }
36214@@ -6145,7 +6146,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
36215 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36216 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36217 (int)part_stat_read(&disk->part0, sectors[1]) -
36218- atomic_read(&disk->sync_io);
36219+ atomic_read_unchecked(&disk->sync_io);
36220 /* sync IO will cause sync_io to increase before the disk_stats
36221 * as sync_io is counted when a request starts, and
36222 * disk_stats is counted when it completes.
36223diff --git a/drivers/md/md.h b/drivers/md/md.h
36224index 87430fe..0024a4c 100644
36225--- a/drivers/md/md.h
36226+++ b/drivers/md/md.h
36227@@ -94,10 +94,10 @@ struct mdk_rdev_s
36228 * only maintained for arrays that
36229 * support hot removal
36230 */
36231- atomic_t read_errors; /* number of consecutive read errors that
36232+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36233 * we have tried to ignore.
36234 */
36235- atomic_t corrected_errors; /* number of corrected read errors,
36236+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36237 * for reporting to userspace and storing
36238 * in superblock.
36239 */
36240@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
36241
36242 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36243 {
36244- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36245+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36246 }
36247
36248 struct mdk_personality
36249diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36250index 968cb14..f0ad2e4 100644
36251--- a/drivers/md/raid1.c
36252+++ b/drivers/md/raid1.c
36253@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
36254 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
36255 continue;
36256 rdev = conf->mirrors[d].rdev;
36257- atomic_add(s, &rdev->corrected_errors);
36258+ atomic_add_unchecked(s, &rdev->corrected_errors);
36259 if (sync_page_io(rdev->bdev,
36260 sect + rdev->data_offset,
36261 s<<9,
36262@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
36263 /* Well, this device is dead */
36264 md_error(mddev, rdev);
36265 else {
36266- atomic_add(s, &rdev->corrected_errors);
36267+ atomic_add_unchecked(s, &rdev->corrected_errors);
36268 printk(KERN_INFO
36269 "raid1:%s: read error corrected "
36270 "(%d sectors at %llu on %s)\n",
36271diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36272index 1b4e232..cf0f534 100644
36273--- a/drivers/md/raid10.c
36274+++ b/drivers/md/raid10.c
36275@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bio, int error)
36276 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
36277 set_bit(R10BIO_Uptodate, &r10_bio->state);
36278 else {
36279- atomic_add(r10_bio->sectors,
36280+ atomic_add_unchecked(r10_bio->sectors,
36281 &conf->mirrors[d].rdev->corrected_errors);
36282 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
36283 md_error(r10_bio->mddev,
36284@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
36285 test_bit(In_sync, &rdev->flags)) {
36286 atomic_inc(&rdev->nr_pending);
36287 rcu_read_unlock();
36288- atomic_add(s, &rdev->corrected_errors);
36289+ atomic_add_unchecked(s, &rdev->corrected_errors);
36290 if (sync_page_io(rdev->bdev,
36291 r10_bio->devs[sl].addr +
36292 sect + rdev->data_offset,
36293diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36294index 883215d..675bf47 100644
36295--- a/drivers/md/raid5.c
36296+++ b/drivers/md/raid5.c
36297@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
36298 bi->bi_next = NULL;
36299 if ((rw & WRITE) &&
36300 test_bit(R5_ReWrite, &sh->dev[i].flags))
36301- atomic_add(STRIPE_SECTORS,
36302+ atomic_add_unchecked(STRIPE_SECTORS,
36303 &rdev->corrected_errors);
36304 generic_make_request(bi);
36305 } else {
36306@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struct bio * bi, int error)
36307 clear_bit(R5_ReadError, &sh->dev[i].flags);
36308 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36309 }
36310- if (atomic_read(&conf->disks[i].rdev->read_errors))
36311- atomic_set(&conf->disks[i].rdev->read_errors, 0);
36312+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
36313+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
36314 } else {
36315 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
36316 int retry = 0;
36317 rdev = conf->disks[i].rdev;
36318
36319 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36320- atomic_inc(&rdev->read_errors);
36321+ atomic_inc_unchecked(&rdev->read_errors);
36322 if (conf->mddev->degraded >= conf->max_degraded)
36323 printk_rl(KERN_WARNING
36324 "raid5:%s: read error not correctable "
36325@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36326 (unsigned long long)(sh->sector
36327 + rdev->data_offset),
36328 bdn);
36329- else if (atomic_read(&rdev->read_errors)
36330+ else if (atomic_read_unchecked(&rdev->read_errors)
36331 > conf->max_nr_stripes)
36332 printk(KERN_WARNING
36333 "raid5:%s: Too many read errors, failing device %s.\n",
36334@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
36335 sector_t r_sector;
36336 struct stripe_head sh2;
36337
36338+ pax_track_stack();
36339
36340 chunk_offset = sector_div(new_sector, sectors_per_chunk);
36341 stripe = new_sector;
36342diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
36343index 05bde9c..2f31d40 100644
36344--- a/drivers/media/common/saa7146_hlp.c
36345+++ b/drivers/media/common/saa7146_hlp.c
36346@@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
36347
36348 int x[32], y[32], w[32], h[32];
36349
36350+ pax_track_stack();
36351+
36352 /* clear out memory */
36353 memset(&line_list[0], 0x00, sizeof(u32)*32);
36354 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
36355diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36356index cb22da5..82b686e 100644
36357--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36358+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36359@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
36360 u8 buf[HOST_LINK_BUF_SIZE];
36361 int i;
36362
36363+ pax_track_stack();
36364+
36365 dprintk("%s\n", __func__);
36366
36367 /* check if we have space for a link buf in the rx_buffer */
36368@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
36369 unsigned long timeout;
36370 int written;
36371
36372+ pax_track_stack();
36373+
36374 dprintk("%s\n", __func__);
36375
36376 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
36377diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
36378index 2fe05d0..a3289c4 100644
36379--- a/drivers/media/dvb/dvb-core/dvb_demux.h
36380+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
36381@@ -71,7 +71,7 @@ struct dvb_demux_feed {
36382 union {
36383 dmx_ts_cb ts;
36384 dmx_section_cb sec;
36385- } cb;
36386+ } __no_const cb;
36387
36388 struct dvb_demux *demux;
36389 void *priv;
36390diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
36391index 94159b9..376bd8e 100644
36392--- a/drivers/media/dvb/dvb-core/dvbdev.c
36393+++ b/drivers/media/dvb/dvb-core/dvbdev.c
36394@@ -191,7 +191,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36395 const struct dvb_device *template, void *priv, int type)
36396 {
36397 struct dvb_device *dvbdev;
36398- struct file_operations *dvbdevfops;
36399+ file_operations_no_const *dvbdevfops;
36400 struct device *clsdev;
36401 int minor;
36402 int id;
36403diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
36404index 2a53dd0..db8c07a 100644
36405--- a/drivers/media/dvb/dvb-usb/cxusb.c
36406+++ b/drivers/media/dvb/dvb-usb/cxusb.c
36407@@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36408 struct dib0700_adapter_state {
36409 int (*set_param_save) (struct dvb_frontend *,
36410 struct dvb_frontend_parameters *);
36411-};
36412+} __no_const;
36413
36414 static int dib7070_set_param_override(struct dvb_frontend *fe,
36415 struct dvb_frontend_parameters *fep)
36416diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
36417index db7f7f7..f55e96f 100644
36418--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
36419+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
36420@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
36421
36422 u8 buf[260];
36423
36424+ pax_track_stack();
36425+
36426 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
36427 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
36428
36429diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36430index 524acf5..5ffc403 100644
36431--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
36432+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36433@@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
36434
36435 struct dib0700_adapter_state {
36436 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
36437-};
36438+} __no_const;
36439
36440 /* Hauppauge Nova-T 500 (aka Bristol)
36441 * has a LNA on GPIO0 which is enabled by setting 1 */
36442diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
36443index ba91735..4261d84 100644
36444--- a/drivers/media/dvb/frontends/dib3000.h
36445+++ b/drivers/media/dvb/frontends/dib3000.h
36446@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36447 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36448 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36449 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36450-};
36451+} __no_const;
36452
36453 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36454 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36455diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
36456index c709ce6..b3fe620 100644
36457--- a/drivers/media/dvb/frontends/or51211.c
36458+++ b/drivers/media/dvb/frontends/or51211.c
36459@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
36460 u8 tudata[585];
36461 int i;
36462
36463+ pax_track_stack();
36464+
36465 dprintk("Firmware is %zd bytes\n",fw->size);
36466
36467 /* Get eprom data */
36468diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36469index 482d0f3..ee1e202 100644
36470--- a/drivers/media/radio/radio-cadet.c
36471+++ b/drivers/media/radio/radio-cadet.c
36472@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36473 while (i < count && dev->rdsin != dev->rdsout)
36474 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36475
36476- if (copy_to_user(data, readbuf, i))
36477+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
36478 return -EFAULT;
36479 return i;
36480 }
36481diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
36482index 6dd51e2..0359b92 100644
36483--- a/drivers/media/video/cx18/cx18-driver.c
36484+++ b/drivers/media/video/cx18/cx18-driver.c
36485@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
36486
36487 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
36488
36489-static atomic_t cx18_instance = ATOMIC_INIT(0);
36490+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
36491
36492 /* Parameter declarations */
36493 static int cardtype[CX18_MAX_CARDS];
36494@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
36495 struct i2c_client c;
36496 u8 eedata[256];
36497
36498+ pax_track_stack();
36499+
36500 memset(&c, 0, sizeof(c));
36501 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
36502 c.adapter = &cx->i2c_adap[0];
36503@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
36504 struct cx18 *cx;
36505
36506 /* FIXME - module parameter arrays constrain max instances */
36507- i = atomic_inc_return(&cx18_instance) - 1;
36508+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
36509 if (i >= CX18_MAX_CARDS) {
36510 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
36511 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
36512diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
36513index 463ec34..2f4625a 100644
36514--- a/drivers/media/video/ivtv/ivtv-driver.c
36515+++ b/drivers/media/video/ivtv/ivtv-driver.c
36516@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
36517 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
36518
36519 /* ivtv instance counter */
36520-static atomic_t ivtv_instance = ATOMIC_INIT(0);
36521+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
36522
36523 /* Parameter declarations */
36524 static int cardtype[IVTV_MAX_CARDS];
36525diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
36526index 5fc4ac0..652a54a 100644
36527--- a/drivers/media/video/omap24xxcam.c
36528+++ b/drivers/media/video/omap24xxcam.c
36529@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
36530 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
36531
36532 do_gettimeofday(&vb->ts);
36533- vb->field_count = atomic_add_return(2, &fh->field_count);
36534+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
36535 if (csr & csr_error) {
36536 vb->state = VIDEOBUF_ERROR;
36537 if (!atomic_read(&fh->cam->in_reset)) {
36538diff --git a/drivers/media/video/omap24xxcam.h b/drivers/media/video/omap24xxcam.h
36539index 2ce67f5..cf26a5b 100644
36540--- a/drivers/media/video/omap24xxcam.h
36541+++ b/drivers/media/video/omap24xxcam.h
36542@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
36543 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
36544 struct videobuf_queue vbq;
36545 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
36546- atomic_t field_count; /* field counter for videobuf_buffer */
36547+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
36548 /* accessing cam here doesn't need serialisation: it's constant */
36549 struct omap24xxcam_device *cam;
36550 };
36551diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36552index 299afa4..eb47459 100644
36553--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36554+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36555@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
36556 u8 *eeprom;
36557 struct tveeprom tvdata;
36558
36559+ pax_track_stack();
36560+
36561 memset(&tvdata,0,sizeof(tvdata));
36562
36563 eeprom = pvr2_eeprom_fetch(hdw);
36564diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36565index 5b152ff..3320638 100644
36566--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36567+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36568@@ -195,7 +195,7 @@ struct pvr2_hdw {
36569
36570 /* I2C stuff */
36571 struct i2c_adapter i2c_adap;
36572- struct i2c_algorithm i2c_algo;
36573+ i2c_algorithm_no_const i2c_algo;
36574 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
36575 int i2c_cx25840_hack_state;
36576 int i2c_linked;
36577diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
36578index 1eabff6..8e2313a 100644
36579--- a/drivers/media/video/saa7134/saa6752hs.c
36580+++ b/drivers/media/video/saa7134/saa6752hs.c
36581@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
36582 unsigned char localPAT[256];
36583 unsigned char localPMT[256];
36584
36585+ pax_track_stack();
36586+
36587 /* Set video format - must be done first as it resets other settings */
36588 set_reg8(client, 0x41, h->video_format);
36589
36590diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
36591index 9c1d3ac..b1b49e9 100644
36592--- a/drivers/media/video/saa7164/saa7164-cmd.c
36593+++ b/drivers/media/video/saa7164/saa7164-cmd.c
36594@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
36595 wait_queue_head_t *q = 0;
36596 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36597
36598+ pax_track_stack();
36599+
36600 /* While any outstand message on the bus exists... */
36601 do {
36602
36603@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
36604 u8 tmp[512];
36605 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36606
36607+ pax_track_stack();
36608+
36609 while (loop) {
36610
36611 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
36612diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
36613index b085496..cde0270 100644
36614--- a/drivers/media/video/usbvideo/ibmcam.c
36615+++ b/drivers/media/video/usbvideo/ibmcam.c
36616@@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] = {
36617 static int __init ibmcam_init(void)
36618 {
36619 struct usbvideo_cb cbTbl;
36620- memset(&cbTbl, 0, sizeof(cbTbl));
36621- cbTbl.probe = ibmcam_probe;
36622- cbTbl.setupOnOpen = ibmcam_setup_on_open;
36623- cbTbl.videoStart = ibmcam_video_start;
36624- cbTbl.videoStop = ibmcam_video_stop;
36625- cbTbl.processData = ibmcam_ProcessIsocData;
36626- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36627- cbTbl.adjustPicture = ibmcam_adjust_picture;
36628- cbTbl.getFPS = ibmcam_calculate_fps;
36629+ memset((void *)&cbTbl, 0, sizeof(cbTbl));
36630+ *(void **)&cbTbl.probe = ibmcam_probe;
36631+ *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
36632+ *(void **)&cbTbl.videoStart = ibmcam_video_start;
36633+ *(void **)&cbTbl.videoStop = ibmcam_video_stop;
36634+ *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
36635+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36636+ *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
36637+ *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
36638 return usbvideo_register(
36639 &cams,
36640 MAX_IBMCAM,
36641diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
36642index 31d57f2..600b735 100644
36643--- a/drivers/media/video/usbvideo/konicawc.c
36644+++ b/drivers/media/video/usbvideo/konicawc.c
36645@@ -225,7 +225,7 @@ static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev
36646 int error;
36647
36648 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36649- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36650+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36651
36652 cam->input = input_dev = input_allocate_device();
36653 if (!input_dev) {
36654@@ -935,16 +935,16 @@ static int __init konicawc_init(void)
36655 struct usbvideo_cb cbTbl;
36656 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
36657 DRIVER_DESC "\n");
36658- memset(&cbTbl, 0, sizeof(cbTbl));
36659- cbTbl.probe = konicawc_probe;
36660- cbTbl.setupOnOpen = konicawc_setup_on_open;
36661- cbTbl.processData = konicawc_process_isoc;
36662- cbTbl.getFPS = konicawc_calculate_fps;
36663- cbTbl.setVideoMode = konicawc_set_video_mode;
36664- cbTbl.startDataPump = konicawc_start_data;
36665- cbTbl.stopDataPump = konicawc_stop_data;
36666- cbTbl.adjustPicture = konicawc_adjust_picture;
36667- cbTbl.userFree = konicawc_free_uvd;
36668+ memset((void * )&cbTbl, 0, sizeof(cbTbl));
36669+ *(void **)&cbTbl.probe = konicawc_probe;
36670+ *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
36671+ *(void **)&cbTbl.processData = konicawc_process_isoc;
36672+ *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
36673+ *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
36674+ *(void **)&cbTbl.startDataPump = konicawc_start_data;
36675+ *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
36676+ *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
36677+ *(void **)&cbTbl.userFree = konicawc_free_uvd;
36678 return usbvideo_register(
36679 &cams,
36680 MAX_CAMERAS,
36681diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
36682index 803d3e4..c4d1b96 100644
36683--- a/drivers/media/video/usbvideo/quickcam_messenger.c
36684+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
36685@@ -89,7 +89,7 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
36686 int error;
36687
36688 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36689- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36690+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36691
36692 cam->input = input_dev = input_allocate_device();
36693 if (!input_dev) {
36694diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
36695index fbd1b63..292f9f0 100644
36696--- a/drivers/media/video/usbvideo/ultracam.c
36697+++ b/drivers/media/video/usbvideo/ultracam.c
36698@@ -655,14 +655,14 @@ static int __init ultracam_init(void)
36699 {
36700 struct usbvideo_cb cbTbl;
36701 memset(&cbTbl, 0, sizeof(cbTbl));
36702- cbTbl.probe = ultracam_probe;
36703- cbTbl.setupOnOpen = ultracam_setup_on_open;
36704- cbTbl.videoStart = ultracam_video_start;
36705- cbTbl.videoStop = ultracam_video_stop;
36706- cbTbl.processData = ultracam_ProcessIsocData;
36707- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36708- cbTbl.adjustPicture = ultracam_adjust_picture;
36709- cbTbl.getFPS = ultracam_calculate_fps;
36710+ *(void **)&cbTbl.probe = ultracam_probe;
36711+ *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
36712+ *(void **)&cbTbl.videoStart = ultracam_video_start;
36713+ *(void **)&cbTbl.videoStop = ultracam_video_stop;
36714+ *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
36715+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36716+ *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
36717+ *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
36718 return usbvideo_register(
36719 &cams,
36720 MAX_CAMERAS,
36721diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
36722index dea8b32..34f6878 100644
36723--- a/drivers/media/video/usbvideo/usbvideo.c
36724+++ b/drivers/media/video/usbvideo/usbvideo.c
36725@@ -697,15 +697,15 @@ int usbvideo_register(
36726 __func__, cams, base_size, num_cams);
36727
36728 /* Copy callbacks, apply defaults for those that are not set */
36729- memmove(&cams->cb, cbTbl, sizeof(cams->cb));
36730+ memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
36731 if (cams->cb.getFrame == NULL)
36732- cams->cb.getFrame = usbvideo_GetFrame;
36733+ *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
36734 if (cams->cb.disconnect == NULL)
36735- cams->cb.disconnect = usbvideo_Disconnect;
36736+ *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
36737 if (cams->cb.startDataPump == NULL)
36738- cams->cb.startDataPump = usbvideo_StartDataPump;
36739+ *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
36740 if (cams->cb.stopDataPump == NULL)
36741- cams->cb.stopDataPump = usbvideo_StopDataPump;
36742+ *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
36743
36744 cams->num_cameras = num_cams;
36745 cams->cam = (struct uvd *) &cams[1];
36746diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
36747index c66985b..7fa143a 100644
36748--- a/drivers/media/video/usbvideo/usbvideo.h
36749+++ b/drivers/media/video/usbvideo/usbvideo.h
36750@@ -268,7 +268,7 @@ struct usbvideo_cb {
36751 int (*startDataPump)(struct uvd *uvd);
36752 void (*stopDataPump)(struct uvd *uvd);
36753 int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
36754-};
36755+} __no_const;
36756
36757 struct usbvideo {
36758 int num_cameras; /* As allocated */
36759diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
36760index e0f91e4..37554ea 100644
36761--- a/drivers/media/video/usbvision/usbvision-core.c
36762+++ b/drivers/media/video/usbvision/usbvision-core.c
36763@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
36764 unsigned char rv, gv, bv;
36765 static unsigned char *Y, *U, *V;
36766
36767+ pax_track_stack();
36768+
36769 frame = usbvision->curFrame;
36770 imageSize = frame->frmwidth * frame->frmheight;
36771 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
36772diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
36773index 0d06e7c..3d17d24 100644
36774--- a/drivers/media/video/v4l2-device.c
36775+++ b/drivers/media/video/v4l2-device.c
36776@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
36777 EXPORT_SYMBOL_GPL(v4l2_device_register);
36778
36779 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
36780- atomic_t *instance)
36781+ atomic_unchecked_t *instance)
36782 {
36783- int num = atomic_inc_return(instance) - 1;
36784+ int num = atomic_inc_return_unchecked(instance) - 1;
36785 int len = strlen(basename);
36786
36787 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
36788diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
36789index 032ebae..6a3532c 100644
36790--- a/drivers/media/video/videobuf-dma-sg.c
36791+++ b/drivers/media/video/videobuf-dma-sg.c
36792@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
36793 {
36794 struct videobuf_queue q;
36795
36796+ pax_track_stack();
36797+
36798 /* Required to make generic handler to call __videobuf_alloc */
36799 q.int_ops = &sg_ops;
36800
36801diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36802index b6992b7..9fa7547 100644
36803--- a/drivers/message/fusion/mptbase.c
36804+++ b/drivers/message/fusion/mptbase.c
36805@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
36806 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36807 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36808
36809+#ifdef CONFIG_GRKERNSEC_HIDESYM
36810+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36811+ NULL, NULL);
36812+#else
36813 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36814 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36815+#endif
36816+
36817 /*
36818 * Rounding UP to nearest 4-kB boundary here...
36819 */
36820diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36821index 83873e3..e360e9a 100644
36822--- a/drivers/message/fusion/mptsas.c
36823+++ b/drivers/message/fusion/mptsas.c
36824@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36825 return 0;
36826 }
36827
36828+static inline void
36829+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36830+{
36831+ if (phy_info->port_details) {
36832+ phy_info->port_details->rphy = rphy;
36833+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36834+ ioc->name, rphy));
36835+ }
36836+
36837+ if (rphy) {
36838+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36839+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36840+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36841+ ioc->name, rphy, rphy->dev.release));
36842+ }
36843+}
36844+
36845 /* no mutex */
36846 static void
36847 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36848@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36849 return NULL;
36850 }
36851
36852-static inline void
36853-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36854-{
36855- if (phy_info->port_details) {
36856- phy_info->port_details->rphy = rphy;
36857- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36858- ioc->name, rphy));
36859- }
36860-
36861- if (rphy) {
36862- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36863- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36864- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36865- ioc->name, rphy, rphy->dev.release));
36866- }
36867-}
36868-
36869 static inline struct sas_port *
36870 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36871 {
36872diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36873index bd096ca..332cf76 100644
36874--- a/drivers/message/fusion/mptscsih.c
36875+++ b/drivers/message/fusion/mptscsih.c
36876@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36877
36878 h = shost_priv(SChost);
36879
36880- if (h) {
36881- if (h->info_kbuf == NULL)
36882- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36883- return h->info_kbuf;
36884- h->info_kbuf[0] = '\0';
36885+ if (!h)
36886+ return NULL;
36887
36888- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36889- h->info_kbuf[size-1] = '\0';
36890- }
36891+ if (h->info_kbuf == NULL)
36892+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36893+ return h->info_kbuf;
36894+ h->info_kbuf[0] = '\0';
36895+
36896+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36897+ h->info_kbuf[size-1] = '\0';
36898
36899 return h->info_kbuf;
36900 }
36901diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
36902index efba702..59b2c0f 100644
36903--- a/drivers/message/i2o/i2o_config.c
36904+++ b/drivers/message/i2o/i2o_config.c
36905@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned long arg)
36906 struct i2o_message *msg;
36907 unsigned int iop;
36908
36909+ pax_track_stack();
36910+
36911 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
36912 return -EFAULT;
36913
36914diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36915index 7045c45..c07b170 100644
36916--- a/drivers/message/i2o/i2o_proc.c
36917+++ b/drivers/message/i2o/i2o_proc.c
36918@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
36919 "Array Controller Device"
36920 };
36921
36922-static char *chtostr(u8 * chars, int n)
36923-{
36924- char tmp[256];
36925- tmp[0] = 0;
36926- return strncat(tmp, (char *)chars, n);
36927-}
36928-
36929 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36930 char *group)
36931 {
36932@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36933
36934 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36935 seq_printf(seq, "%-#8x", ddm_table.module_id);
36936- seq_printf(seq, "%-29s",
36937- chtostr(ddm_table.module_name_version, 28));
36938+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36939 seq_printf(seq, "%9d ", ddm_table.data_size);
36940 seq_printf(seq, "%8d", ddm_table.code_size);
36941
36942@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36943
36944 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36945 seq_printf(seq, "%-#8x", dst->module_id);
36946- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
36947- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
36948+ seq_printf(seq, "%-.28s", dst->module_name_version);
36949+ seq_printf(seq, "%-.8s", dst->date);
36950 seq_printf(seq, "%8d ", dst->module_size);
36951 seq_printf(seq, "%8d ", dst->mpb_size);
36952 seq_printf(seq, "0x%04x", dst->module_flags);
36953@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36954 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36955 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36956 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36957- seq_printf(seq, "Vendor info : %s\n",
36958- chtostr((u8 *) (work32 + 2), 16));
36959- seq_printf(seq, "Product info : %s\n",
36960- chtostr((u8 *) (work32 + 6), 16));
36961- seq_printf(seq, "Description : %s\n",
36962- chtostr((u8 *) (work32 + 10), 16));
36963- seq_printf(seq, "Product rev. : %s\n",
36964- chtostr((u8 *) (work32 + 14), 8));
36965+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36966+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36967+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36968+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36969
36970 seq_printf(seq, "Serial number : ");
36971 print_serial_number(seq, (u8 *) (work32 + 16),
36972@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36973 }
36974
36975 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36976- seq_printf(seq, "Module name : %s\n",
36977- chtostr(result.module_name, 24));
36978- seq_printf(seq, "Module revision : %s\n",
36979- chtostr(result.module_rev, 8));
36980+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
36981+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36982
36983 seq_printf(seq, "Serial number : ");
36984 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36985@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36986 return 0;
36987 }
36988
36989- seq_printf(seq, "Device name : %s\n",
36990- chtostr(result.device_name, 64));
36991- seq_printf(seq, "Service name : %s\n",
36992- chtostr(result.service_name, 64));
36993- seq_printf(seq, "Physical name : %s\n",
36994- chtostr(result.physical_location, 64));
36995- seq_printf(seq, "Instance number : %s\n",
36996- chtostr(result.instance_number, 4));
36997+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
36998+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
36999+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
37000+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
37001
37002 return 0;
37003 }
37004diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
37005index 27cf4af..b1205b8 100644
37006--- a/drivers/message/i2o/iop.c
37007+++ b/drivers/message/i2o/iop.c
37008@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
37009
37010 spin_lock_irqsave(&c->context_list_lock, flags);
37011
37012- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
37013- atomic_inc(&c->context_list_counter);
37014+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
37015+ atomic_inc_unchecked(&c->context_list_counter);
37016
37017- entry->context = atomic_read(&c->context_list_counter);
37018+ entry->context = atomic_read_unchecked(&c->context_list_counter);
37019
37020 list_add(&entry->list, &c->context_list);
37021
37022@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
37023
37024 #if BITS_PER_LONG == 64
37025 spin_lock_init(&c->context_list_lock);
37026- atomic_set(&c->context_list_counter, 0);
37027+ atomic_set_unchecked(&c->context_list_counter, 0);
37028 INIT_LIST_HEAD(&c->context_list);
37029 #endif
37030
37031diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
37032index 78e3e85..66c9a0d 100644
37033--- a/drivers/mfd/ab3100-core.c
37034+++ b/drivers/mfd/ab3100-core.c
37035@@ -777,7 +777,7 @@ struct ab_family_id {
37036 char *name;
37037 };
37038
37039-static const struct ab_family_id ids[] __initdata = {
37040+static const struct ab_family_id ids[] __initconst = {
37041 /* AB3100 */
37042 {
37043 .id = 0xc0,
37044diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
37045index 8d8c932..8104515 100644
37046--- a/drivers/mfd/wm8350-i2c.c
37047+++ b/drivers/mfd/wm8350-i2c.c
37048@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
37049 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
37050 int ret;
37051
37052+ pax_track_stack();
37053+
37054 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
37055 return -EINVAL;
37056
37057diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
37058index e4ff50b..4cc3f04 100644
37059--- a/drivers/misc/kgdbts.c
37060+++ b/drivers/misc/kgdbts.c
37061@@ -118,7 +118,7 @@
37062 } while (0)
37063 #define MAX_CONFIG_LEN 40
37064
37065-static struct kgdb_io kgdbts_io_ops;
37066+static const struct kgdb_io kgdbts_io_ops;
37067 static char get_buf[BUFMAX];
37068 static int get_buf_cnt;
37069 static char put_buf[BUFMAX];
37070@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void)
37071 module_put(THIS_MODULE);
37072 }
37073
37074-static struct kgdb_io kgdbts_io_ops = {
37075+static const struct kgdb_io kgdbts_io_ops = {
37076 .name = "kgdbts",
37077 .read_char = kgdbts_get_char,
37078 .write_char = kgdbts_put_char,
37079diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
37080index 37e7cfc..67cfb76 100644
37081--- a/drivers/misc/sgi-gru/gruhandles.c
37082+++ b/drivers/misc/sgi-gru/gruhandles.c
37083@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37084
37085 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
37086 {
37087- atomic_long_inc(&mcs_op_statistics[op].count);
37088- atomic_long_add(clks, &mcs_op_statistics[op].total);
37089+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
37090+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
37091 if (mcs_op_statistics[op].max < clks)
37092 mcs_op_statistics[op].max = clks;
37093 }
37094diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
37095index 3f2375c..467c6e6 100644
37096--- a/drivers/misc/sgi-gru/gruprocfs.c
37097+++ b/drivers/misc/sgi-gru/gruprocfs.c
37098@@ -32,9 +32,9 @@
37099
37100 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
37101
37102-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
37103+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
37104 {
37105- unsigned long val = atomic_long_read(v);
37106+ unsigned long val = atomic_long_read_unchecked(v);
37107
37108 if (val)
37109 seq_printf(s, "%16lu %s\n", val, id);
37110@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
37111 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
37112
37113 for (op = 0; op < mcsop_last; op++) {
37114- count = atomic_long_read(&mcs_op_statistics[op].count);
37115- total = atomic_long_read(&mcs_op_statistics[op].total);
37116+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
37117+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
37118 max = mcs_op_statistics[op].max;
37119 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
37120 count ? total / count : 0, max);
37121diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
37122index 46990bc..4a251b5 100644
37123--- a/drivers/misc/sgi-gru/grutables.h
37124+++ b/drivers/misc/sgi-gru/grutables.h
37125@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
37126 * GRU statistics.
37127 */
37128 struct gru_stats_s {
37129- atomic_long_t vdata_alloc;
37130- atomic_long_t vdata_free;
37131- atomic_long_t gts_alloc;
37132- atomic_long_t gts_free;
37133- atomic_long_t vdata_double_alloc;
37134- atomic_long_t gts_double_allocate;
37135- atomic_long_t assign_context;
37136- atomic_long_t assign_context_failed;
37137- atomic_long_t free_context;
37138- atomic_long_t load_user_context;
37139- atomic_long_t load_kernel_context;
37140- atomic_long_t lock_kernel_context;
37141- atomic_long_t unlock_kernel_context;
37142- atomic_long_t steal_user_context;
37143- atomic_long_t steal_kernel_context;
37144- atomic_long_t steal_context_failed;
37145- atomic_long_t nopfn;
37146- atomic_long_t break_cow;
37147- atomic_long_t asid_new;
37148- atomic_long_t asid_next;
37149- atomic_long_t asid_wrap;
37150- atomic_long_t asid_reuse;
37151- atomic_long_t intr;
37152- atomic_long_t intr_mm_lock_failed;
37153- atomic_long_t call_os;
37154- atomic_long_t call_os_offnode_reference;
37155- atomic_long_t call_os_check_for_bug;
37156- atomic_long_t call_os_wait_queue;
37157- atomic_long_t user_flush_tlb;
37158- atomic_long_t user_unload_context;
37159- atomic_long_t user_exception;
37160- atomic_long_t set_context_option;
37161- atomic_long_t migrate_check;
37162- atomic_long_t migrated_retarget;
37163- atomic_long_t migrated_unload;
37164- atomic_long_t migrated_unload_delay;
37165- atomic_long_t migrated_nopfn_retarget;
37166- atomic_long_t migrated_nopfn_unload;
37167- atomic_long_t tlb_dropin;
37168- atomic_long_t tlb_dropin_fail_no_asid;
37169- atomic_long_t tlb_dropin_fail_upm;
37170- atomic_long_t tlb_dropin_fail_invalid;
37171- atomic_long_t tlb_dropin_fail_range_active;
37172- atomic_long_t tlb_dropin_fail_idle;
37173- atomic_long_t tlb_dropin_fail_fmm;
37174- atomic_long_t tlb_dropin_fail_no_exception;
37175- atomic_long_t tlb_dropin_fail_no_exception_war;
37176- atomic_long_t tfh_stale_on_fault;
37177- atomic_long_t mmu_invalidate_range;
37178- atomic_long_t mmu_invalidate_page;
37179- atomic_long_t mmu_clear_flush_young;
37180- atomic_long_t flush_tlb;
37181- atomic_long_t flush_tlb_gru;
37182- atomic_long_t flush_tlb_gru_tgh;
37183- atomic_long_t flush_tlb_gru_zero_asid;
37184+ atomic_long_unchecked_t vdata_alloc;
37185+ atomic_long_unchecked_t vdata_free;
37186+ atomic_long_unchecked_t gts_alloc;
37187+ atomic_long_unchecked_t gts_free;
37188+ atomic_long_unchecked_t vdata_double_alloc;
37189+ atomic_long_unchecked_t gts_double_allocate;
37190+ atomic_long_unchecked_t assign_context;
37191+ atomic_long_unchecked_t assign_context_failed;
37192+ atomic_long_unchecked_t free_context;
37193+ atomic_long_unchecked_t load_user_context;
37194+ atomic_long_unchecked_t load_kernel_context;
37195+ atomic_long_unchecked_t lock_kernel_context;
37196+ atomic_long_unchecked_t unlock_kernel_context;
37197+ atomic_long_unchecked_t steal_user_context;
37198+ atomic_long_unchecked_t steal_kernel_context;
37199+ atomic_long_unchecked_t steal_context_failed;
37200+ atomic_long_unchecked_t nopfn;
37201+ atomic_long_unchecked_t break_cow;
37202+ atomic_long_unchecked_t asid_new;
37203+ atomic_long_unchecked_t asid_next;
37204+ atomic_long_unchecked_t asid_wrap;
37205+ atomic_long_unchecked_t asid_reuse;
37206+ atomic_long_unchecked_t intr;
37207+ atomic_long_unchecked_t intr_mm_lock_failed;
37208+ atomic_long_unchecked_t call_os;
37209+ atomic_long_unchecked_t call_os_offnode_reference;
37210+ atomic_long_unchecked_t call_os_check_for_bug;
37211+ atomic_long_unchecked_t call_os_wait_queue;
37212+ atomic_long_unchecked_t user_flush_tlb;
37213+ atomic_long_unchecked_t user_unload_context;
37214+ atomic_long_unchecked_t user_exception;
37215+ atomic_long_unchecked_t set_context_option;
37216+ atomic_long_unchecked_t migrate_check;
37217+ atomic_long_unchecked_t migrated_retarget;
37218+ atomic_long_unchecked_t migrated_unload;
37219+ atomic_long_unchecked_t migrated_unload_delay;
37220+ atomic_long_unchecked_t migrated_nopfn_retarget;
37221+ atomic_long_unchecked_t migrated_nopfn_unload;
37222+ atomic_long_unchecked_t tlb_dropin;
37223+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37224+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37225+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37226+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37227+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37228+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37229+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37230+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
37231+ atomic_long_unchecked_t tfh_stale_on_fault;
37232+ atomic_long_unchecked_t mmu_invalidate_range;
37233+ atomic_long_unchecked_t mmu_invalidate_page;
37234+ atomic_long_unchecked_t mmu_clear_flush_young;
37235+ atomic_long_unchecked_t flush_tlb;
37236+ atomic_long_unchecked_t flush_tlb_gru;
37237+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37238+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37239
37240- atomic_long_t copy_gpa;
37241+ atomic_long_unchecked_t copy_gpa;
37242
37243- atomic_long_t mesq_receive;
37244- atomic_long_t mesq_receive_none;
37245- atomic_long_t mesq_send;
37246- atomic_long_t mesq_send_failed;
37247- atomic_long_t mesq_noop;
37248- atomic_long_t mesq_send_unexpected_error;
37249- atomic_long_t mesq_send_lb_overflow;
37250- atomic_long_t mesq_send_qlimit_reached;
37251- atomic_long_t mesq_send_amo_nacked;
37252- atomic_long_t mesq_send_put_nacked;
37253- atomic_long_t mesq_qf_not_full;
37254- atomic_long_t mesq_qf_locked;
37255- atomic_long_t mesq_qf_noop_not_full;
37256- atomic_long_t mesq_qf_switch_head_failed;
37257- atomic_long_t mesq_qf_unexpected_error;
37258- atomic_long_t mesq_noop_unexpected_error;
37259- atomic_long_t mesq_noop_lb_overflow;
37260- atomic_long_t mesq_noop_qlimit_reached;
37261- atomic_long_t mesq_noop_amo_nacked;
37262- atomic_long_t mesq_noop_put_nacked;
37263+ atomic_long_unchecked_t mesq_receive;
37264+ atomic_long_unchecked_t mesq_receive_none;
37265+ atomic_long_unchecked_t mesq_send;
37266+ atomic_long_unchecked_t mesq_send_failed;
37267+ atomic_long_unchecked_t mesq_noop;
37268+ atomic_long_unchecked_t mesq_send_unexpected_error;
37269+ atomic_long_unchecked_t mesq_send_lb_overflow;
37270+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37271+ atomic_long_unchecked_t mesq_send_amo_nacked;
37272+ atomic_long_unchecked_t mesq_send_put_nacked;
37273+ atomic_long_unchecked_t mesq_qf_not_full;
37274+ atomic_long_unchecked_t mesq_qf_locked;
37275+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37276+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37277+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37278+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37279+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37280+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37281+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37282+ atomic_long_unchecked_t mesq_noop_put_nacked;
37283
37284 };
37285
37286@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37287 cchop_deallocate, tghop_invalidate, mcsop_last};
37288
37289 struct mcs_op_statistic {
37290- atomic_long_t count;
37291- atomic_long_t total;
37292+ atomic_long_unchecked_t count;
37293+ atomic_long_unchecked_t total;
37294 unsigned long max;
37295 };
37296
37297@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37298
37299 #define STAT(id) do { \
37300 if (gru_options & OPT_STATS) \
37301- atomic_long_inc(&gru_stats.id); \
37302+ atomic_long_inc_unchecked(&gru_stats.id); \
37303 } while (0)
37304
37305 #ifdef CONFIG_SGI_GRU_DEBUG
37306diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37307index 2275126..12a9dbfb 100644
37308--- a/drivers/misc/sgi-xp/xp.h
37309+++ b/drivers/misc/sgi-xp/xp.h
37310@@ -289,7 +289,7 @@ struct xpc_interface {
37311 xpc_notify_func, void *);
37312 void (*received) (short, int, void *);
37313 enum xp_retval (*partid_to_nasids) (short, void *);
37314-};
37315+} __no_const;
37316
37317 extern struct xpc_interface xpc_interface;
37318
37319diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37320index b94d5f7..7f494c5 100644
37321--- a/drivers/misc/sgi-xp/xpc.h
37322+++ b/drivers/misc/sgi-xp/xpc.h
37323@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37324 void (*received_payload) (struct xpc_channel *, void *);
37325 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37326 };
37327+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37328
37329 /* struct xpc_partition act_state values (for XPC HB) */
37330
37331@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37332 /* found in xpc_main.c */
37333 extern struct device *xpc_part;
37334 extern struct device *xpc_chan;
37335-extern struct xpc_arch_operations xpc_arch_ops;
37336+extern xpc_arch_operations_no_const xpc_arch_ops;
37337 extern int xpc_disengage_timelimit;
37338 extern int xpc_disengage_timedout;
37339 extern int xpc_activate_IRQ_rcvd;
37340diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37341index fd3688a..7e211a4 100644
37342--- a/drivers/misc/sgi-xp/xpc_main.c
37343+++ b/drivers/misc/sgi-xp/xpc_main.c
37344@@ -169,7 +169,7 @@ static struct notifier_block xpc_die_notifier = {
37345 .notifier_call = xpc_system_die,
37346 };
37347
37348-struct xpc_arch_operations xpc_arch_ops;
37349+xpc_arch_operations_no_const xpc_arch_ops;
37350
37351 /*
37352 * Timer function to enforce the timelimit on the partition disengage.
37353diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
37354index 8b70e03..700bda6 100644
37355--- a/drivers/misc/sgi-xp/xpc_sn2.c
37356+++ b/drivers/misc/sgi-xp/xpc_sn2.c
37357@@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_channel *ch, void *payload)
37358 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
37359 }
37360
37361-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
37362+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
37363 .setup_partitions = xpc_setup_partitions_sn2,
37364 .teardown_partitions = xpc_teardown_partitions_sn2,
37365 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
37366@@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
37367 int ret;
37368 size_t buf_size;
37369
37370- xpc_arch_ops = xpc_arch_ops_sn2;
37371+ pax_open_kernel();
37372+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
37373+ pax_close_kernel();
37374
37375 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
37376 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
37377diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
37378index 8e08d71..7cb8c9b 100644
37379--- a/drivers/misc/sgi-xp/xpc_uv.c
37380+++ b/drivers/misc/sgi-xp/xpc_uv.c
37381@@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
37382 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
37383 }
37384
37385-static struct xpc_arch_operations xpc_arch_ops_uv = {
37386+static const struct xpc_arch_operations xpc_arch_ops_uv = {
37387 .setup_partitions = xpc_setup_partitions_uv,
37388 .teardown_partitions = xpc_teardown_partitions_uv,
37389 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
37390@@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_arch_ops_uv = {
37391 int
37392 xpc_init_uv(void)
37393 {
37394- xpc_arch_ops = xpc_arch_ops_uv;
37395+ pax_open_kernel();
37396+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
37397+ pax_close_kernel();
37398
37399 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
37400 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
37401diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
37402index 6fd20b42..650efe3 100644
37403--- a/drivers/mmc/host/sdhci-pci.c
37404+++ b/drivers/mmc/host/sdhci-pci.c
37405@@ -297,7 +297,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
37406 .probe = via_probe,
37407 };
37408
37409-static const struct pci_device_id pci_ids[] __devinitdata = {
37410+static const struct pci_device_id pci_ids[] __devinitconst = {
37411 {
37412 .vendor = PCI_VENDOR_ID_RICOH,
37413 .device = PCI_DEVICE_ID_RICOH_R5C822,
37414diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
37415index e7563a9..5f90ce5 100644
37416--- a/drivers/mtd/chips/cfi_cmdset_0001.c
37417+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
37418@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
37419 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
37420 unsigned long timeo = jiffies + HZ;
37421
37422+ pax_track_stack();
37423+
37424 /* Prevent setting state FL_SYNCING for chip in suspended state. */
37425 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
37426 goto sleep;
37427@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
37428 unsigned long initial_adr;
37429 int initial_len = len;
37430
37431+ pax_track_stack();
37432+
37433 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
37434 adr += chip->start;
37435 initial_adr = adr;
37436@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
37437 int retries = 3;
37438 int ret;
37439
37440+ pax_track_stack();
37441+
37442 adr += chip->start;
37443
37444 retry:
37445diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
37446index 0667a67..3ab97ed 100644
37447--- a/drivers/mtd/chips/cfi_cmdset_0020.c
37448+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
37449@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
37450 unsigned long cmd_addr;
37451 struct cfi_private *cfi = map->fldrv_priv;
37452
37453+ pax_track_stack();
37454+
37455 adr += chip->start;
37456
37457 /* Ensure cmd read/writes are aligned. */
37458@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
37459 DECLARE_WAITQUEUE(wait, current);
37460 int wbufsize, z;
37461
37462+ pax_track_stack();
37463+
37464 /* M58LW064A requires bus alignment for buffer wriets -- saw */
37465 if (adr & (map_bankwidth(map)-1))
37466 return -EINVAL;
37467@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
37468 DECLARE_WAITQUEUE(wait, current);
37469 int ret = 0;
37470
37471+ pax_track_stack();
37472+
37473 adr += chip->start;
37474
37475 /* Let's determine this according to the interleave only once */
37476@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
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@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
37486 unsigned long timeo = jiffies + HZ;
37487 DECLARE_WAITQUEUE(wait, current);
37488
37489+ pax_track_stack();
37490+
37491 adr += chip->start;
37492
37493 /* Let's determine this according to the interleave only once */
37494diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37495index 5bf5f46..c5de373 100644
37496--- a/drivers/mtd/devices/doc2000.c
37497+++ b/drivers/mtd/devices/doc2000.c
37498@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37499
37500 /* The ECC will not be calculated correctly if less than 512 is written */
37501 /* DBB-
37502- if (len != 0x200 && eccbuf)
37503+ if (len != 0x200)
37504 printk(KERN_WARNING
37505 "ECC needs a full sector write (adr: %lx size %lx)\n",
37506 (long) to, (long) len);
37507diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
37508index 0990f78..bb4e8a4 100644
37509--- a/drivers/mtd/devices/doc2001.c
37510+++ b/drivers/mtd/devices/doc2001.c
37511@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
37512 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
37513
37514 /* Don't allow read past end of device */
37515- if (from >= this->totlen)
37516+ if (from >= this->totlen || !len)
37517 return -EINVAL;
37518
37519 /* Don't allow a single read to cross a 512-byte block boundary */
37520diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
37521index e56d6b4..f07e6cf 100644
37522--- a/drivers/mtd/ftl.c
37523+++ b/drivers/mtd/ftl.c
37524@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
37525 loff_t offset;
37526 uint16_t srcunitswap = cpu_to_le16(srcunit);
37527
37528+ pax_track_stack();
37529+
37530 eun = &part->EUNInfo[srcunit];
37531 xfer = &part->XferInfo[xferunit];
37532 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
37533diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
37534index 8aca552..146446e 100755
37535--- a/drivers/mtd/inftlcore.c
37536+++ b/drivers/mtd/inftlcore.c
37537@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
37538 struct inftl_oob oob;
37539 size_t retlen;
37540
37541+ pax_track_stack();
37542+
37543 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
37544 "pending=%d)\n", inftl, thisVUC, pendingblock);
37545
37546diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
37547index 32e82ae..ed50953 100644
37548--- a/drivers/mtd/inftlmount.c
37549+++ b/drivers/mtd/inftlmount.c
37550@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
37551 struct INFTLPartition *ip;
37552 size_t retlen;
37553
37554+ pax_track_stack();
37555+
37556 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
37557
37558 /*
37559diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
37560index 79bf40f..fe5f8fd 100644
37561--- a/drivers/mtd/lpddr/qinfo_probe.c
37562+++ b/drivers/mtd/lpddr/qinfo_probe.c
37563@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
37564 {
37565 map_word pfow_val[4];
37566
37567+ pax_track_stack();
37568+
37569 /* Check identification string */
37570 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
37571 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
37572diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
37573index 726a1b8..f46b460 100644
37574--- a/drivers/mtd/mtdchar.c
37575+++ b/drivers/mtd/mtdchar.c
37576@@ -461,6 +461,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
37577 u_long size;
37578 struct mtd_info_user info;
37579
37580+ pax_track_stack();
37581+
37582 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
37583
37584 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
37585diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
37586index 1002e18..26d82d5 100644
37587--- a/drivers/mtd/nftlcore.c
37588+++ b/drivers/mtd/nftlcore.c
37589@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
37590 int inplace = 1;
37591 size_t retlen;
37592
37593+ pax_track_stack();
37594+
37595 memset(BlockMap, 0xff, sizeof(BlockMap));
37596 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
37597
37598diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37599index 8b22b18..6fada85 100644
37600--- a/drivers/mtd/nftlmount.c
37601+++ b/drivers/mtd/nftlmount.c
37602@@ -23,6 +23,7 @@
37603 #include <asm/errno.h>
37604 #include <linux/delay.h>
37605 #include <linux/slab.h>
37606+#include <linux/sched.h>
37607 #include <linux/mtd/mtd.h>
37608 #include <linux/mtd/nand.h>
37609 #include <linux/mtd/nftl.h>
37610@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
37611 struct mtd_info *mtd = nftl->mbd.mtd;
37612 unsigned int i;
37613
37614+ pax_track_stack();
37615+
37616 /* Assume logical EraseSize == physical erasesize for starting the scan.
37617 We'll sort it out later if we find a MediaHeader which says otherwise */
37618 /* Actually, we won't. The new DiskOnChip driver has already scanned
37619diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
37620index 14cec04..d775b87 100644
37621--- a/drivers/mtd/ubi/build.c
37622+++ b/drivers/mtd/ubi/build.c
37623@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
37624 static int __init bytes_str_to_int(const char *str)
37625 {
37626 char *endp;
37627- unsigned long result;
37628+ unsigned long result, scale = 1;
37629
37630 result = simple_strtoul(str, &endp, 0);
37631 if (str == endp || result >= INT_MAX) {
37632@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const char *str)
37633
37634 switch (*endp) {
37635 case 'G':
37636- result *= 1024;
37637+ scale *= 1024;
37638 case 'M':
37639- result *= 1024;
37640+ scale *= 1024;
37641 case 'K':
37642- result *= 1024;
37643+ scale *= 1024;
37644 if (endp[1] == 'i' && endp[2] == 'B')
37645 endp += 2;
37646 case '\0':
37647@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const char *str)
37648 return -EINVAL;
37649 }
37650
37651- return result;
37652+ if ((intoverflow_t)result*scale >= INT_MAX) {
37653+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
37654+ str);
37655+ return -EINVAL;
37656+ }
37657+
37658+ return result*scale;
37659 }
37660
37661 /**
37662diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
37663index ab68886..ca405e8 100644
37664--- a/drivers/net/atlx/atl2.c
37665+++ b/drivers/net/atlx/atl2.c
37666@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
37667 */
37668
37669 #define ATL2_PARAM(X, desc) \
37670- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37671+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37672 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
37673 MODULE_PARM_DESC(X, desc);
37674 #else
37675diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
37676index 4874b2b..67f8526 100644
37677--- a/drivers/net/bnx2.c
37678+++ b/drivers/net/bnx2.c
37679@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
37680 int rc = 0;
37681 u32 magic, csum;
37682
37683+ pax_track_stack();
37684+
37685 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
37686 goto test_nvram_done;
37687
37688diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
37689index fd3eb07..8a6978d 100644
37690--- a/drivers/net/cxgb3/l2t.h
37691+++ b/drivers/net/cxgb3/l2t.h
37692@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37693 */
37694 struct l2t_skb_cb {
37695 arp_failure_handler_func arp_failure_handler;
37696-};
37697+} __no_const;
37698
37699 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37700
37701diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
37702index 032cfe0..411af379 100644
37703--- a/drivers/net/cxgb3/t3_hw.c
37704+++ b/drivers/net/cxgb3/t3_hw.c
37705@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
37706 int i, addr, ret;
37707 struct t3_vpd vpd;
37708
37709+ pax_track_stack();
37710+
37711 /*
37712 * Card information is normally at VPD_BASE but some early cards had
37713 * it at 0.
37714diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
37715index d1e0563..b9e129c 100644
37716--- a/drivers/net/e1000e/82571.c
37717+++ b/drivers/net/e1000e/82571.c
37718@@ -212,7 +212,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
37719 {
37720 struct e1000_hw *hw = &adapter->hw;
37721 struct e1000_mac_info *mac = &hw->mac;
37722- struct e1000_mac_operations *func = &mac->ops;
37723+ e1000_mac_operations_no_const *func = &mac->ops;
37724 u32 swsm = 0;
37725 u32 swsm2 = 0;
37726 bool force_clear_smbi = false;
37727@@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
37728 temp = er32(ICRXDMTC);
37729 }
37730
37731-static struct e1000_mac_operations e82571_mac_ops = {
37732+static const struct e1000_mac_operations e82571_mac_ops = {
37733 /* .check_mng_mode: mac type dependent */
37734 /* .check_for_link: media type dependent */
37735 .id_led_init = e1000e_id_led_init,
37736@@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e82571_mac_ops = {
37737 .setup_led = e1000e_setup_led_generic,
37738 };
37739
37740-static struct e1000_phy_operations e82_phy_ops_igp = {
37741+static const struct e1000_phy_operations e82_phy_ops_igp = {
37742 .acquire_phy = e1000_get_hw_semaphore_82571,
37743 .check_reset_block = e1000e_check_reset_block_generic,
37744 .commit_phy = NULL,
37745@@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_phy_ops_igp = {
37746 .cfg_on_link_up = NULL,
37747 };
37748
37749-static struct e1000_phy_operations e82_phy_ops_m88 = {
37750+static const struct e1000_phy_operations e82_phy_ops_m88 = {
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@@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_phy_ops_m88 = {
37755 .cfg_on_link_up = NULL,
37756 };
37757
37758-static struct e1000_phy_operations e82_phy_ops_bm = {
37759+static const struct e1000_phy_operations e82_phy_ops_bm = {
37760 .acquire_phy = e1000_get_hw_semaphore_82571,
37761 .check_reset_block = e1000e_check_reset_block_generic,
37762 .commit_phy = e1000e_phy_sw_reset,
37763@@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_phy_ops_bm = {
37764 .cfg_on_link_up = NULL,
37765 };
37766
37767-static struct e1000_nvm_operations e82571_nvm_ops = {
37768+static const struct e1000_nvm_operations e82571_nvm_ops = {
37769 .acquire_nvm = e1000_acquire_nvm_82571,
37770 .read_nvm = e1000e_read_nvm_eerd,
37771 .release_nvm = e1000_release_nvm_82571,
37772diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
37773index 47db9bd..fa58ccd 100644
37774--- a/drivers/net/e1000e/e1000.h
37775+++ b/drivers/net/e1000e/e1000.h
37776@@ -375,9 +375,9 @@ struct e1000_info {
37777 u32 pba;
37778 u32 max_hw_frame_size;
37779 s32 (*get_variants)(struct e1000_adapter *);
37780- struct e1000_mac_operations *mac_ops;
37781- struct e1000_phy_operations *phy_ops;
37782- struct e1000_nvm_operations *nvm_ops;
37783+ const struct e1000_mac_operations *mac_ops;
37784+ const struct e1000_phy_operations *phy_ops;
37785+ const struct e1000_nvm_operations *nvm_ops;
37786 };
37787
37788 /* hardware capability, feature, and workaround flags */
37789diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
37790index ae5d736..e9a93a1 100644
37791--- a/drivers/net/e1000e/es2lan.c
37792+++ b/drivers/net/e1000e/es2lan.c
37793@@ -207,7 +207,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
37794 {
37795 struct e1000_hw *hw = &adapter->hw;
37796 struct e1000_mac_info *mac = &hw->mac;
37797- struct e1000_mac_operations *func = &mac->ops;
37798+ e1000_mac_operations_no_const *func = &mac->ops;
37799
37800 /* Set media type */
37801 switch (adapter->pdev->device) {
37802@@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
37803 temp = er32(ICRXDMTC);
37804 }
37805
37806-static struct e1000_mac_operations es2_mac_ops = {
37807+static const struct e1000_mac_operations es2_mac_ops = {
37808 .id_led_init = e1000e_id_led_init,
37809 .check_mng_mode = e1000e_check_mng_mode_generic,
37810 /* check_for_link dependent on media type */
37811@@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_mac_ops = {
37812 .setup_led = e1000e_setup_led_generic,
37813 };
37814
37815-static struct e1000_phy_operations es2_phy_ops = {
37816+static const struct e1000_phy_operations es2_phy_ops = {
37817 .acquire_phy = e1000_acquire_phy_80003es2lan,
37818 .check_reset_block = e1000e_check_reset_block_generic,
37819 .commit_phy = e1000e_phy_sw_reset,
37820@@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_phy_ops = {
37821 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
37822 };
37823
37824-static struct e1000_nvm_operations es2_nvm_ops = {
37825+static const struct e1000_nvm_operations es2_nvm_ops = {
37826 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
37827 .read_nvm = e1000e_read_nvm_eerd,
37828 .release_nvm = e1000_release_nvm_80003es2lan,
37829diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
37830index 11f3b7c..6381887 100644
37831--- a/drivers/net/e1000e/hw.h
37832+++ b/drivers/net/e1000e/hw.h
37833@@ -753,6 +753,7 @@ struct e1000_mac_operations {
37834 s32 (*setup_physical_interface)(struct e1000_hw *);
37835 s32 (*setup_led)(struct e1000_hw *);
37836 };
37837+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37838
37839 /* Function pointers for the PHY. */
37840 struct e1000_phy_operations {
37841@@ -774,6 +775,7 @@ struct e1000_phy_operations {
37842 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
37843 s32 (*cfg_on_link_up)(struct e1000_hw *);
37844 };
37845+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37846
37847 /* Function pointers for the NVM. */
37848 struct e1000_nvm_operations {
37849@@ -785,9 +787,10 @@ struct e1000_nvm_operations {
37850 s32 (*validate_nvm)(struct e1000_hw *);
37851 s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
37852 };
37853+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
37854
37855 struct e1000_mac_info {
37856- struct e1000_mac_operations ops;
37857+ e1000_mac_operations_no_const ops;
37858
37859 u8 addr[6];
37860 u8 perm_addr[6];
37861@@ -823,7 +826,7 @@ struct e1000_mac_info {
37862 };
37863
37864 struct e1000_phy_info {
37865- struct e1000_phy_operations ops;
37866+ e1000_phy_operations_no_const ops;
37867
37868 enum e1000_phy_type type;
37869
37870@@ -857,7 +860,7 @@ struct e1000_phy_info {
37871 };
37872
37873 struct e1000_nvm_info {
37874- struct e1000_nvm_operations ops;
37875+ e1000_nvm_operations_no_const ops;
37876
37877 enum e1000_nvm_type type;
37878 enum e1000_nvm_override override;
37879diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
37880index de39f9a..e28d3e0 100644
37881--- a/drivers/net/e1000e/ich8lan.c
37882+++ b/drivers/net/e1000e/ich8lan.c
37883@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
37884 }
37885 }
37886
37887-static struct e1000_mac_operations ich8_mac_ops = {
37888+static const struct e1000_mac_operations ich8_mac_ops = {
37889 .id_led_init = e1000e_id_led_init,
37890 .check_mng_mode = e1000_check_mng_mode_ich8lan,
37891 .check_for_link = e1000_check_for_copper_link_ich8lan,
37892@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_mac_ops = {
37893 /* id_led_init dependent on mac type */
37894 };
37895
37896-static struct e1000_phy_operations ich8_phy_ops = {
37897+static const struct e1000_phy_operations ich8_phy_ops = {
37898 .acquire_phy = e1000_acquire_swflag_ich8lan,
37899 .check_reset_block = e1000_check_reset_block_ich8lan,
37900 .commit_phy = NULL,
37901@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_phy_ops = {
37902 .write_phy_reg = e1000e_write_phy_reg_igp,
37903 };
37904
37905-static struct e1000_nvm_operations ich8_nvm_ops = {
37906+static const struct e1000_nvm_operations ich8_nvm_ops = {
37907 .acquire_nvm = e1000_acquire_nvm_ich8lan,
37908 .read_nvm = e1000_read_nvm_ich8lan,
37909 .release_nvm = e1000_release_nvm_ich8lan,
37910diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
37911index 18d5fbb..542d96d 100644
37912--- a/drivers/net/fealnx.c
37913+++ b/drivers/net/fealnx.c
37914@@ -151,7 +151,7 @@ struct chip_info {
37915 int flags;
37916 };
37917
37918-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
37919+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
37920 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37921 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
37922 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37923diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
37924index 0e5b54b..b503f82 100644
37925--- a/drivers/net/hamradio/6pack.c
37926+++ b/drivers/net/hamradio/6pack.c
37927@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
37928 unsigned char buf[512];
37929 int count1;
37930
37931+ pax_track_stack();
37932+
37933 if (!count)
37934 return;
37935
37936diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
37937index 5862282..7cce8cb 100644
37938--- a/drivers/net/ibmveth.c
37939+++ b/drivers/net/ibmveth.c
37940@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attrs[] = {
37941 NULL,
37942 };
37943
37944-static struct sysfs_ops veth_pool_ops = {
37945+static const struct sysfs_ops veth_pool_ops = {
37946 .show = veth_pool_show,
37947 .store = veth_pool_store,
37948 };
37949diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
37950index d617f2d..57b5309 100644
37951--- a/drivers/net/igb/e1000_82575.c
37952+++ b/drivers/net/igb/e1000_82575.c
37953@@ -1411,7 +1411,7 @@ void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
37954 wr32(E1000_VT_CTL, vt_ctl);
37955 }
37956
37957-static struct e1000_mac_operations e1000_mac_ops_82575 = {
37958+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
37959 .reset_hw = igb_reset_hw_82575,
37960 .init_hw = igb_init_hw_82575,
37961 .check_for_link = igb_check_for_link_82575,
37962@@ -1420,13 +1420,13 @@ static struct e1000_mac_operations e1000_mac_ops_82575 = {
37963 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
37964 };
37965
37966-static struct e1000_phy_operations e1000_phy_ops_82575 = {
37967+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
37968 .acquire = igb_acquire_phy_82575,
37969 .get_cfg_done = igb_get_cfg_done_82575,
37970 .release = igb_release_phy_82575,
37971 };
37972
37973-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
37974+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
37975 .acquire = igb_acquire_nvm_82575,
37976 .read = igb_read_nvm_eerd,
37977 .release = igb_release_nvm_82575,
37978diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
37979index 72081df..d855cf5 100644
37980--- a/drivers/net/igb/e1000_hw.h
37981+++ b/drivers/net/igb/e1000_hw.h
37982@@ -288,6 +288,7 @@ struct e1000_mac_operations {
37983 s32 (*read_mac_addr)(struct e1000_hw *);
37984 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
37985 };
37986+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37987
37988 struct e1000_phy_operations {
37989 s32 (*acquire)(struct e1000_hw *);
37990@@ -303,6 +304,7 @@ struct e1000_phy_operations {
37991 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
37992 s32 (*write_reg)(struct e1000_hw *, u32, u16);
37993 };
37994+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37995
37996 struct e1000_nvm_operations {
37997 s32 (*acquire)(struct e1000_hw *);
37998@@ -310,6 +312,7 @@ struct e1000_nvm_operations {
37999 void (*release)(struct e1000_hw *);
38000 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
38001 };
38002+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
38003
38004 struct e1000_info {
38005 s32 (*get_invariants)(struct e1000_hw *);
38006@@ -321,7 +324,7 @@ struct e1000_info {
38007 extern const struct e1000_info e1000_82575_info;
38008
38009 struct e1000_mac_info {
38010- struct e1000_mac_operations ops;
38011+ e1000_mac_operations_no_const ops;
38012
38013 u8 addr[6];
38014 u8 perm_addr[6];
38015@@ -365,7 +368,7 @@ struct e1000_mac_info {
38016 };
38017
38018 struct e1000_phy_info {
38019- struct e1000_phy_operations ops;
38020+ e1000_phy_operations_no_const ops;
38021
38022 enum e1000_phy_type type;
38023
38024@@ -400,7 +403,7 @@ struct e1000_phy_info {
38025 };
38026
38027 struct e1000_nvm_info {
38028- struct e1000_nvm_operations ops;
38029+ e1000_nvm_operations_no_const ops;
38030
38031 enum e1000_nvm_type type;
38032 enum e1000_nvm_override override;
38033@@ -446,6 +449,7 @@ struct e1000_mbx_operations {
38034 s32 (*check_for_ack)(struct e1000_hw *, u16);
38035 s32 (*check_for_rst)(struct e1000_hw *, u16);
38036 };
38037+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38038
38039 struct e1000_mbx_stats {
38040 u32 msgs_tx;
38041@@ -457,7 +461,7 @@ struct e1000_mbx_stats {
38042 };
38043
38044 struct e1000_mbx_info {
38045- struct e1000_mbx_operations ops;
38046+ e1000_mbx_operations_no_const ops;
38047 struct e1000_mbx_stats stats;
38048 u32 timeout;
38049 u32 usec_delay;
38050diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
38051index 1e8ce37..549c453 100644
38052--- a/drivers/net/igbvf/vf.h
38053+++ b/drivers/net/igbvf/vf.h
38054@@ -187,9 +187,10 @@ struct e1000_mac_operations {
38055 s32 (*read_mac_addr)(struct e1000_hw *);
38056 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
38057 };
38058+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38059
38060 struct e1000_mac_info {
38061- struct e1000_mac_operations ops;
38062+ e1000_mac_operations_no_const ops;
38063 u8 addr[6];
38064 u8 perm_addr[6];
38065
38066@@ -211,6 +212,7 @@ struct e1000_mbx_operations {
38067 s32 (*check_for_ack)(struct e1000_hw *);
38068 s32 (*check_for_rst)(struct e1000_hw *);
38069 };
38070+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38071
38072 struct e1000_mbx_stats {
38073 u32 msgs_tx;
38074@@ -222,7 +224,7 @@ struct e1000_mbx_stats {
38075 };
38076
38077 struct e1000_mbx_info {
38078- struct e1000_mbx_operations ops;
38079+ e1000_mbx_operations_no_const ops;
38080 struct e1000_mbx_stats stats;
38081 u32 timeout;
38082 u32 usec_delay;
38083diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
38084index aa7286b..a61394f 100644
38085--- a/drivers/net/iseries_veth.c
38086+++ b/drivers/net/iseries_veth.c
38087@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_default_attrs[] = {
38088 NULL
38089 };
38090
38091-static struct sysfs_ops veth_cnx_sysfs_ops = {
38092+static const struct sysfs_ops veth_cnx_sysfs_ops = {
38093 .show = veth_cnx_attribute_show
38094 };
38095
38096@@ -441,7 +441,7 @@ static struct attribute *veth_port_default_attrs[] = {
38097 NULL
38098 };
38099
38100-static struct sysfs_ops veth_port_sysfs_ops = {
38101+static const struct sysfs_ops veth_port_sysfs_ops = {
38102 .show = veth_port_attribute_show
38103 };
38104
38105diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
38106index 8aa44dc..fa1e797 100644
38107--- a/drivers/net/ixgb/ixgb_main.c
38108+++ b/drivers/net/ixgb/ixgb_main.c
38109@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev)
38110 u32 rctl;
38111 int i;
38112
38113+ pax_track_stack();
38114+
38115 /* Check for Promiscuous and All Multicast modes */
38116
38117 rctl = IXGB_READ_REG(hw, RCTL);
38118diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
38119index af35e1d..8781785 100644
38120--- a/drivers/net/ixgb/ixgb_param.c
38121+++ b/drivers/net/ixgb/ixgb_param.c
38122@@ -260,6 +260,9 @@ void __devinit
38123 ixgb_check_options(struct ixgb_adapter *adapter)
38124 {
38125 int bd = adapter->bd_number;
38126+
38127+ pax_track_stack();
38128+
38129 if (bd >= IXGB_MAX_NIC) {
38130 printk(KERN_NOTICE
38131 "Warning: no configuration for board #%i\n", bd);
38132diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
38133index b17aa73..ed74540 100644
38134--- a/drivers/net/ixgbe/ixgbe_type.h
38135+++ b/drivers/net/ixgbe/ixgbe_type.h
38136@@ -2327,6 +2327,7 @@ struct ixgbe_eeprom_operations {
38137 s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
38138 s32 (*update_checksum)(struct ixgbe_hw *);
38139 };
38140+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
38141
38142 struct ixgbe_mac_operations {
38143 s32 (*init_hw)(struct ixgbe_hw *);
38144@@ -2376,6 +2377,7 @@ struct ixgbe_mac_operations {
38145 /* Flow Control */
38146 s32 (*fc_enable)(struct ixgbe_hw *, s32);
38147 };
38148+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
38149
38150 struct ixgbe_phy_operations {
38151 s32 (*identify)(struct ixgbe_hw *);
38152@@ -2394,9 +2396,10 @@ struct ixgbe_phy_operations {
38153 s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
38154 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
38155 };
38156+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
38157
38158 struct ixgbe_eeprom_info {
38159- struct ixgbe_eeprom_operations ops;
38160+ ixgbe_eeprom_operations_no_const ops;
38161 enum ixgbe_eeprom_type type;
38162 u32 semaphore_delay;
38163 u16 word_size;
38164@@ -2404,7 +2407,7 @@ struct ixgbe_eeprom_info {
38165 };
38166
38167 struct ixgbe_mac_info {
38168- struct ixgbe_mac_operations ops;
38169+ ixgbe_mac_operations_no_const ops;
38170 enum ixgbe_mac_type type;
38171 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38172 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38173@@ -2423,7 +2426,7 @@ struct ixgbe_mac_info {
38174 };
38175
38176 struct ixgbe_phy_info {
38177- struct ixgbe_phy_operations ops;
38178+ ixgbe_phy_operations_no_const ops;
38179 struct mdio_if_info mdio;
38180 enum ixgbe_phy_type type;
38181 u32 id;
38182diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
38183index 291a505..2543756 100644
38184--- a/drivers/net/mlx4/main.c
38185+++ b/drivers/net/mlx4/main.c
38186@@ -38,6 +38,7 @@
38187 #include <linux/errno.h>
38188 #include <linux/pci.h>
38189 #include <linux/dma-mapping.h>
38190+#include <linux/sched.h>
38191
38192 #include <linux/mlx4/device.h>
38193 #include <linux/mlx4/doorbell.h>
38194@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
38195 u64 icm_size;
38196 int err;
38197
38198+ pax_track_stack();
38199+
38200 err = mlx4_QUERY_FW(dev);
38201 if (err) {
38202 if (err == -EACCES)
38203diff --git a/drivers/net/niu.c b/drivers/net/niu.c
38204index 2dce134..fa5ce75 100644
38205--- a/drivers/net/niu.c
38206+++ b/drivers/net/niu.c
38207@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
38208 int i, num_irqs, err;
38209 u8 first_ldg;
38210
38211+ pax_track_stack();
38212+
38213 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
38214 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
38215 ldg_num_map[i] = first_ldg + i;
38216diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
38217index c1b3f09..97cd8c4 100644
38218--- a/drivers/net/pcnet32.c
38219+++ b/drivers/net/pcnet32.c
38220@@ -79,7 +79,7 @@ static int cards_found;
38221 /*
38222 * VLB I/O addresses
38223 */
38224-static unsigned int pcnet32_portlist[] __initdata =
38225+static unsigned int pcnet32_portlist[] __devinitdata =
38226 { 0x300, 0x320, 0x340, 0x360, 0 };
38227
38228 static int pcnet32_debug = 0;
38229@@ -267,7 +267,7 @@ struct pcnet32_private {
38230 struct sk_buff **rx_skbuff;
38231 dma_addr_t *tx_dma_addr;
38232 dma_addr_t *rx_dma_addr;
38233- struct pcnet32_access a;
38234+ struct pcnet32_access *a;
38235 spinlock_t lock; /* Guard lock */
38236 unsigned int cur_rx, cur_tx; /* The next free ring entry */
38237 unsigned int rx_ring_size; /* current rx ring size */
38238@@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct net_device *dev)
38239 u16 val;
38240
38241 netif_wake_queue(dev);
38242- val = lp->a.read_csr(ioaddr, CSR3);
38243+ val = lp->a->read_csr(ioaddr, CSR3);
38244 val &= 0x00ff;
38245- lp->a.write_csr(ioaddr, CSR3, val);
38246+ lp->a->write_csr(ioaddr, CSR3, val);
38247 napi_enable(&lp->napi);
38248 }
38249
38250@@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
38251 r = mii_link_ok(&lp->mii_if);
38252 } else if (lp->chip_version >= PCNET32_79C970A) {
38253 ulong ioaddr = dev->base_addr; /* card base I/O address */
38254- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38255+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38256 } else { /* can not detect link on really old chips */
38257 r = 1;
38258 }
38259@@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
38260 pcnet32_netif_stop(dev);
38261
38262 spin_lock_irqsave(&lp->lock, flags);
38263- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38264+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38265
38266 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
38267
38268@@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
38269 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38270 {
38271 struct pcnet32_private *lp = netdev_priv(dev);
38272- struct pcnet32_access *a = &lp->a; /* access to registers */
38273+ struct pcnet32_access *a = lp->a; /* access to registers */
38274 ulong ioaddr = dev->base_addr; /* card base I/O address */
38275 struct sk_buff *skb; /* sk buff */
38276 int x, i; /* counters */
38277@@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38278 pcnet32_netif_stop(dev);
38279
38280 spin_lock_irqsave(&lp->lock, flags);
38281- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38282+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38283
38284 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
38285
38286 /* Reset the PCNET32 */
38287- lp->a.reset(ioaddr);
38288- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38289+ lp->a->reset(ioaddr);
38290+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38291
38292 /* switch pcnet32 to 32bit mode */
38293- lp->a.write_bcr(ioaddr, 20, 2);
38294+ lp->a->write_bcr(ioaddr, 20, 2);
38295
38296 /* purge & init rings but don't actually restart */
38297 pcnet32_restart(dev, 0x0000);
38298
38299- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38300+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38301
38302 /* Initialize Transmit buffers. */
38303 size = data_len + 15;
38304@@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38305
38306 /* set int loopback in CSR15 */
38307 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
38308- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
38309+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
38310
38311 teststatus = cpu_to_le16(0x8000);
38312- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38313+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38314
38315 /* Check status of descriptors */
38316 for (x = 0; x < numbuffs; x++) {
38317@@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38318 }
38319 }
38320
38321- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38322+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38323 wmb();
38324 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
38325 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
38326@@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38327 pcnet32_restart(dev, CSR0_NORMAL);
38328 } else {
38329 pcnet32_purge_rx_ring(dev);
38330- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38331+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38332 }
38333 spin_unlock_irqrestore(&lp->lock, flags);
38334
38335@@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38336 static void pcnet32_led_blink_callback(struct net_device *dev)
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;
38344@@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(struct net_device *dev)
38345 static int pcnet32_phys_id(struct net_device *dev, u32 data)
38346 {
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 unsigned long flags;
38352 int i, regs[4];
38353@@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
38354 {
38355 int csr5;
38356 struct pcnet32_private *lp = netdev_priv(dev);
38357- struct pcnet32_access *a = &lp->a;
38358+ struct pcnet32_access *a = lp->a;
38359 ulong ioaddr = dev->base_addr;
38360 int ticks;
38361
38362@@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38363 spin_lock_irqsave(&lp->lock, flags);
38364 if (pcnet32_tx(dev)) {
38365 /* reset the chip to clear the error condition, then restart */
38366- lp->a.reset(ioaddr);
38367- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38368+ lp->a->reset(ioaddr);
38369+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38370 pcnet32_restart(dev, CSR0_START);
38371 netif_wake_queue(dev);
38372 }
38373@@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38374 __napi_complete(napi);
38375
38376 /* clear interrupt masks */
38377- val = lp->a.read_csr(ioaddr, CSR3);
38378+ val = lp->a->read_csr(ioaddr, CSR3);
38379 val &= 0x00ff;
38380- lp->a.write_csr(ioaddr, CSR3, val);
38381+ lp->a->write_csr(ioaddr, CSR3, val);
38382
38383 /* Set interrupt enable. */
38384- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
38385+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
38386
38387 spin_unlock_irqrestore(&lp->lock, flags);
38388 }
38389@@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38390 int i, csr0;
38391 u16 *buff = ptr;
38392 struct pcnet32_private *lp = netdev_priv(dev);
38393- struct pcnet32_access *a = &lp->a;
38394+ struct pcnet32_access *a = lp->a;
38395 ulong ioaddr = dev->base_addr;
38396 unsigned long flags;
38397
38398@@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38399 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
38400 if (lp->phymask & (1 << j)) {
38401 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
38402- lp->a.write_bcr(ioaddr, 33,
38403+ lp->a->write_bcr(ioaddr, 33,
38404 (j << 5) | i);
38405- *buff++ = lp->a.read_bcr(ioaddr, 34);
38406+ *buff++ = lp->a->read_bcr(ioaddr, 34);
38407 }
38408 }
38409 }
38410@@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38411 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
38412 lp->options |= PCNET32_PORT_FD;
38413
38414- lp->a = *a;
38415+ lp->a = a;
38416
38417 /* prior to register_netdev, dev->name is not yet correct */
38418 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
38419@@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38420 if (lp->mii) {
38421 /* lp->phycount and lp->phymask are set to 0 by memset above */
38422
38423- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38424+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38425 /* scan for PHYs */
38426 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38427 unsigned short id1, id2;
38428@@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38429 "Found PHY %04x:%04x at address %d.\n",
38430 id1, id2, i);
38431 }
38432- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38433+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38434 if (lp->phycount > 1) {
38435 lp->options |= PCNET32_PORT_MII;
38436 }
38437@@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_device *dev)
38438 }
38439
38440 /* Reset the PCNET32 */
38441- lp->a.reset(ioaddr);
38442+ lp->a->reset(ioaddr);
38443
38444 /* switch pcnet32 to 32bit mode */
38445- lp->a.write_bcr(ioaddr, 20, 2);
38446+ lp->a->write_bcr(ioaddr, 20, 2);
38447
38448 if (netif_msg_ifup(lp))
38449 printk(KERN_DEBUG
38450@@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_device *dev)
38451 (u32) (lp->init_dma_addr));
38452
38453 /* set/reset autoselect bit */
38454- val = lp->a.read_bcr(ioaddr, 2) & ~2;
38455+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
38456 if (lp->options & PCNET32_PORT_ASEL)
38457 val |= 2;
38458- lp->a.write_bcr(ioaddr, 2, val);
38459+ lp->a->write_bcr(ioaddr, 2, val);
38460
38461 /* handle full duplex setting */
38462 if (lp->mii_if.full_duplex) {
38463- val = lp->a.read_bcr(ioaddr, 9) & ~3;
38464+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
38465 if (lp->options & PCNET32_PORT_FD) {
38466 val |= 1;
38467 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
38468@@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_device *dev)
38469 if (lp->chip_version == 0x2627)
38470 val |= 3;
38471 }
38472- lp->a.write_bcr(ioaddr, 9, val);
38473+ lp->a->write_bcr(ioaddr, 9, val);
38474 }
38475
38476 /* set/reset GPSI bit in test register */
38477- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
38478+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
38479 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
38480 val |= 0x10;
38481- lp->a.write_csr(ioaddr, 124, val);
38482+ lp->a->write_csr(ioaddr, 124, val);
38483
38484 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
38485 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
38486@@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_device *dev)
38487 * duplex, and/or enable auto negotiation, and clear DANAS
38488 */
38489 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
38490- lp->a.write_bcr(ioaddr, 32,
38491- lp->a.read_bcr(ioaddr, 32) | 0x0080);
38492+ lp->a->write_bcr(ioaddr, 32,
38493+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
38494 /* disable Auto Negotiation, set 10Mpbs, HD */
38495- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
38496+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
38497 if (lp->options & PCNET32_PORT_FD)
38498 val |= 0x10;
38499 if (lp->options & PCNET32_PORT_100)
38500 val |= 0x08;
38501- lp->a.write_bcr(ioaddr, 32, val);
38502+ lp->a->write_bcr(ioaddr, 32, val);
38503 } else {
38504 if (lp->options & PCNET32_PORT_ASEL) {
38505- lp->a.write_bcr(ioaddr, 32,
38506- lp->a.read_bcr(ioaddr,
38507+ lp->a->write_bcr(ioaddr, 32,
38508+ lp->a->read_bcr(ioaddr,
38509 32) | 0x0080);
38510 /* enable auto negotiate, setup, disable fd */
38511- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
38512+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
38513 val |= 0x20;
38514- lp->a.write_bcr(ioaddr, 32, val);
38515+ lp->a->write_bcr(ioaddr, 32, val);
38516 }
38517 }
38518 } else {
38519@@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_device *dev)
38520 * There is really no good other way to handle multiple PHYs
38521 * other than turning off all automatics
38522 */
38523- val = lp->a.read_bcr(ioaddr, 2);
38524- lp->a.write_bcr(ioaddr, 2, val & ~2);
38525- val = lp->a.read_bcr(ioaddr, 32);
38526- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38527+ val = lp->a->read_bcr(ioaddr, 2);
38528+ lp->a->write_bcr(ioaddr, 2, val & ~2);
38529+ val = lp->a->read_bcr(ioaddr, 32);
38530+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38531
38532 if (!(lp->options & PCNET32_PORT_ASEL)) {
38533 /* setup ecmd */
38534@@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_device *dev)
38535 ecmd.speed =
38536 lp->
38537 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
38538- bcr9 = lp->a.read_bcr(ioaddr, 9);
38539+ bcr9 = lp->a->read_bcr(ioaddr, 9);
38540
38541 if (lp->options & PCNET32_PORT_FD) {
38542 ecmd.duplex = DUPLEX_FULL;
38543@@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_device *dev)
38544 ecmd.duplex = DUPLEX_HALF;
38545 bcr9 |= ~(1 << 0);
38546 }
38547- lp->a.write_bcr(ioaddr, 9, bcr9);
38548+ lp->a->write_bcr(ioaddr, 9, bcr9);
38549 }
38550
38551 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38552@@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_device *dev)
38553
38554 #ifdef DO_DXSUFLO
38555 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
38556- val = lp->a.read_csr(ioaddr, CSR3);
38557+ val = lp->a->read_csr(ioaddr, CSR3);
38558 val |= 0x40;
38559- lp->a.write_csr(ioaddr, CSR3, val);
38560+ lp->a->write_csr(ioaddr, CSR3, val);
38561 }
38562 #endif
38563
38564@@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_device *dev)
38565 napi_enable(&lp->napi);
38566
38567 /* Re-initialize the PCNET32, and start it when done. */
38568- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38569- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38570+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38571+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38572
38573- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38574- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38575+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38576+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38577
38578 netif_start_queue(dev);
38579
38580@@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_device *dev)
38581
38582 i = 0;
38583 while (i++ < 100)
38584- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38585+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38586 break;
38587 /*
38588 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
38589 * reports that doing so triggers a bug in the '974.
38590 */
38591- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
38592+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
38593
38594 if (netif_msg_ifup(lp))
38595 printk(KERN_DEBUG
38596 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
38597 dev->name, i,
38598 (u32) (lp->init_dma_addr),
38599- lp->a.read_csr(ioaddr, CSR0));
38600+ lp->a->read_csr(ioaddr, CSR0));
38601
38602 spin_unlock_irqrestore(&lp->lock, flags);
38603
38604@@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_device *dev)
38605 * Switch back to 16bit mode to avoid problems with dumb
38606 * DOS packet driver after a warm reboot
38607 */
38608- lp->a.write_bcr(ioaddr, 20, 4);
38609+ lp->a->write_bcr(ioaddr, 20, 4);
38610
38611 err_free_irq:
38612 spin_unlock_irqrestore(&lp->lock, flags);
38613@@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38614
38615 /* wait for stop */
38616 for (i = 0; i < 100; i++)
38617- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
38618+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
38619 break;
38620
38621 if (i >= 100 && netif_msg_drv(lp))
38622@@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38623 return;
38624
38625 /* ReInit Ring */
38626- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38627+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38628 i = 0;
38629 while (i++ < 1000)
38630- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38631+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38632 break;
38633
38634- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
38635+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
38636 }
38637
38638 static void pcnet32_tx_timeout(struct net_device *dev)
38639@@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
38640 if (pcnet32_debug & NETIF_MSG_DRV)
38641 printk(KERN_ERR
38642 "%s: transmit timed out, status %4.4x, resetting.\n",
38643- dev->name, lp->a.read_csr(ioaddr, CSR0));
38644- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38645+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38646+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38647 dev->stats.tx_errors++;
38648 if (netif_msg_tx_err(lp)) {
38649 int i;
38650@@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38651 if (netif_msg_tx_queued(lp)) {
38652 printk(KERN_DEBUG
38653 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
38654- dev->name, lp->a.read_csr(ioaddr, CSR0));
38655+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38656 }
38657
38658 /* Default status -- will not enable Successful-TxDone
38659@@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38660 dev->stats.tx_bytes += skb->len;
38661
38662 /* Trigger an immediate send poll. */
38663- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38664+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38665
38666 dev->trans_start = jiffies;
38667
38668@@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
38669
38670 spin_lock(&lp->lock);
38671
38672- csr0 = lp->a.read_csr(ioaddr, CSR0);
38673+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38674 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
38675 if (csr0 == 0xffff) {
38676 break; /* PCMCIA remove happened */
38677 }
38678 /* Acknowledge all of the current interrupt sources ASAP. */
38679- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38680+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38681
38682 if (netif_msg_intr(lp))
38683 printk(KERN_DEBUG
38684 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
38685- dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
38686+ dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
38687
38688 /* Log misc errors. */
38689 if (csr0 & 0x4000)
38690@@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
38691 if (napi_schedule_prep(&lp->napi)) {
38692 u16 val;
38693 /* set interrupt masks */
38694- val = lp->a.read_csr(ioaddr, CSR3);
38695+ val = lp->a->read_csr(ioaddr, CSR3);
38696 val |= 0x5f00;
38697- lp->a.write_csr(ioaddr, CSR3, val);
38698+ lp->a->write_csr(ioaddr, CSR3, val);
38699
38700 __napi_schedule(&lp->napi);
38701 break;
38702 }
38703- csr0 = lp->a.read_csr(ioaddr, CSR0);
38704+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38705 }
38706
38707 if (netif_msg_intr(lp))
38708 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
38709- dev->name, lp->a.read_csr(ioaddr, CSR0));
38710+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38711
38712 spin_unlock(&lp->lock);
38713
38714@@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_device *dev)
38715
38716 spin_lock_irqsave(&lp->lock, flags);
38717
38718- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38719+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38720
38721 if (netif_msg_ifdown(lp))
38722 printk(KERN_DEBUG
38723 "%s: Shutting down ethercard, status was %2.2x.\n",
38724- dev->name, lp->a.read_csr(ioaddr, CSR0));
38725+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38726
38727 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
38728- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38729+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38730
38731 /*
38732 * Switch back to 16bit mode to avoid problems with dumb
38733 * DOS packet driver after a warm reboot
38734 */
38735- lp->a.write_bcr(ioaddr, 20, 4);
38736+ lp->a->write_bcr(ioaddr, 20, 4);
38737
38738 spin_unlock_irqrestore(&lp->lock, flags);
38739
38740@@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
38741 unsigned long flags;
38742
38743 spin_lock_irqsave(&lp->lock, flags);
38744- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38745+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38746 spin_unlock_irqrestore(&lp->lock, flags);
38747
38748 return &dev->stats;
38749@@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
38750 if (dev->flags & IFF_ALLMULTI) {
38751 ib->filter[0] = cpu_to_le32(~0U);
38752 ib->filter[1] = cpu_to_le32(~0U);
38753- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38754- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38755- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38756- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38757+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38758+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38759+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38760+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38761 return;
38762 }
38763 /* clear the multicast filter */
38764@@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
38765 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
38766 }
38767 for (i = 0; i < 4; i++)
38768- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
38769+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
38770 le16_to_cpu(mcast_table[i]));
38771 return;
38772 }
38773@@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38774
38775 spin_lock_irqsave(&lp->lock, flags);
38776 suspended = pcnet32_suspend(dev, &flags, 0);
38777- csr15 = lp->a.read_csr(ioaddr, CSR15);
38778+ csr15 = lp->a->read_csr(ioaddr, CSR15);
38779 if (dev->flags & IFF_PROMISC) {
38780 /* Log any net taps. */
38781 if (netif_msg_hw(lp))
38782@@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38783 lp->init_block->mode =
38784 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
38785 7);
38786- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
38787+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
38788 } else {
38789 lp->init_block->mode =
38790 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
38791- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38792+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38793 pcnet32_load_multicast(dev);
38794 }
38795
38796 if (suspended) {
38797 int csr5;
38798 /* clear SUSPEND (SPND) - CSR5 bit 0 */
38799- csr5 = lp->a.read_csr(ioaddr, CSR5);
38800- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38801+ csr5 = lp->a->read_csr(ioaddr, CSR5);
38802+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38803 } else {
38804- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38805+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38806 pcnet32_restart(dev, CSR0_NORMAL);
38807 netif_wake_queue(dev);
38808 }
38809@@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
38810 if (!lp->mii)
38811 return 0;
38812
38813- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38814- val_out = lp->a.read_bcr(ioaddr, 34);
38815+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38816+ val_out = lp->a->read_bcr(ioaddr, 34);
38817
38818 return val_out;
38819 }
38820@@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
38821 if (!lp->mii)
38822 return;
38823
38824- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38825- lp->a.write_bcr(ioaddr, 34, val);
38826+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38827+ lp->a->write_bcr(ioaddr, 34, val);
38828 }
38829
38830 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38831@@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38832 curr_link = mii_link_ok(&lp->mii_if);
38833 } else {
38834 ulong ioaddr = dev->base_addr; /* card base I/O address */
38835- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38836+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38837 }
38838 if (!curr_link) {
38839 if (prev_link || verbose) {
38840@@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38841 (ecmd.duplex ==
38842 DUPLEX_FULL) ? "full" : "half");
38843 }
38844- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
38845+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
38846 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
38847 if (lp->mii_if.full_duplex)
38848 bcr9 |= (1 << 0);
38849 else
38850 bcr9 &= ~(1 << 0);
38851- lp->a.write_bcr(dev->base_addr, 9, bcr9);
38852+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
38853 }
38854 } else {
38855 if (netif_msg_link(lp))
38856diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
38857index 7cc9898..6eb50d3 100644
38858--- a/drivers/net/sis190.c
38859+++ b/drivers/net/sis190.c
38860@@ -1598,7 +1598,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
38861 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
38862 struct net_device *dev)
38863 {
38864- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
38865+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
38866 struct sis190_private *tp = netdev_priv(dev);
38867 struct pci_dev *isa_bridge;
38868 u8 reg, tmp8;
38869diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
38870index e13685a..60c948c 100644
38871--- a/drivers/net/sundance.c
38872+++ b/drivers/net/sundance.c
38873@@ -225,7 +225,7 @@ enum {
38874 struct pci_id_info {
38875 const char *name;
38876 };
38877-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
38878+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
38879 {"D-Link DFE-550TX FAST Ethernet Adapter"},
38880 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
38881 {"D-Link DFE-580TX 4 port Server Adapter"},
38882diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
38883index 529f55a..cccaa18 100644
38884--- a/drivers/net/tg3.h
38885+++ b/drivers/net/tg3.h
38886@@ -95,6 +95,7 @@
38887 #define CHIPREV_ID_5750_A0 0x4000
38888 #define CHIPREV_ID_5750_A1 0x4001
38889 #define CHIPREV_ID_5750_A3 0x4003
38890+#define CHIPREV_ID_5750_C1 0x4201
38891 #define CHIPREV_ID_5750_C2 0x4202
38892 #define CHIPREV_ID_5752_A0_HW 0x5000
38893 #define CHIPREV_ID_5752_A0 0x6000
38894diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
38895index b9db1b5..720f9ce 100644
38896--- a/drivers/net/tokenring/abyss.c
38897+++ b/drivers/net/tokenring/abyss.c
38898@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
38899
38900 static int __init abyss_init (void)
38901 {
38902- abyss_netdev_ops = tms380tr_netdev_ops;
38903+ pax_open_kernel();
38904+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38905
38906- abyss_netdev_ops.ndo_open = abyss_open;
38907- abyss_netdev_ops.ndo_stop = abyss_close;
38908+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
38909+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
38910+ pax_close_kernel();
38911
38912 return pci_register_driver(&abyss_driver);
38913 }
38914diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
38915index 456f8bf..373e56d 100644
38916--- a/drivers/net/tokenring/madgemc.c
38917+++ b/drivers/net/tokenring/madgemc.c
38918@@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver = {
38919
38920 static int __init madgemc_init (void)
38921 {
38922- madgemc_netdev_ops = tms380tr_netdev_ops;
38923- madgemc_netdev_ops.ndo_open = madgemc_open;
38924- madgemc_netdev_ops.ndo_stop = madgemc_close;
38925+ pax_open_kernel();
38926+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38927+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
38928+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
38929+ pax_close_kernel();
38930
38931 return mca_register_driver (&madgemc_driver);
38932 }
38933diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
38934index 16e8783..925bd49 100644
38935--- a/drivers/net/tokenring/proteon.c
38936+++ b/drivers/net/tokenring/proteon.c
38937@@ -353,9 +353,11 @@ static int __init proteon_init(void)
38938 struct platform_device *pdev;
38939 int i, num = 0, err = 0;
38940
38941- proteon_netdev_ops = tms380tr_netdev_ops;
38942- proteon_netdev_ops.ndo_open = proteon_open;
38943- proteon_netdev_ops.ndo_stop = tms380tr_close;
38944+ pax_open_kernel();
38945+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38946+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
38947+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
38948+ pax_close_kernel();
38949
38950 err = platform_driver_register(&proteon_driver);
38951 if (err)
38952diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
38953index 46db5c5..37c1536 100644
38954--- a/drivers/net/tokenring/skisa.c
38955+++ b/drivers/net/tokenring/skisa.c
38956@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
38957 struct platform_device *pdev;
38958 int i, num = 0, err = 0;
38959
38960- sk_isa_netdev_ops = tms380tr_netdev_ops;
38961- sk_isa_netdev_ops.ndo_open = sk_isa_open;
38962- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
38963+ pax_open_kernel();
38964+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38965+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
38966+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
38967+ pax_close_kernel();
38968
38969 err = platform_driver_register(&sk_isa_driver);
38970 if (err)
38971diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
38972index 74e5ba4..5cf6bc9 100644
38973--- a/drivers/net/tulip/de2104x.c
38974+++ b/drivers/net/tulip/de2104x.c
38975@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
38976 struct de_srom_info_leaf *il;
38977 void *bufp;
38978
38979+ pax_track_stack();
38980+
38981 /* download entire eeprom */
38982 for (i = 0; i < DE_EEPROM_WORDS; i++)
38983 ((__le16 *)ee_data)[i] =
38984diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
38985index a8349b7..90f9dfe 100644
38986--- a/drivers/net/tulip/de4x5.c
38987+++ b/drivers/net/tulip/de4x5.c
38988@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38989 for (i=0; i<ETH_ALEN; i++) {
38990 tmp.addr[i] = dev->dev_addr[i];
38991 }
38992- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38993+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38994 break;
38995
38996 case DE4X5_SET_HWADDR: /* Set the hardware address */
38997@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38998 spin_lock_irqsave(&lp->lock, flags);
38999 memcpy(&statbuf, &lp->pktStats, ioc->len);
39000 spin_unlock_irqrestore(&lp->lock, flags);
39001- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39002+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39003 return -EFAULT;
39004 break;
39005 }
39006diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
39007index 391acd3..56d11cd 100644
39008--- a/drivers/net/tulip/eeprom.c
39009+++ b/drivers/net/tulip/eeprom.c
39010@@ -80,7 +80,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
39011 {NULL}};
39012
39013
39014-static const char *block_name[] __devinitdata = {
39015+static const char *block_name[] __devinitconst = {
39016 "21140 non-MII",
39017 "21140 MII PHY",
39018 "21142 Serial PHY",
39019diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
39020index b38d3b7..b1cff23 100644
39021--- a/drivers/net/tulip/winbond-840.c
39022+++ b/drivers/net/tulip/winbond-840.c
39023@@ -235,7 +235,7 @@ struct pci_id_info {
39024 int drv_flags; /* Driver use, intended as capability flags. */
39025 };
39026
39027-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
39028+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
39029 { /* Sometime a Level-One switch card. */
39030 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
39031 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
39032diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39033index f450bc9..2b747c8 100644
39034--- a/drivers/net/usb/hso.c
39035+++ b/drivers/net/usb/hso.c
39036@@ -71,7 +71,7 @@
39037 #include <asm/byteorder.h>
39038 #include <linux/serial_core.h>
39039 #include <linux/serial.h>
39040-
39041+#include <asm/local.h>
39042
39043 #define DRIVER_VERSION "1.2"
39044 #define MOD_AUTHOR "Option Wireless"
39045@@ -258,7 +258,7 @@ struct hso_serial {
39046
39047 /* from usb_serial_port */
39048 struct tty_struct *tty;
39049- int open_count;
39050+ local_t open_count;
39051 spinlock_t serial_lock;
39052
39053 int (*write_data) (struct hso_serial *serial);
39054@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39055 struct urb *urb;
39056
39057 urb = serial->rx_urb[0];
39058- if (serial->open_count > 0) {
39059+ if (local_read(&serial->open_count) > 0) {
39060 count = put_rxbuf_data(urb, serial);
39061 if (count == -1)
39062 return;
39063@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39064 DUMP1(urb->transfer_buffer, urb->actual_length);
39065
39066 /* Anyone listening? */
39067- if (serial->open_count == 0)
39068+ if (local_read(&serial->open_count) == 0)
39069 return;
39070
39071 if (status == 0) {
39072@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39073 spin_unlock_irq(&serial->serial_lock);
39074
39075 /* check for port already opened, if not set the termios */
39076- serial->open_count++;
39077- if (serial->open_count == 1) {
39078+ if (local_inc_return(&serial->open_count) == 1) {
39079 tty->low_latency = 1;
39080 serial->rx_state = RX_IDLE;
39081 /* Force default termio settings */
39082@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39083 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39084 if (result) {
39085 hso_stop_serial_device(serial->parent);
39086- serial->open_count--;
39087+ local_dec(&serial->open_count);
39088 kref_put(&serial->parent->ref, hso_serial_ref_free);
39089 }
39090 } else {
39091@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39092
39093 /* reset the rts and dtr */
39094 /* do the actual close */
39095- serial->open_count--;
39096+ local_dec(&serial->open_count);
39097
39098- if (serial->open_count <= 0) {
39099- serial->open_count = 0;
39100+ if (local_read(&serial->open_count) <= 0) {
39101+ local_set(&serial->open_count, 0);
39102 spin_lock_irq(&serial->serial_lock);
39103 if (serial->tty == tty) {
39104 serial->tty->driver_data = NULL;
39105@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39106
39107 /* the actual setup */
39108 spin_lock_irqsave(&serial->serial_lock, flags);
39109- if (serial->open_count)
39110+ if (local_read(&serial->open_count))
39111 _hso_serial_set_termios(tty, old);
39112 else
39113 tty->termios = old;
39114@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interface *iface)
39115 /* Start all serial ports */
39116 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39117 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39118- if (dev2ser(serial_table[i])->open_count) {
39119+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
39120 result =
39121 hso_start_serial_device(serial_table[i], GFP_NOIO);
39122 hso_kick_transmit(dev2ser(serial_table[i]));
39123diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
39124index 3e94f0c..ffdd926 100644
39125--- a/drivers/net/vxge/vxge-config.h
39126+++ b/drivers/net/vxge/vxge-config.h
39127@@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
39128 void (*link_down)(struct __vxge_hw_device *devh);
39129 void (*crit_err)(struct __vxge_hw_device *devh,
39130 enum vxge_hw_event type, u64 ext_data);
39131-};
39132+} __no_const;
39133
39134 /*
39135 * struct __vxge_hw_blockpool_entry - Block private data structure
39136diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
39137index 068d7a9..35293de 100644
39138--- a/drivers/net/vxge/vxge-main.c
39139+++ b/drivers/net/vxge/vxge-main.c
39140@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
39141 struct sk_buff *completed[NR_SKB_COMPLETED];
39142 int more;
39143
39144+ pax_track_stack();
39145+
39146 do {
39147 more = 0;
39148 skb_ptr = completed;
39149@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
39150 u8 mtable[256] = {0}; /* CPU to vpath mapping */
39151 int index;
39152
39153+ pax_track_stack();
39154+
39155 /*
39156 * Filling
39157 * - itable with bucket numbers
39158diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
39159index 461742b..81be42e 100644
39160--- a/drivers/net/vxge/vxge-traffic.h
39161+++ b/drivers/net/vxge/vxge-traffic.h
39162@@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
39163 struct vxge_hw_mempool_dma *dma_object,
39164 u32 index,
39165 u32 is_last);
39166-};
39167+} __no_const;
39168
39169 void
39170 __vxge_hw_mempool_destroy(
39171diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
39172index cd8cb95..4153b79 100644
39173--- a/drivers/net/wan/cycx_x25.c
39174+++ b/drivers/net/wan/cycx_x25.c
39175@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned char *p, int len)
39176 unsigned char hex[1024],
39177 * phex = hex;
39178
39179+ pax_track_stack();
39180+
39181 if (len >= (sizeof(hex) / 2))
39182 len = (sizeof(hex) / 2) - 1;
39183
39184diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
39185index aa9248f..a4e3c3b 100644
39186--- a/drivers/net/wan/hdlc_x25.c
39187+++ b/drivers/net/wan/hdlc_x25.c
39188@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
39189
39190 static int x25_open(struct net_device *dev)
39191 {
39192- struct lapb_register_struct cb;
39193+ static struct lapb_register_struct cb = {
39194+ .connect_confirmation = x25_connected,
39195+ .connect_indication = x25_connected,
39196+ .disconnect_confirmation = x25_disconnected,
39197+ .disconnect_indication = x25_disconnected,
39198+ .data_indication = x25_data_indication,
39199+ .data_transmit = x25_data_transmit
39200+ };
39201 int result;
39202
39203- cb.connect_confirmation = x25_connected;
39204- cb.connect_indication = x25_connected;
39205- cb.disconnect_confirmation = x25_disconnected;
39206- cb.disconnect_indication = x25_disconnected;
39207- cb.data_indication = x25_data_indication;
39208- cb.data_transmit = x25_data_transmit;
39209-
39210 result = lapb_register(dev, &cb);
39211 if (result != LAPB_OK)
39212 return result;
39213diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
39214index 5ad287c..783b020 100644
39215--- a/drivers/net/wimax/i2400m/usb-fw.c
39216+++ b/drivers/net/wimax/i2400m/usb-fw.c
39217@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
39218 int do_autopm = 1;
39219 DECLARE_COMPLETION_ONSTACK(notif_completion);
39220
39221+ pax_track_stack();
39222+
39223 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
39224 i2400m, ack, ack_size);
39225 BUG_ON(_ack == i2400m->bm_ack_buf);
39226diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
39227index 6c26840..62c97c3 100644
39228--- a/drivers/net/wireless/airo.c
39229+++ b/drivers/net/wireless/airo.c
39230@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
39231 BSSListElement * loop_net;
39232 BSSListElement * tmp_net;
39233
39234+ pax_track_stack();
39235+
39236 /* Blow away current list of scan results */
39237 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
39238 list_move_tail (&loop_net->list, &ai->network_free_list);
39239@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
39240 WepKeyRid wkr;
39241 int rc;
39242
39243+ pax_track_stack();
39244+
39245 memset( &mySsid, 0, sizeof( mySsid ) );
39246 kfree (ai->flash);
39247 ai->flash = NULL;
39248@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct inode *inode,
39249 __le32 *vals = stats.vals;
39250 int len;
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@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
39258 /* If doLoseSync is not 1, we won't do a Lose Sync */
39259 int doLoseSync = -1;
39260
39261+ pax_track_stack();
39262+
39263 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39264 return -ENOMEM;
39265 data = (struct proc_data *)file->private_data;
39266@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_device *dev,
39267 int i;
39268 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
39269
39270+ pax_track_stack();
39271+
39272 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
39273 if (!qual)
39274 return -ENOMEM;
39275@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
39276 CapabilityRid cap_rid;
39277 __le32 *vals = stats_rid.vals;
39278
39279+ pax_track_stack();
39280+
39281 /* Get stats out of the card */
39282 clear_bit(JOB_WSTATS, &local->jobs);
39283 if (local->power.event) {
39284diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
39285index 747508c..82e965d 100644
39286--- a/drivers/net/wireless/ath/ath5k/debug.c
39287+++ b/drivers/net/wireless/ath/ath5k/debug.c
39288@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
39289 unsigned int v;
39290 u64 tsf;
39291
39292+ pax_track_stack();
39293+
39294 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
39295 len += snprintf(buf+len, sizeof(buf)-len,
39296 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
39297@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
39298 unsigned int len = 0;
39299 unsigned int i;
39300
39301+ pax_track_stack();
39302+
39303 len += snprintf(buf+len, sizeof(buf)-len,
39304 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
39305
39306diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
39307index 2be4c22..593b1eb 100644
39308--- a/drivers/net/wireless/ath/ath9k/debug.c
39309+++ b/drivers/net/wireless/ath/ath9k/debug.c
39310@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
39311 char buf[512];
39312 unsigned int len = 0;
39313
39314+ pax_track_stack();
39315+
39316 len += snprintf(buf + len, sizeof(buf) - len,
39317 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
39318 len += snprintf(buf + len, sizeof(buf) - len,
39319@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
39320 int i;
39321 u8 addr[ETH_ALEN];
39322
39323+ pax_track_stack();
39324+
39325 len += snprintf(buf + len, sizeof(buf) - len,
39326 "primary: %s (%s chan=%d ht=%d)\n",
39327 wiphy_name(sc->pri_wiphy->hw->wiphy),
39328diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
39329index 80b19a4..dab3a45 100644
39330--- a/drivers/net/wireless/b43/debugfs.c
39331+++ b/drivers/net/wireless/b43/debugfs.c
39332@@ -43,7 +43,7 @@ static struct dentry *rootdir;
39333 struct b43_debugfs_fops {
39334 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
39335 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
39336- struct file_operations fops;
39337+ const struct file_operations fops;
39338 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
39339 size_t file_struct_offset;
39340 };
39341diff --git a/drivers/net/wireless/b43legacy/debugfs.c b/drivers/net/wireless/b43legacy/debugfs.c
39342index 1f85ac5..c99b4b4 100644
39343--- a/drivers/net/wireless/b43legacy/debugfs.c
39344+++ b/drivers/net/wireless/b43legacy/debugfs.c
39345@@ -44,7 +44,7 @@ static struct dentry *rootdir;
39346 struct b43legacy_debugfs_fops {
39347 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
39348 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
39349- struct file_operations fops;
39350+ const struct file_operations fops;
39351 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
39352 size_t file_struct_offset;
39353 /* Take wl->irq_lock before calling read/write? */
39354diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
39355index 43102bf..3b569c3 100644
39356--- a/drivers/net/wireless/ipw2x00/ipw2100.c
39357+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
39358@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
39359 int err;
39360 DECLARE_SSID_BUF(ssid);
39361
39362+ pax_track_stack();
39363+
39364 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
39365
39366 if (ssid_len)
39367@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
39368 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
39369 int err;
39370
39371+ pax_track_stack();
39372+
39373 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
39374 idx, keylen, len);
39375
39376diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
39377index 282b1f7..169f0cf 100644
39378--- a/drivers/net/wireless/ipw2x00/libipw_rx.c
39379+++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
39380@@ -1566,6 +1566,8 @@ static void libipw_process_probe_response(struct libipw_device
39381 unsigned long flags;
39382 DECLARE_SSID_BUF(ssid);
39383
39384+ pax_track_stack();
39385+
39386 LIBIPW_DEBUG_SCAN("'%s' (%pM"
39387 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
39388 print_ssid(ssid, info_element->data, info_element->len),
39389diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
39390index 950267a..80d5fd2 100644
39391--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
39392+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
39393@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib = {
39394 },
39395 };
39396
39397-static struct iwl_ops iwl1000_ops = {
39398+static const struct iwl_ops iwl1000_ops = {
39399 .ucode = &iwl5000_ucode,
39400 .lib = &iwl1000_lib,
39401 .hcmd = &iwl5000_hcmd,
39402diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
39403index 56bfcc3..b348020 100644
39404--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
39405+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
39406@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
39407 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
39408 };
39409
39410-static struct iwl_ops iwl3945_ops = {
39411+static const struct iwl_ops iwl3945_ops = {
39412 .ucode = &iwl3945_ucode,
39413 .lib = &iwl3945_lib,
39414 .hcmd = &iwl3945_hcmd,
39415diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
39416index 585b8d4..e142963 100644
39417--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
39418+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
39419@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib = {
39420 },
39421 };
39422
39423-static struct iwl_ops iwl4965_ops = {
39424+static const struct iwl_ops iwl4965_ops = {
39425 .ucode = &iwl4965_ucode,
39426 .lib = &iwl4965_lib,
39427 .hcmd = &iwl4965_hcmd,
39428diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
39429index 1f423f2..e37c192 100644
39430--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
39431+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
39432@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib = {
39433 },
39434 };
39435
39436-struct iwl_ops iwl5000_ops = {
39437+const struct iwl_ops iwl5000_ops = {
39438 .ucode = &iwl5000_ucode,
39439 .lib = &iwl5000_lib,
39440 .hcmd = &iwl5000_hcmd,
39441 .utils = &iwl5000_hcmd_utils,
39442 };
39443
39444-static struct iwl_ops iwl5150_ops = {
39445+static const struct iwl_ops iwl5150_ops = {
39446 .ucode = &iwl5000_ucode,
39447 .lib = &iwl5150_lib,
39448 .hcmd = &iwl5000_hcmd,
39449diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
39450index 1473452..f07d5e1 100644
39451--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
39452+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
39453@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000_hcmd_utils = {
39454 .calc_rssi = iwl5000_calc_rssi,
39455 };
39456
39457-static struct iwl_ops iwl6000_ops = {
39458+static const struct iwl_ops iwl6000_ops = {
39459 .ucode = &iwl5000_ucode,
39460 .lib = &iwl6000_lib,
39461 .hcmd = &iwl5000_hcmd,
39462diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39463index 1a3dfa2..b3e0a61 100644
39464--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39465+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39466@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
39467 u8 active_index = 0;
39468 s32 tpt = 0;
39469
39470+ pax_track_stack();
39471+
39472 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
39473
39474 if (!ieee80211_is_data(hdr->frame_control) ||
39475@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
39476 u8 valid_tx_ant = 0;
39477 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
39478
39479+ pax_track_stack();
39480+
39481 /* Override starting rate (index 0) if needed for debug purposes */
39482 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
39483
39484diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
39485index 0e56d78..6a3c107 100644
39486--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
39487+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
39488@@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39489 if (iwl_debug_level & IWL_DL_INFO)
39490 dev_printk(KERN_DEBUG, &(pdev->dev),
39491 "Disabling hw_scan\n");
39492- iwl_hw_ops.hw_scan = NULL;
39493+ pax_open_kernel();
39494+ *(void **)&iwl_hw_ops.hw_scan = NULL;
39495+ pax_close_kernel();
39496 }
39497
39498 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
39499diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
39500index cbc6290..eb323d7 100644
39501--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
39502+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
39503@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv);
39504 #endif
39505
39506 #else
39507-#define IWL_DEBUG(__priv, level, fmt, args...)
39508-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
39509+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
39510+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
39511 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
39512 void *p, u32 len)
39513 {}
39514diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39515index a198bcf..8e68233 100644
39516--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39517+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39518@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
39519 int pos = 0;
39520 const size_t bufsz = sizeof(buf);
39521
39522+ pax_track_stack();
39523+
39524 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
39525 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
39526 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
39527@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
39528 const size_t bufsz = sizeof(buf);
39529 ssize_t ret;
39530
39531+ pax_track_stack();
39532+
39533 for (i = 0; i < AC_NUM; i++) {
39534 pos += scnprintf(buf + pos, bufsz - pos,
39535 "\tcw_min\tcw_max\taifsn\ttxop\n");
39536diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
39537index 3539ea4..b174bfa 100644
39538--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
39539+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
39540@@ -68,7 +68,7 @@ struct iwl_tx_queue;
39541
39542 /* shared structures from iwl-5000.c */
39543 extern struct iwl_mod_params iwl50_mod_params;
39544-extern struct iwl_ops iwl5000_ops;
39545+extern const struct iwl_ops iwl5000_ops;
39546 extern struct iwl_ucode_ops iwl5000_ucode;
39547 extern struct iwl_lib_ops iwl5000_lib;
39548 extern struct iwl_hcmd_ops iwl5000_hcmd;
39549diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39550index 619590d..69235ee 100644
39551--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
39552+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39553@@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
39554 */
39555 if (iwl3945_mod_params.disable_hw_scan) {
39556 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
39557- iwl3945_hw_ops.hw_scan = NULL;
39558+ pax_open_kernel();
39559+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
39560+ pax_close_kernel();
39561 }
39562
39563
39564diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39565index 1465379..fe4d78b 100644
39566--- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
39567+++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39568@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
39569 int buf_len = 512;
39570 size_t len = 0;
39571
39572+ pax_track_stack();
39573+
39574 if (*ppos != 0)
39575 return 0;
39576 if (count < sizeof(buf))
39577diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
39578index 893a55c..7f66a50 100644
39579--- a/drivers/net/wireless/libertas/debugfs.c
39580+++ b/drivers/net/wireless/libertas/debugfs.c
39581@@ -708,7 +708,7 @@ out_unlock:
39582 struct lbs_debugfs_files {
39583 const char *name;
39584 int perm;
39585- struct file_operations fops;
39586+ const struct file_operations fops;
39587 };
39588
39589 static const struct lbs_debugfs_files debugfs_files[] = {
39590diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39591index 2ecbedb..42704f0 100644
39592--- a/drivers/net/wireless/rndis_wlan.c
39593+++ b/drivers/net/wireless/rndis_wlan.c
39594@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39595
39596 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
39597
39598- if (rts_threshold < 0 || rts_threshold > 2347)
39599+ if (rts_threshold > 2347)
39600 rts_threshold = 2347;
39601
39602 tmp = cpu_to_le32(rts_threshold);
39603diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39604index 5c4df24..3b42925 100644
39605--- a/drivers/oprofile/buffer_sync.c
39606+++ b/drivers/oprofile/buffer_sync.c
39607@@ -341,7 +341,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39608 if (cookie == NO_COOKIE)
39609 offset = pc;
39610 if (cookie == INVALID_COOKIE) {
39611- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39612+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39613 offset = pc;
39614 }
39615 if (cookie != last_cookie) {
39616@@ -385,14 +385,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39617 /* add userspace sample */
39618
39619 if (!mm) {
39620- atomic_inc(&oprofile_stats.sample_lost_no_mm);
39621+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39622 return 0;
39623 }
39624
39625 cookie = lookup_dcookie(mm, s->eip, &offset);
39626
39627 if (cookie == INVALID_COOKIE) {
39628- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39629+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39630 return 0;
39631 }
39632
39633@@ -561,7 +561,7 @@ void sync_buffer(int cpu)
39634 /* ignore backtraces if failed to add a sample */
39635 if (state == sb_bt_start) {
39636 state = sb_bt_ignore;
39637- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39638+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39639 }
39640 }
39641 release_mm(mm);
39642diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39643index 5df60a6..72f5c1c 100644
39644--- a/drivers/oprofile/event_buffer.c
39645+++ b/drivers/oprofile/event_buffer.c
39646@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39647 }
39648
39649 if (buffer_pos == buffer_size) {
39650- atomic_inc(&oprofile_stats.event_lost_overflow);
39651+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39652 return;
39653 }
39654
39655diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39656index dc8a042..fe5f315 100644
39657--- a/drivers/oprofile/oprof.c
39658+++ b/drivers/oprofile/oprof.c
39659@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39660 if (oprofile_ops.switch_events())
39661 return;
39662
39663- atomic_inc(&oprofile_stats.multiplex_counter);
39664+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39665 start_switch_worker();
39666 }
39667
39668diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39669index 61689e8..387f7f8 100644
39670--- a/drivers/oprofile/oprofile_stats.c
39671+++ b/drivers/oprofile/oprofile_stats.c
39672@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39673 cpu_buf->sample_invalid_eip = 0;
39674 }
39675
39676- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39677- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39678- atomic_set(&oprofile_stats.event_lost_overflow, 0);
39679- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39680- atomic_set(&oprofile_stats.multiplex_counter, 0);
39681+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39682+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39683+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39684+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39685+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39686 }
39687
39688
39689diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39690index 0b54e46..a37c527 100644
39691--- a/drivers/oprofile/oprofile_stats.h
39692+++ b/drivers/oprofile/oprofile_stats.h
39693@@ -13,11 +13,11 @@
39694 #include <asm/atomic.h>
39695
39696 struct oprofile_stat_struct {
39697- atomic_t sample_lost_no_mm;
39698- atomic_t sample_lost_no_mapping;
39699- atomic_t bt_lost_no_mapping;
39700- atomic_t event_lost_overflow;
39701- atomic_t multiplex_counter;
39702+ atomic_unchecked_t sample_lost_no_mm;
39703+ atomic_unchecked_t sample_lost_no_mapping;
39704+ atomic_unchecked_t bt_lost_no_mapping;
39705+ atomic_unchecked_t event_lost_overflow;
39706+ atomic_unchecked_t multiplex_counter;
39707 };
39708
39709 extern struct oprofile_stat_struct oprofile_stats;
39710diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39711index 2766a6d..80c77e2 100644
39712--- a/drivers/oprofile/oprofilefs.c
39713+++ b/drivers/oprofile/oprofilefs.c
39714@@ -187,7 +187,7 @@ static const struct file_operations atomic_ro_fops = {
39715
39716
39717 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39718- char const *name, atomic_t *val)
39719+ char const *name, atomic_unchecked_t *val)
39720 {
39721 struct dentry *d = __oprofilefs_create_file(sb, root, name,
39722 &atomic_ro_fops, 0444);
39723diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
39724index 13a64bc..ad62835 100644
39725--- a/drivers/parisc/pdc_stable.c
39726+++ b/drivers/parisc/pdc_stable.c
39727@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
39728 return ret;
39729 }
39730
39731-static struct sysfs_ops pdcspath_attr_ops = {
39732+static const struct sysfs_ops pdcspath_attr_ops = {
39733 .show = pdcspath_attr_show,
39734 .store = pdcspath_attr_store,
39735 };
39736diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39737index 8eefe56..40751a7 100644
39738--- a/drivers/parport/procfs.c
39739+++ b/drivers/parport/procfs.c
39740@@ -64,7 +64,7 @@ static int do_active_device(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
39748 #ifdef CONFIG_PARPORT_1284
39749@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39750
39751 *ppos += len;
39752
39753- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39754+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39755 }
39756 #endif /* IEEE1284.3 support. */
39757
39758diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
39759index 73e7d8e..c80f3d2 100644
39760--- a/drivers/pci/hotplug/acpiphp_glue.c
39761+++ b/drivers/pci/hotplug/acpiphp_glue.c
39762@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notifier_block *nb, unsigned long val,
39763 }
39764
39765
39766-static struct acpi_dock_ops acpiphp_dock_ops = {
39767+static const struct acpi_dock_ops acpiphp_dock_ops = {
39768 .handler = handle_hotplug_event_func,
39769 };
39770
39771diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
39772index 9fff878..ad0ad53 100644
39773--- a/drivers/pci/hotplug/cpci_hotplug.h
39774+++ b/drivers/pci/hotplug/cpci_hotplug.h
39775@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
39776 int (*hardware_test) (struct slot* slot, u32 value);
39777 u8 (*get_power) (struct slot* slot);
39778 int (*set_power) (struct slot* slot, int value);
39779-};
39780+} __no_const;
39781
39782 struct cpci_hp_controller {
39783 unsigned int irq;
39784diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
39785index 76ba8a1..20ca857 100644
39786--- a/drivers/pci/hotplug/cpqphp_nvram.c
39787+++ b/drivers/pci/hotplug/cpqphp_nvram.c
39788@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
39789
39790 void compaq_nvram_init (void __iomem *rom_start)
39791 {
39792+
39793+#ifndef CONFIG_PAX_KERNEXEC
39794 if (rom_start) {
39795 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
39796 }
39797+#endif
39798+
39799 dbg("int15 entry = %p\n", compaq_int15_entry_point);
39800
39801 /* initialize our int15 lock */
39802diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
39803index 6151389..0a894ef 100644
39804--- a/drivers/pci/hotplug/fakephp.c
39805+++ b/drivers/pci/hotplug/fakephp.c
39806@@ -73,7 +73,7 @@ static void legacy_release(struct kobject *kobj)
39807 }
39808
39809 static struct kobj_type legacy_ktype = {
39810- .sysfs_ops = &(struct sysfs_ops){
39811+ .sysfs_ops = &(const struct sysfs_ops){
39812 .store = legacy_store, .show = legacy_show
39813 },
39814 .release = &legacy_release,
39815diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
39816index 5b680df..fe05b7e 100644
39817--- a/drivers/pci/intel-iommu.c
39818+++ b/drivers/pci/intel-iommu.c
39819@@ -2643,7 +2643,7 @@ error:
39820 return 0;
39821 }
39822
39823-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
39824+dma_addr_t intel_map_page(struct device *dev, struct page *page,
39825 unsigned long offset, size_t size,
39826 enum dma_data_direction dir,
39827 struct dma_attrs *attrs)
39828@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
39829 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
39830 }
39831
39832-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39833+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39834 size_t size, enum dma_data_direction dir,
39835 struct dma_attrs *attrs)
39836 {
39837@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39838 }
39839 }
39840
39841-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39842+void *intel_alloc_coherent(struct device *hwdev, size_t size,
39843 dma_addr_t *dma_handle, gfp_t flags)
39844 {
39845 void *vaddr;
39846@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39847 return NULL;
39848 }
39849
39850-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39851+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39852 dma_addr_t dma_handle)
39853 {
39854 int order;
39855@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39856 free_pages((unsigned long)vaddr, order);
39857 }
39858
39859-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39860+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39861 int nelems, enum dma_data_direction dir,
39862 struct dma_attrs *attrs)
39863 {
39864@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(struct device *hddev,
39865 return nelems;
39866 }
39867
39868-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39869+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39870 enum dma_data_direction dir, struct dma_attrs *attrs)
39871 {
39872 int i;
39873@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
39874 return nelems;
39875 }
39876
39877-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39878+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39879 {
39880 return !dma_addr;
39881 }
39882
39883-struct dma_map_ops intel_dma_ops = {
39884+const struct dma_map_ops intel_dma_ops = {
39885 .alloc_coherent = intel_alloc_coherent,
39886 .free_coherent = intel_free_coherent,
39887 .map_sg = intel_map_sg,
39888diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
39889index 5b7056c..607bc94 100644
39890--- a/drivers/pci/pcie/aspm.c
39891+++ b/drivers/pci/pcie/aspm.c
39892@@ -27,9 +27,9 @@
39893 #define MODULE_PARAM_PREFIX "pcie_aspm."
39894
39895 /* Note: those are not register definitions */
39896-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
39897-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
39898-#define ASPM_STATE_L1 (4) /* L1 state */
39899+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
39900+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
39901+#define ASPM_STATE_L1 (4U) /* L1 state */
39902 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
39903 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
39904
39905diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
39906index 8105e32..ca10419 100644
39907--- a/drivers/pci/probe.c
39908+++ b/drivers/pci/probe.c
39909@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
39910 return ret;
39911 }
39912
39913-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
39914+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
39915 struct device_attribute *attr,
39916 char *buf)
39917 {
39918 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
39919 }
39920
39921-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
39922+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
39923 struct device_attribute *attr,
39924 char *buf)
39925 {
39926diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
39927index a03ad8c..024b0da 100644
39928--- a/drivers/pci/proc.c
39929+++ b/drivers/pci/proc.c
39930@@ -480,7 +480,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
39931 static int __init pci_proc_init(void)
39932 {
39933 struct pci_dev *dev = NULL;
39934+
39935+#ifdef CONFIG_GRKERNSEC_PROC_ADD
39936+#ifdef CONFIG_GRKERNSEC_PROC_USER
39937+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
39938+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
39939+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
39940+#endif
39941+#else
39942 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
39943+#endif
39944 proc_create("devices", 0, proc_bus_pci_dir,
39945 &proc_bus_pci_dev_operations);
39946 proc_initialized = 1;
39947diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
39948index 8c02b6c..5584d8e 100644
39949--- a/drivers/pci/slot.c
39950+++ b/drivers/pci/slot.c
39951@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struct kobject *kobj,
39952 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
39953 }
39954
39955-static struct sysfs_ops pci_slot_sysfs_ops = {
39956+static const struct sysfs_ops pci_slot_sysfs_ops = {
39957 .show = pci_slot_attr_show,
39958 .store = pci_slot_attr_store,
39959 };
39960diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
39961index 30cf71d2..50938f1 100644
39962--- a/drivers/pcmcia/pcmcia_ioctl.c
39963+++ b/drivers/pcmcia/pcmcia_ioctl.c
39964@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
39965 return -EFAULT;
39966 }
39967 }
39968- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
39969+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
39970 if (!buf)
39971 return -ENOMEM;
39972
39973diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
39974index 52183c4..b224c69 100644
39975--- a/drivers/platform/x86/acer-wmi.c
39976+++ b/drivers/platform/x86/acer-wmi.c
39977@@ -918,7 +918,7 @@ static int update_bl_status(struct backlight_device *bd)
39978 return 0;
39979 }
39980
39981-static struct backlight_ops acer_bl_ops = {
39982+static const struct backlight_ops acer_bl_ops = {
39983 .get_brightness = read_brightness,
39984 .update_status = update_bl_status,
39985 };
39986diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
39987index 767cb61..a87380b 100644
39988--- a/drivers/platform/x86/asus-laptop.c
39989+++ b/drivers/platform/x86/asus-laptop.c
39990@@ -250,7 +250,7 @@ static struct backlight_device *asus_backlight_device;
39991 */
39992 static int read_brightness(struct backlight_device *bd);
39993 static int update_bl_status(struct backlight_device *bd);
39994-static struct backlight_ops asusbl_ops = {
39995+static const struct backlight_ops asusbl_ops = {
39996 .get_brightness = read_brightness,
39997 .update_status = update_bl_status,
39998 };
39999diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
40000index d66c07a..a4abaac 100644
40001--- a/drivers/platform/x86/asus_acpi.c
40002+++ b/drivers/platform/x86/asus_acpi.c
40003@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
40004 return 0;
40005 }
40006
40007-static struct backlight_ops asus_backlight_data = {
40008+static const struct backlight_ops asus_backlight_data = {
40009 .get_brightness = read_brightness,
40010 .update_status = set_brightness_status,
40011 };
40012diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
40013index 11003bb..550ff1b 100644
40014--- a/drivers/platform/x86/compal-laptop.c
40015+++ b/drivers/platform/x86/compal-laptop.c
40016@@ -163,7 +163,7 @@ static int bl_update_status(struct backlight_device *b)
40017 return set_lcd_level(b->props.brightness);
40018 }
40019
40020-static struct backlight_ops compalbl_ops = {
40021+static const struct backlight_ops compalbl_ops = {
40022 .get_brightness = bl_get_brightness,
40023 .update_status = bl_update_status,
40024 };
40025diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
40026index 07a74da..9dc99fa 100644
40027--- a/drivers/platform/x86/dell-laptop.c
40028+++ b/drivers/platform/x86/dell-laptop.c
40029@@ -318,7 +318,7 @@ static int dell_get_intensity(struct backlight_device *bd)
40030 return buffer.output[1];
40031 }
40032
40033-static struct backlight_ops dell_ops = {
40034+static const struct backlight_ops dell_ops = {
40035 .get_brightness = dell_get_intensity,
40036 .update_status = dell_send_intensity,
40037 };
40038diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
40039index c533b1c..5c81f22 100644
40040--- a/drivers/platform/x86/eeepc-laptop.c
40041+++ b/drivers/platform/x86/eeepc-laptop.c
40042@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device;
40043 */
40044 static int read_brightness(struct backlight_device *bd);
40045 static int update_bl_status(struct backlight_device *bd);
40046-static struct backlight_ops eeepcbl_ops = {
40047+static const struct backlight_ops eeepcbl_ops = {
40048 .get_brightness = read_brightness,
40049 .update_status = update_bl_status,
40050 };
40051diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
40052index bcd4ba8..a249b35 100644
40053--- a/drivers/platform/x86/fujitsu-laptop.c
40054+++ b/drivers/platform/x86/fujitsu-laptop.c
40055@@ -436,7 +436,7 @@ static int bl_update_status(struct backlight_device *b)
40056 return ret;
40057 }
40058
40059-static struct backlight_ops fujitsubl_ops = {
40060+static const struct backlight_ops fujitsubl_ops = {
40061 .get_brightness = bl_get_brightness,
40062 .update_status = bl_update_status,
40063 };
40064diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40065index 759763d..1093ba2 100644
40066--- a/drivers/platform/x86/msi-laptop.c
40067+++ b/drivers/platform/x86/msi-laptop.c
40068@@ -161,7 +161,7 @@ static int bl_update_status(struct backlight_device *b)
40069 return set_lcd_level(b->props.brightness);
40070 }
40071
40072-static struct backlight_ops msibl_ops = {
40073+static const struct backlight_ops msibl_ops = {
40074 .get_brightness = bl_get_brightness,
40075 .update_status = bl_update_status,
40076 };
40077diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
40078index fe7cf01..9012d8d 100644
40079--- a/drivers/platform/x86/panasonic-laptop.c
40080+++ b/drivers/platform/x86/panasonic-laptop.c
40081@@ -352,7 +352,7 @@ static int bl_set_status(struct backlight_device *bd)
40082 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
40083 }
40084
40085-static struct backlight_ops pcc_backlight_ops = {
40086+static const struct backlight_ops pcc_backlight_ops = {
40087 .get_brightness = bl_get,
40088 .update_status = bl_set_status,
40089 };
40090diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40091index a2a742c..b37e25e 100644
40092--- a/drivers/platform/x86/sony-laptop.c
40093+++ b/drivers/platform/x86/sony-laptop.c
40094@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
40095 }
40096
40097 static struct backlight_device *sony_backlight_device;
40098-static struct backlight_ops sony_backlight_ops = {
40099+static const struct backlight_ops sony_backlight_ops = {
40100 .update_status = sony_backlight_update_status,
40101 .get_brightness = sony_backlight_get_brightness,
40102 };
40103diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40104index 68271ae..5e8fb10 100644
40105--- a/drivers/platform/x86/thinkpad_acpi.c
40106+++ b/drivers/platform/x86/thinkpad_acpi.c
40107@@ -2139,7 +2139,7 @@ static int hotkey_mask_get(void)
40108 return 0;
40109 }
40110
40111-void static hotkey_mask_warn_incomplete_mask(void)
40112+static void hotkey_mask_warn_incomplete_mask(void)
40113 {
40114 /* log only what the user can fix... */
40115 const u32 wantedmask = hotkey_driver_mask &
40116@@ -6125,7 +6125,7 @@ static void tpacpi_brightness_notify_change(void)
40117 BACKLIGHT_UPDATE_HOTKEY);
40118 }
40119
40120-static struct backlight_ops ibm_backlight_data = {
40121+static const struct backlight_ops ibm_backlight_data = {
40122 .get_brightness = brightness_get,
40123 .update_status = brightness_update_status,
40124 };
40125diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
40126index 51c0a8b..0786629 100644
40127--- a/drivers/platform/x86/toshiba_acpi.c
40128+++ b/drivers/platform/x86/toshiba_acpi.c
40129@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
40130 return AE_OK;
40131 }
40132
40133-static struct backlight_ops toshiba_backlight_data = {
40134+static const struct backlight_ops toshiba_backlight_data = {
40135 .get_brightness = get_lcd,
40136 .update_status = set_lcd_status,
40137 };
40138diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40139index fc83783c..cf370d7 100644
40140--- a/drivers/pnp/pnpbios/bioscalls.c
40141+++ b/drivers/pnp/pnpbios/bioscalls.c
40142@@ -60,7 +60,7 @@ do { \
40143 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40144 } while(0)
40145
40146-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40147+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40148 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40149
40150 /*
40151@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40152
40153 cpu = get_cpu();
40154 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40155+
40156+ pax_open_kernel();
40157 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40158+ pax_close_kernel();
40159
40160 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40161 spin_lock_irqsave(&pnp_bios_lock, flags);
40162@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40163 :"memory");
40164 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40165
40166+ pax_open_kernel();
40167 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40168+ pax_close_kernel();
40169+
40170 put_cpu();
40171
40172 /* If we get here and this is set then the PnP BIOS faulted on us. */
40173@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40174 return status;
40175 }
40176
40177-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40178+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40179 {
40180 int i;
40181
40182@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40183 pnp_bios_callpoint.offset = header->fields.pm16offset;
40184 pnp_bios_callpoint.segment = PNP_CS16;
40185
40186+ pax_open_kernel();
40187+
40188 for_each_possible_cpu(i) {
40189 struct desc_struct *gdt = get_cpu_gdt_table(i);
40190 if (!gdt)
40191@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40192 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40193 (unsigned long)__va(header->fields.pm16dseg));
40194 }
40195+
40196+ pax_close_kernel();
40197 }
40198diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40199index ba97654..66b99d4 100644
40200--- a/drivers/pnp/resource.c
40201+++ b/drivers/pnp/resource.c
40202@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40203 return 1;
40204
40205 /* check if the resource is valid */
40206- if (*irq < 0 || *irq > 15)
40207+ if (*irq > 15)
40208 return 0;
40209
40210 /* check if the resource is reserved */
40211@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40212 return 1;
40213
40214 /* check if the resource is valid */
40215- if (*dma < 0 || *dma == 4 || *dma > 7)
40216+ if (*dma == 4 || *dma > 7)
40217 return 0;
40218
40219 /* check if the resource is reserved */
40220diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
40221index 62bb981..24a2dc9 100644
40222--- a/drivers/power/bq27x00_battery.c
40223+++ b/drivers/power/bq27x00_battery.c
40224@@ -44,7 +44,7 @@ struct bq27x00_device_info;
40225 struct bq27x00_access_methods {
40226 int (*read)(u8 reg, int *rt_value, int b_single,
40227 struct bq27x00_device_info *di);
40228-};
40229+} __no_const;
40230
40231 struct bq27x00_device_info {
40232 struct device *dev;
40233diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40234index 62227cd..b5b538b 100644
40235--- a/drivers/rtc/rtc-dev.c
40236+++ b/drivers/rtc/rtc-dev.c
40237@@ -14,6 +14,7 @@
40238 #include <linux/module.h>
40239 #include <linux/rtc.h>
40240 #include <linux/sched.h>
40241+#include <linux/grsecurity.h>
40242 #include "rtc-core.h"
40243
40244 static dev_t rtc_devt;
40245@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *file,
40246 if (copy_from_user(&tm, uarg, sizeof(tm)))
40247 return -EFAULT;
40248
40249+ gr_log_timechange();
40250+
40251 return rtc_set_time(rtc, &tm);
40252
40253 case RTC_PIE_ON:
40254diff --git a/drivers/s390/cio/qdio_perf.c b/drivers/s390/cio/qdio_perf.c
40255index 968e3c7..fbc637a 100644
40256--- a/drivers/s390/cio/qdio_perf.c
40257+++ b/drivers/s390/cio/qdio_perf.c
40258@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_pde;
40259 static int qdio_perf_proc_show(struct seq_file *m, void *v)
40260 {
40261 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
40262- (long)atomic_long_read(&perf_stats.qdio_int));
40263+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
40264 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
40265- (long)atomic_long_read(&perf_stats.pci_int));
40266+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
40267 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
40268- (long)atomic_long_read(&perf_stats.thin_int));
40269+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
40270 seq_printf(m, "\n");
40271 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
40272- (long)atomic_long_read(&perf_stats.tasklet_inbound));
40273+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
40274 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
40275- (long)atomic_long_read(&perf_stats.tasklet_outbound));
40276+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
40277 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
40278- (long)atomic_long_read(&perf_stats.tasklet_thinint),
40279- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
40280+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
40281+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
40282 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
40283- (long)atomic_long_read(&perf_stats.thinint_inbound),
40284- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
40285+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
40286+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
40287 seq_printf(m, "\n");
40288 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
40289- (long)atomic_long_read(&perf_stats.siga_in));
40290+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
40291 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
40292- (long)atomic_long_read(&perf_stats.siga_out));
40293+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
40294 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
40295- (long)atomic_long_read(&perf_stats.siga_sync));
40296+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
40297 seq_printf(m, "\n");
40298 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
40299- (long)atomic_long_read(&perf_stats.inbound_handler));
40300+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
40301 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
40302- (long)atomic_long_read(&perf_stats.outbound_handler));
40303+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
40304 seq_printf(m, "\n");
40305 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
40306- (long)atomic_long_read(&perf_stats.fast_requeue));
40307+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
40308 seq_printf(m, "Number of outbound target full condition\t: %li\n",
40309- (long)atomic_long_read(&perf_stats.outbound_target_full));
40310+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
40311 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
40312- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
40313+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
40314 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
40315- (long)atomic_long_read(&perf_stats.debug_stop_polling));
40316+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
40317 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
40318- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
40319+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
40320 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
40321- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
40322- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
40323+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
40324+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
40325 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
40326- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
40327- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
40328+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
40329+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
40330 seq_printf(m, "\n");
40331 return 0;
40332 }
40333diff --git a/drivers/s390/cio/qdio_perf.h b/drivers/s390/cio/qdio_perf.h
40334index ff4504c..b3604c3 100644
40335--- a/drivers/s390/cio/qdio_perf.h
40336+++ b/drivers/s390/cio/qdio_perf.h
40337@@ -13,46 +13,46 @@
40338
40339 struct qdio_perf_stats {
40340 /* interrupt handler calls */
40341- atomic_long_t qdio_int;
40342- atomic_long_t pci_int;
40343- atomic_long_t thin_int;
40344+ atomic_long_unchecked_t qdio_int;
40345+ atomic_long_unchecked_t pci_int;
40346+ atomic_long_unchecked_t thin_int;
40347
40348 /* tasklet runs */
40349- atomic_long_t tasklet_inbound;
40350- atomic_long_t tasklet_outbound;
40351- atomic_long_t tasklet_thinint;
40352- atomic_long_t tasklet_thinint_loop;
40353- atomic_long_t thinint_inbound;
40354- atomic_long_t thinint_inbound_loop;
40355- atomic_long_t thinint_inbound_loop2;
40356+ atomic_long_unchecked_t tasklet_inbound;
40357+ atomic_long_unchecked_t tasklet_outbound;
40358+ atomic_long_unchecked_t tasklet_thinint;
40359+ atomic_long_unchecked_t tasklet_thinint_loop;
40360+ atomic_long_unchecked_t thinint_inbound;
40361+ atomic_long_unchecked_t thinint_inbound_loop;
40362+ atomic_long_unchecked_t thinint_inbound_loop2;
40363
40364 /* signal adapter calls */
40365- atomic_long_t siga_out;
40366- atomic_long_t siga_in;
40367- atomic_long_t siga_sync;
40368+ atomic_long_unchecked_t siga_out;
40369+ atomic_long_unchecked_t siga_in;
40370+ atomic_long_unchecked_t siga_sync;
40371
40372 /* misc */
40373- atomic_long_t inbound_handler;
40374- atomic_long_t outbound_handler;
40375- atomic_long_t fast_requeue;
40376- atomic_long_t outbound_target_full;
40377+ atomic_long_unchecked_t inbound_handler;
40378+ atomic_long_unchecked_t outbound_handler;
40379+ atomic_long_unchecked_t fast_requeue;
40380+ atomic_long_unchecked_t outbound_target_full;
40381
40382 /* for debugging */
40383- atomic_long_t debug_tl_out_timer;
40384- atomic_long_t debug_stop_polling;
40385- atomic_long_t debug_eqbs_all;
40386- atomic_long_t debug_eqbs_incomplete;
40387- atomic_long_t debug_sqbs_all;
40388- atomic_long_t debug_sqbs_incomplete;
40389+ atomic_long_unchecked_t debug_tl_out_timer;
40390+ atomic_long_unchecked_t debug_stop_polling;
40391+ atomic_long_unchecked_t debug_eqbs_all;
40392+ atomic_long_unchecked_t debug_eqbs_incomplete;
40393+ atomic_long_unchecked_t debug_sqbs_all;
40394+ atomic_long_unchecked_t debug_sqbs_incomplete;
40395 };
40396
40397 extern struct qdio_perf_stats perf_stats;
40398 extern int qdio_performance_stats;
40399
40400-static inline void qdio_perf_stat_inc(atomic_long_t *count)
40401+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
40402 {
40403 if (qdio_performance_stats)
40404- atomic_long_inc(count);
40405+ atomic_long_inc_unchecked(count);
40406 }
40407
40408 int qdio_setup_perf_stats(void);
40409diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
40410index 1ddcf40..a85f062 100644
40411--- a/drivers/scsi/BusLogic.c
40412+++ b/drivers/scsi/BusLogic.c
40413@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
40414 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
40415 *PrototypeHostAdapter)
40416 {
40417+ pax_track_stack();
40418+
40419 /*
40420 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
40421 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
40422diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
40423index cdbdec9..b7d560b 100644
40424--- a/drivers/scsi/aacraid/aacraid.h
40425+++ b/drivers/scsi/aacraid/aacraid.h
40426@@ -471,7 +471,7 @@ struct adapter_ops
40427 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
40428 /* Administrative operations */
40429 int (*adapter_comm)(struct aac_dev * dev, int comm);
40430-};
40431+} __no_const;
40432
40433 /*
40434 * Define which interrupt handler needs to be installed
40435diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
40436index a5b8e7b..a6a0e43 100644
40437--- a/drivers/scsi/aacraid/commctrl.c
40438+++ b/drivers/scsi/aacraid/commctrl.c
40439@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
40440 u32 actual_fibsize64, actual_fibsize = 0;
40441 int i;
40442
40443+ pax_track_stack();
40444
40445 if (dev->in_reset) {
40446 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
40447diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
40448index 9b97c3e..f099725 100644
40449--- a/drivers/scsi/aacraid/linit.c
40450+++ b/drivers/scsi/aacraid/linit.c
40451@@ -91,7 +91,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
40452 #elif defined(__devinitconst)
40453 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40454 #else
40455-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
40456+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40457 #endif
40458 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
40459 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
40460diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
40461index 996f722..9127845 100644
40462--- a/drivers/scsi/aic94xx/aic94xx_init.c
40463+++ b/drivers/scsi/aic94xx/aic94xx_init.c
40464@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(struct device *dev,
40465 flash_error_table[i].reason);
40466 }
40467
40468-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
40469+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
40470 asd_show_update_bios, asd_store_update_bios);
40471
40472 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
40473@@ -1011,7 +1011,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
40474 .lldd_control_phy = asd_control_phy,
40475 };
40476
40477-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
40478+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
40479 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
40480 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
40481 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
40482diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40483index 58efd4b..cb48dc7 100644
40484--- a/drivers/scsi/bfa/bfa_ioc.h
40485+++ b/drivers/scsi/bfa/bfa_ioc.h
40486@@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
40487 bfa_ioc_disable_cbfn_t disable_cbfn;
40488 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40489 bfa_ioc_reset_cbfn_t reset_cbfn;
40490-};
40491+} __no_const;
40492
40493 /**
40494 * Heartbeat failure notification queue element.
40495diff --git a/drivers/scsi/bfa/bfa_iocfc.h b/drivers/scsi/bfa/bfa_iocfc.h
40496index 7ad177e..5503586 100644
40497--- a/drivers/scsi/bfa/bfa_iocfc.h
40498+++ b/drivers/scsi/bfa/bfa_iocfc.h
40499@@ -61,7 +61,7 @@ struct bfa_hwif_s {
40500 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
40501 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
40502 u32 *nvecs, u32 *maxvec);
40503-};
40504+} __no_const;
40505 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
40506
40507 struct bfa_iocfc_s {
40508diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
40509index 4967643..cbec06b 100644
40510--- a/drivers/scsi/dpt_i2o.c
40511+++ b/drivers/scsi/dpt_i2o.c
40512@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
40513 dma_addr_t addr;
40514 ulong flags = 0;
40515
40516+ pax_track_stack();
40517+
40518 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
40519 // get user msg size in u32s
40520 if(get_user(size, &user_msg[0])){
40521@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
40522 s32 rcode;
40523 dma_addr_t addr;
40524
40525+ pax_track_stack();
40526+
40527 memset(msg, 0 , sizeof(msg));
40528 len = scsi_bufflen(cmd);
40529 direction = 0x00000000;
40530diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
40531index c7076ce..e20c67c 100644
40532--- a/drivers/scsi/eata.c
40533+++ b/drivers/scsi/eata.c
40534@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
40535 struct hostdata *ha;
40536 char name[16];
40537
40538+ pax_track_stack();
40539+
40540 sprintf(name, "%s%d", driver_name, j);
40541
40542 if (!request_region(port_base, REGION_SIZE, driver_name)) {
40543diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
40544index 11ae5c9..891daec 100644
40545--- a/drivers/scsi/fcoe/libfcoe.c
40546+++ b/drivers/scsi/fcoe/libfcoe.c
40547@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
40548 size_t rlen;
40549 size_t dlen;
40550
40551+ pax_track_stack();
40552+
40553 fiph = (struct fip_header *)skb->data;
40554 sub = fiph->fip_subcode;
40555 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
40556diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
40557index 71c7bbe..e93088a 100644
40558--- a/drivers/scsi/fnic/fnic_main.c
40559+++ b/drivers/scsi/fnic/fnic_main.c
40560@@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
40561 /* Start local port initiatialization */
40562
40563 lp->link_up = 0;
40564- lp->tt = fnic_transport_template;
40565+ memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
40566
40567 lp->max_retry_count = fnic->config.flogi_retries;
40568 lp->max_rport_retry_count = fnic->config.plogi_retries;
40569diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
40570index bb96d74..9ec3ce4 100644
40571--- a/drivers/scsi/gdth.c
40572+++ b/drivers/scsi/gdth.c
40573@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
40574 ulong flags;
40575 gdth_ha_str *ha;
40576
40577+ pax_track_stack();
40578+
40579 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
40580 return -EFAULT;
40581 ha = gdth_find_ha(ldrv.ionode);
40582@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
40583 gdth_ha_str *ha;
40584 int rval;
40585
40586+ pax_track_stack();
40587+
40588 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
40589 res.number >= MAX_HDRIVES)
40590 return -EFAULT;
40591@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg, char *cmnd)
40592 gdth_ha_str *ha;
40593 int rval;
40594
40595+ pax_track_stack();
40596+
40597 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
40598 return -EFAULT;
40599 ha = gdth_find_ha(gen.ionode);
40600@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
40601 int i;
40602 gdth_cmd_str gdtcmd;
40603 char cmnd[MAX_COMMAND_SIZE];
40604+
40605+ pax_track_stack();
40606+
40607 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
40608
40609 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
40610diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
40611index 1258da3..20d8ae6 100644
40612--- a/drivers/scsi/gdth_proc.c
40613+++ b/drivers/scsi/gdth_proc.c
40614@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
40615 ulong64 paddr;
40616
40617 char cmnd[MAX_COMMAND_SIZE];
40618+
40619+ pax_track_stack();
40620+
40621 memset(cmnd, 0xff, 12);
40622 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
40623
40624@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
40625 gdth_hget_str *phg;
40626 char cmnd[MAX_COMMAND_SIZE];
40627
40628+ pax_track_stack();
40629+
40630 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
40631 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
40632 if (!gdtcmd || !estr)
40633diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40634index d03a926..f324286 100644
40635--- a/drivers/scsi/hosts.c
40636+++ b/drivers/scsi/hosts.c
40637@@ -40,7 +40,7 @@
40638 #include "scsi_logging.h"
40639
40640
40641-static atomic_t scsi_host_next_hn; /* host_no for next new host */
40642+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
40643
40644
40645 static void scsi_host_cls_release(struct device *dev)
40646@@ -347,7 +347,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40647 * subtract one because we increment first then return, but we need to
40648 * know what the next host number was before increment
40649 */
40650- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40651+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40652 shost->dma_channel = 0xff;
40653
40654 /* These three are default values which can be overridden */
40655diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
40656index a601159..55e19d2 100644
40657--- a/drivers/scsi/ipr.c
40658+++ b/drivers/scsi/ipr.c
40659@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
40660 return true;
40661 }
40662
40663-static struct ata_port_operations ipr_sata_ops = {
40664+static const struct ata_port_operations ipr_sata_ops = {
40665 .phy_reset = ipr_ata_phy_reset,
40666 .hardreset = ipr_sata_reset,
40667 .post_internal_cmd = ipr_ata_post_internal,
40668diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
40669index 4e49fbc..97907ff 100644
40670--- a/drivers/scsi/ips.h
40671+++ b/drivers/scsi/ips.h
40672@@ -1027,7 +1027,7 @@ typedef struct {
40673 int (*intr)(struct ips_ha *);
40674 void (*enableint)(struct ips_ha *);
40675 uint32_t (*statupd)(struct ips_ha *);
40676-} ips_hw_func_t;
40677+} __no_const ips_hw_func_t;
40678
40679 typedef struct ips_ha {
40680 uint8_t ha_id[IPS_MAX_CHANNELS+1];
40681diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40682index c1c1574..a9c9348 100644
40683--- a/drivers/scsi/libfc/fc_exch.c
40684+++ b/drivers/scsi/libfc/fc_exch.c
40685@@ -86,12 +86,12 @@ struct fc_exch_mgr {
40686 * all together if not used XXX
40687 */
40688 struct {
40689- atomic_t no_free_exch;
40690- atomic_t no_free_exch_xid;
40691- atomic_t xid_not_found;
40692- atomic_t xid_busy;
40693- atomic_t seq_not_found;
40694- atomic_t non_bls_resp;
40695+ atomic_unchecked_t no_free_exch;
40696+ atomic_unchecked_t no_free_exch_xid;
40697+ atomic_unchecked_t xid_not_found;
40698+ atomic_unchecked_t xid_busy;
40699+ atomic_unchecked_t seq_not_found;
40700+ atomic_unchecked_t non_bls_resp;
40701 } stats;
40702 };
40703 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
40704@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40705 /* allocate memory for exchange */
40706 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40707 if (!ep) {
40708- atomic_inc(&mp->stats.no_free_exch);
40709+ atomic_inc_unchecked(&mp->stats.no_free_exch);
40710 goto out;
40711 }
40712 memset(ep, 0, sizeof(*ep));
40713@@ -557,7 +557,7 @@ out:
40714 return ep;
40715 err:
40716 spin_unlock_bh(&pool->lock);
40717- atomic_inc(&mp->stats.no_free_exch_xid);
40718+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40719 mempool_free(ep, mp->ep_pool);
40720 return NULL;
40721 }
40722@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40723 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40724 ep = fc_exch_find(mp, xid);
40725 if (!ep) {
40726- atomic_inc(&mp->stats.xid_not_found);
40727+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40728 reject = FC_RJT_OX_ID;
40729 goto out;
40730 }
40731@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40732 ep = fc_exch_find(mp, xid);
40733 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40734 if (ep) {
40735- atomic_inc(&mp->stats.xid_busy);
40736+ atomic_inc_unchecked(&mp->stats.xid_busy);
40737 reject = FC_RJT_RX_ID;
40738 goto rel;
40739 }
40740@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40741 }
40742 xid = ep->xid; /* get our XID */
40743 } else if (!ep) {
40744- atomic_inc(&mp->stats.xid_not_found);
40745+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40746 reject = FC_RJT_RX_ID; /* XID not found */
40747 goto out;
40748 }
40749@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40750 } else {
40751 sp = &ep->seq;
40752 if (sp->id != fh->fh_seq_id) {
40753- atomic_inc(&mp->stats.seq_not_found);
40754+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40755 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
40756 goto rel;
40757 }
40758@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40759
40760 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40761 if (!ep) {
40762- atomic_inc(&mp->stats.xid_not_found);
40763+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40764 goto out;
40765 }
40766 if (ep->esb_stat & ESB_ST_COMPLETE) {
40767- atomic_inc(&mp->stats.xid_not_found);
40768+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40769 goto out;
40770 }
40771 if (ep->rxid == FC_XID_UNKNOWN)
40772 ep->rxid = ntohs(fh->fh_rx_id);
40773 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40774- atomic_inc(&mp->stats.xid_not_found);
40775+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40776 goto rel;
40777 }
40778 if (ep->did != ntoh24(fh->fh_s_id) &&
40779 ep->did != FC_FID_FLOGI) {
40780- atomic_inc(&mp->stats.xid_not_found);
40781+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40782 goto rel;
40783 }
40784 sof = fr_sof(fp);
40785@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40786 } else {
40787 sp = &ep->seq;
40788 if (sp->id != fh->fh_seq_id) {
40789- atomic_inc(&mp->stats.seq_not_found);
40790+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40791 goto rel;
40792 }
40793 }
40794@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40795 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40796
40797 if (!sp)
40798- atomic_inc(&mp->stats.xid_not_found);
40799+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40800 else
40801- atomic_inc(&mp->stats.non_bls_resp);
40802+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
40803
40804 fc_frame_free(fp);
40805 }
40806diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40807index 0ee989f..a582241 100644
40808--- a/drivers/scsi/libsas/sas_ata.c
40809+++ b/drivers/scsi/libsas/sas_ata.c
40810@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_link *link, unsigned int sc_reg_in,
40811 }
40812 }
40813
40814-static struct ata_port_operations sas_sata_ops = {
40815+static const struct ata_port_operations sas_sata_ops = {
40816 .phy_reset = sas_ata_phy_reset,
40817 .post_internal_cmd = sas_ata_post_internal,
40818 .qc_defer = ata_std_qc_defer,
40819diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40820index aa10f79..5cc79e4 100644
40821--- a/drivers/scsi/lpfc/lpfc.h
40822+++ b/drivers/scsi/lpfc/lpfc.h
40823@@ -400,7 +400,7 @@ struct lpfc_vport {
40824 struct dentry *debug_nodelist;
40825 struct dentry *vport_debugfs_root;
40826 struct lpfc_debugfs_trc *disc_trc;
40827- atomic_t disc_trc_cnt;
40828+ atomic_unchecked_t disc_trc_cnt;
40829 #endif
40830 uint8_t stat_data_enabled;
40831 uint8_t stat_data_blocked;
40832@@ -725,8 +725,8 @@ struct lpfc_hba {
40833 struct timer_list fabric_block_timer;
40834 unsigned long bit_flags;
40835 #define FABRIC_COMANDS_BLOCKED 0
40836- atomic_t num_rsrc_err;
40837- atomic_t num_cmd_success;
40838+ atomic_unchecked_t num_rsrc_err;
40839+ atomic_unchecked_t num_cmd_success;
40840 unsigned long last_rsrc_error_time;
40841 unsigned long last_ramp_down_time;
40842 unsigned long last_ramp_up_time;
40843@@ -740,7 +740,7 @@ struct lpfc_hba {
40844 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
40845 struct dentry *debug_slow_ring_trc;
40846 struct lpfc_debugfs_trc *slow_ring_trc;
40847- atomic_t slow_ring_trc_cnt;
40848+ atomic_unchecked_t slow_ring_trc_cnt;
40849 #endif
40850
40851 /* Used for deferred freeing of ELS data buffers */
40852diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
40853index 8d0f0de..7c77a62 100644
40854--- a/drivers/scsi/lpfc/lpfc_debugfs.c
40855+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
40856@@ -124,7 +124,7 @@ struct lpfc_debug {
40857 int len;
40858 };
40859
40860-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40861+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40862 static unsigned long lpfc_debugfs_start_time = 0L;
40863
40864 /**
40865@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
40866 lpfc_debugfs_enable = 0;
40867
40868 len = 0;
40869- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
40870+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
40871 (lpfc_debugfs_max_disc_trc - 1);
40872 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
40873 dtp = vport->disc_trc + i;
40874@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
40875 lpfc_debugfs_enable = 0;
40876
40877 len = 0;
40878- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
40879+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
40880 (lpfc_debugfs_max_slow_ring_trc - 1);
40881 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
40882 dtp = phba->slow_ring_trc + i;
40883@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
40884 uint32_t *ptr;
40885 char buffer[1024];
40886
40887+ pax_track_stack();
40888+
40889 off = 0;
40890 spin_lock_irq(&phba->hbalock);
40891
40892@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
40893 !vport || !vport->disc_trc)
40894 return;
40895
40896- index = atomic_inc_return(&vport->disc_trc_cnt) &
40897+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
40898 (lpfc_debugfs_max_disc_trc - 1);
40899 dtp = vport->disc_trc + index;
40900 dtp->fmt = fmt;
40901 dtp->data1 = data1;
40902 dtp->data2 = data2;
40903 dtp->data3 = data3;
40904- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40905+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40906 dtp->jif = jiffies;
40907 #endif
40908 return;
40909@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
40910 !phba || !phba->slow_ring_trc)
40911 return;
40912
40913- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
40914+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
40915 (lpfc_debugfs_max_slow_ring_trc - 1);
40916 dtp = phba->slow_ring_trc + index;
40917 dtp->fmt = fmt;
40918 dtp->data1 = data1;
40919 dtp->data2 = data2;
40920 dtp->data3 = data3;
40921- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40922+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40923 dtp->jif = jiffies;
40924 #endif
40925 return;
40926@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40927 "slow_ring buffer\n");
40928 goto debug_failed;
40929 }
40930- atomic_set(&phba->slow_ring_trc_cnt, 0);
40931+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
40932 memset(phba->slow_ring_trc, 0,
40933 (sizeof(struct lpfc_debugfs_trc) *
40934 lpfc_debugfs_max_slow_ring_trc));
40935@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40936 "buffer\n");
40937 goto debug_failed;
40938 }
40939- atomic_set(&vport->disc_trc_cnt, 0);
40940+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
40941
40942 snprintf(name, sizeof(name), "discovery_trace");
40943 vport->debug_disc_trc =
40944diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
40945index 549bc7d..8189dbb 100644
40946--- a/drivers/scsi/lpfc/lpfc_init.c
40947+++ b/drivers/scsi/lpfc/lpfc_init.c
40948@@ -8021,8 +8021,10 @@ lpfc_init(void)
40949 printk(LPFC_COPYRIGHT "\n");
40950
40951 if (lpfc_enable_npiv) {
40952- lpfc_transport_functions.vport_create = lpfc_vport_create;
40953- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
40954+ pax_open_kernel();
40955+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
40956+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
40957+ pax_close_kernel();
40958 }
40959 lpfc_transport_template =
40960 fc_attach_transport(&lpfc_transport_functions);
40961diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
40962index c88f59f..ff2a42f 100644
40963--- a/drivers/scsi/lpfc/lpfc_scsi.c
40964+++ b/drivers/scsi/lpfc/lpfc_scsi.c
40965@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
40966 uint32_t evt_posted;
40967
40968 spin_lock_irqsave(&phba->hbalock, flags);
40969- atomic_inc(&phba->num_rsrc_err);
40970+ atomic_inc_unchecked(&phba->num_rsrc_err);
40971 phba->last_rsrc_error_time = jiffies;
40972
40973 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
40974@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
40975 unsigned long flags;
40976 struct lpfc_hba *phba = vport->phba;
40977 uint32_t evt_posted;
40978- atomic_inc(&phba->num_cmd_success);
40979+ atomic_inc_unchecked(&phba->num_cmd_success);
40980
40981 if (vport->cfg_lun_queue_depth <= queue_depth)
40982 return;
40983@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
40984 int i;
40985 struct lpfc_rport_data *rdata;
40986
40987- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
40988- num_cmd_success = atomic_read(&phba->num_cmd_success);
40989+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
40990+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
40991
40992 vports = lpfc_create_vport_work_array(phba);
40993 if (vports != NULL)
40994@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
40995 }
40996 }
40997 lpfc_destroy_vport_work_array(phba, vports);
40998- atomic_set(&phba->num_rsrc_err, 0);
40999- atomic_set(&phba->num_cmd_success, 0);
41000+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41001+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41002 }
41003
41004 /**
41005@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41006 }
41007 }
41008 lpfc_destroy_vport_work_array(phba, vports);
41009- atomic_set(&phba->num_rsrc_err, 0);
41010- atomic_set(&phba->num_cmd_success, 0);
41011+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41012+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41013 }
41014
41015 /**
41016diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
41017index 234f0b7..3020aea 100644
41018--- a/drivers/scsi/megaraid/megaraid_mbox.c
41019+++ b/drivers/scsi/megaraid/megaraid_mbox.c
41020@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
41021 int rval;
41022 int i;
41023
41024+ pax_track_stack();
41025+
41026 // Allocate memory for the base list of scb for management module.
41027 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
41028
41029diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
41030index 7a117c1..ee01e9e 100644
41031--- a/drivers/scsi/osd/osd_initiator.c
41032+++ b/drivers/scsi/osd/osd_initiator.c
41033@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
41034 int nelem = ARRAY_SIZE(get_attrs), a = 0;
41035 int ret;
41036
41037+ pax_track_stack();
41038+
41039 or = osd_start_request(od, GFP_KERNEL);
41040 if (!or)
41041 return -ENOMEM;
41042diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41043index 9ab8c86..9425ad3 100644
41044--- a/drivers/scsi/pmcraid.c
41045+++ b/drivers/scsi/pmcraid.c
41046@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41047 res->scsi_dev = scsi_dev;
41048 scsi_dev->hostdata = res;
41049 res->change_detected = 0;
41050- atomic_set(&res->read_failures, 0);
41051- atomic_set(&res->write_failures, 0);
41052+ atomic_set_unchecked(&res->read_failures, 0);
41053+ atomic_set_unchecked(&res->write_failures, 0);
41054 rc = 0;
41055 }
41056 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41057@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41058
41059 /* If this was a SCSI read/write command keep count of errors */
41060 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41061- atomic_inc(&res->read_failures);
41062+ atomic_inc_unchecked(&res->read_failures);
41063 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41064- atomic_inc(&res->write_failures);
41065+ atomic_inc_unchecked(&res->write_failures);
41066
41067 if (!RES_IS_GSCSI(res->cfg_entry) &&
41068 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41069@@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41070
41071 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41072 /* add resources only after host is added into system */
41073- if (!atomic_read(&pinstance->expose_resources))
41074+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41075 return;
41076
41077 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
41078@@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instance(
41079 init_waitqueue_head(&pinstance->reset_wait_q);
41080
41081 atomic_set(&pinstance->outstanding_cmds, 0);
41082- atomic_set(&pinstance->expose_resources, 0);
41083+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41084
41085 INIT_LIST_HEAD(&pinstance->free_res_q);
41086 INIT_LIST_HEAD(&pinstance->used_res_q);
41087@@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
41088 /* Schedule worker thread to handle CCN and take care of adding and
41089 * removing devices to OS
41090 */
41091- atomic_set(&pinstance->expose_resources, 1);
41092+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41093 schedule_work(&pinstance->worker_q);
41094 return rc;
41095
41096diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41097index 3441b3f..6cbe8f7 100644
41098--- a/drivers/scsi/pmcraid.h
41099+++ b/drivers/scsi/pmcraid.h
41100@@ -690,7 +690,7 @@ struct pmcraid_instance {
41101 atomic_t outstanding_cmds;
41102
41103 /* should add/delete resources to mid-layer now ?*/
41104- atomic_t expose_resources;
41105+ atomic_unchecked_t expose_resources;
41106
41107 /* Tasklet to handle deferred processing */
41108 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
41109@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
41110 struct list_head queue; /* link to "to be exposed" resources */
41111 struct pmcraid_config_table_entry cfg_entry;
41112 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41113- atomic_t read_failures; /* count of failed READ commands */
41114- atomic_t write_failures; /* count of failed WRITE commands */
41115+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41116+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41117
41118 /* To indicate add/delete/modify during CCN */
41119 u8 change_detected;
41120diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
41121index 2150618..7034215 100644
41122--- a/drivers/scsi/qla2xxx/qla_def.h
41123+++ b/drivers/scsi/qla2xxx/qla_def.h
41124@@ -2089,7 +2089,7 @@ struct isp_operations {
41125
41126 int (*get_flash_version) (struct scsi_qla_host *, void *);
41127 int (*start_scsi) (srb_t *);
41128-};
41129+} __no_const;
41130
41131 /* MSI-X Support *************************************************************/
41132
41133diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41134index 81b5f29..2ae1fad 100644
41135--- a/drivers/scsi/qla4xxx/ql4_def.h
41136+++ b/drivers/scsi/qla4xxx/ql4_def.h
41137@@ -240,7 +240,7 @@ struct ddb_entry {
41138 atomic_t retry_relogin_timer; /* Min Time between relogins
41139 * (4000 only) */
41140 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
41141- atomic_t relogin_retry_count; /* Num of times relogin has been
41142+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41143 * retried */
41144
41145 uint16_t port;
41146diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
41147index af8c323..515dd51 100644
41148--- a/drivers/scsi/qla4xxx/ql4_init.c
41149+++ b/drivers/scsi/qla4xxx/ql4_init.c
41150@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
41151 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
41152 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41153 atomic_set(&ddb_entry->relogin_timer, 0);
41154- atomic_set(&ddb_entry->relogin_retry_count, 0);
41155+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41156 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41157 list_add_tail(&ddb_entry->list, &ha->ddb_list);
41158 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
41159@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
41160 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41161 atomic_set(&ddb_entry->port_down_timer,
41162 ha->port_down_retry_count);
41163- atomic_set(&ddb_entry->relogin_retry_count, 0);
41164+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41165 atomic_set(&ddb_entry->relogin_timer, 0);
41166 clear_bit(DF_RELOGIN, &ddb_entry->flags);
41167 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
41168diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41169index 83c8b5e..a82b348 100644
41170--- a/drivers/scsi/qla4xxx/ql4_os.c
41171+++ b/drivers/scsi/qla4xxx/ql4_os.c
41172@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
41173 ddb_entry->fw_ddb_device_state ==
41174 DDB_DS_SESSION_FAILED) {
41175 /* Reset retry relogin timer */
41176- atomic_inc(&ddb_entry->relogin_retry_count);
41177+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41178 DEBUG2(printk("scsi%ld: index[%d] relogin"
41179 " timed out-retrying"
41180 " relogin (%d)\n",
41181 ha->host_no,
41182 ddb_entry->fw_ddb_index,
41183- atomic_read(&ddb_entry->
41184+ atomic_read_unchecked(&ddb_entry->
41185 relogin_retry_count))
41186 );
41187 start_dpc++;
41188diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41189index dd098ca..686ce01 100644
41190--- a/drivers/scsi/scsi.c
41191+++ b/drivers/scsi/scsi.c
41192@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41193 unsigned long timeout;
41194 int rtn = 0;
41195
41196- atomic_inc(&cmd->device->iorequest_cnt);
41197+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41198
41199 /* check if the device is still usable */
41200 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41201diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
41202index bc3e363..e1a8e50 100644
41203--- a/drivers/scsi/scsi_debug.c
41204+++ b/drivers/scsi/scsi_debug.c
41205@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
41206 unsigned char arr[SDEBUG_MAX_MSELECT_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@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
41215 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
41216 unsigned char *cmd = (unsigned char *)scp->cmnd;
41217
41218+ pax_track_stack();
41219+
41220 if ((errsts = check_readiness(scp, 1, devip)))
41221 return errsts;
41222 memset(arr, 0, sizeof(arr));
41223diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41224index 8df12522..c4c1472 100644
41225--- a/drivers/scsi/scsi_lib.c
41226+++ b/drivers/scsi/scsi_lib.c
41227@@ -1389,7 +1389,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41228 shost = sdev->host;
41229 scsi_init_cmd_errh(cmd);
41230 cmd->result = DID_NO_CONNECT << 16;
41231- atomic_inc(&cmd->device->iorequest_cnt);
41232+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41233
41234 /*
41235 * SCSI request completion path will do scsi_device_unbusy(),
41236@@ -1420,9 +1420,9 @@ static void scsi_softirq_done(struct request *rq)
41237 */
41238 cmd->serial_number = 0;
41239
41240- atomic_inc(&cmd->device->iodone_cnt);
41241+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41242 if (cmd->result)
41243- atomic_inc(&cmd->device->ioerr_cnt);
41244+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41245
41246 disposition = scsi_decide_disposition(cmd);
41247 if (disposition != SUCCESS &&
41248diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41249index 91a93e0..eae0fe3 100644
41250--- a/drivers/scsi/scsi_sysfs.c
41251+++ b/drivers/scsi/scsi_sysfs.c
41252@@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41253 char *buf) \
41254 { \
41255 struct scsi_device *sdev = to_scsi_device(dev); \
41256- unsigned long long count = atomic_read(&sdev->field); \
41257+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41258 return snprintf(buf, 20, "0x%llx\n", count); \
41259 } \
41260 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41261diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41262index 1030327..f91fd30 100644
41263--- a/drivers/scsi/scsi_tgt_lib.c
41264+++ b/drivers/scsi/scsi_tgt_lib.c
41265@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41266 int err;
41267
41268 dprintk("%lx %u\n", uaddr, len);
41269- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41270+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41271 if (err) {
41272 /*
41273 * TODO: need to fixup sg_tablesize, max_segment_size,
41274diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41275index db02e31..1b42ea9 100644
41276--- a/drivers/scsi/scsi_transport_fc.c
41277+++ b/drivers/scsi/scsi_transport_fc.c
41278@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
41279 * Netlink Infrastructure
41280 */
41281
41282-static atomic_t fc_event_seq;
41283+static atomic_unchecked_t fc_event_seq;
41284
41285 /**
41286 * fc_get_event_number - Obtain the next sequential FC event number
41287@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
41288 u32
41289 fc_get_event_number(void)
41290 {
41291- return atomic_add_return(1, &fc_event_seq);
41292+ return atomic_add_return_unchecked(1, &fc_event_seq);
41293 }
41294 EXPORT_SYMBOL(fc_get_event_number);
41295
41296@@ -641,7 +641,7 @@ static __init int fc_transport_init(void)
41297 {
41298 int error;
41299
41300- atomic_set(&fc_event_seq, 0);
41301+ atomic_set_unchecked(&fc_event_seq, 0);
41302
41303 error = transport_class_register(&fc_host_class);
41304 if (error)
41305diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41306index de2f8c4..63c5278 100644
41307--- a/drivers/scsi/scsi_transport_iscsi.c
41308+++ b/drivers/scsi/scsi_transport_iscsi.c
41309@@ -81,7 +81,7 @@ struct iscsi_internal {
41310 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
41311 };
41312
41313-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41314+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41315 static struct workqueue_struct *iscsi_eh_timer_workq;
41316
41317 /*
41318@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41319 int err;
41320
41321 ihost = shost->shost_data;
41322- session->sid = atomic_add_return(1, &iscsi_session_nr);
41323+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41324
41325 if (id == ISCSI_MAX_TARGET) {
41326 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
41327@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(void)
41328 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41329 ISCSI_TRANSPORT_VERSION);
41330
41331- atomic_set(&iscsi_session_nr, 0);
41332+ atomic_set_unchecked(&iscsi_session_nr, 0);
41333
41334 err = class_register(&iscsi_transport_class);
41335 if (err)
41336diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41337index 21a045e..ec89e03 100644
41338--- a/drivers/scsi/scsi_transport_srp.c
41339+++ b/drivers/scsi/scsi_transport_srp.c
41340@@ -33,7 +33,7 @@
41341 #include "scsi_transport_srp_internal.h"
41342
41343 struct srp_host_attrs {
41344- atomic_t next_port_id;
41345+ atomic_unchecked_t next_port_id;
41346 };
41347 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41348
41349@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41350 struct Scsi_Host *shost = dev_to_shost(dev);
41351 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41352
41353- atomic_set(&srp_host->next_port_id, 0);
41354+ atomic_set_unchecked(&srp_host->next_port_id, 0);
41355 return 0;
41356 }
41357
41358@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41359 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41360 rport->roles = ids->roles;
41361
41362- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41363+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41364 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41365
41366 transport_setup_device(&rport->dev);
41367diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41368index 040f751..98a5ed2 100644
41369--- a/drivers/scsi/sg.c
41370+++ b/drivers/scsi/sg.c
41371@@ -1064,7 +1064,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
41372 sdp->disk->disk_name,
41373 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41374 NULL,
41375- (char *)arg);
41376+ (char __user *)arg);
41377 case BLKTRACESTART:
41378 return blk_trace_startstop(sdp->device->request_queue, 1);
41379 case BLKTRACESTOP:
41380@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
41381 const struct file_operations * fops;
41382 };
41383
41384-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
41385+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
41386 {"allow_dio", &adio_fops},
41387 {"debug", &debug_fops},
41388 {"def_reserved_size", &dressz_fops},
41389@@ -2307,7 +2307,7 @@ sg_proc_init(void)
41390 {
41391 int k, mask;
41392 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
41393- struct sg_proc_leaf * leaf;
41394+ const struct sg_proc_leaf * leaf;
41395
41396 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
41397 if (!sg_proc_sgp)
41398diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
41399index 45374d6..61ee484 100644
41400--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
41401+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
41402@@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
41403 int do_iounmap = 0;
41404 int do_disable_device = 1;
41405
41406+ pax_track_stack();
41407+
41408 memset(&sym_dev, 0, sizeof(sym_dev));
41409 memset(&nvram, 0, sizeof(nvram));
41410 sym_dev.pdev = pdev;
41411diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
41412index eadc1ab..2d81457 100644
41413--- a/drivers/serial/kgdboc.c
41414+++ b/drivers/serial/kgdboc.c
41415@@ -18,7 +18,7 @@
41416
41417 #define MAX_CONFIG_LEN 40
41418
41419-static struct kgdb_io kgdboc_io_ops;
41420+static const struct kgdb_io kgdboc_io_ops;
41421
41422 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41423 static int configured = -1;
41424@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void)
41425 module_put(THIS_MODULE);
41426 }
41427
41428-static struct kgdb_io kgdboc_io_ops = {
41429+static const struct kgdb_io kgdboc_io_ops = {
41430 .name = "kgdboc",
41431 .read_char = kgdboc_get_char,
41432 .write_char = kgdboc_put_char,
41433diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41434index b76f246..7f41af7 100644
41435--- a/drivers/spi/spi.c
41436+++ b/drivers/spi/spi.c
41437@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
41438 EXPORT_SYMBOL_GPL(spi_sync);
41439
41440 /* portable code must never pass more than 32 bytes */
41441-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41442+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
41443
41444 static u8 *buf;
41445
41446diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
41447index 99010d4..6bad87b 100644
41448--- a/drivers/staging/android/binder.c
41449+++ b/drivers/staging/android/binder.c
41450@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_area_struct *vma)
41451 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
41452 }
41453
41454-static struct vm_operations_struct binder_vm_ops = {
41455+static const struct vm_operations_struct binder_vm_ops = {
41456 .open = binder_vma_open,
41457 .close = binder_vma_close,
41458 };
41459diff --git a/drivers/staging/b3dfg/b3dfg.c b/drivers/staging/b3dfg/b3dfg.c
41460index cda26bb..39fed3f 100644
41461--- a/drivers/staging/b3dfg/b3dfg.c
41462+++ b/drivers/staging/b3dfg/b3dfg.c
41463@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_area_struct *vma,
41464 return VM_FAULT_NOPAGE;
41465 }
41466
41467-static struct vm_operations_struct b3dfg_vm_ops = {
41468+static const struct vm_operations_struct b3dfg_vm_ops = {
41469 .fault = b3dfg_vma_fault,
41470 };
41471
41472@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp, struct vm_area_struct *vma)
41473 return r;
41474 }
41475
41476-static struct file_operations b3dfg_fops = {
41477+static const struct file_operations b3dfg_fops = {
41478 .owner = THIS_MODULE,
41479 .open = b3dfg_open,
41480 .release = b3dfg_release,
41481diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
41482index 908f25a..c9a579b 100644
41483--- a/drivers/staging/comedi/comedi_fops.c
41484+++ b/drivers/staging/comedi/comedi_fops.c
41485@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct *area)
41486 mutex_unlock(&dev->mutex);
41487 }
41488
41489-static struct vm_operations_struct comedi_vm_ops = {
41490+static const struct vm_operations_struct comedi_vm_ops = {
41491 .close = comedi_unmap,
41492 };
41493
41494diff --git a/drivers/staging/dream/qdsp5/adsp_driver.c b/drivers/staging/dream/qdsp5/adsp_driver.c
41495index e55a0db..577b776 100644
41496--- a/drivers/staging/dream/qdsp5/adsp_driver.c
41497+++ b/drivers/staging/dream/qdsp5/adsp_driver.c
41498@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_device(struct inode *inode)
41499 static dev_t adsp_devno;
41500 static struct class *adsp_class;
41501
41502-static struct file_operations adsp_fops = {
41503+static const struct file_operations adsp_fops = {
41504 .owner = THIS_MODULE,
41505 .open = adsp_open,
41506 .unlocked_ioctl = adsp_ioctl,
41507diff --git a/drivers/staging/dream/qdsp5/audio_aac.c b/drivers/staging/dream/qdsp5/audio_aac.c
41508index ad2390f..4116ee8 100644
41509--- a/drivers/staging/dream/qdsp5/audio_aac.c
41510+++ b/drivers/staging/dream/qdsp5/audio_aac.c
41511@@ -1022,7 +1022,7 @@ done:
41512 return rc;
41513 }
41514
41515-static struct file_operations audio_aac_fops = {
41516+static const struct file_operations audio_aac_fops = {
41517 .owner = THIS_MODULE,
41518 .open = audio_open,
41519 .release = audio_release,
41520diff --git a/drivers/staging/dream/qdsp5/audio_amrnb.c b/drivers/staging/dream/qdsp5/audio_amrnb.c
41521index cd818a5..870b37b 100644
41522--- a/drivers/staging/dream/qdsp5/audio_amrnb.c
41523+++ b/drivers/staging/dream/qdsp5/audio_amrnb.c
41524@@ -833,7 +833,7 @@ done:
41525 return rc;
41526 }
41527
41528-static struct file_operations audio_amrnb_fops = {
41529+static const struct file_operations audio_amrnb_fops = {
41530 .owner = THIS_MODULE,
41531 .open = audamrnb_open,
41532 .release = audamrnb_release,
41533diff --git a/drivers/staging/dream/qdsp5/audio_evrc.c b/drivers/staging/dream/qdsp5/audio_evrc.c
41534index 4b43e18..cedafda 100644
41535--- a/drivers/staging/dream/qdsp5/audio_evrc.c
41536+++ b/drivers/staging/dream/qdsp5/audio_evrc.c
41537@@ -805,7 +805,7 @@ dma_fail:
41538 return rc;
41539 }
41540
41541-static struct file_operations audio_evrc_fops = {
41542+static const struct file_operations audio_evrc_fops = {
41543 .owner = THIS_MODULE,
41544 .open = audevrc_open,
41545 .release = audevrc_release,
41546diff --git a/drivers/staging/dream/qdsp5/audio_in.c b/drivers/staging/dream/qdsp5/audio_in.c
41547index 3d950a2..9431118 100644
41548--- a/drivers/staging/dream/qdsp5/audio_in.c
41549+++ b/drivers/staging/dream/qdsp5/audio_in.c
41550@@ -913,7 +913,7 @@ static int audpre_open(struct inode *inode, struct file *file)
41551 return 0;
41552 }
41553
41554-static struct file_operations audio_fops = {
41555+static const struct file_operations audio_fops = {
41556 .owner = THIS_MODULE,
41557 .open = audio_in_open,
41558 .release = audio_in_release,
41559@@ -922,7 +922,7 @@ static struct file_operations audio_fops = {
41560 .unlocked_ioctl = audio_in_ioctl,
41561 };
41562
41563-static struct file_operations audpre_fops = {
41564+static const struct file_operations audpre_fops = {
41565 .owner = THIS_MODULE,
41566 .open = audpre_open,
41567 .unlocked_ioctl = audpre_ioctl,
41568diff --git a/drivers/staging/dream/qdsp5/audio_mp3.c b/drivers/staging/dream/qdsp5/audio_mp3.c
41569index b95574f..286c2f4 100644
41570--- a/drivers/staging/dream/qdsp5/audio_mp3.c
41571+++ b/drivers/staging/dream/qdsp5/audio_mp3.c
41572@@ -941,7 +941,7 @@ done:
41573 return rc;
41574 }
41575
41576-static struct file_operations audio_mp3_fops = {
41577+static const struct file_operations audio_mp3_fops = {
41578 .owner = THIS_MODULE,
41579 .open = audio_open,
41580 .release = audio_release,
41581diff --git a/drivers/staging/dream/qdsp5/audio_out.c b/drivers/staging/dream/qdsp5/audio_out.c
41582index d1adcf6..f8f9833 100644
41583--- a/drivers/staging/dream/qdsp5/audio_out.c
41584+++ b/drivers/staging/dream/qdsp5/audio_out.c
41585@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inode, struct file *file)
41586 return 0;
41587 }
41588
41589-static struct file_operations audio_fops = {
41590+static const struct file_operations audio_fops = {
41591 .owner = THIS_MODULE,
41592 .open = audio_open,
41593 .release = audio_release,
41594@@ -819,7 +819,7 @@ static struct file_operations audio_fops = {
41595 .unlocked_ioctl = audio_ioctl,
41596 };
41597
41598-static struct file_operations audpp_fops = {
41599+static const struct file_operations audpp_fops = {
41600 .owner = THIS_MODULE,
41601 .open = audpp_open,
41602 .unlocked_ioctl = audpp_ioctl,
41603diff --git a/drivers/staging/dream/qdsp5/audio_qcelp.c b/drivers/staging/dream/qdsp5/audio_qcelp.c
41604index f0f50e3..f6b9dbc 100644
41605--- a/drivers/staging/dream/qdsp5/audio_qcelp.c
41606+++ b/drivers/staging/dream/qdsp5/audio_qcelp.c
41607@@ -816,7 +816,7 @@ err:
41608 return rc;
41609 }
41610
41611-static struct file_operations audio_qcelp_fops = {
41612+static const struct file_operations audio_qcelp_fops = {
41613 .owner = THIS_MODULE,
41614 .open = audqcelp_open,
41615 .release = audqcelp_release,
41616diff --git a/drivers/staging/dream/qdsp5/snd.c b/drivers/staging/dream/qdsp5/snd.c
41617index 037d7ff..5469ec3 100644
41618--- a/drivers/staging/dream/qdsp5/snd.c
41619+++ b/drivers/staging/dream/qdsp5/snd.c
41620@@ -242,7 +242,7 @@ err:
41621 return rc;
41622 }
41623
41624-static struct file_operations snd_fops = {
41625+static const struct file_operations snd_fops = {
41626 .owner = THIS_MODULE,
41627 .open = snd_open,
41628 .release = snd_release,
41629diff --git a/drivers/staging/dream/smd/smd_qmi.c b/drivers/staging/dream/smd/smd_qmi.c
41630index d4e7d88..0ea632a 100644
41631--- a/drivers/staging/dream/smd/smd_qmi.c
41632+++ b/drivers/staging/dream/smd/smd_qmi.c
41633@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip, struct file *fp)
41634 return 0;
41635 }
41636
41637-static struct file_operations qmi_fops = {
41638+static const struct file_operations qmi_fops = {
41639 .owner = THIS_MODULE,
41640 .read = qmi_read,
41641 .write = qmi_write,
41642diff --git a/drivers/staging/dream/smd/smd_rpcrouter_device.c b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41643index cd3910b..ff053d3 100644
41644--- a/drivers/staging/dream/smd/smd_rpcrouter_device.c
41645+++ b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41646@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file *filp, unsigned int cmd,
41647 return rc;
41648 }
41649
41650-static struct file_operations rpcrouter_server_fops = {
41651+static const struct file_operations rpcrouter_server_fops = {
41652 .owner = THIS_MODULE,
41653 .open = rpcrouter_open,
41654 .release = rpcrouter_release,
41655@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_server_fops = {
41656 .unlocked_ioctl = rpcrouter_ioctl,
41657 };
41658
41659-static struct file_operations rpcrouter_router_fops = {
41660+static const struct file_operations rpcrouter_router_fops = {
41661 .owner = THIS_MODULE,
41662 .open = rpcrouter_open,
41663 .release = rpcrouter_release,
41664diff --git a/drivers/staging/dst/dcore.c b/drivers/staging/dst/dcore.c
41665index c24e4e0..07665be 100644
41666--- a/drivers/staging/dst/dcore.c
41667+++ b/drivers/staging/dst/dcore.c
41668@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendisk *disk, fmode_t mode)
41669 return 0;
41670 }
41671
41672-static struct block_device_operations dst_blk_ops = {
41673+static const struct block_device_operations dst_blk_ops = {
41674 .open = dst_bdev_open,
41675 .release = dst_bdev_release,
41676 .owner = THIS_MODULE,
41677@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(struct dst_ctl *ctl,
41678 n->size = ctl->size;
41679
41680 atomic_set(&n->refcnt, 1);
41681- atomic_long_set(&n->gen, 0);
41682+ atomic_long_set_unchecked(&n->gen, 0);
41683 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
41684
41685 err = dst_node_sysfs_init(n);
41686diff --git a/drivers/staging/dst/trans.c b/drivers/staging/dst/trans.c
41687index 557d372..8d84422 100644
41688--- a/drivers/staging/dst/trans.c
41689+++ b/drivers/staging/dst/trans.c
41690@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n, struct bio *bio)
41691 t->error = 0;
41692 t->retries = 0;
41693 atomic_set(&t->refcnt, 1);
41694- t->gen = atomic_long_inc_return(&n->gen);
41695+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
41696
41697 t->enc = bio_data_dir(bio);
41698 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
41699diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
41700index 94f7752..d051514 100644
41701--- a/drivers/staging/et131x/et1310_tx.c
41702+++ b/drivers/staging/et131x/et1310_tx.c
41703@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
41704 struct net_device_stats *stats = &etdev->net_stats;
41705
41706 if (pMpTcb->Flags & fMP_DEST_BROAD)
41707- atomic_inc(&etdev->Stats.brdcstxmt);
41708+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
41709 else if (pMpTcb->Flags & fMP_DEST_MULTI)
41710- atomic_inc(&etdev->Stats.multixmt);
41711+ atomic_inc_unchecked(&etdev->Stats.multixmt);
41712 else
41713- atomic_inc(&etdev->Stats.unixmt);
41714+ atomic_inc_unchecked(&etdev->Stats.unixmt);
41715
41716 if (pMpTcb->Packet) {
41717 stats->tx_bytes += pMpTcb->Packet->len;
41718diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
41719index 1dfe06f..f469b4d 100644
41720--- a/drivers/staging/et131x/et131x_adapter.h
41721+++ b/drivers/staging/et131x/et131x_adapter.h
41722@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
41723 * operations
41724 */
41725 u32 unircv; /* # multicast packets received */
41726- atomic_t unixmt; /* # multicast packets for Tx */
41727+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
41728 u32 multircv; /* # multicast packets received */
41729- atomic_t multixmt; /* # multicast packets for Tx */
41730+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
41731 u32 brdcstrcv; /* # broadcast packets received */
41732- atomic_t brdcstxmt; /* # broadcast packets for Tx */
41733+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
41734 u32 norcvbuf; /* # Rx packets discarded */
41735 u32 noxmtbuf; /* # Tx packets discarded */
41736
41737diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/go7007/go7007-v4l2.c
41738index 4bd353a..e28f455 100644
41739--- a/drivers/staging/go7007/go7007-v4l2.c
41740+++ b/drivers/staging/go7007/go7007-v4l2.c
41741@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41742 return 0;
41743 }
41744
41745-static struct vm_operations_struct go7007_vm_ops = {
41746+static const struct vm_operations_struct go7007_vm_ops = {
41747 .open = go7007_vm_open,
41748 .close = go7007_vm_close,
41749 .fault = go7007_vm_fault,
41750diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
41751index 366dc95..b974d87 100644
41752--- a/drivers/staging/hv/Channel.c
41753+++ b/drivers/staging/hv/Channel.c
41754@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
41755
41756 DPRINT_ENTER(VMBUS);
41757
41758- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
41759- atomic_inc(&gVmbusConnection.NextGpadlHandle);
41760+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
41761+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
41762
41763 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
41764 ASSERT(msgInfo != NULL);
41765diff --git a/drivers/staging/hv/Hv.c b/drivers/staging/hv/Hv.c
41766index b12237f..01ae28a 100644
41767--- a/drivers/staging/hv/Hv.c
41768+++ b/drivers/staging/hv/Hv.c
41769@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, void *Input, void *Output)
41770 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
41771 u32 outputAddressHi = outputAddress >> 32;
41772 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
41773- volatile void *hypercallPage = gHvContext.HypercallPage;
41774+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
41775
41776 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
41777 Control, Input, Output);
41778diff --git a/drivers/staging/hv/VmbusApi.h b/drivers/staging/hv/VmbusApi.h
41779index d089bb1..2ebc158 100644
41780--- a/drivers/staging/hv/VmbusApi.h
41781+++ b/drivers/staging/hv/VmbusApi.h
41782@@ -109,7 +109,7 @@ struct vmbus_channel_interface {
41783 u32 *GpadlHandle);
41784 int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle);
41785 void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo);
41786-};
41787+} __no_const;
41788
41789 /* Base driver object */
41790 struct hv_driver {
41791diff --git a/drivers/staging/hv/VmbusPrivate.h b/drivers/staging/hv/VmbusPrivate.h
41792index 5a37cce..6ecc88c 100644
41793--- a/drivers/staging/hv/VmbusPrivate.h
41794+++ b/drivers/staging/hv/VmbusPrivate.h
41795@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
41796 struct VMBUS_CONNECTION {
41797 enum VMBUS_CONNECT_STATE ConnectState;
41798
41799- atomic_t NextGpadlHandle;
41800+ atomic_unchecked_t NextGpadlHandle;
41801
41802 /*
41803 * Represents channel interrupts. Each bit position represents a
41804diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
41805index 871a202..ca50ddf 100644
41806--- a/drivers/staging/hv/blkvsc_drv.c
41807+++ b/drivers/staging/hv/blkvsc_drv.c
41808@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
41809 /* The one and only one */
41810 static struct blkvsc_driver_context g_blkvsc_drv;
41811
41812-static struct block_device_operations block_ops = {
41813+static const struct block_device_operations block_ops = {
41814 .owner = THIS_MODULE,
41815 .open = blkvsc_open,
41816 .release = blkvsc_release,
41817diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
41818index 6acc49a..fbc8d46 100644
41819--- a/drivers/staging/hv/vmbus_drv.c
41820+++ b/drivers/staging/hv/vmbus_drv.c
41821@@ -532,7 +532,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41822 to_device_context(root_device_obj);
41823 struct device_context *child_device_ctx =
41824 to_device_context(child_device_obj);
41825- static atomic_t device_num = ATOMIC_INIT(0);
41826+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41827
41828 DPRINT_ENTER(VMBUS_DRV);
41829
41830@@ -541,7 +541,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41831
41832 /* Set the device name. Otherwise, device_register() will fail. */
41833 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
41834- atomic_inc_return(&device_num));
41835+ atomic_inc_return_unchecked(&device_num));
41836
41837 /* The new device belongs to this bus */
41838 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
41839diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
41840index d926189..17b19fd 100644
41841--- a/drivers/staging/iio/ring_generic.h
41842+++ b/drivers/staging/iio/ring_generic.h
41843@@ -87,7 +87,7 @@ struct iio_ring_access_funcs {
41844
41845 int (*is_enabled)(struct iio_ring_buffer *ring);
41846 int (*enable)(struct iio_ring_buffer *ring);
41847-};
41848+} __no_const;
41849
41850 /**
41851 * struct iio_ring_buffer - general ring buffer structure
41852diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41853index 1b237b7..88c624e 100644
41854--- a/drivers/staging/octeon/ethernet-rx.c
41855+++ b/drivers/staging/octeon/ethernet-rx.c
41856@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41857 /* Increment RX stats for virtual ports */
41858 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41859 #ifdef CONFIG_64BIT
41860- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41861- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41862+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41863+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41864 #else
41865- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41866- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41867+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41868+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41869 #endif
41870 }
41871 netif_receive_skb(skb);
41872@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41873 dev->name);
41874 */
41875 #ifdef CONFIG_64BIT
41876- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41877+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
41878 #else
41879- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41880+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
41881 #endif
41882 dev_kfree_skb_irq(skb);
41883 }
41884diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41885index 492c502..d9909f1 100644
41886--- a/drivers/staging/octeon/ethernet.c
41887+++ b/drivers/staging/octeon/ethernet.c
41888@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41889 * since the RX tasklet also increments it.
41890 */
41891 #ifdef CONFIG_64BIT
41892- atomic64_add(rx_status.dropped_packets,
41893- (atomic64_t *)&priv->stats.rx_dropped);
41894+ atomic64_add_unchecked(rx_status.dropped_packets,
41895+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41896 #else
41897- atomic_add(rx_status.dropped_packets,
41898- (atomic_t *)&priv->stats.rx_dropped);
41899+ atomic_add_unchecked(rx_status.dropped_packets,
41900+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
41901 #endif
41902 }
41903
41904diff --git a/drivers/staging/otus/80211core/pub_zfi.h b/drivers/staging/otus/80211core/pub_zfi.h
41905index a35bd5d..28fff45 100644
41906--- a/drivers/staging/otus/80211core/pub_zfi.h
41907+++ b/drivers/staging/otus/80211core/pub_zfi.h
41908@@ -531,7 +531,7 @@ struct zsCbFuncTbl
41909 u8_t (*zfcbClassifyTxPacket)(zdev_t* dev, zbuf_t* buf);
41910
41911 void (*zfcbHwWatchDogNotify)(zdev_t* dev);
41912-};
41913+} __no_const;
41914
41915 extern void zfZeroMemory(u8_t* va, u16_t length);
41916 #define ZM_INIT_CB_FUNC_TABLE(p) zfZeroMemory((u8_t *)p, sizeof(struct zsCbFuncTbl));
41917diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
41918index c39a25f..696f5aa 100644
41919--- a/drivers/staging/panel/panel.c
41920+++ b/drivers/staging/panel/panel.c
41921@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *inode, struct file *file)
41922 return 0;
41923 }
41924
41925-static struct file_operations lcd_fops = {
41926+static const struct file_operations lcd_fops = {
41927 .write = lcd_write,
41928 .open = lcd_open,
41929 .release = lcd_release,
41930@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *inode, struct file *file)
41931 return 0;
41932 }
41933
41934-static struct file_operations keypad_fops = {
41935+static const struct file_operations keypad_fops = {
41936 .read = keypad_read, /* read */
41937 .open = keypad_open, /* open */
41938 .release = keypad_release, /* close */
41939diff --git a/drivers/staging/phison/phison.c b/drivers/staging/phison/phison.c
41940index 270ebcb..37e46af 100644
41941--- a/drivers/staging/phison/phison.c
41942+++ b/drivers/staging/phison/phison.c
41943@@ -43,7 +43,7 @@ static struct scsi_host_template phison_sht = {
41944 ATA_BMDMA_SHT(DRV_NAME),
41945 };
41946
41947-static struct ata_port_operations phison_ops = {
41948+static const struct ata_port_operations phison_ops = {
41949 .inherits = &ata_bmdma_port_ops,
41950 .prereset = phison_pre_reset,
41951 };
41952diff --git a/drivers/staging/poch/poch.c b/drivers/staging/poch/poch.c
41953index 2eb8e3d..57616a7 100644
41954--- a/drivers/staging/poch/poch.c
41955+++ b/drivers/staging/poch/poch.c
41956@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inode, struct file *filp,
41957 return 0;
41958 }
41959
41960-static struct file_operations poch_fops = {
41961+static const struct file_operations poch_fops = {
41962 .owner = THIS_MODULE,
41963 .open = poch_open,
41964 .release = poch_release,
41965diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
41966index c94de31..19402bc 100644
41967--- a/drivers/staging/pohmelfs/inode.c
41968+++ b/drivers/staging/pohmelfs/inode.c
41969@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
41970 mutex_init(&psb->mcache_lock);
41971 psb->mcache_root = RB_ROOT;
41972 psb->mcache_timeout = msecs_to_jiffies(5000);
41973- atomic_long_set(&psb->mcache_gen, 0);
41974+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
41975
41976 psb->trans_max_pages = 100;
41977
41978@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
41979 INIT_LIST_HEAD(&psb->crypto_ready_list);
41980 INIT_LIST_HEAD(&psb->crypto_active_list);
41981
41982- atomic_set(&psb->trans_gen, 1);
41983+ atomic_set_unchecked(&psb->trans_gen, 1);
41984 atomic_long_set(&psb->total_inodes, 0);
41985
41986 mutex_init(&psb->state_lock);
41987diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
41988index e22665c..a2a9390 100644
41989--- a/drivers/staging/pohmelfs/mcache.c
41990+++ b/drivers/staging/pohmelfs/mcache.c
41991@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
41992 m->data = data;
41993 m->start = start;
41994 m->size = size;
41995- m->gen = atomic_long_inc_return(&psb->mcache_gen);
41996+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
41997
41998 mutex_lock(&psb->mcache_lock);
41999 err = pohmelfs_mcache_insert(psb, m);
42000diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
42001index 623a07d..4035c19 100644
42002--- a/drivers/staging/pohmelfs/netfs.h
42003+++ b/drivers/staging/pohmelfs/netfs.h
42004@@ -570,14 +570,14 @@ struct pohmelfs_config;
42005 struct pohmelfs_sb {
42006 struct rb_root mcache_root;
42007 struct mutex mcache_lock;
42008- atomic_long_t mcache_gen;
42009+ atomic_long_unchecked_t mcache_gen;
42010 unsigned long mcache_timeout;
42011
42012 unsigned int idx;
42013
42014 unsigned int trans_retries;
42015
42016- atomic_t trans_gen;
42017+ atomic_unchecked_t trans_gen;
42018
42019 unsigned int crypto_attached_size;
42020 unsigned int crypto_align_size;
42021diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
42022index 36a2535..0591bf4 100644
42023--- a/drivers/staging/pohmelfs/trans.c
42024+++ b/drivers/staging/pohmelfs/trans.c
42025@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
42026 int err;
42027 struct netfs_cmd *cmd = t->iovec.iov_base;
42028
42029- t->gen = atomic_inc_return(&psb->trans_gen);
42030+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
42031
42032 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
42033 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
42034diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
42035index f890a16..509ece8 100644
42036--- a/drivers/staging/sep/sep_driver.c
42037+++ b/drivers/staging/sep/sep_driver.c
42038@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver = {
42039 static dev_t sep_devno;
42040
42041 /* the files operations structure of the driver */
42042-static struct file_operations sep_file_operations = {
42043+static const struct file_operations sep_file_operations = {
42044 .owner = THIS_MODULE,
42045 .ioctl = sep_ioctl,
42046 .poll = sep_poll,
42047diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
42048index 5e16bc3..7655b10 100644
42049--- a/drivers/staging/usbip/usbip_common.h
42050+++ b/drivers/staging/usbip/usbip_common.h
42051@@ -374,7 +374,7 @@ struct usbip_device {
42052 void (*shutdown)(struct usbip_device *);
42053 void (*reset)(struct usbip_device *);
42054 void (*unusable)(struct usbip_device *);
42055- } eh_ops;
42056+ } __no_const eh_ops;
42057 };
42058
42059
42060diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42061index 57f7946..d9df23d 100644
42062--- a/drivers/staging/usbip/vhci.h
42063+++ b/drivers/staging/usbip/vhci.h
42064@@ -92,7 +92,7 @@ struct vhci_hcd {
42065 unsigned resuming:1;
42066 unsigned long re_timeout;
42067
42068- atomic_t seqnum;
42069+ atomic_unchecked_t seqnum;
42070
42071 /*
42072 * NOTE:
42073diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42074index 20cd7db..c2693ff 100644
42075--- a/drivers/staging/usbip/vhci_hcd.c
42076+++ b/drivers/staging/usbip/vhci_hcd.c
42077@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
42078 return;
42079 }
42080
42081- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42082+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42083 if (priv->seqnum == 0xffff)
42084 usbip_uinfo("seqnum max\n");
42085
42086@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42087 return -ENOMEM;
42088 }
42089
42090- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42091+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42092 if (unlink->seqnum == 0xffff)
42093 usbip_uinfo("seqnum max\n");
42094
42095@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hcd)
42096 vdev->rhport = rhport;
42097 }
42098
42099- atomic_set(&vhci->seqnum, 0);
42100+ atomic_set_unchecked(&vhci->seqnum, 0);
42101 spin_lock_init(&vhci->lock);
42102
42103
42104diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42105index 7fd76fe..673695a 100644
42106--- a/drivers/staging/usbip/vhci_rx.c
42107+++ b/drivers/staging/usbip/vhci_rx.c
42108@@ -79,7 +79,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42109 usbip_uerr("cannot find a urb of seqnum %u\n",
42110 pdu->base.seqnum);
42111 usbip_uinfo("max seqnum %d\n",
42112- atomic_read(&the_controller->seqnum));
42113+ atomic_read_unchecked(&the_controller->seqnum));
42114 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42115 return;
42116 }
42117diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
42118index 7891288..8e31300 100644
42119--- a/drivers/staging/vme/devices/vme_user.c
42120+++ b/drivers/staging/vme/devices/vme_user.c
42121@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *, struct file *, unsigned int,
42122 static int __init vme_user_probe(struct device *, int, int);
42123 static int __exit vme_user_remove(struct device *, int, int);
42124
42125-static struct file_operations vme_user_fops = {
42126+static const struct file_operations vme_user_fops = {
42127 .open = vme_user_open,
42128 .release = vme_user_release,
42129 .read = vme_user_read,
42130diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42131index 58abf44..00c1fc8 100644
42132--- a/drivers/staging/vt6655/hostap.c
42133+++ b/drivers/staging/vt6655/hostap.c
42134@@ -84,7 +84,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42135 PSDevice apdev_priv;
42136 struct net_device *dev = pDevice->dev;
42137 int ret;
42138- const struct net_device_ops apdev_netdev_ops = {
42139+ net_device_ops_no_const apdev_netdev_ops = {
42140 .ndo_start_xmit = pDevice->tx_80211,
42141 };
42142
42143diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42144index 0c8267a..db1f363 100644
42145--- a/drivers/staging/vt6656/hostap.c
42146+++ b/drivers/staging/vt6656/hostap.c
42147@@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42148 PSDevice apdev_priv;
42149 struct net_device *dev = pDevice->dev;
42150 int ret;
42151- const struct net_device_ops apdev_netdev_ops = {
42152+ net_device_ops_no_const apdev_netdev_ops = {
42153 .ndo_start_xmit = pDevice->tx_80211,
42154 };
42155
42156diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
42157index 925678b..da7f5ed 100644
42158--- a/drivers/staging/wlan-ng/hfa384x_usb.c
42159+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
42160@@ -205,7 +205,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
42161
42162 struct usbctlx_completor {
42163 int (*complete) (struct usbctlx_completor *);
42164-};
42165+} __no_const;
42166 typedef struct usbctlx_completor usbctlx_completor_t;
42167
42168 static int
42169diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
42170index 40de151..924f268 100644
42171--- a/drivers/telephony/ixj.c
42172+++ b/drivers/telephony/ixj.c
42173@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
42174 bool mContinue;
42175 char *pIn, *pOut;
42176
42177+ pax_track_stack();
42178+
42179 if (!SCI_Prepare(j))
42180 return 0;
42181
42182diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
42183index e941367..b631f5a 100644
42184--- a/drivers/uio/uio.c
42185+++ b/drivers/uio/uio.c
42186@@ -23,6 +23,7 @@
42187 #include <linux/string.h>
42188 #include <linux/kobject.h>
42189 #include <linux/uio_driver.h>
42190+#include <asm/local.h>
42191
42192 #define UIO_MAX_DEVICES 255
42193
42194@@ -30,10 +31,10 @@ struct uio_device {
42195 struct module *owner;
42196 struct device *dev;
42197 int minor;
42198- atomic_t event;
42199+ atomic_unchecked_t event;
42200 struct fasync_struct *async_queue;
42201 wait_queue_head_t wait;
42202- int vma_count;
42203+ local_t vma_count;
42204 struct uio_info *info;
42205 struct kobject *map_dir;
42206 struct kobject *portio_dir;
42207@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
42208 return entry->show(mem, buf);
42209 }
42210
42211-static struct sysfs_ops map_sysfs_ops = {
42212+static const struct sysfs_ops map_sysfs_ops = {
42213 .show = map_type_show,
42214 };
42215
42216@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
42217 return entry->show(port, buf);
42218 }
42219
42220-static struct sysfs_ops portio_sysfs_ops = {
42221+static const struct sysfs_ops portio_sysfs_ops = {
42222 .show = portio_type_show,
42223 };
42224
42225@@ -255,7 +256,7 @@ static ssize_t show_event(struct device *dev,
42226 struct uio_device *idev = dev_get_drvdata(dev);
42227 if (idev)
42228 return sprintf(buf, "%u\n",
42229- (unsigned int)atomic_read(&idev->event));
42230+ (unsigned int)atomic_read_unchecked(&idev->event));
42231 else
42232 return -ENODEV;
42233 }
42234@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *info)
42235 {
42236 struct uio_device *idev = info->uio_dev;
42237
42238- atomic_inc(&idev->event);
42239+ atomic_inc_unchecked(&idev->event);
42240 wake_up_interruptible(&idev->wait);
42241 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
42242 }
42243@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode, struct file *filep)
42244 }
42245
42246 listener->dev = idev;
42247- listener->event_count = atomic_read(&idev->event);
42248+ listener->event_count = atomic_read_unchecked(&idev->event);
42249 filep->private_data = listener;
42250
42251 if (idev->info->open) {
42252@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
42253 return -EIO;
42254
42255 poll_wait(filep, &idev->wait, wait);
42256- if (listener->event_count != atomic_read(&idev->event))
42257+ if (listener->event_count != atomic_read_unchecked(&idev->event))
42258 return POLLIN | POLLRDNORM;
42259 return 0;
42260 }
42261@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
42262 do {
42263 set_current_state(TASK_INTERRUPTIBLE);
42264
42265- event_count = atomic_read(&idev->event);
42266+ event_count = atomic_read_unchecked(&idev->event);
42267 if (event_count != listener->event_count) {
42268 if (copy_to_user(buf, &event_count, count))
42269 retval = -EFAULT;
42270@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
42271 static void uio_vma_open(struct vm_area_struct *vma)
42272 {
42273 struct uio_device *idev = vma->vm_private_data;
42274- idev->vma_count++;
42275+ local_inc(&idev->vma_count);
42276 }
42277
42278 static void uio_vma_close(struct vm_area_struct *vma)
42279 {
42280 struct uio_device *idev = vma->vm_private_data;
42281- idev->vma_count--;
42282+ local_dec(&idev->vma_count);
42283 }
42284
42285 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42286@@ -840,7 +841,7 @@ int __uio_register_device(struct module *owner,
42287 idev->owner = owner;
42288 idev->info = info;
42289 init_waitqueue_head(&idev->wait);
42290- atomic_set(&idev->event, 0);
42291+ atomic_set_unchecked(&idev->event, 0);
42292
42293 ret = uio_get_minor(idev);
42294 if (ret)
42295diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
42296index fbea856..06efea6 100644
42297--- a/drivers/usb/atm/usbatm.c
42298+++ b/drivers/usb/atm/usbatm.c
42299@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42300 if (printk_ratelimit())
42301 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42302 __func__, vpi, vci);
42303- atomic_inc(&vcc->stats->rx_err);
42304+ atomic_inc_unchecked(&vcc->stats->rx_err);
42305 return;
42306 }
42307
42308@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42309 if (length > ATM_MAX_AAL5_PDU) {
42310 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42311 __func__, length, vcc);
42312- atomic_inc(&vcc->stats->rx_err);
42313+ atomic_inc_unchecked(&vcc->stats->rx_err);
42314 goto out;
42315 }
42316
42317@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42318 if (sarb->len < pdu_length) {
42319 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42320 __func__, pdu_length, sarb->len, vcc);
42321- atomic_inc(&vcc->stats->rx_err);
42322+ atomic_inc_unchecked(&vcc->stats->rx_err);
42323 goto out;
42324 }
42325
42326 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42327 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42328 __func__, vcc);
42329- atomic_inc(&vcc->stats->rx_err);
42330+ atomic_inc_unchecked(&vcc->stats->rx_err);
42331 goto out;
42332 }
42333
42334@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42335 if (printk_ratelimit())
42336 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42337 __func__, length);
42338- atomic_inc(&vcc->stats->rx_drop);
42339+ atomic_inc_unchecked(&vcc->stats->rx_drop);
42340 goto out;
42341 }
42342
42343@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42344
42345 vcc->push(vcc, skb);
42346
42347- atomic_inc(&vcc->stats->rx);
42348+ atomic_inc_unchecked(&vcc->stats->rx);
42349 out:
42350 skb_trim(sarb, 0);
42351 }
42352@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned long data)
42353 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42354
42355 usbatm_pop(vcc, skb);
42356- atomic_inc(&vcc->stats->tx);
42357+ atomic_inc_unchecked(&vcc->stats->tx);
42358
42359 skb = skb_dequeue(&instance->sndqueue);
42360 }
42361@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
42362 if (!left--)
42363 return sprintf(page,
42364 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42365- atomic_read(&atm_dev->stats.aal5.tx),
42366- atomic_read(&atm_dev->stats.aal5.tx_err),
42367- atomic_read(&atm_dev->stats.aal5.rx),
42368- atomic_read(&atm_dev->stats.aal5.rx_err),
42369- atomic_read(&atm_dev->stats.aal5.rx_drop));
42370+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42371+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42372+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42373+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42374+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42375
42376 if (!left--) {
42377 if (instance->disconnected)
42378diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
42379index 3e564bf..949b448 100644
42380--- a/drivers/usb/class/cdc-wdm.c
42381+++ b/drivers/usb/class/cdc-wdm.c
42382@@ -314,7 +314,7 @@ static ssize_t wdm_write
42383 if (r < 0)
42384 goto outnp;
42385
42386- if (!file->f_flags && O_NONBLOCK)
42387+ if (!(file->f_flags & O_NONBLOCK))
42388 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
42389 &desc->flags));
42390 else
42391diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
42392index 24e6205..fe5a5d4 100644
42393--- a/drivers/usb/core/hcd.c
42394+++ b/drivers/usb/core/hcd.c
42395@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
42396
42397 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42398
42399-struct usb_mon_operations *mon_ops;
42400+const struct usb_mon_operations *mon_ops;
42401
42402 /*
42403 * The registration is unlocked.
42404@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
42405 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42406 */
42407
42408-int usb_mon_register (struct usb_mon_operations *ops)
42409+int usb_mon_register (const struct usb_mon_operations *ops)
42410 {
42411
42412 if (mon_ops)
42413diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
42414index bcbe104..9cfd1c6 100644
42415--- a/drivers/usb/core/hcd.h
42416+++ b/drivers/usb/core/hcd.h
42417@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) { }
42418 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42419
42420 struct usb_mon_operations {
42421- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
42422- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42423- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42424+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
42425+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42426+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42427 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
42428 };
42429
42430-extern struct usb_mon_operations *mon_ops;
42431+extern const struct usb_mon_operations *mon_ops;
42432
42433 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
42434 {
42435@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
42436 (*mon_ops->urb_complete)(bus, urb, status);
42437 }
42438
42439-int usb_mon_register(struct usb_mon_operations *ops);
42440+int usb_mon_register(const struct usb_mon_operations *ops);
42441 void usb_mon_deregister(void);
42442
42443 #else
42444diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
42445index 409cc94..a673bad 100644
42446--- a/drivers/usb/core/message.c
42447+++ b/drivers/usb/core/message.c
42448@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
42449 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42450 if (buf) {
42451 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42452- if (len > 0) {
42453- smallbuf = kmalloc(++len, GFP_NOIO);
42454+ if (len++ > 0) {
42455+ smallbuf = kmalloc(len, GFP_NOIO);
42456 if (!smallbuf)
42457 return buf;
42458 memcpy(smallbuf, buf, len);
42459diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
42460index 62ff5e7..530b74e 100644
42461--- a/drivers/usb/misc/appledisplay.c
42462+++ b/drivers/usb/misc/appledisplay.c
42463@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
42464 return pdata->msgdata[1];
42465 }
42466
42467-static struct backlight_ops appledisplay_bl_data = {
42468+static const struct backlight_ops appledisplay_bl_data = {
42469 .get_brightness = appledisplay_bl_get_brightness,
42470 .update_status = appledisplay_bl_update_status,
42471 };
42472diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
42473index e0c2db3..bd8cb66 100644
42474--- a/drivers/usb/mon/mon_main.c
42475+++ b/drivers/usb/mon/mon_main.c
42476@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42477 /*
42478 * Ops
42479 */
42480-static struct usb_mon_operations mon_ops_0 = {
42481+static const struct usb_mon_operations mon_ops_0 = {
42482 .urb_submit = mon_submit,
42483 .urb_submit_error = mon_submit_error,
42484 .urb_complete = mon_complete,
42485diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
42486index d6bea3e..60b250e 100644
42487--- a/drivers/usb/wusbcore/wa-hc.h
42488+++ b/drivers/usb/wusbcore/wa-hc.h
42489@@ -192,7 +192,7 @@ struct wahc {
42490 struct list_head xfer_delayed_list;
42491 spinlock_t xfer_list_lock;
42492 struct work_struct xfer_work;
42493- atomic_t xfer_id_count;
42494+ atomic_unchecked_t xfer_id_count;
42495 };
42496
42497
42498@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
42499 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42500 spin_lock_init(&wa->xfer_list_lock);
42501 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42502- atomic_set(&wa->xfer_id_count, 1);
42503+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42504 }
42505
42506 /**
42507diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
42508index 613a5fc..3174865 100644
42509--- a/drivers/usb/wusbcore/wa-xfer.c
42510+++ b/drivers/usb/wusbcore/wa-xfer.c
42511@@ -293,7 +293,7 @@ out:
42512 */
42513 static void wa_xfer_id_init(struct wa_xfer *xfer)
42514 {
42515- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42516+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42517 }
42518
42519 /*
42520diff --git a/drivers/uwb/wlp/messages.c b/drivers/uwb/wlp/messages.c
42521index aa42fce..f8a828c 100644
42522--- a/drivers/uwb/wlp/messages.c
42523+++ b/drivers/uwb/wlp/messages.c
42524@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct sk_buff *skb)
42525 size_t len = skb->len;
42526 size_t used;
42527 ssize_t result;
42528- struct wlp_nonce enonce, rnonce;
42529+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
42530 enum wlp_assc_error assc_err;
42531 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
42532 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
42533diff --git a/drivers/uwb/wlp/sysfs.c b/drivers/uwb/wlp/sysfs.c
42534index 0370399..6627c94 100644
42535--- a/drivers/uwb/wlp/sysfs.c
42536+++ b/drivers/uwb/wlp/sysfs.c
42537@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobject *kobj, struct attribute *attr,
42538 return ret;
42539 }
42540
42541-static
42542-struct sysfs_ops wss_sysfs_ops = {
42543+static const struct sysfs_ops wss_sysfs_ops = {
42544 .show = wlp_wss_attr_show,
42545 .store = wlp_wss_attr_store,
42546 };
42547diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
42548index d5e8010..5687b56 100644
42549--- a/drivers/video/atmel_lcdfb.c
42550+++ b/drivers/video/atmel_lcdfb.c
42551@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struct backlight_device *bl)
42552 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
42553 }
42554
42555-static struct backlight_ops atmel_lcdc_bl_ops = {
42556+static const struct backlight_ops atmel_lcdc_bl_ops = {
42557 .update_status = atmel_bl_update_status,
42558 .get_brightness = atmel_bl_get_brightness,
42559 };
42560diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42561index e4e4d43..66bcbcc 100644
42562--- a/drivers/video/aty/aty128fb.c
42563+++ b/drivers/video/aty/aty128fb.c
42564@@ -149,7 +149,7 @@ enum {
42565 };
42566
42567 /* Must match above enum */
42568-static const char *r128_family[] __devinitdata = {
42569+static const char *r128_family[] __devinitconst = {
42570 "AGP",
42571 "PCI",
42572 "PRO AGP",
42573@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(struct backlight_device *bd)
42574 return bd->props.brightness;
42575 }
42576
42577-static struct backlight_ops aty128_bl_data = {
42578+static const struct backlight_ops aty128_bl_data = {
42579 .get_brightness = aty128_bl_get_brightness,
42580 .update_status = aty128_bl_update_status,
42581 };
42582diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
42583index 913b4a4..9295a38 100644
42584--- a/drivers/video/aty/atyfb_base.c
42585+++ b/drivers/video/aty/atyfb_base.c
42586@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct backlight_device *bd)
42587 return bd->props.brightness;
42588 }
42589
42590-static struct backlight_ops aty_bl_data = {
42591+static const struct backlight_ops aty_bl_data = {
42592 .get_brightness = aty_bl_get_brightness,
42593 .update_status = aty_bl_update_status,
42594 };
42595diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
42596index 1a056ad..221bd6a 100644
42597--- a/drivers/video/aty/radeon_backlight.c
42598+++ b/drivers/video/aty/radeon_backlight.c
42599@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(struct backlight_device *bd)
42600 return bd->props.brightness;
42601 }
42602
42603-static struct backlight_ops radeon_bl_data = {
42604+static const struct backlight_ops radeon_bl_data = {
42605 .get_brightness = radeon_bl_get_brightness,
42606 .update_status = radeon_bl_update_status,
42607 };
42608diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
42609index ad05da5..3cb2cb9 100644
42610--- a/drivers/video/backlight/adp5520_bl.c
42611+++ b/drivers/video/backlight/adp5520_bl.c
42612@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl)
42613 return error ? data->current_brightness : reg_val;
42614 }
42615
42616-static struct backlight_ops adp5520_bl_ops = {
42617+static const struct backlight_ops adp5520_bl_ops = {
42618 .update_status = adp5520_bl_update_status,
42619 .get_brightness = adp5520_bl_get_brightness,
42620 };
42621diff --git a/drivers/video/backlight/adx_bl.c b/drivers/video/backlight/adx_bl.c
42622index 2c3bdfc..d769b0b 100644
42623--- a/drivers/video/backlight/adx_bl.c
42624+++ b/drivers/video/backlight/adx_bl.c
42625@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct fb_info *fb)
42626 return 1;
42627 }
42628
42629-static struct backlight_ops adx_backlight_ops = {
42630+static const struct backlight_ops adx_backlight_ops = {
42631 .options = 0,
42632 .update_status = adx_backlight_update_status,
42633 .get_brightness = adx_backlight_get_brightness,
42634diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
42635index 505c082..6b6b3cc 100644
42636--- a/drivers/video/backlight/atmel-pwm-bl.c
42637+++ b/drivers/video/backlight/atmel-pwm-bl.c
42638@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
42639 return pwm_channel_enable(&pwmbl->pwmc);
42640 }
42641
42642-static struct backlight_ops atmel_pwm_bl_ops = {
42643+static const struct backlight_ops atmel_pwm_bl_ops = {
42644 .get_brightness = atmel_pwm_bl_get_intensity,
42645 .update_status = atmel_pwm_bl_set_intensity,
42646 };
42647diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
42648index 5e20e6e..89025e6 100644
42649--- a/drivers/video/backlight/backlight.c
42650+++ b/drivers/video/backlight/backlight.c
42651@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
42652 * ERR_PTR() or a pointer to the newly allocated device.
42653 */
42654 struct backlight_device *backlight_device_register(const char *name,
42655- struct device *parent, void *devdata, struct backlight_ops *ops)
42656+ struct device *parent, void *devdata, const struct backlight_ops *ops)
42657 {
42658 struct backlight_device *new_bd;
42659 int rc;
42660diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
42661index 9677494..b4bcf80 100644
42662--- a/drivers/video/backlight/corgi_lcd.c
42663+++ b/drivers/video/backlight/corgi_lcd.c
42664@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit)
42665 }
42666 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
42667
42668-static struct backlight_ops corgi_bl_ops = {
42669+static const struct backlight_ops corgi_bl_ops = {
42670 .get_brightness = corgi_bl_get_intensity,
42671 .update_status = corgi_bl_update_status,
42672 };
42673diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
42674index b9fe62b..2914bf1 100644
42675--- a/drivers/video/backlight/cr_bllcd.c
42676+++ b/drivers/video/backlight/cr_bllcd.c
42677@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(struct backlight_device *bd)
42678 return intensity;
42679 }
42680
42681-static struct backlight_ops cr_backlight_ops = {
42682+static const struct backlight_ops cr_backlight_ops = {
42683 .get_brightness = cr_backlight_get_intensity,
42684 .update_status = cr_backlight_set_intensity,
42685 };
42686diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
42687index 701a108..feacfd5 100644
42688--- a/drivers/video/backlight/da903x_bl.c
42689+++ b/drivers/video/backlight/da903x_bl.c
42690@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightness(struct backlight_device *bl)
42691 return data->current_brightness;
42692 }
42693
42694-static struct backlight_ops da903x_backlight_ops = {
42695+static const struct backlight_ops da903x_backlight_ops = {
42696 .update_status = da903x_backlight_update_status,
42697 .get_brightness = da903x_backlight_get_brightness,
42698 };
42699diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
42700index 6d27f62..e6d348e 100644
42701--- a/drivers/video/backlight/generic_bl.c
42702+++ b/drivers/video/backlight/generic_bl.c
42703@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
42704 }
42705 EXPORT_SYMBOL(corgibl_limit_intensity);
42706
42707-static struct backlight_ops genericbl_ops = {
42708+static const struct backlight_ops genericbl_ops = {
42709 .options = BL_CORE_SUSPENDRESUME,
42710 .get_brightness = genericbl_get_intensity,
42711 .update_status = genericbl_send_intensity,
42712diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
42713index 7fb4eef..f7cc528 100644
42714--- a/drivers/video/backlight/hp680_bl.c
42715+++ b/drivers/video/backlight/hp680_bl.c
42716@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
42717 return current_intensity;
42718 }
42719
42720-static struct backlight_ops hp680bl_ops = {
42721+static const struct backlight_ops hp680bl_ops = {
42722 .get_brightness = hp680bl_get_intensity,
42723 .update_status = hp680bl_set_intensity,
42724 };
42725diff --git a/drivers/video/backlight/jornada720_bl.c b/drivers/video/backlight/jornada720_bl.c
42726index 7aed256..db9071f 100644
42727--- a/drivers/video/backlight/jornada720_bl.c
42728+++ b/drivers/video/backlight/jornada720_bl.c
42729@@ -93,7 +93,7 @@ out:
42730 return ret;
42731 }
42732
42733-static struct backlight_ops jornada_bl_ops = {
42734+static const struct backlight_ops jornada_bl_ops = {
42735 .get_brightness = jornada_bl_get_brightness,
42736 .update_status = jornada_bl_update_status,
42737 .options = BL_CORE_SUSPENDRESUME,
42738diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
42739index a38fda1..939e7b8 100644
42740--- a/drivers/video/backlight/kb3886_bl.c
42741+++ b/drivers/video/backlight/kb3886_bl.c
42742@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct backlight_device *bd)
42743 return kb3886bl_intensity;
42744 }
42745
42746-static struct backlight_ops kb3886bl_ops = {
42747+static const struct backlight_ops kb3886bl_ops = {
42748 .get_brightness = kb3886bl_get_intensity,
42749 .update_status = kb3886bl_send_intensity,
42750 };
42751diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
42752index 6b488b8..00a9591 100644
42753--- a/drivers/video/backlight/locomolcd.c
42754+++ b/drivers/video/backlight/locomolcd.c
42755@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struct backlight_device *bd)
42756 return current_intensity;
42757 }
42758
42759-static struct backlight_ops locomobl_data = {
42760+static const struct backlight_ops locomobl_data = {
42761 .get_brightness = locomolcd_get_intensity,
42762 .update_status = locomolcd_set_intensity,
42763 };
42764diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
42765index 99bdfa8..3dac448 100644
42766--- a/drivers/video/backlight/mbp_nvidia_bl.c
42767+++ b/drivers/video/backlight/mbp_nvidia_bl.c
42768@@ -33,7 +33,7 @@ struct dmi_match_data {
42769 unsigned long iostart;
42770 unsigned long iolen;
42771 /* Backlight operations structure. */
42772- struct backlight_ops backlight_ops;
42773+ const struct backlight_ops backlight_ops;
42774 };
42775
42776 /* Module parameters. */
42777diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
42778index cbad67e..3cf900e 100644
42779--- a/drivers/video/backlight/omap1_bl.c
42780+++ b/drivers/video/backlight/omap1_bl.c
42781@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct backlight_device *dev)
42782 return bl->current_intensity;
42783 }
42784
42785-static struct backlight_ops omapbl_ops = {
42786+static const struct backlight_ops omapbl_ops = {
42787 .get_brightness = omapbl_get_intensity,
42788 .update_status = omapbl_update_status,
42789 };
42790diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
42791index 9edaf24..075786e 100644
42792--- a/drivers/video/backlight/progear_bl.c
42793+++ b/drivers/video/backlight/progear_bl.c
42794@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struct backlight_device *bd)
42795 return intensity - HW_LEVEL_MIN;
42796 }
42797
42798-static struct backlight_ops progearbl_ops = {
42799+static const struct backlight_ops progearbl_ops = {
42800 .get_brightness = progearbl_get_intensity,
42801 .update_status = progearbl_set_intensity,
42802 };
42803diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
42804index 8871662..df9e0b3 100644
42805--- a/drivers/video/backlight/pwm_bl.c
42806+++ b/drivers/video/backlight/pwm_bl.c
42807@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(struct backlight_device *bl)
42808 return bl->props.brightness;
42809 }
42810
42811-static struct backlight_ops pwm_backlight_ops = {
42812+static const struct backlight_ops pwm_backlight_ops = {
42813 .update_status = pwm_backlight_update_status,
42814 .get_brightness = pwm_backlight_get_brightness,
42815 };
42816diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
42817index 43edbad..e14ce4d 100644
42818--- a/drivers/video/backlight/tosa_bl.c
42819+++ b/drivers/video/backlight/tosa_bl.c
42820@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct backlight_device *dev)
42821 return props->brightness;
42822 }
42823
42824-static struct backlight_ops bl_ops = {
42825+static const struct backlight_ops bl_ops = {
42826 .get_brightness = tosa_bl_get_brightness,
42827 .update_status = tosa_bl_update_status,
42828 };
42829diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
42830index 467bdb7..e32add3 100644
42831--- a/drivers/video/backlight/wm831x_bl.c
42832+++ b/drivers/video/backlight/wm831x_bl.c
42833@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightness(struct backlight_device *bl)
42834 return data->current_brightness;
42835 }
42836
42837-static struct backlight_ops wm831x_backlight_ops = {
42838+static const struct backlight_ops wm831x_backlight_ops = {
42839 .options = BL_CORE_SUSPENDRESUME,
42840 .update_status = wm831x_backlight_update_status,
42841 .get_brightness = wm831x_backlight_get_brightness,
42842diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
42843index e49ae5e..db4e6f7 100644
42844--- a/drivers/video/bf54x-lq043fb.c
42845+++ b/drivers/video/bf54x-lq043fb.c
42846@@ -463,7 +463,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42847 return 0;
42848 }
42849
42850-static struct backlight_ops bfin_lq043fb_bl_ops = {
42851+static const struct backlight_ops bfin_lq043fb_bl_ops = {
42852 .get_brightness = bl_get_brightness,
42853 };
42854
42855diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
42856index 2c72a7c..d523e52 100644
42857--- a/drivers/video/bfin-t350mcqb-fb.c
42858+++ b/drivers/video/bfin-t350mcqb-fb.c
42859@@ -381,7 +381,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42860 return 0;
42861 }
42862
42863-static struct backlight_ops bfin_lq043fb_bl_ops = {
42864+static const struct backlight_ops bfin_lq043fb_bl_ops = {
42865 .get_brightness = bl_get_brightness,
42866 };
42867
42868diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42869index f53b9f1..958bf4e 100644
42870--- a/drivers/video/fbcmap.c
42871+++ b/drivers/video/fbcmap.c
42872@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42873 rc = -ENODEV;
42874 goto out;
42875 }
42876- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42877- !info->fbops->fb_setcmap)) {
42878+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42879 rc = -EINVAL;
42880 goto out1;
42881 }
42882diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42883index 99bbd28..ad3829e 100644
42884--- a/drivers/video/fbmem.c
42885+++ b/drivers/video/fbmem.c
42886@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42887 image->dx += image->width + 8;
42888 }
42889 } else if (rotate == FB_ROTATE_UD) {
42890- for (x = 0; x < num && image->dx >= 0; x++) {
42891+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42892 info->fbops->fb_imageblit(info, image);
42893 image->dx -= image->width + 8;
42894 }
42895@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42896 image->dy += image->height + 8;
42897 }
42898 } else if (rotate == FB_ROTATE_CCW) {
42899- for (x = 0; x < num && image->dy >= 0; x++) {
42900+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42901 info->fbops->fb_imageblit(info, image);
42902 image->dy -= image->height + 8;
42903 }
42904@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
42905 int flags = info->flags;
42906 int ret = 0;
42907
42908+ pax_track_stack();
42909+
42910 if (var->activate & FB_ACTIVATE_INV_MODE) {
42911 struct fb_videomode mode1, mode2;
42912
42913@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42914 void __user *argp = (void __user *)arg;
42915 long ret = 0;
42916
42917+ pax_track_stack();
42918+
42919 switch (cmd) {
42920 case FBIOGET_VSCREENINFO:
42921 if (!lock_fb_info(info))
42922@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42923 return -EFAULT;
42924 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42925 return -EINVAL;
42926- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42927+ if (con2fb.framebuffer >= FB_MAX)
42928 return -EINVAL;
42929 if (!registered_fb[con2fb.framebuffer])
42930 request_module("fb%d", con2fb.framebuffer);
42931diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
42932index f20eff8..3e4f622 100644
42933--- a/drivers/video/geode/gx1fb_core.c
42934+++ b/drivers/video/geode/gx1fb_core.c
42935@@ -30,7 +30,7 @@ static int crt_option = 1;
42936 static char panel_option[32] = "";
42937
42938 /* Modes relevant to the GX1 (taken from modedb.c) */
42939-static const struct fb_videomode __initdata gx1_modedb[] = {
42940+static const struct fb_videomode __initconst gx1_modedb[] = {
42941 /* 640x480-60 VESA */
42942 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
42943 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
42944diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
42945index 896e53d..4d87d0b 100644
42946--- a/drivers/video/gxt4500.c
42947+++ b/drivers/video/gxt4500.c
42948@@ -156,7 +156,7 @@ struct gxt4500_par {
42949 static char *mode_option;
42950
42951 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
42952-static const struct fb_videomode defaultmode __devinitdata = {
42953+static const struct fb_videomode defaultmode __devinitconst = {
42954 .refresh = 60,
42955 .xres = 1280,
42956 .yres = 1024,
42957@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
42958 return 0;
42959 }
42960
42961-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
42962+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
42963 .id = "IBM GXT4500P",
42964 .type = FB_TYPE_PACKED_PIXELS,
42965 .visual = FB_VISUAL_PSEUDOCOLOR,
42966diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42967index f5bedee..28c6028 100644
42968--- a/drivers/video/i810/i810_accel.c
42969+++ b/drivers/video/i810/i810_accel.c
42970@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42971 }
42972 }
42973 printk("ringbuffer lockup!!!\n");
42974+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42975 i810_report_error(mmio);
42976 par->dev_flags |= LOCKUP;
42977 info->pixmap.scan_align = 1;
42978diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
42979index 5743ea2..457f82c 100644
42980--- a/drivers/video/i810/i810_main.c
42981+++ b/drivers/video/i810/i810_main.c
42982@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
42983 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
42984
42985 /* PCI */
42986-static const char *i810_pci_list[] __devinitdata = {
42987+static const char *i810_pci_list[] __devinitconst = {
42988 "Intel(R) 810 Framebuffer Device" ,
42989 "Intel(R) 810-DC100 Framebuffer Device" ,
42990 "Intel(R) 810E Framebuffer Device" ,
42991diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42992index 3c14e43..eafa544 100644
42993--- a/drivers/video/logo/logo_linux_clut224.ppm
42994+++ b/drivers/video/logo/logo_linux_clut224.ppm
42995@@ -1,1604 +1,1123 @@
42996 P3
42997-# Standard 224-color Linux logo
42998 80 80
42999 255
43000- 0 0 0 0 0 0 0 0 0 0 0 0
43001- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 6 6 6 10 10 10 10 10 10
43010- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
43020- 0 0 0 0 0 0 0 0 0 0 0 0
43021- 0 0 0 0 0 0 0 0 0 0 0 0
43022- 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
43029- 22 22 22 26 26 26 30 30 30 34 34 34
43030- 30 30 30 30 30 30 26 26 26 18 18 18
43031- 14 14 14 10 10 10 6 6 6 0 0 0
43032- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
43040- 0 0 0 0 0 0 0 0 0 0 0 0
43041- 0 0 0 0 0 1 0 0 1 0 0 0
43042- 0 0 0 0 0 0 0 0 0 0 0 0
43043- 0 0 0 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- 6 6 6 14 14 14 26 26 26 42 42 42
43049- 54 54 54 66 66 66 78 78 78 78 78 78
43050- 78 78 78 74 74 74 66 66 66 54 54 54
43051- 42 42 42 26 26 26 18 18 18 10 10 10
43052- 6 6 6 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 0 0 0
43059- 0 0 0 0 0 0 0 0 0 0 0 0
43060- 0 0 0 0 0 0 0 0 0 0 0 0
43061- 0 0 1 0 0 0 0 0 0 0 0 0
43062- 0 0 0 0 0 0 0 0 0 0 0 0
43063- 0 0 0 0 0 0 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 10 10 10
43068- 22 22 22 42 42 42 66 66 66 86 86 86
43069- 66 66 66 38 38 38 38 38 38 22 22 22
43070- 26 26 26 34 34 34 54 54 54 66 66 66
43071- 86 86 86 70 70 70 46 46 46 26 26 26
43072- 14 14 14 6 6 6 0 0 0 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 0 0 0 0 0 0
43079- 0 0 0 0 0 0 0 0 0 0 0 0
43080- 0 0 0 0 0 0 0 0 0 0 0 0
43081- 0 0 1 0 0 1 0 0 1 0 0 0
43082- 0 0 0 0 0 0 0 0 0 0 0 0
43083- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
43088- 50 50 50 82 82 82 58 58 58 6 6 6
43089- 2 2 6 2 2 6 2 2 6 2 2 6
43090- 2 2 6 2 2 6 2 2 6 2 2 6
43091- 6 6 6 54 54 54 86 86 86 66 66 66
43092- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
43099- 0 0 0 0 0 0 0 0 0 0 0 0
43100- 0 0 0 0 0 0 0 0 0 0 0 0
43101- 0 0 0 0 0 0 0 0 0 0 0 0
43102- 0 0 0 0 0 0 0 0 0 0 0 0
43103- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
43108- 78 78 78 34 34 34 2 2 6 2 2 6
43109- 2 2 6 2 2 6 2 2 6 2 2 6
43110- 2 2 6 2 2 6 2 2 6 2 2 6
43111- 2 2 6 2 2 6 6 6 6 70 70 70
43112- 78 78 78 46 46 46 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
43119- 0 0 0 0 0 0 0 0 0 0 0 0
43120- 0 0 0 0 0 0 0 0 0 0 0 0
43121- 0 0 1 0 0 1 0 0 1 0 0 0
43122- 0 0 0 0 0 0 0 0 0 0 0 0
43123- 0 0 0 0 0 0 0 0 0 0 0 0
43124- 0 0 0 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- 6 6 6 18 18 18 42 42 42 82 82 82
43128- 26 26 26 2 2 6 2 2 6 2 2 6
43129- 2 2 6 2 2 6 2 2 6 2 2 6
43130- 2 2 6 2 2 6 2 2 6 14 14 14
43131- 46 46 46 34 34 34 6 6 6 2 2 6
43132- 42 42 42 78 78 78 42 42 42 18 18 18
43133- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
43139- 0 0 0 0 0 0 0 0 0 0 0 0
43140- 0 0 0 0 0 0 0 0 0 0 0 0
43141- 0 0 1 0 0 0 0 0 1 0 0 0
43142- 0 0 0 0 0 0 0 0 0 0 0 0
43143- 0 0 0 0 0 0 0 0 0 0 0 0
43144- 0 0 0 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- 10 10 10 30 30 30 66 66 66 58 58 58
43148- 2 2 6 2 2 6 2 2 6 2 2 6
43149- 2 2 6 2 2 6 2 2 6 2 2 6
43150- 2 2 6 2 2 6 2 2 6 26 26 26
43151- 86 86 86 101 101 101 46 46 46 10 10 10
43152- 2 2 6 58 58 58 70 70 70 34 34 34
43153- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
43159- 0 0 0 0 0 0 0 0 0 0 0 0
43160- 0 0 0 0 0 0 0 0 0 0 0 0
43161- 0 0 1 0 0 1 0 0 1 0 0 0
43162- 0 0 0 0 0 0 0 0 0 0 0 0
43163- 0 0 0 0 0 0 0 0 0 0 0 0
43164- 0 0 0 0 0 0 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- 14 14 14 42 42 42 86 86 86 10 10 10
43168- 2 2 6 2 2 6 2 2 6 2 2 6
43169- 2 2 6 2 2 6 2 2 6 2 2 6
43170- 2 2 6 2 2 6 2 2 6 30 30 30
43171- 94 94 94 94 94 94 58 58 58 26 26 26
43172- 2 2 6 6 6 6 78 78 78 54 54 54
43173- 22 22 22 6 6 6 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 0 0 0
43178- 0 0 0 0 0 0 0 0 0 0 0 0
43179- 0 0 0 0 0 0 0 0 0 0 0 0
43180- 0 0 0 0 0 0 0 0 0 0 0 0
43181- 0 0 0 0 0 0 0 0 0 0 0 0
43182- 0 0 0 0 0 0 0 0 0 0 0 0
43183- 0 0 0 0 0 0 0 0 0 0 0 0
43184- 0 0 0 0 0 0 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 6 6 6
43187- 22 22 22 62 62 62 62 62 62 2 2 6
43188- 2 2 6 2 2 6 2 2 6 2 2 6
43189- 2 2 6 2 2 6 2 2 6 2 2 6
43190- 2 2 6 2 2 6 2 2 6 26 26 26
43191- 54 54 54 38 38 38 18 18 18 10 10 10
43192- 2 2 6 2 2 6 34 34 34 82 82 82
43193- 38 38 38 14 14 14 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 0 0 0
43198- 0 0 0 0 0 0 0 0 0 0 0 0
43199- 0 0 0 0 0 0 0 0 0 0 0 0
43200- 0 0 0 0 0 0 0 0 0 0 0 0
43201- 0 0 0 0 0 1 0 0 1 0 0 0
43202- 0 0 0 0 0 0 0 0 0 0 0 0
43203- 0 0 0 0 0 0 0 0 0 0 0 0
43204- 0 0 0 0 0 0 0 0 0 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 6 6 6
43207- 30 30 30 78 78 78 30 30 30 2 2 6
43208- 2 2 6 2 2 6 2 2 6 2 2 6
43209- 2 2 6 2 2 6 2 2 6 2 2 6
43210- 2 2 6 2 2 6 2 2 6 10 10 10
43211- 10 10 10 2 2 6 2 2 6 2 2 6
43212- 2 2 6 2 2 6 2 2 6 78 78 78
43213- 50 50 50 18 18 18 6 6 6 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 0 0 0
43218- 0 0 0 0 0 0 0 0 0 0 0 0
43219- 0 0 0 0 0 0 0 0 0 0 0 0
43220- 0 0 0 0 0 0 0 0 0 0 0 0
43221- 0 0 1 0 0 0 0 0 0 0 0 0
43222- 0 0 0 0 0 0 0 0 0 0 0 0
43223- 0 0 0 0 0 0 0 0 0 0 0 0
43224- 0 0 0 0 0 0 0 0 0 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 10 10 10
43227- 38 38 38 86 86 86 14 14 14 2 2 6
43228- 2 2 6 2 2 6 2 2 6 2 2 6
43229- 2 2 6 2 2 6 2 2 6 2 2 6
43230- 2 2 6 2 2 6 2 2 6 2 2 6
43231- 2 2 6 2 2 6 2 2 6 2 2 6
43232- 2 2 6 2 2 6 2 2 6 54 54 54
43233- 66 66 66 26 26 26 6 6 6 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 0 0 0
43238- 0 0 0 0 0 0 0 0 0 0 0 0
43239- 0 0 0 0 0 0 0 0 0 0 0 0
43240- 0 0 0 0 0 0 0 0 0 0 0 0
43241- 0 0 0 0 0 1 0 0 1 0 0 0
43242- 0 0 0 0 0 0 0 0 0 0 0 0
43243- 0 0 0 0 0 0 0 0 0 0 0 0
43244- 0 0 0 0 0 0 0 0 0 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 14 14 14
43247- 42 42 42 82 82 82 2 2 6 2 2 6
43248- 2 2 6 6 6 6 10 10 10 2 2 6
43249- 2 2 6 2 2 6 2 2 6 2 2 6
43250- 2 2 6 2 2 6 2 2 6 6 6 6
43251- 14 14 14 10 10 10 2 2 6 2 2 6
43252- 2 2 6 2 2 6 2 2 6 18 18 18
43253- 82 82 82 34 34 34 10 10 10 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 0 0 0
43258- 0 0 0 0 0 0 0 0 0 0 0 0
43259- 0 0 0 0 0 0 0 0 0 0 0 0
43260- 0 0 0 0 0 0 0 0 0 0 0 0
43261- 0 0 1 0 0 0 0 0 0 0 0 0
43262- 0 0 0 0 0 0 0 0 0 0 0 0
43263- 0 0 0 0 0 0 0 0 0 0 0 0
43264- 0 0 0 0 0 0 0 0 0 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 14 14 14
43267- 46 46 46 86 86 86 2 2 6 2 2 6
43268- 6 6 6 6 6 6 22 22 22 34 34 34
43269- 6 6 6 2 2 6 2 2 6 2 2 6
43270- 2 2 6 2 2 6 18 18 18 34 34 34
43271- 10 10 10 50 50 50 22 22 22 2 2 6
43272- 2 2 6 2 2 6 2 2 6 10 10 10
43273- 86 86 86 42 42 42 14 14 14 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 0 0 0
43278- 0 0 0 0 0 0 0 0 0 0 0 0
43279- 0 0 0 0 0 0 0 0 0 0 0 0
43280- 0 0 0 0 0 0 0 0 0 0 0 0
43281- 0 0 1 0 0 1 0 0 1 0 0 0
43282- 0 0 0 0 0 0 0 0 0 0 0 0
43283- 0 0 0 0 0 0 0 0 0 0 0 0
43284- 0 0 0 0 0 0 0 0 0 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 14 14 14
43287- 46 46 46 86 86 86 2 2 6 2 2 6
43288- 38 38 38 116 116 116 94 94 94 22 22 22
43289- 22 22 22 2 2 6 2 2 6 2 2 6
43290- 14 14 14 86 86 86 138 138 138 162 162 162
43291-154 154 154 38 38 38 26 26 26 6 6 6
43292- 2 2 6 2 2 6 2 2 6 2 2 6
43293- 86 86 86 46 46 46 14 14 14 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 0 0 0
43298- 0 0 0 0 0 0 0 0 0 0 0 0
43299- 0 0 0 0 0 0 0 0 0 0 0 0
43300- 0 0 0 0 0 0 0 0 0 0 0 0
43301- 0 0 0 0 0 0 0 0 0 0 0 0
43302- 0 0 0 0 0 0 0 0 0 0 0 0
43303- 0 0 0 0 0 0 0 0 0 0 0 0
43304- 0 0 0 0 0 0 0 0 0 0 0 0
43305- 0 0 0 0 0 0 0 0 0 0 0 0
43306- 0 0 0 0 0 0 0 0 0 14 14 14
43307- 46 46 46 86 86 86 2 2 6 14 14 14
43308-134 134 134 198 198 198 195 195 195 116 116 116
43309- 10 10 10 2 2 6 2 2 6 6 6 6
43310-101 98 89 187 187 187 210 210 210 218 218 218
43311-214 214 214 134 134 134 14 14 14 6 6 6
43312- 2 2 6 2 2 6 2 2 6 2 2 6
43313- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
43318- 0 0 0 0 0 0 0 0 0 0 0 0
43319- 0 0 0 0 0 0 0 0 0 0 0 0
43320- 0 0 0 0 0 0 0 0 1 0 0 0
43321- 0 0 1 0 0 1 0 0 1 0 0 0
43322- 0 0 0 0 0 0 0 0 0 0 0 0
43323- 0 0 0 0 0 0 0 0 0 0 0 0
43324- 0 0 0 0 0 0 0 0 0 0 0 0
43325- 0 0 0 0 0 0 0 0 0 0 0 0
43326- 0 0 0 0 0 0 0 0 0 14 14 14
43327- 46 46 46 86 86 86 2 2 6 54 54 54
43328-218 218 218 195 195 195 226 226 226 246 246 246
43329- 58 58 58 2 2 6 2 2 6 30 30 30
43330-210 210 210 253 253 253 174 174 174 123 123 123
43331-221 221 221 234 234 234 74 74 74 2 2 6
43332- 2 2 6 2 2 6 2 2 6 2 2 6
43333- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
43338- 0 0 0 0 0 0 0 0 0 0 0 0
43339- 0 0 0 0 0 0 0 0 0 0 0 0
43340- 0 0 0 0 0 0 0 0 0 0 0 0
43341- 0 0 0 0 0 0 0 0 0 0 0 0
43342- 0 0 0 0 0 0 0 0 0 0 0 0
43343- 0 0 0 0 0 0 0 0 0 0 0 0
43344- 0 0 0 0 0 0 0 0 0 0 0 0
43345- 0 0 0 0 0 0 0 0 0 0 0 0
43346- 0 0 0 0 0 0 0 0 0 14 14 14
43347- 46 46 46 82 82 82 2 2 6 106 106 106
43348-170 170 170 26 26 26 86 86 86 226 226 226
43349-123 123 123 10 10 10 14 14 14 46 46 46
43350-231 231 231 190 190 190 6 6 6 70 70 70
43351- 90 90 90 238 238 238 158 158 158 2 2 6
43352- 2 2 6 2 2 6 2 2 6 2 2 6
43353- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
43358- 0 0 0 0 0 0 0 0 0 0 0 0
43359- 0 0 0 0 0 0 0 0 0 0 0 0
43360- 0 0 0 0 0 0 0 0 1 0 0 0
43361- 0 0 1 0 0 1 0 0 1 0 0 0
43362- 0 0 0 0 0 0 0 0 0 0 0 0
43363- 0 0 0 0 0 0 0 0 0 0 0 0
43364- 0 0 0 0 0 0 0 0 0 0 0 0
43365- 0 0 0 0 0 0 0 0 0 0 0 0
43366- 0 0 0 0 0 0 0 0 0 14 14 14
43367- 42 42 42 86 86 86 6 6 6 116 116 116
43368-106 106 106 6 6 6 70 70 70 149 149 149
43369-128 128 128 18 18 18 38 38 38 54 54 54
43370-221 221 221 106 106 106 2 2 6 14 14 14
43371- 46 46 46 190 190 190 198 198 198 2 2 6
43372- 2 2 6 2 2 6 2 2 6 2 2 6
43373- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
43378- 0 0 0 0 0 0 0 0 0 0 0 0
43379- 0 0 0 0 0 0 0 0 0 0 0 0
43380- 0 0 0 0 0 0 0 0 1 0 0 0
43381- 0 0 1 0 0 0 0 0 1 0 0 0
43382- 0 0 0 0 0 0 0 0 0 0 0 0
43383- 0 0 0 0 0 0 0 0 0 0 0 0
43384- 0 0 0 0 0 0 0 0 0 0 0 0
43385- 0 0 0 0 0 0 0 0 0 0 0 0
43386- 0 0 0 0 0 0 0 0 0 14 14 14
43387- 42 42 42 94 94 94 14 14 14 101 101 101
43388-128 128 128 2 2 6 18 18 18 116 116 116
43389-118 98 46 121 92 8 121 92 8 98 78 10
43390-162 162 162 106 106 106 2 2 6 2 2 6
43391- 2 2 6 195 195 195 195 195 195 6 6 6
43392- 2 2 6 2 2 6 2 2 6 2 2 6
43393- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
43398- 0 0 0 0 0 0 0 0 0 0 0 0
43399- 0 0 0 0 0 0 0 0 0 0 0 0
43400- 0 0 0 0 0 0 0 0 1 0 0 1
43401- 0 0 1 0 0 0 0 0 1 0 0 0
43402- 0 0 0 0 0 0 0 0 0 0 0 0
43403- 0 0 0 0 0 0 0 0 0 0 0 0
43404- 0 0 0 0 0 0 0 0 0 0 0 0
43405- 0 0 0 0 0 0 0 0 0 0 0 0
43406- 0 0 0 0 0 0 0 0 0 10 10 10
43407- 38 38 38 90 90 90 14 14 14 58 58 58
43408-210 210 210 26 26 26 54 38 6 154 114 10
43409-226 170 11 236 186 11 225 175 15 184 144 12
43410-215 174 15 175 146 61 37 26 9 2 2 6
43411- 70 70 70 246 246 246 138 138 138 2 2 6
43412- 2 2 6 2 2 6 2 2 6 2 2 6
43413- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
43418- 0 0 0 0 0 0 0 0 0 0 0 0
43419- 0 0 0 0 0 0 0 0 0 0 0 0
43420- 0 0 0 0 0 0 0 0 0 0 0 0
43421- 0 0 0 0 0 0 0 0 0 0 0 0
43422- 0 0 0 0 0 0 0 0 0 0 0 0
43423- 0 0 0 0 0 0 0 0 0 0 0 0
43424- 0 0 0 0 0 0 0 0 0 0 0 0
43425- 0 0 0 0 0 0 0 0 0 0 0 0
43426- 0 0 0 0 0 0 0 0 0 10 10 10
43427- 38 38 38 86 86 86 14 14 14 10 10 10
43428-195 195 195 188 164 115 192 133 9 225 175 15
43429-239 182 13 234 190 10 232 195 16 232 200 30
43430-245 207 45 241 208 19 232 195 16 184 144 12
43431-218 194 134 211 206 186 42 42 42 2 2 6
43432- 2 2 6 2 2 6 2 2 6 2 2 6
43433- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
43438- 0 0 0 0 0 0 0 0 0 0 0 0
43439- 0 0 0 0 0 0 0 0 0 0 0 0
43440- 0 0 0 0 0 0 0 0 0 0 0 0
43441- 0 0 0 0 0 0 0 0 0 0 0 0
43442- 0 0 0 0 0 0 0 0 0 0 0 0
43443- 0 0 0 0 0 0 0 0 0 0 0 0
43444- 0 0 0 0 0 0 0 0 0 0 0 0
43445- 0 0 0 0 0 0 0 0 0 0 0 0
43446- 0 0 0 0 0 0 0 0 0 10 10 10
43447- 34 34 34 86 86 86 14 14 14 2 2 6
43448-121 87 25 192 133 9 219 162 10 239 182 13
43449-236 186 11 232 195 16 241 208 19 244 214 54
43450-246 218 60 246 218 38 246 215 20 241 208 19
43451-241 208 19 226 184 13 121 87 25 2 2 6
43452- 2 2 6 2 2 6 2 2 6 2 2 6
43453- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
43458- 0 0 0 0 0 0 0 0 0 0 0 0
43459- 0 0 0 0 0 0 0 0 0 0 0 0
43460- 0 0 0 0 0 0 0 0 0 0 0 0
43461- 0 0 0 0 0 0 0 0 0 0 0 0
43462- 0 0 0 0 0 0 0 0 0 0 0 0
43463- 0 0 0 0 0 0 0 0 0 0 0 0
43464- 0 0 0 0 0 0 0 0 0 0 0 0
43465- 0 0 0 0 0 0 0 0 0 0 0 0
43466- 0 0 0 0 0 0 0 0 0 10 10 10
43467- 34 34 34 82 82 82 30 30 30 61 42 6
43468-180 123 7 206 145 10 230 174 11 239 182 13
43469-234 190 10 238 202 15 241 208 19 246 218 74
43470-246 218 38 246 215 20 246 215 20 246 215 20
43471-226 184 13 215 174 15 184 144 12 6 6 6
43472- 2 2 6 2 2 6 2 2 6 2 2 6
43473- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
43478- 0 0 0 0 0 0 0 0 0 0 0 0
43479- 0 0 0 0 0 0 0 0 0 0 0 0
43480- 0 0 0 0 0 0 0 0 0 0 0 0
43481- 0 0 0 0 0 0 0 0 0 0 0 0
43482- 0 0 0 0 0 0 0 0 0 0 0 0
43483- 0 0 0 0 0 0 0 0 0 0 0 0
43484- 0 0 0 0 0 0 0 0 0 0 0 0
43485- 0 0 0 0 0 0 0 0 0 0 0 0
43486- 0 0 0 0 0 0 0 0 0 10 10 10
43487- 30 30 30 78 78 78 50 50 50 104 69 6
43488-192 133 9 216 158 10 236 178 12 236 186 11
43489-232 195 16 241 208 19 244 214 54 245 215 43
43490-246 215 20 246 215 20 241 208 19 198 155 10
43491-200 144 11 216 158 10 156 118 10 2 2 6
43492- 2 2 6 2 2 6 2 2 6 2 2 6
43493- 6 6 6 90 90 90 54 54 54 18 18 18
43494- 6 6 6 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 0 0 0
43498- 0 0 0 0 0 0 0 0 0 0 0 0
43499- 0 0 0 0 0 0 0 0 0 0 0 0
43500- 0 0 0 0 0 0 0 0 0 0 0 0
43501- 0 0 0 0 0 0 0 0 0 0 0 0
43502- 0 0 0 0 0 0 0 0 0 0 0 0
43503- 0 0 0 0 0 0 0 0 0 0 0 0
43504- 0 0 0 0 0 0 0 0 0 0 0 0
43505- 0 0 0 0 0 0 0 0 0 0 0 0
43506- 0 0 0 0 0 0 0 0 0 10 10 10
43507- 30 30 30 78 78 78 46 46 46 22 22 22
43508-137 92 6 210 162 10 239 182 13 238 190 10
43509-238 202 15 241 208 19 246 215 20 246 215 20
43510-241 208 19 203 166 17 185 133 11 210 150 10
43511-216 158 10 210 150 10 102 78 10 2 2 6
43512- 6 6 6 54 54 54 14 14 14 2 2 6
43513- 2 2 6 62 62 62 74 74 74 30 30 30
43514- 10 10 10 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 0 0 0
43518- 0 0 0 0 0 0 0 0 0 0 0 0
43519- 0 0 0 0 0 0 0 0 0 0 0 0
43520- 0 0 0 0 0 0 0 0 0 0 0 0
43521- 0 0 0 0 0 0 0 0 0 0 0 0
43522- 0 0 0 0 0 0 0 0 0 0 0 0
43523- 0 0 0 0 0 0 0 0 0 0 0 0
43524- 0 0 0 0 0 0 0 0 0 0 0 0
43525- 0 0 0 0 0 0 0 0 0 0 0 0
43526- 0 0 0 0 0 0 0 0 0 10 10 10
43527- 34 34 34 78 78 78 50 50 50 6 6 6
43528- 94 70 30 139 102 15 190 146 13 226 184 13
43529-232 200 30 232 195 16 215 174 15 190 146 13
43530-168 122 10 192 133 9 210 150 10 213 154 11
43531-202 150 34 182 157 106 101 98 89 2 2 6
43532- 2 2 6 78 78 78 116 116 116 58 58 58
43533- 2 2 6 22 22 22 90 90 90 46 46 46
43534- 18 18 18 6 6 6 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 0 0 0
43538- 0 0 0 0 0 0 0 0 0 0 0 0
43539- 0 0 0 0 0 0 0 0 0 0 0 0
43540- 0 0 0 0 0 0 0 0 0 0 0 0
43541- 0 0 0 0 0 0 0 0 0 0 0 0
43542- 0 0 0 0 0 0 0 0 0 0 0 0
43543- 0 0 0 0 0 0 0 0 0 0 0 0
43544- 0 0 0 0 0 0 0 0 0 0 0 0
43545- 0 0 0 0 0 0 0 0 0 0 0 0
43546- 0 0 0 0 0 0 0 0 0 10 10 10
43547- 38 38 38 86 86 86 50 50 50 6 6 6
43548-128 128 128 174 154 114 156 107 11 168 122 10
43549-198 155 10 184 144 12 197 138 11 200 144 11
43550-206 145 10 206 145 10 197 138 11 188 164 115
43551-195 195 195 198 198 198 174 174 174 14 14 14
43552- 2 2 6 22 22 22 116 116 116 116 116 116
43553- 22 22 22 2 2 6 74 74 74 70 70 70
43554- 30 30 30 10 10 10 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 0 0 0 0 0 0
43558- 0 0 0 0 0 0 0 0 0 0 0 0
43559- 0 0 0 0 0 0 0 0 0 0 0 0
43560- 0 0 0 0 0 0 0 0 0 0 0 0
43561- 0 0 0 0 0 0 0 0 0 0 0 0
43562- 0 0 0 0 0 0 0 0 0 0 0 0
43563- 0 0 0 0 0 0 0 0 0 0 0 0
43564- 0 0 0 0 0 0 0 0 0 0 0 0
43565- 0 0 0 0 0 0 0 0 0 0 0 0
43566- 0 0 0 0 0 0 6 6 6 18 18 18
43567- 50 50 50 101 101 101 26 26 26 10 10 10
43568-138 138 138 190 190 190 174 154 114 156 107 11
43569-197 138 11 200 144 11 197 138 11 192 133 9
43570-180 123 7 190 142 34 190 178 144 187 187 187
43571-202 202 202 221 221 221 214 214 214 66 66 66
43572- 2 2 6 2 2 6 50 50 50 62 62 62
43573- 6 6 6 2 2 6 10 10 10 90 90 90
43574- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
43578- 0 0 0 0 0 0 0 0 0 0 0 0
43579- 0 0 0 0 0 0 0 0 0 0 0 0
43580- 0 0 0 0 0 0 0 0 0 0 0 0
43581- 0 0 0 0 0 0 0 0 0 0 0 0
43582- 0 0 0 0 0 0 0 0 0 0 0 0
43583- 0 0 0 0 0 0 0 0 0 0 0 0
43584- 0 0 0 0 0 0 0 0 0 0 0 0
43585- 0 0 0 0 0 0 0 0 0 0 0 0
43586- 0 0 0 0 0 0 10 10 10 34 34 34
43587- 74 74 74 74 74 74 2 2 6 6 6 6
43588-144 144 144 198 198 198 190 190 190 178 166 146
43589-154 121 60 156 107 11 156 107 11 168 124 44
43590-174 154 114 187 187 187 190 190 190 210 210 210
43591-246 246 246 253 253 253 253 253 253 182 182 182
43592- 6 6 6 2 2 6 2 2 6 2 2 6
43593- 2 2 6 2 2 6 2 2 6 62 62 62
43594- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0
43598- 0 0 0 0 0 0 0 0 0 0 0 0
43599- 0 0 0 0 0 0 0 0 0 0 0 0
43600- 0 0 0 0 0 0 0 0 0 0 0 0
43601- 0 0 0 0 0 0 0 0 0 0 0 0
43602- 0 0 0 0 0 0 0 0 0 0 0 0
43603- 0 0 0 0 0 0 0 0 0 0 0 0
43604- 0 0 0 0 0 0 0 0 0 0 0 0
43605- 0 0 0 0 0 0 0 0 0 0 0 0
43606- 0 0 0 10 10 10 22 22 22 54 54 54
43607- 94 94 94 18 18 18 2 2 6 46 46 46
43608-234 234 234 221 221 221 190 190 190 190 190 190
43609-190 190 190 187 187 187 187 187 187 190 190 190
43610-190 190 190 195 195 195 214 214 214 242 242 242
43611-253 253 253 253 253 253 253 253 253 253 253 253
43612- 82 82 82 2 2 6 2 2 6 2 2 6
43613- 2 2 6 2 2 6 2 2 6 14 14 14
43614- 86 86 86 54 54 54 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
43618- 0 0 0 0 0 0 0 0 0 0 0 0
43619- 0 0 0 0 0 0 0 0 0 0 0 0
43620- 0 0 0 0 0 0 0 0 0 0 0 0
43621- 0 0 0 0 0 0 0 0 0 0 0 0
43622- 0 0 0 0 0 0 0 0 0 0 0 0
43623- 0 0 0 0 0 0 0 0 0 0 0 0
43624- 0 0 0 0 0 0 0 0 0 0 0 0
43625- 0 0 0 0 0 0 0 0 0 0 0 0
43626- 6 6 6 18 18 18 46 46 46 90 90 90
43627- 46 46 46 18 18 18 6 6 6 182 182 182
43628-253 253 253 246 246 246 206 206 206 190 190 190
43629-190 190 190 190 190 190 190 190 190 190 190 190
43630-206 206 206 231 231 231 250 250 250 253 253 253
43631-253 253 253 253 253 253 253 253 253 253 253 253
43632-202 202 202 14 14 14 2 2 6 2 2 6
43633- 2 2 6 2 2 6 2 2 6 2 2 6
43634- 42 42 42 86 86 86 42 42 42 18 18 18
43635- 6 6 6 0 0 0 0 0 0 0 0 0
43636- 0 0 0 0 0 0 0 0 0 0 0 0
43637- 0 0 0 0 0 0 0 0 0 0 0 0
43638- 0 0 0 0 0 0 0 0 0 0 0 0
43639- 0 0 0 0 0 0 0 0 0 0 0 0
43640- 0 0 0 0 0 0 0 0 0 0 0 0
43641- 0 0 0 0 0 0 0 0 0 0 0 0
43642- 0 0 0 0 0 0 0 0 0 0 0 0
43643- 0 0 0 0 0 0 0 0 0 0 0 0
43644- 0 0 0 0 0 0 0 0 0 0 0 0
43645- 0 0 0 0 0 0 0 0 0 6 6 6
43646- 14 14 14 38 38 38 74 74 74 66 66 66
43647- 2 2 6 6 6 6 90 90 90 250 250 250
43648-253 253 253 253 253 253 238 238 238 198 198 198
43649-190 190 190 190 190 190 195 195 195 221 221 221
43650-246 246 246 253 253 253 253 253 253 253 253 253
43651-253 253 253 253 253 253 253 253 253 253 253 253
43652-253 253 253 82 82 82 2 2 6 2 2 6
43653- 2 2 6 2 2 6 2 2 6 2 2 6
43654- 2 2 6 78 78 78 70 70 70 34 34 34
43655- 14 14 14 6 6 6 0 0 0 0 0 0
43656- 0 0 0 0 0 0 0 0 0 0 0 0
43657- 0 0 0 0 0 0 0 0 0 0 0 0
43658- 0 0 0 0 0 0 0 0 0 0 0 0
43659- 0 0 0 0 0 0 0 0 0 0 0 0
43660- 0 0 0 0 0 0 0 0 0 0 0 0
43661- 0 0 0 0 0 0 0 0 0 0 0 0
43662- 0 0 0 0 0 0 0 0 0 0 0 0
43663- 0 0 0 0 0 0 0 0 0 0 0 0
43664- 0 0 0 0 0 0 0 0 0 0 0 0
43665- 0 0 0 0 0 0 0 0 0 14 14 14
43666- 34 34 34 66 66 66 78 78 78 6 6 6
43667- 2 2 6 18 18 18 218 218 218 253 253 253
43668-253 253 253 253 253 253 253 253 253 246 246 246
43669-226 226 226 231 231 231 246 246 246 253 253 253
43670-253 253 253 253 253 253 253 253 253 253 253 253
43671-253 253 253 253 253 253 253 253 253 253 253 253
43672-253 253 253 178 178 178 2 2 6 2 2 6
43673- 2 2 6 2 2 6 2 2 6 2 2 6
43674- 2 2 6 18 18 18 90 90 90 62 62 62
43675- 30 30 30 10 10 10 0 0 0 0 0 0
43676- 0 0 0 0 0 0 0 0 0 0 0 0
43677- 0 0 0 0 0 0 0 0 0 0 0 0
43678- 0 0 0 0 0 0 0 0 0 0 0 0
43679- 0 0 0 0 0 0 0 0 0 0 0 0
43680- 0 0 0 0 0 0 0 0 0 0 0 0
43681- 0 0 0 0 0 0 0 0 0 0 0 0
43682- 0 0 0 0 0 0 0 0 0 0 0 0
43683- 0 0 0 0 0 0 0 0 0 0 0 0
43684- 0 0 0 0 0 0 0 0 0 0 0 0
43685- 0 0 0 0 0 0 10 10 10 26 26 26
43686- 58 58 58 90 90 90 18 18 18 2 2 6
43687- 2 2 6 110 110 110 253 253 253 253 253 253
43688-253 253 253 253 253 253 253 253 253 253 253 253
43689-250 250 250 253 253 253 253 253 253 253 253 253
43690-253 253 253 253 253 253 253 253 253 253 253 253
43691-253 253 253 253 253 253 253 253 253 253 253 253
43692-253 253 253 231 231 231 18 18 18 2 2 6
43693- 2 2 6 2 2 6 2 2 6 2 2 6
43694- 2 2 6 2 2 6 18 18 18 94 94 94
43695- 54 54 54 26 26 26 10 10 10 0 0 0
43696- 0 0 0 0 0 0 0 0 0 0 0 0
43697- 0 0 0 0 0 0 0 0 0 0 0 0
43698- 0 0 0 0 0 0 0 0 0 0 0 0
43699- 0 0 0 0 0 0 0 0 0 0 0 0
43700- 0 0 0 0 0 0 0 0 0 0 0 0
43701- 0 0 0 0 0 0 0 0 0 0 0 0
43702- 0 0 0 0 0 0 0 0 0 0 0 0
43703- 0 0 0 0 0 0 0 0 0 0 0 0
43704- 0 0 0 0 0 0 0 0 0 0 0 0
43705- 0 0 0 6 6 6 22 22 22 50 50 50
43706- 90 90 90 26 26 26 2 2 6 2 2 6
43707- 14 14 14 195 195 195 250 250 250 253 253 253
43708-253 253 253 253 253 253 253 253 253 253 253 253
43709-253 253 253 253 253 253 253 253 253 253 253 253
43710-253 253 253 253 253 253 253 253 253 253 253 253
43711-253 253 253 253 253 253 253 253 253 253 253 253
43712-250 250 250 242 242 242 54 54 54 2 2 6
43713- 2 2 6 2 2 6 2 2 6 2 2 6
43714- 2 2 6 2 2 6 2 2 6 38 38 38
43715- 86 86 86 50 50 50 22 22 22 6 6 6
43716- 0 0 0 0 0 0 0 0 0 0 0 0
43717- 0 0 0 0 0 0 0 0 0 0 0 0
43718- 0 0 0 0 0 0 0 0 0 0 0 0
43719- 0 0 0 0 0 0 0 0 0 0 0 0
43720- 0 0 0 0 0 0 0 0 0 0 0 0
43721- 0 0 0 0 0 0 0 0 0 0 0 0
43722- 0 0 0 0 0 0 0 0 0 0 0 0
43723- 0 0 0 0 0 0 0 0 0 0 0 0
43724- 0 0 0 0 0 0 0 0 0 0 0 0
43725- 6 6 6 14 14 14 38 38 38 82 82 82
43726- 34 34 34 2 2 6 2 2 6 2 2 6
43727- 42 42 42 195 195 195 246 246 246 253 253 253
43728-253 253 253 253 253 253 253 253 253 250 250 250
43729-242 242 242 242 242 242 250 250 250 253 253 253
43730-253 253 253 253 253 253 253 253 253 253 253 253
43731-253 253 253 250 250 250 246 246 246 238 238 238
43732-226 226 226 231 231 231 101 101 101 6 6 6
43733- 2 2 6 2 2 6 2 2 6 2 2 6
43734- 2 2 6 2 2 6 2 2 6 2 2 6
43735- 38 38 38 82 82 82 42 42 42 14 14 14
43736- 6 6 6 0 0 0 0 0 0 0 0 0
43737- 0 0 0 0 0 0 0 0 0 0 0 0
43738- 0 0 0 0 0 0 0 0 0 0 0 0
43739- 0 0 0 0 0 0 0 0 0 0 0 0
43740- 0 0 0 0 0 0 0 0 0 0 0 0
43741- 0 0 0 0 0 0 0 0 0 0 0 0
43742- 0 0 0 0 0 0 0 0 0 0 0 0
43743- 0 0 0 0 0 0 0 0 0 0 0 0
43744- 0 0 0 0 0 0 0 0 0 0 0 0
43745- 10 10 10 26 26 26 62 62 62 66 66 66
43746- 2 2 6 2 2 6 2 2 6 6 6 6
43747- 70 70 70 170 170 170 206 206 206 234 234 234
43748-246 246 246 250 250 250 250 250 250 238 238 238
43749-226 226 226 231 231 231 238 238 238 250 250 250
43750-250 250 250 250 250 250 246 246 246 231 231 231
43751-214 214 214 206 206 206 202 202 202 202 202 202
43752-198 198 198 202 202 202 182 182 182 18 18 18
43753- 2 2 6 2 2 6 2 2 6 2 2 6
43754- 2 2 6 2 2 6 2 2 6 2 2 6
43755- 2 2 6 62 62 62 66 66 66 30 30 30
43756- 10 10 10 0 0 0 0 0 0 0 0 0
43757- 0 0 0 0 0 0 0 0 0 0 0 0
43758- 0 0 0 0 0 0 0 0 0 0 0 0
43759- 0 0 0 0 0 0 0 0 0 0 0 0
43760- 0 0 0 0 0 0 0 0 0 0 0 0
43761- 0 0 0 0 0 0 0 0 0 0 0 0
43762- 0 0 0 0 0 0 0 0 0 0 0 0
43763- 0 0 0 0 0 0 0 0 0 0 0 0
43764- 0 0 0 0 0 0 0 0 0 0 0 0
43765- 14 14 14 42 42 42 82 82 82 18 18 18
43766- 2 2 6 2 2 6 2 2 6 10 10 10
43767- 94 94 94 182 182 182 218 218 218 242 242 242
43768-250 250 250 253 253 253 253 253 253 250 250 250
43769-234 234 234 253 253 253 253 253 253 253 253 253
43770-253 253 253 253 253 253 253 253 253 246 246 246
43771-238 238 238 226 226 226 210 210 210 202 202 202
43772-195 195 195 195 195 195 210 210 210 158 158 158
43773- 6 6 6 14 14 14 50 50 50 14 14 14
43774- 2 2 6 2 2 6 2 2 6 2 2 6
43775- 2 2 6 6 6 6 86 86 86 46 46 46
43776- 18 18 18 6 6 6 0 0 0 0 0 0
43777- 0 0 0 0 0 0 0 0 0 0 0 0
43778- 0 0 0 0 0 0 0 0 0 0 0 0
43779- 0 0 0 0 0 0 0 0 0 0 0 0
43780- 0 0 0 0 0 0 0 0 0 0 0 0
43781- 0 0 0 0 0 0 0 0 0 0 0 0
43782- 0 0 0 0 0 0 0 0 0 0 0 0
43783- 0 0 0 0 0 0 0 0 0 0 0 0
43784- 0 0 0 0 0 0 0 0 0 6 6 6
43785- 22 22 22 54 54 54 70 70 70 2 2 6
43786- 2 2 6 10 10 10 2 2 6 22 22 22
43787-166 166 166 231 231 231 250 250 250 253 253 253
43788-253 253 253 253 253 253 253 253 253 250 250 250
43789-242 242 242 253 253 253 253 253 253 253 253 253
43790-253 253 253 253 253 253 253 253 253 253 253 253
43791-253 253 253 253 253 253 253 253 253 246 246 246
43792-231 231 231 206 206 206 198 198 198 226 226 226
43793- 94 94 94 2 2 6 6 6 6 38 38 38
43794- 30 30 30 2 2 6 2 2 6 2 2 6
43795- 2 2 6 2 2 6 62 62 62 66 66 66
43796- 26 26 26 10 10 10 0 0 0 0 0 0
43797- 0 0 0 0 0 0 0 0 0 0 0 0
43798- 0 0 0 0 0 0 0 0 0 0 0 0
43799- 0 0 0 0 0 0 0 0 0 0 0 0
43800- 0 0 0 0 0 0 0 0 0 0 0 0
43801- 0 0 0 0 0 0 0 0 0 0 0 0
43802- 0 0 0 0 0 0 0 0 0 0 0 0
43803- 0 0 0 0 0 0 0 0 0 0 0 0
43804- 0 0 0 0 0 0 0 0 0 10 10 10
43805- 30 30 30 74 74 74 50 50 50 2 2 6
43806- 26 26 26 26 26 26 2 2 6 106 106 106
43807-238 238 238 253 253 253 253 253 253 253 253 253
43808-253 253 253 253 253 253 253 253 253 253 253 253
43809-253 253 253 253 253 253 253 253 253 253 253 253
43810-253 253 253 253 253 253 253 253 253 253 253 253
43811-253 253 253 253 253 253 253 253 253 253 253 253
43812-253 253 253 246 246 246 218 218 218 202 202 202
43813-210 210 210 14 14 14 2 2 6 2 2 6
43814- 30 30 30 22 22 22 2 2 6 2 2 6
43815- 2 2 6 2 2 6 18 18 18 86 86 86
43816- 42 42 42 14 14 14 0 0 0 0 0 0
43817- 0 0 0 0 0 0 0 0 0 0 0 0
43818- 0 0 0 0 0 0 0 0 0 0 0 0
43819- 0 0 0 0 0 0 0 0 0 0 0 0
43820- 0 0 0 0 0 0 0 0 0 0 0 0
43821- 0 0 0 0 0 0 0 0 0 0 0 0
43822- 0 0 0 0 0 0 0 0 0 0 0 0
43823- 0 0 0 0 0 0 0 0 0 0 0 0
43824- 0 0 0 0 0 0 0 0 0 14 14 14
43825- 42 42 42 90 90 90 22 22 22 2 2 6
43826- 42 42 42 2 2 6 18 18 18 218 218 218
43827-253 253 253 253 253 253 253 253 253 253 253 253
43828-253 253 253 253 253 253 253 253 253 253 253 253
43829-253 253 253 253 253 253 253 253 253 253 253 253
43830-253 253 253 253 253 253 253 253 253 253 253 253
43831-253 253 253 253 253 253 253 253 253 253 253 253
43832-253 253 253 253 253 253 250 250 250 221 221 221
43833-218 218 218 101 101 101 2 2 6 14 14 14
43834- 18 18 18 38 38 38 10 10 10 2 2 6
43835- 2 2 6 2 2 6 2 2 6 78 78 78
43836- 58 58 58 22 22 22 6 6 6 0 0 0
43837- 0 0 0 0 0 0 0 0 0 0 0 0
43838- 0 0 0 0 0 0 0 0 0 0 0 0
43839- 0 0 0 0 0 0 0 0 0 0 0 0
43840- 0 0 0 0 0 0 0 0 0 0 0 0
43841- 0 0 0 0 0 0 0 0 0 0 0 0
43842- 0 0 0 0 0 0 0 0 0 0 0 0
43843- 0 0 0 0 0 0 0 0 0 0 0 0
43844- 0 0 0 0 0 0 6 6 6 18 18 18
43845- 54 54 54 82 82 82 2 2 6 26 26 26
43846- 22 22 22 2 2 6 123 123 123 253 253 253
43847-253 253 253 253 253 253 253 253 253 253 253 253
43848-253 253 253 253 253 253 253 253 253 253 253 253
43849-253 253 253 253 253 253 253 253 253 253 253 253
43850-253 253 253 253 253 253 253 253 253 253 253 253
43851-253 253 253 253 253 253 253 253 253 253 253 253
43852-253 253 253 253 253 253 253 253 253 250 250 250
43853-238 238 238 198 198 198 6 6 6 38 38 38
43854- 58 58 58 26 26 26 38 38 38 2 2 6
43855- 2 2 6 2 2 6 2 2 6 46 46 46
43856- 78 78 78 30 30 30 10 10 10 0 0 0
43857- 0 0 0 0 0 0 0 0 0 0 0 0
43858- 0 0 0 0 0 0 0 0 0 0 0 0
43859- 0 0 0 0 0 0 0 0 0 0 0 0
43860- 0 0 0 0 0 0 0 0 0 0 0 0
43861- 0 0 0 0 0 0 0 0 0 0 0 0
43862- 0 0 0 0 0 0 0 0 0 0 0 0
43863- 0 0 0 0 0 0 0 0 0 0 0 0
43864- 0 0 0 0 0 0 10 10 10 30 30 30
43865- 74 74 74 58 58 58 2 2 6 42 42 42
43866- 2 2 6 22 22 22 231 231 231 253 253 253
43867-253 253 253 253 253 253 253 253 253 253 253 253
43868-253 253 253 253 253 253 253 253 253 250 250 250
43869-253 253 253 253 253 253 253 253 253 253 253 253
43870-253 253 253 253 253 253 253 253 253 253 253 253
43871-253 253 253 253 253 253 253 253 253 253 253 253
43872-253 253 253 253 253 253 253 253 253 253 253 253
43873-253 253 253 246 246 246 46 46 46 38 38 38
43874- 42 42 42 14 14 14 38 38 38 14 14 14
43875- 2 2 6 2 2 6 2 2 6 6 6 6
43876- 86 86 86 46 46 46 14 14 14 0 0 0
43877- 0 0 0 0 0 0 0 0 0 0 0 0
43878- 0 0 0 0 0 0 0 0 0 0 0 0
43879- 0 0 0 0 0 0 0 0 0 0 0 0
43880- 0 0 0 0 0 0 0 0 0 0 0 0
43881- 0 0 0 0 0 0 0 0 0 0 0 0
43882- 0 0 0 0 0 0 0 0 0 0 0 0
43883- 0 0 0 0 0 0 0 0 0 0 0 0
43884- 0 0 0 6 6 6 14 14 14 42 42 42
43885- 90 90 90 18 18 18 18 18 18 26 26 26
43886- 2 2 6 116 116 116 253 253 253 253 253 253
43887-253 253 253 253 253 253 253 253 253 253 253 253
43888-253 253 253 253 253 253 250 250 250 238 238 238
43889-253 253 253 253 253 253 253 253 253 253 253 253
43890-253 253 253 253 253 253 253 253 253 253 253 253
43891-253 253 253 253 253 253 253 253 253 253 253 253
43892-253 253 253 253 253 253 253 253 253 253 253 253
43893-253 253 253 253 253 253 94 94 94 6 6 6
43894- 2 2 6 2 2 6 10 10 10 34 34 34
43895- 2 2 6 2 2 6 2 2 6 2 2 6
43896- 74 74 74 58 58 58 22 22 22 6 6 6
43897- 0 0 0 0 0 0 0 0 0 0 0 0
43898- 0 0 0 0 0 0 0 0 0 0 0 0
43899- 0 0 0 0 0 0 0 0 0 0 0 0
43900- 0 0 0 0 0 0 0 0 0 0 0 0
43901- 0 0 0 0 0 0 0 0 0 0 0 0
43902- 0 0 0 0 0 0 0 0 0 0 0 0
43903- 0 0 0 0 0 0 0 0 0 0 0 0
43904- 0 0 0 10 10 10 26 26 26 66 66 66
43905- 82 82 82 2 2 6 38 38 38 6 6 6
43906- 14 14 14 210 210 210 253 253 253 253 253 253
43907-253 253 253 253 253 253 253 253 253 253 253 253
43908-253 253 253 253 253 253 246 246 246 242 242 242
43909-253 253 253 253 253 253 253 253 253 253 253 253
43910-253 253 253 253 253 253 253 253 253 253 253 253
43911-253 253 253 253 253 253 253 253 253 253 253 253
43912-253 253 253 253 253 253 253 253 253 253 253 253
43913-253 253 253 253 253 253 144 144 144 2 2 6
43914- 2 2 6 2 2 6 2 2 6 46 46 46
43915- 2 2 6 2 2 6 2 2 6 2 2 6
43916- 42 42 42 74 74 74 30 30 30 10 10 10
43917- 0 0 0 0 0 0 0 0 0 0 0 0
43918- 0 0 0 0 0 0 0 0 0 0 0 0
43919- 0 0 0 0 0 0 0 0 0 0 0 0
43920- 0 0 0 0 0 0 0 0 0 0 0 0
43921- 0 0 0 0 0 0 0 0 0 0 0 0
43922- 0 0 0 0 0 0 0 0 0 0 0 0
43923- 0 0 0 0 0 0 0 0 0 0 0 0
43924- 6 6 6 14 14 14 42 42 42 90 90 90
43925- 26 26 26 6 6 6 42 42 42 2 2 6
43926- 74 74 74 250 250 250 253 253 253 253 253 253
43927-253 253 253 253 253 253 253 253 253 253 253 253
43928-253 253 253 253 253 253 242 242 242 242 242 242
43929-253 253 253 253 253 253 253 253 253 253 253 253
43930-253 253 253 253 253 253 253 253 253 253 253 253
43931-253 253 253 253 253 253 253 253 253 253 253 253
43932-253 253 253 253 253 253 253 253 253 253 253 253
43933-253 253 253 253 253 253 182 182 182 2 2 6
43934- 2 2 6 2 2 6 2 2 6 46 46 46
43935- 2 2 6 2 2 6 2 2 6 2 2 6
43936- 10 10 10 86 86 86 38 38 38 10 10 10
43937- 0 0 0 0 0 0 0 0 0 0 0 0
43938- 0 0 0 0 0 0 0 0 0 0 0 0
43939- 0 0 0 0 0 0 0 0 0 0 0 0
43940- 0 0 0 0 0 0 0 0 0 0 0 0
43941- 0 0 0 0 0 0 0 0 0 0 0 0
43942- 0 0 0 0 0 0 0 0 0 0 0 0
43943- 0 0 0 0 0 0 0 0 0 0 0 0
43944- 10 10 10 26 26 26 66 66 66 82 82 82
43945- 2 2 6 22 22 22 18 18 18 2 2 6
43946-149 149 149 253 253 253 253 253 253 253 253 253
43947-253 253 253 253 253 253 253 253 253 253 253 253
43948-253 253 253 253 253 253 234 234 234 242 242 242
43949-253 253 253 253 253 253 253 253 253 253 253 253
43950-253 253 253 253 253 253 253 253 253 253 253 253
43951-253 253 253 253 253 253 253 253 253 253 253 253
43952-253 253 253 253 253 253 253 253 253 253 253 253
43953-253 253 253 253 253 253 206 206 206 2 2 6
43954- 2 2 6 2 2 6 2 2 6 38 38 38
43955- 2 2 6 2 2 6 2 2 6 2 2 6
43956- 6 6 6 86 86 86 46 46 46 14 14 14
43957- 0 0 0 0 0 0 0 0 0 0 0 0
43958- 0 0 0 0 0 0 0 0 0 0 0 0
43959- 0 0 0 0 0 0 0 0 0 0 0 0
43960- 0 0 0 0 0 0 0 0 0 0 0 0
43961- 0 0 0 0 0 0 0 0 0 0 0 0
43962- 0 0 0 0 0 0 0 0 0 0 0 0
43963- 0 0 0 0 0 0 0 0 0 6 6 6
43964- 18 18 18 46 46 46 86 86 86 18 18 18
43965- 2 2 6 34 34 34 10 10 10 6 6 6
43966-210 210 210 253 253 253 253 253 253 253 253 253
43967-253 253 253 253 253 253 253 253 253 253 253 253
43968-253 253 253 253 253 253 234 234 234 242 242 242
43969-253 253 253 253 253 253 253 253 253 253 253 253
43970-253 253 253 253 253 253 253 253 253 253 253 253
43971-253 253 253 253 253 253 253 253 253 253 253 253
43972-253 253 253 253 253 253 253 253 253 253 253 253
43973-253 253 253 253 253 253 221 221 221 6 6 6
43974- 2 2 6 2 2 6 6 6 6 30 30 30
43975- 2 2 6 2 2 6 2 2 6 2 2 6
43976- 2 2 6 82 82 82 54 54 54 18 18 18
43977- 6 6 6 0 0 0 0 0 0 0 0 0
43978- 0 0 0 0 0 0 0 0 0 0 0 0
43979- 0 0 0 0 0 0 0 0 0 0 0 0
43980- 0 0 0 0 0 0 0 0 0 0 0 0
43981- 0 0 0 0 0 0 0 0 0 0 0 0
43982- 0 0 0 0 0 0 0 0 0 0 0 0
43983- 0 0 0 0 0 0 0 0 0 10 10 10
43984- 26 26 26 66 66 66 62 62 62 2 2 6
43985- 2 2 6 38 38 38 10 10 10 26 26 26
43986-238 238 238 253 253 253 253 253 253 253 253 253
43987-253 253 253 253 253 253 253 253 253 253 253 253
43988-253 253 253 253 253 253 231 231 231 238 238 238
43989-253 253 253 253 253 253 253 253 253 253 253 253
43990-253 253 253 253 253 253 253 253 253 253 253 253
43991-253 253 253 253 253 253 253 253 253 253 253 253
43992-253 253 253 253 253 253 253 253 253 253 253 253
43993-253 253 253 253 253 253 231 231 231 6 6 6
43994- 2 2 6 2 2 6 10 10 10 30 30 30
43995- 2 2 6 2 2 6 2 2 6 2 2 6
43996- 2 2 6 66 66 66 58 58 58 22 22 22
43997- 6 6 6 0 0 0 0 0 0 0 0 0
43998- 0 0 0 0 0 0 0 0 0 0 0 0
43999- 0 0 0 0 0 0 0 0 0 0 0 0
44000- 0 0 0 0 0 0 0 0 0 0 0 0
44001- 0 0 0 0 0 0 0 0 0 0 0 0
44002- 0 0 0 0 0 0 0 0 0 0 0 0
44003- 0 0 0 0 0 0 0 0 0 10 10 10
44004- 38 38 38 78 78 78 6 6 6 2 2 6
44005- 2 2 6 46 46 46 14 14 14 42 42 42
44006-246 246 246 253 253 253 253 253 253 253 253 253
44007-253 253 253 253 253 253 253 253 253 253 253 253
44008-253 253 253 253 253 253 231 231 231 242 242 242
44009-253 253 253 253 253 253 253 253 253 253 253 253
44010-253 253 253 253 253 253 253 253 253 253 253 253
44011-253 253 253 253 253 253 253 253 253 253 253 253
44012-253 253 253 253 253 253 253 253 253 253 253 253
44013-253 253 253 253 253 253 234 234 234 10 10 10
44014- 2 2 6 2 2 6 22 22 22 14 14 14
44015- 2 2 6 2 2 6 2 2 6 2 2 6
44016- 2 2 6 66 66 66 62 62 62 22 22 22
44017- 6 6 6 0 0 0 0 0 0 0 0 0
44018- 0 0 0 0 0 0 0 0 0 0 0 0
44019- 0 0 0 0 0 0 0 0 0 0 0 0
44020- 0 0 0 0 0 0 0 0 0 0 0 0
44021- 0 0 0 0 0 0 0 0 0 0 0 0
44022- 0 0 0 0 0 0 0 0 0 0 0 0
44023- 0 0 0 0 0 0 6 6 6 18 18 18
44024- 50 50 50 74 74 74 2 2 6 2 2 6
44025- 14 14 14 70 70 70 34 34 34 62 62 62
44026-250 250 250 253 253 253 253 253 253 253 253 253
44027-253 253 253 253 253 253 253 253 253 253 253 253
44028-253 253 253 253 253 253 231 231 231 246 246 246
44029-253 253 253 253 253 253 253 253 253 253 253 253
44030-253 253 253 253 253 253 253 253 253 253 253 253
44031-253 253 253 253 253 253 253 253 253 253 253 253
44032-253 253 253 253 253 253 253 253 253 253 253 253
44033-253 253 253 253 253 253 234 234 234 14 14 14
44034- 2 2 6 2 2 6 30 30 30 2 2 6
44035- 2 2 6 2 2 6 2 2 6 2 2 6
44036- 2 2 6 66 66 66 62 62 62 22 22 22
44037- 6 6 6 0 0 0 0 0 0 0 0 0
44038- 0 0 0 0 0 0 0 0 0 0 0 0
44039- 0 0 0 0 0 0 0 0 0 0 0 0
44040- 0 0 0 0 0 0 0 0 0 0 0 0
44041- 0 0 0 0 0 0 0 0 0 0 0 0
44042- 0 0 0 0 0 0 0 0 0 0 0 0
44043- 0 0 0 0 0 0 6 6 6 18 18 18
44044- 54 54 54 62 62 62 2 2 6 2 2 6
44045- 2 2 6 30 30 30 46 46 46 70 70 70
44046-250 250 250 253 253 253 253 253 253 253 253 253
44047-253 253 253 253 253 253 253 253 253 253 253 253
44048-253 253 253 253 253 253 231 231 231 246 246 246
44049-253 253 253 253 253 253 253 253 253 253 253 253
44050-253 253 253 253 253 253 253 253 253 253 253 253
44051-253 253 253 253 253 253 253 253 253 253 253 253
44052-253 253 253 253 253 253 253 253 253 253 253 253
44053-253 253 253 253 253 253 226 226 226 10 10 10
44054- 2 2 6 6 6 6 30 30 30 2 2 6
44055- 2 2 6 2 2 6 2 2 6 2 2 6
44056- 2 2 6 66 66 66 58 58 58 22 22 22
44057- 6 6 6 0 0 0 0 0 0 0 0 0
44058- 0 0 0 0 0 0 0 0 0 0 0 0
44059- 0 0 0 0 0 0 0 0 0 0 0 0
44060- 0 0 0 0 0 0 0 0 0 0 0 0
44061- 0 0 0 0 0 0 0 0 0 0 0 0
44062- 0 0 0 0 0 0 0 0 0 0 0 0
44063- 0 0 0 0 0 0 6 6 6 22 22 22
44064- 58 58 58 62 62 62 2 2 6 2 2 6
44065- 2 2 6 2 2 6 30 30 30 78 78 78
44066-250 250 250 253 253 253 253 253 253 253 253 253
44067-253 253 253 253 253 253 253 253 253 253 253 253
44068-253 253 253 253 253 253 231 231 231 246 246 246
44069-253 253 253 253 253 253 253 253 253 253 253 253
44070-253 253 253 253 253 253 253 253 253 253 253 253
44071-253 253 253 253 253 253 253 253 253 253 253 253
44072-253 253 253 253 253 253 253 253 253 253 253 253
44073-253 253 253 253 253 253 206 206 206 2 2 6
44074- 22 22 22 34 34 34 18 14 6 22 22 22
44075- 26 26 26 18 18 18 6 6 6 2 2 6
44076- 2 2 6 82 82 82 54 54 54 18 18 18
44077- 6 6 6 0 0 0 0 0 0 0 0 0
44078- 0 0 0 0 0 0 0 0 0 0 0 0
44079- 0 0 0 0 0 0 0 0 0 0 0 0
44080- 0 0 0 0 0 0 0 0 0 0 0 0
44081- 0 0 0 0 0 0 0 0 0 0 0 0
44082- 0 0 0 0 0 0 0 0 0 0 0 0
44083- 0 0 0 0 0 0 6 6 6 26 26 26
44084- 62 62 62 106 106 106 74 54 14 185 133 11
44085-210 162 10 121 92 8 6 6 6 62 62 62
44086-238 238 238 253 253 253 253 253 253 253 253 253
44087-253 253 253 253 253 253 253 253 253 253 253 253
44088-253 253 253 253 253 253 231 231 231 246 246 246
44089-253 253 253 253 253 253 253 253 253 253 253 253
44090-253 253 253 253 253 253 253 253 253 253 253 253
44091-253 253 253 253 253 253 253 253 253 253 253 253
44092-253 253 253 253 253 253 253 253 253 253 253 253
44093-253 253 253 253 253 253 158 158 158 18 18 18
44094- 14 14 14 2 2 6 2 2 6 2 2 6
44095- 6 6 6 18 18 18 66 66 66 38 38 38
44096- 6 6 6 94 94 94 50 50 50 18 18 18
44097- 6 6 6 0 0 0 0 0 0 0 0 0
44098- 0 0 0 0 0 0 0 0 0 0 0 0
44099- 0 0 0 0 0 0 0 0 0 0 0 0
44100- 0 0 0 0 0 0 0 0 0 0 0 0
44101- 0 0 0 0 0 0 0 0 0 0 0 0
44102- 0 0 0 0 0 0 0 0 0 6 6 6
44103- 10 10 10 10 10 10 18 18 18 38 38 38
44104- 78 78 78 142 134 106 216 158 10 242 186 14
44105-246 190 14 246 190 14 156 118 10 10 10 10
44106- 90 90 90 238 238 238 253 253 253 253 253 253
44107-253 253 253 253 253 253 253 253 253 253 253 253
44108-253 253 253 253 253 253 231 231 231 250 250 250
44109-253 253 253 253 253 253 253 253 253 253 253 253
44110-253 253 253 253 253 253 253 253 253 253 253 253
44111-253 253 253 253 253 253 253 253 253 253 253 253
44112-253 253 253 253 253 253 253 253 253 246 230 190
44113-238 204 91 238 204 91 181 142 44 37 26 9
44114- 2 2 6 2 2 6 2 2 6 2 2 6
44115- 2 2 6 2 2 6 38 38 38 46 46 46
44116- 26 26 26 106 106 106 54 54 54 18 18 18
44117- 6 6 6 0 0 0 0 0 0 0 0 0
44118- 0 0 0 0 0 0 0 0 0 0 0 0
44119- 0 0 0 0 0 0 0 0 0 0 0 0
44120- 0 0 0 0 0 0 0 0 0 0 0 0
44121- 0 0 0 0 0 0 0 0 0 0 0 0
44122- 0 0 0 6 6 6 14 14 14 22 22 22
44123- 30 30 30 38 38 38 50 50 50 70 70 70
44124-106 106 106 190 142 34 226 170 11 242 186 14
44125-246 190 14 246 190 14 246 190 14 154 114 10
44126- 6 6 6 74 74 74 226 226 226 253 253 253
44127-253 253 253 253 253 253 253 253 253 253 253 253
44128-253 253 253 253 253 253 231 231 231 250 250 250
44129-253 253 253 253 253 253 253 253 253 253 253 253
44130-253 253 253 253 253 253 253 253 253 253 253 253
44131-253 253 253 253 253 253 253 253 253 253 253 253
44132-253 253 253 253 253 253 253 253 253 228 184 62
44133-241 196 14 241 208 19 232 195 16 38 30 10
44134- 2 2 6 2 2 6 2 2 6 2 2 6
44135- 2 2 6 6 6 6 30 30 30 26 26 26
44136-203 166 17 154 142 90 66 66 66 26 26 26
44137- 6 6 6 0 0 0 0 0 0 0 0 0
44138- 0 0 0 0 0 0 0 0 0 0 0 0
44139- 0 0 0 0 0 0 0 0 0 0 0 0
44140- 0 0 0 0 0 0 0 0 0 0 0 0
44141- 0 0 0 0 0 0 0 0 0 0 0 0
44142- 6 6 6 18 18 18 38 38 38 58 58 58
44143- 78 78 78 86 86 86 101 101 101 123 123 123
44144-175 146 61 210 150 10 234 174 13 246 186 14
44145-246 190 14 246 190 14 246 190 14 238 190 10
44146-102 78 10 2 2 6 46 46 46 198 198 198
44147-253 253 253 253 253 253 253 253 253 253 253 253
44148-253 253 253 253 253 253 234 234 234 242 242 242
44149-253 253 253 253 253 253 253 253 253 253 253 253
44150-253 253 253 253 253 253 253 253 253 253 253 253
44151-253 253 253 253 253 253 253 253 253 253 253 253
44152-253 253 253 253 253 253 253 253 253 224 178 62
44153-242 186 14 241 196 14 210 166 10 22 18 6
44154- 2 2 6 2 2 6 2 2 6 2 2 6
44155- 2 2 6 2 2 6 6 6 6 121 92 8
44156-238 202 15 232 195 16 82 82 82 34 34 34
44157- 10 10 10 0 0 0 0 0 0 0 0 0
44158- 0 0 0 0 0 0 0 0 0 0 0 0
44159- 0 0 0 0 0 0 0 0 0 0 0 0
44160- 0 0 0 0 0 0 0 0 0 0 0 0
44161- 0 0 0 0 0 0 0 0 0 0 0 0
44162- 14 14 14 38 38 38 70 70 70 154 122 46
44163-190 142 34 200 144 11 197 138 11 197 138 11
44164-213 154 11 226 170 11 242 186 14 246 190 14
44165-246 190 14 246 190 14 246 190 14 246 190 14
44166-225 175 15 46 32 6 2 2 6 22 22 22
44167-158 158 158 250 250 250 253 253 253 253 253 253
44168-253 253 253 253 253 253 253 253 253 253 253 253
44169-253 253 253 253 253 253 253 253 253 253 253 253
44170-253 253 253 253 253 253 253 253 253 253 253 253
44171-253 253 253 253 253 253 253 253 253 253 253 253
44172-253 253 253 250 250 250 242 242 242 224 178 62
44173-239 182 13 236 186 11 213 154 11 46 32 6
44174- 2 2 6 2 2 6 2 2 6 2 2 6
44175- 2 2 6 2 2 6 61 42 6 225 175 15
44176-238 190 10 236 186 11 112 100 78 42 42 42
44177- 14 14 14 0 0 0 0 0 0 0 0 0
44178- 0 0 0 0 0 0 0 0 0 0 0 0
44179- 0 0 0 0 0 0 0 0 0 0 0 0
44180- 0 0 0 0 0 0 0 0 0 0 0 0
44181- 0 0 0 0 0 0 0 0 0 6 6 6
44182- 22 22 22 54 54 54 154 122 46 213 154 11
44183-226 170 11 230 174 11 226 170 11 226 170 11
44184-236 178 12 242 186 14 246 190 14 246 190 14
44185-246 190 14 246 190 14 246 190 14 246 190 14
44186-241 196 14 184 144 12 10 10 10 2 2 6
44187- 6 6 6 116 116 116 242 242 242 253 253 253
44188-253 253 253 253 253 253 253 253 253 253 253 253
44189-253 253 253 253 253 253 253 253 253 253 253 253
44190-253 253 253 253 253 253 253 253 253 253 253 253
44191-253 253 253 253 253 253 253 253 253 253 253 253
44192-253 253 253 231 231 231 198 198 198 214 170 54
44193-236 178 12 236 178 12 210 150 10 137 92 6
44194- 18 14 6 2 2 6 2 2 6 2 2 6
44195- 6 6 6 70 47 6 200 144 11 236 178 12
44196-239 182 13 239 182 13 124 112 88 58 58 58
44197- 22 22 22 6 6 6 0 0 0 0 0 0
44198- 0 0 0 0 0 0 0 0 0 0 0 0
44199- 0 0 0 0 0 0 0 0 0 0 0 0
44200- 0 0 0 0 0 0 0 0 0 0 0 0
44201- 0 0 0 0 0 0 0 0 0 10 10 10
44202- 30 30 30 70 70 70 180 133 36 226 170 11
44203-239 182 13 242 186 14 242 186 14 246 186 14
44204-246 190 14 246 190 14 246 190 14 246 190 14
44205-246 190 14 246 190 14 246 190 14 246 190 14
44206-246 190 14 232 195 16 98 70 6 2 2 6
44207- 2 2 6 2 2 6 66 66 66 221 221 221
44208-253 253 253 253 253 253 253 253 253 253 253 253
44209-253 253 253 253 253 253 253 253 253 253 253 253
44210-253 253 253 253 253 253 253 253 253 253 253 253
44211-253 253 253 253 253 253 253 253 253 253 253 253
44212-253 253 253 206 206 206 198 198 198 214 166 58
44213-230 174 11 230 174 11 216 158 10 192 133 9
44214-163 110 8 116 81 8 102 78 10 116 81 8
44215-167 114 7 197 138 11 226 170 11 239 182 13
44216-242 186 14 242 186 14 162 146 94 78 78 78
44217- 34 34 34 14 14 14 6 6 6 0 0 0
44218- 0 0 0 0 0 0 0 0 0 0 0 0
44219- 0 0 0 0 0 0 0 0 0 0 0 0
44220- 0 0 0 0 0 0 0 0 0 0 0 0
44221- 0 0 0 0 0 0 0 0 0 6 6 6
44222- 30 30 30 78 78 78 190 142 34 226 170 11
44223-239 182 13 246 190 14 246 190 14 246 190 14
44224-246 190 14 246 190 14 246 190 14 246 190 14
44225-246 190 14 246 190 14 246 190 14 246 190 14
44226-246 190 14 241 196 14 203 166 17 22 18 6
44227- 2 2 6 2 2 6 2 2 6 38 38 38
44228-218 218 218 253 253 253 253 253 253 253 253 253
44229-253 253 253 253 253 253 253 253 253 253 253 253
44230-253 253 253 253 253 253 253 253 253 253 253 253
44231-253 253 253 253 253 253 253 253 253 253 253 253
44232-250 250 250 206 206 206 198 198 198 202 162 69
44233-226 170 11 236 178 12 224 166 10 210 150 10
44234-200 144 11 197 138 11 192 133 9 197 138 11
44235-210 150 10 226 170 11 242 186 14 246 190 14
44236-246 190 14 246 186 14 225 175 15 124 112 88
44237- 62 62 62 30 30 30 14 14 14 6 6 6
44238- 0 0 0 0 0 0 0 0 0 0 0 0
44239- 0 0 0 0 0 0 0 0 0 0 0 0
44240- 0 0 0 0 0 0 0 0 0 0 0 0
44241- 0 0 0 0 0 0 0 0 0 10 10 10
44242- 30 30 30 78 78 78 174 135 50 224 166 10
44243-239 182 13 246 190 14 246 190 14 246 190 14
44244-246 190 14 246 190 14 246 190 14 246 190 14
44245-246 190 14 246 190 14 246 190 14 246 190 14
44246-246 190 14 246 190 14 241 196 14 139 102 15
44247- 2 2 6 2 2 6 2 2 6 2 2 6
44248- 78 78 78 250 250 250 253 253 253 253 253 253
44249-253 253 253 253 253 253 253 253 253 253 253 253
44250-253 253 253 253 253 253 253 253 253 253 253 253
44251-253 253 253 253 253 253 253 253 253 253 253 253
44252-250 250 250 214 214 214 198 198 198 190 150 46
44253-219 162 10 236 178 12 234 174 13 224 166 10
44254-216 158 10 213 154 11 213 154 11 216 158 10
44255-226 170 11 239 182 13 246 190 14 246 190 14
44256-246 190 14 246 190 14 242 186 14 206 162 42
44257-101 101 101 58 58 58 30 30 30 14 14 14
44258- 6 6 6 0 0 0 0 0 0 0 0 0
44259- 0 0 0 0 0 0 0 0 0 0 0 0
44260- 0 0 0 0 0 0 0 0 0 0 0 0
44261- 0 0 0 0 0 0 0 0 0 10 10 10
44262- 30 30 30 74 74 74 174 135 50 216 158 10
44263-236 178 12 246 190 14 246 190 14 246 190 14
44264-246 190 14 246 190 14 246 190 14 246 190 14
44265-246 190 14 246 190 14 246 190 14 246 190 14
44266-246 190 14 246 190 14 241 196 14 226 184 13
44267- 61 42 6 2 2 6 2 2 6 2 2 6
44268- 22 22 22 238 238 238 253 253 253 253 253 253
44269-253 253 253 253 253 253 253 253 253 253 253 253
44270-253 253 253 253 253 253 253 253 253 253 253 253
44271-253 253 253 253 253 253 253 253 253 253 253 253
44272-253 253 253 226 226 226 187 187 187 180 133 36
44273-216 158 10 236 178 12 239 182 13 236 178 12
44274-230 174 11 226 170 11 226 170 11 230 174 11
44275-236 178 12 242 186 14 246 190 14 246 190 14
44276-246 190 14 246 190 14 246 186 14 239 182 13
44277-206 162 42 106 106 106 66 66 66 34 34 34
44278- 14 14 14 6 6 6 0 0 0 0 0 0
44279- 0 0 0 0 0 0 0 0 0 0 0 0
44280- 0 0 0 0 0 0 0 0 0 0 0 0
44281- 0 0 0 0 0 0 0 0 0 6 6 6
44282- 26 26 26 70 70 70 163 133 67 213 154 11
44283-236 178 12 246 190 14 246 190 14 246 190 14
44284-246 190 14 246 190 14 246 190 14 246 190 14
44285-246 190 14 246 190 14 246 190 14 246 190 14
44286-246 190 14 246 190 14 246 190 14 241 196 14
44287-190 146 13 18 14 6 2 2 6 2 2 6
44288- 46 46 46 246 246 246 253 253 253 253 253 253
44289-253 253 253 253 253 253 253 253 253 253 253 253
44290-253 253 253 253 253 253 253 253 253 253 253 253
44291-253 253 253 253 253 253 253 253 253 253 253 253
44292-253 253 253 221 221 221 86 86 86 156 107 11
44293-216 158 10 236 178 12 242 186 14 246 186 14
44294-242 186 14 239 182 13 239 182 13 242 186 14
44295-242 186 14 246 186 14 246 190 14 246 190 14
44296-246 190 14 246 190 14 246 190 14 246 190 14
44297-242 186 14 225 175 15 142 122 72 66 66 66
44298- 30 30 30 10 10 10 0 0 0 0 0 0
44299- 0 0 0 0 0 0 0 0 0 0 0 0
44300- 0 0 0 0 0 0 0 0 0 0 0 0
44301- 0 0 0 0 0 0 0 0 0 6 6 6
44302- 26 26 26 70 70 70 163 133 67 210 150 10
44303-236 178 12 246 190 14 246 190 14 246 190 14
44304-246 190 14 246 190 14 246 190 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-232 195 16 121 92 8 34 34 34 106 106 106
44308-221 221 221 253 253 253 253 253 253 253 253 253
44309-253 253 253 253 253 253 253 253 253 253 253 253
44310-253 253 253 253 253 253 253 253 253 253 253 253
44311-253 253 253 253 253 253 253 253 253 253 253 253
44312-242 242 242 82 82 82 18 14 6 163 110 8
44313-216 158 10 236 178 12 242 186 14 246 190 14
44314-246 190 14 246 190 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 242 186 14 163 133 67
44318- 46 46 46 18 18 18 6 6 6 0 0 0
44319- 0 0 0 0 0 0 0 0 0 0 0 0
44320- 0 0 0 0 0 0 0 0 0 0 0 0
44321- 0 0 0 0 0 0 0 0 0 10 10 10
44322- 30 30 30 78 78 78 163 133 67 210 150 10
44323-236 178 12 246 186 14 246 190 14 246 190 14
44324-246 190 14 246 190 14 246 190 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-241 196 14 215 174 15 190 178 144 253 253 253
44328-253 253 253 253 253 253 253 253 253 253 253 253
44329-253 253 253 253 253 253 253 253 253 253 253 253
44330-253 253 253 253 253 253 253 253 253 253 253 253
44331-253 253 253 253 253 253 253 253 253 218 218 218
44332- 58 58 58 2 2 6 22 18 6 167 114 7
44333-216 158 10 236 178 12 246 186 14 246 190 14
44334-246 190 14 246 190 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 186 14 242 186 14 190 150 46
44338- 54 54 54 22 22 22 6 6 6 0 0 0
44339- 0 0 0 0 0 0 0 0 0 0 0 0
44340- 0 0 0 0 0 0 0 0 0 0 0 0
44341- 0 0 0 0 0 0 0 0 0 14 14 14
44342- 38 38 38 86 86 86 180 133 36 213 154 11
44343-236 178 12 246 186 14 246 190 14 246 190 14
44344-246 190 14 246 190 14 246 190 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 232 195 16 190 146 13 214 214 214
44348-253 253 253 253 253 253 253 253 253 253 253 253
44349-253 253 253 253 253 253 253 253 253 253 253 253
44350-253 253 253 253 253 253 253 253 253 253 253 253
44351-253 253 253 250 250 250 170 170 170 26 26 26
44352- 2 2 6 2 2 6 37 26 9 163 110 8
44353-219 162 10 239 182 13 246 186 14 246 190 14
44354-246 190 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 186 14 236 178 12 224 166 10 142 122 72
44358- 46 46 46 18 18 18 6 6 6 0 0 0
44359- 0 0 0 0 0 0 0 0 0 0 0 0
44360- 0 0 0 0 0 0 0 0 0 0 0 0
44361- 0 0 0 0 0 0 6 6 6 18 18 18
44362- 50 50 50 109 106 95 192 133 9 224 166 10
44363-242 186 14 246 190 14 246 190 14 246 190 14
44364-246 190 14 246 190 14 246 190 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-242 186 14 226 184 13 210 162 10 142 110 46
44368-226 226 226 253 253 253 253 253 253 253 253 253
44369-253 253 253 253 253 253 253 253 253 253 253 253
44370-253 253 253 253 253 253 253 253 253 253 253 253
44371-198 198 198 66 66 66 2 2 6 2 2 6
44372- 2 2 6 2 2 6 50 34 6 156 107 11
44373-219 162 10 239 182 13 246 186 14 246 190 14
44374-246 190 14 246 190 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 242 186 14
44377-234 174 13 213 154 11 154 122 46 66 66 66
44378- 30 30 30 10 10 10 0 0 0 0 0 0
44379- 0 0 0 0 0 0 0 0 0 0 0 0
44380- 0 0 0 0 0 0 0 0 0 0 0 0
44381- 0 0 0 0 0 0 6 6 6 22 22 22
44382- 58 58 58 154 121 60 206 145 10 234 174 13
44383-242 186 14 246 186 14 246 190 14 246 190 14
44384-246 190 14 246 190 14 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 186 14 236 178 12 210 162 10 163 110 8
44388- 61 42 6 138 138 138 218 218 218 250 250 250
44389-253 253 253 253 253 253 253 253 253 250 250 250
44390-242 242 242 210 210 210 144 144 144 66 66 66
44391- 6 6 6 2 2 6 2 2 6 2 2 6
44392- 2 2 6 2 2 6 61 42 6 163 110 8
44393-216 158 10 236 178 12 246 190 14 246 190 14
44394-246 190 14 246 190 14 246 190 14 246 190 14
44395-246 190 14 246 190 14 246 190 14 246 190 14
44396-246 190 14 239 182 13 230 174 11 216 158 10
44397-190 142 34 124 112 88 70 70 70 38 38 38
44398- 18 18 18 6 6 6 0 0 0 0 0 0
44399- 0 0 0 0 0 0 0 0 0 0 0 0
44400- 0 0 0 0 0 0 0 0 0 0 0 0
44401- 0 0 0 0 0 0 6 6 6 22 22 22
44402- 62 62 62 168 124 44 206 145 10 224 166 10
44403-236 178 12 239 182 13 242 186 14 242 186 14
44404-246 186 14 246 190 14 246 190 14 246 190 14
44405-246 190 14 246 190 14 246 190 14 246 190 14
44406-246 190 14 246 190 14 246 190 14 246 190 14
44407-246 190 14 236 178 12 216 158 10 175 118 6
44408- 80 54 7 2 2 6 6 6 6 30 30 30
44409- 54 54 54 62 62 62 50 50 50 38 38 38
44410- 14 14 14 2 2 6 2 2 6 2 2 6
44411- 2 2 6 2 2 6 2 2 6 2 2 6
44412- 2 2 6 6 6 6 80 54 7 167 114 7
44413-213 154 11 236 178 12 246 190 14 246 190 14
44414-246 190 14 246 190 14 246 190 14 246 190 14
44415-246 190 14 242 186 14 239 182 13 239 182 13
44416-230 174 11 210 150 10 174 135 50 124 112 88
44417- 82 82 82 54 54 54 34 34 34 18 18 18
44418- 6 6 6 0 0 0 0 0 0 0 0 0
44419- 0 0 0 0 0 0 0 0 0 0 0 0
44420- 0 0 0 0 0 0 0 0 0 0 0 0
44421- 0 0 0 0 0 0 6 6 6 18 18 18
44422- 50 50 50 158 118 36 192 133 9 200 144 11
44423-216 158 10 219 162 10 224 166 10 226 170 11
44424-230 174 11 236 178 12 239 182 13 239 182 13
44425-242 186 14 246 186 14 246 190 14 246 190 14
44426-246 190 14 246 190 14 246 190 14 246 190 14
44427-246 186 14 230 174 11 210 150 10 163 110 8
44428-104 69 6 10 10 10 2 2 6 2 2 6
44429- 2 2 6 2 2 6 2 2 6 2 2 6
44430- 2 2 6 2 2 6 2 2 6 2 2 6
44431- 2 2 6 2 2 6 2 2 6 2 2 6
44432- 2 2 6 6 6 6 91 60 6 167 114 7
44433-206 145 10 230 174 11 242 186 14 246 190 14
44434-246 190 14 246 190 14 246 186 14 242 186 14
44435-239 182 13 230 174 11 224 166 10 213 154 11
44436-180 133 36 124 112 88 86 86 86 58 58 58
44437- 38 38 38 22 22 22 10 10 10 6 6 6
44438- 0 0 0 0 0 0 0 0 0 0 0 0
44439- 0 0 0 0 0 0 0 0 0 0 0 0
44440- 0 0 0 0 0 0 0 0 0 0 0 0
44441- 0 0 0 0 0 0 0 0 0 14 14 14
44442- 34 34 34 70 70 70 138 110 50 158 118 36
44443-167 114 7 180 123 7 192 133 9 197 138 11
44444-200 144 11 206 145 10 213 154 11 219 162 10
44445-224 166 10 230 174 11 239 182 13 242 186 14
44446-246 186 14 246 186 14 246 186 14 246 186 14
44447-239 182 13 216 158 10 185 133 11 152 99 6
44448-104 69 6 18 14 6 2 2 6 2 2 6
44449- 2 2 6 2 2 6 2 2 6 2 2 6
44450- 2 2 6 2 2 6 2 2 6 2 2 6
44451- 2 2 6 2 2 6 2 2 6 2 2 6
44452- 2 2 6 6 6 6 80 54 7 152 99 6
44453-192 133 9 219 162 10 236 178 12 239 182 13
44454-246 186 14 242 186 14 239 182 13 236 178 12
44455-224 166 10 206 145 10 192 133 9 154 121 60
44456- 94 94 94 62 62 62 42 42 42 22 22 22
44457- 14 14 14 6 6 6 0 0 0 0 0 0
44458- 0 0 0 0 0 0 0 0 0 0 0 0
44459- 0 0 0 0 0 0 0 0 0 0 0 0
44460- 0 0 0 0 0 0 0 0 0 0 0 0
44461- 0 0 0 0 0 0 0 0 0 6 6 6
44462- 18 18 18 34 34 34 58 58 58 78 78 78
44463-101 98 89 124 112 88 142 110 46 156 107 11
44464-163 110 8 167 114 7 175 118 6 180 123 7
44465-185 133 11 197 138 11 210 150 10 219 162 10
44466-226 170 11 236 178 12 236 178 12 234 174 13
44467-219 162 10 197 138 11 163 110 8 130 83 6
44468- 91 60 6 10 10 10 2 2 6 2 2 6
44469- 18 18 18 38 38 38 38 38 38 38 38 38
44470- 38 38 38 38 38 38 38 38 38 38 38 38
44471- 38 38 38 38 38 38 26 26 26 2 2 6
44472- 2 2 6 6 6 6 70 47 6 137 92 6
44473-175 118 6 200 144 11 219 162 10 230 174 11
44474-234 174 13 230 174 11 219 162 10 210 150 10
44475-192 133 9 163 110 8 124 112 88 82 82 82
44476- 50 50 50 30 30 30 14 14 14 6 6 6
44477- 0 0 0 0 0 0 0 0 0 0 0 0
44478- 0 0 0 0 0 0 0 0 0 0 0 0
44479- 0 0 0 0 0 0 0 0 0 0 0 0
44480- 0 0 0 0 0 0 0 0 0 0 0 0
44481- 0 0 0 0 0 0 0 0 0 0 0 0
44482- 6 6 6 14 14 14 22 22 22 34 34 34
44483- 42 42 42 58 58 58 74 74 74 86 86 86
44484-101 98 89 122 102 70 130 98 46 121 87 25
44485-137 92 6 152 99 6 163 110 8 180 123 7
44486-185 133 11 197 138 11 206 145 10 200 144 11
44487-180 123 7 156 107 11 130 83 6 104 69 6
44488- 50 34 6 54 54 54 110 110 110 101 98 89
44489- 86 86 86 82 82 82 78 78 78 78 78 78
44490- 78 78 78 78 78 78 78 78 78 78 78 78
44491- 78 78 78 82 82 82 86 86 86 94 94 94
44492-106 106 106 101 101 101 86 66 34 124 80 6
44493-156 107 11 180 123 7 192 133 9 200 144 11
44494-206 145 10 200 144 11 192 133 9 175 118 6
44495-139 102 15 109 106 95 70 70 70 42 42 42
44496- 22 22 22 10 10 10 0 0 0 0 0 0
44497- 0 0 0 0 0 0 0 0 0 0 0 0
44498- 0 0 0 0 0 0 0 0 0 0 0 0
44499- 0 0 0 0 0 0 0 0 0 0 0 0
44500- 0 0 0 0 0 0 0 0 0 0 0 0
44501- 0 0 0 0 0 0 0 0 0 0 0 0
44502- 0 0 0 0 0 0 6 6 6 10 10 10
44503- 14 14 14 22 22 22 30 30 30 38 38 38
44504- 50 50 50 62 62 62 74 74 74 90 90 90
44505-101 98 89 112 100 78 121 87 25 124 80 6
44506-137 92 6 152 99 6 152 99 6 152 99 6
44507-138 86 6 124 80 6 98 70 6 86 66 30
44508-101 98 89 82 82 82 58 58 58 46 46 46
44509- 38 38 38 34 34 34 34 34 34 34 34 34
44510- 34 34 34 34 34 34 34 34 34 34 34 34
44511- 34 34 34 34 34 34 38 38 38 42 42 42
44512- 54 54 54 82 82 82 94 86 76 91 60 6
44513-134 86 6 156 107 11 167 114 7 175 118 6
44514-175 118 6 167 114 7 152 99 6 121 87 25
44515-101 98 89 62 62 62 34 34 34 18 18 18
44516- 6 6 6 0 0 0 0 0 0 0 0 0
44517- 0 0 0 0 0 0 0 0 0 0 0 0
44518- 0 0 0 0 0 0 0 0 0 0 0 0
44519- 0 0 0 0 0 0 0 0 0 0 0 0
44520- 0 0 0 0 0 0 0 0 0 0 0 0
44521- 0 0 0 0 0 0 0 0 0 0 0 0
44522- 0 0 0 0 0 0 0 0 0 0 0 0
44523- 0 0 0 6 6 6 6 6 6 10 10 10
44524- 18 18 18 22 22 22 30 30 30 42 42 42
44525- 50 50 50 66 66 66 86 86 86 101 98 89
44526-106 86 58 98 70 6 104 69 6 104 69 6
44527-104 69 6 91 60 6 82 62 34 90 90 90
44528- 62 62 62 38 38 38 22 22 22 14 14 14
44529- 10 10 10 10 10 10 10 10 10 10 10 10
44530- 10 10 10 10 10 10 6 6 6 10 10 10
44531- 10 10 10 10 10 10 10 10 10 14 14 14
44532- 22 22 22 42 42 42 70 70 70 89 81 66
44533- 80 54 7 104 69 6 124 80 6 137 92 6
44534-134 86 6 116 81 8 100 82 52 86 86 86
44535- 58 58 58 30 30 30 14 14 14 6 6 6
44536- 0 0 0 0 0 0 0 0 0 0 0 0
44537- 0 0 0 0 0 0 0 0 0 0 0 0
44538- 0 0 0 0 0 0 0 0 0 0 0 0
44539- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
44544- 0 0 0 6 6 6 10 10 10 14 14 14
44545- 18 18 18 26 26 26 38 38 38 54 54 54
44546- 70 70 70 86 86 86 94 86 76 89 81 66
44547- 89 81 66 86 86 86 74 74 74 50 50 50
44548- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
44553- 82 82 82 89 81 66 89 81 66 89 81 66
44554- 94 86 66 94 86 76 74 74 74 50 50 50
44555- 26 26 26 14 14 14 6 6 6 0 0 0
44556- 0 0 0 0 0 0 0 0 0 0 0 0
44557- 0 0 0 0 0 0 0 0 0 0 0 0
44558- 0 0 0 0 0 0 0 0 0 0 0 0
44559- 0 0 0 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 0 0 0 0 0 0 0 0 0
44564- 0 0 0 0 0 0 0 0 0 0 0 0
44565- 6 6 6 6 6 6 14 14 14 18 18 18
44566- 30 30 30 38 38 38 46 46 46 54 54 54
44567- 50 50 50 42 42 42 30 30 30 18 18 18
44568- 10 10 10 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 6 6 6 14 14 14 26 26 26
44573- 38 38 38 50 50 50 58 58 58 58 58 58
44574- 54 54 54 42 42 42 30 30 30 18 18 18
44575- 10 10 10 0 0 0 0 0 0 0 0 0
44576- 0 0 0 0 0 0 0 0 0 0 0 0
44577- 0 0 0 0 0 0 0 0 0 0 0 0
44578- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
44584- 0 0 0 0 0 0 0 0 0 0 0 0
44585- 0 0 0 0 0 0 0 0 0 6 6 6
44586- 6 6 6 10 10 10 14 14 14 18 18 18
44587- 18 18 18 14 14 14 10 10 10 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
44592- 0 0 0 0 0 0 0 0 0 6 6 6
44593- 14 14 14 18 18 18 22 22 22 22 22 22
44594- 18 18 18 14 14 14 10 10 10 6 6 6
44595- 0 0 0 0 0 0 0 0 0 0 0 0
44596- 0 0 0 0 0 0 0 0 0 0 0 0
44597- 0 0 0 0 0 0 0 0 0 0 0 0
44598- 0 0 0 0 0 0 0 0 0 0 0 0
44599- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
44680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
44684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 3 3 3 0 0 0 0 0 0
44689+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 1 1 1 0 0 0
44694+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44695+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
44698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
44703+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
44704+5 5 5 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+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
44708+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
44709+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
44710+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711+4 4 4 4 4 4
44712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44716+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
44717+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
44718+0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
44721+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
44722+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
44723+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
44724+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
44725+4 4 4 4 4 4
44726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44729+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
44730+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
44731+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
44732+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44735+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
44736+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
44737+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
44738+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
44739+4 4 4 4 4 4
44740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44743+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
44744+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
44745+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
44746+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
44747+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44748+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
44749+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
44750+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
44751+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
44752+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
44753+4 4 4 4 4 4
44754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44757+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
44758+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
44759+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
44760+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
44761+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44762+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
44763+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
44764+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
44765+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
44766+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
44767+4 4 4 4 4 4
44768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44770+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
44771+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
44772+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
44773+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
44774+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
44775+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
44776+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
44777+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
44778+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
44779+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
44780+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
44781+4 4 4 4 4 4
44782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44784+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
44785+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
44786+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
44787+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
44788+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
44789+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
44790+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
44791+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
44792+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
44793+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
44794+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
44795+4 4 4 4 4 4
44796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44798+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
44799+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
44800+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
44801+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
44802+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
44803+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
44804+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
44805+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
44806+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
44807+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
44808+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44809+4 4 4 4 4 4
44810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44812+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
44813+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
44814+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
44815+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
44816+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
44817+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
44818+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
44819+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
44820+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
44821+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
44822+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
44823+4 4 4 4 4 4
44824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44825+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
44826+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
44827+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
44828+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
44829+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
44830+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
44831+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
44832+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
44833+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
44834+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
44835+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
44836+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
44837+4 4 4 4 4 4
44838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44839+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
44840+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
44841+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
44842+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44843+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
44844+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
44845+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
44846+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
44847+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
44848+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
44849+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
44850+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
44851+0 0 0 4 4 4
44852+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44853+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
44854+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
44855+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
44856+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
44857+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
44858+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
44859+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
44860+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
44861+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
44862+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
44863+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
44864+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
44865+2 0 0 0 0 0
44866+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
44867+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
44868+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
44869+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
44870+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
44871+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
44872+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
44873+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
44874+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
44875+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
44876+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
44877+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
44878+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
44879+37 38 37 0 0 0
44880+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44881+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
44882+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
44883+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
44884+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
44885+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
44886+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
44887+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
44888+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
44889+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
44890+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
44891+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
44892+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
44893+85 115 134 4 0 0
44894+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
44895+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
44896+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
44897+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
44898+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
44899+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
44900+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
44901+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
44902+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
44903+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
44904+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
44905+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
44906+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
44907+60 73 81 4 0 0
44908+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
44909+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
44910+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
44911+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
44912+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
44913+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
44914+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
44915+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
44916+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
44917+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
44918+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
44919+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
44920+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
44921+16 19 21 4 0 0
44922+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44923+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44924+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44925+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44926+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44927+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44928+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
44929+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
44930+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
44931+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
44932+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
44933+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
44934+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44935+4 0 0 4 3 3
44936+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44937+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44938+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44940+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44941+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44942+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44943+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44944+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44945+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44946+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44947+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44948+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44949+3 2 2 4 4 4
44950+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44951+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44952+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44953+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44954+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44955+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44956+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44957+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44958+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44959+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44960+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44961+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44962+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44963+4 4 4 4 4 4
44964+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44965+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44966+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44967+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44968+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44969+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44970+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44971+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44972+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44973+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44974+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44975+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44976+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44977+4 4 4 4 4 4
44978+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44979+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44980+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44981+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44982+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44983+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44984+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44985+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44986+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44987+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44988+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44989+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44990+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44991+5 5 5 5 5 5
44992+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44993+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44994+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44995+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44996+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44997+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44998+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44999+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
45000+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
45001+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
45002+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
45003+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
45004+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45005+5 5 5 4 4 4
45006+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
45007+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
45008+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45009+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45010+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45011+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45012+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45013+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45014+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45015+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45016+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45017+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45019+4 4 4 4 4 4
45020+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45021+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45022+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45023+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45024+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45025+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45026+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45027+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45028+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45029+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45030+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45031+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45033+4 4 4 4 4 4
45034+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45035+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45036+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45037+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45038+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45039+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45040+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45041+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45042+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45043+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45044+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45047+4 4 4 4 4 4
45048+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
45049+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
45050+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
45051+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
45052+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45053+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45054+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45055+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
45056+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
45057+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
45058+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
45059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45061+4 4 4 4 4 4
45062+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
45063+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
45064+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
45065+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
45066+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45067+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
45068+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45069+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
45070+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
45071+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
45072+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45075+4 4 4 4 4 4
45076+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
45077+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
45078+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
45079+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
45080+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45081+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
45082+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
45083+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
45084+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
45085+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
45086+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
45087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45089+4 4 4 4 4 4
45090+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
45091+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
45092+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
45093+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
45094+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45095+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
45096+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
45097+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
45098+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
45099+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
45100+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
45101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45103+4 4 4 4 4 4
45104+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
45105+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
45106+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
45107+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45108+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
45109+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
45110+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
45111+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
45112+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
45113+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
45114+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45117+4 4 4 4 4 4
45118+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
45119+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
45120+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
45121+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45122+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45123+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
45124+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
45125+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
45126+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
45127+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
45128+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45131+4 4 4 4 4 4
45132+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
45133+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
45134+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45135+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45136+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45137+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
45138+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
45139+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
45140+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
45141+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
45142+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45145+4 4 4 4 4 4
45146+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
45147+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
45148+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45149+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45150+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45151+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
45152+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
45153+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
45154+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45155+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45156+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45159+4 4 4 4 4 4
45160+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45161+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
45162+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45163+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
45164+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
45165+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
45166+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
45167+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
45168+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45169+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45170+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45173+4 4 4 4 4 4
45174+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45175+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
45176+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45177+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
45178+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45179+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
45180+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
45181+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
45182+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45183+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45184+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45187+4 4 4 4 4 4
45188+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
45189+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
45190+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45191+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
45192+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
45193+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
45194+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
45195+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
45196+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45197+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45198+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45201+4 4 4 4 4 4
45202+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
45203+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
45204+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45205+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
45206+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
45207+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
45208+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
45209+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
45210+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45211+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45212+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45215+4 4 4 4 4 4
45216+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45217+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
45218+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45219+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
45220+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
45221+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
45222+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
45223+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
45224+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45225+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45226+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45229+4 4 4 4 4 4
45230+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
45231+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
45232+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45233+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
45234+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
45235+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
45236+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
45237+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
45238+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
45239+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45240+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45243+4 4 4 4 4 4
45244+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45245+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
45246+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
45247+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
45248+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
45249+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
45250+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
45251+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
45252+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45253+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45254+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45257+4 4 4 4 4 4
45258+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45259+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
45260+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45261+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
45262+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
45263+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
45264+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
45265+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
45266+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45267+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45268+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45271+4 4 4 4 4 4
45272+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45273+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
45274+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
45275+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
45276+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
45277+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
45278+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45279+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
45280+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45281+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45282+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45285+4 4 4 4 4 4
45286+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45287+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
45288+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
45289+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45290+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
45291+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
45292+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45293+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
45294+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45295+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45296+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45299+4 4 4 4 4 4
45300+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45301+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
45302+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
45303+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
45304+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
45305+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
45306+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
45307+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
45308+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
45309+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45310+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45313+4 4 4 4 4 4
45314+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45315+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
45316+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
45317+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
45318+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
45319+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
45320+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
45321+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
45322+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
45323+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45324+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45327+4 4 4 4 4 4
45328+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
45329+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
45330+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
45331+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
45332+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45333+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
45334+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
45335+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
45336+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
45337+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45338+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45341+4 4 4 4 4 4
45342+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45343+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
45344+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
45345+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
45346+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
45347+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
45348+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
45349+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
45350+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
45351+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45352+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45355+4 4 4 4 4 4
45356+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
45357+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
45358+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
45359+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
45360+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
45361+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
45362+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
45363+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
45364+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
45365+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
45366+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45369+4 4 4 4 4 4
45370+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
45371+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45372+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
45373+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
45374+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
45375+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
45376+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
45377+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
45378+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
45379+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
45380+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45383+4 4 4 4 4 4
45384+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
45385+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45386+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
45387+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
45388+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
45389+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
45390+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45391+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
45392+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
45393+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
45394+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45397+4 4 4 4 4 4
45398+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
45399+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
45400+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
45401+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
45402+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
45403+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
45404+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
45405+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
45406+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
45407+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
45408+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45411+4 4 4 4 4 4
45412+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
45413+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
45414+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45415+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
45416+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
45417+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
45418+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
45419+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
45420+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
45421+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
45422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45425+4 4 4 4 4 4
45426+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45427+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
45428+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
45429+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
45430+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
45431+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
45432+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
45433+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
45434+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
45435+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45439+4 4 4 4 4 4
45440+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
45441+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
45442+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
45443+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
45444+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
45445+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
45446+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
45447+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
45448+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
45449+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45453+4 4 4 4 4 4
45454+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
45455+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
45456+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
45457+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
45458+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
45459+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
45460+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
45461+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
45462+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45463+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45467+4 4 4 4 4 4
45468+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
45469+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45470+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
45471+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45472+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
45473+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
45474+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
45475+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
45476+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
45477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45481+4 4 4 4 4 4
45482+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
45483+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
45484+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
45485+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
45486+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
45487+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
45488+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
45489+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
45490+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
45491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45495+4 4 4 4 4 4
45496+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45497+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
45498+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
45499+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
45500+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
45501+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
45502+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
45503+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
45504+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45509+4 4 4 4 4 4
45510+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
45511+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
45512+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45513+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
45514+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
45515+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
45516+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
45517+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
45518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45523+4 4 4 4 4 4
45524+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45525+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
45526+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
45527+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
45528+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
45529+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
45530+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
45531+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45537+4 4 4 4 4 4
45538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45539+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
45540+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45541+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
45542+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
45543+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
45544+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
45545+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
45546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45551+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
45554+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
45555+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
45556+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
45557+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
45558+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
45559+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
45560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45565+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 5 5 5 5 5 5 5 5 5
45568+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
45569+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45570+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
45571+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
45572+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
45573+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45579+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45583+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
45584+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
45585+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
45586+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
45587+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5
45597+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45598+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
45599+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
45600+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
45601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45612+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45613+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
45614+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
45617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5 6 6 6
45626+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45627+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45628+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
45631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5
45640+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
45641+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
45642+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4
45645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45647+4 4 4 4 4 4 4 4 4 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
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 5 5 5
45654+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
45655+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45656+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45661+4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
45669+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
45670+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45675+4 4 4 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
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
45683+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
45684+5 5 5 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 4 4 4 4 4 4 4 4 4
45688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 5 5 5 4 3 3 6 6 6
45697+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4
45702+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 5 5 5 4 3 3
45711+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
45712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45719+4 4 4 4 4 4
45720diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
45721index 443e3c8..c443d6a 100644
45722--- a/drivers/video/nvidia/nv_backlight.c
45723+++ b/drivers/video/nvidia/nv_backlight.c
45724@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(struct backlight_device *bd)
45725 return bd->props.brightness;
45726 }
45727
45728-static struct backlight_ops nvidia_bl_ops = {
45729+static const struct backlight_ops nvidia_bl_ops = {
45730 .get_brightness = nvidia_bl_get_brightness,
45731 .update_status = nvidia_bl_update_status,
45732 };
45733diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
45734index d94c57f..912984c 100644
45735--- a/drivers/video/riva/fbdev.c
45736+++ b/drivers/video/riva/fbdev.c
45737@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct backlight_device *bd)
45738 return bd->props.brightness;
45739 }
45740
45741-static struct backlight_ops riva_bl_ops = {
45742+static const struct backlight_ops riva_bl_ops = {
45743 .get_brightness = riva_bl_get_brightness,
45744 .update_status = riva_bl_update_status,
45745 };
45746diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
45747index 54fbb29..2c108fc 100644
45748--- a/drivers/video/uvesafb.c
45749+++ b/drivers/video/uvesafb.c
45750@@ -18,6 +18,7 @@
45751 #include <linux/fb.h>
45752 #include <linux/io.h>
45753 #include <linux/mutex.h>
45754+#include <linux/moduleloader.h>
45755 #include <video/edid.h>
45756 #include <video/uvesafb.h>
45757 #ifdef CONFIG_X86
45758@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
45759 NULL,
45760 };
45761
45762- return call_usermodehelper(v86d_path, argv, envp, 1);
45763+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
45764 }
45765
45766 /*
45767@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
45768 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
45769 par->pmi_setpal = par->ypan = 0;
45770 } else {
45771+
45772+#ifdef CONFIG_PAX_KERNEXEC
45773+#ifdef CONFIG_MODULES
45774+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
45775+#endif
45776+ if (!par->pmi_code) {
45777+ par->pmi_setpal = par->ypan = 0;
45778+ return 0;
45779+ }
45780+#endif
45781+
45782 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
45783 + task->t.regs.edi);
45784+
45785+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45786+ pax_open_kernel();
45787+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
45788+ pax_close_kernel();
45789+
45790+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
45791+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
45792+#else
45793 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
45794 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
45795+#endif
45796+
45797 printk(KERN_INFO "uvesafb: protected mode interface info at "
45798 "%04x:%04x\n",
45799 (u16)task->t.regs.es, (u16)task->t.regs.edi);
45800@@ -1799,6 +1822,11 @@ out:
45801 if (par->vbe_modes)
45802 kfree(par->vbe_modes);
45803
45804+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45805+ if (par->pmi_code)
45806+ module_free_exec(NULL, par->pmi_code);
45807+#endif
45808+
45809 framebuffer_release(info);
45810 return err;
45811 }
45812@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platform_device *dev)
45813 kfree(par->vbe_state_orig);
45814 if (par->vbe_state_saved)
45815 kfree(par->vbe_state_saved);
45816+
45817+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45818+ if (par->pmi_code)
45819+ module_free_exec(NULL, par->pmi_code);
45820+#endif
45821+
45822 }
45823
45824 framebuffer_release(info);
45825diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
45826index bd37ee1..cb827e8 100644
45827--- a/drivers/video/vesafb.c
45828+++ b/drivers/video/vesafb.c
45829@@ -9,6 +9,7 @@
45830 */
45831
45832 #include <linux/module.h>
45833+#include <linux/moduleloader.h>
45834 #include <linux/kernel.h>
45835 #include <linux/errno.h>
45836 #include <linux/string.h>
45837@@ -53,8 +54,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
45838 static int vram_total __initdata; /* Set total amount of memory */
45839 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
45840 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
45841-static void (*pmi_start)(void) __read_mostly;
45842-static void (*pmi_pal) (void) __read_mostly;
45843+static void (*pmi_start)(void) __read_only;
45844+static void (*pmi_pal) (void) __read_only;
45845 static int depth __read_mostly;
45846 static int vga_compat __read_mostly;
45847 /* --------------------------------------------------------------------- */
45848@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
45849 unsigned int size_vmode;
45850 unsigned int size_remap;
45851 unsigned int size_total;
45852+ void *pmi_code = NULL;
45853
45854 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45855 return -ENODEV;
45856@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45857 size_remap = size_total;
45858 vesafb_fix.smem_len = size_remap;
45859
45860-#ifndef __i386__
45861- screen_info.vesapm_seg = 0;
45862-#endif
45863-
45864 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45865 printk(KERN_WARNING
45866 "vesafb: cannot reserve video memory at 0x%lx\n",
45867@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45868 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45869 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45870
45871+#ifdef __i386__
45872+
45873+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45874+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45875+ if (!pmi_code)
45876+#elif !defined(CONFIG_PAX_KERNEXEC)
45877+ if (0)
45878+#endif
45879+
45880+#endif
45881+ screen_info.vesapm_seg = 0;
45882+
45883 if (screen_info.vesapm_seg) {
45884- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45885- screen_info.vesapm_seg,screen_info.vesapm_off);
45886+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45887+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45888 }
45889
45890 if (screen_info.vesapm_seg < 0xc000)
45891@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45892
45893 if (ypan || pmi_setpal) {
45894 unsigned short *pmi_base;
45895+
45896 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45897- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45898- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45899+
45900+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45901+ pax_open_kernel();
45902+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45903+#else
45904+ pmi_code = pmi_base;
45905+#endif
45906+
45907+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45908+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45909+
45910+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45911+ pmi_start = ktva_ktla(pmi_start);
45912+ pmi_pal = ktva_ktla(pmi_pal);
45913+ pax_close_kernel();
45914+#endif
45915+
45916 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45917 if (pmi_base[3]) {
45918 printk(KERN_INFO "vesafb: pmi: ports = ");
45919@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45920 info->node, info->fix.id);
45921 return 0;
45922 err:
45923+
45924+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45925+ module_free_exec(NULL, pmi_code);
45926+#endif
45927+
45928 if (info->screen_base)
45929 iounmap(info->screen_base);
45930 framebuffer_release(info);
45931diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c
45932index 88a60e0..6783cc2 100644
45933--- a/drivers/xen/sys-hypervisor.c
45934+++ b/drivers/xen/sys-hypervisor.c
45935@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct kobject *kobj,
45936 return 0;
45937 }
45938
45939-static struct sysfs_ops hyp_sysfs_ops = {
45940+static const struct sysfs_ops hyp_sysfs_ops = {
45941 .show = hyp_sysfs_show,
45942 .store = hyp_sysfs_store,
45943 };
45944diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45945index 18f74ec..3227009 100644
45946--- a/fs/9p/vfs_inode.c
45947+++ b/fs/9p/vfs_inode.c
45948@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45949 static void
45950 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45951 {
45952- char *s = nd_get_link(nd);
45953+ const char *s = nd_get_link(nd);
45954
45955 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
45956 IS_ERR(s) ? "<error>" : s);
45957diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45958index bb4cc5b..df5eaa0 100644
45959--- a/fs/Kconfig.binfmt
45960+++ b/fs/Kconfig.binfmt
45961@@ -86,7 +86,7 @@ config HAVE_AOUT
45962
45963 config BINFMT_AOUT
45964 tristate "Kernel support for a.out and ECOFF binaries"
45965- depends on HAVE_AOUT
45966+ depends on HAVE_AOUT && BROKEN
45967 ---help---
45968 A.out (Assembler.OUTput) is a set of formats for libraries and
45969 executables used in the earliest versions of UNIX. Linux used
45970diff --git a/fs/aio.c b/fs/aio.c
45971index 22a19ad..d484e5b 100644
45972--- a/fs/aio.c
45973+++ b/fs/aio.c
45974@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45975 size += sizeof(struct io_event) * nr_events;
45976 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45977
45978- if (nr_pages < 0)
45979+ if (nr_pages <= 0)
45980 return -EINVAL;
45981
45982 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45983@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ctx,
45984 struct aio_timeout to;
45985 int retry = 0;
45986
45987+ pax_track_stack();
45988+
45989 /* needed to zero any padding within an entry (there shouldn't be
45990 * any, but C is fun!
45991 */
45992@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45993 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
45994 {
45995 ssize_t ret;
45996+ struct iovec iovstack;
45997
45998 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
45999 kiocb->ki_nbytes, 1,
46000- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
46001+ &iovstack, &kiocb->ki_iovec);
46002 if (ret < 0)
46003 goto out;
46004
46005+ if (kiocb->ki_iovec == &iovstack) {
46006+ kiocb->ki_inline_vec = iovstack;
46007+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
46008+ }
46009 kiocb->ki_nr_segs = kiocb->ki_nbytes;
46010 kiocb->ki_cur_seg = 0;
46011 /* ki_nbytes/left now reflect bytes instead of segs */
46012diff --git a/fs/attr.c b/fs/attr.c
46013index 96d394b..33cf5b4 100644
46014--- a/fs/attr.c
46015+++ b/fs/attr.c
46016@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
46017 unsigned long limit;
46018
46019 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
46020+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
46021 if (limit != RLIM_INFINITY && offset > limit)
46022 goto out_sig;
46023 if (offset > inode->i_sb->s_maxbytes)
46024diff --git a/fs/autofs/root.c b/fs/autofs/root.c
46025index 4a1401c..05eb5ca 100644
46026--- a/fs/autofs/root.c
46027+++ b/fs/autofs/root.c
46028@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
46029 set_bit(n,sbi->symlink_bitmap);
46030 sl = &sbi->symlink[n];
46031 sl->len = strlen(symname);
46032- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
46033+ slsize = sl->len+1;
46034+ sl->data = kmalloc(slsize, GFP_KERNEL);
46035 if (!sl->data) {
46036 clear_bit(n,sbi->symlink_bitmap);
46037 unlock_kernel();
46038diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
46039index b4ea829..e63ef18 100644
46040--- a/fs/autofs4/symlink.c
46041+++ b/fs/autofs4/symlink.c
46042@@ -15,7 +15,7 @@
46043 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
46044 {
46045 struct autofs_info *ino = autofs4_dentry_ino(dentry);
46046- nd_set_link(nd, (char *)ino->u.symlink);
46047+ nd_set_link(nd, ino->u.symlink);
46048 return NULL;
46049 }
46050
46051diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
46052index 2341375..df9d1c2 100644
46053--- a/fs/autofs4/waitq.c
46054+++ b/fs/autofs4/waitq.c
46055@@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
46056 {
46057 unsigned long sigpipe, flags;
46058 mm_segment_t fs;
46059- const char *data = (const char *)addr;
46060+ const char __user *data = (const char __force_user *)addr;
46061 ssize_t wr = 0;
46062
46063 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
46064diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
46065index 9158c07..3f06659 100644
46066--- a/fs/befs/linuxvfs.c
46067+++ b/fs/befs/linuxvfs.c
46068@@ -498,7 +498,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46069 {
46070 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
46071 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
46072- char *link = nd_get_link(nd);
46073+ const char *link = nd_get_link(nd);
46074 if (!IS_ERR(link))
46075 kfree(link);
46076 }
46077diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
46078index 0133b5a..b3baa9f 100644
46079--- a/fs/binfmt_aout.c
46080+++ b/fs/binfmt_aout.c
46081@@ -16,6 +16,7 @@
46082 #include <linux/string.h>
46083 #include <linux/fs.h>
46084 #include <linux/file.h>
46085+#include <linux/security.h>
46086 #include <linux/stat.h>
46087 #include <linux/fcntl.h>
46088 #include <linux/ptrace.h>
46089@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46090 #endif
46091 # define START_STACK(u) (u.start_stack)
46092
46093+ memset(&dump, 0, sizeof(dump));
46094+
46095 fs = get_fs();
46096 set_fs(KERNEL_DS);
46097 has_dumped = 1;
46098@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46099
46100 /* If the size of the dump file exceeds the rlimit, then see what would happen
46101 if we wrote the stack, but not the data area. */
46102+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
46103 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
46104 dump.u_dsize = 0;
46105
46106 /* Make sure we have enough room to write the stack and data areas. */
46107+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
46108 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
46109 dump.u_ssize = 0;
46110
46111@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46112 dump_size = dump.u_ssize << PAGE_SHIFT;
46113 DUMP_WRITE(dump_start,dump_size);
46114 }
46115-/* Finally dump the task struct. Not be used by gdb, but could be useful */
46116- set_fs(KERNEL_DS);
46117- DUMP_WRITE(current,sizeof(*current));
46118+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
46119 end_coredump:
46120 set_fs(fs);
46121 return has_dumped;
46122@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46123 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
46124 if (rlim >= RLIM_INFINITY)
46125 rlim = ~0;
46126+
46127+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
46128 if (ex.a_data + ex.a_bss > rlim)
46129 return -ENOMEM;
46130
46131@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46132 install_exec_creds(bprm);
46133 current->flags &= ~PF_FORKNOEXEC;
46134
46135+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46136+ current->mm->pax_flags = 0UL;
46137+#endif
46138+
46139+#ifdef CONFIG_PAX_PAGEEXEC
46140+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
46141+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
46142+
46143+#ifdef CONFIG_PAX_EMUTRAMP
46144+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
46145+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
46146+#endif
46147+
46148+#ifdef CONFIG_PAX_MPROTECT
46149+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
46150+ current->mm->pax_flags |= MF_PAX_MPROTECT;
46151+#endif
46152+
46153+ }
46154+#endif
46155+
46156 if (N_MAGIC(ex) == OMAGIC) {
46157 unsigned long text_addr, map_size;
46158 loff_t pos;
46159@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46160
46161 down_write(&current->mm->mmap_sem);
46162 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
46163- PROT_READ | PROT_WRITE | PROT_EXEC,
46164+ PROT_READ | PROT_WRITE,
46165 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
46166 fd_offset + ex.a_text);
46167 up_write(&current->mm->mmap_sem);
46168diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
46169index 1ed37ba..32cc555 100644
46170--- a/fs/binfmt_elf.c
46171+++ b/fs/binfmt_elf.c
46172@@ -50,6 +50,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46173 #define elf_core_dump NULL
46174 #endif
46175
46176+#ifdef CONFIG_PAX_MPROTECT
46177+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
46178+#endif
46179+
46180 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
46181 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
46182 #else
46183@@ -69,6 +73,11 @@ static struct linux_binfmt elf_format = {
46184 .load_binary = load_elf_binary,
46185 .load_shlib = load_elf_library,
46186 .core_dump = elf_core_dump,
46187+
46188+#ifdef CONFIG_PAX_MPROTECT
46189+ .handle_mprotect= elf_handle_mprotect,
46190+#endif
46191+
46192 .min_coredump = ELF_EXEC_PAGESIZE,
46193 .hasvdso = 1
46194 };
46195@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format = {
46196
46197 static int set_brk(unsigned long start, unsigned long end)
46198 {
46199+ unsigned long e = end;
46200+
46201 start = ELF_PAGEALIGN(start);
46202 end = ELF_PAGEALIGN(end);
46203 if (end > start) {
46204@@ -87,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
46205 if (BAD_ADDR(addr))
46206 return addr;
46207 }
46208- current->mm->start_brk = current->mm->brk = end;
46209+ current->mm->start_brk = current->mm->brk = e;
46210 return 0;
46211 }
46212
46213@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46214 elf_addr_t __user *u_rand_bytes;
46215 const char *k_platform = ELF_PLATFORM;
46216 const char *k_base_platform = ELF_BASE_PLATFORM;
46217- unsigned char k_rand_bytes[16];
46218+ u32 k_rand_bytes[4];
46219 int items;
46220 elf_addr_t *elf_info;
46221 int ei_index = 0;
46222 const struct cred *cred = current_cred();
46223 struct vm_area_struct *vma;
46224+ unsigned long saved_auxv[AT_VECTOR_SIZE];
46225+
46226+ pax_track_stack();
46227
46228 /*
46229 * In some cases (e.g. Hyper-Threading), we want to avoid L1
46230@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46231 * Generate 16 random bytes for userspace PRNG seeding.
46232 */
46233 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
46234- u_rand_bytes = (elf_addr_t __user *)
46235- STACK_ALLOC(p, sizeof(k_rand_bytes));
46236+ srandom32(k_rand_bytes[0] ^ random32());
46237+ srandom32(k_rand_bytes[1] ^ random32());
46238+ srandom32(k_rand_bytes[2] ^ random32());
46239+ srandom32(k_rand_bytes[3] ^ random32());
46240+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
46241+ u_rand_bytes = (elf_addr_t __user *) p;
46242 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
46243 return -EFAULT;
46244
46245@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46246 return -EFAULT;
46247 current->mm->env_end = p;
46248
46249+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
46250+
46251 /* Put the elf_info on the stack in the right place. */
46252 sp = (elf_addr_t __user *)envp + 1;
46253- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
46254+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
46255 return -EFAULT;
46256 return 0;
46257 }
46258@@ -385,10 +405,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46259 {
46260 struct elf_phdr *elf_phdata;
46261 struct elf_phdr *eppnt;
46262- unsigned long load_addr = 0;
46263+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
46264 int load_addr_set = 0;
46265 unsigned long last_bss = 0, elf_bss = 0;
46266- unsigned long error = ~0UL;
46267+ unsigned long error = -EINVAL;
46268 unsigned long total_size;
46269 int retval, i, size;
46270
46271@@ -434,6 +454,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46272 goto out_close;
46273 }
46274
46275+#ifdef CONFIG_PAX_SEGMEXEC
46276+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
46277+ pax_task_size = SEGMEXEC_TASK_SIZE;
46278+#endif
46279+
46280 eppnt = elf_phdata;
46281 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
46282 if (eppnt->p_type == PT_LOAD) {
46283@@ -477,8 +502,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46284 k = load_addr + eppnt->p_vaddr;
46285 if (BAD_ADDR(k) ||
46286 eppnt->p_filesz > eppnt->p_memsz ||
46287- eppnt->p_memsz > TASK_SIZE ||
46288- TASK_SIZE - eppnt->p_memsz < k) {
46289+ eppnt->p_memsz > pax_task_size ||
46290+ pax_task_size - eppnt->p_memsz < k) {
46291 error = -ENOMEM;
46292 goto out_close;
46293 }
46294@@ -532,6 +557,194 @@ out:
46295 return error;
46296 }
46297
46298+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
46299+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
46300+{
46301+ unsigned long pax_flags = 0UL;
46302+
46303+#ifdef CONFIG_PAX_PAGEEXEC
46304+ if (elf_phdata->p_flags & PF_PAGEEXEC)
46305+ pax_flags |= MF_PAX_PAGEEXEC;
46306+#endif
46307+
46308+#ifdef CONFIG_PAX_SEGMEXEC
46309+ if (elf_phdata->p_flags & PF_SEGMEXEC)
46310+ pax_flags |= MF_PAX_SEGMEXEC;
46311+#endif
46312+
46313+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46314+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46315+ if (nx_enabled)
46316+ pax_flags &= ~MF_PAX_SEGMEXEC;
46317+ else
46318+ pax_flags &= ~MF_PAX_PAGEEXEC;
46319+ }
46320+#endif
46321+
46322+#ifdef CONFIG_PAX_EMUTRAMP
46323+ if (elf_phdata->p_flags & PF_EMUTRAMP)
46324+ pax_flags |= MF_PAX_EMUTRAMP;
46325+#endif
46326+
46327+#ifdef CONFIG_PAX_MPROTECT
46328+ if (elf_phdata->p_flags & PF_MPROTECT)
46329+ pax_flags |= MF_PAX_MPROTECT;
46330+#endif
46331+
46332+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46333+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
46334+ pax_flags |= MF_PAX_RANDMMAP;
46335+#endif
46336+
46337+ return pax_flags;
46338+}
46339+#endif
46340+
46341+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46342+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
46343+{
46344+ unsigned long pax_flags = 0UL;
46345+
46346+#ifdef CONFIG_PAX_PAGEEXEC
46347+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
46348+ pax_flags |= MF_PAX_PAGEEXEC;
46349+#endif
46350+
46351+#ifdef CONFIG_PAX_SEGMEXEC
46352+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
46353+ pax_flags |= MF_PAX_SEGMEXEC;
46354+#endif
46355+
46356+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46357+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46358+ if (nx_enabled)
46359+ pax_flags &= ~MF_PAX_SEGMEXEC;
46360+ else
46361+ pax_flags &= ~MF_PAX_PAGEEXEC;
46362+ }
46363+#endif
46364+
46365+#ifdef CONFIG_PAX_EMUTRAMP
46366+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
46367+ pax_flags |= MF_PAX_EMUTRAMP;
46368+#endif
46369+
46370+#ifdef CONFIG_PAX_MPROTECT
46371+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
46372+ pax_flags |= MF_PAX_MPROTECT;
46373+#endif
46374+
46375+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46376+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
46377+ pax_flags |= MF_PAX_RANDMMAP;
46378+#endif
46379+
46380+ return pax_flags;
46381+}
46382+#endif
46383+
46384+#ifdef CONFIG_PAX_EI_PAX
46385+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
46386+{
46387+ unsigned long pax_flags = 0UL;
46388+
46389+#ifdef CONFIG_PAX_PAGEEXEC
46390+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
46391+ pax_flags |= MF_PAX_PAGEEXEC;
46392+#endif
46393+
46394+#ifdef CONFIG_PAX_SEGMEXEC
46395+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
46396+ pax_flags |= MF_PAX_SEGMEXEC;
46397+#endif
46398+
46399+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46400+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46401+ if (nx_enabled)
46402+ pax_flags &= ~MF_PAX_SEGMEXEC;
46403+ else
46404+ pax_flags &= ~MF_PAX_PAGEEXEC;
46405+ }
46406+#endif
46407+
46408+#ifdef CONFIG_PAX_EMUTRAMP
46409+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
46410+ pax_flags |= MF_PAX_EMUTRAMP;
46411+#endif
46412+
46413+#ifdef CONFIG_PAX_MPROTECT
46414+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
46415+ pax_flags |= MF_PAX_MPROTECT;
46416+#endif
46417+
46418+#ifdef CONFIG_PAX_ASLR
46419+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
46420+ pax_flags |= MF_PAX_RANDMMAP;
46421+#endif
46422+
46423+ return pax_flags;
46424+}
46425+#endif
46426+
46427+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
46428+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
46429+{
46430+ unsigned long pax_flags = 0UL;
46431+
46432+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46433+ unsigned long i;
46434+ int found_flags = 0;
46435+#endif
46436+
46437+#ifdef CONFIG_PAX_EI_PAX
46438+ pax_flags = pax_parse_ei_pax(elf_ex);
46439+#endif
46440+
46441+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46442+ for (i = 0UL; i < elf_ex->e_phnum; i++)
46443+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
46444+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
46445+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
46446+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
46447+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
46448+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
46449+ return -EINVAL;
46450+
46451+#ifdef CONFIG_PAX_SOFTMODE
46452+ if (pax_softmode)
46453+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
46454+ else
46455+#endif
46456+
46457+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
46458+ found_flags = 1;
46459+ break;
46460+ }
46461+#endif
46462+
46463+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
46464+ if (found_flags == 0) {
46465+ struct elf_phdr phdr;
46466+ memset(&phdr, 0, sizeof(phdr));
46467+ phdr.p_flags = PF_NOEMUTRAMP;
46468+#ifdef CONFIG_PAX_SOFTMODE
46469+ if (pax_softmode)
46470+ pax_flags = pax_parse_softmode(&phdr);
46471+ else
46472+#endif
46473+ pax_flags = pax_parse_hardmode(&phdr);
46474+ }
46475+#endif
46476+
46477+
46478+ if (0 > pax_check_flags(&pax_flags))
46479+ return -EINVAL;
46480+
46481+ current->mm->pax_flags = pax_flags;
46482+ return 0;
46483+}
46484+#endif
46485+
46486 /*
46487 * These are the functions used to load ELF style executables and shared
46488 * libraries. There is no binary dependent code anywhere else.
46489@@ -548,6 +761,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
46490 {
46491 unsigned int random_variable = 0;
46492
46493+#ifdef CONFIG_PAX_RANDUSTACK
46494+ if (randomize_va_space)
46495+ return stack_top - current->mm->delta_stack;
46496+#endif
46497+
46498 if ((current->flags & PF_RANDOMIZE) &&
46499 !(current->personality & ADDR_NO_RANDOMIZE)) {
46500 random_variable = get_random_int() & STACK_RND_MASK;
46501@@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46502 unsigned long load_addr = 0, load_bias = 0;
46503 int load_addr_set = 0;
46504 char * elf_interpreter = NULL;
46505- unsigned long error;
46506+ unsigned long error = 0;
46507 struct elf_phdr *elf_ppnt, *elf_phdata;
46508 unsigned long elf_bss, elf_brk;
46509 int retval, i;
46510@@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46511 unsigned long start_code, end_code, start_data, end_data;
46512 unsigned long reloc_func_desc = 0;
46513 int executable_stack = EXSTACK_DEFAULT;
46514- unsigned long def_flags = 0;
46515 struct {
46516 struct elfhdr elf_ex;
46517 struct elfhdr interp_elf_ex;
46518 } *loc;
46519+ unsigned long pax_task_size = TASK_SIZE;
46520
46521 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
46522 if (!loc) {
46523@@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46524
46525 /* OK, This is the point of no return */
46526 current->flags &= ~PF_FORKNOEXEC;
46527- current->mm->def_flags = def_flags;
46528+
46529+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46530+ current->mm->pax_flags = 0UL;
46531+#endif
46532+
46533+#ifdef CONFIG_PAX_DLRESOLVE
46534+ current->mm->call_dl_resolve = 0UL;
46535+#endif
46536+
46537+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46538+ current->mm->call_syscall = 0UL;
46539+#endif
46540+
46541+#ifdef CONFIG_PAX_ASLR
46542+ current->mm->delta_mmap = 0UL;
46543+ current->mm->delta_stack = 0UL;
46544+#endif
46545+
46546+ current->mm->def_flags = 0;
46547+
46548+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
46549+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
46550+ send_sig(SIGKILL, current, 0);
46551+ goto out_free_dentry;
46552+ }
46553+#endif
46554+
46555+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46556+ pax_set_initial_flags(bprm);
46557+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
46558+ if (pax_set_initial_flags_func)
46559+ (pax_set_initial_flags_func)(bprm);
46560+#endif
46561+
46562+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46563+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
46564+ current->mm->context.user_cs_limit = PAGE_SIZE;
46565+ current->mm->def_flags |= VM_PAGEEXEC;
46566+ }
46567+#endif
46568+
46569+#ifdef CONFIG_PAX_SEGMEXEC
46570+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
46571+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
46572+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
46573+ pax_task_size = SEGMEXEC_TASK_SIZE;
46574+ }
46575+#endif
46576+
46577+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
46578+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46579+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
46580+ put_cpu();
46581+ }
46582+#endif
46583
46584 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
46585 may depend on the personality. */
46586 SET_PERSONALITY(loc->elf_ex);
46587+
46588+#ifdef CONFIG_PAX_ASLR
46589+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
46590+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
46591+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
46592+ }
46593+#endif
46594+
46595+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46596+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46597+ executable_stack = EXSTACK_DISABLE_X;
46598+ current->personality &= ~READ_IMPLIES_EXEC;
46599+ } else
46600+#endif
46601+
46602 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
46603 current->personality |= READ_IMPLIES_EXEC;
46604
46605@@ -800,10 +1087,27 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46606 * might try to exec. This is because the brk will
46607 * follow the loader, and is not movable. */
46608 #ifdef CONFIG_X86
46609- load_bias = 0;
46610+ if (current->flags & PF_RANDOMIZE)
46611+ load_bias = 0;
46612+ else
46613+ load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46614 #else
46615 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46616 #endif
46617+
46618+#ifdef CONFIG_PAX_RANDMMAP
46619+ /* PaX: randomize base address at the default exe base if requested */
46620+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
46621+#ifdef CONFIG_SPARC64
46622+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
46623+#else
46624+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
46625+#endif
46626+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
46627+ elf_flags |= MAP_FIXED;
46628+ }
46629+#endif
46630+
46631 }
46632
46633 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
46634@@ -836,9 +1140,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46635 * allowed task size. Note that p_filesz must always be
46636 * <= p_memsz so it is only necessary to check p_memsz.
46637 */
46638- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46639- elf_ppnt->p_memsz > TASK_SIZE ||
46640- TASK_SIZE - elf_ppnt->p_memsz < k) {
46641+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46642+ elf_ppnt->p_memsz > pax_task_size ||
46643+ pax_task_size - elf_ppnt->p_memsz < k) {
46644 /* set_brk can never work. Avoid overflows. */
46645 send_sig(SIGKILL, current, 0);
46646 retval = -EINVAL;
46647@@ -866,6 +1170,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46648 start_data += load_bias;
46649 end_data += load_bias;
46650
46651+#ifdef CONFIG_PAX_RANDMMAP
46652+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
46653+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
46654+#endif
46655+
46656 /* Calling set_brk effectively mmaps the pages that we need
46657 * for the bss and break sections. We must do this before
46658 * mapping in the interpreter, to make sure it doesn't wind
46659@@ -877,9 +1186,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46660 goto out_free_dentry;
46661 }
46662 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
46663- send_sig(SIGSEGV, current, 0);
46664- retval = -EFAULT; /* Nobody gets to see this, but.. */
46665- goto out_free_dentry;
46666+ /*
46667+ * This bss-zeroing can fail if the ELF
46668+ * file specifies odd protections. So
46669+ * we don't check the return value
46670+ */
46671 }
46672
46673 if (elf_interpreter) {
46674@@ -1112,8 +1423,10 @@ static int dump_seek(struct file *file, loff_t off)
46675 unsigned long n = off;
46676 if (n > PAGE_SIZE)
46677 n = PAGE_SIZE;
46678- if (!dump_write(file, buf, n))
46679+ if (!dump_write(file, buf, n)) {
46680+ free_page((unsigned long)buf);
46681 return 0;
46682+ }
46683 off -= n;
46684 }
46685 free_page((unsigned long)buf);
46686@@ -1125,7 +1438,7 @@ static int dump_seek(struct file *file, loff_t off)
46687 * Decide what to dump of a segment, part, all or none.
46688 */
46689 static unsigned long vma_dump_size(struct vm_area_struct *vma,
46690- unsigned long mm_flags)
46691+ unsigned long mm_flags, long signr)
46692 {
46693 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
46694
46695@@ -1159,7 +1472,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
46696 if (vma->vm_file == NULL)
46697 return 0;
46698
46699- if (FILTER(MAPPED_PRIVATE))
46700+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46701 goto whole;
46702
46703 /*
46704@@ -1255,8 +1568,11 @@ static int writenote(struct memelfnote *men, struct file *file,
46705 #undef DUMP_WRITE
46706
46707 #define DUMP_WRITE(addr, nr) \
46708+ do { \
46709+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
46710 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
46711- goto end_coredump;
46712+ goto end_coredump; \
46713+ } while (0);
46714
46715 static void fill_elf_header(struct elfhdr *elf, int segs,
46716 u16 machine, u32 flags, u8 osabi)
46717@@ -1385,9 +1701,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46718 {
46719 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46720 int i = 0;
46721- do
46722+ do {
46723 i += 2;
46724- while (auxv[i - 2] != AT_NULL);
46725+ } while (auxv[i - 2] != AT_NULL);
46726 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46727 }
46728
46729@@ -1973,7 +2289,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46730 phdr.p_offset = offset;
46731 phdr.p_vaddr = vma->vm_start;
46732 phdr.p_paddr = 0;
46733- phdr.p_filesz = vma_dump_size(vma, mm_flags);
46734+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
46735 phdr.p_memsz = vma->vm_end - vma->vm_start;
46736 offset += phdr.p_filesz;
46737 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46738@@ -2006,7 +2322,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46739 unsigned long addr;
46740 unsigned long end;
46741
46742- end = vma->vm_start + vma_dump_size(vma, mm_flags);
46743+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
46744
46745 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46746 struct page *page;
46747@@ -2015,6 +2331,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46748 page = get_dump_page(addr);
46749 if (page) {
46750 void *kaddr = kmap(page);
46751+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46752 stop = ((size += PAGE_SIZE) > limit) ||
46753 !dump_write(file, kaddr, PAGE_SIZE);
46754 kunmap(page);
46755@@ -2042,6 +2359,97 @@ out:
46756
46757 #endif /* USE_ELF_CORE_DUMP */
46758
46759+#ifdef CONFIG_PAX_MPROTECT
46760+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46761+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46762+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46763+ *
46764+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46765+ * basis because we want to allow the common case and not the special ones.
46766+ */
46767+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46768+{
46769+ struct elfhdr elf_h;
46770+ struct elf_phdr elf_p;
46771+ unsigned long i;
46772+ unsigned long oldflags;
46773+ bool is_textrel_rw, is_textrel_rx, is_relro;
46774+
46775+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46776+ return;
46777+
46778+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46779+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46780+
46781+#ifdef CONFIG_PAX_ELFRELOCS
46782+ /* possible TEXTREL */
46783+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46784+ 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);
46785+#else
46786+ is_textrel_rw = false;
46787+ is_textrel_rx = false;
46788+#endif
46789+
46790+ /* possible RELRO */
46791+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46792+
46793+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46794+ return;
46795+
46796+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46797+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46798+
46799+#ifdef CONFIG_PAX_ETEXECRELOCS
46800+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46801+#else
46802+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46803+#endif
46804+
46805+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46806+ !elf_check_arch(&elf_h) ||
46807+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46808+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46809+ return;
46810+
46811+ for (i = 0UL; i < elf_h.e_phnum; i++) {
46812+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46813+ return;
46814+ switch (elf_p.p_type) {
46815+ case PT_DYNAMIC:
46816+ if (!is_textrel_rw && !is_textrel_rx)
46817+ continue;
46818+ i = 0UL;
46819+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46820+ elf_dyn dyn;
46821+
46822+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46823+ return;
46824+ if (dyn.d_tag == DT_NULL)
46825+ return;
46826+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46827+ gr_log_textrel(vma);
46828+ if (is_textrel_rw)
46829+ vma->vm_flags |= VM_MAYWRITE;
46830+ else
46831+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46832+ vma->vm_flags &= ~VM_MAYWRITE;
46833+ return;
46834+ }
46835+ i++;
46836+ }
46837+ return;
46838+
46839+ case PT_GNU_RELRO:
46840+ if (!is_relro)
46841+ continue;
46842+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46843+ vma->vm_flags &= ~VM_MAYWRITE;
46844+ return;
46845+ }
46846+ }
46847+}
46848+#endif
46849+
46850 static int __init init_elf_binfmt(void)
46851 {
46852 return register_binfmt(&elf_format);
46853diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46854index ca88c46..f155a60 100644
46855--- a/fs/binfmt_flat.c
46856+++ b/fs/binfmt_flat.c
46857@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46858 realdatastart = (unsigned long) -ENOMEM;
46859 printk("Unable to allocate RAM for process data, errno %d\n",
46860 (int)-realdatastart);
46861+ down_write(&current->mm->mmap_sem);
46862 do_munmap(current->mm, textpos, text_len);
46863+ up_write(&current->mm->mmap_sem);
46864 ret = realdatastart;
46865 goto err;
46866 }
46867@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46868 }
46869 if (IS_ERR_VALUE(result)) {
46870 printk("Unable to read data+bss, errno %d\n", (int)-result);
46871+ down_write(&current->mm->mmap_sem);
46872 do_munmap(current->mm, textpos, text_len);
46873 do_munmap(current->mm, realdatastart, data_len + extra);
46874+ up_write(&current->mm->mmap_sem);
46875 ret = result;
46876 goto err;
46877 }
46878@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46879 }
46880 if (IS_ERR_VALUE(result)) {
46881 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46882+ down_write(&current->mm->mmap_sem);
46883 do_munmap(current->mm, textpos, text_len + data_len + extra +
46884 MAX_SHARED_LIBS * sizeof(unsigned long));
46885+ up_write(&current->mm->mmap_sem);
46886 ret = result;
46887 goto err;
46888 }
46889diff --git a/fs/bio.c b/fs/bio.c
46890index e696713..83de133 100644
46891--- a/fs/bio.c
46892+++ b/fs/bio.c
46893@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
46894
46895 i = 0;
46896 while (i < bio_slab_nr) {
46897- struct bio_slab *bslab = &bio_slabs[i];
46898+ bslab = &bio_slabs[i];
46899
46900 if (!bslab->slab && entry == -1)
46901 entry = i;
46902@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46903 const int read = bio_data_dir(bio) == READ;
46904 struct bio_map_data *bmd = bio->bi_private;
46905 int i;
46906- char *p = bmd->sgvecs[0].iov_base;
46907+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46908
46909 __bio_for_each_segment(bvec, bio, i, 0) {
46910 char *addr = page_address(bvec->bv_page);
46911diff --git a/fs/block_dev.c b/fs/block_dev.c
46912index e65efa2..04fae57 100644
46913--- a/fs/block_dev.c
46914+++ b/fs/block_dev.c
46915@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev, void *holder)
46916 else if (bdev->bd_contains == bdev)
46917 res = 0; /* is a whole device which isn't held */
46918
46919- else if (bdev->bd_contains->bd_holder == bd_claim)
46920+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
46921 res = 0; /* is a partition of a device that is being partitioned */
46922 else if (bdev->bd_contains->bd_holder != NULL)
46923 res = -EBUSY; /* is a partition of a held device */
46924diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46925index c4bc570..42acd8d 100644
46926--- a/fs/btrfs/ctree.c
46927+++ b/fs/btrfs/ctree.c
46928@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46929 free_extent_buffer(buf);
46930 add_root_to_dirty_list(root);
46931 } else {
46932- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46933- parent_start = parent->start;
46934- else
46935+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46936+ if (parent)
46937+ parent_start = parent->start;
46938+ else
46939+ parent_start = 0;
46940+ } else
46941 parent_start = 0;
46942
46943 WARN_ON(trans->transid != btrfs_header_generation(parent));
46944@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_trans_handle *trans,
46945
46946 ret = 0;
46947 if (slot == 0) {
46948- struct btrfs_disk_key disk_key;
46949 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
46950 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
46951 }
46952diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
46953index f447188..59c17c5 100644
46954--- a/fs/btrfs/disk-io.c
46955+++ b/fs/btrfs/disk-io.c
46956@@ -39,7 +39,7 @@
46957 #include "tree-log.h"
46958 #include "free-space-cache.h"
46959
46960-static struct extent_io_ops btree_extent_io_ops;
46961+static const struct extent_io_ops btree_extent_io_ops;
46962 static void end_workqueue_fn(struct btrfs_work *work);
46963 static void free_fs_root(struct btrfs_root *root);
46964
46965@@ -2607,7 +2607,7 @@ out:
46966 return 0;
46967 }
46968
46969-static struct extent_io_ops btree_extent_io_ops = {
46970+static const struct extent_io_ops btree_extent_io_ops = {
46971 .write_cache_pages_lock_hook = btree_lock_page_hook,
46972 .readpage_end_io_hook = btree_readpage_end_io_hook,
46973 .submit_bio_hook = btree_submit_bio_hook,
46974diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
46975index 559f724..a026171 100644
46976--- a/fs/btrfs/extent-tree.c
46977+++ b/fs/btrfs/extent-tree.c
46978@@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,
46979 u64 group_start = group->key.objectid;
46980 new_extents = kmalloc(sizeof(*new_extents),
46981 GFP_NOFS);
46982+ if (!new_extents) {
46983+ ret = -ENOMEM;
46984+ goto out;
46985+ }
46986 nr_extents = 1;
46987 ret = get_new_locations(reloc_inode,
46988 extent_key,
46989diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
46990index 36de250..7ec75c7 100644
46991--- a/fs/btrfs/extent_io.h
46992+++ b/fs/btrfs/extent_io.h
46993@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
46994 struct bio *bio, int mirror_num,
46995 unsigned long bio_flags);
46996 struct extent_io_ops {
46997- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
46998+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
46999 u64 start, u64 end, int *page_started,
47000 unsigned long *nr_written);
47001- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
47002- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
47003+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
47004+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
47005 extent_submit_bio_hook_t *submit_bio_hook;
47006- int (*merge_bio_hook)(struct page *page, unsigned long offset,
47007+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
47008 size_t size, struct bio *bio,
47009 unsigned long bio_flags);
47010- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
47011- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47012+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
47013+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
47014 u64 start, u64 end,
47015 struct extent_state *state);
47016- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
47017+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
47018 u64 start, u64 end,
47019 struct extent_state *state);
47020- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47021+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47022 struct extent_state *state);
47023- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47024+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47025 struct extent_state *state, int uptodate);
47026- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
47027+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
47028 unsigned long old, unsigned long bits);
47029- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
47030+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
47031 unsigned long bits);
47032- int (*merge_extent_hook)(struct inode *inode,
47033+ int (* const merge_extent_hook)(struct inode *inode,
47034 struct extent_state *new,
47035 struct extent_state *other);
47036- int (*split_extent_hook)(struct inode *inode,
47037+ int (* const split_extent_hook)(struct inode *inode,
47038 struct extent_state *orig, u64 split);
47039- int (*write_cache_pages_lock_hook)(struct page *page);
47040+ int (* const write_cache_pages_lock_hook)(struct page *page);
47041 };
47042
47043 struct extent_io_tree {
47044@@ -88,7 +88,7 @@ struct extent_io_tree {
47045 u64 dirty_bytes;
47046 spinlock_t lock;
47047 spinlock_t buffer_lock;
47048- struct extent_io_ops *ops;
47049+ const struct extent_io_ops *ops;
47050 };
47051
47052 struct extent_state {
47053diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
47054index cb2849f..3718fb4 100644
47055--- a/fs/btrfs/free-space-cache.c
47056+++ b/fs/btrfs/free-space-cache.c
47057@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
47058
47059 while(1) {
47060 if (entry->bytes < bytes || entry->offset < min_start) {
47061- struct rb_node *node;
47062-
47063 node = rb_next(&entry->offset_index);
47064 if (!node)
47065 break;
47066@@ -1226,7 +1224,7 @@ again:
47067 */
47068 while (entry->bitmap || found_bitmap ||
47069 (!entry->bitmap && entry->bytes < min_bytes)) {
47070- struct rb_node *node = rb_next(&entry->offset_index);
47071+ node = rb_next(&entry->offset_index);
47072
47073 if (entry->bitmap && entry->bytes > bytes + empty_size) {
47074 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
47075diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
47076index e03a836..323837e 100644
47077--- a/fs/btrfs/inode.c
47078+++ b/fs/btrfs/inode.c
47079@@ -63,7 +63,7 @@ static const struct inode_operations btrfs_file_inode_operations;
47080 static const struct address_space_operations btrfs_aops;
47081 static const struct address_space_operations btrfs_symlink_aops;
47082 static const struct file_operations btrfs_dir_file_operations;
47083-static struct extent_io_ops btrfs_extent_io_ops;
47084+static const struct extent_io_ops btrfs_extent_io_ops;
47085
47086 static struct kmem_cache *btrfs_inode_cachep;
47087 struct kmem_cache *btrfs_trans_handle_cachep;
47088@@ -925,6 +925,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
47089 1, 0, NULL, GFP_NOFS);
47090 while (start < end) {
47091 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
47092+ BUG_ON(!async_cow);
47093 async_cow->inode = inode;
47094 async_cow->root = root;
47095 async_cow->locked_page = locked_page;
47096@@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(struct btrfs_path *path,
47097 inline_size = btrfs_file_extent_inline_item_len(leaf,
47098 btrfs_item_nr(leaf, path->slots[0]));
47099 tmp = kmalloc(inline_size, GFP_NOFS);
47100+ if (!tmp)
47101+ return -ENOMEM;
47102 ptr = btrfs_file_extent_inline_start(item);
47103
47104 read_extent_buffer(leaf, tmp, ptr, inline_size);
47105@@ -5410,7 +5413,7 @@ fail:
47106 return -ENOMEM;
47107 }
47108
47109-static int btrfs_getattr(struct vfsmount *mnt,
47110+int btrfs_getattr(struct vfsmount *mnt,
47111 struct dentry *dentry, struct kstat *stat)
47112 {
47113 struct inode *inode = dentry->d_inode;
47114@@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
47115 return 0;
47116 }
47117
47118+EXPORT_SYMBOL(btrfs_getattr);
47119+
47120+dev_t get_btrfs_dev_from_inode(struct inode *inode)
47121+{
47122+ return BTRFS_I(inode)->root->anon_super.s_dev;
47123+}
47124+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
47125+
47126 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
47127 struct inode *new_dir, struct dentry *new_dentry)
47128 {
47129@@ -5972,7 +5983,7 @@ static const struct file_operations btrfs_dir_file_operations = {
47130 .fsync = btrfs_sync_file,
47131 };
47132
47133-static struct extent_io_ops btrfs_extent_io_ops = {
47134+static const struct extent_io_ops btrfs_extent_io_ops = {
47135 .fill_delalloc = run_delalloc_range,
47136 .submit_bio_hook = btrfs_submit_bio_hook,
47137 .merge_bio_hook = btrfs_merge_bio_hook,
47138diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
47139index ab7ab53..94e0781 100644
47140--- a/fs/btrfs/relocation.c
47141+++ b/fs/btrfs/relocation.c
47142@@ -884,7 +884,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
47143 }
47144 spin_unlock(&rc->reloc_root_tree.lock);
47145
47146- BUG_ON((struct btrfs_root *)node->data != root);
47147+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
47148
47149 if (!del) {
47150 spin_lock(&rc->reloc_root_tree.lock);
47151diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
47152index a240b6f..4ce16ef 100644
47153--- a/fs/btrfs/sysfs.c
47154+++ b/fs/btrfs/sysfs.c
47155@@ -164,12 +164,12 @@ static void btrfs_root_release(struct kobject *kobj)
47156 complete(&root->kobj_unregister);
47157 }
47158
47159-static struct sysfs_ops btrfs_super_attr_ops = {
47160+static const struct sysfs_ops btrfs_super_attr_ops = {
47161 .show = btrfs_super_attr_show,
47162 .store = btrfs_super_attr_store,
47163 };
47164
47165-static struct sysfs_ops btrfs_root_attr_ops = {
47166+static const struct sysfs_ops btrfs_root_attr_ops = {
47167 .show = btrfs_root_attr_show,
47168 .store = btrfs_root_attr_store,
47169 };
47170diff --git a/fs/buffer.c b/fs/buffer.c
47171index 6fa5302..395d9f6 100644
47172--- a/fs/buffer.c
47173+++ b/fs/buffer.c
47174@@ -25,6 +25,7 @@
47175 #include <linux/percpu.h>
47176 #include <linux/slab.h>
47177 #include <linux/capability.h>
47178+#include <linux/security.h>
47179 #include <linux/blkdev.h>
47180 #include <linux/file.h>
47181 #include <linux/quotaops.h>
47182diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
47183index 3797e00..ce776f6 100644
47184--- a/fs/cachefiles/bind.c
47185+++ b/fs/cachefiles/bind.c
47186@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
47187 args);
47188
47189 /* start by checking things over */
47190- ASSERT(cache->fstop_percent >= 0 &&
47191- cache->fstop_percent < cache->fcull_percent &&
47192+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
47193 cache->fcull_percent < cache->frun_percent &&
47194 cache->frun_percent < 100);
47195
47196- ASSERT(cache->bstop_percent >= 0 &&
47197- cache->bstop_percent < cache->bcull_percent &&
47198+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
47199 cache->bcull_percent < cache->brun_percent &&
47200 cache->brun_percent < 100);
47201
47202diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
47203index 4618516..bb30d01 100644
47204--- a/fs/cachefiles/daemon.c
47205+++ b/fs/cachefiles/daemon.c
47206@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
47207 if (test_bit(CACHEFILES_DEAD, &cache->flags))
47208 return -EIO;
47209
47210- if (datalen < 0 || datalen > PAGE_SIZE - 1)
47211+ if (datalen > PAGE_SIZE - 1)
47212 return -EOPNOTSUPP;
47213
47214 /* drag the command string into the kernel so we can parse it */
47215@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
47216 if (args[0] != '%' || args[1] != '\0')
47217 return -EINVAL;
47218
47219- if (fstop < 0 || fstop >= cache->fcull_percent)
47220+ if (fstop >= cache->fcull_percent)
47221 return cachefiles_daemon_range_error(cache, args);
47222
47223 cache->fstop_percent = fstop;
47224@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
47225 if (args[0] != '%' || args[1] != '\0')
47226 return -EINVAL;
47227
47228- if (bstop < 0 || bstop >= cache->bcull_percent)
47229+ if (bstop >= cache->bcull_percent)
47230 return cachefiles_daemon_range_error(cache, args);
47231
47232 cache->bstop_percent = bstop;
47233diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
47234index f7c255f..fcd61de 100644
47235--- a/fs/cachefiles/internal.h
47236+++ b/fs/cachefiles/internal.h
47237@@ -56,7 +56,7 @@ struct cachefiles_cache {
47238 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
47239 struct rb_root active_nodes; /* active nodes (can't be culled) */
47240 rwlock_t active_lock; /* lock for active_nodes */
47241- atomic_t gravecounter; /* graveyard uniquifier */
47242+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
47243 unsigned frun_percent; /* when to stop culling (% files) */
47244 unsigned fcull_percent; /* when to start culling (% files) */
47245 unsigned fstop_percent; /* when to stop allocating (% files) */
47246@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
47247 * proc.c
47248 */
47249 #ifdef CONFIG_CACHEFILES_HISTOGRAM
47250-extern atomic_t cachefiles_lookup_histogram[HZ];
47251-extern atomic_t cachefiles_mkdir_histogram[HZ];
47252-extern atomic_t cachefiles_create_histogram[HZ];
47253+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47254+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47255+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
47256
47257 extern int __init cachefiles_proc_init(void);
47258 extern void cachefiles_proc_cleanup(void);
47259 static inline
47260-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
47261+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
47262 {
47263 unsigned long jif = jiffies - start_jif;
47264 if (jif >= HZ)
47265 jif = HZ - 1;
47266- atomic_inc(&histogram[jif]);
47267+ atomic_inc_unchecked(&histogram[jif]);
47268 }
47269
47270 #else
47271diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
47272index 14ac480..a62766c 100644
47273--- a/fs/cachefiles/namei.c
47274+++ b/fs/cachefiles/namei.c
47275@@ -250,7 +250,7 @@ try_again:
47276 /* first step is to make up a grave dentry in the graveyard */
47277 sprintf(nbuffer, "%08x%08x",
47278 (uint32_t) get_seconds(),
47279- (uint32_t) atomic_inc_return(&cache->gravecounter));
47280+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
47281
47282 /* do the multiway lock magic */
47283 trap = lock_rename(cache->graveyard, dir);
47284diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
47285index eccd339..4c1d995 100644
47286--- a/fs/cachefiles/proc.c
47287+++ b/fs/cachefiles/proc.c
47288@@ -14,9 +14,9 @@
47289 #include <linux/seq_file.h>
47290 #include "internal.h"
47291
47292-atomic_t cachefiles_lookup_histogram[HZ];
47293-atomic_t cachefiles_mkdir_histogram[HZ];
47294-atomic_t cachefiles_create_histogram[HZ];
47295+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47296+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47297+atomic_unchecked_t cachefiles_create_histogram[HZ];
47298
47299 /*
47300 * display the latency histogram
47301@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
47302 return 0;
47303 default:
47304 index = (unsigned long) v - 3;
47305- x = atomic_read(&cachefiles_lookup_histogram[index]);
47306- y = atomic_read(&cachefiles_mkdir_histogram[index]);
47307- z = atomic_read(&cachefiles_create_histogram[index]);
47308+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
47309+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
47310+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
47311 if (x == 0 && y == 0 && z == 0)
47312 return 0;
47313
47314diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
47315index a6c8c6f..5cf8517 100644
47316--- a/fs/cachefiles/rdwr.c
47317+++ b/fs/cachefiles/rdwr.c
47318@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
47319 old_fs = get_fs();
47320 set_fs(KERNEL_DS);
47321 ret = file->f_op->write(
47322- file, (const void __user *) data, len, &pos);
47323+ file, (const void __force_user *) data, len, &pos);
47324 set_fs(old_fs);
47325 kunmap(page);
47326 if (ret != len)
47327diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
47328index 42cec2a..2aba466 100644
47329--- a/fs/cifs/cifs_debug.c
47330+++ b/fs/cifs/cifs_debug.c
47331@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
47332 tcon = list_entry(tmp3,
47333 struct cifsTconInfo,
47334 tcon_list);
47335- atomic_set(&tcon->num_smbs_sent, 0);
47336- atomic_set(&tcon->num_writes, 0);
47337- atomic_set(&tcon->num_reads, 0);
47338- atomic_set(&tcon->num_oplock_brks, 0);
47339- atomic_set(&tcon->num_opens, 0);
47340- atomic_set(&tcon->num_posixopens, 0);
47341- atomic_set(&tcon->num_posixmkdirs, 0);
47342- atomic_set(&tcon->num_closes, 0);
47343- atomic_set(&tcon->num_deletes, 0);
47344- atomic_set(&tcon->num_mkdirs, 0);
47345- atomic_set(&tcon->num_rmdirs, 0);
47346- atomic_set(&tcon->num_renames, 0);
47347- atomic_set(&tcon->num_t2renames, 0);
47348- atomic_set(&tcon->num_ffirst, 0);
47349- atomic_set(&tcon->num_fnext, 0);
47350- atomic_set(&tcon->num_fclose, 0);
47351- atomic_set(&tcon->num_hardlinks, 0);
47352- atomic_set(&tcon->num_symlinks, 0);
47353- atomic_set(&tcon->num_locks, 0);
47354+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
47355+ atomic_set_unchecked(&tcon->num_writes, 0);
47356+ atomic_set_unchecked(&tcon->num_reads, 0);
47357+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
47358+ atomic_set_unchecked(&tcon->num_opens, 0);
47359+ atomic_set_unchecked(&tcon->num_posixopens, 0);
47360+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
47361+ atomic_set_unchecked(&tcon->num_closes, 0);
47362+ atomic_set_unchecked(&tcon->num_deletes, 0);
47363+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
47364+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
47365+ atomic_set_unchecked(&tcon->num_renames, 0);
47366+ atomic_set_unchecked(&tcon->num_t2renames, 0);
47367+ atomic_set_unchecked(&tcon->num_ffirst, 0);
47368+ atomic_set_unchecked(&tcon->num_fnext, 0);
47369+ atomic_set_unchecked(&tcon->num_fclose, 0);
47370+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
47371+ atomic_set_unchecked(&tcon->num_symlinks, 0);
47372+ atomic_set_unchecked(&tcon->num_locks, 0);
47373 }
47374 }
47375 }
47376@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
47377 if (tcon->need_reconnect)
47378 seq_puts(m, "\tDISCONNECTED ");
47379 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
47380- atomic_read(&tcon->num_smbs_sent),
47381- atomic_read(&tcon->num_oplock_brks));
47382+ atomic_read_unchecked(&tcon->num_smbs_sent),
47383+ atomic_read_unchecked(&tcon->num_oplock_brks));
47384 seq_printf(m, "\nReads: %d Bytes: %lld",
47385- atomic_read(&tcon->num_reads),
47386+ atomic_read_unchecked(&tcon->num_reads),
47387 (long long)(tcon->bytes_read));
47388 seq_printf(m, "\nWrites: %d Bytes: %lld",
47389- atomic_read(&tcon->num_writes),
47390+ atomic_read_unchecked(&tcon->num_writes),
47391 (long long)(tcon->bytes_written));
47392 seq_printf(m, "\nFlushes: %d",
47393- atomic_read(&tcon->num_flushes));
47394+ atomic_read_unchecked(&tcon->num_flushes));
47395 seq_printf(m, "\nLocks: %d HardLinks: %d "
47396 "Symlinks: %d",
47397- atomic_read(&tcon->num_locks),
47398- atomic_read(&tcon->num_hardlinks),
47399- atomic_read(&tcon->num_symlinks));
47400+ atomic_read_unchecked(&tcon->num_locks),
47401+ atomic_read_unchecked(&tcon->num_hardlinks),
47402+ atomic_read_unchecked(&tcon->num_symlinks));
47403 seq_printf(m, "\nOpens: %d Closes: %d "
47404 "Deletes: %d",
47405- atomic_read(&tcon->num_opens),
47406- atomic_read(&tcon->num_closes),
47407- atomic_read(&tcon->num_deletes));
47408+ atomic_read_unchecked(&tcon->num_opens),
47409+ atomic_read_unchecked(&tcon->num_closes),
47410+ atomic_read_unchecked(&tcon->num_deletes));
47411 seq_printf(m, "\nPosix Opens: %d "
47412 "Posix Mkdirs: %d",
47413- atomic_read(&tcon->num_posixopens),
47414- atomic_read(&tcon->num_posixmkdirs));
47415+ atomic_read_unchecked(&tcon->num_posixopens),
47416+ atomic_read_unchecked(&tcon->num_posixmkdirs));
47417 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
47418- atomic_read(&tcon->num_mkdirs),
47419- atomic_read(&tcon->num_rmdirs));
47420+ atomic_read_unchecked(&tcon->num_mkdirs),
47421+ atomic_read_unchecked(&tcon->num_rmdirs));
47422 seq_printf(m, "\nRenames: %d T2 Renames %d",
47423- atomic_read(&tcon->num_renames),
47424- atomic_read(&tcon->num_t2renames));
47425+ atomic_read_unchecked(&tcon->num_renames),
47426+ atomic_read_unchecked(&tcon->num_t2renames));
47427 seq_printf(m, "\nFindFirst: %d FNext %d "
47428 "FClose %d",
47429- atomic_read(&tcon->num_ffirst),
47430- atomic_read(&tcon->num_fnext),
47431- atomic_read(&tcon->num_fclose));
47432+ atomic_read_unchecked(&tcon->num_ffirst),
47433+ atomic_read_unchecked(&tcon->num_fnext),
47434+ atomic_read_unchecked(&tcon->num_fclose));
47435 }
47436 }
47437 }
47438diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
47439index 1445407..68cb0dc 100644
47440--- a/fs/cifs/cifsfs.c
47441+++ b/fs/cifs/cifsfs.c
47442@@ -869,7 +869,7 @@ cifs_init_request_bufs(void)
47443 cifs_req_cachep = kmem_cache_create("cifs_request",
47444 CIFSMaxBufSize +
47445 MAX_CIFS_HDR_SIZE, 0,
47446- SLAB_HWCACHE_ALIGN, NULL);
47447+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
47448 if (cifs_req_cachep == NULL)
47449 return -ENOMEM;
47450
47451@@ -896,7 +896,7 @@ cifs_init_request_bufs(void)
47452 efficient to alloc 1 per page off the slab compared to 17K (5page)
47453 alloc of large cifs buffers even when page debugging is on */
47454 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
47455- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
47456+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
47457 NULL);
47458 if (cifs_sm_req_cachep == NULL) {
47459 mempool_destroy(cifs_req_poolp);
47460@@ -991,8 +991,8 @@ init_cifs(void)
47461 atomic_set(&bufAllocCount, 0);
47462 atomic_set(&smBufAllocCount, 0);
47463 #ifdef CONFIG_CIFS_STATS2
47464- atomic_set(&totBufAllocCount, 0);
47465- atomic_set(&totSmBufAllocCount, 0);
47466+ atomic_set_unchecked(&totBufAllocCount, 0);
47467+ atomic_set_unchecked(&totSmBufAllocCount, 0);
47468 #endif /* CONFIG_CIFS_STATS2 */
47469
47470 atomic_set(&midCount, 0);
47471diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
47472index e29581e..1c22bab 100644
47473--- a/fs/cifs/cifsglob.h
47474+++ b/fs/cifs/cifsglob.h
47475@@ -252,28 +252,28 @@ struct cifsTconInfo {
47476 __u16 Flags; /* optional support bits */
47477 enum statusEnum tidStatus;
47478 #ifdef CONFIG_CIFS_STATS
47479- atomic_t num_smbs_sent;
47480- atomic_t num_writes;
47481- atomic_t num_reads;
47482- atomic_t num_flushes;
47483- atomic_t num_oplock_brks;
47484- atomic_t num_opens;
47485- atomic_t num_closes;
47486- atomic_t num_deletes;
47487- atomic_t num_mkdirs;
47488- atomic_t num_posixopens;
47489- atomic_t num_posixmkdirs;
47490- atomic_t num_rmdirs;
47491- atomic_t num_renames;
47492- atomic_t num_t2renames;
47493- atomic_t num_ffirst;
47494- atomic_t num_fnext;
47495- atomic_t num_fclose;
47496- atomic_t num_hardlinks;
47497- atomic_t num_symlinks;
47498- atomic_t num_locks;
47499- atomic_t num_acl_get;
47500- atomic_t num_acl_set;
47501+ atomic_unchecked_t num_smbs_sent;
47502+ atomic_unchecked_t num_writes;
47503+ atomic_unchecked_t num_reads;
47504+ atomic_unchecked_t num_flushes;
47505+ atomic_unchecked_t num_oplock_brks;
47506+ atomic_unchecked_t num_opens;
47507+ atomic_unchecked_t num_closes;
47508+ atomic_unchecked_t num_deletes;
47509+ atomic_unchecked_t num_mkdirs;
47510+ atomic_unchecked_t num_posixopens;
47511+ atomic_unchecked_t num_posixmkdirs;
47512+ atomic_unchecked_t num_rmdirs;
47513+ atomic_unchecked_t num_renames;
47514+ atomic_unchecked_t num_t2renames;
47515+ atomic_unchecked_t num_ffirst;
47516+ atomic_unchecked_t num_fnext;
47517+ atomic_unchecked_t num_fclose;
47518+ atomic_unchecked_t num_hardlinks;
47519+ atomic_unchecked_t num_symlinks;
47520+ atomic_unchecked_t num_locks;
47521+ atomic_unchecked_t num_acl_get;
47522+ atomic_unchecked_t num_acl_set;
47523 #ifdef CONFIG_CIFS_STATS2
47524 unsigned long long time_writes;
47525 unsigned long long time_reads;
47526@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
47527 }
47528
47529 #ifdef CONFIG_CIFS_STATS
47530-#define cifs_stats_inc atomic_inc
47531+#define cifs_stats_inc atomic_inc_unchecked
47532
47533 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
47534 unsigned int bytes)
47535@@ -701,8 +701,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
47536 /* Various Debug counters */
47537 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
47538 #ifdef CONFIG_CIFS_STATS2
47539-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
47540-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
47541+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
47542+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
47543 #endif
47544 GLOBAL_EXTERN atomic_t smBufAllocCount;
47545 GLOBAL_EXTERN atomic_t midCount;
47546diff --git a/fs/cifs/link.c b/fs/cifs/link.c
47547index fc1e048..28b3441 100644
47548--- a/fs/cifs/link.c
47549+++ b/fs/cifs/link.c
47550@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
47551
47552 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
47553 {
47554- char *p = nd_get_link(nd);
47555+ const char *p = nd_get_link(nd);
47556 if (!IS_ERR(p))
47557 kfree(p);
47558 }
47559diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
47560index 95b82e8..12a538d 100644
47561--- a/fs/cifs/misc.c
47562+++ b/fs/cifs/misc.c
47563@@ -155,7 +155,7 @@ cifs_buf_get(void)
47564 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
47565 atomic_inc(&bufAllocCount);
47566 #ifdef CONFIG_CIFS_STATS2
47567- atomic_inc(&totBufAllocCount);
47568+ atomic_inc_unchecked(&totBufAllocCount);
47569 #endif /* CONFIG_CIFS_STATS2 */
47570 }
47571
47572@@ -190,7 +190,7 @@ cifs_small_buf_get(void)
47573 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
47574 atomic_inc(&smBufAllocCount);
47575 #ifdef CONFIG_CIFS_STATS2
47576- atomic_inc(&totSmBufAllocCount);
47577+ atomic_inc_unchecked(&totSmBufAllocCount);
47578 #endif /* CONFIG_CIFS_STATS2 */
47579
47580 }
47581diff --git a/fs/coda/cache.c b/fs/coda/cache.c
47582index a5bf577..6d19845 100644
47583--- a/fs/coda/cache.c
47584+++ b/fs/coda/cache.c
47585@@ -24,14 +24,14 @@
47586 #include <linux/coda_fs_i.h>
47587 #include <linux/coda_cache.h>
47588
47589-static atomic_t permission_epoch = ATOMIC_INIT(0);
47590+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
47591
47592 /* replace or extend an acl cache hit */
47593 void coda_cache_enter(struct inode *inode, int mask)
47594 {
47595 struct coda_inode_info *cii = ITOC(inode);
47596
47597- cii->c_cached_epoch = atomic_read(&permission_epoch);
47598+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47599 if (cii->c_uid != current_fsuid()) {
47600 cii->c_uid = current_fsuid();
47601 cii->c_cached_perm = mask;
47602@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inode, int mask)
47603 void coda_cache_clear_inode(struct inode *inode)
47604 {
47605 struct coda_inode_info *cii = ITOC(inode);
47606- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47607+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47608 }
47609
47610 /* remove all acl caches */
47611 void coda_cache_clear_all(struct super_block *sb)
47612 {
47613- atomic_inc(&permission_epoch);
47614+ atomic_inc_unchecked(&permission_epoch);
47615 }
47616
47617
47618@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode, int mask)
47619
47620 hit = (mask & cii->c_cached_perm) == mask &&
47621 cii->c_uid == current_fsuid() &&
47622- cii->c_cached_epoch == atomic_read(&permission_epoch);
47623+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47624
47625 return hit;
47626 }
47627diff --git a/fs/compat.c b/fs/compat.c
47628index d1e2411..27064e4 100644
47629--- a/fs/compat.c
47630+++ b/fs/compat.c
47631@@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
47632 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
47633 {
47634 compat_ino_t ino = stat->ino;
47635- typeof(ubuf->st_uid) uid = 0;
47636- typeof(ubuf->st_gid) gid = 0;
47637+ typeof(((struct compat_stat *)0)->st_uid) uid = 0;
47638+ typeof(((struct compat_stat *)0)->st_gid) gid = 0;
47639 int err;
47640
47641 SET_UID(uid, stat->uid);
47642@@ -533,7 +533,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47643
47644 set_fs(KERNEL_DS);
47645 /* The __user pointer cast is valid because of the set_fs() */
47646- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47647+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47648 set_fs(oldfs);
47649 /* truncating is ok because it's a user address */
47650 if (!ret)
47651@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
47652
47653 struct compat_readdir_callback {
47654 struct compat_old_linux_dirent __user *dirent;
47655+ struct file * file;
47656 int result;
47657 };
47658
47659@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47660 buf->result = -EOVERFLOW;
47661 return -EOVERFLOW;
47662 }
47663+
47664+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47665+ return 0;
47666+
47667 buf->result++;
47668 dirent = buf->dirent;
47669 if (!access_ok(VERIFY_WRITE, dirent,
47670@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47671
47672 buf.result = 0;
47673 buf.dirent = dirent;
47674+ buf.file = file;
47675
47676 error = vfs_readdir(file, compat_fillonedir, &buf);
47677 if (buf.result)
47678@@ -899,6 +905,7 @@ struct compat_linux_dirent {
47679 struct compat_getdents_callback {
47680 struct compat_linux_dirent __user *current_dir;
47681 struct compat_linux_dirent __user *previous;
47682+ struct file * file;
47683 int count;
47684 int error;
47685 };
47686@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47687 buf->error = -EOVERFLOW;
47688 return -EOVERFLOW;
47689 }
47690+
47691+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47692+ return 0;
47693+
47694 dirent = buf->previous;
47695 if (dirent) {
47696 if (__put_user(offset, &dirent->d_off))
47697@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47698 buf.previous = NULL;
47699 buf.count = count;
47700 buf.error = 0;
47701+ buf.file = file;
47702
47703 error = vfs_readdir(file, compat_filldir, &buf);
47704 if (error >= 0)
47705@@ -987,6 +999,7 @@ out:
47706 struct compat_getdents_callback64 {
47707 struct linux_dirent64 __user *current_dir;
47708 struct linux_dirent64 __user *previous;
47709+ struct file * file;
47710 int count;
47711 int error;
47712 };
47713@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47714 buf->error = -EINVAL; /* only used if we fail.. */
47715 if (reclen > buf->count)
47716 return -EINVAL;
47717+
47718+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47719+ return 0;
47720+
47721 dirent = buf->previous;
47722
47723 if (dirent) {
47724@@ -1054,13 +1071,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47725 buf.previous = NULL;
47726 buf.count = count;
47727 buf.error = 0;
47728+ buf.file = file;
47729
47730 error = vfs_readdir(file, compat_filldir64, &buf);
47731 if (error >= 0)
47732 error = buf.error;
47733 lastdirent = buf.previous;
47734 if (lastdirent) {
47735- typeof(lastdirent->d_off) d_off = file->f_pos;
47736+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47737 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47738 error = -EFAULT;
47739 else
47740@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
47741 * verify all the pointers
47742 */
47743 ret = -EINVAL;
47744- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
47745+ if (nr_segs > UIO_MAXIOV)
47746 goto out;
47747 if (!file->f_op)
47748 goto out;
47749@@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
47750 compat_uptr_t __user *envp,
47751 struct pt_regs * regs)
47752 {
47753+#ifdef CONFIG_GRKERNSEC
47754+ struct file *old_exec_file;
47755+ struct acl_subject_label *old_acl;
47756+ struct rlimit old_rlim[RLIM_NLIMITS];
47757+#endif
47758 struct linux_binprm *bprm;
47759 struct file *file;
47760 struct files_struct *displaced;
47761 bool clear_in_exec;
47762 int retval;
47763+ const struct cred *cred = current_cred();
47764+
47765+ /*
47766+ * We move the actual failure in case of RLIMIT_NPROC excess from
47767+ * set*uid() to execve() because too many poorly written programs
47768+ * don't check setuid() return code. Here we additionally recheck
47769+ * whether NPROC limit is still exceeded.
47770+ */
47771+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47772+
47773+ if ((current->flags & PF_NPROC_EXCEEDED) &&
47774+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
47775+ retval = -EAGAIN;
47776+ goto out_ret;
47777+ }
47778+
47779+ /* We're below the limit (still or again), so we don't want to make
47780+ * further execve() calls fail. */
47781+ current->flags &= ~PF_NPROC_EXCEEDED;
47782
47783 retval = unshare_files(&displaced);
47784 if (retval)
47785@@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
47786 bprm->filename = filename;
47787 bprm->interp = filename;
47788
47789+ if (gr_process_user_ban()) {
47790+ retval = -EPERM;
47791+ goto out_file;
47792+ }
47793+
47794+ retval = -EACCES;
47795+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
47796+ goto out_file;
47797+
47798 retval = bprm_mm_init(bprm);
47799 if (retval)
47800 goto out_file;
47801@@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
47802 if (retval < 0)
47803 goto out;
47804
47805+ if (!gr_tpe_allow(file)) {
47806+ retval = -EACCES;
47807+ goto out;
47808+ }
47809+
47810+ if (gr_check_crash_exec(file)) {
47811+ retval = -EACCES;
47812+ goto out;
47813+ }
47814+
47815+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47816+
47817+ gr_handle_exec_args_compat(bprm, argv);
47818+
47819+#ifdef CONFIG_GRKERNSEC
47820+ old_acl = current->acl;
47821+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47822+ old_exec_file = current->exec_file;
47823+ get_file(file);
47824+ current->exec_file = file;
47825+#endif
47826+
47827+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47828+ bprm->unsafe & LSM_UNSAFE_SHARE);
47829+ if (retval < 0)
47830+ goto out_fail;
47831+
47832 retval = search_binary_handler(bprm, regs);
47833 if (retval < 0)
47834- goto out;
47835+ goto out_fail;
47836+#ifdef CONFIG_GRKERNSEC
47837+ if (old_exec_file)
47838+ fput(old_exec_file);
47839+#endif
47840
47841 /* execve succeeded */
47842 current->fs->in_exec = 0;
47843@@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
47844 put_files_struct(displaced);
47845 return retval;
47846
47847+out_fail:
47848+#ifdef CONFIG_GRKERNSEC
47849+ current->acl = old_acl;
47850+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47851+ fput(current->exec_file);
47852+ current->exec_file = old_exec_file;
47853+#endif
47854+
47855 out:
47856 if (bprm->mm) {
47857 acct_arg_size(bprm, 0);
47858@@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
47859 struct fdtable *fdt;
47860 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
47861
47862+ pax_track_stack();
47863+
47864 if (n < 0)
47865 goto out_nofds;
47866
47867@@ -2151,7 +2243,7 @@ asmlinkage long compat_sys_nfsservctl(int cmd,
47868 oldfs = get_fs();
47869 set_fs(KERNEL_DS);
47870 /* The __user pointer casts are valid because of the set_fs() */
47871- err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
47872+ err = sys_nfsservctl(cmd, (void __force_user *) karg, (void __force_user *) kres);
47873 set_fs(oldfs);
47874
47875 if (err)
47876diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47877index 0adced2..bbb1b0d 100644
47878--- a/fs/compat_binfmt_elf.c
47879+++ b/fs/compat_binfmt_elf.c
47880@@ -29,10 +29,12 @@
47881 #undef elfhdr
47882 #undef elf_phdr
47883 #undef elf_note
47884+#undef elf_dyn
47885 #undef elf_addr_t
47886 #define elfhdr elf32_hdr
47887 #define elf_phdr elf32_phdr
47888 #define elf_note elf32_note
47889+#define elf_dyn Elf32_Dyn
47890 #define elf_addr_t Elf32_Addr
47891
47892 /*
47893diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47894index d84e705..d8c364c 100644
47895--- a/fs/compat_ioctl.c
47896+++ b/fs/compat_ioctl.c
47897@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned
47898 up = (struct compat_video_spu_palette __user *) arg;
47899 err = get_user(palp, &up->palette);
47900 err |= get_user(length, &up->length);
47901+ if (err)
47902+ return -EFAULT;
47903
47904 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
47905 err = put_user(compat_ptr(palp), &up_native->palette);
47906@@ -1513,7 +1515,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
47907 return -EFAULT;
47908 if (__get_user(udata, &ss32->iomem_base))
47909 return -EFAULT;
47910- ss.iomem_base = compat_ptr(udata);
47911+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47912 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47913 __get_user(ss.port_high, &ss32->port_high))
47914 return -EFAULT;
47915@@ -1809,7 +1811,7 @@ static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
47916 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47917 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47918 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47919- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47920+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47921 return -EFAULT;
47922
47923 return ioctl_preallocate(file, p);
47924diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47925index 8e48b52..f01ed91 100644
47926--- a/fs/configfs/dir.c
47927+++ b/fs/configfs/dir.c
47928@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47929 }
47930 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47931 struct configfs_dirent *next;
47932- const char * name;
47933+ const unsigned char * name;
47934+ char d_name[sizeof(next->s_dentry->d_iname)];
47935 int len;
47936
47937 next = list_entry(p, struct configfs_dirent,
47938@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47939 continue;
47940
47941 name = configfs_get_name(next);
47942- len = strlen(name);
47943+ if (next->s_dentry && name == next->s_dentry->d_iname) {
47944+ len = next->s_dentry->d_name.len;
47945+ memcpy(d_name, name, len);
47946+ name = d_name;
47947+ } else
47948+ len = strlen(name);
47949 if (next->s_dentry)
47950 ino = next->s_dentry->d_inode->i_ino;
47951 else
47952diff --git a/fs/dcache.c b/fs/dcache.c
47953index 44c0aea..2529092 100644
47954--- a/fs/dcache.c
47955+++ b/fs/dcache.c
47956@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
47957
47958 static struct kmem_cache *dentry_cache __read_mostly;
47959
47960-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
47961-
47962 /*
47963 * This is the single most critical data structure when it comes
47964 * to the dcache: the hashtable for lookups. Somebody should try
47965@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned long mempages)
47966 mempages -= reserve;
47967
47968 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47969- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47970+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47971
47972 dcache_init();
47973 inode_init();
47974diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
47975index c010ecf..a8d8c59 100644
47976--- a/fs/dlm/lockspace.c
47977+++ b/fs/dlm/lockspace.c
47978@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struct kobject *k)
47979 kfree(ls);
47980 }
47981
47982-static struct sysfs_ops dlm_attr_ops = {
47983+static const struct sysfs_ops dlm_attr_ops = {
47984 .show = dlm_attr_show,
47985 .store = dlm_attr_store,
47986 };
47987diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47988index 88ba4d4..073f003 100644
47989--- a/fs/ecryptfs/inode.c
47990+++ b/fs/ecryptfs/inode.c
47991@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47992 old_fs = get_fs();
47993 set_fs(get_ds());
47994 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47995- (char __user *)lower_buf,
47996+ (char __force_user *)lower_buf,
47997 lower_bufsiz);
47998 set_fs(old_fs);
47999 if (rc < 0)
48000@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48001 }
48002 old_fs = get_fs();
48003 set_fs(get_ds());
48004- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
48005+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
48006 set_fs(old_fs);
48007 if (rc < 0)
48008 goto out_free;
48009diff --git a/fs/exec.c b/fs/exec.c
48010index 86fafc6..b307bfa 100644
48011--- a/fs/exec.c
48012+++ b/fs/exec.c
48013@@ -56,12 +56,24 @@
48014 #include <linux/fsnotify.h>
48015 #include <linux/fs_struct.h>
48016 #include <linux/pipe_fs_i.h>
48017+#include <linux/random.h>
48018+#include <linux/seq_file.h>
48019+
48020+#ifdef CONFIG_PAX_REFCOUNT
48021+#include <linux/kallsyms.h>
48022+#include <linux/kdebug.h>
48023+#endif
48024
48025 #include <asm/uaccess.h>
48026 #include <asm/mmu_context.h>
48027 #include <asm/tlb.h>
48028 #include "internal.h"
48029
48030+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
48031+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
48032+EXPORT_SYMBOL(pax_set_initial_flags_func);
48033+#endif
48034+
48035 int core_uses_pid;
48036 char core_pattern[CORENAME_MAX_SIZE] = "core";
48037 unsigned int core_pipe_limit;
48038@@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
48039 int write)
48040 {
48041 struct page *page;
48042- int ret;
48043
48044-#ifdef CONFIG_STACK_GROWSUP
48045- if (write) {
48046- ret = expand_stack_downwards(bprm->vma, pos);
48047- if (ret < 0)
48048- return NULL;
48049- }
48050-#endif
48051- ret = get_user_pages(current, bprm->mm, pos,
48052- 1, write, 1, &page, NULL);
48053- if (ret <= 0)
48054+ if (0 > expand_stack_downwards(bprm->vma, pos))
48055+ return NULL;
48056+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
48057 return NULL;
48058
48059 if (write) {
48060@@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48061 vma->vm_end = STACK_TOP_MAX;
48062 vma->vm_start = vma->vm_end - PAGE_SIZE;
48063 vma->vm_flags = VM_STACK_FLAGS;
48064+
48065+#ifdef CONFIG_PAX_SEGMEXEC
48066+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
48067+#endif
48068+
48069 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
48070
48071 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
48072@@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48073 mm->stack_vm = mm->total_vm = 1;
48074 up_write(&mm->mmap_sem);
48075 bprm->p = vma->vm_end - sizeof(void *);
48076+
48077+#ifdef CONFIG_PAX_RANDUSTACK
48078+ if (randomize_va_space)
48079+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
48080+#endif
48081+
48082 return 0;
48083 err:
48084 up_write(&mm->mmap_sem);
48085@@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
48086 int r;
48087 mm_segment_t oldfs = get_fs();
48088 set_fs(KERNEL_DS);
48089- r = copy_strings(argc, (char __user * __user *)argv, bprm);
48090+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
48091 set_fs(oldfs);
48092 return r;
48093 }
48094@@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48095 unsigned long new_end = old_end - shift;
48096 struct mmu_gather *tlb;
48097
48098- BUG_ON(new_start > new_end);
48099+ if (new_start >= new_end || new_start < mmap_min_addr)
48100+ return -ENOMEM;
48101
48102 /*
48103 * ensure there are no vmas between where we want to go
48104@@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48105 if (vma != find_vma(mm, new_start))
48106 return -EFAULT;
48107
48108+#ifdef CONFIG_PAX_SEGMEXEC
48109+ BUG_ON(pax_find_mirror_vma(vma));
48110+#endif
48111+
48112 /*
48113 * cover the whole range: [new_start, old_end)
48114 */
48115@@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
48116 stack_top = arch_align_stack(stack_top);
48117 stack_top = PAGE_ALIGN(stack_top);
48118
48119- if (unlikely(stack_top < mmap_min_addr) ||
48120- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
48121- return -ENOMEM;
48122-
48123 stack_shift = vma->vm_end - stack_top;
48124
48125 bprm->p -= stack_shift;
48126@@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm *bprm,
48127 bprm->exec -= stack_shift;
48128
48129 down_write(&mm->mmap_sem);
48130+
48131+ /* Move stack pages down in memory. */
48132+ if (stack_shift) {
48133+ ret = shift_arg_pages(vma, stack_shift);
48134+ if (ret)
48135+ goto out_unlock;
48136+ }
48137+
48138 vm_flags = VM_STACK_FLAGS;
48139
48140 /*
48141@@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm *bprm,
48142 vm_flags &= ~VM_EXEC;
48143 vm_flags |= mm->def_flags;
48144
48145+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48146+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48147+ vm_flags &= ~VM_EXEC;
48148+
48149+#ifdef CONFIG_PAX_MPROTECT
48150+ if (mm->pax_flags & MF_PAX_MPROTECT)
48151+ vm_flags &= ~VM_MAYEXEC;
48152+#endif
48153+
48154+ }
48155+#endif
48156+
48157 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
48158 vm_flags);
48159 if (ret)
48160 goto out_unlock;
48161 BUG_ON(prev != vma);
48162
48163- /* Move stack pages down in memory. */
48164- if (stack_shift) {
48165- ret = shift_arg_pages(vma, stack_shift);
48166- if (ret)
48167- goto out_unlock;
48168- }
48169-
48170 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
48171 stack_size = vma->vm_end - vma->vm_start;
48172 /*
48173@@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_t offset,
48174 old_fs = get_fs();
48175 set_fs(get_ds());
48176 /* The cast to a user pointer is valid due to the set_fs() */
48177- result = vfs_read(file, (void __user *)addr, count, &pos);
48178+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
48179 set_fs(old_fs);
48180 return result;
48181 }
48182@@ -1152,7 +1181,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
48183 }
48184 rcu_read_unlock();
48185
48186- if (p->fs->users > n_fs) {
48187+ if (atomic_read(&p->fs->users) > n_fs) {
48188 bprm->unsafe |= LSM_UNSAFE_SHARE;
48189 } else {
48190 res = -EAGAIN;
48191@@ -1347,11 +1376,35 @@ int do_execve(char * filename,
48192 char __user *__user *envp,
48193 struct pt_regs * regs)
48194 {
48195+#ifdef CONFIG_GRKERNSEC
48196+ struct file *old_exec_file;
48197+ struct acl_subject_label *old_acl;
48198+ struct rlimit old_rlim[RLIM_NLIMITS];
48199+#endif
48200 struct linux_binprm *bprm;
48201 struct file *file;
48202 struct files_struct *displaced;
48203 bool clear_in_exec;
48204 int retval;
48205+ const struct cred *cred = current_cred();
48206+
48207+ /*
48208+ * We move the actual failure in case of RLIMIT_NPROC excess from
48209+ * set*uid() to execve() because too many poorly written programs
48210+ * don't check setuid() return code. Here we additionally recheck
48211+ * whether NPROC limit is still exceeded.
48212+ */
48213+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48214+
48215+ if ((current->flags & PF_NPROC_EXCEEDED) &&
48216+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48217+ retval = -EAGAIN;
48218+ goto out_ret;
48219+ }
48220+
48221+ /* We're below the limit (still or again), so we don't want to make
48222+ * further execve() calls fail. */
48223+ current->flags &= ~PF_NPROC_EXCEEDED;
48224
48225 retval = unshare_files(&displaced);
48226 if (retval)
48227@@ -1383,6 +1436,16 @@ int do_execve(char * filename,
48228 bprm->filename = filename;
48229 bprm->interp = filename;
48230
48231+ if (gr_process_user_ban()) {
48232+ retval = -EPERM;
48233+ goto out_file;
48234+ }
48235+
48236+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
48237+ retval = -EACCES;
48238+ goto out_file;
48239+ }
48240+
48241 retval = bprm_mm_init(bprm);
48242 if (retval)
48243 goto out_file;
48244@@ -1412,10 +1475,41 @@ int do_execve(char * filename,
48245 if (retval < 0)
48246 goto out;
48247
48248+ if (!gr_tpe_allow(file)) {
48249+ retval = -EACCES;
48250+ goto out;
48251+ }
48252+
48253+ if (gr_check_crash_exec(file)) {
48254+ retval = -EACCES;
48255+ goto out;
48256+ }
48257+
48258+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48259+
48260+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
48261+
48262+#ifdef CONFIG_GRKERNSEC
48263+ old_acl = current->acl;
48264+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48265+ old_exec_file = current->exec_file;
48266+ get_file(file);
48267+ current->exec_file = file;
48268+#endif
48269+
48270+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48271+ bprm->unsafe & LSM_UNSAFE_SHARE);
48272+ if (retval < 0)
48273+ goto out_fail;
48274+
48275 current->flags &= ~PF_KTHREAD;
48276 retval = search_binary_handler(bprm,regs);
48277 if (retval < 0)
48278- goto out;
48279+ goto out_fail;
48280+#ifdef CONFIG_GRKERNSEC
48281+ if (old_exec_file)
48282+ fput(old_exec_file);
48283+#endif
48284
48285 /* execve succeeded */
48286 current->fs->in_exec = 0;
48287@@ -1426,6 +1520,14 @@ int do_execve(char * filename,
48288 put_files_struct(displaced);
48289 return retval;
48290
48291+out_fail:
48292+#ifdef CONFIG_GRKERNSEC
48293+ current->acl = old_acl;
48294+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48295+ fput(current->exec_file);
48296+ current->exec_file = old_exec_file;
48297+#endif
48298+
48299 out:
48300 if (bprm->mm) {
48301 acct_arg_size(bprm, 0);
48302@@ -1591,6 +1693,220 @@ out:
48303 return ispipe;
48304 }
48305
48306+int pax_check_flags(unsigned long *flags)
48307+{
48308+ int retval = 0;
48309+
48310+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
48311+ if (*flags & MF_PAX_SEGMEXEC)
48312+ {
48313+ *flags &= ~MF_PAX_SEGMEXEC;
48314+ retval = -EINVAL;
48315+ }
48316+#endif
48317+
48318+ if ((*flags & MF_PAX_PAGEEXEC)
48319+
48320+#ifdef CONFIG_PAX_PAGEEXEC
48321+ && (*flags & MF_PAX_SEGMEXEC)
48322+#endif
48323+
48324+ )
48325+ {
48326+ *flags &= ~MF_PAX_PAGEEXEC;
48327+ retval = -EINVAL;
48328+ }
48329+
48330+ if ((*flags & MF_PAX_MPROTECT)
48331+
48332+#ifdef CONFIG_PAX_MPROTECT
48333+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48334+#endif
48335+
48336+ )
48337+ {
48338+ *flags &= ~MF_PAX_MPROTECT;
48339+ retval = -EINVAL;
48340+ }
48341+
48342+ if ((*flags & MF_PAX_EMUTRAMP)
48343+
48344+#ifdef CONFIG_PAX_EMUTRAMP
48345+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48346+#endif
48347+
48348+ )
48349+ {
48350+ *flags &= ~MF_PAX_EMUTRAMP;
48351+ retval = -EINVAL;
48352+ }
48353+
48354+ return retval;
48355+}
48356+
48357+EXPORT_SYMBOL(pax_check_flags);
48358+
48359+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48360+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
48361+{
48362+ struct task_struct *tsk = current;
48363+ struct mm_struct *mm = current->mm;
48364+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
48365+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
48366+ char *path_exec = NULL;
48367+ char *path_fault = NULL;
48368+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
48369+
48370+ if (buffer_exec && buffer_fault) {
48371+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
48372+
48373+ down_read(&mm->mmap_sem);
48374+ vma = mm->mmap;
48375+ while (vma && (!vma_exec || !vma_fault)) {
48376+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
48377+ vma_exec = vma;
48378+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
48379+ vma_fault = vma;
48380+ vma = vma->vm_next;
48381+ }
48382+ if (vma_exec) {
48383+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
48384+ if (IS_ERR(path_exec))
48385+ path_exec = "<path too long>";
48386+ else {
48387+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
48388+ if (path_exec) {
48389+ *path_exec = 0;
48390+ path_exec = buffer_exec;
48391+ } else
48392+ path_exec = "<path too long>";
48393+ }
48394+ }
48395+ if (vma_fault) {
48396+ start = vma_fault->vm_start;
48397+ end = vma_fault->vm_end;
48398+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48399+ if (vma_fault->vm_file) {
48400+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48401+ if (IS_ERR(path_fault))
48402+ path_fault = "<path too long>";
48403+ else {
48404+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48405+ if (path_fault) {
48406+ *path_fault = 0;
48407+ path_fault = buffer_fault;
48408+ } else
48409+ path_fault = "<path too long>";
48410+ }
48411+ } else
48412+ path_fault = "<anonymous mapping>";
48413+ }
48414+ up_read(&mm->mmap_sem);
48415+ }
48416+ if (tsk->signal->curr_ip)
48417+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48418+ else
48419+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48420+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
48421+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
48422+ task_uid(tsk), task_euid(tsk), pc, sp);
48423+ free_page((unsigned long)buffer_exec);
48424+ free_page((unsigned long)buffer_fault);
48425+ pax_report_insns(regs, pc, sp);
48426+ do_coredump(SIGKILL, SIGKILL, regs);
48427+}
48428+#endif
48429+
48430+#ifdef CONFIG_PAX_REFCOUNT
48431+void pax_report_refcount_overflow(struct pt_regs *regs)
48432+{
48433+ if (current->signal->curr_ip)
48434+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48435+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
48436+ else
48437+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48438+ current->comm, task_pid_nr(current), current_uid(), current_euid());
48439+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48440+ show_regs(regs);
48441+ force_sig_specific(SIGKILL, current);
48442+}
48443+#endif
48444+
48445+#ifdef CONFIG_PAX_USERCOPY
48446+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48447+int object_is_on_stack(const void *obj, unsigned long len)
48448+{
48449+ const void * const stack = task_stack_page(current);
48450+ const void * const stackend = stack + THREAD_SIZE;
48451+
48452+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48453+ const void *frame = NULL;
48454+ const void *oldframe;
48455+#endif
48456+
48457+ if (obj + len < obj)
48458+ return -1;
48459+
48460+ if (obj + len <= stack || stackend <= obj)
48461+ return 0;
48462+
48463+ if (obj < stack || stackend < obj + len)
48464+ return -1;
48465+
48466+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48467+ oldframe = __builtin_frame_address(1);
48468+ if (oldframe)
48469+ frame = __builtin_frame_address(2);
48470+ /*
48471+ low ----------------------------------------------> high
48472+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48473+ ^----------------^
48474+ allow copies only within here
48475+ */
48476+ while (stack <= frame && frame < stackend) {
48477+ /* if obj + len extends past the last frame, this
48478+ check won't pass and the next frame will be 0,
48479+ causing us to bail out and correctly report
48480+ the copy as invalid
48481+ */
48482+ if (obj + len <= frame)
48483+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48484+ oldframe = frame;
48485+ frame = *(const void * const *)frame;
48486+ }
48487+ return -1;
48488+#else
48489+ return 1;
48490+#endif
48491+}
48492+
48493+
48494+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48495+{
48496+ if (current->signal->curr_ip)
48497+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48498+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48499+ else
48500+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48501+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48502+
48503+ dump_stack();
48504+ gr_handle_kernel_exploit();
48505+ do_group_exit(SIGKILL);
48506+}
48507+#endif
48508+
48509+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48510+void pax_track_stack(void)
48511+{
48512+ unsigned long sp = (unsigned long)&sp;
48513+ if (sp < current_thread_info()->lowest_stack &&
48514+ sp > (unsigned long)task_stack_page(current))
48515+ current_thread_info()->lowest_stack = sp;
48516+}
48517+EXPORT_SYMBOL(pax_track_stack);
48518+#endif
48519+
48520 static int zap_process(struct task_struct *start)
48521 {
48522 struct task_struct *t;
48523@@ -1793,17 +2109,17 @@ static void wait_for_dump_helpers(struct file *file)
48524 pipe = file->f_path.dentry->d_inode->i_pipe;
48525
48526 pipe_lock(pipe);
48527- pipe->readers++;
48528- pipe->writers--;
48529+ atomic_inc(&pipe->readers);
48530+ atomic_dec(&pipe->writers);
48531
48532- while ((pipe->readers > 1) && (!signal_pending(current))) {
48533+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
48534 wake_up_interruptible_sync(&pipe->wait);
48535 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48536 pipe_wait(pipe);
48537 }
48538
48539- pipe->readers--;
48540- pipe->writers++;
48541+ atomic_dec(&pipe->readers);
48542+ atomic_inc(&pipe->writers);
48543 pipe_unlock(pipe);
48544
48545 }
48546@@ -1826,10 +2142,13 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48547 char **helper_argv = NULL;
48548 int helper_argc = 0;
48549 int dump_count = 0;
48550- static atomic_t core_dump_count = ATOMIC_INIT(0);
48551+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
48552
48553 audit_core_dumps(signr);
48554
48555+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
48556+ gr_handle_brute_attach(current, mm->flags);
48557+
48558 binfmt = mm->binfmt;
48559 if (!binfmt || !binfmt->core_dump)
48560 goto fail;
48561@@ -1874,6 +2193,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48562 */
48563 clear_thread_flag(TIF_SIGPENDING);
48564
48565+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
48566+
48567 /*
48568 * lock_kernel() because format_corename() is controlled by sysctl, which
48569 * uses lock_kernel()
48570@@ -1908,7 +2229,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48571 goto fail_unlock;
48572 }
48573
48574- dump_count = atomic_inc_return(&core_dump_count);
48575+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
48576 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
48577 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
48578 task_tgid_vnr(current), current->comm);
48579@@ -1972,7 +2293,7 @@ close_fail:
48580 filp_close(file, NULL);
48581 fail_dropcount:
48582 if (dump_count)
48583- atomic_dec(&core_dump_count);
48584+ atomic_dec_unchecked(&core_dump_count);
48585 fail_unlock:
48586 if (helper_argv)
48587 argv_free(helper_argv);
48588diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48589index 7f8d2e5..a1abdbb 100644
48590--- a/fs/ext2/balloc.c
48591+++ b/fs/ext2/balloc.c
48592@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48593
48594 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48595 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48596- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48597+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48598 sbi->s_resuid != current_fsuid() &&
48599 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48600 return 0;
48601diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48602index 27967f9..9f2a5fb 100644
48603--- a/fs/ext3/balloc.c
48604+++ b/fs/ext3/balloc.c
48605@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
48606
48607 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48608 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48609- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48610+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48611 sbi->s_resuid != current_fsuid() &&
48612 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48613 return 0;
48614diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48615index e85b63c..80398e6 100644
48616--- a/fs/ext4/balloc.c
48617+++ b/fs/ext4/balloc.c
48618@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
48619 /* Hm, nope. Are (enough) root reserved blocks available? */
48620 if (sbi->s_resuid == current_fsuid() ||
48621 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
48622- capable(CAP_SYS_RESOURCE)) {
48623+ capable_nolog(CAP_SYS_RESOURCE)) {
48624 if (free_blocks >= (nblocks + dirty_blocks))
48625 return 1;
48626 }
48627diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48628index 67c46ed..1f237e5 100644
48629--- a/fs/ext4/ext4.h
48630+++ b/fs/ext4/ext4.h
48631@@ -1077,19 +1077,19 @@ struct ext4_sb_info {
48632
48633 /* stats for buddy allocator */
48634 spinlock_t s_mb_pa_lock;
48635- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48636- atomic_t s_bal_success; /* we found long enough chunks */
48637- atomic_t s_bal_allocated; /* in blocks */
48638- atomic_t s_bal_ex_scanned; /* total extents scanned */
48639- atomic_t s_bal_goals; /* goal hits */
48640- atomic_t s_bal_breaks; /* too long searches */
48641- atomic_t s_bal_2orders; /* 2^order hits */
48642+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48643+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48644+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48645+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48646+ atomic_unchecked_t s_bal_goals; /* goal hits */
48647+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48648+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48649 spinlock_t s_bal_lock;
48650 unsigned long s_mb_buddies_generated;
48651 unsigned long long s_mb_generation_time;
48652- atomic_t s_mb_lost_chunks;
48653- atomic_t s_mb_preallocated;
48654- atomic_t s_mb_discarded;
48655+ atomic_unchecked_t s_mb_lost_chunks;
48656+ atomic_unchecked_t s_mb_preallocated;
48657+ atomic_unchecked_t s_mb_discarded;
48658 atomic_t s_lock_busy;
48659
48660 /* locality groups */
48661diff --git a/fs/ext4/file.c b/fs/ext4/file.c
48662index 2a60541..7439d61 100644
48663--- a/fs/ext4/file.c
48664+++ b/fs/ext4/file.c
48665@@ -122,8 +122,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
48666 cp = d_path(&path, buf, sizeof(buf));
48667 path_put(&path);
48668 if (!IS_ERR(cp)) {
48669- memcpy(sbi->s_es->s_last_mounted, cp,
48670- sizeof(sbi->s_es->s_last_mounted));
48671+ strlcpy(sbi->s_es->s_last_mounted, cp,
48672+ sizeof(sbi->s_es->s_last_mounted));
48673 sb->s_dirt = 1;
48674 }
48675 }
48676diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48677index 42bac1b..0aab9d8 100644
48678--- a/fs/ext4/mballoc.c
48679+++ b/fs/ext4/mballoc.c
48680@@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48681 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48682
48683 if (EXT4_SB(sb)->s_mb_stats)
48684- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48685+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48686
48687 break;
48688 }
48689@@ -2131,7 +2131,7 @@ repeat:
48690 ac->ac_status = AC_STATUS_CONTINUE;
48691 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48692 cr = 3;
48693- atomic_inc(&sbi->s_mb_lost_chunks);
48694+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48695 goto repeat;
48696 }
48697 }
48698@@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
48699 ext4_grpblk_t counters[16];
48700 } sg;
48701
48702+ pax_track_stack();
48703+
48704 group--;
48705 if (group == 0)
48706 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
48707@@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *sb)
48708 if (sbi->s_mb_stats) {
48709 printk(KERN_INFO
48710 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
48711- atomic_read(&sbi->s_bal_allocated),
48712- atomic_read(&sbi->s_bal_reqs),
48713- atomic_read(&sbi->s_bal_success));
48714+ atomic_read_unchecked(&sbi->s_bal_allocated),
48715+ atomic_read_unchecked(&sbi->s_bal_reqs),
48716+ atomic_read_unchecked(&sbi->s_bal_success));
48717 printk(KERN_INFO
48718 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
48719 "%u 2^N hits, %u breaks, %u lost\n",
48720- atomic_read(&sbi->s_bal_ex_scanned),
48721- atomic_read(&sbi->s_bal_goals),
48722- atomic_read(&sbi->s_bal_2orders),
48723- atomic_read(&sbi->s_bal_breaks),
48724- atomic_read(&sbi->s_mb_lost_chunks));
48725+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48726+ atomic_read_unchecked(&sbi->s_bal_goals),
48727+ atomic_read_unchecked(&sbi->s_bal_2orders),
48728+ atomic_read_unchecked(&sbi->s_bal_breaks),
48729+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48730 printk(KERN_INFO
48731 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
48732 sbi->s_mb_buddies_generated++,
48733 sbi->s_mb_generation_time);
48734 printk(KERN_INFO
48735 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
48736- atomic_read(&sbi->s_mb_preallocated),
48737- atomic_read(&sbi->s_mb_discarded));
48738+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48739+ atomic_read_unchecked(&sbi->s_mb_discarded));
48740 }
48741
48742 free_percpu(sbi->s_locality_groups);
48743@@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48744 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48745
48746 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48747- atomic_inc(&sbi->s_bal_reqs);
48748- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48749+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48750+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48751 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
48752- atomic_inc(&sbi->s_bal_success);
48753- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48754+ atomic_inc_unchecked(&sbi->s_bal_success);
48755+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48756 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48757 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48758- atomic_inc(&sbi->s_bal_goals);
48759+ atomic_inc_unchecked(&sbi->s_bal_goals);
48760 if (ac->ac_found > sbi->s_mb_max_to_scan)
48761- atomic_inc(&sbi->s_bal_breaks);
48762+ atomic_inc_unchecked(&sbi->s_bal_breaks);
48763 }
48764
48765 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48766@@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48767 trace_ext4_mb_new_inode_pa(ac, pa);
48768
48769 ext4_mb_use_inode_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 ei = EXT4_I(ac->ac_inode);
48774 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48775@@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48776 trace_ext4_mb_new_group_pa(ac, pa);
48777
48778 ext4_mb_use_group_pa(ac, pa);
48779- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48780+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48781
48782 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48783 lg = ac->ac_lg;
48784@@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48785 * from the bitmap and continue.
48786 */
48787 }
48788- atomic_add(free, &sbi->s_mb_discarded);
48789+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
48790
48791 return err;
48792 }
48793@@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48794 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48795 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48796 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48797- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48798+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48799
48800 if (ac) {
48801 ac->ac_sb = sb;
48802diff --git a/fs/ext4/super.c b/fs/ext4/super.c
48803index f27e045..be5a1c3 100644
48804--- a/fs/ext4/super.c
48805+++ b/fs/ext4/super.c
48806@@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobject *kobj)
48807 }
48808
48809
48810-static struct sysfs_ops ext4_attr_ops = {
48811+static const struct sysfs_ops ext4_attr_ops = {
48812 .show = ext4_attr_show,
48813 .store = ext4_attr_store,
48814 };
48815diff --git a/fs/fcntl.c b/fs/fcntl.c
48816index 97e01dc..e9aab2d 100644
48817--- a/fs/fcntl.c
48818+++ b/fs/fcntl.c
48819@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48820 if (err)
48821 return err;
48822
48823+ if (gr_handle_chroot_fowner(pid, type))
48824+ return -ENOENT;
48825+ if (gr_check_protected_task_fowner(pid, type))
48826+ return -EACCES;
48827+
48828 f_modown(filp, pid, type, force);
48829 return 0;
48830 }
48831@@ -265,7 +270,7 @@ pid_t f_getown(struct file *filp)
48832
48833 static int f_setown_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 struct pid *pid;
48839 int type;
48840@@ -305,7 +310,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
48841
48842 static int f_getown_ex(struct file *filp, unsigned long arg)
48843 {
48844- struct f_owner_ex * __user owner_p = (void * __user)arg;
48845+ struct f_owner_ex __user *owner_p = (void __user *)arg;
48846 struct f_owner_ex owner;
48847 int ret = 0;
48848
48849@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
48850 switch (cmd) {
48851 case F_DUPFD:
48852 case F_DUPFD_CLOEXEC:
48853+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
48854 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
48855 break;
48856 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
48857diff --git a/fs/fifo.c b/fs/fifo.c
48858index f8f97b8..b1f2259 100644
48859--- a/fs/fifo.c
48860+++ b/fs/fifo.c
48861@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48862 */
48863 filp->f_op = &read_pipefifo_fops;
48864 pipe->r_counter++;
48865- if (pipe->readers++ == 0)
48866+ if (atomic_inc_return(&pipe->readers) == 1)
48867 wake_up_partner(inode);
48868
48869- if (!pipe->writers) {
48870+ if (!atomic_read(&pipe->writers)) {
48871 if ((filp->f_flags & O_NONBLOCK)) {
48872 /* suppress POLLHUP until we have
48873 * seen a writer */
48874@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48875 * errno=ENXIO when there is no process reading the FIFO.
48876 */
48877 ret = -ENXIO;
48878- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48879+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48880 goto err;
48881
48882 filp->f_op = &write_pipefifo_fops;
48883 pipe->w_counter++;
48884- if (!pipe->writers++)
48885+ if (atomic_inc_return(&pipe->writers) == 1)
48886 wake_up_partner(inode);
48887
48888- if (!pipe->readers) {
48889+ if (!atomic_read(&pipe->readers)) {
48890 wait_for_partner(inode, &pipe->r_counter);
48891 if (signal_pending(current))
48892 goto err_wr;
48893@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48894 */
48895 filp->f_op = &rdwr_pipefifo_fops;
48896
48897- pipe->readers++;
48898- pipe->writers++;
48899+ atomic_inc(&pipe->readers);
48900+ atomic_inc(&pipe->writers);
48901 pipe->r_counter++;
48902 pipe->w_counter++;
48903- if (pipe->readers == 1 || pipe->writers == 1)
48904+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48905 wake_up_partner(inode);
48906 break;
48907
48908@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48909 return 0;
48910
48911 err_rd:
48912- if (!--pipe->readers)
48913+ if (atomic_dec_and_test(&pipe->readers))
48914 wake_up_interruptible(&pipe->wait);
48915 ret = -ERESTARTSYS;
48916 goto err;
48917
48918 err_wr:
48919- if (!--pipe->writers)
48920+ if (atomic_dec_and_test(&pipe->writers))
48921 wake_up_interruptible(&pipe->wait);
48922 ret = -ERESTARTSYS;
48923 goto err;
48924
48925 err:
48926- if (!pipe->readers && !pipe->writers)
48927+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48928 free_pipe_info(inode);
48929
48930 err_nocleanup:
48931diff --git a/fs/file.c b/fs/file.c
48932index 87e1290..a930cc4 100644
48933--- a/fs/file.c
48934+++ b/fs/file.c
48935@@ -14,6 +14,7 @@
48936 #include <linux/slab.h>
48937 #include <linux/vmalloc.h>
48938 #include <linux/file.h>
48939+#include <linux/security.h>
48940 #include <linux/fdtable.h>
48941 #include <linux/bitops.h>
48942 #include <linux/interrupt.h>
48943@@ -257,6 +258,8 @@ int expand_files(struct files_struct *files, int nr)
48944 * N.B. For clone tasks sharing a files structure, this test
48945 * will limit the total number of files that can be opened.
48946 */
48947+
48948+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
48949 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
48950 return -EMFILE;
48951
48952diff --git a/fs/filesystems.c b/fs/filesystems.c
48953index a24c58e..53f91ee 100644
48954--- a/fs/filesystems.c
48955+++ b/fs/filesystems.c
48956@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(const char *name)
48957 int len = dot ? dot - name : strlen(name);
48958
48959 fs = __get_fs_type(name, len);
48960+
48961+#ifdef CONFIG_GRKERNSEC_MODHARDEN
48962+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48963+#else
48964 if (!fs && (request_module("%.*s", len, name) == 0))
48965+#endif
48966 fs = __get_fs_type(name, len);
48967
48968 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48969diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48970index eee0590..ef5bc0e 100644
48971--- a/fs/fs_struct.c
48972+++ b/fs/fs_struct.c
48973@@ -4,6 +4,7 @@
48974 #include <linux/path.h>
48975 #include <linux/slab.h>
48976 #include <linux/fs_struct.h>
48977+#include <linux/grsecurity.h>
48978
48979 /*
48980 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
48981@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48982 old_root = fs->root;
48983 fs->root = *path;
48984 path_get(path);
48985+ gr_set_chroot_entries(current, path);
48986 write_unlock(&fs->lock);
48987 if (old_root.dentry)
48988 path_put(&old_root);
48989@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48990 && fs->root.mnt == old_root->mnt) {
48991 path_get(new_root);
48992 fs->root = *new_root;
48993+ gr_set_chroot_entries(p, new_root);
48994 count++;
48995 }
48996 if (fs->pwd.dentry == old_root->dentry
48997@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
48998 task_lock(tsk);
48999 write_lock(&fs->lock);
49000 tsk->fs = NULL;
49001- kill = !--fs->users;
49002+ gr_clear_chroot_entries(tsk);
49003+ kill = !atomic_dec_return(&fs->users);
49004 write_unlock(&fs->lock);
49005 task_unlock(tsk);
49006 if (kill)
49007@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
49008 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
49009 /* We don't need to lock fs - think why ;-) */
49010 if (fs) {
49011- fs->users = 1;
49012+ atomic_set(&fs->users, 1);
49013 fs->in_exec = 0;
49014 rwlock_init(&fs->lock);
49015 fs->umask = old->umask;
49016@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
49017
49018 task_lock(current);
49019 write_lock(&fs->lock);
49020- kill = !--fs->users;
49021+ kill = !atomic_dec_return(&fs->users);
49022 current->fs = new_fs;
49023+ gr_set_chroot_entries(current, &new_fs->root);
49024 write_unlock(&fs->lock);
49025 task_unlock(current);
49026
49027@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
49028
49029 /* to be mentioned only in INIT_TASK */
49030 struct fs_struct init_fs = {
49031- .users = 1,
49032+ .users = ATOMIC_INIT(1),
49033 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
49034 .umask = 0022,
49035 };
49036@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
49037 task_lock(current);
49038
49039 write_lock(&init_fs.lock);
49040- init_fs.users++;
49041+ atomic_inc(&init_fs.users);
49042 write_unlock(&init_fs.lock);
49043
49044 write_lock(&fs->lock);
49045 current->fs = &init_fs;
49046- kill = !--fs->users;
49047+ gr_set_chroot_entries(current, &current->fs->root);
49048+ kill = !atomic_dec_return(&fs->users);
49049 write_unlock(&fs->lock);
49050
49051 task_unlock(current);
49052diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
49053index 9905350..02eaec4 100644
49054--- a/fs/fscache/cookie.c
49055+++ b/fs/fscache/cookie.c
49056@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
49057 parent ? (char *) parent->def->name : "<no-parent>",
49058 def->name, netfs_data);
49059
49060- fscache_stat(&fscache_n_acquires);
49061+ fscache_stat_unchecked(&fscache_n_acquires);
49062
49063 /* if there's no parent cookie, then we don't create one here either */
49064 if (!parent) {
49065- fscache_stat(&fscache_n_acquires_null);
49066+ fscache_stat_unchecked(&fscache_n_acquires_null);
49067 _leave(" [no parent]");
49068 return NULL;
49069 }
49070@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
49071 /* allocate and initialise a cookie */
49072 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
49073 if (!cookie) {
49074- fscache_stat(&fscache_n_acquires_oom);
49075+ fscache_stat_unchecked(&fscache_n_acquires_oom);
49076 _leave(" [ENOMEM]");
49077 return NULL;
49078 }
49079@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49080
49081 switch (cookie->def->type) {
49082 case FSCACHE_COOKIE_TYPE_INDEX:
49083- fscache_stat(&fscache_n_cookie_index);
49084+ fscache_stat_unchecked(&fscache_n_cookie_index);
49085 break;
49086 case FSCACHE_COOKIE_TYPE_DATAFILE:
49087- fscache_stat(&fscache_n_cookie_data);
49088+ fscache_stat_unchecked(&fscache_n_cookie_data);
49089 break;
49090 default:
49091- fscache_stat(&fscache_n_cookie_special);
49092+ fscache_stat_unchecked(&fscache_n_cookie_special);
49093 break;
49094 }
49095
49096@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49097 if (fscache_acquire_non_index_cookie(cookie) < 0) {
49098 atomic_dec(&parent->n_children);
49099 __fscache_cookie_put(cookie);
49100- fscache_stat(&fscache_n_acquires_nobufs);
49101+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
49102 _leave(" = NULL");
49103 return NULL;
49104 }
49105 }
49106
49107- fscache_stat(&fscache_n_acquires_ok);
49108+ fscache_stat_unchecked(&fscache_n_acquires_ok);
49109 _leave(" = %p", cookie);
49110 return cookie;
49111 }
49112@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
49113 cache = fscache_select_cache_for_object(cookie->parent);
49114 if (!cache) {
49115 up_read(&fscache_addremove_sem);
49116- fscache_stat(&fscache_n_acquires_no_cache);
49117+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
49118 _leave(" = -ENOMEDIUM [no cache]");
49119 return -ENOMEDIUM;
49120 }
49121@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
49122 object = cache->ops->alloc_object(cache, cookie);
49123 fscache_stat_d(&fscache_n_cop_alloc_object);
49124 if (IS_ERR(object)) {
49125- fscache_stat(&fscache_n_object_no_alloc);
49126+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
49127 ret = PTR_ERR(object);
49128 goto error;
49129 }
49130
49131- fscache_stat(&fscache_n_object_alloc);
49132+ fscache_stat_unchecked(&fscache_n_object_alloc);
49133
49134 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
49135
49136@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
49137 struct fscache_object *object;
49138 struct hlist_node *_p;
49139
49140- fscache_stat(&fscache_n_updates);
49141+ fscache_stat_unchecked(&fscache_n_updates);
49142
49143 if (!cookie) {
49144- fscache_stat(&fscache_n_updates_null);
49145+ fscache_stat_unchecked(&fscache_n_updates_null);
49146 _leave(" [no cookie]");
49147 return;
49148 }
49149@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49150 struct fscache_object *object;
49151 unsigned long event;
49152
49153- fscache_stat(&fscache_n_relinquishes);
49154+ fscache_stat_unchecked(&fscache_n_relinquishes);
49155 if (retire)
49156- fscache_stat(&fscache_n_relinquishes_retire);
49157+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
49158
49159 if (!cookie) {
49160- fscache_stat(&fscache_n_relinquishes_null);
49161+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
49162 _leave(" [no cookie]");
49163 return;
49164 }
49165@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49166
49167 /* wait for the cookie to finish being instantiated (or to fail) */
49168 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
49169- fscache_stat(&fscache_n_relinquishes_waitcrt);
49170+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
49171 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
49172 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
49173 }
49174diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
49175index edd7434..0725e66 100644
49176--- a/fs/fscache/internal.h
49177+++ b/fs/fscache/internal.h
49178@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
49179 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
49180 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
49181
49182-extern atomic_t fscache_n_op_pend;
49183-extern atomic_t fscache_n_op_run;
49184-extern atomic_t fscache_n_op_enqueue;
49185-extern atomic_t fscache_n_op_deferred_release;
49186-extern atomic_t fscache_n_op_release;
49187-extern atomic_t fscache_n_op_gc;
49188-extern atomic_t fscache_n_op_cancelled;
49189-extern atomic_t fscache_n_op_rejected;
49190+extern atomic_unchecked_t fscache_n_op_pend;
49191+extern atomic_unchecked_t fscache_n_op_run;
49192+extern atomic_unchecked_t fscache_n_op_enqueue;
49193+extern atomic_unchecked_t fscache_n_op_deferred_release;
49194+extern atomic_unchecked_t fscache_n_op_release;
49195+extern atomic_unchecked_t fscache_n_op_gc;
49196+extern atomic_unchecked_t fscache_n_op_cancelled;
49197+extern atomic_unchecked_t fscache_n_op_rejected;
49198
49199-extern atomic_t fscache_n_attr_changed;
49200-extern atomic_t fscache_n_attr_changed_ok;
49201-extern atomic_t fscache_n_attr_changed_nobufs;
49202-extern atomic_t fscache_n_attr_changed_nomem;
49203-extern atomic_t fscache_n_attr_changed_calls;
49204+extern atomic_unchecked_t fscache_n_attr_changed;
49205+extern atomic_unchecked_t fscache_n_attr_changed_ok;
49206+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
49207+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
49208+extern atomic_unchecked_t fscache_n_attr_changed_calls;
49209
49210-extern atomic_t fscache_n_allocs;
49211-extern atomic_t fscache_n_allocs_ok;
49212-extern atomic_t fscache_n_allocs_wait;
49213-extern atomic_t fscache_n_allocs_nobufs;
49214-extern atomic_t fscache_n_allocs_intr;
49215-extern atomic_t fscache_n_allocs_object_dead;
49216-extern atomic_t fscache_n_alloc_ops;
49217-extern atomic_t fscache_n_alloc_op_waits;
49218+extern atomic_unchecked_t fscache_n_allocs;
49219+extern atomic_unchecked_t fscache_n_allocs_ok;
49220+extern atomic_unchecked_t fscache_n_allocs_wait;
49221+extern atomic_unchecked_t fscache_n_allocs_nobufs;
49222+extern atomic_unchecked_t fscache_n_allocs_intr;
49223+extern atomic_unchecked_t fscache_n_allocs_object_dead;
49224+extern atomic_unchecked_t fscache_n_alloc_ops;
49225+extern atomic_unchecked_t fscache_n_alloc_op_waits;
49226
49227-extern atomic_t fscache_n_retrievals;
49228-extern atomic_t fscache_n_retrievals_ok;
49229-extern atomic_t fscache_n_retrievals_wait;
49230-extern atomic_t fscache_n_retrievals_nodata;
49231-extern atomic_t fscache_n_retrievals_nobufs;
49232-extern atomic_t fscache_n_retrievals_intr;
49233-extern atomic_t fscache_n_retrievals_nomem;
49234-extern atomic_t fscache_n_retrievals_object_dead;
49235-extern atomic_t fscache_n_retrieval_ops;
49236-extern atomic_t fscache_n_retrieval_op_waits;
49237+extern atomic_unchecked_t fscache_n_retrievals;
49238+extern atomic_unchecked_t fscache_n_retrievals_ok;
49239+extern atomic_unchecked_t fscache_n_retrievals_wait;
49240+extern atomic_unchecked_t fscache_n_retrievals_nodata;
49241+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
49242+extern atomic_unchecked_t fscache_n_retrievals_intr;
49243+extern atomic_unchecked_t fscache_n_retrievals_nomem;
49244+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
49245+extern atomic_unchecked_t fscache_n_retrieval_ops;
49246+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
49247
49248-extern atomic_t fscache_n_stores;
49249-extern atomic_t fscache_n_stores_ok;
49250-extern atomic_t fscache_n_stores_again;
49251-extern atomic_t fscache_n_stores_nobufs;
49252-extern atomic_t fscache_n_stores_oom;
49253-extern atomic_t fscache_n_store_ops;
49254-extern atomic_t fscache_n_store_calls;
49255-extern atomic_t fscache_n_store_pages;
49256-extern atomic_t fscache_n_store_radix_deletes;
49257-extern atomic_t fscache_n_store_pages_over_limit;
49258+extern atomic_unchecked_t fscache_n_stores;
49259+extern atomic_unchecked_t fscache_n_stores_ok;
49260+extern atomic_unchecked_t fscache_n_stores_again;
49261+extern atomic_unchecked_t fscache_n_stores_nobufs;
49262+extern atomic_unchecked_t fscache_n_stores_oom;
49263+extern atomic_unchecked_t fscache_n_store_ops;
49264+extern atomic_unchecked_t fscache_n_store_calls;
49265+extern atomic_unchecked_t fscache_n_store_pages;
49266+extern atomic_unchecked_t fscache_n_store_radix_deletes;
49267+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
49268
49269-extern atomic_t fscache_n_store_vmscan_not_storing;
49270-extern atomic_t fscache_n_store_vmscan_gone;
49271-extern atomic_t fscache_n_store_vmscan_busy;
49272-extern atomic_t fscache_n_store_vmscan_cancelled;
49273+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49274+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
49275+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
49276+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49277
49278-extern atomic_t fscache_n_marks;
49279-extern atomic_t fscache_n_uncaches;
49280+extern atomic_unchecked_t fscache_n_marks;
49281+extern atomic_unchecked_t fscache_n_uncaches;
49282
49283-extern atomic_t fscache_n_acquires;
49284-extern atomic_t fscache_n_acquires_null;
49285-extern atomic_t fscache_n_acquires_no_cache;
49286-extern atomic_t fscache_n_acquires_ok;
49287-extern atomic_t fscache_n_acquires_nobufs;
49288-extern atomic_t fscache_n_acquires_oom;
49289+extern atomic_unchecked_t fscache_n_acquires;
49290+extern atomic_unchecked_t fscache_n_acquires_null;
49291+extern atomic_unchecked_t fscache_n_acquires_no_cache;
49292+extern atomic_unchecked_t fscache_n_acquires_ok;
49293+extern atomic_unchecked_t fscache_n_acquires_nobufs;
49294+extern atomic_unchecked_t fscache_n_acquires_oom;
49295
49296-extern atomic_t fscache_n_updates;
49297-extern atomic_t fscache_n_updates_null;
49298-extern atomic_t fscache_n_updates_run;
49299+extern atomic_unchecked_t fscache_n_updates;
49300+extern atomic_unchecked_t fscache_n_updates_null;
49301+extern atomic_unchecked_t fscache_n_updates_run;
49302
49303-extern atomic_t fscache_n_relinquishes;
49304-extern atomic_t fscache_n_relinquishes_null;
49305-extern atomic_t fscache_n_relinquishes_waitcrt;
49306-extern atomic_t fscache_n_relinquishes_retire;
49307+extern atomic_unchecked_t fscache_n_relinquishes;
49308+extern atomic_unchecked_t fscache_n_relinquishes_null;
49309+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49310+extern atomic_unchecked_t fscache_n_relinquishes_retire;
49311
49312-extern atomic_t fscache_n_cookie_index;
49313-extern atomic_t fscache_n_cookie_data;
49314-extern atomic_t fscache_n_cookie_special;
49315+extern atomic_unchecked_t fscache_n_cookie_index;
49316+extern atomic_unchecked_t fscache_n_cookie_data;
49317+extern atomic_unchecked_t fscache_n_cookie_special;
49318
49319-extern atomic_t fscache_n_object_alloc;
49320-extern atomic_t fscache_n_object_no_alloc;
49321-extern atomic_t fscache_n_object_lookups;
49322-extern atomic_t fscache_n_object_lookups_negative;
49323-extern atomic_t fscache_n_object_lookups_positive;
49324-extern atomic_t fscache_n_object_lookups_timed_out;
49325-extern atomic_t fscache_n_object_created;
49326-extern atomic_t fscache_n_object_avail;
49327-extern atomic_t fscache_n_object_dead;
49328+extern atomic_unchecked_t fscache_n_object_alloc;
49329+extern atomic_unchecked_t fscache_n_object_no_alloc;
49330+extern atomic_unchecked_t fscache_n_object_lookups;
49331+extern atomic_unchecked_t fscache_n_object_lookups_negative;
49332+extern atomic_unchecked_t fscache_n_object_lookups_positive;
49333+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
49334+extern atomic_unchecked_t fscache_n_object_created;
49335+extern atomic_unchecked_t fscache_n_object_avail;
49336+extern atomic_unchecked_t fscache_n_object_dead;
49337
49338-extern atomic_t fscache_n_checkaux_none;
49339-extern atomic_t fscache_n_checkaux_okay;
49340-extern atomic_t fscache_n_checkaux_update;
49341-extern atomic_t fscache_n_checkaux_obsolete;
49342+extern atomic_unchecked_t fscache_n_checkaux_none;
49343+extern atomic_unchecked_t fscache_n_checkaux_okay;
49344+extern atomic_unchecked_t fscache_n_checkaux_update;
49345+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
49346
49347 extern atomic_t fscache_n_cop_alloc_object;
49348 extern atomic_t fscache_n_cop_lookup_object;
49349@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t *stat)
49350 atomic_inc(stat);
49351 }
49352
49353+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
49354+{
49355+ atomic_inc_unchecked(stat);
49356+}
49357+
49358 static inline void fscache_stat_d(atomic_t *stat)
49359 {
49360 atomic_dec(stat);
49361@@ -259,6 +264,7 @@ extern const struct file_operations fscache_stats_fops;
49362
49363 #define __fscache_stat(stat) (NULL)
49364 #define fscache_stat(stat) do {} while (0)
49365+#define fscache_stat_unchecked(stat) do {} while (0)
49366 #define fscache_stat_d(stat) do {} while (0)
49367 #endif
49368
49369diff --git a/fs/fscache/object.c b/fs/fscache/object.c
49370index e513ac5..e888d34 100644
49371--- a/fs/fscache/object.c
49372+++ b/fs/fscache/object.c
49373@@ -144,7 +144,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49374 /* update the object metadata on disk */
49375 case FSCACHE_OBJECT_UPDATING:
49376 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
49377- fscache_stat(&fscache_n_updates_run);
49378+ fscache_stat_unchecked(&fscache_n_updates_run);
49379 fscache_stat(&fscache_n_cop_update_object);
49380 object->cache->ops->update_object(object);
49381 fscache_stat_d(&fscache_n_cop_update_object);
49382@@ -233,7 +233,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 /* handle the parent cache of this object being withdrawn from
49391@@ -248,7 +248,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49392 spin_lock(&object->lock);
49393 object->state = FSCACHE_OBJECT_DEAD;
49394 spin_unlock(&object->lock);
49395- fscache_stat(&fscache_n_object_dead);
49396+ fscache_stat_unchecked(&fscache_n_object_dead);
49397 goto terminal_transit;
49398
49399 /* complain about the object being woken up once it is
49400@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49401 parent->cookie->def->name, cookie->def->name,
49402 object->cache->tag->name);
49403
49404- fscache_stat(&fscache_n_object_lookups);
49405+ fscache_stat_unchecked(&fscache_n_object_lookups);
49406 fscache_stat(&fscache_n_cop_lookup_object);
49407 ret = object->cache->ops->lookup_object(object);
49408 fscache_stat_d(&fscache_n_cop_lookup_object);
49409@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49410 if (ret == -ETIMEDOUT) {
49411 /* probably stuck behind another object, so move this one to
49412 * the back of the queue */
49413- fscache_stat(&fscache_n_object_lookups_timed_out);
49414+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49415 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49416 }
49417
49418@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49419
49420 spin_lock(&object->lock);
49421 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49422- fscache_stat(&fscache_n_object_lookups_negative);
49423+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49424
49425 /* transit here to allow write requests to begin stacking up
49426 * and read requests to begin returning ENODATA */
49427@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fscache_object *object)
49428 * result, in which case there may be data available */
49429 spin_lock(&object->lock);
49430 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49431- fscache_stat(&fscache_n_object_lookups_positive);
49432+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49433
49434 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49435
49436@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fscache_object *object)
49437 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49438 } else {
49439 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49440- fscache_stat(&fscache_n_object_created);
49441+ fscache_stat_unchecked(&fscache_n_object_created);
49442
49443 object->state = FSCACHE_OBJECT_AVAILABLE;
49444 spin_unlock(&object->lock);
49445@@ -633,7 +633,7 @@ static void fscache_object_available(struct fscache_object *object)
49446 fscache_enqueue_dependents(object);
49447
49448 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49449- fscache_stat(&fscache_n_object_avail);
49450+ fscache_stat_unchecked(&fscache_n_object_avail);
49451
49452 _leave("");
49453 }
49454@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49455 enum fscache_checkaux result;
49456
49457 if (!object->cookie->def->check_aux) {
49458- fscache_stat(&fscache_n_checkaux_none);
49459+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49460 return FSCACHE_CHECKAUX_OKAY;
49461 }
49462
49463@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49464 switch (result) {
49465 /* entry okay as is */
49466 case FSCACHE_CHECKAUX_OKAY:
49467- fscache_stat(&fscache_n_checkaux_okay);
49468+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49469 break;
49470
49471 /* entry requires update */
49472 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49473- fscache_stat(&fscache_n_checkaux_update);
49474+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49475 break;
49476
49477 /* entry requires deletion */
49478 case FSCACHE_CHECKAUX_OBSOLETE:
49479- fscache_stat(&fscache_n_checkaux_obsolete);
49480+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49481 break;
49482
49483 default:
49484diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49485index 313e79a..775240f 100644
49486--- a/fs/fscache/operation.c
49487+++ b/fs/fscache/operation.c
49488@@ -16,7 +16,7 @@
49489 #include <linux/seq_file.h>
49490 #include "internal.h"
49491
49492-atomic_t fscache_op_debug_id;
49493+atomic_unchecked_t fscache_op_debug_id;
49494 EXPORT_SYMBOL(fscache_op_debug_id);
49495
49496 /**
49497@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49498 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
49499 ASSERTCMP(atomic_read(&op->usage), >, 0);
49500
49501- fscache_stat(&fscache_n_op_enqueue);
49502+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49503 switch (op->flags & FSCACHE_OP_TYPE) {
49504 case FSCACHE_OP_FAST:
49505 _debug("queue fast");
49506@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscache_object *object,
49507 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49508 if (op->processor)
49509 fscache_enqueue_operation(op);
49510- fscache_stat(&fscache_n_op_run);
49511+ fscache_stat_unchecked(&fscache_n_op_run);
49512 }
49513
49514 /*
49515@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49516 if (object->n_ops > 0) {
49517 atomic_inc(&op->usage);
49518 list_add_tail(&op->pend_link, &object->pending_ops);
49519- fscache_stat(&fscache_n_op_pend);
49520+ fscache_stat_unchecked(&fscache_n_op_pend);
49521 } else if (!list_empty(&object->pending_ops)) {
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 fscache_start_operations(object);
49527 } else {
49528 ASSERTCMP(object->n_in_progress, ==, 0);
49529@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49530 object->n_exclusive++; /* reads and writes must wait */
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 ret = 0;
49536 } else {
49537 /* not allowed to submit ops in any other state */
49538@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_object *object,
49539 if (object->n_exclusive > 0) {
49540 atomic_inc(&op->usage);
49541 list_add_tail(&op->pend_link, &object->pending_ops);
49542- fscache_stat(&fscache_n_op_pend);
49543+ fscache_stat_unchecked(&fscache_n_op_pend);
49544 } else if (!list_empty(&object->pending_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 fscache_start_operations(object);
49550 } else {
49551 ASSERTCMP(object->n_exclusive, ==, 0);
49552@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_object *object,
49553 object->n_ops++;
49554 atomic_inc(&op->usage);
49555 list_add_tail(&op->pend_link, &object->pending_ops);
49556- fscache_stat(&fscache_n_op_pend);
49557+ fscache_stat_unchecked(&fscache_n_op_pend);
49558 ret = 0;
49559 } else if (object->state == FSCACHE_OBJECT_DYING ||
49560 object->state == FSCACHE_OBJECT_LC_DYING ||
49561 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49562- fscache_stat(&fscache_n_op_rejected);
49563+ fscache_stat_unchecked(&fscache_n_op_rejected);
49564 ret = -ENOBUFS;
49565 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49566 fscache_report_unexpected_submission(object, op, ostate);
49567@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_operation *op)
49568
49569 ret = -EBUSY;
49570 if (!list_empty(&op->pend_link)) {
49571- fscache_stat(&fscache_n_op_cancelled);
49572+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49573 list_del_init(&op->pend_link);
49574 object->n_ops--;
49575 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
49576@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscache_operation *op)
49577 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
49578 BUG();
49579
49580- fscache_stat(&fscache_n_op_release);
49581+ fscache_stat_unchecked(&fscache_n_op_release);
49582
49583 if (op->release) {
49584 op->release(op);
49585@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscache_operation *op)
49586 * lock, and defer it otherwise */
49587 if (!spin_trylock(&object->lock)) {
49588 _debug("defer put");
49589- fscache_stat(&fscache_n_op_deferred_release);
49590+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49591
49592 cache = object->cache;
49593 spin_lock(&cache->op_gc_list_lock);
49594@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_struct *work)
49595
49596 _debug("GC DEFERRED REL OBJ%x OP%x",
49597 object->debug_id, op->debug_id);
49598- fscache_stat(&fscache_n_op_gc);
49599+ fscache_stat_unchecked(&fscache_n_op_gc);
49600
49601 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49602
49603diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49604index c598ea4..6aac13e 100644
49605--- a/fs/fscache/page.c
49606+++ b/fs/fscache/page.c
49607@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49608 val = radix_tree_lookup(&cookie->stores, page->index);
49609 if (!val) {
49610 rcu_read_unlock();
49611- fscache_stat(&fscache_n_store_vmscan_not_storing);
49612+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49613 __fscache_uncache_page(cookie, page);
49614 return true;
49615 }
49616@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49617 spin_unlock(&cookie->stores_lock);
49618
49619 if (xpage) {
49620- fscache_stat(&fscache_n_store_vmscan_cancelled);
49621- fscache_stat(&fscache_n_store_radix_deletes);
49622+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49623+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49624 ASSERTCMP(xpage, ==, page);
49625 } else {
49626- fscache_stat(&fscache_n_store_vmscan_gone);
49627+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49628 }
49629
49630 wake_up_bit(&cookie->flags, 0);
49631@@ -106,7 +106,7 @@ page_busy:
49632 /* we might want to wait here, but that could deadlock the allocator as
49633 * the slow-work threads writing to the cache may all end up sleeping
49634 * on memory allocation */
49635- fscache_stat(&fscache_n_store_vmscan_busy);
49636+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49637 return false;
49638 }
49639 EXPORT_SYMBOL(__fscache_maybe_release_page);
49640@@ -130,7 +130,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49641 FSCACHE_COOKIE_STORING_TAG);
49642 if (!radix_tree_tag_get(&cookie->stores, page->index,
49643 FSCACHE_COOKIE_PENDING_TAG)) {
49644- fscache_stat(&fscache_n_store_radix_deletes);
49645+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49646 xpage = radix_tree_delete(&cookie->stores, page->index);
49647 }
49648 spin_unlock(&cookie->stores_lock);
49649@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49650
49651 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49652
49653- fscache_stat(&fscache_n_attr_changed_calls);
49654+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49655
49656 if (fscache_object_is_active(object)) {
49657 fscache_set_op_state(op, "CallFS");
49658@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49659
49660 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49661
49662- fscache_stat(&fscache_n_attr_changed);
49663+ fscache_stat_unchecked(&fscache_n_attr_changed);
49664
49665 op = kzalloc(sizeof(*op), GFP_KERNEL);
49666 if (!op) {
49667- fscache_stat(&fscache_n_attr_changed_nomem);
49668+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49669 _leave(" = -ENOMEM");
49670 return -ENOMEM;
49671 }
49672@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49673 if (fscache_submit_exclusive_op(object, op) < 0)
49674 goto nobufs;
49675 spin_unlock(&cookie->lock);
49676- fscache_stat(&fscache_n_attr_changed_ok);
49677+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49678 fscache_put_operation(op);
49679 _leave(" = 0");
49680 return 0;
49681@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49682 nobufs:
49683 spin_unlock(&cookie->lock);
49684 kfree(op);
49685- fscache_stat(&fscache_n_attr_changed_nobufs);
49686+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49687 _leave(" = %d", -ENOBUFS);
49688 return -ENOBUFS;
49689 }
49690@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49691 /* allocate a retrieval operation and attempt to submit it */
49692 op = kzalloc(sizeof(*op), GFP_NOIO);
49693 if (!op) {
49694- fscache_stat(&fscache_n_retrievals_nomem);
49695+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49696 return NULL;
49697 }
49698
49699@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49700 return 0;
49701 }
49702
49703- fscache_stat(&fscache_n_retrievals_wait);
49704+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49705
49706 jif = jiffies;
49707 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49708 fscache_wait_bit_interruptible,
49709 TASK_INTERRUPTIBLE) != 0) {
49710- fscache_stat(&fscache_n_retrievals_intr);
49711+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49712 _leave(" = -ERESTARTSYS");
49713 return -ERESTARTSYS;
49714 }
49715@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49716 */
49717 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49718 struct fscache_retrieval *op,
49719- atomic_t *stat_op_waits,
49720- atomic_t *stat_object_dead)
49721+ atomic_unchecked_t *stat_op_waits,
49722+ atomic_unchecked_t *stat_object_dead)
49723 {
49724 int ret;
49725
49726@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49727 goto check_if_dead;
49728
49729 _debug(">>> WT");
49730- fscache_stat(stat_op_waits);
49731+ fscache_stat_unchecked(stat_op_waits);
49732 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49733 fscache_wait_bit_interruptible,
49734 TASK_INTERRUPTIBLE) < 0) {
49735@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49736
49737 check_if_dead:
49738 if (unlikely(fscache_object_is_dead(object))) {
49739- fscache_stat(stat_object_dead);
49740+ fscache_stat_unchecked(stat_object_dead);
49741 return -ENOBUFS;
49742 }
49743 return 0;
49744@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49745
49746 _enter("%p,%p,,,", cookie, page);
49747
49748- fscache_stat(&fscache_n_retrievals);
49749+ fscache_stat_unchecked(&fscache_n_retrievals);
49750
49751 if (hlist_empty(&cookie->backing_objects))
49752 goto nobufs;
49753@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49754 goto nobufs_unlock;
49755 spin_unlock(&cookie->lock);
49756
49757- fscache_stat(&fscache_n_retrieval_ops);
49758+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49759
49760 /* pin the netfs read context in case we need to do the actual netfs
49761 * read because we've encountered a cache read failure */
49762@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49763
49764 error:
49765 if (ret == -ENOMEM)
49766- fscache_stat(&fscache_n_retrievals_nomem);
49767+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49768 else if (ret == -ERESTARTSYS)
49769- fscache_stat(&fscache_n_retrievals_intr);
49770+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49771 else if (ret == -ENODATA)
49772- fscache_stat(&fscache_n_retrievals_nodata);
49773+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49774 else if (ret < 0)
49775- fscache_stat(&fscache_n_retrievals_nobufs);
49776+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49777 else
49778- fscache_stat(&fscache_n_retrievals_ok);
49779+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49780
49781 fscache_put_retrieval(op);
49782 _leave(" = %d", ret);
49783@@ -453,7 +453,7 @@ nobufs_unlock:
49784 spin_unlock(&cookie->lock);
49785 kfree(op);
49786 nobufs:
49787- fscache_stat(&fscache_n_retrievals_nobufs);
49788+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49789 _leave(" = -ENOBUFS");
49790 return -ENOBUFS;
49791 }
49792@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49793
49794 _enter("%p,,%d,,,", cookie, *nr_pages);
49795
49796- fscache_stat(&fscache_n_retrievals);
49797+ fscache_stat_unchecked(&fscache_n_retrievals);
49798
49799 if (hlist_empty(&cookie->backing_objects))
49800 goto nobufs;
49801@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49802 goto nobufs_unlock;
49803 spin_unlock(&cookie->lock);
49804
49805- fscache_stat(&fscache_n_retrieval_ops);
49806+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49807
49808 /* pin the netfs read context in case we need to do the actual netfs
49809 * read because we've encountered a cache read failure */
49810@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49811
49812 error:
49813 if (ret == -ENOMEM)
49814- fscache_stat(&fscache_n_retrievals_nomem);
49815+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49816 else if (ret == -ERESTARTSYS)
49817- fscache_stat(&fscache_n_retrievals_intr);
49818+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49819 else if (ret == -ENODATA)
49820- fscache_stat(&fscache_n_retrievals_nodata);
49821+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49822 else if (ret < 0)
49823- fscache_stat(&fscache_n_retrievals_nobufs);
49824+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49825 else
49826- fscache_stat(&fscache_n_retrievals_ok);
49827+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49828
49829 fscache_put_retrieval(op);
49830 _leave(" = %d", ret);
49831@@ -570,7 +570,7 @@ nobufs_unlock:
49832 spin_unlock(&cookie->lock);
49833 kfree(op);
49834 nobufs:
49835- fscache_stat(&fscache_n_retrievals_nobufs);
49836+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49837 _leave(" = -ENOBUFS");
49838 return -ENOBUFS;
49839 }
49840@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49841
49842 _enter("%p,%p,,,", cookie, page);
49843
49844- fscache_stat(&fscache_n_allocs);
49845+ fscache_stat_unchecked(&fscache_n_allocs);
49846
49847 if (hlist_empty(&cookie->backing_objects))
49848 goto nobufs;
49849@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49850 goto nobufs_unlock;
49851 spin_unlock(&cookie->lock);
49852
49853- fscache_stat(&fscache_n_alloc_ops);
49854+ fscache_stat_unchecked(&fscache_n_alloc_ops);
49855
49856 ret = fscache_wait_for_retrieval_activation(
49857 object, op,
49858@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49859
49860 error:
49861 if (ret == -ERESTARTSYS)
49862- fscache_stat(&fscache_n_allocs_intr);
49863+ fscache_stat_unchecked(&fscache_n_allocs_intr);
49864 else if (ret < 0)
49865- fscache_stat(&fscache_n_allocs_nobufs);
49866+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49867 else
49868- fscache_stat(&fscache_n_allocs_ok);
49869+ fscache_stat_unchecked(&fscache_n_allocs_ok);
49870
49871 fscache_put_retrieval(op);
49872 _leave(" = %d", ret);
49873@@ -651,7 +651,7 @@ nobufs_unlock:
49874 spin_unlock(&cookie->lock);
49875 kfree(op);
49876 nobufs:
49877- fscache_stat(&fscache_n_allocs_nobufs);
49878+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49879 _leave(" = -ENOBUFS");
49880 return -ENOBUFS;
49881 }
49882@@ -694,7 +694,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49883
49884 spin_lock(&cookie->stores_lock);
49885
49886- fscache_stat(&fscache_n_store_calls);
49887+ fscache_stat_unchecked(&fscache_n_store_calls);
49888
49889 /* find a page to store */
49890 page = NULL;
49891@@ -705,7 +705,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49892 page = results[0];
49893 _debug("gang %d [%lx]", n, page->index);
49894 if (page->index > op->store_limit) {
49895- fscache_stat(&fscache_n_store_pages_over_limit);
49896+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49897 goto superseded;
49898 }
49899
49900@@ -721,7 +721,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49901
49902 if (page) {
49903 fscache_set_op_state(&op->op, "Store");
49904- fscache_stat(&fscache_n_store_pages);
49905+ fscache_stat_unchecked(&fscache_n_store_pages);
49906 fscache_stat(&fscache_n_cop_write_page);
49907 ret = object->cache->ops->write_page(op, page);
49908 fscache_stat_d(&fscache_n_cop_write_page);
49909@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49910 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49911 ASSERT(PageFsCache(page));
49912
49913- fscache_stat(&fscache_n_stores);
49914+ fscache_stat_unchecked(&fscache_n_stores);
49915
49916 op = kzalloc(sizeof(*op), GFP_NOIO);
49917 if (!op)
49918@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49919 spin_unlock(&cookie->stores_lock);
49920 spin_unlock(&object->lock);
49921
49922- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49923+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49924 op->store_limit = object->store_limit;
49925
49926 if (fscache_submit_op(object, &op->op) < 0)
49927@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49928
49929 spin_unlock(&cookie->lock);
49930 radix_tree_preload_end();
49931- fscache_stat(&fscache_n_store_ops);
49932- fscache_stat(&fscache_n_stores_ok);
49933+ fscache_stat_unchecked(&fscache_n_store_ops);
49934+ fscache_stat_unchecked(&fscache_n_stores_ok);
49935
49936 /* the slow work queue now carries its own ref on the object */
49937 fscache_put_operation(&op->op);
49938@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49939 return 0;
49940
49941 already_queued:
49942- fscache_stat(&fscache_n_stores_again);
49943+ fscache_stat_unchecked(&fscache_n_stores_again);
49944 already_pending:
49945 spin_unlock(&cookie->stores_lock);
49946 spin_unlock(&object->lock);
49947 spin_unlock(&cookie->lock);
49948 radix_tree_preload_end();
49949 kfree(op);
49950- fscache_stat(&fscache_n_stores_ok);
49951+ fscache_stat_unchecked(&fscache_n_stores_ok);
49952 _leave(" = 0");
49953 return 0;
49954
49955@@ -886,14 +886,14 @@ nobufs:
49956 spin_unlock(&cookie->lock);
49957 radix_tree_preload_end();
49958 kfree(op);
49959- fscache_stat(&fscache_n_stores_nobufs);
49960+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
49961 _leave(" = -ENOBUFS");
49962 return -ENOBUFS;
49963
49964 nomem_free:
49965 kfree(op);
49966 nomem:
49967- fscache_stat(&fscache_n_stores_oom);
49968+ fscache_stat_unchecked(&fscache_n_stores_oom);
49969 _leave(" = -ENOMEM");
49970 return -ENOMEM;
49971 }
49972@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49973 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49974 ASSERTCMP(page, !=, NULL);
49975
49976- fscache_stat(&fscache_n_uncaches);
49977+ fscache_stat_unchecked(&fscache_n_uncaches);
49978
49979 /* cache withdrawal may beat us to it */
49980 if (!PageFsCache(page))
49981@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
49982 unsigned long loop;
49983
49984 #ifdef CONFIG_FSCACHE_STATS
49985- atomic_add(pagevec->nr, &fscache_n_marks);
49986+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
49987 #endif
49988
49989 for (loop = 0; loop < pagevec->nr; loop++) {
49990diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49991index 46435f3..8cddf18 100644
49992--- a/fs/fscache/stats.c
49993+++ b/fs/fscache/stats.c
49994@@ -18,95 +18,95 @@
49995 /*
49996 * operation counters
49997 */
49998-atomic_t fscache_n_op_pend;
49999-atomic_t fscache_n_op_run;
50000-atomic_t fscache_n_op_enqueue;
50001-atomic_t fscache_n_op_requeue;
50002-atomic_t fscache_n_op_deferred_release;
50003-atomic_t fscache_n_op_release;
50004-atomic_t fscache_n_op_gc;
50005-atomic_t fscache_n_op_cancelled;
50006-atomic_t fscache_n_op_rejected;
50007+atomic_unchecked_t fscache_n_op_pend;
50008+atomic_unchecked_t fscache_n_op_run;
50009+atomic_unchecked_t fscache_n_op_enqueue;
50010+atomic_unchecked_t fscache_n_op_requeue;
50011+atomic_unchecked_t fscache_n_op_deferred_release;
50012+atomic_unchecked_t fscache_n_op_release;
50013+atomic_unchecked_t fscache_n_op_gc;
50014+atomic_unchecked_t fscache_n_op_cancelled;
50015+atomic_unchecked_t fscache_n_op_rejected;
50016
50017-atomic_t fscache_n_attr_changed;
50018-atomic_t fscache_n_attr_changed_ok;
50019-atomic_t fscache_n_attr_changed_nobufs;
50020-atomic_t fscache_n_attr_changed_nomem;
50021-atomic_t fscache_n_attr_changed_calls;
50022+atomic_unchecked_t fscache_n_attr_changed;
50023+atomic_unchecked_t fscache_n_attr_changed_ok;
50024+atomic_unchecked_t fscache_n_attr_changed_nobufs;
50025+atomic_unchecked_t fscache_n_attr_changed_nomem;
50026+atomic_unchecked_t fscache_n_attr_changed_calls;
50027
50028-atomic_t fscache_n_allocs;
50029-atomic_t fscache_n_allocs_ok;
50030-atomic_t fscache_n_allocs_wait;
50031-atomic_t fscache_n_allocs_nobufs;
50032-atomic_t fscache_n_allocs_intr;
50033-atomic_t fscache_n_allocs_object_dead;
50034-atomic_t fscache_n_alloc_ops;
50035-atomic_t fscache_n_alloc_op_waits;
50036+atomic_unchecked_t fscache_n_allocs;
50037+atomic_unchecked_t fscache_n_allocs_ok;
50038+atomic_unchecked_t fscache_n_allocs_wait;
50039+atomic_unchecked_t fscache_n_allocs_nobufs;
50040+atomic_unchecked_t fscache_n_allocs_intr;
50041+atomic_unchecked_t fscache_n_allocs_object_dead;
50042+atomic_unchecked_t fscache_n_alloc_ops;
50043+atomic_unchecked_t fscache_n_alloc_op_waits;
50044
50045-atomic_t fscache_n_retrievals;
50046-atomic_t fscache_n_retrievals_ok;
50047-atomic_t fscache_n_retrievals_wait;
50048-atomic_t fscache_n_retrievals_nodata;
50049-atomic_t fscache_n_retrievals_nobufs;
50050-atomic_t fscache_n_retrievals_intr;
50051-atomic_t fscache_n_retrievals_nomem;
50052-atomic_t fscache_n_retrievals_object_dead;
50053-atomic_t fscache_n_retrieval_ops;
50054-atomic_t fscache_n_retrieval_op_waits;
50055+atomic_unchecked_t fscache_n_retrievals;
50056+atomic_unchecked_t fscache_n_retrievals_ok;
50057+atomic_unchecked_t fscache_n_retrievals_wait;
50058+atomic_unchecked_t fscache_n_retrievals_nodata;
50059+atomic_unchecked_t fscache_n_retrievals_nobufs;
50060+atomic_unchecked_t fscache_n_retrievals_intr;
50061+atomic_unchecked_t fscache_n_retrievals_nomem;
50062+atomic_unchecked_t fscache_n_retrievals_object_dead;
50063+atomic_unchecked_t fscache_n_retrieval_ops;
50064+atomic_unchecked_t fscache_n_retrieval_op_waits;
50065
50066-atomic_t fscache_n_stores;
50067-atomic_t fscache_n_stores_ok;
50068-atomic_t fscache_n_stores_again;
50069-atomic_t fscache_n_stores_nobufs;
50070-atomic_t fscache_n_stores_oom;
50071-atomic_t fscache_n_store_ops;
50072-atomic_t fscache_n_store_calls;
50073-atomic_t fscache_n_store_pages;
50074-atomic_t fscache_n_store_radix_deletes;
50075-atomic_t fscache_n_store_pages_over_limit;
50076+atomic_unchecked_t fscache_n_stores;
50077+atomic_unchecked_t fscache_n_stores_ok;
50078+atomic_unchecked_t fscache_n_stores_again;
50079+atomic_unchecked_t fscache_n_stores_nobufs;
50080+atomic_unchecked_t fscache_n_stores_oom;
50081+atomic_unchecked_t fscache_n_store_ops;
50082+atomic_unchecked_t fscache_n_store_calls;
50083+atomic_unchecked_t fscache_n_store_pages;
50084+atomic_unchecked_t fscache_n_store_radix_deletes;
50085+atomic_unchecked_t fscache_n_store_pages_over_limit;
50086
50087-atomic_t fscache_n_store_vmscan_not_storing;
50088-atomic_t fscache_n_store_vmscan_gone;
50089-atomic_t fscache_n_store_vmscan_busy;
50090-atomic_t fscache_n_store_vmscan_cancelled;
50091+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50092+atomic_unchecked_t fscache_n_store_vmscan_gone;
50093+atomic_unchecked_t fscache_n_store_vmscan_busy;
50094+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50095
50096-atomic_t fscache_n_marks;
50097-atomic_t fscache_n_uncaches;
50098+atomic_unchecked_t fscache_n_marks;
50099+atomic_unchecked_t fscache_n_uncaches;
50100
50101-atomic_t fscache_n_acquires;
50102-atomic_t fscache_n_acquires_null;
50103-atomic_t fscache_n_acquires_no_cache;
50104-atomic_t fscache_n_acquires_ok;
50105-atomic_t fscache_n_acquires_nobufs;
50106-atomic_t fscache_n_acquires_oom;
50107+atomic_unchecked_t fscache_n_acquires;
50108+atomic_unchecked_t fscache_n_acquires_null;
50109+atomic_unchecked_t fscache_n_acquires_no_cache;
50110+atomic_unchecked_t fscache_n_acquires_ok;
50111+atomic_unchecked_t fscache_n_acquires_nobufs;
50112+atomic_unchecked_t fscache_n_acquires_oom;
50113
50114-atomic_t fscache_n_updates;
50115-atomic_t fscache_n_updates_null;
50116-atomic_t fscache_n_updates_run;
50117+atomic_unchecked_t fscache_n_updates;
50118+atomic_unchecked_t fscache_n_updates_null;
50119+atomic_unchecked_t fscache_n_updates_run;
50120
50121-atomic_t fscache_n_relinquishes;
50122-atomic_t fscache_n_relinquishes_null;
50123-atomic_t fscache_n_relinquishes_waitcrt;
50124-atomic_t fscache_n_relinquishes_retire;
50125+atomic_unchecked_t fscache_n_relinquishes;
50126+atomic_unchecked_t fscache_n_relinquishes_null;
50127+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50128+atomic_unchecked_t fscache_n_relinquishes_retire;
50129
50130-atomic_t fscache_n_cookie_index;
50131-atomic_t fscache_n_cookie_data;
50132-atomic_t fscache_n_cookie_special;
50133+atomic_unchecked_t fscache_n_cookie_index;
50134+atomic_unchecked_t fscache_n_cookie_data;
50135+atomic_unchecked_t fscache_n_cookie_special;
50136
50137-atomic_t fscache_n_object_alloc;
50138-atomic_t fscache_n_object_no_alloc;
50139-atomic_t fscache_n_object_lookups;
50140-atomic_t fscache_n_object_lookups_negative;
50141-atomic_t fscache_n_object_lookups_positive;
50142-atomic_t fscache_n_object_lookups_timed_out;
50143-atomic_t fscache_n_object_created;
50144-atomic_t fscache_n_object_avail;
50145-atomic_t fscache_n_object_dead;
50146+atomic_unchecked_t fscache_n_object_alloc;
50147+atomic_unchecked_t fscache_n_object_no_alloc;
50148+atomic_unchecked_t fscache_n_object_lookups;
50149+atomic_unchecked_t fscache_n_object_lookups_negative;
50150+atomic_unchecked_t fscache_n_object_lookups_positive;
50151+atomic_unchecked_t fscache_n_object_lookups_timed_out;
50152+atomic_unchecked_t fscache_n_object_created;
50153+atomic_unchecked_t fscache_n_object_avail;
50154+atomic_unchecked_t fscache_n_object_dead;
50155
50156-atomic_t fscache_n_checkaux_none;
50157-atomic_t fscache_n_checkaux_okay;
50158-atomic_t fscache_n_checkaux_update;
50159-atomic_t fscache_n_checkaux_obsolete;
50160+atomic_unchecked_t fscache_n_checkaux_none;
50161+atomic_unchecked_t fscache_n_checkaux_okay;
50162+atomic_unchecked_t fscache_n_checkaux_update;
50163+atomic_unchecked_t fscache_n_checkaux_obsolete;
50164
50165 atomic_t fscache_n_cop_alloc_object;
50166 atomic_t fscache_n_cop_lookup_object;
50167@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
50168 seq_puts(m, "FS-Cache statistics\n");
50169
50170 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
50171- atomic_read(&fscache_n_cookie_index),
50172- atomic_read(&fscache_n_cookie_data),
50173- atomic_read(&fscache_n_cookie_special));
50174+ atomic_read_unchecked(&fscache_n_cookie_index),
50175+ atomic_read_unchecked(&fscache_n_cookie_data),
50176+ atomic_read_unchecked(&fscache_n_cookie_special));
50177
50178 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
50179- atomic_read(&fscache_n_object_alloc),
50180- atomic_read(&fscache_n_object_no_alloc),
50181- atomic_read(&fscache_n_object_avail),
50182- atomic_read(&fscache_n_object_dead));
50183+ atomic_read_unchecked(&fscache_n_object_alloc),
50184+ atomic_read_unchecked(&fscache_n_object_no_alloc),
50185+ atomic_read_unchecked(&fscache_n_object_avail),
50186+ atomic_read_unchecked(&fscache_n_object_dead));
50187 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
50188- atomic_read(&fscache_n_checkaux_none),
50189- atomic_read(&fscache_n_checkaux_okay),
50190- atomic_read(&fscache_n_checkaux_update),
50191- atomic_read(&fscache_n_checkaux_obsolete));
50192+ atomic_read_unchecked(&fscache_n_checkaux_none),
50193+ atomic_read_unchecked(&fscache_n_checkaux_okay),
50194+ atomic_read_unchecked(&fscache_n_checkaux_update),
50195+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
50196
50197 seq_printf(m, "Pages : mrk=%u unc=%u\n",
50198- atomic_read(&fscache_n_marks),
50199- atomic_read(&fscache_n_uncaches));
50200+ atomic_read_unchecked(&fscache_n_marks),
50201+ atomic_read_unchecked(&fscache_n_uncaches));
50202
50203 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
50204 " oom=%u\n",
50205- atomic_read(&fscache_n_acquires),
50206- atomic_read(&fscache_n_acquires_null),
50207- atomic_read(&fscache_n_acquires_no_cache),
50208- atomic_read(&fscache_n_acquires_ok),
50209- atomic_read(&fscache_n_acquires_nobufs),
50210- atomic_read(&fscache_n_acquires_oom));
50211+ atomic_read_unchecked(&fscache_n_acquires),
50212+ atomic_read_unchecked(&fscache_n_acquires_null),
50213+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
50214+ atomic_read_unchecked(&fscache_n_acquires_ok),
50215+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
50216+ atomic_read_unchecked(&fscache_n_acquires_oom));
50217
50218 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
50219- atomic_read(&fscache_n_object_lookups),
50220- atomic_read(&fscache_n_object_lookups_negative),
50221- atomic_read(&fscache_n_object_lookups_positive),
50222- atomic_read(&fscache_n_object_lookups_timed_out),
50223- atomic_read(&fscache_n_object_created));
50224+ atomic_read_unchecked(&fscache_n_object_lookups),
50225+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
50226+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
50227+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
50228+ atomic_read_unchecked(&fscache_n_object_created));
50229
50230 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
50231- atomic_read(&fscache_n_updates),
50232- atomic_read(&fscache_n_updates_null),
50233- atomic_read(&fscache_n_updates_run));
50234+ atomic_read_unchecked(&fscache_n_updates),
50235+ atomic_read_unchecked(&fscache_n_updates_null),
50236+ atomic_read_unchecked(&fscache_n_updates_run));
50237
50238 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
50239- atomic_read(&fscache_n_relinquishes),
50240- atomic_read(&fscache_n_relinquishes_null),
50241- atomic_read(&fscache_n_relinquishes_waitcrt),
50242- atomic_read(&fscache_n_relinquishes_retire));
50243+ atomic_read_unchecked(&fscache_n_relinquishes),
50244+ atomic_read_unchecked(&fscache_n_relinquishes_null),
50245+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
50246+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
50247
50248 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
50249- atomic_read(&fscache_n_attr_changed),
50250- atomic_read(&fscache_n_attr_changed_ok),
50251- atomic_read(&fscache_n_attr_changed_nobufs),
50252- atomic_read(&fscache_n_attr_changed_nomem),
50253- atomic_read(&fscache_n_attr_changed_calls));
50254+ atomic_read_unchecked(&fscache_n_attr_changed),
50255+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
50256+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
50257+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
50258+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
50259
50260 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
50261- atomic_read(&fscache_n_allocs),
50262- atomic_read(&fscache_n_allocs_ok),
50263- atomic_read(&fscache_n_allocs_wait),
50264- atomic_read(&fscache_n_allocs_nobufs),
50265- atomic_read(&fscache_n_allocs_intr));
50266+ atomic_read_unchecked(&fscache_n_allocs),
50267+ atomic_read_unchecked(&fscache_n_allocs_ok),
50268+ atomic_read_unchecked(&fscache_n_allocs_wait),
50269+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
50270+ atomic_read_unchecked(&fscache_n_allocs_intr));
50271 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
50272- atomic_read(&fscache_n_alloc_ops),
50273- atomic_read(&fscache_n_alloc_op_waits),
50274- atomic_read(&fscache_n_allocs_object_dead));
50275+ atomic_read_unchecked(&fscache_n_alloc_ops),
50276+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
50277+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
50278
50279 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
50280 " int=%u oom=%u\n",
50281- atomic_read(&fscache_n_retrievals),
50282- atomic_read(&fscache_n_retrievals_ok),
50283- atomic_read(&fscache_n_retrievals_wait),
50284- atomic_read(&fscache_n_retrievals_nodata),
50285- atomic_read(&fscache_n_retrievals_nobufs),
50286- atomic_read(&fscache_n_retrievals_intr),
50287- atomic_read(&fscache_n_retrievals_nomem));
50288+ atomic_read_unchecked(&fscache_n_retrievals),
50289+ atomic_read_unchecked(&fscache_n_retrievals_ok),
50290+ atomic_read_unchecked(&fscache_n_retrievals_wait),
50291+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
50292+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
50293+ atomic_read_unchecked(&fscache_n_retrievals_intr),
50294+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
50295 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
50296- atomic_read(&fscache_n_retrieval_ops),
50297- atomic_read(&fscache_n_retrieval_op_waits),
50298- atomic_read(&fscache_n_retrievals_object_dead));
50299+ atomic_read_unchecked(&fscache_n_retrieval_ops),
50300+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
50301+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
50302
50303 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
50304- atomic_read(&fscache_n_stores),
50305- atomic_read(&fscache_n_stores_ok),
50306- atomic_read(&fscache_n_stores_again),
50307- atomic_read(&fscache_n_stores_nobufs),
50308- atomic_read(&fscache_n_stores_oom));
50309+ atomic_read_unchecked(&fscache_n_stores),
50310+ atomic_read_unchecked(&fscache_n_stores_ok),
50311+ atomic_read_unchecked(&fscache_n_stores_again),
50312+ atomic_read_unchecked(&fscache_n_stores_nobufs),
50313+ atomic_read_unchecked(&fscache_n_stores_oom));
50314 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
50315- atomic_read(&fscache_n_store_ops),
50316- atomic_read(&fscache_n_store_calls),
50317- atomic_read(&fscache_n_store_pages),
50318- atomic_read(&fscache_n_store_radix_deletes),
50319- atomic_read(&fscache_n_store_pages_over_limit));
50320+ atomic_read_unchecked(&fscache_n_store_ops),
50321+ atomic_read_unchecked(&fscache_n_store_calls),
50322+ atomic_read_unchecked(&fscache_n_store_pages),
50323+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
50324+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
50325
50326 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
50327- atomic_read(&fscache_n_store_vmscan_not_storing),
50328- atomic_read(&fscache_n_store_vmscan_gone),
50329- atomic_read(&fscache_n_store_vmscan_busy),
50330- atomic_read(&fscache_n_store_vmscan_cancelled));
50331+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
50332+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
50333+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
50334+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
50335
50336 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
50337- atomic_read(&fscache_n_op_pend),
50338- atomic_read(&fscache_n_op_run),
50339- atomic_read(&fscache_n_op_enqueue),
50340- atomic_read(&fscache_n_op_cancelled),
50341- atomic_read(&fscache_n_op_rejected));
50342+ atomic_read_unchecked(&fscache_n_op_pend),
50343+ atomic_read_unchecked(&fscache_n_op_run),
50344+ atomic_read_unchecked(&fscache_n_op_enqueue),
50345+ atomic_read_unchecked(&fscache_n_op_cancelled),
50346+ atomic_read_unchecked(&fscache_n_op_rejected));
50347 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
50348- atomic_read(&fscache_n_op_deferred_release),
50349- atomic_read(&fscache_n_op_release),
50350- atomic_read(&fscache_n_op_gc));
50351+ atomic_read_unchecked(&fscache_n_op_deferred_release),
50352+ atomic_read_unchecked(&fscache_n_op_release),
50353+ atomic_read_unchecked(&fscache_n_op_gc));
50354
50355 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
50356 atomic_read(&fscache_n_cop_alloc_object),
50357diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50358index de792dc..448b532 100644
50359--- a/fs/fuse/cuse.c
50360+++ b/fs/fuse/cuse.c
50361@@ -576,10 +576,12 @@ static int __init cuse_init(void)
50362 INIT_LIST_HEAD(&cuse_conntbl[i]);
50363
50364 /* inherit and extend fuse_dev_operations */
50365- cuse_channel_fops = fuse_dev_operations;
50366- cuse_channel_fops.owner = THIS_MODULE;
50367- cuse_channel_fops.open = cuse_channel_open;
50368- cuse_channel_fops.release = cuse_channel_release;
50369+ pax_open_kernel();
50370+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50371+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50372+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50373+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50374+ pax_close_kernel();
50375
50376 cuse_class = class_create(THIS_MODULE, "cuse");
50377 if (IS_ERR(cuse_class))
50378diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50379index 1facb39..7f48557 100644
50380--- a/fs/fuse/dev.c
50381+++ b/fs/fuse/dev.c
50382@@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50383 {
50384 struct fuse_notify_inval_entry_out outarg;
50385 int err = -EINVAL;
50386- char buf[FUSE_NAME_MAX+1];
50387+ char *buf = NULL;
50388 struct qstr name;
50389
50390 if (size < sizeof(outarg))
50391@@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50392 if (outarg.namelen > FUSE_NAME_MAX)
50393 goto err;
50394
50395+ err = -ENOMEM;
50396+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
50397+ if (!buf)
50398+ goto err;
50399+
50400 err = -EINVAL;
50401 if (size != sizeof(outarg) + outarg.namelen + 1)
50402 goto err;
50403@@ -914,17 +919,15 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50404
50405 down_read(&fc->killsb);
50406 err = -ENOENT;
50407- if (!fc->sb)
50408- goto err_unlock;
50409-
50410- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50411-
50412-err_unlock:
50413+ if (fc->sb)
50414+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50415 up_read(&fc->killsb);
50416+ kfree(buf);
50417 return err;
50418
50419 err:
50420 fuse_copy_finish(cs);
50421+ kfree(buf);
50422 return err;
50423 }
50424
50425diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50426index 4787ae6..73efff7 100644
50427--- a/fs/fuse/dir.c
50428+++ b/fs/fuse/dir.c
50429@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *dentry)
50430 return link;
50431 }
50432
50433-static void free_link(char *link)
50434+static void free_link(const char *link)
50435 {
50436 if (!IS_ERR(link))
50437 free_page((unsigned long) link);
50438diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
50439index 247436c..e650ccb 100644
50440--- a/fs/gfs2/ops_inode.c
50441+++ b/fs/gfs2/ops_inode.c
50442@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
50443 unsigned int x;
50444 int error;
50445
50446+ pax_track_stack();
50447+
50448 if (ndentry->d_inode) {
50449 nip = GFS2_I(ndentry->d_inode);
50450 if (ip == nip)
50451diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
50452index 4463297..4fed53b 100644
50453--- a/fs/gfs2/sys.c
50454+++ b/fs/gfs2/sys.c
50455@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
50456 return a->store ? a->store(sdp, buf, len) : len;
50457 }
50458
50459-static struct sysfs_ops gfs2_attr_ops = {
50460+static const struct sysfs_ops gfs2_attr_ops = {
50461 .show = gfs2_attr_show,
50462 .store = gfs2_attr_store,
50463 };
50464@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
50465 return 0;
50466 }
50467
50468-static struct kset_uevent_ops gfs2_uevent_ops = {
50469+static const struct kset_uevent_ops gfs2_uevent_ops = {
50470 .uevent = gfs2_uevent,
50471 };
50472
50473diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
50474index 052f214..2462c5b 100644
50475--- a/fs/hfs/btree.c
50476+++ b/fs/hfs/btree.c
50477@@ -45,11 +45,27 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
50478 case HFS_EXT_CNID:
50479 hfs_inode_read_fork(tree->inode, mdb->drXTExtRec, mdb->drXTFlSize,
50480 mdb->drXTFlSize, be32_to_cpu(mdb->drXTClpSiz));
50481+
50482+ if (HFS_I(tree->inode)->alloc_blocks >
50483+ HFS_I(tree->inode)->first_blocks) {
50484+ printk(KERN_ERR "hfs: invalid btree extent records\n");
50485+ unlock_new_inode(tree->inode);
50486+ goto free_inode;
50487+ }
50488+
50489 tree->inode->i_mapping->a_ops = &hfs_btree_aops;
50490 break;
50491 case HFS_CAT_CNID:
50492 hfs_inode_read_fork(tree->inode, mdb->drCTExtRec, mdb->drCTFlSize,
50493 mdb->drCTFlSize, be32_to_cpu(mdb->drCTClpSiz));
50494+
50495+ if (!HFS_I(tree->inode)->first_blocks) {
50496+ printk(KERN_ERR "hfs: invalid btree extent records "
50497+ "(0 size).\n");
50498+ unlock_new_inode(tree->inode);
50499+ goto free_inode;
50500+ }
50501+
50502 tree->inode->i_mapping->a_ops = &hfs_btree_aops;
50503 break;
50504 default:
50505@@ -58,11 +74,6 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
50506 }
50507 unlock_new_inode(tree->inode);
50508
50509- if (!HFS_I(tree->inode)->first_blocks) {
50510- printk(KERN_ERR "hfs: invalid btree extent records (0 size).\n");
50511- goto free_inode;
50512- }
50513-
50514 mapping = tree->inode->i_mapping;
50515 page = read_mapping_page(mapping, 0, NULL);
50516 if (IS_ERR(page))
50517diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
50518index f6874ac..7cd98a8 100644
50519--- a/fs/hfsplus/catalog.c
50520+++ b/fs/hfsplus/catalog.c
50521@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
50522 int err;
50523 u16 type;
50524
50525+ pax_track_stack();
50526+
50527 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
50528 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
50529 if (err)
50530@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino
50531 int entry_size;
50532 int err;
50533
50534+ pax_track_stack();
50535+
50536 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
50537 sb = dir->i_sb;
50538 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
50539@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
50540 int entry_size, type;
50541 int err = 0;
50542
50543+ pax_track_stack();
50544+
50545 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
50546 dst_dir->i_ino, dst_name->name);
50547 sb = src_dir->i_sb;
50548diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
50549index 5f40236..dac3421 100644
50550--- a/fs/hfsplus/dir.c
50551+++ b/fs/hfsplus/dir.c
50552@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
50553 struct hfsplus_readdir_data *rd;
50554 u16 type;
50555
50556+ pax_track_stack();
50557+
50558 if (filp->f_pos >= inode->i_size)
50559 return 0;
50560
50561diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
50562index 1bcf597..905a251 100644
50563--- a/fs/hfsplus/inode.c
50564+++ b/fs/hfsplus/inode.c
50565@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
50566 int res = 0;
50567 u16 type;
50568
50569+ pax_track_stack();
50570+
50571 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
50572
50573 HFSPLUS_I(inode).dev = 0;
50574@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
50575 struct hfs_find_data fd;
50576 hfsplus_cat_entry entry;
50577
50578+ pax_track_stack();
50579+
50580 if (HFSPLUS_IS_RSRC(inode))
50581 main_inode = HFSPLUS_I(inode).rsrc_inode;
50582
50583diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
50584index f457d2c..7ef4ad5 100644
50585--- a/fs/hfsplus/ioctl.c
50586+++ b/fs/hfsplus/ioctl.c
50587@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
50588 struct hfsplus_cat_file *file;
50589 int res;
50590
50591+ pax_track_stack();
50592+
50593 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50594 return -EOPNOTSUPP;
50595
50596@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
50597 struct hfsplus_cat_file *file;
50598 ssize_t res = 0;
50599
50600+ pax_track_stack();
50601+
50602 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50603 return -EOPNOTSUPP;
50604
50605diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
50606index 43022f3..7298079 100644
50607--- a/fs/hfsplus/super.c
50608+++ b/fs/hfsplus/super.c
50609@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
50610 struct nls_table *nls = NULL;
50611 int err = -EINVAL;
50612
50613+ pax_track_stack();
50614+
50615 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
50616 if (!sbi)
50617 return -ENOMEM;
50618diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50619index 87a1258..5694d91 100644
50620--- a/fs/hugetlbfs/inode.c
50621+++ b/fs/hugetlbfs/inode.c
50622@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50623 .kill_sb = kill_litter_super,
50624 };
50625
50626-static struct vfsmount *hugetlbfs_vfsmount;
50627+struct vfsmount *hugetlbfs_vfsmount;
50628
50629 static int can_do_hugetlb_shm(void)
50630 {
50631diff --git a/fs/ioctl.c b/fs/ioctl.c
50632index 6c75110..19d2c3c 100644
50633--- a/fs/ioctl.c
50634+++ b/fs/ioctl.c
50635@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
50636 u64 phys, u64 len, u32 flags)
50637 {
50638 struct fiemap_extent extent;
50639- struct fiemap_extent *dest = fieinfo->fi_extents_start;
50640+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
50641
50642 /* only count the extents */
50643 if (fieinfo->fi_extents_max == 0) {
50644@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50645
50646 fieinfo.fi_flags = fiemap.fm_flags;
50647 fieinfo.fi_extents_max = fiemap.fm_extent_count;
50648- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
50649+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
50650
50651 if (fiemap.fm_extent_count != 0 &&
50652 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
50653@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50654 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
50655 fiemap.fm_flags = fieinfo.fi_flags;
50656 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
50657- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
50658+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
50659 error = -EFAULT;
50660
50661 return error;
50662diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
50663index b0435dd..81ee0be 100644
50664--- a/fs/jbd/checkpoint.c
50665+++ b/fs/jbd/checkpoint.c
50666@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal)
50667 tid_t this_tid;
50668 int result;
50669
50670+ pax_track_stack();
50671+
50672 jbd_debug(1, "Start checkpoint\n");
50673
50674 /*
50675diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
50676index 546d153..736896c 100644
50677--- a/fs/jffs2/compr_rtime.c
50678+++ b/fs/jffs2/compr_rtime.c
50679@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
50680 int outpos = 0;
50681 int pos=0;
50682
50683+ pax_track_stack();
50684+
50685 memset(positions,0,sizeof(positions));
50686
50687 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
50688@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
50689 int outpos = 0;
50690 int pos=0;
50691
50692+ pax_track_stack();
50693+
50694 memset(positions,0,sizeof(positions));
50695
50696 while (outpos<destlen) {
50697diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
50698index 170d289..3254b98 100644
50699--- a/fs/jffs2/compr_rubin.c
50700+++ b/fs/jffs2/compr_rubin.c
50701@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
50702 int ret;
50703 uint32_t mysrclen, mydstlen;
50704
50705+ pax_track_stack();
50706+
50707 mysrclen = *sourcelen;
50708 mydstlen = *dstlen - 8;
50709
50710diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50711index b47679b..00d65d3 100644
50712--- a/fs/jffs2/erase.c
50713+++ b/fs/jffs2/erase.c
50714@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50715 struct jffs2_unknown_node marker = {
50716 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50717 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50718- .totlen = cpu_to_je32(c->cleanmarker_size)
50719+ .totlen = cpu_to_je32(c->cleanmarker_size),
50720+ .hdr_crc = cpu_to_je32(0)
50721 };
50722
50723 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50724diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50725index 5ef7bac..4fd1e3c 100644
50726--- a/fs/jffs2/wbuf.c
50727+++ b/fs/jffs2/wbuf.c
50728@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50729 {
50730 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50731 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50732- .totlen = constant_cpu_to_je32(8)
50733+ .totlen = constant_cpu_to_je32(8),
50734+ .hdr_crc = constant_cpu_to_je32(0)
50735 };
50736
50737 /*
50738diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
50739index 082e844..52012a1 100644
50740--- a/fs/jffs2/xattr.c
50741+++ b/fs/jffs2/xattr.c
50742@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
50743
50744 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
50745
50746+ pax_track_stack();
50747+
50748 /* Phase.1 : Merge same xref */
50749 for (i=0; i < XREF_TMPHASH_SIZE; i++)
50750 xref_tmphash[i] = NULL;
50751diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50752index 2234c73..f6e6e6b 100644
50753--- a/fs/jfs/super.c
50754+++ b/fs/jfs/super.c
50755@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
50756
50757 jfs_inode_cachep =
50758 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50759- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50760+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50761 init_once);
50762 if (jfs_inode_cachep == NULL)
50763 return -ENOMEM;
50764diff --git a/fs/libfs.c b/fs/libfs.c
50765index ba36e93..3153fce 100644
50766--- a/fs/libfs.c
50767+++ b/fs/libfs.c
50768@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50769
50770 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50771 struct dentry *next;
50772+ char d_name[sizeof(next->d_iname)];
50773+ const unsigned char *name;
50774+
50775 next = list_entry(p, struct dentry, d_u.d_child);
50776 if (d_unhashed(next) || !next->d_inode)
50777 continue;
50778
50779 spin_unlock(&dcache_lock);
50780- if (filldir(dirent, next->d_name.name,
50781+ name = next->d_name.name;
50782+ if (name == next->d_iname) {
50783+ memcpy(d_name, name, next->d_name.len);
50784+ name = d_name;
50785+ }
50786+ if (filldir(dirent, name,
50787 next->d_name.len, filp->f_pos,
50788 next->d_inode->i_ino,
50789 dt_type(next->d_inode)) < 0)
50790diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50791index c325a83..d15b07b 100644
50792--- a/fs/lockd/clntproc.c
50793+++ b/fs/lockd/clntproc.c
50794@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50795 /*
50796 * Cookie counter for NLM requests
50797 */
50798-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50799+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50800
50801 void nlmclnt_next_cookie(struct nlm_cookie *c)
50802 {
50803- u32 cookie = atomic_inc_return(&nlm_cookie);
50804+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50805
50806 memcpy(c->data, &cookie, 4);
50807 c->len=4;
50808@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
50809 struct nlm_rqst reqst, *req;
50810 int status;
50811
50812+ pax_track_stack();
50813+
50814 req = &reqst;
50815 memset(req, 0, sizeof(*req));
50816 locks_init_lock(&req->a_args.lock.fl);
50817diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
50818index 1a54ae1..6a16c27 100644
50819--- a/fs/lockd/svc.c
50820+++ b/fs/lockd/svc.c
50821@@ -43,7 +43,7 @@
50822
50823 static struct svc_program nlmsvc_program;
50824
50825-struct nlmsvc_binding * nlmsvc_ops;
50826+const struct nlmsvc_binding * nlmsvc_ops;
50827 EXPORT_SYMBOL_GPL(nlmsvc_ops);
50828
50829 static DEFINE_MUTEX(nlmsvc_mutex);
50830diff --git a/fs/locks.c b/fs/locks.c
50831index a8794f2..4041e55 100644
50832--- a/fs/locks.c
50833+++ b/fs/locks.c
50834@@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
50835
50836 static struct kmem_cache *filelock_cache __read_mostly;
50837
50838+static void locks_init_lock_always(struct file_lock *fl)
50839+{
50840+ fl->fl_next = NULL;
50841+ fl->fl_fasync = NULL;
50842+ fl->fl_owner = NULL;
50843+ fl->fl_pid = 0;
50844+ fl->fl_nspid = NULL;
50845+ fl->fl_file = NULL;
50846+ fl->fl_flags = 0;
50847+ fl->fl_type = 0;
50848+ fl->fl_start = fl->fl_end = 0;
50849+}
50850+
50851 /* Allocate an empty lock structure. */
50852 static struct file_lock *locks_alloc_lock(void)
50853 {
50854- return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
50855+ struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
50856+
50857+ if (fl)
50858+ locks_init_lock_always(fl);
50859+
50860+ return fl;
50861 }
50862
50863 void locks_release_private(struct file_lock *fl)
50864@@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *fl)
50865 INIT_LIST_HEAD(&fl->fl_link);
50866 INIT_LIST_HEAD(&fl->fl_block);
50867 init_waitqueue_head(&fl->fl_wait);
50868- fl->fl_next = NULL;
50869- fl->fl_fasync = NULL;
50870- fl->fl_owner = NULL;
50871- fl->fl_pid = 0;
50872- fl->fl_nspid = NULL;
50873- fl->fl_file = NULL;
50874- fl->fl_flags = 0;
50875- fl->fl_type = 0;
50876- fl->fl_start = fl->fl_end = 0;
50877 fl->fl_ops = NULL;
50878 fl->fl_lmops = NULL;
50879+ locks_init_lock_always(fl);
50880 }
50881
50882 EXPORT_SYMBOL(locks_init_lock);
50883@@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *filp)
50884 return;
50885
50886 if (filp->f_op && filp->f_op->flock) {
50887- struct file_lock fl = {
50888+ struct file_lock flock = {
50889 .fl_pid = current->tgid,
50890 .fl_file = filp,
50891 .fl_flags = FL_FLOCK,
50892 .fl_type = F_UNLCK,
50893 .fl_end = OFFSET_MAX,
50894 };
50895- filp->f_op->flock(filp, F_SETLKW, &fl);
50896- if (fl.fl_ops && fl.fl_ops->fl_release_private)
50897- fl.fl_ops->fl_release_private(&fl);
50898+ filp->f_op->flock(filp, F_SETLKW, &flock);
50899+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
50900+ flock.fl_ops->fl_release_private(&flock);
50901 }
50902
50903 lock_kernel();
50904diff --git a/fs/mbcache.c b/fs/mbcache.c
50905index ec88ff3..b843a82 100644
50906--- a/fs/mbcache.c
50907+++ b/fs/mbcache.c
50908@@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct mb_cache_op *cache_op,
50909 if (!cache)
50910 goto fail;
50911 cache->c_name = name;
50912- cache->c_op.free = NULL;
50913+ *(void **)&cache->c_op.free = NULL;
50914 if (cache_op)
50915- cache->c_op.free = cache_op->free;
50916+ *(void **)&cache->c_op.free = cache_op->free;
50917 atomic_set(&cache->c_entry_count, 0);
50918 cache->c_bucket_bits = bucket_bits;
50919 #ifdef MB_CACHE_INDEXES_COUNT
50920diff --git a/fs/namei.c b/fs/namei.c
50921index b0afbd4..8d065a1 100644
50922--- a/fs/namei.c
50923+++ b/fs/namei.c
50924@@ -224,6 +224,14 @@ int generic_permission(struct inode *inode, int mask,
50925 return ret;
50926
50927 /*
50928+ * Searching includes executable on directories, else just read.
50929+ */
50930+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50931+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
50932+ if (capable(CAP_DAC_READ_SEARCH))
50933+ return 0;
50934+
50935+ /*
50936 * Read/write DACs are always overridable.
50937 * Executable DACs are overridable if at least one exec bit is set.
50938 */
50939@@ -231,14 +239,6 @@ int generic_permission(struct inode *inode, int mask,
50940 if (capable(CAP_DAC_OVERRIDE))
50941 return 0;
50942
50943- /*
50944- * Searching includes executable on directories, else just read.
50945- */
50946- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50947- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
50948- if (capable(CAP_DAC_READ_SEARCH))
50949- return 0;
50950-
50951 return -EACCES;
50952 }
50953
50954@@ -458,7 +458,8 @@ static int exec_permission_lite(struct inode *inode)
50955 if (!ret)
50956 goto ok;
50957
50958- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
50959+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
50960+ capable(CAP_DAC_OVERRIDE))
50961 goto ok;
50962
50963 return ret;
50964@@ -638,7 +639,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
50965 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
50966 error = PTR_ERR(cookie);
50967 if (!IS_ERR(cookie)) {
50968- char *s = nd_get_link(nd);
50969+ const char *s = nd_get_link(nd);
50970 error = 0;
50971 if (s)
50972 error = __vfs_follow_link(nd, s);
50973@@ -669,6 +670,13 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
50974 err = security_inode_follow_link(path->dentry, nd);
50975 if (err)
50976 goto loop;
50977+
50978+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
50979+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
50980+ err = -EACCES;
50981+ goto loop;
50982+ }
50983+
50984 current->link_count++;
50985 current->total_link_count++;
50986 nd->depth++;
50987@@ -1016,11 +1024,19 @@ return_reval:
50988 break;
50989 }
50990 return_base:
50991+ if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT)) &&
50992+ !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50993+ path_put(&nd->path);
50994+ return -ENOENT;
50995+ }
50996 return 0;
50997 out_dput:
50998 path_put_conditional(&next, nd);
50999 break;
51000 }
51001+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
51002+ err = -ENOENT;
51003+
51004 path_put(&nd->path);
51005 return_err:
51006 return err;
51007@@ -1091,13 +1107,20 @@ static int do_path_lookup(int dfd, const char *name,
51008 int retval = path_init(dfd, name, flags, nd);
51009 if (!retval)
51010 retval = path_walk(name, nd);
51011- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
51012- nd->path.dentry->d_inode))
51013- audit_inode(name, nd->path.dentry);
51014+
51015+ if (likely(!retval)) {
51016+ if (nd->path.dentry && nd->path.dentry->d_inode) {
51017+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
51018+ retval = -ENOENT;
51019+ if (!audit_dummy_context())
51020+ audit_inode(name, nd->path.dentry);
51021+ }
51022+ }
51023 if (nd->root.mnt) {
51024 path_put(&nd->root);
51025 nd->root.mnt = NULL;
51026 }
51027+
51028 return retval;
51029 }
51030
51031@@ -1576,6 +1599,20 @@ int may_open(struct path *path, int acc_mode, int flag)
51032 if (error)
51033 goto err_out;
51034
51035+
51036+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
51037+ error = -EPERM;
51038+ goto err_out;
51039+ }
51040+ if (gr_handle_rawio(inode)) {
51041+ error = -EPERM;
51042+ goto err_out;
51043+ }
51044+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
51045+ error = -EACCES;
51046+ goto err_out;
51047+ }
51048+
51049 if (flag & O_TRUNC) {
51050 error = get_write_access(inode);
51051 if (error)
51052@@ -1620,6 +1657,17 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51053 {
51054 int error;
51055 struct dentry *dir = nd->path.dentry;
51056+ int acc_mode = ACC_MODE(flag);
51057+
51058+ if (flag & O_TRUNC)
51059+ acc_mode |= MAY_WRITE;
51060+ if (flag & O_APPEND)
51061+ acc_mode |= MAY_APPEND;
51062+
51063+ if (!gr_acl_handle_creat(path->dentry, dir, nd->path.mnt, flag, acc_mode, mode)) {
51064+ error = -EACCES;
51065+ goto out_unlock;
51066+ }
51067
51068 if (!IS_POSIXACL(dir->d_inode))
51069 mode &= ~current_umask();
51070@@ -1627,6 +1675,8 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51071 if (error)
51072 goto out_unlock;
51073 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
51074+ if (!error)
51075+ gr_handle_create(path->dentry, nd->path.mnt);
51076 out_unlock:
51077 mutex_unlock(&dir->d_inode->i_mutex);
51078 dput(nd->path.dentry);
51079@@ -1709,6 +1759,22 @@ struct file *do_filp_open(int dfd, const char *pathname,
51080 &nd, flag);
51081 if (error)
51082 return ERR_PTR(error);
51083+
51084+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
51085+ error = -EPERM;
51086+ goto exit;
51087+ }
51088+
51089+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
51090+ error = -EPERM;
51091+ goto exit;
51092+ }
51093+
51094+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, acc_mode)) {
51095+ error = -EACCES;
51096+ goto exit;
51097+ }
51098+
51099 goto ok;
51100 }
51101
51102@@ -1795,6 +1861,19 @@ do_last:
51103 /*
51104 * It already exists.
51105 */
51106+
51107+ if (!gr_acl_handle_hidden_file(path.dentry, path.mnt)) {
51108+ error = -ENOENT;
51109+ goto exit_mutex_unlock;
51110+ }
51111+
51112+ /* only check if O_CREAT is specified, all other checks need
51113+ to go into may_open */
51114+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
51115+ error = -EACCES;
51116+ goto exit_mutex_unlock;
51117+ }
51118+
51119 mutex_unlock(&dir->d_inode->i_mutex);
51120 audit_inode(pathname, path.dentry);
51121
51122@@ -1887,6 +1966,13 @@ do_link:
51123 error = security_inode_follow_link(path.dentry, &nd);
51124 if (error)
51125 goto exit_dput;
51126+
51127+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
51128+ path.dentry, nd.path.mnt)) {
51129+ error = -EACCES;
51130+ goto exit_dput;
51131+ }
51132+
51133 error = __do_follow_link(&path, &nd);
51134 if (error) {
51135 /* Does someone understand code flow here? Or it is only
51136@@ -1984,6 +2070,10 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
51137 }
51138 return dentry;
51139 eexist:
51140+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
51141+ dput(dentry);
51142+ return ERR_PTR(-ENOENT);
51143+ }
51144 dput(dentry);
51145 dentry = ERR_PTR(-EEXIST);
51146 fail:
51147@@ -2061,6 +2151,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51148 error = may_mknod(mode);
51149 if (error)
51150 goto out_dput;
51151+
51152+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
51153+ error = -EPERM;
51154+ goto out_dput;
51155+ }
51156+
51157+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
51158+ error = -EACCES;
51159+ goto out_dput;
51160+ }
51161+
51162 error = mnt_want_write(nd.path.mnt);
51163 if (error)
51164 goto out_dput;
51165@@ -2081,6 +2182,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51166 }
51167 out_drop_write:
51168 mnt_drop_write(nd.path.mnt);
51169+
51170+ if (!error)
51171+ gr_handle_create(dentry, nd.path.mnt);
51172 out_dput:
51173 dput(dentry);
51174 out_unlock:
51175@@ -2134,6 +2238,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51176 if (IS_ERR(dentry))
51177 goto out_unlock;
51178
51179+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
51180+ error = -EACCES;
51181+ goto out_dput;
51182+ }
51183+
51184 if (!IS_POSIXACL(nd.path.dentry->d_inode))
51185 mode &= ~current_umask();
51186 error = mnt_want_write(nd.path.mnt);
51187@@ -2145,6 +2254,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51188 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
51189 out_drop_write:
51190 mnt_drop_write(nd.path.mnt);
51191+
51192+ if (!error)
51193+ gr_handle_create(dentry, nd.path.mnt);
51194+
51195 out_dput:
51196 dput(dentry);
51197 out_unlock:
51198@@ -2226,6 +2339,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51199 char * name;
51200 struct dentry *dentry;
51201 struct nameidata nd;
51202+ ino_t saved_ino = 0;
51203+ dev_t saved_dev = 0;
51204
51205 error = user_path_parent(dfd, pathname, &nd, &name);
51206 if (error)
51207@@ -2250,6 +2365,17 @@ static long do_rmdir(int dfd, const char __user *pathname)
51208 error = PTR_ERR(dentry);
51209 if (IS_ERR(dentry))
51210 goto exit2;
51211+
51212+ if (dentry->d_inode != NULL) {
51213+ saved_ino = dentry->d_inode->i_ino;
51214+ saved_dev = gr_get_dev_from_dentry(dentry);
51215+
51216+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
51217+ error = -EACCES;
51218+ goto exit3;
51219+ }
51220+ }
51221+
51222 error = mnt_want_write(nd.path.mnt);
51223 if (error)
51224 goto exit3;
51225@@ -2257,6 +2383,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51226 if (error)
51227 goto exit4;
51228 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
51229+ if (!error && (saved_dev || saved_ino))
51230+ gr_handle_delete(saved_ino, saved_dev);
51231 exit4:
51232 mnt_drop_write(nd.path.mnt);
51233 exit3:
51234@@ -2318,6 +2446,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51235 struct dentry *dentry;
51236 struct nameidata nd;
51237 struct inode *inode = NULL;
51238+ ino_t saved_ino = 0;
51239+ dev_t saved_dev = 0;
51240
51241 error = user_path_parent(dfd, pathname, &nd, &name);
51242 if (error)
51243@@ -2337,8 +2467,19 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51244 if (nd.last.name[nd.last.len])
51245 goto slashes;
51246 inode = dentry->d_inode;
51247- if (inode)
51248+ if (inode) {
51249+ if (inode->i_nlink <= 1) {
51250+ saved_ino = inode->i_ino;
51251+ saved_dev = gr_get_dev_from_dentry(dentry);
51252+ }
51253+
51254 atomic_inc(&inode->i_count);
51255+
51256+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
51257+ error = -EACCES;
51258+ goto exit2;
51259+ }
51260+ }
51261 error = mnt_want_write(nd.path.mnt);
51262 if (error)
51263 goto exit2;
51264@@ -2346,6 +2487,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51265 if (error)
51266 goto exit3;
51267 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
51268+ if (!error && (saved_ino || saved_dev))
51269+ gr_handle_delete(saved_ino, saved_dev);
51270 exit3:
51271 mnt_drop_write(nd.path.mnt);
51272 exit2:
51273@@ -2424,6 +2567,11 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51274 if (IS_ERR(dentry))
51275 goto out_unlock;
51276
51277+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
51278+ error = -EACCES;
51279+ goto out_dput;
51280+ }
51281+
51282 error = mnt_want_write(nd.path.mnt);
51283 if (error)
51284 goto out_dput;
51285@@ -2431,6 +2579,8 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51286 if (error)
51287 goto out_drop_write;
51288 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
51289+ if (!error)
51290+ gr_handle_create(dentry, nd.path.mnt);
51291 out_drop_write:
51292 mnt_drop_write(nd.path.mnt);
51293 out_dput:
51294@@ -2524,6 +2674,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51295 error = PTR_ERR(new_dentry);
51296 if (IS_ERR(new_dentry))
51297 goto out_unlock;
51298+
51299+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
51300+ old_path.dentry->d_inode,
51301+ old_path.dentry->d_inode->i_mode, to)) {
51302+ error = -EACCES;
51303+ goto out_dput;
51304+ }
51305+
51306+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
51307+ old_path.dentry, old_path.mnt, to)) {
51308+ error = -EACCES;
51309+ goto out_dput;
51310+ }
51311+
51312 error = mnt_want_write(nd.path.mnt);
51313 if (error)
51314 goto out_dput;
51315@@ -2531,6 +2695,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51316 if (error)
51317 goto out_drop_write;
51318 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
51319+ if (!error)
51320+ gr_handle_create(new_dentry, nd.path.mnt);
51321 out_drop_write:
51322 mnt_drop_write(nd.path.mnt);
51323 out_dput:
51324@@ -2708,6 +2874,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51325 char *to;
51326 int error;
51327
51328+ pax_track_stack();
51329+
51330 error = user_path_parent(olddfd, oldname, &oldnd, &from);
51331 if (error)
51332 goto exit;
51333@@ -2764,6 +2932,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51334 if (new_dentry == trap)
51335 goto exit5;
51336
51337+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
51338+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
51339+ to);
51340+ if (error)
51341+ goto exit5;
51342+
51343 error = mnt_want_write(oldnd.path.mnt);
51344 if (error)
51345 goto exit5;
51346@@ -2773,6 +2947,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51347 goto exit6;
51348 error = vfs_rename(old_dir->d_inode, old_dentry,
51349 new_dir->d_inode, new_dentry);
51350+ if (!error)
51351+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
51352+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
51353 exit6:
51354 mnt_drop_write(oldnd.path.mnt);
51355 exit5:
51356@@ -2798,6 +2975,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
51357
51358 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
51359 {
51360+ char tmpbuf[64];
51361+ const char *newlink;
51362 int len;
51363
51364 len = PTR_ERR(link);
51365@@ -2807,7 +2986,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
51366 len = strlen(link);
51367 if (len > (unsigned) buflen)
51368 len = buflen;
51369- if (copy_to_user(buffer, link, len))
51370+
51371+ if (len < sizeof(tmpbuf)) {
51372+ memcpy(tmpbuf, link, len);
51373+ newlink = tmpbuf;
51374+ } else
51375+ newlink = link;
51376+
51377+ if (copy_to_user(buffer, newlink, len))
51378 len = -EFAULT;
51379 out:
51380 return len;
51381diff --git a/fs/namespace.c b/fs/namespace.c
51382index 2beb0fb..11a95a5 100644
51383--- a/fs/namespace.c
51384+++ b/fs/namespace.c
51385@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51386 if (!(sb->s_flags & MS_RDONLY))
51387 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
51388 up_write(&sb->s_umount);
51389+
51390+ gr_log_remount(mnt->mnt_devname, retval);
51391+
51392 return retval;
51393 }
51394
51395@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51396 security_sb_umount_busy(mnt);
51397 up_write(&namespace_sem);
51398 release_mounts(&umount_list);
51399+
51400+ gr_log_unmount(mnt->mnt_devname, retval);
51401+
51402 return retval;
51403 }
51404
51405@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51406 if (retval)
51407 goto dput_out;
51408
51409+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
51410+ retval = -EPERM;
51411+ goto dput_out;
51412+ }
51413+
51414+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
51415+ retval = -EPERM;
51416+ goto dput_out;
51417+ }
51418+
51419 if (flags & MS_REMOUNT)
51420 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
51421 data_page);
51422@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51423 dev_name, data_page);
51424 dput_out:
51425 path_put(&path);
51426+
51427+ gr_log_mount(dev_name, dir_name, retval);
51428+
51429 return retval;
51430 }
51431
51432@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
51433 goto out1;
51434 }
51435
51436+ if (gr_handle_chroot_pivot()) {
51437+ error = -EPERM;
51438+ path_put(&old);
51439+ goto out1;
51440+ }
51441+
51442 read_lock(&current->fs->lock);
51443 root = current->fs->root;
51444 path_get(&current->fs->root);
51445diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
51446index b8b5b30..2bd9ccb 100644
51447--- a/fs/ncpfs/dir.c
51448+++ b/fs/ncpfs/dir.c
51449@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *dentry)
51450 int res, val = 0, len;
51451 __u8 __name[NCP_MAXPATHLEN + 1];
51452
51453+ pax_track_stack();
51454+
51455 parent = dget_parent(dentry);
51456 dir = parent->d_inode;
51457
51458@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
51459 int error, res, len;
51460 __u8 __name[NCP_MAXPATHLEN + 1];
51461
51462+ pax_track_stack();
51463+
51464 lock_kernel();
51465 error = -EIO;
51466 if (!ncp_conn_valid(server))
51467@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
51468 int error, result, len;
51469 int opmode;
51470 __u8 __name[NCP_MAXPATHLEN + 1];
51471-
51472+
51473 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
51474 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
51475
51476+ pax_track_stack();
51477+
51478 error = -EIO;
51479 lock_kernel();
51480 if (!ncp_conn_valid(server))
51481@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51482 int error, len;
51483 __u8 __name[NCP_MAXPATHLEN + 1];
51484
51485+ pax_track_stack();
51486+
51487 DPRINTK("ncp_mkdir: making %s/%s\n",
51488 dentry->d_parent->d_name.name, dentry->d_name.name);
51489
51490@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51491 if (!ncp_conn_valid(server))
51492 goto out;
51493
51494+ pax_track_stack();
51495+
51496 ncp_age_dentry(server, dentry);
51497 len = sizeof(__name);
51498 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
51499@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
51500 int old_len, new_len;
51501 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
51502
51503+ pax_track_stack();
51504+
51505 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
51506 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
51507 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
51508diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
51509index cf98da1..da890a9 100644
51510--- a/fs/ncpfs/inode.c
51511+++ b/fs/ncpfs/inode.c
51512@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
51513 #endif
51514 struct ncp_entry_info finfo;
51515
51516+ pax_track_stack();
51517+
51518 data.wdog_pid = NULL;
51519 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
51520 if (!server)
51521diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
51522index bfaef7b..e9d03ca 100644
51523--- a/fs/nfs/inode.c
51524+++ b/fs/nfs/inode.c
51525@@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
51526 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
51527 nfsi->attrtimeo_timestamp = jiffies;
51528
51529- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
51530+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
51531 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
51532 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
51533 else
51534@@ -973,16 +973,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51535 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51536 }
51537
51538-static atomic_long_t nfs_attr_generation_counter;
51539+static atomic_long_unchecked_t nfs_attr_generation_counter;
51540
51541 static unsigned long nfs_read_attr_generation_counter(void)
51542 {
51543- return atomic_long_read(&nfs_attr_generation_counter);
51544+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51545 }
51546
51547 unsigned long nfs_inc_attr_generation_counter(void)
51548 {
51549- return atomic_long_inc_return(&nfs_attr_generation_counter);
51550+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51551 }
51552
51553 void nfs_fattr_init(struct nfs_fattr *fattr)
51554diff --git a/fs/nfsd/lockd.c b/fs/nfsd/lockd.c
51555index cc2f505..f6a236f 100644
51556--- a/fs/nfsd/lockd.c
51557+++ b/fs/nfsd/lockd.c
51558@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
51559 fput(filp);
51560 }
51561
51562-static struct nlmsvc_binding nfsd_nlm_ops = {
51563+static const struct nlmsvc_binding nfsd_nlm_ops = {
51564 .fopen = nlm_fopen, /* open file for locking */
51565 .fclose = nlm_fclose, /* close file */
51566 };
51567diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
51568index cfc3391..dcc083a 100644
51569--- a/fs/nfsd/nfs4state.c
51570+++ b/fs/nfsd/nfs4state.c
51571@@ -3459,6 +3459,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
51572 unsigned int cmd;
51573 int err;
51574
51575+ pax_track_stack();
51576+
51577 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
51578 (long long) lock->lk_offset,
51579 (long long) lock->lk_length);
51580diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
51581index 4a82a96..0d5fb49 100644
51582--- a/fs/nfsd/nfs4xdr.c
51583+++ b/fs/nfsd/nfs4xdr.c
51584@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
51585 struct nfsd4_compoundres *resp = rqstp->rq_resp;
51586 u32 minorversion = resp->cstate.minorversion;
51587
51588+ pax_track_stack();
51589+
51590 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
51591 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
51592 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
51593diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51594index 2e09588..596421d 100644
51595--- a/fs/nfsd/vfs.c
51596+++ b/fs/nfsd/vfs.c
51597@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51598 } else {
51599 oldfs = get_fs();
51600 set_fs(KERNEL_DS);
51601- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51602+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51603 set_fs(oldfs);
51604 }
51605
51606@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51607
51608 /* Write the data. */
51609 oldfs = get_fs(); set_fs(KERNEL_DS);
51610- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51611+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51612 set_fs(oldfs);
51613 if (host_err < 0)
51614 goto out_nfserr;
51615@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51616 */
51617
51618 oldfs = get_fs(); set_fs(KERNEL_DS);
51619- host_err = inode->i_op->readlink(dentry, buf, *lenp);
51620+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
51621 set_fs(oldfs);
51622
51623 if (host_err < 0)
51624diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
51625index f6af760..d6b2b83 100644
51626--- a/fs/nilfs2/ioctl.c
51627+++ b/fs/nilfs2/ioctl.c
51628@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
51629 unsigned int cmd, void __user *argp)
51630 {
51631 struct nilfs_argv argv[5];
51632- const static size_t argsz[5] = {
51633+ static const size_t argsz[5] = {
51634 sizeof(struct nilfs_vdesc),
51635 sizeof(struct nilfs_period),
51636 sizeof(__u64),
51637diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
51638index 7e54e52..9337248 100644
51639--- a/fs/notify/dnotify/dnotify.c
51640+++ b/fs/notify/dnotify/dnotify.c
51641@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsnotify_mark_entry *entry)
51642 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
51643 }
51644
51645-static struct fsnotify_ops dnotify_fsnotify_ops = {
51646+static const struct fsnotify_ops dnotify_fsnotify_ops = {
51647 .handle_event = dnotify_handle_event,
51648 .should_send_event = dnotify_should_send_event,
51649 .free_group_priv = NULL,
51650diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51651index b8bf53b..c518688 100644
51652--- a/fs/notify/notification.c
51653+++ b/fs/notify/notification.c
51654@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51655 * get set to 0 so it will never get 'freed'
51656 */
51657 static struct fsnotify_event q_overflow_event;
51658-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51659+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51660
51661 /**
51662 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51663@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51664 */
51665 u32 fsnotify_get_cookie(void)
51666 {
51667- return atomic_inc_return(&fsnotify_sync_cookie);
51668+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51669 }
51670 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51671
51672diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51673index 5a9e344..0f8cd28 100644
51674--- a/fs/ntfs/dir.c
51675+++ b/fs/ntfs/dir.c
51676@@ -1328,7 +1328,7 @@ find_next_index_buffer:
51677 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51678 ~(s64)(ndir->itype.index.block_size - 1)));
51679 /* Bounds checks. */
51680- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51681+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51682 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51683 "inode 0x%lx or driver bug.", vdir->i_ino);
51684 goto err_out;
51685diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51686index 663c0e3..b6868e9 100644
51687--- a/fs/ntfs/file.c
51688+++ b/fs/ntfs/file.c
51689@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51690 #endif /* NTFS_RW */
51691 };
51692
51693-const struct file_operations ntfs_empty_file_ops = {};
51694+const struct file_operations ntfs_empty_file_ops __read_only;
51695
51696-const struct inode_operations ntfs_empty_inode_ops = {};
51697+const struct inode_operations ntfs_empty_inode_ops __read_only;
51698diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
51699index 1cd2934..880b5d2 100644
51700--- a/fs/ocfs2/cluster/masklog.c
51701+++ b/fs/ocfs2/cluster/masklog.c
51702@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
51703 return mlog_mask_store(mlog_attr->mask, buf, count);
51704 }
51705
51706-static struct sysfs_ops mlog_attr_ops = {
51707+static const struct sysfs_ops mlog_attr_ops = {
51708 .show = mlog_show,
51709 .store = mlog_store,
51710 };
51711diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51712index ac10f83..2cd2607 100644
51713--- a/fs/ocfs2/localalloc.c
51714+++ b/fs/ocfs2/localalloc.c
51715@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51716 goto bail;
51717 }
51718
51719- atomic_inc(&osb->alloc_stats.moves);
51720+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51721
51722 status = 0;
51723 bail:
51724diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
51725index f010b22..9f9ed34 100644
51726--- a/fs/ocfs2/namei.c
51727+++ b/fs/ocfs2/namei.c
51728@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *old_dir,
51729 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
51730 struct ocfs2_dir_lookup_result target_insert = { NULL, };
51731
51732+ pax_track_stack();
51733+
51734 /* At some point it might be nice to break this function up a
51735 * bit. */
51736
51737diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51738index d963d86..914cfbd 100644
51739--- a/fs/ocfs2/ocfs2.h
51740+++ b/fs/ocfs2/ocfs2.h
51741@@ -217,11 +217,11 @@ enum ocfs2_vol_state
51742
51743 struct ocfs2_alloc_stats
51744 {
51745- atomic_t moves;
51746- atomic_t local_data;
51747- atomic_t bitmap_data;
51748- atomic_t bg_allocs;
51749- atomic_t bg_extends;
51750+ atomic_unchecked_t moves;
51751+ atomic_unchecked_t local_data;
51752+ atomic_unchecked_t bitmap_data;
51753+ atomic_unchecked_t bg_allocs;
51754+ atomic_unchecked_t bg_extends;
51755 };
51756
51757 enum ocfs2_local_alloc_state
51758diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51759index 79b5dac..d322952 100644
51760--- a/fs/ocfs2/suballoc.c
51761+++ b/fs/ocfs2/suballoc.c
51762@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51763 mlog_errno(status);
51764 goto bail;
51765 }
51766- atomic_inc(&osb->alloc_stats.bg_extends);
51767+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51768
51769 /* You should never ask for this much metadata */
51770 BUG_ON(bits_wanted >
51771@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb,
51772 mlog_errno(status);
51773 goto bail;
51774 }
51775- atomic_inc(&osb->alloc_stats.bg_allocs);
51776+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51777
51778 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
51779 ac->ac_bits_given += (*num_bits);
51780@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb,
51781 mlog_errno(status);
51782 goto bail;
51783 }
51784- atomic_inc(&osb->alloc_stats.bg_allocs);
51785+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51786
51787 BUG_ON(num_bits != 1);
51788
51789@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51790 cluster_start,
51791 num_clusters);
51792 if (!status)
51793- atomic_inc(&osb->alloc_stats.local_data);
51794+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51795 } else {
51796 if (min_clusters > (osb->bitmap_cpg - 1)) {
51797 /* The only paths asking for contiguousness
51798@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51799 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51800 bg_blkno,
51801 bg_bit_off);
51802- atomic_inc(&osb->alloc_stats.bitmap_data);
51803+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51804 }
51805 }
51806 if (status < 0) {
51807diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51808index 9f55be4..a3f8048 100644
51809--- a/fs/ocfs2/super.c
51810+++ b/fs/ocfs2/super.c
51811@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51812 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51813 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51814 "Stats",
51815- atomic_read(&osb->alloc_stats.bitmap_data),
51816- atomic_read(&osb->alloc_stats.local_data),
51817- atomic_read(&osb->alloc_stats.bg_allocs),
51818- atomic_read(&osb->alloc_stats.moves),
51819- atomic_read(&osb->alloc_stats.bg_extends));
51820+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51821+ atomic_read_unchecked(&osb->alloc_stats.local_data),
51822+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51823+ atomic_read_unchecked(&osb->alloc_stats.moves),
51824+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51825
51826 out += snprintf(buf + out, len - out,
51827 "%10s => State: %u Descriptor: %llu Size: %u bits "
51828@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51829 spin_lock_init(&osb->osb_xattr_lock);
51830 ocfs2_init_inode_steal_slot(osb);
51831
51832- atomic_set(&osb->alloc_stats.moves, 0);
51833- atomic_set(&osb->alloc_stats.local_data, 0);
51834- atomic_set(&osb->alloc_stats.bitmap_data, 0);
51835- atomic_set(&osb->alloc_stats.bg_allocs, 0);
51836- atomic_set(&osb->alloc_stats.bg_extends, 0);
51837+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51838+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51839+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51840+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51841+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51842
51843 /* Copy the blockcheck stats from the superblock probe */
51844 osb->osb_ecc_stats = *stats;
51845diff --git a/fs/open.c b/fs/open.c
51846index 4f01e06..091f6c3 100644
51847--- a/fs/open.c
51848+++ b/fs/open.c
51849@@ -275,6 +275,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
51850 error = locks_verify_truncate(inode, NULL, length);
51851 if (!error)
51852 error = security_path_truncate(&path, length, 0);
51853+
51854+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
51855+ error = -EACCES;
51856+
51857 if (!error) {
51858 vfs_dq_init(inode);
51859 error = do_truncate(path.dentry, length, 0, NULL);
51860@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
51861 if (__mnt_is_readonly(path.mnt))
51862 res = -EROFS;
51863
51864+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51865+ res = -EACCES;
51866+
51867 out_path_release:
51868 path_put(&path);
51869 out:
51870@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
51871 if (error)
51872 goto dput_and_out;
51873
51874+ gr_log_chdir(path.dentry, path.mnt);
51875+
51876 set_fs_pwd(current->fs, &path);
51877
51878 dput_and_out:
51879@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51880 goto out_putf;
51881
51882 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
51883+
51884+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
51885+ error = -EPERM;
51886+
51887+ if (!error)
51888+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
51889+
51890 if (!error)
51891 set_fs_pwd(current->fs, &file->f_path);
51892 out_putf:
51893@@ -588,7 +604,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
51894 if (!capable(CAP_SYS_CHROOT))
51895 goto dput_and_out;
51896
51897+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51898+ goto dput_and_out;
51899+
51900 set_fs_root(current->fs, &path);
51901+
51902+ gr_handle_chroot_chdir(&path);
51903+
51904 error = 0;
51905 dput_and_out:
51906 path_put(&path);
51907@@ -616,12 +638,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
51908 err = mnt_want_write_file(file);
51909 if (err)
51910 goto out_putf;
51911+
51912 mutex_lock(&inode->i_mutex);
51913+
51914+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
51915+ err = -EACCES;
51916+ goto out_unlock;
51917+ }
51918+
51919 if (mode == (mode_t) -1)
51920 mode = inode->i_mode;
51921+
51922+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
51923+ err = -EPERM;
51924+ goto out_unlock;
51925+ }
51926+
51927 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
51928 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
51929 err = notify_change(dentry, &newattrs);
51930+
51931+out_unlock:
51932 mutex_unlock(&inode->i_mutex);
51933 mnt_drop_write(file->f_path.mnt);
51934 out_putf:
51935@@ -645,12 +682,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
51936 error = mnt_want_write(path.mnt);
51937 if (error)
51938 goto dput_and_out;
51939+
51940 mutex_lock(&inode->i_mutex);
51941+
51942+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
51943+ error = -EACCES;
51944+ goto out_unlock;
51945+ }
51946+
51947 if (mode == (mode_t) -1)
51948 mode = inode->i_mode;
51949+
51950+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
51951+ error = -EACCES;
51952+ goto out_unlock;
51953+ }
51954+
51955 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
51956 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
51957 error = notify_change(path.dentry, &newattrs);
51958+
51959+out_unlock:
51960 mutex_unlock(&inode->i_mutex);
51961 mnt_drop_write(path.mnt);
51962 dput_and_out:
51963@@ -664,12 +716,15 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode)
51964 return sys_fchmodat(AT_FDCWD, filename, mode);
51965 }
51966
51967-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
51968+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
51969 {
51970 struct inode *inode = dentry->d_inode;
51971 int error;
51972 struct iattr newattrs;
51973
51974+ if (!gr_acl_handle_chown(dentry, mnt))
51975+ return -EACCES;
51976+
51977 newattrs.ia_valid = ATTR_CTIME;
51978 if (user != (uid_t) -1) {
51979 newattrs.ia_valid |= ATTR_UID;
51980@@ -700,7 +755,7 @@ SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
51981 error = mnt_want_write(path.mnt);
51982 if (error)
51983 goto out_release;
51984- error = chown_common(path.dentry, user, group);
51985+ error = chown_common(path.dentry, user, group, path.mnt);
51986 mnt_drop_write(path.mnt);
51987 out_release:
51988 path_put(&path);
51989@@ -725,7 +780,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
51990 error = mnt_want_write(path.mnt);
51991 if (error)
51992 goto out_release;
51993- error = chown_common(path.dentry, user, group);
51994+ error = chown_common(path.dentry, user, group, path.mnt);
51995 mnt_drop_write(path.mnt);
51996 out_release:
51997 path_put(&path);
51998@@ -744,7 +799,7 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
51999 error = mnt_want_write(path.mnt);
52000 if (error)
52001 goto out_release;
52002- error = chown_common(path.dentry, user, group);
52003+ error = chown_common(path.dentry, user, group, path.mnt);
52004 mnt_drop_write(path.mnt);
52005 out_release:
52006 path_put(&path);
52007@@ -767,7 +822,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
52008 goto out_fput;
52009 dentry = file->f_path.dentry;
52010 audit_inode(NULL, dentry);
52011- error = chown_common(dentry, user, group);
52012+ error = chown_common(dentry, user, group, file->f_path.mnt);
52013 mnt_drop_write(file->f_path.mnt);
52014 out_fput:
52015 fput(file);
52016@@ -1036,7 +1091,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
52017 if (!IS_ERR(tmp)) {
52018 fd = get_unused_fd_flags(flags);
52019 if (fd >= 0) {
52020- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
52021+ struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
52022 if (IS_ERR(f)) {
52023 put_unused_fd(fd);
52024 fd = PTR_ERR(f);
52025diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
52026index 6ab70f4..f4103d1 100644
52027--- a/fs/partitions/efi.c
52028+++ b/fs/partitions/efi.c
52029@@ -231,14 +231,14 @@ alloc_read_gpt_entries(struct block_device *bdev, gpt_header *gpt)
52030 if (!bdev || !gpt)
52031 return NULL;
52032
52033+ if (!le32_to_cpu(gpt->num_partition_entries))
52034+ return NULL;
52035+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
52036+ if (!pte)
52037+ return NULL;
52038+
52039 count = le32_to_cpu(gpt->num_partition_entries) *
52040 le32_to_cpu(gpt->sizeof_partition_entry);
52041- if (!count)
52042- return NULL;
52043- pte = kzalloc(count, GFP_KERNEL);
52044- if (!pte)
52045- return NULL;
52046-
52047 if (read_lba(bdev, le64_to_cpu(gpt->partition_entry_lba),
52048 (u8 *) pte,
52049 count) < count) {
52050diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
52051index dd6efdb..3babc6c 100644
52052--- a/fs/partitions/ldm.c
52053+++ b/fs/partitions/ldm.c
52054@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52055 ldm_error ("A VBLK claims to have %d parts.", num);
52056 return false;
52057 }
52058+
52059 if (rec >= num) {
52060 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
52061 return false;
52062@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52063 goto found;
52064 }
52065
52066- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
52067+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
52068 if (!f) {
52069 ldm_crit ("Out of memory.");
52070 return false;
52071diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
52072index 5765198..7f8e9e0 100644
52073--- a/fs/partitions/mac.c
52074+++ b/fs/partitions/mac.c
52075@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
52076 return 0; /* not a MacOS disk */
52077 }
52078 blocks_in_map = be32_to_cpu(part->map_count);
52079- if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52080- put_dev_sector(sect);
52081- return 0;
52082- }
52083 printk(" [mac]");
52084+ if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52085+ put_dev_sector(sect);
52086+ return 0;
52087+ }
52088 for (slot = 1; slot <= blocks_in_map; ++slot) {
52089 int pos = slot * secsize;
52090 put_dev_sector(sect);
52091diff --git a/fs/pipe.c b/fs/pipe.c
52092index d0cc080..8a6f211 100644
52093--- a/fs/pipe.c
52094+++ b/fs/pipe.c
52095@@ -401,9 +401,9 @@ redo:
52096 }
52097 if (bufs) /* More to do? */
52098 continue;
52099- if (!pipe->writers)
52100+ if (!atomic_read(&pipe->writers))
52101 break;
52102- if (!pipe->waiting_writers) {
52103+ if (!atomic_read(&pipe->waiting_writers)) {
52104 /* syscall merging: Usually we must not sleep
52105 * if O_NONBLOCK is set, or if we got some data.
52106 * But if a writer sleeps in kernel space, then
52107@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
52108 mutex_lock(&inode->i_mutex);
52109 pipe = inode->i_pipe;
52110
52111- if (!pipe->readers) {
52112+ if (!atomic_read(&pipe->readers)) {
52113 send_sig(SIGPIPE, current, 0);
52114 ret = -EPIPE;
52115 goto out;
52116@@ -511,7 +511,7 @@ redo1:
52117 for (;;) {
52118 int bufs;
52119
52120- if (!pipe->readers) {
52121+ if (!atomic_read(&pipe->readers)) {
52122 send_sig(SIGPIPE, current, 0);
52123 if (!ret)
52124 ret = -EPIPE;
52125@@ -597,9 +597,9 @@ redo2:
52126 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
52127 do_wakeup = 0;
52128 }
52129- pipe->waiting_writers++;
52130+ atomic_inc(&pipe->waiting_writers);
52131 pipe_wait(pipe);
52132- pipe->waiting_writers--;
52133+ atomic_dec(&pipe->waiting_writers);
52134 }
52135 out:
52136 mutex_unlock(&inode->i_mutex);
52137@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52138 mask = 0;
52139 if (filp->f_mode & FMODE_READ) {
52140 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
52141- if (!pipe->writers && filp->f_version != pipe->w_counter)
52142+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
52143 mask |= POLLHUP;
52144 }
52145
52146@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52147 * Most Unices do not set POLLERR for FIFOs but on Linux they
52148 * behave exactly like pipes for poll().
52149 */
52150- if (!pipe->readers)
52151+ if (!atomic_read(&pipe->readers))
52152 mask |= POLLERR;
52153 }
52154
52155@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int decr, int decw)
52156
52157 mutex_lock(&inode->i_mutex);
52158 pipe = inode->i_pipe;
52159- pipe->readers -= decr;
52160- pipe->writers -= decw;
52161+ atomic_sub(decr, &pipe->readers);
52162+ atomic_sub(decw, &pipe->writers);
52163
52164- if (!pipe->readers && !pipe->writers) {
52165+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
52166 free_pipe_info(inode);
52167 } else {
52168 wake_up_interruptible_sync(&pipe->wait);
52169@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
52170
52171 if (inode->i_pipe) {
52172 ret = 0;
52173- inode->i_pipe->readers++;
52174+ atomic_inc(&inode->i_pipe->readers);
52175 }
52176
52177 mutex_unlock(&inode->i_mutex);
52178@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
52179
52180 if (inode->i_pipe) {
52181 ret = 0;
52182- inode->i_pipe->writers++;
52183+ atomic_inc(&inode->i_pipe->writers);
52184 }
52185
52186 mutex_unlock(&inode->i_mutex);
52187@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
52188 if (inode->i_pipe) {
52189 ret = 0;
52190 if (filp->f_mode & FMODE_READ)
52191- inode->i_pipe->readers++;
52192+ atomic_inc(&inode->i_pipe->readers);
52193 if (filp->f_mode & FMODE_WRITE)
52194- inode->i_pipe->writers++;
52195+ atomic_inc(&inode->i_pipe->writers);
52196 }
52197
52198 mutex_unlock(&inode->i_mutex);
52199@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
52200 inode->i_pipe = NULL;
52201 }
52202
52203-static struct vfsmount *pipe_mnt __read_mostly;
52204+struct vfsmount *pipe_mnt __read_mostly;
52205 static int pipefs_delete_dentry(struct dentry *dentry)
52206 {
52207 /*
52208@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(void)
52209 goto fail_iput;
52210 inode->i_pipe = pipe;
52211
52212- pipe->readers = pipe->writers = 1;
52213+ atomic_set(&pipe->readers, 1);
52214+ atomic_set(&pipe->writers, 1);
52215 inode->i_fop = &rdwr_pipefifo_fops;
52216
52217 /*
52218diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
52219index 50f8f06..c5755df 100644
52220--- a/fs/proc/Kconfig
52221+++ b/fs/proc/Kconfig
52222@@ -30,12 +30,12 @@ config PROC_FS
52223
52224 config PROC_KCORE
52225 bool "/proc/kcore support" if !ARM
52226- depends on PROC_FS && MMU
52227+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
52228
52229 config PROC_VMCORE
52230 bool "/proc/vmcore support (EXPERIMENTAL)"
52231- depends on PROC_FS && CRASH_DUMP
52232- default y
52233+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
52234+ default n
52235 help
52236 Exports the dump image of crashed kernel in ELF format.
52237
52238@@ -59,8 +59,8 @@ config PROC_SYSCTL
52239 limited in memory.
52240
52241 config PROC_PAGE_MONITOR
52242- default y
52243- depends on PROC_FS && MMU
52244+ default n
52245+ depends on PROC_FS && MMU && !GRKERNSEC
52246 bool "Enable /proc page monitoring" if EMBEDDED
52247 help
52248 Various /proc files exist to monitor process memory utilization:
52249diff --git a/fs/proc/array.c b/fs/proc/array.c
52250index c5ef152..1363194 100644
52251--- a/fs/proc/array.c
52252+++ b/fs/proc/array.c
52253@@ -60,6 +60,7 @@
52254 #include <linux/tty.h>
52255 #include <linux/string.h>
52256 #include <linux/mman.h>
52257+#include <linux/grsecurity.h>
52258 #include <linux/proc_fs.h>
52259 #include <linux/ioport.h>
52260 #include <linux/uaccess.h>
52261@@ -321,6 +322,21 @@ static inline void task_context_switch_counts(struct seq_file *m,
52262 p->nivcsw);
52263 }
52264
52265+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52266+static inline void task_pax(struct seq_file *m, struct task_struct *p)
52267+{
52268+ if (p->mm)
52269+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
52270+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
52271+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
52272+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
52273+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
52274+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
52275+ else
52276+ seq_printf(m, "PaX:\t-----\n");
52277+}
52278+#endif
52279+
52280 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52281 struct pid *pid, struct task_struct *task)
52282 {
52283@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52284 task_cap(m, task);
52285 cpuset_task_status_allowed(m, task);
52286 task_context_switch_counts(m, task);
52287+
52288+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52289+ task_pax(m, task);
52290+#endif
52291+
52292+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
52293+ task_grsec_rbac(m, task);
52294+#endif
52295+
52296 return 0;
52297 }
52298
52299+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52300+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52301+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52302+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52303+#endif
52304+
52305 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52306 struct pid *pid, struct task_struct *task, int whole)
52307 {
52308@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52309 cputime_t cutime, cstime, utime, stime;
52310 cputime_t cgtime, gtime;
52311 unsigned long rsslim = 0;
52312- char tcomm[sizeof(task->comm)];
52313+ char tcomm[sizeof(task->comm)] = { 0 };
52314 unsigned long flags;
52315
52316+ pax_track_stack();
52317+
52318 state = *get_task_state(task);
52319 vsize = eip = esp = 0;
52320 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
52321@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52322 gtime = task_gtime(task);
52323 }
52324
52325+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52326+ if (PAX_RAND_FLAGS(mm)) {
52327+ eip = 0;
52328+ esp = 0;
52329+ wchan = 0;
52330+ }
52331+#endif
52332+#ifdef CONFIG_GRKERNSEC_HIDESYM
52333+ wchan = 0;
52334+ eip =0;
52335+ esp =0;
52336+#endif
52337+
52338 /* scale priority and nice values from timeslices to -20..20 */
52339 /* to make it look like a "normal" Unix priority/nice value */
52340 priority = task_prio(task);
52341@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52342 vsize,
52343 mm ? get_mm_rss(mm) : 0,
52344 rsslim,
52345+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52346+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
52347+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
52348+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
52349+#else
52350 mm ? (permitted ? mm->start_code : 1) : 0,
52351 mm ? (permitted ? mm->end_code : 1) : 0,
52352 (permitted && mm) ? mm->start_stack : 0,
52353+#endif
52354 esp,
52355 eip,
52356 /* The signal information here is obsolete.
52357@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52358
52359 return 0;
52360 }
52361+
52362+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52363+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
52364+{
52365+ u32 curr_ip = 0;
52366+ unsigned long flags;
52367+
52368+ if (lock_task_sighand(task, &flags)) {
52369+ curr_ip = task->signal->curr_ip;
52370+ unlock_task_sighand(task, &flags);
52371+ }
52372+
52373+ return sprintf(buffer, "%pI4\n", &curr_ip);
52374+}
52375+#endif
52376diff --git a/fs/proc/base.c b/fs/proc/base.c
52377index 67f7dc0..e95ea4f 100644
52378--- a/fs/proc/base.c
52379+++ b/fs/proc/base.c
52380@@ -102,6 +102,22 @@ struct pid_entry {
52381 union proc_op op;
52382 };
52383
52384+struct getdents_callback {
52385+ struct linux_dirent __user * current_dir;
52386+ struct linux_dirent __user * previous;
52387+ struct file * file;
52388+ int count;
52389+ int error;
52390+};
52391+
52392+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
52393+ loff_t offset, u64 ino, unsigned int d_type)
52394+{
52395+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
52396+ buf->error = -EINVAL;
52397+ return 0;
52398+}
52399+
52400 #define NOD(NAME, MODE, IOP, FOP, OP) { \
52401 .name = (NAME), \
52402 .len = sizeof(NAME) - 1, \
52403@@ -213,6 +229,9 @@ static int check_mem_permission(struct task_struct *task)
52404 if (task == current)
52405 return 0;
52406
52407+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
52408+ return -EPERM;
52409+
52410 /*
52411 * If current is actively ptrace'ing, and would also be
52412 * permitted to freshly attach with ptrace now, permit it.
52413@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
52414 if (!mm->arg_end)
52415 goto out_mm; /* Shh! No looking before we're done */
52416
52417+ if (gr_acl_handle_procpidmem(task))
52418+ goto out_mm;
52419+
52420 len = mm->arg_end - mm->arg_start;
52421
52422 if (len > PAGE_SIZE)
52423@@ -287,12 +309,28 @@ out:
52424 return res;
52425 }
52426
52427+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52428+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52429+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52430+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52431+#endif
52432+
52433 static int proc_pid_auxv(struct task_struct *task, char *buffer)
52434 {
52435 int res = 0;
52436 struct mm_struct *mm = get_task_mm(task);
52437 if (mm) {
52438 unsigned int nwords = 0;
52439+
52440+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52441+ /* allow if we're currently ptracing this task */
52442+ if (PAX_RAND_FLAGS(mm) &&
52443+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
52444+ mmput(mm);
52445+ return 0;
52446+ }
52447+#endif
52448+
52449 do {
52450 nwords += 2;
52451 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
52452@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
52453 }
52454
52455
52456-#ifdef CONFIG_KALLSYMS
52457+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52458 /*
52459 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
52460 * Returns the resolved symbol. If that fails, simply return the address.
52461@@ -345,7 +383,7 @@ static void unlock_trace(struct task_struct *task)
52462 mutex_unlock(&task->cred_guard_mutex);
52463 }
52464
52465-#ifdef CONFIG_STACKTRACE
52466+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52467
52468 #define MAX_STACK_TRACE_DEPTH 64
52469
52470@@ -545,7 +583,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
52471 return count;
52472 }
52473
52474-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52475+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52476 static int proc_pid_syscall(struct task_struct *task, char *buffer)
52477 {
52478 long nr;
52479@@ -574,7 +612,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
52480 /************************************************************************/
52481
52482 /* permission checks */
52483-static int proc_fd_access_allowed(struct inode *inode)
52484+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
52485 {
52486 struct task_struct *task;
52487 int allowed = 0;
52488@@ -584,7 +622,10 @@ static int proc_fd_access_allowed(struct inode *inode)
52489 */
52490 task = get_proc_task(inode);
52491 if (task) {
52492- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52493+ if (log)
52494+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
52495+ else
52496+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52497 put_task_struct(task);
52498 }
52499 return allowed;
52500@@ -963,6 +1004,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
52501 if (!task)
52502 goto out_no_task;
52503
52504+ if (gr_acl_handle_procpidmem(task))
52505+ goto out;
52506+
52507 if (!ptrace_may_access(task, PTRACE_MODE_READ))
52508 goto out;
52509
52510@@ -1377,7 +1421,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
52511 path_put(&nd->path);
52512
52513 /* Are we allowed to snoop on the tasks file descriptors? */
52514- if (!proc_fd_access_allowed(inode))
52515+ if (!proc_fd_access_allowed(inode,0))
52516 goto out;
52517
52518 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
52519@@ -1417,8 +1461,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
52520 struct path path;
52521
52522 /* Are we allowed to snoop on the tasks file descriptors? */
52523- if (!proc_fd_access_allowed(inode))
52524- goto out;
52525+ /* logging this is needed for learning on chromium to work properly,
52526+ but we don't want to flood the logs from 'ps' which does a readlink
52527+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
52528+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
52529+ */
52530+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
52531+ if (!proc_fd_access_allowed(inode,0))
52532+ goto out;
52533+ } else {
52534+ if (!proc_fd_access_allowed(inode,1))
52535+ goto out;
52536+ }
52537
52538 error = PROC_I(inode)->op.proc_get_link(inode, &path);
52539 if (error)
52540@@ -1483,7 +1537,11 @@ static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_st
52541 rcu_read_lock();
52542 cred = __task_cred(task);
52543 inode->i_uid = cred->euid;
52544+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52545+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52546+#else
52547 inode->i_gid = cred->egid;
52548+#endif
52549 rcu_read_unlock();
52550 }
52551 security_task_to_inode(task, inode);
52552@@ -1501,6 +1559,9 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52553 struct inode *inode = dentry->d_inode;
52554 struct task_struct *task;
52555 const struct cred *cred;
52556+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52557+ const struct cred *tmpcred = current_cred();
52558+#endif
52559
52560 generic_fillattr(inode, stat);
52561
52562@@ -1508,13 +1569,41 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52563 stat->uid = 0;
52564 stat->gid = 0;
52565 task = pid_task(proc_pid(inode), PIDTYPE_PID);
52566+
52567+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
52568+ rcu_read_unlock();
52569+ return -ENOENT;
52570+ }
52571+
52572 if (task) {
52573+ cred = __task_cred(task);
52574+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52575+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
52576+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52577+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52578+#endif
52579+ ) {
52580+#endif
52581 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52582+#ifdef CONFIG_GRKERNSEC_PROC_USER
52583+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52584+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52585+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52586+#endif
52587 task_dumpable(task)) {
52588- cred = __task_cred(task);
52589 stat->uid = cred->euid;
52590+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52591+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
52592+#else
52593 stat->gid = cred->egid;
52594+#endif
52595 }
52596+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52597+ } else {
52598+ rcu_read_unlock();
52599+ return -ENOENT;
52600+ }
52601+#endif
52602 }
52603 rcu_read_unlock();
52604 return 0;
52605@@ -1545,11 +1634,20 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
52606
52607 if (task) {
52608 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52609+#ifdef CONFIG_GRKERNSEC_PROC_USER
52610+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52611+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52612+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52613+#endif
52614 task_dumpable(task)) {
52615 rcu_read_lock();
52616 cred = __task_cred(task);
52617 inode->i_uid = cred->euid;
52618+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52619+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52620+#else
52621 inode->i_gid = cred->egid;
52622+#endif
52623 rcu_read_unlock();
52624 } else {
52625 inode->i_uid = 0;
52626@@ -1670,7 +1768,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
52627 int fd = proc_fd(inode);
52628
52629 if (task) {
52630- files = get_files_struct(task);
52631+ if (!gr_acl_handle_procpidmem(task))
52632+ files = get_files_struct(task);
52633 put_task_struct(task);
52634 }
52635 if (files) {
52636@@ -1922,12 +2021,22 @@ static const struct file_operations proc_fd_operations = {
52637 static int proc_fd_permission(struct inode *inode, int mask)
52638 {
52639 int rv;
52640+ struct task_struct *task;
52641
52642 rv = generic_permission(inode, mask, NULL);
52643- if (rv == 0)
52644- return 0;
52645+
52646 if (task_pid(current) == proc_pid(inode))
52647 rv = 0;
52648+
52649+ task = get_proc_task(inode);
52650+ if (task == NULL)
52651+ return rv;
52652+
52653+ if (gr_acl_handle_procpidmem(task))
52654+ rv = -EACCES;
52655+
52656+ put_task_struct(task);
52657+
52658 return rv;
52659 }
52660
52661@@ -2036,6 +2145,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
52662 if (!task)
52663 goto out_no_task;
52664
52665+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52666+ goto out;
52667+
52668 /*
52669 * Yes, it does not scale. And it should not. Don't add
52670 * new entries into /proc/<tgid>/ without very good reasons.
52671@@ -2080,6 +2192,9 @@ static int proc_pident_readdir(struct file *filp,
52672 if (!task)
52673 goto out_no_task;
52674
52675+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52676+ goto out;
52677+
52678 ret = 0;
52679 i = filp->f_pos;
52680 switch (i) {
52681@@ -2347,7 +2462,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52682 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52683 void *cookie)
52684 {
52685- char *s = nd_get_link(nd);
52686+ const char *s = nd_get_link(nd);
52687 if (!IS_ERR(s))
52688 __putname(s);
52689 }
52690@@ -2553,7 +2668,7 @@ static const struct pid_entry tgid_base_stuff[] = {
52691 #ifdef CONFIG_SCHED_DEBUG
52692 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52693 #endif
52694-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52695+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52696 INF("syscall", S_IRUGO, proc_pid_syscall),
52697 #endif
52698 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52699@@ -2578,10 +2693,10 @@ static const struct pid_entry tgid_base_stuff[] = {
52700 #ifdef CONFIG_SECURITY
52701 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52702 #endif
52703-#ifdef CONFIG_KALLSYMS
52704+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52705 INF("wchan", S_IRUGO, proc_pid_wchan),
52706 #endif
52707-#ifdef CONFIG_STACKTRACE
52708+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52709 ONE("stack", S_IRUGO, proc_pid_stack),
52710 #endif
52711 #ifdef CONFIG_SCHEDSTATS
52712@@ -2611,6 +2726,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52713 #ifdef CONFIG_TASK_IO_ACCOUNTING
52714 INF("io", S_IRUSR, proc_tgid_io_accounting),
52715 #endif
52716+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52717+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52718+#endif
52719 };
52720
52721 static int proc_tgid_base_readdir(struct file * filp,
52722@@ -2735,7 +2853,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52723 if (!inode)
52724 goto out;
52725
52726+#ifdef CONFIG_GRKERNSEC_PROC_USER
52727+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52728+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52729+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52730+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52731+#else
52732 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52733+#endif
52734 inode->i_op = &proc_tgid_base_inode_operations;
52735 inode->i_fop = &proc_tgid_base_operations;
52736 inode->i_flags|=S_IMMUTABLE;
52737@@ -2777,7 +2902,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
52738 if (!task)
52739 goto out;
52740
52741+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52742+ goto out_put_task;
52743+
52744 result = proc_pid_instantiate(dir, dentry, task, NULL);
52745+out_put_task:
52746 put_task_struct(task);
52747 out:
52748 return result;
52749@@ -2842,6 +2971,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52750 {
52751 unsigned int nr;
52752 struct task_struct *reaper;
52753+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52754+ const struct cred *tmpcred = current_cred();
52755+ const struct cred *itercred;
52756+#endif
52757+ filldir_t __filldir = filldir;
52758 struct tgid_iter iter;
52759 struct pid_namespace *ns;
52760
52761@@ -2865,8 +2999,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52762 for (iter = next_tgid(ns, iter);
52763 iter.task;
52764 iter.tgid += 1, iter = next_tgid(ns, iter)) {
52765+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52766+ rcu_read_lock();
52767+ itercred = __task_cred(iter.task);
52768+#endif
52769+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
52770+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52771+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
52772+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52773+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52774+#endif
52775+ )
52776+#endif
52777+ )
52778+ __filldir = &gr_fake_filldir;
52779+ else
52780+ __filldir = filldir;
52781+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52782+ rcu_read_unlock();
52783+#endif
52784 filp->f_pos = iter.tgid + TGID_OFFSET;
52785- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
52786+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
52787 put_task_struct(iter.task);
52788 goto out;
52789 }
52790@@ -2892,7 +3045,7 @@ static const struct pid_entry tid_base_stuff[] = {
52791 #ifdef CONFIG_SCHED_DEBUG
52792 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52793 #endif
52794-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52795+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52796 INF("syscall", S_IRUGO, proc_pid_syscall),
52797 #endif
52798 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52799@@ -2916,10 +3069,10 @@ static const struct pid_entry tid_base_stuff[] = {
52800 #ifdef CONFIG_SECURITY
52801 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52802 #endif
52803-#ifdef CONFIG_KALLSYMS
52804+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52805 INF("wchan", S_IRUGO, proc_pid_wchan),
52806 #endif
52807-#ifdef CONFIG_STACKTRACE
52808+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52809 ONE("stack", S_IRUGO, proc_pid_stack),
52810 #endif
52811 #ifdef CONFIG_SCHEDSTATS
52812diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52813index 82676e3..5f8518a 100644
52814--- a/fs/proc/cmdline.c
52815+++ b/fs/proc/cmdline.c
52816@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52817
52818 static int __init proc_cmdline_init(void)
52819 {
52820+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52821+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52822+#else
52823 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52824+#endif
52825 return 0;
52826 }
52827 module_init(proc_cmdline_init);
52828diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52829index 59ee7da..469b4b6 100644
52830--- a/fs/proc/devices.c
52831+++ b/fs/proc/devices.c
52832@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52833
52834 static int __init proc_devices_init(void)
52835 {
52836+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52837+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52838+#else
52839 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52840+#endif
52841 return 0;
52842 }
52843 module_init(proc_devices_init);
52844diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52845index d78ade3..81767f9 100644
52846--- a/fs/proc/inode.c
52847+++ b/fs/proc/inode.c
52848@@ -18,12 +18,19 @@
52849 #include <linux/module.h>
52850 #include <linux/smp_lock.h>
52851 #include <linux/sysctl.h>
52852+#include <linux/grsecurity.h>
52853
52854 #include <asm/system.h>
52855 #include <asm/uaccess.h>
52856
52857 #include "internal.h"
52858
52859+#ifdef CONFIG_PROC_SYSCTL
52860+extern const struct inode_operations proc_sys_inode_operations;
52861+extern const struct inode_operations proc_sys_dir_operations;
52862+#endif
52863+
52864+
52865 struct proc_dir_entry *de_get(struct proc_dir_entry *de)
52866 {
52867 atomic_inc(&de->count);
52868@@ -62,6 +69,13 @@ static void proc_delete_inode(struct inode *inode)
52869 de_put(de);
52870 if (PROC_I(inode)->sysctl)
52871 sysctl_head_put(PROC_I(inode)->sysctl);
52872+
52873+#ifdef CONFIG_PROC_SYSCTL
52874+ if (inode->i_op == &proc_sys_inode_operations ||
52875+ inode->i_op == &proc_sys_dir_operations)
52876+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52877+#endif
52878+
52879 clear_inode(inode);
52880 }
52881
52882@@ -457,7 +471,11 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
52883 if (de->mode) {
52884 inode->i_mode = de->mode;
52885 inode->i_uid = de->uid;
52886+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52887+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52888+#else
52889 inode->i_gid = de->gid;
52890+#endif
52891 }
52892 if (de->size)
52893 inode->i_size = de->size;
52894diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52895index 753ca37..26bcf3b 100644
52896--- a/fs/proc/internal.h
52897+++ b/fs/proc/internal.h
52898@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52899 struct pid *pid, struct task_struct *task);
52900 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52901 struct pid *pid, struct task_struct *task);
52902+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52903+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52904+#endif
52905 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52906
52907 extern const struct file_operations proc_maps_operations;
52908diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52909index b442dac..aab29cb 100644
52910--- a/fs/proc/kcore.c
52911+++ b/fs/proc/kcore.c
52912@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
52913 off_t offset = 0;
52914 struct kcore_list *m;
52915
52916+ pax_track_stack();
52917+
52918 /* setup ELF header */
52919 elf = (struct elfhdr *) bufp;
52920 bufp += sizeof(struct elfhdr);
52921@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52922 * the addresses in the elf_phdr on our list.
52923 */
52924 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52925- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52926+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52927+ if (tsz > buflen)
52928 tsz = buflen;
52929-
52930+
52931 while (buflen) {
52932 struct kcore_list *m;
52933
52934@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52935 kfree(elf_buf);
52936 } else {
52937 if (kern_addr_valid(start)) {
52938- unsigned long n;
52939+ char *elf_buf;
52940+ mm_segment_t oldfs;
52941
52942- n = copy_to_user(buffer, (char *)start, tsz);
52943- /*
52944- * We cannot distingush between fault on source
52945- * and fault on destination. When this happens
52946- * we clear too and hope it will trigger the
52947- * EFAULT again.
52948- */
52949- if (n) {
52950- if (clear_user(buffer + tsz - n,
52951- n))
52952+ elf_buf = kmalloc(tsz, GFP_KERNEL);
52953+ if (!elf_buf)
52954+ return -ENOMEM;
52955+ oldfs = get_fs();
52956+ set_fs(KERNEL_DS);
52957+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52958+ set_fs(oldfs);
52959+ if (copy_to_user(buffer, elf_buf, tsz)) {
52960+ kfree(elf_buf);
52961 return -EFAULT;
52962+ }
52963 }
52964+ set_fs(oldfs);
52965+ kfree(elf_buf);
52966 } else {
52967 if (clear_user(buffer, tsz))
52968 return -EFAULT;
52969@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52970
52971 static int open_kcore(struct inode *inode, struct file *filp)
52972 {
52973+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52974+ return -EPERM;
52975+#endif
52976 if (!capable(CAP_SYS_RAWIO))
52977 return -EPERM;
52978 if (kcore_need_update)
52979diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52980index a65239c..ad1182a 100644
52981--- a/fs/proc/meminfo.c
52982+++ b/fs/proc/meminfo.c
52983@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52984 unsigned long pages[NR_LRU_LISTS];
52985 int lru;
52986
52987+ pax_track_stack();
52988+
52989 /*
52990 * display in kilobytes.
52991 */
52992@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52993 vmi.used >> 10,
52994 vmi.largest_chunk >> 10
52995 #ifdef CONFIG_MEMORY_FAILURE
52996- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52997+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52998 #endif
52999 );
53000
53001diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
53002index 9fe7d7e..cdb62c9 100644
53003--- a/fs/proc/nommu.c
53004+++ b/fs/proc/nommu.c
53005@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
53006 if (len < 1)
53007 len = 1;
53008 seq_printf(m, "%*c", len, ' ');
53009- seq_path(m, &file->f_path, "");
53010+ seq_path(m, &file->f_path, "\n\\");
53011 }
53012
53013 seq_putc(m, '\n');
53014diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
53015index 04d1270..25e1173 100644
53016--- a/fs/proc/proc_net.c
53017+++ b/fs/proc/proc_net.c
53018@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(struct inode *dir)
53019 struct task_struct *task;
53020 struct nsproxy *ns;
53021 struct net *net = NULL;
53022+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53023+ const struct cred *cred = current_cred();
53024+#endif
53025+
53026+#ifdef CONFIG_GRKERNSEC_PROC_USER
53027+ if (cred->fsuid)
53028+ return net;
53029+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53030+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
53031+ return net;
53032+#endif
53033
53034 rcu_read_lock();
53035 task = pid_task(proc_pid(dir), PIDTYPE_PID);
53036diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
53037index f667e8a..55f4d96 100644
53038--- a/fs/proc/proc_sysctl.c
53039+++ b/fs/proc/proc_sysctl.c
53040@@ -7,11 +7,13 @@
53041 #include <linux/security.h>
53042 #include "internal.h"
53043
53044+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
53045+
53046 static const struct dentry_operations proc_sys_dentry_operations;
53047 static const struct file_operations proc_sys_file_operations;
53048-static const struct inode_operations proc_sys_inode_operations;
53049+const struct inode_operations proc_sys_inode_operations;
53050 static const struct file_operations proc_sys_dir_file_operations;
53051-static const struct inode_operations proc_sys_dir_operations;
53052+const struct inode_operations proc_sys_dir_operations;
53053
53054 static struct inode *proc_sys_make_inode(struct super_block *sb,
53055 struct ctl_table_header *head, struct ctl_table *table)
53056@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53057 if (!p)
53058 goto out;
53059
53060+ if (gr_handle_sysctl(p, MAY_EXEC))
53061+ goto out;
53062+
53063 err = ERR_PTR(-ENOMEM);
53064 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
53065 if (h)
53066@@ -119,6 +124,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53067
53068 err = NULL;
53069 dentry->d_op = &proc_sys_dentry_operations;
53070+
53071+ gr_handle_proc_create(dentry, inode);
53072+
53073 d_add(dentry, inode);
53074
53075 out:
53076@@ -200,6 +208,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
53077 return -ENOMEM;
53078 } else {
53079 child->d_op = &proc_sys_dentry_operations;
53080+
53081+ gr_handle_proc_create(child, inode);
53082+
53083 d_add(child, inode);
53084 }
53085 } else {
53086@@ -228,6 +239,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
53087 if (*pos < file->f_pos)
53088 continue;
53089
53090+ if (gr_handle_sysctl(table, 0))
53091+ continue;
53092+
53093 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
53094 if (res)
53095 return res;
53096@@ -344,6 +358,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
53097 if (IS_ERR(head))
53098 return PTR_ERR(head);
53099
53100+ if (table && gr_handle_sysctl(table, MAY_EXEC))
53101+ return -ENOENT;
53102+
53103 generic_fillattr(inode, stat);
53104 if (table)
53105 stat->mode = (stat->mode & S_IFMT) | table->mode;
53106@@ -358,17 +375,18 @@ static const struct file_operations proc_sys_file_operations = {
53107 };
53108
53109 static const struct file_operations proc_sys_dir_file_operations = {
53110+ .read = generic_read_dir,
53111 .readdir = proc_sys_readdir,
53112 .llseek = generic_file_llseek,
53113 };
53114
53115-static const struct inode_operations proc_sys_inode_operations = {
53116+const struct inode_operations proc_sys_inode_operations = {
53117 .permission = proc_sys_permission,
53118 .setattr = proc_sys_setattr,
53119 .getattr = proc_sys_getattr,
53120 };
53121
53122-static const struct inode_operations proc_sys_dir_operations = {
53123+const struct inode_operations proc_sys_dir_operations = {
53124 .lookup = proc_sys_lookup,
53125 .permission = proc_sys_permission,
53126 .setattr = proc_sys_setattr,
53127diff --git a/fs/proc/root.c b/fs/proc/root.c
53128index b080b79..d957e63 100644
53129--- a/fs/proc/root.c
53130+++ b/fs/proc/root.c
53131@@ -134,7 +134,15 @@ void __init proc_root_init(void)
53132 #ifdef CONFIG_PROC_DEVICETREE
53133 proc_device_tree_init();
53134 #endif
53135+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53136+#ifdef CONFIG_GRKERNSEC_PROC_USER
53137+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
53138+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53139+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
53140+#endif
53141+#else
53142 proc_mkdir("bus", NULL);
53143+#endif
53144 proc_sys_init();
53145 }
53146
53147diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
53148index 3b7b82a..7dbb571 100644
53149--- a/fs/proc/task_mmu.c
53150+++ b/fs/proc/task_mmu.c
53151@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53152 "VmStk:\t%8lu kB\n"
53153 "VmExe:\t%8lu kB\n"
53154 "VmLib:\t%8lu kB\n"
53155- "VmPTE:\t%8lu kB\n",
53156- hiwater_vm << (PAGE_SHIFT-10),
53157+ "VmPTE:\t%8lu kB\n"
53158+
53159+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53160+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
53161+#endif
53162+
53163+ ,hiwater_vm << (PAGE_SHIFT-10),
53164 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
53165 mm->locked_vm << (PAGE_SHIFT-10),
53166 hiwater_rss << (PAGE_SHIFT-10),
53167 total_rss << (PAGE_SHIFT-10),
53168 data << (PAGE_SHIFT-10),
53169 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
53170- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
53171+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
53172+
53173+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53174+ , mm->context.user_cs_base, mm->context.user_cs_limit
53175+#endif
53176+
53177+ );
53178 }
53179
53180 unsigned long task_vsize(struct mm_struct *mm)
53181@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, void *v)
53182 struct proc_maps_private *priv = m->private;
53183 struct vm_area_struct *vma = v;
53184
53185- vma_stop(priv, vma);
53186+ if (!IS_ERR(vma))
53187+ vma_stop(priv, vma);
53188 if (priv->task)
53189 put_task_struct(priv->task);
53190 }
53191@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
53192 return ret;
53193 }
53194
53195+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53196+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53197+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
53198+ _mm->pax_flags & MF_PAX_SEGMEXEC))
53199+#endif
53200+
53201 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53202 {
53203 struct mm_struct *mm = vma->vm_mm;
53204@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53205 int flags = vma->vm_flags;
53206 unsigned long ino = 0;
53207 unsigned long long pgoff = 0;
53208- unsigned long start;
53209 dev_t dev = 0;
53210 int len;
53211
53212@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53213 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
53214 }
53215
53216- /* We don't show the stack guard page in /proc/maps */
53217- start = vma->vm_start;
53218- if (vma->vm_flags & VM_GROWSDOWN)
53219- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
53220- start += PAGE_SIZE;
53221-
53222 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
53223- start,
53224+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53225+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
53226+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
53227+#else
53228+ vma->vm_start,
53229 vma->vm_end,
53230+#endif
53231 flags & VM_READ ? 'r' : '-',
53232 flags & VM_WRITE ? 'w' : '-',
53233 flags & VM_EXEC ? 'x' : '-',
53234 flags & VM_MAYSHARE ? 's' : 'p',
53235+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53236+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
53237+#else
53238 pgoff,
53239+#endif
53240 MAJOR(dev), MINOR(dev), ino, &len);
53241
53242 /*
53243@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53244 */
53245 if (file) {
53246 pad_len_spaces(m, len);
53247- seq_path(m, &file->f_path, "\n");
53248+ seq_path(m, &file->f_path, "\n\\");
53249 } else {
53250 const char *name = arch_vma_name(vma);
53251 if (!name) {
53252@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53253 if (vma->vm_start <= mm->brk &&
53254 vma->vm_end >= mm->start_brk) {
53255 name = "[heap]";
53256- } else if (vma->vm_start <= mm->start_stack &&
53257- vma->vm_end >= mm->start_stack) {
53258+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
53259+ (vma->vm_start <= mm->start_stack &&
53260+ vma->vm_end >= mm->start_stack)) {
53261 name = "[stack]";
53262 }
53263 } else {
53264@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m, void *v)
53265 };
53266
53267 memset(&mss, 0, sizeof mss);
53268- mss.vma = vma;
53269- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53270- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53271+
53272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53273+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
53274+#endif
53275+ mss.vma = vma;
53276+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53277+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53278+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53279+ }
53280+#endif
53281
53282 show_map_vma(m, vma);
53283
53284@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m, void *v)
53285 "Swap: %8lu kB\n"
53286 "KernelPageSize: %8lu kB\n"
53287 "MMUPageSize: %8lu kB\n",
53288+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53289+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
53290+#else
53291 (vma->vm_end - vma->vm_start) >> 10,
53292+#endif
53293 mss.resident >> 10,
53294 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
53295 mss.shared_clean >> 10,
53296diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
53297index 8f5c05d..c99c76d 100644
53298--- a/fs/proc/task_nommu.c
53299+++ b/fs/proc/task_nommu.c
53300@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53301 else
53302 bytes += kobjsize(mm);
53303
53304- if (current->fs && current->fs->users > 1)
53305+ if (current->fs && atomic_read(&current->fs->users) > 1)
53306 sbytes += kobjsize(current->fs);
53307 else
53308 bytes += kobjsize(current->fs);
53309@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
53310 if (len < 1)
53311 len = 1;
53312 seq_printf(m, "%*c", len, ' ');
53313- seq_path(m, &file->f_path, "");
53314+ seq_path(m, &file->f_path, "\n\\");
53315 }
53316
53317 seq_putc(m, '\n');
53318diff --git a/fs/readdir.c b/fs/readdir.c
53319index 7723401..30059a6 100644
53320--- a/fs/readdir.c
53321+++ b/fs/readdir.c
53322@@ -16,6 +16,7 @@
53323 #include <linux/security.h>
53324 #include <linux/syscalls.h>
53325 #include <linux/unistd.h>
53326+#include <linux/namei.h>
53327
53328 #include <asm/uaccess.h>
53329
53330@@ -67,6 +68,7 @@ struct old_linux_dirent {
53331
53332 struct readdir_callback {
53333 struct old_linux_dirent __user * dirent;
53334+ struct file * file;
53335 int result;
53336 };
53337
53338@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
53339 buf->result = -EOVERFLOW;
53340 return -EOVERFLOW;
53341 }
53342+
53343+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53344+ return 0;
53345+
53346 buf->result++;
53347 dirent = buf->dirent;
53348 if (!access_ok(VERIFY_WRITE, dirent,
53349@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
53350
53351 buf.result = 0;
53352 buf.dirent = dirent;
53353+ buf.file = file;
53354
53355 error = vfs_readdir(file, fillonedir, &buf);
53356 if (buf.result)
53357@@ -142,6 +149,7 @@ struct linux_dirent {
53358 struct getdents_callback {
53359 struct linux_dirent __user * current_dir;
53360 struct linux_dirent __user * previous;
53361+ struct file * file;
53362 int count;
53363 int error;
53364 };
53365@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
53366 buf->error = -EOVERFLOW;
53367 return -EOVERFLOW;
53368 }
53369+
53370+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53371+ return 0;
53372+
53373 dirent = buf->previous;
53374 if (dirent) {
53375 if (__put_user(offset, &dirent->d_off))
53376@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
53377 buf.previous = NULL;
53378 buf.count = count;
53379 buf.error = 0;
53380+ buf.file = file;
53381
53382 error = vfs_readdir(file, filldir, &buf);
53383 if (error >= 0)
53384@@ -228,6 +241,7 @@ out:
53385 struct getdents_callback64 {
53386 struct linux_dirent64 __user * current_dir;
53387 struct linux_dirent64 __user * previous;
53388+ struct file *file;
53389 int count;
53390 int error;
53391 };
53392@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
53393 buf->error = -EINVAL; /* only used if we fail.. */
53394 if (reclen > buf->count)
53395 return -EINVAL;
53396+
53397+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53398+ return 0;
53399+
53400 dirent = buf->previous;
53401 if (dirent) {
53402 if (__put_user(offset, &dirent->d_off))
53403@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53404
53405 buf.current_dir = dirent;
53406 buf.previous = NULL;
53407+ buf.file = file;
53408 buf.count = count;
53409 buf.error = 0;
53410
53411@@ -297,7 +316,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53412 error = buf.error;
53413 lastdirent = buf.previous;
53414 if (lastdirent) {
53415- typeof(lastdirent->d_off) d_off = file->f_pos;
53416+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
53417 if (__put_user(d_off, &lastdirent->d_off))
53418 error = -EFAULT;
53419 else
53420diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
53421index d42c30c..4fd8718 100644
53422--- a/fs/reiserfs/dir.c
53423+++ b/fs/reiserfs/dir.c
53424@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
53425 struct reiserfs_dir_entry de;
53426 int ret = 0;
53427
53428+ pax_track_stack();
53429+
53430 reiserfs_write_lock(inode->i_sb);
53431
53432 reiserfs_check_lock_depth(inode->i_sb, "readdir");
53433diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
53434index 128d3f7..8840d44 100644
53435--- a/fs/reiserfs/do_balan.c
53436+++ b/fs/reiserfs/do_balan.c
53437@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
53438 return;
53439 }
53440
53441- atomic_inc(&(fs_generation(tb->tb_sb)));
53442+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
53443 do_balance_starts(tb);
53444
53445 /* balance leaf returns 0 except if combining L R and S into
53446diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
53447index 72cb1cc..d0e3181 100644
53448--- a/fs/reiserfs/item_ops.c
53449+++ b/fs/reiserfs/item_ops.c
53450@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_item *vi)
53451 vi->vi_index, vi->vi_type, vi->vi_ih);
53452 }
53453
53454-static struct item_operations stat_data_ops = {
53455+static const struct item_operations stat_data_ops = {
53456 .bytes_number = sd_bytes_number,
53457 .decrement_key = sd_decrement_key,
53458 .is_left_mergeable = sd_is_left_mergeable,
53459@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtual_item *vi)
53460 vi->vi_index, vi->vi_type, vi->vi_ih);
53461 }
53462
53463-static struct item_operations direct_ops = {
53464+static const struct item_operations direct_ops = {
53465 .bytes_number = direct_bytes_number,
53466 .decrement_key = direct_decrement_key,
53467 .is_left_mergeable = direct_is_left_mergeable,
53468@@ -341,7 +341,7 @@ static void indirect_print_vi(struct virtual_item *vi)
53469 vi->vi_index, vi->vi_type, vi->vi_ih);
53470 }
53471
53472-static struct item_operations indirect_ops = {
53473+static const struct item_operations indirect_ops = {
53474 .bytes_number = indirect_bytes_number,
53475 .decrement_key = indirect_decrement_key,
53476 .is_left_mergeable = indirect_is_left_mergeable,
53477@@ -628,7 +628,7 @@ static void direntry_print_vi(struct virtual_item *vi)
53478 printk("\n");
53479 }
53480
53481-static struct item_operations direntry_ops = {
53482+static const struct item_operations direntry_ops = {
53483 .bytes_number = direntry_bytes_number,
53484 .decrement_key = direntry_decrement_key,
53485 .is_left_mergeable = direntry_is_left_mergeable,
53486@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct virtual_item *vi)
53487 "Invalid item type observed, run fsck ASAP");
53488 }
53489
53490-static struct item_operations errcatch_ops = {
53491+static const struct item_operations errcatch_ops = {
53492 errcatch_bytes_number,
53493 errcatch_decrement_key,
53494 errcatch_is_left_mergeable,
53495@@ -746,7 +746,7 @@ static struct item_operations errcatch_ops = {
53496 #error Item types must use disk-format assigned values.
53497 #endif
53498
53499-struct item_operations *item_ops[TYPE_ANY + 1] = {
53500+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
53501 &stat_data_ops,
53502 &indirect_ops,
53503 &direct_ops,
53504diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
53505index b5fe0aa..e0e25c4 100644
53506--- a/fs/reiserfs/journal.c
53507+++ b/fs/reiserfs/journal.c
53508@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
53509 struct buffer_head *bh;
53510 int i, j;
53511
53512+ pax_track_stack();
53513+
53514 bh = __getblk(dev, block, bufsize);
53515 if (buffer_uptodate(bh))
53516 return (bh);
53517diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
53518index 2715791..b8996db 100644
53519--- a/fs/reiserfs/namei.c
53520+++ b/fs/reiserfs/namei.c
53521@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
53522 unsigned long savelink = 1;
53523 struct timespec ctime;
53524
53525+ pax_track_stack();
53526+
53527 /* three balancings: (1) old name removal, (2) new name insertion
53528 and (3) maybe "save" link insertion
53529 stat data updates: (1) old directory,
53530diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
53531index 9229e55..3d2e3b7 100644
53532--- a/fs/reiserfs/procfs.c
53533+++ b/fs/reiserfs/procfs.c
53534@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
53535 "SMALL_TAILS " : "NO_TAILS ",
53536 replay_only(sb) ? "REPLAY_ONLY " : "",
53537 convert_reiserfs(sb) ? "CONV " : "",
53538- atomic_read(&r->s_generation_counter),
53539+ atomic_read_unchecked(&r->s_generation_counter),
53540 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
53541 SF(s_do_balance), SF(s_unneeded_left_neighbor),
53542 SF(s_good_search_by_key_reada), SF(s_bmaps),
53543@@ -309,6 +309,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
53544 struct journal_params *jp = &rs->s_v1.s_journal;
53545 char b[BDEVNAME_SIZE];
53546
53547+ pax_track_stack();
53548+
53549 seq_printf(m, /* on-disk fields */
53550 "jp_journal_1st_block: \t%i\n"
53551 "jp_journal_dev: \t%s[%x]\n"
53552diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
53553index d036ee5..4c7dca1 100644
53554--- a/fs/reiserfs/stree.c
53555+++ b/fs/reiserfs/stree.c
53556@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
53557 int iter = 0;
53558 #endif
53559
53560+ pax_track_stack();
53561+
53562 BUG_ON(!th->t_trans_id);
53563
53564 init_tb_struct(th, &s_del_balance, sb, path,
53565@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
53566 int retval;
53567 int quota_cut_bytes = 0;
53568
53569+ pax_track_stack();
53570+
53571 BUG_ON(!th->t_trans_id);
53572
53573 le_key2cpu_key(&cpu_key, key);
53574@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
53575 int quota_cut_bytes;
53576 loff_t tail_pos = 0;
53577
53578+ pax_track_stack();
53579+
53580 BUG_ON(!th->t_trans_id);
53581
53582 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
53583@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
53584 int retval;
53585 int fs_gen;
53586
53587+ pax_track_stack();
53588+
53589 BUG_ON(!th->t_trans_id);
53590
53591 fs_gen = get_generation(inode->i_sb);
53592@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
53593 int fs_gen = 0;
53594 int quota_bytes = 0;
53595
53596+ pax_track_stack();
53597+
53598 BUG_ON(!th->t_trans_id);
53599
53600 if (inode) { /* Do we count quotas for item? */
53601diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
53602index f0ad05f..af3306f 100644
53603--- a/fs/reiserfs/super.c
53604+++ b/fs/reiserfs/super.c
53605@@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
53606 {.option_name = NULL}
53607 };
53608
53609+ pax_track_stack();
53610+
53611 *blocks = 0;
53612 if (!options || !*options)
53613 /* use default configuration: create tails, journaling on, no
53614diff --git a/fs/select.c b/fs/select.c
53615index fd38ce2..f5381b8 100644
53616--- a/fs/select.c
53617+++ b/fs/select.c
53618@@ -20,6 +20,7 @@
53619 #include <linux/module.h>
53620 #include <linux/slab.h>
53621 #include <linux/poll.h>
53622+#include <linux/security.h>
53623 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
53624 #include <linux/file.h>
53625 #include <linux/fdtable.h>
53626@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
53627 int retval, i, timed_out = 0;
53628 unsigned long slack = 0;
53629
53630+ pax_track_stack();
53631+
53632 rcu_read_lock();
53633 retval = max_select_fd(n, fds);
53634 rcu_read_unlock();
53635@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
53636 /* Allocate small arguments on the stack to save memory and be faster */
53637 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
53638
53639+ pax_track_stack();
53640+
53641 ret = -EINVAL;
53642 if (n < 0)
53643 goto out_nofds;
53644@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
53645 struct poll_list *walk = head;
53646 unsigned long todo = nfds;
53647
53648+ pax_track_stack();
53649+
53650+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
53651 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
53652 return -EINVAL;
53653
53654diff --git a/fs/seq_file.c b/fs/seq_file.c
53655index eae7d9d..679f099 100644
53656--- a/fs/seq_file.c
53657+++ b/fs/seq_file.c
53658@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53659 return 0;
53660 }
53661 if (!m->buf) {
53662- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53663+ m->size = PAGE_SIZE;
53664+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53665 if (!m->buf)
53666 return -ENOMEM;
53667 }
53668@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53669 Eoverflow:
53670 m->op->stop(m, p);
53671 kfree(m->buf);
53672- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53673+ m->size <<= 1;
53674+ m->buf = kmalloc(m->size, GFP_KERNEL);
53675 return !m->buf ? -ENOMEM : -EAGAIN;
53676 }
53677
53678@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53679 m->version = file->f_version;
53680 /* grab buffer if we didn't have one */
53681 if (!m->buf) {
53682- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53683+ m->size = PAGE_SIZE;
53684+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53685 if (!m->buf)
53686 goto Enomem;
53687 }
53688@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53689 goto Fill;
53690 m->op->stop(m, p);
53691 kfree(m->buf);
53692- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53693+ m->size <<= 1;
53694+ m->buf = kmalloc(m->size, GFP_KERNEL);
53695 if (!m->buf)
53696 goto Enomem;
53697 m->count = 0;
53698@@ -551,7 +555,7 @@ static void single_stop(struct seq_file *p, void *v)
53699 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
53700 void *data)
53701 {
53702- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
53703+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
53704 int res = -ENOMEM;
53705
53706 if (op) {
53707diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
53708index 71c29b6..54694dd 100644
53709--- a/fs/smbfs/proc.c
53710+++ b/fs/smbfs/proc.c
53711@@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *server, struct smb_nls_codepage *cp)
53712
53713 out:
53714 if (server->local_nls != NULL && server->remote_nls != NULL)
53715- server->ops->convert = convert_cp;
53716+ *(void **)&server->ops->convert = convert_cp;
53717 else
53718- server->ops->convert = convert_memcpy;
53719+ *(void **)&server->ops->convert = convert_memcpy;
53720
53721 smb_unlock_server(server);
53722 return n;
53723@@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
53724
53725 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
53726 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
53727- server->ops->getattr = smb_proc_getattr_core;
53728+ *(void **)&server->ops->getattr = smb_proc_getattr_core;
53729 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
53730- server->ops->getattr = smb_proc_getattr_ff;
53731+ *(void **)&server->ops->getattr = smb_proc_getattr_ff;
53732 }
53733
53734 /* Decode server capabilities */
53735@@ -3439,7 +3439,7 @@ out:
53736 static void
53737 install_ops(struct smb_ops *dst, struct smb_ops *src)
53738 {
53739- memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53740+ memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53741 }
53742
53743 /* < LANMAN2 */
53744diff --git a/fs/smbfs/symlink.c b/fs/smbfs/symlink.c
53745index 00b2909..2ace383 100644
53746--- a/fs/smbfs/symlink.c
53747+++ b/fs/smbfs/symlink.c
53748@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dentry *dentry, struct nameidata *nd)
53749
53750 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53751 {
53752- char *s = nd_get_link(nd);
53753+ const char *s = nd_get_link(nd);
53754 if (!IS_ERR(s))
53755 __putname(s);
53756 }
53757diff --git a/fs/splice.c b/fs/splice.c
53758index bb92b7c..5aa72b0 100644
53759--- a/fs/splice.c
53760+++ b/fs/splice.c
53761@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
53762 pipe_lock(pipe);
53763
53764 for (;;) {
53765- if (!pipe->readers) {
53766+ if (!atomic_read(&pipe->readers)) {
53767 send_sig(SIGPIPE, current, 0);
53768 if (!ret)
53769 ret = -EPIPE;
53770@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
53771 do_wakeup = 0;
53772 }
53773
53774- pipe->waiting_writers++;
53775+ atomic_inc(&pipe->waiting_writers);
53776 pipe_wait(pipe);
53777- pipe->waiting_writers--;
53778+ atomic_dec(&pipe->waiting_writers);
53779 }
53780
53781 pipe_unlock(pipe);
53782@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
53783 .spd_release = spd_release_page,
53784 };
53785
53786+ pax_track_stack();
53787+
53788 index = *ppos >> PAGE_CACHE_SHIFT;
53789 loff = *ppos & ~PAGE_CACHE_MASK;
53790 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
53791@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
53792 old_fs = get_fs();
53793 set_fs(get_ds());
53794 /* The cast to a user pointer is valid due to the set_fs() */
53795- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
53796+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
53797 set_fs(old_fs);
53798
53799 return res;
53800@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
53801 old_fs = get_fs();
53802 set_fs(get_ds());
53803 /* The cast to a user pointer is valid due to the set_fs() */
53804- res = vfs_write(file, (const char __user *)buf, count, &pos);
53805+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
53806 set_fs(old_fs);
53807
53808 return res;
53809@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53810 .spd_release = spd_release_page,
53811 };
53812
53813+ pax_track_stack();
53814+
53815 index = *ppos >> PAGE_CACHE_SHIFT;
53816 offset = *ppos & ~PAGE_CACHE_MASK;
53817 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
53818@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53819 goto err;
53820
53821 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
53822- vec[i].iov_base = (void __user *) page_address(page);
53823+ vec[i].iov_base = (__force void __user *) page_address(page);
53824 vec[i].iov_len = this_len;
53825 pages[i] = page;
53826 spd.nr_pages++;
53827@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
53828 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
53829 {
53830 while (!pipe->nrbufs) {
53831- if (!pipe->writers)
53832+ if (!atomic_read(&pipe->writers))
53833 return 0;
53834
53835- if (!pipe->waiting_writers && sd->num_spliced)
53836+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
53837 return 0;
53838
53839 if (sd->flags & SPLICE_F_NONBLOCK)
53840@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
53841 * out of the pipe right after the splice_to_pipe(). So set
53842 * PIPE_READERS appropriately.
53843 */
53844- pipe->readers = 1;
53845+ atomic_set(&pipe->readers, 1);
53846
53847 current->splice_pipe = pipe;
53848 }
53849@@ -1593,6 +1597,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
53850 .spd_release = spd_release_page,
53851 };
53852
53853+ pax_track_stack();
53854+
53855 pipe = pipe_info(file->f_path.dentry->d_inode);
53856 if (!pipe)
53857 return -EBADF;
53858@@ -1701,9 +1707,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53859 ret = -ERESTARTSYS;
53860 break;
53861 }
53862- if (!pipe->writers)
53863+ if (!atomic_read(&pipe->writers))
53864 break;
53865- if (!pipe->waiting_writers) {
53866+ if (!atomic_read(&pipe->waiting_writers)) {
53867 if (flags & SPLICE_F_NONBLOCK) {
53868 ret = -EAGAIN;
53869 break;
53870@@ -1735,7 +1741,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53871 pipe_lock(pipe);
53872
53873 while (pipe->nrbufs >= PIPE_BUFFERS) {
53874- if (!pipe->readers) {
53875+ if (!atomic_read(&pipe->readers)) {
53876 send_sig(SIGPIPE, current, 0);
53877 ret = -EPIPE;
53878 break;
53879@@ -1748,9 +1754,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53880 ret = -ERESTARTSYS;
53881 break;
53882 }
53883- pipe->waiting_writers++;
53884+ atomic_inc(&pipe->waiting_writers);
53885 pipe_wait(pipe);
53886- pipe->waiting_writers--;
53887+ atomic_dec(&pipe->waiting_writers);
53888 }
53889
53890 pipe_unlock(pipe);
53891@@ -1786,14 +1792,14 @@ retry:
53892 pipe_double_lock(ipipe, opipe);
53893
53894 do {
53895- if (!opipe->readers) {
53896+ if (!atomic_read(&opipe->readers)) {
53897 send_sig(SIGPIPE, current, 0);
53898 if (!ret)
53899 ret = -EPIPE;
53900 break;
53901 }
53902
53903- if (!ipipe->nrbufs && !ipipe->writers)
53904+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53905 break;
53906
53907 /*
53908@@ -1893,7 +1899,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53909 pipe_double_lock(ipipe, opipe);
53910
53911 do {
53912- if (!opipe->readers) {
53913+ if (!atomic_read(&opipe->readers)) {
53914 send_sig(SIGPIPE, current, 0);
53915 if (!ret)
53916 ret = -EPIPE;
53917@@ -1938,7 +1944,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53918 * return EAGAIN if we have the potential of some data in the
53919 * future, otherwise just return 0
53920 */
53921- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53922+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53923 ret = -EAGAIN;
53924
53925 pipe_unlock(ipipe);
53926diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53927index 7118a38..70af853 100644
53928--- a/fs/sysfs/file.c
53929+++ b/fs/sysfs/file.c
53930@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53931
53932 struct sysfs_open_dirent {
53933 atomic_t refcnt;
53934- atomic_t event;
53935+ atomic_unchecked_t event;
53936 wait_queue_head_t poll;
53937 struct list_head buffers; /* goes through sysfs_buffer.list */
53938 };
53939@@ -53,7 +53,7 @@ struct sysfs_buffer {
53940 size_t count;
53941 loff_t pos;
53942 char * page;
53943- struct sysfs_ops * ops;
53944+ const struct sysfs_ops * ops;
53945 struct mutex mutex;
53946 int needs_read_fill;
53947 int event;
53948@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53949 {
53950 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
53951 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53952- struct sysfs_ops * ops = buffer->ops;
53953+ const struct sysfs_ops * ops = buffer->ops;
53954 int ret = 0;
53955 ssize_t count;
53956
53957@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53958 if (!sysfs_get_active_two(attr_sd))
53959 return -ENODEV;
53960
53961- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53962+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53963 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53964
53965 sysfs_put_active_two(attr_sd);
53966@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
53967 {
53968 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
53969 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53970- struct sysfs_ops * ops = buffer->ops;
53971+ const struct sysfs_ops * ops = buffer->ops;
53972 int rc;
53973
53974 /* need attr_sd for attr and ops, its parent for kobj */
53975@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53976 return -ENOMEM;
53977
53978 atomic_set(&new_od->refcnt, 0);
53979- atomic_set(&new_od->event, 1);
53980+ atomic_set_unchecked(&new_od->event, 1);
53981 init_waitqueue_head(&new_od->poll);
53982 INIT_LIST_HEAD(&new_od->buffers);
53983 goto retry;
53984@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
53985 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
53986 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53987 struct sysfs_buffer *buffer;
53988- struct sysfs_ops *ops;
53989+ const struct sysfs_ops *ops;
53990 int error = -EACCES;
53991 char *p;
53992
53993@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53994
53995 sysfs_put_active_two(attr_sd);
53996
53997- if (buffer->event != atomic_read(&od->event))
53998+ if (buffer->event != atomic_read_unchecked(&od->event))
53999 goto trigger;
54000
54001 return DEFAULT_POLLMASK;
54002@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
54003
54004 od = sd->s_attr.open;
54005 if (od) {
54006- atomic_inc(&od->event);
54007+ atomic_inc_unchecked(&od->event);
54008 wake_up_interruptible(&od->poll);
54009 }
54010
54011diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
54012index 4974995..c26609c 100644
54013--- a/fs/sysfs/mount.c
54014+++ b/fs/sysfs/mount.c
54015@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
54016 .s_name = "",
54017 .s_count = ATOMIC_INIT(1),
54018 .s_flags = SYSFS_DIR,
54019+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54020+ .s_mode = S_IFDIR | S_IRWXU,
54021+#else
54022 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54023+#endif
54024 .s_ino = 1,
54025 };
54026
54027diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
54028index c5081ad..342ea86 100644
54029--- a/fs/sysfs/symlink.c
54030+++ b/fs/sysfs/symlink.c
54031@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54032
54033 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
54034 {
54035- char *page = nd_get_link(nd);
54036+ const char *page = nd_get_link(nd);
54037 if (!IS_ERR(page))
54038 free_page((unsigned long)page);
54039 }
54040diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
54041index 1e06853..b06d325 100644
54042--- a/fs/udf/balloc.c
54043+++ b/fs/udf/balloc.c
54044@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
54045
54046 mutex_lock(&sbi->s_alloc_mutex);
54047 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54048- if (bloc->logicalBlockNum < 0 ||
54049- (bloc->logicalBlockNum + count) >
54050- partmap->s_partition_len) {
54051+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54052 udf_debug("%d < %d || %d + %d > %d\n",
54053 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
54054 count, partmap->s_partition_len);
54055@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct super_block *sb,
54056
54057 mutex_lock(&sbi->s_alloc_mutex);
54058 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54059- if (bloc->logicalBlockNum < 0 ||
54060- (bloc->logicalBlockNum + count) >
54061- partmap->s_partition_len) {
54062+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54063 udf_debug("%d < %d || %d + %d > %d\n",
54064 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
54065 partmap->s_partition_len);
54066diff --git a/fs/udf/inode.c b/fs/udf/inode.c
54067index 6d24c2c..fff470f 100644
54068--- a/fs/udf/inode.c
54069+++ b/fs/udf/inode.c
54070@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
54071 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
54072 int lastblock = 0;
54073
54074+ pax_track_stack();
54075+
54076 prev_epos.offset = udf_file_entry_alloc_offset(inode);
54077 prev_epos.block = iinfo->i_location;
54078 prev_epos.bh = NULL;
54079diff --git a/fs/udf/misc.c b/fs/udf/misc.c
54080index 9215700..bf1f68e 100644
54081--- a/fs/udf/misc.c
54082+++ b/fs/udf/misc.c
54083@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
54084
54085 u8 udf_tag_checksum(const struct tag *t)
54086 {
54087- u8 *data = (u8 *)t;
54088+ const u8 *data = (const u8 *)t;
54089 u8 checksum = 0;
54090 int i;
54091 for (i = 0; i < sizeof(struct tag); ++i)
54092diff --git a/fs/utimes.c b/fs/utimes.c
54093index e4c75db..b4df0e0 100644
54094--- a/fs/utimes.c
54095+++ b/fs/utimes.c
54096@@ -1,6 +1,7 @@
54097 #include <linux/compiler.h>
54098 #include <linux/file.h>
54099 #include <linux/fs.h>
54100+#include <linux/security.h>
54101 #include <linux/linkage.h>
54102 #include <linux/mount.h>
54103 #include <linux/namei.h>
54104@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
54105 goto mnt_drop_write_and_out;
54106 }
54107 }
54108+
54109+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
54110+ error = -EACCES;
54111+ goto mnt_drop_write_and_out;
54112+ }
54113+
54114 mutex_lock(&inode->i_mutex);
54115 error = notify_change(path->dentry, &newattrs);
54116 mutex_unlock(&inode->i_mutex);
54117diff --git a/fs/xattr.c b/fs/xattr.c
54118index 6d4f6d3..cda3958 100644
54119--- a/fs/xattr.c
54120+++ b/fs/xattr.c
54121@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
54122 * Extended attribute SET operations
54123 */
54124 static long
54125-setxattr(struct dentry *d, const char __user *name, const void __user *value,
54126+setxattr(struct path *path, const char __user *name, const void __user *value,
54127 size_t size, int flags)
54128 {
54129 int error;
54130@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
54131 return PTR_ERR(kvalue);
54132 }
54133
54134- error = vfs_setxattr(d, kname, kvalue, size, flags);
54135+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
54136+ error = -EACCES;
54137+ goto out;
54138+ }
54139+
54140+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
54141+out:
54142 kfree(kvalue);
54143 return error;
54144 }
54145@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
54146 return error;
54147 error = mnt_want_write(path.mnt);
54148 if (!error) {
54149- error = setxattr(path.dentry, name, value, size, flags);
54150+ error = setxattr(&path, name, value, size, flags);
54151 mnt_drop_write(path.mnt);
54152 }
54153 path_put(&path);
54154@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
54155 return error;
54156 error = mnt_want_write(path.mnt);
54157 if (!error) {
54158- error = setxattr(path.dentry, name, value, size, flags);
54159+ error = setxattr(&path, name, value, size, flags);
54160 mnt_drop_write(path.mnt);
54161 }
54162 path_put(&path);
54163@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
54164 const void __user *,value, size_t, size, int, flags)
54165 {
54166 struct file *f;
54167- struct dentry *dentry;
54168 int error = -EBADF;
54169
54170 f = fget(fd);
54171 if (!f)
54172 return error;
54173- dentry = f->f_path.dentry;
54174- audit_inode(NULL, dentry);
54175+ audit_inode(NULL, f->f_path.dentry);
54176 error = mnt_want_write_file(f);
54177 if (!error) {
54178- error = setxattr(dentry, name, value, size, flags);
54179+ error = setxattr(&f->f_path, name, value, size, flags);
54180 mnt_drop_write(f->f_path.mnt);
54181 }
54182 fput(f);
54183diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
54184index c6ad7c7..f2847a7 100644
54185--- a/fs/xattr_acl.c
54186+++ b/fs/xattr_acl.c
54187@@ -17,8 +17,8 @@
54188 struct posix_acl *
54189 posix_acl_from_xattr(const void *value, size_t size)
54190 {
54191- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
54192- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
54193+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
54194+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
54195 int count;
54196 struct posix_acl *acl;
54197 struct posix_acl_entry *acl_e;
54198diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
54199index 942362f..88f96f5 100644
54200--- a/fs/xfs/linux-2.6/xfs_ioctl.c
54201+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
54202@@ -134,7 +134,7 @@ xfs_find_handle(
54203 }
54204
54205 error = -EFAULT;
54206- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
54207+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
54208 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
54209 goto out_put;
54210
54211@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
54212 if (IS_ERR(dentry))
54213 return PTR_ERR(dentry);
54214
54215- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
54216+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
54217 if (!kbuf)
54218 goto out_dput;
54219
54220@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
54221 xfs_mount_t *mp,
54222 void __user *arg)
54223 {
54224- xfs_fsop_geom_t fsgeo;
54225+ xfs_fsop_geom_t fsgeo;
54226 int error;
54227
54228 error = xfs_fs_geometry(mp, &fsgeo, 3);
54229diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
54230index bad485a..479bd32 100644
54231--- a/fs/xfs/linux-2.6/xfs_ioctl32.c
54232+++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
54233@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
54234 xfs_fsop_geom_t fsgeo;
54235 int error;
54236
54237+ memset(&fsgeo, 0, sizeof(fsgeo));
54238 error = xfs_fs_geometry(mp, &fsgeo, 3);
54239 if (error)
54240 return -error;
54241diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
54242index 1f3b4b8..6102f6d 100644
54243--- a/fs/xfs/linux-2.6/xfs_iops.c
54244+++ b/fs/xfs/linux-2.6/xfs_iops.c
54245@@ -468,7 +468,7 @@ xfs_vn_put_link(
54246 struct nameidata *nd,
54247 void *p)
54248 {
54249- char *s = nd_get_link(nd);
54250+ const char *s = nd_get_link(nd);
54251
54252 if (!IS_ERR(s))
54253 kfree(s);
54254diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
54255index 8971fb0..5fc1eb2 100644
54256--- a/fs/xfs/xfs_bmap.c
54257+++ b/fs/xfs/xfs_bmap.c
54258@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
54259 int nmap,
54260 int ret_nmap);
54261 #else
54262-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
54263+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
54264 #endif /* DEBUG */
54265
54266 #if defined(XFS_RW_TRACE)
54267diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
54268index e89734e..5e84d8d 100644
54269--- a/fs/xfs/xfs_dir2_sf.c
54270+++ b/fs/xfs/xfs_dir2_sf.c
54271@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
54272 }
54273
54274 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
54275- if (filldir(dirent, sfep->name, sfep->namelen,
54276+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
54277+ char name[sfep->namelen];
54278+ memcpy(name, sfep->name, sfep->namelen);
54279+ if (filldir(dirent, name, sfep->namelen,
54280+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
54281+ *offset = off & 0x7fffffff;
54282+ return 0;
54283+ }
54284+ } else if (filldir(dirent, sfep->name, sfep->namelen,
54285 off & 0x7fffffff, ino, DT_UNKNOWN)) {
54286 *offset = off & 0x7fffffff;
54287 return 0;
54288diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
54289index 8f32f50..859e8a3 100644
54290--- a/fs/xfs/xfs_vnodeops.c
54291+++ b/fs/xfs/xfs_vnodeops.c
54292@@ -564,13 +564,17 @@ xfs_readlink(
54293
54294 xfs_ilock(ip, XFS_ILOCK_SHARED);
54295
54296- ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFLNK);
54297- ASSERT(ip->i_d.di_size <= MAXPATHLEN);
54298-
54299 pathlen = ip->i_d.di_size;
54300 if (!pathlen)
54301 goto out;
54302
54303+ if (pathlen > MAXPATHLEN) {
54304+ xfs_fs_cmn_err(CE_ALERT, mp, "%s: inode (%llu) symlink length (%d) too long",
54305+ __func__, (unsigned long long)ip->i_ino, pathlen);
54306+ ASSERT(0);
54307+ return XFS_ERROR(EFSCORRUPTED);
54308+ }
54309+
54310 if (ip->i_df.if_flags & XFS_IFINLINE) {
54311 memcpy(link, ip->i_df.if_u1.if_data, pathlen);
54312 link[pathlen] = '\0';
54313diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
54314new file mode 100644
54315index 0000000..f27a8e8
54316--- /dev/null
54317+++ b/grsecurity/Kconfig
54318@@ -0,0 +1,1036 @@
54319+#
54320+# grecurity configuration
54321+#
54322+
54323+menu "Grsecurity"
54324+
54325+config GRKERNSEC
54326+ bool "Grsecurity"
54327+ select CRYPTO
54328+ select CRYPTO_SHA256
54329+ help
54330+ If you say Y here, you will be able to configure many features
54331+ that will enhance the security of your system. It is highly
54332+ recommended that you say Y here and read through the help
54333+ for each option so that you fully understand the features and
54334+ can evaluate their usefulness for your machine.
54335+
54336+choice
54337+ prompt "Security Level"
54338+ depends on GRKERNSEC
54339+ default GRKERNSEC_CUSTOM
54340+
54341+config GRKERNSEC_LOW
54342+ bool "Low"
54343+ select GRKERNSEC_LINK
54344+ select GRKERNSEC_FIFO
54345+ select GRKERNSEC_RANDNET
54346+ select GRKERNSEC_DMESG
54347+ select GRKERNSEC_CHROOT
54348+ select GRKERNSEC_CHROOT_CHDIR
54349+
54350+ help
54351+ If you choose this option, several of the grsecurity options will
54352+ be enabled that will give you greater protection against a number
54353+ of attacks, while assuring that none of your software will have any
54354+ conflicts with the additional security measures. If you run a lot
54355+ of unusual software, or you are having problems with the higher
54356+ security levels, you should say Y here. With this option, the
54357+ following features are enabled:
54358+
54359+ - Linking restrictions
54360+ - FIFO restrictions
54361+ - Restricted dmesg
54362+ - Enforced chdir("/") on chroot
54363+ - Runtime module disabling
54364+
54365+config GRKERNSEC_MEDIUM
54366+ bool "Medium"
54367+ select PAX
54368+ select PAX_EI_PAX
54369+ select PAX_PT_PAX_FLAGS
54370+ select PAX_HAVE_ACL_FLAGS
54371+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54372+ select GRKERNSEC_CHROOT
54373+ select GRKERNSEC_CHROOT_SYSCTL
54374+ select GRKERNSEC_LINK
54375+ select GRKERNSEC_FIFO
54376+ select GRKERNSEC_DMESG
54377+ select GRKERNSEC_RANDNET
54378+ select GRKERNSEC_FORKFAIL
54379+ select GRKERNSEC_TIME
54380+ select GRKERNSEC_SIGNAL
54381+ select GRKERNSEC_CHROOT
54382+ select GRKERNSEC_CHROOT_UNIX
54383+ select GRKERNSEC_CHROOT_MOUNT
54384+ select GRKERNSEC_CHROOT_PIVOT
54385+ select GRKERNSEC_CHROOT_DOUBLE
54386+ select GRKERNSEC_CHROOT_CHDIR
54387+ select GRKERNSEC_CHROOT_MKNOD
54388+ select GRKERNSEC_PROC
54389+ select GRKERNSEC_PROC_USERGROUP
54390+ select PAX_RANDUSTACK
54391+ select PAX_ASLR
54392+ select PAX_RANDMMAP
54393+ select PAX_REFCOUNT if (X86 || SPARC64)
54394+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54395+
54396+ help
54397+ If you say Y here, several features in addition to those included
54398+ in the low additional security level will be enabled. These
54399+ features provide even more security to your system, though in rare
54400+ cases they may be incompatible with very old or poorly written
54401+ software. If you enable this option, make sure that your auth
54402+ service (identd) is running as gid 1001. With this option,
54403+ the following features (in addition to those provided in the
54404+ low additional security level) will be enabled:
54405+
54406+ - Failed fork logging
54407+ - Time change logging
54408+ - Signal logging
54409+ - Deny mounts in chroot
54410+ - Deny double chrooting
54411+ - Deny sysctl writes in chroot
54412+ - Deny mknod in chroot
54413+ - Deny access to abstract AF_UNIX sockets out of chroot
54414+ - Deny pivot_root in chroot
54415+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
54416+ - /proc restrictions with special GID set to 10 (usually wheel)
54417+ - Address Space Layout Randomization (ASLR)
54418+ - Prevent exploitation of most refcount overflows
54419+ - Bounds checking of copying between the kernel and userland
54420+
54421+config GRKERNSEC_HIGH
54422+ bool "High"
54423+ select GRKERNSEC_LINK
54424+ select GRKERNSEC_FIFO
54425+ select GRKERNSEC_DMESG
54426+ select GRKERNSEC_FORKFAIL
54427+ select GRKERNSEC_TIME
54428+ select GRKERNSEC_SIGNAL
54429+ select GRKERNSEC_CHROOT
54430+ select GRKERNSEC_CHROOT_SHMAT
54431+ select GRKERNSEC_CHROOT_UNIX
54432+ select GRKERNSEC_CHROOT_MOUNT
54433+ select GRKERNSEC_CHROOT_FCHDIR
54434+ select GRKERNSEC_CHROOT_PIVOT
54435+ select GRKERNSEC_CHROOT_DOUBLE
54436+ select GRKERNSEC_CHROOT_CHDIR
54437+ select GRKERNSEC_CHROOT_MKNOD
54438+ select GRKERNSEC_CHROOT_CAPS
54439+ select GRKERNSEC_CHROOT_SYSCTL
54440+ select GRKERNSEC_CHROOT_FINDTASK
54441+ select GRKERNSEC_SYSFS_RESTRICT
54442+ select GRKERNSEC_PROC
54443+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54444+ select GRKERNSEC_HIDESYM
54445+ select GRKERNSEC_BRUTE
54446+ select GRKERNSEC_PROC_USERGROUP
54447+ select GRKERNSEC_KMEM
54448+ select GRKERNSEC_RESLOG
54449+ select GRKERNSEC_RANDNET
54450+ select GRKERNSEC_PROC_ADD
54451+ select GRKERNSEC_CHROOT_CHMOD
54452+ select GRKERNSEC_CHROOT_NICE
54453+ select GRKERNSEC_AUDIT_MOUNT
54454+ select GRKERNSEC_MODHARDEN if (MODULES)
54455+ select GRKERNSEC_HARDEN_PTRACE
54456+ select GRKERNSEC_VM86 if (X86_32)
54457+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
54458+ select PAX
54459+ select PAX_RANDUSTACK
54460+ select PAX_ASLR
54461+ select PAX_RANDMMAP
54462+ select PAX_NOEXEC
54463+ select PAX_MPROTECT
54464+ select PAX_EI_PAX
54465+ select PAX_PT_PAX_FLAGS
54466+ select PAX_HAVE_ACL_FLAGS
54467+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
54468+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
54469+ select PAX_RANDKSTACK if (X86_TSC && X86)
54470+ select PAX_SEGMEXEC if (X86_32)
54471+ select PAX_PAGEEXEC
54472+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
54473+ select PAX_EMUTRAMP if (PARISC)
54474+ select PAX_EMUSIGRT if (PARISC)
54475+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
54476+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
54477+ select PAX_REFCOUNT if (X86 || SPARC64)
54478+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54479+ help
54480+ If you say Y here, many of the features of grsecurity will be
54481+ enabled, which will protect you against many kinds of attacks
54482+ against your system. The heightened security comes at a cost
54483+ of an increased chance of incompatibilities with rare software
54484+ on your machine. Since this security level enables PaX, you should
54485+ view <http://pax.grsecurity.net> and read about the PaX
54486+ project. While you are there, download chpax and run it on
54487+ binaries that cause problems with PaX. Also remember that
54488+ since the /proc restrictions are enabled, you must run your
54489+ identd as gid 1001. This security level enables the following
54490+ features in addition to those listed in the low and medium
54491+ security levels:
54492+
54493+ - Additional /proc restrictions
54494+ - Chmod restrictions in chroot
54495+ - No signals, ptrace, or viewing of processes outside of chroot
54496+ - Capability restrictions in chroot
54497+ - Deny fchdir out of chroot
54498+ - Priority restrictions in chroot
54499+ - Segmentation-based implementation of PaX
54500+ - Mprotect restrictions
54501+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
54502+ - Kernel stack randomization
54503+ - Mount/unmount/remount logging
54504+ - Kernel symbol hiding
54505+ - Hardening of module auto-loading
54506+ - Ptrace restrictions
54507+ - Restricted vm86 mode
54508+ - Restricted sysfs/debugfs
54509+ - Active kernel exploit response
54510+
54511+config GRKERNSEC_CUSTOM
54512+ bool "Custom"
54513+ help
54514+ If you say Y here, you will be able to configure every grsecurity
54515+ option, which allows you to enable many more features that aren't
54516+ covered in the basic security levels. These additional features
54517+ include TPE, socket restrictions, and the sysctl system for
54518+ grsecurity. It is advised that you read through the help for
54519+ each option to determine its usefulness in your situation.
54520+
54521+endchoice
54522+
54523+menu "Address Space Protection"
54524+depends on GRKERNSEC
54525+
54526+config GRKERNSEC_KMEM
54527+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
54528+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
54529+ help
54530+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
54531+ be written to or read from to modify or leak the contents of the running
54532+ kernel. /dev/port will also not be allowed to be opened. If you have module
54533+ support disabled, enabling this will close up four ways that are
54534+ currently used to insert malicious code into the running kernel.
54535+ Even with all these features enabled, we still highly recommend that
54536+ you use the RBAC system, as it is still possible for an attacker to
54537+ modify the running kernel through privileged I/O granted by ioperm/iopl.
54538+ If you are not using XFree86, you may be able to stop this additional
54539+ case by enabling the 'Disable privileged I/O' option. Though nothing
54540+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
54541+ but only to video memory, which is the only writing we allow in this
54542+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
54543+ not be allowed to mprotect it with PROT_WRITE later.
54544+ It is highly recommended that you say Y here if you meet all the
54545+ conditions above.
54546+
54547+config GRKERNSEC_VM86
54548+ bool "Restrict VM86 mode"
54549+ depends on X86_32
54550+
54551+ help
54552+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
54553+ make use of a special execution mode on 32bit x86 processors called
54554+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
54555+ video cards and will still work with this option enabled. The purpose
54556+ of the option is to prevent exploitation of emulation errors in
54557+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
54558+ Nearly all users should be able to enable this option.
54559+
54560+config GRKERNSEC_IO
54561+ bool "Disable privileged I/O"
54562+ depends on X86
54563+ select RTC_CLASS
54564+ select RTC_INTF_DEV
54565+ select RTC_DRV_CMOS
54566+
54567+ help
54568+ If you say Y here, all ioperm and iopl calls will return an error.
54569+ Ioperm and iopl can be used to modify the running kernel.
54570+ Unfortunately, some programs need this access to operate properly,
54571+ the most notable of which are XFree86 and hwclock. hwclock can be
54572+ remedied by having RTC support in the kernel, so real-time
54573+ clock support is enabled if this option is enabled, to ensure
54574+ that hwclock operates correctly. XFree86 still will not
54575+ operate correctly with this option enabled, so DO NOT CHOOSE Y
54576+ IF YOU USE XFree86. If you use XFree86 and you still want to
54577+ protect your kernel against modification, use the RBAC system.
54578+
54579+config GRKERNSEC_PROC_MEMMAP
54580+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
54581+ default y if (PAX_NOEXEC || PAX_ASLR)
54582+ depends on PAX_NOEXEC || PAX_ASLR
54583+ help
54584+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
54585+ give no information about the addresses of its mappings if
54586+ PaX features that rely on random addresses are enabled on the task.
54587+ If you use PaX it is greatly recommended that you say Y here as it
54588+ closes up a hole that makes the full ASLR useless for suid
54589+ binaries.
54590+
54591+config GRKERNSEC_BRUTE
54592+ bool "Deter exploit bruteforcing"
54593+ help
54594+ If you say Y here, attempts to bruteforce exploits against forking
54595+ daemons such as apache or sshd, as well as against suid/sgid binaries
54596+ will be deterred. When a child of a forking daemon is killed by PaX
54597+ or crashes due to an illegal instruction or other suspicious signal,
54598+ the parent process will be delayed 30 seconds upon every subsequent
54599+ fork until the administrator is able to assess the situation and
54600+ restart the daemon.
54601+ In the suid/sgid case, the attempt is logged, the user has all their
54602+ processes terminated, and they are prevented from executing any further
54603+ processes for 15 minutes.
54604+ It is recommended that you also enable signal logging in the auditing
54605+ section so that logs are generated when a process triggers a suspicious
54606+ signal.
54607+ If the sysctl option is enabled, a sysctl option with name
54608+ "deter_bruteforce" is created.
54609+
54610+config GRKERNSEC_MODHARDEN
54611+ bool "Harden module auto-loading"
54612+ depends on MODULES
54613+ help
54614+ If you say Y here, module auto-loading in response to use of some
54615+ feature implemented by an unloaded module will be restricted to
54616+ root users. Enabling this option helps defend against attacks
54617+ by unprivileged users who abuse the auto-loading behavior to
54618+ cause a vulnerable module to load that is then exploited.
54619+
54620+ If this option prevents a legitimate use of auto-loading for a
54621+ non-root user, the administrator can execute modprobe manually
54622+ with the exact name of the module mentioned in the alert log.
54623+ Alternatively, the administrator can add the module to the list
54624+ of modules loaded at boot by modifying init scripts.
54625+
54626+ Modification of init scripts will most likely be needed on
54627+ Ubuntu servers with encrypted home directory support enabled,
54628+ as the first non-root user logging in will cause the ecb(aes),
54629+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
54630+
54631+config GRKERNSEC_HIDESYM
54632+ bool "Hide kernel symbols"
54633+ help
54634+ If you say Y here, getting information on loaded modules, and
54635+ displaying all kernel symbols through a syscall will be restricted
54636+ to users with CAP_SYS_MODULE. For software compatibility reasons,
54637+ /proc/kallsyms will be restricted to the root user. The RBAC
54638+ system can hide that entry even from root.
54639+
54640+ This option also prevents leaking of kernel addresses through
54641+ several /proc entries.
54642+
54643+ Note that this option is only effective provided the following
54644+ conditions are met:
54645+ 1) The kernel using grsecurity is not precompiled by some distribution
54646+ 2) You have also enabled GRKERNSEC_DMESG
54647+ 3) You are using the RBAC system and hiding other files such as your
54648+ kernel image and System.map. Alternatively, enabling this option
54649+ causes the permissions on /boot, /lib/modules, and the kernel
54650+ source directory to change at compile time to prevent
54651+ reading by non-root users.
54652+ If the above conditions are met, this option will aid in providing a
54653+ useful protection against local kernel exploitation of overflows
54654+ and arbitrary read/write vulnerabilities.
54655+
54656+config GRKERNSEC_KERN_LOCKOUT
54657+ bool "Active kernel exploit response"
54658+ depends on X86 || ARM || PPC || SPARC
54659+ help
54660+ If you say Y here, when a PaX alert is triggered due to suspicious
54661+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
54662+ or an OOPs occurs due to bad memory accesses, instead of just
54663+ terminating the offending process (and potentially allowing
54664+ a subsequent exploit from the same user), we will take one of two
54665+ actions:
54666+ If the user was root, we will panic the system
54667+ If the user was non-root, we will log the attempt, terminate
54668+ all processes owned by the user, then prevent them from creating
54669+ any new processes until the system is restarted
54670+ This deters repeated kernel exploitation/bruteforcing attempts
54671+ and is useful for later forensics.
54672+
54673+endmenu
54674+menu "Role Based Access Control Options"
54675+depends on GRKERNSEC
54676+
54677+config GRKERNSEC_RBAC_DEBUG
54678+ bool
54679+
54680+config GRKERNSEC_NO_RBAC
54681+ bool "Disable RBAC system"
54682+ help
54683+ If you say Y here, the /dev/grsec device will be removed from the kernel,
54684+ preventing the RBAC system from being enabled. You should only say Y
54685+ here if you have no intention of using the RBAC system, so as to prevent
54686+ an attacker with root access from misusing the RBAC system to hide files
54687+ and processes when loadable module support and /dev/[k]mem have been
54688+ locked down.
54689+
54690+config GRKERNSEC_ACL_HIDEKERN
54691+ bool "Hide kernel processes"
54692+ help
54693+ If you say Y here, all kernel threads will be hidden to all
54694+ processes but those whose subject has the "view hidden processes"
54695+ flag.
54696+
54697+config GRKERNSEC_ACL_MAXTRIES
54698+ int "Maximum tries before password lockout"
54699+ default 3
54700+ help
54701+ This option enforces the maximum number of times a user can attempt
54702+ to authorize themselves with the grsecurity RBAC system before being
54703+ denied the ability to attempt authorization again for a specified time.
54704+ The lower the number, the harder it will be to brute-force a password.
54705+
54706+config GRKERNSEC_ACL_TIMEOUT
54707+ int "Time to wait after max password tries, in seconds"
54708+ default 30
54709+ help
54710+ This option specifies the time the user must wait after attempting to
54711+ authorize to the RBAC system with the maximum number of invalid
54712+ passwords. The higher the number, the harder it will be to brute-force
54713+ a password.
54714+
54715+endmenu
54716+menu "Filesystem Protections"
54717+depends on GRKERNSEC
54718+
54719+config GRKERNSEC_PROC
54720+ bool "Proc restrictions"
54721+ help
54722+ If you say Y here, the permissions of the /proc filesystem
54723+ will be altered to enhance system security and privacy. You MUST
54724+ choose either a user only restriction or a user and group restriction.
54725+ Depending upon the option you choose, you can either restrict users to
54726+ see only the processes they themselves run, or choose a group that can
54727+ view all processes and files normally restricted to root if you choose
54728+ the "restrict to user only" option. NOTE: If you're running identd as
54729+ a non-root user, you will have to run it as the group you specify here.
54730+
54731+config GRKERNSEC_PROC_USER
54732+ bool "Restrict /proc to user only"
54733+ depends on GRKERNSEC_PROC
54734+ help
54735+ If you say Y here, non-root users will only be able to view their own
54736+ processes, and restricts them from viewing network-related information,
54737+ and viewing kernel symbol and module information.
54738+
54739+config GRKERNSEC_PROC_USERGROUP
54740+ bool "Allow special group"
54741+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
54742+ help
54743+ If you say Y here, you will be able to select a group that will be
54744+ able to view all processes and network-related information. If you've
54745+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
54746+ remain hidden. This option is useful if you want to run identd as
54747+ a non-root user.
54748+
54749+config GRKERNSEC_PROC_GID
54750+ int "GID for special group"
54751+ depends on GRKERNSEC_PROC_USERGROUP
54752+ default 1001
54753+
54754+config GRKERNSEC_PROC_ADD
54755+ bool "Additional restrictions"
54756+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
54757+ help
54758+ If you say Y here, additional restrictions will be placed on
54759+ /proc that keep normal users from viewing device information and
54760+ slabinfo information that could be useful for exploits.
54761+
54762+config GRKERNSEC_LINK
54763+ bool "Linking restrictions"
54764+ help
54765+ If you say Y here, /tmp race exploits will be prevented, since users
54766+ will no longer be able to follow symlinks owned by other users in
54767+ world-writable +t directories (e.g. /tmp), unless the owner of the
54768+ symlink is the owner of the directory. users will also not be
54769+ able to hardlink to files they do not own. If the sysctl option is
54770+ enabled, a sysctl option with name "linking_restrictions" is created.
54771+
54772+config GRKERNSEC_FIFO
54773+ bool "FIFO restrictions"
54774+ help
54775+ If you say Y here, users will not be able to write to FIFOs they don't
54776+ own in world-writable +t directories (e.g. /tmp), unless the owner of
54777+ the FIFO is the same owner of the directory it's held in. If the sysctl
54778+ option is enabled, a sysctl option with name "fifo_restrictions" is
54779+ created.
54780+
54781+config GRKERNSEC_SYSFS_RESTRICT
54782+ bool "Sysfs/debugfs restriction"
54783+ depends on SYSFS
54784+ help
54785+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
54786+ any filesystem normally mounted under it (e.g. debugfs) will only
54787+ be accessible by root. These filesystems generally provide access
54788+ to hardware and debug information that isn't appropriate for unprivileged
54789+ users of the system. Sysfs and debugfs have also become a large source
54790+ of new vulnerabilities, ranging from infoleaks to local compromise.
54791+ There has been very little oversight with an eye toward security involved
54792+ in adding new exporters of information to these filesystems, so their
54793+ use is discouraged.
54794+ This option is equivalent to a chmod 0700 of the mount paths.
54795+
54796+config GRKERNSEC_ROFS
54797+ bool "Runtime read-only mount protection"
54798+ help
54799+ If you say Y here, a sysctl option with name "romount_protect" will
54800+ be created. By setting this option to 1 at runtime, filesystems
54801+ will be protected in the following ways:
54802+ * No new writable mounts will be allowed
54803+ * Existing read-only mounts won't be able to be remounted read/write
54804+ * Write operations will be denied on all block devices
54805+ This option acts independently of grsec_lock: once it is set to 1,
54806+ it cannot be turned off. Therefore, please be mindful of the resulting
54807+ behavior if this option is enabled in an init script on a read-only
54808+ filesystem. This feature is mainly intended for secure embedded systems.
54809+
54810+config GRKERNSEC_CHROOT
54811+ bool "Chroot jail restrictions"
54812+ help
54813+ If you say Y here, you will be able to choose several options that will
54814+ make breaking out of a chrooted jail much more difficult. If you
54815+ encounter no software incompatibilities with the following options, it
54816+ is recommended that you enable each one.
54817+
54818+config GRKERNSEC_CHROOT_MOUNT
54819+ bool "Deny mounts"
54820+ depends on GRKERNSEC_CHROOT
54821+ help
54822+ If you say Y here, processes inside a chroot will not be able to
54823+ mount or remount filesystems. If the sysctl option is enabled, a
54824+ sysctl option with name "chroot_deny_mount" is created.
54825+
54826+config GRKERNSEC_CHROOT_DOUBLE
54827+ bool "Deny double-chroots"
54828+ depends on GRKERNSEC_CHROOT
54829+ help
54830+ If you say Y here, processes inside a chroot will not be able to chroot
54831+ again outside the chroot. This is a widely used method of breaking
54832+ out of a chroot jail and should not be allowed. If the sysctl
54833+ option is enabled, a sysctl option with name
54834+ "chroot_deny_chroot" is created.
54835+
54836+config GRKERNSEC_CHROOT_PIVOT
54837+ bool "Deny pivot_root in chroot"
54838+ depends on GRKERNSEC_CHROOT
54839+ help
54840+ If you say Y here, processes inside a chroot will not be able to use
54841+ a function called pivot_root() that was introduced in Linux 2.3.41. It
54842+ works similar to chroot in that it changes the root filesystem. This
54843+ function could be misused in a chrooted process to attempt to break out
54844+ of the chroot, and therefore should not be allowed. If the sysctl
54845+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
54846+ created.
54847+
54848+config GRKERNSEC_CHROOT_CHDIR
54849+ bool "Enforce chdir(\"/\") on all chroots"
54850+ depends on GRKERNSEC_CHROOT
54851+ help
54852+ If you say Y here, the current working directory of all newly-chrooted
54853+ applications will be set to the the root directory of the chroot.
54854+ The man page on chroot(2) states:
54855+ Note that this call does not change the current working
54856+ directory, so that `.' can be outside the tree rooted at
54857+ `/'. In particular, the super-user can escape from a
54858+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
54859+
54860+ It is recommended that you say Y here, since it's not known to break
54861+ any software. If the sysctl option is enabled, a sysctl option with
54862+ name "chroot_enforce_chdir" is created.
54863+
54864+config GRKERNSEC_CHROOT_CHMOD
54865+ bool "Deny (f)chmod +s"
54866+ depends on GRKERNSEC_CHROOT
54867+ help
54868+ If you say Y here, processes inside a chroot will not be able to chmod
54869+ or fchmod files to make them have suid or sgid bits. This protects
54870+ against another published method of breaking a chroot. If the sysctl
54871+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
54872+ created.
54873+
54874+config GRKERNSEC_CHROOT_FCHDIR
54875+ bool "Deny fchdir out of chroot"
54876+ depends on GRKERNSEC_CHROOT
54877+ help
54878+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
54879+ to a file descriptor of the chrooting process that points to a directory
54880+ outside the filesystem will be stopped. If the sysctl option
54881+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
54882+
54883+config GRKERNSEC_CHROOT_MKNOD
54884+ bool "Deny mknod"
54885+ depends on GRKERNSEC_CHROOT
54886+ help
54887+ If you say Y here, processes inside a chroot will not be allowed to
54888+ mknod. The problem with using mknod inside a chroot is that it
54889+ would allow an attacker to create a device entry that is the same
54890+ as one on the physical root of your system, which could range from
54891+ anything from the console device to a device for your harddrive (which
54892+ they could then use to wipe the drive or steal data). It is recommended
54893+ that you say Y here, unless you run into software incompatibilities.
54894+ If the sysctl option is enabled, a sysctl option with name
54895+ "chroot_deny_mknod" is created.
54896+
54897+config GRKERNSEC_CHROOT_SHMAT
54898+ bool "Deny shmat() out of chroot"
54899+ depends on GRKERNSEC_CHROOT
54900+ help
54901+ If you say Y here, processes inside a chroot will not be able to attach
54902+ to shared memory segments that were created outside of the chroot jail.
54903+ It is recommended that you say Y here. If the sysctl option is enabled,
54904+ a sysctl option with name "chroot_deny_shmat" is created.
54905+
54906+config GRKERNSEC_CHROOT_UNIX
54907+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
54908+ depends on GRKERNSEC_CHROOT
54909+ help
54910+ If you say Y here, processes inside a chroot will not be able to
54911+ connect to abstract (meaning not belonging to a filesystem) Unix
54912+ domain sockets that were bound outside of a chroot. It is recommended
54913+ that you say Y here. If the sysctl option is enabled, a sysctl option
54914+ with name "chroot_deny_unix" is created.
54915+
54916+config GRKERNSEC_CHROOT_FINDTASK
54917+ bool "Protect outside processes"
54918+ depends on GRKERNSEC_CHROOT
54919+ help
54920+ If you say Y here, processes inside a chroot will not be able to
54921+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
54922+ getsid, or view any process outside of the chroot. If the sysctl
54923+ option is enabled, a sysctl option with name "chroot_findtask" is
54924+ created.
54925+
54926+config GRKERNSEC_CHROOT_NICE
54927+ bool "Restrict priority changes"
54928+ depends on GRKERNSEC_CHROOT
54929+ help
54930+ If you say Y here, processes inside a chroot will not be able to raise
54931+ the priority of processes in the chroot, or alter the priority of
54932+ processes outside the chroot. This provides more security than simply
54933+ removing CAP_SYS_NICE from the process' capability set. If the
54934+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
54935+ is created.
54936+
54937+config GRKERNSEC_CHROOT_SYSCTL
54938+ bool "Deny sysctl writes"
54939+ depends on GRKERNSEC_CHROOT
54940+ help
54941+ If you say Y here, an attacker in a chroot will not be able to
54942+ write to sysctl entries, either by sysctl(2) or through a /proc
54943+ interface. It is strongly recommended that you say Y here. If the
54944+ sysctl option is enabled, a sysctl option with name
54945+ "chroot_deny_sysctl" is created.
54946+
54947+config GRKERNSEC_CHROOT_CAPS
54948+ bool "Capability restrictions"
54949+ depends on GRKERNSEC_CHROOT
54950+ help
54951+ If you say Y here, the capabilities on all processes within a
54952+ chroot jail will be lowered to stop module insertion, raw i/o,
54953+ system and net admin tasks, rebooting the system, modifying immutable
54954+ files, modifying IPC owned by another, and changing the system time.
54955+ This is left an option because it can break some apps. Disable this
54956+ if your chrooted apps are having problems performing those kinds of
54957+ tasks. If the sysctl option is enabled, a sysctl option with
54958+ name "chroot_caps" is created.
54959+
54960+endmenu
54961+menu "Kernel Auditing"
54962+depends on GRKERNSEC
54963+
54964+config GRKERNSEC_AUDIT_GROUP
54965+ bool "Single group for auditing"
54966+ help
54967+ If you say Y here, the exec, chdir, and (un)mount logging features
54968+ will only operate on a group you specify. This option is recommended
54969+ if you only want to watch certain users instead of having a large
54970+ amount of logs from the entire system. If the sysctl option is enabled,
54971+ a sysctl option with name "audit_group" is created.
54972+
54973+config GRKERNSEC_AUDIT_GID
54974+ int "GID for auditing"
54975+ depends on GRKERNSEC_AUDIT_GROUP
54976+ default 1007
54977+
54978+config GRKERNSEC_EXECLOG
54979+ bool "Exec logging"
54980+ help
54981+ If you say Y here, all execve() calls will be logged (since the
54982+ other exec*() calls are frontends to execve(), all execution
54983+ will be logged). Useful for shell-servers that like to keep track
54984+ of their users. If the sysctl option is enabled, a sysctl option with
54985+ name "exec_logging" is created.
54986+ WARNING: This option when enabled will produce a LOT of logs, especially
54987+ on an active system.
54988+
54989+config GRKERNSEC_RESLOG
54990+ bool "Resource logging"
54991+ help
54992+ If you say Y here, all attempts to overstep resource limits will
54993+ be logged with the resource name, the requested size, and the current
54994+ limit. It is highly recommended that you say Y here. If the sysctl
54995+ option is enabled, a sysctl option with name "resource_logging" is
54996+ created. If the RBAC system is enabled, the sysctl value is ignored.
54997+
54998+config GRKERNSEC_CHROOT_EXECLOG
54999+ bool "Log execs within chroot"
55000+ help
55001+ If you say Y here, all executions inside a chroot jail will be logged
55002+ to syslog. This can cause a large amount of logs if certain
55003+ applications (eg. djb's daemontools) are installed on the system, and
55004+ is therefore left as an option. If the sysctl option is enabled, a
55005+ sysctl option with name "chroot_execlog" is created.
55006+
55007+config GRKERNSEC_AUDIT_PTRACE
55008+ bool "Ptrace logging"
55009+ help
55010+ If you say Y here, all attempts to attach to a process via ptrace
55011+ will be logged. If the sysctl option is enabled, a sysctl option
55012+ with name "audit_ptrace" is created.
55013+
55014+config GRKERNSEC_AUDIT_CHDIR
55015+ bool "Chdir logging"
55016+ help
55017+ If you say Y here, all chdir() calls will be logged. If the sysctl
55018+ option is enabled, a sysctl option with name "audit_chdir" is created.
55019+
55020+config GRKERNSEC_AUDIT_MOUNT
55021+ bool "(Un)Mount logging"
55022+ help
55023+ If you say Y here, all mounts and unmounts will be logged. If the
55024+ sysctl option is enabled, a sysctl option with name "audit_mount" is
55025+ created.
55026+
55027+config GRKERNSEC_SIGNAL
55028+ bool "Signal logging"
55029+ help
55030+ If you say Y here, certain important signals will be logged, such as
55031+ SIGSEGV, which will as a result inform you of when a error in a program
55032+ occurred, which in some cases could mean a possible exploit attempt.
55033+ If the sysctl option is enabled, a sysctl option with name
55034+ "signal_logging" is created.
55035+
55036+config GRKERNSEC_FORKFAIL
55037+ bool "Fork failure logging"
55038+ help
55039+ If you say Y here, all failed fork() attempts will be logged.
55040+ This could suggest a fork bomb, or someone attempting to overstep
55041+ their process limit. If the sysctl option is enabled, a sysctl option
55042+ with name "forkfail_logging" is created.
55043+
55044+config GRKERNSEC_TIME
55045+ bool "Time change logging"
55046+ help
55047+ If you say Y here, any changes of the system clock will be logged.
55048+ If the sysctl option is enabled, a sysctl option with name
55049+ "timechange_logging" is created.
55050+
55051+config GRKERNSEC_PROC_IPADDR
55052+ bool "/proc/<pid>/ipaddr support"
55053+ help
55054+ If you say Y here, a new entry will be added to each /proc/<pid>
55055+ directory that contains the IP address of the person using the task.
55056+ The IP is carried across local TCP and AF_UNIX stream sockets.
55057+ This information can be useful for IDS/IPSes to perform remote response
55058+ to a local attack. The entry is readable by only the owner of the
55059+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
55060+ the RBAC system), and thus does not create privacy concerns.
55061+
55062+config GRKERNSEC_RWXMAP_LOG
55063+ bool 'Denied RWX mmap/mprotect logging'
55064+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
55065+ help
55066+ If you say Y here, calls to mmap() and mprotect() with explicit
55067+ usage of PROT_WRITE and PROT_EXEC together will be logged when
55068+ denied by the PAX_MPROTECT feature. If the sysctl option is
55069+ enabled, a sysctl option with name "rwxmap_logging" is created.
55070+
55071+config GRKERNSEC_AUDIT_TEXTREL
55072+ bool 'ELF text relocations logging (READ HELP)'
55073+ depends on PAX_MPROTECT
55074+ help
55075+ If you say Y here, text relocations will be logged with the filename
55076+ of the offending library or binary. The purpose of the feature is
55077+ to help Linux distribution developers get rid of libraries and
55078+ binaries that need text relocations which hinder the future progress
55079+ of PaX. Only Linux distribution developers should say Y here, and
55080+ never on a production machine, as this option creates an information
55081+ leak that could aid an attacker in defeating the randomization of
55082+ a single memory region. If the sysctl option is enabled, a sysctl
55083+ option with name "audit_textrel" is created.
55084+
55085+endmenu
55086+
55087+menu "Executable Protections"
55088+depends on GRKERNSEC
55089+
55090+config GRKERNSEC_DMESG
55091+ bool "Dmesg(8) restriction"
55092+ help
55093+ If you say Y here, non-root users will not be able to use dmesg(8)
55094+ to view up to the last 4kb of messages in the kernel's log buffer.
55095+ The kernel's log buffer often contains kernel addresses and other
55096+ identifying information useful to an attacker in fingerprinting a
55097+ system for a targeted exploit.
55098+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
55099+ created.
55100+
55101+config GRKERNSEC_HARDEN_PTRACE
55102+ bool "Deter ptrace-based process snooping"
55103+ help
55104+ If you say Y here, TTY sniffers and other malicious monitoring
55105+ programs implemented through ptrace will be defeated. If you
55106+ have been using the RBAC system, this option has already been
55107+ enabled for several years for all users, with the ability to make
55108+ fine-grained exceptions.
55109+
55110+ This option only affects the ability of non-root users to ptrace
55111+ processes that are not a descendent of the ptracing process.
55112+ This means that strace ./binary and gdb ./binary will still work,
55113+ but attaching to arbitrary processes will not. If the sysctl
55114+ option is enabled, a sysctl option with name "harden_ptrace" is
55115+ created.
55116+
55117+config GRKERNSEC_TPE
55118+ bool "Trusted Path Execution (TPE)"
55119+ help
55120+ If you say Y here, you will be able to choose a gid to add to the
55121+ supplementary groups of users you want to mark as "untrusted."
55122+ These users will not be able to execute any files that are not in
55123+ root-owned directories writable only by root. If the sysctl option
55124+ is enabled, a sysctl option with name "tpe" is created.
55125+
55126+config GRKERNSEC_TPE_ALL
55127+ bool "Partially restrict all non-root users"
55128+ depends on GRKERNSEC_TPE
55129+ help
55130+ If you say Y here, all non-root users will be covered under
55131+ a weaker TPE restriction. This is separate from, and in addition to,
55132+ the main TPE options that you have selected elsewhere. Thus, if a
55133+ "trusted" GID is chosen, this restriction applies to even that GID.
55134+ Under this restriction, all non-root users will only be allowed to
55135+ execute files in directories they own that are not group or
55136+ world-writable, or in directories owned by root and writable only by
55137+ root. If the sysctl option is enabled, a sysctl option with name
55138+ "tpe_restrict_all" is created.
55139+
55140+config GRKERNSEC_TPE_INVERT
55141+ bool "Invert GID option"
55142+ depends on GRKERNSEC_TPE
55143+ help
55144+ If you say Y here, the group you specify in the TPE configuration will
55145+ decide what group TPE restrictions will be *disabled* for. This
55146+ option is useful if you want TPE restrictions to be applied to most
55147+ users on the system. If the sysctl option is enabled, a sysctl option
55148+ with name "tpe_invert" is created. Unlike other sysctl options, this
55149+ entry will default to on for backward-compatibility.
55150+
55151+config GRKERNSEC_TPE_GID
55152+ int "GID for untrusted users"
55153+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
55154+ default 1005
55155+ help
55156+ Setting this GID determines what group TPE restrictions will be
55157+ *enabled* for. If the sysctl option is enabled, a sysctl option
55158+ with name "tpe_gid" is created.
55159+
55160+config GRKERNSEC_TPE_GID
55161+ int "GID for trusted users"
55162+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
55163+ default 1005
55164+ help
55165+ Setting this GID determines what group TPE restrictions will be
55166+ *disabled* for. If the sysctl option is enabled, a sysctl option
55167+ with name "tpe_gid" is created.
55168+
55169+endmenu
55170+menu "Network Protections"
55171+depends on GRKERNSEC
55172+
55173+config GRKERNSEC_RANDNET
55174+ bool "Larger entropy pools"
55175+ help
55176+ If you say Y here, the entropy pools used for many features of Linux
55177+ and grsecurity will be doubled in size. Since several grsecurity
55178+ features use additional randomness, it is recommended that you say Y
55179+ here. Saying Y here has a similar effect as modifying
55180+ /proc/sys/kernel/random/poolsize.
55181+
55182+config GRKERNSEC_BLACKHOLE
55183+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
55184+ depends on NET
55185+ help
55186+ If you say Y here, neither TCP resets nor ICMP
55187+ destination-unreachable packets will be sent in response to packets
55188+ sent to ports for which no associated listening process exists.
55189+ This feature supports both IPV4 and IPV6 and exempts the
55190+ loopback interface from blackholing. Enabling this feature
55191+ makes a host more resilient to DoS attacks and reduces network
55192+ visibility against scanners.
55193+
55194+ The blackhole feature as-implemented is equivalent to the FreeBSD
55195+ blackhole feature, as it prevents RST responses to all packets, not
55196+ just SYNs. Under most application behavior this causes no
55197+ problems, but applications (like haproxy) may not close certain
55198+ connections in a way that cleanly terminates them on the remote
55199+ end, leaving the remote host in LAST_ACK state. Because of this
55200+ side-effect and to prevent intentional LAST_ACK DoSes, this
55201+ feature also adds automatic mitigation against such attacks.
55202+ The mitigation drastically reduces the amount of time a socket
55203+ can spend in LAST_ACK state. If you're using haproxy and not
55204+ all servers it connects to have this option enabled, consider
55205+ disabling this feature on the haproxy host.
55206+
55207+ If the sysctl option is enabled, two sysctl options with names
55208+ "ip_blackhole" and "lastack_retries" will be created.
55209+ While "ip_blackhole" takes the standard zero/non-zero on/off
55210+ toggle, "lastack_retries" uses the same kinds of values as
55211+ "tcp_retries1" and "tcp_retries2". The default value of 4
55212+ prevents a socket from lasting more than 45 seconds in LAST_ACK
55213+ state.
55214+
55215+config GRKERNSEC_SOCKET
55216+ bool "Socket restrictions"
55217+ depends on NET
55218+ help
55219+ If you say Y here, you will be able to choose from several options.
55220+ If you assign a GID on your system and add it to the supplementary
55221+ groups of users you want to restrict socket access to, this patch
55222+ will perform up to three things, based on the option(s) you choose.
55223+
55224+config GRKERNSEC_SOCKET_ALL
55225+ bool "Deny any sockets to group"
55226+ depends on GRKERNSEC_SOCKET
55227+ help
55228+ If you say Y here, you will be able to choose a GID of whose users will
55229+ be unable to connect to other hosts from your machine or run server
55230+ applications from your machine. If the sysctl option is enabled, a
55231+ sysctl option with name "socket_all" is created.
55232+
55233+config GRKERNSEC_SOCKET_ALL_GID
55234+ int "GID to deny all sockets for"
55235+ depends on GRKERNSEC_SOCKET_ALL
55236+ default 1004
55237+ help
55238+ Here you can choose the GID to disable socket access for. Remember to
55239+ add the users you want socket access disabled for to the GID
55240+ specified here. If the sysctl option is enabled, a sysctl option
55241+ with name "socket_all_gid" is created.
55242+
55243+config GRKERNSEC_SOCKET_CLIENT
55244+ bool "Deny client sockets to group"
55245+ depends on GRKERNSEC_SOCKET
55246+ help
55247+ If you say Y here, you will be able to choose a GID of whose users will
55248+ be unable to connect to other hosts from your machine, but will be
55249+ able to run servers. If this option is enabled, all users in the group
55250+ you specify will have to use passive mode when initiating ftp transfers
55251+ from the shell on your machine. If the sysctl option is enabled, a
55252+ sysctl option with name "socket_client" is created.
55253+
55254+config GRKERNSEC_SOCKET_CLIENT_GID
55255+ int "GID to deny client sockets for"
55256+ depends on GRKERNSEC_SOCKET_CLIENT
55257+ default 1003
55258+ help
55259+ Here you can choose the GID to disable client socket access for.
55260+ Remember to add the users you want client socket access disabled for to
55261+ the GID specified here. If the sysctl option is enabled, a sysctl
55262+ option with name "socket_client_gid" is created.
55263+
55264+config GRKERNSEC_SOCKET_SERVER
55265+ bool "Deny server sockets to group"
55266+ depends on GRKERNSEC_SOCKET
55267+ help
55268+ If you say Y here, you will be able to choose a GID of whose users will
55269+ be unable to run server applications from your machine. If the sysctl
55270+ option is enabled, a sysctl option with name "socket_server" is created.
55271+
55272+config GRKERNSEC_SOCKET_SERVER_GID
55273+ int "GID to deny server sockets for"
55274+ depends on GRKERNSEC_SOCKET_SERVER
55275+ default 1002
55276+ help
55277+ Here you can choose the GID to disable server socket access for.
55278+ Remember to add the users you want server socket access disabled for to
55279+ the GID specified here. If the sysctl option is enabled, a sysctl
55280+ option with name "socket_server_gid" is created.
55281+
55282+endmenu
55283+menu "Sysctl support"
55284+depends on GRKERNSEC && SYSCTL
55285+
55286+config GRKERNSEC_SYSCTL
55287+ bool "Sysctl support"
55288+ help
55289+ If you say Y here, you will be able to change the options that
55290+ grsecurity runs with at bootup, without having to recompile your
55291+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
55292+ to enable (1) or disable (0) various features. All the sysctl entries
55293+ are mutable until the "grsec_lock" entry is set to a non-zero value.
55294+ All features enabled in the kernel configuration are disabled at boot
55295+ if you do not say Y to the "Turn on features by default" option.
55296+ All options should be set at startup, and the grsec_lock entry should
55297+ be set to a non-zero value after all the options are set.
55298+ *THIS IS EXTREMELY IMPORTANT*
55299+
55300+config GRKERNSEC_SYSCTL_DISTRO
55301+ bool "Extra sysctl support for distro makers (READ HELP)"
55302+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
55303+ help
55304+ If you say Y here, additional sysctl options will be created
55305+ for features that affect processes running as root. Therefore,
55306+ it is critical when using this option that the grsec_lock entry be
55307+ enabled after boot. Only distros with prebuilt kernel packages
55308+ with this option enabled that can ensure grsec_lock is enabled
55309+ after boot should use this option.
55310+ *Failure to set grsec_lock after boot makes all grsec features
55311+ this option covers useless*
55312+
55313+ Currently this option creates the following sysctl entries:
55314+ "Disable Privileged I/O": "disable_priv_io"
55315+
55316+config GRKERNSEC_SYSCTL_ON
55317+ bool "Turn on features by default"
55318+ depends on GRKERNSEC_SYSCTL
55319+ help
55320+ If you say Y here, instead of having all features enabled in the
55321+ kernel configuration disabled at boot time, the features will be
55322+ enabled at boot time. It is recommended you say Y here unless
55323+ there is some reason you would want all sysctl-tunable features to
55324+ be disabled by default. As mentioned elsewhere, it is important
55325+ to enable the grsec_lock entry once you have finished modifying
55326+ the sysctl entries.
55327+
55328+endmenu
55329+menu "Logging Options"
55330+depends on GRKERNSEC
55331+
55332+config GRKERNSEC_FLOODTIME
55333+ int "Seconds in between log messages (minimum)"
55334+ default 10
55335+ help
55336+ This option allows you to enforce the number of seconds between
55337+ grsecurity log messages. The default should be suitable for most
55338+ people, however, if you choose to change it, choose a value small enough
55339+ to allow informative logs to be produced, but large enough to
55340+ prevent flooding.
55341+
55342+config GRKERNSEC_FLOODBURST
55343+ int "Number of messages in a burst (maximum)"
55344+ default 6
55345+ help
55346+ This option allows you to choose the maximum number of messages allowed
55347+ within the flood time interval you chose in a separate option. The
55348+ default should be suitable for most people, however if you find that
55349+ many of your logs are being interpreted as flooding, you may want to
55350+ raise this value.
55351+
55352+endmenu
55353+
55354+endmenu
55355diff --git a/grsecurity/Makefile b/grsecurity/Makefile
55356new file mode 100644
55357index 0000000..be9ae3a
55358--- /dev/null
55359+++ b/grsecurity/Makefile
55360@@ -0,0 +1,36 @@
55361+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
55362+# during 2001-2009 it has been completely redesigned by Brad Spengler
55363+# into an RBAC system
55364+#
55365+# All code in this directory and various hooks inserted throughout the kernel
55366+# are copyright Brad Spengler - Open Source Security, Inc., and released
55367+# under the GPL v2 or higher
55368+
55369+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
55370+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
55371+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
55372+
55373+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
55374+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
55375+ gracl_learn.o grsec_log.o
55376+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
55377+
55378+ifdef CONFIG_NET
55379+obj-y += grsec_sock.o
55380+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
55381+endif
55382+
55383+ifndef CONFIG_GRKERNSEC
55384+obj-y += grsec_disabled.o
55385+endif
55386+
55387+ifdef CONFIG_GRKERNSEC_HIDESYM
55388+extra-y := grsec_hidesym.o
55389+$(obj)/grsec_hidesym.o:
55390+ @-chmod -f 500 /boot
55391+ @-chmod -f 500 /lib/modules
55392+ @-chmod -f 500 /lib64/modules
55393+ @-chmod -f 500 /lib32/modules
55394+ @-chmod -f 700 .
55395+ @echo ' grsec: protected kernel image paths'
55396+endif
55397diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
55398new file mode 100644
55399index 0000000..6bd68d6
55400--- /dev/null
55401+++ b/grsecurity/gracl.c
55402@@ -0,0 +1,4141 @@
55403+#include <linux/kernel.h>
55404+#include <linux/module.h>
55405+#include <linux/sched.h>
55406+#include <linux/mm.h>
55407+#include <linux/file.h>
55408+#include <linux/fs.h>
55409+#include <linux/namei.h>
55410+#include <linux/mount.h>
55411+#include <linux/tty.h>
55412+#include <linux/proc_fs.h>
55413+#include <linux/smp_lock.h>
55414+#include <linux/slab.h>
55415+#include <linux/vmalloc.h>
55416+#include <linux/types.h>
55417+#include <linux/sysctl.h>
55418+#include <linux/netdevice.h>
55419+#include <linux/ptrace.h>
55420+#include <linux/gracl.h>
55421+#include <linux/gralloc.h>
55422+#include <linux/grsecurity.h>
55423+#include <linux/grinternal.h>
55424+#include <linux/pid_namespace.h>
55425+#include <linux/fdtable.h>
55426+#include <linux/percpu.h>
55427+
55428+#include <asm/uaccess.h>
55429+#include <asm/errno.h>
55430+#include <asm/mman.h>
55431+
55432+static struct acl_role_db acl_role_set;
55433+static struct name_db name_set;
55434+static struct inodev_db inodev_set;
55435+
55436+/* for keeping track of userspace pointers used for subjects, so we
55437+ can share references in the kernel as well
55438+*/
55439+
55440+static struct dentry *real_root;
55441+static struct vfsmount *real_root_mnt;
55442+
55443+static struct acl_subj_map_db subj_map_set;
55444+
55445+static struct acl_role_label *default_role;
55446+
55447+static struct acl_role_label *role_list;
55448+
55449+static u16 acl_sp_role_value;
55450+
55451+extern char *gr_shared_page[4];
55452+static DEFINE_MUTEX(gr_dev_mutex);
55453+DEFINE_RWLOCK(gr_inode_lock);
55454+
55455+struct gr_arg *gr_usermode;
55456+
55457+static unsigned int gr_status __read_only = GR_STATUS_INIT;
55458+
55459+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
55460+extern void gr_clear_learn_entries(void);
55461+
55462+#ifdef CONFIG_GRKERNSEC_RESLOG
55463+extern void gr_log_resource(const struct task_struct *task,
55464+ const int res, const unsigned long wanted, const int gt);
55465+#endif
55466+
55467+unsigned char *gr_system_salt;
55468+unsigned char *gr_system_sum;
55469+
55470+static struct sprole_pw **acl_special_roles = NULL;
55471+static __u16 num_sprole_pws = 0;
55472+
55473+static struct acl_role_label *kernel_role = NULL;
55474+
55475+static unsigned int gr_auth_attempts = 0;
55476+static unsigned long gr_auth_expires = 0UL;
55477+
55478+#ifdef CONFIG_NET
55479+extern struct vfsmount *sock_mnt;
55480+#endif
55481+extern struct vfsmount *pipe_mnt;
55482+extern struct vfsmount *shm_mnt;
55483+#ifdef CONFIG_HUGETLBFS
55484+extern struct vfsmount *hugetlbfs_vfsmount;
55485+#endif
55486+
55487+static struct acl_object_label *fakefs_obj_rw;
55488+static struct acl_object_label *fakefs_obj_rwx;
55489+
55490+extern int gr_init_uidset(void);
55491+extern void gr_free_uidset(void);
55492+extern void gr_remove_uid(uid_t uid);
55493+extern int gr_find_uid(uid_t uid);
55494+
55495+__inline__ int
55496+gr_acl_is_enabled(void)
55497+{
55498+ return (gr_status & GR_READY);
55499+}
55500+
55501+#ifdef CONFIG_BTRFS_FS
55502+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55503+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55504+#endif
55505+
55506+static inline dev_t __get_dev(const struct dentry *dentry)
55507+{
55508+#ifdef CONFIG_BTRFS_FS
55509+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55510+ return get_btrfs_dev_from_inode(dentry->d_inode);
55511+ else
55512+#endif
55513+ return dentry->d_inode->i_sb->s_dev;
55514+}
55515+
55516+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55517+{
55518+ return __get_dev(dentry);
55519+}
55520+
55521+static char gr_task_roletype_to_char(struct task_struct *task)
55522+{
55523+ switch (task->role->roletype &
55524+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
55525+ GR_ROLE_SPECIAL)) {
55526+ case GR_ROLE_DEFAULT:
55527+ return 'D';
55528+ case GR_ROLE_USER:
55529+ return 'U';
55530+ case GR_ROLE_GROUP:
55531+ return 'G';
55532+ case GR_ROLE_SPECIAL:
55533+ return 'S';
55534+ }
55535+
55536+ return 'X';
55537+}
55538+
55539+char gr_roletype_to_char(void)
55540+{
55541+ return gr_task_roletype_to_char(current);
55542+}
55543+
55544+__inline__ int
55545+gr_acl_tpe_check(void)
55546+{
55547+ if (unlikely(!(gr_status & GR_READY)))
55548+ return 0;
55549+ if (current->role->roletype & GR_ROLE_TPE)
55550+ return 1;
55551+ else
55552+ return 0;
55553+}
55554+
55555+int
55556+gr_handle_rawio(const struct inode *inode)
55557+{
55558+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55559+ if (inode && S_ISBLK(inode->i_mode) &&
55560+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55561+ !capable(CAP_SYS_RAWIO))
55562+ return 1;
55563+#endif
55564+ return 0;
55565+}
55566+
55567+static int
55568+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
55569+{
55570+ if (likely(lena != lenb))
55571+ return 0;
55572+
55573+ return !memcmp(a, b, lena);
55574+}
55575+
55576+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
55577+{
55578+ *buflen -= namelen;
55579+ if (*buflen < 0)
55580+ return -ENAMETOOLONG;
55581+ *buffer -= namelen;
55582+ memcpy(*buffer, str, namelen);
55583+ return 0;
55584+}
55585+
55586+/* this must be called with vfsmount_lock and dcache_lock held */
55587+
55588+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55589+ struct dentry *root, struct vfsmount *rootmnt,
55590+ char *buffer, int buflen)
55591+{
55592+ char * end = buffer+buflen;
55593+ char * retval;
55594+ int namelen;
55595+
55596+ *--end = '\0';
55597+ buflen--;
55598+
55599+ if (buflen < 1)
55600+ goto Elong;
55601+ /* Get '/' right */
55602+ retval = end-1;
55603+ *retval = '/';
55604+
55605+ for (;;) {
55606+ struct dentry * parent;
55607+
55608+ if (dentry == root && vfsmnt == rootmnt)
55609+ break;
55610+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
55611+ /* Global root? */
55612+ if (vfsmnt->mnt_parent == vfsmnt)
55613+ goto global_root;
55614+ dentry = vfsmnt->mnt_mountpoint;
55615+ vfsmnt = vfsmnt->mnt_parent;
55616+ continue;
55617+ }
55618+ parent = dentry->d_parent;
55619+ prefetch(parent);
55620+ namelen = dentry->d_name.len;
55621+ buflen -= namelen + 1;
55622+ if (buflen < 0)
55623+ goto Elong;
55624+ end -= namelen;
55625+ memcpy(end, dentry->d_name.name, namelen);
55626+ *--end = '/';
55627+ retval = end;
55628+ dentry = parent;
55629+ }
55630+
55631+out:
55632+ return retval;
55633+
55634+global_root:
55635+ namelen = dentry->d_name.len;
55636+ buflen -= namelen;
55637+ if (buflen < 0)
55638+ goto Elong;
55639+ retval -= namelen-1; /* hit the slash */
55640+ memcpy(retval, dentry->d_name.name, namelen);
55641+ goto out;
55642+Elong:
55643+ retval = ERR_PTR(-ENAMETOOLONG);
55644+ goto out;
55645+}
55646+
55647+static char *
55648+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55649+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
55650+{
55651+ char *retval;
55652+
55653+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
55654+ if (unlikely(IS_ERR(retval)))
55655+ retval = strcpy(buf, "<path too long>");
55656+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
55657+ retval[1] = '\0';
55658+
55659+ return retval;
55660+}
55661+
55662+static char *
55663+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55664+ char *buf, int buflen)
55665+{
55666+ char *res;
55667+
55668+ /* we can use real_root, real_root_mnt, because this is only called
55669+ by the RBAC system */
55670+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
55671+
55672+ return res;
55673+}
55674+
55675+static char *
55676+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55677+ char *buf, int buflen)
55678+{
55679+ char *res;
55680+ struct dentry *root;
55681+ struct vfsmount *rootmnt;
55682+ struct task_struct *reaper = &init_task;
55683+
55684+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
55685+ read_lock(&reaper->fs->lock);
55686+ root = dget(reaper->fs->root.dentry);
55687+ rootmnt = mntget(reaper->fs->root.mnt);
55688+ read_unlock(&reaper->fs->lock);
55689+
55690+ spin_lock(&dcache_lock);
55691+ spin_lock(&vfsmount_lock);
55692+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
55693+ spin_unlock(&vfsmount_lock);
55694+ spin_unlock(&dcache_lock);
55695+
55696+ dput(root);
55697+ mntput(rootmnt);
55698+ return res;
55699+}
55700+
55701+static char *
55702+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55703+{
55704+ char *ret;
55705+ spin_lock(&dcache_lock);
55706+ spin_lock(&vfsmount_lock);
55707+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55708+ PAGE_SIZE);
55709+ spin_unlock(&vfsmount_lock);
55710+ spin_unlock(&dcache_lock);
55711+ return ret;
55712+}
55713+
55714+static char *
55715+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55716+{
55717+ char *ret;
55718+ char *buf;
55719+ int buflen;
55720+
55721+ spin_lock(&dcache_lock);
55722+ spin_lock(&vfsmount_lock);
55723+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55724+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
55725+ buflen = (int)(ret - buf);
55726+ if (buflen >= 5)
55727+ prepend(&ret, &buflen, "/proc", 5);
55728+ else
55729+ ret = strcpy(buf, "<path too long>");
55730+ spin_unlock(&vfsmount_lock);
55731+ spin_unlock(&dcache_lock);
55732+ return ret;
55733+}
55734+
55735+char *
55736+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
55737+{
55738+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55739+ PAGE_SIZE);
55740+}
55741+
55742+char *
55743+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
55744+{
55745+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55746+ PAGE_SIZE);
55747+}
55748+
55749+char *
55750+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
55751+{
55752+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
55753+ PAGE_SIZE);
55754+}
55755+
55756+char *
55757+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
55758+{
55759+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
55760+ PAGE_SIZE);
55761+}
55762+
55763+char *
55764+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
55765+{
55766+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
55767+ PAGE_SIZE);
55768+}
55769+
55770+__inline__ __u32
55771+to_gr_audit(const __u32 reqmode)
55772+{
55773+ /* masks off auditable permission flags, then shifts them to create
55774+ auditing flags, and adds the special case of append auditing if
55775+ we're requesting write */
55776+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
55777+}
55778+
55779+struct acl_subject_label *
55780+lookup_subject_map(const struct acl_subject_label *userp)
55781+{
55782+ unsigned int index = shash(userp, subj_map_set.s_size);
55783+ struct subject_map *match;
55784+
55785+ match = subj_map_set.s_hash[index];
55786+
55787+ while (match && match->user != userp)
55788+ match = match->next;
55789+
55790+ if (match != NULL)
55791+ return match->kernel;
55792+ else
55793+ return NULL;
55794+}
55795+
55796+static void
55797+insert_subj_map_entry(struct subject_map *subjmap)
55798+{
55799+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
55800+ struct subject_map **curr;
55801+
55802+ subjmap->prev = NULL;
55803+
55804+ curr = &subj_map_set.s_hash[index];
55805+ if (*curr != NULL)
55806+ (*curr)->prev = subjmap;
55807+
55808+ subjmap->next = *curr;
55809+ *curr = subjmap;
55810+
55811+ return;
55812+}
55813+
55814+static struct acl_role_label *
55815+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
55816+ const gid_t gid)
55817+{
55818+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
55819+ struct acl_role_label *match;
55820+ struct role_allowed_ip *ipp;
55821+ unsigned int x;
55822+ u32 curr_ip = task->signal->curr_ip;
55823+
55824+ task->signal->saved_ip = curr_ip;
55825+
55826+ match = acl_role_set.r_hash[index];
55827+
55828+ while (match) {
55829+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
55830+ for (x = 0; x < match->domain_child_num; x++) {
55831+ if (match->domain_children[x] == uid)
55832+ goto found;
55833+ }
55834+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
55835+ break;
55836+ match = match->next;
55837+ }
55838+found:
55839+ if (match == NULL) {
55840+ try_group:
55841+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
55842+ match = acl_role_set.r_hash[index];
55843+
55844+ while (match) {
55845+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
55846+ for (x = 0; x < match->domain_child_num; x++) {
55847+ if (match->domain_children[x] == gid)
55848+ goto found2;
55849+ }
55850+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
55851+ break;
55852+ match = match->next;
55853+ }
55854+found2:
55855+ if (match == NULL)
55856+ match = default_role;
55857+ if (match->allowed_ips == NULL)
55858+ return match;
55859+ else {
55860+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
55861+ if (likely
55862+ ((ntohl(curr_ip) & ipp->netmask) ==
55863+ (ntohl(ipp->addr) & ipp->netmask)))
55864+ return match;
55865+ }
55866+ match = default_role;
55867+ }
55868+ } else if (match->allowed_ips == NULL) {
55869+ return match;
55870+ } else {
55871+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
55872+ if (likely
55873+ ((ntohl(curr_ip) & ipp->netmask) ==
55874+ (ntohl(ipp->addr) & ipp->netmask)))
55875+ return match;
55876+ }
55877+ goto try_group;
55878+ }
55879+
55880+ return match;
55881+}
55882+
55883+struct acl_subject_label *
55884+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
55885+ const struct acl_role_label *role)
55886+{
55887+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
55888+ struct acl_subject_label *match;
55889+
55890+ match = role->subj_hash[index];
55891+
55892+ while (match && (match->inode != ino || match->device != dev ||
55893+ (match->mode & GR_DELETED))) {
55894+ match = match->next;
55895+ }
55896+
55897+ if (match && !(match->mode & GR_DELETED))
55898+ return match;
55899+ else
55900+ return NULL;
55901+}
55902+
55903+struct acl_subject_label *
55904+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
55905+ const struct acl_role_label *role)
55906+{
55907+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
55908+ struct acl_subject_label *match;
55909+
55910+ match = role->subj_hash[index];
55911+
55912+ while (match && (match->inode != ino || match->device != dev ||
55913+ !(match->mode & GR_DELETED))) {
55914+ match = match->next;
55915+ }
55916+
55917+ if (match && (match->mode & GR_DELETED))
55918+ return match;
55919+ else
55920+ return NULL;
55921+}
55922+
55923+static struct acl_object_label *
55924+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
55925+ const struct acl_subject_label *subj)
55926+{
55927+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
55928+ struct acl_object_label *match;
55929+
55930+ match = subj->obj_hash[index];
55931+
55932+ while (match && (match->inode != ino || match->device != dev ||
55933+ (match->mode & GR_DELETED))) {
55934+ match = match->next;
55935+ }
55936+
55937+ if (match && !(match->mode & GR_DELETED))
55938+ return match;
55939+ else
55940+ return NULL;
55941+}
55942+
55943+static struct acl_object_label *
55944+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
55945+ const struct acl_subject_label *subj)
55946+{
55947+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
55948+ struct acl_object_label *match;
55949+
55950+ match = subj->obj_hash[index];
55951+
55952+ while (match && (match->inode != ino || match->device != dev ||
55953+ !(match->mode & GR_DELETED))) {
55954+ match = match->next;
55955+ }
55956+
55957+ if (match && (match->mode & GR_DELETED))
55958+ return match;
55959+
55960+ match = subj->obj_hash[index];
55961+
55962+ while (match && (match->inode != ino || match->device != dev ||
55963+ (match->mode & GR_DELETED))) {
55964+ match = match->next;
55965+ }
55966+
55967+ if (match && !(match->mode & GR_DELETED))
55968+ return match;
55969+ else
55970+ return NULL;
55971+}
55972+
55973+static struct name_entry *
55974+lookup_name_entry(const char *name)
55975+{
55976+ unsigned int len = strlen(name);
55977+ unsigned int key = full_name_hash(name, len);
55978+ unsigned int index = key % name_set.n_size;
55979+ struct name_entry *match;
55980+
55981+ match = name_set.n_hash[index];
55982+
55983+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55984+ match = match->next;
55985+
55986+ return match;
55987+}
55988+
55989+static struct name_entry *
55990+lookup_name_entry_create(const char *name)
55991+{
55992+ unsigned int len = strlen(name);
55993+ unsigned int key = full_name_hash(name, len);
55994+ unsigned int index = key % name_set.n_size;
55995+ struct name_entry *match;
55996+
55997+ match = name_set.n_hash[index];
55998+
55999+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56000+ !match->deleted))
56001+ match = match->next;
56002+
56003+ if (match && match->deleted)
56004+ return match;
56005+
56006+ match = name_set.n_hash[index];
56007+
56008+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56009+ match->deleted))
56010+ match = match->next;
56011+
56012+ if (match && !match->deleted)
56013+ return match;
56014+ else
56015+ return NULL;
56016+}
56017+
56018+static struct inodev_entry *
56019+lookup_inodev_entry(const ino_t ino, const dev_t dev)
56020+{
56021+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
56022+ struct inodev_entry *match;
56023+
56024+ match = inodev_set.i_hash[index];
56025+
56026+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
56027+ match = match->next;
56028+
56029+ return match;
56030+}
56031+
56032+static void
56033+insert_inodev_entry(struct inodev_entry *entry)
56034+{
56035+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
56036+ inodev_set.i_size);
56037+ struct inodev_entry **curr;
56038+
56039+ entry->prev = NULL;
56040+
56041+ curr = &inodev_set.i_hash[index];
56042+ if (*curr != NULL)
56043+ (*curr)->prev = entry;
56044+
56045+ entry->next = *curr;
56046+ *curr = entry;
56047+
56048+ return;
56049+}
56050+
56051+static void
56052+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
56053+{
56054+ unsigned int index =
56055+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
56056+ struct acl_role_label **curr;
56057+ struct acl_role_label *tmp;
56058+
56059+ curr = &acl_role_set.r_hash[index];
56060+
56061+ /* if role was already inserted due to domains and already has
56062+ a role in the same bucket as it attached, then we need to
56063+ combine these two buckets
56064+ */
56065+ if (role->next) {
56066+ tmp = role->next;
56067+ while (tmp->next)
56068+ tmp = tmp->next;
56069+ tmp->next = *curr;
56070+ } else
56071+ role->next = *curr;
56072+ *curr = role;
56073+
56074+ return;
56075+}
56076+
56077+static void
56078+insert_acl_role_label(struct acl_role_label *role)
56079+{
56080+ int i;
56081+
56082+ if (role_list == NULL) {
56083+ role_list = role;
56084+ role->prev = NULL;
56085+ } else {
56086+ role->prev = role_list;
56087+ role_list = role;
56088+ }
56089+
56090+ /* used for hash chains */
56091+ role->next = NULL;
56092+
56093+ if (role->roletype & GR_ROLE_DOMAIN) {
56094+ for (i = 0; i < role->domain_child_num; i++)
56095+ __insert_acl_role_label(role, role->domain_children[i]);
56096+ } else
56097+ __insert_acl_role_label(role, role->uidgid);
56098+}
56099+
56100+static int
56101+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
56102+{
56103+ struct name_entry **curr, *nentry;
56104+ struct inodev_entry *ientry;
56105+ unsigned int len = strlen(name);
56106+ unsigned int key = full_name_hash(name, len);
56107+ unsigned int index = key % name_set.n_size;
56108+
56109+ curr = &name_set.n_hash[index];
56110+
56111+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
56112+ curr = &((*curr)->next);
56113+
56114+ if (*curr != NULL)
56115+ return 1;
56116+
56117+ nentry = acl_alloc(sizeof (struct name_entry));
56118+ if (nentry == NULL)
56119+ return 0;
56120+ ientry = acl_alloc(sizeof (struct inodev_entry));
56121+ if (ientry == NULL)
56122+ return 0;
56123+ ientry->nentry = nentry;
56124+
56125+ nentry->key = key;
56126+ nentry->name = name;
56127+ nentry->inode = inode;
56128+ nentry->device = device;
56129+ nentry->len = len;
56130+ nentry->deleted = deleted;
56131+
56132+ nentry->prev = NULL;
56133+ curr = &name_set.n_hash[index];
56134+ if (*curr != NULL)
56135+ (*curr)->prev = nentry;
56136+ nentry->next = *curr;
56137+ *curr = nentry;
56138+
56139+ /* insert us into the table searchable by inode/dev */
56140+ insert_inodev_entry(ientry);
56141+
56142+ return 1;
56143+}
56144+
56145+static void
56146+insert_acl_obj_label(struct acl_object_label *obj,
56147+ struct acl_subject_label *subj)
56148+{
56149+ unsigned int index =
56150+ fhash(obj->inode, obj->device, subj->obj_hash_size);
56151+ struct acl_object_label **curr;
56152+
56153+
56154+ obj->prev = NULL;
56155+
56156+ curr = &subj->obj_hash[index];
56157+ if (*curr != NULL)
56158+ (*curr)->prev = obj;
56159+
56160+ obj->next = *curr;
56161+ *curr = obj;
56162+
56163+ return;
56164+}
56165+
56166+static void
56167+insert_acl_subj_label(struct acl_subject_label *obj,
56168+ struct acl_role_label *role)
56169+{
56170+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
56171+ struct acl_subject_label **curr;
56172+
56173+ obj->prev = NULL;
56174+
56175+ curr = &role->subj_hash[index];
56176+ if (*curr != NULL)
56177+ (*curr)->prev = obj;
56178+
56179+ obj->next = *curr;
56180+ *curr = obj;
56181+
56182+ return;
56183+}
56184+
56185+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
56186+
56187+static void *
56188+create_table(__u32 * len, int elementsize)
56189+{
56190+ unsigned int table_sizes[] = {
56191+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
56192+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
56193+ 4194301, 8388593, 16777213, 33554393, 67108859
56194+ };
56195+ void *newtable = NULL;
56196+ unsigned int pwr = 0;
56197+
56198+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
56199+ table_sizes[pwr] <= *len)
56200+ pwr++;
56201+
56202+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
56203+ return newtable;
56204+
56205+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
56206+ newtable =
56207+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
56208+ else
56209+ newtable = vmalloc(table_sizes[pwr] * elementsize);
56210+
56211+ *len = table_sizes[pwr];
56212+
56213+ return newtable;
56214+}
56215+
56216+static int
56217+init_variables(const struct gr_arg *arg)
56218+{
56219+ struct task_struct *reaper = &init_task;
56220+ unsigned int stacksize;
56221+
56222+ subj_map_set.s_size = arg->role_db.num_subjects;
56223+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
56224+ name_set.n_size = arg->role_db.num_objects;
56225+ inodev_set.i_size = arg->role_db.num_objects;
56226+
56227+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
56228+ !name_set.n_size || !inodev_set.i_size)
56229+ return 1;
56230+
56231+ if (!gr_init_uidset())
56232+ return 1;
56233+
56234+ /* set up the stack that holds allocation info */
56235+
56236+ stacksize = arg->role_db.num_pointers + 5;
56237+
56238+ if (!acl_alloc_stack_init(stacksize))
56239+ return 1;
56240+
56241+ /* grab reference for the real root dentry and vfsmount */
56242+ read_lock(&reaper->fs->lock);
56243+ real_root = dget(reaper->fs->root.dentry);
56244+ real_root_mnt = mntget(reaper->fs->root.mnt);
56245+ read_unlock(&reaper->fs->lock);
56246+
56247+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56248+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
56249+#endif
56250+
56251+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
56252+ if (fakefs_obj_rw == NULL)
56253+ return 1;
56254+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
56255+
56256+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
56257+ if (fakefs_obj_rwx == NULL)
56258+ return 1;
56259+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
56260+
56261+ subj_map_set.s_hash =
56262+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
56263+ acl_role_set.r_hash =
56264+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
56265+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
56266+ inodev_set.i_hash =
56267+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
56268+
56269+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
56270+ !name_set.n_hash || !inodev_set.i_hash)
56271+ return 1;
56272+
56273+ memset(subj_map_set.s_hash, 0,
56274+ sizeof(struct subject_map *) * subj_map_set.s_size);
56275+ memset(acl_role_set.r_hash, 0,
56276+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
56277+ memset(name_set.n_hash, 0,
56278+ sizeof (struct name_entry *) * name_set.n_size);
56279+ memset(inodev_set.i_hash, 0,
56280+ sizeof (struct inodev_entry *) * inodev_set.i_size);
56281+
56282+ return 0;
56283+}
56284+
56285+/* free information not needed after startup
56286+ currently contains user->kernel pointer mappings for subjects
56287+*/
56288+
56289+static void
56290+free_init_variables(void)
56291+{
56292+ __u32 i;
56293+
56294+ if (subj_map_set.s_hash) {
56295+ for (i = 0; i < subj_map_set.s_size; i++) {
56296+ if (subj_map_set.s_hash[i]) {
56297+ kfree(subj_map_set.s_hash[i]);
56298+ subj_map_set.s_hash[i] = NULL;
56299+ }
56300+ }
56301+
56302+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
56303+ PAGE_SIZE)
56304+ kfree(subj_map_set.s_hash);
56305+ else
56306+ vfree(subj_map_set.s_hash);
56307+ }
56308+
56309+ return;
56310+}
56311+
56312+static void
56313+free_variables(void)
56314+{
56315+ struct acl_subject_label *s;
56316+ struct acl_role_label *r;
56317+ struct task_struct *task, *task2;
56318+ unsigned int x;
56319+
56320+ gr_clear_learn_entries();
56321+
56322+ read_lock(&tasklist_lock);
56323+ do_each_thread(task2, task) {
56324+ task->acl_sp_role = 0;
56325+ task->acl_role_id = 0;
56326+ task->acl = NULL;
56327+ task->role = NULL;
56328+ } while_each_thread(task2, task);
56329+ read_unlock(&tasklist_lock);
56330+
56331+ /* release the reference to the real root dentry and vfsmount */
56332+ if (real_root)
56333+ dput(real_root);
56334+ real_root = NULL;
56335+ if (real_root_mnt)
56336+ mntput(real_root_mnt);
56337+ real_root_mnt = NULL;
56338+
56339+ /* free all object hash tables */
56340+
56341+ FOR_EACH_ROLE_START(r)
56342+ if (r->subj_hash == NULL)
56343+ goto next_role;
56344+ FOR_EACH_SUBJECT_START(r, s, x)
56345+ if (s->obj_hash == NULL)
56346+ break;
56347+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56348+ kfree(s->obj_hash);
56349+ else
56350+ vfree(s->obj_hash);
56351+ FOR_EACH_SUBJECT_END(s, x)
56352+ FOR_EACH_NESTED_SUBJECT_START(r, s)
56353+ if (s->obj_hash == NULL)
56354+ break;
56355+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56356+ kfree(s->obj_hash);
56357+ else
56358+ vfree(s->obj_hash);
56359+ FOR_EACH_NESTED_SUBJECT_END(s)
56360+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
56361+ kfree(r->subj_hash);
56362+ else
56363+ vfree(r->subj_hash);
56364+ r->subj_hash = NULL;
56365+next_role:
56366+ FOR_EACH_ROLE_END(r)
56367+
56368+ acl_free_all();
56369+
56370+ if (acl_role_set.r_hash) {
56371+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
56372+ PAGE_SIZE)
56373+ kfree(acl_role_set.r_hash);
56374+ else
56375+ vfree(acl_role_set.r_hash);
56376+ }
56377+ if (name_set.n_hash) {
56378+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
56379+ PAGE_SIZE)
56380+ kfree(name_set.n_hash);
56381+ else
56382+ vfree(name_set.n_hash);
56383+ }
56384+
56385+ if (inodev_set.i_hash) {
56386+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
56387+ PAGE_SIZE)
56388+ kfree(inodev_set.i_hash);
56389+ else
56390+ vfree(inodev_set.i_hash);
56391+ }
56392+
56393+ gr_free_uidset();
56394+
56395+ memset(&name_set, 0, sizeof (struct name_db));
56396+ memset(&inodev_set, 0, sizeof (struct inodev_db));
56397+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
56398+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
56399+
56400+ default_role = NULL;
56401+ role_list = NULL;
56402+
56403+ return;
56404+}
56405+
56406+static __u32
56407+count_user_objs(struct acl_object_label *userp)
56408+{
56409+ struct acl_object_label o_tmp;
56410+ __u32 num = 0;
56411+
56412+ while (userp) {
56413+ if (copy_from_user(&o_tmp, userp,
56414+ sizeof (struct acl_object_label)))
56415+ break;
56416+
56417+ userp = o_tmp.prev;
56418+ num++;
56419+ }
56420+
56421+ return num;
56422+}
56423+
56424+static struct acl_subject_label *
56425+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
56426+
56427+static int
56428+copy_user_glob(struct acl_object_label *obj)
56429+{
56430+ struct acl_object_label *g_tmp, **guser;
56431+ unsigned int len;
56432+ char *tmp;
56433+
56434+ if (obj->globbed == NULL)
56435+ return 0;
56436+
56437+ guser = &obj->globbed;
56438+ while (*guser) {
56439+ g_tmp = (struct acl_object_label *)
56440+ acl_alloc(sizeof (struct acl_object_label));
56441+ if (g_tmp == NULL)
56442+ return -ENOMEM;
56443+
56444+ if (copy_from_user(g_tmp, *guser,
56445+ sizeof (struct acl_object_label)))
56446+ return -EFAULT;
56447+
56448+ len = strnlen_user(g_tmp->filename, PATH_MAX);
56449+
56450+ if (!len || len >= PATH_MAX)
56451+ return -EINVAL;
56452+
56453+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56454+ return -ENOMEM;
56455+
56456+ if (copy_from_user(tmp, g_tmp->filename, len))
56457+ return -EFAULT;
56458+ tmp[len-1] = '\0';
56459+ g_tmp->filename = tmp;
56460+
56461+ *guser = g_tmp;
56462+ guser = &(g_tmp->next);
56463+ }
56464+
56465+ return 0;
56466+}
56467+
56468+static int
56469+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
56470+ struct acl_role_label *role)
56471+{
56472+ struct acl_object_label *o_tmp;
56473+ unsigned int len;
56474+ int ret;
56475+ char *tmp;
56476+
56477+ while (userp) {
56478+ if ((o_tmp = (struct acl_object_label *)
56479+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
56480+ return -ENOMEM;
56481+
56482+ if (copy_from_user(o_tmp, userp,
56483+ sizeof (struct acl_object_label)))
56484+ return -EFAULT;
56485+
56486+ userp = o_tmp->prev;
56487+
56488+ len = strnlen_user(o_tmp->filename, PATH_MAX);
56489+
56490+ if (!len || len >= PATH_MAX)
56491+ return -EINVAL;
56492+
56493+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56494+ return -ENOMEM;
56495+
56496+ if (copy_from_user(tmp, o_tmp->filename, len))
56497+ return -EFAULT;
56498+ tmp[len-1] = '\0';
56499+ o_tmp->filename = tmp;
56500+
56501+ insert_acl_obj_label(o_tmp, subj);
56502+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
56503+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
56504+ return -ENOMEM;
56505+
56506+ ret = copy_user_glob(o_tmp);
56507+ if (ret)
56508+ return ret;
56509+
56510+ if (o_tmp->nested) {
56511+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
56512+ if (IS_ERR(o_tmp->nested))
56513+ return PTR_ERR(o_tmp->nested);
56514+
56515+ /* insert into nested subject list */
56516+ o_tmp->nested->next = role->hash->first;
56517+ role->hash->first = o_tmp->nested;
56518+ }
56519+ }
56520+
56521+ return 0;
56522+}
56523+
56524+static __u32
56525+count_user_subjs(struct acl_subject_label *userp)
56526+{
56527+ struct acl_subject_label s_tmp;
56528+ __u32 num = 0;
56529+
56530+ while (userp) {
56531+ if (copy_from_user(&s_tmp, userp,
56532+ sizeof (struct acl_subject_label)))
56533+ break;
56534+
56535+ userp = s_tmp.prev;
56536+ /* do not count nested subjects against this count, since
56537+ they are not included in the hash table, but are
56538+ attached to objects. We have already counted
56539+ the subjects in userspace for the allocation
56540+ stack
56541+ */
56542+ if (!(s_tmp.mode & GR_NESTED))
56543+ num++;
56544+ }
56545+
56546+ return num;
56547+}
56548+
56549+static int
56550+copy_user_allowedips(struct acl_role_label *rolep)
56551+{
56552+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
56553+
56554+ ruserip = rolep->allowed_ips;
56555+
56556+ while (ruserip) {
56557+ rlast = rtmp;
56558+
56559+ if ((rtmp = (struct role_allowed_ip *)
56560+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
56561+ return -ENOMEM;
56562+
56563+ if (copy_from_user(rtmp, ruserip,
56564+ sizeof (struct role_allowed_ip)))
56565+ return -EFAULT;
56566+
56567+ ruserip = rtmp->prev;
56568+
56569+ if (!rlast) {
56570+ rtmp->prev = NULL;
56571+ rolep->allowed_ips = rtmp;
56572+ } else {
56573+ rlast->next = rtmp;
56574+ rtmp->prev = rlast;
56575+ }
56576+
56577+ if (!ruserip)
56578+ rtmp->next = NULL;
56579+ }
56580+
56581+ return 0;
56582+}
56583+
56584+static int
56585+copy_user_transitions(struct acl_role_label *rolep)
56586+{
56587+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
56588+
56589+ unsigned int len;
56590+ char *tmp;
56591+
56592+ rusertp = rolep->transitions;
56593+
56594+ while (rusertp) {
56595+ rlast = rtmp;
56596+
56597+ if ((rtmp = (struct role_transition *)
56598+ acl_alloc(sizeof (struct role_transition))) == NULL)
56599+ return -ENOMEM;
56600+
56601+ if (copy_from_user(rtmp, rusertp,
56602+ sizeof (struct role_transition)))
56603+ return -EFAULT;
56604+
56605+ rusertp = rtmp->prev;
56606+
56607+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
56608+
56609+ if (!len || len >= GR_SPROLE_LEN)
56610+ return -EINVAL;
56611+
56612+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56613+ return -ENOMEM;
56614+
56615+ if (copy_from_user(tmp, rtmp->rolename, len))
56616+ return -EFAULT;
56617+ tmp[len-1] = '\0';
56618+ rtmp->rolename = tmp;
56619+
56620+ if (!rlast) {
56621+ rtmp->prev = NULL;
56622+ rolep->transitions = rtmp;
56623+ } else {
56624+ rlast->next = rtmp;
56625+ rtmp->prev = rlast;
56626+ }
56627+
56628+ if (!rusertp)
56629+ rtmp->next = NULL;
56630+ }
56631+
56632+ return 0;
56633+}
56634+
56635+static struct acl_subject_label *
56636+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
56637+{
56638+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
56639+ unsigned int len;
56640+ char *tmp;
56641+ __u32 num_objs;
56642+ struct acl_ip_label **i_tmp, *i_utmp2;
56643+ struct gr_hash_struct ghash;
56644+ struct subject_map *subjmap;
56645+ unsigned int i_num;
56646+ int err;
56647+
56648+ s_tmp = lookup_subject_map(userp);
56649+
56650+ /* we've already copied this subject into the kernel, just return
56651+ the reference to it, and don't copy it over again
56652+ */
56653+ if (s_tmp)
56654+ return(s_tmp);
56655+
56656+ if ((s_tmp = (struct acl_subject_label *)
56657+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
56658+ return ERR_PTR(-ENOMEM);
56659+
56660+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
56661+ if (subjmap == NULL)
56662+ return ERR_PTR(-ENOMEM);
56663+
56664+ subjmap->user = userp;
56665+ subjmap->kernel = s_tmp;
56666+ insert_subj_map_entry(subjmap);
56667+
56668+ if (copy_from_user(s_tmp, userp,
56669+ sizeof (struct acl_subject_label)))
56670+ return ERR_PTR(-EFAULT);
56671+
56672+ len = strnlen_user(s_tmp->filename, PATH_MAX);
56673+
56674+ if (!len || len >= PATH_MAX)
56675+ return ERR_PTR(-EINVAL);
56676+
56677+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56678+ return ERR_PTR(-ENOMEM);
56679+
56680+ if (copy_from_user(tmp, s_tmp->filename, len))
56681+ return ERR_PTR(-EFAULT);
56682+ tmp[len-1] = '\0';
56683+ s_tmp->filename = tmp;
56684+
56685+ if (!strcmp(s_tmp->filename, "/"))
56686+ role->root_label = s_tmp;
56687+
56688+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
56689+ return ERR_PTR(-EFAULT);
56690+
56691+ /* copy user and group transition tables */
56692+
56693+ if (s_tmp->user_trans_num) {
56694+ uid_t *uidlist;
56695+
56696+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
56697+ if (uidlist == NULL)
56698+ return ERR_PTR(-ENOMEM);
56699+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
56700+ return ERR_PTR(-EFAULT);
56701+
56702+ s_tmp->user_transitions = uidlist;
56703+ }
56704+
56705+ if (s_tmp->group_trans_num) {
56706+ gid_t *gidlist;
56707+
56708+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
56709+ if (gidlist == NULL)
56710+ return ERR_PTR(-ENOMEM);
56711+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
56712+ return ERR_PTR(-EFAULT);
56713+
56714+ s_tmp->group_transitions = gidlist;
56715+ }
56716+
56717+ /* set up object hash table */
56718+ num_objs = count_user_objs(ghash.first);
56719+
56720+ s_tmp->obj_hash_size = num_objs;
56721+ s_tmp->obj_hash =
56722+ (struct acl_object_label **)
56723+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
56724+
56725+ if (!s_tmp->obj_hash)
56726+ return ERR_PTR(-ENOMEM);
56727+
56728+ memset(s_tmp->obj_hash, 0,
56729+ s_tmp->obj_hash_size *
56730+ sizeof (struct acl_object_label *));
56731+
56732+ /* add in objects */
56733+ err = copy_user_objs(ghash.first, s_tmp, role);
56734+
56735+ if (err)
56736+ return ERR_PTR(err);
56737+
56738+ /* set pointer for parent subject */
56739+ if (s_tmp->parent_subject) {
56740+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
56741+
56742+ if (IS_ERR(s_tmp2))
56743+ return s_tmp2;
56744+
56745+ s_tmp->parent_subject = s_tmp2;
56746+ }
56747+
56748+ /* add in ip acls */
56749+
56750+ if (!s_tmp->ip_num) {
56751+ s_tmp->ips = NULL;
56752+ goto insert;
56753+ }
56754+
56755+ i_tmp =
56756+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
56757+ sizeof (struct acl_ip_label *));
56758+
56759+ if (!i_tmp)
56760+ return ERR_PTR(-ENOMEM);
56761+
56762+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
56763+ *(i_tmp + i_num) =
56764+ (struct acl_ip_label *)
56765+ acl_alloc(sizeof (struct acl_ip_label));
56766+ if (!*(i_tmp + i_num))
56767+ return ERR_PTR(-ENOMEM);
56768+
56769+ if (copy_from_user
56770+ (&i_utmp2, s_tmp->ips + i_num,
56771+ sizeof (struct acl_ip_label *)))
56772+ return ERR_PTR(-EFAULT);
56773+
56774+ if (copy_from_user
56775+ (*(i_tmp + i_num), i_utmp2,
56776+ sizeof (struct acl_ip_label)))
56777+ return ERR_PTR(-EFAULT);
56778+
56779+ if ((*(i_tmp + i_num))->iface == NULL)
56780+ continue;
56781+
56782+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
56783+ if (!len || len >= IFNAMSIZ)
56784+ return ERR_PTR(-EINVAL);
56785+ tmp = acl_alloc(len);
56786+ if (tmp == NULL)
56787+ return ERR_PTR(-ENOMEM);
56788+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
56789+ return ERR_PTR(-EFAULT);
56790+ (*(i_tmp + i_num))->iface = tmp;
56791+ }
56792+
56793+ s_tmp->ips = i_tmp;
56794+
56795+insert:
56796+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
56797+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
56798+ return ERR_PTR(-ENOMEM);
56799+
56800+ return s_tmp;
56801+}
56802+
56803+static int
56804+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
56805+{
56806+ struct acl_subject_label s_pre;
56807+ struct acl_subject_label * ret;
56808+ int err;
56809+
56810+ while (userp) {
56811+ if (copy_from_user(&s_pre, userp,
56812+ sizeof (struct acl_subject_label)))
56813+ return -EFAULT;
56814+
56815+ /* do not add nested subjects here, add
56816+ while parsing objects
56817+ */
56818+
56819+ if (s_pre.mode & GR_NESTED) {
56820+ userp = s_pre.prev;
56821+ continue;
56822+ }
56823+
56824+ ret = do_copy_user_subj(userp, role);
56825+
56826+ err = PTR_ERR(ret);
56827+ if (IS_ERR(ret))
56828+ return err;
56829+
56830+ insert_acl_subj_label(ret, role);
56831+
56832+ userp = s_pre.prev;
56833+ }
56834+
56835+ return 0;
56836+}
56837+
56838+static int
56839+copy_user_acl(struct gr_arg *arg)
56840+{
56841+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
56842+ struct sprole_pw *sptmp;
56843+ struct gr_hash_struct *ghash;
56844+ uid_t *domainlist;
56845+ unsigned int r_num;
56846+ unsigned int len;
56847+ char *tmp;
56848+ int err = 0;
56849+ __u16 i;
56850+ __u32 num_subjs;
56851+
56852+ /* we need a default and kernel role */
56853+ if (arg->role_db.num_roles < 2)
56854+ return -EINVAL;
56855+
56856+ /* copy special role authentication info from userspace */
56857+
56858+ num_sprole_pws = arg->num_sprole_pws;
56859+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
56860+
56861+ if (!acl_special_roles) {
56862+ err = -ENOMEM;
56863+ goto cleanup;
56864+ }
56865+
56866+ for (i = 0; i < num_sprole_pws; i++) {
56867+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
56868+ if (!sptmp) {
56869+ err = -ENOMEM;
56870+ goto cleanup;
56871+ }
56872+ if (copy_from_user(sptmp, arg->sprole_pws + i,
56873+ sizeof (struct sprole_pw))) {
56874+ err = -EFAULT;
56875+ goto cleanup;
56876+ }
56877+
56878+ len =
56879+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
56880+
56881+ if (!len || len >= GR_SPROLE_LEN) {
56882+ err = -EINVAL;
56883+ goto cleanup;
56884+ }
56885+
56886+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
56887+ err = -ENOMEM;
56888+ goto cleanup;
56889+ }
56890+
56891+ if (copy_from_user(tmp, sptmp->rolename, len)) {
56892+ err = -EFAULT;
56893+ goto cleanup;
56894+ }
56895+ tmp[len-1] = '\0';
56896+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56897+ printk(KERN_ALERT "Copying special role %s\n", tmp);
56898+#endif
56899+ sptmp->rolename = tmp;
56900+ acl_special_roles[i] = sptmp;
56901+ }
56902+
56903+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
56904+
56905+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
56906+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
56907+
56908+ if (!r_tmp) {
56909+ err = -ENOMEM;
56910+ goto cleanup;
56911+ }
56912+
56913+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
56914+ sizeof (struct acl_role_label *))) {
56915+ err = -EFAULT;
56916+ goto cleanup;
56917+ }
56918+
56919+ if (copy_from_user(r_tmp, r_utmp2,
56920+ sizeof (struct acl_role_label))) {
56921+ err = -EFAULT;
56922+ goto cleanup;
56923+ }
56924+
56925+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
56926+
56927+ if (!len || len >= PATH_MAX) {
56928+ err = -EINVAL;
56929+ goto cleanup;
56930+ }
56931+
56932+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
56933+ err = -ENOMEM;
56934+ goto cleanup;
56935+ }
56936+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
56937+ err = -EFAULT;
56938+ goto cleanup;
56939+ }
56940+ tmp[len-1] = '\0';
56941+ r_tmp->rolename = tmp;
56942+
56943+ if (!strcmp(r_tmp->rolename, "default")
56944+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
56945+ default_role = r_tmp;
56946+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56947+ kernel_role = r_tmp;
56948+ }
56949+
56950+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
56951+ err = -ENOMEM;
56952+ goto cleanup;
56953+ }
56954+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
56955+ err = -EFAULT;
56956+ goto cleanup;
56957+ }
56958+
56959+ r_tmp->hash = ghash;
56960+
56961+ num_subjs = count_user_subjs(r_tmp->hash->first);
56962+
56963+ r_tmp->subj_hash_size = num_subjs;
56964+ r_tmp->subj_hash =
56965+ (struct acl_subject_label **)
56966+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56967+
56968+ if (!r_tmp->subj_hash) {
56969+ err = -ENOMEM;
56970+ goto cleanup;
56971+ }
56972+
56973+ err = copy_user_allowedips(r_tmp);
56974+ if (err)
56975+ goto cleanup;
56976+
56977+ /* copy domain info */
56978+ if (r_tmp->domain_children != NULL) {
56979+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56980+ if (domainlist == NULL) {
56981+ err = -ENOMEM;
56982+ goto cleanup;
56983+ }
56984+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
56985+ err = -EFAULT;
56986+ goto cleanup;
56987+ }
56988+ r_tmp->domain_children = domainlist;
56989+ }
56990+
56991+ err = copy_user_transitions(r_tmp);
56992+ if (err)
56993+ goto cleanup;
56994+
56995+ memset(r_tmp->subj_hash, 0,
56996+ r_tmp->subj_hash_size *
56997+ sizeof (struct acl_subject_label *));
56998+
56999+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
57000+
57001+ if (err)
57002+ goto cleanup;
57003+
57004+ /* set nested subject list to null */
57005+ r_tmp->hash->first = NULL;
57006+
57007+ insert_acl_role_label(r_tmp);
57008+ }
57009+
57010+ goto return_err;
57011+ cleanup:
57012+ free_variables();
57013+ return_err:
57014+ return err;
57015+
57016+}
57017+
57018+static int
57019+gracl_init(struct gr_arg *args)
57020+{
57021+ int error = 0;
57022+
57023+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
57024+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
57025+
57026+ if (init_variables(args)) {
57027+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
57028+ error = -ENOMEM;
57029+ free_variables();
57030+ goto out;
57031+ }
57032+
57033+ error = copy_user_acl(args);
57034+ free_init_variables();
57035+ if (error) {
57036+ free_variables();
57037+ goto out;
57038+ }
57039+
57040+ if ((error = gr_set_acls(0))) {
57041+ free_variables();
57042+ goto out;
57043+ }
57044+
57045+ pax_open_kernel();
57046+ gr_status |= GR_READY;
57047+ pax_close_kernel();
57048+
57049+ out:
57050+ return error;
57051+}
57052+
57053+/* derived from glibc fnmatch() 0: match, 1: no match*/
57054+
57055+static int
57056+glob_match(const char *p, const char *n)
57057+{
57058+ char c;
57059+
57060+ while ((c = *p++) != '\0') {
57061+ switch (c) {
57062+ case '?':
57063+ if (*n == '\0')
57064+ return 1;
57065+ else if (*n == '/')
57066+ return 1;
57067+ break;
57068+ case '\\':
57069+ if (*n != c)
57070+ return 1;
57071+ break;
57072+ case '*':
57073+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
57074+ if (*n == '/')
57075+ return 1;
57076+ else if (c == '?') {
57077+ if (*n == '\0')
57078+ return 1;
57079+ else
57080+ ++n;
57081+ }
57082+ }
57083+ if (c == '\0') {
57084+ return 0;
57085+ } else {
57086+ const char *endp;
57087+
57088+ if ((endp = strchr(n, '/')) == NULL)
57089+ endp = n + strlen(n);
57090+
57091+ if (c == '[') {
57092+ for (--p; n < endp; ++n)
57093+ if (!glob_match(p, n))
57094+ return 0;
57095+ } else if (c == '/') {
57096+ while (*n != '\0' && *n != '/')
57097+ ++n;
57098+ if (*n == '/' && !glob_match(p, n + 1))
57099+ return 0;
57100+ } else {
57101+ for (--p; n < endp; ++n)
57102+ if (*n == c && !glob_match(p, n))
57103+ return 0;
57104+ }
57105+
57106+ return 1;
57107+ }
57108+ case '[':
57109+ {
57110+ int not;
57111+ char cold;
57112+
57113+ if (*n == '\0' || *n == '/')
57114+ return 1;
57115+
57116+ not = (*p == '!' || *p == '^');
57117+ if (not)
57118+ ++p;
57119+
57120+ c = *p++;
57121+ for (;;) {
57122+ unsigned char fn = (unsigned char)*n;
57123+
57124+ if (c == '\0')
57125+ return 1;
57126+ else {
57127+ if (c == fn)
57128+ goto matched;
57129+ cold = c;
57130+ c = *p++;
57131+
57132+ if (c == '-' && *p != ']') {
57133+ unsigned char cend = *p++;
57134+
57135+ if (cend == '\0')
57136+ return 1;
57137+
57138+ if (cold <= fn && fn <= cend)
57139+ goto matched;
57140+
57141+ c = *p++;
57142+ }
57143+ }
57144+
57145+ if (c == ']')
57146+ break;
57147+ }
57148+ if (!not)
57149+ return 1;
57150+ break;
57151+ matched:
57152+ while (c != ']') {
57153+ if (c == '\0')
57154+ return 1;
57155+
57156+ c = *p++;
57157+ }
57158+ if (not)
57159+ return 1;
57160+ }
57161+ break;
57162+ default:
57163+ if (c != *n)
57164+ return 1;
57165+ }
57166+
57167+ ++n;
57168+ }
57169+
57170+ if (*n == '\0')
57171+ return 0;
57172+
57173+ if (*n == '/')
57174+ return 0;
57175+
57176+ return 1;
57177+}
57178+
57179+static struct acl_object_label *
57180+chk_glob_label(struct acl_object_label *globbed,
57181+ struct dentry *dentry, struct vfsmount *mnt, char **path)
57182+{
57183+ struct acl_object_label *tmp;
57184+
57185+ if (*path == NULL)
57186+ *path = gr_to_filename_nolock(dentry, mnt);
57187+
57188+ tmp = globbed;
57189+
57190+ while (tmp) {
57191+ if (!glob_match(tmp->filename, *path))
57192+ return tmp;
57193+ tmp = tmp->next;
57194+ }
57195+
57196+ return NULL;
57197+}
57198+
57199+static struct acl_object_label *
57200+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57201+ const ino_t curr_ino, const dev_t curr_dev,
57202+ const struct acl_subject_label *subj, char **path, const int checkglob)
57203+{
57204+ struct acl_subject_label *tmpsubj;
57205+ struct acl_object_label *retval;
57206+ struct acl_object_label *retval2;
57207+
57208+ tmpsubj = (struct acl_subject_label *) subj;
57209+ read_lock(&gr_inode_lock);
57210+ do {
57211+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
57212+ if (retval) {
57213+ if (checkglob && retval->globbed) {
57214+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
57215+ (struct vfsmount *)orig_mnt, path);
57216+ if (retval2)
57217+ retval = retval2;
57218+ }
57219+ break;
57220+ }
57221+ } while ((tmpsubj = tmpsubj->parent_subject));
57222+ read_unlock(&gr_inode_lock);
57223+
57224+ return retval;
57225+}
57226+
57227+static __inline__ struct acl_object_label *
57228+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57229+ const struct dentry *curr_dentry,
57230+ const struct acl_subject_label *subj, char **path, const int checkglob)
57231+{
57232+ int newglob = checkglob;
57233+
57234+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
57235+ as we don't want a / * rule to match instead of the / object
57236+ don't do this for create lookups that call this function though, since they're looking up
57237+ on the parent and thus need globbing checks on all paths
57238+ */
57239+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
57240+ newglob = GR_NO_GLOB;
57241+
57242+ return __full_lookup(orig_dentry, orig_mnt,
57243+ curr_dentry->d_inode->i_ino,
57244+ __get_dev(curr_dentry), subj, path, newglob);
57245+}
57246+
57247+static struct acl_object_label *
57248+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57249+ const struct acl_subject_label *subj, char *path, const int checkglob)
57250+{
57251+ struct dentry *dentry = (struct dentry *) l_dentry;
57252+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57253+ struct acl_object_label *retval;
57254+
57255+ spin_lock(&dcache_lock);
57256+ spin_lock(&vfsmount_lock);
57257+
57258+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
57259+#ifdef CONFIG_NET
57260+ mnt == sock_mnt ||
57261+#endif
57262+#ifdef CONFIG_HUGETLBFS
57263+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
57264+#endif
57265+ /* ignore Eric Biederman */
57266+ IS_PRIVATE(l_dentry->d_inode))) {
57267+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
57268+ goto out;
57269+ }
57270+
57271+ for (;;) {
57272+ if (dentry == real_root && mnt == real_root_mnt)
57273+ break;
57274+
57275+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57276+ if (mnt->mnt_parent == mnt)
57277+ break;
57278+
57279+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57280+ if (retval != NULL)
57281+ goto out;
57282+
57283+ dentry = mnt->mnt_mountpoint;
57284+ mnt = mnt->mnt_parent;
57285+ continue;
57286+ }
57287+
57288+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57289+ if (retval != NULL)
57290+ goto out;
57291+
57292+ dentry = dentry->d_parent;
57293+ }
57294+
57295+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57296+
57297+ if (retval == NULL)
57298+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
57299+out:
57300+ spin_unlock(&vfsmount_lock);
57301+ spin_unlock(&dcache_lock);
57302+
57303+ BUG_ON(retval == NULL);
57304+
57305+ return retval;
57306+}
57307+
57308+static __inline__ struct acl_object_label *
57309+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57310+ const struct acl_subject_label *subj)
57311+{
57312+ char *path = NULL;
57313+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
57314+}
57315+
57316+static __inline__ struct acl_object_label *
57317+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57318+ const struct acl_subject_label *subj)
57319+{
57320+ char *path = NULL;
57321+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
57322+}
57323+
57324+static __inline__ struct acl_object_label *
57325+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57326+ const struct acl_subject_label *subj, char *path)
57327+{
57328+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
57329+}
57330+
57331+static struct acl_subject_label *
57332+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57333+ const struct acl_role_label *role)
57334+{
57335+ struct dentry *dentry = (struct dentry *) l_dentry;
57336+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57337+ struct acl_subject_label *retval;
57338+
57339+ spin_lock(&dcache_lock);
57340+ spin_lock(&vfsmount_lock);
57341+
57342+ for (;;) {
57343+ if (dentry == real_root && mnt == real_root_mnt)
57344+ break;
57345+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57346+ if (mnt->mnt_parent == mnt)
57347+ break;
57348+
57349+ read_lock(&gr_inode_lock);
57350+ retval =
57351+ lookup_acl_subj_label(dentry->d_inode->i_ino,
57352+ __get_dev(dentry), role);
57353+ read_unlock(&gr_inode_lock);
57354+ if (retval != NULL)
57355+ goto out;
57356+
57357+ dentry = mnt->mnt_mountpoint;
57358+ mnt = mnt->mnt_parent;
57359+ continue;
57360+ }
57361+
57362+ read_lock(&gr_inode_lock);
57363+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57364+ __get_dev(dentry), role);
57365+ read_unlock(&gr_inode_lock);
57366+ if (retval != NULL)
57367+ goto out;
57368+
57369+ dentry = dentry->d_parent;
57370+ }
57371+
57372+ read_lock(&gr_inode_lock);
57373+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57374+ __get_dev(dentry), role);
57375+ read_unlock(&gr_inode_lock);
57376+
57377+ if (unlikely(retval == NULL)) {
57378+ read_lock(&gr_inode_lock);
57379+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
57380+ __get_dev(real_root), role);
57381+ read_unlock(&gr_inode_lock);
57382+ }
57383+out:
57384+ spin_unlock(&vfsmount_lock);
57385+ spin_unlock(&dcache_lock);
57386+
57387+ BUG_ON(retval == NULL);
57388+
57389+ return retval;
57390+}
57391+
57392+static void
57393+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
57394+{
57395+ struct task_struct *task = current;
57396+ const struct cred *cred = current_cred();
57397+
57398+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57399+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57400+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57401+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
57402+
57403+ return;
57404+}
57405+
57406+static void
57407+gr_log_learn_sysctl(const char *path, const __u32 mode)
57408+{
57409+ struct task_struct *task = current;
57410+ const struct cred *cred = current_cred();
57411+
57412+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57413+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57414+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57415+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
57416+
57417+ return;
57418+}
57419+
57420+static void
57421+gr_log_learn_id_change(const char type, const unsigned int real,
57422+ const unsigned int effective, const unsigned int fs)
57423+{
57424+ struct task_struct *task = current;
57425+ const struct cred *cred = current_cred();
57426+
57427+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
57428+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57429+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57430+ type, real, effective, fs, &task->signal->saved_ip);
57431+
57432+ return;
57433+}
57434+
57435+__u32
57436+gr_search_file(const struct dentry * dentry, const __u32 mode,
57437+ const struct vfsmount * mnt)
57438+{
57439+ __u32 retval = mode;
57440+ struct acl_subject_label *curracl;
57441+ struct acl_object_label *currobj;
57442+
57443+ if (unlikely(!(gr_status & GR_READY)))
57444+ return (mode & ~GR_AUDITS);
57445+
57446+ curracl = current->acl;
57447+
57448+ currobj = chk_obj_label(dentry, mnt, curracl);
57449+ retval = currobj->mode & mode;
57450+
57451+ /* if we're opening a specified transfer file for writing
57452+ (e.g. /dev/initctl), then transfer our role to init
57453+ */
57454+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
57455+ current->role->roletype & GR_ROLE_PERSIST)) {
57456+ struct task_struct *task = init_pid_ns.child_reaper;
57457+
57458+ if (task->role != current->role) {
57459+ task->acl_sp_role = 0;
57460+ task->acl_role_id = current->acl_role_id;
57461+ task->role = current->role;
57462+ rcu_read_lock();
57463+ read_lock(&grsec_exec_file_lock);
57464+ gr_apply_subject_to_task(task);
57465+ read_unlock(&grsec_exec_file_lock);
57466+ rcu_read_unlock();
57467+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
57468+ }
57469+ }
57470+
57471+ if (unlikely
57472+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
57473+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
57474+ __u32 new_mode = mode;
57475+
57476+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57477+
57478+ retval = new_mode;
57479+
57480+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
57481+ new_mode |= GR_INHERIT;
57482+
57483+ if (!(mode & GR_NOLEARN))
57484+ gr_log_learn(dentry, mnt, new_mode);
57485+ }
57486+
57487+ return retval;
57488+}
57489+
57490+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
57491+ const struct dentry *parent,
57492+ const struct vfsmount *mnt)
57493+{
57494+ struct name_entry *match;
57495+ struct acl_object_label *matchpo;
57496+ struct acl_subject_label *curracl;
57497+ char *path;
57498+
57499+ if (unlikely(!(gr_status & GR_READY)))
57500+ return NULL;
57501+
57502+ preempt_disable();
57503+ path = gr_to_filename_rbac(new_dentry, mnt);
57504+ match = lookup_name_entry_create(path);
57505+
57506+ curracl = current->acl;
57507+
57508+ if (match) {
57509+ read_lock(&gr_inode_lock);
57510+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
57511+ read_unlock(&gr_inode_lock);
57512+
57513+ if (matchpo) {
57514+ preempt_enable();
57515+ return matchpo;
57516+ }
57517+ }
57518+
57519+ // lookup parent
57520+
57521+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
57522+
57523+ preempt_enable();
57524+ return matchpo;
57525+}
57526+
57527+__u32
57528+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
57529+ const struct vfsmount * mnt, const __u32 mode)
57530+{
57531+ struct acl_object_label *matchpo;
57532+ __u32 retval;
57533+
57534+ if (unlikely(!(gr_status & GR_READY)))
57535+ return (mode & ~GR_AUDITS);
57536+
57537+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
57538+
57539+ retval = matchpo->mode & mode;
57540+
57541+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
57542+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57543+ __u32 new_mode = mode;
57544+
57545+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57546+
57547+ gr_log_learn(new_dentry, mnt, new_mode);
57548+ return new_mode;
57549+ }
57550+
57551+ return retval;
57552+}
57553+
57554+__u32
57555+gr_check_link(const struct dentry * new_dentry,
57556+ const struct dentry * parent_dentry,
57557+ const struct vfsmount * parent_mnt,
57558+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
57559+{
57560+ struct acl_object_label *obj;
57561+ __u32 oldmode, newmode;
57562+ __u32 needmode;
57563+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
57564+ GR_DELETE | GR_INHERIT;
57565+
57566+ if (unlikely(!(gr_status & GR_READY)))
57567+ return (GR_CREATE | GR_LINK);
57568+
57569+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
57570+ oldmode = obj->mode;
57571+
57572+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
57573+ newmode = obj->mode;
57574+
57575+ needmode = newmode & checkmodes;
57576+
57577+ // old name for hardlink must have at least the permissions of the new name
57578+ if ((oldmode & needmode) != needmode)
57579+ goto bad;
57580+
57581+ // if old name had restrictions/auditing, make sure the new name does as well
57582+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
57583+
57584+ // don't allow hardlinking of suid/sgid files without permission
57585+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57586+ needmode |= GR_SETID;
57587+
57588+ if ((newmode & needmode) != needmode)
57589+ goto bad;
57590+
57591+ // enforce minimum permissions
57592+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
57593+ return newmode;
57594+bad:
57595+ needmode = oldmode;
57596+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57597+ needmode |= GR_SETID;
57598+
57599+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
57600+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
57601+ return (GR_CREATE | GR_LINK);
57602+ } else if (newmode & GR_SUPPRESS)
57603+ return GR_SUPPRESS;
57604+ else
57605+ return 0;
57606+}
57607+
57608+int
57609+gr_check_hidden_task(const struct task_struct *task)
57610+{
57611+ if (unlikely(!(gr_status & GR_READY)))
57612+ return 0;
57613+
57614+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
57615+ return 1;
57616+
57617+ return 0;
57618+}
57619+
57620+int
57621+gr_check_protected_task(const struct task_struct *task)
57622+{
57623+ if (unlikely(!(gr_status & GR_READY) || !task))
57624+ return 0;
57625+
57626+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57627+ task->acl != current->acl)
57628+ return 1;
57629+
57630+ return 0;
57631+}
57632+
57633+int
57634+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57635+{
57636+ struct task_struct *p;
57637+ int ret = 0;
57638+
57639+ if (unlikely(!(gr_status & GR_READY) || !pid))
57640+ return ret;
57641+
57642+ read_lock(&tasklist_lock);
57643+ do_each_pid_task(pid, type, p) {
57644+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57645+ p->acl != current->acl) {
57646+ ret = 1;
57647+ goto out;
57648+ }
57649+ } while_each_pid_task(pid, type, p);
57650+out:
57651+ read_unlock(&tasklist_lock);
57652+
57653+ return ret;
57654+}
57655+
57656+void
57657+gr_copy_label(struct task_struct *tsk)
57658+{
57659+ tsk->signal->used_accept = 0;
57660+ tsk->acl_sp_role = 0;
57661+ tsk->acl_role_id = current->acl_role_id;
57662+ tsk->acl = current->acl;
57663+ tsk->role = current->role;
57664+ tsk->signal->curr_ip = current->signal->curr_ip;
57665+ tsk->signal->saved_ip = current->signal->saved_ip;
57666+ if (current->exec_file)
57667+ get_file(current->exec_file);
57668+ tsk->exec_file = current->exec_file;
57669+ tsk->is_writable = current->is_writable;
57670+ if (unlikely(current->signal->used_accept)) {
57671+ current->signal->curr_ip = 0;
57672+ current->signal->saved_ip = 0;
57673+ }
57674+
57675+ return;
57676+}
57677+
57678+static void
57679+gr_set_proc_res(struct task_struct *task)
57680+{
57681+ struct acl_subject_label *proc;
57682+ unsigned short i;
57683+
57684+ proc = task->acl;
57685+
57686+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
57687+ return;
57688+
57689+ for (i = 0; i < RLIM_NLIMITS; i++) {
57690+ if (!(proc->resmask & (1 << i)))
57691+ continue;
57692+
57693+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
57694+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
57695+ }
57696+
57697+ return;
57698+}
57699+
57700+extern int __gr_process_user_ban(struct user_struct *user);
57701+
57702+int
57703+gr_check_user_change(int real, int effective, int fs)
57704+{
57705+ unsigned int i;
57706+ __u16 num;
57707+ uid_t *uidlist;
57708+ int curuid;
57709+ int realok = 0;
57710+ int effectiveok = 0;
57711+ int fsok = 0;
57712+
57713+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57714+ struct user_struct *user;
57715+
57716+ if (real == -1)
57717+ goto skipit;
57718+
57719+ user = find_user(real);
57720+ if (user == NULL)
57721+ goto skipit;
57722+
57723+ if (__gr_process_user_ban(user)) {
57724+ /* for find_user */
57725+ free_uid(user);
57726+ return 1;
57727+ }
57728+
57729+ /* for find_user */
57730+ free_uid(user);
57731+
57732+skipit:
57733+#endif
57734+
57735+ if (unlikely(!(gr_status & GR_READY)))
57736+ return 0;
57737+
57738+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57739+ gr_log_learn_id_change('u', real, effective, fs);
57740+
57741+ num = current->acl->user_trans_num;
57742+ uidlist = current->acl->user_transitions;
57743+
57744+ if (uidlist == NULL)
57745+ return 0;
57746+
57747+ if (real == -1)
57748+ realok = 1;
57749+ if (effective == -1)
57750+ effectiveok = 1;
57751+ if (fs == -1)
57752+ fsok = 1;
57753+
57754+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
57755+ for (i = 0; i < num; i++) {
57756+ curuid = (int)uidlist[i];
57757+ if (real == curuid)
57758+ realok = 1;
57759+ if (effective == curuid)
57760+ effectiveok = 1;
57761+ if (fs == curuid)
57762+ fsok = 1;
57763+ }
57764+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
57765+ for (i = 0; i < num; i++) {
57766+ curuid = (int)uidlist[i];
57767+ if (real == curuid)
57768+ break;
57769+ if (effective == curuid)
57770+ break;
57771+ if (fs == curuid)
57772+ break;
57773+ }
57774+ /* not in deny list */
57775+ if (i == num) {
57776+ realok = 1;
57777+ effectiveok = 1;
57778+ fsok = 1;
57779+ }
57780+ }
57781+
57782+ if (realok && effectiveok && fsok)
57783+ return 0;
57784+ else {
57785+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
57786+ return 1;
57787+ }
57788+}
57789+
57790+int
57791+gr_check_group_change(int real, int effective, int fs)
57792+{
57793+ unsigned int i;
57794+ __u16 num;
57795+ gid_t *gidlist;
57796+ int curgid;
57797+ int realok = 0;
57798+ int effectiveok = 0;
57799+ int fsok = 0;
57800+
57801+ if (unlikely(!(gr_status & GR_READY)))
57802+ return 0;
57803+
57804+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57805+ gr_log_learn_id_change('g', real, effective, fs);
57806+
57807+ num = current->acl->group_trans_num;
57808+ gidlist = current->acl->group_transitions;
57809+
57810+ if (gidlist == NULL)
57811+ return 0;
57812+
57813+ if (real == -1)
57814+ realok = 1;
57815+ if (effective == -1)
57816+ effectiveok = 1;
57817+ if (fs == -1)
57818+ fsok = 1;
57819+
57820+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
57821+ for (i = 0; i < num; i++) {
57822+ curgid = (int)gidlist[i];
57823+ if (real == curgid)
57824+ realok = 1;
57825+ if (effective == curgid)
57826+ effectiveok = 1;
57827+ if (fs == curgid)
57828+ fsok = 1;
57829+ }
57830+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
57831+ for (i = 0; i < num; i++) {
57832+ curgid = (int)gidlist[i];
57833+ if (real == curgid)
57834+ break;
57835+ if (effective == curgid)
57836+ break;
57837+ if (fs == curgid)
57838+ break;
57839+ }
57840+ /* not in deny list */
57841+ if (i == num) {
57842+ realok = 1;
57843+ effectiveok = 1;
57844+ fsok = 1;
57845+ }
57846+ }
57847+
57848+ if (realok && effectiveok && fsok)
57849+ return 0;
57850+ else {
57851+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
57852+ return 1;
57853+ }
57854+}
57855+
57856+void
57857+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
57858+{
57859+ struct acl_role_label *role = task->role;
57860+ struct acl_subject_label *subj = NULL;
57861+ struct acl_object_label *obj;
57862+ struct file *filp;
57863+
57864+ if (unlikely(!(gr_status & GR_READY)))
57865+ return;
57866+
57867+ filp = task->exec_file;
57868+
57869+ /* kernel process, we'll give them the kernel role */
57870+ if (unlikely(!filp)) {
57871+ task->role = kernel_role;
57872+ task->acl = kernel_role->root_label;
57873+ return;
57874+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
57875+ role = lookup_acl_role_label(task, uid, gid);
57876+
57877+ /* perform subject lookup in possibly new role
57878+ we can use this result below in the case where role == task->role
57879+ */
57880+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
57881+
57882+ /* if we changed uid/gid, but result in the same role
57883+ and are using inheritance, don't lose the inherited subject
57884+ if current subject is other than what normal lookup
57885+ would result in, we arrived via inheritance, don't
57886+ lose subject
57887+ */
57888+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
57889+ (subj == task->acl)))
57890+ task->acl = subj;
57891+
57892+ task->role = role;
57893+
57894+ task->is_writable = 0;
57895+
57896+ /* ignore additional mmap checks for processes that are writable
57897+ by the default ACL */
57898+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57899+ if (unlikely(obj->mode & GR_WRITE))
57900+ task->is_writable = 1;
57901+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57902+ if (unlikely(obj->mode & GR_WRITE))
57903+ task->is_writable = 1;
57904+
57905+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57906+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57907+#endif
57908+
57909+ gr_set_proc_res(task);
57910+
57911+ return;
57912+}
57913+
57914+int
57915+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57916+ const int unsafe_share)
57917+{
57918+ struct task_struct *task = current;
57919+ struct acl_subject_label *newacl;
57920+ struct acl_object_label *obj;
57921+ __u32 retmode;
57922+
57923+ if (unlikely(!(gr_status & GR_READY)))
57924+ return 0;
57925+
57926+ newacl = chk_subj_label(dentry, mnt, task->role);
57927+
57928+ task_lock(task);
57929+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
57930+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57931+ !(task->role->roletype & GR_ROLE_GOD) &&
57932+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57933+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
57934+ task_unlock(task);
57935+ if (unsafe_share)
57936+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57937+ else
57938+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57939+ return -EACCES;
57940+ }
57941+ task_unlock(task);
57942+
57943+ obj = chk_obj_label(dentry, mnt, task->acl);
57944+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57945+
57946+ if (!(task->acl->mode & GR_INHERITLEARN) &&
57947+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57948+ if (obj->nested)
57949+ task->acl = obj->nested;
57950+ else
57951+ task->acl = newacl;
57952+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57953+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57954+
57955+ task->is_writable = 0;
57956+
57957+ /* ignore additional mmap checks for processes that are writable
57958+ by the default ACL */
57959+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
57960+ if (unlikely(obj->mode & GR_WRITE))
57961+ task->is_writable = 1;
57962+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
57963+ if (unlikely(obj->mode & GR_WRITE))
57964+ task->is_writable = 1;
57965+
57966+ gr_set_proc_res(task);
57967+
57968+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57969+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57970+#endif
57971+ return 0;
57972+}
57973+
57974+/* always called with valid inodev ptr */
57975+static void
57976+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57977+{
57978+ struct acl_object_label *matchpo;
57979+ struct acl_subject_label *matchps;
57980+ struct acl_subject_label *subj;
57981+ struct acl_role_label *role;
57982+ unsigned int x;
57983+
57984+ FOR_EACH_ROLE_START(role)
57985+ FOR_EACH_SUBJECT_START(role, subj, x)
57986+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57987+ matchpo->mode |= GR_DELETED;
57988+ FOR_EACH_SUBJECT_END(subj,x)
57989+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57990+ if (subj->inode == ino && subj->device == dev)
57991+ subj->mode |= GR_DELETED;
57992+ FOR_EACH_NESTED_SUBJECT_END(subj)
57993+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57994+ matchps->mode |= GR_DELETED;
57995+ FOR_EACH_ROLE_END(role)
57996+
57997+ inodev->nentry->deleted = 1;
57998+
57999+ return;
58000+}
58001+
58002+void
58003+gr_handle_delete(const ino_t ino, const dev_t dev)
58004+{
58005+ struct inodev_entry *inodev;
58006+
58007+ if (unlikely(!(gr_status & GR_READY)))
58008+ return;
58009+
58010+ write_lock(&gr_inode_lock);
58011+ inodev = lookup_inodev_entry(ino, dev);
58012+ if (inodev != NULL)
58013+ do_handle_delete(inodev, ino, dev);
58014+ write_unlock(&gr_inode_lock);
58015+
58016+ return;
58017+}
58018+
58019+static void
58020+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
58021+ const ino_t newinode, const dev_t newdevice,
58022+ struct acl_subject_label *subj)
58023+{
58024+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
58025+ struct acl_object_label *match;
58026+
58027+ match = subj->obj_hash[index];
58028+
58029+ while (match && (match->inode != oldinode ||
58030+ match->device != olddevice ||
58031+ !(match->mode & GR_DELETED)))
58032+ match = match->next;
58033+
58034+ if (match && (match->inode == oldinode)
58035+ && (match->device == olddevice)
58036+ && (match->mode & GR_DELETED)) {
58037+ if (match->prev == NULL) {
58038+ subj->obj_hash[index] = match->next;
58039+ if (match->next != NULL)
58040+ match->next->prev = NULL;
58041+ } else {
58042+ match->prev->next = match->next;
58043+ if (match->next != NULL)
58044+ match->next->prev = match->prev;
58045+ }
58046+ match->prev = NULL;
58047+ match->next = NULL;
58048+ match->inode = newinode;
58049+ match->device = newdevice;
58050+ match->mode &= ~GR_DELETED;
58051+
58052+ insert_acl_obj_label(match, subj);
58053+ }
58054+
58055+ return;
58056+}
58057+
58058+static void
58059+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
58060+ const ino_t newinode, const dev_t newdevice,
58061+ struct acl_role_label *role)
58062+{
58063+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
58064+ struct acl_subject_label *match;
58065+
58066+ match = role->subj_hash[index];
58067+
58068+ while (match && (match->inode != oldinode ||
58069+ match->device != olddevice ||
58070+ !(match->mode & GR_DELETED)))
58071+ match = match->next;
58072+
58073+ if (match && (match->inode == oldinode)
58074+ && (match->device == olddevice)
58075+ && (match->mode & GR_DELETED)) {
58076+ if (match->prev == NULL) {
58077+ role->subj_hash[index] = match->next;
58078+ if (match->next != NULL)
58079+ match->next->prev = NULL;
58080+ } else {
58081+ match->prev->next = match->next;
58082+ if (match->next != NULL)
58083+ match->next->prev = match->prev;
58084+ }
58085+ match->prev = NULL;
58086+ match->next = NULL;
58087+ match->inode = newinode;
58088+ match->device = newdevice;
58089+ match->mode &= ~GR_DELETED;
58090+
58091+ insert_acl_subj_label(match, role);
58092+ }
58093+
58094+ return;
58095+}
58096+
58097+static void
58098+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
58099+ const ino_t newinode, const dev_t newdevice)
58100+{
58101+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
58102+ struct inodev_entry *match;
58103+
58104+ match = inodev_set.i_hash[index];
58105+
58106+ while (match && (match->nentry->inode != oldinode ||
58107+ match->nentry->device != olddevice || !match->nentry->deleted))
58108+ match = match->next;
58109+
58110+ if (match && (match->nentry->inode == oldinode)
58111+ && (match->nentry->device == olddevice) &&
58112+ match->nentry->deleted) {
58113+ if (match->prev == NULL) {
58114+ inodev_set.i_hash[index] = match->next;
58115+ if (match->next != NULL)
58116+ match->next->prev = NULL;
58117+ } else {
58118+ match->prev->next = match->next;
58119+ if (match->next != NULL)
58120+ match->next->prev = match->prev;
58121+ }
58122+ match->prev = NULL;
58123+ match->next = NULL;
58124+ match->nentry->inode = newinode;
58125+ match->nentry->device = newdevice;
58126+ match->nentry->deleted = 0;
58127+
58128+ insert_inodev_entry(match);
58129+ }
58130+
58131+ return;
58132+}
58133+
58134+static void
58135+__do_handle_create(const struct name_entry *matchn, ino_t inode, dev_t dev)
58136+{
58137+ struct acl_subject_label *subj;
58138+ struct acl_role_label *role;
58139+ unsigned int x;
58140+
58141+ FOR_EACH_ROLE_START(role)
58142+ update_acl_subj_label(matchn->inode, matchn->device,
58143+ inode, dev, role);
58144+
58145+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
58146+ if ((subj->inode == inode) && (subj->device == dev)) {
58147+ subj->inode = inode;
58148+ subj->device = dev;
58149+ }
58150+ FOR_EACH_NESTED_SUBJECT_END(subj)
58151+ FOR_EACH_SUBJECT_START(role, subj, x)
58152+ update_acl_obj_label(matchn->inode, matchn->device,
58153+ inode, dev, subj);
58154+ FOR_EACH_SUBJECT_END(subj,x)
58155+ FOR_EACH_ROLE_END(role)
58156+
58157+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
58158+
58159+ return;
58160+}
58161+
58162+static void
58163+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
58164+ const struct vfsmount *mnt)
58165+{
58166+ ino_t ino = dentry->d_inode->i_ino;
58167+ dev_t dev = __get_dev(dentry);
58168+
58169+ __do_handle_create(matchn, ino, dev);
58170+
58171+ return;
58172+}
58173+
58174+void
58175+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58176+{
58177+ struct name_entry *matchn;
58178+
58179+ if (unlikely(!(gr_status & GR_READY)))
58180+ return;
58181+
58182+ preempt_disable();
58183+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
58184+
58185+ if (unlikely((unsigned long)matchn)) {
58186+ write_lock(&gr_inode_lock);
58187+ do_handle_create(matchn, dentry, mnt);
58188+ write_unlock(&gr_inode_lock);
58189+ }
58190+ preempt_enable();
58191+
58192+ return;
58193+}
58194+
58195+void
58196+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58197+{
58198+ struct name_entry *matchn;
58199+
58200+ if (unlikely(!(gr_status & GR_READY)))
58201+ return;
58202+
58203+ preempt_disable();
58204+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
58205+
58206+ if (unlikely((unsigned long)matchn)) {
58207+ write_lock(&gr_inode_lock);
58208+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
58209+ write_unlock(&gr_inode_lock);
58210+ }
58211+ preempt_enable();
58212+
58213+ return;
58214+}
58215+
58216+void
58217+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58218+ struct dentry *old_dentry,
58219+ struct dentry *new_dentry,
58220+ struct vfsmount *mnt, const __u8 replace)
58221+{
58222+ struct name_entry *matchn;
58223+ struct inodev_entry *inodev;
58224+ struct inode *inode = new_dentry->d_inode;
58225+ ino_t oldinode = old_dentry->d_inode->i_ino;
58226+ dev_t olddev = __get_dev(old_dentry);
58227+
58228+ /* vfs_rename swaps the name and parent link for old_dentry and
58229+ new_dentry
58230+ at this point, old_dentry has the new name, parent link, and inode
58231+ for the renamed file
58232+ if a file is being replaced by a rename, new_dentry has the inode
58233+ and name for the replaced file
58234+ */
58235+
58236+ if (unlikely(!(gr_status & GR_READY)))
58237+ return;
58238+
58239+ preempt_disable();
58240+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
58241+
58242+ /* we wouldn't have to check d_inode if it weren't for
58243+ NFS silly-renaming
58244+ */
58245+
58246+ write_lock(&gr_inode_lock);
58247+ if (unlikely(replace && inode)) {
58248+ ino_t newinode = inode->i_ino;
58249+ dev_t newdev = __get_dev(new_dentry);
58250+ inodev = lookup_inodev_entry(newinode, newdev);
58251+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
58252+ do_handle_delete(inodev, newinode, newdev);
58253+ }
58254+
58255+ inodev = lookup_inodev_entry(oldinode, olddev);
58256+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
58257+ do_handle_delete(inodev, oldinode, olddev);
58258+
58259+ if (unlikely((unsigned long)matchn))
58260+ do_handle_create(matchn, old_dentry, mnt);
58261+
58262+ write_unlock(&gr_inode_lock);
58263+ preempt_enable();
58264+
58265+ return;
58266+}
58267+
58268+static int
58269+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
58270+ unsigned char **sum)
58271+{
58272+ struct acl_role_label *r;
58273+ struct role_allowed_ip *ipp;
58274+ struct role_transition *trans;
58275+ unsigned int i;
58276+ int found = 0;
58277+ u32 curr_ip = current->signal->curr_ip;
58278+
58279+ current->signal->saved_ip = curr_ip;
58280+
58281+ /* check transition table */
58282+
58283+ for (trans = current->role->transitions; trans; trans = trans->next) {
58284+ if (!strcmp(rolename, trans->rolename)) {
58285+ found = 1;
58286+ break;
58287+ }
58288+ }
58289+
58290+ if (!found)
58291+ return 0;
58292+
58293+ /* handle special roles that do not require authentication
58294+ and check ip */
58295+
58296+ FOR_EACH_ROLE_START(r)
58297+ if (!strcmp(rolename, r->rolename) &&
58298+ (r->roletype & GR_ROLE_SPECIAL)) {
58299+ found = 0;
58300+ if (r->allowed_ips != NULL) {
58301+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
58302+ if ((ntohl(curr_ip) & ipp->netmask) ==
58303+ (ntohl(ipp->addr) & ipp->netmask))
58304+ found = 1;
58305+ }
58306+ } else
58307+ found = 2;
58308+ if (!found)
58309+ return 0;
58310+
58311+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
58312+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
58313+ *salt = NULL;
58314+ *sum = NULL;
58315+ return 1;
58316+ }
58317+ }
58318+ FOR_EACH_ROLE_END(r)
58319+
58320+ for (i = 0; i < num_sprole_pws; i++) {
58321+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
58322+ *salt = acl_special_roles[i]->salt;
58323+ *sum = acl_special_roles[i]->sum;
58324+ return 1;
58325+ }
58326+ }
58327+
58328+ return 0;
58329+}
58330+
58331+static void
58332+assign_special_role(char *rolename)
58333+{
58334+ struct acl_object_label *obj;
58335+ struct acl_role_label *r;
58336+ struct acl_role_label *assigned = NULL;
58337+ struct task_struct *tsk;
58338+ struct file *filp;
58339+
58340+ FOR_EACH_ROLE_START(r)
58341+ if (!strcmp(rolename, r->rolename) &&
58342+ (r->roletype & GR_ROLE_SPECIAL)) {
58343+ assigned = r;
58344+ break;
58345+ }
58346+ FOR_EACH_ROLE_END(r)
58347+
58348+ if (!assigned)
58349+ return;
58350+
58351+ read_lock(&tasklist_lock);
58352+ read_lock(&grsec_exec_file_lock);
58353+
58354+ tsk = current->real_parent;
58355+ if (tsk == NULL)
58356+ goto out_unlock;
58357+
58358+ filp = tsk->exec_file;
58359+ if (filp == NULL)
58360+ goto out_unlock;
58361+
58362+ tsk->is_writable = 0;
58363+
58364+ tsk->acl_sp_role = 1;
58365+ tsk->acl_role_id = ++acl_sp_role_value;
58366+ tsk->role = assigned;
58367+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
58368+
58369+ /* ignore additional mmap checks for processes that are writable
58370+ by the default ACL */
58371+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58372+ if (unlikely(obj->mode & GR_WRITE))
58373+ tsk->is_writable = 1;
58374+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
58375+ if (unlikely(obj->mode & GR_WRITE))
58376+ tsk->is_writable = 1;
58377+
58378+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58379+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
58380+#endif
58381+
58382+out_unlock:
58383+ read_unlock(&grsec_exec_file_lock);
58384+ read_unlock(&tasklist_lock);
58385+ return;
58386+}
58387+
58388+int gr_check_secure_terminal(struct task_struct *task)
58389+{
58390+ struct task_struct *p, *p2, *p3;
58391+ struct files_struct *files;
58392+ struct fdtable *fdt;
58393+ struct file *our_file = NULL, *file;
58394+ int i;
58395+
58396+ if (task->signal->tty == NULL)
58397+ return 1;
58398+
58399+ files = get_files_struct(task);
58400+ if (files != NULL) {
58401+ rcu_read_lock();
58402+ fdt = files_fdtable(files);
58403+ for (i=0; i < fdt->max_fds; i++) {
58404+ file = fcheck_files(files, i);
58405+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
58406+ get_file(file);
58407+ our_file = file;
58408+ }
58409+ }
58410+ rcu_read_unlock();
58411+ put_files_struct(files);
58412+ }
58413+
58414+ if (our_file == NULL)
58415+ return 1;
58416+
58417+ read_lock(&tasklist_lock);
58418+ do_each_thread(p2, p) {
58419+ files = get_files_struct(p);
58420+ if (files == NULL ||
58421+ (p->signal && p->signal->tty == task->signal->tty)) {
58422+ if (files != NULL)
58423+ put_files_struct(files);
58424+ continue;
58425+ }
58426+ rcu_read_lock();
58427+ fdt = files_fdtable(files);
58428+ for (i=0; i < fdt->max_fds; i++) {
58429+ file = fcheck_files(files, i);
58430+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
58431+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
58432+ p3 = task;
58433+ while (p3->pid > 0) {
58434+ if (p3 == p)
58435+ break;
58436+ p3 = p3->real_parent;
58437+ }
58438+ if (p3 == p)
58439+ break;
58440+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
58441+ gr_handle_alertkill(p);
58442+ rcu_read_unlock();
58443+ put_files_struct(files);
58444+ read_unlock(&tasklist_lock);
58445+ fput(our_file);
58446+ return 0;
58447+ }
58448+ }
58449+ rcu_read_unlock();
58450+ put_files_struct(files);
58451+ } while_each_thread(p2, p);
58452+ read_unlock(&tasklist_lock);
58453+
58454+ fput(our_file);
58455+ return 1;
58456+}
58457+
58458+ssize_t
58459+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
58460+{
58461+ struct gr_arg_wrapper uwrap;
58462+ unsigned char *sprole_salt = NULL;
58463+ unsigned char *sprole_sum = NULL;
58464+ int error = sizeof (struct gr_arg_wrapper);
58465+ int error2 = 0;
58466+
58467+ mutex_lock(&gr_dev_mutex);
58468+
58469+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
58470+ error = -EPERM;
58471+ goto out;
58472+ }
58473+
58474+ if (count != sizeof (struct gr_arg_wrapper)) {
58475+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
58476+ error = -EINVAL;
58477+ goto out;
58478+ }
58479+
58480+
58481+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
58482+ gr_auth_expires = 0;
58483+ gr_auth_attempts = 0;
58484+ }
58485+
58486+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
58487+ error = -EFAULT;
58488+ goto out;
58489+ }
58490+
58491+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
58492+ error = -EINVAL;
58493+ goto out;
58494+ }
58495+
58496+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
58497+ error = -EFAULT;
58498+ goto out;
58499+ }
58500+
58501+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58502+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58503+ time_after(gr_auth_expires, get_seconds())) {
58504+ error = -EBUSY;
58505+ goto out;
58506+ }
58507+
58508+ /* if non-root trying to do anything other than use a special role,
58509+ do not attempt authentication, do not count towards authentication
58510+ locking
58511+ */
58512+
58513+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
58514+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58515+ current_uid()) {
58516+ error = -EPERM;
58517+ goto out;
58518+ }
58519+
58520+ /* ensure pw and special role name are null terminated */
58521+
58522+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
58523+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
58524+
58525+ /* Okay.
58526+ * We have our enough of the argument structure..(we have yet
58527+ * to copy_from_user the tables themselves) . Copy the tables
58528+ * only if we need them, i.e. for loading operations. */
58529+
58530+ switch (gr_usermode->mode) {
58531+ case GR_STATUS:
58532+ if (gr_status & GR_READY) {
58533+ error = 1;
58534+ if (!gr_check_secure_terminal(current))
58535+ error = 3;
58536+ } else
58537+ error = 2;
58538+ goto out;
58539+ case GR_SHUTDOWN:
58540+ if ((gr_status & GR_READY)
58541+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58542+ pax_open_kernel();
58543+ gr_status &= ~GR_READY;
58544+ pax_close_kernel();
58545+
58546+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
58547+ free_variables();
58548+ memset(gr_usermode, 0, sizeof (struct gr_arg));
58549+ memset(gr_system_salt, 0, GR_SALT_LEN);
58550+ memset(gr_system_sum, 0, GR_SHA_LEN);
58551+ } else if (gr_status & GR_READY) {
58552+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
58553+ error = -EPERM;
58554+ } else {
58555+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
58556+ error = -EAGAIN;
58557+ }
58558+ break;
58559+ case GR_ENABLE:
58560+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
58561+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
58562+ else {
58563+ if (gr_status & GR_READY)
58564+ error = -EAGAIN;
58565+ else
58566+ error = error2;
58567+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
58568+ }
58569+ break;
58570+ case GR_RELOAD:
58571+ if (!(gr_status & GR_READY)) {
58572+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
58573+ error = -EAGAIN;
58574+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58575+ lock_kernel();
58576+
58577+ pax_open_kernel();
58578+ gr_status &= ~GR_READY;
58579+ pax_close_kernel();
58580+
58581+ free_variables();
58582+ if (!(error2 = gracl_init(gr_usermode))) {
58583+ unlock_kernel();
58584+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
58585+ } else {
58586+ unlock_kernel();
58587+ error = error2;
58588+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58589+ }
58590+ } else {
58591+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58592+ error = -EPERM;
58593+ }
58594+ break;
58595+ case GR_SEGVMOD:
58596+ if (unlikely(!(gr_status & GR_READY))) {
58597+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
58598+ error = -EAGAIN;
58599+ break;
58600+ }
58601+
58602+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58603+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
58604+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
58605+ struct acl_subject_label *segvacl;
58606+ segvacl =
58607+ lookup_acl_subj_label(gr_usermode->segv_inode,
58608+ gr_usermode->segv_device,
58609+ current->role);
58610+ if (segvacl) {
58611+ segvacl->crashes = 0;
58612+ segvacl->expires = 0;
58613+ }
58614+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
58615+ gr_remove_uid(gr_usermode->segv_uid);
58616+ }
58617+ } else {
58618+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
58619+ error = -EPERM;
58620+ }
58621+ break;
58622+ case GR_SPROLE:
58623+ case GR_SPROLEPAM:
58624+ if (unlikely(!(gr_status & GR_READY))) {
58625+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
58626+ error = -EAGAIN;
58627+ break;
58628+ }
58629+
58630+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
58631+ current->role->expires = 0;
58632+ current->role->auth_attempts = 0;
58633+ }
58634+
58635+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58636+ time_after(current->role->expires, get_seconds())) {
58637+ error = -EBUSY;
58638+ goto out;
58639+ }
58640+
58641+ if (lookup_special_role_auth
58642+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
58643+ && ((!sprole_salt && !sprole_sum)
58644+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
58645+ char *p = "";
58646+ assign_special_role(gr_usermode->sp_role);
58647+ read_lock(&tasklist_lock);
58648+ if (current->real_parent)
58649+ p = current->real_parent->role->rolename;
58650+ read_unlock(&tasklist_lock);
58651+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
58652+ p, acl_sp_role_value);
58653+ } else {
58654+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
58655+ error = -EPERM;
58656+ if(!(current->role->auth_attempts++))
58657+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58658+
58659+ goto out;
58660+ }
58661+ break;
58662+ case GR_UNSPROLE:
58663+ if (unlikely(!(gr_status & GR_READY))) {
58664+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
58665+ error = -EAGAIN;
58666+ break;
58667+ }
58668+
58669+ if (current->role->roletype & GR_ROLE_SPECIAL) {
58670+ char *p = "";
58671+ int i = 0;
58672+
58673+ read_lock(&tasklist_lock);
58674+ if (current->real_parent) {
58675+ p = current->real_parent->role->rolename;
58676+ i = current->real_parent->acl_role_id;
58677+ }
58678+ read_unlock(&tasklist_lock);
58679+
58680+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
58681+ gr_set_acls(1);
58682+ } else {
58683+ error = -EPERM;
58684+ goto out;
58685+ }
58686+ break;
58687+ default:
58688+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
58689+ error = -EINVAL;
58690+ break;
58691+ }
58692+
58693+ if (error != -EPERM)
58694+ goto out;
58695+
58696+ if(!(gr_auth_attempts++))
58697+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58698+
58699+ out:
58700+ mutex_unlock(&gr_dev_mutex);
58701+ return error;
58702+}
58703+
58704+/* must be called with
58705+ rcu_read_lock();
58706+ read_lock(&tasklist_lock);
58707+ read_lock(&grsec_exec_file_lock);
58708+*/
58709+int gr_apply_subject_to_task(struct task_struct *task)
58710+{
58711+ struct acl_object_label *obj;
58712+ char *tmpname;
58713+ struct acl_subject_label *tmpsubj;
58714+ struct file *filp;
58715+ struct name_entry *nmatch;
58716+
58717+ filp = task->exec_file;
58718+ if (filp == NULL)
58719+ return 0;
58720+
58721+ /* the following is to apply the correct subject
58722+ on binaries running when the RBAC system
58723+ is enabled, when the binaries have been
58724+ replaced or deleted since their execution
58725+ -----
58726+ when the RBAC system starts, the inode/dev
58727+ from exec_file will be one the RBAC system
58728+ is unaware of. It only knows the inode/dev
58729+ of the present file on disk, or the absence
58730+ of it.
58731+ */
58732+ preempt_disable();
58733+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
58734+
58735+ nmatch = lookup_name_entry(tmpname);
58736+ preempt_enable();
58737+ tmpsubj = NULL;
58738+ if (nmatch) {
58739+ if (nmatch->deleted)
58740+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
58741+ else
58742+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
58743+ if (tmpsubj != NULL)
58744+ task->acl = tmpsubj;
58745+ }
58746+ if (tmpsubj == NULL)
58747+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
58748+ task->role);
58749+ if (task->acl) {
58750+ task->is_writable = 0;
58751+ /* ignore additional mmap checks for processes that are writable
58752+ by the default ACL */
58753+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58754+ if (unlikely(obj->mode & GR_WRITE))
58755+ task->is_writable = 1;
58756+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
58757+ if (unlikely(obj->mode & GR_WRITE))
58758+ task->is_writable = 1;
58759+
58760+ gr_set_proc_res(task);
58761+
58762+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58763+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58764+#endif
58765+ } else {
58766+ return 1;
58767+ }
58768+
58769+ return 0;
58770+}
58771+
58772+int
58773+gr_set_acls(const int type)
58774+{
58775+ struct task_struct *task, *task2;
58776+ struct acl_role_label *role = current->role;
58777+ __u16 acl_role_id = current->acl_role_id;
58778+ const struct cred *cred;
58779+ int ret;
58780+
58781+ rcu_read_lock();
58782+ read_lock(&tasklist_lock);
58783+ read_lock(&grsec_exec_file_lock);
58784+ do_each_thread(task2, task) {
58785+ /* check to see if we're called from the exit handler,
58786+ if so, only replace ACLs that have inherited the admin
58787+ ACL */
58788+
58789+ if (type && (task->role != role ||
58790+ task->acl_role_id != acl_role_id))
58791+ continue;
58792+
58793+ task->acl_role_id = 0;
58794+ task->acl_sp_role = 0;
58795+
58796+ if (task->exec_file) {
58797+ cred = __task_cred(task);
58798+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
58799+
58800+ ret = gr_apply_subject_to_task(task);
58801+ if (ret) {
58802+ read_unlock(&grsec_exec_file_lock);
58803+ read_unlock(&tasklist_lock);
58804+ rcu_read_unlock();
58805+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
58806+ return ret;
58807+ }
58808+ } else {
58809+ // it's a kernel process
58810+ task->role = kernel_role;
58811+ task->acl = kernel_role->root_label;
58812+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
58813+ task->acl->mode &= ~GR_PROCFIND;
58814+#endif
58815+ }
58816+ } while_each_thread(task2, task);
58817+ read_unlock(&grsec_exec_file_lock);
58818+ read_unlock(&tasklist_lock);
58819+ rcu_read_unlock();
58820+
58821+ return 0;
58822+}
58823+
58824+void
58825+gr_learn_resource(const struct task_struct *task,
58826+ const int res, const unsigned long wanted, const int gt)
58827+{
58828+ struct acl_subject_label *acl;
58829+ const struct cred *cred;
58830+
58831+ if (unlikely((gr_status & GR_READY) &&
58832+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
58833+ goto skip_reslog;
58834+
58835+#ifdef CONFIG_GRKERNSEC_RESLOG
58836+ gr_log_resource(task, res, wanted, gt);
58837+#endif
58838+ skip_reslog:
58839+
58840+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
58841+ return;
58842+
58843+ acl = task->acl;
58844+
58845+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
58846+ !(acl->resmask & (1 << (unsigned short) res))))
58847+ return;
58848+
58849+ if (wanted >= acl->res[res].rlim_cur) {
58850+ unsigned long res_add;
58851+
58852+ res_add = wanted;
58853+ switch (res) {
58854+ case RLIMIT_CPU:
58855+ res_add += GR_RLIM_CPU_BUMP;
58856+ break;
58857+ case RLIMIT_FSIZE:
58858+ res_add += GR_RLIM_FSIZE_BUMP;
58859+ break;
58860+ case RLIMIT_DATA:
58861+ res_add += GR_RLIM_DATA_BUMP;
58862+ break;
58863+ case RLIMIT_STACK:
58864+ res_add += GR_RLIM_STACK_BUMP;
58865+ break;
58866+ case RLIMIT_CORE:
58867+ res_add += GR_RLIM_CORE_BUMP;
58868+ break;
58869+ case RLIMIT_RSS:
58870+ res_add += GR_RLIM_RSS_BUMP;
58871+ break;
58872+ case RLIMIT_NPROC:
58873+ res_add += GR_RLIM_NPROC_BUMP;
58874+ break;
58875+ case RLIMIT_NOFILE:
58876+ res_add += GR_RLIM_NOFILE_BUMP;
58877+ break;
58878+ case RLIMIT_MEMLOCK:
58879+ res_add += GR_RLIM_MEMLOCK_BUMP;
58880+ break;
58881+ case RLIMIT_AS:
58882+ res_add += GR_RLIM_AS_BUMP;
58883+ break;
58884+ case RLIMIT_LOCKS:
58885+ res_add += GR_RLIM_LOCKS_BUMP;
58886+ break;
58887+ case RLIMIT_SIGPENDING:
58888+ res_add += GR_RLIM_SIGPENDING_BUMP;
58889+ break;
58890+ case RLIMIT_MSGQUEUE:
58891+ res_add += GR_RLIM_MSGQUEUE_BUMP;
58892+ break;
58893+ case RLIMIT_NICE:
58894+ res_add += GR_RLIM_NICE_BUMP;
58895+ break;
58896+ case RLIMIT_RTPRIO:
58897+ res_add += GR_RLIM_RTPRIO_BUMP;
58898+ break;
58899+ case RLIMIT_RTTIME:
58900+ res_add += GR_RLIM_RTTIME_BUMP;
58901+ break;
58902+ }
58903+
58904+ acl->res[res].rlim_cur = res_add;
58905+
58906+ if (wanted > acl->res[res].rlim_max)
58907+ acl->res[res].rlim_max = res_add;
58908+
58909+ /* only log the subject filename, since resource logging is supported for
58910+ single-subject learning only */
58911+ rcu_read_lock();
58912+ cred = __task_cred(task);
58913+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58914+ task->role->roletype, cred->uid, cred->gid, acl->filename,
58915+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
58916+ "", (unsigned long) res, &task->signal->saved_ip);
58917+ rcu_read_unlock();
58918+ }
58919+
58920+ return;
58921+}
58922+
58923+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
58924+void
58925+pax_set_initial_flags(struct linux_binprm *bprm)
58926+{
58927+ struct task_struct *task = current;
58928+ struct acl_subject_label *proc;
58929+ unsigned long flags;
58930+
58931+ if (unlikely(!(gr_status & GR_READY)))
58932+ return;
58933+
58934+ flags = pax_get_flags(task);
58935+
58936+ proc = task->acl;
58937+
58938+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58939+ flags &= ~MF_PAX_PAGEEXEC;
58940+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58941+ flags &= ~MF_PAX_SEGMEXEC;
58942+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58943+ flags &= ~MF_PAX_RANDMMAP;
58944+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58945+ flags &= ~MF_PAX_EMUTRAMP;
58946+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58947+ flags &= ~MF_PAX_MPROTECT;
58948+
58949+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58950+ flags |= MF_PAX_PAGEEXEC;
58951+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58952+ flags |= MF_PAX_SEGMEXEC;
58953+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58954+ flags |= MF_PAX_RANDMMAP;
58955+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58956+ flags |= MF_PAX_EMUTRAMP;
58957+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58958+ flags |= MF_PAX_MPROTECT;
58959+
58960+ pax_set_flags(task, flags);
58961+
58962+ return;
58963+}
58964+#endif
58965+
58966+#ifdef CONFIG_SYSCTL
58967+/* Eric Biederman likes breaking userland ABI and every inode-based security
58968+ system to save 35kb of memory */
58969+
58970+/* we modify the passed in filename, but adjust it back before returning */
58971+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
58972+{
58973+ struct name_entry *nmatch;
58974+ char *p, *lastp = NULL;
58975+ struct acl_object_label *obj = NULL, *tmp;
58976+ struct acl_subject_label *tmpsubj;
58977+ char c = '\0';
58978+
58979+ read_lock(&gr_inode_lock);
58980+
58981+ p = name + len - 1;
58982+ do {
58983+ nmatch = lookup_name_entry(name);
58984+ if (lastp != NULL)
58985+ *lastp = c;
58986+
58987+ if (nmatch == NULL)
58988+ goto next_component;
58989+ tmpsubj = current->acl;
58990+ do {
58991+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
58992+ if (obj != NULL) {
58993+ tmp = obj->globbed;
58994+ while (tmp) {
58995+ if (!glob_match(tmp->filename, name)) {
58996+ obj = tmp;
58997+ goto found_obj;
58998+ }
58999+ tmp = tmp->next;
59000+ }
59001+ goto found_obj;
59002+ }
59003+ } while ((tmpsubj = tmpsubj->parent_subject));
59004+next_component:
59005+ /* end case */
59006+ if (p == name)
59007+ break;
59008+
59009+ while (*p != '/')
59010+ p--;
59011+ if (p == name)
59012+ lastp = p + 1;
59013+ else {
59014+ lastp = p;
59015+ p--;
59016+ }
59017+ c = *lastp;
59018+ *lastp = '\0';
59019+ } while (1);
59020+found_obj:
59021+ read_unlock(&gr_inode_lock);
59022+ /* obj returned will always be non-null */
59023+ return obj;
59024+}
59025+
59026+/* returns 0 when allowing, non-zero on error
59027+ op of 0 is used for readdir, so we don't log the names of hidden files
59028+*/
59029+__u32
59030+gr_handle_sysctl(const struct ctl_table *table, const int op)
59031+{
59032+ ctl_table *tmp;
59033+ const char *proc_sys = "/proc/sys";
59034+ char *path;
59035+ struct acl_object_label *obj;
59036+ unsigned short len = 0, pos = 0, depth = 0, i;
59037+ __u32 err = 0;
59038+ __u32 mode = 0;
59039+
59040+ if (unlikely(!(gr_status & GR_READY)))
59041+ return 0;
59042+
59043+ /* for now, ignore operations on non-sysctl entries if it's not a
59044+ readdir*/
59045+ if (table->child != NULL && op != 0)
59046+ return 0;
59047+
59048+ mode |= GR_FIND;
59049+ /* it's only a read if it's an entry, read on dirs is for readdir */
59050+ if (op & MAY_READ)
59051+ mode |= GR_READ;
59052+ if (op & MAY_WRITE)
59053+ mode |= GR_WRITE;
59054+
59055+ preempt_disable();
59056+
59057+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
59058+
59059+ /* it's only a read/write if it's an actual entry, not a dir
59060+ (which are opened for readdir)
59061+ */
59062+
59063+ /* convert the requested sysctl entry into a pathname */
59064+
59065+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59066+ len += strlen(tmp->procname);
59067+ len++;
59068+ depth++;
59069+ }
59070+
59071+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
59072+ /* deny */
59073+ goto out;
59074+ }
59075+
59076+ memset(path, 0, PAGE_SIZE);
59077+
59078+ memcpy(path, proc_sys, strlen(proc_sys));
59079+
59080+ pos += strlen(proc_sys);
59081+
59082+ for (; depth > 0; depth--) {
59083+ path[pos] = '/';
59084+ pos++;
59085+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59086+ if (depth == i) {
59087+ memcpy(path + pos, tmp->procname,
59088+ strlen(tmp->procname));
59089+ pos += strlen(tmp->procname);
59090+ }
59091+ i++;
59092+ }
59093+ }
59094+
59095+ obj = gr_lookup_by_name(path, pos);
59096+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
59097+
59098+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
59099+ ((err & mode) != mode))) {
59100+ __u32 new_mode = mode;
59101+
59102+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59103+
59104+ err = 0;
59105+ gr_log_learn_sysctl(path, new_mode);
59106+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
59107+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
59108+ err = -ENOENT;
59109+ } else if (!(err & GR_FIND)) {
59110+ err = -ENOENT;
59111+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
59112+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
59113+ path, (mode & GR_READ) ? " reading" : "",
59114+ (mode & GR_WRITE) ? " writing" : "");
59115+ err = -EACCES;
59116+ } else if ((err & mode) != mode) {
59117+ err = -EACCES;
59118+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
59119+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
59120+ path, (mode & GR_READ) ? " reading" : "",
59121+ (mode & GR_WRITE) ? " writing" : "");
59122+ err = 0;
59123+ } else
59124+ err = 0;
59125+
59126+ out:
59127+ preempt_enable();
59128+
59129+ return err;
59130+}
59131+#endif
59132+
59133+int
59134+gr_handle_proc_ptrace(struct task_struct *task)
59135+{
59136+ struct file *filp;
59137+ struct task_struct *tmp = task;
59138+ struct task_struct *curtemp = current;
59139+ __u32 retmode;
59140+
59141+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59142+ if (unlikely(!(gr_status & GR_READY)))
59143+ return 0;
59144+#endif
59145+
59146+ read_lock(&tasklist_lock);
59147+ read_lock(&grsec_exec_file_lock);
59148+ filp = task->exec_file;
59149+
59150+ while (tmp->pid > 0) {
59151+ if (tmp == curtemp)
59152+ break;
59153+ tmp = tmp->real_parent;
59154+ }
59155+
59156+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59157+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
59158+ read_unlock(&grsec_exec_file_lock);
59159+ read_unlock(&tasklist_lock);
59160+ return 1;
59161+ }
59162+
59163+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59164+ if (!(gr_status & GR_READY)) {
59165+ read_unlock(&grsec_exec_file_lock);
59166+ read_unlock(&tasklist_lock);
59167+ return 0;
59168+ }
59169+#endif
59170+
59171+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
59172+ read_unlock(&grsec_exec_file_lock);
59173+ read_unlock(&tasklist_lock);
59174+
59175+ if (retmode & GR_NOPTRACE)
59176+ return 1;
59177+
59178+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
59179+ && (current->acl != task->acl || (current->acl != current->role->root_label
59180+ && current->pid != task->pid)))
59181+ return 1;
59182+
59183+ return 0;
59184+}
59185+
59186+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
59187+{
59188+ if (unlikely(!(gr_status & GR_READY)))
59189+ return;
59190+
59191+ if (!(current->role->roletype & GR_ROLE_GOD))
59192+ return;
59193+
59194+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
59195+ p->role->rolename, gr_task_roletype_to_char(p),
59196+ p->acl->filename);
59197+}
59198+
59199+int
59200+gr_handle_ptrace(struct task_struct *task, const long request)
59201+{
59202+ struct task_struct *tmp = task;
59203+ struct task_struct *curtemp = current;
59204+ __u32 retmode;
59205+
59206+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59207+ if (unlikely(!(gr_status & GR_READY)))
59208+ return 0;
59209+#endif
59210+
59211+ read_lock(&tasklist_lock);
59212+ while (tmp->pid > 0) {
59213+ if (tmp == curtemp)
59214+ break;
59215+ tmp = tmp->real_parent;
59216+ }
59217+
59218+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59219+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
59220+ read_unlock(&tasklist_lock);
59221+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59222+ return 1;
59223+ }
59224+ read_unlock(&tasklist_lock);
59225+
59226+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59227+ if (!(gr_status & GR_READY))
59228+ return 0;
59229+#endif
59230+
59231+ read_lock(&grsec_exec_file_lock);
59232+ if (unlikely(!task->exec_file)) {
59233+ read_unlock(&grsec_exec_file_lock);
59234+ return 0;
59235+ }
59236+
59237+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
59238+ read_unlock(&grsec_exec_file_lock);
59239+
59240+ if (retmode & GR_NOPTRACE) {
59241+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59242+ return 1;
59243+ }
59244+
59245+ if (retmode & GR_PTRACERD) {
59246+ switch (request) {
59247+ case PTRACE_POKETEXT:
59248+ case PTRACE_POKEDATA:
59249+ case PTRACE_POKEUSR:
59250+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
59251+ case PTRACE_SETREGS:
59252+ case PTRACE_SETFPREGS:
59253+#endif
59254+#ifdef CONFIG_X86
59255+ case PTRACE_SETFPXREGS:
59256+#endif
59257+#ifdef CONFIG_ALTIVEC
59258+ case PTRACE_SETVRREGS:
59259+#endif
59260+ return 1;
59261+ default:
59262+ return 0;
59263+ }
59264+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
59265+ !(current->role->roletype & GR_ROLE_GOD) &&
59266+ (current->acl != task->acl)) {
59267+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59268+ return 1;
59269+ }
59270+
59271+ return 0;
59272+}
59273+
59274+static int is_writable_mmap(const struct file *filp)
59275+{
59276+ struct task_struct *task = current;
59277+ struct acl_object_label *obj, *obj2;
59278+
59279+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
59280+ !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))) {
59281+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59282+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
59283+ task->role->root_label);
59284+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
59285+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
59286+ return 1;
59287+ }
59288+ }
59289+ return 0;
59290+}
59291+
59292+int
59293+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
59294+{
59295+ __u32 mode;
59296+
59297+ if (unlikely(!file || !(prot & PROT_EXEC)))
59298+ return 1;
59299+
59300+ if (is_writable_mmap(file))
59301+ return 0;
59302+
59303+ mode =
59304+ gr_search_file(file->f_path.dentry,
59305+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59306+ file->f_path.mnt);
59307+
59308+ if (!gr_tpe_allow(file))
59309+ return 0;
59310+
59311+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59312+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59313+ return 0;
59314+ } else if (unlikely(!(mode & GR_EXEC))) {
59315+ return 0;
59316+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59317+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59318+ return 1;
59319+ }
59320+
59321+ return 1;
59322+}
59323+
59324+int
59325+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59326+{
59327+ __u32 mode;
59328+
59329+ if (unlikely(!file || !(prot & PROT_EXEC)))
59330+ return 1;
59331+
59332+ if (is_writable_mmap(file))
59333+ return 0;
59334+
59335+ mode =
59336+ gr_search_file(file->f_path.dentry,
59337+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59338+ file->f_path.mnt);
59339+
59340+ if (!gr_tpe_allow(file))
59341+ return 0;
59342+
59343+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59344+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59345+ return 0;
59346+ } else if (unlikely(!(mode & GR_EXEC))) {
59347+ return 0;
59348+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59349+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59350+ return 1;
59351+ }
59352+
59353+ return 1;
59354+}
59355+
59356+void
59357+gr_acl_handle_psacct(struct task_struct *task, const long code)
59358+{
59359+ unsigned long runtime;
59360+ unsigned long cputime;
59361+ unsigned int wday, cday;
59362+ __u8 whr, chr;
59363+ __u8 wmin, cmin;
59364+ __u8 wsec, csec;
59365+ struct timespec timeval;
59366+
59367+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
59368+ !(task->acl->mode & GR_PROCACCT)))
59369+ return;
59370+
59371+ do_posix_clock_monotonic_gettime(&timeval);
59372+ runtime = timeval.tv_sec - task->start_time.tv_sec;
59373+ wday = runtime / (3600 * 24);
59374+ runtime -= wday * (3600 * 24);
59375+ whr = runtime / 3600;
59376+ runtime -= whr * 3600;
59377+ wmin = runtime / 60;
59378+ runtime -= wmin * 60;
59379+ wsec = runtime;
59380+
59381+ cputime = (task->utime + task->stime) / HZ;
59382+ cday = cputime / (3600 * 24);
59383+ cputime -= cday * (3600 * 24);
59384+ chr = cputime / 3600;
59385+ cputime -= chr * 3600;
59386+ cmin = cputime / 60;
59387+ cputime -= cmin * 60;
59388+ csec = cputime;
59389+
59390+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
59391+
59392+ return;
59393+}
59394+
59395+void gr_set_kernel_label(struct task_struct *task)
59396+{
59397+ if (gr_status & GR_READY) {
59398+ task->role = kernel_role;
59399+ task->acl = kernel_role->root_label;
59400+ }
59401+ return;
59402+}
59403+
59404+#ifdef CONFIG_TASKSTATS
59405+int gr_is_taskstats_denied(int pid)
59406+{
59407+ struct task_struct *task;
59408+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59409+ const struct cred *cred;
59410+#endif
59411+ int ret = 0;
59412+
59413+ /* restrict taskstats viewing to un-chrooted root users
59414+ who have the 'view' subject flag if the RBAC system is enabled
59415+ */
59416+
59417+ rcu_read_lock();
59418+ read_lock(&tasklist_lock);
59419+ task = find_task_by_vpid(pid);
59420+ if (task) {
59421+#ifdef CONFIG_GRKERNSEC_CHROOT
59422+ if (proc_is_chrooted(task))
59423+ ret = -EACCES;
59424+#endif
59425+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59426+ cred = __task_cred(task);
59427+#ifdef CONFIG_GRKERNSEC_PROC_USER
59428+ if (cred->uid != 0)
59429+ ret = -EACCES;
59430+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59431+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
59432+ ret = -EACCES;
59433+#endif
59434+#endif
59435+ if (gr_status & GR_READY) {
59436+ if (!(task->acl->mode & GR_VIEW))
59437+ ret = -EACCES;
59438+ }
59439+ } else
59440+ ret = -ENOENT;
59441+
59442+ read_unlock(&tasklist_lock);
59443+ rcu_read_unlock();
59444+
59445+ return ret;
59446+}
59447+#endif
59448+
59449+/* AUXV entries are filled via a descendant of search_binary_handler
59450+ after we've already applied the subject for the target
59451+*/
59452+int gr_acl_enable_at_secure(void)
59453+{
59454+ if (unlikely(!(gr_status & GR_READY)))
59455+ return 0;
59456+
59457+ if (current->acl->mode & GR_ATSECURE)
59458+ return 1;
59459+
59460+ return 0;
59461+}
59462+
59463+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
59464+{
59465+ struct task_struct *task = current;
59466+ struct dentry *dentry = file->f_path.dentry;
59467+ struct vfsmount *mnt = file->f_path.mnt;
59468+ struct acl_object_label *obj, *tmp;
59469+ struct acl_subject_label *subj;
59470+ unsigned int bufsize;
59471+ int is_not_root;
59472+ char *path;
59473+ dev_t dev = __get_dev(dentry);
59474+
59475+ if (unlikely(!(gr_status & GR_READY)))
59476+ return 1;
59477+
59478+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59479+ return 1;
59480+
59481+ /* ignore Eric Biederman */
59482+ if (IS_PRIVATE(dentry->d_inode))
59483+ return 1;
59484+
59485+ subj = task->acl;
59486+ do {
59487+ obj = lookup_acl_obj_label(ino, dev, subj);
59488+ if (obj != NULL)
59489+ return (obj->mode & GR_FIND) ? 1 : 0;
59490+ } while ((subj = subj->parent_subject));
59491+
59492+ /* this is purely an optimization since we're looking for an object
59493+ for the directory we're doing a readdir on
59494+ if it's possible for any globbed object to match the entry we're
59495+ filling into the directory, then the object we find here will be
59496+ an anchor point with attached globbed objects
59497+ */
59498+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
59499+ if (obj->globbed == NULL)
59500+ return (obj->mode & GR_FIND) ? 1 : 0;
59501+
59502+ is_not_root = ((obj->filename[0] == '/') &&
59503+ (obj->filename[1] == '\0')) ? 0 : 1;
59504+ bufsize = PAGE_SIZE - namelen - is_not_root;
59505+
59506+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
59507+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
59508+ return 1;
59509+
59510+ preempt_disable();
59511+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
59512+ bufsize);
59513+
59514+ bufsize = strlen(path);
59515+
59516+ /* if base is "/", don't append an additional slash */
59517+ if (is_not_root)
59518+ *(path + bufsize) = '/';
59519+ memcpy(path + bufsize + is_not_root, name, namelen);
59520+ *(path + bufsize + namelen + is_not_root) = '\0';
59521+
59522+ tmp = obj->globbed;
59523+ while (tmp) {
59524+ if (!glob_match(tmp->filename, path)) {
59525+ preempt_enable();
59526+ return (tmp->mode & GR_FIND) ? 1 : 0;
59527+ }
59528+ tmp = tmp->next;
59529+ }
59530+ preempt_enable();
59531+ return (obj->mode & GR_FIND) ? 1 : 0;
59532+}
59533+
59534+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
59535+EXPORT_SYMBOL(gr_acl_is_enabled);
59536+#endif
59537+EXPORT_SYMBOL(gr_learn_resource);
59538+EXPORT_SYMBOL(gr_set_kernel_label);
59539+#ifdef CONFIG_SECURITY
59540+EXPORT_SYMBOL(gr_check_user_change);
59541+EXPORT_SYMBOL(gr_check_group_change);
59542+#endif
59543+
59544diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
59545new file mode 100644
59546index 0000000..34fefda
59547--- /dev/null
59548+++ b/grsecurity/gracl_alloc.c
59549@@ -0,0 +1,105 @@
59550+#include <linux/kernel.h>
59551+#include <linux/mm.h>
59552+#include <linux/slab.h>
59553+#include <linux/vmalloc.h>
59554+#include <linux/gracl.h>
59555+#include <linux/grsecurity.h>
59556+
59557+static unsigned long alloc_stack_next = 1;
59558+static unsigned long alloc_stack_size = 1;
59559+static void **alloc_stack;
59560+
59561+static __inline__ int
59562+alloc_pop(void)
59563+{
59564+ if (alloc_stack_next == 1)
59565+ return 0;
59566+
59567+ kfree(alloc_stack[alloc_stack_next - 2]);
59568+
59569+ alloc_stack_next--;
59570+
59571+ return 1;
59572+}
59573+
59574+static __inline__ int
59575+alloc_push(void *buf)
59576+{
59577+ if (alloc_stack_next >= alloc_stack_size)
59578+ return 1;
59579+
59580+ alloc_stack[alloc_stack_next - 1] = buf;
59581+
59582+ alloc_stack_next++;
59583+
59584+ return 0;
59585+}
59586+
59587+void *
59588+acl_alloc(unsigned long len)
59589+{
59590+ void *ret = NULL;
59591+
59592+ if (!len || len > PAGE_SIZE)
59593+ goto out;
59594+
59595+ ret = kmalloc(len, GFP_KERNEL);
59596+
59597+ if (ret) {
59598+ if (alloc_push(ret)) {
59599+ kfree(ret);
59600+ ret = NULL;
59601+ }
59602+ }
59603+
59604+out:
59605+ return ret;
59606+}
59607+
59608+void *
59609+acl_alloc_num(unsigned long num, unsigned long len)
59610+{
59611+ if (!len || (num > (PAGE_SIZE / len)))
59612+ return NULL;
59613+
59614+ return acl_alloc(num * len);
59615+}
59616+
59617+void
59618+acl_free_all(void)
59619+{
59620+ if (gr_acl_is_enabled() || !alloc_stack)
59621+ return;
59622+
59623+ while (alloc_pop()) ;
59624+
59625+ if (alloc_stack) {
59626+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
59627+ kfree(alloc_stack);
59628+ else
59629+ vfree(alloc_stack);
59630+ }
59631+
59632+ alloc_stack = NULL;
59633+ alloc_stack_size = 1;
59634+ alloc_stack_next = 1;
59635+
59636+ return;
59637+}
59638+
59639+int
59640+acl_alloc_stack_init(unsigned long size)
59641+{
59642+ if ((size * sizeof (void *)) <= PAGE_SIZE)
59643+ alloc_stack =
59644+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
59645+ else
59646+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
59647+
59648+ alloc_stack_size = size;
59649+
59650+ if (!alloc_stack)
59651+ return 0;
59652+ else
59653+ return 1;
59654+}
59655diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
59656new file mode 100644
59657index 0000000..955ddfb
59658--- /dev/null
59659+++ b/grsecurity/gracl_cap.c
59660@@ -0,0 +1,101 @@
59661+#include <linux/kernel.h>
59662+#include <linux/module.h>
59663+#include <linux/sched.h>
59664+#include <linux/gracl.h>
59665+#include <linux/grsecurity.h>
59666+#include <linux/grinternal.h>
59667+
59668+extern const char *captab_log[];
59669+extern int captab_log_entries;
59670+
59671+int
59672+gr_acl_is_capable(const int cap)
59673+{
59674+ struct task_struct *task = current;
59675+ const struct cred *cred = current_cred();
59676+ struct acl_subject_label *curracl;
59677+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59678+ kernel_cap_t cap_audit = __cap_empty_set;
59679+
59680+ if (!gr_acl_is_enabled())
59681+ return 1;
59682+
59683+ curracl = task->acl;
59684+
59685+ cap_drop = curracl->cap_lower;
59686+ cap_mask = curracl->cap_mask;
59687+ cap_audit = curracl->cap_invert_audit;
59688+
59689+ while ((curracl = curracl->parent_subject)) {
59690+ /* if the cap isn't specified in the current computed mask but is specified in the
59691+ current level subject, and is lowered in the current level subject, then add
59692+ it to the set of dropped capabilities
59693+ otherwise, add the current level subject's mask to the current computed mask
59694+ */
59695+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59696+ cap_raise(cap_mask, cap);
59697+ if (cap_raised(curracl->cap_lower, cap))
59698+ cap_raise(cap_drop, cap);
59699+ if (cap_raised(curracl->cap_invert_audit, cap))
59700+ cap_raise(cap_audit, cap);
59701+ }
59702+ }
59703+
59704+ if (!cap_raised(cap_drop, cap)) {
59705+ if (cap_raised(cap_audit, cap))
59706+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
59707+ return 1;
59708+ }
59709+
59710+ curracl = task->acl;
59711+
59712+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
59713+ && cap_raised(cred->cap_effective, cap)) {
59714+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
59715+ task->role->roletype, cred->uid,
59716+ cred->gid, task->exec_file ?
59717+ gr_to_filename(task->exec_file->f_path.dentry,
59718+ task->exec_file->f_path.mnt) : curracl->filename,
59719+ curracl->filename, 0UL,
59720+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
59721+ return 1;
59722+ }
59723+
59724+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
59725+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
59726+ return 0;
59727+}
59728+
59729+int
59730+gr_acl_is_capable_nolog(const int cap)
59731+{
59732+ struct acl_subject_label *curracl;
59733+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59734+
59735+ if (!gr_acl_is_enabled())
59736+ return 1;
59737+
59738+ curracl = current->acl;
59739+
59740+ cap_drop = curracl->cap_lower;
59741+ cap_mask = curracl->cap_mask;
59742+
59743+ while ((curracl = curracl->parent_subject)) {
59744+ /* if the cap isn't specified in the current computed mask but is specified in the
59745+ current level subject, and is lowered in the current level subject, then add
59746+ it to the set of dropped capabilities
59747+ otherwise, add the current level subject's mask to the current computed mask
59748+ */
59749+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59750+ cap_raise(cap_mask, cap);
59751+ if (cap_raised(curracl->cap_lower, cap))
59752+ cap_raise(cap_drop, cap);
59753+ }
59754+ }
59755+
59756+ if (!cap_raised(cap_drop, cap))
59757+ return 1;
59758+
59759+ return 0;
59760+}
59761+
59762diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
59763new file mode 100644
59764index 0000000..d5f210c
59765--- /dev/null
59766+++ b/grsecurity/gracl_fs.c
59767@@ -0,0 +1,433 @@
59768+#include <linux/kernel.h>
59769+#include <linux/sched.h>
59770+#include <linux/types.h>
59771+#include <linux/fs.h>
59772+#include <linux/file.h>
59773+#include <linux/stat.h>
59774+#include <linux/grsecurity.h>
59775+#include <linux/grinternal.h>
59776+#include <linux/gracl.h>
59777+
59778+__u32
59779+gr_acl_handle_hidden_file(const struct dentry * dentry,
59780+ const struct vfsmount * mnt)
59781+{
59782+ __u32 mode;
59783+
59784+ if (unlikely(!dentry->d_inode))
59785+ return GR_FIND;
59786+
59787+ mode =
59788+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
59789+
59790+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
59791+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
59792+ return mode;
59793+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
59794+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
59795+ return 0;
59796+ } else if (unlikely(!(mode & GR_FIND)))
59797+ return 0;
59798+
59799+ return GR_FIND;
59800+}
59801+
59802+__u32
59803+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59804+ int acc_mode)
59805+{
59806+ __u32 reqmode = GR_FIND;
59807+ __u32 mode;
59808+
59809+ if (unlikely(!dentry->d_inode))
59810+ return reqmode;
59811+
59812+ if (acc_mode & MAY_APPEND)
59813+ reqmode |= GR_APPEND;
59814+ else if (acc_mode & MAY_WRITE)
59815+ reqmode |= GR_WRITE;
59816+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
59817+ reqmode |= GR_READ;
59818+
59819+ mode =
59820+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
59821+ mnt);
59822+
59823+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59824+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
59825+ reqmode & GR_READ ? " reading" : "",
59826+ reqmode & GR_WRITE ? " writing" : reqmode &
59827+ GR_APPEND ? " appending" : "");
59828+ return reqmode;
59829+ } else
59830+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59831+ {
59832+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
59833+ reqmode & GR_READ ? " reading" : "",
59834+ reqmode & GR_WRITE ? " writing" : reqmode &
59835+ GR_APPEND ? " appending" : "");
59836+ return 0;
59837+ } else if (unlikely((mode & reqmode) != reqmode))
59838+ return 0;
59839+
59840+ return reqmode;
59841+}
59842+
59843+__u32
59844+gr_acl_handle_creat(const struct dentry * dentry,
59845+ const struct dentry * p_dentry,
59846+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59847+ const int imode)
59848+{
59849+ __u32 reqmode = GR_WRITE | GR_CREATE;
59850+ __u32 mode;
59851+
59852+ if (acc_mode & MAY_APPEND)
59853+ reqmode |= GR_APPEND;
59854+ // if a directory was required or the directory already exists, then
59855+ // don't count this open as a read
59856+ if ((acc_mode & MAY_READ) &&
59857+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
59858+ reqmode |= GR_READ;
59859+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
59860+ reqmode |= GR_SETID;
59861+
59862+ mode =
59863+ gr_check_create(dentry, p_dentry, p_mnt,
59864+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59865+
59866+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59867+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
59868+ reqmode & GR_READ ? " reading" : "",
59869+ reqmode & GR_WRITE ? " writing" : reqmode &
59870+ GR_APPEND ? " appending" : "");
59871+ return reqmode;
59872+ } else
59873+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59874+ {
59875+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
59876+ reqmode & GR_READ ? " reading" : "",
59877+ reqmode & GR_WRITE ? " writing" : reqmode &
59878+ GR_APPEND ? " appending" : "");
59879+ return 0;
59880+ } else if (unlikely((mode & reqmode) != reqmode))
59881+ return 0;
59882+
59883+ return reqmode;
59884+}
59885+
59886+__u32
59887+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
59888+ const int fmode)
59889+{
59890+ __u32 mode, reqmode = GR_FIND;
59891+
59892+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
59893+ reqmode |= GR_EXEC;
59894+ if (fmode & S_IWOTH)
59895+ reqmode |= GR_WRITE;
59896+ if (fmode & S_IROTH)
59897+ reqmode |= GR_READ;
59898+
59899+ mode =
59900+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
59901+ mnt);
59902+
59903+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59904+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
59905+ reqmode & GR_READ ? " reading" : "",
59906+ reqmode & GR_WRITE ? " writing" : "",
59907+ reqmode & GR_EXEC ? " executing" : "");
59908+ return reqmode;
59909+ } else
59910+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59911+ {
59912+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
59913+ reqmode & GR_READ ? " reading" : "",
59914+ reqmode & GR_WRITE ? " writing" : "",
59915+ reqmode & GR_EXEC ? " executing" : "");
59916+ return 0;
59917+ } else if (unlikely((mode & reqmode) != reqmode))
59918+ return 0;
59919+
59920+ return reqmode;
59921+}
59922+
59923+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
59924+{
59925+ __u32 mode;
59926+
59927+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
59928+
59929+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59930+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
59931+ return mode;
59932+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59933+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
59934+ return 0;
59935+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
59936+ return 0;
59937+
59938+ return (reqmode);
59939+}
59940+
59941+__u32
59942+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59943+{
59944+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
59945+}
59946+
59947+__u32
59948+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
59949+{
59950+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
59951+}
59952+
59953+__u32
59954+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
59955+{
59956+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
59957+}
59958+
59959+__u32
59960+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
59961+{
59962+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
59963+}
59964+
59965+__u32
59966+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
59967+ mode_t mode)
59968+{
59969+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
59970+ return 1;
59971+
59972+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
59973+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
59974+ GR_FCHMOD_ACL_MSG);
59975+ } else {
59976+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
59977+ }
59978+}
59979+
59980+__u32
59981+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
59982+ mode_t mode)
59983+{
59984+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
59985+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
59986+ GR_CHMOD_ACL_MSG);
59987+ } else {
59988+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
59989+ }
59990+}
59991+
59992+__u32
59993+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
59994+{
59995+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
59996+}
59997+
59998+__u32
59999+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
60000+{
60001+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
60002+}
60003+
60004+__u32
60005+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
60006+{
60007+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
60008+}
60009+
60010+__u32
60011+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
60012+{
60013+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
60014+ GR_UNIXCONNECT_ACL_MSG);
60015+}
60016+
60017+/* hardlinks require at minimum create and link permission,
60018+ any additional privilege required is based on the
60019+ privilege of the file being linked to
60020+*/
60021+__u32
60022+gr_acl_handle_link(const struct dentry * new_dentry,
60023+ const struct dentry * parent_dentry,
60024+ const struct vfsmount * parent_mnt,
60025+ const struct dentry * old_dentry,
60026+ const struct vfsmount * old_mnt, const char *to)
60027+{
60028+ __u32 mode;
60029+ __u32 needmode = GR_CREATE | GR_LINK;
60030+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
60031+
60032+ mode =
60033+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
60034+ old_mnt);
60035+
60036+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
60037+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60038+ return mode;
60039+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60040+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60041+ return 0;
60042+ } else if (unlikely((mode & needmode) != needmode))
60043+ return 0;
60044+
60045+ return 1;
60046+}
60047+
60048+__u32
60049+gr_acl_handle_symlink(const struct dentry * new_dentry,
60050+ const struct dentry * parent_dentry,
60051+ const struct vfsmount * parent_mnt, const char *from)
60052+{
60053+ __u32 needmode = GR_WRITE | GR_CREATE;
60054+ __u32 mode;
60055+
60056+ mode =
60057+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
60058+ GR_CREATE | GR_AUDIT_CREATE |
60059+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
60060+
60061+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
60062+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60063+ return mode;
60064+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60065+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60066+ return 0;
60067+ } else if (unlikely((mode & needmode) != needmode))
60068+ return 0;
60069+
60070+ return (GR_WRITE | GR_CREATE);
60071+}
60072+
60073+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)
60074+{
60075+ __u32 mode;
60076+
60077+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60078+
60079+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60080+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
60081+ return mode;
60082+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60083+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
60084+ return 0;
60085+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
60086+ return 0;
60087+
60088+ return (reqmode);
60089+}
60090+
60091+__u32
60092+gr_acl_handle_mknod(const struct dentry * new_dentry,
60093+ const struct dentry * parent_dentry,
60094+ const struct vfsmount * parent_mnt,
60095+ const int mode)
60096+{
60097+ __u32 reqmode = GR_WRITE | GR_CREATE;
60098+ if (unlikely(mode & (S_ISUID | S_ISGID)))
60099+ reqmode |= GR_SETID;
60100+
60101+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60102+ reqmode, GR_MKNOD_ACL_MSG);
60103+}
60104+
60105+__u32
60106+gr_acl_handle_mkdir(const struct dentry *new_dentry,
60107+ const struct dentry *parent_dentry,
60108+ const struct vfsmount *parent_mnt)
60109+{
60110+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60111+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
60112+}
60113+
60114+#define RENAME_CHECK_SUCCESS(old, new) \
60115+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
60116+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
60117+
60118+int
60119+gr_acl_handle_rename(struct dentry *new_dentry,
60120+ struct dentry *parent_dentry,
60121+ const struct vfsmount *parent_mnt,
60122+ struct dentry *old_dentry,
60123+ struct inode *old_parent_inode,
60124+ struct vfsmount *old_mnt, const char *newname)
60125+{
60126+ __u32 comp1, comp2;
60127+ int error = 0;
60128+
60129+ if (unlikely(!gr_acl_is_enabled()))
60130+ return 0;
60131+
60132+ if (!new_dentry->d_inode) {
60133+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
60134+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
60135+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
60136+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
60137+ GR_DELETE | GR_AUDIT_DELETE |
60138+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60139+ GR_SUPPRESS, old_mnt);
60140+ } else {
60141+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
60142+ GR_CREATE | GR_DELETE |
60143+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
60144+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60145+ GR_SUPPRESS, parent_mnt);
60146+ comp2 =
60147+ gr_search_file(old_dentry,
60148+ GR_READ | GR_WRITE | GR_AUDIT_READ |
60149+ GR_DELETE | GR_AUDIT_DELETE |
60150+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
60151+ }
60152+
60153+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
60154+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
60155+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60156+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
60157+ && !(comp2 & GR_SUPPRESS)) {
60158+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60159+ error = -EACCES;
60160+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
60161+ error = -EACCES;
60162+
60163+ return error;
60164+}
60165+
60166+void
60167+gr_acl_handle_exit(void)
60168+{
60169+ u16 id;
60170+ char *rolename;
60171+ struct file *exec_file;
60172+
60173+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
60174+ !(current->role->roletype & GR_ROLE_PERSIST))) {
60175+ id = current->acl_role_id;
60176+ rolename = current->role->rolename;
60177+ gr_set_acls(1);
60178+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
60179+ }
60180+
60181+ write_lock(&grsec_exec_file_lock);
60182+ exec_file = current->exec_file;
60183+ current->exec_file = NULL;
60184+ write_unlock(&grsec_exec_file_lock);
60185+
60186+ if (exec_file)
60187+ fput(exec_file);
60188+}
60189+
60190+int
60191+gr_acl_handle_procpidmem(const struct task_struct *task)
60192+{
60193+ if (unlikely(!gr_acl_is_enabled()))
60194+ return 0;
60195+
60196+ if (task != current && task->acl->mode & GR_PROTPROCFD)
60197+ return -EACCES;
60198+
60199+ return 0;
60200+}
60201diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
60202new file mode 100644
60203index 0000000..cd07b96
60204--- /dev/null
60205+++ b/grsecurity/gracl_ip.c
60206@@ -0,0 +1,382 @@
60207+#include <linux/kernel.h>
60208+#include <asm/uaccess.h>
60209+#include <asm/errno.h>
60210+#include <net/sock.h>
60211+#include <linux/file.h>
60212+#include <linux/fs.h>
60213+#include <linux/net.h>
60214+#include <linux/in.h>
60215+#include <linux/skbuff.h>
60216+#include <linux/ip.h>
60217+#include <linux/udp.h>
60218+#include <linux/smp_lock.h>
60219+#include <linux/types.h>
60220+#include <linux/sched.h>
60221+#include <linux/netdevice.h>
60222+#include <linux/inetdevice.h>
60223+#include <linux/gracl.h>
60224+#include <linux/grsecurity.h>
60225+#include <linux/grinternal.h>
60226+
60227+#define GR_BIND 0x01
60228+#define GR_CONNECT 0x02
60229+#define GR_INVERT 0x04
60230+#define GR_BINDOVERRIDE 0x08
60231+#define GR_CONNECTOVERRIDE 0x10
60232+#define GR_SOCK_FAMILY 0x20
60233+
60234+static const char * gr_protocols[IPPROTO_MAX] = {
60235+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
60236+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
60237+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
60238+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
60239+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
60240+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
60241+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
60242+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
60243+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
60244+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
60245+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
60246+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
60247+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
60248+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
60249+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
60250+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
60251+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
60252+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
60253+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
60254+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
60255+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
60256+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
60257+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
60258+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
60259+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
60260+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
60261+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
60262+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
60263+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
60264+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
60265+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
60266+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
60267+ };
60268+
60269+static const char * gr_socktypes[SOCK_MAX] = {
60270+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
60271+ "unknown:7", "unknown:8", "unknown:9", "packet"
60272+ };
60273+
60274+static const char * gr_sockfamilies[AF_MAX+1] = {
60275+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
60276+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
60277+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
60278+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
60279+ };
60280+
60281+const char *
60282+gr_proto_to_name(unsigned char proto)
60283+{
60284+ return gr_protocols[proto];
60285+}
60286+
60287+const char *
60288+gr_socktype_to_name(unsigned char type)
60289+{
60290+ return gr_socktypes[type];
60291+}
60292+
60293+const char *
60294+gr_sockfamily_to_name(unsigned char family)
60295+{
60296+ return gr_sockfamilies[family];
60297+}
60298+
60299+int
60300+gr_search_socket(const int domain, const int type, const int protocol)
60301+{
60302+ struct acl_subject_label *curr;
60303+ const struct cred *cred = current_cred();
60304+
60305+ if (unlikely(!gr_acl_is_enabled()))
60306+ goto exit;
60307+
60308+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
60309+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
60310+ goto exit; // let the kernel handle it
60311+
60312+ curr = current->acl;
60313+
60314+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
60315+ /* the family is allowed, if this is PF_INET allow it only if
60316+ the extra sock type/protocol checks pass */
60317+ if (domain == PF_INET)
60318+ goto inet_check;
60319+ goto exit;
60320+ } else {
60321+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60322+ __u32 fakeip = 0;
60323+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60324+ current->role->roletype, cred->uid,
60325+ cred->gid, current->exec_file ?
60326+ gr_to_filename(current->exec_file->f_path.dentry,
60327+ current->exec_file->f_path.mnt) :
60328+ curr->filename, curr->filename,
60329+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
60330+ &current->signal->saved_ip);
60331+ goto exit;
60332+ }
60333+ goto exit_fail;
60334+ }
60335+
60336+inet_check:
60337+ /* the rest of this checking is for IPv4 only */
60338+ if (!curr->ips)
60339+ goto exit;
60340+
60341+ if ((curr->ip_type & (1 << type)) &&
60342+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
60343+ goto exit;
60344+
60345+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60346+ /* we don't place acls on raw sockets , and sometimes
60347+ dgram/ip sockets are opened for ioctl and not
60348+ bind/connect, so we'll fake a bind learn log */
60349+ if (type == SOCK_RAW || type == SOCK_PACKET) {
60350+ __u32 fakeip = 0;
60351+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60352+ current->role->roletype, cred->uid,
60353+ cred->gid, current->exec_file ?
60354+ gr_to_filename(current->exec_file->f_path.dentry,
60355+ current->exec_file->f_path.mnt) :
60356+ curr->filename, curr->filename,
60357+ &fakeip, 0, type,
60358+ protocol, GR_CONNECT, &current->signal->saved_ip);
60359+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
60360+ __u32 fakeip = 0;
60361+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60362+ current->role->roletype, cred->uid,
60363+ cred->gid, current->exec_file ?
60364+ gr_to_filename(current->exec_file->f_path.dentry,
60365+ current->exec_file->f_path.mnt) :
60366+ curr->filename, curr->filename,
60367+ &fakeip, 0, type,
60368+ protocol, GR_BIND, &current->signal->saved_ip);
60369+ }
60370+ /* we'll log when they use connect or bind */
60371+ goto exit;
60372+ }
60373+
60374+exit_fail:
60375+ if (domain == PF_INET)
60376+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
60377+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
60378+ else
60379+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
60380+ gr_socktype_to_name(type), protocol);
60381+
60382+ return 0;
60383+exit:
60384+ return 1;
60385+}
60386+
60387+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)
60388+{
60389+ if ((ip->mode & mode) &&
60390+ (ip_port >= ip->low) &&
60391+ (ip_port <= ip->high) &&
60392+ ((ntohl(ip_addr) & our_netmask) ==
60393+ (ntohl(our_addr) & our_netmask))
60394+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
60395+ && (ip->type & (1 << type))) {
60396+ if (ip->mode & GR_INVERT)
60397+ return 2; // specifically denied
60398+ else
60399+ return 1; // allowed
60400+ }
60401+
60402+ return 0; // not specifically allowed, may continue parsing
60403+}
60404+
60405+static int
60406+gr_search_connectbind(const int full_mode, struct sock *sk,
60407+ struct sockaddr_in *addr, const int type)
60408+{
60409+ char iface[IFNAMSIZ] = {0};
60410+ struct acl_subject_label *curr;
60411+ struct acl_ip_label *ip;
60412+ struct inet_sock *isk;
60413+ struct net_device *dev;
60414+ struct in_device *idev;
60415+ unsigned long i;
60416+ int ret;
60417+ int mode = full_mode & (GR_BIND | GR_CONNECT);
60418+ __u32 ip_addr = 0;
60419+ __u32 our_addr;
60420+ __u32 our_netmask;
60421+ char *p;
60422+ __u16 ip_port = 0;
60423+ const struct cred *cred = current_cred();
60424+
60425+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
60426+ return 0;
60427+
60428+ curr = current->acl;
60429+ isk = inet_sk(sk);
60430+
60431+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
60432+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
60433+ addr->sin_addr.s_addr = curr->inaddr_any_override;
60434+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
60435+ struct sockaddr_in saddr;
60436+ int err;
60437+
60438+ saddr.sin_family = AF_INET;
60439+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
60440+ saddr.sin_port = isk->sport;
60441+
60442+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60443+ if (err)
60444+ return err;
60445+
60446+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60447+ if (err)
60448+ return err;
60449+ }
60450+
60451+ if (!curr->ips)
60452+ return 0;
60453+
60454+ ip_addr = addr->sin_addr.s_addr;
60455+ ip_port = ntohs(addr->sin_port);
60456+
60457+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60458+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60459+ current->role->roletype, cred->uid,
60460+ cred->gid, current->exec_file ?
60461+ gr_to_filename(current->exec_file->f_path.dentry,
60462+ current->exec_file->f_path.mnt) :
60463+ curr->filename, curr->filename,
60464+ &ip_addr, ip_port, type,
60465+ sk->sk_protocol, mode, &current->signal->saved_ip);
60466+ return 0;
60467+ }
60468+
60469+ for (i = 0; i < curr->ip_num; i++) {
60470+ ip = *(curr->ips + i);
60471+ if (ip->iface != NULL) {
60472+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
60473+ p = strchr(iface, ':');
60474+ if (p != NULL)
60475+ *p = '\0';
60476+ dev = dev_get_by_name(sock_net(sk), iface);
60477+ if (dev == NULL)
60478+ continue;
60479+ idev = in_dev_get(dev);
60480+ if (idev == NULL) {
60481+ dev_put(dev);
60482+ continue;
60483+ }
60484+ rcu_read_lock();
60485+ for_ifa(idev) {
60486+ if (!strcmp(ip->iface, ifa->ifa_label)) {
60487+ our_addr = ifa->ifa_address;
60488+ our_netmask = 0xffffffff;
60489+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60490+ if (ret == 1) {
60491+ rcu_read_unlock();
60492+ in_dev_put(idev);
60493+ dev_put(dev);
60494+ return 0;
60495+ } else if (ret == 2) {
60496+ rcu_read_unlock();
60497+ in_dev_put(idev);
60498+ dev_put(dev);
60499+ goto denied;
60500+ }
60501+ }
60502+ } endfor_ifa(idev);
60503+ rcu_read_unlock();
60504+ in_dev_put(idev);
60505+ dev_put(dev);
60506+ } else {
60507+ our_addr = ip->addr;
60508+ our_netmask = ip->netmask;
60509+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60510+ if (ret == 1)
60511+ return 0;
60512+ else if (ret == 2)
60513+ goto denied;
60514+ }
60515+ }
60516+
60517+denied:
60518+ if (mode == GR_BIND)
60519+ 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));
60520+ else if (mode == GR_CONNECT)
60521+ 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));
60522+
60523+ return -EACCES;
60524+}
60525+
60526+int
60527+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
60528+{
60529+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
60530+}
60531+
60532+int
60533+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
60534+{
60535+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
60536+}
60537+
60538+int gr_search_listen(struct socket *sock)
60539+{
60540+ struct sock *sk = sock->sk;
60541+ struct sockaddr_in addr;
60542+
60543+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60544+ addr.sin_port = inet_sk(sk)->sport;
60545+
60546+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60547+}
60548+
60549+int gr_search_accept(struct socket *sock)
60550+{
60551+ struct sock *sk = sock->sk;
60552+ struct sockaddr_in addr;
60553+
60554+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60555+ addr.sin_port = inet_sk(sk)->sport;
60556+
60557+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60558+}
60559+
60560+int
60561+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
60562+{
60563+ if (addr)
60564+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
60565+ else {
60566+ struct sockaddr_in sin;
60567+ const struct inet_sock *inet = inet_sk(sk);
60568+
60569+ sin.sin_addr.s_addr = inet->daddr;
60570+ sin.sin_port = inet->dport;
60571+
60572+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60573+ }
60574+}
60575+
60576+int
60577+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
60578+{
60579+ struct sockaddr_in sin;
60580+
60581+ if (unlikely(skb->len < sizeof (struct udphdr)))
60582+ return 0; // skip this packet
60583+
60584+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
60585+ sin.sin_port = udp_hdr(skb)->source;
60586+
60587+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60588+}
60589diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
60590new file mode 100644
60591index 0000000..34bdd46
60592--- /dev/null
60593+++ b/grsecurity/gracl_learn.c
60594@@ -0,0 +1,208 @@
60595+#include <linux/kernel.h>
60596+#include <linux/mm.h>
60597+#include <linux/sched.h>
60598+#include <linux/poll.h>
60599+#include <linux/smp_lock.h>
60600+#include <linux/string.h>
60601+#include <linux/file.h>
60602+#include <linux/types.h>
60603+#include <linux/vmalloc.h>
60604+#include <linux/grinternal.h>
60605+
60606+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
60607+ size_t count, loff_t *ppos);
60608+extern int gr_acl_is_enabled(void);
60609+
60610+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
60611+static int gr_learn_attached;
60612+
60613+/* use a 512k buffer */
60614+#define LEARN_BUFFER_SIZE (512 * 1024)
60615+
60616+static DEFINE_SPINLOCK(gr_learn_lock);
60617+static DEFINE_MUTEX(gr_learn_user_mutex);
60618+
60619+/* we need to maintain two buffers, so that the kernel context of grlearn
60620+ uses a semaphore around the userspace copying, and the other kernel contexts
60621+ use a spinlock when copying into the buffer, since they cannot sleep
60622+*/
60623+static char *learn_buffer;
60624+static char *learn_buffer_user;
60625+static int learn_buffer_len;
60626+static int learn_buffer_user_len;
60627+
60628+static ssize_t
60629+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
60630+{
60631+ DECLARE_WAITQUEUE(wait, current);
60632+ ssize_t retval = 0;
60633+
60634+ add_wait_queue(&learn_wait, &wait);
60635+ set_current_state(TASK_INTERRUPTIBLE);
60636+ do {
60637+ mutex_lock(&gr_learn_user_mutex);
60638+ spin_lock(&gr_learn_lock);
60639+ if (learn_buffer_len)
60640+ break;
60641+ spin_unlock(&gr_learn_lock);
60642+ mutex_unlock(&gr_learn_user_mutex);
60643+ if (file->f_flags & O_NONBLOCK) {
60644+ retval = -EAGAIN;
60645+ goto out;
60646+ }
60647+ if (signal_pending(current)) {
60648+ retval = -ERESTARTSYS;
60649+ goto out;
60650+ }
60651+
60652+ schedule();
60653+ } while (1);
60654+
60655+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
60656+ learn_buffer_user_len = learn_buffer_len;
60657+ retval = learn_buffer_len;
60658+ learn_buffer_len = 0;
60659+
60660+ spin_unlock(&gr_learn_lock);
60661+
60662+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
60663+ retval = -EFAULT;
60664+
60665+ mutex_unlock(&gr_learn_user_mutex);
60666+out:
60667+ set_current_state(TASK_RUNNING);
60668+ remove_wait_queue(&learn_wait, &wait);
60669+ return retval;
60670+}
60671+
60672+static unsigned int
60673+poll_learn(struct file * file, poll_table * wait)
60674+{
60675+ poll_wait(file, &learn_wait, wait);
60676+
60677+ if (learn_buffer_len)
60678+ return (POLLIN | POLLRDNORM);
60679+
60680+ return 0;
60681+}
60682+
60683+void
60684+gr_clear_learn_entries(void)
60685+{
60686+ char *tmp;
60687+
60688+ mutex_lock(&gr_learn_user_mutex);
60689+ spin_lock(&gr_learn_lock);
60690+ tmp = learn_buffer;
60691+ learn_buffer = NULL;
60692+ spin_unlock(&gr_learn_lock);
60693+ if (tmp)
60694+ vfree(tmp);
60695+ if (learn_buffer_user != NULL) {
60696+ vfree(learn_buffer_user);
60697+ learn_buffer_user = NULL;
60698+ }
60699+ learn_buffer_len = 0;
60700+ mutex_unlock(&gr_learn_user_mutex);
60701+
60702+ return;
60703+}
60704+
60705+void
60706+gr_add_learn_entry(const char *fmt, ...)
60707+{
60708+ va_list args;
60709+ unsigned int len;
60710+
60711+ if (!gr_learn_attached)
60712+ return;
60713+
60714+ spin_lock(&gr_learn_lock);
60715+
60716+ /* leave a gap at the end so we know when it's "full" but don't have to
60717+ compute the exact length of the string we're trying to append
60718+ */
60719+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
60720+ spin_unlock(&gr_learn_lock);
60721+ wake_up_interruptible(&learn_wait);
60722+ return;
60723+ }
60724+ if (learn_buffer == NULL) {
60725+ spin_unlock(&gr_learn_lock);
60726+ return;
60727+ }
60728+
60729+ va_start(args, fmt);
60730+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
60731+ va_end(args);
60732+
60733+ learn_buffer_len += len + 1;
60734+
60735+ spin_unlock(&gr_learn_lock);
60736+ wake_up_interruptible(&learn_wait);
60737+
60738+ return;
60739+}
60740+
60741+static int
60742+open_learn(struct inode *inode, struct file *file)
60743+{
60744+ if (file->f_mode & FMODE_READ && gr_learn_attached)
60745+ return -EBUSY;
60746+ if (file->f_mode & FMODE_READ) {
60747+ int retval = 0;
60748+ mutex_lock(&gr_learn_user_mutex);
60749+ if (learn_buffer == NULL)
60750+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
60751+ if (learn_buffer_user == NULL)
60752+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
60753+ if (learn_buffer == NULL) {
60754+ retval = -ENOMEM;
60755+ goto out_error;
60756+ }
60757+ if (learn_buffer_user == NULL) {
60758+ retval = -ENOMEM;
60759+ goto out_error;
60760+ }
60761+ learn_buffer_len = 0;
60762+ learn_buffer_user_len = 0;
60763+ gr_learn_attached = 1;
60764+out_error:
60765+ mutex_unlock(&gr_learn_user_mutex);
60766+ return retval;
60767+ }
60768+ return 0;
60769+}
60770+
60771+static int
60772+close_learn(struct inode *inode, struct file *file)
60773+{
60774+ if (file->f_mode & FMODE_READ) {
60775+ char *tmp = NULL;
60776+ mutex_lock(&gr_learn_user_mutex);
60777+ spin_lock(&gr_learn_lock);
60778+ tmp = learn_buffer;
60779+ learn_buffer = NULL;
60780+ spin_unlock(&gr_learn_lock);
60781+ if (tmp)
60782+ vfree(tmp);
60783+ if (learn_buffer_user != NULL) {
60784+ vfree(learn_buffer_user);
60785+ learn_buffer_user = NULL;
60786+ }
60787+ learn_buffer_len = 0;
60788+ learn_buffer_user_len = 0;
60789+ gr_learn_attached = 0;
60790+ mutex_unlock(&gr_learn_user_mutex);
60791+ }
60792+
60793+ return 0;
60794+}
60795+
60796+const struct file_operations grsec_fops = {
60797+ .read = read_learn,
60798+ .write = write_grsec_handler,
60799+ .open = open_learn,
60800+ .release = close_learn,
60801+ .poll = poll_learn,
60802+};
60803diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
60804new file mode 100644
60805index 0000000..70b2179
60806--- /dev/null
60807+++ b/grsecurity/gracl_res.c
60808@@ -0,0 +1,67 @@
60809+#include <linux/kernel.h>
60810+#include <linux/sched.h>
60811+#include <linux/gracl.h>
60812+#include <linux/grinternal.h>
60813+
60814+static const char *restab_log[] = {
60815+ [RLIMIT_CPU] = "RLIMIT_CPU",
60816+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
60817+ [RLIMIT_DATA] = "RLIMIT_DATA",
60818+ [RLIMIT_STACK] = "RLIMIT_STACK",
60819+ [RLIMIT_CORE] = "RLIMIT_CORE",
60820+ [RLIMIT_RSS] = "RLIMIT_RSS",
60821+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
60822+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
60823+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
60824+ [RLIMIT_AS] = "RLIMIT_AS",
60825+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
60826+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
60827+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
60828+ [RLIMIT_NICE] = "RLIMIT_NICE",
60829+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
60830+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
60831+ [GR_CRASH_RES] = "RLIMIT_CRASH"
60832+};
60833+
60834+void
60835+gr_log_resource(const struct task_struct *task,
60836+ const int res, const unsigned long wanted, const int gt)
60837+{
60838+ const struct cred *cred;
60839+ unsigned long rlim;
60840+
60841+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
60842+ return;
60843+
60844+ // not yet supported resource
60845+ if (unlikely(!restab_log[res]))
60846+ return;
60847+
60848+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
60849+ rlim = task->signal->rlim[res].rlim_max;
60850+ else
60851+ rlim = task->signal->rlim[res].rlim_cur;
60852+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
60853+ return;
60854+
60855+ rcu_read_lock();
60856+ cred = __task_cred(task);
60857+
60858+ if (res == RLIMIT_NPROC &&
60859+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
60860+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
60861+ goto out_rcu_unlock;
60862+ else if (res == RLIMIT_MEMLOCK &&
60863+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
60864+ goto out_rcu_unlock;
60865+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
60866+ goto out_rcu_unlock;
60867+ rcu_read_unlock();
60868+
60869+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
60870+
60871+ return;
60872+out_rcu_unlock:
60873+ rcu_read_unlock();
60874+ return;
60875+}
60876diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
60877new file mode 100644
60878index 0000000..1d1b734
60879--- /dev/null
60880+++ b/grsecurity/gracl_segv.c
60881@@ -0,0 +1,284 @@
60882+#include <linux/kernel.h>
60883+#include <linux/mm.h>
60884+#include <asm/uaccess.h>
60885+#include <asm/errno.h>
60886+#include <asm/mman.h>
60887+#include <net/sock.h>
60888+#include <linux/file.h>
60889+#include <linux/fs.h>
60890+#include <linux/net.h>
60891+#include <linux/in.h>
60892+#include <linux/smp_lock.h>
60893+#include <linux/slab.h>
60894+#include <linux/types.h>
60895+#include <linux/sched.h>
60896+#include <linux/timer.h>
60897+#include <linux/gracl.h>
60898+#include <linux/grsecurity.h>
60899+#include <linux/grinternal.h>
60900+
60901+static struct crash_uid *uid_set;
60902+static unsigned short uid_used;
60903+static DEFINE_SPINLOCK(gr_uid_lock);
60904+extern rwlock_t gr_inode_lock;
60905+extern struct acl_subject_label *
60906+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
60907+ struct acl_role_label *role);
60908+extern int gr_fake_force_sig(int sig, struct task_struct *t);
60909+
60910+int
60911+gr_init_uidset(void)
60912+{
60913+ uid_set =
60914+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
60915+ uid_used = 0;
60916+
60917+ return uid_set ? 1 : 0;
60918+}
60919+
60920+void
60921+gr_free_uidset(void)
60922+{
60923+ if (uid_set)
60924+ kfree(uid_set);
60925+
60926+ return;
60927+}
60928+
60929+int
60930+gr_find_uid(const uid_t uid)
60931+{
60932+ struct crash_uid *tmp = uid_set;
60933+ uid_t buid;
60934+ int low = 0, high = uid_used - 1, mid;
60935+
60936+ while (high >= low) {
60937+ mid = (low + high) >> 1;
60938+ buid = tmp[mid].uid;
60939+ if (buid == uid)
60940+ return mid;
60941+ if (buid > uid)
60942+ high = mid - 1;
60943+ if (buid < uid)
60944+ low = mid + 1;
60945+ }
60946+
60947+ return -1;
60948+}
60949+
60950+static __inline__ void
60951+gr_insertsort(void)
60952+{
60953+ unsigned short i, j;
60954+ struct crash_uid index;
60955+
60956+ for (i = 1; i < uid_used; i++) {
60957+ index = uid_set[i];
60958+ j = i;
60959+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
60960+ uid_set[j] = uid_set[j - 1];
60961+ j--;
60962+ }
60963+ uid_set[j] = index;
60964+ }
60965+
60966+ return;
60967+}
60968+
60969+static __inline__ void
60970+gr_insert_uid(const uid_t uid, const unsigned long expires)
60971+{
60972+ int loc;
60973+
60974+ if (uid_used == GR_UIDTABLE_MAX)
60975+ return;
60976+
60977+ loc = gr_find_uid(uid);
60978+
60979+ if (loc >= 0) {
60980+ uid_set[loc].expires = expires;
60981+ return;
60982+ }
60983+
60984+ uid_set[uid_used].uid = uid;
60985+ uid_set[uid_used].expires = expires;
60986+ uid_used++;
60987+
60988+ gr_insertsort();
60989+
60990+ return;
60991+}
60992+
60993+void
60994+gr_remove_uid(const unsigned short loc)
60995+{
60996+ unsigned short i;
60997+
60998+ for (i = loc + 1; i < uid_used; i++)
60999+ uid_set[i - 1] = uid_set[i];
61000+
61001+ uid_used--;
61002+
61003+ return;
61004+}
61005+
61006+int
61007+gr_check_crash_uid(const uid_t uid)
61008+{
61009+ int loc;
61010+ int ret = 0;
61011+
61012+ if (unlikely(!gr_acl_is_enabled()))
61013+ return 0;
61014+
61015+ spin_lock(&gr_uid_lock);
61016+ loc = gr_find_uid(uid);
61017+
61018+ if (loc < 0)
61019+ goto out_unlock;
61020+
61021+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
61022+ gr_remove_uid(loc);
61023+ else
61024+ ret = 1;
61025+
61026+out_unlock:
61027+ spin_unlock(&gr_uid_lock);
61028+ return ret;
61029+}
61030+
61031+static __inline__ int
61032+proc_is_setxid(const struct cred *cred)
61033+{
61034+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
61035+ cred->uid != cred->fsuid)
61036+ return 1;
61037+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
61038+ cred->gid != cred->fsgid)
61039+ return 1;
61040+
61041+ return 0;
61042+}
61043+
61044+void
61045+gr_handle_crash(struct task_struct *task, const int sig)
61046+{
61047+ struct acl_subject_label *curr;
61048+ struct task_struct *tsk, *tsk2;
61049+ const struct cred *cred;
61050+ const struct cred *cred2;
61051+
61052+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
61053+ return;
61054+
61055+ if (unlikely(!gr_acl_is_enabled()))
61056+ return;
61057+
61058+ curr = task->acl;
61059+
61060+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
61061+ return;
61062+
61063+ if (time_before_eq(curr->expires, get_seconds())) {
61064+ curr->expires = 0;
61065+ curr->crashes = 0;
61066+ }
61067+
61068+ curr->crashes++;
61069+
61070+ if (!curr->expires)
61071+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
61072+
61073+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61074+ time_after(curr->expires, get_seconds())) {
61075+ rcu_read_lock();
61076+ cred = __task_cred(task);
61077+ if (cred->uid && proc_is_setxid(cred)) {
61078+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61079+ spin_lock(&gr_uid_lock);
61080+ gr_insert_uid(cred->uid, curr->expires);
61081+ spin_unlock(&gr_uid_lock);
61082+ curr->expires = 0;
61083+ curr->crashes = 0;
61084+ read_lock(&tasklist_lock);
61085+ do_each_thread(tsk2, tsk) {
61086+ cred2 = __task_cred(tsk);
61087+ if (tsk != task && cred2->uid == cred->uid)
61088+ gr_fake_force_sig(SIGKILL, tsk);
61089+ } while_each_thread(tsk2, tsk);
61090+ read_unlock(&tasklist_lock);
61091+ } else {
61092+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61093+ read_lock(&tasklist_lock);
61094+ read_lock(&grsec_exec_file_lock);
61095+ do_each_thread(tsk2, tsk) {
61096+ if (likely(tsk != task)) {
61097+ // if this thread has the same subject as the one that triggered
61098+ // RES_CRASH and it's the same binary, kill it
61099+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
61100+ gr_fake_force_sig(SIGKILL, tsk);
61101+ }
61102+ } while_each_thread(tsk2, tsk);
61103+ read_unlock(&grsec_exec_file_lock);
61104+ read_unlock(&tasklist_lock);
61105+ }
61106+ rcu_read_unlock();
61107+ }
61108+
61109+ return;
61110+}
61111+
61112+int
61113+gr_check_crash_exec(const struct file *filp)
61114+{
61115+ struct acl_subject_label *curr;
61116+
61117+ if (unlikely(!gr_acl_is_enabled()))
61118+ return 0;
61119+
61120+ read_lock(&gr_inode_lock);
61121+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
61122+ filp->f_path.dentry->d_inode->i_sb->s_dev,
61123+ current->role);
61124+ read_unlock(&gr_inode_lock);
61125+
61126+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
61127+ (!curr->crashes && !curr->expires))
61128+ return 0;
61129+
61130+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61131+ time_after(curr->expires, get_seconds()))
61132+ return 1;
61133+ else if (time_before_eq(curr->expires, get_seconds())) {
61134+ curr->crashes = 0;
61135+ curr->expires = 0;
61136+ }
61137+
61138+ return 0;
61139+}
61140+
61141+void
61142+gr_handle_alertkill(struct task_struct *task)
61143+{
61144+ struct acl_subject_label *curracl;
61145+ __u32 curr_ip;
61146+ struct task_struct *p, *p2;
61147+
61148+ if (unlikely(!gr_acl_is_enabled()))
61149+ return;
61150+
61151+ curracl = task->acl;
61152+ curr_ip = task->signal->curr_ip;
61153+
61154+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
61155+ read_lock(&tasklist_lock);
61156+ do_each_thread(p2, p) {
61157+ if (p->signal->curr_ip == curr_ip)
61158+ gr_fake_force_sig(SIGKILL, p);
61159+ } while_each_thread(p2, p);
61160+ read_unlock(&tasklist_lock);
61161+ } else if (curracl->mode & GR_KILLPROC)
61162+ gr_fake_force_sig(SIGKILL, task);
61163+
61164+ return;
61165+}
61166diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
61167new file mode 100644
61168index 0000000..9d83a69
61169--- /dev/null
61170+++ b/grsecurity/gracl_shm.c
61171@@ -0,0 +1,40 @@
61172+#include <linux/kernel.h>
61173+#include <linux/mm.h>
61174+#include <linux/sched.h>
61175+#include <linux/file.h>
61176+#include <linux/ipc.h>
61177+#include <linux/gracl.h>
61178+#include <linux/grsecurity.h>
61179+#include <linux/grinternal.h>
61180+
61181+int
61182+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61183+ const time_t shm_createtime, const uid_t cuid, const int shmid)
61184+{
61185+ struct task_struct *task;
61186+
61187+ if (!gr_acl_is_enabled())
61188+ return 1;
61189+
61190+ rcu_read_lock();
61191+ read_lock(&tasklist_lock);
61192+
61193+ task = find_task_by_vpid(shm_cprid);
61194+
61195+ if (unlikely(!task))
61196+ task = find_task_by_vpid(shm_lapid);
61197+
61198+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
61199+ (task->pid == shm_lapid)) &&
61200+ (task->acl->mode & GR_PROTSHM) &&
61201+ (task->acl != current->acl))) {
61202+ read_unlock(&tasklist_lock);
61203+ rcu_read_unlock();
61204+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
61205+ return 0;
61206+ }
61207+ read_unlock(&tasklist_lock);
61208+ rcu_read_unlock();
61209+
61210+ return 1;
61211+}
61212diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
61213new file mode 100644
61214index 0000000..bc0be01
61215--- /dev/null
61216+++ b/grsecurity/grsec_chdir.c
61217@@ -0,0 +1,19 @@
61218+#include <linux/kernel.h>
61219+#include <linux/sched.h>
61220+#include <linux/fs.h>
61221+#include <linux/file.h>
61222+#include <linux/grsecurity.h>
61223+#include <linux/grinternal.h>
61224+
61225+void
61226+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
61227+{
61228+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61229+ if ((grsec_enable_chdir && grsec_enable_group &&
61230+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
61231+ !grsec_enable_group)) {
61232+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
61233+ }
61234+#endif
61235+ return;
61236+}
61237diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
61238new file mode 100644
61239index 0000000..197bdd5
61240--- /dev/null
61241+++ b/grsecurity/grsec_chroot.c
61242@@ -0,0 +1,386 @@
61243+#include <linux/kernel.h>
61244+#include <linux/module.h>
61245+#include <linux/sched.h>
61246+#include <linux/file.h>
61247+#include <linux/fs.h>
61248+#include <linux/mount.h>
61249+#include <linux/types.h>
61250+#include <linux/pid_namespace.h>
61251+#include <linux/grsecurity.h>
61252+#include <linux/grinternal.h>
61253+
61254+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
61255+{
61256+#ifdef CONFIG_GRKERNSEC
61257+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
61258+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
61259+ task->gr_is_chrooted = 1;
61260+ else
61261+ task->gr_is_chrooted = 0;
61262+
61263+ task->gr_chroot_dentry = path->dentry;
61264+#endif
61265+ return;
61266+}
61267+
61268+void gr_clear_chroot_entries(struct task_struct *task)
61269+{
61270+#ifdef CONFIG_GRKERNSEC
61271+ task->gr_is_chrooted = 0;
61272+ task->gr_chroot_dentry = NULL;
61273+#endif
61274+ return;
61275+}
61276+
61277+int
61278+gr_handle_chroot_unix(const pid_t pid)
61279+{
61280+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61281+ struct task_struct *p;
61282+
61283+ if (unlikely(!grsec_enable_chroot_unix))
61284+ return 1;
61285+
61286+ if (likely(!proc_is_chrooted(current)))
61287+ return 1;
61288+
61289+ rcu_read_lock();
61290+ read_lock(&tasklist_lock);
61291+
61292+ p = find_task_by_vpid_unrestricted(pid);
61293+ if (unlikely(p && !have_same_root(current, p))) {
61294+ read_unlock(&tasklist_lock);
61295+ rcu_read_unlock();
61296+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
61297+ return 0;
61298+ }
61299+ read_unlock(&tasklist_lock);
61300+ rcu_read_unlock();
61301+#endif
61302+ return 1;
61303+}
61304+
61305+int
61306+gr_handle_chroot_nice(void)
61307+{
61308+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61309+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
61310+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
61311+ return -EPERM;
61312+ }
61313+#endif
61314+ return 0;
61315+}
61316+
61317+int
61318+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
61319+{
61320+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61321+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
61322+ && proc_is_chrooted(current)) {
61323+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
61324+ return -EACCES;
61325+ }
61326+#endif
61327+ return 0;
61328+}
61329+
61330+int
61331+gr_handle_chroot_rawio(const struct inode *inode)
61332+{
61333+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61334+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
61335+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
61336+ return 1;
61337+#endif
61338+ return 0;
61339+}
61340+
61341+int
61342+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
61343+{
61344+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61345+ struct task_struct *p;
61346+ int ret = 0;
61347+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
61348+ return ret;
61349+
61350+ read_lock(&tasklist_lock);
61351+ do_each_pid_task(pid, type, p) {
61352+ if (!have_same_root(current, p)) {
61353+ ret = 1;
61354+ goto out;
61355+ }
61356+ } while_each_pid_task(pid, type, p);
61357+out:
61358+ read_unlock(&tasklist_lock);
61359+ return ret;
61360+#endif
61361+ return 0;
61362+}
61363+
61364+int
61365+gr_pid_is_chrooted(struct task_struct *p)
61366+{
61367+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61368+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
61369+ return 0;
61370+
61371+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
61372+ !have_same_root(current, p)) {
61373+ return 1;
61374+ }
61375+#endif
61376+ return 0;
61377+}
61378+
61379+EXPORT_SYMBOL(gr_pid_is_chrooted);
61380+
61381+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
61382+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
61383+{
61384+ struct dentry *dentry = (struct dentry *)u_dentry;
61385+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
61386+ struct dentry *realroot;
61387+ struct vfsmount *realrootmnt;
61388+ struct dentry *currentroot;
61389+ struct vfsmount *currentmnt;
61390+ struct task_struct *reaper = &init_task;
61391+ int ret = 1;
61392+
61393+ read_lock(&reaper->fs->lock);
61394+ realrootmnt = mntget(reaper->fs->root.mnt);
61395+ realroot = dget(reaper->fs->root.dentry);
61396+ read_unlock(&reaper->fs->lock);
61397+
61398+ read_lock(&current->fs->lock);
61399+ currentmnt = mntget(current->fs->root.mnt);
61400+ currentroot = dget(current->fs->root.dentry);
61401+ read_unlock(&current->fs->lock);
61402+
61403+ spin_lock(&dcache_lock);
61404+ for (;;) {
61405+ if (unlikely((dentry == realroot && mnt == realrootmnt)
61406+ || (dentry == currentroot && mnt == currentmnt)))
61407+ break;
61408+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
61409+ if (mnt->mnt_parent == mnt)
61410+ break;
61411+ dentry = mnt->mnt_mountpoint;
61412+ mnt = mnt->mnt_parent;
61413+ continue;
61414+ }
61415+ dentry = dentry->d_parent;
61416+ }
61417+ spin_unlock(&dcache_lock);
61418+
61419+ dput(currentroot);
61420+ mntput(currentmnt);
61421+
61422+ /* access is outside of chroot */
61423+ if (dentry == realroot && mnt == realrootmnt)
61424+ ret = 0;
61425+
61426+ dput(realroot);
61427+ mntput(realrootmnt);
61428+ return ret;
61429+}
61430+#endif
61431+
61432+int
61433+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
61434+{
61435+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61436+ if (!grsec_enable_chroot_fchdir)
61437+ return 1;
61438+
61439+ if (!proc_is_chrooted(current))
61440+ return 1;
61441+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
61442+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
61443+ return 0;
61444+ }
61445+#endif
61446+ return 1;
61447+}
61448+
61449+int
61450+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61451+ const time_t shm_createtime)
61452+{
61453+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61454+ struct task_struct *p;
61455+ time_t starttime;
61456+
61457+ if (unlikely(!grsec_enable_chroot_shmat))
61458+ return 1;
61459+
61460+ if (likely(!proc_is_chrooted(current)))
61461+ return 1;
61462+
61463+ rcu_read_lock();
61464+ read_lock(&tasklist_lock);
61465+
61466+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
61467+ starttime = p->start_time.tv_sec;
61468+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
61469+ if (have_same_root(current, p)) {
61470+ goto allow;
61471+ } else {
61472+ read_unlock(&tasklist_lock);
61473+ rcu_read_unlock();
61474+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61475+ return 0;
61476+ }
61477+ }
61478+ /* creator exited, pid reuse, fall through to next check */
61479+ }
61480+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
61481+ if (unlikely(!have_same_root(current, p))) {
61482+ read_unlock(&tasklist_lock);
61483+ rcu_read_unlock();
61484+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61485+ return 0;
61486+ }
61487+ }
61488+
61489+allow:
61490+ read_unlock(&tasklist_lock);
61491+ rcu_read_unlock();
61492+#endif
61493+ return 1;
61494+}
61495+
61496+void
61497+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
61498+{
61499+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61500+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
61501+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
61502+#endif
61503+ return;
61504+}
61505+
61506+int
61507+gr_handle_chroot_mknod(const struct dentry *dentry,
61508+ const struct vfsmount *mnt, const int mode)
61509+{
61510+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61511+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
61512+ proc_is_chrooted(current)) {
61513+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
61514+ return -EPERM;
61515+ }
61516+#endif
61517+ return 0;
61518+}
61519+
61520+int
61521+gr_handle_chroot_mount(const struct dentry *dentry,
61522+ const struct vfsmount *mnt, const char *dev_name)
61523+{
61524+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61525+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
61526+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
61527+ return -EPERM;
61528+ }
61529+#endif
61530+ return 0;
61531+}
61532+
61533+int
61534+gr_handle_chroot_pivot(void)
61535+{
61536+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61537+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
61538+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
61539+ return -EPERM;
61540+ }
61541+#endif
61542+ return 0;
61543+}
61544+
61545+int
61546+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
61547+{
61548+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61549+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
61550+ !gr_is_outside_chroot(dentry, mnt)) {
61551+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
61552+ return -EPERM;
61553+ }
61554+#endif
61555+ return 0;
61556+}
61557+
61558+extern const char *captab_log[];
61559+extern int captab_log_entries;
61560+
61561+int
61562+gr_chroot_is_capable(const int cap)
61563+{
61564+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61565+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61566+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61567+ if (cap_raised(chroot_caps, cap)) {
61568+ const struct cred *creds = current_cred();
61569+ if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
61570+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
61571+ }
61572+ return 0;
61573+ }
61574+ }
61575+#endif
61576+ return 1;
61577+}
61578+
61579+int
61580+gr_chroot_is_capable_nolog(const int cap)
61581+{
61582+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61583+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61584+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61585+ if (cap_raised(chroot_caps, cap)) {
61586+ return 0;
61587+ }
61588+ }
61589+#endif
61590+ return 1;
61591+}
61592+
61593+int
61594+gr_handle_chroot_sysctl(const int op)
61595+{
61596+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61597+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
61598+ && (op & MAY_WRITE))
61599+ return -EACCES;
61600+#endif
61601+ return 0;
61602+}
61603+
61604+void
61605+gr_handle_chroot_chdir(struct path *path)
61606+{
61607+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61608+ if (grsec_enable_chroot_chdir)
61609+ set_fs_pwd(current->fs, path);
61610+#endif
61611+ return;
61612+}
61613+
61614+int
61615+gr_handle_chroot_chmod(const struct dentry *dentry,
61616+ const struct vfsmount *mnt, const int mode)
61617+{
61618+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61619+ /* allow chmod +s on directories, but not on files */
61620+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
61621+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
61622+ proc_is_chrooted(current)) {
61623+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
61624+ return -EPERM;
61625+ }
61626+#endif
61627+ return 0;
61628+}
61629diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
61630new file mode 100644
61631index 0000000..b81db5b
61632--- /dev/null
61633+++ b/grsecurity/grsec_disabled.c
61634@@ -0,0 +1,439 @@
61635+#include <linux/kernel.h>
61636+#include <linux/module.h>
61637+#include <linux/sched.h>
61638+#include <linux/file.h>
61639+#include <linux/fs.h>
61640+#include <linux/kdev_t.h>
61641+#include <linux/net.h>
61642+#include <linux/in.h>
61643+#include <linux/ip.h>
61644+#include <linux/skbuff.h>
61645+#include <linux/sysctl.h>
61646+
61647+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61648+void
61649+pax_set_initial_flags(struct linux_binprm *bprm)
61650+{
61651+ return;
61652+}
61653+#endif
61654+
61655+#ifdef CONFIG_SYSCTL
61656+__u32
61657+gr_handle_sysctl(const struct ctl_table * table, const int op)
61658+{
61659+ return 0;
61660+}
61661+#endif
61662+
61663+#ifdef CONFIG_TASKSTATS
61664+int gr_is_taskstats_denied(int pid)
61665+{
61666+ return 0;
61667+}
61668+#endif
61669+
61670+int
61671+gr_acl_is_enabled(void)
61672+{
61673+ return 0;
61674+}
61675+
61676+void
61677+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61678+{
61679+ return;
61680+}
61681+
61682+int
61683+gr_handle_rawio(const struct inode *inode)
61684+{
61685+ return 0;
61686+}
61687+
61688+void
61689+gr_acl_handle_psacct(struct task_struct *task, const long code)
61690+{
61691+ return;
61692+}
61693+
61694+int
61695+gr_handle_ptrace(struct task_struct *task, const long request)
61696+{
61697+ return 0;
61698+}
61699+
61700+int
61701+gr_handle_proc_ptrace(struct task_struct *task)
61702+{
61703+ return 0;
61704+}
61705+
61706+void
61707+gr_learn_resource(const struct task_struct *task,
61708+ const int res, const unsigned long wanted, const int gt)
61709+{
61710+ return;
61711+}
61712+
61713+int
61714+gr_set_acls(const int type)
61715+{
61716+ return 0;
61717+}
61718+
61719+int
61720+gr_check_hidden_task(const struct task_struct *tsk)
61721+{
61722+ return 0;
61723+}
61724+
61725+int
61726+gr_check_protected_task(const struct task_struct *task)
61727+{
61728+ return 0;
61729+}
61730+
61731+int
61732+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
61733+{
61734+ return 0;
61735+}
61736+
61737+void
61738+gr_copy_label(struct task_struct *tsk)
61739+{
61740+ return;
61741+}
61742+
61743+void
61744+gr_set_pax_flags(struct task_struct *task)
61745+{
61746+ return;
61747+}
61748+
61749+int
61750+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
61751+ const int unsafe_share)
61752+{
61753+ return 0;
61754+}
61755+
61756+void
61757+gr_handle_delete(const ino_t ino, const dev_t dev)
61758+{
61759+ return;
61760+}
61761+
61762+void
61763+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61764+{
61765+ return;
61766+}
61767+
61768+void
61769+gr_handle_crash(struct task_struct *task, const int sig)
61770+{
61771+ return;
61772+}
61773+
61774+int
61775+gr_check_crash_exec(const struct file *filp)
61776+{
61777+ return 0;
61778+}
61779+
61780+int
61781+gr_check_crash_uid(const uid_t uid)
61782+{
61783+ return 0;
61784+}
61785+
61786+void
61787+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61788+ struct dentry *old_dentry,
61789+ struct dentry *new_dentry,
61790+ struct vfsmount *mnt, const __u8 replace)
61791+{
61792+ return;
61793+}
61794+
61795+int
61796+gr_search_socket(const int family, const int type, const int protocol)
61797+{
61798+ return 1;
61799+}
61800+
61801+int
61802+gr_search_connectbind(const int mode, const struct socket *sock,
61803+ const struct sockaddr_in *addr)
61804+{
61805+ return 0;
61806+}
61807+
61808+void
61809+gr_handle_alertkill(struct task_struct *task)
61810+{
61811+ return;
61812+}
61813+
61814+__u32
61815+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
61816+{
61817+ return 1;
61818+}
61819+
61820+__u32
61821+gr_acl_handle_hidden_file(const struct dentry * dentry,
61822+ const struct vfsmount * mnt)
61823+{
61824+ return 1;
61825+}
61826+
61827+__u32
61828+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61829+ int acc_mode)
61830+{
61831+ return 1;
61832+}
61833+
61834+__u32
61835+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61836+{
61837+ return 1;
61838+}
61839+
61840+__u32
61841+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
61842+{
61843+ return 1;
61844+}
61845+
61846+int
61847+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
61848+ unsigned int *vm_flags)
61849+{
61850+ return 1;
61851+}
61852+
61853+__u32
61854+gr_acl_handle_truncate(const struct dentry * dentry,
61855+ const struct vfsmount * mnt)
61856+{
61857+ return 1;
61858+}
61859+
61860+__u32
61861+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
61862+{
61863+ return 1;
61864+}
61865+
61866+__u32
61867+gr_acl_handle_access(const struct dentry * dentry,
61868+ const struct vfsmount * mnt, const int fmode)
61869+{
61870+ return 1;
61871+}
61872+
61873+__u32
61874+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
61875+ mode_t mode)
61876+{
61877+ return 1;
61878+}
61879+
61880+__u32
61881+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
61882+ mode_t mode)
61883+{
61884+ return 1;
61885+}
61886+
61887+__u32
61888+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
61889+{
61890+ return 1;
61891+}
61892+
61893+__u32
61894+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
61895+{
61896+ return 1;
61897+}
61898+
61899+void
61900+grsecurity_init(void)
61901+{
61902+ return;
61903+}
61904+
61905+__u32
61906+gr_acl_handle_mknod(const struct dentry * new_dentry,
61907+ const struct dentry * parent_dentry,
61908+ const struct vfsmount * parent_mnt,
61909+ const int mode)
61910+{
61911+ return 1;
61912+}
61913+
61914+__u32
61915+gr_acl_handle_mkdir(const struct dentry * new_dentry,
61916+ const struct dentry * parent_dentry,
61917+ const struct vfsmount * parent_mnt)
61918+{
61919+ return 1;
61920+}
61921+
61922+__u32
61923+gr_acl_handle_symlink(const struct dentry * new_dentry,
61924+ const struct dentry * parent_dentry,
61925+ const struct vfsmount * parent_mnt, const char *from)
61926+{
61927+ return 1;
61928+}
61929+
61930+__u32
61931+gr_acl_handle_link(const struct dentry * new_dentry,
61932+ const struct dentry * parent_dentry,
61933+ const struct vfsmount * parent_mnt,
61934+ const struct dentry * old_dentry,
61935+ const struct vfsmount * old_mnt, const char *to)
61936+{
61937+ return 1;
61938+}
61939+
61940+int
61941+gr_acl_handle_rename(const struct dentry *new_dentry,
61942+ const struct dentry *parent_dentry,
61943+ const struct vfsmount *parent_mnt,
61944+ const struct dentry *old_dentry,
61945+ const struct inode *old_parent_inode,
61946+ const struct vfsmount *old_mnt, const char *newname)
61947+{
61948+ return 0;
61949+}
61950+
61951+int
61952+gr_acl_handle_filldir(const struct file *file, const char *name,
61953+ const int namelen, const ino_t ino)
61954+{
61955+ return 1;
61956+}
61957+
61958+int
61959+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61960+ const time_t shm_createtime, const uid_t cuid, const int shmid)
61961+{
61962+ return 1;
61963+}
61964+
61965+int
61966+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
61967+{
61968+ return 0;
61969+}
61970+
61971+int
61972+gr_search_accept(const struct socket *sock)
61973+{
61974+ return 0;
61975+}
61976+
61977+int
61978+gr_search_listen(const struct socket *sock)
61979+{
61980+ return 0;
61981+}
61982+
61983+int
61984+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
61985+{
61986+ return 0;
61987+}
61988+
61989+__u32
61990+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
61991+{
61992+ return 1;
61993+}
61994+
61995+__u32
61996+gr_acl_handle_creat(const struct dentry * dentry,
61997+ const struct dentry * p_dentry,
61998+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61999+ const int imode)
62000+{
62001+ return 1;
62002+}
62003+
62004+void
62005+gr_acl_handle_exit(void)
62006+{
62007+ return;
62008+}
62009+
62010+int
62011+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62012+{
62013+ return 1;
62014+}
62015+
62016+void
62017+gr_set_role_label(const uid_t uid, const gid_t gid)
62018+{
62019+ return;
62020+}
62021+
62022+int
62023+gr_acl_handle_procpidmem(const struct task_struct *task)
62024+{
62025+ return 0;
62026+}
62027+
62028+int
62029+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
62030+{
62031+ return 0;
62032+}
62033+
62034+int
62035+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
62036+{
62037+ return 0;
62038+}
62039+
62040+void
62041+gr_set_kernel_label(struct task_struct *task)
62042+{
62043+ return;
62044+}
62045+
62046+int
62047+gr_check_user_change(int real, int effective, int fs)
62048+{
62049+ return 0;
62050+}
62051+
62052+int
62053+gr_check_group_change(int real, int effective, int fs)
62054+{
62055+ return 0;
62056+}
62057+
62058+int gr_acl_enable_at_secure(void)
62059+{
62060+ return 0;
62061+}
62062+
62063+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62064+{
62065+ return dentry->d_inode->i_sb->s_dev;
62066+}
62067+
62068+EXPORT_SYMBOL(gr_learn_resource);
62069+EXPORT_SYMBOL(gr_set_kernel_label);
62070+#ifdef CONFIG_SECURITY
62071+EXPORT_SYMBOL(gr_check_user_change);
62072+EXPORT_SYMBOL(gr_check_group_change);
62073+#endif
62074diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
62075new file mode 100644
62076index 0000000..a96e155
62077--- /dev/null
62078+++ b/grsecurity/grsec_exec.c
62079@@ -0,0 +1,204 @@
62080+#include <linux/kernel.h>
62081+#include <linux/sched.h>
62082+#include <linux/file.h>
62083+#include <linux/binfmts.h>
62084+#include <linux/smp_lock.h>
62085+#include <linux/fs.h>
62086+#include <linux/types.h>
62087+#include <linux/grdefs.h>
62088+#include <linux/grinternal.h>
62089+#include <linux/capability.h>
62090+#include <linux/compat.h>
62091+#include <linux/module.h>
62092+
62093+#include <asm/uaccess.h>
62094+
62095+#ifdef CONFIG_GRKERNSEC_EXECLOG
62096+static char gr_exec_arg_buf[132];
62097+static DEFINE_MUTEX(gr_exec_arg_mutex);
62098+#endif
62099+
62100+void
62101+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
62102+{
62103+#ifdef CONFIG_GRKERNSEC_EXECLOG
62104+ char *grarg = gr_exec_arg_buf;
62105+ unsigned int i, x, execlen = 0;
62106+ char c;
62107+
62108+ if (!((grsec_enable_execlog && grsec_enable_group &&
62109+ in_group_p(grsec_audit_gid))
62110+ || (grsec_enable_execlog && !grsec_enable_group)))
62111+ return;
62112+
62113+ mutex_lock(&gr_exec_arg_mutex);
62114+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62115+
62116+ if (unlikely(argv == NULL))
62117+ goto log;
62118+
62119+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62120+ const char __user *p;
62121+ unsigned int len;
62122+
62123+ if (copy_from_user(&p, argv + i, sizeof(p)))
62124+ goto log;
62125+ if (!p)
62126+ goto log;
62127+ len = strnlen_user(p, 128 - execlen);
62128+ if (len > 128 - execlen)
62129+ len = 128 - execlen;
62130+ else if (len > 0)
62131+ len--;
62132+ if (copy_from_user(grarg + execlen, p, len))
62133+ goto log;
62134+
62135+ /* rewrite unprintable characters */
62136+ for (x = 0; x < len; x++) {
62137+ c = *(grarg + execlen + x);
62138+ if (c < 32 || c > 126)
62139+ *(grarg + execlen + x) = ' ';
62140+ }
62141+
62142+ execlen += len;
62143+ *(grarg + execlen) = ' ';
62144+ *(grarg + execlen + 1) = '\0';
62145+ execlen++;
62146+ }
62147+
62148+ log:
62149+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62150+ bprm->file->f_path.mnt, grarg);
62151+ mutex_unlock(&gr_exec_arg_mutex);
62152+#endif
62153+ return;
62154+}
62155+
62156+#ifdef CONFIG_COMPAT
62157+void
62158+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
62159+{
62160+#ifdef CONFIG_GRKERNSEC_EXECLOG
62161+ char *grarg = gr_exec_arg_buf;
62162+ unsigned int i, x, execlen = 0;
62163+ char c;
62164+
62165+ if (!((grsec_enable_execlog && grsec_enable_group &&
62166+ in_group_p(grsec_audit_gid))
62167+ || (grsec_enable_execlog && !grsec_enable_group)))
62168+ return;
62169+
62170+ mutex_lock(&gr_exec_arg_mutex);
62171+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62172+
62173+ if (unlikely(argv == NULL))
62174+ goto log;
62175+
62176+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62177+ compat_uptr_t p;
62178+ unsigned int len;
62179+
62180+ if (get_user(p, argv + i))
62181+ goto log;
62182+ len = strnlen_user(compat_ptr(p), 128 - execlen);
62183+ if (len > 128 - execlen)
62184+ len = 128 - execlen;
62185+ else if (len > 0)
62186+ len--;
62187+ else
62188+ goto log;
62189+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
62190+ goto log;
62191+
62192+ /* rewrite unprintable characters */
62193+ for (x = 0; x < len; x++) {
62194+ c = *(grarg + execlen + x);
62195+ if (c < 32 || c > 126)
62196+ *(grarg + execlen + x) = ' ';
62197+ }
62198+
62199+ execlen += len;
62200+ *(grarg + execlen) = ' ';
62201+ *(grarg + execlen + 1) = '\0';
62202+ execlen++;
62203+ }
62204+
62205+ log:
62206+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62207+ bprm->file->f_path.mnt, grarg);
62208+ mutex_unlock(&gr_exec_arg_mutex);
62209+#endif
62210+ return;
62211+}
62212+#endif
62213+
62214+#ifdef CONFIG_GRKERNSEC
62215+extern int gr_acl_is_capable(const int cap);
62216+extern int gr_acl_is_capable_nolog(const int cap);
62217+extern int gr_chroot_is_capable(const int cap);
62218+extern int gr_chroot_is_capable_nolog(const int cap);
62219+#endif
62220+
62221+const char *captab_log[] = {
62222+ "CAP_CHOWN",
62223+ "CAP_DAC_OVERRIDE",
62224+ "CAP_DAC_READ_SEARCH",
62225+ "CAP_FOWNER",
62226+ "CAP_FSETID",
62227+ "CAP_KILL",
62228+ "CAP_SETGID",
62229+ "CAP_SETUID",
62230+ "CAP_SETPCAP",
62231+ "CAP_LINUX_IMMUTABLE",
62232+ "CAP_NET_BIND_SERVICE",
62233+ "CAP_NET_BROADCAST",
62234+ "CAP_NET_ADMIN",
62235+ "CAP_NET_RAW",
62236+ "CAP_IPC_LOCK",
62237+ "CAP_IPC_OWNER",
62238+ "CAP_SYS_MODULE",
62239+ "CAP_SYS_RAWIO",
62240+ "CAP_SYS_CHROOT",
62241+ "CAP_SYS_PTRACE",
62242+ "CAP_SYS_PACCT",
62243+ "CAP_SYS_ADMIN",
62244+ "CAP_SYS_BOOT",
62245+ "CAP_SYS_NICE",
62246+ "CAP_SYS_RESOURCE",
62247+ "CAP_SYS_TIME",
62248+ "CAP_SYS_TTY_CONFIG",
62249+ "CAP_MKNOD",
62250+ "CAP_LEASE",
62251+ "CAP_AUDIT_WRITE",
62252+ "CAP_AUDIT_CONTROL",
62253+ "CAP_SETFCAP",
62254+ "CAP_MAC_OVERRIDE",
62255+ "CAP_MAC_ADMIN"
62256+};
62257+
62258+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
62259+
62260+int gr_is_capable(const int cap)
62261+{
62262+#ifdef CONFIG_GRKERNSEC
62263+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
62264+ return 1;
62265+ return 0;
62266+#else
62267+ return 1;
62268+#endif
62269+}
62270+
62271+int gr_is_capable_nolog(const int cap)
62272+{
62273+#ifdef CONFIG_GRKERNSEC
62274+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
62275+ return 1;
62276+ return 0;
62277+#else
62278+ return 1;
62279+#endif
62280+}
62281+
62282+EXPORT_SYMBOL(gr_is_capable);
62283+EXPORT_SYMBOL(gr_is_capable_nolog);
62284diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
62285new file mode 100644
62286index 0000000..d3ee748
62287--- /dev/null
62288+++ b/grsecurity/grsec_fifo.c
62289@@ -0,0 +1,24 @@
62290+#include <linux/kernel.h>
62291+#include <linux/sched.h>
62292+#include <linux/fs.h>
62293+#include <linux/file.h>
62294+#include <linux/grinternal.h>
62295+
62296+int
62297+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
62298+ const struct dentry *dir, const int flag, const int acc_mode)
62299+{
62300+#ifdef CONFIG_GRKERNSEC_FIFO
62301+ const struct cred *cred = current_cred();
62302+
62303+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
62304+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
62305+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
62306+ (cred->fsuid != dentry->d_inode->i_uid)) {
62307+ if (!inode_permission(dentry->d_inode, acc_mode))
62308+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
62309+ return -EACCES;
62310+ }
62311+#endif
62312+ return 0;
62313+}
62314diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
62315new file mode 100644
62316index 0000000..8ca18bf
62317--- /dev/null
62318+++ b/grsecurity/grsec_fork.c
62319@@ -0,0 +1,23 @@
62320+#include <linux/kernel.h>
62321+#include <linux/sched.h>
62322+#include <linux/grsecurity.h>
62323+#include <linux/grinternal.h>
62324+#include <linux/errno.h>
62325+
62326+void
62327+gr_log_forkfail(const int retval)
62328+{
62329+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62330+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
62331+ switch (retval) {
62332+ case -EAGAIN:
62333+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
62334+ break;
62335+ case -ENOMEM:
62336+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
62337+ break;
62338+ }
62339+ }
62340+#endif
62341+ return;
62342+}
62343diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
62344new file mode 100644
62345index 0000000..f813c26
62346--- /dev/null
62347+++ b/grsecurity/grsec_init.c
62348@@ -0,0 +1,270 @@
62349+#include <linux/kernel.h>
62350+#include <linux/sched.h>
62351+#include <linux/mm.h>
62352+#include <linux/smp_lock.h>
62353+#include <linux/gracl.h>
62354+#include <linux/slab.h>
62355+#include <linux/vmalloc.h>
62356+#include <linux/percpu.h>
62357+#include <linux/module.h>
62358+
62359+int grsec_enable_brute;
62360+int grsec_enable_link;
62361+int grsec_enable_dmesg;
62362+int grsec_enable_harden_ptrace;
62363+int grsec_enable_fifo;
62364+int grsec_enable_execlog;
62365+int grsec_enable_signal;
62366+int grsec_enable_forkfail;
62367+int grsec_enable_audit_ptrace;
62368+int grsec_enable_time;
62369+int grsec_enable_audit_textrel;
62370+int grsec_enable_group;
62371+int grsec_audit_gid;
62372+int grsec_enable_chdir;
62373+int grsec_enable_mount;
62374+int grsec_enable_rofs;
62375+int grsec_enable_chroot_findtask;
62376+int grsec_enable_chroot_mount;
62377+int grsec_enable_chroot_shmat;
62378+int grsec_enable_chroot_fchdir;
62379+int grsec_enable_chroot_double;
62380+int grsec_enable_chroot_pivot;
62381+int grsec_enable_chroot_chdir;
62382+int grsec_enable_chroot_chmod;
62383+int grsec_enable_chroot_mknod;
62384+int grsec_enable_chroot_nice;
62385+int grsec_enable_chroot_execlog;
62386+int grsec_enable_chroot_caps;
62387+int grsec_enable_chroot_sysctl;
62388+int grsec_enable_chroot_unix;
62389+int grsec_enable_tpe;
62390+int grsec_tpe_gid;
62391+int grsec_enable_blackhole;
62392+#ifdef CONFIG_IPV6_MODULE
62393+EXPORT_SYMBOL(grsec_enable_blackhole);
62394+#endif
62395+int grsec_lastack_retries;
62396+int grsec_enable_tpe_all;
62397+int grsec_enable_tpe_invert;
62398+int grsec_enable_socket_all;
62399+int grsec_socket_all_gid;
62400+int grsec_enable_socket_client;
62401+int grsec_socket_client_gid;
62402+int grsec_enable_socket_server;
62403+int grsec_socket_server_gid;
62404+int grsec_resource_logging;
62405+int grsec_disable_privio;
62406+int grsec_enable_log_rwxmaps;
62407+int grsec_lock;
62408+
62409+DEFINE_SPINLOCK(grsec_alert_lock);
62410+unsigned long grsec_alert_wtime = 0;
62411+unsigned long grsec_alert_fyet = 0;
62412+
62413+DEFINE_SPINLOCK(grsec_audit_lock);
62414+
62415+DEFINE_RWLOCK(grsec_exec_file_lock);
62416+
62417+char *gr_shared_page[4];
62418+
62419+char *gr_alert_log_fmt;
62420+char *gr_audit_log_fmt;
62421+char *gr_alert_log_buf;
62422+char *gr_audit_log_buf;
62423+
62424+extern struct gr_arg *gr_usermode;
62425+extern unsigned char *gr_system_salt;
62426+extern unsigned char *gr_system_sum;
62427+
62428+void __init
62429+grsecurity_init(void)
62430+{
62431+ int j;
62432+ /* create the per-cpu shared pages */
62433+
62434+#ifdef CONFIG_X86
62435+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
62436+#endif
62437+
62438+ for (j = 0; j < 4; j++) {
62439+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
62440+ if (gr_shared_page[j] == NULL) {
62441+ panic("Unable to allocate grsecurity shared page");
62442+ return;
62443+ }
62444+ }
62445+
62446+ /* allocate log buffers */
62447+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
62448+ if (!gr_alert_log_fmt) {
62449+ panic("Unable to allocate grsecurity alert log format buffer");
62450+ return;
62451+ }
62452+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
62453+ if (!gr_audit_log_fmt) {
62454+ panic("Unable to allocate grsecurity audit log format buffer");
62455+ return;
62456+ }
62457+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62458+ if (!gr_alert_log_buf) {
62459+ panic("Unable to allocate grsecurity alert log buffer");
62460+ return;
62461+ }
62462+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62463+ if (!gr_audit_log_buf) {
62464+ panic("Unable to allocate grsecurity audit log buffer");
62465+ return;
62466+ }
62467+
62468+ /* allocate memory for authentication structure */
62469+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
62470+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
62471+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
62472+
62473+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
62474+ panic("Unable to allocate grsecurity authentication structure");
62475+ return;
62476+ }
62477+
62478+
62479+#ifdef CONFIG_GRKERNSEC_IO
62480+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
62481+ grsec_disable_privio = 1;
62482+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62483+ grsec_disable_privio = 1;
62484+#else
62485+ grsec_disable_privio = 0;
62486+#endif
62487+#endif
62488+
62489+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62490+ /* for backward compatibility, tpe_invert always defaults to on if
62491+ enabled in the kernel
62492+ */
62493+ grsec_enable_tpe_invert = 1;
62494+#endif
62495+
62496+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62497+#ifndef CONFIG_GRKERNSEC_SYSCTL
62498+ grsec_lock = 1;
62499+#endif
62500+
62501+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62502+ grsec_enable_audit_textrel = 1;
62503+#endif
62504+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62505+ grsec_enable_log_rwxmaps = 1;
62506+#endif
62507+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62508+ grsec_enable_group = 1;
62509+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
62510+#endif
62511+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62512+ grsec_enable_chdir = 1;
62513+#endif
62514+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62515+ grsec_enable_harden_ptrace = 1;
62516+#endif
62517+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62518+ grsec_enable_mount = 1;
62519+#endif
62520+#ifdef CONFIG_GRKERNSEC_LINK
62521+ grsec_enable_link = 1;
62522+#endif
62523+#ifdef CONFIG_GRKERNSEC_BRUTE
62524+ grsec_enable_brute = 1;
62525+#endif
62526+#ifdef CONFIG_GRKERNSEC_DMESG
62527+ grsec_enable_dmesg = 1;
62528+#endif
62529+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62530+ grsec_enable_blackhole = 1;
62531+ grsec_lastack_retries = 4;
62532+#endif
62533+#ifdef CONFIG_GRKERNSEC_FIFO
62534+ grsec_enable_fifo = 1;
62535+#endif
62536+#ifdef CONFIG_GRKERNSEC_EXECLOG
62537+ grsec_enable_execlog = 1;
62538+#endif
62539+#ifdef CONFIG_GRKERNSEC_SIGNAL
62540+ grsec_enable_signal = 1;
62541+#endif
62542+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62543+ grsec_enable_forkfail = 1;
62544+#endif
62545+#ifdef CONFIG_GRKERNSEC_TIME
62546+ grsec_enable_time = 1;
62547+#endif
62548+#ifdef CONFIG_GRKERNSEC_RESLOG
62549+ grsec_resource_logging = 1;
62550+#endif
62551+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62552+ grsec_enable_chroot_findtask = 1;
62553+#endif
62554+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62555+ grsec_enable_chroot_unix = 1;
62556+#endif
62557+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62558+ grsec_enable_chroot_mount = 1;
62559+#endif
62560+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62561+ grsec_enable_chroot_fchdir = 1;
62562+#endif
62563+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62564+ grsec_enable_chroot_shmat = 1;
62565+#endif
62566+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62567+ grsec_enable_audit_ptrace = 1;
62568+#endif
62569+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62570+ grsec_enable_chroot_double = 1;
62571+#endif
62572+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62573+ grsec_enable_chroot_pivot = 1;
62574+#endif
62575+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62576+ grsec_enable_chroot_chdir = 1;
62577+#endif
62578+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62579+ grsec_enable_chroot_chmod = 1;
62580+#endif
62581+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62582+ grsec_enable_chroot_mknod = 1;
62583+#endif
62584+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62585+ grsec_enable_chroot_nice = 1;
62586+#endif
62587+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62588+ grsec_enable_chroot_execlog = 1;
62589+#endif
62590+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62591+ grsec_enable_chroot_caps = 1;
62592+#endif
62593+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62594+ grsec_enable_chroot_sysctl = 1;
62595+#endif
62596+#ifdef CONFIG_GRKERNSEC_TPE
62597+ grsec_enable_tpe = 1;
62598+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
62599+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62600+ grsec_enable_tpe_all = 1;
62601+#endif
62602+#endif
62603+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62604+ grsec_enable_socket_all = 1;
62605+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
62606+#endif
62607+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62608+ grsec_enable_socket_client = 1;
62609+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
62610+#endif
62611+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62612+ grsec_enable_socket_server = 1;
62613+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
62614+#endif
62615+#endif
62616+
62617+ return;
62618+}
62619diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
62620new file mode 100644
62621index 0000000..3efe141
62622--- /dev/null
62623+++ b/grsecurity/grsec_link.c
62624@@ -0,0 +1,43 @@
62625+#include <linux/kernel.h>
62626+#include <linux/sched.h>
62627+#include <linux/fs.h>
62628+#include <linux/file.h>
62629+#include <linux/grinternal.h>
62630+
62631+int
62632+gr_handle_follow_link(const struct inode *parent,
62633+ const struct inode *inode,
62634+ const struct dentry *dentry, const struct vfsmount *mnt)
62635+{
62636+#ifdef CONFIG_GRKERNSEC_LINK
62637+ const struct cred *cred = current_cred();
62638+
62639+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
62640+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
62641+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
62642+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
62643+ return -EACCES;
62644+ }
62645+#endif
62646+ return 0;
62647+}
62648+
62649+int
62650+gr_handle_hardlink(const struct dentry *dentry,
62651+ const struct vfsmount *mnt,
62652+ struct inode *inode, const int mode, const char *to)
62653+{
62654+#ifdef CONFIG_GRKERNSEC_LINK
62655+ const struct cred *cred = current_cred();
62656+
62657+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
62658+ (!S_ISREG(mode) || (mode & S_ISUID) ||
62659+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
62660+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
62661+ !capable(CAP_FOWNER) && cred->uid) {
62662+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
62663+ return -EPERM;
62664+ }
62665+#endif
62666+ return 0;
62667+}
62668diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
62669new file mode 100644
62670index 0000000..a45d2e9
62671--- /dev/null
62672+++ b/grsecurity/grsec_log.c
62673@@ -0,0 +1,322 @@
62674+#include <linux/kernel.h>
62675+#include <linux/sched.h>
62676+#include <linux/file.h>
62677+#include <linux/tty.h>
62678+#include <linux/fs.h>
62679+#include <linux/grinternal.h>
62680+
62681+#ifdef CONFIG_TREE_PREEMPT_RCU
62682+#define DISABLE_PREEMPT() preempt_disable()
62683+#define ENABLE_PREEMPT() preempt_enable()
62684+#else
62685+#define DISABLE_PREEMPT()
62686+#define ENABLE_PREEMPT()
62687+#endif
62688+
62689+#define BEGIN_LOCKS(x) \
62690+ DISABLE_PREEMPT(); \
62691+ rcu_read_lock(); \
62692+ read_lock(&tasklist_lock); \
62693+ read_lock(&grsec_exec_file_lock); \
62694+ if (x != GR_DO_AUDIT) \
62695+ spin_lock(&grsec_alert_lock); \
62696+ else \
62697+ spin_lock(&grsec_audit_lock)
62698+
62699+#define END_LOCKS(x) \
62700+ if (x != GR_DO_AUDIT) \
62701+ spin_unlock(&grsec_alert_lock); \
62702+ else \
62703+ spin_unlock(&grsec_audit_lock); \
62704+ read_unlock(&grsec_exec_file_lock); \
62705+ read_unlock(&tasklist_lock); \
62706+ rcu_read_unlock(); \
62707+ ENABLE_PREEMPT(); \
62708+ if (x == GR_DONT_AUDIT) \
62709+ gr_handle_alertkill(current)
62710+
62711+enum {
62712+ FLOODING,
62713+ NO_FLOODING
62714+};
62715+
62716+extern char *gr_alert_log_fmt;
62717+extern char *gr_audit_log_fmt;
62718+extern char *gr_alert_log_buf;
62719+extern char *gr_audit_log_buf;
62720+
62721+static int gr_log_start(int audit)
62722+{
62723+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
62724+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
62725+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62726+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
62727+ unsigned long curr_secs = get_seconds();
62728+
62729+ if (audit == GR_DO_AUDIT)
62730+ goto set_fmt;
62731+
62732+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
62733+ grsec_alert_wtime = curr_secs;
62734+ grsec_alert_fyet = 0;
62735+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
62736+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
62737+ grsec_alert_fyet++;
62738+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
62739+ grsec_alert_wtime = curr_secs;
62740+ grsec_alert_fyet++;
62741+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
62742+ return FLOODING;
62743+ }
62744+ else return FLOODING;
62745+
62746+set_fmt:
62747+#endif
62748+ memset(buf, 0, PAGE_SIZE);
62749+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
62750+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
62751+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62752+ } else if (current->signal->curr_ip) {
62753+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
62754+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
62755+ } else if (gr_acl_is_enabled()) {
62756+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
62757+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62758+ } else {
62759+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
62760+ strcpy(buf, fmt);
62761+ }
62762+
62763+ return NO_FLOODING;
62764+}
62765+
62766+static void gr_log_middle(int audit, const char *msg, va_list ap)
62767+ __attribute__ ((format (printf, 2, 0)));
62768+
62769+static void gr_log_middle(int audit, const char *msg, va_list ap)
62770+{
62771+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62772+ unsigned int len = strlen(buf);
62773+
62774+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
62775+
62776+ return;
62777+}
62778+
62779+static void gr_log_middle_varargs(int audit, const char *msg, ...)
62780+ __attribute__ ((format (printf, 2, 3)));
62781+
62782+static void gr_log_middle_varargs(int audit, const char *msg, ...)
62783+{
62784+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62785+ unsigned int len = strlen(buf);
62786+ va_list ap;
62787+
62788+ va_start(ap, msg);
62789+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
62790+ va_end(ap);
62791+
62792+ return;
62793+}
62794+
62795+static void gr_log_end(int audit, int append_default)
62796+{
62797+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62798+
62799+ if (append_default) {
62800+ unsigned int len = strlen(buf);
62801+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
62802+ }
62803+
62804+ printk("%s\n", buf);
62805+
62806+ return;
62807+}
62808+
62809+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
62810+{
62811+ int logtype;
62812+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
62813+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
62814+ void *voidptr = NULL;
62815+ int num1 = 0, num2 = 0;
62816+ unsigned long ulong1 = 0, ulong2 = 0;
62817+ struct dentry *dentry = NULL;
62818+ struct vfsmount *mnt = NULL;
62819+ struct file *file = NULL;
62820+ struct task_struct *task = NULL;
62821+ const struct cred *cred, *pcred;
62822+ va_list ap;
62823+
62824+ BEGIN_LOCKS(audit);
62825+ logtype = gr_log_start(audit);
62826+ if (logtype == FLOODING) {
62827+ END_LOCKS(audit);
62828+ return;
62829+ }
62830+ va_start(ap, argtypes);
62831+ switch (argtypes) {
62832+ case GR_TTYSNIFF:
62833+ task = va_arg(ap, struct task_struct *);
62834+ 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);
62835+ break;
62836+ case GR_SYSCTL_HIDDEN:
62837+ str1 = va_arg(ap, char *);
62838+ gr_log_middle_varargs(audit, msg, result, str1);
62839+ break;
62840+ case GR_RBAC:
62841+ dentry = va_arg(ap, struct dentry *);
62842+ mnt = va_arg(ap, struct vfsmount *);
62843+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
62844+ break;
62845+ case GR_RBAC_STR:
62846+ dentry = va_arg(ap, struct dentry *);
62847+ mnt = va_arg(ap, struct vfsmount *);
62848+ str1 = va_arg(ap, char *);
62849+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
62850+ break;
62851+ case GR_STR_RBAC:
62852+ str1 = va_arg(ap, char *);
62853+ dentry = va_arg(ap, struct dentry *);
62854+ mnt = va_arg(ap, struct vfsmount *);
62855+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
62856+ break;
62857+ case GR_RBAC_MODE2:
62858+ dentry = va_arg(ap, struct dentry *);
62859+ mnt = va_arg(ap, struct vfsmount *);
62860+ str1 = va_arg(ap, char *);
62861+ str2 = va_arg(ap, char *);
62862+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
62863+ break;
62864+ case GR_RBAC_MODE3:
62865+ dentry = va_arg(ap, struct dentry *);
62866+ mnt = va_arg(ap, struct vfsmount *);
62867+ str1 = va_arg(ap, char *);
62868+ str2 = va_arg(ap, char *);
62869+ str3 = va_arg(ap, char *);
62870+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
62871+ break;
62872+ case GR_FILENAME:
62873+ dentry = va_arg(ap, struct dentry *);
62874+ mnt = va_arg(ap, struct vfsmount *);
62875+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
62876+ break;
62877+ case GR_STR_FILENAME:
62878+ str1 = va_arg(ap, char *);
62879+ dentry = va_arg(ap, struct dentry *);
62880+ mnt = va_arg(ap, struct vfsmount *);
62881+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
62882+ break;
62883+ case GR_FILENAME_STR:
62884+ dentry = va_arg(ap, struct dentry *);
62885+ mnt = va_arg(ap, struct vfsmount *);
62886+ str1 = va_arg(ap, char *);
62887+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
62888+ break;
62889+ case GR_FILENAME_TWO_INT:
62890+ dentry = va_arg(ap, struct dentry *);
62891+ mnt = va_arg(ap, struct vfsmount *);
62892+ num1 = va_arg(ap, int);
62893+ num2 = va_arg(ap, int);
62894+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
62895+ break;
62896+ case GR_FILENAME_TWO_INT_STR:
62897+ dentry = va_arg(ap, struct dentry *);
62898+ mnt = va_arg(ap, struct vfsmount *);
62899+ num1 = va_arg(ap, int);
62900+ num2 = va_arg(ap, int);
62901+ str1 = va_arg(ap, char *);
62902+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
62903+ break;
62904+ case GR_TEXTREL:
62905+ file = va_arg(ap, struct file *);
62906+ ulong1 = va_arg(ap, unsigned long);
62907+ ulong2 = va_arg(ap, unsigned long);
62908+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
62909+ break;
62910+ case GR_PTRACE:
62911+ task = va_arg(ap, struct task_struct *);
62912+ 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);
62913+ break;
62914+ case GR_RESOURCE:
62915+ task = va_arg(ap, struct task_struct *);
62916+ cred = __task_cred(task);
62917+ pcred = __task_cred(task->real_parent);
62918+ ulong1 = va_arg(ap, unsigned long);
62919+ str1 = va_arg(ap, char *);
62920+ ulong2 = va_arg(ap, unsigned long);
62921+ 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);
62922+ break;
62923+ case GR_CAP:
62924+ task = va_arg(ap, struct task_struct *);
62925+ cred = __task_cred(task);
62926+ pcred = __task_cred(task->real_parent);
62927+ str1 = va_arg(ap, char *);
62928+ 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);
62929+ break;
62930+ case GR_SIG:
62931+ str1 = va_arg(ap, char *);
62932+ voidptr = va_arg(ap, void *);
62933+ gr_log_middle_varargs(audit, msg, str1, voidptr);
62934+ break;
62935+ case GR_SIG2:
62936+ task = va_arg(ap, struct task_struct *);
62937+ cred = __task_cred(task);
62938+ pcred = __task_cred(task->real_parent);
62939+ num1 = va_arg(ap, int);
62940+ 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);
62941+ break;
62942+ case GR_CRASH1:
62943+ task = va_arg(ap, struct task_struct *);
62944+ cred = __task_cred(task);
62945+ pcred = __task_cred(task->real_parent);
62946+ ulong1 = va_arg(ap, unsigned long);
62947+ 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);
62948+ break;
62949+ case GR_CRASH2:
62950+ task = va_arg(ap, struct task_struct *);
62951+ cred = __task_cred(task);
62952+ pcred = __task_cred(task->real_parent);
62953+ ulong1 = va_arg(ap, unsigned long);
62954+ 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);
62955+ break;
62956+ case GR_RWXMAP:
62957+ file = va_arg(ap, struct file *);
62958+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
62959+ break;
62960+ case GR_PSACCT:
62961+ {
62962+ unsigned int wday, cday;
62963+ __u8 whr, chr;
62964+ __u8 wmin, cmin;
62965+ __u8 wsec, csec;
62966+ char cur_tty[64] = { 0 };
62967+ char parent_tty[64] = { 0 };
62968+
62969+ task = va_arg(ap, struct task_struct *);
62970+ wday = va_arg(ap, unsigned int);
62971+ cday = va_arg(ap, unsigned int);
62972+ whr = va_arg(ap, int);
62973+ chr = va_arg(ap, int);
62974+ wmin = va_arg(ap, int);
62975+ cmin = va_arg(ap, int);
62976+ wsec = va_arg(ap, int);
62977+ csec = va_arg(ap, int);
62978+ ulong1 = va_arg(ap, unsigned long);
62979+ cred = __task_cred(task);
62980+ pcred = __task_cred(task->real_parent);
62981+
62982+ 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);
62983+ }
62984+ break;
62985+ default:
62986+ gr_log_middle(audit, msg, ap);
62987+ }
62988+ va_end(ap);
62989+ // these don't need DEFAULTSECARGS printed on the end
62990+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
62991+ gr_log_end(audit, 0);
62992+ else
62993+ gr_log_end(audit, 1);
62994+ END_LOCKS(audit);
62995+}
62996diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
62997new file mode 100644
62998index 0000000..6c0416b
62999--- /dev/null
63000+++ b/grsecurity/grsec_mem.c
63001@@ -0,0 +1,33 @@
63002+#include <linux/kernel.h>
63003+#include <linux/sched.h>
63004+#include <linux/mm.h>
63005+#include <linux/mman.h>
63006+#include <linux/grinternal.h>
63007+
63008+void
63009+gr_handle_ioperm(void)
63010+{
63011+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
63012+ return;
63013+}
63014+
63015+void
63016+gr_handle_iopl(void)
63017+{
63018+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
63019+ return;
63020+}
63021+
63022+void
63023+gr_handle_mem_readwrite(u64 from, u64 to)
63024+{
63025+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
63026+ return;
63027+}
63028+
63029+void
63030+gr_handle_vm86(void)
63031+{
63032+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
63033+ return;
63034+}
63035diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
63036new file mode 100644
63037index 0000000..2131422
63038--- /dev/null
63039+++ b/grsecurity/grsec_mount.c
63040@@ -0,0 +1,62 @@
63041+#include <linux/kernel.h>
63042+#include <linux/sched.h>
63043+#include <linux/mount.h>
63044+#include <linux/grsecurity.h>
63045+#include <linux/grinternal.h>
63046+
63047+void
63048+gr_log_remount(const char *devname, const int retval)
63049+{
63050+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63051+ if (grsec_enable_mount && (retval >= 0))
63052+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
63053+#endif
63054+ return;
63055+}
63056+
63057+void
63058+gr_log_unmount(const char *devname, const int retval)
63059+{
63060+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63061+ if (grsec_enable_mount && (retval >= 0))
63062+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
63063+#endif
63064+ return;
63065+}
63066+
63067+void
63068+gr_log_mount(const char *from, const char *to, const int retval)
63069+{
63070+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63071+ if (grsec_enable_mount && (retval >= 0))
63072+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
63073+#endif
63074+ return;
63075+}
63076+
63077+int
63078+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
63079+{
63080+#ifdef CONFIG_GRKERNSEC_ROFS
63081+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
63082+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
63083+ return -EPERM;
63084+ } else
63085+ return 0;
63086+#endif
63087+ return 0;
63088+}
63089+
63090+int
63091+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
63092+{
63093+#ifdef CONFIG_GRKERNSEC_ROFS
63094+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
63095+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
63096+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
63097+ return -EPERM;
63098+ } else
63099+ return 0;
63100+#endif
63101+ return 0;
63102+}
63103diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
63104new file mode 100644
63105index 0000000..a3b12a0
63106--- /dev/null
63107+++ b/grsecurity/grsec_pax.c
63108@@ -0,0 +1,36 @@
63109+#include <linux/kernel.h>
63110+#include <linux/sched.h>
63111+#include <linux/mm.h>
63112+#include <linux/file.h>
63113+#include <linux/grinternal.h>
63114+#include <linux/grsecurity.h>
63115+
63116+void
63117+gr_log_textrel(struct vm_area_struct * vma)
63118+{
63119+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63120+ if (grsec_enable_audit_textrel)
63121+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
63122+#endif
63123+ return;
63124+}
63125+
63126+void
63127+gr_log_rwxmmap(struct file *file)
63128+{
63129+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63130+ if (grsec_enable_log_rwxmaps)
63131+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
63132+#endif
63133+ return;
63134+}
63135+
63136+void
63137+gr_log_rwxmprotect(struct file *file)
63138+{
63139+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63140+ if (grsec_enable_log_rwxmaps)
63141+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
63142+#endif
63143+ return;
63144+}
63145diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
63146new file mode 100644
63147index 0000000..472c1d6
63148--- /dev/null
63149+++ b/grsecurity/grsec_ptrace.c
63150@@ -0,0 +1,14 @@
63151+#include <linux/kernel.h>
63152+#include <linux/sched.h>
63153+#include <linux/grinternal.h>
63154+#include <linux/grsecurity.h>
63155+
63156+void
63157+gr_audit_ptrace(struct task_struct *task)
63158+{
63159+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63160+ if (grsec_enable_audit_ptrace)
63161+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
63162+#endif
63163+ return;
63164+}
63165diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
63166new file mode 100644
63167index 0000000..dc73fe9
63168--- /dev/null
63169+++ b/grsecurity/grsec_sig.c
63170@@ -0,0 +1,205 @@
63171+#include <linux/kernel.h>
63172+#include <linux/sched.h>
63173+#include <linux/delay.h>
63174+#include <linux/grsecurity.h>
63175+#include <linux/grinternal.h>
63176+#include <linux/hardirq.h>
63177+
63178+char *signames[] = {
63179+ [SIGSEGV] = "Segmentation fault",
63180+ [SIGILL] = "Illegal instruction",
63181+ [SIGABRT] = "Abort",
63182+ [SIGBUS] = "Invalid alignment/Bus error"
63183+};
63184+
63185+void
63186+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
63187+{
63188+#ifdef CONFIG_GRKERNSEC_SIGNAL
63189+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
63190+ (sig == SIGABRT) || (sig == SIGBUS))) {
63191+ if (t->pid == current->pid) {
63192+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
63193+ } else {
63194+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
63195+ }
63196+ }
63197+#endif
63198+ return;
63199+}
63200+
63201+int
63202+gr_handle_signal(const struct task_struct *p, const int sig)
63203+{
63204+#ifdef CONFIG_GRKERNSEC
63205+ if (current->pid > 1 && gr_check_protected_task(p)) {
63206+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
63207+ return -EPERM;
63208+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
63209+ return -EPERM;
63210+ }
63211+#endif
63212+ return 0;
63213+}
63214+
63215+#ifdef CONFIG_GRKERNSEC
63216+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
63217+
63218+int gr_fake_force_sig(int sig, struct task_struct *t)
63219+{
63220+ unsigned long int flags;
63221+ int ret, blocked, ignored;
63222+ struct k_sigaction *action;
63223+
63224+ spin_lock_irqsave(&t->sighand->siglock, flags);
63225+ action = &t->sighand->action[sig-1];
63226+ ignored = action->sa.sa_handler == SIG_IGN;
63227+ blocked = sigismember(&t->blocked, sig);
63228+ if (blocked || ignored) {
63229+ action->sa.sa_handler = SIG_DFL;
63230+ if (blocked) {
63231+ sigdelset(&t->blocked, sig);
63232+ recalc_sigpending_and_wake(t);
63233+ }
63234+ }
63235+ if (action->sa.sa_handler == SIG_DFL)
63236+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
63237+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
63238+
63239+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
63240+
63241+ return ret;
63242+}
63243+#endif
63244+
63245+#ifdef CONFIG_GRKERNSEC_BRUTE
63246+#define GR_USER_BAN_TIME (15 * 60)
63247+
63248+static int __get_dumpable(unsigned long mm_flags)
63249+{
63250+ int ret;
63251+
63252+ ret = mm_flags & MMF_DUMPABLE_MASK;
63253+ return (ret >= 2) ? 2 : ret;
63254+}
63255+#endif
63256+
63257+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
63258+{
63259+#ifdef CONFIG_GRKERNSEC_BRUTE
63260+ uid_t uid = 0;
63261+
63262+ if (!grsec_enable_brute)
63263+ return;
63264+
63265+ rcu_read_lock();
63266+ read_lock(&tasklist_lock);
63267+ read_lock(&grsec_exec_file_lock);
63268+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
63269+ p->real_parent->brute = 1;
63270+ else {
63271+ const struct cred *cred = __task_cred(p), *cred2;
63272+ struct task_struct *tsk, *tsk2;
63273+
63274+ if (!__get_dumpable(mm_flags) && cred->uid) {
63275+ struct user_struct *user;
63276+
63277+ uid = cred->uid;
63278+
63279+ /* this is put upon execution past expiration */
63280+ user = find_user(uid);
63281+ if (user == NULL)
63282+ goto unlock;
63283+ user->banned = 1;
63284+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
63285+ if (user->ban_expires == ~0UL)
63286+ user->ban_expires--;
63287+
63288+ do_each_thread(tsk2, tsk) {
63289+ cred2 = __task_cred(tsk);
63290+ if (tsk != p && cred2->uid == uid)
63291+ gr_fake_force_sig(SIGKILL, tsk);
63292+ } while_each_thread(tsk2, tsk);
63293+ }
63294+ }
63295+unlock:
63296+ read_unlock(&grsec_exec_file_lock);
63297+ read_unlock(&tasklist_lock);
63298+ rcu_read_unlock();
63299+
63300+ if (uid)
63301+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
63302+#endif
63303+ return;
63304+}
63305+
63306+void gr_handle_brute_check(void)
63307+{
63308+#ifdef CONFIG_GRKERNSEC_BRUTE
63309+ if (current->brute)
63310+ msleep(30 * 1000);
63311+#endif
63312+ return;
63313+}
63314+
63315+void gr_handle_kernel_exploit(void)
63316+{
63317+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
63318+ const struct cred *cred;
63319+ struct task_struct *tsk, *tsk2;
63320+ struct user_struct *user;
63321+ uid_t uid;
63322+
63323+ if (in_irq() || in_serving_softirq() || in_nmi())
63324+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
63325+
63326+ uid = current_uid();
63327+
63328+ if (uid == 0)
63329+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
63330+ else {
63331+ /* kill all the processes of this user, hold a reference
63332+ to their creds struct, and prevent them from creating
63333+ another process until system reset
63334+ */
63335+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
63336+ /* we intentionally leak this ref */
63337+ user = get_uid(current->cred->user);
63338+ if (user) {
63339+ user->banned = 1;
63340+ user->ban_expires = ~0UL;
63341+ }
63342+
63343+ read_lock(&tasklist_lock);
63344+ do_each_thread(tsk2, tsk) {
63345+ cred = __task_cred(tsk);
63346+ if (cred->uid == uid)
63347+ gr_fake_force_sig(SIGKILL, tsk);
63348+ } while_each_thread(tsk2, tsk);
63349+ read_unlock(&tasklist_lock);
63350+ }
63351+#endif
63352+}
63353+
63354+int __gr_process_user_ban(struct user_struct *user)
63355+{
63356+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63357+ if (unlikely(user->banned)) {
63358+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
63359+ user->banned = 0;
63360+ user->ban_expires = 0;
63361+ free_uid(user);
63362+ } else
63363+ return -EPERM;
63364+ }
63365+#endif
63366+ return 0;
63367+}
63368+
63369+int gr_process_user_ban(void)
63370+{
63371+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63372+ return __gr_process_user_ban(current->cred->user);
63373+#endif
63374+ return 0;
63375+}
63376diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
63377new file mode 100644
63378index 0000000..7512ea9
63379--- /dev/null
63380+++ b/grsecurity/grsec_sock.c
63381@@ -0,0 +1,275 @@
63382+#include <linux/kernel.h>
63383+#include <linux/module.h>
63384+#include <linux/sched.h>
63385+#include <linux/file.h>
63386+#include <linux/net.h>
63387+#include <linux/in.h>
63388+#include <linux/ip.h>
63389+#include <net/sock.h>
63390+#include <net/inet_sock.h>
63391+#include <linux/grsecurity.h>
63392+#include <linux/grinternal.h>
63393+#include <linux/gracl.h>
63394+
63395+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
63396+EXPORT_SYMBOL(gr_cap_rtnetlink);
63397+
63398+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
63399+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
63400+
63401+EXPORT_SYMBOL(gr_search_udp_recvmsg);
63402+EXPORT_SYMBOL(gr_search_udp_sendmsg);
63403+
63404+#ifdef CONFIG_UNIX_MODULE
63405+EXPORT_SYMBOL(gr_acl_handle_unix);
63406+EXPORT_SYMBOL(gr_acl_handle_mknod);
63407+EXPORT_SYMBOL(gr_handle_chroot_unix);
63408+EXPORT_SYMBOL(gr_handle_create);
63409+#endif
63410+
63411+#ifdef CONFIG_GRKERNSEC
63412+#define gr_conn_table_size 32749
63413+struct conn_table_entry {
63414+ struct conn_table_entry *next;
63415+ struct signal_struct *sig;
63416+};
63417+
63418+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
63419+DEFINE_SPINLOCK(gr_conn_table_lock);
63420+
63421+extern const char * gr_socktype_to_name(unsigned char type);
63422+extern const char * gr_proto_to_name(unsigned char proto);
63423+extern const char * gr_sockfamily_to_name(unsigned char family);
63424+
63425+static __inline__ int
63426+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
63427+{
63428+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
63429+}
63430+
63431+static __inline__ int
63432+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
63433+ __u16 sport, __u16 dport)
63434+{
63435+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
63436+ sig->gr_sport == sport && sig->gr_dport == dport))
63437+ return 1;
63438+ else
63439+ return 0;
63440+}
63441+
63442+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
63443+{
63444+ struct conn_table_entry **match;
63445+ unsigned int index;
63446+
63447+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63448+ sig->gr_sport, sig->gr_dport,
63449+ gr_conn_table_size);
63450+
63451+ newent->sig = sig;
63452+
63453+ match = &gr_conn_table[index];
63454+ newent->next = *match;
63455+ *match = newent;
63456+
63457+ return;
63458+}
63459+
63460+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
63461+{
63462+ struct conn_table_entry *match, *last = NULL;
63463+ unsigned int index;
63464+
63465+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63466+ sig->gr_sport, sig->gr_dport,
63467+ gr_conn_table_size);
63468+
63469+ match = gr_conn_table[index];
63470+ while (match && !conn_match(match->sig,
63471+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
63472+ sig->gr_dport)) {
63473+ last = match;
63474+ match = match->next;
63475+ }
63476+
63477+ if (match) {
63478+ if (last)
63479+ last->next = match->next;
63480+ else
63481+ gr_conn_table[index] = NULL;
63482+ kfree(match);
63483+ }
63484+
63485+ return;
63486+}
63487+
63488+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
63489+ __u16 sport, __u16 dport)
63490+{
63491+ struct conn_table_entry *match;
63492+ unsigned int index;
63493+
63494+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
63495+
63496+ match = gr_conn_table[index];
63497+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
63498+ match = match->next;
63499+
63500+ if (match)
63501+ return match->sig;
63502+ else
63503+ return NULL;
63504+}
63505+
63506+#endif
63507+
63508+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
63509+{
63510+#ifdef CONFIG_GRKERNSEC
63511+ struct signal_struct *sig = task->signal;
63512+ struct conn_table_entry *newent;
63513+
63514+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
63515+ if (newent == NULL)
63516+ return;
63517+ /* no bh lock needed since we are called with bh disabled */
63518+ spin_lock(&gr_conn_table_lock);
63519+ gr_del_task_from_ip_table_nolock(sig);
63520+ sig->gr_saddr = inet->rcv_saddr;
63521+ sig->gr_daddr = inet->daddr;
63522+ sig->gr_sport = inet->sport;
63523+ sig->gr_dport = inet->dport;
63524+ gr_add_to_task_ip_table_nolock(sig, newent);
63525+ spin_unlock(&gr_conn_table_lock);
63526+#endif
63527+ return;
63528+}
63529+
63530+void gr_del_task_from_ip_table(struct task_struct *task)
63531+{
63532+#ifdef CONFIG_GRKERNSEC
63533+ spin_lock_bh(&gr_conn_table_lock);
63534+ gr_del_task_from_ip_table_nolock(task->signal);
63535+ spin_unlock_bh(&gr_conn_table_lock);
63536+#endif
63537+ return;
63538+}
63539+
63540+void
63541+gr_attach_curr_ip(const struct sock *sk)
63542+{
63543+#ifdef CONFIG_GRKERNSEC
63544+ struct signal_struct *p, *set;
63545+ const struct inet_sock *inet = inet_sk(sk);
63546+
63547+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
63548+ return;
63549+
63550+ set = current->signal;
63551+
63552+ spin_lock_bh(&gr_conn_table_lock);
63553+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
63554+ inet->dport, inet->sport);
63555+ if (unlikely(p != NULL)) {
63556+ set->curr_ip = p->curr_ip;
63557+ set->used_accept = 1;
63558+ gr_del_task_from_ip_table_nolock(p);
63559+ spin_unlock_bh(&gr_conn_table_lock);
63560+ return;
63561+ }
63562+ spin_unlock_bh(&gr_conn_table_lock);
63563+
63564+ set->curr_ip = inet->daddr;
63565+ set->used_accept = 1;
63566+#endif
63567+ return;
63568+}
63569+
63570+int
63571+gr_handle_sock_all(const int family, const int type, const int protocol)
63572+{
63573+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63574+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
63575+ (family != AF_UNIX)) {
63576+ if (family == AF_INET)
63577+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
63578+ else
63579+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
63580+ return -EACCES;
63581+ }
63582+#endif
63583+ return 0;
63584+}
63585+
63586+int
63587+gr_handle_sock_server(const struct sockaddr *sck)
63588+{
63589+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63590+ if (grsec_enable_socket_server &&
63591+ in_group_p(grsec_socket_server_gid) &&
63592+ sck && (sck->sa_family != AF_UNIX) &&
63593+ (sck->sa_family != AF_LOCAL)) {
63594+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63595+ return -EACCES;
63596+ }
63597+#endif
63598+ return 0;
63599+}
63600+
63601+int
63602+gr_handle_sock_server_other(const struct sock *sck)
63603+{
63604+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63605+ if (grsec_enable_socket_server &&
63606+ in_group_p(grsec_socket_server_gid) &&
63607+ sck && (sck->sk_family != AF_UNIX) &&
63608+ (sck->sk_family != AF_LOCAL)) {
63609+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63610+ return -EACCES;
63611+ }
63612+#endif
63613+ return 0;
63614+}
63615+
63616+int
63617+gr_handle_sock_client(const struct sockaddr *sck)
63618+{
63619+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63620+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
63621+ sck && (sck->sa_family != AF_UNIX) &&
63622+ (sck->sa_family != AF_LOCAL)) {
63623+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
63624+ return -EACCES;
63625+ }
63626+#endif
63627+ return 0;
63628+}
63629+
63630+kernel_cap_t
63631+gr_cap_rtnetlink(struct sock *sock)
63632+{
63633+#ifdef CONFIG_GRKERNSEC
63634+ if (!gr_acl_is_enabled())
63635+ return current_cap();
63636+ else if (sock->sk_protocol == NETLINK_ISCSI &&
63637+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
63638+ gr_is_capable(CAP_SYS_ADMIN))
63639+ return current_cap();
63640+ else if (sock->sk_protocol == NETLINK_AUDIT &&
63641+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
63642+ gr_is_capable(CAP_AUDIT_WRITE) &&
63643+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
63644+ gr_is_capable(CAP_AUDIT_CONTROL))
63645+ return current_cap();
63646+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
63647+ ((sock->sk_protocol == NETLINK_ROUTE) ?
63648+ gr_is_capable_nolog(CAP_NET_ADMIN) :
63649+ gr_is_capable(CAP_NET_ADMIN)))
63650+ return current_cap();
63651+ else
63652+ return __cap_empty_set;
63653+#else
63654+ return current_cap();
63655+#endif
63656+}
63657diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
63658new file mode 100644
63659index 0000000..2753505
63660--- /dev/null
63661+++ b/grsecurity/grsec_sysctl.c
63662@@ -0,0 +1,479 @@
63663+#include <linux/kernel.h>
63664+#include <linux/sched.h>
63665+#include <linux/sysctl.h>
63666+#include <linux/grsecurity.h>
63667+#include <linux/grinternal.h>
63668+
63669+int
63670+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
63671+{
63672+#ifdef CONFIG_GRKERNSEC_SYSCTL
63673+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
63674+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
63675+ return -EACCES;
63676+ }
63677+#endif
63678+ return 0;
63679+}
63680+
63681+#ifdef CONFIG_GRKERNSEC_ROFS
63682+static int __maybe_unused one = 1;
63683+#endif
63684+
63685+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
63686+ctl_table grsecurity_table[] = {
63687+#ifdef CONFIG_GRKERNSEC_SYSCTL
63688+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
63689+#ifdef CONFIG_GRKERNSEC_IO
63690+ {
63691+ .ctl_name = CTL_UNNUMBERED,
63692+ .procname = "disable_priv_io",
63693+ .data = &grsec_disable_privio,
63694+ .maxlen = sizeof(int),
63695+ .mode = 0600,
63696+ .proc_handler = &proc_dointvec,
63697+ },
63698+#endif
63699+#endif
63700+#ifdef CONFIG_GRKERNSEC_LINK
63701+ {
63702+ .ctl_name = CTL_UNNUMBERED,
63703+ .procname = "linking_restrictions",
63704+ .data = &grsec_enable_link,
63705+ .maxlen = sizeof(int),
63706+ .mode = 0600,
63707+ .proc_handler = &proc_dointvec,
63708+ },
63709+#endif
63710+#ifdef CONFIG_GRKERNSEC_BRUTE
63711+ {
63712+ .ctl_name = CTL_UNNUMBERED,
63713+ .procname = "deter_bruteforce",
63714+ .data = &grsec_enable_brute,
63715+ .maxlen = sizeof(int),
63716+ .mode = 0600,
63717+ .proc_handler = &proc_dointvec,
63718+ },
63719+#endif
63720+#ifdef CONFIG_GRKERNSEC_FIFO
63721+ {
63722+ .ctl_name = CTL_UNNUMBERED,
63723+ .procname = "fifo_restrictions",
63724+ .data = &grsec_enable_fifo,
63725+ .maxlen = sizeof(int),
63726+ .mode = 0600,
63727+ .proc_handler = &proc_dointvec,
63728+ },
63729+#endif
63730+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63731+ {
63732+ .ctl_name = CTL_UNNUMBERED,
63733+ .procname = "ip_blackhole",
63734+ .data = &grsec_enable_blackhole,
63735+ .maxlen = sizeof(int),
63736+ .mode = 0600,
63737+ .proc_handler = &proc_dointvec,
63738+ },
63739+ {
63740+ .ctl_name = CTL_UNNUMBERED,
63741+ .procname = "lastack_retries",
63742+ .data = &grsec_lastack_retries,
63743+ .maxlen = sizeof(int),
63744+ .mode = 0600,
63745+ .proc_handler = &proc_dointvec,
63746+ },
63747+#endif
63748+#ifdef CONFIG_GRKERNSEC_EXECLOG
63749+ {
63750+ .ctl_name = CTL_UNNUMBERED,
63751+ .procname = "exec_logging",
63752+ .data = &grsec_enable_execlog,
63753+ .maxlen = sizeof(int),
63754+ .mode = 0600,
63755+ .proc_handler = &proc_dointvec,
63756+ },
63757+#endif
63758+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63759+ {
63760+ .ctl_name = CTL_UNNUMBERED,
63761+ .procname = "rwxmap_logging",
63762+ .data = &grsec_enable_log_rwxmaps,
63763+ .maxlen = sizeof(int),
63764+ .mode = 0600,
63765+ .proc_handler = &proc_dointvec,
63766+ },
63767+#endif
63768+#ifdef CONFIG_GRKERNSEC_SIGNAL
63769+ {
63770+ .ctl_name = CTL_UNNUMBERED,
63771+ .procname = "signal_logging",
63772+ .data = &grsec_enable_signal,
63773+ .maxlen = sizeof(int),
63774+ .mode = 0600,
63775+ .proc_handler = &proc_dointvec,
63776+ },
63777+#endif
63778+#ifdef CONFIG_GRKERNSEC_FORKFAIL
63779+ {
63780+ .ctl_name = CTL_UNNUMBERED,
63781+ .procname = "forkfail_logging",
63782+ .data = &grsec_enable_forkfail,
63783+ .maxlen = sizeof(int),
63784+ .mode = 0600,
63785+ .proc_handler = &proc_dointvec,
63786+ },
63787+#endif
63788+#ifdef CONFIG_GRKERNSEC_TIME
63789+ {
63790+ .ctl_name = CTL_UNNUMBERED,
63791+ .procname = "timechange_logging",
63792+ .data = &grsec_enable_time,
63793+ .maxlen = sizeof(int),
63794+ .mode = 0600,
63795+ .proc_handler = &proc_dointvec,
63796+ },
63797+#endif
63798+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63799+ {
63800+ .ctl_name = CTL_UNNUMBERED,
63801+ .procname = "chroot_deny_shmat",
63802+ .data = &grsec_enable_chroot_shmat,
63803+ .maxlen = sizeof(int),
63804+ .mode = 0600,
63805+ .proc_handler = &proc_dointvec,
63806+ },
63807+#endif
63808+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63809+ {
63810+ .ctl_name = CTL_UNNUMBERED,
63811+ .procname = "chroot_deny_unix",
63812+ .data = &grsec_enable_chroot_unix,
63813+ .maxlen = sizeof(int),
63814+ .mode = 0600,
63815+ .proc_handler = &proc_dointvec,
63816+ },
63817+#endif
63818+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63819+ {
63820+ .ctl_name = CTL_UNNUMBERED,
63821+ .procname = "chroot_deny_mount",
63822+ .data = &grsec_enable_chroot_mount,
63823+ .maxlen = sizeof(int),
63824+ .mode = 0600,
63825+ .proc_handler = &proc_dointvec,
63826+ },
63827+#endif
63828+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63829+ {
63830+ .ctl_name = CTL_UNNUMBERED,
63831+ .procname = "chroot_deny_fchdir",
63832+ .data = &grsec_enable_chroot_fchdir,
63833+ .maxlen = sizeof(int),
63834+ .mode = 0600,
63835+ .proc_handler = &proc_dointvec,
63836+ },
63837+#endif
63838+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63839+ {
63840+ .ctl_name = CTL_UNNUMBERED,
63841+ .procname = "chroot_deny_chroot",
63842+ .data = &grsec_enable_chroot_double,
63843+ .maxlen = sizeof(int),
63844+ .mode = 0600,
63845+ .proc_handler = &proc_dointvec,
63846+ },
63847+#endif
63848+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63849+ {
63850+ .ctl_name = CTL_UNNUMBERED,
63851+ .procname = "chroot_deny_pivot",
63852+ .data = &grsec_enable_chroot_pivot,
63853+ .maxlen = sizeof(int),
63854+ .mode = 0600,
63855+ .proc_handler = &proc_dointvec,
63856+ },
63857+#endif
63858+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63859+ {
63860+ .ctl_name = CTL_UNNUMBERED,
63861+ .procname = "chroot_enforce_chdir",
63862+ .data = &grsec_enable_chroot_chdir,
63863+ .maxlen = sizeof(int),
63864+ .mode = 0600,
63865+ .proc_handler = &proc_dointvec,
63866+ },
63867+#endif
63868+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63869+ {
63870+ .ctl_name = CTL_UNNUMBERED,
63871+ .procname = "chroot_deny_chmod",
63872+ .data = &grsec_enable_chroot_chmod,
63873+ .maxlen = sizeof(int),
63874+ .mode = 0600,
63875+ .proc_handler = &proc_dointvec,
63876+ },
63877+#endif
63878+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63879+ {
63880+ .ctl_name = CTL_UNNUMBERED,
63881+ .procname = "chroot_deny_mknod",
63882+ .data = &grsec_enable_chroot_mknod,
63883+ .maxlen = sizeof(int),
63884+ .mode = 0600,
63885+ .proc_handler = &proc_dointvec,
63886+ },
63887+#endif
63888+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63889+ {
63890+ .ctl_name = CTL_UNNUMBERED,
63891+ .procname = "chroot_restrict_nice",
63892+ .data = &grsec_enable_chroot_nice,
63893+ .maxlen = sizeof(int),
63894+ .mode = 0600,
63895+ .proc_handler = &proc_dointvec,
63896+ },
63897+#endif
63898+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63899+ {
63900+ .ctl_name = CTL_UNNUMBERED,
63901+ .procname = "chroot_execlog",
63902+ .data = &grsec_enable_chroot_execlog,
63903+ .maxlen = sizeof(int),
63904+ .mode = 0600,
63905+ .proc_handler = &proc_dointvec,
63906+ },
63907+#endif
63908+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63909+ {
63910+ .ctl_name = CTL_UNNUMBERED,
63911+ .procname = "chroot_caps",
63912+ .data = &grsec_enable_chroot_caps,
63913+ .maxlen = sizeof(int),
63914+ .mode = 0600,
63915+ .proc_handler = &proc_dointvec,
63916+ },
63917+#endif
63918+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63919+ {
63920+ .ctl_name = CTL_UNNUMBERED,
63921+ .procname = "chroot_deny_sysctl",
63922+ .data = &grsec_enable_chroot_sysctl,
63923+ .maxlen = sizeof(int),
63924+ .mode = 0600,
63925+ .proc_handler = &proc_dointvec,
63926+ },
63927+#endif
63928+#ifdef CONFIG_GRKERNSEC_TPE
63929+ {
63930+ .ctl_name = CTL_UNNUMBERED,
63931+ .procname = "tpe",
63932+ .data = &grsec_enable_tpe,
63933+ .maxlen = sizeof(int),
63934+ .mode = 0600,
63935+ .proc_handler = &proc_dointvec,
63936+ },
63937+ {
63938+ .ctl_name = CTL_UNNUMBERED,
63939+ .procname = "tpe_gid",
63940+ .data = &grsec_tpe_gid,
63941+ .maxlen = sizeof(int),
63942+ .mode = 0600,
63943+ .proc_handler = &proc_dointvec,
63944+ },
63945+#endif
63946+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63947+ {
63948+ .ctl_name = CTL_UNNUMBERED,
63949+ .procname = "tpe_invert",
63950+ .data = &grsec_enable_tpe_invert,
63951+ .maxlen = sizeof(int),
63952+ .mode = 0600,
63953+ .proc_handler = &proc_dointvec,
63954+ },
63955+#endif
63956+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63957+ {
63958+ .ctl_name = CTL_UNNUMBERED,
63959+ .procname = "tpe_restrict_all",
63960+ .data = &grsec_enable_tpe_all,
63961+ .maxlen = sizeof(int),
63962+ .mode = 0600,
63963+ .proc_handler = &proc_dointvec,
63964+ },
63965+#endif
63966+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63967+ {
63968+ .ctl_name = CTL_UNNUMBERED,
63969+ .procname = "socket_all",
63970+ .data = &grsec_enable_socket_all,
63971+ .maxlen = sizeof(int),
63972+ .mode = 0600,
63973+ .proc_handler = &proc_dointvec,
63974+ },
63975+ {
63976+ .ctl_name = CTL_UNNUMBERED,
63977+ .procname = "socket_all_gid",
63978+ .data = &grsec_socket_all_gid,
63979+ .maxlen = sizeof(int),
63980+ .mode = 0600,
63981+ .proc_handler = &proc_dointvec,
63982+ },
63983+#endif
63984+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63985+ {
63986+ .ctl_name = CTL_UNNUMBERED,
63987+ .procname = "socket_client",
63988+ .data = &grsec_enable_socket_client,
63989+ .maxlen = sizeof(int),
63990+ .mode = 0600,
63991+ .proc_handler = &proc_dointvec,
63992+ },
63993+ {
63994+ .ctl_name = CTL_UNNUMBERED,
63995+ .procname = "socket_client_gid",
63996+ .data = &grsec_socket_client_gid,
63997+ .maxlen = sizeof(int),
63998+ .mode = 0600,
63999+ .proc_handler = &proc_dointvec,
64000+ },
64001+#endif
64002+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64003+ {
64004+ .ctl_name = CTL_UNNUMBERED,
64005+ .procname = "socket_server",
64006+ .data = &grsec_enable_socket_server,
64007+ .maxlen = sizeof(int),
64008+ .mode = 0600,
64009+ .proc_handler = &proc_dointvec,
64010+ },
64011+ {
64012+ .ctl_name = CTL_UNNUMBERED,
64013+ .procname = "socket_server_gid",
64014+ .data = &grsec_socket_server_gid,
64015+ .maxlen = sizeof(int),
64016+ .mode = 0600,
64017+ .proc_handler = &proc_dointvec,
64018+ },
64019+#endif
64020+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64021+ {
64022+ .ctl_name = CTL_UNNUMBERED,
64023+ .procname = "audit_group",
64024+ .data = &grsec_enable_group,
64025+ .maxlen = sizeof(int),
64026+ .mode = 0600,
64027+ .proc_handler = &proc_dointvec,
64028+ },
64029+ {
64030+ .ctl_name = CTL_UNNUMBERED,
64031+ .procname = "audit_gid",
64032+ .data = &grsec_audit_gid,
64033+ .maxlen = sizeof(int),
64034+ .mode = 0600,
64035+ .proc_handler = &proc_dointvec,
64036+ },
64037+#endif
64038+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64039+ {
64040+ .ctl_name = CTL_UNNUMBERED,
64041+ .procname = "audit_chdir",
64042+ .data = &grsec_enable_chdir,
64043+ .maxlen = sizeof(int),
64044+ .mode = 0600,
64045+ .proc_handler = &proc_dointvec,
64046+ },
64047+#endif
64048+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64049+ {
64050+ .ctl_name = CTL_UNNUMBERED,
64051+ .procname = "audit_mount",
64052+ .data = &grsec_enable_mount,
64053+ .maxlen = sizeof(int),
64054+ .mode = 0600,
64055+ .proc_handler = &proc_dointvec,
64056+ },
64057+#endif
64058+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64059+ {
64060+ .ctl_name = CTL_UNNUMBERED,
64061+ .procname = "audit_textrel",
64062+ .data = &grsec_enable_audit_textrel,
64063+ .maxlen = sizeof(int),
64064+ .mode = 0600,
64065+ .proc_handler = &proc_dointvec,
64066+ },
64067+#endif
64068+#ifdef CONFIG_GRKERNSEC_DMESG
64069+ {
64070+ .ctl_name = CTL_UNNUMBERED,
64071+ .procname = "dmesg",
64072+ .data = &grsec_enable_dmesg,
64073+ .maxlen = sizeof(int),
64074+ .mode = 0600,
64075+ .proc_handler = &proc_dointvec,
64076+ },
64077+#endif
64078+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64079+ {
64080+ .ctl_name = CTL_UNNUMBERED,
64081+ .procname = "chroot_findtask",
64082+ .data = &grsec_enable_chroot_findtask,
64083+ .maxlen = sizeof(int),
64084+ .mode = 0600,
64085+ .proc_handler = &proc_dointvec,
64086+ },
64087+#endif
64088+#ifdef CONFIG_GRKERNSEC_RESLOG
64089+ {
64090+ .ctl_name = CTL_UNNUMBERED,
64091+ .procname = "resource_logging",
64092+ .data = &grsec_resource_logging,
64093+ .maxlen = sizeof(int),
64094+ .mode = 0600,
64095+ .proc_handler = &proc_dointvec,
64096+ },
64097+#endif
64098+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64099+ {
64100+ .ctl_name = CTL_UNNUMBERED,
64101+ .procname = "audit_ptrace",
64102+ .data = &grsec_enable_audit_ptrace,
64103+ .maxlen = sizeof(int),
64104+ .mode = 0600,
64105+ .proc_handler = &proc_dointvec,
64106+ },
64107+#endif
64108+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64109+ {
64110+ .ctl_name = CTL_UNNUMBERED,
64111+ .procname = "harden_ptrace",
64112+ .data = &grsec_enable_harden_ptrace,
64113+ .maxlen = sizeof(int),
64114+ .mode = 0600,
64115+ .proc_handler = &proc_dointvec,
64116+ },
64117+#endif
64118+ {
64119+ .ctl_name = CTL_UNNUMBERED,
64120+ .procname = "grsec_lock",
64121+ .data = &grsec_lock,
64122+ .maxlen = sizeof(int),
64123+ .mode = 0600,
64124+ .proc_handler = &proc_dointvec,
64125+ },
64126+#endif
64127+#ifdef CONFIG_GRKERNSEC_ROFS
64128+ {
64129+ .ctl_name = CTL_UNNUMBERED,
64130+ .procname = "romount_protect",
64131+ .data = &grsec_enable_rofs,
64132+ .maxlen = sizeof(int),
64133+ .mode = 0600,
64134+ .proc_handler = &proc_dointvec_minmax,
64135+ .extra1 = &one,
64136+ .extra2 = &one,
64137+ },
64138+#endif
64139+ { .ctl_name = 0 }
64140+};
64141+#endif
64142diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
64143new file mode 100644
64144index 0000000..0dc13c3
64145--- /dev/null
64146+++ b/grsecurity/grsec_time.c
64147@@ -0,0 +1,16 @@
64148+#include <linux/kernel.h>
64149+#include <linux/sched.h>
64150+#include <linux/grinternal.h>
64151+#include <linux/module.h>
64152+
64153+void
64154+gr_log_timechange(void)
64155+{
64156+#ifdef CONFIG_GRKERNSEC_TIME
64157+ if (grsec_enable_time)
64158+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
64159+#endif
64160+ return;
64161+}
64162+
64163+EXPORT_SYMBOL(gr_log_timechange);
64164diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
64165new file mode 100644
64166index 0000000..4a78774
64167--- /dev/null
64168+++ b/grsecurity/grsec_tpe.c
64169@@ -0,0 +1,39 @@
64170+#include <linux/kernel.h>
64171+#include <linux/sched.h>
64172+#include <linux/file.h>
64173+#include <linux/fs.h>
64174+#include <linux/grinternal.h>
64175+
64176+extern int gr_acl_tpe_check(void);
64177+
64178+int
64179+gr_tpe_allow(const struct file *file)
64180+{
64181+#ifdef CONFIG_GRKERNSEC
64182+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
64183+ const struct cred *cred = current_cred();
64184+
64185+ if (cred->uid && ((grsec_enable_tpe &&
64186+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64187+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
64188+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
64189+#else
64190+ in_group_p(grsec_tpe_gid)
64191+#endif
64192+ ) || gr_acl_tpe_check()) &&
64193+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
64194+ (inode->i_mode & S_IWOTH))))) {
64195+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64196+ return 0;
64197+ }
64198+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64199+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
64200+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
64201+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
64202+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64203+ return 0;
64204+ }
64205+#endif
64206+#endif
64207+ return 1;
64208+}
64209diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
64210new file mode 100644
64211index 0000000..9f7b1ac
64212--- /dev/null
64213+++ b/grsecurity/grsum.c
64214@@ -0,0 +1,61 @@
64215+#include <linux/err.h>
64216+#include <linux/kernel.h>
64217+#include <linux/sched.h>
64218+#include <linux/mm.h>
64219+#include <linux/scatterlist.h>
64220+#include <linux/crypto.h>
64221+#include <linux/gracl.h>
64222+
64223+
64224+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
64225+#error "crypto and sha256 must be built into the kernel"
64226+#endif
64227+
64228+int
64229+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
64230+{
64231+ char *p;
64232+ struct crypto_hash *tfm;
64233+ struct hash_desc desc;
64234+ struct scatterlist sg;
64235+ unsigned char temp_sum[GR_SHA_LEN];
64236+ volatile int retval = 0;
64237+ volatile int dummy = 0;
64238+ unsigned int i;
64239+
64240+ sg_init_table(&sg, 1);
64241+
64242+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
64243+ if (IS_ERR(tfm)) {
64244+ /* should never happen, since sha256 should be built in */
64245+ return 1;
64246+ }
64247+
64248+ desc.tfm = tfm;
64249+ desc.flags = 0;
64250+
64251+ crypto_hash_init(&desc);
64252+
64253+ p = salt;
64254+ sg_set_buf(&sg, p, GR_SALT_LEN);
64255+ crypto_hash_update(&desc, &sg, sg.length);
64256+
64257+ p = entry->pw;
64258+ sg_set_buf(&sg, p, strlen(p));
64259+
64260+ crypto_hash_update(&desc, &sg, sg.length);
64261+
64262+ crypto_hash_final(&desc, temp_sum);
64263+
64264+ memset(entry->pw, 0, GR_PW_LEN);
64265+
64266+ for (i = 0; i < GR_SHA_LEN; i++)
64267+ if (sum[i] != temp_sum[i])
64268+ retval = 1;
64269+ else
64270+ dummy = 1; // waste a cycle
64271+
64272+ crypto_free_hash(tfm);
64273+
64274+ return retval;
64275+}
64276diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
64277index 3cd9ccd..fe16d47 100644
64278--- a/include/acpi/acpi_bus.h
64279+++ b/include/acpi/acpi_bus.h
64280@@ -107,7 +107,7 @@ struct acpi_device_ops {
64281 acpi_op_bind bind;
64282 acpi_op_unbind unbind;
64283 acpi_op_notify notify;
64284-};
64285+} __no_const;
64286
64287 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
64288
64289diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
64290index f4906f6..71feb73 100644
64291--- a/include/acpi/acpi_drivers.h
64292+++ b/include/acpi/acpi_drivers.h
64293@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type);
64294 Dock Station
64295 -------------------------------------------------------------------------- */
64296 struct acpi_dock_ops {
64297- acpi_notify_handler handler;
64298- acpi_notify_handler uevent;
64299+ const acpi_notify_handler handler;
64300+ const acpi_notify_handler uevent;
64301 };
64302
64303 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
64304@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle handle);
64305 extern int register_dock_notifier(struct notifier_block *nb);
64306 extern void unregister_dock_notifier(struct notifier_block *nb);
64307 extern int register_hotplug_dock_device(acpi_handle handle,
64308- struct acpi_dock_ops *ops,
64309+ const struct acpi_dock_ops *ops,
64310 void *context);
64311 extern void unregister_hotplug_dock_device(acpi_handle handle);
64312 #else
64313@@ -144,7 +144,7 @@ static inline void unregister_dock_notifier(struct notifier_block *nb)
64314 {
64315 }
64316 static inline int register_hotplug_dock_device(acpi_handle handle,
64317- struct acpi_dock_ops *ops,
64318+ const struct acpi_dock_ops *ops,
64319 void *context)
64320 {
64321 return -ENODEV;
64322diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
64323index b7babf0..a9ac9fc 100644
64324--- a/include/asm-generic/atomic-long.h
64325+++ b/include/asm-generic/atomic-long.h
64326@@ -22,6 +22,12 @@
64327
64328 typedef atomic64_t atomic_long_t;
64329
64330+#ifdef CONFIG_PAX_REFCOUNT
64331+typedef atomic64_unchecked_t atomic_long_unchecked_t;
64332+#else
64333+typedef atomic64_t atomic_long_unchecked_t;
64334+#endif
64335+
64336 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
64337
64338 static inline long atomic_long_read(atomic_long_t *l)
64339@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64340 return (long)atomic64_read(v);
64341 }
64342
64343+#ifdef CONFIG_PAX_REFCOUNT
64344+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64345+{
64346+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64347+
64348+ return (long)atomic64_read_unchecked(v);
64349+}
64350+#endif
64351+
64352 static inline void atomic_long_set(atomic_long_t *l, long i)
64353 {
64354 atomic64_t *v = (atomic64_t *)l;
64355@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64356 atomic64_set(v, i);
64357 }
64358
64359+#ifdef CONFIG_PAX_REFCOUNT
64360+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64361+{
64362+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64363+
64364+ atomic64_set_unchecked(v, i);
64365+}
64366+#endif
64367+
64368 static inline void atomic_long_inc(atomic_long_t *l)
64369 {
64370 atomic64_t *v = (atomic64_t *)l;
64371@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64372 atomic64_inc(v);
64373 }
64374
64375+#ifdef CONFIG_PAX_REFCOUNT
64376+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64377+{
64378+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64379+
64380+ atomic64_inc_unchecked(v);
64381+}
64382+#endif
64383+
64384 static inline void atomic_long_dec(atomic_long_t *l)
64385 {
64386 atomic64_t *v = (atomic64_t *)l;
64387@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64388 atomic64_dec(v);
64389 }
64390
64391+#ifdef CONFIG_PAX_REFCOUNT
64392+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64393+{
64394+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64395+
64396+ atomic64_dec_unchecked(v);
64397+}
64398+#endif
64399+
64400 static inline void atomic_long_add(long i, atomic_long_t *l)
64401 {
64402 atomic64_t *v = (atomic64_t *)l;
64403@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64404 atomic64_add(i, v);
64405 }
64406
64407+#ifdef CONFIG_PAX_REFCOUNT
64408+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64409+{
64410+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64411+
64412+ atomic64_add_unchecked(i, v);
64413+}
64414+#endif
64415+
64416 static inline void atomic_long_sub(long i, atomic_long_t *l)
64417 {
64418 atomic64_t *v = (atomic64_t *)l;
64419@@ -115,6 +166,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64420 return (long)atomic64_inc_return(v);
64421 }
64422
64423+#ifdef CONFIG_PAX_REFCOUNT
64424+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64425+{
64426+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64427+
64428+ return (long)atomic64_inc_return_unchecked(v);
64429+}
64430+#endif
64431+
64432 static inline long atomic_long_dec_return(atomic_long_t *l)
64433 {
64434 atomic64_t *v = (atomic64_t *)l;
64435@@ -140,6 +200,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64436
64437 typedef atomic_t atomic_long_t;
64438
64439+#ifdef CONFIG_PAX_REFCOUNT
64440+typedef atomic_unchecked_t atomic_long_unchecked_t;
64441+#else
64442+typedef atomic_t atomic_long_unchecked_t;
64443+#endif
64444+
64445 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
64446 static inline long atomic_long_read(atomic_long_t *l)
64447 {
64448@@ -148,6 +214,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64449 return (long)atomic_read(v);
64450 }
64451
64452+#ifdef CONFIG_PAX_REFCOUNT
64453+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64454+{
64455+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64456+
64457+ return (long)atomic_read_unchecked(v);
64458+}
64459+#endif
64460+
64461 static inline void atomic_long_set(atomic_long_t *l, long i)
64462 {
64463 atomic_t *v = (atomic_t *)l;
64464@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64465 atomic_set(v, i);
64466 }
64467
64468+#ifdef CONFIG_PAX_REFCOUNT
64469+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64470+{
64471+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64472+
64473+ atomic_set_unchecked(v, i);
64474+}
64475+#endif
64476+
64477 static inline void atomic_long_inc(atomic_long_t *l)
64478 {
64479 atomic_t *v = (atomic_t *)l;
64480@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64481 atomic_inc(v);
64482 }
64483
64484+#ifdef CONFIG_PAX_REFCOUNT
64485+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64486+{
64487+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64488+
64489+ atomic_inc_unchecked(v);
64490+}
64491+#endif
64492+
64493 static inline void atomic_long_dec(atomic_long_t *l)
64494 {
64495 atomic_t *v = (atomic_t *)l;
64496@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64497 atomic_dec(v);
64498 }
64499
64500+#ifdef CONFIG_PAX_REFCOUNT
64501+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64502+{
64503+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64504+
64505+ atomic_dec_unchecked(v);
64506+}
64507+#endif
64508+
64509 static inline void atomic_long_add(long i, atomic_long_t *l)
64510 {
64511 atomic_t *v = (atomic_t *)l;
64512@@ -176,6 +278,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64513 atomic_add(i, v);
64514 }
64515
64516+#ifdef CONFIG_PAX_REFCOUNT
64517+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64518+{
64519+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64520+
64521+ atomic_add_unchecked(i, v);
64522+}
64523+#endif
64524+
64525 static inline void atomic_long_sub(long i, atomic_long_t *l)
64526 {
64527 atomic_t *v = (atomic_t *)l;
64528@@ -232,6 +343,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64529 return (long)atomic_inc_return(v);
64530 }
64531
64532+#ifdef CONFIG_PAX_REFCOUNT
64533+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64534+{
64535+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64536+
64537+ return (long)atomic_inc_return_unchecked(v);
64538+}
64539+#endif
64540+
64541 static inline long atomic_long_dec_return(atomic_long_t *l)
64542 {
64543 atomic_t *v = (atomic_t *)l;
64544@@ -255,4 +375,47 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64545
64546 #endif /* BITS_PER_LONG == 64 */
64547
64548+#ifdef CONFIG_PAX_REFCOUNT
64549+static inline void pax_refcount_needs_these_functions(void)
64550+{
64551+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
64552+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
64553+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
64554+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
64555+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
64556+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
64557+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
64558+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
64559+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
64560+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
64561+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
64562+
64563+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
64564+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
64565+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
64566+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
64567+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
64568+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
64569+}
64570+#else
64571+#define atomic_read_unchecked(v) atomic_read(v)
64572+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
64573+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
64574+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
64575+#define atomic_inc_unchecked(v) atomic_inc(v)
64576+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
64577+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
64578+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
64579+#define atomic_dec_unchecked(v) atomic_dec(v)
64580+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
64581+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
64582+
64583+#define atomic_long_read_unchecked(v) atomic_long_read(v)
64584+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
64585+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
64586+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
64587+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
64588+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
64589+#endif
64590+
64591 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
64592diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
64593index b18ce4f..2ee2843 100644
64594--- a/include/asm-generic/atomic64.h
64595+++ b/include/asm-generic/atomic64.h
64596@@ -16,6 +16,8 @@ typedef struct {
64597 long long counter;
64598 } atomic64_t;
64599
64600+typedef atomic64_t atomic64_unchecked_t;
64601+
64602 #define ATOMIC64_INIT(i) { (i) }
64603
64604 extern long long atomic64_read(const atomic64_t *v);
64605@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
64606 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
64607 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
64608
64609+#define atomic64_read_unchecked(v) atomic64_read(v)
64610+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
64611+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
64612+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
64613+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
64614+#define atomic64_inc_unchecked(v) atomic64_inc(v)
64615+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
64616+#define atomic64_dec_unchecked(v) atomic64_dec(v)
64617+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
64618+
64619 #endif /* _ASM_GENERIC_ATOMIC64_H */
64620diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
64621index d48ddf0..656a0ac 100644
64622--- a/include/asm-generic/bug.h
64623+++ b/include/asm-generic/bug.h
64624@@ -105,11 +105,11 @@ extern void warn_slowpath_null(const char *file, const int line);
64625
64626 #else /* !CONFIG_BUG */
64627 #ifndef HAVE_ARCH_BUG
64628-#define BUG() do {} while(0)
64629+#define BUG() do { for (;;) ; } while(0)
64630 #endif
64631
64632 #ifndef HAVE_ARCH_BUG_ON
64633-#define BUG_ON(condition) do { if (condition) ; } while(0)
64634+#define BUG_ON(condition) do { if (condition) for (;;) ; } while(0)
64635 #endif
64636
64637 #ifndef HAVE_ARCH_WARN_ON
64638diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
64639index 1bfcfe5..e04c5c9 100644
64640--- a/include/asm-generic/cache.h
64641+++ b/include/asm-generic/cache.h
64642@@ -6,7 +6,7 @@
64643 * cache lines need to provide their own cache.h.
64644 */
64645
64646-#define L1_CACHE_SHIFT 5
64647-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
64648+#define L1_CACHE_SHIFT 5UL
64649+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
64650
64651 #endif /* __ASM_GENERIC_CACHE_H */
64652diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
64653index 6920695..41038bc 100644
64654--- a/include/asm-generic/dma-mapping-common.h
64655+++ b/include/asm-generic/dma-mapping-common.h
64656@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
64657 enum dma_data_direction dir,
64658 struct dma_attrs *attrs)
64659 {
64660- struct dma_map_ops *ops = get_dma_ops(dev);
64661+ const struct dma_map_ops *ops = get_dma_ops(dev);
64662 dma_addr_t addr;
64663
64664 kmemcheck_mark_initialized(ptr, size);
64665@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
64666 enum dma_data_direction dir,
64667 struct dma_attrs *attrs)
64668 {
64669- struct dma_map_ops *ops = get_dma_ops(dev);
64670+ const struct dma_map_ops *ops = get_dma_ops(dev);
64671
64672 BUG_ON(!valid_dma_direction(dir));
64673 if (ops->unmap_page)
64674@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
64675 int nents, enum dma_data_direction dir,
64676 struct dma_attrs *attrs)
64677 {
64678- struct dma_map_ops *ops = get_dma_ops(dev);
64679+ const struct dma_map_ops *ops = get_dma_ops(dev);
64680 int i, ents;
64681 struct scatterlist *s;
64682
64683@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg
64684 int nents, enum dma_data_direction dir,
64685 struct dma_attrs *attrs)
64686 {
64687- struct dma_map_ops *ops = get_dma_ops(dev);
64688+ const struct dma_map_ops *ops = get_dma_ops(dev);
64689
64690 BUG_ON(!valid_dma_direction(dir));
64691 debug_dma_unmap_sg(dev, sg, nents, dir);
64692@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64693 size_t offset, size_t size,
64694 enum dma_data_direction dir)
64695 {
64696- struct dma_map_ops *ops = get_dma_ops(dev);
64697+ const struct dma_map_ops *ops = get_dma_ops(dev);
64698 dma_addr_t addr;
64699
64700 kmemcheck_mark_initialized(page_address(page) + offset, size);
64701@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64702 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
64703 size_t size, enum dma_data_direction dir)
64704 {
64705- struct dma_map_ops *ops = get_dma_ops(dev);
64706+ const struct dma_map_ops *ops = get_dma_ops(dev);
64707
64708 BUG_ON(!valid_dma_direction(dir));
64709 if (ops->unmap_page)
64710@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
64711 size_t size,
64712 enum dma_data_direction dir)
64713 {
64714- struct dma_map_ops *ops = get_dma_ops(dev);
64715+ const struct dma_map_ops *ops = get_dma_ops(dev);
64716
64717 BUG_ON(!valid_dma_direction(dir));
64718 if (ops->sync_single_for_cpu)
64719@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_device(struct device *dev,
64720 dma_addr_t addr, size_t size,
64721 enum dma_data_direction dir)
64722 {
64723- struct dma_map_ops *ops = get_dma_ops(dev);
64724+ const struct dma_map_ops *ops = get_dma_ops(dev);
64725
64726 BUG_ON(!valid_dma_direction(dir));
64727 if (ops->sync_single_for_device)
64728@@ -123,7 +123,7 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
64729 size_t size,
64730 enum dma_data_direction dir)
64731 {
64732- struct dma_map_ops *ops = get_dma_ops(dev);
64733+ const struct dma_map_ops *ops = get_dma_ops(dev);
64734
64735 BUG_ON(!valid_dma_direction(dir));
64736 if (ops->sync_single_range_for_cpu) {
64737@@ -140,7 +140,7 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
64738 size_t size,
64739 enum dma_data_direction dir)
64740 {
64741- struct dma_map_ops *ops = get_dma_ops(dev);
64742+ const struct dma_map_ops *ops = get_dma_ops(dev);
64743
64744 BUG_ON(!valid_dma_direction(dir));
64745 if (ops->sync_single_range_for_device) {
64746@@ -155,7 +155,7 @@ static inline void
64747 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
64748 int nelems, enum dma_data_direction dir)
64749 {
64750- struct dma_map_ops *ops = get_dma_ops(dev);
64751+ const struct dma_map_ops *ops = get_dma_ops(dev);
64752
64753 BUG_ON(!valid_dma_direction(dir));
64754 if (ops->sync_sg_for_cpu)
64755@@ -167,7 +167,7 @@ static inline void
64756 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
64757 int nelems, enum dma_data_direction dir)
64758 {
64759- struct dma_map_ops *ops = get_dma_ops(dev);
64760+ const struct dma_map_ops *ops = get_dma_ops(dev);
64761
64762 BUG_ON(!valid_dma_direction(dir));
64763 if (ops->sync_sg_for_device)
64764diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
64765index 0d68a1e..b74a761 100644
64766--- a/include/asm-generic/emergency-restart.h
64767+++ b/include/asm-generic/emergency-restart.h
64768@@ -1,7 +1,7 @@
64769 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
64770 #define _ASM_GENERIC_EMERGENCY_RESTART_H
64771
64772-static inline void machine_emergency_restart(void)
64773+static inline __noreturn void machine_emergency_restart(void)
64774 {
64775 machine_restart(NULL);
64776 }
64777diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
64778index 3c2344f..4590a7d 100644
64779--- a/include/asm-generic/futex.h
64780+++ b/include/asm-generic/futex.h
64781@@ -6,7 +6,7 @@
64782 #include <asm/errno.h>
64783
64784 static inline int
64785-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
64786+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
64787 {
64788 int op = (encoded_op >> 28) & 7;
64789 int cmp = (encoded_op >> 24) & 15;
64790@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
64791 }
64792
64793 static inline int
64794-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
64795+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
64796 {
64797 return -ENOSYS;
64798 }
64799diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
64800index 1ca3efc..e3dc852 100644
64801--- a/include/asm-generic/int-l64.h
64802+++ b/include/asm-generic/int-l64.h
64803@@ -46,6 +46,8 @@ typedef unsigned int u32;
64804 typedef signed long s64;
64805 typedef unsigned long u64;
64806
64807+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
64808+
64809 #define S8_C(x) x
64810 #define U8_C(x) x ## U
64811 #define S16_C(x) x
64812diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
64813index f394147..b6152b9 100644
64814--- a/include/asm-generic/int-ll64.h
64815+++ b/include/asm-generic/int-ll64.h
64816@@ -51,6 +51,8 @@ typedef unsigned int u32;
64817 typedef signed long long s64;
64818 typedef unsigned long long u64;
64819
64820+typedef unsigned long long intoverflow_t;
64821+
64822 #define S8_C(x) x
64823 #define U8_C(x) x ## U
64824 #define S16_C(x) x
64825diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
64826index e5f234a..cdb16b3 100644
64827--- a/include/asm-generic/kmap_types.h
64828+++ b/include/asm-generic/kmap_types.h
64829@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
64830 KMAP_D(16) KM_IRQ_PTE,
64831 KMAP_D(17) KM_NMI,
64832 KMAP_D(18) KM_NMI_PTE,
64833-KMAP_D(19) KM_TYPE_NR
64834+KMAP_D(19) KM_CLEARPAGE,
64835+KMAP_D(20) KM_TYPE_NR
64836 };
64837
64838 #undef KMAP_D
64839diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
64840index 725612b..9cc513a 100644
64841--- a/include/asm-generic/pgtable-nopmd.h
64842+++ b/include/asm-generic/pgtable-nopmd.h
64843@@ -1,14 +1,19 @@
64844 #ifndef _PGTABLE_NOPMD_H
64845 #define _PGTABLE_NOPMD_H
64846
64847-#ifndef __ASSEMBLY__
64848-
64849 #include <asm-generic/pgtable-nopud.h>
64850
64851-struct mm_struct;
64852-
64853 #define __PAGETABLE_PMD_FOLDED
64854
64855+#define PMD_SHIFT PUD_SHIFT
64856+#define PTRS_PER_PMD 1
64857+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
64858+#define PMD_MASK (~(PMD_SIZE-1))
64859+
64860+#ifndef __ASSEMBLY__
64861+
64862+struct mm_struct;
64863+
64864 /*
64865 * Having the pmd type consist of a pud gets the size right, and allows
64866 * us to conceptually access the pud entry that this pmd is folded into
64867@@ -16,11 +21,6 @@ struct mm_struct;
64868 */
64869 typedef struct { pud_t pud; } pmd_t;
64870
64871-#define PMD_SHIFT PUD_SHIFT
64872-#define PTRS_PER_PMD 1
64873-#define PMD_SIZE (1UL << PMD_SHIFT)
64874-#define PMD_MASK (~(PMD_SIZE-1))
64875-
64876 /*
64877 * The "pud_xxx()" functions here are trivial for a folded two-level
64878 * setup: the pmd is never bad, and a pmd always exists (as it's folded
64879diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
64880index 810431d..ccc3638 100644
64881--- a/include/asm-generic/pgtable-nopud.h
64882+++ b/include/asm-generic/pgtable-nopud.h
64883@@ -1,10 +1,15 @@
64884 #ifndef _PGTABLE_NOPUD_H
64885 #define _PGTABLE_NOPUD_H
64886
64887-#ifndef __ASSEMBLY__
64888-
64889 #define __PAGETABLE_PUD_FOLDED
64890
64891+#define PUD_SHIFT PGDIR_SHIFT
64892+#define PTRS_PER_PUD 1
64893+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
64894+#define PUD_MASK (~(PUD_SIZE-1))
64895+
64896+#ifndef __ASSEMBLY__
64897+
64898 /*
64899 * Having the pud type consist of a pgd gets the size right, and allows
64900 * us to conceptually access the pgd entry that this pud is folded into
64901@@ -12,11 +17,6 @@
64902 */
64903 typedef struct { pgd_t pgd; } pud_t;
64904
64905-#define PUD_SHIFT PGDIR_SHIFT
64906-#define PTRS_PER_PUD 1
64907-#define PUD_SIZE (1UL << PUD_SHIFT)
64908-#define PUD_MASK (~(PUD_SIZE-1))
64909-
64910 /*
64911 * The "pgd_xxx()" functions here are trivial for a folded two-level
64912 * setup: the pud is never bad, and a pud always exists (as it's folded
64913diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
64914index e2bd73e..fea8ed3 100644
64915--- a/include/asm-generic/pgtable.h
64916+++ b/include/asm-generic/pgtable.h
64917@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_area_struct *vma, unsigned long pfn,
64918 unsigned long size);
64919 #endif
64920
64921+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
64922+static inline unsigned long pax_open_kernel(void) { return 0; }
64923+#endif
64924+
64925+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
64926+static inline unsigned long pax_close_kernel(void) { return 0; }
64927+#endif
64928+
64929 #endif /* !__ASSEMBLY__ */
64930
64931 #endif /* _ASM_GENERIC_PGTABLE_H */
64932diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
64933index b6e818f..21aa58a 100644
64934--- a/include/asm-generic/vmlinux.lds.h
64935+++ b/include/asm-generic/vmlinux.lds.h
64936@@ -199,6 +199,7 @@
64937 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
64938 VMLINUX_SYMBOL(__start_rodata) = .; \
64939 *(.rodata) *(.rodata.*) \
64940+ *(.data.read_only) \
64941 *(__vermagic) /* Kernel version magic */ \
64942 *(__markers_strings) /* Markers: strings */ \
64943 *(__tracepoints_strings)/* Tracepoints: strings */ \
64944@@ -656,22 +657,24 @@
64945 * section in the linker script will go there too. @phdr should have
64946 * a leading colon.
64947 *
64948- * Note that this macros defines __per_cpu_load as an absolute symbol.
64949+ * Note that this macros defines per_cpu_load as an absolute symbol.
64950 * If there is no need to put the percpu section at a predetermined
64951 * address, use PERCPU().
64952 */
64953 #define PERCPU_VADDR(vaddr, phdr) \
64954- VMLINUX_SYMBOL(__per_cpu_load) = .; \
64955- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
64956+ per_cpu_load = .; \
64957+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
64958 - LOAD_OFFSET) { \
64959+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
64960 VMLINUX_SYMBOL(__per_cpu_start) = .; \
64961 *(.data.percpu.first) \
64962- *(.data.percpu.page_aligned) \
64963 *(.data.percpu) \
64964+ . = ALIGN(PAGE_SIZE); \
64965+ *(.data.percpu.page_aligned) \
64966 *(.data.percpu.shared_aligned) \
64967 VMLINUX_SYMBOL(__per_cpu_end) = .; \
64968 } phdr \
64969- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
64970+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
64971
64972 /**
64973 * PERCPU - define output section for percpu area, simple version
64974diff --git a/include/drm/drmP.h b/include/drm/drmP.h
64975index 66713c6..98c0460 100644
64976--- a/include/drm/drmP.h
64977+++ b/include/drm/drmP.h
64978@@ -71,6 +71,7 @@
64979 #include <linux/workqueue.h>
64980 #include <linux/poll.h>
64981 #include <asm/pgalloc.h>
64982+#include <asm/local.h>
64983 #include "drm.h"
64984
64985 #include <linux/idr.h>
64986@@ -814,7 +815,7 @@ struct drm_driver {
64987 void (*vgaarb_irq)(struct drm_device *dev, bool state);
64988
64989 /* Driver private ops for this object */
64990- struct vm_operations_struct *gem_vm_ops;
64991+ const struct vm_operations_struct *gem_vm_ops;
64992
64993 int major;
64994 int minor;
64995@@ -917,7 +918,7 @@ struct drm_device {
64996
64997 /** \name Usage Counters */
64998 /*@{ */
64999- int open_count; /**< Outstanding files open */
65000+ local_t open_count; /**< Outstanding files open */
65001 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
65002 atomic_t vma_count; /**< Outstanding vma areas open */
65003 int buf_use; /**< Buffers in use -- cannot alloc */
65004@@ -928,7 +929,7 @@ struct drm_device {
65005 /*@{ */
65006 unsigned long counters;
65007 enum drm_stat_type types[15];
65008- atomic_t counts[15];
65009+ atomic_unchecked_t counts[15];
65010 /*@} */
65011
65012 struct list_head filelist;
65013@@ -1016,7 +1017,7 @@ struct drm_device {
65014 struct pci_controller *hose;
65015 #endif
65016 struct drm_sg_mem *sg; /**< Scatter gather memory */
65017- unsigned int num_crtcs; /**< Number of CRTCs on this device */
65018+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
65019 void *dev_private; /**< device private data */
65020 void *mm_private;
65021 struct address_space *dev_mapping;
65022@@ -1042,11 +1043,11 @@ struct drm_device {
65023 spinlock_t object_name_lock;
65024 struct idr object_name_idr;
65025 atomic_t object_count;
65026- atomic_t object_memory;
65027+ atomic_unchecked_t object_memory;
65028 atomic_t pin_count;
65029- atomic_t pin_memory;
65030+ atomic_unchecked_t pin_memory;
65031 atomic_t gtt_count;
65032- atomic_t gtt_memory;
65033+ atomic_unchecked_t gtt_memory;
65034 uint32_t gtt_total;
65035 uint32_t invalidate_domains; /* domains pending invalidation */
65036 uint32_t flush_domains; /* domains pending flush */
65037diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
65038index b29e201..3413cc9 100644
65039--- a/include/drm/drm_crtc_helper.h
65040+++ b/include/drm/drm_crtc_helper.h
65041@@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
65042
65043 /* reload the current crtc LUT */
65044 void (*load_lut)(struct drm_crtc *crtc);
65045-};
65046+} __no_const;
65047
65048 struct drm_encoder_helper_funcs {
65049 void (*dpms)(struct drm_encoder *encoder, int mode);
65050@@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
65051 struct drm_connector *connector);
65052 /* disable encoder when not in use - more explicit than dpms off */
65053 void (*disable)(struct drm_encoder *encoder);
65054-};
65055+} __no_const;
65056
65057 struct drm_connector_helper_funcs {
65058 int (*get_modes)(struct drm_connector *connector);
65059diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
65060index b199170..6f9e64c 100644
65061--- a/include/drm/ttm/ttm_memory.h
65062+++ b/include/drm/ttm/ttm_memory.h
65063@@ -47,7 +47,7 @@
65064
65065 struct ttm_mem_shrink {
65066 int (*do_shrink) (struct ttm_mem_shrink *);
65067-};
65068+} __no_const;
65069
65070 /**
65071 * struct ttm_mem_global - Global memory accounting structure.
65072diff --git a/include/linux/a.out.h b/include/linux/a.out.h
65073index e86dfca..40cc55f 100644
65074--- a/include/linux/a.out.h
65075+++ b/include/linux/a.out.h
65076@@ -39,6 +39,14 @@ enum machine_type {
65077 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65078 };
65079
65080+/* Constants for the N_FLAGS field */
65081+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65082+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65083+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65084+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65085+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65086+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65087+
65088 #if !defined (N_MAGIC)
65089 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65090 #endif
65091diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
65092index 817b237..62c10bc 100644
65093--- a/include/linux/atmdev.h
65094+++ b/include/linux/atmdev.h
65095@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
65096 #endif
65097
65098 struct k_atm_aal_stats {
65099-#define __HANDLE_ITEM(i) atomic_t i
65100+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65101 __AAL_STAT_ITEMS
65102 #undef __HANDLE_ITEM
65103 };
65104diff --git a/include/linux/backlight.h b/include/linux/backlight.h
65105index 0f5f578..8c4f884 100644
65106--- a/include/linux/backlight.h
65107+++ b/include/linux/backlight.h
65108@@ -36,18 +36,18 @@ struct backlight_device;
65109 struct fb_info;
65110
65111 struct backlight_ops {
65112- unsigned int options;
65113+ const unsigned int options;
65114
65115 #define BL_CORE_SUSPENDRESUME (1 << 0)
65116
65117 /* Notify the backlight driver some property has changed */
65118- int (*update_status)(struct backlight_device *);
65119+ int (* const update_status)(struct backlight_device *);
65120 /* Return the current backlight brightness (accounting for power,
65121 fb_blank etc.) */
65122- int (*get_brightness)(struct backlight_device *);
65123+ int (* const get_brightness)(struct backlight_device *);
65124 /* Check if given framebuffer device is the one bound to this backlight;
65125 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
65126- int (*check_fb)(struct fb_info *);
65127+ int (* const check_fb)(struct fb_info *);
65128 };
65129
65130 /* This structure defines all the properties of a backlight */
65131@@ -86,7 +86,7 @@ struct backlight_device {
65132 registered this device has been unloaded, and if class_get_devdata()
65133 points to something in the body of that driver, it is also invalid. */
65134 struct mutex ops_lock;
65135- struct backlight_ops *ops;
65136+ const struct backlight_ops *ops;
65137
65138 /* The framebuffer notifier block */
65139 struct notifier_block fb_notif;
65140@@ -103,7 +103,7 @@ static inline void backlight_update_status(struct backlight_device *bd)
65141 }
65142
65143 extern struct backlight_device *backlight_device_register(const char *name,
65144- struct device *dev, void *devdata, struct backlight_ops *ops);
65145+ struct device *dev, void *devdata, const struct backlight_ops *ops);
65146 extern void backlight_device_unregister(struct backlight_device *bd);
65147 extern void backlight_force_update(struct backlight_device *bd,
65148 enum backlight_update_reason reason);
65149diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
65150index a3d802e..482f69c 100644
65151--- a/include/linux/binfmts.h
65152+++ b/include/linux/binfmts.h
65153@@ -83,6 +83,7 @@ struct linux_binfmt {
65154 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
65155 int (*load_shlib)(struct file *);
65156 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
65157+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
65158 unsigned long min_coredump; /* minimal dump size */
65159 int hasvdso;
65160 };
65161diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
65162index a06bfab..4fa38bb 100644
65163--- a/include/linux/blkdev.h
65164+++ b/include/linux/blkdev.h
65165@@ -1278,7 +1278,7 @@ struct block_device_operations {
65166 int (*revalidate_disk) (struct gendisk *);
65167 int (*getgeo)(struct block_device *, struct hd_geometry *);
65168 struct module *owner;
65169-};
65170+} __do_const;
65171
65172 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
65173 unsigned long);
65174diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
65175index 3b73b99..629d21b 100644
65176--- a/include/linux/blktrace_api.h
65177+++ b/include/linux/blktrace_api.h
65178@@ -160,7 +160,7 @@ struct blk_trace {
65179 struct dentry *dir;
65180 struct dentry *dropped_file;
65181 struct dentry *msg_file;
65182- atomic_t dropped;
65183+ atomic_unchecked_t dropped;
65184 };
65185
65186 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
65187diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
65188index 83195fb..0b0f77d 100644
65189--- a/include/linux/byteorder/little_endian.h
65190+++ b/include/linux/byteorder/little_endian.h
65191@@ -42,51 +42,51 @@
65192
65193 static inline __le64 __cpu_to_le64p(const __u64 *p)
65194 {
65195- return (__force __le64)*p;
65196+ return (__force const __le64)*p;
65197 }
65198 static inline __u64 __le64_to_cpup(const __le64 *p)
65199 {
65200- return (__force __u64)*p;
65201+ return (__force const __u64)*p;
65202 }
65203 static inline __le32 __cpu_to_le32p(const __u32 *p)
65204 {
65205- return (__force __le32)*p;
65206+ return (__force const __le32)*p;
65207 }
65208 static inline __u32 __le32_to_cpup(const __le32 *p)
65209 {
65210- return (__force __u32)*p;
65211+ return (__force const __u32)*p;
65212 }
65213 static inline __le16 __cpu_to_le16p(const __u16 *p)
65214 {
65215- return (__force __le16)*p;
65216+ return (__force const __le16)*p;
65217 }
65218 static inline __u16 __le16_to_cpup(const __le16 *p)
65219 {
65220- return (__force __u16)*p;
65221+ return (__force const __u16)*p;
65222 }
65223 static inline __be64 __cpu_to_be64p(const __u64 *p)
65224 {
65225- return (__force __be64)__swab64p(p);
65226+ return (__force const __be64)__swab64p(p);
65227 }
65228 static inline __u64 __be64_to_cpup(const __be64 *p)
65229 {
65230- return __swab64p((__u64 *)p);
65231+ return __swab64p((const __u64 *)p);
65232 }
65233 static inline __be32 __cpu_to_be32p(const __u32 *p)
65234 {
65235- return (__force __be32)__swab32p(p);
65236+ return (__force const __be32)__swab32p(p);
65237 }
65238 static inline __u32 __be32_to_cpup(const __be32 *p)
65239 {
65240- return __swab32p((__u32 *)p);
65241+ return __swab32p((const __u32 *)p);
65242 }
65243 static inline __be16 __cpu_to_be16p(const __u16 *p)
65244 {
65245- return (__force __be16)__swab16p(p);
65246+ return (__force const __be16)__swab16p(p);
65247 }
65248 static inline __u16 __be16_to_cpup(const __be16 *p)
65249 {
65250- return __swab16p((__u16 *)p);
65251+ return __swab16p((const __u16 *)p);
65252 }
65253 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65254 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65255diff --git a/include/linux/cache.h b/include/linux/cache.h
65256index 97e2488..e7576b9 100644
65257--- a/include/linux/cache.h
65258+++ b/include/linux/cache.h
65259@@ -16,6 +16,10 @@
65260 #define __read_mostly
65261 #endif
65262
65263+#ifndef __read_only
65264+#define __read_only __read_mostly
65265+#endif
65266+
65267 #ifndef ____cacheline_aligned
65268 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
65269 #endif
65270diff --git a/include/linux/capability.h b/include/linux/capability.h
65271index c8f2a5f7..1618a5c 100644
65272--- a/include/linux/capability.h
65273+++ b/include/linux/capability.h
65274@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff_set;
65275 (security_real_capable_noaudit((t), (cap)) == 0)
65276
65277 extern int capable(int cap);
65278+int capable_nolog(int cap);
65279
65280 /* audit system wants to get cap info from files as well */
65281 struct dentry;
65282diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
65283index 450fa59..86019fb 100644
65284--- a/include/linux/compiler-gcc4.h
65285+++ b/include/linux/compiler-gcc4.h
65286@@ -36,4 +36,16 @@
65287 the kernel context */
65288 #define __cold __attribute__((__cold__))
65289
65290+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
65291+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
65292+#define __bos0(ptr) __bos((ptr), 0)
65293+#define __bos1(ptr) __bos((ptr), 1)
65294+
65295+#if __GNUC_MINOR__ >= 5
65296+#ifdef CONSTIFY_PLUGIN
65297+#define __no_const __attribute__((no_const))
65298+#define __do_const __attribute__((do_const))
65299+#endif
65300+#endif
65301+
65302 #endif
65303diff --git a/include/linux/compiler.h b/include/linux/compiler.h
65304index 04fb513..fd6477b 100644
65305--- a/include/linux/compiler.h
65306+++ b/include/linux/compiler.h
65307@@ -5,11 +5,14 @@
65308
65309 #ifdef __CHECKER__
65310 # define __user __attribute__((noderef, address_space(1)))
65311+# define __force_user __force __user
65312 # define __kernel /* default address space */
65313+# define __force_kernel __force __kernel
65314 # define __safe __attribute__((safe))
65315 # define __force __attribute__((force))
65316 # define __nocast __attribute__((nocast))
65317 # define __iomem __attribute__((noderef, address_space(2)))
65318+# define __force_iomem __force __iomem
65319 # define __acquires(x) __attribute__((context(x,0,1)))
65320 # define __releases(x) __attribute__((context(x,1,0)))
65321 # define __acquire(x) __context__(x,1)
65322@@ -17,13 +20,34 @@
65323 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
65324 extern void __chk_user_ptr(const volatile void __user *);
65325 extern void __chk_io_ptr(const volatile void __iomem *);
65326+#elif defined(CHECKER_PLUGIN)
65327+//# define __user
65328+//# define __force_user
65329+//# define __kernel
65330+//# define __force_kernel
65331+# define __safe
65332+# define __force
65333+# define __nocast
65334+# define __iomem
65335+# define __force_iomem
65336+# define __chk_user_ptr(x) (void)0
65337+# define __chk_io_ptr(x) (void)0
65338+# define __builtin_warning(x, y...) (1)
65339+# define __acquires(x)
65340+# define __releases(x)
65341+# define __acquire(x) (void)0
65342+# define __release(x) (void)0
65343+# define __cond_lock(x,c) (c)
65344 #else
65345 # define __user
65346+# define __force_user
65347 # define __kernel
65348+# define __force_kernel
65349 # define __safe
65350 # define __force
65351 # define __nocast
65352 # define __iomem
65353+# define __force_iomem
65354 # define __chk_user_ptr(x) (void)0
65355 # define __chk_io_ptr(x) (void)0
65356 # define __builtin_warning(x, y...) (1)
65357@@ -247,6 +271,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65358 # define __attribute_const__ /* unimplemented */
65359 #endif
65360
65361+#ifndef __no_const
65362+# define __no_const
65363+#endif
65364+
65365+#ifndef __do_const
65366+# define __do_const
65367+#endif
65368+
65369 /*
65370 * Tell gcc if a function is cold. The compiler will assume any path
65371 * directly leading to the call is unlikely.
65372@@ -256,6 +288,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65373 #define __cold
65374 #endif
65375
65376+#ifndef __alloc_size
65377+#define __alloc_size(...)
65378+#endif
65379+
65380+#ifndef __bos
65381+#define __bos(ptr, arg)
65382+#endif
65383+
65384+#ifndef __bos0
65385+#define __bos0(ptr)
65386+#endif
65387+
65388+#ifndef __bos1
65389+#define __bos1(ptr)
65390+#endif
65391+
65392 /* Simple shorthand for a section definition */
65393 #ifndef __section
65394 # define __section(S) __attribute__ ((__section__(#S)))
65395@@ -278,6 +326,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65396 * use is to mediate communication between process-level code and irq/NMI
65397 * handlers, all running on the same CPU.
65398 */
65399-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
65400+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
65401+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
65402
65403 #endif /* __LINUX_COMPILER_H */
65404diff --git a/include/linux/crypto.h b/include/linux/crypto.h
65405index fd92988..a3164bd 100644
65406--- a/include/linux/crypto.h
65407+++ b/include/linux/crypto.h
65408@@ -394,7 +394,7 @@ struct cipher_tfm {
65409 const u8 *key, unsigned int keylen);
65410 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65411 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65412-};
65413+} __no_const;
65414
65415 struct hash_tfm {
65416 int (*init)(struct hash_desc *desc);
65417@@ -415,13 +415,13 @@ struct compress_tfm {
65418 int (*cot_decompress)(struct crypto_tfm *tfm,
65419 const u8 *src, unsigned int slen,
65420 u8 *dst, unsigned int *dlen);
65421-};
65422+} __no_const;
65423
65424 struct rng_tfm {
65425 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
65426 unsigned int dlen);
65427 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
65428-};
65429+} __no_const;
65430
65431 #define crt_ablkcipher crt_u.ablkcipher
65432 #define crt_aead crt_u.aead
65433diff --git a/include/linux/dcache.h b/include/linux/dcache.h
65434index 30b93b2..cd7a8db 100644
65435--- a/include/linux/dcache.h
65436+++ b/include/linux/dcache.h
65437@@ -119,6 +119,8 @@ struct dentry {
65438 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
65439 };
65440
65441+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
65442+
65443 /*
65444 * dentry->d_lock spinlock nesting subclasses:
65445 *
65446diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
65447index 3e9bd6a..f4e1aa0 100644
65448--- a/include/linux/decompress/mm.h
65449+++ b/include/linux/decompress/mm.h
65450@@ -78,7 +78,7 @@ static void free(void *where)
65451 * warnings when not needed (indeed large_malloc / large_free are not
65452 * needed by inflate */
65453
65454-#define malloc(a) kmalloc(a, GFP_KERNEL)
65455+#define malloc(a) kmalloc((a), GFP_KERNEL)
65456 #define free(a) kfree(a)
65457
65458 #define large_malloc(a) vmalloc(a)
65459diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
65460index 91b7618..92a93d32 100644
65461--- a/include/linux/dma-mapping.h
65462+++ b/include/linux/dma-mapping.h
65463@@ -16,51 +16,51 @@ enum dma_data_direction {
65464 };
65465
65466 struct dma_map_ops {
65467- void* (*alloc_coherent)(struct device *dev, size_t size,
65468+ void* (* const alloc_coherent)(struct device *dev, size_t size,
65469 dma_addr_t *dma_handle, gfp_t gfp);
65470- void (*free_coherent)(struct device *dev, size_t size,
65471+ void (* const free_coherent)(struct device *dev, size_t size,
65472 void *vaddr, dma_addr_t dma_handle);
65473- dma_addr_t (*map_page)(struct device *dev, struct page *page,
65474+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
65475 unsigned long offset, size_t size,
65476 enum dma_data_direction dir,
65477 struct dma_attrs *attrs);
65478- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
65479+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
65480 size_t size, enum dma_data_direction dir,
65481 struct dma_attrs *attrs);
65482- int (*map_sg)(struct device *dev, struct scatterlist *sg,
65483+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
65484 int nents, enum dma_data_direction dir,
65485 struct dma_attrs *attrs);
65486- void (*unmap_sg)(struct device *dev,
65487+ void (* const unmap_sg)(struct device *dev,
65488 struct scatterlist *sg, int nents,
65489 enum dma_data_direction dir,
65490 struct dma_attrs *attrs);
65491- void (*sync_single_for_cpu)(struct device *dev,
65492+ void (* const sync_single_for_cpu)(struct device *dev,
65493 dma_addr_t dma_handle, size_t size,
65494 enum dma_data_direction dir);
65495- void (*sync_single_for_device)(struct device *dev,
65496+ void (* const sync_single_for_device)(struct device *dev,
65497 dma_addr_t dma_handle, size_t size,
65498 enum dma_data_direction dir);
65499- void (*sync_single_range_for_cpu)(struct device *dev,
65500+ void (* const sync_single_range_for_cpu)(struct device *dev,
65501 dma_addr_t dma_handle,
65502 unsigned long offset,
65503 size_t size,
65504 enum dma_data_direction dir);
65505- void (*sync_single_range_for_device)(struct device *dev,
65506+ void (* const sync_single_range_for_device)(struct device *dev,
65507 dma_addr_t dma_handle,
65508 unsigned long offset,
65509 size_t size,
65510 enum dma_data_direction dir);
65511- void (*sync_sg_for_cpu)(struct device *dev,
65512+ void (* const sync_sg_for_cpu)(struct device *dev,
65513 struct scatterlist *sg, int nents,
65514 enum dma_data_direction dir);
65515- void (*sync_sg_for_device)(struct device *dev,
65516+ void (* const sync_sg_for_device)(struct device *dev,
65517 struct scatterlist *sg, int nents,
65518 enum dma_data_direction dir);
65519- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
65520- int (*dma_supported)(struct device *dev, u64 mask);
65521+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
65522+ int (* const dma_supported)(struct device *dev, u64 mask);
65523 int (*set_dma_mask)(struct device *dev, u64 mask);
65524 int is_phys;
65525-};
65526+} __do_const;
65527
65528 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
65529
65530diff --git a/include/linux/dst.h b/include/linux/dst.h
65531index e26fed8..b976d9f 100644
65532--- a/include/linux/dst.h
65533+++ b/include/linux/dst.h
65534@@ -380,7 +380,7 @@ struct dst_node
65535 struct thread_pool *pool;
65536
65537 /* Transaction IDs live here */
65538- atomic_long_t gen;
65539+ atomic_long_unchecked_t gen;
65540
65541 /*
65542 * How frequently and how many times transaction
65543diff --git a/include/linux/elf.h b/include/linux/elf.h
65544index 90a4ed0..d652617 100644
65545--- a/include/linux/elf.h
65546+++ b/include/linux/elf.h
65547@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
65548 #define PT_GNU_EH_FRAME 0x6474e550
65549
65550 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65551+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65552+
65553+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65554+
65555+/* Constants for the e_flags field */
65556+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65557+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65558+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65559+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65560+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65561+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65562
65563 /* These constants define the different elf file types */
65564 #define ET_NONE 0
65565@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
65566 #define DT_DEBUG 21
65567 #define DT_TEXTREL 22
65568 #define DT_JMPREL 23
65569+#define DT_FLAGS 30
65570+ #define DF_TEXTREL 0x00000004
65571 #define DT_ENCODING 32
65572 #define OLD_DT_LOOS 0x60000000
65573 #define DT_LOOS 0x6000000d
65574@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
65575 #define PF_W 0x2
65576 #define PF_X 0x1
65577
65578+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65579+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65580+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65581+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65582+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65583+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65584+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65585+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65586+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65587+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65588+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65589+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65590+
65591 typedef struct elf32_phdr{
65592 Elf32_Word p_type;
65593 Elf32_Off p_offset;
65594@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
65595 #define EI_OSABI 7
65596 #define EI_PAD 8
65597
65598+#define EI_PAX 14
65599+
65600 #define ELFMAG0 0x7f /* EI_MAG */
65601 #define ELFMAG1 'E'
65602 #define ELFMAG2 'L'
65603@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
65604 #define elf_phdr elf32_phdr
65605 #define elf_note elf32_note
65606 #define elf_addr_t Elf32_Off
65607+#define elf_dyn Elf32_Dyn
65608
65609 #else
65610
65611@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
65612 #define elf_phdr elf64_phdr
65613 #define elf_note elf64_note
65614 #define elf_addr_t Elf64_Off
65615+#define elf_dyn Elf64_Dyn
65616
65617 #endif
65618
65619diff --git a/include/linux/fs.h b/include/linux/fs.h
65620index 1b9a47a..6fe2934 100644
65621--- a/include/linux/fs.h
65622+++ b/include/linux/fs.h
65623@@ -568,41 +568,41 @@ typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
65624 unsigned long, unsigned long);
65625
65626 struct address_space_operations {
65627- int (*writepage)(struct page *page, struct writeback_control *wbc);
65628- int (*readpage)(struct file *, struct page *);
65629- void (*sync_page)(struct page *);
65630+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
65631+ int (* const readpage)(struct file *, struct page *);
65632+ void (* const sync_page)(struct page *);
65633
65634 /* Write back some dirty pages from this mapping. */
65635- int (*writepages)(struct address_space *, struct writeback_control *);
65636+ int (* const writepages)(struct address_space *, struct writeback_control *);
65637
65638 /* Set a page dirty. Return true if this dirtied it */
65639- int (*set_page_dirty)(struct page *page);
65640+ int (* const set_page_dirty)(struct page *page);
65641
65642- int (*readpages)(struct file *filp, struct address_space *mapping,
65643+ int (* const readpages)(struct file *filp, struct address_space *mapping,
65644 struct list_head *pages, unsigned nr_pages);
65645
65646- int (*write_begin)(struct file *, struct address_space *mapping,
65647+ int (* const write_begin)(struct file *, struct address_space *mapping,
65648 loff_t pos, unsigned len, unsigned flags,
65649 struct page **pagep, void **fsdata);
65650- int (*write_end)(struct file *, struct address_space *mapping,
65651+ int (* const write_end)(struct file *, struct address_space *mapping,
65652 loff_t pos, unsigned len, unsigned copied,
65653 struct page *page, void *fsdata);
65654
65655 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
65656- sector_t (*bmap)(struct address_space *, sector_t);
65657- void (*invalidatepage) (struct page *, unsigned long);
65658- int (*releasepage) (struct page *, gfp_t);
65659- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
65660+ sector_t (* const bmap)(struct address_space *, sector_t);
65661+ void (* const invalidatepage) (struct page *, unsigned long);
65662+ int (* const releasepage) (struct page *, gfp_t);
65663+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
65664 loff_t offset, unsigned long nr_segs);
65665- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
65666+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
65667 void **, unsigned long *);
65668 /* migrate the contents of a page to the specified target */
65669- int (*migratepage) (struct address_space *,
65670+ int (* const migratepage) (struct address_space *,
65671 struct page *, struct page *);
65672- int (*launder_page) (struct page *);
65673- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
65674+ int (* const launder_page) (struct page *);
65675+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
65676 unsigned long);
65677- int (*error_remove_page)(struct address_space *, struct page *);
65678+ int (* const error_remove_page)(struct address_space *, struct page *);
65679 };
65680
65681 /*
65682@@ -1031,19 +1031,19 @@ static inline int file_check_writeable(struct file *filp)
65683 typedef struct files_struct *fl_owner_t;
65684
65685 struct file_lock_operations {
65686- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65687- void (*fl_release_private)(struct file_lock *);
65688+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65689+ void (* const fl_release_private)(struct file_lock *);
65690 };
65691
65692 struct lock_manager_operations {
65693- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
65694- void (*fl_notify)(struct file_lock *); /* unblock callback */
65695- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
65696- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65697- void (*fl_release_private)(struct file_lock *);
65698- void (*fl_break)(struct file_lock *);
65699- int (*fl_mylease)(struct file_lock *, struct file_lock *);
65700- int (*fl_change)(struct file_lock **, int);
65701+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
65702+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
65703+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
65704+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65705+ void (* const fl_release_private)(struct file_lock *);
65706+ void (* const fl_break)(struct file_lock *);
65707+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
65708+ int (* const fl_change)(struct file_lock **, int);
65709 };
65710
65711 struct lock_manager {
65712@@ -1442,7 +1442,7 @@ struct fiemap_extent_info {
65713 unsigned int fi_flags; /* Flags as passed from user */
65714 unsigned int fi_extents_mapped; /* Number of mapped extents */
65715 unsigned int fi_extents_max; /* Size of fiemap_extent array */
65716- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
65717+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
65718 * array */
65719 };
65720 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
65721@@ -1512,7 +1512,8 @@ struct file_operations {
65722 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
65723 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
65724 int (*setlease)(struct file *, long, struct file_lock **);
65725-};
65726+} __do_const;
65727+typedef struct file_operations __no_const file_operations_no_const;
65728
65729 struct inode_operations {
65730 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
65731@@ -1559,30 +1560,30 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
65732 unsigned long, loff_t *);
65733
65734 struct super_operations {
65735- struct inode *(*alloc_inode)(struct super_block *sb);
65736- void (*destroy_inode)(struct inode *);
65737+ struct inode *(* const alloc_inode)(struct super_block *sb);
65738+ void (* const destroy_inode)(struct inode *);
65739
65740- void (*dirty_inode) (struct inode *);
65741- int (*write_inode) (struct inode *, int);
65742- void (*drop_inode) (struct inode *);
65743- void (*delete_inode) (struct inode *);
65744- void (*put_super) (struct super_block *);
65745- void (*write_super) (struct super_block *);
65746- int (*sync_fs)(struct super_block *sb, int wait);
65747- int (*freeze_fs) (struct super_block *);
65748- int (*unfreeze_fs) (struct super_block *);
65749- int (*statfs) (struct dentry *, struct kstatfs *);
65750- int (*remount_fs) (struct super_block *, int *, char *);
65751- void (*clear_inode) (struct inode *);
65752- void (*umount_begin) (struct super_block *);
65753+ void (* const dirty_inode) (struct inode *);
65754+ int (* const write_inode) (struct inode *, int);
65755+ void (* const drop_inode) (struct inode *);
65756+ void (* const delete_inode) (struct inode *);
65757+ void (* const put_super) (struct super_block *);
65758+ void (* const write_super) (struct super_block *);
65759+ int (* const sync_fs)(struct super_block *sb, int wait);
65760+ int (* const freeze_fs) (struct super_block *);
65761+ int (* const unfreeze_fs) (struct super_block *);
65762+ int (* const statfs) (struct dentry *, struct kstatfs *);
65763+ int (* const remount_fs) (struct super_block *, int *, char *);
65764+ void (* const clear_inode) (struct inode *);
65765+ void (* const umount_begin) (struct super_block *);
65766
65767- int (*show_options)(struct seq_file *, struct vfsmount *);
65768- int (*show_stats)(struct seq_file *, struct vfsmount *);
65769+ int (* const show_options)(struct seq_file *, struct vfsmount *);
65770+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
65771 #ifdef CONFIG_QUOTA
65772- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
65773- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
65774+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
65775+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
65776 #endif
65777- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
65778+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
65779 };
65780
65781 /*
65782diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
65783index 78a05bf..2a7d3e1 100644
65784--- a/include/linux/fs_struct.h
65785+++ b/include/linux/fs_struct.h
65786@@ -4,7 +4,7 @@
65787 #include <linux/path.h>
65788
65789 struct fs_struct {
65790- int users;
65791+ atomic_t users;
65792 rwlock_t lock;
65793 int umask;
65794 int in_exec;
65795diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
65796index 7be0c6f..2f63a2b 100644
65797--- a/include/linux/fscache-cache.h
65798+++ b/include/linux/fscache-cache.h
65799@@ -116,7 +116,7 @@ struct fscache_operation {
65800 #endif
65801 };
65802
65803-extern atomic_t fscache_op_debug_id;
65804+extern atomic_unchecked_t fscache_op_debug_id;
65805 extern const struct slow_work_ops fscache_op_slow_work_ops;
65806
65807 extern void fscache_enqueue_operation(struct fscache_operation *);
65808@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
65809 fscache_operation_release_t release)
65810 {
65811 atomic_set(&op->usage, 1);
65812- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
65813+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
65814 op->release = release;
65815 INIT_LIST_HEAD(&op->pend_link);
65816 fscache_set_op_state(op, "Init");
65817diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
65818index 4ec5e67..42f1eb9 100644
65819--- a/include/linux/ftrace_event.h
65820+++ b/include/linux/ftrace_event.h
65821@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftrace_event_call *call,
65822 int filter_type);
65823 extern int trace_define_common_fields(struct ftrace_event_call *call);
65824
65825-#define is_signed_type(type) (((type)(-1)) < 0)
65826+#define is_signed_type(type) (((type)(-1)) < (type)1)
65827
65828 int trace_set_clr_event(const char *system, const char *event, int set);
65829
65830diff --git a/include/linux/genhd.h b/include/linux/genhd.h
65831index 297df45..b6a74ff 100644
65832--- a/include/linux/genhd.h
65833+++ b/include/linux/genhd.h
65834@@ -161,7 +161,7 @@ struct gendisk {
65835
65836 struct timer_rand_state *random;
65837
65838- atomic_t sync_io; /* RAID */
65839+ atomic_unchecked_t sync_io; /* RAID */
65840 struct work_struct async_notify;
65841 #ifdef CONFIG_BLK_DEV_INTEGRITY
65842 struct blk_integrity *integrity;
65843diff --git a/include/linux/gracl.h b/include/linux/gracl.h
65844new file mode 100644
65845index 0000000..0dc3943
65846--- /dev/null
65847+++ b/include/linux/gracl.h
65848@@ -0,0 +1,317 @@
65849+#ifndef GR_ACL_H
65850+#define GR_ACL_H
65851+
65852+#include <linux/grdefs.h>
65853+#include <linux/resource.h>
65854+#include <linux/capability.h>
65855+#include <linux/dcache.h>
65856+#include <asm/resource.h>
65857+
65858+/* Major status information */
65859+
65860+#define GR_VERSION "grsecurity 2.2.2"
65861+#define GRSECURITY_VERSION 0x2202
65862+
65863+enum {
65864+ GR_SHUTDOWN = 0,
65865+ GR_ENABLE = 1,
65866+ GR_SPROLE = 2,
65867+ GR_RELOAD = 3,
65868+ GR_SEGVMOD = 4,
65869+ GR_STATUS = 5,
65870+ GR_UNSPROLE = 6,
65871+ GR_PASSSET = 7,
65872+ GR_SPROLEPAM = 8,
65873+};
65874+
65875+/* Password setup definitions
65876+ * kernel/grhash.c */
65877+enum {
65878+ GR_PW_LEN = 128,
65879+ GR_SALT_LEN = 16,
65880+ GR_SHA_LEN = 32,
65881+};
65882+
65883+enum {
65884+ GR_SPROLE_LEN = 64,
65885+};
65886+
65887+enum {
65888+ GR_NO_GLOB = 0,
65889+ GR_REG_GLOB,
65890+ GR_CREATE_GLOB
65891+};
65892+
65893+#define GR_NLIMITS 32
65894+
65895+/* Begin Data Structures */
65896+
65897+struct sprole_pw {
65898+ unsigned char *rolename;
65899+ unsigned char salt[GR_SALT_LEN];
65900+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
65901+};
65902+
65903+struct name_entry {
65904+ __u32 key;
65905+ ino_t inode;
65906+ dev_t device;
65907+ char *name;
65908+ __u16 len;
65909+ __u8 deleted;
65910+ struct name_entry *prev;
65911+ struct name_entry *next;
65912+};
65913+
65914+struct inodev_entry {
65915+ struct name_entry *nentry;
65916+ struct inodev_entry *prev;
65917+ struct inodev_entry *next;
65918+};
65919+
65920+struct acl_role_db {
65921+ struct acl_role_label **r_hash;
65922+ __u32 r_size;
65923+};
65924+
65925+struct inodev_db {
65926+ struct inodev_entry **i_hash;
65927+ __u32 i_size;
65928+};
65929+
65930+struct name_db {
65931+ struct name_entry **n_hash;
65932+ __u32 n_size;
65933+};
65934+
65935+struct crash_uid {
65936+ uid_t uid;
65937+ unsigned long expires;
65938+};
65939+
65940+struct gr_hash_struct {
65941+ void **table;
65942+ void **nametable;
65943+ void *first;
65944+ __u32 table_size;
65945+ __u32 used_size;
65946+ int type;
65947+};
65948+
65949+/* Userspace Grsecurity ACL data structures */
65950+
65951+struct acl_subject_label {
65952+ char *filename;
65953+ ino_t inode;
65954+ dev_t device;
65955+ __u32 mode;
65956+ kernel_cap_t cap_mask;
65957+ kernel_cap_t cap_lower;
65958+ kernel_cap_t cap_invert_audit;
65959+
65960+ struct rlimit res[GR_NLIMITS];
65961+ __u32 resmask;
65962+
65963+ __u8 user_trans_type;
65964+ __u8 group_trans_type;
65965+ uid_t *user_transitions;
65966+ gid_t *group_transitions;
65967+ __u16 user_trans_num;
65968+ __u16 group_trans_num;
65969+
65970+ __u32 sock_families[2];
65971+ __u32 ip_proto[8];
65972+ __u32 ip_type;
65973+ struct acl_ip_label **ips;
65974+ __u32 ip_num;
65975+ __u32 inaddr_any_override;
65976+
65977+ __u32 crashes;
65978+ unsigned long expires;
65979+
65980+ struct acl_subject_label *parent_subject;
65981+ struct gr_hash_struct *hash;
65982+ struct acl_subject_label *prev;
65983+ struct acl_subject_label *next;
65984+
65985+ struct acl_object_label **obj_hash;
65986+ __u32 obj_hash_size;
65987+ __u16 pax_flags;
65988+};
65989+
65990+struct role_allowed_ip {
65991+ __u32 addr;
65992+ __u32 netmask;
65993+
65994+ struct role_allowed_ip *prev;
65995+ struct role_allowed_ip *next;
65996+};
65997+
65998+struct role_transition {
65999+ char *rolename;
66000+
66001+ struct role_transition *prev;
66002+ struct role_transition *next;
66003+};
66004+
66005+struct acl_role_label {
66006+ char *rolename;
66007+ uid_t uidgid;
66008+ __u16 roletype;
66009+
66010+ __u16 auth_attempts;
66011+ unsigned long expires;
66012+
66013+ struct acl_subject_label *root_label;
66014+ struct gr_hash_struct *hash;
66015+
66016+ struct acl_role_label *prev;
66017+ struct acl_role_label *next;
66018+
66019+ struct role_transition *transitions;
66020+ struct role_allowed_ip *allowed_ips;
66021+ uid_t *domain_children;
66022+ __u16 domain_child_num;
66023+
66024+ struct acl_subject_label **subj_hash;
66025+ __u32 subj_hash_size;
66026+};
66027+
66028+struct user_acl_role_db {
66029+ struct acl_role_label **r_table;
66030+ __u32 num_pointers; /* Number of allocations to track */
66031+ __u32 num_roles; /* Number of roles */
66032+ __u32 num_domain_children; /* Number of domain children */
66033+ __u32 num_subjects; /* Number of subjects */
66034+ __u32 num_objects; /* Number of objects */
66035+};
66036+
66037+struct acl_object_label {
66038+ char *filename;
66039+ ino_t inode;
66040+ dev_t device;
66041+ __u32 mode;
66042+
66043+ struct acl_subject_label *nested;
66044+ struct acl_object_label *globbed;
66045+
66046+ /* next two structures not used */
66047+
66048+ struct acl_object_label *prev;
66049+ struct acl_object_label *next;
66050+};
66051+
66052+struct acl_ip_label {
66053+ char *iface;
66054+ __u32 addr;
66055+ __u32 netmask;
66056+ __u16 low, high;
66057+ __u8 mode;
66058+ __u32 type;
66059+ __u32 proto[8];
66060+
66061+ /* next two structures not used */
66062+
66063+ struct acl_ip_label *prev;
66064+ struct acl_ip_label *next;
66065+};
66066+
66067+struct gr_arg {
66068+ struct user_acl_role_db role_db;
66069+ unsigned char pw[GR_PW_LEN];
66070+ unsigned char salt[GR_SALT_LEN];
66071+ unsigned char sum[GR_SHA_LEN];
66072+ unsigned char sp_role[GR_SPROLE_LEN];
66073+ struct sprole_pw *sprole_pws;
66074+ dev_t segv_device;
66075+ ino_t segv_inode;
66076+ uid_t segv_uid;
66077+ __u16 num_sprole_pws;
66078+ __u16 mode;
66079+};
66080+
66081+struct gr_arg_wrapper {
66082+ struct gr_arg *arg;
66083+ __u32 version;
66084+ __u32 size;
66085+};
66086+
66087+struct subject_map {
66088+ struct acl_subject_label *user;
66089+ struct acl_subject_label *kernel;
66090+ struct subject_map *prev;
66091+ struct subject_map *next;
66092+};
66093+
66094+struct acl_subj_map_db {
66095+ struct subject_map **s_hash;
66096+ __u32 s_size;
66097+};
66098+
66099+/* End Data Structures Section */
66100+
66101+/* Hash functions generated by empirical testing by Brad Spengler
66102+ Makes good use of the low bits of the inode. Generally 0-1 times
66103+ in loop for successful match. 0-3 for unsuccessful match.
66104+ Shift/add algorithm with modulus of table size and an XOR*/
66105+
66106+static __inline__ unsigned int
66107+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
66108+{
66109+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
66110+}
66111+
66112+ static __inline__ unsigned int
66113+shash(const struct acl_subject_label *userp, const unsigned int sz)
66114+{
66115+ return ((const unsigned long)userp % sz);
66116+}
66117+
66118+static __inline__ unsigned int
66119+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
66120+{
66121+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
66122+}
66123+
66124+static __inline__ unsigned int
66125+nhash(const char *name, const __u16 len, const unsigned int sz)
66126+{
66127+ return full_name_hash((const unsigned char *)name, len) % sz;
66128+}
66129+
66130+#define FOR_EACH_ROLE_START(role) \
66131+ role = role_list; \
66132+ while (role) {
66133+
66134+#define FOR_EACH_ROLE_END(role) \
66135+ role = role->prev; \
66136+ }
66137+
66138+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
66139+ subj = NULL; \
66140+ iter = 0; \
66141+ while (iter < role->subj_hash_size) { \
66142+ if (subj == NULL) \
66143+ subj = role->subj_hash[iter]; \
66144+ if (subj == NULL) { \
66145+ iter++; \
66146+ continue; \
66147+ }
66148+
66149+#define FOR_EACH_SUBJECT_END(subj,iter) \
66150+ subj = subj->next; \
66151+ if (subj == NULL) \
66152+ iter++; \
66153+ }
66154+
66155+
66156+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
66157+ subj = role->hash->first; \
66158+ while (subj != NULL) {
66159+
66160+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
66161+ subj = subj->next; \
66162+ }
66163+
66164+#endif
66165+
66166diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
66167new file mode 100644
66168index 0000000..323ecf2
66169--- /dev/null
66170+++ b/include/linux/gralloc.h
66171@@ -0,0 +1,9 @@
66172+#ifndef __GRALLOC_H
66173+#define __GRALLOC_H
66174+
66175+void acl_free_all(void);
66176+int acl_alloc_stack_init(unsigned long size);
66177+void *acl_alloc(unsigned long len);
66178+void *acl_alloc_num(unsigned long num, unsigned long len);
66179+
66180+#endif
66181diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
66182new file mode 100644
66183index 0000000..70d6cd5
66184--- /dev/null
66185+++ b/include/linux/grdefs.h
66186@@ -0,0 +1,140 @@
66187+#ifndef GRDEFS_H
66188+#define GRDEFS_H
66189+
66190+/* Begin grsecurity status declarations */
66191+
66192+enum {
66193+ GR_READY = 0x01,
66194+ GR_STATUS_INIT = 0x00 // disabled state
66195+};
66196+
66197+/* Begin ACL declarations */
66198+
66199+/* Role flags */
66200+
66201+enum {
66202+ GR_ROLE_USER = 0x0001,
66203+ GR_ROLE_GROUP = 0x0002,
66204+ GR_ROLE_DEFAULT = 0x0004,
66205+ GR_ROLE_SPECIAL = 0x0008,
66206+ GR_ROLE_AUTH = 0x0010,
66207+ GR_ROLE_NOPW = 0x0020,
66208+ GR_ROLE_GOD = 0x0040,
66209+ GR_ROLE_LEARN = 0x0080,
66210+ GR_ROLE_TPE = 0x0100,
66211+ GR_ROLE_DOMAIN = 0x0200,
66212+ GR_ROLE_PAM = 0x0400,
66213+ GR_ROLE_PERSIST = 0x800
66214+};
66215+
66216+/* ACL Subject and Object mode flags */
66217+enum {
66218+ GR_DELETED = 0x80000000
66219+};
66220+
66221+/* ACL Object-only mode flags */
66222+enum {
66223+ GR_READ = 0x00000001,
66224+ GR_APPEND = 0x00000002,
66225+ GR_WRITE = 0x00000004,
66226+ GR_EXEC = 0x00000008,
66227+ GR_FIND = 0x00000010,
66228+ GR_INHERIT = 0x00000020,
66229+ GR_SETID = 0x00000040,
66230+ GR_CREATE = 0x00000080,
66231+ GR_DELETE = 0x00000100,
66232+ GR_LINK = 0x00000200,
66233+ GR_AUDIT_READ = 0x00000400,
66234+ GR_AUDIT_APPEND = 0x00000800,
66235+ GR_AUDIT_WRITE = 0x00001000,
66236+ GR_AUDIT_EXEC = 0x00002000,
66237+ GR_AUDIT_FIND = 0x00004000,
66238+ GR_AUDIT_INHERIT= 0x00008000,
66239+ GR_AUDIT_SETID = 0x00010000,
66240+ GR_AUDIT_CREATE = 0x00020000,
66241+ GR_AUDIT_DELETE = 0x00040000,
66242+ GR_AUDIT_LINK = 0x00080000,
66243+ GR_PTRACERD = 0x00100000,
66244+ GR_NOPTRACE = 0x00200000,
66245+ GR_SUPPRESS = 0x00400000,
66246+ GR_NOLEARN = 0x00800000,
66247+ GR_INIT_TRANSFER= 0x01000000
66248+};
66249+
66250+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
66251+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
66252+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
66253+
66254+/* ACL subject-only mode flags */
66255+enum {
66256+ GR_KILL = 0x00000001,
66257+ GR_VIEW = 0x00000002,
66258+ GR_PROTECTED = 0x00000004,
66259+ GR_LEARN = 0x00000008,
66260+ GR_OVERRIDE = 0x00000010,
66261+ /* just a placeholder, this mode is only used in userspace */
66262+ GR_DUMMY = 0x00000020,
66263+ GR_PROTSHM = 0x00000040,
66264+ GR_KILLPROC = 0x00000080,
66265+ GR_KILLIPPROC = 0x00000100,
66266+ /* just a placeholder, this mode is only used in userspace */
66267+ GR_NOTROJAN = 0x00000200,
66268+ GR_PROTPROCFD = 0x00000400,
66269+ GR_PROCACCT = 0x00000800,
66270+ GR_RELAXPTRACE = 0x00001000,
66271+ GR_NESTED = 0x00002000,
66272+ GR_INHERITLEARN = 0x00004000,
66273+ GR_PROCFIND = 0x00008000,
66274+ GR_POVERRIDE = 0x00010000,
66275+ GR_KERNELAUTH = 0x00020000,
66276+ GR_ATSECURE = 0x00040000,
66277+ GR_SHMEXEC = 0x00080000
66278+};
66279+
66280+enum {
66281+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
66282+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
66283+ GR_PAX_ENABLE_MPROTECT = 0x0004,
66284+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
66285+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
66286+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
66287+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
66288+ GR_PAX_DISABLE_MPROTECT = 0x0400,
66289+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
66290+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
66291+};
66292+
66293+enum {
66294+ GR_ID_USER = 0x01,
66295+ GR_ID_GROUP = 0x02,
66296+};
66297+
66298+enum {
66299+ GR_ID_ALLOW = 0x01,
66300+ GR_ID_DENY = 0x02,
66301+};
66302+
66303+#define GR_CRASH_RES 31
66304+#define GR_UIDTABLE_MAX 500
66305+
66306+/* begin resource learning section */
66307+enum {
66308+ GR_RLIM_CPU_BUMP = 60,
66309+ GR_RLIM_FSIZE_BUMP = 50000,
66310+ GR_RLIM_DATA_BUMP = 10000,
66311+ GR_RLIM_STACK_BUMP = 1000,
66312+ GR_RLIM_CORE_BUMP = 10000,
66313+ GR_RLIM_RSS_BUMP = 500000,
66314+ GR_RLIM_NPROC_BUMP = 1,
66315+ GR_RLIM_NOFILE_BUMP = 5,
66316+ GR_RLIM_MEMLOCK_BUMP = 50000,
66317+ GR_RLIM_AS_BUMP = 500000,
66318+ GR_RLIM_LOCKS_BUMP = 2,
66319+ GR_RLIM_SIGPENDING_BUMP = 5,
66320+ GR_RLIM_MSGQUEUE_BUMP = 10000,
66321+ GR_RLIM_NICE_BUMP = 1,
66322+ GR_RLIM_RTPRIO_BUMP = 1,
66323+ GR_RLIM_RTTIME_BUMP = 1000000
66324+};
66325+
66326+#endif
66327diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
66328new file mode 100644
66329index 0000000..e5817d7
66330--- /dev/null
66331+++ b/include/linux/grinternal.h
66332@@ -0,0 +1,218 @@
66333+#ifndef __GRINTERNAL_H
66334+#define __GRINTERNAL_H
66335+
66336+#ifdef CONFIG_GRKERNSEC
66337+
66338+#include <linux/fs.h>
66339+#include <linux/mnt_namespace.h>
66340+#include <linux/nsproxy.h>
66341+#include <linux/gracl.h>
66342+#include <linux/grdefs.h>
66343+#include <linux/grmsg.h>
66344+
66345+void gr_add_learn_entry(const char *fmt, ...)
66346+ __attribute__ ((format (printf, 1, 2)));
66347+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
66348+ const struct vfsmount *mnt);
66349+__u32 gr_check_create(const struct dentry *new_dentry,
66350+ const struct dentry *parent,
66351+ const struct vfsmount *mnt, const __u32 mode);
66352+int gr_check_protected_task(const struct task_struct *task);
66353+__u32 to_gr_audit(const __u32 reqmode);
66354+int gr_set_acls(const int type);
66355+int gr_apply_subject_to_task(struct task_struct *task);
66356+int gr_acl_is_enabled(void);
66357+char gr_roletype_to_char(void);
66358+
66359+void gr_handle_alertkill(struct task_struct *task);
66360+char *gr_to_filename(const struct dentry *dentry,
66361+ const struct vfsmount *mnt);
66362+char *gr_to_filename1(const struct dentry *dentry,
66363+ const struct vfsmount *mnt);
66364+char *gr_to_filename2(const struct dentry *dentry,
66365+ const struct vfsmount *mnt);
66366+char *gr_to_filename3(const struct dentry *dentry,
66367+ const struct vfsmount *mnt);
66368+
66369+extern int grsec_enable_harden_ptrace;
66370+extern int grsec_enable_link;
66371+extern int grsec_enable_fifo;
66372+extern int grsec_enable_shm;
66373+extern int grsec_enable_execlog;
66374+extern int grsec_enable_signal;
66375+extern int grsec_enable_audit_ptrace;
66376+extern int grsec_enable_forkfail;
66377+extern int grsec_enable_time;
66378+extern int grsec_enable_rofs;
66379+extern int grsec_enable_chroot_shmat;
66380+extern int grsec_enable_chroot_mount;
66381+extern int grsec_enable_chroot_double;
66382+extern int grsec_enable_chroot_pivot;
66383+extern int grsec_enable_chroot_chdir;
66384+extern int grsec_enable_chroot_chmod;
66385+extern int grsec_enable_chroot_mknod;
66386+extern int grsec_enable_chroot_fchdir;
66387+extern int grsec_enable_chroot_nice;
66388+extern int grsec_enable_chroot_execlog;
66389+extern int grsec_enable_chroot_caps;
66390+extern int grsec_enable_chroot_sysctl;
66391+extern int grsec_enable_chroot_unix;
66392+extern int grsec_enable_tpe;
66393+extern int grsec_tpe_gid;
66394+extern int grsec_enable_tpe_all;
66395+extern int grsec_enable_tpe_invert;
66396+extern int grsec_enable_socket_all;
66397+extern int grsec_socket_all_gid;
66398+extern int grsec_enable_socket_client;
66399+extern int grsec_socket_client_gid;
66400+extern int grsec_enable_socket_server;
66401+extern int grsec_socket_server_gid;
66402+extern int grsec_audit_gid;
66403+extern int grsec_enable_group;
66404+extern int grsec_enable_audit_textrel;
66405+extern int grsec_enable_log_rwxmaps;
66406+extern int grsec_enable_mount;
66407+extern int grsec_enable_chdir;
66408+extern int grsec_resource_logging;
66409+extern int grsec_enable_blackhole;
66410+extern int grsec_lastack_retries;
66411+extern int grsec_enable_brute;
66412+extern int grsec_lock;
66413+
66414+extern spinlock_t grsec_alert_lock;
66415+extern unsigned long grsec_alert_wtime;
66416+extern unsigned long grsec_alert_fyet;
66417+
66418+extern spinlock_t grsec_audit_lock;
66419+
66420+extern rwlock_t grsec_exec_file_lock;
66421+
66422+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
66423+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
66424+ (tsk)->exec_file->f_vfsmnt) : "/")
66425+
66426+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
66427+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
66428+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66429+
66430+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
66431+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
66432+ (tsk)->exec_file->f_vfsmnt) : "/")
66433+
66434+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
66435+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
66436+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66437+
66438+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
66439+
66440+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
66441+
66442+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
66443+ (task)->pid, (cred)->uid, \
66444+ (cred)->euid, (cred)->gid, (cred)->egid, \
66445+ gr_parent_task_fullpath(task), \
66446+ (task)->real_parent->comm, (task)->real_parent->pid, \
66447+ (pcred)->uid, (pcred)->euid, \
66448+ (pcred)->gid, (pcred)->egid
66449+
66450+#define GR_CHROOT_CAPS {{ \
66451+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
66452+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
66453+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
66454+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
66455+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
66456+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
66457+ CAP_TO_MASK(CAP_MAC_ADMIN) }}
66458+
66459+#define security_learn(normal_msg,args...) \
66460+({ \
66461+ read_lock(&grsec_exec_file_lock); \
66462+ gr_add_learn_entry(normal_msg "\n", ## args); \
66463+ read_unlock(&grsec_exec_file_lock); \
66464+})
66465+
66466+enum {
66467+ GR_DO_AUDIT,
66468+ GR_DONT_AUDIT,
66469+ GR_DONT_AUDIT_GOOD
66470+};
66471+
66472+enum {
66473+ GR_TTYSNIFF,
66474+ GR_RBAC,
66475+ GR_RBAC_STR,
66476+ GR_STR_RBAC,
66477+ GR_RBAC_MODE2,
66478+ GR_RBAC_MODE3,
66479+ GR_FILENAME,
66480+ GR_SYSCTL_HIDDEN,
66481+ GR_NOARGS,
66482+ GR_ONE_INT,
66483+ GR_ONE_INT_TWO_STR,
66484+ GR_ONE_STR,
66485+ GR_STR_INT,
66486+ GR_TWO_STR_INT,
66487+ GR_TWO_INT,
66488+ GR_TWO_U64,
66489+ GR_THREE_INT,
66490+ GR_FIVE_INT_TWO_STR,
66491+ GR_TWO_STR,
66492+ GR_THREE_STR,
66493+ GR_FOUR_STR,
66494+ GR_STR_FILENAME,
66495+ GR_FILENAME_STR,
66496+ GR_FILENAME_TWO_INT,
66497+ GR_FILENAME_TWO_INT_STR,
66498+ GR_TEXTREL,
66499+ GR_PTRACE,
66500+ GR_RESOURCE,
66501+ GR_CAP,
66502+ GR_SIG,
66503+ GR_SIG2,
66504+ GR_CRASH1,
66505+ GR_CRASH2,
66506+ GR_PSACCT,
66507+ GR_RWXMAP
66508+};
66509+
66510+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
66511+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
66512+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
66513+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
66514+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
66515+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
66516+#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)
66517+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
66518+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
66519+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
66520+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
66521+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
66522+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
66523+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
66524+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
66525+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
66526+#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)
66527+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
66528+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
66529+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
66530+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
66531+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
66532+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
66533+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
66534+#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)
66535+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
66536+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
66537+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
66538+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
66539+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
66540+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
66541+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
66542+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
66543+#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)
66544+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
66545+
66546+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
66547+
66548+#endif
66549+
66550+#endif
66551diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
66552new file mode 100644
66553index 0000000..9d5fd4a
66554--- /dev/null
66555+++ b/include/linux/grmsg.h
66556@@ -0,0 +1,108 @@
66557+#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"
66558+#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"
66559+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
66560+#define GR_STOPMOD_MSG "denied modification of module state by "
66561+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
66562+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
66563+#define GR_IOPERM_MSG "denied use of ioperm() by "
66564+#define GR_IOPL_MSG "denied use of iopl() by "
66565+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
66566+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
66567+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
66568+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
66569+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
66570+#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"
66571+#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"
66572+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
66573+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
66574+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
66575+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
66576+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
66577+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
66578+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
66579+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
66580+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
66581+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
66582+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
66583+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
66584+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
66585+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
66586+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
66587+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
66588+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
66589+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
66590+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
66591+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
66592+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
66593+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
66594+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
66595+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
66596+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
66597+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
66598+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
66599+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
66600+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
66601+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
66602+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
66603+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
66604+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
66605+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
66606+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
66607+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
66608+#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"
66609+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
66610+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
66611+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
66612+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
66613+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
66614+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
66615+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
66616+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
66617+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
66618+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
66619+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
66620+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
66621+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
66622+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
66623+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
66624+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
66625+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
66626+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
66627+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
66628+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
66629+#define GR_FAILFORK_MSG "failed fork with errno %s by "
66630+#define GR_NICE_CHROOT_MSG "denied priority change by "
66631+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
66632+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
66633+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
66634+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
66635+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
66636+#define GR_TIME_MSG "time set by "
66637+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
66638+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
66639+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
66640+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
66641+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
66642+#define GR_BIND_MSG "denied bind() by "
66643+#define GR_CONNECT_MSG "denied connect() by "
66644+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
66645+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
66646+#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"
66647+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
66648+#define GR_CAP_ACL_MSG "use of %s denied for "
66649+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
66650+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
66651+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
66652+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
66653+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
66654+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
66655+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
66656+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
66657+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
66658+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
66659+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
66660+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
66661+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
66662+#define GR_VM86_MSG "denied use of vm86 by "
66663+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
66664+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
66665diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
66666new file mode 100644
66667index 0000000..24676f4
66668--- /dev/null
66669+++ b/include/linux/grsecurity.h
66670@@ -0,0 +1,218 @@
66671+#ifndef GR_SECURITY_H
66672+#define GR_SECURITY_H
66673+#include <linux/fs.h>
66674+#include <linux/fs_struct.h>
66675+#include <linux/binfmts.h>
66676+#include <linux/gracl.h>
66677+#include <linux/compat.h>
66678+
66679+/* notify of brain-dead configs */
66680+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66681+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
66682+#endif
66683+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
66684+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
66685+#endif
66686+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66687+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66688+#endif
66689+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66690+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66691+#endif
66692+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
66693+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
66694+#endif
66695+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
66696+#error "CONFIG_PAX enabled, but no PaX options are enabled."
66697+#endif
66698+
66699+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
66700+void gr_handle_brute_check(void);
66701+void gr_handle_kernel_exploit(void);
66702+int gr_process_user_ban(void);
66703+
66704+char gr_roletype_to_char(void);
66705+
66706+int gr_acl_enable_at_secure(void);
66707+
66708+int gr_check_user_change(int real, int effective, int fs);
66709+int gr_check_group_change(int real, int effective, int fs);
66710+
66711+void gr_del_task_from_ip_table(struct task_struct *p);
66712+
66713+int gr_pid_is_chrooted(struct task_struct *p);
66714+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
66715+int gr_handle_chroot_nice(void);
66716+int gr_handle_chroot_sysctl(const int op);
66717+int gr_handle_chroot_setpriority(struct task_struct *p,
66718+ const int niceval);
66719+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
66720+int gr_handle_chroot_chroot(const struct dentry *dentry,
66721+ const struct vfsmount *mnt);
66722+void gr_handle_chroot_chdir(struct path *path);
66723+int gr_handle_chroot_chmod(const struct dentry *dentry,
66724+ const struct vfsmount *mnt, const int mode);
66725+int gr_handle_chroot_mknod(const struct dentry *dentry,
66726+ const struct vfsmount *mnt, const int mode);
66727+int gr_handle_chroot_mount(const struct dentry *dentry,
66728+ const struct vfsmount *mnt,
66729+ const char *dev_name);
66730+int gr_handle_chroot_pivot(void);
66731+int gr_handle_chroot_unix(const pid_t pid);
66732+
66733+int gr_handle_rawio(const struct inode *inode);
66734+
66735+void gr_handle_ioperm(void);
66736+void gr_handle_iopl(void);
66737+
66738+int gr_tpe_allow(const struct file *file);
66739+
66740+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
66741+void gr_clear_chroot_entries(struct task_struct *task);
66742+
66743+void gr_log_forkfail(const int retval);
66744+void gr_log_timechange(void);
66745+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
66746+void gr_log_chdir(const struct dentry *dentry,
66747+ const struct vfsmount *mnt);
66748+void gr_log_chroot_exec(const struct dentry *dentry,
66749+ const struct vfsmount *mnt);
66750+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
66751+#ifdef CONFIG_COMPAT
66752+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
66753+#endif
66754+void gr_log_remount(const char *devname, const int retval);
66755+void gr_log_unmount(const char *devname, const int retval);
66756+void gr_log_mount(const char *from, const char *to, const int retval);
66757+void gr_log_textrel(struct vm_area_struct *vma);
66758+void gr_log_rwxmmap(struct file *file);
66759+void gr_log_rwxmprotect(struct file *file);
66760+
66761+int gr_handle_follow_link(const struct inode *parent,
66762+ const struct inode *inode,
66763+ const struct dentry *dentry,
66764+ const struct vfsmount *mnt);
66765+int gr_handle_fifo(const struct dentry *dentry,
66766+ const struct vfsmount *mnt,
66767+ const struct dentry *dir, const int flag,
66768+ const int acc_mode);
66769+int gr_handle_hardlink(const struct dentry *dentry,
66770+ const struct vfsmount *mnt,
66771+ struct inode *inode,
66772+ const int mode, const char *to);
66773+
66774+int gr_is_capable(const int cap);
66775+int gr_is_capable_nolog(const int cap);
66776+void gr_learn_resource(const struct task_struct *task, const int limit,
66777+ const unsigned long wanted, const int gt);
66778+void gr_copy_label(struct task_struct *tsk);
66779+void gr_handle_crash(struct task_struct *task, const int sig);
66780+int gr_handle_signal(const struct task_struct *p, const int sig);
66781+int gr_check_crash_uid(const uid_t uid);
66782+int gr_check_protected_task(const struct task_struct *task);
66783+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
66784+int gr_acl_handle_mmap(const struct file *file,
66785+ const unsigned long prot);
66786+int gr_acl_handle_mprotect(const struct file *file,
66787+ const unsigned long prot);
66788+int gr_check_hidden_task(const struct task_struct *tsk);
66789+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
66790+ const struct vfsmount *mnt);
66791+__u32 gr_acl_handle_utime(const struct dentry *dentry,
66792+ const struct vfsmount *mnt);
66793+__u32 gr_acl_handle_access(const struct dentry *dentry,
66794+ const struct vfsmount *mnt, const int fmode);
66795+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
66796+ const struct vfsmount *mnt, mode_t mode);
66797+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
66798+ const struct vfsmount *mnt, mode_t mode);
66799+__u32 gr_acl_handle_chown(const struct dentry *dentry,
66800+ const struct vfsmount *mnt);
66801+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
66802+ const struct vfsmount *mnt);
66803+int gr_handle_ptrace(struct task_struct *task, const long request);
66804+int gr_handle_proc_ptrace(struct task_struct *task);
66805+__u32 gr_acl_handle_execve(const struct dentry *dentry,
66806+ const struct vfsmount *mnt);
66807+int gr_check_crash_exec(const struct file *filp);
66808+int gr_acl_is_enabled(void);
66809+void gr_set_kernel_label(struct task_struct *task);
66810+void gr_set_role_label(struct task_struct *task, const uid_t uid,
66811+ const gid_t gid);
66812+int gr_set_proc_label(const struct dentry *dentry,
66813+ const struct vfsmount *mnt,
66814+ const int unsafe_share);
66815+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
66816+ const struct vfsmount *mnt);
66817+__u32 gr_acl_handle_open(const struct dentry *dentry,
66818+ const struct vfsmount *mnt, int acc_mode);
66819+__u32 gr_acl_handle_creat(const struct dentry *dentry,
66820+ const struct dentry *p_dentry,
66821+ const struct vfsmount *p_mnt,
66822+ int open_flags, int acc_mode, const int imode);
66823+void gr_handle_create(const struct dentry *dentry,
66824+ const struct vfsmount *mnt);
66825+void gr_handle_proc_create(const struct dentry *dentry,
66826+ const struct inode *inode);
66827+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
66828+ const struct dentry *parent_dentry,
66829+ const struct vfsmount *parent_mnt,
66830+ const int mode);
66831+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
66832+ const struct dentry *parent_dentry,
66833+ const struct vfsmount *parent_mnt);
66834+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
66835+ const struct vfsmount *mnt);
66836+void gr_handle_delete(const ino_t ino, const dev_t dev);
66837+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
66838+ const struct vfsmount *mnt);
66839+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
66840+ const struct dentry *parent_dentry,
66841+ const struct vfsmount *parent_mnt,
66842+ const char *from);
66843+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
66844+ const struct dentry *parent_dentry,
66845+ const struct vfsmount *parent_mnt,
66846+ const struct dentry *old_dentry,
66847+ const struct vfsmount *old_mnt, const char *to);
66848+int gr_acl_handle_rename(struct dentry *new_dentry,
66849+ struct dentry *parent_dentry,
66850+ const struct vfsmount *parent_mnt,
66851+ struct dentry *old_dentry,
66852+ struct inode *old_parent_inode,
66853+ struct vfsmount *old_mnt, const char *newname);
66854+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
66855+ struct dentry *old_dentry,
66856+ struct dentry *new_dentry,
66857+ struct vfsmount *mnt, const __u8 replace);
66858+__u32 gr_check_link(const struct dentry *new_dentry,
66859+ const struct dentry *parent_dentry,
66860+ const struct vfsmount *parent_mnt,
66861+ const struct dentry *old_dentry,
66862+ const struct vfsmount *old_mnt);
66863+int gr_acl_handle_filldir(const struct file *file, const char *name,
66864+ const unsigned int namelen, const ino_t ino);
66865+
66866+__u32 gr_acl_handle_unix(const struct dentry *dentry,
66867+ const struct vfsmount *mnt);
66868+void gr_acl_handle_exit(void);
66869+void gr_acl_handle_psacct(struct task_struct *task, const long code);
66870+int gr_acl_handle_procpidmem(const struct task_struct *task);
66871+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
66872+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
66873+void gr_audit_ptrace(struct task_struct *task);
66874+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
66875+
66876+#ifdef CONFIG_GRKERNSEC
66877+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
66878+void gr_handle_vm86(void);
66879+void gr_handle_mem_readwrite(u64 from, u64 to);
66880+
66881+extern int grsec_enable_dmesg;
66882+extern int grsec_disable_privio;
66883+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66884+extern int grsec_enable_chroot_findtask;
66885+#endif
66886+#endif
66887+
66888+#endif
66889diff --git a/include/linux/hdpu_features.h b/include/linux/hdpu_features.h
66890index 6a87154..a3ce57b 100644
66891--- a/include/linux/hdpu_features.h
66892+++ b/include/linux/hdpu_features.h
66893@@ -3,7 +3,7 @@
66894 struct cpustate_t {
66895 spinlock_t lock;
66896 int excl;
66897- int open_count;
66898+ atomic_t open_count;
66899 unsigned char cached_val;
66900 int inited;
66901 unsigned long *set_addr;
66902diff --git a/include/linux/highmem.h b/include/linux/highmem.h
66903index 211ff44..00ab6d7 100644
66904--- a/include/linux/highmem.h
66905+++ b/include/linux/highmem.h
66906@@ -137,6 +137,18 @@ static inline void clear_highpage(struct page *page)
66907 kunmap_atomic(kaddr, KM_USER0);
66908 }
66909
66910+static inline void sanitize_highpage(struct page *page)
66911+{
66912+ void *kaddr;
66913+ unsigned long flags;
66914+
66915+ local_irq_save(flags);
66916+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
66917+ clear_page(kaddr);
66918+ kunmap_atomic(kaddr, KM_CLEARPAGE);
66919+ local_irq_restore(flags);
66920+}
66921+
66922 static inline void zero_user_segments(struct page *page,
66923 unsigned start1, unsigned end1,
66924 unsigned start2, unsigned end2)
66925diff --git a/include/linux/i2c.h b/include/linux/i2c.h
66926index 7b40cda..24eb44e 100644
66927--- a/include/linux/i2c.h
66928+++ b/include/linux/i2c.h
66929@@ -325,6 +325,7 @@ struct i2c_algorithm {
66930 /* To determine what the adapter supports */
66931 u32 (*functionality) (struct i2c_adapter *);
66932 };
66933+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
66934
66935 /*
66936 * i2c_adapter is the structure used to identify a physical i2c bus along
66937diff --git a/include/linux/i2o.h b/include/linux/i2o.h
66938index 4c4e57d..f3c5303 100644
66939--- a/include/linux/i2o.h
66940+++ b/include/linux/i2o.h
66941@@ -564,7 +564,7 @@ struct i2o_controller {
66942 struct i2o_device *exec; /* Executive */
66943 #if BITS_PER_LONG == 64
66944 spinlock_t context_list_lock; /* lock for context_list */
66945- atomic_t context_list_counter; /* needed for unique contexts */
66946+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
66947 struct list_head context_list; /* list of context id's
66948 and pointers */
66949 #endif
66950diff --git a/include/linux/init_task.h b/include/linux/init_task.h
66951index 21a6f5d..dc42eab 100644
66952--- a/include/linux/init_task.h
66953+++ b/include/linux/init_task.h
66954@@ -83,6 +83,12 @@ extern struct group_info init_groups;
66955 #define INIT_IDS
66956 #endif
66957
66958+#ifdef CONFIG_X86
66959+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
66960+#else
66961+#define INIT_TASK_THREAD_INFO
66962+#endif
66963+
66964 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
66965 /*
66966 * Because of the reduced scope of CAP_SETPCAP when filesystem
66967@@ -156,6 +162,7 @@ extern struct cred init_cred;
66968 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
66969 .comm = "swapper", \
66970 .thread = INIT_THREAD, \
66971+ INIT_TASK_THREAD_INFO \
66972 .fs = &init_fs, \
66973 .files = &init_files, \
66974 .signal = &init_signals, \
66975diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
66976index 4f0a72a..a849599 100644
66977--- a/include/linux/intel-iommu.h
66978+++ b/include/linux/intel-iommu.h
66979@@ -296,7 +296,7 @@ struct iommu_flush {
66980 u8 fm, u64 type);
66981 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
66982 unsigned int size_order, u64 type);
66983-};
66984+} __no_const;
66985
66986 enum {
66987 SR_DMAR_FECTL_REG,
66988diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
66989index c739150..be577b5 100644
66990--- a/include/linux/interrupt.h
66991+++ b/include/linux/interrupt.h
66992@@ -369,7 +369,7 @@ enum
66993 /* map softirq index to softirq name. update 'softirq_to_name' in
66994 * kernel/softirq.c when adding a new softirq.
66995 */
66996-extern char *softirq_to_name[NR_SOFTIRQS];
66997+extern const char * const softirq_to_name[NR_SOFTIRQS];
66998
66999 /* softirq mask and active fields moved to irq_cpustat_t in
67000 * asm/hardirq.h to get better cache usage. KAO
67001@@ -377,12 +377,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
67002
67003 struct softirq_action
67004 {
67005- void (*action)(struct softirq_action *);
67006+ void (*action)(void);
67007 };
67008
67009 asmlinkage void do_softirq(void);
67010 asmlinkage void __do_softirq(void);
67011-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
67012+extern void open_softirq(int nr, void (*action)(void));
67013 extern void softirq_init(void);
67014 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
67015 extern void raise_softirq_irqoff(unsigned int nr);
67016diff --git a/include/linux/irq.h b/include/linux/irq.h
67017index 9e5f45a..025865b 100644
67018--- a/include/linux/irq.h
67019+++ b/include/linux/irq.h
67020@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
67021 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
67022 bool boot)
67023 {
67024+#ifdef CONFIG_CPUMASK_OFFSTACK
67025 gfp_t gfp = GFP_ATOMIC;
67026
67027 if (boot)
67028 gfp = GFP_NOWAIT;
67029
67030-#ifdef CONFIG_CPUMASK_OFFSTACK
67031 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
67032 return false;
67033
67034diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
67035index 7922742..27306a2 100644
67036--- a/include/linux/kallsyms.h
67037+++ b/include/linux/kallsyms.h
67038@@ -15,7 +15,8 @@
67039
67040 struct module;
67041
67042-#ifdef CONFIG_KALLSYMS
67043+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
67044+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67045 /* Lookup the address for a symbol. Returns 0 if not found. */
67046 unsigned long kallsyms_lookup_name(const char *name);
67047
67048@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
67049 /* Stupid that this does nothing, but I didn't create this mess. */
67050 #define __print_symbol(fmt, addr)
67051 #endif /*CONFIG_KALLSYMS*/
67052+#else /* when included by kallsyms.c, vsnprintf.c, or
67053+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
67054+extern void __print_symbol(const char *fmt, unsigned long address);
67055+extern int sprint_symbol(char *buffer, unsigned long address);
67056+const char *kallsyms_lookup(unsigned long addr,
67057+ unsigned long *symbolsize,
67058+ unsigned long *offset,
67059+ char **modname, char *namebuf);
67060+#endif
67061
67062 /* This macro allows us to keep printk typechecking */
67063 static void __check_printsym_format(const char *fmt, ...)
67064diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
67065index 6adcc29..13369e8 100644
67066--- a/include/linux/kgdb.h
67067+++ b/include/linux/kgdb.h
67068@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
67069
67070 extern int kgdb_connected;
67071
67072-extern atomic_t kgdb_setting_breakpoint;
67073-extern atomic_t kgdb_cpu_doing_single_step;
67074+extern atomic_unchecked_t kgdb_setting_breakpoint;
67075+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
67076
67077 extern struct task_struct *kgdb_usethread;
67078 extern struct task_struct *kgdb_contthread;
67079@@ -235,7 +235,7 @@ struct kgdb_arch {
67080 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
67081 void (*remove_all_hw_break)(void);
67082 void (*correct_hw_break)(void);
67083-};
67084+} __do_const;
67085
67086 /**
67087 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
67088@@ -257,14 +257,14 @@ struct kgdb_io {
67089 int (*init) (void);
67090 void (*pre_exception) (void);
67091 void (*post_exception) (void);
67092-};
67093+} __do_const;
67094
67095-extern struct kgdb_arch arch_kgdb_ops;
67096+extern const struct kgdb_arch arch_kgdb_ops;
67097
67098 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
67099
67100-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
67101-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
67102+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
67103+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
67104
67105 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
67106 extern int kgdb_mem2hex(char *mem, char *buf, int count);
67107diff --git a/include/linux/kmod.h b/include/linux/kmod.h
67108index 384ca8b..83dd97d 100644
67109--- a/include/linux/kmod.h
67110+++ b/include/linux/kmod.h
67111@@ -31,6 +31,8 @@
67112 * usually useless though. */
67113 extern int __request_module(bool wait, const char *name, ...) \
67114 __attribute__((format(printf, 2, 3)));
67115+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
67116+ __attribute__((format(printf, 3, 4)));
67117 #define request_module(mod...) __request_module(true, mod)
67118 #define request_module_nowait(mod...) __request_module(false, mod)
67119 #define try_then_request_module(x, mod...) \
67120diff --git a/include/linux/kobject.h b/include/linux/kobject.h
67121index 58ae8e0..3950d3c 100644
67122--- a/include/linux/kobject.h
67123+++ b/include/linux/kobject.h
67124@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
67125
67126 struct kobj_type {
67127 void (*release)(struct kobject *kobj);
67128- struct sysfs_ops *sysfs_ops;
67129+ const struct sysfs_ops *sysfs_ops;
67130 struct attribute **default_attrs;
67131 };
67132
67133@@ -118,9 +118,9 @@ struct kobj_uevent_env {
67134 };
67135
67136 struct kset_uevent_ops {
67137- int (*filter)(struct kset *kset, struct kobject *kobj);
67138- const char *(*name)(struct kset *kset, struct kobject *kobj);
67139- int (*uevent)(struct kset *kset, struct kobject *kobj,
67140+ int (* const filter)(struct kset *kset, struct kobject *kobj);
67141+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
67142+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
67143 struct kobj_uevent_env *env);
67144 };
67145
67146@@ -132,7 +132,7 @@ struct kobj_attribute {
67147 const char *buf, size_t count);
67148 };
67149
67150-extern struct sysfs_ops kobj_sysfs_ops;
67151+extern const struct sysfs_ops kobj_sysfs_ops;
67152
67153 /**
67154 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
67155@@ -155,14 +155,14 @@ struct kset {
67156 struct list_head list;
67157 spinlock_t list_lock;
67158 struct kobject kobj;
67159- struct kset_uevent_ops *uevent_ops;
67160+ const struct kset_uevent_ops *uevent_ops;
67161 };
67162
67163 extern void kset_init(struct kset *kset);
67164 extern int __must_check kset_register(struct kset *kset);
67165 extern void kset_unregister(struct kset *kset);
67166 extern struct kset * __must_check kset_create_and_add(const char *name,
67167- struct kset_uevent_ops *u,
67168+ const struct kset_uevent_ops *u,
67169 struct kobject *parent_kobj);
67170
67171 static inline struct kset *to_kset(struct kobject *kobj)
67172diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
67173index c728a50..752d821 100644
67174--- a/include/linux/kvm_host.h
67175+++ b/include/linux/kvm_host.h
67176@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
67177 void vcpu_load(struct kvm_vcpu *vcpu);
67178 void vcpu_put(struct kvm_vcpu *vcpu);
67179
67180-int kvm_init(void *opaque, unsigned int vcpu_size,
67181+int kvm_init(const void *opaque, unsigned int vcpu_size,
67182 struct module *module);
67183 void kvm_exit(void);
67184
67185@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
67186 struct kvm_guest_debug *dbg);
67187 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
67188
67189-int kvm_arch_init(void *opaque);
67190+int kvm_arch_init(const void *opaque);
67191 void kvm_arch_exit(void);
67192
67193 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
67194diff --git a/include/linux/libata.h b/include/linux/libata.h
67195index a069916..223edde 100644
67196--- a/include/linux/libata.h
67197+++ b/include/linux/libata.h
67198@@ -525,11 +525,11 @@ struct ata_ioports {
67199
67200 struct ata_host {
67201 spinlock_t lock;
67202- struct device *dev;
67203+ struct device *dev;
67204 void __iomem * const *iomap;
67205 unsigned int n_ports;
67206 void *private_data;
67207- struct ata_port_operations *ops;
67208+ const struct ata_port_operations *ops;
67209 unsigned long flags;
67210 #ifdef CONFIG_ATA_ACPI
67211 acpi_handle acpi_handle;
67212@@ -710,7 +710,7 @@ struct ata_link {
67213
67214 struct ata_port {
67215 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
67216- struct ata_port_operations *ops;
67217+ const struct ata_port_operations *ops;
67218 spinlock_t *lock;
67219 /* Flags owned by the EH context. Only EH should touch these once the
67220 port is active */
67221@@ -884,7 +884,7 @@ struct ata_port_operations {
67222 * fields must be pointers.
67223 */
67224 const struct ata_port_operations *inherits;
67225-};
67226+} __do_const;
67227
67228 struct ata_port_info {
67229 unsigned long flags;
67230@@ -892,7 +892,7 @@ struct ata_port_info {
67231 unsigned long pio_mask;
67232 unsigned long mwdma_mask;
67233 unsigned long udma_mask;
67234- struct ata_port_operations *port_ops;
67235+ const struct ata_port_operations *port_ops;
67236 void *private_data;
67237 };
67238
67239@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timing_normal[];
67240 extern const unsigned long sata_deb_timing_hotplug[];
67241 extern const unsigned long sata_deb_timing_long[];
67242
67243-extern struct ata_port_operations ata_dummy_port_ops;
67244+extern const struct ata_port_operations ata_dummy_port_ops;
67245 extern const struct ata_port_info ata_dummy_port_info;
67246
67247 static inline const unsigned long *
67248@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_host *host, int irq,
67249 struct scsi_host_template *sht);
67250 extern void ata_host_detach(struct ata_host *host);
67251 extern void ata_host_init(struct ata_host *, struct device *,
67252- unsigned long, struct ata_port_operations *);
67253+ unsigned long, const struct ata_port_operations *);
67254 extern int ata_scsi_detect(struct scsi_host_template *sht);
67255 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
67256 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
67257diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h
67258index fbc48f8..0886e57 100644
67259--- a/include/linux/lockd/bind.h
67260+++ b/include/linux/lockd/bind.h
67261@@ -23,13 +23,13 @@ struct svc_rqst;
67262 * This is the set of functions for lockd->nfsd communication
67263 */
67264 struct nlmsvc_binding {
67265- __be32 (*fopen)(struct svc_rqst *,
67266+ __be32 (* const fopen)(struct svc_rqst *,
67267 struct nfs_fh *,
67268 struct file **);
67269- void (*fclose)(struct file *);
67270+ void (* const fclose)(struct file *);
67271 };
67272
67273-extern struct nlmsvc_binding * nlmsvc_ops;
67274+extern const struct nlmsvc_binding * nlmsvc_ops;
67275
67276 /*
67277 * Similar to nfs_client_initdata, but without the NFS-specific
67278diff --git a/include/linux/mca.h b/include/linux/mca.h
67279index 3797270..7765ede 100644
67280--- a/include/linux/mca.h
67281+++ b/include/linux/mca.h
67282@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
67283 int region);
67284 void * (*mca_transform_memory)(struct mca_device *,
67285 void *memory);
67286-};
67287+} __no_const;
67288
67289 struct mca_bus {
67290 u64 default_dma_mask;
67291diff --git a/include/linux/memory.h b/include/linux/memory.h
67292index 37fa19b..b597c85 100644
67293--- a/include/linux/memory.h
67294+++ b/include/linux/memory.h
67295@@ -108,7 +108,7 @@ struct memory_accessor {
67296 size_t count);
67297 ssize_t (*write)(struct memory_accessor *, const char *buf,
67298 off_t offset, size_t count);
67299-};
67300+} __no_const;
67301
67302 /*
67303 * Kernel text modification mutex, used for code patching. Users of this lock
67304diff --git a/include/linux/mm.h b/include/linux/mm.h
67305index 11e5be6..1ff2423 100644
67306--- a/include/linux/mm.h
67307+++ b/include/linux/mm.h
67308@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void *objp);
67309
67310 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
67311 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
67312+
67313+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
67314+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
67315+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
67316+#else
67317 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
67318+#endif
67319+
67320 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
67321 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
67322
67323@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
67324 int set_page_dirty_lock(struct page *page);
67325 int clear_page_dirty_for_io(struct page *page);
67326
67327-/* Is the vma a continuation of the stack vma above it? */
67328-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
67329-{
67330- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
67331-}
67332-
67333 extern unsigned long move_page_tables(struct vm_area_struct *vma,
67334 unsigned long old_addr, struct vm_area_struct *new_vma,
67335 unsigned long new_addr, unsigned long len);
67336@@ -890,6 +891,8 @@ struct shrinker {
67337 extern void register_shrinker(struct shrinker *);
67338 extern void unregister_shrinker(struct shrinker *);
67339
67340+pgprot_t vm_get_page_prot(unsigned long vm_flags);
67341+
67342 int vma_wants_writenotify(struct vm_area_struct *vma);
67343
67344 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
67345@@ -1162,6 +1165,7 @@ out:
67346 }
67347
67348 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
67349+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
67350
67351 extern unsigned long do_brk(unsigned long, unsigned long);
67352
67353@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
67354 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
67355 struct vm_area_struct **pprev);
67356
67357+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
67358+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
67359+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
67360+
67361 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
67362 NULL if none. Assume start_addr < end_addr. */
67363 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
67364@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
67365 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
67366 }
67367
67368-pgprot_t vm_get_page_prot(unsigned long vm_flags);
67369 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
67370 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
67371 unsigned long pfn, unsigned long size, pgprot_t);
67372@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long pfn, int trapno);
67373 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
67374 extern int sysctl_memory_failure_early_kill;
67375 extern int sysctl_memory_failure_recovery;
67376-extern atomic_long_t mce_bad_pages;
67377+extern atomic_long_unchecked_t mce_bad_pages;
67378+
67379+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67380+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
67381+#else
67382+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
67383+#endif
67384
67385 #endif /* __KERNEL__ */
67386 #endif /* _LINUX_MM_H */
67387diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
67388index 9d12ed5..8023125 100644
67389--- a/include/linux/mm_types.h
67390+++ b/include/linux/mm_types.h
67391@@ -186,6 +186,8 @@ struct vm_area_struct {
67392 #ifdef CONFIG_NUMA
67393 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
67394 #endif
67395+
67396+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
67397 };
67398
67399 struct core_thread {
67400@@ -287,6 +289,24 @@ struct mm_struct {
67401 #ifdef CONFIG_MMU_NOTIFIER
67402 struct mmu_notifier_mm *mmu_notifier_mm;
67403 #endif
67404+
67405+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67406+ unsigned long pax_flags;
67407+#endif
67408+
67409+#ifdef CONFIG_PAX_DLRESOLVE
67410+ unsigned long call_dl_resolve;
67411+#endif
67412+
67413+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
67414+ unsigned long call_syscall;
67415+#endif
67416+
67417+#ifdef CONFIG_PAX_ASLR
67418+ unsigned long delta_mmap; /* randomized offset */
67419+ unsigned long delta_stack; /* randomized offset */
67420+#endif
67421+
67422 };
67423
67424 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
67425diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
67426index 4e02ee2..afb159e 100644
67427--- a/include/linux/mmu_notifier.h
67428+++ b/include/linux/mmu_notifier.h
67429@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
67430 */
67431 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
67432 ({ \
67433- pte_t __pte; \
67434+ pte_t ___pte; \
67435 struct vm_area_struct *___vma = __vma; \
67436 unsigned long ___address = __address; \
67437- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
67438+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
67439 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
67440- __pte; \
67441+ ___pte; \
67442 })
67443
67444 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
67445diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
67446index 6c31a2a..4b0e930 100644
67447--- a/include/linux/mmzone.h
67448+++ b/include/linux/mmzone.h
67449@@ -350,7 +350,7 @@ struct zone {
67450 unsigned long flags; /* zone flags, see below */
67451
67452 /* Zone statistics */
67453- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67454+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67455
67456 /*
67457 * prev_priority holds the scanning priority for this zone. It is
67458diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
67459index f58e9d8..3503935 100644
67460--- a/include/linux/mod_devicetable.h
67461+++ b/include/linux/mod_devicetable.h
67462@@ -12,7 +12,7 @@
67463 typedef unsigned long kernel_ulong_t;
67464 #endif
67465
67466-#define PCI_ANY_ID (~0)
67467+#define PCI_ANY_ID ((__u16)~0)
67468
67469 struct pci_device_id {
67470 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
67471@@ -131,7 +131,7 @@ struct usb_device_id {
67472 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
67473 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
67474
67475-#define HID_ANY_ID (~0)
67476+#define HID_ANY_ID (~0U)
67477
67478 struct hid_device_id {
67479 __u16 bus;
67480diff --git a/include/linux/module.h b/include/linux/module.h
67481index 482efc8..642032b 100644
67482--- a/include/linux/module.h
67483+++ b/include/linux/module.h
67484@@ -16,6 +16,7 @@
67485 #include <linux/kobject.h>
67486 #include <linux/moduleparam.h>
67487 #include <linux/tracepoint.h>
67488+#include <linux/fs.h>
67489
67490 #include <asm/local.h>
67491 #include <asm/module.h>
67492@@ -287,16 +288,16 @@ struct module
67493 int (*init)(void);
67494
67495 /* If this is non-NULL, vfree after init() returns */
67496- void *module_init;
67497+ void *module_init_rx, *module_init_rw;
67498
67499 /* Here is the actual code + data, vfree'd on unload. */
67500- void *module_core;
67501+ void *module_core_rx, *module_core_rw;
67502
67503 /* Here are the sizes of the init and core sections */
67504- unsigned int init_size, core_size;
67505+ unsigned int init_size_rw, core_size_rw;
67506
67507 /* The size of the executable code in each section. */
67508- unsigned int init_text_size, core_text_size;
67509+ unsigned int init_size_rx, core_size_rx;
67510
67511 /* Arch-specific module values */
67512 struct mod_arch_specific arch;
67513@@ -345,6 +346,10 @@ struct module
67514 #ifdef CONFIG_EVENT_TRACING
67515 struct ftrace_event_call *trace_events;
67516 unsigned int num_trace_events;
67517+ struct file_operations trace_id;
67518+ struct file_operations trace_enable;
67519+ struct file_operations trace_format;
67520+ struct file_operations trace_filter;
67521 #endif
67522 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
67523 unsigned long *ftrace_callsites;
67524@@ -393,16 +398,46 @@ struct module *__module_address(unsigned long addr);
67525 bool is_module_address(unsigned long addr);
67526 bool is_module_text_address(unsigned long addr);
67527
67528+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
67529+{
67530+
67531+#ifdef CONFIG_PAX_KERNEXEC
67532+ if (ktla_ktva(addr) >= (unsigned long)start &&
67533+ ktla_ktva(addr) < (unsigned long)start + size)
67534+ return 1;
67535+#endif
67536+
67537+ return ((void *)addr >= start && (void *)addr < start + size);
67538+}
67539+
67540+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
67541+{
67542+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
67543+}
67544+
67545+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
67546+{
67547+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
67548+}
67549+
67550+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
67551+{
67552+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
67553+}
67554+
67555+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
67556+{
67557+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
67558+}
67559+
67560 static inline int within_module_core(unsigned long addr, struct module *mod)
67561 {
67562- return (unsigned long)mod->module_core <= addr &&
67563- addr < (unsigned long)mod->module_core + mod->core_size;
67564+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
67565 }
67566
67567 static inline int within_module_init(unsigned long addr, struct module *mod)
67568 {
67569- return (unsigned long)mod->module_init <= addr &&
67570- addr < (unsigned long)mod->module_init + mod->init_size;
67571+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
67572 }
67573
67574 /* Search for module by name: must hold module_mutex. */
67575diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
67576index c1f40c2..682ca53 100644
67577--- a/include/linux/moduleloader.h
67578+++ b/include/linux/moduleloader.h
67579@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
67580 sections. Returns NULL on failure. */
67581 void *module_alloc(unsigned long size);
67582
67583+#ifdef CONFIG_PAX_KERNEXEC
67584+void *module_alloc_exec(unsigned long size);
67585+#else
67586+#define module_alloc_exec(x) module_alloc(x)
67587+#endif
67588+
67589 /* Free memory returned from module_alloc. */
67590 void module_free(struct module *mod, void *module_region);
67591
67592+#ifdef CONFIG_PAX_KERNEXEC
67593+void module_free_exec(struct module *mod, void *module_region);
67594+#else
67595+#define module_free_exec(x, y) module_free((x), (y))
67596+#endif
67597+
67598 /* Apply the given relocation to the (simplified) ELF. Return -error
67599 or 0. */
67600 int apply_relocate(Elf_Shdr *sechdrs,
67601diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
67602index 82a9124..8a5f622 100644
67603--- a/include/linux/moduleparam.h
67604+++ b/include/linux/moduleparam.h
67605@@ -132,7 +132,7 @@ struct kparam_array
67606
67607 /* Actually copy string: maxlen param is usually sizeof(string). */
67608 #define module_param_string(name, string, len, perm) \
67609- static const struct kparam_string __param_string_##name \
67610+ static const struct kparam_string __param_string_##name __used \
67611 = { len, string }; \
67612 __module_param_call(MODULE_PARAM_PREFIX, name, \
67613 param_set_copystring, param_get_string, \
67614@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp);
67615
67616 /* Comma-separated array: *nump is set to number they actually specified. */
67617 #define module_param_array_named(name, array, type, nump, perm) \
67618- static const struct kparam_array __param_arr_##name \
67619+ static const struct kparam_array __param_arr_##name __used \
67620 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
67621 sizeof(array[0]), array }; \
67622 __module_param_call(MODULE_PARAM_PREFIX, name, \
67623diff --git a/include/linux/mutex.h b/include/linux/mutex.h
67624index 878cab4..c92cb3e 100644
67625--- a/include/linux/mutex.h
67626+++ b/include/linux/mutex.h
67627@@ -51,7 +51,7 @@ struct mutex {
67628 spinlock_t wait_lock;
67629 struct list_head wait_list;
67630 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
67631- struct thread_info *owner;
67632+ struct task_struct *owner;
67633 #endif
67634 #ifdef CONFIG_DEBUG_MUTEXES
67635 const char *name;
67636diff --git a/include/linux/namei.h b/include/linux/namei.h
67637index ec0f607..d19e675 100644
67638--- a/include/linux/namei.h
67639+++ b/include/linux/namei.h
67640@@ -22,7 +22,7 @@ struct nameidata {
67641 unsigned int flags;
67642 int last_type;
67643 unsigned depth;
67644- char *saved_names[MAX_NESTED_LINKS + 1];
67645+ const char *saved_names[MAX_NESTED_LINKS + 1];
67646
67647 /* Intent data */
67648 union {
67649@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
67650 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
67651 extern void unlock_rename(struct dentry *, struct dentry *);
67652
67653-static inline void nd_set_link(struct nameidata *nd, char *path)
67654+static inline void nd_set_link(struct nameidata *nd, const char *path)
67655 {
67656 nd->saved_names[nd->depth] = path;
67657 }
67658
67659-static inline char *nd_get_link(struct nameidata *nd)
67660+static inline const char *nd_get_link(const struct nameidata *nd)
67661 {
67662 return nd->saved_names[nd->depth];
67663 }
67664diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
67665index 9d7e8f7..04428c5 100644
67666--- a/include/linux/netdevice.h
67667+++ b/include/linux/netdevice.h
67668@@ -637,6 +637,7 @@ struct net_device_ops {
67669 u16 xid);
67670 #endif
67671 };
67672+typedef struct net_device_ops __no_const net_device_ops_no_const;
67673
67674 /*
67675 * The DEVICE structure.
67676diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
67677new file mode 100644
67678index 0000000..33f4af8
67679--- /dev/null
67680+++ b/include/linux/netfilter/xt_gradm.h
67681@@ -0,0 +1,9 @@
67682+#ifndef _LINUX_NETFILTER_XT_GRADM_H
67683+#define _LINUX_NETFILTER_XT_GRADM_H 1
67684+
67685+struct xt_gradm_mtinfo {
67686+ __u16 flags;
67687+ __u16 invflags;
67688+};
67689+
67690+#endif
67691diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
67692index b359c4a..c08b334 100644
67693--- a/include/linux/nodemask.h
67694+++ b/include/linux/nodemask.h
67695@@ -464,11 +464,11 @@ static inline int num_node_state(enum node_states state)
67696
67697 #define any_online_node(mask) \
67698 ({ \
67699- int node; \
67700- for_each_node_mask(node, (mask)) \
67701- if (node_online(node)) \
67702+ int __node; \
67703+ for_each_node_mask(__node, (mask)) \
67704+ if (node_online(__node)) \
67705 break; \
67706- node; \
67707+ __node; \
67708 })
67709
67710 #define num_online_nodes() num_node_state(N_ONLINE)
67711diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
67712index 5171639..7cf4235 100644
67713--- a/include/linux/oprofile.h
67714+++ b/include/linux/oprofile.h
67715@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
67716 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
67717 char const * name, ulong * val);
67718
67719-/** Create a file for read-only access to an atomic_t. */
67720+/** Create a file for read-only access to an atomic_unchecked_t. */
67721 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
67722- char const * name, atomic_t * val);
67723+ char const * name, atomic_unchecked_t * val);
67724
67725 /** create a directory */
67726 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
67727diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
67728index 3c62ed4..8924c7c 100644
67729--- a/include/linux/pagemap.h
67730+++ b/include/linux/pagemap.h
67731@@ -425,7 +425,9 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)
67732 if (((unsigned long)uaddr & PAGE_MASK) !=
67733 ((unsigned long)end & PAGE_MASK))
67734 ret = __get_user(c, end);
67735+ (void)c;
67736 }
67737+ (void)c;
67738 return ret;
67739 }
67740
67741diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
67742index 81c9689..a567a55 100644
67743--- a/include/linux/perf_event.h
67744+++ b/include/linux/perf_event.h
67745@@ -476,7 +476,7 @@ struct hw_perf_event {
67746 struct hrtimer hrtimer;
67747 };
67748 };
67749- atomic64_t prev_count;
67750+ atomic64_unchecked_t prev_count;
67751 u64 sample_period;
67752 u64 last_period;
67753 atomic64_t period_left;
67754@@ -557,7 +557,7 @@ struct perf_event {
67755 const struct pmu *pmu;
67756
67757 enum perf_event_active_state state;
67758- atomic64_t count;
67759+ atomic64_unchecked_t count;
67760
67761 /*
67762 * These are the total time in nanoseconds that the event
67763@@ -595,8 +595,8 @@ struct perf_event {
67764 * These accumulate total time (in nanoseconds) that children
67765 * events have been enabled and running, respectively.
67766 */
67767- atomic64_t child_total_time_enabled;
67768- atomic64_t child_total_time_running;
67769+ atomic64_unchecked_t child_total_time_enabled;
67770+ atomic64_unchecked_t child_total_time_running;
67771
67772 /*
67773 * Protect attach/detach and child_list:
67774diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
67775index b43a9e0..b77d869 100644
67776--- a/include/linux/pipe_fs_i.h
67777+++ b/include/linux/pipe_fs_i.h
67778@@ -46,9 +46,9 @@ struct pipe_inode_info {
67779 wait_queue_head_t wait;
67780 unsigned int nrbufs, curbuf;
67781 struct page *tmp_page;
67782- unsigned int readers;
67783- unsigned int writers;
67784- unsigned int waiting_writers;
67785+ atomic_t readers;
67786+ atomic_t writers;
67787+ atomic_t waiting_writers;
67788 unsigned int r_counter;
67789 unsigned int w_counter;
67790 struct fasync_struct *fasync_readers;
67791diff --git a/include/linux/poison.h b/include/linux/poison.h
67792index 34066ff..e95d744 100644
67793--- a/include/linux/poison.h
67794+++ b/include/linux/poison.h
67795@@ -19,8 +19,8 @@
67796 * under normal circumstances, used to verify that nobody uses
67797 * non-initialized list entries.
67798 */
67799-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
67800-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
67801+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
67802+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
67803
67804 /********** include/linux/timer.h **********/
67805 /*
67806diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
67807index 4f71bf4..77ffa64 100644
67808--- a/include/linux/posix-timers.h
67809+++ b/include/linux/posix-timers.h
67810@@ -67,7 +67,7 @@ struct k_itimer {
67811 };
67812
67813 struct k_clock {
67814- int res; /* in nanoseconds */
67815+ const int res; /* in nanoseconds */
67816 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
67817 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
67818 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
67819diff --git a/include/linux/preempt.h b/include/linux/preempt.h
67820index 72b1a10..13303a9 100644
67821--- a/include/linux/preempt.h
67822+++ b/include/linux/preempt.h
67823@@ -110,7 +110,7 @@ struct preempt_ops {
67824 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
67825 void (*sched_out)(struct preempt_notifier *notifier,
67826 struct task_struct *next);
67827-};
67828+} __no_const;
67829
67830 /**
67831 * preempt_notifier - key for installing preemption notifiers
67832diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
67833index 379eaed..1bf73e3 100644
67834--- a/include/linux/proc_fs.h
67835+++ b/include/linux/proc_fs.h
67836@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
67837 return proc_create_data(name, mode, parent, proc_fops, NULL);
67838 }
67839
67840+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
67841+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
67842+{
67843+#ifdef CONFIG_GRKERNSEC_PROC_USER
67844+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
67845+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67846+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
67847+#else
67848+ return proc_create_data(name, mode, parent, proc_fops, NULL);
67849+#endif
67850+}
67851+
67852+
67853 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
67854 mode_t mode, struct proc_dir_entry *base,
67855 read_proc_t *read_proc, void * data)
67856@@ -256,7 +269,7 @@ union proc_op {
67857 int (*proc_show)(struct seq_file *m,
67858 struct pid_namespace *ns, struct pid *pid,
67859 struct task_struct *task);
67860-};
67861+} __no_const;
67862
67863 struct ctl_table_header;
67864 struct ctl_table;
67865diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
67866index 7456d7d..6c1cfc9 100644
67867--- a/include/linux/ptrace.h
67868+++ b/include/linux/ptrace.h
67869@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_struct *child);
67870 extern void exit_ptrace(struct task_struct *tracer);
67871 #define PTRACE_MODE_READ 1
67872 #define PTRACE_MODE_ATTACH 2
67873-/* Returns 0 on success, -errno on denial. */
67874-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
67875 /* Returns true on success, false on denial. */
67876 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
67877+/* Returns true on success, false on denial. */
67878+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
67879
67880 static inline int ptrace_reparented(struct task_struct *child)
67881 {
67882diff --git a/include/linux/random.h b/include/linux/random.h
67883index 2948046..3262567 100644
67884--- a/include/linux/random.h
67885+++ b/include/linux/random.h
67886@@ -63,6 +63,11 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
67887 u32 random32(void);
67888 void srandom32(u32 seed);
67889
67890+static inline unsigned long pax_get_random_long(void)
67891+{
67892+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
67893+}
67894+
67895 #endif /* __KERNEL___ */
67896
67897 #endif /* _LINUX_RANDOM_H */
67898diff --git a/include/linux/reboot.h b/include/linux/reboot.h
67899index 988e55f..17cb4ef 100644
67900--- a/include/linux/reboot.h
67901+++ b/include/linux/reboot.h
67902@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
67903 * Architecture-specific implementations of sys_reboot commands.
67904 */
67905
67906-extern void machine_restart(char *cmd);
67907-extern void machine_halt(void);
67908-extern void machine_power_off(void);
67909+extern void machine_restart(char *cmd) __noreturn;
67910+extern void machine_halt(void) __noreturn;
67911+extern void machine_power_off(void) __noreturn;
67912
67913 extern void machine_shutdown(void);
67914 struct pt_regs;
67915@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
67916 */
67917
67918 extern void kernel_restart_prepare(char *cmd);
67919-extern void kernel_restart(char *cmd);
67920-extern void kernel_halt(void);
67921-extern void kernel_power_off(void);
67922+extern void kernel_restart(char *cmd) __noreturn;
67923+extern void kernel_halt(void) __noreturn;
67924+extern void kernel_power_off(void) __noreturn;
67925
67926 void ctrl_alt_del(void);
67927
67928@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
67929 * Emergency restart, callable from an interrupt handler.
67930 */
67931
67932-extern void emergency_restart(void);
67933+extern void emergency_restart(void) __noreturn;
67934 #include <asm/emergency-restart.h>
67935
67936 #endif
67937diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
67938index dd31e7b..5b03c5c 100644
67939--- a/include/linux/reiserfs_fs.h
67940+++ b/include/linux/reiserfs_fs.h
67941@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67942 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
67943
67944 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67945-#define get_generation(s) atomic_read (&fs_generation(s))
67946+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67947 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67948 #define __fs_changed(gen,s) (gen != get_generation (s))
67949 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
67950@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_from_bi(struct buffer_info *bi)
67951 */
67952
67953 struct item_operations {
67954- int (*bytes_number) (struct item_head * ih, int block_size);
67955- void (*decrement_key) (struct cpu_key *);
67956- int (*is_left_mergeable) (struct reiserfs_key * ih,
67957+ int (* const bytes_number) (struct item_head * ih, int block_size);
67958+ void (* const decrement_key) (struct cpu_key *);
67959+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
67960 unsigned long bsize);
67961- void (*print_item) (struct item_head *, char *item);
67962- void (*check_item) (struct item_head *, char *item);
67963+ void (* const print_item) (struct item_head *, char *item);
67964+ void (* const check_item) (struct item_head *, char *item);
67965
67966- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
67967+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
67968 int is_affected, int insert_size);
67969- int (*check_left) (struct virtual_item * vi, int free,
67970+ int (* const check_left) (struct virtual_item * vi, int free,
67971 int start_skip, int end_skip);
67972- int (*check_right) (struct virtual_item * vi, int free);
67973- int (*part_size) (struct virtual_item * vi, int from, int to);
67974- int (*unit_num) (struct virtual_item * vi);
67975- void (*print_vi) (struct virtual_item * vi);
67976+ int (* const check_right) (struct virtual_item * vi, int free);
67977+ int (* const part_size) (struct virtual_item * vi, int from, int to);
67978+ int (* const unit_num) (struct virtual_item * vi);
67979+ void (* const print_vi) (struct virtual_item * vi);
67980 };
67981
67982-extern struct item_operations *item_ops[TYPE_ANY + 1];
67983+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
67984
67985 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
67986 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
67987diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
67988index dab68bb..0688727 100644
67989--- a/include/linux/reiserfs_fs_sb.h
67990+++ b/include/linux/reiserfs_fs_sb.h
67991@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
67992 /* Comment? -Hans */
67993 wait_queue_head_t s_wait;
67994 /* To be obsoleted soon by per buffer seals.. -Hans */
67995- atomic_t s_generation_counter; // increased by one every time the
67996+ atomic_unchecked_t s_generation_counter; // increased by one every time the
67997 // tree gets re-balanced
67998 unsigned long s_properties; /* File system properties. Currently holds
67999 on-disk FS format */
68000diff --git a/include/linux/relay.h b/include/linux/relay.h
68001index 14a86bc..17d0700 100644
68002--- a/include/linux/relay.h
68003+++ b/include/linux/relay.h
68004@@ -159,7 +159,7 @@ struct rchan_callbacks
68005 * The callback should return 0 if successful, negative if not.
68006 */
68007 int (*remove_buf_file)(struct dentry *dentry);
68008-};
68009+} __no_const;
68010
68011 /*
68012 * CONFIG_RELAY kernel API, kernel/relay.c
68013diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
68014index 3392c59..a746428 100644
68015--- a/include/linux/rfkill.h
68016+++ b/include/linux/rfkill.h
68017@@ -144,6 +144,7 @@ struct rfkill_ops {
68018 void (*query)(struct rfkill *rfkill, void *data);
68019 int (*set_block)(void *data, bool blocked);
68020 };
68021+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
68022
68023 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
68024 /**
68025diff --git a/include/linux/sched.h b/include/linux/sched.h
68026index 71849bf..40217dc 100644
68027--- a/include/linux/sched.h
68028+++ b/include/linux/sched.h
68029@@ -101,6 +101,7 @@ struct bio;
68030 struct fs_struct;
68031 struct bts_context;
68032 struct perf_event_context;
68033+struct linux_binprm;
68034
68035 /*
68036 * List of flags we want to share for kernel threads,
68037@@ -350,7 +351,7 @@ extern signed long schedule_timeout_killable(signed long timeout);
68038 extern signed long schedule_timeout_uninterruptible(signed long timeout);
68039 asmlinkage void __schedule(void);
68040 asmlinkage void schedule(void);
68041-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
68042+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
68043
68044 struct nsproxy;
68045 struct user_namespace;
68046@@ -371,9 +372,12 @@ struct user_namespace;
68047 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
68048
68049 extern int sysctl_max_map_count;
68050+extern unsigned long sysctl_heap_stack_gap;
68051
68052 #include <linux/aio.h>
68053
68054+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
68055+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
68056 extern unsigned long
68057 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
68058 unsigned long, unsigned long);
68059@@ -666,6 +670,16 @@ struct signal_struct {
68060 struct tty_audit_buf *tty_audit_buf;
68061 #endif
68062
68063+#ifdef CONFIG_GRKERNSEC
68064+ u32 curr_ip;
68065+ u32 saved_ip;
68066+ u32 gr_saddr;
68067+ u32 gr_daddr;
68068+ u16 gr_sport;
68069+ u16 gr_dport;
68070+ u8 used_accept:1;
68071+#endif
68072+
68073 int oom_adj; /* OOM kill score adjustment (bit shift) */
68074 };
68075
68076@@ -723,6 +737,11 @@ struct user_struct {
68077 struct key *session_keyring; /* UID's default session keyring */
68078 #endif
68079
68080+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
68081+ unsigned int banned;
68082+ unsigned long ban_expires;
68083+#endif
68084+
68085 /* Hash table maintenance information */
68086 struct hlist_node uidhash_node;
68087 uid_t uid;
68088@@ -1328,8 +1347,8 @@ struct task_struct {
68089 struct list_head thread_group;
68090
68091 struct completion *vfork_done; /* for vfork() */
68092- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
68093- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68094+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
68095+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68096
68097 cputime_t utime, stime, utimescaled, stimescaled;
68098 cputime_t gtime;
68099@@ -1343,16 +1362,6 @@ struct task_struct {
68100 struct task_cputime cputime_expires;
68101 struct list_head cpu_timers[3];
68102
68103-/* process credentials */
68104- const struct cred *real_cred; /* objective and real subjective task
68105- * credentials (COW) */
68106- const struct cred *cred; /* effective (overridable) subjective task
68107- * credentials (COW) */
68108- struct mutex cred_guard_mutex; /* guard against foreign influences on
68109- * credential calculations
68110- * (notably. ptrace) */
68111- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68112-
68113 char comm[TASK_COMM_LEN]; /* executable name excluding path
68114 - access with [gs]et_task_comm (which lock
68115 it with task_lock())
68116@@ -1369,6 +1378,10 @@ struct task_struct {
68117 #endif
68118 /* CPU-specific state of this task */
68119 struct thread_struct thread;
68120+/* thread_info moved to task_struct */
68121+#ifdef CONFIG_X86
68122+ struct thread_info tinfo;
68123+#endif
68124 /* filesystem information */
68125 struct fs_struct *fs;
68126 /* open file information */
68127@@ -1436,6 +1449,15 @@ struct task_struct {
68128 int hardirq_context;
68129 int softirq_context;
68130 #endif
68131+
68132+/* process credentials */
68133+ const struct cred *real_cred; /* objective and real subjective task
68134+ * credentials (COW) */
68135+ struct mutex cred_guard_mutex; /* guard against foreign influences on
68136+ * credential calculations
68137+ * (notably. ptrace) */
68138+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68139+
68140 #ifdef CONFIG_LOCKDEP
68141 # define MAX_LOCK_DEPTH 48UL
68142 u64 curr_chain_key;
68143@@ -1456,6 +1478,9 @@ struct task_struct {
68144
68145 struct backing_dev_info *backing_dev_info;
68146
68147+ const struct cred *cred; /* effective (overridable) subjective task
68148+ * credentials (COW) */
68149+
68150 struct io_context *io_context;
68151
68152 unsigned long ptrace_message;
68153@@ -1519,6 +1544,21 @@ struct task_struct {
68154 unsigned long default_timer_slack_ns;
68155
68156 struct list_head *scm_work_list;
68157+
68158+#ifdef CONFIG_GRKERNSEC
68159+ /* grsecurity */
68160+ struct dentry *gr_chroot_dentry;
68161+ struct acl_subject_label *acl;
68162+ struct acl_role_label *role;
68163+ struct file *exec_file;
68164+ u16 acl_role_id;
68165+ /* is this the task that authenticated to the special role */
68166+ u8 acl_sp_role;
68167+ u8 is_writable;
68168+ u8 brute;
68169+ u8 gr_is_chrooted;
68170+#endif
68171+
68172 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
68173 /* Index of current stored adress in ret_stack */
68174 int curr_ret_stack;
68175@@ -1542,6 +1582,57 @@ struct task_struct {
68176 #endif /* CONFIG_TRACING */
68177 };
68178
68179+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
68180+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
68181+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
68182+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
68183+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
68184+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
68185+
68186+#ifdef CONFIG_PAX_SOFTMODE
68187+extern int pax_softmode;
68188+#endif
68189+
68190+extern int pax_check_flags(unsigned long *);
68191+
68192+/* if tsk != current then task_lock must be held on it */
68193+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68194+static inline unsigned long pax_get_flags(struct task_struct *tsk)
68195+{
68196+ if (likely(tsk->mm))
68197+ return tsk->mm->pax_flags;
68198+ else
68199+ return 0UL;
68200+}
68201+
68202+/* if tsk != current then task_lock must be held on it */
68203+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
68204+{
68205+ if (likely(tsk->mm)) {
68206+ tsk->mm->pax_flags = flags;
68207+ return 0;
68208+ }
68209+ return -EINVAL;
68210+}
68211+#endif
68212+
68213+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68214+extern void pax_set_initial_flags(struct linux_binprm *bprm);
68215+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
68216+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
68217+#endif
68218+
68219+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
68220+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
68221+extern void pax_report_refcount_overflow(struct pt_regs *regs);
68222+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
68223+
68224+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
68225+extern void pax_track_stack(void);
68226+#else
68227+static inline void pax_track_stack(void) {}
68228+#endif
68229+
68230 /* Future-safe accessor for struct task_struct's cpus_allowed. */
68231 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
68232
68233@@ -1740,7 +1831,7 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
68234 #define PF_DUMPCORE 0x00000200 /* dumped core */
68235 #define PF_SIGNALED 0x00000400 /* killed by a signal */
68236 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
68237-#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
68238+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
68239 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
68240 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
68241 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
68242@@ -1978,7 +2069,9 @@ void yield(void);
68243 extern struct exec_domain default_exec_domain;
68244
68245 union thread_union {
68246+#ifndef CONFIG_X86
68247 struct thread_info thread_info;
68248+#endif
68249 unsigned long stack[THREAD_SIZE/sizeof(long)];
68250 };
68251
68252@@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
68253 */
68254
68255 extern struct task_struct *find_task_by_vpid(pid_t nr);
68256+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
68257 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
68258 struct pid_namespace *ns);
68259
68260@@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
68261 extern void exit_itimers(struct signal_struct *);
68262 extern void flush_itimer_signals(void);
68263
68264-extern NORET_TYPE void do_group_exit(int);
68265+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
68266
68267 extern void daemonize(const char *, ...);
68268 extern int allow_signal(int);
68269@@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
68270
68271 #endif
68272
68273-static inline int object_is_on_stack(void *obj)
68274+static inline int object_starts_on_stack(void *obj)
68275 {
68276- void *stack = task_stack_page(current);
68277+ const void *stack = task_stack_page(current);
68278
68279 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
68280 }
68281
68282+#ifdef CONFIG_PAX_USERCOPY
68283+extern int object_is_on_stack(const void *obj, unsigned long len);
68284+#endif
68285+
68286 extern void thread_info_cache_init(void);
68287
68288 #ifdef CONFIG_DEBUG_STACK_USAGE
68289diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
68290index 1ee2c05..81b7ec4 100644
68291--- a/include/linux/screen_info.h
68292+++ b/include/linux/screen_info.h
68293@@ -42,7 +42,8 @@ struct screen_info {
68294 __u16 pages; /* 0x32 */
68295 __u16 vesa_attributes; /* 0x34 */
68296 __u32 capabilities; /* 0x36 */
68297- __u8 _reserved[6]; /* 0x3a */
68298+ __u16 vesapm_size; /* 0x3a */
68299+ __u8 _reserved[4]; /* 0x3c */
68300 } __attribute__((packed));
68301
68302 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68303diff --git a/include/linux/security.h b/include/linux/security.h
68304index d40d23f..253bd14 100644
68305--- a/include/linux/security.h
68306+++ b/include/linux/security.h
68307@@ -34,6 +34,7 @@
68308 #include <linux/key.h>
68309 #include <linux/xfrm.h>
68310 #include <linux/gfp.h>
68311+#include <linux/grsecurity.h>
68312 #include <net/flow.h>
68313
68314 /* Maximum number of letters for an LSM name string */
68315diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
68316index 8366d8f..2307490 100644
68317--- a/include/linux/seq_file.h
68318+++ b/include/linux/seq_file.h
68319@@ -32,6 +32,7 @@ struct seq_operations {
68320 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
68321 int (*show) (struct seq_file *m, void *v);
68322 };
68323+typedef struct seq_operations __no_const seq_operations_no_const;
68324
68325 #define SEQ_SKIP 1
68326
68327diff --git a/include/linux/shm.h b/include/linux/shm.h
68328index eca6235..c7417ed 100644
68329--- a/include/linux/shm.h
68330+++ b/include/linux/shm.h
68331@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the kernel */
68332 pid_t shm_cprid;
68333 pid_t shm_lprid;
68334 struct user_struct *mlock_user;
68335+#ifdef CONFIG_GRKERNSEC
68336+ time_t shm_createtime;
68337+ pid_t shm_lapid;
68338+#endif
68339 };
68340
68341 /* shm_mode upper byte flags */
68342diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
68343index bcdd660..6e12e11 100644
68344--- a/include/linux/skbuff.h
68345+++ b/include/linux/skbuff.h
68346@@ -14,6 +14,7 @@
68347 #ifndef _LINUX_SKBUFF_H
68348 #define _LINUX_SKBUFF_H
68349
68350+#include <linux/const.h>
68351 #include <linux/kernel.h>
68352 #include <linux/kmemcheck.h>
68353 #include <linux/compiler.h>
68354@@ -544,7 +545,7 @@ static inline union skb_shared_tx *skb_tx(struct sk_buff *skb)
68355 */
68356 static inline int skb_queue_empty(const struct sk_buff_head *list)
68357 {
68358- return list->next == (struct sk_buff *)list;
68359+ return list->next == (const struct sk_buff *)list;
68360 }
68361
68362 /**
68363@@ -557,7 +558,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
68364 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68365 const struct sk_buff *skb)
68366 {
68367- return (skb->next == (struct sk_buff *) list);
68368+ return (skb->next == (const struct sk_buff *) list);
68369 }
68370
68371 /**
68372@@ -570,7 +571,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68373 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
68374 const struct sk_buff *skb)
68375 {
68376- return (skb->prev == (struct sk_buff *) list);
68377+ return (skb->prev == (const struct sk_buff *) list);
68378 }
68379
68380 /**
68381@@ -1367,7 +1368,7 @@ static inline int skb_network_offset(const struct sk_buff *skb)
68382 * headroom, you should not reduce this.
68383 */
68384 #ifndef NET_SKB_PAD
68385-#define NET_SKB_PAD 32
68386+#define NET_SKB_PAD (_AC(32,UL))
68387 #endif
68388
68389 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
68390diff --git a/include/linux/slab.h b/include/linux/slab.h
68391index 2da8372..a3be824 100644
68392--- a/include/linux/slab.h
68393+++ b/include/linux/slab.h
68394@@ -11,12 +11,20 @@
68395
68396 #include <linux/gfp.h>
68397 #include <linux/types.h>
68398+#include <linux/err.h>
68399
68400 /*
68401 * Flags to pass to kmem_cache_create().
68402 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
68403 */
68404 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
68405+
68406+#ifdef CONFIG_PAX_USERCOPY
68407+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
68408+#else
68409+#define SLAB_USERCOPY 0x00000000UL
68410+#endif
68411+
68412 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
68413 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
68414 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
68415@@ -82,10 +90,13 @@
68416 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
68417 * Both make kfree a no-op.
68418 */
68419-#define ZERO_SIZE_PTR ((void *)16)
68420+#define ZERO_SIZE_PTR \
68421+({ \
68422+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
68423+ (void *)(-MAX_ERRNO-1L); \
68424+})
68425
68426-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
68427- (unsigned long)ZERO_SIZE_PTR)
68428+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
68429
68430 /*
68431 * struct kmem_cache related prototypes
68432@@ -138,6 +149,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
68433 void kfree(const void *);
68434 void kzfree(const void *);
68435 size_t ksize(const void *);
68436+void check_object_size(const void *ptr, unsigned long n, bool to);
68437
68438 /*
68439 * Allocator specific definitions. These are mainly used to establish optimized
68440@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
68441
68442 void __init kmem_cache_init_late(void);
68443
68444+#define kmalloc(x, y) \
68445+({ \
68446+ void *___retval; \
68447+ intoverflow_t ___x = (intoverflow_t)x; \
68448+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
68449+ ___retval = NULL; \
68450+ else \
68451+ ___retval = kmalloc((size_t)___x, (y)); \
68452+ ___retval; \
68453+})
68454+
68455+#define kmalloc_node(x, y, z) \
68456+({ \
68457+ void *___retval; \
68458+ intoverflow_t ___x = (intoverflow_t)x; \
68459+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
68460+ ___retval = NULL; \
68461+ else \
68462+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
68463+ ___retval; \
68464+})
68465+
68466+#define kzalloc(x, y) \
68467+({ \
68468+ void *___retval; \
68469+ intoverflow_t ___x = (intoverflow_t)x; \
68470+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
68471+ ___retval = NULL; \
68472+ else \
68473+ ___retval = kzalloc((size_t)___x, (y)); \
68474+ ___retval; \
68475+})
68476+
68477 #endif /* _LINUX_SLAB_H */
68478diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
68479index 850d057..d9dfe3c 100644
68480--- a/include/linux/slab_def.h
68481+++ b/include/linux/slab_def.h
68482@@ -69,10 +69,10 @@ struct kmem_cache {
68483 unsigned long node_allocs;
68484 unsigned long node_frees;
68485 unsigned long node_overflow;
68486- atomic_t allochit;
68487- atomic_t allocmiss;
68488- atomic_t freehit;
68489- atomic_t freemiss;
68490+ atomic_unchecked_t allochit;
68491+ atomic_unchecked_t allocmiss;
68492+ atomic_unchecked_t freehit;
68493+ atomic_unchecked_t freemiss;
68494
68495 /*
68496 * If debugging is enabled, then the allocator can add additional
68497diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
68498index 5ad70a6..57f9f65 100644
68499--- a/include/linux/slub_def.h
68500+++ b/include/linux/slub_def.h
68501@@ -86,7 +86,7 @@ struct kmem_cache {
68502 struct kmem_cache_order_objects max;
68503 struct kmem_cache_order_objects min;
68504 gfp_t allocflags; /* gfp flags to use on each alloc */
68505- int refcount; /* Refcount for slab cache destroy */
68506+ atomic_t refcount; /* Refcount for slab cache destroy */
68507 void (*ctor)(void *);
68508 int inuse; /* Offset to metadata */
68509 int align; /* Alignment */
68510@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
68511 #endif
68512
68513 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
68514-void *__kmalloc(size_t size, gfp_t flags);
68515+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
68516
68517 #ifdef CONFIG_KMEMTRACE
68518 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
68519diff --git a/include/linux/sonet.h b/include/linux/sonet.h
68520index 67ad11f..0bbd8af 100644
68521--- a/include/linux/sonet.h
68522+++ b/include/linux/sonet.h
68523@@ -61,7 +61,7 @@ struct sonet_stats {
68524 #include <asm/atomic.h>
68525
68526 struct k_sonet_stats {
68527-#define __HANDLE_ITEM(i) atomic_t i
68528+#define __HANDLE_ITEM(i) atomic_unchecked_t i
68529 __SONET_ITEMS
68530 #undef __HANDLE_ITEM
68531 };
68532diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
68533index 6f52b4d..5500323 100644
68534--- a/include/linux/sunrpc/cache.h
68535+++ b/include/linux/sunrpc/cache.h
68536@@ -125,7 +125,7 @@ struct cache_detail {
68537 */
68538 struct cache_req {
68539 struct cache_deferred_req *(*defer)(struct cache_req *req);
68540-};
68541+} __no_const;
68542 /* this must be embedded in a deferred_request that is being
68543 * delayed awaiting cache-fill
68544 */
68545diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
68546index 8ed9642..101ceab 100644
68547--- a/include/linux/sunrpc/clnt.h
68548+++ b/include/linux/sunrpc/clnt.h
68549@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
68550 {
68551 switch (sap->sa_family) {
68552 case AF_INET:
68553- return ntohs(((struct sockaddr_in *)sap)->sin_port);
68554+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
68555 case AF_INET6:
68556- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
68557+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
68558 }
68559 return 0;
68560 }
68561@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
68562 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
68563 const struct sockaddr *src)
68564 {
68565- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
68566+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
68567 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
68568
68569 dsin->sin_family = ssin->sin_family;
68570@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
68571 if (sa->sa_family != AF_INET6)
68572 return 0;
68573
68574- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
68575+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
68576 }
68577
68578 #endif /* __KERNEL__ */
68579diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
68580index c14fe86..393245e 100644
68581--- a/include/linux/sunrpc/svc_rdma.h
68582+++ b/include/linux/sunrpc/svc_rdma.h
68583@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
68584 extern unsigned int svcrdma_max_requests;
68585 extern unsigned int svcrdma_max_req_size;
68586
68587-extern atomic_t rdma_stat_recv;
68588-extern atomic_t rdma_stat_read;
68589-extern atomic_t rdma_stat_write;
68590-extern atomic_t rdma_stat_sq_starve;
68591-extern atomic_t rdma_stat_rq_starve;
68592-extern atomic_t rdma_stat_rq_poll;
68593-extern atomic_t rdma_stat_rq_prod;
68594-extern atomic_t rdma_stat_sq_poll;
68595-extern atomic_t rdma_stat_sq_prod;
68596+extern atomic_unchecked_t rdma_stat_recv;
68597+extern atomic_unchecked_t rdma_stat_read;
68598+extern atomic_unchecked_t rdma_stat_write;
68599+extern atomic_unchecked_t rdma_stat_sq_starve;
68600+extern atomic_unchecked_t rdma_stat_rq_starve;
68601+extern atomic_unchecked_t rdma_stat_rq_poll;
68602+extern atomic_unchecked_t rdma_stat_rq_prod;
68603+extern atomic_unchecked_t rdma_stat_sq_poll;
68604+extern atomic_unchecked_t rdma_stat_sq_prod;
68605
68606 #define RPCRDMA_VERSION 1
68607
68608diff --git a/include/linux/suspend.h b/include/linux/suspend.h
68609index 5e781d8..1e62818 100644
68610--- a/include/linux/suspend.h
68611+++ b/include/linux/suspend.h
68612@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
68613 * which require special recovery actions in that situation.
68614 */
68615 struct platform_suspend_ops {
68616- int (*valid)(suspend_state_t state);
68617- int (*begin)(suspend_state_t state);
68618- int (*prepare)(void);
68619- int (*prepare_late)(void);
68620- int (*enter)(suspend_state_t state);
68621- void (*wake)(void);
68622- void (*finish)(void);
68623- void (*end)(void);
68624- void (*recover)(void);
68625+ int (* const valid)(suspend_state_t state);
68626+ int (* const begin)(suspend_state_t state);
68627+ int (* const prepare)(void);
68628+ int (* const prepare_late)(void);
68629+ int (* const enter)(suspend_state_t state);
68630+ void (* const wake)(void);
68631+ void (* const finish)(void);
68632+ void (* const end)(void);
68633+ void (* const recover)(void);
68634 };
68635
68636 #ifdef CONFIG_SUSPEND
68637@@ -120,7 +120,7 @@ struct platform_suspend_ops {
68638 * suspend_set_ops - set platform dependent suspend operations
68639 * @ops: The new suspend operations to set.
68640 */
68641-extern void suspend_set_ops(struct platform_suspend_ops *ops);
68642+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
68643 extern int suspend_valid_only_mem(suspend_state_t state);
68644
68645 /**
68646@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t state);
68647 #else /* !CONFIG_SUSPEND */
68648 #define suspend_valid_only_mem NULL
68649
68650-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
68651+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
68652 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
68653 #endif /* !CONFIG_SUSPEND */
68654
68655@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone *zone);
68656 * platforms which require special recovery actions in that situation.
68657 */
68658 struct platform_hibernation_ops {
68659- int (*begin)(void);
68660- void (*end)(void);
68661- int (*pre_snapshot)(void);
68662- void (*finish)(void);
68663- int (*prepare)(void);
68664- int (*enter)(void);
68665- void (*leave)(void);
68666- int (*pre_restore)(void);
68667- void (*restore_cleanup)(void);
68668- void (*recover)(void);
68669+ int (* const begin)(void);
68670+ void (* const end)(void);
68671+ int (* const pre_snapshot)(void);
68672+ void (* const finish)(void);
68673+ int (* const prepare)(void);
68674+ int (* const enter)(void);
68675+ void (* const leave)(void);
68676+ int (* const pre_restore)(void);
68677+ void (* const restore_cleanup)(void);
68678+ void (* const recover)(void);
68679 };
68680
68681 #ifdef CONFIG_HIBERNATION
68682@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct page *);
68683 extern void swsusp_unset_page_free(struct page *);
68684 extern unsigned long get_safe_page(gfp_t gfp_mask);
68685
68686-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
68687+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
68688 extern int hibernate(void);
68689 extern bool system_entering_hibernation(void);
68690 #else /* CONFIG_HIBERNATION */
68691@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
68692 static inline void swsusp_set_page_free(struct page *p) {}
68693 static inline void swsusp_unset_page_free(struct page *p) {}
68694
68695-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
68696+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
68697 static inline int hibernate(void) { return -ENOSYS; }
68698 static inline bool system_entering_hibernation(void) { return false; }
68699 #endif /* CONFIG_HIBERNATION */
68700diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
68701index 0eb6942..a805cb6 100644
68702--- a/include/linux/sysctl.h
68703+++ b/include/linux/sysctl.h
68704@@ -164,7 +164,11 @@ enum
68705 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68706 };
68707
68708-
68709+#ifdef CONFIG_PAX_SOFTMODE
68710+enum {
68711+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68712+};
68713+#endif
68714
68715 /* CTL_VM names: */
68716 enum
68717@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
68718
68719 extern int proc_dostring(struct ctl_table *, int,
68720 void __user *, size_t *, loff_t *);
68721+extern int proc_dostring_modpriv(struct ctl_table *, int,
68722+ void __user *, size_t *, loff_t *);
68723 extern int proc_dointvec(struct ctl_table *, int,
68724 void __user *, size_t *, loff_t *);
68725 extern int proc_dointvec_minmax(struct ctl_table *, int,
68726@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name, int nlen,
68727
68728 extern ctl_handler sysctl_data;
68729 extern ctl_handler sysctl_string;
68730+extern ctl_handler sysctl_string_modpriv;
68731 extern ctl_handler sysctl_intvec;
68732 extern ctl_handler sysctl_jiffies;
68733 extern ctl_handler sysctl_ms_jiffies;
68734diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
68735index 9d68fed..71f02cc 100644
68736--- a/include/linux/sysfs.h
68737+++ b/include/linux/sysfs.h
68738@@ -75,8 +75,8 @@ struct bin_attribute {
68739 };
68740
68741 struct sysfs_ops {
68742- ssize_t (*show)(struct kobject *, struct attribute *,char *);
68743- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
68744+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
68745+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
68746 };
68747
68748 struct sysfs_dirent;
68749diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
68750index a8cc4e1..98d3b85 100644
68751--- a/include/linux/thread_info.h
68752+++ b/include/linux/thread_info.h
68753@@ -23,7 +23,7 @@ struct restart_block {
68754 };
68755 /* For futex_wait and futex_wait_requeue_pi */
68756 struct {
68757- u32 *uaddr;
68758+ u32 __user *uaddr;
68759 u32 val;
68760 u32 flags;
68761 u32 bitset;
68762diff --git a/include/linux/tty.h b/include/linux/tty.h
68763index e9c57e9..ee6d489 100644
68764--- a/include/linux/tty.h
68765+++ b/include/linux/tty.h
68766@@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
68767 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
68768 extern void tty_ldisc_enable(struct tty_struct *tty);
68769
68770-
68771 /* n_tty.c */
68772 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
68773
68774diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
68775index 0c4ee9b..9f7c426 100644
68776--- a/include/linux/tty_ldisc.h
68777+++ b/include/linux/tty_ldisc.h
68778@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
68779
68780 struct module *owner;
68781
68782- int refcount;
68783+ atomic_t refcount;
68784 };
68785
68786 struct tty_ldisc {
68787diff --git a/include/linux/types.h b/include/linux/types.h
68788index c42724f..d190eee 100644
68789--- a/include/linux/types.h
68790+++ b/include/linux/types.h
68791@@ -191,10 +191,26 @@ typedef struct {
68792 volatile int counter;
68793 } atomic_t;
68794
68795+#ifdef CONFIG_PAX_REFCOUNT
68796+typedef struct {
68797+ volatile int counter;
68798+} atomic_unchecked_t;
68799+#else
68800+typedef atomic_t atomic_unchecked_t;
68801+#endif
68802+
68803 #ifdef CONFIG_64BIT
68804 typedef struct {
68805 volatile long counter;
68806 } atomic64_t;
68807+
68808+#ifdef CONFIG_PAX_REFCOUNT
68809+typedef struct {
68810+ volatile long counter;
68811+} atomic64_unchecked_t;
68812+#else
68813+typedef atomic64_t atomic64_unchecked_t;
68814+#endif
68815 #endif
68816
68817 struct ustat {
68818diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
68819index 6b58367..53a3e8e 100644
68820--- a/include/linux/uaccess.h
68821+++ b/include/linux/uaccess.h
68822@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
68823 long ret; \
68824 mm_segment_t old_fs = get_fs(); \
68825 \
68826- set_fs(KERNEL_DS); \
68827 pagefault_disable(); \
68828- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
68829- pagefault_enable(); \
68830+ set_fs(KERNEL_DS); \
68831+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
68832 set_fs(old_fs); \
68833+ pagefault_enable(); \
68834 ret; \
68835 })
68836
68837@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_user_nocache(void *to,
68838 * Safely read from address @src to the buffer at @dst. If a kernel fault
68839 * happens, handle that and return -EFAULT.
68840 */
68841-extern long probe_kernel_read(void *dst, void *src, size_t size);
68842+extern long probe_kernel_read(void *dst, const void *src, size_t size);
68843
68844 /*
68845 * probe_kernel_write(): safely attempt to write to a location
68846@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst, void *src, size_t size);
68847 * Safely write to address @dst from the buffer at @src. If a kernel fault
68848 * happens, handle that and return -EFAULT.
68849 */
68850-extern long probe_kernel_write(void *dst, void *src, size_t size);
68851+extern long probe_kernel_write(void *dst, const void *src, size_t size);
68852
68853 #endif /* __LINUX_UACCESS_H__ */
68854diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
68855index 99c1b4d..bb94261 100644
68856--- a/include/linux/unaligned/access_ok.h
68857+++ b/include/linux/unaligned/access_ok.h
68858@@ -6,32 +6,32 @@
68859
68860 static inline u16 get_unaligned_le16(const void *p)
68861 {
68862- return le16_to_cpup((__le16 *)p);
68863+ return le16_to_cpup((const __le16 *)p);
68864 }
68865
68866 static inline u32 get_unaligned_le32(const void *p)
68867 {
68868- return le32_to_cpup((__le32 *)p);
68869+ return le32_to_cpup((const __le32 *)p);
68870 }
68871
68872 static inline u64 get_unaligned_le64(const void *p)
68873 {
68874- return le64_to_cpup((__le64 *)p);
68875+ return le64_to_cpup((const __le64 *)p);
68876 }
68877
68878 static inline u16 get_unaligned_be16(const void *p)
68879 {
68880- return be16_to_cpup((__be16 *)p);
68881+ return be16_to_cpup((const __be16 *)p);
68882 }
68883
68884 static inline u32 get_unaligned_be32(const void *p)
68885 {
68886- return be32_to_cpup((__be32 *)p);
68887+ return be32_to_cpup((const __be32 *)p);
68888 }
68889
68890 static inline u64 get_unaligned_be64(const void *p)
68891 {
68892- return be64_to_cpup((__be64 *)p);
68893+ return be64_to_cpup((const __be64 *)p);
68894 }
68895
68896 static inline void put_unaligned_le16(u16 val, void *p)
68897diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
68898index 79b9837..b5a56f9 100644
68899--- a/include/linux/vermagic.h
68900+++ b/include/linux/vermagic.h
68901@@ -26,9 +26,35 @@
68902 #define MODULE_ARCH_VERMAGIC ""
68903 #endif
68904
68905+#ifdef CONFIG_PAX_REFCOUNT
68906+#define MODULE_PAX_REFCOUNT "REFCOUNT "
68907+#else
68908+#define MODULE_PAX_REFCOUNT ""
68909+#endif
68910+
68911+#ifdef CONSTIFY_PLUGIN
68912+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
68913+#else
68914+#define MODULE_CONSTIFY_PLUGIN ""
68915+#endif
68916+
68917+#ifdef STACKLEAK_PLUGIN
68918+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
68919+#else
68920+#define MODULE_STACKLEAK_PLUGIN ""
68921+#endif
68922+
68923+#ifdef CONFIG_GRKERNSEC
68924+#define MODULE_GRSEC "GRSEC "
68925+#else
68926+#define MODULE_GRSEC ""
68927+#endif
68928+
68929 #define VERMAGIC_STRING \
68930 UTS_RELEASE " " \
68931 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
68932 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
68933- MODULE_ARCH_VERMAGIC
68934+ MODULE_ARCH_VERMAGIC \
68935+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
68936+ MODULE_GRSEC
68937
68938diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
68939index 819a634..462ac12 100644
68940--- a/include/linux/vmalloc.h
68941+++ b/include/linux/vmalloc.h
68942@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
68943 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
68944 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
68945 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
68946+
68947+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
68948+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
68949+#endif
68950+
68951 /* bits [20..32] reserved for arch specific ioremap internals */
68952
68953 /*
68954@@ -124,4 +129,81 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
68955
68956 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
68957
68958+#define vmalloc(x) \
68959+({ \
68960+ void *___retval; \
68961+ intoverflow_t ___x = (intoverflow_t)x; \
68962+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
68963+ ___retval = NULL; \
68964+ else \
68965+ ___retval = vmalloc((unsigned long)___x); \
68966+ ___retval; \
68967+})
68968+
68969+#define __vmalloc(x, y, z) \
68970+({ \
68971+ void *___retval; \
68972+ intoverflow_t ___x = (intoverflow_t)x; \
68973+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
68974+ ___retval = NULL; \
68975+ else \
68976+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
68977+ ___retval; \
68978+})
68979+
68980+#define vmalloc_user(x) \
68981+({ \
68982+ void *___retval; \
68983+ intoverflow_t ___x = (intoverflow_t)x; \
68984+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
68985+ ___retval = NULL; \
68986+ else \
68987+ ___retval = vmalloc_user((unsigned long)___x); \
68988+ ___retval; \
68989+})
68990+
68991+#define vmalloc_exec(x) \
68992+({ \
68993+ void *___retval; \
68994+ intoverflow_t ___x = (intoverflow_t)x; \
68995+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
68996+ ___retval = NULL; \
68997+ else \
68998+ ___retval = vmalloc_exec((unsigned long)___x); \
68999+ ___retval; \
69000+})
69001+
69002+#define vmalloc_node(x, y) \
69003+({ \
69004+ void *___retval; \
69005+ intoverflow_t ___x = (intoverflow_t)x; \
69006+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
69007+ ___retval = NULL; \
69008+ else \
69009+ ___retval = vmalloc_node((unsigned long)___x, (y));\
69010+ ___retval; \
69011+})
69012+
69013+#define vmalloc_32(x) \
69014+({ \
69015+ void *___retval; \
69016+ intoverflow_t ___x = (intoverflow_t)x; \
69017+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
69018+ ___retval = NULL; \
69019+ else \
69020+ ___retval = vmalloc_32((unsigned long)___x); \
69021+ ___retval; \
69022+})
69023+
69024+#define vmalloc_32_user(x) \
69025+({ \
69026+ void *___retval; \
69027+ intoverflow_t ___x = (intoverflow_t)x; \
69028+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
69029+ ___retval = NULL; \
69030+ else \
69031+ ___retval = vmalloc_32_user((unsigned long)___x);\
69032+ ___retval; \
69033+})
69034+
69035 #endif /* _LINUX_VMALLOC_H */
69036diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
69037index 13070d6..aa4159a 100644
69038--- a/include/linux/vmstat.h
69039+++ b/include/linux/vmstat.h
69040@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(int cpu)
69041 /*
69042 * Zone based page accounting with per cpu differentials.
69043 */
69044-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69045+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69046
69047 static inline void zone_page_state_add(long x, struct zone *zone,
69048 enum zone_stat_item item)
69049 {
69050- atomic_long_add(x, &zone->vm_stat[item]);
69051- atomic_long_add(x, &vm_stat[item]);
69052+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
69053+ atomic_long_add_unchecked(x, &vm_stat[item]);
69054 }
69055
69056 static inline unsigned long global_page_state(enum zone_stat_item item)
69057 {
69058- long x = atomic_long_read(&vm_stat[item]);
69059+ long x = atomic_long_read_unchecked(&vm_stat[item]);
69060 #ifdef CONFIG_SMP
69061 if (x < 0)
69062 x = 0;
69063@@ -158,7 +158,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
69064 static inline unsigned long zone_page_state(struct zone *zone,
69065 enum zone_stat_item item)
69066 {
69067- long x = atomic_long_read(&zone->vm_stat[item]);
69068+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69069 #ifdef CONFIG_SMP
69070 if (x < 0)
69071 x = 0;
69072@@ -175,7 +175,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
69073 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
69074 enum zone_stat_item item)
69075 {
69076- long x = atomic_long_read(&zone->vm_stat[item]);
69077+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69078
69079 #ifdef CONFIG_SMP
69080 int cpu;
69081@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
69082
69083 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
69084 {
69085- atomic_long_inc(&zone->vm_stat[item]);
69086- atomic_long_inc(&vm_stat[item]);
69087+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
69088+ atomic_long_inc_unchecked(&vm_stat[item]);
69089 }
69090
69091 static inline void __inc_zone_page_state(struct page *page,
69092@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state(struct page *page,
69093
69094 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
69095 {
69096- atomic_long_dec(&zone->vm_stat[item]);
69097- atomic_long_dec(&vm_stat[item]);
69098+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
69099+ atomic_long_dec_unchecked(&vm_stat[item]);
69100 }
69101
69102 static inline void __dec_zone_page_state(struct page *page,
69103diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
69104index eed5fcc..5080d24 100644
69105--- a/include/media/saa7146_vv.h
69106+++ b/include/media/saa7146_vv.h
69107@@ -167,7 +167,7 @@ struct saa7146_ext_vv
69108 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
69109
69110 /* the extension can override this */
69111- struct v4l2_ioctl_ops ops;
69112+ v4l2_ioctl_ops_no_const ops;
69113 /* pointer to the saa7146 core ops */
69114 const struct v4l2_ioctl_ops *core_ops;
69115
69116diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
69117index 73c9867..2da8837 100644
69118--- a/include/media/v4l2-dev.h
69119+++ b/include/media/v4l2-dev.h
69120@@ -34,7 +34,7 @@ struct v4l2_device;
69121 #define V4L2_FL_UNREGISTERED (0)
69122
69123 struct v4l2_file_operations {
69124- struct module *owner;
69125+ struct module * const owner;
69126 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
69127 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
69128 unsigned int (*poll) (struct file *, struct poll_table_struct *);
69129@@ -46,6 +46,7 @@ struct v4l2_file_operations {
69130 int (*open) (struct file *);
69131 int (*release) (struct file *);
69132 };
69133+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
69134
69135 /*
69136 * Newer version of video_device, handled by videodev2.c
69137diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
69138index 5d5d550..f559ef1 100644
69139--- a/include/media/v4l2-device.h
69140+++ b/include/media/v4l2-device.h
69141@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
69142 this function returns 0. If the name ends with a digit (e.g. cx18),
69143 then the name will be set to cx18-0 since cx180 looks really odd. */
69144 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
69145- atomic_t *instance);
69146+ atomic_unchecked_t *instance);
69147
69148 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
69149 Since the parent disappears this ensures that v4l2_dev doesn't have an
69150diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
69151index 7a4529d..7244290 100644
69152--- a/include/media/v4l2-ioctl.h
69153+++ b/include/media/v4l2-ioctl.h
69154@@ -243,6 +243,7 @@ struct v4l2_ioctl_ops {
69155 long (*vidioc_default) (struct file *file, void *fh,
69156 int cmd, void *arg);
69157 };
69158+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
69159
69160
69161 /* v4l debugging and diagnostics */
69162diff --git a/include/net/flow.h b/include/net/flow.h
69163index 809970b..c3df4f3 100644
69164--- a/include/net/flow.h
69165+++ b/include/net/flow.h
69166@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net *net, struct flowi *key, u16 family,
69167 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
69168 u8 dir, flow_resolve_t resolver);
69169 extern void flow_cache_flush(void);
69170-extern atomic_t flow_cache_genid;
69171+extern atomic_unchecked_t flow_cache_genid;
69172
69173 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
69174 {
69175diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
69176index 15e1f8fe..668837c 100644
69177--- a/include/net/inetpeer.h
69178+++ b/include/net/inetpeer.h
69179@@ -24,7 +24,7 @@ struct inet_peer
69180 __u32 dtime; /* the time of last use of not
69181 * referenced entries */
69182 atomic_t refcnt;
69183- atomic_t rid; /* Frag reception counter */
69184+ atomic_unchecked_t rid; /* Frag reception counter */
69185 __u32 tcp_ts;
69186 unsigned long tcp_ts_stamp;
69187 };
69188diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
69189index 98978e7..2243a3d 100644
69190--- a/include/net/ip_vs.h
69191+++ b/include/net/ip_vs.h
69192@@ -365,7 +365,7 @@ struct ip_vs_conn {
69193 struct ip_vs_conn *control; /* Master control connection */
69194 atomic_t n_control; /* Number of controlled ones */
69195 struct ip_vs_dest *dest; /* real server */
69196- atomic_t in_pkts; /* incoming packet counter */
69197+ atomic_unchecked_t in_pkts; /* incoming packet counter */
69198
69199 /* packet transmitter for different forwarding methods. If it
69200 mangles the packet, it must return NF_DROP or better NF_STOLEN,
69201@@ -466,7 +466,7 @@ struct ip_vs_dest {
69202 union nf_inet_addr addr; /* IP address of the server */
69203 __be16 port; /* port number of the server */
69204 volatile unsigned flags; /* dest status flags */
69205- atomic_t conn_flags; /* flags to copy to conn */
69206+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
69207 atomic_t weight; /* server weight */
69208
69209 atomic_t refcnt; /* reference counter */
69210diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
69211index 69b610a..fe3962c 100644
69212--- a/include/net/irda/ircomm_core.h
69213+++ b/include/net/irda/ircomm_core.h
69214@@ -51,7 +51,7 @@ typedef struct {
69215 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
69216 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
69217 struct ircomm_info *);
69218-} call_t;
69219+} __no_const call_t;
69220
69221 struct ircomm_cb {
69222 irda_queue_t queue;
69223diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
69224index eea2e61..08c692d 100644
69225--- a/include/net/irda/ircomm_tty.h
69226+++ b/include/net/irda/ircomm_tty.h
69227@@ -35,6 +35,7 @@
69228 #include <linux/termios.h>
69229 #include <linux/timer.h>
69230 #include <linux/tty.h> /* struct tty_struct */
69231+#include <asm/local.h>
69232
69233 #include <net/irda/irias_object.h>
69234 #include <net/irda/ircomm_core.h>
69235@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
69236 unsigned short close_delay;
69237 unsigned short closing_wait; /* time to wait before closing */
69238
69239- int open_count;
69240- int blocked_open; /* # of blocked opens */
69241+ local_t open_count;
69242+ local_t blocked_open; /* # of blocked opens */
69243
69244 /* Protect concurent access to :
69245 * o self->open_count
69246diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
69247index f82a1e8..82d81e8 100644
69248--- a/include/net/iucv/af_iucv.h
69249+++ b/include/net/iucv/af_iucv.h
69250@@ -87,7 +87,7 @@ struct iucv_sock {
69251 struct iucv_sock_list {
69252 struct hlist_head head;
69253 rwlock_t lock;
69254- atomic_t autobind_name;
69255+ atomic_unchecked_t autobind_name;
69256 };
69257
69258 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
69259diff --git a/include/net/lapb.h b/include/net/lapb.h
69260index 96cb5dd..25e8d4f 100644
69261--- a/include/net/lapb.h
69262+++ b/include/net/lapb.h
69263@@ -95,7 +95,7 @@ struct lapb_cb {
69264 struct sk_buff_head write_queue;
69265 struct sk_buff_head ack_queue;
69266 unsigned char window;
69267- struct lapb_register_struct callbacks;
69268+ struct lapb_register_struct *callbacks;
69269
69270 /* FRMR control information */
69271 struct lapb_frame frmr_data;
69272diff --git a/include/net/neighbour.h b/include/net/neighbour.h
69273index 3817fda..cdb2343 100644
69274--- a/include/net/neighbour.h
69275+++ b/include/net/neighbour.h
69276@@ -131,7 +131,7 @@ struct neigh_ops
69277 int (*connected_output)(struct sk_buff*);
69278 int (*hh_output)(struct sk_buff*);
69279 int (*queue_xmit)(struct sk_buff*);
69280-};
69281+} __do_const;
69282
69283 struct pneigh_entry
69284 {
69285diff --git a/include/net/netlink.h b/include/net/netlink.h
69286index c344646..4778c71 100644
69287--- a/include/net/netlink.h
69288+++ b/include/net/netlink.h
69289@@ -335,7 +335,7 @@ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
69290 {
69291 return (remaining >= (int) sizeof(struct nlmsghdr) &&
69292 nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
69293- nlh->nlmsg_len <= remaining);
69294+ nlh->nlmsg_len <= (unsigned int)remaining);
69295 }
69296
69297 /**
69298@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
69299 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
69300 {
69301 if (mark)
69302- skb_trim(skb, (unsigned char *) mark - skb->data);
69303+ skb_trim(skb, (const unsigned char *) mark - skb->data);
69304 }
69305
69306 /**
69307diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
69308index 9a4b8b7..e49e077 100644
69309--- a/include/net/netns/ipv4.h
69310+++ b/include/net/netns/ipv4.h
69311@@ -54,7 +54,7 @@ struct netns_ipv4 {
69312 int current_rt_cache_rebuild_count;
69313
69314 struct timer_list rt_secret_timer;
69315- atomic_t rt_genid;
69316+ atomic_unchecked_t rt_genid;
69317
69318 #ifdef CONFIG_IP_MROUTE
69319 struct sock *mroute_sk;
69320diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
69321index 8a6d529..171f401 100644
69322--- a/include/net/sctp/sctp.h
69323+++ b/include/net/sctp/sctp.h
69324@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
69325
69326 #else /* SCTP_DEBUG */
69327
69328-#define SCTP_DEBUG_PRINTK(whatever...)
69329-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
69330+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
69331+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
69332 #define SCTP_ENABLE_DEBUG
69333 #define SCTP_DISABLE_DEBUG
69334 #define SCTP_ASSERT(expr, str, func)
69335diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
69336index d97f689..f3b90ab 100644
69337--- a/include/net/secure_seq.h
69338+++ b/include/net/secure_seq.h
69339@@ -7,14 +7,14 @@ extern __u32 secure_ip_id(__be32 daddr);
69340 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
69341 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
69342 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
69343- __be16 dport);
69344+ __be16 dport);
69345 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
69346 __be16 sport, __be16 dport);
69347 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69348- __be16 sport, __be16 dport);
69349+ __be16 sport, __be16 dport);
69350 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
69351- __be16 sport, __be16 dport);
69352+ __be16 sport, __be16 dport);
69353 extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69354- __be16 sport, __be16 dport);
69355+ __be16 sport, __be16 dport);
69356
69357 #endif /* _NET_SECURE_SEQ */
69358diff --git a/include/net/sock.h b/include/net/sock.h
69359index 9f96394..76fc9c7 100644
69360--- a/include/net/sock.h
69361+++ b/include/net/sock.h
69362@@ -272,7 +272,7 @@ struct sock {
69363 rwlock_t sk_callback_lock;
69364 int sk_err,
69365 sk_err_soft;
69366- atomic_t sk_drops;
69367+ atomic_unchecked_t sk_drops;
69368 unsigned short sk_ack_backlog;
69369 unsigned short sk_max_ack_backlog;
69370 __u32 sk_priority;
69371@@ -737,7 +737,7 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
69372 extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
69373 extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
69374 #else
69375-static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
69376+static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
69377 int inc)
69378 {
69379 }
69380diff --git a/include/net/tcp.h b/include/net/tcp.h
69381index 6cfe18b..dd21acb 100644
69382--- a/include/net/tcp.h
69383+++ b/include/net/tcp.h
69384@@ -1444,8 +1444,8 @@ enum tcp_seq_states {
69385 struct tcp_seq_afinfo {
69386 char *name;
69387 sa_family_t family;
69388- struct file_operations seq_fops;
69389- struct seq_operations seq_ops;
69390+ file_operations_no_const seq_fops;
69391+ seq_operations_no_const seq_ops;
69392 };
69393
69394 struct tcp_iter_state {
69395diff --git a/include/net/udp.h b/include/net/udp.h
69396index f98abd2..b4b042f 100644
69397--- a/include/net/udp.h
69398+++ b/include/net/udp.h
69399@@ -187,8 +187,8 @@ struct udp_seq_afinfo {
69400 char *name;
69401 sa_family_t family;
69402 struct udp_table *udp_table;
69403- struct file_operations seq_fops;
69404- struct seq_operations seq_ops;
69405+ file_operations_no_const seq_fops;
69406+ seq_operations_no_const seq_ops;
69407 };
69408
69409 struct udp_iter_state {
69410diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
69411index cbb822e..e9c1cbe 100644
69412--- a/include/rdma/iw_cm.h
69413+++ b/include/rdma/iw_cm.h
69414@@ -129,7 +129,7 @@ struct iw_cm_verbs {
69415 int backlog);
69416
69417 int (*destroy_listen)(struct iw_cm_id *cm_id);
69418-};
69419+} __no_const;
69420
69421 /**
69422 * iw_create_cm_id - Create an IW CM identifier.
69423diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
69424index 09a124b..caa8ca8 100644
69425--- a/include/scsi/libfc.h
69426+++ b/include/scsi/libfc.h
69427@@ -675,6 +675,7 @@ struct libfc_function_template {
69428 */
69429 void (*disc_stop_final) (struct fc_lport *);
69430 };
69431+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
69432
69433 /* information used by the discovery layer */
69434 struct fc_disc {
69435@@ -707,7 +708,7 @@ struct fc_lport {
69436 struct fc_disc disc;
69437
69438 /* Operational Information */
69439- struct libfc_function_template tt;
69440+ libfc_function_template_no_const tt;
69441 u8 link_up;
69442 u8 qfull;
69443 enum fc_lport_state state;
69444diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
69445index de8e180..f15e0d7 100644
69446--- a/include/scsi/scsi_device.h
69447+++ b/include/scsi/scsi_device.h
69448@@ -156,9 +156,9 @@ struct scsi_device {
69449 unsigned int max_device_blocked; /* what device_blocked counts down from */
69450 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
69451
69452- atomic_t iorequest_cnt;
69453- atomic_t iodone_cnt;
69454- atomic_t ioerr_cnt;
69455+ atomic_unchecked_t iorequest_cnt;
69456+ atomic_unchecked_t iodone_cnt;
69457+ atomic_unchecked_t ioerr_cnt;
69458
69459 struct device sdev_gendev,
69460 sdev_dev;
69461diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
69462index fc50bd6..81ba9cb 100644
69463--- a/include/scsi/scsi_transport_fc.h
69464+++ b/include/scsi/scsi_transport_fc.h
69465@@ -708,7 +708,7 @@ struct fc_function_template {
69466 unsigned long show_host_system_hostname:1;
69467
69468 unsigned long disable_target_scan:1;
69469-};
69470+} __do_const;
69471
69472
69473 /**
69474diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
69475index 3dae3f7..8440d6f 100644
69476--- a/include/sound/ac97_codec.h
69477+++ b/include/sound/ac97_codec.h
69478@@ -419,15 +419,15 @@
69479 struct snd_ac97;
69480
69481 struct snd_ac97_build_ops {
69482- int (*build_3d) (struct snd_ac97 *ac97);
69483- int (*build_specific) (struct snd_ac97 *ac97);
69484- int (*build_spdif) (struct snd_ac97 *ac97);
69485- int (*build_post_spdif) (struct snd_ac97 *ac97);
69486+ int (* const build_3d) (struct snd_ac97 *ac97);
69487+ int (* const build_specific) (struct snd_ac97 *ac97);
69488+ int (* const build_spdif) (struct snd_ac97 *ac97);
69489+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
69490 #ifdef CONFIG_PM
69491- void (*suspend) (struct snd_ac97 *ac97);
69492- void (*resume) (struct snd_ac97 *ac97);
69493+ void (* const suspend) (struct snd_ac97 *ac97);
69494+ void (* const resume) (struct snd_ac97 *ac97);
69495 #endif
69496- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69497+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69498 };
69499
69500 struct snd_ac97_bus_ops {
69501@@ -477,7 +477,7 @@ struct snd_ac97_template {
69502
69503 struct snd_ac97 {
69504 /* -- lowlevel (hardware) driver specific -- */
69505- struct snd_ac97_build_ops * build_ops;
69506+ const struct snd_ac97_build_ops * build_ops;
69507 void *private_data;
69508 void (*private_free) (struct snd_ac97 *ac97);
69509 /* --- */
69510diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
69511index 891cf1a..a94ba2b 100644
69512--- a/include/sound/ak4xxx-adda.h
69513+++ b/include/sound/ak4xxx-adda.h
69514@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
69515 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
69516 unsigned char val);
69517 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
69518-};
69519+} __no_const;
69520
69521 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
69522
69523diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
69524index 8c05e47..2b5df97 100644
69525--- a/include/sound/hwdep.h
69526+++ b/include/sound/hwdep.h
69527@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
69528 struct snd_hwdep_dsp_status *status);
69529 int (*dsp_load)(struct snd_hwdep *hw,
69530 struct snd_hwdep_dsp_image *image);
69531-};
69532+} __no_const;
69533
69534 struct snd_hwdep {
69535 struct snd_card *card;
69536diff --git a/include/sound/info.h b/include/sound/info.h
69537index 112e894..6fda5b5 100644
69538--- a/include/sound/info.h
69539+++ b/include/sound/info.h
69540@@ -44,7 +44,7 @@ struct snd_info_entry_text {
69541 struct snd_info_buffer *buffer);
69542 void (*write)(struct snd_info_entry *entry,
69543 struct snd_info_buffer *buffer);
69544-};
69545+} __no_const;
69546
69547 struct snd_info_entry_ops {
69548 int (*open)(struct snd_info_entry *entry,
69549diff --git a/include/sound/pcm.h b/include/sound/pcm.h
69550index de6d981..590a550 100644
69551--- a/include/sound/pcm.h
69552+++ b/include/sound/pcm.h
69553@@ -80,6 +80,7 @@ struct snd_pcm_ops {
69554 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
69555 int (*ack)(struct snd_pcm_substream *substream);
69556 };
69557+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
69558
69559 /*
69560 *
69561diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
69562index 736eac7..fe8a80f 100644
69563--- a/include/sound/sb16_csp.h
69564+++ b/include/sound/sb16_csp.h
69565@@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
69566 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
69567 int (*csp_stop) (struct snd_sb_csp * p);
69568 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
69569-};
69570+} __no_const;
69571
69572 /*
69573 * CSP private data
69574diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
69575index 444cd6b..3327cc5 100644
69576--- a/include/sound/ymfpci.h
69577+++ b/include/sound/ymfpci.h
69578@@ -358,7 +358,7 @@ struct snd_ymfpci {
69579 spinlock_t reg_lock;
69580 spinlock_t voice_lock;
69581 wait_queue_head_t interrupt_sleep;
69582- atomic_t interrupt_sleep_count;
69583+ atomic_unchecked_t interrupt_sleep_count;
69584 struct snd_info_entry *proc_entry;
69585 const struct firmware *dsp_microcode;
69586 const struct firmware *controller_microcode;
69587diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
69588index b89f9db..f097b38 100644
69589--- a/include/trace/events/irq.h
69590+++ b/include/trace/events/irq.h
69591@@ -34,7 +34,7 @@
69592 */
69593 TRACE_EVENT(irq_handler_entry,
69594
69595- TP_PROTO(int irq, struct irqaction *action),
69596+ TP_PROTO(int irq, const struct irqaction *action),
69597
69598 TP_ARGS(irq, action),
69599
69600@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
69601 */
69602 TRACE_EVENT(irq_handler_exit,
69603
69604- TP_PROTO(int irq, struct irqaction *action, int ret),
69605+ TP_PROTO(int irq, const struct irqaction *action, int ret),
69606
69607 TP_ARGS(irq, action, ret),
69608
69609@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
69610 */
69611 TRACE_EVENT(softirq_entry,
69612
69613- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69614+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69615
69616 TP_ARGS(h, vec),
69617
69618@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
69619 */
69620 TRACE_EVENT(softirq_exit,
69621
69622- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69623+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69624
69625 TP_ARGS(h, vec),
69626
69627diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
69628index 0993a22..32ba2fe 100644
69629--- a/include/video/uvesafb.h
69630+++ b/include/video/uvesafb.h
69631@@ -177,6 +177,7 @@ struct uvesafb_par {
69632 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
69633 u8 pmi_setpal; /* PMI for palette changes */
69634 u16 *pmi_base; /* protected mode interface location */
69635+ u8 *pmi_code; /* protected mode code location */
69636 void *pmi_start;
69637 void *pmi_pal;
69638 u8 *vbe_state_orig; /*
69639diff --git a/init/Kconfig b/init/Kconfig
69640index d72691b..3996e54 100644
69641--- a/init/Kconfig
69642+++ b/init/Kconfig
69643@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
69644
69645 config COMPAT_BRK
69646 bool "Disable heap randomization"
69647- default y
69648+ default n
69649 help
69650 Randomizing heap placement makes heap exploits harder, but it
69651 also breaks ancient binaries (including anything libc5 based).
69652diff --git a/init/do_mounts.c b/init/do_mounts.c
69653index bb008d0..4fa3933 100644
69654--- a/init/do_mounts.c
69655+++ b/init/do_mounts.c
69656@@ -216,11 +216,11 @@ static void __init get_fs_names(char *page)
69657
69658 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
69659 {
69660- int err = sys_mount(name, "/root", fs, flags, data);
69661+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
69662 if (err)
69663 return err;
69664
69665- sys_chdir("/root");
69666+ sys_chdir((__force const char __user *)"/root");
69667 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
69668 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
69669 current->fs->pwd.mnt->mnt_sb->s_type->name,
69670@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...)
69671 va_start(args, fmt);
69672 vsprintf(buf, fmt, args);
69673 va_end(args);
69674- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
69675+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
69676 if (fd >= 0) {
69677 sys_ioctl(fd, FDEJECT, 0);
69678 sys_close(fd);
69679 }
69680 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
69681- fd = sys_open("/dev/console", O_RDWR, 0);
69682+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
69683 if (fd >= 0) {
69684 sys_ioctl(fd, TCGETS, (long)&termios);
69685 termios.c_lflag &= ~ICANON;
69686 sys_ioctl(fd, TCSETSF, (long)&termios);
69687- sys_read(fd, &c, 1);
69688+ sys_read(fd, (char __user *)&c, 1);
69689 termios.c_lflag |= ICANON;
69690 sys_ioctl(fd, TCSETSF, (long)&termios);
69691 sys_close(fd);
69692@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
69693 mount_root();
69694 out:
69695 devtmpfs_mount("dev");
69696- sys_mount(".", "/", NULL, MS_MOVE, NULL);
69697- sys_chroot(".");
69698+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
69699+ sys_chroot((__force char __user *)".");
69700 }
69701diff --git a/init/do_mounts.h b/init/do_mounts.h
69702index f5b978a..69dbfe8 100644
69703--- a/init/do_mounts.h
69704+++ b/init/do_mounts.h
69705@@ -15,15 +15,15 @@ extern int root_mountflags;
69706
69707 static inline int create_dev(char *name, dev_t dev)
69708 {
69709- sys_unlink(name);
69710- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
69711+ sys_unlink((char __force_user *)name);
69712+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
69713 }
69714
69715 #if BITS_PER_LONG == 32
69716 static inline u32 bstat(char *name)
69717 {
69718 struct stat64 stat;
69719- if (sys_stat64(name, &stat) != 0)
69720+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
69721 return 0;
69722 if (!S_ISBLK(stat.st_mode))
69723 return 0;
69724@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
69725 static inline u32 bstat(char *name)
69726 {
69727 struct stat stat;
69728- if (sys_newstat(name, &stat) != 0)
69729+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
69730 return 0;
69731 if (!S_ISBLK(stat.st_mode))
69732 return 0;
69733diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
69734index 614241b..4da046b 100644
69735--- a/init/do_mounts_initrd.c
69736+++ b/init/do_mounts_initrd.c
69737@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shell)
69738 sys_close(old_fd);sys_close(root_fd);
69739 sys_close(0);sys_close(1);sys_close(2);
69740 sys_setsid();
69741- (void) sys_open("/dev/console",O_RDWR,0);
69742+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
69743 (void) sys_dup(0);
69744 (void) sys_dup(0);
69745 return kernel_execve(shell, argv, envp_init);
69746@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
69747 create_dev("/dev/root.old", Root_RAM0);
69748 /* mount initrd on rootfs' /root */
69749 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
69750- sys_mkdir("/old", 0700);
69751- root_fd = sys_open("/", 0, 0);
69752- old_fd = sys_open("/old", 0, 0);
69753+ sys_mkdir((const char __force_user *)"/old", 0700);
69754+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
69755+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
69756 /* move initrd over / and chdir/chroot in initrd root */
69757- sys_chdir("/root");
69758- sys_mount(".", "/", NULL, MS_MOVE, NULL);
69759- sys_chroot(".");
69760+ sys_chdir((const char __force_user *)"/root");
69761+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
69762+ sys_chroot((const char __force_user *)".");
69763
69764 /*
69765 * In case that a resume from disk is carried out by linuxrc or one of
69766@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
69767
69768 /* move initrd to rootfs' /old */
69769 sys_fchdir(old_fd);
69770- sys_mount("/", ".", NULL, MS_MOVE, NULL);
69771+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
69772 /* switch root and cwd back to / of rootfs */
69773 sys_fchdir(root_fd);
69774- sys_chroot(".");
69775+ sys_chroot((const char __force_user *)".");
69776 sys_close(old_fd);
69777 sys_close(root_fd);
69778
69779 if (new_decode_dev(real_root_dev) == Root_RAM0) {
69780- sys_chdir("/old");
69781+ sys_chdir((const char __force_user *)"/old");
69782 return;
69783 }
69784
69785@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
69786 mount_root();
69787
69788 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
69789- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
69790+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
69791 if (!error)
69792 printk("okay\n");
69793 else {
69794- int fd = sys_open("/dev/root.old", O_RDWR, 0);
69795+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
69796 if (error == -ENOENT)
69797 printk("/initrd does not exist. Ignored.\n");
69798 else
69799 printk("failed\n");
69800 printk(KERN_NOTICE "Unmounting old root\n");
69801- sys_umount("/old", MNT_DETACH);
69802+ sys_umount((char __force_user *)"/old", MNT_DETACH);
69803 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
69804 if (fd < 0) {
69805 error = fd;
69806@@ -119,11 +119,11 @@ int __init initrd_load(void)
69807 * mounted in the normal path.
69808 */
69809 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
69810- sys_unlink("/initrd.image");
69811+ sys_unlink((const char __force_user *)"/initrd.image");
69812 handle_initrd();
69813 return 1;
69814 }
69815 }
69816- sys_unlink("/initrd.image");
69817+ sys_unlink((const char __force_user *)"/initrd.image");
69818 return 0;
69819 }
69820diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
69821index 69aebbf..c0bf6a7 100644
69822--- a/init/do_mounts_md.c
69823+++ b/init/do_mounts_md.c
69824@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
69825 partitioned ? "_d" : "", minor,
69826 md_setup_args[ent].device_names);
69827
69828- fd = sys_open(name, 0, 0);
69829+ fd = sys_open((char __force_user *)name, 0, 0);
69830 if (fd < 0) {
69831 printk(KERN_ERR "md: open failed - cannot start "
69832 "array %s\n", name);
69833@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
69834 * array without it
69835 */
69836 sys_close(fd);
69837- fd = sys_open(name, 0, 0);
69838+ fd = sys_open((char __force_user *)name, 0, 0);
69839 sys_ioctl(fd, BLKRRPART, 0);
69840 }
69841 sys_close(fd);
69842@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
69843
69844 wait_for_device_probe();
69845
69846- fd = sys_open("/dev/md0", 0, 0);
69847+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
69848 if (fd >= 0) {
69849 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
69850 sys_close(fd);
69851diff --git a/init/initramfs.c b/init/initramfs.c
69852index 1fd59b8..a01b079 100644
69853--- a/init/initramfs.c
69854+++ b/init/initramfs.c
69855@@ -74,7 +74,7 @@ static void __init free_hash(void)
69856 }
69857 }
69858
69859-static long __init do_utime(char __user *filename, time_t mtime)
69860+static long __init do_utime(__force char __user *filename, time_t mtime)
69861 {
69862 struct timespec t[2];
69863
69864@@ -109,7 +109,7 @@ static void __init dir_utime(void)
69865 struct dir_entry *de, *tmp;
69866 list_for_each_entry_safe(de, tmp, &dir_list, list) {
69867 list_del(&de->list);
69868- do_utime(de->name, de->mtime);
69869+ do_utime((char __force_user *)de->name, de->mtime);
69870 kfree(de->name);
69871 kfree(de);
69872 }
69873@@ -271,7 +271,7 @@ static int __init maybe_link(void)
69874 if (nlink >= 2) {
69875 char *old = find_link(major, minor, ino, mode, collected);
69876 if (old)
69877- return (sys_link(old, collected) < 0) ? -1 : 1;
69878+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
69879 }
69880 return 0;
69881 }
69882@@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
69883 {
69884 struct stat st;
69885
69886- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
69887+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
69888 if (S_ISDIR(st.st_mode))
69889- sys_rmdir(path);
69890+ sys_rmdir((char __force_user *)path);
69891 else
69892- sys_unlink(path);
69893+ sys_unlink((char __force_user *)path);
69894 }
69895 }
69896
69897@@ -305,7 +305,7 @@ static int __init do_name(void)
69898 int openflags = O_WRONLY|O_CREAT;
69899 if (ml != 1)
69900 openflags |= O_TRUNC;
69901- wfd = sys_open(collected, openflags, mode);
69902+ wfd = sys_open((char __force_user *)collected, openflags, mode);
69903
69904 if (wfd >= 0) {
69905 sys_fchown(wfd, uid, gid);
69906@@ -317,17 +317,17 @@ static int __init do_name(void)
69907 }
69908 }
69909 } else if (S_ISDIR(mode)) {
69910- sys_mkdir(collected, mode);
69911- sys_chown(collected, uid, gid);
69912- sys_chmod(collected, mode);
69913+ sys_mkdir((char __force_user *)collected, mode);
69914+ sys_chown((char __force_user *)collected, uid, gid);
69915+ sys_chmod((char __force_user *)collected, mode);
69916 dir_add(collected, mtime);
69917 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
69918 S_ISFIFO(mode) || S_ISSOCK(mode)) {
69919 if (maybe_link() == 0) {
69920- sys_mknod(collected, mode, rdev);
69921- sys_chown(collected, uid, gid);
69922- sys_chmod(collected, mode);
69923- do_utime(collected, mtime);
69924+ sys_mknod((char __force_user *)collected, mode, rdev);
69925+ sys_chown((char __force_user *)collected, uid, gid);
69926+ sys_chmod((char __force_user *)collected, mode);
69927+ do_utime((char __force_user *)collected, mtime);
69928 }
69929 }
69930 return 0;
69931@@ -336,15 +336,15 @@ static int __init do_name(void)
69932 static int __init do_copy(void)
69933 {
69934 if (count >= body_len) {
69935- sys_write(wfd, victim, body_len);
69936+ sys_write(wfd, (char __force_user *)victim, body_len);
69937 sys_close(wfd);
69938- do_utime(vcollected, mtime);
69939+ do_utime((char __force_user *)vcollected, mtime);
69940 kfree(vcollected);
69941 eat(body_len);
69942 state = SkipIt;
69943 return 0;
69944 } else {
69945- sys_write(wfd, victim, count);
69946+ sys_write(wfd, (char __force_user *)victim, count);
69947 body_len -= count;
69948 eat(count);
69949 return 1;
69950@@ -355,9 +355,9 @@ static int __init do_symlink(void)
69951 {
69952 collected[N_ALIGN(name_len) + body_len] = '\0';
69953 clean_path(collected, 0);
69954- sys_symlink(collected + N_ALIGN(name_len), collected);
69955- sys_lchown(collected, uid, gid);
69956- do_utime(collected, mtime);
69957+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
69958+ sys_lchown((char __force_user *)collected, uid, gid);
69959+ do_utime((char __force_user *)collected, mtime);
69960 state = SkipIt;
69961 next_state = Reset;
69962 return 0;
69963diff --git a/init/main.c b/init/main.c
69964index 1eb4bd5..da8c6f5 100644
69965--- a/init/main.c
69966+++ b/init/main.c
69967@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void) { }
69968 #ifdef CONFIG_TC
69969 extern void tc_init(void);
69970 #endif
69971+extern void grsecurity_init(void);
69972
69973 enum system_states system_state __read_mostly;
69974 EXPORT_SYMBOL(system_state);
69975@@ -183,6 +184,49 @@ static int __init set_reset_devices(char *str)
69976
69977 __setup("reset_devices", set_reset_devices);
69978
69979+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69980+extern char pax_enter_kernel_user[];
69981+extern char pax_exit_kernel_user[];
69982+extern pgdval_t clone_pgd_mask;
69983+#endif
69984+
69985+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69986+static int __init setup_pax_nouderef(char *str)
69987+{
69988+#ifdef CONFIG_X86_32
69989+ unsigned int cpu;
69990+ struct desc_struct *gdt;
69991+
69992+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
69993+ gdt = get_cpu_gdt_table(cpu);
69994+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69995+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69996+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69997+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69998+ }
69999+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
70000+#else
70001+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
70002+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
70003+ clone_pgd_mask = ~(pgdval_t)0UL;
70004+#endif
70005+
70006+ return 0;
70007+}
70008+early_param("pax_nouderef", setup_pax_nouderef);
70009+#endif
70010+
70011+#ifdef CONFIG_PAX_SOFTMODE
70012+int pax_softmode;
70013+
70014+static int __init setup_pax_softmode(char *str)
70015+{
70016+ get_option(&str, &pax_softmode);
70017+ return 1;
70018+}
70019+__setup("pax_softmode=", setup_pax_softmode);
70020+#endif
70021+
70022 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
70023 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
70024 static const char *panic_later, *panic_param;
70025@@ -705,52 +749,53 @@ int initcall_debug;
70026 core_param(initcall_debug, initcall_debug, bool, 0644);
70027
70028 static char msgbuf[64];
70029-static struct boot_trace_call call;
70030-static struct boot_trace_ret ret;
70031+static struct boot_trace_call trace_call;
70032+static struct boot_trace_ret trace_ret;
70033
70034 int do_one_initcall(initcall_t fn)
70035 {
70036 int count = preempt_count();
70037 ktime_t calltime, delta, rettime;
70038+ const char *msg1 = "", *msg2 = "";
70039
70040 if (initcall_debug) {
70041- call.caller = task_pid_nr(current);
70042- printk("calling %pF @ %i\n", fn, call.caller);
70043+ trace_call.caller = task_pid_nr(current);
70044+ printk("calling %pF @ %i\n", fn, trace_call.caller);
70045 calltime = ktime_get();
70046- trace_boot_call(&call, fn);
70047+ trace_boot_call(&trace_call, fn);
70048 enable_boot_trace();
70049 }
70050
70051- ret.result = fn();
70052+ trace_ret.result = fn();
70053
70054 if (initcall_debug) {
70055 disable_boot_trace();
70056 rettime = ktime_get();
70057 delta = ktime_sub(rettime, calltime);
70058- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70059- trace_boot_ret(&ret, fn);
70060+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70061+ trace_boot_ret(&trace_ret, fn);
70062 printk("initcall %pF returned %d after %Ld usecs\n", fn,
70063- ret.result, ret.duration);
70064+ trace_ret.result, trace_ret.duration);
70065 }
70066
70067 msgbuf[0] = 0;
70068
70069- if (ret.result && ret.result != -ENODEV && initcall_debug)
70070- sprintf(msgbuf, "error code %d ", ret.result);
70071+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
70072+ sprintf(msgbuf, "error code %d ", trace_ret.result);
70073
70074 if (preempt_count() != count) {
70075- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
70076+ msg1 = " preemption imbalance";
70077 preempt_count() = count;
70078 }
70079 if (irqs_disabled()) {
70080- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
70081+ msg2 = " disabled interrupts";
70082 local_irq_enable();
70083 }
70084- if (msgbuf[0]) {
70085- printk("initcall %pF returned with %s\n", fn, msgbuf);
70086+ if (msgbuf[0] || *msg1 || *msg2) {
70087+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
70088 }
70089
70090- return ret.result;
70091+ return trace_ret.result;
70092 }
70093
70094
70095@@ -893,11 +938,13 @@ static int __init kernel_init(void * unused)
70096 if (!ramdisk_execute_command)
70097 ramdisk_execute_command = "/init";
70098
70099- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
70100+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
70101 ramdisk_execute_command = NULL;
70102 prepare_namespace();
70103 }
70104
70105+ grsecurity_init();
70106+
70107 /*
70108 * Ok, we have completed the initial bootup, and
70109 * we're essentially up and running. Get rid of the
70110diff --git a/init/noinitramfs.c b/init/noinitramfs.c
70111index f4c1a3a..96c19bd 100644
70112--- a/init/noinitramfs.c
70113+++ b/init/noinitramfs.c
70114@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
70115 {
70116 int err;
70117
70118- err = sys_mkdir("/dev", 0755);
70119+ err = sys_mkdir((const char __user *)"/dev", 0755);
70120 if (err < 0)
70121 goto out;
70122
70123@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
70124 if (err < 0)
70125 goto out;
70126
70127- err = sys_mkdir("/root", 0700);
70128+ err = sys_mkdir((const char __user *)"/root", 0700);
70129 if (err < 0)
70130 goto out;
70131
70132diff --git a/ipc/mqueue.c b/ipc/mqueue.c
70133index d01bc14..8df81db 100644
70134--- a/ipc/mqueue.c
70135+++ b/ipc/mqueue.c
70136@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
70137 mq_bytes = (mq_msg_tblsz +
70138 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
70139
70140+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
70141 spin_lock(&mq_lock);
70142 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
70143 u->mq_bytes + mq_bytes >
70144diff --git a/ipc/msg.c b/ipc/msg.c
70145index 779f762..4af9e36 100644
70146--- a/ipc/msg.c
70147+++ b/ipc/msg.c
70148@@ -310,18 +310,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
70149 return security_msg_queue_associate(msq, msgflg);
70150 }
70151
70152+static struct ipc_ops msg_ops = {
70153+ .getnew = newque,
70154+ .associate = msg_security,
70155+ .more_checks = NULL
70156+};
70157+
70158 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
70159 {
70160 struct ipc_namespace *ns;
70161- struct ipc_ops msg_ops;
70162 struct ipc_params msg_params;
70163
70164 ns = current->nsproxy->ipc_ns;
70165
70166- msg_ops.getnew = newque;
70167- msg_ops.associate = msg_security;
70168- msg_ops.more_checks = NULL;
70169-
70170 msg_params.key = key;
70171 msg_params.flg = msgflg;
70172
70173diff --git a/ipc/sem.c b/ipc/sem.c
70174index b781007..f738b04 100644
70175--- a/ipc/sem.c
70176+++ b/ipc/sem.c
70177@@ -309,10 +309,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
70178 return 0;
70179 }
70180
70181+static struct ipc_ops sem_ops = {
70182+ .getnew = newary,
70183+ .associate = sem_security,
70184+ .more_checks = sem_more_checks
70185+};
70186+
70187 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70188 {
70189 struct ipc_namespace *ns;
70190- struct ipc_ops sem_ops;
70191 struct ipc_params sem_params;
70192
70193 ns = current->nsproxy->ipc_ns;
70194@@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70195 if (nsems < 0 || nsems > ns->sc_semmsl)
70196 return -EINVAL;
70197
70198- sem_ops.getnew = newary;
70199- sem_ops.associate = sem_security;
70200- sem_ops.more_checks = sem_more_checks;
70201-
70202 sem_params.key = key;
70203 sem_params.flg = semflg;
70204 sem_params.u.nsems = nsems;
70205@@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
70206 ushort* sem_io = fast_sem_io;
70207 int nsems;
70208
70209+ pax_track_stack();
70210+
70211 sma = sem_lock_check(ns, semid);
70212 if (IS_ERR(sma))
70213 return PTR_ERR(sma);
70214@@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
70215 unsigned long jiffies_left = 0;
70216 struct ipc_namespace *ns;
70217
70218+ pax_track_stack();
70219+
70220 ns = current->nsproxy->ipc_ns;
70221
70222 if (nsops < 1 || semid < 0)
70223diff --git a/ipc/shm.c b/ipc/shm.c
70224index d30732c..7379456 100644
70225--- a/ipc/shm.c
70226+++ b/ipc/shm.c
70227@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
70228 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
70229 #endif
70230
70231+#ifdef CONFIG_GRKERNSEC
70232+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70233+ const time_t shm_createtime, const uid_t cuid,
70234+ const int shmid);
70235+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70236+ const time_t shm_createtime);
70237+#endif
70238+
70239 void shm_init_ns(struct ipc_namespace *ns)
70240 {
70241 ns->shm_ctlmax = SHMMAX;
70242@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
70243 shp->shm_lprid = 0;
70244 shp->shm_atim = shp->shm_dtim = 0;
70245 shp->shm_ctim = get_seconds();
70246+#ifdef CONFIG_GRKERNSEC
70247+ {
70248+ struct timespec timeval;
70249+ do_posix_clock_monotonic_gettime(&timeval);
70250+
70251+ shp->shm_createtime = timeval.tv_sec;
70252+ }
70253+#endif
70254 shp->shm_segsz = size;
70255 shp->shm_nattch = 0;
70256 shp->shm_file = file;
70257@@ -446,18 +462,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
70258 return 0;
70259 }
70260
70261+static struct ipc_ops shm_ops = {
70262+ .getnew = newseg,
70263+ .associate = shm_security,
70264+ .more_checks = shm_more_checks
70265+};
70266+
70267 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
70268 {
70269 struct ipc_namespace *ns;
70270- struct ipc_ops shm_ops;
70271 struct ipc_params shm_params;
70272
70273 ns = current->nsproxy->ipc_ns;
70274
70275- shm_ops.getnew = newseg;
70276- shm_ops.associate = shm_security;
70277- shm_ops.more_checks = shm_more_checks;
70278-
70279 shm_params.key = key;
70280 shm_params.flg = shmflg;
70281 shm_params.u.size = size;
70282@@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
70283 if (err)
70284 goto out_unlock;
70285
70286+#ifdef CONFIG_GRKERNSEC
70287+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
70288+ shp->shm_perm.cuid, shmid) ||
70289+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
70290+ err = -EACCES;
70291+ goto out_unlock;
70292+ }
70293+#endif
70294+
70295 path.dentry = dget(shp->shm_file->f_path.dentry);
70296 path.mnt = shp->shm_file->f_path.mnt;
70297 shp->shm_nattch++;
70298+#ifdef CONFIG_GRKERNSEC
70299+ shp->shm_lapid = current->pid;
70300+#endif
70301 size = i_size_read(path.dentry->d_inode);
70302 shm_unlock(shp);
70303
70304diff --git a/kernel/acct.c b/kernel/acct.c
70305index a6605ca..ca91111 100644
70306--- a/kernel/acct.c
70307+++ b/kernel/acct.c
70308@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
70309 */
70310 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
70311 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
70312- file->f_op->write(file, (char *)&ac,
70313+ file->f_op->write(file, (char __force_user *)&ac,
70314 sizeof(acct_t), &file->f_pos);
70315 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
70316 set_fs(fs);
70317diff --git a/kernel/audit.c b/kernel/audit.c
70318index 5feed23..513b02c 100644
70319--- a/kernel/audit.c
70320+++ b/kernel/audit.c
70321@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
70322 3) suppressed due to audit_rate_limit
70323 4) suppressed due to audit_backlog_limit
70324 */
70325-static atomic_t audit_lost = ATOMIC_INIT(0);
70326+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
70327
70328 /* The netlink socket. */
70329 static struct sock *audit_sock;
70330@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
70331 unsigned long now;
70332 int print;
70333
70334- atomic_inc(&audit_lost);
70335+ atomic_inc_unchecked(&audit_lost);
70336
70337 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
70338
70339@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
70340 printk(KERN_WARNING
70341 "audit: audit_lost=%d audit_rate_limit=%d "
70342 "audit_backlog_limit=%d\n",
70343- atomic_read(&audit_lost),
70344+ atomic_read_unchecked(&audit_lost),
70345 audit_rate_limit,
70346 audit_backlog_limit);
70347 audit_panic(message);
70348@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70349 status_set.pid = audit_pid;
70350 status_set.rate_limit = audit_rate_limit;
70351 status_set.backlog_limit = audit_backlog_limit;
70352- status_set.lost = atomic_read(&audit_lost);
70353+ status_set.lost = atomic_read_unchecked(&audit_lost);
70354 status_set.backlog = skb_queue_len(&audit_skb_queue);
70355 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
70356 &status_set, sizeof(status_set));
70357@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70358 spin_unlock_irq(&tsk->sighand->siglock);
70359 }
70360 read_unlock(&tasklist_lock);
70361- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
70362- &s, sizeof(s));
70363+
70364+ if (!err)
70365+ audit_send_reply(NETLINK_CB(skb).pid, seq,
70366+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
70367 break;
70368 }
70369 case AUDIT_TTY_SET: {
70370diff --git a/kernel/auditsc.c b/kernel/auditsc.c
70371index 267e484..f8e295a 100644
70372--- a/kernel/auditsc.c
70373+++ b/kernel/auditsc.c
70374@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
70375 }
70376
70377 /* global counter which is incremented every time something logs in */
70378-static atomic_t session_id = ATOMIC_INIT(0);
70379+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
70380
70381 /**
70382 * audit_set_loginuid - set a task's audit_context loginuid
70383@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
70384 */
70385 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
70386 {
70387- unsigned int sessionid = atomic_inc_return(&session_id);
70388+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
70389 struct audit_context *context = task->audit_context;
70390
70391 if (context && context->in_syscall) {
70392diff --git a/kernel/capability.c b/kernel/capability.c
70393index 8a944f5..db5001e 100644
70394--- a/kernel/capability.c
70395+++ b/kernel/capability.c
70396@@ -305,10 +305,26 @@ int capable(int cap)
70397 BUG();
70398 }
70399
70400- if (security_capable(cap) == 0) {
70401+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
70402 current->flags |= PF_SUPERPRIV;
70403 return 1;
70404 }
70405 return 0;
70406 }
70407+
70408+int capable_nolog(int cap)
70409+{
70410+ if (unlikely(!cap_valid(cap))) {
70411+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
70412+ BUG();
70413+ }
70414+
70415+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
70416+ current->flags |= PF_SUPERPRIV;
70417+ return 1;
70418+ }
70419+ return 0;
70420+}
70421+
70422 EXPORT_SYMBOL(capable);
70423+EXPORT_SYMBOL(capable_nolog);
70424diff --git a/kernel/cgroup.c b/kernel/cgroup.c
70425index 1fbcc74..7000012 100644
70426--- a/kernel/cgroup.c
70427+++ b/kernel/cgroup.c
70428@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
70429 struct hlist_head *hhead;
70430 struct cg_cgroup_link *link;
70431
70432+ pax_track_stack();
70433+
70434 /* First see if we already have a cgroup group that matches
70435 * the desired set */
70436 read_lock(&css_set_lock);
70437diff --git a/kernel/compat.c b/kernel/compat.c
70438index 8bc5578..186e44a 100644
70439--- a/kernel/compat.c
70440+++ b/kernel/compat.c
70441@@ -108,7 +108,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
70442 mm_segment_t oldfs;
70443 long ret;
70444
70445- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
70446+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
70447 oldfs = get_fs();
70448 set_fs(KERNEL_DS);
70449 ret = hrtimer_nanosleep_restart(restart);
70450@@ -140,7 +140,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
70451 oldfs = get_fs();
70452 set_fs(KERNEL_DS);
70453 ret = hrtimer_nanosleep(&tu,
70454- rmtp ? (struct timespec __user *)&rmt : NULL,
70455+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
70456 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
70457 set_fs(oldfs);
70458
70459@@ -247,7 +247,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
70460 mm_segment_t old_fs = get_fs();
70461
70462 set_fs(KERNEL_DS);
70463- ret = sys_sigpending((old_sigset_t __user *) &s);
70464+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
70465 set_fs(old_fs);
70466 if (ret == 0)
70467 ret = put_user(s, set);
70468@@ -266,8 +266,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
70469 old_fs = get_fs();
70470 set_fs(KERNEL_DS);
70471 ret = sys_sigprocmask(how,
70472- set ? (old_sigset_t __user *) &s : NULL,
70473- oset ? (old_sigset_t __user *) &s : NULL);
70474+ set ? (old_sigset_t __force_user *) &s : NULL,
70475+ oset ? (old_sigset_t __force_user *) &s : NULL);
70476 set_fs(old_fs);
70477 if (ret == 0)
70478 if (oset)
70479@@ -310,7 +310,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
70480 mm_segment_t old_fs = get_fs();
70481
70482 set_fs(KERNEL_DS);
70483- ret = sys_old_getrlimit(resource, &r);
70484+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
70485 set_fs(old_fs);
70486
70487 if (!ret) {
70488@@ -385,7 +385,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
70489 mm_segment_t old_fs = get_fs();
70490
70491 set_fs(KERNEL_DS);
70492- ret = sys_getrusage(who, (struct rusage __user *) &r);
70493+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
70494 set_fs(old_fs);
70495
70496 if (ret)
70497@@ -412,8 +412,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
70498 set_fs (KERNEL_DS);
70499 ret = sys_wait4(pid,
70500 (stat_addr ?
70501- (unsigned int __user *) &status : NULL),
70502- options, (struct rusage __user *) &r);
70503+ (unsigned int __force_user *) &status : NULL),
70504+ options, (struct rusage __force_user *) &r);
70505 set_fs (old_fs);
70506
70507 if (ret > 0) {
70508@@ -438,8 +438,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
70509 memset(&info, 0, sizeof(info));
70510
70511 set_fs(KERNEL_DS);
70512- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
70513- uru ? (struct rusage __user *)&ru : NULL);
70514+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
70515+ uru ? (struct rusage __force_user *)&ru : NULL);
70516 set_fs(old_fs);
70517
70518 if ((ret < 0) || (info.si_signo == 0))
70519@@ -569,8 +569,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
70520 oldfs = get_fs();
70521 set_fs(KERNEL_DS);
70522 err = sys_timer_settime(timer_id, flags,
70523- (struct itimerspec __user *) &newts,
70524- (struct itimerspec __user *) &oldts);
70525+ (struct itimerspec __force_user *) &newts,
70526+ (struct itimerspec __force_user *) &oldts);
70527 set_fs(oldfs);
70528 if (!err && old && put_compat_itimerspec(old, &oldts))
70529 return -EFAULT;
70530@@ -587,7 +587,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
70531 oldfs = get_fs();
70532 set_fs(KERNEL_DS);
70533 err = sys_timer_gettime(timer_id,
70534- (struct itimerspec __user *) &ts);
70535+ (struct itimerspec __force_user *) &ts);
70536 set_fs(oldfs);
70537 if (!err && put_compat_itimerspec(setting, &ts))
70538 return -EFAULT;
70539@@ -606,7 +606,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
70540 oldfs = get_fs();
70541 set_fs(KERNEL_DS);
70542 err = sys_clock_settime(which_clock,
70543- (struct timespec __user *) &ts);
70544+ (struct timespec __force_user *) &ts);
70545 set_fs(oldfs);
70546 return err;
70547 }
70548@@ -621,7 +621,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
70549 oldfs = get_fs();
70550 set_fs(KERNEL_DS);
70551 err = sys_clock_gettime(which_clock,
70552- (struct timespec __user *) &ts);
70553+ (struct timespec __force_user *) &ts);
70554 set_fs(oldfs);
70555 if (!err && put_compat_timespec(&ts, tp))
70556 return -EFAULT;
70557@@ -638,7 +638,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
70558 oldfs = get_fs();
70559 set_fs(KERNEL_DS);
70560 err = sys_clock_getres(which_clock,
70561- (struct timespec __user *) &ts);
70562+ (struct timespec __force_user *) &ts);
70563 set_fs(oldfs);
70564 if (!err && tp && put_compat_timespec(&ts, tp))
70565 return -EFAULT;
70566@@ -650,9 +650,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
70567 long err;
70568 mm_segment_t oldfs;
70569 struct timespec tu;
70570- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
70571+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
70572
70573- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
70574+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
70575 oldfs = get_fs();
70576 set_fs(KERNEL_DS);
70577 err = clock_nanosleep_restart(restart);
70578@@ -684,8 +684,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
70579 oldfs = get_fs();
70580 set_fs(KERNEL_DS);
70581 err = sys_clock_nanosleep(which_clock, flags,
70582- (struct timespec __user *) &in,
70583- (struct timespec __user *) &out);
70584+ (struct timespec __force_user *) &in,
70585+ (struct timespec __force_user *) &out);
70586 set_fs(oldfs);
70587
70588 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
70589diff --git a/kernel/configs.c b/kernel/configs.c
70590index abaee68..047facd 100644
70591--- a/kernel/configs.c
70592+++ b/kernel/configs.c
70593@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
70594 struct proc_dir_entry *entry;
70595
70596 /* create the current config file */
70597+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
70598+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
70599+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
70600+ &ikconfig_file_ops);
70601+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70602+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
70603+ &ikconfig_file_ops);
70604+#endif
70605+#else
70606 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
70607 &ikconfig_file_ops);
70608+#endif
70609+
70610 if (!entry)
70611 return -ENOMEM;
70612
70613diff --git a/kernel/cpu.c b/kernel/cpu.c
70614index 7e8b6ac..8921388 100644
70615--- a/kernel/cpu.c
70616+++ b/kernel/cpu.c
70617@@ -19,7 +19,7 @@
70618 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
70619 static DEFINE_MUTEX(cpu_add_remove_lock);
70620
70621-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
70622+static RAW_NOTIFIER_HEAD(cpu_chain);
70623
70624 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
70625 * Should always be manipulated under cpu_add_remove_lock
70626diff --git a/kernel/cred.c b/kernel/cred.c
70627index 0b5b5fc..419b86a 100644
70628--- a/kernel/cred.c
70629+++ b/kernel/cred.c
70630@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
70631 */
70632 void __put_cred(struct cred *cred)
70633 {
70634+ pax_track_stack();
70635+
70636 kdebug("__put_cred(%p{%d,%d})", cred,
70637 atomic_read(&cred->usage),
70638 read_cred_subscribers(cred));
70639@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
70640 {
70641 struct cred *cred;
70642
70643+ pax_track_stack();
70644+
70645 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
70646 atomic_read(&tsk->cred->usage),
70647 read_cred_subscribers(tsk->cred));
70648@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct task_struct *task)
70649 {
70650 const struct cred *cred;
70651
70652+ pax_track_stack();
70653+
70654 rcu_read_lock();
70655
70656 do {
70657@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
70658 {
70659 struct cred *new;
70660
70661+ pax_track_stack();
70662+
70663 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
70664 if (!new)
70665 return NULL;
70666@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
70667 const struct cred *old;
70668 struct cred *new;
70669
70670+ pax_track_stack();
70671+
70672 validate_process_creds();
70673
70674 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
70675@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
70676 struct thread_group_cred *tgcred = NULL;
70677 struct cred *new;
70678
70679+ pax_track_stack();
70680+
70681 #ifdef CONFIG_KEYS
70682 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
70683 if (!tgcred)
70684@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
70685 struct cred *new;
70686 int ret;
70687
70688+ pax_track_stack();
70689+
70690 mutex_init(&p->cred_guard_mutex);
70691
70692 if (
70693@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
70694 struct task_struct *task = current;
70695 const struct cred *old = task->real_cred;
70696
70697+ pax_track_stack();
70698+
70699 kdebug("commit_creds(%p{%d,%d})", new,
70700 atomic_read(&new->usage),
70701 read_cred_subscribers(new));
70702@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
70703
70704 get_cred(new); /* we will require a ref for the subj creds too */
70705
70706+ gr_set_role_label(task, new->uid, new->gid);
70707+
70708 /* dumpability changes */
70709 if (old->euid != new->euid ||
70710 old->egid != new->egid ||
70711@@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
70712 key_fsgid_changed(task);
70713
70714 /* do it
70715- * - What if a process setreuid()'s and this brings the
70716- * new uid over his NPROC rlimit? We can check this now
70717- * cheaply with the new uid cache, so if it matters
70718- * we should be checking for it. -DaveM
70719+ * RLIMIT_NPROC limits on user->processes have already been checked
70720+ * in set_user().
70721 */
70722 alter_cred_subscribers(new, 2);
70723 if (new->user != old->user)
70724@@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
70725 */
70726 void abort_creds(struct cred *new)
70727 {
70728+ pax_track_stack();
70729+
70730 kdebug("abort_creds(%p{%d,%d})", new,
70731 atomic_read(&new->usage),
70732 read_cred_subscribers(new));
70733@@ -629,6 +647,8 @@ const struct cred *override_creds(const struct cred *new)
70734 {
70735 const struct cred *old = current->cred;
70736
70737+ pax_track_stack();
70738+
70739 kdebug("override_creds(%p{%d,%d})", new,
70740 atomic_read(&new->usage),
70741 read_cred_subscribers(new));
70742@@ -658,6 +678,8 @@ void revert_creds(const struct cred *old)
70743 {
70744 const struct cred *override = current->cred;
70745
70746+ pax_track_stack();
70747+
70748 kdebug("revert_creds(%p{%d,%d})", old,
70749 atomic_read(&old->usage),
70750 read_cred_subscribers(old));
70751@@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
70752 const struct cred *old;
70753 struct cred *new;
70754
70755+ pax_track_stack();
70756+
70757 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
70758 if (!new)
70759 return NULL;
70760@@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
70761 */
70762 int set_security_override(struct cred *new, u32 secid)
70763 {
70764+ pax_track_stack();
70765+
70766 return security_kernel_act_as(new, secid);
70767 }
70768 EXPORT_SYMBOL(set_security_override);
70769@@ -777,6 +803,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
70770 u32 secid;
70771 int ret;
70772
70773+ pax_track_stack();
70774+
70775 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
70776 if (ret < 0)
70777 return ret;
70778diff --git a/kernel/exit.c b/kernel/exit.c
70779index 0f8fae3..9344a56 100644
70780--- a/kernel/exit.c
70781+++ b/kernel/exit.c
70782@@ -55,6 +55,10 @@
70783 #include <asm/pgtable.h>
70784 #include <asm/mmu_context.h>
70785
70786+#ifdef CONFIG_GRKERNSEC
70787+extern rwlock_t grsec_exec_file_lock;
70788+#endif
70789+
70790 static void exit_mm(struct task_struct * tsk);
70791
70792 static void __unhash_process(struct task_struct *p)
70793@@ -174,6 +178,10 @@ void release_task(struct task_struct * p)
70794 struct task_struct *leader;
70795 int zap_leader;
70796 repeat:
70797+#ifdef CONFIG_NET
70798+ gr_del_task_from_ip_table(p);
70799+#endif
70800+
70801 tracehook_prepare_release_task(p);
70802 /* don't need to get the RCU readlock here - the process is dead and
70803 * can't be modifying its own credentials */
70804@@ -397,7 +405,7 @@ int allow_signal(int sig)
70805 * know it'll be handled, so that they don't get converted to
70806 * SIGKILL or just silently dropped.
70807 */
70808- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70809+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70810 recalc_sigpending();
70811 spin_unlock_irq(&current->sighand->siglock);
70812 return 0;
70813@@ -433,6 +441,17 @@ void daemonize(const char *name, ...)
70814 vsnprintf(current->comm, sizeof(current->comm), name, args);
70815 va_end(args);
70816
70817+#ifdef CONFIG_GRKERNSEC
70818+ write_lock(&grsec_exec_file_lock);
70819+ if (current->exec_file) {
70820+ fput(current->exec_file);
70821+ current->exec_file = NULL;
70822+ }
70823+ write_unlock(&grsec_exec_file_lock);
70824+#endif
70825+
70826+ gr_set_kernel_label(current);
70827+
70828 /*
70829 * If we were started as result of loading a module, close all of the
70830 * user space pages. We don't need them, and if we didn't close them
70831@@ -897,17 +916,17 @@ NORET_TYPE void do_exit(long code)
70832 struct task_struct *tsk = current;
70833 int group_dead;
70834
70835- profile_task_exit(tsk);
70836-
70837- WARN_ON(atomic_read(&tsk->fs_excl));
70838-
70839+ /*
70840+ * Check this first since set_fs() below depends on
70841+ * current_thread_info(), which we better not access when we're in
70842+ * interrupt context. Other than that, we want to do the set_fs()
70843+ * as early as possible.
70844+ */
70845 if (unlikely(in_interrupt()))
70846 panic("Aiee, killing interrupt handler!");
70847- if (unlikely(!tsk->pid))
70848- panic("Attempted to kill the idle task!");
70849
70850 /*
70851- * If do_exit is called because this processes oopsed, it's possible
70852+ * If do_exit is called because this processes Oops'ed, it's possible
70853 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
70854 * continuing. Amongst other possible reasons, this is to prevent
70855 * mm_release()->clear_child_tid() from writing to a user-controlled
70856@@ -915,6 +934,13 @@ NORET_TYPE void do_exit(long code)
70857 */
70858 set_fs(USER_DS);
70859
70860+ profile_task_exit(tsk);
70861+
70862+ WARN_ON(atomic_read(&tsk->fs_excl));
70863+
70864+ if (unlikely(!tsk->pid))
70865+ panic("Attempted to kill the idle task!");
70866+
70867 tracehook_report_exit(&code);
70868
70869 validate_creds_for_do_exit(tsk);
70870@@ -973,6 +999,9 @@ NORET_TYPE void do_exit(long code)
70871 tsk->exit_code = code;
70872 taskstats_exit(tsk, group_dead);
70873
70874+ gr_acl_handle_psacct(tsk, code);
70875+ gr_acl_handle_exit();
70876+
70877 exit_mm(tsk);
70878
70879 if (group_dead)
70880@@ -1188,7 +1217,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
70881
70882 if (unlikely(wo->wo_flags & WNOWAIT)) {
70883 int exit_code = p->exit_code;
70884- int why, status;
70885+ int why;
70886
70887 get_task_struct(p);
70888 read_unlock(&tasklist_lock);
70889diff --git a/kernel/fork.c b/kernel/fork.c
70890index 4bde56f..29a9bab 100644
70891--- a/kernel/fork.c
70892+++ b/kernel/fork.c
70893@@ -253,7 +253,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70894 *stackend = STACK_END_MAGIC; /* for overflow detection */
70895
70896 #ifdef CONFIG_CC_STACKPROTECTOR
70897- tsk->stack_canary = get_random_int();
70898+ tsk->stack_canary = pax_get_random_long();
70899 #endif
70900
70901 /* One for us, one for whoever does the "release_task()" (usually parent) */
70902@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70903 mm->locked_vm = 0;
70904 mm->mmap = NULL;
70905 mm->mmap_cache = NULL;
70906- mm->free_area_cache = oldmm->mmap_base;
70907- mm->cached_hole_size = ~0UL;
70908+ mm->free_area_cache = oldmm->free_area_cache;
70909+ mm->cached_hole_size = oldmm->cached_hole_size;
70910 mm->map_count = 0;
70911 cpumask_clear(mm_cpumask(mm));
70912 mm->mm_rb = RB_ROOT;
70913@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70914 tmp->vm_flags &= ~VM_LOCKED;
70915 tmp->vm_mm = mm;
70916 tmp->vm_next = tmp->vm_prev = NULL;
70917+ tmp->vm_mirror = NULL;
70918 anon_vma_link(tmp);
70919 file = tmp->vm_file;
70920 if (file) {
70921@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70922 if (retval)
70923 goto out;
70924 }
70925+
70926+#ifdef CONFIG_PAX_SEGMEXEC
70927+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70928+ struct vm_area_struct *mpnt_m;
70929+
70930+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70931+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70932+
70933+ if (!mpnt->vm_mirror)
70934+ continue;
70935+
70936+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70937+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70938+ mpnt->vm_mirror = mpnt_m;
70939+ } else {
70940+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70941+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70942+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70943+ mpnt->vm_mirror->vm_mirror = mpnt;
70944+ }
70945+ }
70946+ BUG_ON(mpnt_m);
70947+ }
70948+#endif
70949+
70950 /* a new mm has just been created */
70951 arch_dup_mmap(oldmm, mm);
70952 retval = 0;
70953@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70954 write_unlock(&fs->lock);
70955 return -EAGAIN;
70956 }
70957- fs->users++;
70958+ atomic_inc(&fs->users);
70959 write_unlock(&fs->lock);
70960 return 0;
70961 }
70962 tsk->fs = copy_fs_struct(fs);
70963 if (!tsk->fs)
70964 return -ENOMEM;
70965+ gr_set_chroot_entries(tsk, &tsk->fs->root);
70966 return 0;
70967 }
70968
70969@@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70970 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70971 #endif
70972 retval = -EAGAIN;
70973+
70974+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70975+
70976 if (atomic_read(&p->real_cred->user->processes) >=
70977 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
70978- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70979- p->real_cred->user != INIT_USER)
70980+ if (p->real_cred->user != INIT_USER &&
70981+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
70982 goto bad_fork_free;
70983 }
70984+ current->flags &= ~PF_NPROC_EXCEEDED;
70985
70986 retval = copy_creds(p, clone_flags);
70987 if (retval < 0)
70988@@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70989 goto bad_fork_free_pid;
70990 }
70991
70992+ gr_copy_label(p);
70993+
70994 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
70995 /*
70996 * Clear TID on mm_release()?
70997@@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
70998 bad_fork_free:
70999 free_task(p);
71000 fork_out:
71001+ gr_log_forkfail(retval);
71002+
71003 return ERR_PTR(retval);
71004 }
71005
71006@@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
71007 if (clone_flags & CLONE_PARENT_SETTID)
71008 put_user(nr, parent_tidptr);
71009
71010+ gr_handle_brute_check();
71011+
71012 if (clone_flags & CLONE_VFORK) {
71013 p->vfork_done = &vfork;
71014 init_completion(&vfork);
71015@@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
71016 return 0;
71017
71018 /* don't need lock here; in the worst case we'll do useless copy */
71019- if (fs->users == 1)
71020+ if (atomic_read(&fs->users) == 1)
71021 return 0;
71022
71023 *new_fsp = copy_fs_struct(fs);
71024@@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
71025 fs = current->fs;
71026 write_lock(&fs->lock);
71027 current->fs = new_fs;
71028- if (--fs->users)
71029+ gr_set_chroot_entries(current, &current->fs->root);
71030+ if (atomic_dec_return(&fs->users))
71031 new_fs = NULL;
71032 else
71033 new_fs = fs;
71034diff --git a/kernel/futex.c b/kernel/futex.c
71035index fb98c9f..f158c0c 100644
71036--- a/kernel/futex.c
71037+++ b/kernel/futex.c
71038@@ -54,6 +54,7 @@
71039 #include <linux/mount.h>
71040 #include <linux/pagemap.h>
71041 #include <linux/syscalls.h>
71042+#include <linux/ptrace.h>
71043 #include <linux/signal.h>
71044 #include <linux/module.h>
71045 #include <linux/magic.h>
71046@@ -223,6 +224,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
71047 struct page *page;
71048 int err, ro = 0;
71049
71050+#ifdef CONFIG_PAX_SEGMEXEC
71051+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
71052+ return -EFAULT;
71053+#endif
71054+
71055 /*
71056 * The futex address must be "naturally" aligned.
71057 */
71058@@ -1819,6 +1825,8 @@ static int futex_wait(u32 __user *uaddr, int fshared,
71059 struct futex_q q;
71060 int ret;
71061
71062+ pax_track_stack();
71063+
71064 if (!bitset)
71065 return -EINVAL;
71066
71067@@ -1871,7 +1879,7 @@ retry:
71068
71069 restart = &current_thread_info()->restart_block;
71070 restart->fn = futex_wait_restart;
71071- restart->futex.uaddr = (u32 *)uaddr;
71072+ restart->futex.uaddr = uaddr;
71073 restart->futex.val = val;
71074 restart->futex.time = abs_time->tv64;
71075 restart->futex.bitset = bitset;
71076@@ -2233,6 +2241,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared,
71077 struct futex_q q;
71078 int res, ret;
71079
71080+ pax_track_stack();
71081+
71082 if (!bitset)
71083 return -EINVAL;
71084
71085@@ -2407,7 +2417,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
71086 {
71087 struct robust_list_head __user *head;
71088 unsigned long ret;
71089+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
71090 const struct cred *cred = current_cred(), *pcred;
71091+#endif
71092
71093 if (!futex_cmpxchg_enabled)
71094 return -ENOSYS;
71095@@ -2423,11 +2435,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
71096 if (!p)
71097 goto err_unlock;
71098 ret = -EPERM;
71099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71100+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71101+ goto err_unlock;
71102+#else
71103 pcred = __task_cred(p);
71104 if (cred->euid != pcred->euid &&
71105 cred->euid != pcred->uid &&
71106 !capable(CAP_SYS_PTRACE))
71107 goto err_unlock;
71108+#endif
71109 head = p->robust_list;
71110 rcu_read_unlock();
71111 }
71112@@ -2489,7 +2506,7 @@ retry:
71113 */
71114 static inline int fetch_robust_entry(struct robust_list __user **entry,
71115 struct robust_list __user * __user *head,
71116- int *pi)
71117+ unsigned int *pi)
71118 {
71119 unsigned long uentry;
71120
71121@@ -2670,6 +2687,7 @@ static int __init futex_init(void)
71122 {
71123 u32 curval;
71124 int i;
71125+ mm_segment_t oldfs;
71126
71127 /*
71128 * This will fail and we want it. Some arch implementations do
71129@@ -2681,7 +2699,10 @@ static int __init futex_init(void)
71130 * implementation, the non functional ones will return
71131 * -ENOSYS.
71132 */
71133+ oldfs = get_fs();
71134+ set_fs(USER_DS);
71135 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
71136+ set_fs(oldfs);
71137 if (curval == -EFAULT)
71138 futex_cmpxchg_enabled = 1;
71139
71140diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
71141index 2357165..8d70cee 100644
71142--- a/kernel/futex_compat.c
71143+++ b/kernel/futex_compat.c
71144@@ -10,6 +10,7 @@
71145 #include <linux/compat.h>
71146 #include <linux/nsproxy.h>
71147 #include <linux/futex.h>
71148+#include <linux/ptrace.h>
71149
71150 #include <asm/uaccess.h>
71151
71152@@ -135,7 +136,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71153 {
71154 struct compat_robust_list_head __user *head;
71155 unsigned long ret;
71156- const struct cred *cred = current_cred(), *pcred;
71157+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
71158+ const struct cred *cred = current_cred();
71159+ const struct cred *pcred;
71160+#endif
71161
71162 if (!futex_cmpxchg_enabled)
71163 return -ENOSYS;
71164@@ -151,11 +155,16 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71165 if (!p)
71166 goto err_unlock;
71167 ret = -EPERM;
71168+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71169+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71170+ goto err_unlock;
71171+#else
71172 pcred = __task_cred(p);
71173 if (cred->euid != pcred->euid &&
71174 cred->euid != pcred->uid &&
71175 !capable(CAP_SYS_PTRACE))
71176 goto err_unlock;
71177+#endif
71178 head = p->compat_robust_list;
71179 read_unlock(&tasklist_lock);
71180 }
71181diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
71182index 9b22d03..6295b62 100644
71183--- a/kernel/gcov/base.c
71184+++ b/kernel/gcov/base.c
71185@@ -102,11 +102,6 @@ void gcov_enable_events(void)
71186 }
71187
71188 #ifdef CONFIG_MODULES
71189-static inline int within(void *addr, void *start, unsigned long size)
71190-{
71191- return ((addr >= start) && (addr < start + size));
71192-}
71193-
71194 /* Update list and generate events when modules are unloaded. */
71195 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71196 void *data)
71197@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71198 prev = NULL;
71199 /* Remove entries located in module from linked list. */
71200 for (info = gcov_info_head; info; info = info->next) {
71201- if (within(info, mod->module_core, mod->core_size)) {
71202+ if (within_module_core_rw((unsigned long)info, mod)) {
71203 if (prev)
71204 prev->next = info->next;
71205 else
71206diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
71207index a6e9d00..a0da4f9 100644
71208--- a/kernel/hrtimer.c
71209+++ b/kernel/hrtimer.c
71210@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
71211 local_irq_restore(flags);
71212 }
71213
71214-static void run_hrtimer_softirq(struct softirq_action *h)
71215+static void run_hrtimer_softirq(void)
71216 {
71217 hrtimer_peek_ahead_timers();
71218 }
71219diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
71220index 8b6b8b6..6bc87df 100644
71221--- a/kernel/kallsyms.c
71222+++ b/kernel/kallsyms.c
71223@@ -11,6 +11,9 @@
71224 * Changed the compression method from stem compression to "table lookup"
71225 * compression (see scripts/kallsyms.c for a more complete description)
71226 */
71227+#ifdef CONFIG_GRKERNSEC_HIDESYM
71228+#define __INCLUDED_BY_HIDESYM 1
71229+#endif
71230 #include <linux/kallsyms.h>
71231 #include <linux/module.h>
71232 #include <linux/init.h>
71233@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
71234
71235 static inline int is_kernel_inittext(unsigned long addr)
71236 {
71237+ if (system_state != SYSTEM_BOOTING)
71238+ return 0;
71239+
71240 if (addr >= (unsigned long)_sinittext
71241 && addr <= (unsigned long)_einittext)
71242 return 1;
71243 return 0;
71244 }
71245
71246+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71247+#ifdef CONFIG_MODULES
71248+static inline int is_module_text(unsigned long addr)
71249+{
71250+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
71251+ return 1;
71252+
71253+ addr = ktla_ktva(addr);
71254+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
71255+}
71256+#else
71257+static inline int is_module_text(unsigned long addr)
71258+{
71259+ return 0;
71260+}
71261+#endif
71262+#endif
71263+
71264 static inline int is_kernel_text(unsigned long addr)
71265 {
71266 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
71267@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigned long addr)
71268
71269 static inline int is_kernel(unsigned long addr)
71270 {
71271+
71272+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71273+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
71274+ return 1;
71275+
71276+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
71277+#else
71278 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
71279+#endif
71280+
71281 return 1;
71282 return in_gate_area_no_task(addr);
71283 }
71284
71285 static int is_ksym_addr(unsigned long addr)
71286 {
71287+
71288+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71289+ if (is_module_text(addr))
71290+ return 0;
71291+#endif
71292+
71293 if (all_var)
71294 return is_kernel(addr);
71295
71296@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
71297
71298 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
71299 {
71300- iter->name[0] = '\0';
71301 iter->nameoff = get_symbol_offset(new_pos);
71302 iter->pos = new_pos;
71303 }
71304@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, void *p)
71305 {
71306 struct kallsym_iter *iter = m->private;
71307
71308+#ifdef CONFIG_GRKERNSEC_HIDESYM
71309+ if (current_uid())
71310+ return 0;
71311+#endif
71312+
71313 /* Some debugging symbols have no name. Ignore them. */
71314 if (!iter->name[0])
71315 return 0;
71316@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
71317 struct kallsym_iter *iter;
71318 int ret;
71319
71320- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
71321+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
71322 if (!iter)
71323 return -ENOMEM;
71324 reset_iter(iter, 0);
71325diff --git a/kernel/kexec.c b/kernel/kexec.c
71326index f336e21..9c1c20b 100644
71327--- a/kernel/kexec.c
71328+++ b/kernel/kexec.c
71329@@ -1028,7 +1028,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
71330 unsigned long flags)
71331 {
71332 struct compat_kexec_segment in;
71333- struct kexec_segment out, __user *ksegments;
71334+ struct kexec_segment out;
71335+ struct kexec_segment __user *ksegments;
71336 unsigned long i, result;
71337
71338 /* Don't allow clients that don't understand the native
71339diff --git a/kernel/kgdb.c b/kernel/kgdb.c
71340index 53dae4b..9ba3743 100644
71341--- a/kernel/kgdb.c
71342+++ b/kernel/kgdb.c
71343@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
71344 /* Guard for recursive entry */
71345 static int exception_level;
71346
71347-static struct kgdb_io *kgdb_io_ops;
71348+static const struct kgdb_io *kgdb_io_ops;
71349 static DEFINE_SPINLOCK(kgdb_registration_lock);
71350
71351 /* kgdb console driver is loaded */
71352@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1);
71353 */
71354 static atomic_t passive_cpu_wait[NR_CPUS];
71355 static atomic_t cpu_in_kgdb[NR_CPUS];
71356-atomic_t kgdb_setting_breakpoint;
71357+atomic_unchecked_t kgdb_setting_breakpoint;
71358
71359 struct task_struct *kgdb_usethread;
71360 struct task_struct *kgdb_contthread;
71361@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBYTES +
71362 sizeof(unsigned long)];
71363
71364 /* to keep track of the CPU which is doing the single stepping*/
71365-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71366+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71367
71368 /*
71369 * If you are debugging a problem where roundup (the collection of
71370@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
71371 return 0;
71372 if (kgdb_connected)
71373 return 1;
71374- if (atomic_read(&kgdb_setting_breakpoint))
71375+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
71376 return 1;
71377 if (print_wait)
71378 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
71379@@ -1426,8 +1426,8 @@ acquirelock:
71380 * instance of the exception handler wanted to come into the
71381 * debugger on a different CPU via a single step
71382 */
71383- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
71384- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
71385+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
71386+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
71387
71388 atomic_set(&kgdb_active, -1);
71389 touch_softlockup_watchdog();
71390@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void)
71391 *
71392 * Register it with the KGDB core.
71393 */
71394-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
71395+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
71396 {
71397 int err;
71398
71399@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_module);
71400 *
71401 * Unregister it with the KGDB core.
71402 */
71403-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
71404+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
71405 {
71406 BUG_ON(kgdb_connected);
71407
71408@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
71409 */
71410 void kgdb_breakpoint(void)
71411 {
71412- atomic_set(&kgdb_setting_breakpoint, 1);
71413+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
71414 wmb(); /* Sync point before breakpoint */
71415 arch_kgdb_breakpoint();
71416 wmb(); /* Sync point after breakpoint */
71417- atomic_set(&kgdb_setting_breakpoint, 0);
71418+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
71419 }
71420 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
71421
71422diff --git a/kernel/kmod.c b/kernel/kmod.c
71423index d206078..e27ba6a 100644
71424--- a/kernel/kmod.c
71425+++ b/kernel/kmod.c
71426@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
71427 * If module auto-loading support is disabled then this function
71428 * becomes a no-operation.
71429 */
71430-int __request_module(bool wait, const char *fmt, ...)
71431+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
71432 {
71433- va_list args;
71434 char module_name[MODULE_NAME_LEN];
71435 unsigned int max_modprobes;
71436 int ret;
71437- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
71438+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
71439 static char *envp[] = { "HOME=/",
71440 "TERM=linux",
71441 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
71442@@ -84,12 +83,24 @@ int __request_module(bool wait, const char *fmt, ...)
71443 if (ret)
71444 return ret;
71445
71446- va_start(args, fmt);
71447- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
71448- va_end(args);
71449+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
71450 if (ret >= MODULE_NAME_LEN)
71451 return -ENAMETOOLONG;
71452
71453+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71454+ if (!current_uid()) {
71455+ /* hack to workaround consolekit/udisks stupidity */
71456+ read_lock(&tasklist_lock);
71457+ if (!strcmp(current->comm, "mount") &&
71458+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
71459+ read_unlock(&tasklist_lock);
71460+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
71461+ return -EPERM;
71462+ }
71463+ read_unlock(&tasklist_lock);
71464+ }
71465+#endif
71466+
71467 /* If modprobe needs a service that is in a module, we get a recursive
71468 * loop. Limit the number of running kmod threads to max_threads/2 or
71469 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
71470@@ -123,6 +134,48 @@ int __request_module(bool wait, const char *fmt, ...)
71471 atomic_dec(&kmod_concurrent);
71472 return ret;
71473 }
71474+
71475+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
71476+{
71477+ va_list args;
71478+ int ret;
71479+
71480+ va_start(args, fmt);
71481+ ret = ____request_module(wait, module_param, fmt, args);
71482+ va_end(args);
71483+
71484+ return ret;
71485+}
71486+
71487+int __request_module(bool wait, const char *fmt, ...)
71488+{
71489+ va_list args;
71490+ int ret;
71491+
71492+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71493+ if (current_uid()) {
71494+ char module_param[MODULE_NAME_LEN];
71495+
71496+ memset(module_param, 0, sizeof(module_param));
71497+
71498+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
71499+
71500+ va_start(args, fmt);
71501+ ret = ____request_module(wait, module_param, fmt, args);
71502+ va_end(args);
71503+
71504+ return ret;
71505+ }
71506+#endif
71507+
71508+ va_start(args, fmt);
71509+ ret = ____request_module(wait, NULL, fmt, args);
71510+ va_end(args);
71511+
71512+ return ret;
71513+}
71514+
71515+
71516 EXPORT_SYMBOL(__request_module);
71517 #endif /* CONFIG_MODULES */
71518
71519@@ -228,7 +281,7 @@ static int wait_for_helper(void *data)
71520 *
71521 * Thus the __user pointer cast is valid here.
71522 */
71523- sys_wait4(pid, (int __user *)&ret, 0, NULL);
71524+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
71525
71526 /*
71527 * If ret is 0, either ____call_usermodehelper failed and the
71528diff --git a/kernel/kprobes.c b/kernel/kprobes.c
71529index 5240d75..5a6fb33 100644
71530--- a/kernel/kprobes.c
71531+++ b/kernel/kprobes.c
71532@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void)
71533 * kernel image and loaded module images reside. This is required
71534 * so x86_64 can correctly handle the %rip-relative fixups.
71535 */
71536- kip->insns = module_alloc(PAGE_SIZE);
71537+ kip->insns = module_alloc_exec(PAGE_SIZE);
71538 if (!kip->insns) {
71539 kfree(kip);
71540 return NULL;
71541@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
71542 */
71543 if (!list_is_singular(&kprobe_insn_pages)) {
71544 list_del(&kip->list);
71545- module_free(NULL, kip->insns);
71546+ module_free_exec(NULL, kip->insns);
71547 kfree(kip);
71548 }
71549 return 1;
71550@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
71551 {
71552 int i, err = 0;
71553 unsigned long offset = 0, size = 0;
71554- char *modname, namebuf[128];
71555+ char *modname, namebuf[KSYM_NAME_LEN];
71556 const char *symbol_name;
71557 void *addr;
71558 struct kprobe_blackpoint *kb;
71559@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
71560 const char *sym = NULL;
71561 unsigned int i = *(loff_t *) v;
71562 unsigned long offset = 0;
71563- char *modname, namebuf[128];
71564+ char *modname, namebuf[KSYM_NAME_LEN];
71565
71566 head = &kprobe_table[i];
71567 preempt_disable();
71568diff --git a/kernel/lockdep.c b/kernel/lockdep.c
71569index d86fe89..d12fc66 100644
71570--- a/kernel/lockdep.c
71571+++ b/kernel/lockdep.c
71572@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_trace = {
71573 /*
71574 * Various lockdep statistics:
71575 */
71576-atomic_t chain_lookup_hits;
71577-atomic_t chain_lookup_misses;
71578-atomic_t hardirqs_on_events;
71579-atomic_t hardirqs_off_events;
71580-atomic_t redundant_hardirqs_on;
71581-atomic_t redundant_hardirqs_off;
71582-atomic_t softirqs_on_events;
71583-atomic_t softirqs_off_events;
71584-atomic_t redundant_softirqs_on;
71585-atomic_t redundant_softirqs_off;
71586-atomic_t nr_unused_locks;
71587-atomic_t nr_cyclic_checks;
71588-atomic_t nr_find_usage_forwards_checks;
71589-atomic_t nr_find_usage_backwards_checks;
71590+atomic_unchecked_t chain_lookup_hits;
71591+atomic_unchecked_t chain_lookup_misses;
71592+atomic_unchecked_t hardirqs_on_events;
71593+atomic_unchecked_t hardirqs_off_events;
71594+atomic_unchecked_t redundant_hardirqs_on;
71595+atomic_unchecked_t redundant_hardirqs_off;
71596+atomic_unchecked_t softirqs_on_events;
71597+atomic_unchecked_t softirqs_off_events;
71598+atomic_unchecked_t redundant_softirqs_on;
71599+atomic_unchecked_t redundant_softirqs_off;
71600+atomic_unchecked_t nr_unused_locks;
71601+atomic_unchecked_t nr_cyclic_checks;
71602+atomic_unchecked_t nr_find_usage_forwards_checks;
71603+atomic_unchecked_t nr_find_usage_backwards_checks;
71604 #endif
71605
71606 /*
71607@@ -577,6 +577,10 @@ static int static_obj(void *obj)
71608 int i;
71609 #endif
71610
71611+#ifdef CONFIG_PAX_KERNEXEC
71612+ start = ktla_ktva(start);
71613+#endif
71614+
71615 /*
71616 * static variable?
71617 */
71618@@ -592,8 +596,7 @@ static int static_obj(void *obj)
71619 */
71620 for_each_possible_cpu(i) {
71621 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
71622- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
71623- + per_cpu_offset(i);
71624+ end = start + PERCPU_ENOUGH_ROOM;
71625
71626 if ((addr >= start) && (addr < end))
71627 return 1;
71628@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
71629 if (!static_obj(lock->key)) {
71630 debug_locks_off();
71631 printk("INFO: trying to register non-static key.\n");
71632+ printk("lock:%pS key:%pS.\n", lock, lock->key);
71633 printk("the code is fine but needs lockdep annotation.\n");
71634 printk("turning off the locking correctness validator.\n");
71635 dump_stack();
71636@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71637 if (!class)
71638 return 0;
71639 }
71640- debug_atomic_inc((atomic_t *)&class->ops);
71641+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
71642 if (very_verbose(class)) {
71643 printk("\nacquire class [%p] %s", class->key, class->name);
71644 if (class->name_version > 1)
71645diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h
71646index a2ee95a..092f0f2 100644
71647--- a/kernel/lockdep_internals.h
71648+++ b/kernel/lockdep_internals.h
71649@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_class *class)
71650 /*
71651 * Various lockdep statistics:
71652 */
71653-extern atomic_t chain_lookup_hits;
71654-extern atomic_t chain_lookup_misses;
71655-extern atomic_t hardirqs_on_events;
71656-extern atomic_t hardirqs_off_events;
71657-extern atomic_t redundant_hardirqs_on;
71658-extern atomic_t redundant_hardirqs_off;
71659-extern atomic_t softirqs_on_events;
71660-extern atomic_t softirqs_off_events;
71661-extern atomic_t redundant_softirqs_on;
71662-extern atomic_t redundant_softirqs_off;
71663-extern atomic_t nr_unused_locks;
71664-extern atomic_t nr_cyclic_checks;
71665-extern atomic_t nr_cyclic_check_recursions;
71666-extern atomic_t nr_find_usage_forwards_checks;
71667-extern atomic_t nr_find_usage_forwards_recursions;
71668-extern atomic_t nr_find_usage_backwards_checks;
71669-extern atomic_t nr_find_usage_backwards_recursions;
71670-# define debug_atomic_inc(ptr) atomic_inc(ptr)
71671-# define debug_atomic_dec(ptr) atomic_dec(ptr)
71672-# define debug_atomic_read(ptr) atomic_read(ptr)
71673+extern atomic_unchecked_t chain_lookup_hits;
71674+extern atomic_unchecked_t chain_lookup_misses;
71675+extern atomic_unchecked_t hardirqs_on_events;
71676+extern atomic_unchecked_t hardirqs_off_events;
71677+extern atomic_unchecked_t redundant_hardirqs_on;
71678+extern atomic_unchecked_t redundant_hardirqs_off;
71679+extern atomic_unchecked_t softirqs_on_events;
71680+extern atomic_unchecked_t softirqs_off_events;
71681+extern atomic_unchecked_t redundant_softirqs_on;
71682+extern atomic_unchecked_t redundant_softirqs_off;
71683+extern atomic_unchecked_t nr_unused_locks;
71684+extern atomic_unchecked_t nr_cyclic_checks;
71685+extern atomic_unchecked_t nr_cyclic_check_recursions;
71686+extern atomic_unchecked_t nr_find_usage_forwards_checks;
71687+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
71688+extern atomic_unchecked_t nr_find_usage_backwards_checks;
71689+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
71690+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
71691+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
71692+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
71693 #else
71694 # define debug_atomic_inc(ptr) do { } while (0)
71695 # define debug_atomic_dec(ptr) do { } while (0)
71696diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
71697index d4aba4f..02a353f 100644
71698--- a/kernel/lockdep_proc.c
71699+++ b/kernel/lockdep_proc.c
71700@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
71701
71702 static void print_name(struct seq_file *m, struct lock_class *class)
71703 {
71704- char str[128];
71705+ char str[KSYM_NAME_LEN];
71706 const char *name = class->name;
71707
71708 if (!name) {
71709diff --git a/kernel/module.c b/kernel/module.c
71710index 4b270e6..2226274 100644
71711--- a/kernel/module.c
71712+++ b/kernel/module.c
71713@@ -55,6 +55,7 @@
71714 #include <linux/async.h>
71715 #include <linux/percpu.h>
71716 #include <linux/kmemleak.h>
71717+#include <linux/grsecurity.h>
71718
71719 #define CREATE_TRACE_POINTS
71720 #include <trace/events/module.h>
71721@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
71722 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71723
71724 /* Bounds of module allocation, for speeding __module_address */
71725-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71726+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71727+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71728
71729 int register_module_notifier(struct notifier_block * nb)
71730 {
71731@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
71732 return true;
71733
71734 list_for_each_entry_rcu(mod, &modules, list) {
71735- struct symsearch arr[] = {
71736+ struct symsearch modarr[] = {
71737 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71738 NOT_GPL_ONLY, false },
71739 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71740@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
71741 #endif
71742 };
71743
71744- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71745+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71746 return true;
71747 }
71748 return false;
71749@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned long size, unsigned long align,
71750 void *ptr;
71751 int cpu;
71752
71753- if (align > PAGE_SIZE) {
71754+ if (align-1 >= PAGE_SIZE) {
71755 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71756 name, align, PAGE_SIZE);
71757 align = PAGE_SIZE;
71758@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
71759 * /sys/module/foo/sections stuff
71760 * J. Corbet <corbet@lwn.net>
71761 */
71762-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
71763+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71764
71765 static inline bool sect_empty(const Elf_Shdr *sect)
71766 {
71767@@ -1545,7 +1547,8 @@ static void free_module(struct module *mod)
71768 destroy_params(mod->kp, mod->num_kp);
71769
71770 /* This may be NULL, but that's OK */
71771- module_free(mod, mod->module_init);
71772+ module_free(mod, mod->module_init_rw);
71773+ module_free_exec(mod, mod->module_init_rx);
71774 kfree(mod->args);
71775 if (mod->percpu)
71776 percpu_modfree(mod->percpu);
71777@@ -1554,10 +1557,12 @@ static void free_module(struct module *mod)
71778 percpu_modfree(mod->refptr);
71779 #endif
71780 /* Free lock-classes: */
71781- lockdep_free_key_range(mod->module_core, mod->core_size);
71782+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71783+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71784
71785 /* Finally, free the core (containing the module structure) */
71786- module_free(mod, mod->module_core);
71787+ module_free_exec(mod, mod->module_core_rx);
71788+ module_free(mod, mod->module_core_rw);
71789
71790 #ifdef CONFIG_MPU
71791 update_protections(current->mm);
71792@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71793 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
71794 int ret = 0;
71795 const struct kernel_symbol *ksym;
71796+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71797+ int is_fs_load = 0;
71798+ int register_filesystem_found = 0;
71799+ char *p;
71800+
71801+ p = strstr(mod->args, "grsec_modharden_fs");
71802+
71803+ if (p) {
71804+ char *endptr = p + strlen("grsec_modharden_fs");
71805+ /* copy \0 as well */
71806+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71807+ is_fs_load = 1;
71808+ }
71809+#endif
71810+
71811
71812 for (i = 1; i < n; i++) {
71813+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71814+ const char *name = strtab + sym[i].st_name;
71815+
71816+ /* it's a real shame this will never get ripped and copied
71817+ upstream! ;(
71818+ */
71819+ if (is_fs_load && !strcmp(name, "register_filesystem"))
71820+ register_filesystem_found = 1;
71821+#endif
71822 switch (sym[i].st_shndx) {
71823 case SHN_COMMON:
71824 /* We compiled with -fno-common. These are not
71825@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71826 strtab + sym[i].st_name, mod);
71827 /* Ok if resolved. */
71828 if (ksym) {
71829+ pax_open_kernel();
71830 sym[i].st_value = ksym->value;
71831+ pax_close_kernel();
71832 break;
71833 }
71834
71835@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71836 secbase = (unsigned long)mod->percpu;
71837 else
71838 secbase = sechdrs[sym[i].st_shndx].sh_addr;
71839+ pax_open_kernel();
71840 sym[i].st_value += secbase;
71841+ pax_close_kernel();
71842 break;
71843 }
71844 }
71845
71846+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71847+ if (is_fs_load && !register_filesystem_found) {
71848+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71849+ ret = -EPERM;
71850+ }
71851+#endif
71852+
71853 return ret;
71854 }
71855
71856@@ -1731,11 +1771,12 @@ static void layout_sections(struct module *mod,
71857 || s->sh_entsize != ~0UL
71858 || strstarts(secstrings + s->sh_name, ".init"))
71859 continue;
71860- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71861+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71862+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71863+ else
71864+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71865 DEBUGP("\t%s\n", secstrings + s->sh_name);
71866 }
71867- if (m == 0)
71868- mod->core_text_size = mod->core_size;
71869 }
71870
71871 DEBUGP("Init section allocation order:\n");
71872@@ -1748,12 +1789,13 @@ static void layout_sections(struct module *mod,
71873 || s->sh_entsize != ~0UL
71874 || !strstarts(secstrings + s->sh_name, ".init"))
71875 continue;
71876- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71877- | INIT_OFFSET_MASK);
71878+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71879+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71880+ else
71881+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71882+ s->sh_entsize |= INIT_OFFSET_MASK;
71883 DEBUGP("\t%s\n", secstrings + s->sh_name);
71884 }
71885- if (m == 0)
71886- mod->init_text_size = mod->init_size;
71887 }
71888 }
71889
71890@@ -1857,9 +1899,8 @@ static int is_exported(const char *name, unsigned long value,
71891
71892 /* As per nm */
71893 static char elf_type(const Elf_Sym *sym,
71894- Elf_Shdr *sechdrs,
71895- const char *secstrings,
71896- struct module *mod)
71897+ const Elf_Shdr *sechdrs,
71898+ const char *secstrings)
71899 {
71900 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
71901 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
71902@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struct module *mod,
71903
71904 /* Put symbol section at end of init part of module. */
71905 symsect->sh_flags |= SHF_ALLOC;
71906- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71907+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71908 symindex) | INIT_OFFSET_MASK;
71909 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
71910
71911@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struct module *mod,
71912 }
71913
71914 /* Append room for core symbols at end of core part. */
71915- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71916- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
71917+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71918+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
71919
71920 /* Put string table section at end of init part of module. */
71921 strsect->sh_flags |= SHF_ALLOC;
71922- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71923+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71924 strindex) | INIT_OFFSET_MASK;
71925 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
71926
71927 /* Append room for core symbols' strings at end of core part. */
71928- *pstroffs = mod->core_size;
71929+ *pstroffs = mod->core_size_rx;
71930 __set_bit(0, strmap);
71931- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
71932+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
71933
71934 return symoffs;
71935 }
71936@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *mod,
71937 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
71938 mod->strtab = (void *)sechdrs[strindex].sh_addr;
71939
71940+ pax_open_kernel();
71941+
71942 /* Set types up while we still have access to sections. */
71943 for (i = 0; i < mod->num_symtab; i++)
71944 mod->symtab[i].st_info
71945- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
71946+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
71947
71948- mod->core_symtab = dst = mod->module_core + symoffs;
71949+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
71950 src = mod->symtab;
71951 *dst = *src;
71952 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
71953@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *mod,
71954 }
71955 mod->core_num_syms = ndst;
71956
71957- mod->core_strtab = s = mod->module_core + stroffs;
71958+ mod->core_strtab = s = mod->module_core_rx + stroffs;
71959 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
71960 if (test_bit(i, strmap))
71961 *++s = mod->strtab[i];
71962+
71963+ pax_close_kernel();
71964 }
71965 #else
71966 static inline unsigned long layout_symtab(struct module *mod,
71967@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
71968 #endif
71969 }
71970
71971-static void *module_alloc_update_bounds(unsigned long size)
71972+static void *module_alloc_update_bounds_rw(unsigned long size)
71973 {
71974 void *ret = module_alloc(size);
71975
71976 if (ret) {
71977 /* Update module bounds. */
71978- if ((unsigned long)ret < module_addr_min)
71979- module_addr_min = (unsigned long)ret;
71980- if ((unsigned long)ret + size > module_addr_max)
71981- module_addr_max = (unsigned long)ret + size;
71982+ if ((unsigned long)ret < module_addr_min_rw)
71983+ module_addr_min_rw = (unsigned long)ret;
71984+ if ((unsigned long)ret + size > module_addr_max_rw)
71985+ module_addr_max_rw = (unsigned long)ret + size;
71986+ }
71987+ return ret;
71988+}
71989+
71990+static void *module_alloc_update_bounds_rx(unsigned long size)
71991+{
71992+ void *ret = module_alloc_exec(size);
71993+
71994+ if (ret) {
71995+ /* Update module bounds. */
71996+ if ((unsigned long)ret < module_addr_min_rx)
71997+ module_addr_min_rx = (unsigned long)ret;
71998+ if ((unsigned long)ret + size > module_addr_max_rx)
71999+ module_addr_max_rx = (unsigned long)ret + size;
72000 }
72001 return ret;
72002 }
72003@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72004 unsigned int i;
72005
72006 /* only scan the sections containing data */
72007- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
72008- (unsigned long)mod->module_core,
72009+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
72010+ (unsigned long)mod->module_core_rw,
72011 sizeof(struct module), GFP_KERNEL);
72012
72013 for (i = 1; i < hdr->e_shnum; i++) {
72014@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72015 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
72016 continue;
72017
72018- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
72019- (unsigned long)mod->module_core,
72020+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
72021+ (unsigned long)mod->module_core_rw,
72022 sechdrs[i].sh_size, GFP_KERNEL);
72023 }
72024 }
72025@@ -2097,7 +2156,7 @@ static noinline struct module *load_module(void __user *umod,
72026 Elf_Ehdr *hdr;
72027 Elf_Shdr *sechdrs;
72028 char *secstrings, *args, *modmagic, *strtab = NULL;
72029- char *staging;
72030+ char *staging, *license;
72031 unsigned int i;
72032 unsigned int symindex = 0;
72033 unsigned int strindex = 0;
72034@@ -2195,6 +2254,14 @@ static noinline struct module *load_module(void __user *umod,
72035 goto free_hdr;
72036 }
72037
72038+ license = get_modinfo(sechdrs, infoindex, "license");
72039+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
72040+ if (!license || !license_is_gpl_compatible(license)) {
72041+ err -ENOEXEC;
72042+ goto free_hdr;
72043+ }
72044+#endif
72045+
72046 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
72047 /* This is allowed: modprobe --force will invalidate it. */
72048 if (!modmagic) {
72049@@ -2263,7 +2330,7 @@ static noinline struct module *load_module(void __user *umod,
72050 secstrings, &stroffs, strmap);
72051
72052 /* Do the allocs. */
72053- ptr = module_alloc_update_bounds(mod->core_size);
72054+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
72055 /*
72056 * The pointer to this block is stored in the module structure
72057 * which is inside the block. Just mark it as not being a
72058@@ -2274,23 +2341,47 @@ static noinline struct module *load_module(void __user *umod,
72059 err = -ENOMEM;
72060 goto free_percpu;
72061 }
72062- memset(ptr, 0, mod->core_size);
72063- mod->module_core = ptr;
72064+ memset(ptr, 0, mod->core_size_rw);
72065+ mod->module_core_rw = ptr;
72066
72067- ptr = module_alloc_update_bounds(mod->init_size);
72068+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
72069 /*
72070 * The pointer to this block is stored in the module structure
72071 * which is inside the block. This block doesn't need to be
72072 * scanned as it contains data and code that will be freed
72073 * after the module is initialized.
72074 */
72075- kmemleak_ignore(ptr);
72076- if (!ptr && mod->init_size) {
72077+ kmemleak_not_leak(ptr);
72078+ if (!ptr && mod->init_size_rw) {
72079 err = -ENOMEM;
72080- goto free_core;
72081+ goto free_core_rw;
72082 }
72083- memset(ptr, 0, mod->init_size);
72084- mod->module_init = ptr;
72085+ memset(ptr, 0, mod->init_size_rw);
72086+ mod->module_init_rw = ptr;
72087+
72088+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
72089+ kmemleak_not_leak(ptr);
72090+ if (!ptr) {
72091+ err = -ENOMEM;
72092+ goto free_init_rw;
72093+ }
72094+
72095+ pax_open_kernel();
72096+ memset(ptr, 0, mod->core_size_rx);
72097+ pax_close_kernel();
72098+ mod->module_core_rx = ptr;
72099+
72100+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
72101+ kmemleak_not_leak(ptr);
72102+ if (!ptr && mod->init_size_rx) {
72103+ err = -ENOMEM;
72104+ goto free_core_rx;
72105+ }
72106+
72107+ pax_open_kernel();
72108+ memset(ptr, 0, mod->init_size_rx);
72109+ pax_close_kernel();
72110+ mod->module_init_rx = ptr;
72111
72112 /* Transfer each section which specifies SHF_ALLOC */
72113 DEBUGP("final section addresses:\n");
72114@@ -2300,17 +2391,45 @@ static noinline struct module *load_module(void __user *umod,
72115 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
72116 continue;
72117
72118- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
72119- dest = mod->module_init
72120- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72121- else
72122- dest = mod->module_core + sechdrs[i].sh_entsize;
72123+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
72124+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72125+ dest = mod->module_init_rw
72126+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72127+ else
72128+ dest = mod->module_init_rx
72129+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72130+ } else {
72131+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72132+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
72133+ else
72134+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
72135+ }
72136
72137- if (sechdrs[i].sh_type != SHT_NOBITS)
72138- memcpy(dest, (void *)sechdrs[i].sh_addr,
72139- sechdrs[i].sh_size);
72140+ if (sechdrs[i].sh_type != SHT_NOBITS) {
72141+
72142+#ifdef CONFIG_PAX_KERNEXEC
72143+#ifdef CONFIG_X86_64
72144+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
72145+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
72146+#endif
72147+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
72148+ pax_open_kernel();
72149+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72150+ pax_close_kernel();
72151+ } else
72152+#endif
72153+
72154+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72155+ }
72156 /* Update sh_addr to point to copy in image. */
72157- sechdrs[i].sh_addr = (unsigned long)dest;
72158+
72159+#ifdef CONFIG_PAX_KERNEXEC
72160+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
72161+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
72162+ else
72163+#endif
72164+
72165+ sechdrs[i].sh_addr = (unsigned long)dest;
72166 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
72167 }
72168 /* Module has been moved. */
72169@@ -2322,7 +2441,7 @@ static noinline struct module *load_module(void __user *umod,
72170 mod->name);
72171 if (!mod->refptr) {
72172 err = -ENOMEM;
72173- goto free_init;
72174+ goto free_init_rx;
72175 }
72176 #endif
72177 /* Now we've moved module, initialize linked lists, etc. */
72178@@ -2334,7 +2453,7 @@ static noinline struct module *load_module(void __user *umod,
72179 goto free_unload;
72180
72181 /* Set up license info based on the info section */
72182- set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
72183+ set_license(mod, license);
72184
72185 /*
72186 * ndiswrapper is under GPL by itself, but loads proprietary modules.
72187@@ -2351,6 +2470,31 @@ static noinline struct module *load_module(void __user *umod,
72188 /* Set up MODINFO_ATTR fields */
72189 setup_modinfo(mod, sechdrs, infoindex);
72190
72191+ mod->args = args;
72192+
72193+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72194+ {
72195+ char *p, *p2;
72196+
72197+ if (strstr(mod->args, "grsec_modharden_netdev")) {
72198+ 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);
72199+ err = -EPERM;
72200+ goto cleanup;
72201+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
72202+ p += strlen("grsec_modharden_normal");
72203+ p2 = strstr(p, "_");
72204+ if (p2) {
72205+ *p2 = '\0';
72206+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
72207+ *p2 = '_';
72208+ }
72209+ err = -EPERM;
72210+ goto cleanup;
72211+ }
72212+ }
72213+#endif
72214+
72215+
72216 /* Fix up syms, so that st_value is a pointer to location. */
72217 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
72218 mod);
72219@@ -2431,8 +2575,8 @@ static noinline struct module *load_module(void __user *umod,
72220
72221 /* Now do relocations. */
72222 for (i = 1; i < hdr->e_shnum; i++) {
72223- const char *strtab = (char *)sechdrs[strindex].sh_addr;
72224 unsigned int info = sechdrs[i].sh_info;
72225+ strtab = (char *)sechdrs[strindex].sh_addr;
72226
72227 /* Not a valid relocation section? */
72228 if (info >= hdr->e_shnum)
72229@@ -2493,16 +2637,15 @@ static noinline struct module *load_module(void __user *umod,
72230 * Do it before processing of module parameters, so the module
72231 * can provide parameter accessor functions of its own.
72232 */
72233- if (mod->module_init)
72234- flush_icache_range((unsigned long)mod->module_init,
72235- (unsigned long)mod->module_init
72236- + mod->init_size);
72237- flush_icache_range((unsigned long)mod->module_core,
72238- (unsigned long)mod->module_core + mod->core_size);
72239+ if (mod->module_init_rx)
72240+ flush_icache_range((unsigned long)mod->module_init_rx,
72241+ (unsigned long)mod->module_init_rx
72242+ + mod->init_size_rx);
72243+ flush_icache_range((unsigned long)mod->module_core_rx,
72244+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
72245
72246 set_fs(old_fs);
72247
72248- mod->args = args;
72249 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
72250 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
72251 mod->name);
72252@@ -2546,12 +2689,16 @@ static noinline struct module *load_module(void __user *umod,
72253 free_unload:
72254 module_unload_free(mod);
72255 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
72256+ free_init_rx:
72257 percpu_modfree(mod->refptr);
72258- free_init:
72259 #endif
72260- module_free(mod, mod->module_init);
72261- free_core:
72262- module_free(mod, mod->module_core);
72263+ module_free_exec(mod, mod->module_init_rx);
72264+ free_core_rx:
72265+ module_free_exec(mod, mod->module_core_rx);
72266+ free_init_rw:
72267+ module_free(mod, mod->module_init_rw);
72268+ free_core_rw:
72269+ module_free(mod, mod->module_core_rw);
72270 /* mod will be freed with core. Don't access it beyond this line! */
72271 free_percpu:
72272 if (percpu)
72273@@ -2653,10 +2800,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
72274 mod->symtab = mod->core_symtab;
72275 mod->strtab = mod->core_strtab;
72276 #endif
72277- module_free(mod, mod->module_init);
72278- mod->module_init = NULL;
72279- mod->init_size = 0;
72280- mod->init_text_size = 0;
72281+ module_free(mod, mod->module_init_rw);
72282+ module_free_exec(mod, mod->module_init_rx);
72283+ mod->module_init_rw = NULL;
72284+ mod->module_init_rx = NULL;
72285+ mod->init_size_rw = 0;
72286+ mod->init_size_rx = 0;
72287 mutex_unlock(&module_mutex);
72288
72289 return 0;
72290@@ -2687,10 +2836,16 @@ static const char *get_ksymbol(struct module *mod,
72291 unsigned long nextval;
72292
72293 /* At worse, next value is at end of module */
72294- if (within_module_init(addr, mod))
72295- nextval = (unsigned long)mod->module_init+mod->init_text_size;
72296+ if (within_module_init_rx(addr, mod))
72297+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
72298+ else if (within_module_init_rw(addr, mod))
72299+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
72300+ else if (within_module_core_rx(addr, mod))
72301+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
72302+ else if (within_module_core_rw(addr, mod))
72303+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
72304 else
72305- nextval = (unsigned long)mod->module_core+mod->core_text_size;
72306+ return NULL;
72307
72308 /* Scan for closest preceeding symbol, and next symbol. (ELF
72309 starts real symbols at 1). */
72310@@ -2936,7 +3091,7 @@ static int m_show(struct seq_file *m, void *p)
72311 char buf[8];
72312
72313 seq_printf(m, "%s %u",
72314- mod->name, mod->init_size + mod->core_size);
72315+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
72316 print_unload_info(m, mod);
72317
72318 /* Informative for users. */
72319@@ -2945,7 +3100,7 @@ static int m_show(struct seq_file *m, void *p)
72320 mod->state == MODULE_STATE_COMING ? "Loading":
72321 "Live");
72322 /* Used by oprofile and other similar tools. */
72323- seq_printf(m, " 0x%p", mod->module_core);
72324+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
72325
72326 /* Taints info */
72327 if (mod->taints)
72328@@ -2981,7 +3136,17 @@ static const struct file_operations proc_modules_operations = {
72329
72330 static int __init proc_modules_init(void)
72331 {
72332+#ifndef CONFIG_GRKERNSEC_HIDESYM
72333+#ifdef CONFIG_GRKERNSEC_PROC_USER
72334+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72335+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72336+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
72337+#else
72338 proc_create("modules", 0, NULL, &proc_modules_operations);
72339+#endif
72340+#else
72341+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72342+#endif
72343 return 0;
72344 }
72345 module_init(proc_modules_init);
72346@@ -3040,12 +3205,12 @@ struct module *__module_address(unsigned long addr)
72347 {
72348 struct module *mod;
72349
72350- if (addr < module_addr_min || addr > module_addr_max)
72351+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
72352+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
72353 return NULL;
72354
72355 list_for_each_entry_rcu(mod, &modules, list)
72356- if (within_module_core(addr, mod)
72357- || within_module_init(addr, mod))
72358+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
72359 return mod;
72360 return NULL;
72361 }
72362@@ -3079,11 +3244,20 @@ bool is_module_text_address(unsigned long addr)
72363 */
72364 struct module *__module_text_address(unsigned long addr)
72365 {
72366- struct module *mod = __module_address(addr);
72367+ struct module *mod;
72368+
72369+#ifdef CONFIG_X86_32
72370+ addr = ktla_ktva(addr);
72371+#endif
72372+
72373+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
72374+ return NULL;
72375+
72376+ mod = __module_address(addr);
72377+
72378 if (mod) {
72379 /* Make sure it's within the text section. */
72380- if (!within(addr, mod->module_init, mod->init_text_size)
72381- && !within(addr, mod->module_core, mod->core_text_size))
72382+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
72383 mod = NULL;
72384 }
72385 return mod;
72386diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
72387index ec815a9..fe46e99 100644
72388--- a/kernel/mutex-debug.c
72389+++ b/kernel/mutex-debug.c
72390@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
72391 }
72392
72393 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72394- struct thread_info *ti)
72395+ struct task_struct *task)
72396 {
72397 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
72398
72399 /* Mark the current thread as blocked on the lock: */
72400- ti->task->blocked_on = waiter;
72401+ task->blocked_on = waiter;
72402 }
72403
72404 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72405- struct thread_info *ti)
72406+ struct task_struct *task)
72407 {
72408 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
72409- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
72410- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
72411- ti->task->blocked_on = NULL;
72412+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
72413+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
72414+ task->blocked_on = NULL;
72415
72416 list_del_init(&waiter->list);
72417 waiter->task = NULL;
72418@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lock)
72419 return;
72420
72421 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
72422- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
72423+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
72424 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
72425 mutex_clear_owner(lock);
72426 }
72427diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
72428index 6b2d735..372d3c4 100644
72429--- a/kernel/mutex-debug.h
72430+++ b/kernel/mutex-debug.h
72431@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
72432 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
72433 extern void debug_mutex_add_waiter(struct mutex *lock,
72434 struct mutex_waiter *waiter,
72435- struct thread_info *ti);
72436+ struct task_struct *task);
72437 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72438- struct thread_info *ti);
72439+ struct task_struct *task);
72440 extern void debug_mutex_unlock(struct mutex *lock);
72441 extern void debug_mutex_init(struct mutex *lock, const char *name,
72442 struct lock_class_key *key);
72443
72444 static inline void mutex_set_owner(struct mutex *lock)
72445 {
72446- lock->owner = current_thread_info();
72447+ lock->owner = current;
72448 }
72449
72450 static inline void mutex_clear_owner(struct mutex *lock)
72451diff --git a/kernel/mutex.c b/kernel/mutex.c
72452index f85644c..5ee9f77 100644
72453--- a/kernel/mutex.c
72454+++ b/kernel/mutex.c
72455@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72456 */
72457
72458 for (;;) {
72459- struct thread_info *owner;
72460+ struct task_struct *owner;
72461
72462 /*
72463 * If we own the BKL, then don't spin. The owner of
72464@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72465 spin_lock_mutex(&lock->wait_lock, flags);
72466
72467 debug_mutex_lock_common(lock, &waiter);
72468- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
72469+ debug_mutex_add_waiter(lock, &waiter, task);
72470
72471 /* add waiting tasks to the end of the waitqueue (FIFO): */
72472 list_add_tail(&waiter.list, &lock->wait_list);
72473@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72474 * TASK_UNINTERRUPTIBLE case.)
72475 */
72476 if (unlikely(signal_pending_state(state, task))) {
72477- mutex_remove_waiter(lock, &waiter,
72478- task_thread_info(task));
72479+ mutex_remove_waiter(lock, &waiter, task);
72480 mutex_release(&lock->dep_map, 1, ip);
72481 spin_unlock_mutex(&lock->wait_lock, flags);
72482
72483@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72484 done:
72485 lock_acquired(&lock->dep_map, ip);
72486 /* got the lock - rejoice! */
72487- mutex_remove_waiter(lock, &waiter, current_thread_info());
72488+ mutex_remove_waiter(lock, &waiter, task);
72489 mutex_set_owner(lock);
72490
72491 /* set it to 0 if there are no waiters left: */
72492diff --git a/kernel/mutex.h b/kernel/mutex.h
72493index 67578ca..4115fbf 100644
72494--- a/kernel/mutex.h
72495+++ b/kernel/mutex.h
72496@@ -19,7 +19,7 @@
72497 #ifdef CONFIG_SMP
72498 static inline void mutex_set_owner(struct mutex *lock)
72499 {
72500- lock->owner = current_thread_info();
72501+ lock->owner = current;
72502 }
72503
72504 static inline void mutex_clear_owner(struct mutex *lock)
72505diff --git a/kernel/panic.c b/kernel/panic.c
72506index 96b45d0..45c447a 100644
72507--- a/kernel/panic.c
72508+++ b/kernel/panic.c
72509@@ -352,7 +352,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
72510 const char *board;
72511
72512 printk(KERN_WARNING "------------[ cut here ]------------\n");
72513- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
72514+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
72515 board = dmi_get_system_info(DMI_PRODUCT_NAME);
72516 if (board)
72517 printk(KERN_WARNING "Hardware name: %s\n", board);
72518@@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
72519 */
72520 void __stack_chk_fail(void)
72521 {
72522- panic("stack-protector: Kernel stack is corrupted in: %p\n",
72523+ dump_stack();
72524+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
72525 __builtin_return_address(0));
72526 }
72527 EXPORT_SYMBOL(__stack_chk_fail);
72528diff --git a/kernel/params.c b/kernel/params.c
72529index d656c27..21e452c 100644
72530--- a/kernel/params.c
72531+++ b/kernel/params.c
72532@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
72533 return ret;
72534 }
72535
72536-static struct sysfs_ops module_sysfs_ops = {
72537+static const struct sysfs_ops module_sysfs_ops = {
72538 .show = module_attr_show,
72539 .store = module_attr_store,
72540 };
72541@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
72542 return 0;
72543 }
72544
72545-static struct kset_uevent_ops module_uevent_ops = {
72546+static const struct kset_uevent_ops module_uevent_ops = {
72547 .filter = uevent_filter,
72548 };
72549
72550diff --git a/kernel/perf_event.c b/kernel/perf_event.c
72551index 37ebc14..9c121d9 100644
72552--- a/kernel/perf_event.c
72553+++ b/kernel/perf_event.c
72554@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostly = 516; /* 'free' kb per user */
72555 */
72556 int sysctl_perf_event_sample_rate __read_mostly = 100000;
72557
72558-static atomic64_t perf_event_id;
72559+static atomic64_unchecked_t perf_event_id;
72560
72561 /*
72562 * Lock for (sysadmin-configurable) event reservations:
72563@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struct perf_event *event,
72564 * In order to keep per-task stats reliable we need to flip the event
72565 * values when we flip the contexts.
72566 */
72567- value = atomic64_read(&next_event->count);
72568- value = atomic64_xchg(&event->count, value);
72569- atomic64_set(&next_event->count, value);
72570+ value = atomic64_read_unchecked(&next_event->count);
72571+ value = atomic64_xchg_unchecked(&event->count, value);
72572+ atomic64_set_unchecked(&next_event->count, value);
72573
72574 swap(event->total_time_enabled, next_event->total_time_enabled);
72575 swap(event->total_time_running, next_event->total_time_running);
72576@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_event *event)
72577 update_event_times(event);
72578 }
72579
72580- return atomic64_read(&event->count);
72581+ return atomic64_read_unchecked(&event->count);
72582 }
72583
72584 /*
72585@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct perf_event *event,
72586 values[n++] = 1 + leader->nr_siblings;
72587 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72588 values[n++] = leader->total_time_enabled +
72589- atomic64_read(&leader->child_total_time_enabled);
72590+ atomic64_read_unchecked(&leader->child_total_time_enabled);
72591 }
72592 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72593 values[n++] = leader->total_time_running +
72594- atomic64_read(&leader->child_total_time_running);
72595+ atomic64_read_unchecked(&leader->child_total_time_running);
72596 }
72597
72598 size = n * sizeof(u64);
72599@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct perf_event *event,
72600 values[n++] = perf_event_read_value(event);
72601 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72602 values[n++] = event->total_time_enabled +
72603- atomic64_read(&event->child_total_time_enabled);
72604+ atomic64_read_unchecked(&event->child_total_time_enabled);
72605 }
72606 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72607 values[n++] = event->total_time_running +
72608- atomic64_read(&event->child_total_time_running);
72609+ atomic64_read_unchecked(&event->child_total_time_running);
72610 }
72611 if (read_format & PERF_FORMAT_ID)
72612 values[n++] = primary_event_id(event);
72613@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)
72614 static void perf_event_reset(struct perf_event *event)
72615 {
72616 (void)perf_event_read(event);
72617- atomic64_set(&event->count, 0);
72618+ atomic64_set_unchecked(&event->count, 0);
72619 perf_event_update_userpage(event);
72620 }
72621
72622@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct perf_event *event)
72623 ++userpg->lock;
72624 barrier();
72625 userpg->index = perf_event_index(event);
72626- userpg->offset = atomic64_read(&event->count);
72627+ userpg->offset = atomic64_read_unchecked(&event->count);
72628 if (event->state == PERF_EVENT_STATE_ACTIVE)
72629- userpg->offset -= atomic64_read(&event->hw.prev_count);
72630+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
72631
72632 userpg->time_enabled = event->total_time_enabled +
72633- atomic64_read(&event->child_total_time_enabled);
72634+ atomic64_read_unchecked(&event->child_total_time_enabled);
72635
72636 userpg->time_running = event->total_time_running +
72637- atomic64_read(&event->child_total_time_running);
72638+ atomic64_read_unchecked(&event->child_total_time_running);
72639
72640 barrier();
72641 ++userpg->lock;
72642@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct perf_output_handle *handle,
72643 u64 values[4];
72644 int n = 0;
72645
72646- values[n++] = atomic64_read(&event->count);
72647+ values[n++] = atomic64_read_unchecked(&event->count);
72648 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72649 values[n++] = event->total_time_enabled +
72650- atomic64_read(&event->child_total_time_enabled);
72651+ atomic64_read_unchecked(&event->child_total_time_enabled);
72652 }
72653 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72654 values[n++] = event->total_time_running +
72655- atomic64_read(&event->child_total_time_running);
72656+ atomic64_read_unchecked(&event->child_total_time_running);
72657 }
72658 if (read_format & PERF_FORMAT_ID)
72659 values[n++] = primary_event_id(event);
72660@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
72661 if (leader != event)
72662 leader->pmu->read(leader);
72663
72664- values[n++] = atomic64_read(&leader->count);
72665+ values[n++] = atomic64_read_unchecked(&leader->count);
72666 if (read_format & PERF_FORMAT_ID)
72667 values[n++] = primary_event_id(leader);
72668
72669@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
72670 if (sub != event)
72671 sub->pmu->read(sub);
72672
72673- values[n++] = atomic64_read(&sub->count);
72674+ values[n++] = atomic64_read_unchecked(&sub->count);
72675 if (read_format & PERF_FORMAT_ID)
72676 values[n++] = primary_event_id(sub);
72677
72678@@ -3525,12 +3525,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
72679 * need to add enough zero bytes after the string to handle
72680 * the 64bit alignment we do later.
72681 */
72682- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
72683+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
72684 if (!buf) {
72685 name = strncpy(tmp, "//enomem", sizeof(tmp));
72686 goto got_name;
72687 }
72688- name = d_path(&file->f_path, buf, PATH_MAX);
72689+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
72690 if (IS_ERR(name)) {
72691 name = strncpy(tmp, "//toolong", sizeof(tmp));
72692 goto got_name;
72693@@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
72694 {
72695 struct hw_perf_event *hwc = &event->hw;
72696
72697- atomic64_add(nr, &event->count);
72698+ atomic64_add_unchecked(nr, &event->count);
72699
72700 if (!hwc->sample_period)
72701 return;
72702@@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(struct perf_event *event)
72703 u64 now;
72704
72705 now = cpu_clock(cpu);
72706- prev = atomic64_read(&event->hw.prev_count);
72707- atomic64_set(&event->hw.prev_count, now);
72708- atomic64_add(now - prev, &event->count);
72709+ prev = atomic64_read_unchecked(&event->hw.prev_count);
72710+ atomic64_set_unchecked(&event->hw.prev_count, now);
72711+ atomic64_add_unchecked(now - prev, &event->count);
72712 }
72713
72714 static int cpu_clock_perf_event_enable(struct perf_event *event)
72715@@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(struct perf_event *event)
72716 struct hw_perf_event *hwc = &event->hw;
72717 int cpu = raw_smp_processor_id();
72718
72719- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
72720+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
72721 perf_swevent_start_hrtimer(event);
72722
72723 return 0;
72724@@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update(struct perf_event *event, u64 now)
72725 u64 prev;
72726 s64 delta;
72727
72728- prev = atomic64_xchg(&event->hw.prev_count, now);
72729+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
72730 delta = now - prev;
72731- atomic64_add(delta, &event->count);
72732+ atomic64_add_unchecked(delta, &event->count);
72733 }
72734
72735 static int task_clock_perf_event_enable(struct perf_event *event)
72736@@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(struct perf_event *event)
72737
72738 now = event->ctx->time;
72739
72740- atomic64_set(&hwc->prev_count, now);
72741+ atomic64_set_unchecked(&hwc->prev_count, now);
72742
72743 perf_swevent_start_hrtimer(event);
72744
72745@@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr *attr,
72746 event->parent = parent_event;
72747
72748 event->ns = get_pid_ns(current->nsproxy->pid_ns);
72749- event->id = atomic64_inc_return(&perf_event_id);
72750+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
72751
72752 event->state = PERF_EVENT_STATE_INACTIVE;
72753
72754@@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf_event *child_event,
72755 if (child_event->attr.inherit_stat)
72756 perf_event_read_event(child_event, child);
72757
72758- child_val = atomic64_read(&child_event->count);
72759+ child_val = atomic64_read_unchecked(&child_event->count);
72760
72761 /*
72762 * Add back the child's count to the parent's count:
72763 */
72764- atomic64_add(child_val, &parent_event->count);
72765- atomic64_add(child_event->total_time_enabled,
72766+ atomic64_add_unchecked(child_val, &parent_event->count);
72767+ atomic64_add_unchecked(child_event->total_time_enabled,
72768 &parent_event->child_total_time_enabled);
72769- atomic64_add(child_event->total_time_running,
72770+ atomic64_add_unchecked(child_event->total_time_running,
72771 &parent_event->child_total_time_running);
72772
72773 /*
72774diff --git a/kernel/pid.c b/kernel/pid.c
72775index fce7198..4f23a7e 100644
72776--- a/kernel/pid.c
72777+++ b/kernel/pid.c
72778@@ -33,6 +33,7 @@
72779 #include <linux/rculist.h>
72780 #include <linux/bootmem.h>
72781 #include <linux/hash.h>
72782+#include <linux/security.h>
72783 #include <linux/pid_namespace.h>
72784 #include <linux/init_task.h>
72785 #include <linux/syscalls.h>
72786@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
72787
72788 int pid_max = PID_MAX_DEFAULT;
72789
72790-#define RESERVED_PIDS 300
72791+#define RESERVED_PIDS 500
72792
72793 int pid_max_min = RESERVED_PIDS + 1;
72794 int pid_max_max = PID_MAX_LIMIT;
72795@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
72796 */
72797 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
72798 {
72799- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72800+ struct task_struct *task;
72801+
72802+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72803+
72804+ if (gr_pid_is_chrooted(task))
72805+ return NULL;
72806+
72807+ return task;
72808 }
72809
72810 struct task_struct *find_task_by_vpid(pid_t vnr)
72811@@ -391,6 +399,11 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
72812 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
72813 }
72814
72815+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
72816+{
72817+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
72818+}
72819+
72820 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
72821 {
72822 struct pid *pid;
72823diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
72824index 5c9dc22..d271117 100644
72825--- a/kernel/posix-cpu-timers.c
72826+++ b/kernel/posix-cpu-timers.c
72827@@ -6,6 +6,7 @@
72828 #include <linux/posix-timers.h>
72829 #include <linux/errno.h>
72830 #include <linux/math64.h>
72831+#include <linux/security.h>
72832 #include <asm/uaccess.h>
72833 #include <linux/kernel_stat.h>
72834 #include <trace/events/timer.h>
72835@@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
72836
72837 static __init int init_posix_cpu_timers(void)
72838 {
72839- struct k_clock process = {
72840+ static struct k_clock process = {
72841 .clock_getres = process_cpu_clock_getres,
72842 .clock_get = process_cpu_clock_get,
72843 .clock_set = do_posix_clock_nosettime,
72844@@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(void)
72845 .nsleep = process_cpu_nsleep,
72846 .nsleep_restart = process_cpu_nsleep_restart,
72847 };
72848- struct k_clock thread = {
72849+ static struct k_clock thread = {
72850 .clock_getres = thread_cpu_clock_getres,
72851 .clock_get = thread_cpu_clock_get,
72852 .clock_set = do_posix_clock_nosettime,
72853diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72854index 5e76d22..cf1baeb 100644
72855--- a/kernel/posix-timers.c
72856+++ b/kernel/posix-timers.c
72857@@ -42,6 +42,7 @@
72858 #include <linux/compiler.h>
72859 #include <linux/idr.h>
72860 #include <linux/posix-timers.h>
72861+#include <linux/grsecurity.h>
72862 #include <linux/syscalls.h>
72863 #include <linux/wait.h>
72864 #include <linux/workqueue.h>
72865@@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
72866 * which we beg off on and pass to do_sys_settimeofday().
72867 */
72868
72869-static struct k_clock posix_clocks[MAX_CLOCKS];
72870+static struct k_clock *posix_clocks[MAX_CLOCKS];
72871
72872 /*
72873 * These ones are defined below.
72874@@ -157,8 +158,8 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
72875 */
72876 #define CLOCK_DISPATCH(clock, call, arglist) \
72877 ((clock) < 0 ? posix_cpu_##call arglist : \
72878- (posix_clocks[clock].call != NULL \
72879- ? (*posix_clocks[clock].call) arglist : common_##call arglist))
72880+ (posix_clocks[clock]->call != NULL \
72881+ ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
72882
72883 /*
72884 * Default clock hook functions when the struct k_clock passed
72885@@ -172,7 +173,7 @@ static inline int common_clock_getres(const clockid_t which_clock,
72886 struct timespec *tp)
72887 {
72888 tp->tv_sec = 0;
72889- tp->tv_nsec = posix_clocks[which_clock].res;
72890+ tp->tv_nsec = posix_clocks[which_clock]->res;
72891 return 0;
72892 }
72893
72894@@ -217,9 +218,11 @@ static inline int invalid_clockid(const clockid_t which_clock)
72895 return 0;
72896 if ((unsigned) which_clock >= MAX_CLOCKS)
72897 return 1;
72898- if (posix_clocks[which_clock].clock_getres != NULL)
72899+ if (posix_clocks[which_clock] == NULL)
72900 return 0;
72901- if (posix_clocks[which_clock].res != 0)
72902+ if (posix_clocks[which_clock]->clock_getres != NULL)
72903+ return 0;
72904+ if (posix_clocks[which_clock]->res != 0)
72905 return 0;
72906 return 1;
72907 }
72908@@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
72909 */
72910 static __init int init_posix_timers(void)
72911 {
72912- struct k_clock clock_realtime = {
72913+ static struct k_clock clock_realtime = {
72914 .clock_getres = hrtimer_get_res,
72915 };
72916- struct k_clock clock_monotonic = {
72917+ static struct k_clock clock_monotonic = {
72918 .clock_getres = hrtimer_get_res,
72919 .clock_get = posix_ktime_get_ts,
72920 .clock_set = do_posix_clock_nosettime,
72921 };
72922- struct k_clock clock_monotonic_raw = {
72923+ static struct k_clock clock_monotonic_raw = {
72924 .clock_getres = hrtimer_get_res,
72925 .clock_get = posix_get_monotonic_raw,
72926 .clock_set = do_posix_clock_nosettime,
72927 .timer_create = no_timer_create,
72928 .nsleep = no_nsleep,
72929 };
72930- struct k_clock clock_realtime_coarse = {
72931+ static struct k_clock clock_realtime_coarse = {
72932 .clock_getres = posix_get_coarse_res,
72933 .clock_get = posix_get_realtime_coarse,
72934 .clock_set = do_posix_clock_nosettime,
72935 .timer_create = no_timer_create,
72936 .nsleep = no_nsleep,
72937 };
72938- struct k_clock clock_monotonic_coarse = {
72939+ static struct k_clock clock_monotonic_coarse = {
72940 .clock_getres = posix_get_coarse_res,
72941 .clock_get = posix_get_monotonic_coarse,
72942 .clock_set = do_posix_clock_nosettime,
72943@@ -296,6 +299,8 @@ static __init int init_posix_timers(void)
72944 .nsleep = no_nsleep,
72945 };
72946
72947+ pax_track_stack();
72948+
72949 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
72950 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
72951 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
72952@@ -484,7 +489,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
72953 return;
72954 }
72955
72956- posix_clocks[clock_id] = *new_clock;
72957+ posix_clocks[clock_id] = new_clock;
72958 }
72959 EXPORT_SYMBOL_GPL(register_posix_clock);
72960
72961@@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72962 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72963 return -EFAULT;
72964
72965+ /* only the CLOCK_REALTIME clock can be set, all other clocks
72966+ have their clock_set fptr set to a nosettime dummy function
72967+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72968+ call common_clock_set, which calls do_sys_settimeofday, which
72969+ we hook
72970+ */
72971+
72972 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
72973 }
72974
72975diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
72976index 04a9e90..bc355aa 100644
72977--- a/kernel/power/hibernate.c
72978+++ b/kernel/power/hibernate.c
72979@@ -48,14 +48,14 @@ enum {
72980
72981 static int hibernation_mode = HIBERNATION_SHUTDOWN;
72982
72983-static struct platform_hibernation_ops *hibernation_ops;
72984+static const struct platform_hibernation_ops *hibernation_ops;
72985
72986 /**
72987 * hibernation_set_ops - set the global hibernate operations
72988 * @ops: the hibernation operations to use in subsequent hibernation transitions
72989 */
72990
72991-void hibernation_set_ops(struct platform_hibernation_ops *ops)
72992+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
72993 {
72994 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
72995 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
72996diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
72997index e8b3370..484c2e4 100644
72998--- a/kernel/power/poweroff.c
72999+++ b/kernel/power/poweroff.c
73000@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
73001 .enable_mask = SYSRQ_ENABLE_BOOT,
73002 };
73003
73004-static int pm_sysrq_init(void)
73005+static int __init pm_sysrq_init(void)
73006 {
73007 register_sysrq_key('o', &sysrq_poweroff_op);
73008 return 0;
73009diff --git a/kernel/power/process.c b/kernel/power/process.c
73010index e7cd671..56d5f459 100644
73011--- a/kernel/power/process.c
73012+++ b/kernel/power/process.c
73013@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_only)
73014 struct timeval start, end;
73015 u64 elapsed_csecs64;
73016 unsigned int elapsed_csecs;
73017+ bool timedout = false;
73018
73019 do_gettimeofday(&start);
73020
73021 end_time = jiffies + TIMEOUT;
73022 do {
73023 todo = 0;
73024+ if (time_after(jiffies, end_time))
73025+ timedout = true;
73026 read_lock(&tasklist_lock);
73027 do_each_thread(g, p) {
73028 if (frozen(p) || !freezeable(p))
73029@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_only)
73030 * It is "frozen enough". If the task does wake
73031 * up, it will immediately call try_to_freeze.
73032 */
73033- if (!task_is_stopped_or_traced(p) &&
73034- !freezer_should_skip(p))
73035+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
73036 todo++;
73037+ if (timedout) {
73038+ printk(KERN_ERR "Task refusing to freeze:\n");
73039+ sched_show_task(p);
73040+ }
73041+ }
73042 } while_each_thread(g, p);
73043 read_unlock(&tasklist_lock);
73044 yield(); /* Yield is okay here */
73045- if (time_after(jiffies, end_time))
73046- break;
73047- } while (todo);
73048+ } while (todo && !timedout);
73049
73050 do_gettimeofday(&end);
73051 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
73052diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
73053index 40dd021..fb30ceb 100644
73054--- a/kernel/power/suspend.c
73055+++ b/kernel/power/suspend.c
73056@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_MAX] = {
73057 [PM_SUSPEND_MEM] = "mem",
73058 };
73059
73060-static struct platform_suspend_ops *suspend_ops;
73061+static const struct platform_suspend_ops *suspend_ops;
73062
73063 /**
73064 * suspend_set_ops - Set the global suspend method table.
73065 * @ops: Pointer to ops structure.
73066 */
73067-void suspend_set_ops(struct platform_suspend_ops *ops)
73068+void suspend_set_ops(const struct platform_suspend_ops *ops)
73069 {
73070 mutex_lock(&pm_mutex);
73071 suspend_ops = ops;
73072diff --git a/kernel/printk.c b/kernel/printk.c
73073index 4cade47..637e78a 100644
73074--- a/kernel/printk.c
73075+++ b/kernel/printk.c
73076@@ -278,6 +278,11 @@ int do_syslog(int type, char __user *buf, int len)
73077 char c;
73078 int error = 0;
73079
73080+#ifdef CONFIG_GRKERNSEC_DMESG
73081+ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
73082+ return -EPERM;
73083+#endif
73084+
73085 error = security_syslog(type);
73086 if (error)
73087 return error;
73088diff --git a/kernel/profile.c b/kernel/profile.c
73089index dfadc5b..7f59404 100644
73090--- a/kernel/profile.c
73091+++ b/kernel/profile.c
73092@@ -39,7 +39,7 @@ struct profile_hit {
73093 /* Oprofile timer tick hook */
73094 static int (*timer_hook)(struct pt_regs *) __read_mostly;
73095
73096-static atomic_t *prof_buffer;
73097+static atomic_unchecked_t *prof_buffer;
73098 static unsigned long prof_len, prof_shift;
73099
73100 int prof_on __read_mostly;
73101@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
73102 hits[i].pc = 0;
73103 continue;
73104 }
73105- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73106+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73107 hits[i].hits = hits[i].pc = 0;
73108 }
73109 }
73110@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73111 * Add the current hit(s) and flush the write-queue out
73112 * to the global buffer:
73113 */
73114- atomic_add(nr_hits, &prof_buffer[pc]);
73115+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
73116 for (i = 0; i < NR_PROFILE_HIT; ++i) {
73117- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73118+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73119 hits[i].pc = hits[i].hits = 0;
73120 }
73121 out:
73122@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73123 if (prof_on != type || !prof_buffer)
73124 return;
73125 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
73126- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73127+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73128 }
73129 #endif /* !CONFIG_SMP */
73130 EXPORT_SYMBOL_GPL(profile_hits);
73131@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
73132 return -EFAULT;
73133 buf++; p++; count--; read++;
73134 }
73135- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
73136+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
73137 if (copy_to_user(buf, (void *)pnt, count))
73138 return -EFAULT;
73139 read += count;
73140@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
73141 }
73142 #endif
73143 profile_discard_flip_buffers();
73144- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
73145+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
73146 return count;
73147 }
73148
73149diff --git a/kernel/ptrace.c b/kernel/ptrace.c
73150index 05625f6..733bf70 100644
73151--- a/kernel/ptrace.c
73152+++ b/kernel/ptrace.c
73153@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_struct *child, int kill)
73154 return ret;
73155 }
73156
73157-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73158+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
73159+ unsigned int log)
73160 {
73161 const struct cred *cred = current_cred(), *tcred;
73162
73163@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73164 cred->gid != tcred->egid ||
73165 cred->gid != tcred->sgid ||
73166 cred->gid != tcred->gid) &&
73167- !capable(CAP_SYS_PTRACE)) {
73168+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73169+ (log && !capable(CAP_SYS_PTRACE)))
73170+ ) {
73171 rcu_read_unlock();
73172 return -EPERM;
73173 }
73174@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73175 smp_rmb();
73176 if (task->mm)
73177 dumpable = get_dumpable(task->mm);
73178- if (!dumpable && !capable(CAP_SYS_PTRACE))
73179+ if (!dumpable &&
73180+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73181+ (log && !capable(CAP_SYS_PTRACE))))
73182 return -EPERM;
73183
73184 return security_ptrace_access_check(task, mode);
73185@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
73186 {
73187 int err;
73188 task_lock(task);
73189- err = __ptrace_may_access(task, mode);
73190+ err = __ptrace_may_access(task, mode, 0);
73191+ task_unlock(task);
73192+ return !err;
73193+}
73194+
73195+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
73196+{
73197+ int err;
73198+ task_lock(task);
73199+ err = __ptrace_may_access(task, mode, 1);
73200 task_unlock(task);
73201 return !err;
73202 }
73203@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *task)
73204 goto out;
73205
73206 task_lock(task);
73207- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
73208+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
73209 task_unlock(task);
73210 if (retval)
73211 goto unlock_creds;
73212@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *task)
73213 goto unlock_tasklist;
73214
73215 task->ptrace = PT_PTRACED;
73216- if (capable(CAP_SYS_PTRACE))
73217+ if (capable_nolog(CAP_SYS_PTRACE))
73218 task->ptrace |= PT_PTRACE_CAP;
73219
73220 __ptrace_link(task, current);
73221@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
73222 {
73223 int copied = 0;
73224
73225+ pax_track_stack();
73226+
73227 while (len > 0) {
73228 char buf[128];
73229 int this_len, retval;
73230@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
73231 {
73232 int copied = 0;
73233
73234+ pax_track_stack();
73235+
73236 while (len > 0) {
73237 char buf[128];
73238 int this_len, retval;
73239@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *child, long request,
73240 int ret = -EIO;
73241 siginfo_t siginfo;
73242
73243+ pax_track_stack();
73244+
73245 switch (request) {
73246 case PTRACE_PEEKTEXT:
73247 case PTRACE_PEEKDATA:
73248@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *child, long request,
73249 ret = ptrace_setoptions(child, data);
73250 break;
73251 case PTRACE_GETEVENTMSG:
73252- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
73253+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
73254 break;
73255
73256 case PTRACE_GETSIGINFO:
73257 ret = ptrace_getsiginfo(child, &siginfo);
73258 if (!ret)
73259- ret = copy_siginfo_to_user((siginfo_t __user *) data,
73260+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
73261 &siginfo);
73262 break;
73263
73264 case PTRACE_SETSIGINFO:
73265- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
73266+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
73267 sizeof siginfo))
73268 ret = -EFAULT;
73269 else
73270@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
73271 goto out;
73272 }
73273
73274+ if (gr_handle_ptrace(child, request)) {
73275+ ret = -EPERM;
73276+ goto out_put_task_struct;
73277+ }
73278+
73279 if (request == PTRACE_ATTACH) {
73280 ret = ptrace_attach(child);
73281 /*
73282 * Some architectures need to do book-keeping after
73283 * a ptrace attach.
73284 */
73285- if (!ret)
73286+ if (!ret) {
73287 arch_ptrace_attach(child);
73288+ gr_audit_ptrace(child);
73289+ }
73290 goto out_put_task_struct;
73291 }
73292
73293@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
73294 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
73295 if (copied != sizeof(tmp))
73296 return -EIO;
73297- return put_user(tmp, (unsigned long __user *)data);
73298+ return put_user(tmp, (__force unsigned long __user *)data);
73299 }
73300
73301 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
73302@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
73303 siginfo_t siginfo;
73304 int ret;
73305
73306+ pax_track_stack();
73307+
73308 switch (request) {
73309 case PTRACE_PEEKTEXT:
73310 case PTRACE_PEEKDATA:
73311@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73312 goto out;
73313 }
73314
73315+ if (gr_handle_ptrace(child, request)) {
73316+ ret = -EPERM;
73317+ goto out_put_task_struct;
73318+ }
73319+
73320 if (request == PTRACE_ATTACH) {
73321 ret = ptrace_attach(child);
73322 /*
73323 * Some architectures need to do book-keeping after
73324 * a ptrace attach.
73325 */
73326- if (!ret)
73327+ if (!ret) {
73328 arch_ptrace_attach(child);
73329+ gr_audit_ptrace(child);
73330+ }
73331 goto out_put_task_struct;
73332 }
73333
73334diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
73335index 697c0a0..2402696 100644
73336--- a/kernel/rcutorture.c
73337+++ b/kernel/rcutorture.c
73338@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
73339 { 0 };
73340 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
73341 { 0 };
73342-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73343-static atomic_t n_rcu_torture_alloc;
73344-static atomic_t n_rcu_torture_alloc_fail;
73345-static atomic_t n_rcu_torture_free;
73346-static atomic_t n_rcu_torture_mberror;
73347-static atomic_t n_rcu_torture_error;
73348+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73349+static atomic_unchecked_t n_rcu_torture_alloc;
73350+static atomic_unchecked_t n_rcu_torture_alloc_fail;
73351+static atomic_unchecked_t n_rcu_torture_free;
73352+static atomic_unchecked_t n_rcu_torture_mberror;
73353+static atomic_unchecked_t n_rcu_torture_error;
73354 static long n_rcu_torture_timers;
73355 static struct list_head rcu_torture_removed;
73356 static cpumask_var_t shuffle_tmp_mask;
73357@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
73358
73359 spin_lock_bh(&rcu_torture_lock);
73360 if (list_empty(&rcu_torture_freelist)) {
73361- atomic_inc(&n_rcu_torture_alloc_fail);
73362+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
73363 spin_unlock_bh(&rcu_torture_lock);
73364 return NULL;
73365 }
73366- atomic_inc(&n_rcu_torture_alloc);
73367+ atomic_inc_unchecked(&n_rcu_torture_alloc);
73368 p = rcu_torture_freelist.next;
73369 list_del_init(p);
73370 spin_unlock_bh(&rcu_torture_lock);
73371@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
73372 static void
73373 rcu_torture_free(struct rcu_torture *p)
73374 {
73375- atomic_inc(&n_rcu_torture_free);
73376+ atomic_inc_unchecked(&n_rcu_torture_free);
73377 spin_lock_bh(&rcu_torture_lock);
73378 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
73379 spin_unlock_bh(&rcu_torture_lock);
73380@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
73381 i = rp->rtort_pipe_count;
73382 if (i > RCU_TORTURE_PIPE_LEN)
73383 i = RCU_TORTURE_PIPE_LEN;
73384- atomic_inc(&rcu_torture_wcount[i]);
73385+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73386 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73387 rp->rtort_mbtest = 0;
73388 rcu_torture_free(rp);
73389@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
73390 i = rp->rtort_pipe_count;
73391 if (i > RCU_TORTURE_PIPE_LEN)
73392 i = RCU_TORTURE_PIPE_LEN;
73393- atomic_inc(&rcu_torture_wcount[i]);
73394+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73395 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73396 rp->rtort_mbtest = 0;
73397 list_del(&rp->rtort_free);
73398@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
73399 i = old_rp->rtort_pipe_count;
73400 if (i > RCU_TORTURE_PIPE_LEN)
73401 i = RCU_TORTURE_PIPE_LEN;
73402- atomic_inc(&rcu_torture_wcount[i]);
73403+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73404 old_rp->rtort_pipe_count++;
73405 cur_ops->deferred_free(old_rp);
73406 }
73407@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned long unused)
73408 return;
73409 }
73410 if (p->rtort_mbtest == 0)
73411- atomic_inc(&n_rcu_torture_mberror);
73412+ atomic_inc_unchecked(&n_rcu_torture_mberror);
73413 spin_lock(&rand_lock);
73414 cur_ops->read_delay(&rand);
73415 n_rcu_torture_timers++;
73416@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
73417 continue;
73418 }
73419 if (p->rtort_mbtest == 0)
73420- atomic_inc(&n_rcu_torture_mberror);
73421+ atomic_inc_unchecked(&n_rcu_torture_mberror);
73422 cur_ops->read_delay(&rand);
73423 preempt_disable();
73424 pipe_count = p->rtort_pipe_count;
73425@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
73426 rcu_torture_current,
73427 rcu_torture_current_version,
73428 list_empty(&rcu_torture_freelist),
73429- atomic_read(&n_rcu_torture_alloc),
73430- atomic_read(&n_rcu_torture_alloc_fail),
73431- atomic_read(&n_rcu_torture_free),
73432- atomic_read(&n_rcu_torture_mberror),
73433+ atomic_read_unchecked(&n_rcu_torture_alloc),
73434+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
73435+ atomic_read_unchecked(&n_rcu_torture_free),
73436+ atomic_read_unchecked(&n_rcu_torture_mberror),
73437 n_rcu_torture_timers);
73438- if (atomic_read(&n_rcu_torture_mberror) != 0)
73439+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
73440 cnt += sprintf(&page[cnt], " !!!");
73441 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
73442 if (i > 1) {
73443 cnt += sprintf(&page[cnt], "!!! ");
73444- atomic_inc(&n_rcu_torture_error);
73445+ atomic_inc_unchecked(&n_rcu_torture_error);
73446 WARN_ON_ONCE(1);
73447 }
73448 cnt += sprintf(&page[cnt], "Reader Pipe: ");
73449@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
73450 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
73451 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73452 cnt += sprintf(&page[cnt], " %d",
73453- atomic_read(&rcu_torture_wcount[i]));
73454+ atomic_read_unchecked(&rcu_torture_wcount[i]));
73455 }
73456 cnt += sprintf(&page[cnt], "\n");
73457 if (cur_ops->stats)
73458@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
73459
73460 if (cur_ops->cleanup)
73461 cur_ops->cleanup();
73462- if (atomic_read(&n_rcu_torture_error))
73463+ if (atomic_read_unchecked(&n_rcu_torture_error))
73464 rcu_torture_print_module_parms("End of test: FAILURE");
73465 else
73466 rcu_torture_print_module_parms("End of test: SUCCESS");
73467@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
73468
73469 rcu_torture_current = NULL;
73470 rcu_torture_current_version = 0;
73471- atomic_set(&n_rcu_torture_alloc, 0);
73472- atomic_set(&n_rcu_torture_alloc_fail, 0);
73473- atomic_set(&n_rcu_torture_free, 0);
73474- atomic_set(&n_rcu_torture_mberror, 0);
73475- atomic_set(&n_rcu_torture_error, 0);
73476+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
73477+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
73478+ atomic_set_unchecked(&n_rcu_torture_free, 0);
73479+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
73480+ atomic_set_unchecked(&n_rcu_torture_error, 0);
73481 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
73482- atomic_set(&rcu_torture_wcount[i], 0);
73483+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
73484 for_each_possible_cpu(cpu) {
73485 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73486 per_cpu(rcu_torture_count, cpu)[i] = 0;
73487diff --git a/kernel/rcutree.c b/kernel/rcutree.c
73488index 683c4f3..97f54c6 100644
73489--- a/kernel/rcutree.c
73490+++ b/kernel/rcutree.c
73491@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
73492 /*
73493 * Do softirq processing for the current CPU.
73494 */
73495-static void rcu_process_callbacks(struct softirq_action *unused)
73496+static void rcu_process_callbacks(void)
73497 {
73498 /*
73499 * Memory references from any prior RCU read-side critical sections
73500diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
73501index c03edf7..ac1b341 100644
73502--- a/kernel/rcutree_plugin.h
73503+++ b/kernel/rcutree_plugin.h
73504@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_switch(int cpu)
73505 */
73506 void __rcu_read_lock(void)
73507 {
73508- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
73509+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
73510 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
73511 }
73512 EXPORT_SYMBOL_GPL(__rcu_read_lock);
73513@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
73514 struct task_struct *t = current;
73515
73516 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
73517- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
73518+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
73519 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
73520 rcu_read_unlock_special(t);
73521 }
73522diff --git a/kernel/relay.c b/kernel/relay.c
73523index 760c262..a9fd241 100644
73524--- a/kernel/relay.c
73525+++ b/kernel/relay.c
73526@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct file *in,
73527 unsigned int flags,
73528 int *nonpad_ret)
73529 {
73530- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
73531+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
73532 struct rchan_buf *rbuf = in->private_data;
73533 unsigned int subbuf_size = rbuf->chan->subbuf_size;
73534 uint64_t pos = (uint64_t) *ppos;
73535@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct file *in,
73536 .ops = &relay_pipe_buf_ops,
73537 .spd_release = relay_page_release,
73538 };
73539+ ssize_t ret;
73540+
73541+ pax_track_stack();
73542
73543 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
73544 return 0;
73545diff --git a/kernel/resource.c b/kernel/resource.c
73546index fb11a58..4e61ae1 100644
73547--- a/kernel/resource.c
73548+++ b/kernel/resource.c
73549@@ -132,8 +132,18 @@ static const struct file_operations proc_iomem_operations = {
73550
73551 static int __init ioresources_init(void)
73552 {
73553+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73554+#ifdef CONFIG_GRKERNSEC_PROC_USER
73555+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
73556+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
73557+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73558+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
73559+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
73560+#endif
73561+#else
73562 proc_create("ioports", 0, NULL, &proc_ioports_operations);
73563 proc_create("iomem", 0, NULL, &proc_iomem_operations);
73564+#endif
73565 return 0;
73566 }
73567 __initcall(ioresources_init);
73568diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
73569index a56f629..1fc4989 100644
73570--- a/kernel/rtmutex-tester.c
73571+++ b/kernel/rtmutex-tester.c
73572@@ -21,7 +21,7 @@
73573 #define MAX_RT_TEST_MUTEXES 8
73574
73575 static spinlock_t rttest_lock;
73576-static atomic_t rttest_event;
73577+static atomic_unchecked_t rttest_event;
73578
73579 struct test_thread_data {
73580 int opcode;
73581@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73582
73583 case RTTEST_LOCKCONT:
73584 td->mutexes[td->opdata] = 1;
73585- td->event = atomic_add_return(1, &rttest_event);
73586+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73587 return 0;
73588
73589 case RTTEST_RESET:
73590@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73591 return 0;
73592
73593 case RTTEST_RESETEVENT:
73594- atomic_set(&rttest_event, 0);
73595+ atomic_set_unchecked(&rttest_event, 0);
73596 return 0;
73597
73598 default:
73599@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73600 return ret;
73601
73602 td->mutexes[id] = 1;
73603- td->event = atomic_add_return(1, &rttest_event);
73604+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73605 rt_mutex_lock(&mutexes[id]);
73606- td->event = atomic_add_return(1, &rttest_event);
73607+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73608 td->mutexes[id] = 4;
73609 return 0;
73610
73611@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73612 return ret;
73613
73614 td->mutexes[id] = 1;
73615- td->event = atomic_add_return(1, &rttest_event);
73616+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73617 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73618- td->event = atomic_add_return(1, &rttest_event);
73619+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73620 td->mutexes[id] = ret ? 0 : 4;
73621 return ret ? -EINTR : 0;
73622
73623@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73624 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73625 return ret;
73626
73627- td->event = atomic_add_return(1, &rttest_event);
73628+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73629 rt_mutex_unlock(&mutexes[id]);
73630- td->event = atomic_add_return(1, &rttest_event);
73631+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73632 td->mutexes[id] = 0;
73633 return 0;
73634
73635@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73636 break;
73637
73638 td->mutexes[dat] = 2;
73639- td->event = atomic_add_return(1, &rttest_event);
73640+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73641 break;
73642
73643 case RTTEST_LOCKBKL:
73644@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73645 return;
73646
73647 td->mutexes[dat] = 3;
73648- td->event = atomic_add_return(1, &rttest_event);
73649+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73650 break;
73651
73652 case RTTEST_LOCKNOWAIT:
73653@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73654 return;
73655
73656 td->mutexes[dat] = 1;
73657- td->event = atomic_add_return(1, &rttest_event);
73658+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73659 return;
73660
73661 case RTTEST_LOCKBKL:
73662diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
73663index 29bd4ba..8c5de90 100644
73664--- a/kernel/rtmutex.c
73665+++ b/kernel/rtmutex.c
73666@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
73667 */
73668 spin_lock_irqsave(&pendowner->pi_lock, flags);
73669
73670- WARN_ON(!pendowner->pi_blocked_on);
73671+ BUG_ON(!pendowner->pi_blocked_on);
73672 WARN_ON(pendowner->pi_blocked_on != waiter);
73673 WARN_ON(pendowner->pi_blocked_on->lock != lock);
73674
73675diff --git a/kernel/sched.c b/kernel/sched.c
73676index 0591df8..6e343c3 100644
73677--- a/kernel/sched.c
73678+++ b/kernel/sched.c
73679@@ -2764,9 +2764,10 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
73680 {
73681 unsigned long flags;
73682 struct rq *rq;
73683- int cpu = get_cpu();
73684
73685 #ifdef CONFIG_SMP
73686+ int cpu = get_cpu();
73687+
73688 rq = task_rq_lock(p, &flags);
73689 p->state = TASK_WAKING;
73690
73691@@ -5043,7 +5044,7 @@ out:
73692 * In CONFIG_NO_HZ case, the idle load balance owner will do the
73693 * rebalancing for all the cpus for whom scheduler ticks are stopped.
73694 */
73695-static void run_rebalance_domains(struct softirq_action *h)
73696+static void run_rebalance_domains(void)
73697 {
73698 int this_cpu = smp_processor_id();
73699 struct rq *this_rq = cpu_rq(this_cpu);
73700@@ -5700,6 +5701,8 @@ asmlinkage void __sched schedule(void)
73701 struct rq *rq;
73702 int cpu;
73703
73704+ pax_track_stack();
73705+
73706 need_resched:
73707 preempt_disable();
73708 cpu = smp_processor_id();
73709@@ -5770,7 +5773,7 @@ EXPORT_SYMBOL(schedule);
73710 * Look out! "owner" is an entirely speculative pointer
73711 * access and not reliable.
73712 */
73713-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73714+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
73715 {
73716 unsigned int cpu;
73717 struct rq *rq;
73718@@ -5784,10 +5787,10 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73719 * DEBUG_PAGEALLOC could have unmapped it if
73720 * the mutex owner just released it and exited.
73721 */
73722- if (probe_kernel_address(&owner->cpu, cpu))
73723+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
73724 return 0;
73725 #else
73726- cpu = owner->cpu;
73727+ cpu = task_thread_info(owner)->cpu;
73728 #endif
73729
73730 /*
73731@@ -5816,7 +5819,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73732 /*
73733 * Is that owner really running on that cpu?
73734 */
73735- if (task_thread_info(rq->curr) != owner || need_resched())
73736+ if (rq->curr != owner || need_resched())
73737 return 0;
73738
73739 cpu_relax();
73740@@ -6359,6 +6362,8 @@ int can_nice(const struct task_struct *p, const int nice)
73741 /* convert nice value [19,-20] to rlimit style value [1,40] */
73742 int nice_rlim = 20 - nice;
73743
73744+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73745+
73746 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
73747 capable(CAP_SYS_NICE));
73748 }
73749@@ -6392,7 +6397,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73750 if (nice > 19)
73751 nice = 19;
73752
73753- if (increment < 0 && !can_nice(current, nice))
73754+ if (increment < 0 && (!can_nice(current, nice) ||
73755+ gr_handle_chroot_nice()))
73756 return -EPERM;
73757
73758 retval = security_task_setnice(current, nice);
73759@@ -8774,7 +8780,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
73760 long power;
73761 int weight;
73762
73763- WARN_ON(!sd || !sd->groups);
73764+ BUG_ON(!sd || !sd->groups);
73765
73766 if (cpu != group_first_cpu(sd->groups))
73767 return;
73768diff --git a/kernel/signal.c b/kernel/signal.c
73769index 2494827..cda80a0 100644
73770--- a/kernel/signal.c
73771+++ b/kernel/signal.c
73772@@ -41,12 +41,12 @@
73773
73774 static struct kmem_cache *sigqueue_cachep;
73775
73776-static void __user *sig_handler(struct task_struct *t, int sig)
73777+static __sighandler_t sig_handler(struct task_struct *t, int sig)
73778 {
73779 return t->sighand->action[sig - 1].sa.sa_handler;
73780 }
73781
73782-static int sig_handler_ignored(void __user *handler, int sig)
73783+static int sig_handler_ignored(__sighandler_t handler, int sig)
73784 {
73785 /* Is it explicitly or implicitly ignored? */
73786 return handler == SIG_IGN ||
73787@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73788 static int sig_task_ignored(struct task_struct *t, int sig,
73789 int from_ancestor_ns)
73790 {
73791- void __user *handler;
73792+ __sighandler_t handler;
73793
73794 handler = sig_handler(t, sig);
73795
73796@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
73797 */
73798 user = get_uid(__task_cred(t)->user);
73799 atomic_inc(&user->sigpending);
73800+
73801+ if (!override_rlimit)
73802+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73803 if (override_rlimit ||
73804 atomic_read(&user->sigpending) <=
73805 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
73806@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73807
73808 int unhandled_signal(struct task_struct *tsk, int sig)
73809 {
73810- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73811+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73812 if (is_global_init(tsk))
73813 return 1;
73814 if (handler != SIG_IGN && handler != SIG_DFL)
73815@@ -627,6 +630,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73816 }
73817 }
73818
73819+ /* allow glibc communication via tgkill to other threads in our
73820+ thread group */
73821+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73822+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73823+ && gr_handle_signal(t, sig))
73824+ return -EPERM;
73825+
73826 return security_task_kill(t, info, sig, 0);
73827 }
73828
73829@@ -968,7 +978,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73830 return send_signal(sig, info, p, 1);
73831 }
73832
73833-static int
73834+int
73835 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73836 {
73837 return send_signal(sig, info, t, 0);
73838@@ -1005,6 +1015,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73839 unsigned long int flags;
73840 int ret, blocked, ignored;
73841 struct k_sigaction *action;
73842+ int is_unhandled = 0;
73843
73844 spin_lock_irqsave(&t->sighand->siglock, flags);
73845 action = &t->sighand->action[sig-1];
73846@@ -1019,9 +1030,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73847 }
73848 if (action->sa.sa_handler == SIG_DFL)
73849 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73850+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73851+ is_unhandled = 1;
73852 ret = specific_send_sig_info(sig, info, t);
73853 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73854
73855+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
73856+ normal operation */
73857+ if (is_unhandled) {
73858+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73859+ gr_handle_crash(t, sig);
73860+ }
73861+
73862 return ret;
73863 }
73864
73865@@ -1081,8 +1101,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73866 {
73867 int ret = check_kill_permission(sig, info, p);
73868
73869- if (!ret && sig)
73870+ if (!ret && sig) {
73871 ret = do_send_sig_info(sig, info, p, true);
73872+ if (!ret)
73873+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73874+ }
73875
73876 return ret;
73877 }
73878@@ -1644,6 +1667,8 @@ void ptrace_notify(int exit_code)
73879 {
73880 siginfo_t info;
73881
73882+ pax_track_stack();
73883+
73884 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
73885
73886 memset(&info, 0, sizeof info);
73887@@ -2275,7 +2300,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73888 int error = -ESRCH;
73889
73890 rcu_read_lock();
73891- p = find_task_by_vpid(pid);
73892+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73893+ /* allow glibc communication via tgkill to other threads in our
73894+ thread group */
73895+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73896+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
73897+ p = find_task_by_vpid_unrestricted(pid);
73898+ else
73899+#endif
73900+ p = find_task_by_vpid(pid);
73901 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73902 error = check_kill_permission(sig, info, p);
73903 /*
73904diff --git a/kernel/smp.c b/kernel/smp.c
73905index aa9cff3..631a0de 100644
73906--- a/kernel/smp.c
73907+++ b/kernel/smp.c
73908@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void *), void *info, int wait)
73909 }
73910 EXPORT_SYMBOL(smp_call_function);
73911
73912-void ipi_call_lock(void)
73913+void ipi_call_lock(void) __acquires(call_function.lock)
73914 {
73915 spin_lock(&call_function.lock);
73916 }
73917
73918-void ipi_call_unlock(void)
73919+void ipi_call_unlock(void) __releases(call_function.lock)
73920 {
73921 spin_unlock(&call_function.lock);
73922 }
73923
73924-void ipi_call_lock_irq(void)
73925+void ipi_call_lock_irq(void) __acquires(call_function.lock)
73926 {
73927 spin_lock_irq(&call_function.lock);
73928 }
73929
73930-void ipi_call_unlock_irq(void)
73931+void ipi_call_unlock_irq(void) __releases(call_function.lock)
73932 {
73933 spin_unlock_irq(&call_function.lock);
73934 }
73935diff --git a/kernel/softirq.c b/kernel/softirq.c
73936index 04a0252..580c512 100644
73937--- a/kernel/softirq.c
73938+++ b/kernel/softirq.c
73939@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
73940
73941 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73942
73943-char *softirq_to_name[NR_SOFTIRQS] = {
73944+const char * const softirq_to_name[NR_SOFTIRQS] = {
73945 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73946 "TASKLET", "SCHED", "HRTIMER", "RCU"
73947 };
73948@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
73949
73950 asmlinkage void __do_softirq(void)
73951 {
73952- struct softirq_action *h;
73953+ const struct softirq_action *h;
73954 __u32 pending;
73955 int max_restart = MAX_SOFTIRQ_RESTART;
73956 int cpu;
73957@@ -233,7 +233,7 @@ restart:
73958 kstat_incr_softirqs_this_cpu(h - softirq_vec);
73959
73960 trace_softirq_entry(h, softirq_vec);
73961- h->action(h);
73962+ h->action();
73963 trace_softirq_exit(h, softirq_vec);
73964 if (unlikely(prev_count != preempt_count())) {
73965 printk(KERN_ERR "huh, entered softirq %td %s %p"
73966@@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
73967 local_irq_restore(flags);
73968 }
73969
73970-void open_softirq(int nr, void (*action)(struct softirq_action *))
73971+void open_softirq(int nr, void (*action)(void))
73972 {
73973- softirq_vec[nr].action = action;
73974+ pax_open_kernel();
73975+ *(void **)&softirq_vec[nr].action = action;
73976+ pax_close_kernel();
73977 }
73978
73979 /*
73980@@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73981
73982 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73983
73984-static void tasklet_action(struct softirq_action *a)
73985+static void tasklet_action(void)
73986 {
73987 struct tasklet_struct *list;
73988
73989@@ -454,7 +456,7 @@ static void tasklet_action(struct softirq_action *a)
73990 }
73991 }
73992
73993-static void tasklet_hi_action(struct softirq_action *a)
73994+static void tasklet_hi_action(void)
73995 {
73996 struct tasklet_struct *list;
73997
73998diff --git a/kernel/sys.c b/kernel/sys.c
73999index e9512b1..3c265de 100644
74000--- a/kernel/sys.c
74001+++ b/kernel/sys.c
74002@@ -133,6 +133,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
74003 error = -EACCES;
74004 goto out;
74005 }
74006+
74007+ if (gr_handle_chroot_setpriority(p, niceval)) {
74008+ error = -EACCES;
74009+ goto out;
74010+ }
74011+
74012 no_nice = security_task_setnice(p, niceval);
74013 if (no_nice) {
74014 error = no_nice;
74015@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
74016 !(user = find_user(who)))
74017 goto out_unlock; /* No processes for this user */
74018
74019- do_each_thread(g, p)
74020+ do_each_thread(g, p) {
74021 if (__task_cred(p)->uid == who)
74022 error = set_one_prio(p, niceval, error);
74023- while_each_thread(g, p);
74024+ } while_each_thread(g, p);
74025 if (who != cred->uid)
74026 free_uid(user); /* For find_user() */
74027 break;
74028@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
74029 !(user = find_user(who)))
74030 goto out_unlock; /* No processes for this user */
74031
74032- do_each_thread(g, p)
74033+ do_each_thread(g, p) {
74034 if (__task_cred(p)->uid == who) {
74035 niceval = 20 - task_nice(p);
74036 if (niceval > retval)
74037 retval = niceval;
74038 }
74039- while_each_thread(g, p);
74040+ } while_each_thread(g, p);
74041 if (who != cred->uid)
74042 free_uid(user); /* for find_user() */
74043 break;
74044@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
74045 goto error;
74046 }
74047
74048+ if (gr_check_group_change(new->gid, new->egid, -1))
74049+ goto error;
74050+
74051 if (rgid != (gid_t) -1 ||
74052 (egid != (gid_t) -1 && egid != old->gid))
74053 new->sgid = new->egid;
74054@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
74055 goto error;
74056
74057 retval = -EPERM;
74058+
74059+ if (gr_check_group_change(gid, gid, gid))
74060+ goto error;
74061+
74062 if (capable(CAP_SETGID))
74063 new->gid = new->egid = new->sgid = new->fsgid = gid;
74064 else if (gid == old->gid || gid == old->sgid)
74065@@ -567,12 +580,19 @@ static int set_user(struct cred *new)
74066 if (!new_user)
74067 return -EAGAIN;
74068
74069+ /*
74070+ * We don't fail in case of NPROC limit excess here because too many
74071+ * poorly written programs don't check set*uid() return code, assuming
74072+ * it never fails if called by root. We may still enforce NPROC limit
74073+ * for programs doing set*uid()+execve() by harmlessly deferring the
74074+ * failure to the execve() stage.
74075+ */
74076 if (atomic_read(&new_user->processes) >=
74077 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
74078- new_user != INIT_USER) {
74079- free_uid(new_user);
74080- return -EAGAIN;
74081- }
74082+ new_user != INIT_USER)
74083+ current->flags |= PF_NPROC_EXCEEDED;
74084+ else
74085+ current->flags &= ~PF_NPROC_EXCEEDED;
74086
74087 free_uid(new->user);
74088 new->user = new_user;
74089@@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
74090 goto error;
74091 }
74092
74093+ if (gr_check_user_change(new->uid, new->euid, -1))
74094+ goto error;
74095+
74096 if (new->uid != old->uid) {
74097 retval = set_user(new);
74098 if (retval < 0)
74099@@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
74100 goto error;
74101
74102 retval = -EPERM;
74103+
74104+ if (gr_check_crash_uid(uid))
74105+ goto error;
74106+ if (gr_check_user_change(uid, uid, uid))
74107+ goto error;
74108+
74109 if (capable(CAP_SETUID)) {
74110 new->suid = new->uid = uid;
74111 if (uid != old->uid) {
74112@@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
74113 goto error;
74114 }
74115
74116+ if (gr_check_user_change(ruid, euid, -1))
74117+ goto error;
74118+
74119 if (ruid != (uid_t) -1) {
74120 new->uid = ruid;
74121 if (ruid != old->uid) {
74122@@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
74123 goto error;
74124 }
74125
74126+ if (gr_check_group_change(rgid, egid, -1))
74127+ goto error;
74128+
74129 if (rgid != (gid_t) -1)
74130 new->gid = rgid;
74131 if (egid != (gid_t) -1)
74132@@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
74133 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
74134 goto error;
74135
74136+ if (gr_check_user_change(-1, -1, uid))
74137+ goto error;
74138+
74139 if (uid == old->uid || uid == old->euid ||
74140 uid == old->suid || uid == old->fsuid ||
74141 capable(CAP_SETUID)) {
74142@@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
74143 if (gid == old->gid || gid == old->egid ||
74144 gid == old->sgid || gid == old->fsgid ||
74145 capable(CAP_SETGID)) {
74146+ if (gr_check_group_change(-1, -1, gid))
74147+ goto error;
74148+
74149 if (gid != old_fsgid) {
74150 new->fsgid = gid;
74151 goto change_okay;
74152@@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
74153 error = get_dumpable(me->mm);
74154 break;
74155 case PR_SET_DUMPABLE:
74156- if (arg2 < 0 || arg2 > 1) {
74157+ if (arg2 > 1) {
74158 error = -EINVAL;
74159 break;
74160 }
74161diff --git a/kernel/sysctl.c b/kernel/sysctl.c
74162index b8bd058..ab6a76be 100644
74163--- a/kernel/sysctl.c
74164+++ b/kernel/sysctl.c
74165@@ -63,6 +63,13 @@
74166 static int deprecated_sysctl_warning(struct __sysctl_args *args);
74167
74168 #if defined(CONFIG_SYSCTL)
74169+#include <linux/grsecurity.h>
74170+#include <linux/grinternal.h>
74171+
74172+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
74173+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
74174+ const int op);
74175+extern int gr_handle_chroot_sysctl(const int op);
74176
74177 /* External variables not in a header file. */
74178 extern int C_A_D;
74179@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
74180 static int proc_taint(struct ctl_table *table, int write,
74181 void __user *buffer, size_t *lenp, loff_t *ppos);
74182 #endif
74183+extern ctl_table grsecurity_table[];
74184
74185 static struct ctl_table root_table[];
74186 static struct ctl_table_root sysctl_table_root;
74187@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
74188 int sysctl_legacy_va_layout;
74189 #endif
74190
74191+#ifdef CONFIG_PAX_SOFTMODE
74192+static ctl_table pax_table[] = {
74193+ {
74194+ .ctl_name = CTL_UNNUMBERED,
74195+ .procname = "softmode",
74196+ .data = &pax_softmode,
74197+ .maxlen = sizeof(unsigned int),
74198+ .mode = 0600,
74199+ .proc_handler = &proc_dointvec,
74200+ },
74201+
74202+ { .ctl_name = 0 }
74203+};
74204+#endif
74205+
74206 extern int prove_locking;
74207 extern int lock_stat;
74208
74209@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
74210 #endif
74211
74212 static struct ctl_table kern_table[] = {
74213+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
74214+ {
74215+ .ctl_name = CTL_UNNUMBERED,
74216+ .procname = "grsecurity",
74217+ .mode = 0500,
74218+ .child = grsecurity_table,
74219+ },
74220+#endif
74221+
74222+#ifdef CONFIG_PAX_SOFTMODE
74223+ {
74224+ .ctl_name = CTL_UNNUMBERED,
74225+ .procname = "pax",
74226+ .mode = 0500,
74227+ .child = pax_table,
74228+ },
74229+#endif
74230+
74231 {
74232 .ctl_name = CTL_UNNUMBERED,
74233 .procname = "sched_child_runs_first",
74234@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
74235 .data = &modprobe_path,
74236 .maxlen = KMOD_PATH_LEN,
74237 .mode = 0644,
74238- .proc_handler = &proc_dostring,
74239- .strategy = &sysctl_string,
74240+ .proc_handler = &proc_dostring_modpriv,
74241+ .strategy = &sysctl_string_modpriv,
74242 },
74243 {
74244 .ctl_name = CTL_UNNUMBERED,
74245@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
74246 .mode = 0644,
74247 .proc_handler = &proc_dointvec
74248 },
74249+ {
74250+ .procname = "heap_stack_gap",
74251+ .data = &sysctl_heap_stack_gap,
74252+ .maxlen = sizeof(sysctl_heap_stack_gap),
74253+ .mode = 0644,
74254+ .proc_handler = proc_doulongvec_minmax,
74255+ },
74256 #else
74257 {
74258 .ctl_name = CTL_UNNUMBERED,
74259@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
74260 return 0;
74261 }
74262
74263+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
74264+
74265 static int parse_table(int __user *name, int nlen,
74266 void __user *oldval, size_t __user *oldlenp,
74267 void __user *newval, size_t newlen,
74268@@ -1821,7 +1871,7 @@ repeat:
74269 if (n == table->ctl_name) {
74270 int error;
74271 if (table->child) {
74272- if (sysctl_perm(root, table, MAY_EXEC))
74273+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
74274 return -EPERM;
74275 name++;
74276 nlen--;
74277@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
74278 int error;
74279 int mode;
74280
74281+ if (table->parent != NULL && table->parent->procname != NULL &&
74282+ table->procname != NULL &&
74283+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
74284+ return -EACCES;
74285+ if (gr_handle_chroot_sysctl(op))
74286+ return -EACCES;
74287+ error = gr_handle_sysctl(table, op);
74288+ if (error)
74289+ return error;
74290+
74291+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74292+ if (error)
74293+ return error;
74294+
74295+ if (root->permissions)
74296+ mode = root->permissions(root, current->nsproxy, table);
74297+ else
74298+ mode = table->mode;
74299+
74300+ return test_perm(mode, op);
74301+}
74302+
74303+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
74304+{
74305+ int error;
74306+ int mode;
74307+
74308 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74309 if (error)
74310 return error;
74311@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *table, int write,
74312 buffer, lenp, ppos);
74313 }
74314
74315+int proc_dostring_modpriv(struct ctl_table *table, int write,
74316+ void __user *buffer, size_t *lenp, loff_t *ppos)
74317+{
74318+ if (write && !capable(CAP_SYS_MODULE))
74319+ return -EPERM;
74320+
74321+ return _proc_do_string(table->data, table->maxlen, write,
74322+ buffer, lenp, ppos);
74323+}
74324+
74325
74326 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
74327 int *valp,
74328@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
74329 vleft = table->maxlen / sizeof(unsigned long);
74330 left = *lenp;
74331
74332- for (; left && vleft--; i++, min++, max++, first=0) {
74333+ for (; left && vleft--; i++, first=0) {
74334 if (write) {
74335 while (left) {
74336 char c;
74337@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *table, int write,
74338 return -ENOSYS;
74339 }
74340
74341+int proc_dostring_modpriv(struct ctl_table *table, int write,
74342+ void __user *buffer, size_t *lenp, loff_t *ppos)
74343+{
74344+ return -ENOSYS;
74345+}
74346+
74347 int proc_dointvec(struct ctl_table *table, int write,
74348 void __user *buffer, size_t *lenp, loff_t *ppos)
74349 {
74350@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *table,
74351 return 1;
74352 }
74353
74354+int sysctl_string_modpriv(struct ctl_table *table,
74355+ void __user *oldval, size_t __user *oldlenp,
74356+ void __user *newval, size_t newlen)
74357+{
74358+ if (newval && newlen && !capable(CAP_SYS_MODULE))
74359+ return -EPERM;
74360+
74361+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
74362+}
74363+
74364 /*
74365 * This function makes sure that all of the integers in the vector
74366 * are between the minimum and maximum values given in the arrays
74367@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *table,
74368 return -ENOSYS;
74369 }
74370
74371+int sysctl_string_modpriv(struct ctl_table *table,
74372+ void __user *oldval, size_t __user *oldlenp,
74373+ void __user *newval, size_t newlen)
74374+{
74375+ return -ENOSYS;
74376+}
74377+
74378 int sysctl_intvec(struct ctl_table *table,
74379 void __user *oldval, size_t __user *oldlenp,
74380 void __user *newval, size_t newlen)
74381@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
74382 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
74383 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
74384 EXPORT_SYMBOL(proc_dostring);
74385+EXPORT_SYMBOL(proc_dostring_modpriv);
74386 EXPORT_SYMBOL(proc_doulongvec_minmax);
74387 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
74388 EXPORT_SYMBOL(register_sysctl_table);
74389@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
74390 EXPORT_SYMBOL(sysctl_jiffies);
74391 EXPORT_SYMBOL(sysctl_ms_jiffies);
74392 EXPORT_SYMBOL(sysctl_string);
74393+EXPORT_SYMBOL(sysctl_string_modpriv);
74394 EXPORT_SYMBOL(sysctl_data);
74395 EXPORT_SYMBOL(unregister_sysctl_table);
74396diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
74397index 469193c..ea3ecb2 100644
74398--- a/kernel/sysctl_check.c
74399+++ b/kernel/sysctl_check.c
74400@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
74401 } else {
74402 if ((table->strategy == sysctl_data) ||
74403 (table->strategy == sysctl_string) ||
74404+ (table->strategy == sysctl_string_modpriv) ||
74405 (table->strategy == sysctl_intvec) ||
74406 (table->strategy == sysctl_jiffies) ||
74407 (table->strategy == sysctl_ms_jiffies) ||
74408 (table->proc_handler == proc_dostring) ||
74409+ (table->proc_handler == proc_dostring_modpriv) ||
74410 (table->proc_handler == proc_dointvec) ||
74411 (table->proc_handler == proc_dointvec_minmax) ||
74412 (table->proc_handler == proc_dointvec_jiffies) ||
74413diff --git a/kernel/taskstats.c b/kernel/taskstats.c
74414index b080920..d344f89 100644
74415--- a/kernel/taskstats.c
74416+++ b/kernel/taskstats.c
74417@@ -26,9 +26,12 @@
74418 #include <linux/cgroup.h>
74419 #include <linux/fs.h>
74420 #include <linux/file.h>
74421+#include <linux/grsecurity.h>
74422 #include <net/genetlink.h>
74423 #include <asm/atomic.h>
74424
74425+extern int gr_is_taskstats_denied(int pid);
74426+
74427 /*
74428 * Maximum length of a cpumask that can be specified in
74429 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
74430@@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
74431 size_t size;
74432 cpumask_var_t mask;
74433
74434+ if (gr_is_taskstats_denied(current->pid))
74435+ return -EACCES;
74436+
74437 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
74438 return -ENOMEM;
74439
74440diff --git a/kernel/time.c b/kernel/time.c
74441index 33df60e..ca768bd 100644
74442--- a/kernel/time.c
74443+++ b/kernel/time.c
74444@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
74445 return error;
74446
74447 if (tz) {
74448+ /* we log in do_settimeofday called below, so don't log twice
74449+ */
74450+ if (!tv)
74451+ gr_log_timechange();
74452+
74453 /* SMP safe, global irq locking makes it work. */
74454 sys_tz = *tz;
74455 update_vsyscall_tz();
74456@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
74457 * Avoid unnecessary multiplications/divisions in the
74458 * two most common HZ cases:
74459 */
74460-unsigned int inline jiffies_to_msecs(const unsigned long j)
74461+inline unsigned int jiffies_to_msecs(const unsigned long j)
74462 {
74463 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
74464 return (MSEC_PER_SEC / HZ) * j;
74465@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
74466 }
74467 EXPORT_SYMBOL(jiffies_to_msecs);
74468
74469-unsigned int inline jiffies_to_usecs(const unsigned long j)
74470+inline unsigned int jiffies_to_usecs(const unsigned long j)
74471 {
74472 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
74473 return (USEC_PER_SEC / HZ) * j;
74474diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
74475index 57b953f..06f149f 100644
74476--- a/kernel/time/tick-broadcast.c
74477+++ b/kernel/time/tick-broadcast.c
74478@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
74479 * then clear the broadcast bit.
74480 */
74481 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
74482- int cpu = smp_processor_id();
74483+ cpu = smp_processor_id();
74484
74485 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
74486 tick_broadcast_clear_oneshot(cpu);
74487diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
74488index 4a71cff..ffb5548 100644
74489--- a/kernel/time/timekeeping.c
74490+++ b/kernel/time/timekeeping.c
74491@@ -14,6 +14,7 @@
74492 #include <linux/init.h>
74493 #include <linux/mm.h>
74494 #include <linux/sched.h>
74495+#include <linux/grsecurity.h>
74496 #include <linux/sysdev.h>
74497 #include <linux/clocksource.h>
74498 #include <linux/jiffies.h>
74499@@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
74500 */
74501 struct timespec ts = xtime;
74502 timespec_add_ns(&ts, nsec);
74503- ACCESS_ONCE(xtime_cache) = ts;
74504+ ACCESS_ONCE_RW(xtime_cache) = ts;
74505 }
74506
74507 /* must hold xtime_lock */
74508@@ -337,6 +338,8 @@ int do_settimeofday(struct timespec *tv)
74509 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
74510 return -EINVAL;
74511
74512+ gr_log_timechange();
74513+
74514 write_seqlock_irqsave(&xtime_lock, flags);
74515
74516 timekeeping_forward_now();
74517diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74518index 54c0dda..e9095d9 100644
74519--- a/kernel/time/timer_list.c
74520+++ b/kernel/time/timer_list.c
74521@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74522
74523 static void print_name_offset(struct seq_file *m, void *sym)
74524 {
74525+#ifdef CONFIG_GRKERNSEC_HIDESYM
74526+ SEQ_printf(m, "<%p>", NULL);
74527+#else
74528 char symname[KSYM_NAME_LEN];
74529
74530 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74531 SEQ_printf(m, "<%p>", sym);
74532 else
74533 SEQ_printf(m, "%s", symname);
74534+#endif
74535 }
74536
74537 static void
74538@@ -112,7 +116,11 @@ next_one:
74539 static void
74540 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
74541 {
74542+#ifdef CONFIG_GRKERNSEC_HIDESYM
74543+ SEQ_printf(m, " .base: %p\n", NULL);
74544+#else
74545 SEQ_printf(m, " .base: %p\n", base);
74546+#endif
74547 SEQ_printf(m, " .index: %d\n",
74548 base->index);
74549 SEQ_printf(m, " .resolution: %Lu nsecs\n",
74550@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs(void)
74551 {
74552 struct proc_dir_entry *pe;
74553
74554+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74555+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
74556+#else
74557 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
74558+#endif
74559 if (!pe)
74560 return -ENOMEM;
74561 return 0;
74562diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
74563index ee5681f..634089b 100644
74564--- a/kernel/time/timer_stats.c
74565+++ b/kernel/time/timer_stats.c
74566@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74567 static unsigned long nr_entries;
74568 static struct entry entries[MAX_ENTRIES];
74569
74570-static atomic_t overflow_count;
74571+static atomic_unchecked_t overflow_count;
74572
74573 /*
74574 * The entries are in a hash-table, for fast lookup:
74575@@ -140,7 +140,7 @@ static void reset_entries(void)
74576 nr_entries = 0;
74577 memset(entries, 0, sizeof(entries));
74578 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74579- atomic_set(&overflow_count, 0);
74580+ atomic_set_unchecked(&overflow_count, 0);
74581 }
74582
74583 static struct entry *alloc_entry(void)
74584@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74585 if (likely(entry))
74586 entry->count++;
74587 else
74588- atomic_inc(&overflow_count);
74589+ atomic_inc_unchecked(&overflow_count);
74590
74591 out_unlock:
74592 spin_unlock_irqrestore(lock, flags);
74593@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74594
74595 static void print_name_offset(struct seq_file *m, unsigned long addr)
74596 {
74597+#ifdef CONFIG_GRKERNSEC_HIDESYM
74598+ seq_printf(m, "<%p>", NULL);
74599+#else
74600 char symname[KSYM_NAME_LEN];
74601
74602 if (lookup_symbol_name(addr, symname) < 0)
74603 seq_printf(m, "<%p>", (void *)addr);
74604 else
74605 seq_printf(m, "%s", symname);
74606+#endif
74607 }
74608
74609 static int tstats_show(struct seq_file *m, void *v)
74610@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74611
74612 seq_puts(m, "Timer Stats Version: v0.2\n");
74613 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74614- if (atomic_read(&overflow_count))
74615+ if (atomic_read_unchecked(&overflow_count))
74616 seq_printf(m, "Overflow: %d entries\n",
74617- atomic_read(&overflow_count));
74618+ atomic_read_unchecked(&overflow_count));
74619
74620 for (i = 0; i < nr_entries; i++) {
74621 entry = entries + i;
74622@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(void)
74623 {
74624 struct proc_dir_entry *pe;
74625
74626+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74627+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74628+#else
74629 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74630+#endif
74631 if (!pe)
74632 return -ENOMEM;
74633 return 0;
74634diff --git a/kernel/timer.c b/kernel/timer.c
74635index cb3c1f1..8bf5526 100644
74636--- a/kernel/timer.c
74637+++ b/kernel/timer.c
74638@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
74639 /*
74640 * This function runs timers and the timer-tq in bottom half context.
74641 */
74642-static void run_timer_softirq(struct softirq_action *h)
74643+static void run_timer_softirq(void)
74644 {
74645 struct tvec_base *base = __get_cpu_var(tvec_bases);
74646
74647diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74648index d9d6206..f19467e 100644
74649--- a/kernel/trace/blktrace.c
74650+++ b/kernel/trace/blktrace.c
74651@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74652 struct blk_trace *bt = filp->private_data;
74653 char buf[16];
74654
74655- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74656+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74657
74658 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74659 }
74660@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74661 return 1;
74662
74663 bt = buf->chan->private_data;
74664- atomic_inc(&bt->dropped);
74665+ atomic_inc_unchecked(&bt->dropped);
74666 return 0;
74667 }
74668
74669@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74670
74671 bt->dir = dir;
74672 bt->dev = dev;
74673- atomic_set(&bt->dropped, 0);
74674+ atomic_set_unchecked(&bt->dropped, 0);
74675
74676 ret = -EIO;
74677 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74678diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74679index 4872937..c794d40 100644
74680--- a/kernel/trace/ftrace.c
74681+++ b/kernel/trace/ftrace.c
74682@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74683
74684 ip = rec->ip;
74685
74686+ ret = ftrace_arch_code_modify_prepare();
74687+ FTRACE_WARN_ON(ret);
74688+ if (ret)
74689+ return 0;
74690+
74691 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74692+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74693 if (ret) {
74694 ftrace_bug(ret, ip);
74695 rec->flags |= FTRACE_FL_FAILED;
74696- return 0;
74697 }
74698- return 1;
74699+ return ret ? 0 : 1;
74700 }
74701
74702 /*
74703diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74704index e749a05..19c6e94 100644
74705--- a/kernel/trace/ring_buffer.c
74706+++ b/kernel/trace/ring_buffer.c
74707@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(struct list_head *list)
74708 * the reader page). But if the next page is a header page,
74709 * its flags will be non zero.
74710 */
74711-static int inline
74712+static inline int
74713 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74714 struct buffer_page *page, struct list_head *list)
74715 {
74716diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74717index a2a2d1f..7f32b09 100644
74718--- a/kernel/trace/trace.c
74719+++ b/kernel/trace/trace.c
74720@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
74721 size_t rem;
74722 unsigned int i;
74723
74724+ pax_track_stack();
74725+
74726 /* copy the tracer to avoid using a global lock all around */
74727 mutex_lock(&trace_types_lock);
74728 if (unlikely(old_tracer != current_trace && current_trace)) {
74729@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
74730 int entries, size, i;
74731 size_t ret;
74732
74733+ pax_track_stack();
74734+
74735 if (*ppos & (PAGE_SIZE - 1)) {
74736 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
74737 return -EINVAL;
74738@@ -3816,10 +3820,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74739 };
74740 #endif
74741
74742-static struct dentry *d_tracer;
74743-
74744 struct dentry *tracing_init_dentry(void)
74745 {
74746+ static struct dentry *d_tracer;
74747 static int once;
74748
74749 if (d_tracer)
74750@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
74751 return d_tracer;
74752 }
74753
74754-static struct dentry *d_percpu;
74755-
74756 struct dentry *tracing_dentry_percpu(void)
74757 {
74758+ static struct dentry *d_percpu;
74759 static int once;
74760 struct dentry *d_tracer;
74761
74762diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74763index d128f65..f37b4af 100644
74764--- a/kernel/trace/trace_events.c
74765+++ b/kernel/trace/trace_events.c
74766@@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list);
74767 * Modules must own their file_operations to keep up with
74768 * reference counting.
74769 */
74770+
74771 struct ftrace_module_file_ops {
74772 struct list_head list;
74773 struct module *mod;
74774- struct file_operations id;
74775- struct file_operations enable;
74776- struct file_operations format;
74777- struct file_operations filter;
74778 };
74779
74780 static void remove_subsystem_dir(const char *name)
74781@@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod)
74782
74783 file_ops->mod = mod;
74784
74785- file_ops->id = ftrace_event_id_fops;
74786- file_ops->id.owner = mod;
74787-
74788- file_ops->enable = ftrace_enable_fops;
74789- file_ops->enable.owner = mod;
74790-
74791- file_ops->filter = ftrace_event_filter_fops;
74792- file_ops->filter.owner = mod;
74793-
74794- file_ops->format = ftrace_event_format_fops;
74795- file_ops->format.owner = mod;
74796+ pax_open_kernel();
74797+ *(void **)&mod->trace_id.owner = mod;
74798+ *(void **)&mod->trace_enable.owner = mod;
74799+ *(void **)&mod->trace_filter.owner = mod;
74800+ *(void **)&mod->trace_format.owner = mod;
74801+ pax_close_kernel();
74802
74803 list_add(&file_ops->list, &ftrace_module_file_list);
74804
74805@@ -1063,8 +1055,8 @@ static void trace_module_add_events(struct module *mod)
74806 call->mod = mod;
74807 list_add(&call->list, &ftrace_events);
74808 event_create_dir(call, d_events,
74809- &file_ops->id, &file_ops->enable,
74810- &file_ops->filter, &file_ops->format);
74811+ &mod->trace_id, &mod->trace_enable,
74812+ &mod->trace_filter, &mod->trace_format);
74813 }
74814 }
74815
74816diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74817index 0acd834..b800b56 100644
74818--- a/kernel/trace/trace_mmiotrace.c
74819+++ b/kernel/trace/trace_mmiotrace.c
74820@@ -23,7 +23,7 @@ struct header_iter {
74821 static struct trace_array *mmio_trace_array;
74822 static bool overrun_detected;
74823 static unsigned long prev_overruns;
74824-static atomic_t dropped_count;
74825+static atomic_unchecked_t dropped_count;
74826
74827 static void mmio_reset_data(struct trace_array *tr)
74828 {
74829@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iterator *iter)
74830
74831 static unsigned long count_overruns(struct trace_iterator *iter)
74832 {
74833- unsigned long cnt = atomic_xchg(&dropped_count, 0);
74834+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74835 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74836
74837 if (over > prev_overruns)
74838@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74839 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74840 sizeof(*entry), 0, pc);
74841 if (!event) {
74842- atomic_inc(&dropped_count);
74843+ atomic_inc_unchecked(&dropped_count);
74844 return;
74845 }
74846 entry = ring_buffer_event_data(event);
74847@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74848 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74849 sizeof(*entry), 0, pc);
74850 if (!event) {
74851- atomic_inc(&dropped_count);
74852+ atomic_inc_unchecked(&dropped_count);
74853 return;
74854 }
74855 entry = ring_buffer_event_data(event);
74856diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74857index b6c12c6..41fdc53 100644
74858--- a/kernel/trace/trace_output.c
74859+++ b/kernel/trace/trace_output.c
74860@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
74861 return 0;
74862 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74863 if (!IS_ERR(p)) {
74864- p = mangle_path(s->buffer + s->len, p, "\n");
74865+ p = mangle_path(s->buffer + s->len, p, "\n\\");
74866 if (p) {
74867 s->len = p - s->buffer;
74868 return 1;
74869diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74870index 8504ac7..ecf0adb 100644
74871--- a/kernel/trace/trace_stack.c
74872+++ b/kernel/trace/trace_stack.c
74873@@ -50,7 +50,7 @@ static inline void check_stack(void)
74874 return;
74875
74876 /* we do not handle interrupt stacks yet */
74877- if (!object_is_on_stack(&this_size))
74878+ if (!object_starts_on_stack(&this_size))
74879 return;
74880
74881 local_irq_save(flags);
74882diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
74883index 40cafb0..d5ead43 100644
74884--- a/kernel/trace/trace_workqueue.c
74885+++ b/kernel/trace/trace_workqueue.c
74886@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
74887 int cpu;
74888 pid_t pid;
74889 /* Can be inserted from interrupt or user context, need to be atomic */
74890- atomic_t inserted;
74891+ atomic_unchecked_t inserted;
74892 /*
74893 * Don't need to be atomic, works are serialized in a single workqueue thread
74894 * on a single CPU.
74895@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_struct *wq_thread,
74896 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
74897 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
74898 if (node->pid == wq_thread->pid) {
74899- atomic_inc(&node->inserted);
74900+ atomic_inc_unchecked(&node->inserted);
74901 goto found;
74902 }
74903 }
74904@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
74905 tsk = get_pid_task(pid, PIDTYPE_PID);
74906 if (tsk) {
74907 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
74908- atomic_read(&cws->inserted), cws->executed,
74909+ atomic_read_unchecked(&cws->inserted), cws->executed,
74910 tsk->comm);
74911 put_task_struct(tsk);
74912 }
74913diff --git a/kernel/user.c b/kernel/user.c
74914index 1b91701..8795237 100644
74915--- a/kernel/user.c
74916+++ b/kernel/user.c
74917@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
74918 spin_lock_irq(&uidhash_lock);
74919 up = uid_hash_find(uid, hashent);
74920 if (up) {
74921+ put_user_ns(ns);
74922 key_put(new->uid_keyring);
74923 key_put(new->session_keyring);
74924 kmem_cache_free(uid_cachep, new);
74925diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74926index 234ceb1..ad74049 100644
74927--- a/lib/Kconfig.debug
74928+++ b/lib/Kconfig.debug
74929@@ -905,7 +905,7 @@ config LATENCYTOP
74930 select STACKTRACE
74931 select SCHEDSTATS
74932 select SCHED_DEBUG
74933- depends on HAVE_LATENCYTOP_SUPPORT
74934+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
74935 help
74936 Enable this option if you want to use the LatencyTOP tool
74937 to find out which userspace is blocking on what kernel operations.
74938diff --git a/lib/bitmap.c b/lib/bitmap.c
74939index 7025658..8d14cab 100644
74940--- a/lib/bitmap.c
74941+++ b/lib/bitmap.c
74942@@ -341,7 +341,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74943 {
74944 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74945 u32 chunk;
74946- const char __user *ubuf = buf;
74947+ const char __user *ubuf = (const char __force_user *)buf;
74948
74949 bitmap_zero(maskp, nmaskbits);
74950
74951@@ -426,7 +426,7 @@ int bitmap_parse_user(const char __user *ubuf,
74952 {
74953 if (!access_ok(VERIFY_READ, ubuf, ulen))
74954 return -EFAULT;
74955- return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
74956+ return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
74957 }
74958 EXPORT_SYMBOL(bitmap_parse_user);
74959
74960diff --git a/lib/bug.c b/lib/bug.c
74961index 300e41a..2779eb0 100644
74962--- a/lib/bug.c
74963+++ b/lib/bug.c
74964@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74965 return BUG_TRAP_TYPE_NONE;
74966
74967 bug = find_bug(bugaddr);
74968+ if (!bug)
74969+ return BUG_TRAP_TYPE_NONE;
74970
74971 printk(KERN_EMERG "------------[ cut here ]------------\n");
74972
74973diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74974index 2b413db..e21d207 100644
74975--- a/lib/debugobjects.c
74976+++ b/lib/debugobjects.c
74977@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74978 if (limit > 4)
74979 return;
74980
74981- is_on_stack = object_is_on_stack(addr);
74982+ is_on_stack = object_starts_on_stack(addr);
74983 if (is_on_stack == onstack)
74984 return;
74985
74986diff --git a/lib/devres.c b/lib/devres.c
74987index 72c8909..7543868 100644
74988--- a/lib/devres.c
74989+++ b/lib/devres.c
74990@@ -80,7 +80,7 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
74991 {
74992 iounmap(addr);
74993 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74994- (void *)addr));
74995+ (void __force *)addr));
74996 }
74997 EXPORT_SYMBOL(devm_iounmap);
74998
74999@@ -140,7 +140,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
75000 {
75001 ioport_unmap(addr);
75002 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
75003- devm_ioport_map_match, (void *)addr));
75004+ devm_ioport_map_match, (void __force *)addr));
75005 }
75006 EXPORT_SYMBOL(devm_ioport_unmap);
75007
75008diff --git a/lib/dma-debug.c b/lib/dma-debug.c
75009index 084e879..0674448 100644
75010--- a/lib/dma-debug.c
75011+++ b/lib/dma-debug.c
75012@@ -861,7 +861,7 @@ out:
75013
75014 static void check_for_stack(struct device *dev, void *addr)
75015 {
75016- if (object_is_on_stack(addr))
75017+ if (object_starts_on_stack(addr))
75018 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
75019 "stack [addr=%p]\n", addr);
75020 }
75021diff --git a/lib/idr.c b/lib/idr.c
75022index eda7ba3..915dfae 100644
75023--- a/lib/idr.c
75024+++ b/lib/idr.c
75025@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
75026 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
75027
75028 /* if already at the top layer, we need to grow */
75029- if (id >= 1 << (idp->layers * IDR_BITS)) {
75030+ if (id >= (1 << (idp->layers * IDR_BITS))) {
75031 *starting_id = id;
75032 return IDR_NEED_TO_GROW;
75033 }
75034diff --git a/lib/inflate.c b/lib/inflate.c
75035index d102559..4215f31 100644
75036--- a/lib/inflate.c
75037+++ b/lib/inflate.c
75038@@ -266,7 +266,7 @@ static void free(void *where)
75039 malloc_ptr = free_mem_ptr;
75040 }
75041 #else
75042-#define malloc(a) kmalloc(a, GFP_KERNEL)
75043+#define malloc(a) kmalloc((a), GFP_KERNEL)
75044 #define free(a) kfree(a)
75045 #endif
75046
75047diff --git a/lib/kobject.c b/lib/kobject.c
75048index b512b74..8115eb1 100644
75049--- a/lib/kobject.c
75050+++ b/lib/kobject.c
75051@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
75052 return ret;
75053 }
75054
75055-struct sysfs_ops kobj_sysfs_ops = {
75056+const struct sysfs_ops kobj_sysfs_ops = {
75057 .show = kobj_attr_show,
75058 .store = kobj_attr_store,
75059 };
75060@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
75061 * If the kset was not able to be created, NULL will be returned.
75062 */
75063 static struct kset *kset_create(const char *name,
75064- struct kset_uevent_ops *uevent_ops,
75065+ const struct kset_uevent_ops *uevent_ops,
75066 struct kobject *parent_kobj)
75067 {
75068 struct kset *kset;
75069@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
75070 * If the kset was not able to be created, NULL will be returned.
75071 */
75072 struct kset *kset_create_and_add(const char *name,
75073- struct kset_uevent_ops *uevent_ops,
75074+ const struct kset_uevent_ops *uevent_ops,
75075 struct kobject *parent_kobj)
75076 {
75077 struct kset *kset;
75078diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
75079index 507b821..0bf8ed0 100644
75080--- a/lib/kobject_uevent.c
75081+++ b/lib/kobject_uevent.c
75082@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
75083 const char *subsystem;
75084 struct kobject *top_kobj;
75085 struct kset *kset;
75086- struct kset_uevent_ops *uevent_ops;
75087+ const struct kset_uevent_ops *uevent_ops;
75088 u64 seq;
75089 int i = 0;
75090 int retval = 0;
75091diff --git a/lib/kref.c b/lib/kref.c
75092index 9ecd6e8..12c94c1 100644
75093--- a/lib/kref.c
75094+++ b/lib/kref.c
75095@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
75096 */
75097 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
75098 {
75099- WARN_ON(release == NULL);
75100+ BUG_ON(release == NULL);
75101 WARN_ON(release == (void (*)(struct kref *))kfree);
75102
75103 if (atomic_dec_and_test(&kref->refcount)) {
75104diff --git a/lib/parser.c b/lib/parser.c
75105index b00d020..1b34325 100644
75106--- a/lib/parser.c
75107+++ b/lib/parser.c
75108@@ -126,7 +126,7 @@ static int match_number(substring_t *s, int *result, int base)
75109 char *buf;
75110 int ret;
75111
75112- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
75113+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
75114 if (!buf)
75115 return -ENOMEM;
75116 memcpy(buf, s->from, s->to - s->from);
75117diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75118index 92cdd99..a8149d7 100644
75119--- a/lib/radix-tree.c
75120+++ b/lib/radix-tree.c
75121@@ -81,7 +81,7 @@ struct radix_tree_preload {
75122 int nr;
75123 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
75124 };
75125-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75126+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75127
75128 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
75129 {
75130diff --git a/lib/random32.c b/lib/random32.c
75131index 217d5c4..45aba8a 100644
75132--- a/lib/random32.c
75133+++ b/lib/random32.c
75134@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *state)
75135 */
75136 static inline u32 __seed(u32 x, u32 m)
75137 {
75138- return (x < m) ? x + m : x;
75139+ return (x <= m) ? x + m + 1 : x;
75140 }
75141
75142 /**
75143diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75144index 33bed5e..1477e46 100644
75145--- a/lib/vsprintf.c
75146+++ b/lib/vsprintf.c
75147@@ -16,6 +16,9 @@
75148 * - scnprintf and vscnprintf
75149 */
75150
75151+#ifdef CONFIG_GRKERNSEC_HIDESYM
75152+#define __INCLUDED_BY_HIDESYM 1
75153+#endif
75154 #include <stdarg.h>
75155 #include <linux/module.h>
75156 #include <linux/types.h>
75157@@ -546,12 +549,12 @@ static char *number(char *buf, char *end, unsigned long long num,
75158 return buf;
75159 }
75160
75161-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
75162+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
75163 {
75164 int len, i;
75165
75166 if ((unsigned long)s < PAGE_SIZE)
75167- s = "<NULL>";
75168+ s = "(null)";
75169
75170 len = strnlen(s, spec.precision);
75171
75172@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, char *end, void *ptr,
75173 unsigned long value = (unsigned long) ptr;
75174 #ifdef CONFIG_KALLSYMS
75175 char sym[KSYM_SYMBOL_LEN];
75176- if (ext != 'f' && ext != 's')
75177+ if (ext != 'f' && ext != 's' && ext != 'a')
75178 sprint_symbol(sym, value);
75179 else
75180 kallsyms_lookup(value, NULL, NULL, NULL, sym);
75181@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
75182 * - 'f' For simple symbolic function names without offset
75183 * - 'S' For symbolic direct pointers with offset
75184 * - 's' For symbolic direct pointers without offset
75185+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75186+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75187 * - 'R' For a struct resource pointer, it prints the range of
75188 * addresses (not the name nor the flags)
75189 * - 'M' For a 6-byte MAC address, it prints the address in the
75190@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75191 struct printf_spec spec)
75192 {
75193 if (!ptr)
75194- return string(buf, end, "(null)", spec);
75195+ return string(buf, end, "(nil)", spec);
75196
75197 switch (*fmt) {
75198 case 'F':
75199@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75200 case 's':
75201 /* Fallthrough */
75202 case 'S':
75203+#ifdef CONFIG_GRKERNSEC_HIDESYM
75204+ break;
75205+#else
75206+ return symbol_string(buf, end, ptr, spec, *fmt);
75207+#endif
75208+ case 'a':
75209+ /* Fallthrough */
75210+ case 'A':
75211 return symbol_string(buf, end, ptr, spec, *fmt);
75212 case 'R':
75213 return resource_string(buf, end, ptr, spec);
75214@@ -1445,7 +1458,7 @@ do { \
75215 size_t len;
75216 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
75217 || (unsigned long)save_str < PAGE_SIZE)
75218- save_str = "<NULL>";
75219+ save_str = "(null)";
75220 len = strlen(save_str);
75221 if (str + len + 1 < end)
75222 memcpy(str, save_str, len + 1);
75223@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75224 typeof(type) value; \
75225 if (sizeof(type) == 8) { \
75226 args = PTR_ALIGN(args, sizeof(u32)); \
75227- *(u32 *)&value = *(u32 *)args; \
75228- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75229+ *(u32 *)&value = *(const u32 *)args; \
75230+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75231 } else { \
75232 args = PTR_ALIGN(args, sizeof(type)); \
75233- value = *(typeof(type) *)args; \
75234+ value = *(const typeof(type) *)args; \
75235 } \
75236 args += sizeof(type); \
75237 value; \
75238@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75239 const char *str_arg = args;
75240 size_t len = strlen(str_arg);
75241 args += len + 1;
75242- str = string(str, end, (char *)str_arg, spec);
75243+ str = string(str, end, str_arg, spec);
75244 break;
75245 }
75246
75247diff --git a/localversion-grsec b/localversion-grsec
75248new file mode 100644
75249index 0000000..7cd6065
75250--- /dev/null
75251+++ b/localversion-grsec
75252@@ -0,0 +1 @@
75253+-grsec
75254diff --git a/mm/Kconfig b/mm/Kconfig
75255index 2c19c0b..f3c3f83 100644
75256--- a/mm/Kconfig
75257+++ b/mm/Kconfig
75258@@ -228,7 +228,7 @@ config KSM
75259 config DEFAULT_MMAP_MIN_ADDR
75260 int "Low address space to protect from user allocation"
75261 depends on MMU
75262- default 4096
75263+ default 65536
75264 help
75265 This is the portion of low virtual memory which should be protected
75266 from userspace allocation. Keeping a user from writing to low pages
75267diff --git a/mm/backing-dev.c b/mm/backing-dev.c
75268index 67a33a5..094dcf1 100644
75269--- a/mm/backing-dev.c
75270+++ b/mm/backing-dev.c
75271@@ -272,7 +272,7 @@ static void bdi_task_init(struct backing_dev_info *bdi,
75272 list_add_tail_rcu(&wb->list, &bdi->wb_list);
75273 spin_unlock(&bdi->wb_lock);
75274
75275- tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
75276+ tsk->flags |= PF_SWAPWRITE;
75277 set_freezable();
75278
75279 /*
75280@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rcu_head *head)
75281 * Add the default flusher task that gets created for any bdi
75282 * that has dirty data pending writeout
75283 */
75284-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75285+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75286 {
75287 if (!bdi_cap_writeback_dirty(bdi))
75288 return;
75289diff --git a/mm/filemap.c b/mm/filemap.c
75290index 9e0826e..4ee8f13 100644
75291--- a/mm/filemap.c
75292+++ b/mm/filemap.c
75293@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75294 struct address_space *mapping = file->f_mapping;
75295
75296 if (!mapping->a_ops->readpage)
75297- return -ENOEXEC;
75298+ return -ENODEV;
75299 file_accessed(file);
75300 vma->vm_ops = &generic_file_vm_ops;
75301 vma->vm_flags |= VM_CAN_NONLINEAR;
75302@@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75303 *pos = i_size_read(inode);
75304
75305 if (limit != RLIM_INFINITY) {
75306+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75307 if (*pos >= limit) {
75308 send_sig(SIGXFSZ, current, 0);
75309 return -EFBIG;
75310diff --git a/mm/fremap.c b/mm/fremap.c
75311index b6ec85a..a24ac22 100644
75312--- a/mm/fremap.c
75313+++ b/mm/fremap.c
75314@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75315 retry:
75316 vma = find_vma(mm, start);
75317
75318+#ifdef CONFIG_PAX_SEGMEXEC
75319+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75320+ goto out;
75321+#endif
75322+
75323 /*
75324 * Make sure the vma is shared, that it supports prefaulting,
75325 * and that the remapped range is valid and fully within
75326@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75327 /*
75328 * drop PG_Mlocked flag for over-mapped range
75329 */
75330- unsigned int saved_flags = vma->vm_flags;
75331+ unsigned long saved_flags = vma->vm_flags;
75332 munlock_vma_pages_range(vma, start, start + size);
75333 vma->vm_flags = saved_flags;
75334 }
75335diff --git a/mm/highmem.c b/mm/highmem.c
75336index 9c1e627..5ca9447 100644
75337--- a/mm/highmem.c
75338+++ b/mm/highmem.c
75339@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
75340 * So no dangers, even with speculative execution.
75341 */
75342 page = pte_page(pkmap_page_table[i]);
75343+ pax_open_kernel();
75344 pte_clear(&init_mm, (unsigned long)page_address(page),
75345 &pkmap_page_table[i]);
75346-
75347+ pax_close_kernel();
75348 set_page_address(page, NULL);
75349 need_flush = 1;
75350 }
75351@@ -177,9 +178,11 @@ start:
75352 }
75353 }
75354 vaddr = PKMAP_ADDR(last_pkmap_nr);
75355+
75356+ pax_open_kernel();
75357 set_pte_at(&init_mm, vaddr,
75358 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75359-
75360+ pax_close_kernel();
75361 pkmap_count[last_pkmap_nr] = 1;
75362 set_page_address(page, (void *)vaddr);
75363
75364diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75365index 5e1e508..9f0ebad 100644
75366--- a/mm/hugetlb.c
75367+++ b/mm/hugetlb.c
75368@@ -1933,6 +1933,26 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75369 return 1;
75370 }
75371
75372+#ifdef CONFIG_PAX_SEGMEXEC
75373+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75374+{
75375+ struct mm_struct *mm = vma->vm_mm;
75376+ struct vm_area_struct *vma_m;
75377+ unsigned long address_m;
75378+ pte_t *ptep_m;
75379+
75380+ vma_m = pax_find_mirror_vma(vma);
75381+ if (!vma_m)
75382+ return;
75383+
75384+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75385+ address_m = address + SEGMEXEC_TASK_SIZE;
75386+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75387+ get_page(page_m);
75388+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75389+}
75390+#endif
75391+
75392 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
75393 unsigned long address, pte_t *ptep, pte_t pte,
75394 struct page *pagecache_page)
75395@@ -2004,6 +2024,11 @@ retry_avoidcopy:
75396 huge_ptep_clear_flush(vma, address, ptep);
75397 set_huge_pte_at(mm, address, ptep,
75398 make_huge_pte(vma, new_page, 1));
75399+
75400+#ifdef CONFIG_PAX_SEGMEXEC
75401+ pax_mirror_huge_pte(vma, address, new_page);
75402+#endif
75403+
75404 /* Make the old page be freed below */
75405 new_page = old_page;
75406 }
75407@@ -2135,6 +2160,10 @@ retry:
75408 && (vma->vm_flags & VM_SHARED)));
75409 set_huge_pte_at(mm, address, ptep, new_pte);
75410
75411+#ifdef CONFIG_PAX_SEGMEXEC
75412+ pax_mirror_huge_pte(vma, address, page);
75413+#endif
75414+
75415 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75416 /* Optimization, do the COW without a second fault */
75417 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75418@@ -2163,6 +2192,28 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75419 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75420 struct hstate *h = hstate_vma(vma);
75421
75422+#ifdef CONFIG_PAX_SEGMEXEC
75423+ struct vm_area_struct *vma_m;
75424+
75425+ vma_m = pax_find_mirror_vma(vma);
75426+ if (vma_m) {
75427+ unsigned long address_m;
75428+
75429+ if (vma->vm_start > vma_m->vm_start) {
75430+ address_m = address;
75431+ address -= SEGMEXEC_TASK_SIZE;
75432+ vma = vma_m;
75433+ h = hstate_vma(vma);
75434+ } else
75435+ address_m = address + SEGMEXEC_TASK_SIZE;
75436+
75437+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75438+ return VM_FAULT_OOM;
75439+ address_m &= HPAGE_MASK;
75440+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75441+ }
75442+#endif
75443+
75444 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75445 if (!ptep)
75446 return VM_FAULT_OOM;
75447diff --git a/mm/internal.h b/mm/internal.h
75448index f03e8e2..7354343 100644
75449--- a/mm/internal.h
75450+++ b/mm/internal.h
75451@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page *page);
75452 * in mm/page_alloc.c
75453 */
75454 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75455+extern void free_compound_page(struct page *page);
75456 extern void prep_compound_page(struct page *page, unsigned long order);
75457
75458
75459diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75460index c346660..b47382f 100644
75461--- a/mm/kmemleak.c
75462+++ b/mm/kmemleak.c
75463@@ -358,7 +358,7 @@ static void print_unreferenced(struct seq_file *seq,
75464
75465 for (i = 0; i < object->trace_len; i++) {
75466 void *ptr = (void *)object->trace[i];
75467- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75468+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
75469 }
75470 }
75471
75472diff --git a/mm/maccess.c b/mm/maccess.c
75473index 9073695..1127f348 100644
75474--- a/mm/maccess.c
75475+++ b/mm/maccess.c
75476@@ -14,7 +14,7 @@
75477 * Safely read from address @src to the buffer at @dst. If a kernel fault
75478 * happens, handle that and return -EFAULT.
75479 */
75480-long probe_kernel_read(void *dst, void *src, size_t size)
75481+long probe_kernel_read(void *dst, const void *src, size_t size)
75482 {
75483 long ret;
75484 mm_segment_t old_fs = get_fs();
75485@@ -22,7 +22,7 @@ long probe_kernel_read(void *dst, void *src, size_t size)
75486 set_fs(KERNEL_DS);
75487 pagefault_disable();
75488 ret = __copy_from_user_inatomic(dst,
75489- (__force const void __user *)src, size);
75490+ (const void __force_user *)src, size);
75491 pagefault_enable();
75492 set_fs(old_fs);
75493
75494@@ -39,14 +39,14 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
75495 * Safely write to address @dst from the buffer at @src. If a kernel fault
75496 * happens, handle that and return -EFAULT.
75497 */
75498-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
75499+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
75500 {
75501 long ret;
75502 mm_segment_t old_fs = get_fs();
75503
75504 set_fs(KERNEL_DS);
75505 pagefault_disable();
75506- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75507+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75508 pagefault_enable();
75509 set_fs(old_fs);
75510
75511diff --git a/mm/madvise.c b/mm/madvise.c
75512index 35b1479..499f7d4 100644
75513--- a/mm/madvise.c
75514+++ b/mm/madvise.c
75515@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75516 pgoff_t pgoff;
75517 unsigned long new_flags = vma->vm_flags;
75518
75519+#ifdef CONFIG_PAX_SEGMEXEC
75520+ struct vm_area_struct *vma_m;
75521+#endif
75522+
75523 switch (behavior) {
75524 case MADV_NORMAL:
75525 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75526@@ -103,6 +107,13 @@ success:
75527 /*
75528 * vm_flags is protected by the mmap_sem held in write mode.
75529 */
75530+
75531+#ifdef CONFIG_PAX_SEGMEXEC
75532+ vma_m = pax_find_mirror_vma(vma);
75533+ if (vma_m)
75534+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75535+#endif
75536+
75537 vma->vm_flags = new_flags;
75538
75539 out:
75540@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75541 struct vm_area_struct ** prev,
75542 unsigned long start, unsigned long end)
75543 {
75544+
75545+#ifdef CONFIG_PAX_SEGMEXEC
75546+ struct vm_area_struct *vma_m;
75547+#endif
75548+
75549 *prev = vma;
75550 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75551 return -EINVAL;
75552@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75553 zap_page_range(vma, start, end - start, &details);
75554 } else
75555 zap_page_range(vma, start, end - start, NULL);
75556+
75557+#ifdef CONFIG_PAX_SEGMEXEC
75558+ vma_m = pax_find_mirror_vma(vma);
75559+ if (vma_m) {
75560+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75561+ struct zap_details details = {
75562+ .nonlinear_vma = vma_m,
75563+ .last_index = ULONG_MAX,
75564+ };
75565+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75566+ } else
75567+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75568+ }
75569+#endif
75570+
75571 return 0;
75572 }
75573
75574@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75575 if (end < start)
75576 goto out;
75577
75578+#ifdef CONFIG_PAX_SEGMEXEC
75579+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75580+ if (end > SEGMEXEC_TASK_SIZE)
75581+ goto out;
75582+ } else
75583+#endif
75584+
75585+ if (end > TASK_SIZE)
75586+ goto out;
75587+
75588 error = 0;
75589 if (end == start)
75590 goto out;
75591diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75592index 8aeba53..b4a4198 100644
75593--- a/mm/memory-failure.c
75594+++ b/mm/memory-failure.c
75595@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75596
75597 int sysctl_memory_failure_recovery __read_mostly = 1;
75598
75599-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75600+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75601
75602 /*
75603 * Send all the processes who have the page mapped an ``action optional''
75604@@ -64,7 +64,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
75605 si.si_signo = SIGBUS;
75606 si.si_errno = 0;
75607 si.si_code = BUS_MCEERR_AO;
75608- si.si_addr = (void *)addr;
75609+ si.si_addr = (void __user *)addr;
75610 #ifdef __ARCH_SI_TRAPNO
75611 si.si_trapno = trapno;
75612 #endif
75613@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref)
75614 return 0;
75615 }
75616
75617- atomic_long_add(1, &mce_bad_pages);
75618+ atomic_long_add_unchecked(1, &mce_bad_pages);
75619
75620 /*
75621 * We need/can do nothing about count=0 pages.
75622diff --git a/mm/memory.c b/mm/memory.c
75623index 6c836d3..48f3264 100644
75624--- a/mm/memory.c
75625+++ b/mm/memory.c
75626@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75627 return;
75628
75629 pmd = pmd_offset(pud, start);
75630+
75631+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75632 pud_clear(pud);
75633 pmd_free_tlb(tlb, pmd, start);
75634+#endif
75635+
75636 }
75637
75638 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75639@@ -219,9 +223,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75640 if (end - 1 > ceiling - 1)
75641 return;
75642
75643+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75644 pud = pud_offset(pgd, start);
75645 pgd_clear(pgd);
75646 pud_free_tlb(tlb, pud, start);
75647+#endif
75648+
75649 }
75650
75651 /*
75652@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75653 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
75654 i = 0;
75655
75656- do {
75657+ while (nr_pages) {
75658 struct vm_area_struct *vma;
75659
75660- vma = find_extend_vma(mm, start);
75661+ vma = find_vma(mm, start);
75662 if (!vma && in_gate_area(tsk, start)) {
75663 unsigned long pg = start & PAGE_MASK;
75664 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
75665@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75666 continue;
75667 }
75668
75669- if (!vma ||
75670+ if (!vma || start < vma->vm_start ||
75671 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75672 !(vm_flags & vma->vm_flags))
75673 return i ? : -EFAULT;
75674@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75675 start += PAGE_SIZE;
75676 nr_pages--;
75677 } while (nr_pages && start < vma->vm_end);
75678- } while (nr_pages);
75679+ }
75680 return i;
75681 }
75682
75683@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75684 page_add_file_rmap(page);
75685 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75686
75687+#ifdef CONFIG_PAX_SEGMEXEC
75688+ pax_mirror_file_pte(vma, addr, page, ptl);
75689+#endif
75690+
75691 retval = 0;
75692 pte_unmap_unlock(pte, ptl);
75693 return retval;
75694@@ -1560,10 +1571,22 @@ out:
75695 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75696 struct page *page)
75697 {
75698+
75699+#ifdef CONFIG_PAX_SEGMEXEC
75700+ struct vm_area_struct *vma_m;
75701+#endif
75702+
75703 if (addr < vma->vm_start || addr >= vma->vm_end)
75704 return -EFAULT;
75705 if (!page_count(page))
75706 return -EINVAL;
75707+
75708+#ifdef CONFIG_PAX_SEGMEXEC
75709+ vma_m = pax_find_mirror_vma(vma);
75710+ if (vma_m)
75711+ vma_m->vm_flags |= VM_INSERTPAGE;
75712+#endif
75713+
75714 vma->vm_flags |= VM_INSERTPAGE;
75715 return insert_page(vma, addr, page, vma->vm_page_prot);
75716 }
75717@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75718 unsigned long pfn)
75719 {
75720 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75721+ BUG_ON(vma->vm_mirror);
75722
75723 if (addr < vma->vm_start || addr >= vma->vm_end)
75724 return -EFAULT;
75725@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75726 copy_user_highpage(dst, src, va, vma);
75727 }
75728
75729+#ifdef CONFIG_PAX_SEGMEXEC
75730+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75731+{
75732+ struct mm_struct *mm = vma->vm_mm;
75733+ spinlock_t *ptl;
75734+ pte_t *pte, entry;
75735+
75736+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75737+ entry = *pte;
75738+ if (!pte_present(entry)) {
75739+ if (!pte_none(entry)) {
75740+ BUG_ON(pte_file(entry));
75741+ free_swap_and_cache(pte_to_swp_entry(entry));
75742+ pte_clear_not_present_full(mm, address, pte, 0);
75743+ }
75744+ } else {
75745+ struct page *page;
75746+
75747+ flush_cache_page(vma, address, pte_pfn(entry));
75748+ entry = ptep_clear_flush(vma, address, pte);
75749+ BUG_ON(pte_dirty(entry));
75750+ page = vm_normal_page(vma, address, entry);
75751+ if (page) {
75752+ update_hiwater_rss(mm);
75753+ if (PageAnon(page))
75754+ dec_mm_counter(mm, anon_rss);
75755+ else
75756+ dec_mm_counter(mm, file_rss);
75757+ page_remove_rmap(page);
75758+ page_cache_release(page);
75759+ }
75760+ }
75761+ pte_unmap_unlock(pte, ptl);
75762+}
75763+
75764+/* PaX: if vma is mirrored, synchronize the mirror's PTE
75765+ *
75766+ * the ptl of the lower mapped page is held on entry and is not released on exit
75767+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75768+ */
75769+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75770+{
75771+ struct mm_struct *mm = vma->vm_mm;
75772+ unsigned long address_m;
75773+ spinlock_t *ptl_m;
75774+ struct vm_area_struct *vma_m;
75775+ pmd_t *pmd_m;
75776+ pte_t *pte_m, entry_m;
75777+
75778+ BUG_ON(!page_m || !PageAnon(page_m));
75779+
75780+ vma_m = pax_find_mirror_vma(vma);
75781+ if (!vma_m)
75782+ return;
75783+
75784+ BUG_ON(!PageLocked(page_m));
75785+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75786+ address_m = address + SEGMEXEC_TASK_SIZE;
75787+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75788+ pte_m = pte_offset_map_nested(pmd_m, address_m);
75789+ ptl_m = pte_lockptr(mm, pmd_m);
75790+ if (ptl != ptl_m) {
75791+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75792+ if (!pte_none(*pte_m))
75793+ goto out;
75794+ }
75795+
75796+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75797+ page_cache_get(page_m);
75798+ page_add_anon_rmap(page_m, vma_m, address_m);
75799+ inc_mm_counter(mm, anon_rss);
75800+ set_pte_at(mm, address_m, pte_m, entry_m);
75801+ update_mmu_cache(vma_m, address_m, entry_m);
75802+out:
75803+ if (ptl != ptl_m)
75804+ spin_unlock(ptl_m);
75805+ pte_unmap_nested(pte_m);
75806+ unlock_page(page_m);
75807+}
75808+
75809+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75810+{
75811+ struct mm_struct *mm = vma->vm_mm;
75812+ unsigned long address_m;
75813+ spinlock_t *ptl_m;
75814+ struct vm_area_struct *vma_m;
75815+ pmd_t *pmd_m;
75816+ pte_t *pte_m, entry_m;
75817+
75818+ BUG_ON(!page_m || PageAnon(page_m));
75819+
75820+ vma_m = pax_find_mirror_vma(vma);
75821+ if (!vma_m)
75822+ return;
75823+
75824+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75825+ address_m = address + SEGMEXEC_TASK_SIZE;
75826+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75827+ pte_m = pte_offset_map_nested(pmd_m, address_m);
75828+ ptl_m = pte_lockptr(mm, pmd_m);
75829+ if (ptl != ptl_m) {
75830+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75831+ if (!pte_none(*pte_m))
75832+ goto out;
75833+ }
75834+
75835+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75836+ page_cache_get(page_m);
75837+ page_add_file_rmap(page_m);
75838+ inc_mm_counter(mm, file_rss);
75839+ set_pte_at(mm, address_m, pte_m, entry_m);
75840+ update_mmu_cache(vma_m, address_m, entry_m);
75841+out:
75842+ if (ptl != ptl_m)
75843+ spin_unlock(ptl_m);
75844+ pte_unmap_nested(pte_m);
75845+}
75846+
75847+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75848+{
75849+ struct mm_struct *mm = vma->vm_mm;
75850+ unsigned long address_m;
75851+ spinlock_t *ptl_m;
75852+ struct vm_area_struct *vma_m;
75853+ pmd_t *pmd_m;
75854+ pte_t *pte_m, entry_m;
75855+
75856+ vma_m = pax_find_mirror_vma(vma);
75857+ if (!vma_m)
75858+ return;
75859+
75860+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75861+ address_m = address + SEGMEXEC_TASK_SIZE;
75862+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75863+ pte_m = pte_offset_map_nested(pmd_m, address_m);
75864+ ptl_m = pte_lockptr(mm, pmd_m);
75865+ if (ptl != ptl_m) {
75866+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75867+ if (!pte_none(*pte_m))
75868+ goto out;
75869+ }
75870+
75871+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75872+ set_pte_at(mm, address_m, pte_m, entry_m);
75873+out:
75874+ if (ptl != ptl_m)
75875+ spin_unlock(ptl_m);
75876+ pte_unmap_nested(pte_m);
75877+}
75878+
75879+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75880+{
75881+ struct page *page_m;
75882+ pte_t entry;
75883+
75884+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75885+ goto out;
75886+
75887+ entry = *pte;
75888+ page_m = vm_normal_page(vma, address, entry);
75889+ if (!page_m)
75890+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
75891+ else if (PageAnon(page_m)) {
75892+ if (pax_find_mirror_vma(vma)) {
75893+ pte_unmap_unlock(pte, ptl);
75894+ lock_page(page_m);
75895+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
75896+ if (pte_same(entry, *pte))
75897+ pax_mirror_anon_pte(vma, address, page_m, ptl);
75898+ else
75899+ unlock_page(page_m);
75900+ }
75901+ } else
75902+ pax_mirror_file_pte(vma, address, page_m, ptl);
75903+
75904+out:
75905+ pte_unmap_unlock(pte, ptl);
75906+}
75907+#endif
75908+
75909 /*
75910 * This routine handles present pages, when users try to write
75911 * to a shared page. It is done by copying the page to a new address
75912@@ -2156,6 +2360,12 @@ gotten:
75913 */
75914 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75915 if (likely(pte_same(*page_table, orig_pte))) {
75916+
75917+#ifdef CONFIG_PAX_SEGMEXEC
75918+ if (pax_find_mirror_vma(vma))
75919+ BUG_ON(!trylock_page(new_page));
75920+#endif
75921+
75922 if (old_page) {
75923 if (!PageAnon(old_page)) {
75924 dec_mm_counter(mm, file_rss);
75925@@ -2207,6 +2417,10 @@ gotten:
75926 page_remove_rmap(old_page);
75927 }
75928
75929+#ifdef CONFIG_PAX_SEGMEXEC
75930+ pax_mirror_anon_pte(vma, address, new_page, ptl);
75931+#endif
75932+
75933 /* Free the old page.. */
75934 new_page = old_page;
75935 ret |= VM_FAULT_WRITE;
75936@@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75937 swap_free(entry);
75938 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
75939 try_to_free_swap(page);
75940+
75941+#ifdef CONFIG_PAX_SEGMEXEC
75942+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
75943+#endif
75944+
75945 unlock_page(page);
75946
75947 if (flags & FAULT_FLAG_WRITE) {
75948@@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75949
75950 /* No need to invalidate - it was non-present before */
75951 update_mmu_cache(vma, address, pte);
75952+
75953+#ifdef CONFIG_PAX_SEGMEXEC
75954+ pax_mirror_anon_pte(vma, address, page, ptl);
75955+#endif
75956+
75957 unlock:
75958 pte_unmap_unlock(page_table, ptl);
75959 out:
75960@@ -2632,40 +2856,6 @@ out_release:
75961 }
75962
75963 /*
75964- * This is like a special single-page "expand_{down|up}wards()",
75965- * except we must first make sure that 'address{-|+}PAGE_SIZE'
75966- * doesn't hit another vma.
75967- */
75968-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
75969-{
75970- address &= PAGE_MASK;
75971- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
75972- struct vm_area_struct *prev = vma->vm_prev;
75973-
75974- /*
75975- * Is there a mapping abutting this one below?
75976- *
75977- * That's only ok if it's the same stack mapping
75978- * that has gotten split..
75979- */
75980- if (prev && prev->vm_end == address)
75981- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
75982-
75983- expand_stack(vma, address - PAGE_SIZE);
75984- }
75985- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
75986- struct vm_area_struct *next = vma->vm_next;
75987-
75988- /* As VM_GROWSDOWN but s/below/above/ */
75989- if (next && next->vm_start == address + PAGE_SIZE)
75990- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
75991-
75992- expand_upwards(vma, address + PAGE_SIZE);
75993- }
75994- return 0;
75995-}
75996-
75997-/*
75998 * We enter with non-exclusive mmap_sem (to exclude vma changes,
75999 * but allow concurrent faults), and pte mapped but not yet locked.
76000 * We return with mmap_sem still held, but pte unmapped and unlocked.
76001@@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76002 unsigned long address, pte_t *page_table, pmd_t *pmd,
76003 unsigned int flags)
76004 {
76005- struct page *page;
76006+ struct page *page = NULL;
76007 spinlock_t *ptl;
76008 pte_t entry;
76009
76010- pte_unmap(page_table);
76011-
76012- /* Check if we need to add a guard page to the stack */
76013- if (check_stack_guard_page(vma, address) < 0)
76014- return VM_FAULT_SIGBUS;
76015-
76016- /* Use the zero-page for reads */
76017 if (!(flags & FAULT_FLAG_WRITE)) {
76018 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76019 vma->vm_page_prot));
76020- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76021+ ptl = pte_lockptr(mm, pmd);
76022+ spin_lock(ptl);
76023 if (!pte_none(*page_table))
76024 goto unlock;
76025 goto setpte;
76026 }
76027
76028 /* Allocate our own private page. */
76029+ pte_unmap(page_table);
76030+
76031 if (unlikely(anon_vma_prepare(vma)))
76032 goto oom;
76033 page = alloc_zeroed_user_highpage_movable(vma, address);
76034@@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76035 if (!pte_none(*page_table))
76036 goto release;
76037
76038+#ifdef CONFIG_PAX_SEGMEXEC
76039+ if (pax_find_mirror_vma(vma))
76040+ BUG_ON(!trylock_page(page));
76041+#endif
76042+
76043 inc_mm_counter(mm, anon_rss);
76044 page_add_new_anon_rmap(page, vma, address);
76045 setpte:
76046@@ -2720,6 +2911,12 @@ setpte:
76047
76048 /* No need to invalidate - it was non-present before */
76049 update_mmu_cache(vma, address, entry);
76050+
76051+#ifdef CONFIG_PAX_SEGMEXEC
76052+ if (page)
76053+ pax_mirror_anon_pte(vma, address, page, ptl);
76054+#endif
76055+
76056 unlock:
76057 pte_unmap_unlock(page_table, ptl);
76058 return 0;
76059@@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76060 */
76061 /* Only go through if we didn't race with anybody else... */
76062 if (likely(pte_same(*page_table, orig_pte))) {
76063+
76064+#ifdef CONFIG_PAX_SEGMEXEC
76065+ if (anon && pax_find_mirror_vma(vma))
76066+ BUG_ON(!trylock_page(page));
76067+#endif
76068+
76069 flush_icache_page(vma, page);
76070 entry = mk_pte(page, vma->vm_page_prot);
76071 if (flags & FAULT_FLAG_WRITE)
76072@@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76073
76074 /* no need to invalidate: a not-present page won't be cached */
76075 update_mmu_cache(vma, address, entry);
76076+
76077+#ifdef CONFIG_PAX_SEGMEXEC
76078+ if (anon)
76079+ pax_mirror_anon_pte(vma, address, page, ptl);
76080+ else
76081+ pax_mirror_file_pte(vma, address, page, ptl);
76082+#endif
76083+
76084 } else {
76085 if (charged)
76086 mem_cgroup_uncharge_page(page);
76087@@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struct mm_struct *mm,
76088 if (flags & FAULT_FLAG_WRITE)
76089 flush_tlb_page(vma, address);
76090 }
76091+
76092+#ifdef CONFIG_PAX_SEGMEXEC
76093+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76094+ return 0;
76095+#endif
76096+
76097 unlock:
76098 pte_unmap_unlock(pte, ptl);
76099 return 0;
76100@@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76101 pmd_t *pmd;
76102 pte_t *pte;
76103
76104+#ifdef CONFIG_PAX_SEGMEXEC
76105+ struct vm_area_struct *vma_m;
76106+#endif
76107+
76108 __set_current_state(TASK_RUNNING);
76109
76110 count_vm_event(PGFAULT);
76111@@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76112 if (unlikely(is_vm_hugetlb_page(vma)))
76113 return hugetlb_fault(mm, vma, address, flags);
76114
76115+#ifdef CONFIG_PAX_SEGMEXEC
76116+ vma_m = pax_find_mirror_vma(vma);
76117+ if (vma_m) {
76118+ unsigned long address_m;
76119+ pgd_t *pgd_m;
76120+ pud_t *pud_m;
76121+ pmd_t *pmd_m;
76122+
76123+ if (vma->vm_start > vma_m->vm_start) {
76124+ address_m = address;
76125+ address -= SEGMEXEC_TASK_SIZE;
76126+ vma = vma_m;
76127+ } else
76128+ address_m = address + SEGMEXEC_TASK_SIZE;
76129+
76130+ pgd_m = pgd_offset(mm, address_m);
76131+ pud_m = pud_alloc(mm, pgd_m, address_m);
76132+ if (!pud_m)
76133+ return VM_FAULT_OOM;
76134+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76135+ if (!pmd_m)
76136+ return VM_FAULT_OOM;
76137+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
76138+ return VM_FAULT_OOM;
76139+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76140+ }
76141+#endif
76142+
76143 pgd = pgd_offset(mm, address);
76144 pud = pud_alloc(mm, pgd, address);
76145 if (!pud)
76146@@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
76147 gate_vma.vm_start = FIXADDR_USER_START;
76148 gate_vma.vm_end = FIXADDR_USER_END;
76149 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76150- gate_vma.vm_page_prot = __P101;
76151+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76152 /*
76153 * Make sure the vDSO gets into every core dump.
76154 * Dumping its contents makes post-mortem fully interpretable later
76155diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76156index 3c6e3e2..ad9871c 100644
76157--- a/mm/mempolicy.c
76158+++ b/mm/mempolicy.c
76159@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76160 struct vm_area_struct *next;
76161 int err;
76162
76163+#ifdef CONFIG_PAX_SEGMEXEC
76164+ struct vm_area_struct *vma_m;
76165+#endif
76166+
76167 err = 0;
76168 for (; vma && vma->vm_start < end; vma = next) {
76169 next = vma->vm_next;
76170@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76171 err = policy_vma(vma, new);
76172 if (err)
76173 break;
76174+
76175+#ifdef CONFIG_PAX_SEGMEXEC
76176+ vma_m = pax_find_mirror_vma(vma);
76177+ if (vma_m) {
76178+ err = policy_vma(vma_m, new);
76179+ if (err)
76180+ break;
76181+ }
76182+#endif
76183+
76184 }
76185 return err;
76186 }
76187@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76188
76189 if (end < start)
76190 return -EINVAL;
76191+
76192+#ifdef CONFIG_PAX_SEGMEXEC
76193+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76194+ if (end > SEGMEXEC_TASK_SIZE)
76195+ return -EINVAL;
76196+ } else
76197+#endif
76198+
76199+ if (end > TASK_SIZE)
76200+ return -EINVAL;
76201+
76202 if (end == start)
76203 return 0;
76204
76205@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76206 if (!mm)
76207 return -EINVAL;
76208
76209+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76210+ if (mm != current->mm &&
76211+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76212+ err = -EPERM;
76213+ goto out;
76214+ }
76215+#endif
76216+
76217 /*
76218 * Check if this process has the right to modify the specified
76219 * process. The right exists if the process has administrative
76220@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76221 rcu_read_lock();
76222 tcred = __task_cred(task);
76223 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76224- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76225- !capable(CAP_SYS_NICE)) {
76226+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76227 rcu_read_unlock();
76228 err = -EPERM;
76229 goto out;
76230@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, void *v)
76231
76232 if (file) {
76233 seq_printf(m, " file=");
76234- seq_path(m, &file->f_path, "\n\t= ");
76235+ seq_path(m, &file->f_path, "\n\t\\= ");
76236 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
76237 seq_printf(m, " heap");
76238 } else if (vma->vm_start <= mm->start_stack &&
76239diff --git a/mm/migrate.c b/mm/migrate.c
76240index aaca868..2ebecdc 100644
76241--- a/mm/migrate.c
76242+++ b/mm/migrate.c
76243@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
76244 unsigned long chunk_start;
76245 int err;
76246
76247+ pax_track_stack();
76248+
76249 task_nodes = cpuset_mems_allowed(task);
76250
76251 err = -ENOMEM;
76252@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76253 if (!mm)
76254 return -EINVAL;
76255
76256+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76257+ if (mm != current->mm &&
76258+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76259+ err = -EPERM;
76260+ goto out;
76261+ }
76262+#endif
76263+
76264 /*
76265 * Check if this process has the right to modify the specified
76266 * process. The right exists if the process has administrative
76267@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76268 rcu_read_lock();
76269 tcred = __task_cred(task);
76270 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76271- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76272- !capable(CAP_SYS_NICE)) {
76273+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76274 rcu_read_unlock();
76275 err = -EPERM;
76276 goto out;
76277diff --git a/mm/mlock.c b/mm/mlock.c
76278index 2d846cf..98134d2 100644
76279--- a/mm/mlock.c
76280+++ b/mm/mlock.c
76281@@ -13,6 +13,7 @@
76282 #include <linux/pagemap.h>
76283 #include <linux/mempolicy.h>
76284 #include <linux/syscalls.h>
76285+#include <linux/security.h>
76286 #include <linux/sched.h>
76287 #include <linux/module.h>
76288 #include <linux/rmap.h>
76289@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
76290 }
76291 }
76292
76293-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
76294-{
76295- return (vma->vm_flags & VM_GROWSDOWN) &&
76296- (vma->vm_start == addr) &&
76297- !vma_stack_continue(vma->vm_prev, addr);
76298-}
76299-
76300 /**
76301 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
76302 * @vma: target vma
76303@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
76304 if (vma->vm_flags & VM_WRITE)
76305 gup_flags |= FOLL_WRITE;
76306
76307- /* We don't try to access the guard page of a stack vma */
76308- if (stack_guard_page(vma, start)) {
76309- addr += PAGE_SIZE;
76310- nr_pages--;
76311- }
76312-
76313 while (nr_pages > 0) {
76314 int i;
76315
76316@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76317 {
76318 unsigned long nstart, end, tmp;
76319 struct vm_area_struct * vma, * prev;
76320- int error;
76321+ int error = -EINVAL;
76322
76323 len = PAGE_ALIGN(len);
76324 end = start + len;
76325@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76326 return -EINVAL;
76327 if (end == start)
76328 return 0;
76329+ if (end > TASK_SIZE)
76330+ return -EINVAL;
76331+
76332 vma = find_vma_prev(current->mm, start, &prev);
76333 if (!vma || vma->vm_start > start)
76334 return -ENOMEM;
76335@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76336 for (nstart = start ; ; ) {
76337 unsigned int newflags;
76338
76339+#ifdef CONFIG_PAX_SEGMEXEC
76340+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76341+ break;
76342+#endif
76343+
76344 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76345
76346 newflags = vma->vm_flags | VM_LOCKED;
76347@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76348 lock_limit >>= PAGE_SHIFT;
76349
76350 /* check against resource limits */
76351+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76352 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76353 error = do_mlock(start, len, 1);
76354 up_write(&current->mm->mmap_sem);
76355@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
76356 static int do_mlockall(int flags)
76357 {
76358 struct vm_area_struct * vma, * prev = NULL;
76359- unsigned int def_flags = 0;
76360
76361 if (flags & MCL_FUTURE)
76362- def_flags = VM_LOCKED;
76363- current->mm->def_flags = def_flags;
76364+ current->mm->def_flags |= VM_LOCKED;
76365+ else
76366+ current->mm->def_flags &= ~VM_LOCKED;
76367 if (flags == MCL_FUTURE)
76368 goto out;
76369
76370 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76371- unsigned int newflags;
76372+ unsigned long newflags;
76373
76374+#ifdef CONFIG_PAX_SEGMEXEC
76375+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76376+ break;
76377+#endif
76378+
76379+ BUG_ON(vma->vm_end > TASK_SIZE);
76380 newflags = vma->vm_flags | VM_LOCKED;
76381 if (!(flags & MCL_CURRENT))
76382 newflags &= ~VM_LOCKED;
76383@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76384 lock_limit >>= PAGE_SHIFT;
76385
76386 ret = -ENOMEM;
76387+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76388 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76389 capable(CAP_IPC_LOCK))
76390 ret = do_mlockall(flags);
76391diff --git a/mm/mmap.c b/mm/mmap.c
76392index 4b80cbf..c5ce1df 100644
76393--- a/mm/mmap.c
76394+++ b/mm/mmap.c
76395@@ -45,6 +45,16 @@
76396 #define arch_rebalance_pgtables(addr, len) (addr)
76397 #endif
76398
76399+static inline void verify_mm_writelocked(struct mm_struct *mm)
76400+{
76401+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76402+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76403+ up_read(&mm->mmap_sem);
76404+ BUG();
76405+ }
76406+#endif
76407+}
76408+
76409 static void unmap_region(struct mm_struct *mm,
76410 struct vm_area_struct *vma, struct vm_area_struct *prev,
76411 unsigned long start, unsigned long end);
76412@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struct *mm,
76413 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76414 *
76415 */
76416-pgprot_t protection_map[16] = {
76417+pgprot_t protection_map[16] __read_only = {
76418 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76419 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76420 };
76421
76422 pgprot_t vm_get_page_prot(unsigned long vm_flags)
76423 {
76424- return __pgprot(pgprot_val(protection_map[vm_flags &
76425+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76426 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76427 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76428+
76429+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76430+ if (!nx_enabled &&
76431+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76432+ (vm_flags & (VM_READ | VM_WRITE)))
76433+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76434+#endif
76435+
76436+ return prot;
76437 }
76438 EXPORT_SYMBOL(vm_get_page_prot);
76439
76440 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76441 int sysctl_overcommit_ratio = 50; /* default is 50% */
76442 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76443+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76444 struct percpu_counter vm_committed_as;
76445
76446 /*
76447@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76448 struct vm_area_struct *next = vma->vm_next;
76449
76450 might_sleep();
76451+ BUG_ON(vma->vm_mirror);
76452 if (vma->vm_ops && vma->vm_ops->close)
76453 vma->vm_ops->close(vma);
76454 if (vma->vm_file) {
76455@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76456 * not page aligned -Ram Gupta
76457 */
76458 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
76459+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76460 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76461 (mm->end_data - mm->start_data) > rlim)
76462 goto out;
76463@@ -704,6 +726,12 @@ static int
76464 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76465 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76466 {
76467+
76468+#ifdef CONFIG_PAX_SEGMEXEC
76469+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76470+ return 0;
76471+#endif
76472+
76473 if (is_mergeable_vma(vma, file, vm_flags) &&
76474 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76475 if (vma->vm_pgoff == vm_pgoff)
76476@@ -723,6 +751,12 @@ static int
76477 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76478 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76479 {
76480+
76481+#ifdef CONFIG_PAX_SEGMEXEC
76482+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76483+ return 0;
76484+#endif
76485+
76486 if (is_mergeable_vma(vma, file, vm_flags) &&
76487 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76488 pgoff_t vm_pglen;
76489@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76490 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76491 struct vm_area_struct *prev, unsigned long addr,
76492 unsigned long end, unsigned long vm_flags,
76493- struct anon_vma *anon_vma, struct file *file,
76494+ struct anon_vma *anon_vma, struct file *file,
76495 pgoff_t pgoff, struct mempolicy *policy)
76496 {
76497 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76498 struct vm_area_struct *area, *next;
76499
76500+#ifdef CONFIG_PAX_SEGMEXEC
76501+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76502+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76503+
76504+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76505+#endif
76506+
76507 /*
76508 * We later require that vma->vm_flags == vm_flags,
76509 * so this tests vma->vm_flags & VM_SPECIAL, too.
76510@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76511 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76512 next = next->vm_next;
76513
76514+#ifdef CONFIG_PAX_SEGMEXEC
76515+ if (prev)
76516+ prev_m = pax_find_mirror_vma(prev);
76517+ if (area)
76518+ area_m = pax_find_mirror_vma(area);
76519+ if (next)
76520+ next_m = pax_find_mirror_vma(next);
76521+#endif
76522+
76523 /*
76524 * Can it merge with the predecessor?
76525 */
76526@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76527 /* cases 1, 6 */
76528 vma_adjust(prev, prev->vm_start,
76529 next->vm_end, prev->vm_pgoff, NULL);
76530- } else /* cases 2, 5, 7 */
76531+
76532+#ifdef CONFIG_PAX_SEGMEXEC
76533+ if (prev_m)
76534+ vma_adjust(prev_m, prev_m->vm_start,
76535+ next_m->vm_end, prev_m->vm_pgoff, NULL);
76536+#endif
76537+
76538+ } else { /* cases 2, 5, 7 */
76539 vma_adjust(prev, prev->vm_start,
76540 end, prev->vm_pgoff, NULL);
76541+
76542+#ifdef CONFIG_PAX_SEGMEXEC
76543+ if (prev_m)
76544+ vma_adjust(prev_m, prev_m->vm_start,
76545+ end_m, prev_m->vm_pgoff, NULL);
76546+#endif
76547+
76548+ }
76549 return prev;
76550 }
76551
76552@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76553 mpol_equal(policy, vma_policy(next)) &&
76554 can_vma_merge_before(next, vm_flags,
76555 anon_vma, file, pgoff+pglen)) {
76556- if (prev && addr < prev->vm_end) /* case 4 */
76557+ if (prev && addr < prev->vm_end) { /* case 4 */
76558 vma_adjust(prev, prev->vm_start,
76559 addr, prev->vm_pgoff, NULL);
76560- else /* cases 3, 8 */
76561+
76562+#ifdef CONFIG_PAX_SEGMEXEC
76563+ if (prev_m)
76564+ vma_adjust(prev_m, prev_m->vm_start,
76565+ addr_m, prev_m->vm_pgoff, NULL);
76566+#endif
76567+
76568+ } else { /* cases 3, 8 */
76569 vma_adjust(area, addr, next->vm_end,
76570 next->vm_pgoff - pglen, NULL);
76571+
76572+#ifdef CONFIG_PAX_SEGMEXEC
76573+ if (area_m)
76574+ vma_adjust(area_m, addr_m, next_m->vm_end,
76575+ next_m->vm_pgoff - pglen, NULL);
76576+#endif
76577+
76578+ }
76579 return area;
76580 }
76581
76582@@ -898,14 +978,11 @@ none:
76583 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76584 struct file *file, long pages)
76585 {
76586- const unsigned long stack_flags
76587- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76588-
76589 if (file) {
76590 mm->shared_vm += pages;
76591 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76592 mm->exec_vm += pages;
76593- } else if (flags & stack_flags)
76594+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76595 mm->stack_vm += pages;
76596 if (flags & (VM_RESERVED|VM_IO))
76597 mm->reserved_vm += pages;
76598@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76599 * (the exception is when the underlying filesystem is noexec
76600 * mounted, in which case we dont add PROT_EXEC.)
76601 */
76602- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76603+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76604 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76605 prot |= PROT_EXEC;
76606
76607@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76608 /* Obtain the address to map to. we verify (or select) it and ensure
76609 * that it represents a valid section of the address space.
76610 */
76611- addr = get_unmapped_area(file, addr, len, pgoff, flags);
76612+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76613 if (addr & ~PAGE_MASK)
76614 return addr;
76615
76616@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76617 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76618 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76619
76620+#ifdef CONFIG_PAX_MPROTECT
76621+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76622+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76623+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76624+ gr_log_rwxmmap(file);
76625+
76626+#ifdef CONFIG_PAX_EMUPLT
76627+ vm_flags &= ~VM_EXEC;
76628+#else
76629+ return -EPERM;
76630+#endif
76631+
76632+ }
76633+
76634+ if (!(vm_flags & VM_EXEC))
76635+ vm_flags &= ~VM_MAYEXEC;
76636+#else
76637+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76638+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76639+#endif
76640+ else
76641+ vm_flags &= ~VM_MAYWRITE;
76642+ }
76643+#endif
76644+
76645+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76646+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76647+ vm_flags &= ~VM_PAGEEXEC;
76648+#endif
76649+
76650 if (flags & MAP_LOCKED)
76651 if (!can_do_mlock())
76652 return -EPERM;
76653@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76654 locked += mm->locked_vm;
76655 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
76656 lock_limit >>= PAGE_SHIFT;
76657+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76658 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76659 return -EAGAIN;
76660 }
76661@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76662 if (error)
76663 return error;
76664
76665+ if (!gr_acl_handle_mmap(file, prot))
76666+ return -EACCES;
76667+
76668 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76669 }
76670 EXPORT_SYMBOL(do_mmap_pgoff);
76671@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
76672 */
76673 int vma_wants_writenotify(struct vm_area_struct *vma)
76674 {
76675- unsigned int vm_flags = vma->vm_flags;
76676+ unsigned long vm_flags = vma->vm_flags;
76677
76678 /* If it was private or non-writable, the write bit is already clear */
76679- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76680+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76681 return 0;
76682
76683 /* The backer wishes to know when pages are first written to? */
76684@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76685 unsigned long charged = 0;
76686 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76687
76688+#ifdef CONFIG_PAX_SEGMEXEC
76689+ struct vm_area_struct *vma_m = NULL;
76690+#endif
76691+
76692+ /*
76693+ * mm->mmap_sem is required to protect against another thread
76694+ * changing the mappings in case we sleep.
76695+ */
76696+ verify_mm_writelocked(mm);
76697+
76698 /* Clear old maps */
76699 error = -ENOMEM;
76700-munmap_back:
76701 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
76702 if (vma && vma->vm_start < addr + len) {
76703 if (do_munmap(mm, addr, len))
76704 return -ENOMEM;
76705- goto munmap_back;
76706+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
76707+ BUG_ON(vma && vma->vm_start < addr + len);
76708 }
76709
76710 /* Check against address space limit. */
76711@@ -1173,6 +1294,16 @@ munmap_back:
76712 goto unacct_error;
76713 }
76714
76715+#ifdef CONFIG_PAX_SEGMEXEC
76716+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76717+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76718+ if (!vma_m) {
76719+ error = -ENOMEM;
76720+ goto free_vma;
76721+ }
76722+ }
76723+#endif
76724+
76725 vma->vm_mm = mm;
76726 vma->vm_start = addr;
76727 vma->vm_end = addr + len;
76728@@ -1195,6 +1326,19 @@ munmap_back:
76729 error = file->f_op->mmap(file, vma);
76730 if (error)
76731 goto unmap_and_free_vma;
76732+
76733+#ifdef CONFIG_PAX_SEGMEXEC
76734+ if (vma_m && (vm_flags & VM_EXECUTABLE))
76735+ added_exe_file_vma(mm);
76736+#endif
76737+
76738+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76739+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76740+ vma->vm_flags |= VM_PAGEEXEC;
76741+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76742+ }
76743+#endif
76744+
76745 if (vm_flags & VM_EXECUTABLE)
76746 added_exe_file_vma(mm);
76747
76748@@ -1218,6 +1362,11 @@ munmap_back:
76749 vma_link(mm, vma, prev, rb_link, rb_parent);
76750 file = vma->vm_file;
76751
76752+#ifdef CONFIG_PAX_SEGMEXEC
76753+ if (vma_m)
76754+ pax_mirror_vma(vma_m, vma);
76755+#endif
76756+
76757 /* Once vma denies write, undo our temporary denial count */
76758 if (correct_wcount)
76759 atomic_inc(&inode->i_writecount);
76760@@ -1226,6 +1375,7 @@ out:
76761
76762 mm->total_vm += len >> PAGE_SHIFT;
76763 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76764+ track_exec_limit(mm, addr, addr + len, vm_flags);
76765 if (vm_flags & VM_LOCKED) {
76766 /*
76767 * makes pages present; downgrades, drops, reacquires mmap_sem
76768@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
76769 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76770 charged = 0;
76771 free_vma:
76772+
76773+#ifdef CONFIG_PAX_SEGMEXEC
76774+ if (vma_m)
76775+ kmem_cache_free(vm_area_cachep, vma_m);
76776+#endif
76777+
76778 kmem_cache_free(vm_area_cachep, vma);
76779 unacct_error:
76780 if (charged)
76781@@ -1255,6 +1411,44 @@ unacct_error:
76782 return error;
76783 }
76784
76785+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
76786+{
76787+ if (!vma) {
76788+#ifdef CONFIG_STACK_GROWSUP
76789+ if (addr > sysctl_heap_stack_gap)
76790+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76791+ else
76792+ vma = find_vma(current->mm, 0);
76793+ if (vma && (vma->vm_flags & VM_GROWSUP))
76794+ return false;
76795+#endif
76796+ return true;
76797+ }
76798+
76799+ if (addr + len > vma->vm_start)
76800+ return false;
76801+
76802+ if (vma->vm_flags & VM_GROWSDOWN)
76803+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76804+#ifdef CONFIG_STACK_GROWSUP
76805+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76806+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76807+#endif
76808+
76809+ return true;
76810+}
76811+
76812+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
76813+{
76814+ if (vma->vm_start < len)
76815+ return -ENOMEM;
76816+ if (!(vma->vm_flags & VM_GROWSDOWN))
76817+ return vma->vm_start - len;
76818+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
76819+ return vma->vm_start - len - sysctl_heap_stack_gap;
76820+ return -ENOMEM;
76821+}
76822+
76823 /* Get an address range which is currently unmapped.
76824 * For shmat() with addr=0.
76825 *
76826@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76827 if (flags & MAP_FIXED)
76828 return addr;
76829
76830+#ifdef CONFIG_PAX_RANDMMAP
76831+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76832+#endif
76833+
76834 if (addr) {
76835 addr = PAGE_ALIGN(addr);
76836- vma = find_vma(mm, addr);
76837- if (TASK_SIZE - len >= addr &&
76838- (!vma || addr + len <= vma->vm_start))
76839- return addr;
76840+ if (TASK_SIZE - len >= addr) {
76841+ vma = find_vma(mm, addr);
76842+ if (check_heap_stack_gap(vma, addr, len))
76843+ return addr;
76844+ }
76845 }
76846 if (len > mm->cached_hole_size) {
76847- start_addr = addr = mm->free_area_cache;
76848+ start_addr = addr = mm->free_area_cache;
76849 } else {
76850- start_addr = addr = TASK_UNMAPPED_BASE;
76851- mm->cached_hole_size = 0;
76852+ start_addr = addr = mm->mmap_base;
76853+ mm->cached_hole_size = 0;
76854 }
76855
76856 full_search:
76857@@ -1303,34 +1502,40 @@ full_search:
76858 * Start a new search - just in case we missed
76859 * some holes.
76860 */
76861- if (start_addr != TASK_UNMAPPED_BASE) {
76862- addr = TASK_UNMAPPED_BASE;
76863- start_addr = addr;
76864+ if (start_addr != mm->mmap_base) {
76865+ start_addr = addr = mm->mmap_base;
76866 mm->cached_hole_size = 0;
76867 goto full_search;
76868 }
76869 return -ENOMEM;
76870 }
76871- if (!vma || addr + len <= vma->vm_start) {
76872- /*
76873- * Remember the place where we stopped the search:
76874- */
76875- mm->free_area_cache = addr + len;
76876- return addr;
76877- }
76878+ if (check_heap_stack_gap(vma, addr, len))
76879+ break;
76880 if (addr + mm->cached_hole_size < vma->vm_start)
76881 mm->cached_hole_size = vma->vm_start - addr;
76882 addr = vma->vm_end;
76883 }
76884+
76885+ /*
76886+ * Remember the place where we stopped the search:
76887+ */
76888+ mm->free_area_cache = addr + len;
76889+ return addr;
76890 }
76891 #endif
76892
76893 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76894 {
76895+
76896+#ifdef CONFIG_PAX_SEGMEXEC
76897+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76898+ return;
76899+#endif
76900+
76901 /*
76902 * Is this a new hole at the lowest possible address?
76903 */
76904- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
76905+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
76906 mm->free_area_cache = addr;
76907 mm->cached_hole_size = ~0UL;
76908 }
76909@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76910 {
76911 struct vm_area_struct *vma;
76912 struct mm_struct *mm = current->mm;
76913- unsigned long addr = addr0;
76914+ unsigned long base = mm->mmap_base, addr = addr0;
76915
76916 /* requested length too big for entire address space */
76917 if (len > TASK_SIZE)
76918@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76919 if (flags & MAP_FIXED)
76920 return addr;
76921
76922+#ifdef CONFIG_PAX_RANDMMAP
76923+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76924+#endif
76925+
76926 /* requesting a specific address */
76927 if (addr) {
76928 addr = PAGE_ALIGN(addr);
76929- vma = find_vma(mm, addr);
76930- if (TASK_SIZE - len >= addr &&
76931- (!vma || addr + len <= vma->vm_start))
76932- return addr;
76933+ if (TASK_SIZE - len >= addr) {
76934+ vma = find_vma(mm, addr);
76935+ if (check_heap_stack_gap(vma, addr, len))
76936+ return addr;
76937+ }
76938 }
76939
76940 /* check if free_area_cache is useful for us */
76941@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76942 /* make sure it can fit in the remaining address space */
76943 if (addr > len) {
76944 vma = find_vma(mm, addr-len);
76945- if (!vma || addr <= vma->vm_start)
76946+ if (check_heap_stack_gap(vma, addr - len, len))
76947 /* remember the address as a hint for next time */
76948 return (mm->free_area_cache = addr-len);
76949 }
76950@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76951 * return with success:
76952 */
76953 vma = find_vma(mm, addr);
76954- if (!vma || addr+len <= vma->vm_start)
76955+ if (check_heap_stack_gap(vma, addr, len))
76956 /* remember the address as a hint for next time */
76957 return (mm->free_area_cache = addr);
76958
76959@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76960 mm->cached_hole_size = vma->vm_start - addr;
76961
76962 /* try just below the current vma->vm_start */
76963- addr = vma->vm_start-len;
76964- } while (len < vma->vm_start);
76965+ addr = skip_heap_stack_gap(vma, len);
76966+ } while (!IS_ERR_VALUE(addr));
76967
76968 bottomup:
76969 /*
76970@@ -1414,13 +1624,21 @@ bottomup:
76971 * can happen with large stack limits and large mmap()
76972 * allocations.
76973 */
76974+ mm->mmap_base = TASK_UNMAPPED_BASE;
76975+
76976+#ifdef CONFIG_PAX_RANDMMAP
76977+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76978+ mm->mmap_base += mm->delta_mmap;
76979+#endif
76980+
76981+ mm->free_area_cache = mm->mmap_base;
76982 mm->cached_hole_size = ~0UL;
76983- mm->free_area_cache = TASK_UNMAPPED_BASE;
76984 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
76985 /*
76986 * Restore the topdown base:
76987 */
76988- mm->free_area_cache = mm->mmap_base;
76989+ mm->mmap_base = base;
76990+ mm->free_area_cache = base;
76991 mm->cached_hole_size = ~0UL;
76992
76993 return addr;
76994@@ -1429,6 +1647,12 @@ bottomup:
76995
76996 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76997 {
76998+
76999+#ifdef CONFIG_PAX_SEGMEXEC
77000+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77001+ return;
77002+#endif
77003+
77004 /*
77005 * Is this a new hole at the highest possible address?
77006 */
77007@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77008 mm->free_area_cache = addr;
77009
77010 /* dont allow allocations above current base */
77011- if (mm->free_area_cache > mm->mmap_base)
77012+ if (mm->free_area_cache > mm->mmap_base) {
77013 mm->free_area_cache = mm->mmap_base;
77014+ mm->cached_hole_size = ~0UL;
77015+ }
77016 }
77017
77018 unsigned long
77019@@ -1545,6 +1771,27 @@ out:
77020 return prev ? prev->vm_next : vma;
77021 }
77022
77023+#ifdef CONFIG_PAX_SEGMEXEC
77024+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77025+{
77026+ struct vm_area_struct *vma_m;
77027+
77028+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77029+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77030+ BUG_ON(vma->vm_mirror);
77031+ return NULL;
77032+ }
77033+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77034+ vma_m = vma->vm_mirror;
77035+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77036+ BUG_ON(vma->vm_file != vma_m->vm_file);
77037+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77038+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
77039+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
77040+ return vma_m;
77041+}
77042+#endif
77043+
77044 /*
77045 * Verify that the stack growth is acceptable and
77046 * update accounting. This is shared with both the
77047@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77048 return -ENOMEM;
77049
77050 /* Stack limit test */
77051+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
77052 if (size > rlim[RLIMIT_STACK].rlim_cur)
77053 return -ENOMEM;
77054
77055@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77056 unsigned long limit;
77057 locked = mm->locked_vm + grow;
77058 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
77059+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77060 if (locked > limit && !capable(CAP_IPC_LOCK))
77061 return -ENOMEM;
77062 }
77063@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77064 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77065 * vma is the last one with address > vma->vm_end. Have to extend vma.
77066 */
77067+#ifndef CONFIG_IA64
77068+static
77069+#endif
77070 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77071 {
77072 int error;
77073+ bool locknext;
77074
77075 if (!(vma->vm_flags & VM_GROWSUP))
77076 return -EFAULT;
77077
77078+ /* Also guard against wrapping around to address 0. */
77079+ if (address < PAGE_ALIGN(address+1))
77080+ address = PAGE_ALIGN(address+1);
77081+ else
77082+ return -ENOMEM;
77083+
77084 /*
77085 * We must make sure the anon_vma is allocated
77086 * so that the anon_vma locking is not a noop.
77087 */
77088 if (unlikely(anon_vma_prepare(vma)))
77089 return -ENOMEM;
77090+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77091+ if (locknext && anon_vma_prepare(vma->vm_next))
77092+ return -ENOMEM;
77093 anon_vma_lock(vma);
77094+ if (locknext)
77095+ anon_vma_lock(vma->vm_next);
77096
77097 /*
77098 * vma->vm_start/vm_end cannot change under us because the caller
77099 * is required to hold the mmap_sem in read mode. We need the
77100- * anon_vma lock to serialize against concurrent expand_stacks.
77101- * Also guard against wrapping around to address 0.
77102+ * anon_vma locks to serialize against concurrent expand_stacks
77103+ * and expand_upwards.
77104 */
77105- if (address < PAGE_ALIGN(address+4))
77106- address = PAGE_ALIGN(address+4);
77107- else {
77108- anon_vma_unlock(vma);
77109- return -ENOMEM;
77110- }
77111 error = 0;
77112
77113 /* Somebody else might have raced and expanded it already */
77114- if (address > vma->vm_end) {
77115+ 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)
77116+ error = -ENOMEM;
77117+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77118 unsigned long size, grow;
77119
77120 size = address - vma->vm_start;
77121@@ -1643,6 +1903,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77122 vma->vm_end = address;
77123 }
77124 }
77125+ if (locknext)
77126+ anon_vma_unlock(vma->vm_next);
77127 anon_vma_unlock(vma);
77128 return error;
77129 }
77130@@ -1655,6 +1917,8 @@ static int expand_downwards(struct vm_area_struct *vma,
77131 unsigned long address)
77132 {
77133 int error;
77134+ bool lockprev = false;
77135+ struct vm_area_struct *prev;
77136
77137 /*
77138 * We must make sure the anon_vma is allocated
77139@@ -1668,6 +1932,15 @@ static int expand_downwards(struct vm_area_struct *vma,
77140 if (error)
77141 return error;
77142
77143+ prev = vma->vm_prev;
77144+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77145+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77146+#endif
77147+ if (lockprev && anon_vma_prepare(prev))
77148+ return -ENOMEM;
77149+ if (lockprev)
77150+ anon_vma_lock(prev);
77151+
77152 anon_vma_lock(vma);
77153
77154 /*
77155@@ -1677,9 +1950,17 @@ static int expand_downwards(struct vm_area_struct *vma,
77156 */
77157
77158 /* Somebody else might have raced and expanded it already */
77159- if (address < vma->vm_start) {
77160+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77161+ error = -ENOMEM;
77162+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77163 unsigned long size, grow;
77164
77165+#ifdef CONFIG_PAX_SEGMEXEC
77166+ struct vm_area_struct *vma_m;
77167+
77168+ vma_m = pax_find_mirror_vma(vma);
77169+#endif
77170+
77171 size = vma->vm_end - address;
77172 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77173
77174@@ -1689,10 +1970,22 @@ static int expand_downwards(struct vm_area_struct *vma,
77175 if (!error) {
77176 vma->vm_start = address;
77177 vma->vm_pgoff -= grow;
77178+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77179+
77180+#ifdef CONFIG_PAX_SEGMEXEC
77181+ if (vma_m) {
77182+ vma_m->vm_start -= grow << PAGE_SHIFT;
77183+ vma_m->vm_pgoff -= grow;
77184+ }
77185+#endif
77186+
77187+
77188 }
77189 }
77190 }
77191 anon_vma_unlock(vma);
77192+ if (lockprev)
77193+ anon_vma_unlock(prev);
77194 return error;
77195 }
77196
77197@@ -1768,6 +2061,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77198 do {
77199 long nrpages = vma_pages(vma);
77200
77201+#ifdef CONFIG_PAX_SEGMEXEC
77202+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77203+ vma = remove_vma(vma);
77204+ continue;
77205+ }
77206+#endif
77207+
77208 mm->total_vm -= nrpages;
77209 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77210 vma = remove_vma(vma);
77211@@ -1813,6 +2113,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77212 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77213 vma->vm_prev = NULL;
77214 do {
77215+
77216+#ifdef CONFIG_PAX_SEGMEXEC
77217+ if (vma->vm_mirror) {
77218+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77219+ vma->vm_mirror->vm_mirror = NULL;
77220+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77221+ vma->vm_mirror = NULL;
77222+ }
77223+#endif
77224+
77225 rb_erase(&vma->vm_rb, &mm->mm_rb);
77226 mm->map_count--;
77227 tail_vma = vma;
77228@@ -1840,10 +2150,25 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77229 struct mempolicy *pol;
77230 struct vm_area_struct *new;
77231
77232+#ifdef CONFIG_PAX_SEGMEXEC
77233+ struct vm_area_struct *vma_m, *new_m = NULL;
77234+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77235+#endif
77236+
77237 if (is_vm_hugetlb_page(vma) && (addr &
77238 ~(huge_page_mask(hstate_vma(vma)))))
77239 return -EINVAL;
77240
77241+#ifdef CONFIG_PAX_SEGMEXEC
77242+ vma_m = pax_find_mirror_vma(vma);
77243+
77244+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77245+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77246+ if (mm->map_count >= sysctl_max_map_count-1)
77247+ return -ENOMEM;
77248+ } else
77249+#endif
77250+
77251 if (mm->map_count >= sysctl_max_map_count)
77252 return -ENOMEM;
77253
77254@@ -1851,6 +2176,16 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77255 if (!new)
77256 return -ENOMEM;
77257
77258+#ifdef CONFIG_PAX_SEGMEXEC
77259+ if (vma_m) {
77260+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77261+ if (!new_m) {
77262+ kmem_cache_free(vm_area_cachep, new);
77263+ return -ENOMEM;
77264+ }
77265+ }
77266+#endif
77267+
77268 /* most fields are the same, copy all, and then fixup */
77269 *new = *vma;
77270
77271@@ -1861,8 +2196,29 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77272 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77273 }
77274
77275+#ifdef CONFIG_PAX_SEGMEXEC
77276+ if (vma_m) {
77277+ *new_m = *vma_m;
77278+ new_m->vm_mirror = new;
77279+ new->vm_mirror = new_m;
77280+
77281+ if (new_below)
77282+ new_m->vm_end = addr_m;
77283+ else {
77284+ new_m->vm_start = addr_m;
77285+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77286+ }
77287+ }
77288+#endif
77289+
77290 pol = mpol_dup(vma_policy(vma));
77291 if (IS_ERR(pol)) {
77292+
77293+#ifdef CONFIG_PAX_SEGMEXEC
77294+ if (new_m)
77295+ kmem_cache_free(vm_area_cachep, new_m);
77296+#endif
77297+
77298 kmem_cache_free(vm_area_cachep, new);
77299 return PTR_ERR(pol);
77300 }
77301@@ -1883,6 +2239,28 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77302 else
77303 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77304
77305+#ifdef CONFIG_PAX_SEGMEXEC
77306+ if (vma_m) {
77307+ mpol_get(pol);
77308+ vma_set_policy(new_m, pol);
77309+
77310+ if (new_m->vm_file) {
77311+ get_file(new_m->vm_file);
77312+ if (vma_m->vm_flags & VM_EXECUTABLE)
77313+ added_exe_file_vma(mm);
77314+ }
77315+
77316+ if (new_m->vm_ops && new_m->vm_ops->open)
77317+ new_m->vm_ops->open(new_m);
77318+
77319+ if (new_below)
77320+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77321+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77322+ else
77323+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77324+ }
77325+#endif
77326+
77327 return 0;
77328 }
77329
77330@@ -1891,11 +2269,30 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77331 * work. This now handles partial unmappings.
77332 * Jeremy Fitzhardinge <jeremy@goop.org>
77333 */
77334+#ifdef CONFIG_PAX_SEGMEXEC
77335 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77336 {
77337+ int ret = __do_munmap(mm, start, len);
77338+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77339+ return ret;
77340+
77341+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77342+}
77343+
77344+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77345+#else
77346+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77347+#endif
77348+{
77349 unsigned long end;
77350 struct vm_area_struct *vma, *prev, *last;
77351
77352+ /*
77353+ * mm->mmap_sem is required to protect against another thread
77354+ * changing the mappings in case we sleep.
77355+ */
77356+ verify_mm_writelocked(mm);
77357+
77358 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77359 return -EINVAL;
77360
77361@@ -1959,6 +2356,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77362 /* Fix up all other VM information */
77363 remove_vma_list(mm, vma);
77364
77365+ track_exec_limit(mm, start, end, 0UL);
77366+
77367 return 0;
77368 }
77369
77370@@ -1971,22 +2370,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77371
77372 profile_munmap(addr);
77373
77374+#ifdef CONFIG_PAX_SEGMEXEC
77375+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77376+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
77377+ return -EINVAL;
77378+#endif
77379+
77380 down_write(&mm->mmap_sem);
77381 ret = do_munmap(mm, addr, len);
77382 up_write(&mm->mmap_sem);
77383 return ret;
77384 }
77385
77386-static inline void verify_mm_writelocked(struct mm_struct *mm)
77387-{
77388-#ifdef CONFIG_DEBUG_VM
77389- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77390- WARN_ON(1);
77391- up_read(&mm->mmap_sem);
77392- }
77393-#endif
77394-}
77395-
77396 /*
77397 * this is really a simplified "do_mmap". it only handles
77398 * anonymous maps. eventually we may be able to do some
77399@@ -2000,6 +2395,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77400 struct rb_node ** rb_link, * rb_parent;
77401 pgoff_t pgoff = addr >> PAGE_SHIFT;
77402 int error;
77403+ unsigned long charged;
77404
77405 len = PAGE_ALIGN(len);
77406 if (!len)
77407@@ -2011,16 +2407,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77408
77409 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77410
77411+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77412+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77413+ flags &= ~VM_EXEC;
77414+
77415+#ifdef CONFIG_PAX_MPROTECT
77416+ if (mm->pax_flags & MF_PAX_MPROTECT)
77417+ flags &= ~VM_MAYEXEC;
77418+#endif
77419+
77420+ }
77421+#endif
77422+
77423 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77424 if (error & ~PAGE_MASK)
77425 return error;
77426
77427+ charged = len >> PAGE_SHIFT;
77428+
77429 /*
77430 * mlock MCL_FUTURE?
77431 */
77432 if (mm->def_flags & VM_LOCKED) {
77433 unsigned long locked, lock_limit;
77434- locked = len >> PAGE_SHIFT;
77435+ locked = charged;
77436 locked += mm->locked_vm;
77437 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
77438 lock_limit >>= PAGE_SHIFT;
77439@@ -2037,22 +2447,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77440 /*
77441 * Clear old maps. this also does some error checking for us
77442 */
77443- munmap_back:
77444 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77445 if (vma && vma->vm_start < addr + len) {
77446 if (do_munmap(mm, addr, len))
77447 return -ENOMEM;
77448- goto munmap_back;
77449+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77450+ BUG_ON(vma && vma->vm_start < addr + len);
77451 }
77452
77453 /* Check against address space limits *after* clearing old maps... */
77454- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77455+ if (!may_expand_vm(mm, charged))
77456 return -ENOMEM;
77457
77458 if (mm->map_count > sysctl_max_map_count)
77459 return -ENOMEM;
77460
77461- if (security_vm_enough_memory(len >> PAGE_SHIFT))
77462+ if (security_vm_enough_memory(charged))
77463 return -ENOMEM;
77464
77465 /* Can we just expand an old private anonymous mapping? */
77466@@ -2066,7 +2476,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77467 */
77468 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77469 if (!vma) {
77470- vm_unacct_memory(len >> PAGE_SHIFT);
77471+ vm_unacct_memory(charged);
77472 return -ENOMEM;
77473 }
77474
77475@@ -2078,11 +2488,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77476 vma->vm_page_prot = vm_get_page_prot(flags);
77477 vma_link(mm, vma, prev, rb_link, rb_parent);
77478 out:
77479- mm->total_vm += len >> PAGE_SHIFT;
77480+ mm->total_vm += charged;
77481 if (flags & VM_LOCKED) {
77482 if (!mlock_vma_pages_range(vma, addr, addr + len))
77483- mm->locked_vm += (len >> PAGE_SHIFT);
77484+ mm->locked_vm += charged;
77485 }
77486+ track_exec_limit(mm, addr, addr + len, flags);
77487 return addr;
77488 }
77489
77490@@ -2129,8 +2540,10 @@ void exit_mmap(struct mm_struct *mm)
77491 * Walk the list again, actually closing and freeing it,
77492 * with preemption enabled, without holding any MM locks.
77493 */
77494- while (vma)
77495+ while (vma) {
77496+ vma->vm_mirror = NULL;
77497 vma = remove_vma(vma);
77498+ }
77499
77500 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
77501 }
77502@@ -2144,6 +2557,10 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77503 struct vm_area_struct * __vma, * prev;
77504 struct rb_node ** rb_link, * rb_parent;
77505
77506+#ifdef CONFIG_PAX_SEGMEXEC
77507+ struct vm_area_struct *vma_m = NULL;
77508+#endif
77509+
77510 /*
77511 * The vm_pgoff of a purely anonymous vma should be irrelevant
77512 * until its first write fault, when page's anon_vma and index
77513@@ -2166,7 +2583,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77514 if ((vma->vm_flags & VM_ACCOUNT) &&
77515 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77516 return -ENOMEM;
77517+
77518+#ifdef CONFIG_PAX_SEGMEXEC
77519+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77520+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77521+ if (!vma_m)
77522+ return -ENOMEM;
77523+ }
77524+#endif
77525+
77526 vma_link(mm, vma, prev, rb_link, rb_parent);
77527+
77528+#ifdef CONFIG_PAX_SEGMEXEC
77529+ if (vma_m)
77530+ pax_mirror_vma(vma_m, vma);
77531+#endif
77532+
77533 return 0;
77534 }
77535
77536@@ -2184,6 +2616,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77537 struct rb_node **rb_link, *rb_parent;
77538 struct mempolicy *pol;
77539
77540+ BUG_ON(vma->vm_mirror);
77541+
77542 /*
77543 * If anonymous vma has not yet been faulted, update new pgoff
77544 * to match new location, to increase its chance of merging.
77545@@ -2227,6 +2661,35 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77546 return new_vma;
77547 }
77548
77549+#ifdef CONFIG_PAX_SEGMEXEC
77550+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77551+{
77552+ struct vm_area_struct *prev_m;
77553+ struct rb_node **rb_link_m, *rb_parent_m;
77554+ struct mempolicy *pol_m;
77555+
77556+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77557+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77558+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77559+ *vma_m = *vma;
77560+ pol_m = vma_policy(vma_m);
77561+ mpol_get(pol_m);
77562+ vma_set_policy(vma_m, pol_m);
77563+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77564+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77565+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77566+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77567+ if (vma_m->vm_file)
77568+ get_file(vma_m->vm_file);
77569+ if (vma_m->vm_ops && vma_m->vm_ops->open)
77570+ vma_m->vm_ops->open(vma_m);
77571+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
77572+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77573+ vma_m->vm_mirror = vma;
77574+ vma->vm_mirror = vma_m;
77575+}
77576+#endif
77577+
77578 /*
77579 * Return true if the calling process may expand its vm space by the passed
77580 * number of pages
77581@@ -2237,7 +2700,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77582 unsigned long lim;
77583
77584 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
77585-
77586+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77587 if (cur + npages > lim)
77588 return 0;
77589 return 1;
77590@@ -2307,6 +2770,22 @@ int install_special_mapping(struct mm_struct *mm,
77591 vma->vm_start = addr;
77592 vma->vm_end = addr + len;
77593
77594+#ifdef CONFIG_PAX_MPROTECT
77595+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77596+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77597+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77598+ return -EPERM;
77599+ if (!(vm_flags & VM_EXEC))
77600+ vm_flags &= ~VM_MAYEXEC;
77601+#else
77602+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77603+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77604+#endif
77605+ else
77606+ vm_flags &= ~VM_MAYWRITE;
77607+ }
77608+#endif
77609+
77610 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77611 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77612
77613diff --git a/mm/mprotect.c b/mm/mprotect.c
77614index 1737c7e..c7faeb4 100644
77615--- a/mm/mprotect.c
77616+++ b/mm/mprotect.c
77617@@ -24,10 +24,16 @@
77618 #include <linux/mmu_notifier.h>
77619 #include <linux/migrate.h>
77620 #include <linux/perf_event.h>
77621+
77622+#ifdef CONFIG_PAX_MPROTECT
77623+#include <linux/elf.h>
77624+#endif
77625+
77626 #include <asm/uaccess.h>
77627 #include <asm/pgtable.h>
77628 #include <asm/cacheflush.h>
77629 #include <asm/tlbflush.h>
77630+#include <asm/mmu_context.h>
77631
77632 #ifndef pgprot_modify
77633 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77634@@ -132,6 +138,48 @@ static void change_protection(struct vm_area_struct *vma,
77635 flush_tlb_range(vma, start, end);
77636 }
77637
77638+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77639+/* called while holding the mmap semaphor for writing except stack expansion */
77640+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77641+{
77642+ unsigned long oldlimit, newlimit = 0UL;
77643+
77644+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
77645+ return;
77646+
77647+ spin_lock(&mm->page_table_lock);
77648+ oldlimit = mm->context.user_cs_limit;
77649+ if ((prot & VM_EXEC) && oldlimit < end)
77650+ /* USER_CS limit moved up */
77651+ newlimit = end;
77652+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77653+ /* USER_CS limit moved down */
77654+ newlimit = start;
77655+
77656+ if (newlimit) {
77657+ mm->context.user_cs_limit = newlimit;
77658+
77659+#ifdef CONFIG_SMP
77660+ wmb();
77661+ cpus_clear(mm->context.cpu_user_cs_mask);
77662+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77663+#endif
77664+
77665+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77666+ }
77667+ spin_unlock(&mm->page_table_lock);
77668+ if (newlimit == end) {
77669+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
77670+
77671+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
77672+ if (is_vm_hugetlb_page(vma))
77673+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77674+ else
77675+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
77676+ }
77677+}
77678+#endif
77679+
77680 int
77681 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77682 unsigned long start, unsigned long end, unsigned long newflags)
77683@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77684 int error;
77685 int dirty_accountable = 0;
77686
77687+#ifdef CONFIG_PAX_SEGMEXEC
77688+ struct vm_area_struct *vma_m = NULL;
77689+ unsigned long start_m, end_m;
77690+
77691+ start_m = start + SEGMEXEC_TASK_SIZE;
77692+ end_m = end + SEGMEXEC_TASK_SIZE;
77693+#endif
77694+
77695 if (newflags == oldflags) {
77696 *pprev = vma;
77697 return 0;
77698 }
77699
77700+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77701+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77702+
77703+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77704+ return -ENOMEM;
77705+
77706+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77707+ return -ENOMEM;
77708+ }
77709+
77710 /*
77711 * If we make a private mapping writable we increase our commit;
77712 * but (without finer accounting) cannot reduce our commit if we
77713@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77714 }
77715 }
77716
77717+#ifdef CONFIG_PAX_SEGMEXEC
77718+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77719+ if (start != vma->vm_start) {
77720+ error = split_vma(mm, vma, start, 1);
77721+ if (error)
77722+ goto fail;
77723+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77724+ *pprev = (*pprev)->vm_next;
77725+ }
77726+
77727+ if (end != vma->vm_end) {
77728+ error = split_vma(mm, vma, end, 0);
77729+ if (error)
77730+ goto fail;
77731+ }
77732+
77733+ if (pax_find_mirror_vma(vma)) {
77734+ error = __do_munmap(mm, start_m, end_m - start_m);
77735+ if (error)
77736+ goto fail;
77737+ } else {
77738+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77739+ if (!vma_m) {
77740+ error = -ENOMEM;
77741+ goto fail;
77742+ }
77743+ vma->vm_flags = newflags;
77744+ pax_mirror_vma(vma_m, vma);
77745+ }
77746+ }
77747+#endif
77748+
77749 /*
77750 * First try to merge with previous and/or next vma.
77751 */
77752@@ -195,9 +293,21 @@ success:
77753 * vm_flags and vm_page_prot are protected by the mmap_sem
77754 * held in write mode.
77755 */
77756+
77757+#ifdef CONFIG_PAX_SEGMEXEC
77758+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77759+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77760+#endif
77761+
77762 vma->vm_flags = newflags;
77763+
77764+#ifdef CONFIG_PAX_MPROTECT
77765+ if (mm->binfmt && mm->binfmt->handle_mprotect)
77766+ mm->binfmt->handle_mprotect(vma, newflags);
77767+#endif
77768+
77769 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77770- vm_get_page_prot(newflags));
77771+ vm_get_page_prot(vma->vm_flags));
77772
77773 if (vma_wants_writenotify(vma)) {
77774 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77775@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77776 end = start + len;
77777 if (end <= start)
77778 return -ENOMEM;
77779+
77780+#ifdef CONFIG_PAX_SEGMEXEC
77781+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77782+ if (end > SEGMEXEC_TASK_SIZE)
77783+ return -EINVAL;
77784+ } else
77785+#endif
77786+
77787+ if (end > TASK_SIZE)
77788+ return -EINVAL;
77789+
77790 if (!arch_validate_prot(prot))
77791 return -EINVAL;
77792
77793@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77794 /*
77795 * Does the application expect PROT_READ to imply PROT_EXEC:
77796 */
77797- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77798+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77799 prot |= PROT_EXEC;
77800
77801 vm_flags = calc_vm_prot_bits(prot);
77802@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77803 if (start > vma->vm_start)
77804 prev = vma;
77805
77806+#ifdef CONFIG_PAX_MPROTECT
77807+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77808+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
77809+#endif
77810+
77811 for (nstart = start ; ; ) {
77812 unsigned long newflags;
77813
77814@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77815
77816 /* newflags >> 4 shift VM_MAY% in place of VM_% */
77817 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
77818+ if (prot & (PROT_WRITE | PROT_EXEC))
77819+ gr_log_rwxmprotect(vma->vm_file);
77820+
77821+ error = -EACCES;
77822+ goto out;
77823+ }
77824+
77825+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
77826 error = -EACCES;
77827 goto out;
77828 }
77829@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77830 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
77831 if (error)
77832 goto out;
77833+
77834+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
77835+
77836 nstart = tmp;
77837
77838 if (nstart < prev->vm_end)
77839diff --git a/mm/mremap.c b/mm/mremap.c
77840index 3e98d79..1706cec 100644
77841--- a/mm/mremap.c
77842+++ b/mm/mremap.c
77843@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
77844 continue;
77845 pte = ptep_clear_flush(vma, old_addr, old_pte);
77846 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
77847+
77848+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77849+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
77850+ pte = pte_exprotect(pte);
77851+#endif
77852+
77853 set_pte_at(mm, new_addr, new_pte, pte);
77854 }
77855
77856@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
77857 if (is_vm_hugetlb_page(vma))
77858 goto Einval;
77859
77860+#ifdef CONFIG_PAX_SEGMEXEC
77861+ if (pax_find_mirror_vma(vma))
77862+ goto Einval;
77863+#endif
77864+
77865 /* We can't remap across vm area boundaries */
77866 if (old_len > vma->vm_end - addr)
77867 goto Efault;
77868@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned long addr,
77869 unsigned long ret = -EINVAL;
77870 unsigned long charged = 0;
77871 unsigned long map_flags;
77872+ unsigned long pax_task_size = TASK_SIZE;
77873
77874 if (new_addr & ~PAGE_MASK)
77875 goto out;
77876
77877- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
77878+#ifdef CONFIG_PAX_SEGMEXEC
77879+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77880+ pax_task_size = SEGMEXEC_TASK_SIZE;
77881+#endif
77882+
77883+ pax_task_size -= PAGE_SIZE;
77884+
77885+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
77886 goto out;
77887
77888 /* Check if the location we're moving into overlaps the
77889 * old location at all, and fail if it does.
77890 */
77891- if ((new_addr <= addr) && (new_addr+new_len) > addr)
77892- goto out;
77893-
77894- if ((addr <= new_addr) && (addr+old_len) > new_addr)
77895+ if (addr + old_len > new_addr && new_addr + new_len > addr)
77896 goto out;
77897
77898 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
77899@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long addr,
77900 struct vm_area_struct *vma;
77901 unsigned long ret = -EINVAL;
77902 unsigned long charged = 0;
77903+ unsigned long pax_task_size = TASK_SIZE;
77904
77905 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
77906 goto out;
77907@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long addr,
77908 if (!new_len)
77909 goto out;
77910
77911+#ifdef CONFIG_PAX_SEGMEXEC
77912+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77913+ pax_task_size = SEGMEXEC_TASK_SIZE;
77914+#endif
77915+
77916+ pax_task_size -= PAGE_SIZE;
77917+
77918+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77919+ old_len > pax_task_size || addr > pax_task_size-old_len)
77920+ goto out;
77921+
77922 if (flags & MREMAP_FIXED) {
77923 if (flags & MREMAP_MAYMOVE)
77924 ret = mremap_to(addr, old_len, new_addr, new_len);
77925@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long addr,
77926 addr + new_len);
77927 }
77928 ret = addr;
77929+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77930 goto out;
77931 }
77932 }
77933@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long addr,
77934 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
77935 if (ret)
77936 goto out;
77937+
77938+ map_flags = vma->vm_flags;
77939 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77940+ if (!(ret & ~PAGE_MASK)) {
77941+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77942+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77943+ }
77944 }
77945 out:
77946 if (ret & ~PAGE_MASK)
77947diff --git a/mm/nommu.c b/mm/nommu.c
77948index 406e8d4..53970d3 100644
77949--- a/mm/nommu.c
77950+++ b/mm/nommu.c
77951@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77952 int sysctl_overcommit_ratio = 50; /* default is 50% */
77953 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77954 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77955-int heap_stack_gap = 0;
77956
77957 atomic_long_t mmap_pages_allocated;
77958
77959@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77960 EXPORT_SYMBOL(find_vma);
77961
77962 /*
77963- * find a VMA
77964- * - we don't extend stack VMAs under NOMMU conditions
77965- */
77966-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77967-{
77968- return find_vma(mm, addr);
77969-}
77970-
77971-/*
77972 * expand a stack to a given address
77973 * - not supported under NOMMU conditions
77974 */
77975diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77976index 3ecab7e..594a471 100644
77977--- a/mm/page_alloc.c
77978+++ b/mm/page_alloc.c
77979@@ -289,7 +289,7 @@ out:
77980 * This usage means that zero-order pages may not be compound.
77981 */
77982
77983-static void free_compound_page(struct page *page)
77984+void free_compound_page(struct page *page)
77985 {
77986 __free_pages_ok(page, compound_order(page));
77987 }
77988@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
77989 int bad = 0;
77990 int wasMlocked = __TestClearPageMlocked(page);
77991
77992+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77993+ unsigned long index = 1UL << order;
77994+#endif
77995+
77996 kmemcheck_free_shadow(page, order);
77997
77998 for (i = 0 ; i < (1 << order) ; ++i)
77999@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78000 debug_check_no_obj_freed(page_address(page),
78001 PAGE_SIZE << order);
78002 }
78003+
78004+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78005+ for (; index; --index)
78006+ sanitize_highpage(page + index - 1);
78007+#endif
78008+
78009 arch_free_page(page, order);
78010 kernel_map_pages(page, 1 << order, 0);
78011
78012@@ -702,8 +712,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78013 arch_alloc_page(page, order);
78014 kernel_map_pages(page, 1 << order, 1);
78015
78016+#ifndef CONFIG_PAX_MEMORY_SANITIZE
78017 if (gfp_flags & __GFP_ZERO)
78018 prep_zero_page(page, order, gfp_flags);
78019+#endif
78020
78021 if (order && (gfp_flags & __GFP_COMP))
78022 prep_compound_page(page, order);
78023@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct page *page, int cold)
78024 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
78025 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
78026 }
78027+
78028+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78029+ sanitize_highpage(page);
78030+#endif
78031+
78032 arch_free_page(page, 0);
78033 kernel_map_pages(page, 1, 0);
78034
78035@@ -2179,6 +2196,8 @@ void show_free_areas(void)
78036 int cpu;
78037 struct zone *zone;
78038
78039+ pax_track_stack();
78040+
78041 for_each_populated_zone(zone) {
78042 show_node(zone);
78043 printk("%s per-cpu:\n", zone->name);
78044@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct pglist_data *pgdat,
78045 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
78046 }
78047 #else
78048-static void inline setup_usemap(struct pglist_data *pgdat,
78049+static inline void setup_usemap(struct pglist_data *pgdat,
78050 struct zone *zone, unsigned long zonesize) {}
78051 #endif /* CONFIG_SPARSEMEM */
78052
78053diff --git a/mm/percpu.c b/mm/percpu.c
78054index 3bfd6e2..60404b9 100644
78055--- a/mm/percpu.c
78056+++ b/mm/percpu.c
78057@@ -115,7 +115,7 @@ static unsigned int pcpu_first_unit_cpu __read_mostly;
78058 static unsigned int pcpu_last_unit_cpu __read_mostly;
78059
78060 /* the address of the first chunk which starts with the kernel static area */
78061-void *pcpu_base_addr __read_mostly;
78062+void *pcpu_base_addr __read_only;
78063 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78064
78065 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78066diff --git a/mm/rmap.c b/mm/rmap.c
78067index dd43373..d848cd7 100644
78068--- a/mm/rmap.c
78069+++ b/mm/rmap.c
78070@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78071 /* page_table_lock to protect against threads */
78072 spin_lock(&mm->page_table_lock);
78073 if (likely(!vma->anon_vma)) {
78074+
78075+#ifdef CONFIG_PAX_SEGMEXEC
78076+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78077+
78078+ if (vma_m) {
78079+ BUG_ON(vma_m->anon_vma);
78080+ vma_m->anon_vma = anon_vma;
78081+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
78082+ }
78083+#endif
78084+
78085 vma->anon_vma = anon_vma;
78086 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
78087 allocated = NULL;
78088diff --git a/mm/shmem.c b/mm/shmem.c
78089index 3e0005b..1d659a8 100644
78090--- a/mm/shmem.c
78091+++ b/mm/shmem.c
78092@@ -31,7 +31,7 @@
78093 #include <linux/swap.h>
78094 #include <linux/ima.h>
78095
78096-static struct vfsmount *shm_mnt;
78097+struct vfsmount *shm_mnt;
78098
78099 #ifdef CONFIG_SHMEM
78100 /*
78101@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
78102 goto unlock;
78103 }
78104 entry = shmem_swp_entry(info, index, NULL);
78105+ if (!entry)
78106+ goto unlock;
78107 if (entry->val) {
78108 /*
78109 * The more uptodate page coming down from a stacked
78110@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
78111 struct vm_area_struct pvma;
78112 struct page *page;
78113
78114+ pax_track_stack();
78115+
78116 spol = mpol_cond_copy(&mpol,
78117 mpol_shared_policy_lookup(&info->policy, idx));
78118
78119@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
78120
78121 info = SHMEM_I(inode);
78122 inode->i_size = len-1;
78123- if (len <= (char *)inode - (char *)info) {
78124+ if (len <= (char *)inode - (char *)info && len <= 64) {
78125 /* do it inline */
78126 memcpy(info, symname, len);
78127 inode->i_op = &shmem_symlink_inline_operations;
78128@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78129 int err = -ENOMEM;
78130
78131 /* Round up to L1_CACHE_BYTES to resist false sharing */
78132- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78133- L1_CACHE_BYTES), GFP_KERNEL);
78134+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78135 if (!sbinfo)
78136 return -ENOMEM;
78137
78138diff --git a/mm/slab.c b/mm/slab.c
78139index c8d466a..909e01e 100644
78140--- a/mm/slab.c
78141+++ b/mm/slab.c
78142@@ -174,7 +174,7 @@
78143
78144 /* Legal flag mask for kmem_cache_create(). */
78145 #if DEBUG
78146-# define CREATE_MASK (SLAB_RED_ZONE | \
78147+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
78148 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
78149 SLAB_CACHE_DMA | \
78150 SLAB_STORE_USER | \
78151@@ -182,7 +182,7 @@
78152 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78153 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
78154 #else
78155-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
78156+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
78157 SLAB_CACHE_DMA | \
78158 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
78159 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78160@@ -308,7 +308,7 @@ struct kmem_list3 {
78161 * Need this for bootstrapping a per node allocator.
78162 */
78163 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78164-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78165+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78166 #define CACHE_CACHE 0
78167 #define SIZE_AC MAX_NUMNODES
78168 #define SIZE_L3 (2 * MAX_NUMNODES)
78169@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78170 if ((x)->max_freeable < i) \
78171 (x)->max_freeable = i; \
78172 } while (0)
78173-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78174-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78175-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78176-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78177+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78178+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78179+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78180+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78181 #else
78182 #define STATS_INC_ACTIVE(x) do { } while (0)
78183 #define STATS_DEC_ACTIVE(x) do { } while (0)
78184@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78185 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78186 */
78187 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78188- const struct slab *slab, void *obj)
78189+ const struct slab *slab, const void *obj)
78190 {
78191 u32 offset = (obj - slab->s_mem);
78192 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78193@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
78194 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
78195 sizes[INDEX_AC].cs_size,
78196 ARCH_KMALLOC_MINALIGN,
78197- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78198+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78199 NULL);
78200
78201 if (INDEX_AC != INDEX_L3) {
78202@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
78203 kmem_cache_create(names[INDEX_L3].name,
78204 sizes[INDEX_L3].cs_size,
78205 ARCH_KMALLOC_MINALIGN,
78206- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78207+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78208 NULL);
78209 }
78210
78211@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
78212 sizes->cs_cachep = kmem_cache_create(names->name,
78213 sizes->cs_size,
78214 ARCH_KMALLOC_MINALIGN,
78215- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78216+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78217 NULL);
78218 }
78219 #ifdef CONFIG_ZONE_DMA
78220@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, void *p)
78221 }
78222 /* cpu stats */
78223 {
78224- unsigned long allochit = atomic_read(&cachep->allochit);
78225- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78226- unsigned long freehit = atomic_read(&cachep->freehit);
78227- unsigned long freemiss = atomic_read(&cachep->freemiss);
78228+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78229+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78230+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78231+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78232
78233 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78234 allochit, allocmiss, freehit, freemiss);
78235@@ -4471,15 +4471,70 @@ static const struct file_operations proc_slabstats_operations = {
78236
78237 static int __init slab_proc_init(void)
78238 {
78239- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
78240+ mode_t gr_mode = S_IRUGO;
78241+
78242+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78243+ gr_mode = S_IRUSR;
78244+#endif
78245+
78246+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
78247 #ifdef CONFIG_DEBUG_SLAB_LEAK
78248- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78249+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
78250 #endif
78251 return 0;
78252 }
78253 module_init(slab_proc_init);
78254 #endif
78255
78256+void check_object_size(const void *ptr, unsigned long n, bool to)
78257+{
78258+
78259+#ifdef CONFIG_PAX_USERCOPY
78260+ struct page *page;
78261+ struct kmem_cache *cachep = NULL;
78262+ struct slab *slabp;
78263+ unsigned int objnr;
78264+ unsigned long offset;
78265+ const char *type;
78266+
78267+ if (!n)
78268+ return;
78269+
78270+ type = "<null>";
78271+ if (ZERO_OR_NULL_PTR(ptr))
78272+ goto report;
78273+
78274+ if (!virt_addr_valid(ptr))
78275+ return;
78276+
78277+ page = virt_to_head_page(ptr);
78278+
78279+ type = "<process stack>";
78280+ if (!PageSlab(page)) {
78281+ if (object_is_on_stack(ptr, n) == -1)
78282+ goto report;
78283+ return;
78284+ }
78285+
78286+ cachep = page_get_cache(page);
78287+ type = cachep->name;
78288+ if (!(cachep->flags & SLAB_USERCOPY))
78289+ goto report;
78290+
78291+ slabp = page_get_slab(page);
78292+ objnr = obj_to_index(cachep, slabp, ptr);
78293+ BUG_ON(objnr >= cachep->num);
78294+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78295+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
78296+ return;
78297+
78298+report:
78299+ pax_report_usercopy(ptr, n, to, type);
78300+#endif
78301+
78302+}
78303+EXPORT_SYMBOL(check_object_size);
78304+
78305 /**
78306 * ksize - get the actual amount of memory allocated for a given object
78307 * @objp: Pointer to the object
78308diff --git a/mm/slob.c b/mm/slob.c
78309index 837ebd6..4712174 100644
78310--- a/mm/slob.c
78311+++ b/mm/slob.c
78312@@ -29,7 +29,7 @@
78313 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
78314 * alloc_pages() directly, allocating compound pages so the page order
78315 * does not have to be separately tracked, and also stores the exact
78316- * allocation size in page->private so that it can be used to accurately
78317+ * allocation size in slob_page->size so that it can be used to accurately
78318 * provide ksize(). These objects are detected in kfree() because slob_page()
78319 * is false for them.
78320 *
78321@@ -58,6 +58,7 @@
78322 */
78323
78324 #include <linux/kernel.h>
78325+#include <linux/sched.h>
78326 #include <linux/slab.h>
78327 #include <linux/mm.h>
78328 #include <linux/swap.h> /* struct reclaim_state */
78329@@ -100,7 +101,8 @@ struct slob_page {
78330 unsigned long flags; /* mandatory */
78331 atomic_t _count; /* mandatory */
78332 slobidx_t units; /* free units left in page */
78333- unsigned long pad[2];
78334+ unsigned long pad[1];
78335+ unsigned long size; /* size when >=PAGE_SIZE */
78336 slob_t *free; /* first free slob_t in page */
78337 struct list_head list; /* linked list of free pages */
78338 };
78339@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
78340 */
78341 static inline int is_slob_page(struct slob_page *sp)
78342 {
78343- return PageSlab((struct page *)sp);
78344+ return PageSlab((struct page *)sp) && !sp->size;
78345 }
78346
78347 static inline void set_slob_page(struct slob_page *sp)
78348@@ -148,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
78349
78350 static inline struct slob_page *slob_page(const void *addr)
78351 {
78352- return (struct slob_page *)virt_to_page(addr);
78353+ return (struct slob_page *)virt_to_head_page(addr);
78354 }
78355
78356 /*
78357@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78358 /*
78359 * Return the size of a slob block.
78360 */
78361-static slobidx_t slob_units(slob_t *s)
78362+static slobidx_t slob_units(const slob_t *s)
78363 {
78364 if (s->units > 0)
78365 return s->units;
78366@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
78367 /*
78368 * Return the next free slob block pointer after this one.
78369 */
78370-static slob_t *slob_next(slob_t *s)
78371+static slob_t *slob_next(const slob_t *s)
78372 {
78373 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78374 slobidx_t next;
78375@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
78376 /*
78377 * Returns true if s is the last free block in its page.
78378 */
78379-static int slob_last(slob_t *s)
78380+static int slob_last(const slob_t *s)
78381 {
78382 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78383 }
78384@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78385 if (!page)
78386 return NULL;
78387
78388+ set_slob_page(page);
78389 return page_address(page);
78390 }
78391
78392@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78393 if (!b)
78394 return NULL;
78395 sp = slob_page(b);
78396- set_slob_page(sp);
78397
78398 spin_lock_irqsave(&slob_lock, flags);
78399 sp->units = SLOB_UNITS(PAGE_SIZE);
78400 sp->free = b;
78401+ sp->size = 0;
78402 INIT_LIST_HEAD(&sp->list);
78403 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78404 set_slob_page_free(sp, slob_list);
78405@@ -475,10 +478,9 @@ out:
78406 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
78407 #endif
78408
78409-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78410+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
78411 {
78412- unsigned int *m;
78413- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78414+ slob_t *m;
78415 void *ret;
78416
78417 lockdep_trace_alloc(gfp);
78418@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78419
78420 if (!m)
78421 return NULL;
78422- *m = size;
78423+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78424+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78425+ m[0].units = size;
78426+ m[1].units = align;
78427 ret = (void *)m + align;
78428
78429 trace_kmalloc_node(_RET_IP_, ret,
78430@@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78431
78432 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
78433 if (ret) {
78434- struct page *page;
78435- page = virt_to_page(ret);
78436- page->private = size;
78437+ struct slob_page *sp;
78438+ sp = slob_page(ret);
78439+ sp->size = size;
78440 }
78441
78442 trace_kmalloc_node(_RET_IP_, ret,
78443 size, PAGE_SIZE << order, gfp, node);
78444 }
78445
78446- kmemleak_alloc(ret, size, 1, gfp);
78447+ return ret;
78448+}
78449+
78450+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78451+{
78452+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78453+ void *ret = __kmalloc_node_align(size, gfp, node, align);
78454+
78455+ if (!ZERO_OR_NULL_PTR(ret))
78456+ kmemleak_alloc(ret, size, 1, gfp);
78457 return ret;
78458 }
78459 EXPORT_SYMBOL(__kmalloc_node);
78460@@ -528,13 +542,92 @@ void kfree(const void *block)
78461 sp = slob_page(block);
78462 if (is_slob_page(sp)) {
78463 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78464- unsigned int *m = (unsigned int *)(block - align);
78465- slob_free(m, *m + align);
78466- } else
78467+ slob_t *m = (slob_t *)(block - align);
78468+ slob_free(m, m[0].units + align);
78469+ } else {
78470+ clear_slob_page(sp);
78471+ free_slob_page(sp);
78472+ sp->size = 0;
78473 put_page(&sp->page);
78474+ }
78475 }
78476 EXPORT_SYMBOL(kfree);
78477
78478+void check_object_size(const void *ptr, unsigned long n, bool to)
78479+{
78480+
78481+#ifdef CONFIG_PAX_USERCOPY
78482+ struct slob_page *sp;
78483+ const slob_t *free;
78484+ const void *base;
78485+ unsigned long flags;
78486+ const char *type;
78487+
78488+ if (!n)
78489+ return;
78490+
78491+ type = "<null>";
78492+ if (ZERO_OR_NULL_PTR(ptr))
78493+ goto report;
78494+
78495+ if (!virt_addr_valid(ptr))
78496+ return;
78497+
78498+ type = "<process stack>";
78499+ sp = slob_page(ptr);
78500+ if (!PageSlab((struct page*)sp)) {
78501+ if (object_is_on_stack(ptr, n) == -1)
78502+ goto report;
78503+ return;
78504+ }
78505+
78506+ type = "<slob>";
78507+ if (sp->size) {
78508+ base = page_address(&sp->page);
78509+ if (base <= ptr && n <= sp->size - (ptr - base))
78510+ return;
78511+ goto report;
78512+ }
78513+
78514+ /* some tricky double walking to find the chunk */
78515+ spin_lock_irqsave(&slob_lock, flags);
78516+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78517+ free = sp->free;
78518+
78519+ while (!slob_last(free) && (void *)free <= ptr) {
78520+ base = free + slob_units(free);
78521+ free = slob_next(free);
78522+ }
78523+
78524+ while (base < (void *)free) {
78525+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78526+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
78527+ int offset;
78528+
78529+ if (ptr < base + align)
78530+ break;
78531+
78532+ offset = ptr - base - align;
78533+ if (offset >= m) {
78534+ base += size;
78535+ continue;
78536+ }
78537+
78538+ if (n > m - offset)
78539+ break;
78540+
78541+ spin_unlock_irqrestore(&slob_lock, flags);
78542+ return;
78543+ }
78544+
78545+ spin_unlock_irqrestore(&slob_lock, flags);
78546+report:
78547+ pax_report_usercopy(ptr, n, to, type);
78548+#endif
78549+
78550+}
78551+EXPORT_SYMBOL(check_object_size);
78552+
78553 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78554 size_t ksize(const void *block)
78555 {
78556@@ -547,10 +640,10 @@ size_t ksize(const void *block)
78557 sp = slob_page(block);
78558 if (is_slob_page(sp)) {
78559 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78560- unsigned int *m = (unsigned int *)(block - align);
78561- return SLOB_UNITS(*m) * SLOB_UNIT;
78562+ slob_t *m = (slob_t *)(block - align);
78563+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78564 } else
78565- return sp->page.private;
78566+ return sp->size;
78567 }
78568 EXPORT_SYMBOL(ksize);
78569
78570@@ -566,8 +659,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78571 {
78572 struct kmem_cache *c;
78573
78574+#ifdef CONFIG_PAX_USERCOPY
78575+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
78576+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
78577+#else
78578 c = slob_alloc(sizeof(struct kmem_cache),
78579 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
78580+#endif
78581
78582 if (c) {
78583 c->name = name;
78584@@ -605,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78585 {
78586 void *b;
78587
78588+#ifdef CONFIG_PAX_USERCOPY
78589+ b = __kmalloc_node_align(c->size, flags, node, c->align);
78590+#else
78591 if (c->size < PAGE_SIZE) {
78592 b = slob_alloc(c->size, flags, c->align, node);
78593 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
78594 SLOB_UNITS(c->size) * SLOB_UNIT,
78595 flags, node);
78596 } else {
78597+ struct slob_page *sp;
78598+
78599 b = slob_new_pages(flags, get_order(c->size), node);
78600+ sp = slob_page(b);
78601+ sp->size = c->size;
78602 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
78603 PAGE_SIZE << get_order(c->size),
78604 flags, node);
78605 }
78606+#endif
78607
78608 if (c->ctor)
78609 c->ctor(b);
78610@@ -627,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78611
78612 static void __kmem_cache_free(void *b, int size)
78613 {
78614- if (size < PAGE_SIZE)
78615+ struct slob_page *sp = slob_page(b);
78616+
78617+ if (is_slob_page(sp))
78618 slob_free(b, size);
78619- else
78620+ else {
78621+ clear_slob_page(sp);
78622+ free_slob_page(sp);
78623+ sp->size = 0;
78624 slob_free_pages(b, get_order(size));
78625+ }
78626 }
78627
78628 static void kmem_rcu_free(struct rcu_head *head)
78629@@ -643,18 +755,32 @@ static void kmem_rcu_free(struct rcu_head *head)
78630
78631 void kmem_cache_free(struct kmem_cache *c, void *b)
78632 {
78633+ int size = c->size;
78634+
78635+#ifdef CONFIG_PAX_USERCOPY
78636+ if (size + c->align < PAGE_SIZE) {
78637+ size += c->align;
78638+ b -= c->align;
78639+ }
78640+#endif
78641+
78642 kmemleak_free_recursive(b, c->flags);
78643 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78644 struct slob_rcu *slob_rcu;
78645- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78646+ slob_rcu = b + (size - sizeof(struct slob_rcu));
78647 INIT_RCU_HEAD(&slob_rcu->head);
78648- slob_rcu->size = c->size;
78649+ slob_rcu->size = size;
78650 call_rcu(&slob_rcu->head, kmem_rcu_free);
78651 } else {
78652- __kmem_cache_free(b, c->size);
78653+ __kmem_cache_free(b, size);
78654 }
78655
78656+#ifdef CONFIG_PAX_USERCOPY
78657+ trace_kfree(_RET_IP_, b);
78658+#else
78659 trace_kmem_cache_free(_RET_IP_, b);
78660+#endif
78661+
78662 }
78663 EXPORT_SYMBOL(kmem_cache_free);
78664
78665diff --git a/mm/slub.c b/mm/slub.c
78666index 4996fc7..87e01d0 100644
78667--- a/mm/slub.c
78668+++ b/mm/slub.c
78669@@ -201,7 +201,7 @@ struct track {
78670
78671 enum track_item { TRACK_ALLOC, TRACK_FREE };
78672
78673-#ifdef CONFIG_SLUB_DEBUG
78674+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78675 static int sysfs_slab_add(struct kmem_cache *);
78676 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78677 static void sysfs_slab_remove(struct kmem_cache *);
78678@@ -410,7 +410,7 @@ static void print_track(const char *s, struct track *t)
78679 if (!t->addr)
78680 return;
78681
78682- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78683+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78684 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78685 }
78686
78687@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
78688
78689 page = virt_to_head_page(x);
78690
78691+ BUG_ON(!PageSlab(page));
78692+
78693 slab_free(s, page, x, _RET_IP_);
78694
78695 trace_kmem_cache_free(_RET_IP_, x);
78696@@ -1937,7 +1939,7 @@ static int slub_min_objects;
78697 * Merge control. If this is set then no merging of slab caches will occur.
78698 * (Could be removed. This was introduced to pacify the merge skeptics.)
78699 */
78700-static int slub_nomerge;
78701+static int slub_nomerge = 1;
78702
78703 /*
78704 * Calculate the order of allocation given an slab object size.
78705@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
78706 * list to avoid pounding the page allocator excessively.
78707 */
78708 set_min_partial(s, ilog2(s->size));
78709- s->refcount = 1;
78710+ atomic_set(&s->refcount, 1);
78711 #ifdef CONFIG_NUMA
78712 s->remote_node_defrag_ratio = 1000;
78713 #endif
78714@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
78715 void kmem_cache_destroy(struct kmem_cache *s)
78716 {
78717 down_write(&slub_lock);
78718- s->refcount--;
78719- if (!s->refcount) {
78720+ if (atomic_dec_and_test(&s->refcount)) {
78721 list_del(&s->list);
78722 up_write(&slub_lock);
78723 if (kmem_cache_close(s)) {
78724@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(char *str)
78725 __setup("slub_nomerge", setup_slub_nomerge);
78726
78727 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
78728- const char *name, int size, gfp_t gfp_flags)
78729+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
78730 {
78731- unsigned int flags = 0;
78732-
78733 if (gfp_flags & SLUB_DMA)
78734- flags = SLAB_CACHE_DMA;
78735+ flags |= SLAB_CACHE_DMA;
78736
78737 /*
78738 * This function is called with IRQs disabled during early-boot on
78739@@ -2915,6 +2914,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78740 EXPORT_SYMBOL(__kmalloc_node);
78741 #endif
78742
78743+void check_object_size(const void *ptr, unsigned long n, bool to)
78744+{
78745+
78746+#ifdef CONFIG_PAX_USERCOPY
78747+ struct page *page;
78748+ struct kmem_cache *s = NULL;
78749+ unsigned long offset;
78750+ const char *type;
78751+
78752+ if (!n)
78753+ return;
78754+
78755+ type = "<null>";
78756+ if (ZERO_OR_NULL_PTR(ptr))
78757+ goto report;
78758+
78759+ if (!virt_addr_valid(ptr))
78760+ return;
78761+
78762+ page = get_object_page(ptr);
78763+
78764+ type = "<process stack>";
78765+ if (!page) {
78766+ if (object_is_on_stack(ptr, n) == -1)
78767+ goto report;
78768+ return;
78769+ }
78770+
78771+ s = page->slab;
78772+ type = s->name;
78773+ if (!(s->flags & SLAB_USERCOPY))
78774+ goto report;
78775+
78776+ offset = (ptr - page_address(page)) % s->size;
78777+ if (offset <= s->objsize && n <= s->objsize - offset)
78778+ return;
78779+
78780+report:
78781+ pax_report_usercopy(ptr, n, to, type);
78782+#endif
78783+
78784+}
78785+EXPORT_SYMBOL(check_object_size);
78786+
78787 size_t ksize(const void *object)
78788 {
78789 struct page *page;
78790@@ -3185,8 +3228,8 @@ void __init kmem_cache_init(void)
78791 * kmem_cache_open for slab_state == DOWN.
78792 */
78793 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
78794- sizeof(struct kmem_cache_node), GFP_NOWAIT);
78795- kmalloc_caches[0].refcount = -1;
78796+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
78797+ atomic_set(&kmalloc_caches[0].refcount, -1);
78798 caches++;
78799
78800 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
78801@@ -3198,18 +3241,18 @@ void __init kmem_cache_init(void)
78802 /* Caches that are not of the two-to-the-power-of size */
78803 if (KMALLOC_MIN_SIZE <= 32) {
78804 create_kmalloc_cache(&kmalloc_caches[1],
78805- "kmalloc-96", 96, GFP_NOWAIT);
78806+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
78807 caches++;
78808 }
78809 if (KMALLOC_MIN_SIZE <= 64) {
78810 create_kmalloc_cache(&kmalloc_caches[2],
78811- "kmalloc-192", 192, GFP_NOWAIT);
78812+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
78813 caches++;
78814 }
78815
78816 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78817 create_kmalloc_cache(&kmalloc_caches[i],
78818- "kmalloc", 1 << i, GFP_NOWAIT);
78819+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
78820 caches++;
78821 }
78822
78823@@ -3293,7 +3336,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78824 /*
78825 * We may have set a slab to be unmergeable during bootstrap.
78826 */
78827- if (s->refcount < 0)
78828+ if (atomic_read(&s->refcount) < 0)
78829 return 1;
78830
78831 return 0;
78832@@ -3353,7 +3396,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78833 if (s) {
78834 int cpu;
78835
78836- s->refcount++;
78837+ atomic_inc(&s->refcount);
78838 /*
78839 * Adjust the object sizes so that we clear
78840 * the complete object on kzalloc.
78841@@ -3372,7 +3415,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78842
78843 if (sysfs_slab_alias(s, name)) {
78844 down_write(&slub_lock);
78845- s->refcount--;
78846+ atomic_dec(&s->refcount);
78847 up_write(&slub_lock);
78848 goto err;
78849 }
78850@@ -4101,7 +4144,7 @@ SLAB_ATTR_RO(ctor);
78851
78852 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78853 {
78854- return sprintf(buf, "%d\n", s->refcount - 1);
78855+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78856 }
78857 SLAB_ATTR_RO(aliases);
78858
78859@@ -4503,7 +4546,7 @@ static void kmem_cache_release(struct kobject *kobj)
78860 kfree(s);
78861 }
78862
78863-static struct sysfs_ops slab_sysfs_ops = {
78864+static const struct sysfs_ops slab_sysfs_ops = {
78865 .show = slab_attr_show,
78866 .store = slab_attr_store,
78867 };
78868@@ -4522,7 +4565,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
78869 return 0;
78870 }
78871
78872-static struct kset_uevent_ops slab_uevent_ops = {
78873+static const struct kset_uevent_ops slab_uevent_ops = {
78874 .filter = uevent_filter,
78875 };
78876
78877@@ -4564,6 +4607,7 @@ static char *create_unique_id(struct kmem_cache *s)
78878 return name;
78879 }
78880
78881+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78882 static int sysfs_slab_add(struct kmem_cache *s)
78883 {
78884 int err;
78885@@ -4619,6 +4663,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78886 kobject_del(&s->kobj);
78887 kobject_put(&s->kobj);
78888 }
78889+#endif
78890
78891 /*
78892 * Need to buffer aliases during bootup until sysfs becomes
78893@@ -4632,6 +4677,7 @@ struct saved_alias {
78894
78895 static struct saved_alias *alias_list;
78896
78897+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78898 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78899 {
78900 struct saved_alias *al;
78901@@ -4654,6 +4700,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78902 alias_list = al;
78903 return 0;
78904 }
78905+#endif
78906
78907 static int __init slab_sysfs_init(void)
78908 {
78909@@ -4785,7 +4832,13 @@ static const struct file_operations proc_slabinfo_operations = {
78910
78911 static int __init slab_proc_init(void)
78912 {
78913- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
78914+ mode_t gr_mode = S_IRUGO;
78915+
78916+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78917+ gr_mode = S_IRUSR;
78918+#endif
78919+
78920+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
78921 return 0;
78922 }
78923 module_init(slab_proc_init);
78924diff --git a/mm/swap.c b/mm/swap.c
78925index 308e57d..5de19c0 100644
78926--- a/mm/swap.c
78927+++ b/mm/swap.c
78928@@ -30,6 +30,7 @@
78929 #include <linux/notifier.h>
78930 #include <linux/backing-dev.h>
78931 #include <linux/memcontrol.h>
78932+#include <linux/hugetlb.h>
78933
78934 #include "internal.h"
78935
78936@@ -65,6 +66,8 @@ static void put_compound_page(struct page *page)
78937 compound_page_dtor *dtor;
78938
78939 dtor = get_compound_page_dtor(page);
78940+ if (!PageHuge(page))
78941+ BUG_ON(dtor != free_compound_page);
78942 (*dtor)(page);
78943 }
78944 }
78945diff --git a/mm/util.c b/mm/util.c
78946index b377ce4..3a891af 100644
78947--- a/mm/util.c
78948+++ b/mm/util.c
78949@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
78950 void arch_pick_mmap_layout(struct mm_struct *mm)
78951 {
78952 mm->mmap_base = TASK_UNMAPPED_BASE;
78953+
78954+#ifdef CONFIG_PAX_RANDMMAP
78955+ if (mm->pax_flags & MF_PAX_RANDMMAP)
78956+ mm->mmap_base += mm->delta_mmap;
78957+#endif
78958+
78959 mm->get_unmapped_area = arch_get_unmapped_area;
78960 mm->unmap_area = arch_unmap_area;
78961 }
78962diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78963index f34ffd0..e60c44f 100644
78964--- a/mm/vmalloc.c
78965+++ b/mm/vmalloc.c
78966@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78967
78968 pte = pte_offset_kernel(pmd, addr);
78969 do {
78970- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78971- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78972+
78973+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78974+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78975+ BUG_ON(!pte_exec(*pte));
78976+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78977+ continue;
78978+ }
78979+#endif
78980+
78981+ {
78982+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78983+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78984+ }
78985 } while (pte++, addr += PAGE_SIZE, addr != end);
78986 }
78987
78988@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78989 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
78990 {
78991 pte_t *pte;
78992+ int ret = -ENOMEM;
78993
78994 /*
78995 * nr is a running index into the array which helps higher level
78996@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78997 pte = pte_alloc_kernel(pmd, addr);
78998 if (!pte)
78999 return -ENOMEM;
79000+
79001+ pax_open_kernel();
79002 do {
79003 struct page *page = pages[*nr];
79004
79005- if (WARN_ON(!pte_none(*pte)))
79006- return -EBUSY;
79007- if (WARN_ON(!page))
79008- return -ENOMEM;
79009+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79010+ if (!(pgprot_val(prot) & _PAGE_NX))
79011+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
79012+ else
79013+#endif
79014+
79015+ if (WARN_ON(!pte_none(*pte))) {
79016+ ret = -EBUSY;
79017+ goto out;
79018+ }
79019+ if (WARN_ON(!page)) {
79020+ ret = -ENOMEM;
79021+ goto out;
79022+ }
79023 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79024 (*nr)++;
79025 } while (pte++, addr += PAGE_SIZE, addr != end);
79026- return 0;
79027+ ret = 0;
79028+out:
79029+ pax_close_kernel();
79030+ return ret;
79031 }
79032
79033 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79034@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void *x)
79035 * and fall back on vmalloc() if that fails. Others
79036 * just put it in the vmalloc space.
79037 */
79038-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79039+#ifdef CONFIG_MODULES
79040+#ifdef MODULES_VADDR
79041 unsigned long addr = (unsigned long)x;
79042 if (addr >= MODULES_VADDR && addr < MODULES_END)
79043 return 1;
79044 #endif
79045+
79046+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79047+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79048+ return 1;
79049+#endif
79050+
79051+#endif
79052+
79053 return is_vmalloc_addr(x);
79054 }
79055
79056@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79057
79058 if (!pgd_none(*pgd)) {
79059 pud_t *pud = pud_offset(pgd, addr);
79060+#ifdef CONFIG_X86
79061+ if (!pud_large(*pud))
79062+#endif
79063 if (!pud_none(*pud)) {
79064 pmd_t *pmd = pmd_offset(pud, addr);
79065+#ifdef CONFIG_X86
79066+ if (!pmd_large(*pmd))
79067+#endif
79068 if (!pmd_none(*pmd)) {
79069 pte_t *ptep, pte;
79070
79071@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vmap_area *va)
79072 struct rb_node *tmp;
79073
79074 while (*p) {
79075- struct vmap_area *tmp;
79076+ struct vmap_area *varea;
79077
79078 parent = *p;
79079- tmp = rb_entry(parent, struct vmap_area, rb_node);
79080- if (va->va_start < tmp->va_end)
79081+ varea = rb_entry(parent, struct vmap_area, rb_node);
79082+ if (va->va_start < varea->va_end)
79083 p = &(*p)->rb_left;
79084- else if (va->va_end > tmp->va_start)
79085+ else if (va->va_end > varea->va_start)
79086 p = &(*p)->rb_right;
79087 else
79088 BUG();
79089@@ -1245,6 +1287,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79090 struct vm_struct *area;
79091
79092 BUG_ON(in_interrupt());
79093+
79094+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79095+ if (flags & VM_KERNEXEC) {
79096+ if (start != VMALLOC_START || end != VMALLOC_END)
79097+ return NULL;
79098+ start = (unsigned long)MODULES_EXEC_VADDR;
79099+ end = (unsigned long)MODULES_EXEC_END;
79100+ }
79101+#endif
79102+
79103 if (flags & VM_IOREMAP) {
79104 int bit = fls(size);
79105
79106@@ -1484,6 +1536,11 @@ void *vmap(struct page **pages, unsigned int count,
79107 if (count > totalram_pages)
79108 return NULL;
79109
79110+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79111+ if (!(pgprot_val(prot) & _PAGE_NX))
79112+ flags |= VM_KERNEXEC;
79113+#endif
79114+
79115 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79116 __builtin_return_address(0));
79117 if (!area)
79118@@ -1594,6 +1651,14 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79119 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79120 return NULL;
79121
79122+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79123+ if (!(pgprot_val(prot) & _PAGE_NX))
79124+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79125+ VMALLOC_START, VMALLOC_END, node,
79126+ gfp_mask, caller);
79127+ else
79128+#endif
79129+
79130 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79131 VMALLOC_START, VMALLOC_END, node,
79132 gfp_mask, caller);
79133@@ -1619,6 +1684,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79134 return addr;
79135 }
79136
79137+#undef __vmalloc
79138 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
79139 {
79140 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
79141@@ -1635,6 +1701,7 @@ EXPORT_SYMBOL(__vmalloc);
79142 * For tight control over page level allocator and protection flags
79143 * use __vmalloc() instead.
79144 */
79145+#undef vmalloc
79146 void *vmalloc(unsigned long size)
79147 {
79148 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79149@@ -1649,6 +1716,7 @@ EXPORT_SYMBOL(vmalloc);
79150 * The resulting memory area is zeroed so it can be mapped to userspace
79151 * without leaking data.
79152 */
79153+#undef vmalloc_user
79154 void *vmalloc_user(unsigned long size)
79155 {
79156 struct vm_struct *area;
79157@@ -1676,6 +1744,7 @@ EXPORT_SYMBOL(vmalloc_user);
79158 * For tight control over page level allocator and protection flags
79159 * use __vmalloc() instead.
79160 */
79161+#undef vmalloc_node
79162 void *vmalloc_node(unsigned long size, int node)
79163 {
79164 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79165@@ -1698,10 +1767,10 @@ EXPORT_SYMBOL(vmalloc_node);
79166 * For tight control over page level allocator and protection flags
79167 * use __vmalloc() instead.
79168 */
79169-
79170+#undef vmalloc_exec
79171 void *vmalloc_exec(unsigned long size)
79172 {
79173- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79174+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79175 -1, __builtin_return_address(0));
79176 }
79177
79178@@ -1720,6 +1789,7 @@ void *vmalloc_exec(unsigned long size)
79179 * Allocate enough 32bit PA addressable pages to cover @size from the
79180 * page level allocator and map them into contiguous kernel virtual space.
79181 */
79182+#undef vmalloc_32
79183 void *vmalloc_32(unsigned long size)
79184 {
79185 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
79186@@ -1734,6 +1804,7 @@ EXPORT_SYMBOL(vmalloc_32);
79187 * The resulting memory area is 32bit addressable and zeroed so it can be
79188 * mapped to userspace without leaking data.
79189 */
79190+#undef vmalloc_32_user
79191 void *vmalloc_32_user(unsigned long size)
79192 {
79193 struct vm_struct *area;
79194@@ -1998,6 +2069,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79195 unsigned long uaddr = vma->vm_start;
79196 unsigned long usize = vma->vm_end - vma->vm_start;
79197
79198+ BUG_ON(vma->vm_mirror);
79199+
79200 if ((PAGE_SIZE-1) & (unsigned long)addr)
79201 return -EINVAL;
79202
79203diff --git a/mm/vmstat.c b/mm/vmstat.c
79204index 42d76c6..5643dc4 100644
79205--- a/mm/vmstat.c
79206+++ b/mm/vmstat.c
79207@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
79208 *
79209 * vm_stat contains the global counters
79210 */
79211-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79212+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79213 EXPORT_SYMBOL(vm_stat);
79214
79215 #ifdef CONFIG_SMP
79216@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
79217 v = p->vm_stat_diff[i];
79218 p->vm_stat_diff[i] = 0;
79219 local_irq_restore(flags);
79220- atomic_long_add(v, &zone->vm_stat[i]);
79221+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79222 global_diff[i] += v;
79223 #ifdef CONFIG_NUMA
79224 /* 3 seconds idle till flush */
79225@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
79226
79227 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79228 if (global_diff[i])
79229- atomic_long_add(global_diff[i], &vm_stat[i]);
79230+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79231 }
79232
79233 #endif
79234@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
79235 start_cpu_timer(cpu);
79236 #endif
79237 #ifdef CONFIG_PROC_FS
79238- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79239- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79240- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79241- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79242+ {
79243+ mode_t gr_mode = S_IRUGO;
79244+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79245+ gr_mode = S_IRUSR;
79246+#endif
79247+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79248+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79249+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79250+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79251+#else
79252+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79253+#endif
79254+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79255+ }
79256 #endif
79257 return 0;
79258 }
79259diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79260index a29c5ab..6143f20 100644
79261--- a/net/8021q/vlan.c
79262+++ b/net/8021q/vlan.c
79263@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79264 err = -EPERM;
79265 if (!capable(CAP_NET_ADMIN))
79266 break;
79267- if ((args.u.name_type >= 0) &&
79268- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79269+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79270 struct vlan_net *vn;
79271
79272 vn = net_generic(net, vlan_net_id);
79273diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79274index a2d2984..f9eb711 100644
79275--- a/net/9p/trans_fd.c
79276+++ b/net/9p/trans_fd.c
79277@@ -419,7 +419,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79278 oldfs = get_fs();
79279 set_fs(get_ds());
79280 /* The cast to a user pointer is valid due to the set_fs() */
79281- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79282+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79283 set_fs(oldfs);
79284
79285 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79286diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79287index 02cc7e7..4514f1b 100644
79288--- a/net/atm/atm_misc.c
79289+++ b/net/atm/atm_misc.c
79290@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int truesize)
79291 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79292 return 1;
79293 atm_return(vcc,truesize);
79294- atomic_inc(&vcc->stats->rx_drop);
79295+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79296 return 0;
79297 }
79298
79299@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
79300 }
79301 }
79302 atm_return(vcc,guess);
79303- atomic_inc(&vcc->stats->rx_drop);
79304+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79305 return NULL;
79306 }
79307
79308@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafprm *tp)
79309
79310 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79311 {
79312-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79313+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79314 __SONET_ITEMS
79315 #undef __HANDLE_ITEM
79316 }
79317@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79318
79319 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79320 {
79321-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
79322+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79323 __SONET_ITEMS
79324 #undef __HANDLE_ITEM
79325 }
79326diff --git a/net/atm/lec.h b/net/atm/lec.h
79327index 9d14d19..5c145f3 100644
79328--- a/net/atm/lec.h
79329+++ b/net/atm/lec.h
79330@@ -48,7 +48,7 @@ struct lane2_ops {
79331 const u8 *tlvs, u32 sizeoftlvs);
79332 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79333 const u8 *tlvs, u32 sizeoftlvs);
79334-};
79335+} __no_const;
79336
79337 /*
79338 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79339diff --git a/net/atm/mpc.h b/net/atm/mpc.h
79340index 0919a88..a23d54e 100644
79341--- a/net/atm/mpc.h
79342+++ b/net/atm/mpc.h
79343@@ -33,7 +33,7 @@ struct mpoa_client {
79344 struct mpc_parameters parameters; /* parameters for this client */
79345
79346 const struct net_device_ops *old_ops;
79347- struct net_device_ops new_ops;
79348+ net_device_ops_no_const new_ops;
79349 };
79350
79351
79352diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
79353index 4504a4b..1733f1e 100644
79354--- a/net/atm/mpoa_caches.c
79355+++ b/net/atm/mpoa_caches.c
79356@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_client *client)
79357 struct timeval now;
79358 struct k_message msg;
79359
79360+ pax_track_stack();
79361+
79362 do_gettimeofday(&now);
79363
79364 write_lock_irq(&client->egress_lock);
79365diff --git a/net/atm/proc.c b/net/atm/proc.c
79366index ab8419a..aa91497 100644
79367--- a/net/atm/proc.c
79368+++ b/net/atm/proc.c
79369@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79370 const struct k_atm_aal_stats *stats)
79371 {
79372 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79373- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
79374- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
79375- atomic_read(&stats->rx_drop));
79376+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79377+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79378+ atomic_read_unchecked(&stats->rx_drop));
79379 }
79380
79381 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79382@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
79383 {
79384 struct sock *sk = sk_atm(vcc);
79385
79386+#ifdef CONFIG_GRKERNSEC_HIDESYM
79387+ seq_printf(seq, "%p ", NULL);
79388+#else
79389 seq_printf(seq, "%p ", vcc);
79390+#endif
79391+
79392 if (!vcc->dev)
79393 seq_printf(seq, "Unassigned ");
79394 else
79395@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
79396 {
79397 if (!vcc->dev)
79398 seq_printf(seq, sizeof(void *) == 4 ?
79399+#ifdef CONFIG_GRKERNSEC_HIDESYM
79400+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
79401+#else
79402 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
79403+#endif
79404 else
79405 seq_printf(seq, "%3d %3d %5d ",
79406 vcc->dev->number, vcc->vpi, vcc->vci);
79407diff --git a/net/atm/resources.c b/net/atm/resources.c
79408index 56b7322..c48b84e 100644
79409--- a/net/atm/resources.c
79410+++ b/net/atm/resources.c
79411@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *dev)
79412 static void copy_aal_stats(struct k_atm_aal_stats *from,
79413 struct atm_aal_stats *to)
79414 {
79415-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79416+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79417 __AAL_STAT_ITEMS
79418 #undef __HANDLE_ITEM
79419 }
79420@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79421 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79422 struct atm_aal_stats *to)
79423 {
79424-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79425+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79426 __AAL_STAT_ITEMS
79427 #undef __HANDLE_ITEM
79428 }
79429diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
79430index 8567d47..bba2292 100644
79431--- a/net/bridge/br_private.h
79432+++ b/net/bridge/br_private.h
79433@@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
79434
79435 #ifdef CONFIG_SYSFS
79436 /* br_sysfs_if.c */
79437-extern struct sysfs_ops brport_sysfs_ops;
79438+extern const struct sysfs_ops brport_sysfs_ops;
79439 extern int br_sysfs_addif(struct net_bridge_port *p);
79440
79441 /* br_sysfs_br.c */
79442diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
79443index 9a52ac5..c97538e 100644
79444--- a/net/bridge/br_stp_if.c
79445+++ b/net/bridge/br_stp_if.c
79446@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridge *br)
79447 char *envp[] = { NULL };
79448
79449 if (br->stp_enabled == BR_USER_STP) {
79450- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
79451+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
79452 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
79453 br->dev->name, r);
79454
79455diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
79456index 820643a..ce77fb3 100644
79457--- a/net/bridge/br_sysfs_if.c
79458+++ b/net/bridge/br_sysfs_if.c
79459@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobject * kobj,
79460 return ret;
79461 }
79462
79463-struct sysfs_ops brport_sysfs_ops = {
79464+const struct sysfs_ops brport_sysfs_ops = {
79465 .show = brport_show,
79466 .store = brport_store,
79467 };
79468diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79469index d73d47f..72df42a 100644
79470--- a/net/bridge/netfilter/ebtables.c
79471+++ b/net/bridge/netfilter/ebtables.c
79472@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
79473 unsigned int entries_size, nentries;
79474 char *entries;
79475
79476+ pax_track_stack();
79477+
79478 if (cmd == EBT_SO_GET_ENTRIES) {
79479 entries_size = t->private->entries_size;
79480 nentries = t->private->nentries;
79481diff --git a/net/can/bcm.c b/net/can/bcm.c
79482index 2ffd2e0..72a7486 100644
79483--- a/net/can/bcm.c
79484+++ b/net/can/bcm.c
79485@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file *m, void *v)
79486 struct bcm_sock *bo = bcm_sk(sk);
79487 struct bcm_op *op;
79488
79489+#ifdef CONFIG_GRKERNSEC_HIDESYM
79490+ seq_printf(m, ">>> socket %p", NULL);
79491+ seq_printf(m, " / sk %p", NULL);
79492+ seq_printf(m, " / bo %p", NULL);
79493+#else
79494 seq_printf(m, ">>> socket %p", sk->sk_socket);
79495 seq_printf(m, " / sk %p", sk);
79496 seq_printf(m, " / bo %p", bo);
79497+#endif
79498 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
79499 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
79500 seq_printf(m, " <<<\n");
79501diff --git a/net/compat.c b/net/compat.c
79502index 9559afc..ccd74e1 100644
79503--- a/net/compat.c
79504+++ b/net/compat.c
79505@@ -69,9 +69,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79506 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79507 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79508 return -EFAULT;
79509- kmsg->msg_name = compat_ptr(tmp1);
79510- kmsg->msg_iov = compat_ptr(tmp2);
79511- kmsg->msg_control = compat_ptr(tmp3);
79512+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79513+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79514+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79515 return 0;
79516 }
79517
79518@@ -94,7 +94,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79519 kern_msg->msg_name = NULL;
79520
79521 tot_len = iov_from_user_compat_to_kern(kern_iov,
79522- (struct compat_iovec __user *)kern_msg->msg_iov,
79523+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
79524 kern_msg->msg_iovlen);
79525 if (tot_len >= 0)
79526 kern_msg->msg_iov = kern_iov;
79527@@ -114,20 +114,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79528
79529 #define CMSG_COMPAT_FIRSTHDR(msg) \
79530 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79531- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79532+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79533 (struct compat_cmsghdr __user *)NULL)
79534
79535 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79536 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79537 (ucmlen) <= (unsigned long) \
79538 ((mhdr)->msg_controllen - \
79539- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79540+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79541
79542 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79543 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79544 {
79545 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79546- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79547+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79548 msg->msg_controllen)
79549 return NULL;
79550 return (struct compat_cmsghdr __user *)ptr;
79551@@ -219,7 +219,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79552 {
79553 struct compat_timeval ctv;
79554 struct compat_timespec cts[3];
79555- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79556+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79557 struct compat_cmsghdr cmhdr;
79558 int cmlen;
79559
79560@@ -271,7 +271,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79561
79562 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79563 {
79564- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79565+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79566 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79567 int fdnum = scm->fp->count;
79568 struct file **fp = scm->fp->fp;
79569@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79570 len = sizeof(ktime);
79571 old_fs = get_fs();
79572 set_fs(KERNEL_DS);
79573- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79574+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79575 set_fs(old_fs);
79576
79577 if (!err) {
79578@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79579 case MCAST_JOIN_GROUP:
79580 case MCAST_LEAVE_GROUP:
79581 {
79582- struct compat_group_req __user *gr32 = (void *)optval;
79583+ struct compat_group_req __user *gr32 = (void __user *)optval;
79584 struct group_req __user *kgr =
79585 compat_alloc_user_space(sizeof(struct group_req));
79586 u32 interface;
79587@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79588 case MCAST_BLOCK_SOURCE:
79589 case MCAST_UNBLOCK_SOURCE:
79590 {
79591- struct compat_group_source_req __user *gsr32 = (void *)optval;
79592+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79593 struct group_source_req __user *kgsr = compat_alloc_user_space(
79594 sizeof(struct group_source_req));
79595 u32 interface;
79596@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79597 }
79598 case MCAST_MSFILTER:
79599 {
79600- struct compat_group_filter __user *gf32 = (void *)optval;
79601+ struct compat_group_filter __user *gf32 = (void __user *)optval;
79602 struct group_filter __user *kgf;
79603 u32 interface, fmode, numsrc;
79604
79605diff --git a/net/core/dev.c b/net/core/dev.c
79606index 84a0705..575db4c 100644
79607--- a/net/core/dev.c
79608+++ b/net/core/dev.c
79609@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const char *name)
79610 if (no_module && capable(CAP_NET_ADMIN))
79611 no_module = request_module("netdev-%s", name);
79612 if (no_module && capable(CAP_SYS_MODULE)) {
79613+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79614+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
79615+#else
79616 if (!request_module("%s", name))
79617 pr_err("Loading kernel module for a network device "
79618 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
79619 "instead\n", name);
79620+#endif
79621 }
79622 }
79623 EXPORT_SYMBOL(dev_load);
79624@@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79625
79626 struct dev_gso_cb {
79627 void (*destructor)(struct sk_buff *skb);
79628-};
79629+} __no_const;
79630
79631 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79632
79633@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
79634 }
79635 EXPORT_SYMBOL(netif_rx_ni);
79636
79637-static void net_tx_action(struct softirq_action *h)
79638+static void net_tx_action(void)
79639 {
79640 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79641
79642@@ -2827,7 +2831,7 @@ void netif_napi_del(struct napi_struct *napi)
79643 EXPORT_SYMBOL(netif_napi_del);
79644
79645
79646-static void net_rx_action(struct softirq_action *h)
79647+static void net_rx_action(void)
79648 {
79649 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
79650 unsigned long time_limit = jiffies + 2;
79651diff --git a/net/core/flow.c b/net/core/flow.c
79652index 9601587..8c4824e 100644
79653--- a/net/core/flow.c
79654+++ b/net/core/flow.c
79655@@ -35,11 +35,11 @@ struct flow_cache_entry {
79656 atomic_t *object_ref;
79657 };
79658
79659-atomic_t flow_cache_genid = ATOMIC_INIT(0);
79660+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79661
79662 static u32 flow_hash_shift;
79663 #define flow_hash_size (1 << flow_hash_shift)
79664-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
79665+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
79666
79667 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
79668
79669@@ -52,7 +52,7 @@ struct flow_percpu_info {
79670 u32 hash_rnd;
79671 int count;
79672 };
79673-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
79674+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
79675
79676 #define flow_hash_rnd_recalc(cpu) \
79677 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
79678@@ -69,7 +69,7 @@ struct flow_flush_info {
79679 atomic_t cpuleft;
79680 struct completion completion;
79681 };
79682-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
79683+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
79684
79685 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
79686
79687@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir,
79688 if (fle->family == family &&
79689 fle->dir == dir &&
79690 flow_key_compare(key, &fle->key) == 0) {
79691- if (fle->genid == atomic_read(&flow_cache_genid)) {
79692+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
79693 void *ret = fle->object;
79694
79695 if (ret)
79696@@ -228,7 +228,7 @@ nocache:
79697 err = resolver(net, key, family, dir, &obj, &obj_ref);
79698
79699 if (fle && !err) {
79700- fle->genid = atomic_read(&flow_cache_genid);
79701+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
79702
79703 if (fle->object)
79704 atomic_dec(fle->object_ref);
79705@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(unsigned long data)
79706
79707 fle = flow_table(cpu)[i];
79708 for (; fle; fle = fle->next) {
79709- unsigned genid = atomic_read(&flow_cache_genid);
79710+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
79711
79712 if (!fle->object || fle->genid == genid)
79713 continue;
79714diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79715index d4fd895..ac9b1e6 100644
79716--- a/net/core/rtnetlink.c
79717+++ b/net/core/rtnetlink.c
79718@@ -57,7 +57,7 @@ struct rtnl_link
79719 {
79720 rtnl_doit_func doit;
79721 rtnl_dumpit_func dumpit;
79722-};
79723+} __no_const;
79724
79725 static DEFINE_MUTEX(rtnl_mutex);
79726
79727diff --git a/net/core/scm.c b/net/core/scm.c
79728index d98eafc..1a190a9 100644
79729--- a/net/core/scm.c
79730+++ b/net/core/scm.c
79731@@ -191,7 +191,7 @@ error:
79732 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79733 {
79734 struct cmsghdr __user *cm
79735- = (__force struct cmsghdr __user *)msg->msg_control;
79736+ = (struct cmsghdr __force_user *)msg->msg_control;
79737 struct cmsghdr cmhdr;
79738 int cmlen = CMSG_LEN(len);
79739 int err;
79740@@ -214,7 +214,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79741 err = -EFAULT;
79742 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79743 goto out;
79744- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79745+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79746 goto out;
79747 cmlen = CMSG_SPACE(len);
79748 if (msg->msg_controllen < cmlen)
79749@@ -229,7 +229,7 @@ out:
79750 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79751 {
79752 struct cmsghdr __user *cm
79753- = (__force struct cmsghdr __user*)msg->msg_control;
79754+ = (struct cmsghdr __force_user *)msg->msg_control;
79755
79756 int fdmax = 0;
79757 int fdnum = scm->fp->count;
79758@@ -249,7 +249,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79759 if (fdnum < fdmax)
79760 fdmax = fdnum;
79761
79762- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79763+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79764 i++, cmfptr++)
79765 {
79766 int new_fd;
79767diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
79768index 45329d7..626aaa6 100644
79769--- a/net/core/secure_seq.c
79770+++ b/net/core/secure_seq.c
79771@@ -57,7 +57,7 @@ __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
79772 EXPORT_SYMBOL(secure_tcpv6_sequence_number);
79773
79774 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
79775- __be16 dport)
79776+ __be16 dport)
79777 {
79778 u32 secret[MD5_MESSAGE_BYTES / 4];
79779 u32 hash[MD5_DIGEST_WORDS];
79780@@ -71,7 +71,6 @@ u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
79781 secret[i] = net_secret[i];
79782
79783 md5_transform(hash, secret);
79784-
79785 return hash[0];
79786 }
79787 #endif
79788diff --git a/net/core/skbuff.c b/net/core/skbuff.c
79789index a807f8c..65f906f 100644
79790--- a/net/core/skbuff.c
79791+++ b/net/core/skbuff.c
79792@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
79793 struct sk_buff *frag_iter;
79794 struct sock *sk = skb->sk;
79795
79796+ pax_track_stack();
79797+
79798 /*
79799 * __skb_splice_bits() only fails if the output has no room left,
79800 * so no point in going over the frag_list for the error case.
79801diff --git a/net/core/sock.c b/net/core/sock.c
79802index 6605e75..3acebda 100644
79803--- a/net/core/sock.c
79804+++ b/net/core/sock.c
79805@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79806 break;
79807
79808 case SO_PEERCRED:
79809+ {
79810+ struct ucred peercred;
79811 if (len > sizeof(sk->sk_peercred))
79812 len = sizeof(sk->sk_peercred);
79813- if (copy_to_user(optval, &sk->sk_peercred, len))
79814+ peercred = sk->sk_peercred;
79815+ if (copy_to_user(optval, &peercred, len))
79816 return -EFAULT;
79817 goto lenout;
79818+ }
79819
79820 case SO_PEERNAME:
79821 {
79822@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79823 */
79824 smp_wmb();
79825 atomic_set(&sk->sk_refcnt, 1);
79826- atomic_set(&sk->sk_drops, 0);
79827+ atomic_set_unchecked(&sk->sk_drops, 0);
79828 }
79829 EXPORT_SYMBOL(sock_init_data);
79830
79831diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79832index 2036568..c55883d 100644
79833--- a/net/decnet/sysctl_net_decnet.c
79834+++ b/net/decnet/sysctl_net_decnet.c
79835@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79836
79837 if (len > *lenp) len = *lenp;
79838
79839- if (copy_to_user(buffer, addr, len))
79840+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
79841 return -EFAULT;
79842
79843 *lenp = len;
79844@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79845
79846 if (len > *lenp) len = *lenp;
79847
79848- if (copy_to_user(buffer, devname, len))
79849+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
79850 return -EFAULT;
79851
79852 *lenp = len;
79853diff --git a/net/econet/Kconfig b/net/econet/Kconfig
79854index 39a2d29..f39c0fe 100644
79855--- a/net/econet/Kconfig
79856+++ b/net/econet/Kconfig
79857@@ -4,7 +4,7 @@
79858
79859 config ECONET
79860 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
79861- depends on EXPERIMENTAL && INET
79862+ depends on EXPERIMENTAL && INET && BROKEN
79863 ---help---
79864 Econet is a fairly old and slow networking protocol mainly used by
79865 Acorn computers to access file and print servers. It uses native
79866diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
79867index a413b1b..380849c 100644
79868--- a/net/ieee802154/dgram.c
79869+++ b/net/ieee802154/dgram.c
79870@@ -318,7 +318,7 @@ out:
79871 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
79872 {
79873 if (sock_queue_rcv_skb(sk, skb) < 0) {
79874- atomic_inc(&sk->sk_drops);
79875+ atomic_inc_unchecked(&sk->sk_drops);
79876 kfree_skb(skb);
79877 return NET_RX_DROP;
79878 }
79879diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
79880index 30e74ee..bfc6ee0 100644
79881--- a/net/ieee802154/raw.c
79882+++ b/net/ieee802154/raw.c
79883@@ -206,7 +206,7 @@ out:
79884 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79885 {
79886 if (sock_queue_rcv_skb(sk, skb) < 0) {
79887- atomic_inc(&sk->sk_drops);
79888+ atomic_inc_unchecked(&sk->sk_drops);
79889 kfree_skb(skb);
79890 return NET_RX_DROP;
79891 }
79892diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
79893index dba56d2..acee5d6 100644
79894--- a/net/ipv4/inet_diag.c
79895+++ b/net/ipv4/inet_diag.c
79896@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct sock *sk,
79897 r->idiag_retrans = 0;
79898
79899 r->id.idiag_if = sk->sk_bound_dev_if;
79900+#ifdef CONFIG_GRKERNSEC_HIDESYM
79901+ r->id.idiag_cookie[0] = 0;
79902+ r->id.idiag_cookie[1] = 0;
79903+#else
79904 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
79905 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79906+#endif
79907
79908 r->id.idiag_sport = inet->sport;
79909 r->id.idiag_dport = inet->dport;
79910@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
79911 r->idiag_family = tw->tw_family;
79912 r->idiag_retrans = 0;
79913 r->id.idiag_if = tw->tw_bound_dev_if;
79914+
79915+#ifdef CONFIG_GRKERNSEC_HIDESYM
79916+ r->id.idiag_cookie[0] = 0;
79917+ r->id.idiag_cookie[1] = 0;
79918+#else
79919 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
79920 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
79921+#endif
79922+
79923 r->id.idiag_sport = tw->tw_sport;
79924 r->id.idiag_dport = tw->tw_dport;
79925 r->id.idiag_src[0] = tw->tw_rcv_saddr;
79926@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
79927 if (sk == NULL)
79928 goto unlock;
79929
79930+#ifndef CONFIG_GRKERNSEC_HIDESYM
79931 err = -ESTALE;
79932 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
79933 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
79934 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
79935 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
79936 goto out;
79937+#endif
79938
79939 err = -ENOMEM;
79940 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
79941@@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
79942 r->idiag_retrans = req->retrans;
79943
79944 r->id.idiag_if = sk->sk_bound_dev_if;
79945+
79946+#ifdef CONFIG_GRKERNSEC_HIDESYM
79947+ r->id.idiag_cookie[0] = 0;
79948+ r->id.idiag_cookie[1] = 0;
79949+#else
79950 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
79951 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
79952+#endif
79953
79954 tmo = req->expires - jiffies;
79955 if (tmo < 0)
79956diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79957index d717267..56de7e7 100644
79958--- a/net/ipv4/inet_hashtables.c
79959+++ b/net/ipv4/inet_hashtables.c
79960@@ -18,12 +18,15 @@
79961 #include <linux/sched.h>
79962 #include <linux/slab.h>
79963 #include <linux/wait.h>
79964+#include <linux/security.h>
79965
79966 #include <net/inet_connection_sock.h>
79967 #include <net/inet_hashtables.h>
79968 #include <net/secure_seq.h>
79969 #include <net/ip.h>
79970
79971+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79972+
79973 /*
79974 * Allocate and initialize a new local port bind bucket.
79975 * The bindhash mutex for snum's hash chain must be held here.
79976@@ -491,6 +494,8 @@ ok:
79977 }
79978 spin_unlock(&head->lock);
79979
79980+ gr_update_task_in_ip_table(current, inet_sk(sk));
79981+
79982 if (tw) {
79983 inet_twsk_deschedule(tw, death_row);
79984 inet_twsk_put(tw);
79985diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79986index 13b229f..6956484 100644
79987--- a/net/ipv4/inetpeer.c
79988+++ b/net/ipv4/inetpeer.c
79989@@ -367,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
79990 struct inet_peer *p, *n;
79991 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
79992
79993+ pax_track_stack();
79994+
79995 /* Look up for the address quickly. */
79996 read_lock_bh(&peer_pool_lock);
79997 p = lookup(daddr, NULL);
79998@@ -390,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
79999 return NULL;
80000 n->v4daddr = daddr;
80001 atomic_set(&n->refcnt, 1);
80002- atomic_set(&n->rid, 0);
80003+ atomic_set_unchecked(&n->rid, 0);
80004 n->ip_id_count = secure_ip_id(daddr);
80005 n->tcp_ts_stamp = 0;
80006
80007diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80008index d3fe10b..feeafc9 100644
80009--- a/net/ipv4/ip_fragment.c
80010+++ b/net/ipv4/ip_fragment.c
80011@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80012 return 0;
80013
80014 start = qp->rid;
80015- end = atomic_inc_return(&peer->rid);
80016+ end = atomic_inc_return_unchecked(&peer->rid);
80017 qp->rid = end;
80018
80019 rc = qp->q.fragments && (end - start) > max;
80020diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80021index e982b5c..f079d75 100644
80022--- a/net/ipv4/ip_sockglue.c
80023+++ b/net/ipv4/ip_sockglue.c
80024@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80025 int val;
80026 int len;
80027
80028+ pax_track_stack();
80029+
80030 if (level != SOL_IP)
80031 return -EOPNOTSUPP;
80032
80033@@ -1173,7 +1175,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80034 if (sk->sk_type != SOCK_STREAM)
80035 return -ENOPROTOOPT;
80036
80037- msg.msg_control = optval;
80038+ msg.msg_control = (void __force_kernel *)optval;
80039 msg.msg_controllen = len;
80040 msg.msg_flags = 0;
80041
80042diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80043index f8d04c2..c1188f2 100644
80044--- a/net/ipv4/ipconfig.c
80045+++ b/net/ipv4/ipconfig.c
80046@@ -295,7 +295,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80047
80048 mm_segment_t oldfs = get_fs();
80049 set_fs(get_ds());
80050- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80051+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80052 set_fs(oldfs);
80053 return res;
80054 }
80055@@ -306,7 +306,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80056
80057 mm_segment_t oldfs = get_fs();
80058 set_fs(get_ds());
80059- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80060+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80061 set_fs(oldfs);
80062 return res;
80063 }
80064@@ -317,7 +317,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80065
80066 mm_segment_t oldfs = get_fs();
80067 set_fs(get_ds());
80068- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80069+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80070 set_fs(oldfs);
80071 return res;
80072 }
80073diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80074index c8b0cc3..4da5ae2 100644
80075--- a/net/ipv4/netfilter/arp_tables.c
80076+++ b/net/ipv4/netfilter/arp_tables.c
80077@@ -934,6 +934,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80078 private = &tmp;
80079 }
80080 #endif
80081+ memset(&info, 0, sizeof(info));
80082 info.valid_hooks = t->valid_hooks;
80083 memcpy(info.hook_entry, private->hook_entry,
80084 sizeof(info.hook_entry));
80085diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
80086index c156db2..e772975 100644
80087--- a/net/ipv4/netfilter/ip_queue.c
80088+++ b/net/ipv4/netfilter/ip_queue.c
80089@@ -286,6 +286,9 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80090
80091 if (v->data_len < sizeof(*user_iph))
80092 return 0;
80093+ if (v->data_len > 65535)
80094+ return -EMSGSIZE;
80095+
80096 diff = v->data_len - e->skb->len;
80097 if (diff < 0) {
80098 if (pskb_trim(e->skb, v->data_len))
80099@@ -409,7 +412,8 @@ ipq_dev_drop(int ifindex)
80100 static inline void
80101 __ipq_rcv_skb(struct sk_buff *skb)
80102 {
80103- int status, type, pid, flags, nlmsglen, skblen;
80104+ int status, type, pid, flags;
80105+ unsigned int nlmsglen, skblen;
80106 struct nlmsghdr *nlh;
80107
80108 skblen = skb->len;
80109diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80110index 0606db1..02e7e4c 100644
80111--- a/net/ipv4/netfilter/ip_tables.c
80112+++ b/net/ipv4/netfilter/ip_tables.c
80113@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80114 private = &tmp;
80115 }
80116 #endif
80117+ memset(&info, 0, sizeof(info));
80118 info.valid_hooks = t->valid_hooks;
80119 memcpy(info.hook_entry, private->hook_entry,
80120 sizeof(info.hook_entry));
80121diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80122index d9521f6..3c3eb25 100644
80123--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
80124+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80125@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
80126
80127 *len = 0;
80128
80129- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
80130+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
80131 if (*octets == NULL) {
80132 if (net_ratelimit())
80133 printk("OOM in bsalg (%d)\n", __LINE__);
80134diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80135index ab996f9..3da5f96 100644
80136--- a/net/ipv4/raw.c
80137+++ b/net/ipv4/raw.c
80138@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80139 /* Charge it to the socket. */
80140
80141 if (sock_queue_rcv_skb(sk, skb) < 0) {
80142- atomic_inc(&sk->sk_drops);
80143+ atomic_inc_unchecked(&sk->sk_drops);
80144 kfree_skb(skb);
80145 return NET_RX_DROP;
80146 }
80147@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80148 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80149 {
80150 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80151- atomic_inc(&sk->sk_drops);
80152+ atomic_inc_unchecked(&sk->sk_drops);
80153 kfree_skb(skb);
80154 return NET_RX_DROP;
80155 }
80156@@ -724,16 +724,23 @@ static int raw_init(struct sock *sk)
80157
80158 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80159 {
80160+ struct icmp_filter filter;
80161+
80162+ if (optlen < 0)
80163+ return -EINVAL;
80164 if (optlen > sizeof(struct icmp_filter))
80165 optlen = sizeof(struct icmp_filter);
80166- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80167+ if (copy_from_user(&filter, optval, optlen))
80168 return -EFAULT;
80169+ raw_sk(sk)->filter = filter;
80170+
80171 return 0;
80172 }
80173
80174 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80175 {
80176 int len, ret = -EFAULT;
80177+ struct icmp_filter filter;
80178
80179 if (get_user(len, optlen))
80180 goto out;
80181@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80182 if (len > sizeof(struct icmp_filter))
80183 len = sizeof(struct icmp_filter);
80184 ret = -EFAULT;
80185- if (put_user(len, optlen) ||
80186- copy_to_user(optval, &raw_sk(sk)->filter, len))
80187+ filter = raw_sk(sk)->filter;
80188+ if (put_user(len, optlen) || len > sizeof filter ||
80189+ copy_to_user(optval, &filter, len))
80190 goto out;
80191 ret = 0;
80192 out: return ret;
80193@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80194 sk_wmem_alloc_get(sp),
80195 sk_rmem_alloc_get(sp),
80196 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80197- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80198+ atomic_read(&sp->sk_refcnt),
80199+#ifdef CONFIG_GRKERNSEC_HIDESYM
80200+ NULL,
80201+#else
80202+ sp,
80203+#endif
80204+ atomic_read_unchecked(&sp->sk_drops));
80205 }
80206
80207 static int raw_seq_show(struct seq_file *seq, void *v)
80208diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80209index 58f141b..b759702 100644
80210--- a/net/ipv4/route.c
80211+++ b/net/ipv4/route.c
80212@@ -269,7 +269,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
80213
80214 static inline int rt_genid(struct net *net)
80215 {
80216- return atomic_read(&net->ipv4.rt_genid);
80217+ return atomic_read_unchecked(&net->ipv4.rt_genid);
80218 }
80219
80220 #ifdef CONFIG_PROC_FS
80221@@ -889,7 +889,7 @@ static void rt_cache_invalidate(struct net *net)
80222 unsigned char shuffle;
80223
80224 get_random_bytes(&shuffle, sizeof(shuffle));
80225- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
80226+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
80227 }
80228
80229 /*
80230@@ -3357,7 +3357,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80231
80232 static __net_init int rt_secret_timer_init(struct net *net)
80233 {
80234- atomic_set(&net->ipv4.rt_genid,
80235+ atomic_set_unchecked(&net->ipv4.rt_genid,
80236 (int) ((num_physpages ^ (num_physpages>>8)) ^
80237 (jiffies ^ (jiffies >> 7))));
80238
80239diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
80240index f095659..adc892a 100644
80241--- a/net/ipv4/tcp.c
80242+++ b/net/ipv4/tcp.c
80243@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
80244 int val;
80245 int err = 0;
80246
80247+ pax_track_stack();
80248+
80249 /* This is a string value all the others are int's */
80250 if (optname == TCP_CONGESTION) {
80251 char name[TCP_CA_NAME_MAX];
80252@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
80253 struct tcp_sock *tp = tcp_sk(sk);
80254 int val, len;
80255
80256+ pax_track_stack();
80257+
80258 if (get_user(len, optlen))
80259 return -EFAULT;
80260
80261diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80262index 6fc7961..33bad4a 100644
80263--- a/net/ipv4/tcp_ipv4.c
80264+++ b/net/ipv4/tcp_ipv4.c
80265@@ -85,6 +85,9 @@
80266 int sysctl_tcp_tw_reuse __read_mostly;
80267 int sysctl_tcp_low_latency __read_mostly;
80268
80269+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80270+extern int grsec_enable_blackhole;
80271+#endif
80272
80273 #ifdef CONFIG_TCP_MD5SIG
80274 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
80275@@ -1543,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80276 return 0;
80277
80278 reset:
80279+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80280+ if (!grsec_enable_blackhole)
80281+#endif
80282 tcp_v4_send_reset(rsk, skb);
80283 discard:
80284 kfree_skb(skb);
80285@@ -1604,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
80286 TCP_SKB_CB(skb)->sacked = 0;
80287
80288 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80289- if (!sk)
80290+ if (!sk) {
80291+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80292+ ret = 1;
80293+#endif
80294 goto no_tcp_socket;
80295+ }
80296
80297 process:
80298- if (sk->sk_state == TCP_TIME_WAIT)
80299+ if (sk->sk_state == TCP_TIME_WAIT) {
80300+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80301+ ret = 2;
80302+#endif
80303 goto do_time_wait;
80304+ }
80305
80306 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
80307 goto discard_and_relse;
80308@@ -1651,6 +1665,10 @@ no_tcp_socket:
80309 bad_packet:
80310 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80311 } else {
80312+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80313+ if (!grsec_enable_blackhole || (ret == 1 &&
80314+ (skb->dev->flags & IFF_LOOPBACK)))
80315+#endif
80316 tcp_v4_send_reset(NULL, skb);
80317 }
80318
80319@@ -2238,7 +2256,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
80320 0, /* non standard timer */
80321 0, /* open_requests have no inode */
80322 atomic_read(&sk->sk_refcnt),
80323+#ifdef CONFIG_GRKERNSEC_HIDESYM
80324+ NULL,
80325+#else
80326 req,
80327+#endif
80328 len);
80329 }
80330
80331@@ -2280,7 +2302,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
80332 sock_i_uid(sk),
80333 icsk->icsk_probes_out,
80334 sock_i_ino(sk),
80335- atomic_read(&sk->sk_refcnt), sk,
80336+ atomic_read(&sk->sk_refcnt),
80337+#ifdef CONFIG_GRKERNSEC_HIDESYM
80338+ NULL,
80339+#else
80340+ sk,
80341+#endif
80342 jiffies_to_clock_t(icsk->icsk_rto),
80343 jiffies_to_clock_t(icsk->icsk_ack.ato),
80344 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
80345@@ -2308,7 +2335,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
80346 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
80347 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
80348 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
80349- atomic_read(&tw->tw_refcnt), tw, len);
80350+ atomic_read(&tw->tw_refcnt),
80351+#ifdef CONFIG_GRKERNSEC_HIDESYM
80352+ NULL,
80353+#else
80354+ tw,
80355+#endif
80356+ len);
80357 }
80358
80359 #define TMPSZ 150
80360diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80361index 4c03598..e09a8e8 100644
80362--- a/net/ipv4/tcp_minisocks.c
80363+++ b/net/ipv4/tcp_minisocks.c
80364@@ -26,6 +26,10 @@
80365 #include <net/inet_common.h>
80366 #include <net/xfrm.h>
80367
80368+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80369+extern int grsec_enable_blackhole;
80370+#endif
80371+
80372 #ifdef CONFIG_SYSCTL
80373 #define SYNC_INIT 0 /* let the user enable it */
80374 #else
80375@@ -672,6 +676,10 @@ listen_overflow:
80376
80377 embryonic_reset:
80378 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
80379+
80380+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80381+ if (!grsec_enable_blackhole)
80382+#endif
80383 if (!(flg & TCP_FLAG_RST))
80384 req->rsk_ops->send_reset(sk, skb);
80385
80386diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
80387index af83bdf..ec91cb2 100644
80388--- a/net/ipv4/tcp_output.c
80389+++ b/net/ipv4/tcp_output.c
80390@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
80391 __u8 *md5_hash_location;
80392 int mss;
80393
80394+ pax_track_stack();
80395+
80396 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
80397 if (skb == NULL)
80398 return NULL;
80399diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80400index 59f5b5e..193860f 100644
80401--- a/net/ipv4/tcp_probe.c
80402+++ b/net/ipv4/tcp_probe.c
80403@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80404 if (cnt + width >= len)
80405 break;
80406
80407- if (copy_to_user(buf + cnt, tbuf, width))
80408+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80409 return -EFAULT;
80410 cnt += width;
80411 }
80412diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80413index 57d5501..a9ed13a 100644
80414--- a/net/ipv4/tcp_timer.c
80415+++ b/net/ipv4/tcp_timer.c
80416@@ -21,6 +21,10 @@
80417 #include <linux/module.h>
80418 #include <net/tcp.h>
80419
80420+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80421+extern int grsec_lastack_retries;
80422+#endif
80423+
80424 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80425 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80426 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80427@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock *sk)
80428 }
80429 }
80430
80431+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80432+ if ((sk->sk_state == TCP_LAST_ACK) &&
80433+ (grsec_lastack_retries > 0) &&
80434+ (grsec_lastack_retries < retry_until))
80435+ retry_until = grsec_lastack_retries;
80436+#endif
80437+
80438 if (retransmits_timed_out(sk, retry_until)) {
80439 /* Has it gone just too far? */
80440 tcp_write_err(sk);
80441diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80442index 0ac8833..58d8c43 100644
80443--- a/net/ipv4/udp.c
80444+++ b/net/ipv4/udp.c
80445@@ -86,6 +86,7 @@
80446 #include <linux/types.h>
80447 #include <linux/fcntl.h>
80448 #include <linux/module.h>
80449+#include <linux/security.h>
80450 #include <linux/socket.h>
80451 #include <linux/sockios.h>
80452 #include <linux/igmp.h>
80453@@ -106,6 +107,10 @@
80454 #include <net/xfrm.h>
80455 #include "udp_impl.h"
80456
80457+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80458+extern int grsec_enable_blackhole;
80459+#endif
80460+
80461 struct udp_table udp_table;
80462 EXPORT_SYMBOL(udp_table);
80463
80464@@ -371,6 +376,9 @@ found:
80465 return s;
80466 }
80467
80468+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80469+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80470+
80471 /*
80472 * This routine is called by the ICMP module when it gets some
80473 * sort of error condition. If err < 0 then the socket should
80474@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80475 dport = usin->sin_port;
80476 if (dport == 0)
80477 return -EINVAL;
80478+
80479+ err = gr_search_udp_sendmsg(sk, usin);
80480+ if (err)
80481+ return err;
80482 } else {
80483 if (sk->sk_state != TCP_ESTABLISHED)
80484 return -EDESTADDRREQ;
80485+
80486+ err = gr_search_udp_sendmsg(sk, NULL);
80487+ if (err)
80488+ return err;
80489+
80490 daddr = inet->daddr;
80491 dport = inet->dport;
80492 /* Open fast path for connected socket.
80493@@ -945,6 +962,10 @@ try_again:
80494 if (!skb)
80495 goto out;
80496
80497+ err = gr_search_udp_recvmsg(sk, skb);
80498+ if (err)
80499+ goto out_free;
80500+
80501 ulen = skb->len - sizeof(struct udphdr);
80502 copied = len;
80503 if (copied > ulen)
80504@@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80505 if (rc == -ENOMEM) {
80506 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80507 is_udplite);
80508- atomic_inc(&sk->sk_drops);
80509+ atomic_inc_unchecked(&sk->sk_drops);
80510 }
80511 goto drop;
80512 }
80513@@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80514 goto csum_error;
80515
80516 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80517+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80518+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80519+#endif
80520 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80521
80522 /*
80523@@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80524 sk_wmem_alloc_get(sp),
80525 sk_rmem_alloc_get(sp),
80526 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80527- atomic_read(&sp->sk_refcnt), sp,
80528- atomic_read(&sp->sk_drops), len);
80529+ atomic_read(&sp->sk_refcnt),
80530+#ifdef CONFIG_GRKERNSEC_HIDESYM
80531+ NULL,
80532+#else
80533+ sp,
80534+#endif
80535+ atomic_read_unchecked(&sp->sk_drops), len);
80536 }
80537
80538 int udp4_seq_show(struct seq_file *seq, void *v)
80539diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80540index 8ac3d09..fc58c5f 100644
80541--- a/net/ipv6/addrconf.c
80542+++ b/net/ipv6/addrconf.c
80543@@ -2053,7 +2053,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80544 p.iph.ihl = 5;
80545 p.iph.protocol = IPPROTO_IPV6;
80546 p.iph.ttl = 64;
80547- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80548+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80549
80550 if (ops->ndo_do_ioctl) {
80551 mm_segment_t oldfs = get_fs();
80552diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
80553index cc4797d..7cfdfcc 100644
80554--- a/net/ipv6/inet6_connection_sock.c
80555+++ b/net/ipv6/inet6_connection_sock.c
80556@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
80557 #ifdef CONFIG_XFRM
80558 {
80559 struct rt6_info *rt = (struct rt6_info *)dst;
80560- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
80561+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
80562 }
80563 #endif
80564 }
80565@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
80566 #ifdef CONFIG_XFRM
80567 if (dst) {
80568 struct rt6_info *rt = (struct rt6_info *)dst;
80569- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
80570+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
80571 sk->sk_dst_cache = NULL;
80572 dst_release(dst);
80573 dst = NULL;
80574diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
80575index 093e9b2..f72cddb 100644
80576--- a/net/ipv6/inet6_hashtables.c
80577+++ b/net/ipv6/inet6_hashtables.c
80578@@ -119,7 +119,7 @@ out:
80579 }
80580 EXPORT_SYMBOL(__inet6_lookup_established);
80581
80582-static int inline compute_score(struct sock *sk, struct net *net,
80583+static inline int compute_score(struct sock *sk, struct net *net,
80584 const unsigned short hnum,
80585 const struct in6_addr *daddr,
80586 const int dif)
80587diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80588index 4f7aaf6..f7acf45 100644
80589--- a/net/ipv6/ipv6_sockglue.c
80590+++ b/net/ipv6/ipv6_sockglue.c
80591@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
80592 int val, valbool;
80593 int retv = -ENOPROTOOPT;
80594
80595+ pax_track_stack();
80596+
80597 if (optval == NULL)
80598 val=0;
80599 else {
80600@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80601 int len;
80602 int val;
80603
80604+ pax_track_stack();
80605+
80606 if (ip6_mroute_opt(optname))
80607 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
80608
80609@@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80610 if (sk->sk_type != SOCK_STREAM)
80611 return -ENOPROTOOPT;
80612
80613- msg.msg_control = optval;
80614+ msg.msg_control = (void __force_kernel *)optval;
80615 msg.msg_controllen = len;
80616 msg.msg_flags = 0;
80617
80618diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
80619index 1cf3f0c..1d4376f 100644
80620--- a/net/ipv6/netfilter/ip6_queue.c
80621+++ b/net/ipv6/netfilter/ip6_queue.c
80622@@ -287,6 +287,9 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80623
80624 if (v->data_len < sizeof(*user_iph))
80625 return 0;
80626+ if (v->data_len > 65535)
80627+ return -EMSGSIZE;
80628+
80629 diff = v->data_len - e->skb->len;
80630 if (diff < 0) {
80631 if (pskb_trim(e->skb, v->data_len))
80632@@ -411,7 +414,8 @@ ipq_dev_drop(int ifindex)
80633 static inline void
80634 __ipq_rcv_skb(struct sk_buff *skb)
80635 {
80636- int status, type, pid, flags, nlmsglen, skblen;
80637+ int status, type, pid, flags;
80638+ unsigned int nlmsglen, skblen;
80639 struct nlmsghdr *nlh;
80640
80641 skblen = skb->len;
80642diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80643index 78b5a36..7f37433 100644
80644--- a/net/ipv6/netfilter/ip6_tables.c
80645+++ b/net/ipv6/netfilter/ip6_tables.c
80646@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80647 private = &tmp;
80648 }
80649 #endif
80650+ memset(&info, 0, sizeof(info));
80651 info.valid_hooks = t->valid_hooks;
80652 memcpy(info.hook_entry, private->hook_entry,
80653 sizeof(info.hook_entry));
80654diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80655index 4f24570..b813b34 100644
80656--- a/net/ipv6/raw.c
80657+++ b/net/ipv6/raw.c
80658@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
80659 {
80660 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
80661 skb_checksum_complete(skb)) {
80662- atomic_inc(&sk->sk_drops);
80663+ atomic_inc_unchecked(&sk->sk_drops);
80664 kfree_skb(skb);
80665 return NET_RX_DROP;
80666 }
80667
80668 /* Charge it to the socket. */
80669 if (sock_queue_rcv_skb(sk,skb)<0) {
80670- atomic_inc(&sk->sk_drops);
80671+ atomic_inc_unchecked(&sk->sk_drops);
80672 kfree_skb(skb);
80673 return NET_RX_DROP;
80674 }
80675@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80676 struct raw6_sock *rp = raw6_sk(sk);
80677
80678 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80679- atomic_inc(&sk->sk_drops);
80680+ atomic_inc_unchecked(&sk->sk_drops);
80681 kfree_skb(skb);
80682 return NET_RX_DROP;
80683 }
80684@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80685
80686 if (inet->hdrincl) {
80687 if (skb_checksum_complete(skb)) {
80688- atomic_inc(&sk->sk_drops);
80689+ atomic_inc_unchecked(&sk->sk_drops);
80690 kfree_skb(skb);
80691 return NET_RX_DROP;
80692 }
80693@@ -518,7 +518,7 @@ csum_copy_err:
80694 as some normal condition.
80695 */
80696 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
80697- atomic_inc(&sk->sk_drops);
80698+ atomic_inc_unchecked(&sk->sk_drops);
80699 goto out;
80700 }
80701
80702@@ -600,7 +600,7 @@ out:
80703 return err;
80704 }
80705
80706-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80707+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80708 struct flowi *fl, struct rt6_info *rt,
80709 unsigned int flags)
80710 {
80711@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
80712 u16 proto;
80713 int err;
80714
80715+ pax_track_stack();
80716+
80717 /* Rough check on arithmetic overflow,
80718 better check is made in ip6_append_data().
80719 */
80720@@ -916,12 +918,17 @@ do_confirm:
80721 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80722 char __user *optval, int optlen)
80723 {
80724+ struct icmp6_filter filter;
80725+
80726 switch (optname) {
80727 case ICMPV6_FILTER:
80728+ if (optlen < 0)
80729+ return -EINVAL;
80730 if (optlen > sizeof(struct icmp6_filter))
80731 optlen = sizeof(struct icmp6_filter);
80732- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80733+ if (copy_from_user(&filter, optval, optlen))
80734 return -EFAULT;
80735+ raw6_sk(sk)->filter = filter;
80736 return 0;
80737 default:
80738 return -ENOPROTOOPT;
80739@@ -934,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80740 char __user *optval, int __user *optlen)
80741 {
80742 int len;
80743+ struct icmp6_filter filter;
80744
80745 switch (optname) {
80746 case ICMPV6_FILTER:
80747@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80748 len = sizeof(struct icmp6_filter);
80749 if (put_user(len, optlen))
80750 return -EFAULT;
80751- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80752+ filter = raw6_sk(sk)->filter;
80753+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
80754 return -EFAULT;
80755 return 0;
80756 default:
80757@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80758 0, 0L, 0,
80759 sock_i_uid(sp), 0,
80760 sock_i_ino(sp),
80761- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80762+ atomic_read(&sp->sk_refcnt),
80763+#ifdef CONFIG_GRKERNSEC_HIDESYM
80764+ NULL,
80765+#else
80766+ sp,
80767+#endif
80768+ atomic_read_unchecked(&sp->sk_drops));
80769 }
80770
80771 static int raw6_seq_show(struct seq_file *seq, void *v)
80772diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80773index faae6df..d4430c1 100644
80774--- a/net/ipv6/tcp_ipv6.c
80775+++ b/net/ipv6/tcp_ipv6.c
80776@@ -89,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
80777 }
80778 #endif
80779
80780+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80781+extern int grsec_enable_blackhole;
80782+#endif
80783+
80784 static void tcp_v6_hash(struct sock *sk)
80785 {
80786 if (sk->sk_state != TCP_CLOSE) {
80787@@ -1579,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80788 return 0;
80789
80790 reset:
80791+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80792+ if (!grsec_enable_blackhole)
80793+#endif
80794 tcp_v6_send_reset(sk, skb);
80795 discard:
80796 if (opt_skb)
80797@@ -1656,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80798 TCP_SKB_CB(skb)->sacked = 0;
80799
80800 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80801- if (!sk)
80802+ if (!sk) {
80803+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80804+ ret = 1;
80805+#endif
80806 goto no_tcp_socket;
80807+ }
80808
80809 process:
80810- if (sk->sk_state == TCP_TIME_WAIT)
80811+ if (sk->sk_state == TCP_TIME_WAIT) {
80812+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80813+ ret = 2;
80814+#endif
80815 goto do_time_wait;
80816+ }
80817
80818 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
80819 goto discard_and_relse;
80820@@ -1701,6 +1716,10 @@ no_tcp_socket:
80821 bad_packet:
80822 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80823 } else {
80824+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80825+ if (!grsec_enable_blackhole || (ret == 1 &&
80826+ (skb->dev->flags & IFF_LOOPBACK)))
80827+#endif
80828 tcp_v6_send_reset(NULL, skb);
80829 }
80830
80831@@ -1916,7 +1935,13 @@ static void get_openreq6(struct seq_file *seq,
80832 uid,
80833 0, /* non standard timer */
80834 0, /* open_requests have no inode */
80835- 0, req);
80836+ 0,
80837+#ifdef CONFIG_GRKERNSEC_HIDESYM
80838+ NULL
80839+#else
80840+ req
80841+#endif
80842+ );
80843 }
80844
80845 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
80846@@ -1966,7 +1991,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
80847 sock_i_uid(sp),
80848 icsk->icsk_probes_out,
80849 sock_i_ino(sp),
80850- atomic_read(&sp->sk_refcnt), sp,
80851+ atomic_read(&sp->sk_refcnt),
80852+#ifdef CONFIG_GRKERNSEC_HIDESYM
80853+ NULL,
80854+#else
80855+ sp,
80856+#endif
80857 jiffies_to_clock_t(icsk->icsk_rto),
80858 jiffies_to_clock_t(icsk->icsk_ack.ato),
80859 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
80860@@ -2001,7 +2031,13 @@ static void get_timewait6_sock(struct seq_file *seq,
80861 dest->s6_addr32[2], dest->s6_addr32[3], destp,
80862 tw->tw_substate, 0, 0,
80863 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
80864- atomic_read(&tw->tw_refcnt), tw);
80865+ atomic_read(&tw->tw_refcnt),
80866+#ifdef CONFIG_GRKERNSEC_HIDESYM
80867+ NULL
80868+#else
80869+ tw
80870+#endif
80871+ );
80872 }
80873
80874 static int tcp6_seq_show(struct seq_file *seq, void *v)
80875diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80876index 9cc6289..052c521 100644
80877--- a/net/ipv6/udp.c
80878+++ b/net/ipv6/udp.c
80879@@ -49,6 +49,10 @@
80880 #include <linux/seq_file.h>
80881 #include "udp_impl.h"
80882
80883+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80884+extern int grsec_enable_blackhole;
80885+#endif
80886+
80887 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80888 {
80889 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80890@@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
80891 if (rc == -ENOMEM) {
80892 UDP6_INC_STATS_BH(sock_net(sk),
80893 UDP_MIB_RCVBUFERRORS, is_udplite);
80894- atomic_inc(&sk->sk_drops);
80895+ atomic_inc_unchecked(&sk->sk_drops);
80896 }
80897 goto drop;
80898 }
80899@@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80900 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
80901 proto == IPPROTO_UDPLITE);
80902
80903+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80904+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80905+#endif
80906 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
80907
80908 kfree_skb(skb);
80909@@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80910 0, 0L, 0,
80911 sock_i_uid(sp), 0,
80912 sock_i_ino(sp),
80913- atomic_read(&sp->sk_refcnt), sp,
80914- atomic_read(&sp->sk_drops));
80915+ atomic_read(&sp->sk_refcnt),
80916+#ifdef CONFIG_GRKERNSEC_HIDESYM
80917+ NULL,
80918+#else
80919+ sp,
80920+#endif
80921+ atomic_read_unchecked(&sp->sk_drops));
80922 }
80923
80924 int udp6_seq_show(struct seq_file *seq, void *v)
80925diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80926index 811984d..11f59b7 100644
80927--- a/net/irda/ircomm/ircomm_tty.c
80928+++ b/net/irda/ircomm/ircomm_tty.c
80929@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80930 add_wait_queue(&self->open_wait, &wait);
80931
80932 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80933- __FILE__,__LINE__, tty->driver->name, self->open_count );
80934+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
80935
80936 /* As far as I can see, we protect open_count - Jean II */
80937 spin_lock_irqsave(&self->spinlock, flags);
80938 if (!tty_hung_up_p(filp)) {
80939 extra_count = 1;
80940- self->open_count--;
80941+ local_dec(&self->open_count);
80942 }
80943 spin_unlock_irqrestore(&self->spinlock, flags);
80944- self->blocked_open++;
80945+ local_inc(&self->blocked_open);
80946
80947 while (1) {
80948 if (tty->termios->c_cflag & CBAUD) {
80949@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80950 }
80951
80952 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80953- __FILE__,__LINE__, tty->driver->name, self->open_count );
80954+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
80955
80956 schedule();
80957 }
80958@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80959 if (extra_count) {
80960 /* ++ is not atomic, so this should be protected - Jean II */
80961 spin_lock_irqsave(&self->spinlock, flags);
80962- self->open_count++;
80963+ local_inc(&self->open_count);
80964 spin_unlock_irqrestore(&self->spinlock, flags);
80965 }
80966- self->blocked_open--;
80967+ local_dec(&self->blocked_open);
80968
80969 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80970- __FILE__,__LINE__, tty->driver->name, self->open_count);
80971+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
80972
80973 if (!retval)
80974 self->flags |= ASYNC_NORMAL_ACTIVE;
80975@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80976 }
80977 /* ++ is not atomic, so this should be protected - Jean II */
80978 spin_lock_irqsave(&self->spinlock, flags);
80979- self->open_count++;
80980+ local_inc(&self->open_count);
80981
80982 tty->driver_data = self;
80983 self->tty = tty;
80984 spin_unlock_irqrestore(&self->spinlock, flags);
80985
80986 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80987- self->line, self->open_count);
80988+ self->line, local_read(&self->open_count));
80989
80990 /* Not really used by us, but lets do it anyway */
80991 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80992@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
80993 return;
80994 }
80995
80996- if ((tty->count == 1) && (self->open_count != 1)) {
80997+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
80998 /*
80999 * Uh, oh. tty->count is 1, which means that the tty
81000 * structure will be freed. state->count should always
81001@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81002 */
81003 IRDA_DEBUG(0, "%s(), bad serial port count; "
81004 "tty->count is 1, state->count is %d\n", __func__ ,
81005- self->open_count);
81006- self->open_count = 1;
81007+ local_read(&self->open_count));
81008+ local_set(&self->open_count, 1);
81009 }
81010
81011- if (--self->open_count < 0) {
81012+ if (local_dec_return(&self->open_count) < 0) {
81013 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
81014- __func__, self->line, self->open_count);
81015- self->open_count = 0;
81016+ __func__, self->line, local_read(&self->open_count));
81017+ local_set(&self->open_count, 0);
81018 }
81019- if (self->open_count) {
81020+ if (local_read(&self->open_count)) {
81021 spin_unlock_irqrestore(&self->spinlock, flags);
81022
81023 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
81024@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81025 tty->closing = 0;
81026 self->tty = NULL;
81027
81028- if (self->blocked_open) {
81029+ if (local_read(&self->blocked_open)) {
81030 if (self->close_delay)
81031 schedule_timeout_interruptible(self->close_delay);
81032 wake_up_interruptible(&self->open_wait);
81033@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81034 spin_lock_irqsave(&self->spinlock, flags);
81035 self->flags &= ~ASYNC_NORMAL_ACTIVE;
81036 self->tty = NULL;
81037- self->open_count = 0;
81038+ local_set(&self->open_count, 0);
81039 spin_unlock_irqrestore(&self->spinlock, flags);
81040
81041 wake_up_interruptible(&self->open_wait);
81042@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81043 seq_putc(m, '\n');
81044
81045 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81046- seq_printf(m, "Open count: %d\n", self->open_count);
81047+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
81048 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81049 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81050
81051diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81052index bada1b9..f325943 100644
81053--- a/net/iucv/af_iucv.c
81054+++ b/net/iucv/af_iucv.c
81055@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct sock *sk)
81056
81057 write_lock_bh(&iucv_sk_list.lock);
81058
81059- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81060+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81061 while (__iucv_get_sock_by_name(name)) {
81062 sprintf(name, "%08x",
81063- atomic_inc_return(&iucv_sk_list.autobind_name));
81064+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81065 }
81066
81067 write_unlock_bh(&iucv_sk_list.lock);
81068diff --git a/net/key/af_key.c b/net/key/af_key.c
81069index 4e98193..439b449 100644
81070--- a/net/key/af_key.c
81071+++ b/net/key/af_key.c
81072@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
81073 struct xfrm_migrate m[XFRM_MAX_DEPTH];
81074 struct xfrm_kmaddress k;
81075
81076+ pax_track_stack();
81077+
81078 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
81079 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
81080 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
81081@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
81082 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
81083 else
81084 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
81085+#ifdef CONFIG_GRKERNSEC_HIDESYM
81086+ NULL,
81087+#else
81088 s,
81089+#endif
81090 atomic_read(&s->sk_refcnt),
81091 sk_rmem_alloc_get(s),
81092 sk_wmem_alloc_get(s),
81093diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
81094index bda96d1..c038b72 100644
81095--- a/net/lapb/lapb_iface.c
81096+++ b/net/lapb/lapb_iface.c
81097@@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
81098 goto out;
81099
81100 lapb->dev = dev;
81101- lapb->callbacks = *callbacks;
81102+ lapb->callbacks = callbacks;
81103
81104 __lapb_insert_cb(lapb);
81105
81106@@ -379,32 +379,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
81107
81108 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
81109 {
81110- if (lapb->callbacks.connect_confirmation)
81111- lapb->callbacks.connect_confirmation(lapb->dev, reason);
81112+ if (lapb->callbacks->connect_confirmation)
81113+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
81114 }
81115
81116 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
81117 {
81118- if (lapb->callbacks.connect_indication)
81119- lapb->callbacks.connect_indication(lapb->dev, reason);
81120+ if (lapb->callbacks->connect_indication)
81121+ lapb->callbacks->connect_indication(lapb->dev, reason);
81122 }
81123
81124 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
81125 {
81126- if (lapb->callbacks.disconnect_confirmation)
81127- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
81128+ if (lapb->callbacks->disconnect_confirmation)
81129+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
81130 }
81131
81132 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
81133 {
81134- if (lapb->callbacks.disconnect_indication)
81135- lapb->callbacks.disconnect_indication(lapb->dev, reason);
81136+ if (lapb->callbacks->disconnect_indication)
81137+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
81138 }
81139
81140 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
81141 {
81142- if (lapb->callbacks.data_indication)
81143- return lapb->callbacks.data_indication(lapb->dev, skb);
81144+ if (lapb->callbacks->data_indication)
81145+ return lapb->callbacks->data_indication(lapb->dev, skb);
81146
81147 kfree_skb(skb);
81148 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
81149@@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
81150 {
81151 int used = 0;
81152
81153- if (lapb->callbacks.data_transmit) {
81154- lapb->callbacks.data_transmit(lapb->dev, skb);
81155+ if (lapb->callbacks->data_transmit) {
81156+ lapb->callbacks->data_transmit(lapb->dev, skb);
81157 used = 1;
81158 }
81159
81160diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81161index fe2d3f8..e57f683 100644
81162--- a/net/mac80211/cfg.c
81163+++ b/net/mac80211/cfg.c
81164@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
81165 return err;
81166 }
81167
81168-struct cfg80211_ops mac80211_config_ops = {
81169+const struct cfg80211_ops mac80211_config_ops = {
81170 .add_virtual_intf = ieee80211_add_iface,
81171 .del_virtual_intf = ieee80211_del_iface,
81172 .change_virtual_intf = ieee80211_change_iface,
81173diff --git a/net/mac80211/cfg.h b/net/mac80211/cfg.h
81174index 7d7879f..2d51f62 100644
81175--- a/net/mac80211/cfg.h
81176+++ b/net/mac80211/cfg.h
81177@@ -4,6 +4,6 @@
81178 #ifndef __CFG_H
81179 #define __CFG_H
81180
81181-extern struct cfg80211_ops mac80211_config_ops;
81182+extern const struct cfg80211_ops mac80211_config_ops;
81183
81184 #endif /* __CFG_H */
81185diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
81186index 99c7525..9cb4937 100644
81187--- a/net/mac80211/debugfs_key.c
81188+++ b/net/mac80211/debugfs_key.c
81189@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
81190 size_t count, loff_t *ppos)
81191 {
81192 struct ieee80211_key *key = file->private_data;
81193- int i, res, bufsize = 2 * key->conf.keylen + 2;
81194+ int i, bufsize = 2 * key->conf.keylen + 2;
81195 char *buf = kmalloc(bufsize, GFP_KERNEL);
81196 char *p = buf;
81197+ ssize_t res;
81198+
81199+ if (buf == NULL)
81200+ return -ENOMEM;
81201
81202 for (i = 0; i < key->conf.keylen; i++)
81203 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
81204diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
81205index 33a2e89..08650c8 100644
81206--- a/net/mac80211/debugfs_sta.c
81207+++ b/net/mac80211/debugfs_sta.c
81208@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
81209 int i;
81210 struct sta_info *sta = file->private_data;
81211
81212+ pax_track_stack();
81213+
81214 spin_lock_bh(&sta->lock);
81215 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
81216 sta->ampdu_mlme.dialog_token_allocator + 1);
81217diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81218index ca62bfe..6657a03 100644
81219--- a/net/mac80211/ieee80211_i.h
81220+++ b/net/mac80211/ieee80211_i.h
81221@@ -25,6 +25,7 @@
81222 #include <linux/etherdevice.h>
81223 #include <net/cfg80211.h>
81224 #include <net/mac80211.h>
81225+#include <asm/local.h>
81226 #include "key.h"
81227 #include "sta_info.h"
81228
81229@@ -635,7 +636,7 @@ struct ieee80211_local {
81230 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81231 spinlock_t queue_stop_reason_lock;
81232
81233- int open_count;
81234+ local_t open_count;
81235 int monitors, cooked_mntrs;
81236 /* number of interfaces with corresponding FIF_ flags */
81237 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
81238diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81239index 079c500..eb3c6d4 100644
81240--- a/net/mac80211/iface.c
81241+++ b/net/mac80211/iface.c
81242@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_device *dev)
81243 break;
81244 }
81245
81246- if (local->open_count == 0) {
81247+ if (local_read(&local->open_count) == 0) {
81248 res = drv_start(local);
81249 if (res)
81250 goto err_del_bss;
81251@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_device *dev)
81252 * Validate the MAC address for this device.
81253 */
81254 if (!is_valid_ether_addr(dev->dev_addr)) {
81255- if (!local->open_count)
81256+ if (!local_read(&local->open_count))
81257 drv_stop(local);
81258 return -EADDRNOTAVAIL;
81259 }
81260@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_device *dev)
81261
81262 hw_reconf_flags |= __ieee80211_recalc_idle(local);
81263
81264- local->open_count++;
81265+ local_inc(&local->open_count);
81266 if (hw_reconf_flags) {
81267 ieee80211_hw_config(local, hw_reconf_flags);
81268 /*
81269@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_device *dev)
81270 err_del_interface:
81271 drv_remove_interface(local, &conf);
81272 err_stop:
81273- if (!local->open_count)
81274+ if (!local_read(&local->open_count))
81275 drv_stop(local);
81276 err_del_bss:
81277 sdata->bss = NULL;
81278@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_device *dev)
81279 WARN_ON(!list_empty(&sdata->u.ap.vlans));
81280 }
81281
81282- local->open_count--;
81283+ local_dec(&local->open_count);
81284
81285 switch (sdata->vif.type) {
81286 case NL80211_IFTYPE_AP_VLAN:
81287@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_device *dev)
81288
81289 ieee80211_recalc_ps(local, -1);
81290
81291- if (local->open_count == 0) {
81292+ if (local_read(&local->open_count) == 0) {
81293 ieee80211_clear_tx_pending(local);
81294 ieee80211_stop_device(local);
81295
81296diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81297index 2dfe176..74e4388 100644
81298--- a/net/mac80211/main.c
81299+++ b/net/mac80211/main.c
81300@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81301 local->hw.conf.power_level = power;
81302 }
81303
81304- if (changed && local->open_count) {
81305+ if (changed && local_read(&local->open_count)) {
81306 ret = drv_config(local, changed);
81307 /*
81308 * Goal:
81309diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
81310index e67eea7..fcc227e 100644
81311--- a/net/mac80211/mlme.c
81312+++ b/net/mac80211/mlme.c
81313@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
81314 bool have_higher_than_11mbit = false, newsta = false;
81315 u16 ap_ht_cap_flags;
81316
81317+ pax_track_stack();
81318+
81319 /*
81320 * AssocResp and ReassocResp have identical structure, so process both
81321 * of them in this function.
81322diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81323index e535f1c..4d733d1 100644
81324--- a/net/mac80211/pm.c
81325+++ b/net/mac80211/pm.c
81326@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
81327 }
81328
81329 /* stop hardware - this must stop RX */
81330- if (local->open_count)
81331+ if (local_read(&local->open_count))
81332 ieee80211_stop_device(local);
81333
81334 local->suspended = true;
81335diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81336index b33efc4..0a2efb6 100644
81337--- a/net/mac80211/rate.c
81338+++ b/net/mac80211/rate.c
81339@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81340 struct rate_control_ref *ref, *old;
81341
81342 ASSERT_RTNL();
81343- if (local->open_count)
81344+ if (local_read(&local->open_count))
81345 return -EBUSY;
81346
81347 ref = rate_control_alloc(name, local);
81348diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
81349index b1d7904..57e4da7 100644
81350--- a/net/mac80211/tx.c
81351+++ b/net/mac80211/tx.c
81352@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
81353 return cpu_to_le16(dur);
81354 }
81355
81356-static int inline is_ieee80211_device(struct ieee80211_local *local,
81357+static inline int is_ieee80211_device(struct ieee80211_local *local,
81358 struct net_device *dev)
81359 {
81360 return local == wdev_priv(dev->ieee80211_ptr);
81361diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81362index 31b1085..48fb26d 100644
81363--- a/net/mac80211/util.c
81364+++ b/net/mac80211/util.c
81365@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81366 local->resuming = true;
81367
81368 /* restart hardware */
81369- if (local->open_count) {
81370+ if (local_read(&local->open_count)) {
81371 /*
81372 * Upon resume hardware can sometimes be goofy due to
81373 * various platform / driver / bus issues, so restarting
81374diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81375index 634d14a..b35a608 100644
81376--- a/net/netfilter/Kconfig
81377+++ b/net/netfilter/Kconfig
81378@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
81379
81380 To compile it as a module, choose M here. If unsure, say N.
81381
81382+config NETFILTER_XT_MATCH_GRADM
81383+ tristate '"gradm" match support'
81384+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81385+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81386+ ---help---
81387+ The gradm match allows to match on grsecurity RBAC being enabled.
81388+ It is useful when iptables rules are applied early on bootup to
81389+ prevent connections to the machine (except from a trusted host)
81390+ while the RBAC system is disabled.
81391+
81392 config NETFILTER_XT_MATCH_HASHLIMIT
81393 tristate '"hashlimit" match support'
81394 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81395diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81396index 49f62ee..a17b2c6 100644
81397--- a/net/netfilter/Makefile
81398+++ b/net/netfilter/Makefile
81399@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
81400 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
81401 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81402 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81403+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81404 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81405 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81406 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81407diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
81408index 3c7e427..724043c 100644
81409--- a/net/netfilter/ipvs/ip_vs_app.c
81410+++ b/net/netfilter/ipvs/ip_vs_app.c
81411@@ -564,7 +564,7 @@ static const struct file_operations ip_vs_app_fops = {
81412 .open = ip_vs_app_open,
81413 .read = seq_read,
81414 .llseek = seq_lseek,
81415- .release = seq_release,
81416+ .release = seq_release_net,
81417 };
81418 #endif
81419
81420diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81421index 95682e5..457dbac 100644
81422--- a/net/netfilter/ipvs/ip_vs_conn.c
81423+++ b/net/netfilter/ipvs/ip_vs_conn.c
81424@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81425 /* if the connection is not template and is created
81426 * by sync, preserve the activity flag.
81427 */
81428- cp->flags |= atomic_read(&dest->conn_flags) &
81429+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
81430 (~IP_VS_CONN_F_INACTIVE);
81431 else
81432- cp->flags |= atomic_read(&dest->conn_flags);
81433+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
81434 cp->dest = dest;
81435
81436 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
81437@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
81438 atomic_set(&cp->refcnt, 1);
81439
81440 atomic_set(&cp->n_control, 0);
81441- atomic_set(&cp->in_pkts, 0);
81442+ atomic_set_unchecked(&cp->in_pkts, 0);
81443
81444 atomic_inc(&ip_vs_conn_count);
81445 if (flags & IP_VS_CONN_F_NO_CPORT)
81446@@ -871,7 +871,7 @@ static const struct file_operations ip_vs_conn_fops = {
81447 .open = ip_vs_conn_open,
81448 .read = seq_read,
81449 .llseek = seq_lseek,
81450- .release = seq_release,
81451+ .release = seq_release_net,
81452 };
81453
81454 static const char *ip_vs_origin_name(unsigned flags)
81455@@ -934,7 +934,7 @@ static const struct file_operations ip_vs_conn_sync_fops = {
81456 .open = ip_vs_conn_sync_open,
81457 .read = seq_read,
81458 .llseek = seq_lseek,
81459- .release = seq_release,
81460+ .release = seq_release_net,
81461 };
81462
81463 #endif
81464@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81465
81466 /* Don't drop the entry if its number of incoming packets is not
81467 located in [0, 8] */
81468- i = atomic_read(&cp->in_pkts);
81469+ i = atomic_read_unchecked(&cp->in_pkts);
81470 if (i > 8 || i < 0) return 0;
81471
81472 if (!todrop_rate[i]) return 0;
81473diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81474index b95699f..5fee919 100644
81475--- a/net/netfilter/ipvs/ip_vs_core.c
81476+++ b/net/netfilter/ipvs/ip_vs_core.c
81477@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81478 ret = cp->packet_xmit(skb, cp, pp);
81479 /* do not touch skb anymore */
81480
81481- atomic_inc(&cp->in_pkts);
81482+ atomic_inc_unchecked(&cp->in_pkts);
81483 ip_vs_conn_put(cp);
81484 return ret;
81485 }
81486@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
81487 * Sync connection if it is about to close to
81488 * encorage the standby servers to update the connections timeout
81489 */
81490- pkts = atomic_add_return(1, &cp->in_pkts);
81491+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81492 if (af == AF_INET &&
81493 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
81494 (((cp->protocol != IPPROTO_TCP ||
81495diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81496index 02b2610..2d89424 100644
81497--- a/net/netfilter/ipvs/ip_vs_ctl.c
81498+++ b/net/netfilter/ipvs/ip_vs_ctl.c
81499@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc,
81500 ip_vs_rs_hash(dest);
81501 write_unlock_bh(&__ip_vs_rs_lock);
81502 }
81503- atomic_set(&dest->conn_flags, conn_flags);
81504+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
81505
81506 /* bind the service */
81507 if (!dest->svc) {
81508@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81509 " %-7s %-6d %-10d %-10d\n",
81510 &dest->addr.in6,
81511 ntohs(dest->port),
81512- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81513+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81514 atomic_read(&dest->weight),
81515 atomic_read(&dest->activeconns),
81516 atomic_read(&dest->inactconns));
81517@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81518 "%-7s %-6d %-10d %-10d\n",
81519 ntohl(dest->addr.ip),
81520 ntohs(dest->port),
81521- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81522+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81523 atomic_read(&dest->weight),
81524 atomic_read(&dest->activeconns),
81525 atomic_read(&dest->inactconns));
81526@@ -1927,7 +1927,7 @@ static const struct file_operations ip_vs_info_fops = {
81527 .open = ip_vs_info_open,
81528 .read = seq_read,
81529 .llseek = seq_lseek,
81530- .release = seq_release_private,
81531+ .release = seq_release_net,
81532 };
81533
81534 #endif
81535@@ -1976,7 +1976,7 @@ static const struct file_operations ip_vs_stats_fops = {
81536 .open = ip_vs_stats_seq_open,
81537 .read = seq_read,
81538 .llseek = seq_lseek,
81539- .release = single_release,
81540+ .release = single_release_net,
81541 };
81542
81543 #endif
81544@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip_vs_get_dests *get,
81545
81546 entry.addr = dest->addr.ip;
81547 entry.port = dest->port;
81548- entry.conn_flags = atomic_read(&dest->conn_flags);
81549+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81550 entry.weight = atomic_read(&dest->weight);
81551 entry.u_threshold = dest->u_threshold;
81552 entry.l_threshold = dest->l_threshold;
81553@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81554 unsigned char arg[128];
81555 int ret = 0;
81556
81557+ pax_track_stack();
81558+
81559 if (!capable(CAP_NET_ADMIN))
81560 return -EPERM;
81561
81562@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81563 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
81564
81565 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81566- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
81567+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
81568 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
81569 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
81570 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
81571diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81572index e177f0d..55e8581 100644
81573--- a/net/netfilter/ipvs/ip_vs_sync.c
81574+++ b/net/netfilter/ipvs/ip_vs_sync.c
81575@@ -438,7 +438,7 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
81576
81577 if (opt)
81578 memcpy(&cp->in_seq, opt, sizeof(*opt));
81579- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
81580+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
81581 cp->state = state;
81582 cp->old_state = cp->state;
81583 /*
81584diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81585index 30b3189..e2e4b55 100644
81586--- a/net/netfilter/ipvs/ip_vs_xmit.c
81587+++ b/net/netfilter/ipvs/ip_vs_xmit.c
81588@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81589 else
81590 rc = NF_ACCEPT;
81591 /* do not touch skb anymore */
81592- atomic_inc(&cp->in_pkts);
81593+ atomic_inc_unchecked(&cp->in_pkts);
81594 goto out;
81595 }
81596
81597@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81598 else
81599 rc = NF_ACCEPT;
81600 /* do not touch skb anymore */
81601- atomic_inc(&cp->in_pkts);
81602+ atomic_inc_unchecked(&cp->in_pkts);
81603 goto out;
81604 }
81605
81606diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
81607index d521718..d0fd7a1 100644
81608--- a/net/netfilter/nf_conntrack_netlink.c
81609+++ b/net/netfilter/nf_conntrack_netlink.c
81610@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
81611 static int
81612 ctnetlink_parse_tuple(const struct nlattr * const cda[],
81613 struct nf_conntrack_tuple *tuple,
81614- enum ctattr_tuple type, u_int8_t l3num)
81615+ enum ctattr_type type, u_int8_t l3num)
81616 {
81617 struct nlattr *tb[CTA_TUPLE_MAX+1];
81618 int err;
81619diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81620index f900dc3..5e45346 100644
81621--- a/net/netfilter/nfnetlink_log.c
81622+++ b/net/netfilter/nfnetlink_log.c
81623@@ -68,7 +68,7 @@ struct nfulnl_instance {
81624 };
81625
81626 static DEFINE_RWLOCK(instances_lock);
81627-static atomic_t global_seq;
81628+static atomic_unchecked_t global_seq;
81629
81630 #define INSTANCE_BUCKETS 16
81631 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81632@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81633 /* global sequence number */
81634 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
81635 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
81636- htonl(atomic_inc_return(&global_seq)));
81637+ htonl(atomic_inc_return_unchecked(&global_seq)));
81638
81639 if (data_len) {
81640 struct nlattr *nla;
81641diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81642new file mode 100644
81643index 0000000..b1bac76
81644--- /dev/null
81645+++ b/net/netfilter/xt_gradm.c
81646@@ -0,0 +1,51 @@
81647+/*
81648+ * gradm match for netfilter
81649