]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.51-201112222105.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.51-201112222105.patch
CommitLineData
60dcdb15
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 1c640ea..b545bdc 100644
189--- a/Makefile
190+++ b/Makefile
191@@ -221,8 +221,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
192
193 HOSTCC = gcc
194 HOSTCXX = g++
195-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
196-HOSTCXXFLAGS = -O2
197+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
198+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
199+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
200
201 # Decide whether to build built-in, modular, or both.
202 # Normally, just do built-in.
203@@ -376,8 +377,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
204 # Rules shared between *config targets and build targets
205
206 # Basic helpers built in scripts/
207-PHONY += scripts_basic
208-scripts_basic:
209+PHONY += scripts_basic gcc-plugins
210+scripts_basic: gcc-plugins
211 $(Q)$(MAKE) $(build)=scripts/basic
212
213 # To avoid any implicit rule to kick in, define an empty command.
214@@ -403,7 +404,7 @@ endif
215 # of make so .config is not included in this case either (for *config).
216
217 no-dot-config-targets := clean mrproper distclean \
218- cscope TAGS tags help %docs check% \
219+ cscope gtags TAGS tags help %docs check% \
220 include/linux/version.h headers_% \
221 kernelrelease kernelversion
222
223@@ -526,6 +527,42 @@ else
224 KBUILD_CFLAGS += -O2
225 endif
226
227+ifndef DISABLE_PAX_PLUGINS
228+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
229+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
230+CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
231+endif
232+ifdef CONFIG_PAX_MEMORY_STACKLEAK
233+STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
234+STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
235+endif
236+ifdef CONFIG_KALLOCSTAT_PLUGIN
237+KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
238+endif
239+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
240+KERNEXEC_PLUGIN := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
241+KERNEXEC_PLUGIN += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD)
242+endif
243+ifdef CONFIG_CHECKER_PLUGIN
244+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
245+CHECKER_PLUGIN := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
246+endif
247+endif
248+GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN) $(KERNEXEC_PLUGIN) $(CHECKER_PLUGIN)
249+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
250+gcc-plugins:
251+ $(Q)$(MAKE) $(build)=tools/gcc
252+else
253+gcc-plugins:
254+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
255+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
256+else
257+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
258+endif
259+ $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
260+endif
261+endif
262+
263 include $(srctree)/arch/$(SRCARCH)/Makefile
264
265 ifneq ($(CONFIG_FRAME_WARN),0)
266@@ -647,7 +684,7 @@ export mod_strip_cmd
267
268
269 ifeq ($(KBUILD_EXTMOD),)
270-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
271+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
272
273 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
274 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
275@@ -868,6 +905,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
276
277 # The actual objects are generated when descending,
278 # make sure no implicit rule kicks in
279+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
280 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
281
282 # Handle descending into subdirectories listed in $(vmlinux-dirs)
283@@ -877,7 +915,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
284 # Error messages still appears in the original language
285
286 PHONY += $(vmlinux-dirs)
287-$(vmlinux-dirs): prepare scripts
288+$(vmlinux-dirs): gcc-plugins prepare scripts
289 $(Q)$(MAKE) $(build)=$@
290
291 # Build the kernel release string
292@@ -986,6 +1024,7 @@ prepare0: archprepare FORCE
293 $(Q)$(MAKE) $(build)=. missing-syscalls
294
295 # All the preparing..
296+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
297 prepare: prepare0
298
299 # The asm symlink changes when $(ARCH) changes.
300@@ -1127,6 +1166,7 @@ all: modules
301 # using awk while concatenating to the final file.
302
303 PHONY += modules
304+modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
305 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
306 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
307 @$(kecho) ' Building modules, stage 2.';
308@@ -1136,7 +1176,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
309
310 # Target to prepare building external modules
311 PHONY += modules_prepare
312-modules_prepare: prepare scripts
313+modules_prepare: gcc-plugins prepare scripts
314
315 # Target to install modules
316 PHONY += modules_install
317@@ -1201,7 +1241,7 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
318 include/linux/autoconf.h include/linux/version.h \
319 include/linux/utsrelease.h \
320 include/linux/bounds.h include/asm*/asm-offsets.h \
321- Module.symvers Module.markers tags TAGS cscope*
322+ Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
323
324 # clean - Delete most, but leave enough to build external modules
325 #
326@@ -1245,7 +1285,7 @@ distclean: mrproper
327 @find $(srctree) $(RCS_FIND_IGNORE) \
328 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
329 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
330- -o -name '.*.rej' -o -size 0 \
331+ -o -name '.*.rej' -o -name '*.so' -o -size 0 \
332 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
333 -type f -print | xargs rm -f
334
335@@ -1292,6 +1332,7 @@ help:
336 @echo ' modules_prepare - Set up for building external modules'
337 @echo ' tags/TAGS - Generate tags file for editors'
338 @echo ' cscope - Generate cscope index'
339+ @echo ' gtags - Generate GNU GLOBAL index'
340 @echo ' kernelrelease - Output the release version string'
341 @echo ' kernelversion - Output the version stored in Makefile'
342 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
343@@ -1393,6 +1434,7 @@ PHONY += $(module-dirs) modules
344 $(module-dirs): crmodverdir $(objtree)/Module.symvers
345 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
346
347+modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
348 modules: $(module-dirs)
349 @$(kecho) ' Building modules, stage 2.';
350 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
351@@ -1448,7 +1490,7 @@ endif # KBUILD_EXTMOD
352 quiet_cmd_tags = GEN $@
353 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
354
355-tags TAGS cscope: FORCE
356+tags TAGS cscope gtags: FORCE
357 $(call cmd,tags)
358
359 # Scripts to check various things for consistency
360@@ -1513,17 +1555,19 @@ else
361 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
362 endif
363
364-%.s: %.c prepare scripts FORCE
365+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
366+%.s: %.c gcc-plugins prepare scripts FORCE
367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
368 %.i: %.c prepare scripts FORCE
369 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
370-%.o: %.c prepare scripts FORCE
371+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
372+%.o: %.c gcc-plugins prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 %.lst: %.c prepare scripts FORCE
375 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
376-%.s: %.S prepare scripts FORCE
377+%.s: %.S gcc-plugins prepare scripts FORCE
378 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
379-%.o: %.S prepare scripts FORCE
380+%.o: %.S gcc-plugins prepare scripts FORCE
381 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
382 %.symtypes: %.c prepare scripts FORCE
383 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
384@@ -1533,11 +1577,13 @@ endif
385 $(cmd_crmodverdir)
386 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
387 $(build)=$(build-dir)
388-%/: prepare scripts FORCE
389+%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
390+%/: gcc-plugins prepare scripts FORCE
391 $(cmd_crmodverdir)
392 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
393 $(build)=$(build-dir)
394-%.ko: prepare scripts FORCE
395+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
396+%.ko: gcc-plugins prepare scripts FORCE
397 $(cmd_crmodverdir)
398 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
399 $(build)=$(build-dir) $(@:.ko=.o)
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 829edf0..672adb3 100644
26006--- a/arch/x86/oprofile/backtrace.c
26007+++ b/arch/x86/oprofile/backtrace.c
26008@@ -115,7 +115,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26009 {
26010 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
26011
26012- if (!user_mode_vm(regs)) {
26013+ if (!user_mode(regs)) {
26014 unsigned long stack = kernel_stack_pointer(regs);
26015 if (depth)
26016 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26017diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
26018index e6a160a..36deff6 100644
26019--- a/arch/x86/oprofile/op_model_p4.c
26020+++ b/arch/x86/oprofile/op_model_p4.c
26021@@ -50,7 +50,7 @@ static inline void setup_num_counters(void)
26022 #endif
26023 }
26024
26025-static int inline addr_increment(void)
26026+static inline int addr_increment(void)
26027 {
26028 #ifdef CONFIG_SMP
26029 return smp_num_siblings == 2 ? 2 : 1;
26030diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
26031index 1331fcf..03901b2 100644
26032--- a/arch/x86/pci/common.c
26033+++ b/arch/x86/pci/common.c
26034@@ -31,8 +31,8 @@ int noioapicreroute = 1;
26035 int pcibios_last_bus = -1;
26036 unsigned long pirq_table_addr;
26037 struct pci_bus *pci_root_bus;
26038-struct pci_raw_ops *raw_pci_ops;
26039-struct pci_raw_ops *raw_pci_ext_ops;
26040+const struct pci_raw_ops *raw_pci_ops;
26041+const struct pci_raw_ops *raw_pci_ext_ops;
26042
26043 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
26044 int reg, int len, u32 *val)
26045diff --git a/arch/x86/pci/direct.c b/arch/x86/pci/direct.c
26046index 347d882..4baf6b6 100644
26047--- a/arch/x86/pci/direct.c
26048+++ b/arch/x86/pci/direct.c
26049@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
26050
26051 #undef PCI_CONF1_ADDRESS
26052
26053-struct pci_raw_ops pci_direct_conf1 = {
26054+const struct pci_raw_ops pci_direct_conf1 = {
26055 .read = pci_conf1_read,
26056 .write = pci_conf1_write,
26057 };
26058@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
26059
26060 #undef PCI_CONF2_ADDRESS
26061
26062-struct pci_raw_ops pci_direct_conf2 = {
26063+const struct pci_raw_ops pci_direct_conf2 = {
26064 .read = pci_conf2_read,
26065 .write = pci_conf2_write,
26066 };
26067@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
26068 * This should be close to trivial, but it isn't, because there are buggy
26069 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
26070 */
26071-static int __init pci_sanity_check(struct pci_raw_ops *o)
26072+static int __init pci_sanity_check(const struct pci_raw_ops *o)
26073 {
26074 u32 x = 0;
26075 int year, devfn;
26076diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c
26077index f10a7e9..0425342 100644
26078--- a/arch/x86/pci/mmconfig_32.c
26079+++ b/arch/x86/pci/mmconfig_32.c
26080@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26081 return 0;
26082 }
26083
26084-static struct pci_raw_ops pci_mmcfg = {
26085+static const struct pci_raw_ops pci_mmcfg = {
26086 .read = pci_mmcfg_read,
26087 .write = pci_mmcfg_write,
26088 };
26089diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c
26090index 94349f8..41600a7 100644
26091--- a/arch/x86/pci/mmconfig_64.c
26092+++ b/arch/x86/pci/mmconfig_64.c
26093@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26094 return 0;
26095 }
26096
26097-static struct pci_raw_ops pci_mmcfg = {
26098+static const struct pci_raw_ops pci_mmcfg = {
26099 .read = pci_mmcfg_read,
26100 .write = pci_mmcfg_write,
26101 };
26102diff --git a/arch/x86/pci/numaq_32.c b/arch/x86/pci/numaq_32.c
26103index 8eb295e..86bd657 100644
26104--- a/arch/x86/pci/numaq_32.c
26105+++ b/arch/x86/pci/numaq_32.c
26106@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
26107
26108 #undef PCI_CONF1_MQ_ADDRESS
26109
26110-static struct pci_raw_ops pci_direct_conf1_mq = {
26111+static const struct pci_raw_ops pci_direct_conf1_mq = {
26112 .read = pci_conf1_mq_read,
26113 .write = pci_conf1_mq_write
26114 };
26115diff --git a/arch/x86/pci/olpc.c b/arch/x86/pci/olpc.c
26116index b889d82..5a58a0a 100644
26117--- a/arch/x86/pci/olpc.c
26118+++ b/arch/x86/pci/olpc.c
26119@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int seg, unsigned int bus,
26120 return 0;
26121 }
26122
26123-static struct pci_raw_ops pci_olpc_conf = {
26124+static const struct pci_raw_ops pci_olpc_conf = {
26125 .read = pci_olpc_read,
26126 .write = pci_olpc_write,
26127 };
26128diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26129index 1c975cc..ffd0536 100644
26130--- a/arch/x86/pci/pcbios.c
26131+++ b/arch/x86/pci/pcbios.c
26132@@ -56,50 +56,93 @@ union bios32 {
26133 static struct {
26134 unsigned long address;
26135 unsigned short segment;
26136-} bios32_indirect = { 0, __KERNEL_CS };
26137+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26138
26139 /*
26140 * Returns the entry point for the given service, NULL on error
26141 */
26142
26143-static unsigned long bios32_service(unsigned long service)
26144+static unsigned long __devinit bios32_service(unsigned long service)
26145 {
26146 unsigned char return_code; /* %al */
26147 unsigned long address; /* %ebx */
26148 unsigned long length; /* %ecx */
26149 unsigned long entry; /* %edx */
26150 unsigned long flags;
26151+ struct desc_struct d, *gdt;
26152
26153 local_irq_save(flags);
26154- __asm__("lcall *(%%edi); cld"
26155+
26156+ gdt = get_cpu_gdt_table(smp_processor_id());
26157+
26158+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26159+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26160+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26161+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26162+
26163+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26164 : "=a" (return_code),
26165 "=b" (address),
26166 "=c" (length),
26167 "=d" (entry)
26168 : "0" (service),
26169 "1" (0),
26170- "D" (&bios32_indirect));
26171+ "D" (&bios32_indirect),
26172+ "r"(__PCIBIOS_DS)
26173+ : "memory");
26174+
26175+ pax_open_kernel();
26176+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26177+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26178+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26179+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26180+ pax_close_kernel();
26181+
26182 local_irq_restore(flags);
26183
26184 switch (return_code) {
26185- case 0:
26186- return address + entry;
26187- case 0x80: /* Not present */
26188- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26189- return 0;
26190- default: /* Shouldn't happen */
26191- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26192- service, return_code);
26193+ case 0: {
26194+ int cpu;
26195+ unsigned char flags;
26196+
26197+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26198+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26199+ printk(KERN_WARNING "bios32_service: not valid\n");
26200 return 0;
26201+ }
26202+ address = address + PAGE_OFFSET;
26203+ length += 16UL; /* some BIOSs underreport this... */
26204+ flags = 4;
26205+ if (length >= 64*1024*1024) {
26206+ length >>= PAGE_SHIFT;
26207+ flags |= 8;
26208+ }
26209+
26210+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
26211+ gdt = get_cpu_gdt_table(cpu);
26212+ pack_descriptor(&d, address, length, 0x9b, flags);
26213+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26214+ pack_descriptor(&d, address, length, 0x93, flags);
26215+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26216+ }
26217+ return entry;
26218+ }
26219+ case 0x80: /* Not present */
26220+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26221+ return 0;
26222+ default: /* Shouldn't happen */
26223+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26224+ service, return_code);
26225+ return 0;
26226 }
26227 }
26228
26229 static struct {
26230 unsigned long address;
26231 unsigned short segment;
26232-} pci_indirect = { 0, __KERNEL_CS };
26233+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26234
26235-static int pci_bios_present;
26236+static int pci_bios_present __read_only;
26237
26238 static int __devinit check_pcibios(void)
26239 {
26240@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
26241 unsigned long flags, pcibios_entry;
26242
26243 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26244- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26245+ pci_indirect.address = pcibios_entry;
26246
26247 local_irq_save(flags);
26248- __asm__(
26249- "lcall *(%%edi); cld\n\t"
26250+ __asm__("movw %w6, %%ds\n\t"
26251+ "lcall *%%ss:(%%edi); cld\n\t"
26252+ "push %%ss\n\t"
26253+ "pop %%ds\n\t"
26254 "jc 1f\n\t"
26255 "xor %%ah, %%ah\n"
26256 "1:"
26257@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
26258 "=b" (ebx),
26259 "=c" (ecx)
26260 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26261- "D" (&pci_indirect)
26262+ "D" (&pci_indirect),
26263+ "r" (__PCIBIOS_DS)
26264 : "memory");
26265 local_irq_restore(flags);
26266
26267@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26268
26269 switch (len) {
26270 case 1:
26271- __asm__("lcall *(%%esi); cld\n\t"
26272+ __asm__("movw %w6, %%ds\n\t"
26273+ "lcall *%%ss:(%%esi); cld\n\t"
26274+ "push %%ss\n\t"
26275+ "pop %%ds\n\t"
26276 "jc 1f\n\t"
26277 "xor %%ah, %%ah\n"
26278 "1:"
26279@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26280 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26281 "b" (bx),
26282 "D" ((long)reg),
26283- "S" (&pci_indirect));
26284+ "S" (&pci_indirect),
26285+ "r" (__PCIBIOS_DS));
26286 /*
26287 * Zero-extend the result beyond 8 bits, do not trust the
26288 * BIOS having done it:
26289@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26290 *value &= 0xff;
26291 break;
26292 case 2:
26293- __asm__("lcall *(%%esi); cld\n\t"
26294+ __asm__("movw %w6, %%ds\n\t"
26295+ "lcall *%%ss:(%%esi); cld\n\t"
26296+ "push %%ss\n\t"
26297+ "pop %%ds\n\t"
26298 "jc 1f\n\t"
26299 "xor %%ah, %%ah\n"
26300 "1:"
26301@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26302 : "1" (PCIBIOS_READ_CONFIG_WORD),
26303 "b" (bx),
26304 "D" ((long)reg),
26305- "S" (&pci_indirect));
26306+ "S" (&pci_indirect),
26307+ "r" (__PCIBIOS_DS));
26308 /*
26309 * Zero-extend the result beyond 16 bits, do not trust the
26310 * BIOS having done it:
26311@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26312 *value &= 0xffff;
26313 break;
26314 case 4:
26315- __asm__("lcall *(%%esi); cld\n\t"
26316+ __asm__("movw %w6, %%ds\n\t"
26317+ "lcall *%%ss:(%%esi); cld\n\t"
26318+ "push %%ss\n\t"
26319+ "pop %%ds\n\t"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26324 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26325 "b" (bx),
26326 "D" ((long)reg),
26327- "S" (&pci_indirect));
26328+ "S" (&pci_indirect),
26329+ "r" (__PCIBIOS_DS));
26330 break;
26331 }
26332
26333@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26334
26335 switch (len) {
26336 case 1:
26337- __asm__("lcall *(%%esi); cld\n\t"
26338+ __asm__("movw %w6, %%ds\n\t"
26339+ "lcall *%%ss:(%%esi); cld\n\t"
26340+ "push %%ss\n\t"
26341+ "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26346 "c" (value),
26347 "b" (bx),
26348 "D" ((long)reg),
26349- "S" (&pci_indirect));
26350+ "S" (&pci_indirect),
26351+ "r" (__PCIBIOS_DS));
26352 break;
26353 case 2:
26354- __asm__("lcall *(%%esi); cld\n\t"
26355+ __asm__("movw %w6, %%ds\n\t"
26356+ "lcall *%%ss:(%%esi); cld\n\t"
26357+ "push %%ss\n\t"
26358+ "pop %%ds\n\t"
26359 "jc 1f\n\t"
26360 "xor %%ah, %%ah\n"
26361 "1:"
26362@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26363 "c" (value),
26364 "b" (bx),
26365 "D" ((long)reg),
26366- "S" (&pci_indirect));
26367+ "S" (&pci_indirect),
26368+ "r" (__PCIBIOS_DS));
26369 break;
26370 case 4:
26371- __asm__("lcall *(%%esi); cld\n\t"
26372+ __asm__("movw %w6, %%ds\n\t"
26373+ "lcall *%%ss:(%%esi); cld\n\t"
26374+ "push %%ss\n\t"
26375+ "pop %%ds\n\t"
26376 "jc 1f\n\t"
26377 "xor %%ah, %%ah\n"
26378 "1:"
26379@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26380 "c" (value),
26381 "b" (bx),
26382 "D" ((long)reg),
26383- "S" (&pci_indirect));
26384+ "S" (&pci_indirect),
26385+ "r" (__PCIBIOS_DS));
26386 break;
26387 }
26388
26389@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26390 * Function table for BIOS32 access
26391 */
26392
26393-static struct pci_raw_ops pci_bios_access = {
26394+static const struct pci_raw_ops pci_bios_access = {
26395 .read = pci_bios_read,
26396 .write = pci_bios_write
26397 };
26398@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_access = {
26399 * Try to find PCI BIOS.
26400 */
26401
26402-static struct pci_raw_ops * __devinit pci_find_bios(void)
26403+static const struct pci_raw_ops * __devinit pci_find_bios(void)
26404 {
26405 union bios32 *check;
26406 unsigned char sum;
26407@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26408
26409 DBG("PCI: Fetching IRQ routing table... ");
26410 __asm__("push %%es\n\t"
26411+ "movw %w8, %%ds\n\t"
26412 "push %%ds\n\t"
26413 "pop %%es\n\t"
26414- "lcall *(%%esi); cld\n\t"
26415+ "lcall *%%ss:(%%esi); cld\n\t"
26416 "pop %%es\n\t"
26417+ "push %%ss\n\t"
26418+ "pop %%ds\n"
26419 "jc 1f\n\t"
26420 "xor %%ah, %%ah\n"
26421 "1:"
26422@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26423 "1" (0),
26424 "D" ((long) &opt),
26425 "S" (&pci_indirect),
26426- "m" (opt)
26427+ "m" (opt),
26428+ "r" (__PCIBIOS_DS)
26429 : "memory");
26430 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26431 if (ret & 0xff00)
26432@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26433 {
26434 int ret;
26435
26436- __asm__("lcall *(%%esi); cld\n\t"
26437+ __asm__("movw %w5, %%ds\n\t"
26438+ "lcall *%%ss:(%%esi); cld\n\t"
26439+ "push %%ss\n\t"
26440+ "pop %%ds\n"
26441 "jc 1f\n\t"
26442 "xor %%ah, %%ah\n"
26443 "1:"
26444@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26445 : "0" (PCIBIOS_SET_PCI_HW_INT),
26446 "b" ((dev->bus->number << 8) | dev->devfn),
26447 "c" ((irq << 8) | (pin + 10)),
26448- "S" (&pci_indirect));
26449+ "S" (&pci_indirect),
26450+ "r" (__PCIBIOS_DS));
26451 return !(ret & 0xff00);
26452 }
26453 EXPORT_SYMBOL(pcibios_set_irq_routing);
26454diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26455index fa0f651..9d8f3d9 100644
26456--- a/arch/x86/power/cpu.c
26457+++ b/arch/x86/power/cpu.c
26458@@ -129,7 +129,7 @@ static void do_fpu_end(void)
26459 static void fix_processor_context(void)
26460 {
26461 int cpu = smp_processor_id();
26462- struct tss_struct *t = &per_cpu(init_tss, cpu);
26463+ struct tss_struct *t = init_tss + cpu;
26464
26465 set_tss_desc(cpu, t); /*
26466 * This just modifies memory; should not be
26467@@ -139,7 +139,9 @@ static void fix_processor_context(void)
26468 */
26469
26470 #ifdef CONFIG_X86_64
26471+ pax_open_kernel();
26472 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26473+ pax_close_kernel();
26474
26475 syscall_init(); /* This sets MSR_*STAR and related */
26476 #endif
26477diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26478index dd78ef6..f9d928d 100644
26479--- a/arch/x86/vdso/Makefile
26480+++ b/arch/x86/vdso/Makefile
26481@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
26482 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
26483 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
26484
26485-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26486+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26487 GCOV_PROFILE := n
26488
26489 #
26490diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
26491index ee55754..0013b2e 100644
26492--- a/arch/x86/vdso/vclock_gettime.c
26493+++ b/arch/x86/vdso/vclock_gettime.c
26494@@ -22,24 +22,48 @@
26495 #include <asm/hpet.h>
26496 #include <asm/unistd.h>
26497 #include <asm/io.h>
26498+#include <asm/fixmap.h>
26499 #include "vextern.h"
26500
26501 #define gtod vdso_vsyscall_gtod_data
26502
26503+notrace noinline long __vdso_fallback_time(long *t)
26504+{
26505+ long secs;
26506+ asm volatile("syscall"
26507+ : "=a" (secs)
26508+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
26509+ return secs;
26510+}
26511+
26512 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
26513 {
26514 long ret;
26515 asm("syscall" : "=a" (ret) :
26516- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
26517+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
26518 return ret;
26519 }
26520
26521+notrace static inline cycle_t __vdso_vread_hpet(void)
26522+{
26523+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
26524+}
26525+
26526+notrace static inline cycle_t __vdso_vread_tsc(void)
26527+{
26528+ cycle_t ret = (cycle_t)vget_cycles();
26529+
26530+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
26531+}
26532+
26533 notrace static inline long vgetns(void)
26534 {
26535 long v;
26536- cycles_t (*vread)(void);
26537- vread = gtod->clock.vread;
26538- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
26539+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
26540+ v = __vdso_vread_tsc();
26541+ else
26542+ v = __vdso_vread_hpet();
26543+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
26544 return (v * gtod->clock.mult) >> gtod->clock.shift;
26545 }
26546
26547@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic_coarse(struct timespec *ts)
26548
26549 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26550 {
26551- if (likely(gtod->sysctl_enabled))
26552+ if (likely(gtod->sysctl_enabled &&
26553+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26554+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26555 switch (clock) {
26556 case CLOCK_REALTIME:
26557 if (likely(gtod->clock.vread))
26558@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26559 int clock_gettime(clockid_t, struct timespec *)
26560 __attribute__((weak, alias("__vdso_clock_gettime")));
26561
26562+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
26563+{
26564+ long ret;
26565+ asm("syscall" : "=a" (ret) :
26566+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
26567+ return ret;
26568+}
26569+
26570 notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26571 {
26572- long ret;
26573- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
26574+ if (likely(gtod->sysctl_enabled &&
26575+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26576+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26577+ {
26578 if (likely(tv != NULL)) {
26579 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
26580 offsetof(struct timespec, tv_nsec) ||
26581@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26582 }
26583 return 0;
26584 }
26585- asm("syscall" : "=a" (ret) :
26586- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
26587- return ret;
26588+ return __vdso_fallback_gettimeofday(tv, tz);
26589 }
26590 int gettimeofday(struct timeval *, struct timezone *)
26591 __attribute__((weak, alias("__vdso_gettimeofday")));
26592diff --git a/arch/x86/vdso/vdso.lds.S b/arch/x86/vdso/vdso.lds.S
26593index 4e5dd3b..00ba15e 100644
26594--- a/arch/x86/vdso/vdso.lds.S
26595+++ b/arch/x86/vdso/vdso.lds.S
26596@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
26597 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
26598 #include "vextern.h"
26599 #undef VEXTERN
26600+
26601+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
26602+VEXTERN(fallback_gettimeofday)
26603+VEXTERN(fallback_time)
26604+VEXTERN(getcpu)
26605+#undef VEXTERN
26606diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26607index 58bc00f..d53fb48 100644
26608--- a/arch/x86/vdso/vdso32-setup.c
26609+++ b/arch/x86/vdso/vdso32-setup.c
26610@@ -25,6 +25,7 @@
26611 #include <asm/tlbflush.h>
26612 #include <asm/vdso.h>
26613 #include <asm/proto.h>
26614+#include <asm/mman.h>
26615
26616 enum {
26617 VDSO_DISABLED = 0,
26618@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26619 void enable_sep_cpu(void)
26620 {
26621 int cpu = get_cpu();
26622- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26623+ struct tss_struct *tss = init_tss + cpu;
26624
26625 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26626 put_cpu();
26627@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26628 gate_vma.vm_start = FIXADDR_USER_START;
26629 gate_vma.vm_end = FIXADDR_USER_END;
26630 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26631- gate_vma.vm_page_prot = __P101;
26632+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26633 /*
26634 * Make sure the vDSO gets into every core dump.
26635 * Dumping its contents makes post-mortem fully interpretable later
26636@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26637 if (compat)
26638 addr = VDSO_HIGH_BASE;
26639 else {
26640- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26641+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26642 if (IS_ERR_VALUE(addr)) {
26643 ret = addr;
26644 goto up_fail;
26645 }
26646 }
26647
26648- current->mm->context.vdso = (void *)addr;
26649+ current->mm->context.vdso = addr;
26650
26651 if (compat_uses_vma || !compat) {
26652 /*
26653@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26654 }
26655
26656 current_thread_info()->sysenter_return =
26657- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26658+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26659
26660 up_fail:
26661 if (ret)
26662- current->mm->context.vdso = NULL;
26663+ current->mm->context.vdso = 0;
26664
26665 up_write(&mm->mmap_sem);
26666
26667@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
26668
26669 const char *arch_vma_name(struct vm_area_struct *vma)
26670 {
26671- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26672+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26673 return "[vdso]";
26674+
26675+#ifdef CONFIG_PAX_SEGMEXEC
26676+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26677+ return "[vdso]";
26678+#endif
26679+
26680 return NULL;
26681 }
26682
26683@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
26684 struct mm_struct *mm = tsk->mm;
26685
26686 /* Check to see if this task was created in compat vdso mode */
26687- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26688+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26689 return &gate_vma;
26690 return NULL;
26691 }
26692diff --git a/arch/x86/vdso/vextern.h b/arch/x86/vdso/vextern.h
26693index 1683ba2..48d07f3 100644
26694--- a/arch/x86/vdso/vextern.h
26695+++ b/arch/x86/vdso/vextern.h
26696@@ -11,6 +11,5 @@
26697 put into vextern.h and be referenced as a pointer with vdso prefix.
26698 The main kernel later fills in the values. */
26699
26700-VEXTERN(jiffies)
26701 VEXTERN(vgetcpu_mode)
26702 VEXTERN(vsyscall_gtod_data)
26703diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26704index 21e1aeb..2c0b3c4 100644
26705--- a/arch/x86/vdso/vma.c
26706+++ b/arch/x86/vdso/vma.c
26707@@ -17,8 +17,6 @@
26708 #include "vextern.h" /* Just for VMAGIC. */
26709 #undef VEXTERN
26710
26711-unsigned int __read_mostly vdso_enabled = 1;
26712-
26713 extern char vdso_start[], vdso_end[];
26714 extern unsigned short vdso_sync_cpuid;
26715
26716@@ -27,10 +25,8 @@ static unsigned vdso_size;
26717
26718 static inline void *var_ref(void *p, char *name)
26719 {
26720- if (*(void **)p != (void *)VMAGIC) {
26721- printk("VDSO: variable %s broken\n", name);
26722- vdso_enabled = 0;
26723- }
26724+ if (*(void **)p != (void *)VMAGIC)
26725+ panic("VDSO: variable %s broken\n", name);
26726 return p;
26727 }
26728
26729@@ -57,21 +53,18 @@ static int __init init_vdso_vars(void)
26730 if (!vbase)
26731 goto oom;
26732
26733- if (memcmp(vbase, "\177ELF", 4)) {
26734- printk("VDSO: I'm broken; not ELF\n");
26735- vdso_enabled = 0;
26736- }
26737+ if (memcmp(vbase, ELFMAG, SELFMAG))
26738+ panic("VDSO: I'm broken; not ELF\n");
26739
26740 #define VEXTERN(x) \
26741 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
26742 #include "vextern.h"
26743 #undef VEXTERN
26744+ vunmap(vbase);
26745 return 0;
26746
26747 oom:
26748- printk("Cannot allocate vdso\n");
26749- vdso_enabled = 0;
26750- return -ENOMEM;
26751+ panic("Cannot allocate vdso\n");
26752 }
26753 __initcall(init_vdso_vars);
26754
26755@@ -102,13 +95,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26756 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26757 {
26758 struct mm_struct *mm = current->mm;
26759- unsigned long addr;
26760+ unsigned long addr = 0;
26761 int ret;
26762
26763- if (!vdso_enabled)
26764- return 0;
26765-
26766 down_write(&mm->mmap_sem);
26767+
26768+#ifdef CONFIG_PAX_RANDMMAP
26769+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26770+#endif
26771+
26772 addr = vdso_addr(mm->start_stack, vdso_size);
26773 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26774 if (IS_ERR_VALUE(addr)) {
26775@@ -116,7 +111,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26776 goto up_fail;
26777 }
26778
26779- current->mm->context.vdso = (void *)addr;
26780+ current->mm->context.vdso = addr;
26781
26782 ret = install_special_mapping(mm, addr, vdso_size,
26783 VM_READ|VM_EXEC|
26784@@ -124,7 +119,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26785 VM_ALWAYSDUMP,
26786 vdso_pages);
26787 if (ret) {
26788- current->mm->context.vdso = NULL;
26789+ current->mm->context.vdso = 0;
26790 goto up_fail;
26791 }
26792
26793@@ -132,10 +127,3 @@ up_fail:
26794 up_write(&mm->mmap_sem);
26795 return ret;
26796 }
26797-
26798-static __init int vdso_setup(char *s)
26799-{
26800- vdso_enabled = simple_strtoul(s, NULL, 0);
26801- return 0;
26802-}
26803-__setup("vdso=", vdso_setup);
26804diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26805index 0087b00..eecb34f 100644
26806--- a/arch/x86/xen/enlighten.c
26807+++ b/arch/x86/xen/enlighten.c
26808@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26809
26810 struct shared_info xen_dummy_shared_info;
26811
26812-void *xen_initial_gdt;
26813-
26814 /*
26815 * Point at some empty memory to start with. We map the real shared_info
26816 * page as soon as fixmap is up and running.
26817@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g)
26818
26819 preempt_disable();
26820
26821- start = __get_cpu_var(idt_desc).address;
26822+ start = (unsigned long)__get_cpu_var(idt_desc).address;
26823 end = start + __get_cpu_var(idt_desc).size + 1;
26824
26825 xen_mc_flush();
26826@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic_ops __initdata = {
26827 #endif
26828 };
26829
26830-static void xen_reboot(int reason)
26831+static __noreturn void xen_reboot(int reason)
26832 {
26833 struct sched_shutdown r = { .reason = reason };
26834
26835@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
26836 BUG();
26837 }
26838
26839-static void xen_restart(char *msg)
26840+static __noreturn void xen_restart(char *msg)
26841 {
26842 xen_reboot(SHUTDOWN_reboot);
26843 }
26844
26845-static void xen_emergency_restart(void)
26846+static __noreturn void xen_emergency_restart(void)
26847 {
26848 xen_reboot(SHUTDOWN_reboot);
26849 }
26850
26851-static void xen_machine_halt(void)
26852+static __noreturn void xen_machine_halt(void)
26853 {
26854 xen_reboot(SHUTDOWN_poweroff);
26855 }
26856@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(void)
26857 */
26858 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26859
26860-#ifdef CONFIG_X86_64
26861 /* Work out if we support NX */
26862- check_efer();
26863+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26864+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26865+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26866+ unsigned l, h;
26867+
26868+#ifdef CONFIG_X86_PAE
26869+ nx_enabled = 1;
26870+#endif
26871+ __supported_pte_mask |= _PAGE_NX;
26872+ rdmsr(MSR_EFER, l, h);
26873+ l |= EFER_NX;
26874+ wrmsr(MSR_EFER, l, h);
26875+ }
26876 #endif
26877
26878 xen_setup_features();
26879@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(void)
26880
26881 machine_ops = xen_machine_ops;
26882
26883- /*
26884- * The only reliable way to retain the initial address of the
26885- * percpu gdt_page is to remember it here, so we can go and
26886- * mark it RW later, when the initial percpu area is freed.
26887- */
26888- xen_initial_gdt = &per_cpu(gdt_page, 0);
26889-
26890 xen_smp_init();
26891
26892 pgd = (pgd_t *)xen_start_info->pt_base;
26893diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26894index 3f90a2c..2c2ad84 100644
26895--- a/arch/x86/xen/mmu.c
26896+++ b/arch/x86/xen/mmu.c
26897@@ -1719,6 +1719,9 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26898 convert_pfn_mfn(init_level4_pgt);
26899 convert_pfn_mfn(level3_ident_pgt);
26900 convert_pfn_mfn(level3_kernel_pgt);
26901+ convert_pfn_mfn(level3_vmalloc_start_pgt);
26902+ convert_pfn_mfn(level3_vmalloc_end_pgt);
26903+ convert_pfn_mfn(level3_vmemmap_pgt);
26904
26905 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26906 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26907@@ -1737,7 +1740,11 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26908 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26909 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26910 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26911+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26912+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26913+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26914 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26915+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26916 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26917 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26918
26919@@ -1860,6 +1867,7 @@ static __init void xen_post_allocator_init(void)
26920 pv_mmu_ops.set_pud = xen_set_pud;
26921 #if PAGETABLE_LEVELS == 4
26922 pv_mmu_ops.set_pgd = xen_set_pgd;
26923+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26924 #endif
26925
26926 /* This will work as long as patching hasn't happened yet
26927@@ -1946,6 +1954,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
26928 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26929 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26930 .set_pgd = xen_set_pgd_hyper,
26931+ .set_pgd_batched = xen_set_pgd_hyper,
26932
26933 .alloc_pud = xen_alloc_pmd_init,
26934 .release_pud = xen_release_pmd_init,
26935diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26936index a96204a..fca9b8e 100644
26937--- a/arch/x86/xen/smp.c
26938+++ b/arch/x86/xen/smp.c
26939@@ -168,11 +168,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26940 {
26941 BUG_ON(smp_processor_id() != 0);
26942 native_smp_prepare_boot_cpu();
26943-
26944- /* We've switched to the "real" per-cpu gdt, so make sure the
26945- old memory can be recycled */
26946- make_lowmem_page_readwrite(xen_initial_gdt);
26947-
26948 xen_setup_vcpu_info_placement();
26949 }
26950
26951@@ -241,12 +236,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26952 gdt = get_cpu_gdt_table(cpu);
26953
26954 ctxt->flags = VGCF_IN_KERNEL;
26955- ctxt->user_regs.ds = __USER_DS;
26956- ctxt->user_regs.es = __USER_DS;
26957+ ctxt->user_regs.ds = __KERNEL_DS;
26958+ ctxt->user_regs.es = __KERNEL_DS;
26959 ctxt->user_regs.ss = __KERNEL_DS;
26960 #ifdef CONFIG_X86_32
26961 ctxt->user_regs.fs = __KERNEL_PERCPU;
26962- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26963+ savesegment(gs, ctxt->user_regs.gs);
26964 #else
26965 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26966 #endif
26967@@ -297,13 +292,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26968 int rc;
26969
26970 per_cpu(current_task, cpu) = idle;
26971+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26972 #ifdef CONFIG_X86_32
26973 irq_ctx_init(cpu);
26974 #else
26975 clear_tsk_thread_flag(idle, TIF_FORK);
26976- per_cpu(kernel_stack, cpu) =
26977- (unsigned long)task_stack_page(idle) -
26978- KERNEL_STACK_OFFSET + THREAD_SIZE;
26979+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26980 #endif
26981 xen_setup_runstate_info(cpu);
26982 xen_setup_timer(cpu);
26983diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26984index 9a95a9c..4f39e774 100644
26985--- a/arch/x86/xen/xen-asm_32.S
26986+++ b/arch/x86/xen/xen-asm_32.S
26987@@ -83,14 +83,14 @@ ENTRY(xen_iret)
26988 ESP_OFFSET=4 # bytes pushed onto stack
26989
26990 /*
26991- * Store vcpu_info pointer for easy access. Do it this way to
26992- * avoid having to reload %fs
26993+ * Store vcpu_info pointer for easy access.
26994 */
26995 #ifdef CONFIG_SMP
26996- GET_THREAD_INFO(%eax)
26997- movl TI_cpu(%eax), %eax
26998- movl __per_cpu_offset(,%eax,4), %eax
26999- mov per_cpu__xen_vcpu(%eax), %eax
27000+ push %fs
27001+ mov $(__KERNEL_PERCPU), %eax
27002+ mov %eax, %fs
27003+ mov PER_CPU_VAR(xen_vcpu), %eax
27004+ pop %fs
27005 #else
27006 movl per_cpu__xen_vcpu, %eax
27007 #endif
27008diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27009index 1a5ff24..a187d40 100644
27010--- a/arch/x86/xen/xen-head.S
27011+++ b/arch/x86/xen/xen-head.S
27012@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27013 #ifdef CONFIG_X86_32
27014 mov %esi,xen_start_info
27015 mov $init_thread_union+THREAD_SIZE,%esp
27016+#ifdef CONFIG_SMP
27017+ movl $cpu_gdt_table,%edi
27018+ movl $__per_cpu_load,%eax
27019+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27020+ rorl $16,%eax
27021+ movb %al,__KERNEL_PERCPU + 4(%edi)
27022+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27023+ movl $__per_cpu_end - 1,%eax
27024+ subl $__per_cpu_start,%eax
27025+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27026+#endif
27027 #else
27028 mov %rsi,xen_start_info
27029 mov $init_thread_union+THREAD_SIZE,%rsp
27030diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27031index f9153a3..51eab3d 100644
27032--- a/arch/x86/xen/xen-ops.h
27033+++ b/arch/x86/xen/xen-ops.h
27034@@ -10,8 +10,6 @@
27035 extern const char xen_hypervisor_callback[];
27036 extern const char xen_failsafe_callback[];
27037
27038-extern void *xen_initial_gdt;
27039-
27040 struct trap_info;
27041 void xen_copy_trap_info(struct trap_info *traps);
27042
27043diff --git a/block/blk-integrity.c b/block/blk-integrity.c
27044index 15c6308..96e83c2 100644
27045--- a/block/blk-integrity.c
27046+++ b/block/blk-integrity.c
27047@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs[] = {
27048 NULL,
27049 };
27050
27051-static struct sysfs_ops integrity_ops = {
27052+static const struct sysfs_ops integrity_ops = {
27053 .show = &integrity_attr_show,
27054 .store = &integrity_attr_store,
27055 };
27056diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27057index ca56420..f2fc409 100644
27058--- a/block/blk-iopoll.c
27059+++ b/block/blk-iopoll.c
27060@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27061 }
27062 EXPORT_SYMBOL(blk_iopoll_complete);
27063
27064-static void blk_iopoll_softirq(struct softirq_action *h)
27065+static void blk_iopoll_softirq(void)
27066 {
27067 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27068 int rearm = 0, budget = blk_iopoll_budget;
27069diff --git a/block/blk-map.c b/block/blk-map.c
27070index 30a7e51..0aeec6a 100644
27071--- a/block/blk-map.c
27072+++ b/block/blk-map.c
27073@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
27074 * direct dma. else, set up kernel bounce buffers
27075 */
27076 uaddr = (unsigned long) ubuf;
27077- if (blk_rq_aligned(q, ubuf, len) && !map_data)
27078+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
27079 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
27080 else
27081 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
27082@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
27083 for (i = 0; i < iov_count; i++) {
27084 unsigned long uaddr = (unsigned long)iov[i].iov_base;
27085
27086+ if (!iov[i].iov_len)
27087+ return -EINVAL;
27088+
27089 if (uaddr & queue_dma_alignment(q)) {
27090 unaligned = 1;
27091 break;
27092 }
27093- if (!iov[i].iov_len)
27094- return -EINVAL;
27095 }
27096
27097 if (unaligned || (q->dma_pad_mask & len) || map_data)
27098@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27099 if (!len || !kbuf)
27100 return -EINVAL;
27101
27102- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
27103+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
27104 if (do_copy)
27105 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27106 else
27107diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27108index ee9c216..58d410a 100644
27109--- a/block/blk-softirq.c
27110+++ b/block/blk-softirq.c
27111@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27112 * Softirq action handler - move entries to local list and loop over them
27113 * while passing them to the queue registered handler.
27114 */
27115-static void blk_done_softirq(struct softirq_action *h)
27116+static void blk_done_softirq(void)
27117 {
27118 struct list_head *cpu_list, local_list;
27119
27120diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
27121index bb9c5ea..5330d48 100644
27122--- a/block/blk-sysfs.c
27123+++ b/block/blk-sysfs.c
27124@@ -414,7 +414,7 @@ static void blk_release_queue(struct kobject *kobj)
27125 kmem_cache_free(blk_requestq_cachep, q);
27126 }
27127
27128-static struct sysfs_ops queue_sysfs_ops = {
27129+static const struct sysfs_ops queue_sysfs_ops = {
27130 .show = queue_attr_show,
27131 .store = queue_attr_store,
27132 };
27133diff --git a/block/bsg.c b/block/bsg.c
27134index 7154a7a..08ac2f0 100644
27135--- a/block/bsg.c
27136+++ b/block/bsg.c
27137@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27138 struct sg_io_v4 *hdr, struct bsg_device *bd,
27139 fmode_t has_write_perm)
27140 {
27141+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27142+ unsigned char *cmdptr;
27143+
27144 if (hdr->request_len > BLK_MAX_CDB) {
27145 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27146 if (!rq->cmd)
27147 return -ENOMEM;
27148- }
27149+ cmdptr = rq->cmd;
27150+ } else
27151+ cmdptr = tmpcmd;
27152
27153- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
27154+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27155 hdr->request_len))
27156 return -EFAULT;
27157
27158+ if (cmdptr != rq->cmd)
27159+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27160+
27161 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27162 if (blk_verify_command(rq->cmd, has_write_perm))
27163 return -EPERM;
27164@@ -282,7 +290,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27165 rq->next_rq = next_rq;
27166 next_rq->cmd_type = rq->cmd_type;
27167
27168- dxferp = (void*)(unsigned long)hdr->din_xferp;
27169+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27170 ret = blk_rq_map_user(q, next_rq, NULL, dxferp,
27171 hdr->din_xfer_len, GFP_KERNEL);
27172 if (ret)
27173@@ -291,10 +299,10 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27174
27175 if (hdr->dout_xfer_len) {
27176 dxfer_len = hdr->dout_xfer_len;
27177- dxferp = (void*)(unsigned long)hdr->dout_xferp;
27178+ dxferp = (void __user *)(unsigned long)hdr->dout_xferp;
27179 } else if (hdr->din_xfer_len) {
27180 dxfer_len = hdr->din_xfer_len;
27181- dxferp = (void*)(unsigned long)hdr->din_xferp;
27182+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27183 } else
27184 dxfer_len = 0;
27185
27186@@ -436,7 +444,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
27187 int len = min_t(unsigned int, hdr->max_response_len,
27188 rq->sense_len);
27189
27190- ret = copy_to_user((void*)(unsigned long)hdr->response,
27191+ ret = copy_to_user((void __user *)(unsigned long)hdr->response,
27192 rq->sense, len);
27193 if (!ret)
27194 hdr->response_len = len;
27195diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27196index 9bd086c..ca1fc22 100644
27197--- a/block/compat_ioctl.c
27198+++ b/block/compat_ioctl.c
27199@@ -354,7 +354,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27200 err |= __get_user(f->spec1, &uf->spec1);
27201 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27202 err |= __get_user(name, &uf->name);
27203- f->name = compat_ptr(name);
27204+ f->name = (void __force_kernel *)compat_ptr(name);
27205 if (err) {
27206 err = -EFAULT;
27207 goto out;
27208diff --git a/block/elevator.c b/block/elevator.c
27209index a847046..75a1746 100644
27210--- a/block/elevator.c
27211+++ b/block/elevator.c
27212@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
27213 return error;
27214 }
27215
27216-static struct sysfs_ops elv_sysfs_ops = {
27217+static const struct sysfs_ops elv_sysfs_ops = {
27218 .show = elv_attr_show,
27219 .store = elv_attr_store,
27220 };
27221diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27222index 1d5a780..0e2fb8c 100644
27223--- a/block/scsi_ioctl.c
27224+++ b/block/scsi_ioctl.c
27225@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
27226 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27227 struct sg_io_hdr *hdr, fmode_t mode)
27228 {
27229- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27230+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27231+ unsigned char *cmdptr;
27232+
27233+ if (rq->cmd != rq->__cmd)
27234+ cmdptr = rq->cmd;
27235+ else
27236+ cmdptr = tmpcmd;
27237+
27238+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27239 return -EFAULT;
27240+
27241+ if (cmdptr != rq->cmd)
27242+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27243+
27244 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27245 return -EPERM;
27246
27247@@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27248 int err;
27249 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27250 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27251+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27252+ unsigned char *cmdptr;
27253
27254 if (!sic)
27255 return -EINVAL;
27256@@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27257 */
27258 err = -EFAULT;
27259 rq->cmd_len = cmdlen;
27260- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27261+
27262+ if (rq->cmd != rq->__cmd)
27263+ cmdptr = rq->cmd;
27264+ else
27265+ cmdptr = tmpcmd;
27266+
27267+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27268 goto error;
27269
27270+ if (rq->cmd != cmdptr)
27271+ memcpy(rq->cmd, cmdptr, cmdlen);
27272+
27273 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27274 goto error;
27275
27276diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27277index 3533582..f143117 100644
27278--- a/crypto/cryptd.c
27279+++ b/crypto/cryptd.c
27280@@ -50,7 +50,7 @@ struct cryptd_blkcipher_ctx {
27281
27282 struct cryptd_blkcipher_request_ctx {
27283 crypto_completion_t complete;
27284-};
27285+} __no_const;
27286
27287 struct cryptd_hash_ctx {
27288 struct crypto_shash *child;
27289diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c
27290index a90d260..7a9765e 100644
27291--- a/crypto/gf128mul.c
27292+++ b/crypto/gf128mul.c
27293@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128 *b)
27294 for (i = 0; i < 7; ++i)
27295 gf128mul_x_lle(&p[i + 1], &p[i]);
27296
27297- memset(r, 0, sizeof(r));
27298+ memset(r, 0, sizeof(*r));
27299 for (i = 0;;) {
27300 u8 ch = ((u8 *)b)[15 - i];
27301
27302@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128 *b)
27303 for (i = 0; i < 7; ++i)
27304 gf128mul_x_bbe(&p[i + 1], &p[i]);
27305
27306- memset(r, 0, sizeof(r));
27307+ memset(r, 0, sizeof(*r));
27308 for (i = 0;;) {
27309 u8 ch = ((u8 *)b)[i];
27310
27311diff --git a/crypto/serpent.c b/crypto/serpent.c
27312index b651a55..023297d 100644
27313--- a/crypto/serpent.c
27314+++ b/crypto/serpent.c
27315@@ -21,6 +21,7 @@
27316 #include <asm/byteorder.h>
27317 #include <linux/crypto.h>
27318 #include <linux/types.h>
27319+#include <linux/sched.h>
27320
27321 /* Key is padded to the maximum of 256 bits before round key generation.
27322 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
27323@@ -224,6 +225,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
27324 u32 r0,r1,r2,r3,r4;
27325 int i;
27326
27327+ pax_track_stack();
27328+
27329 /* Copy key, add padding */
27330
27331 for (i = 0; i < keylen; ++i)
27332diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
27333index 0d2cdb8..d8de48d 100644
27334--- a/drivers/acpi/acpi_pad.c
27335+++ b/drivers/acpi/acpi_pad.c
27336@@ -30,7 +30,7 @@
27337 #include <acpi/acpi_bus.h>
27338 #include <acpi/acpi_drivers.h>
27339
27340-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
27341+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
27342 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
27343 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
27344 static DEFINE_MUTEX(isolated_cpus_lock);
27345diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27346index 3f4602b..2e41d36 100644
27347--- a/drivers/acpi/battery.c
27348+++ b/drivers/acpi/battery.c
27349@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
27350 }
27351
27352 static struct battery_file {
27353- struct file_operations ops;
27354+ const struct file_operations ops;
27355 mode_t mode;
27356 const char *name;
27357 } acpi_battery_file[] = {
27358diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
27359index 7338b6a..82f0257 100644
27360--- a/drivers/acpi/dock.c
27361+++ b/drivers/acpi/dock.c
27362@@ -77,7 +77,7 @@ struct dock_dependent_device {
27363 struct list_head list;
27364 struct list_head hotplug_list;
27365 acpi_handle handle;
27366- struct acpi_dock_ops *ops;
27367+ const struct acpi_dock_ops *ops;
27368 void *context;
27369 };
27370
27371@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
27372 * the dock driver after _DCK is executed.
27373 */
27374 int
27375-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
27376+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
27377 void *context)
27378 {
27379 struct dock_dependent_device *dd;
27380diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
27381index 7c1c59e..2993595 100644
27382--- a/drivers/acpi/osl.c
27383+++ b/drivers/acpi/osl.c
27384@@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
27385 void __iomem *virt_addr;
27386
27387 virt_addr = ioremap(phys_addr, width);
27388+ if (!virt_addr)
27389+ return AE_NO_MEMORY;
27390 if (!value)
27391 value = &dummy;
27392
27393@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
27394 void __iomem *virt_addr;
27395
27396 virt_addr = ioremap(phys_addr, width);
27397+ if (!virt_addr)
27398+ return AE_NO_MEMORY;
27399
27400 switch (width) {
27401 case 8:
27402diff --git a/drivers/acpi/power_meter.c b/drivers/acpi/power_meter.c
27403index c216062..eec10d2 100644
27404--- a/drivers/acpi/power_meter.c
27405+++ b/drivers/acpi/power_meter.c
27406@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
27407 return res;
27408
27409 temp /= 1000;
27410- if (temp < 0)
27411- return -EINVAL;
27412
27413 mutex_lock(&resource->lock);
27414 resource->trip[attr->index - 7] = temp;
27415diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27416index d0d25e2..961643d 100644
27417--- a/drivers/acpi/proc.c
27418+++ b/drivers/acpi/proc.c
27419@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct file *file,
27420 size_t count, loff_t * ppos)
27421 {
27422 struct list_head *node, *next;
27423- char strbuf[5];
27424- char str[5] = "";
27425- unsigned int len = count;
27426+ char strbuf[5] = {0};
27427 struct acpi_device *found_dev = NULL;
27428
27429- if (len > 4)
27430- len = 4;
27431- if (len < 0)
27432- return -EFAULT;
27433+ if (count > 4)
27434+ count = 4;
27435
27436- if (copy_from_user(strbuf, buffer, len))
27437+ if (copy_from_user(strbuf, buffer, count))
27438 return -EFAULT;
27439- strbuf[len] = '\0';
27440- sscanf(strbuf, "%s", str);
27441+ strbuf[count] = '\0';
27442
27443 mutex_lock(&acpi_device_lock);
27444 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27445@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct file *file,
27446 if (!dev->wakeup.flags.valid)
27447 continue;
27448
27449- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27450+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27451 dev->wakeup.state.enabled =
27452 dev->wakeup.state.enabled ? 0 : 1;
27453 found_dev = dev;
27454diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
27455index 7102474..de8ad22 100644
27456--- a/drivers/acpi/processor_core.c
27457+++ b/drivers/acpi/processor_core.c
27458@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27459 return 0;
27460 }
27461
27462- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27463+ BUG_ON(pr->id >= nr_cpu_ids);
27464
27465 /*
27466 * Buggy BIOS check
27467diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
27468index d933980..5761f13 100644
27469--- a/drivers/acpi/sbshc.c
27470+++ b/drivers/acpi/sbshc.c
27471@@ -17,7 +17,7 @@
27472
27473 #define PREFIX "ACPI: "
27474
27475-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
27476+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
27477 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
27478
27479 struct acpi_smb_hc {
27480diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
27481index 0458094..6978e7b 100644
27482--- a/drivers/acpi/sleep.c
27483+++ b/drivers/acpi/sleep.c
27484@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
27485 }
27486 }
27487
27488-static struct platform_suspend_ops acpi_suspend_ops = {
27489+static const struct platform_suspend_ops acpi_suspend_ops = {
27490 .valid = acpi_suspend_state_valid,
27491 .begin = acpi_suspend_begin,
27492 .prepare_late = acpi_pm_prepare,
27493@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
27494 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27495 * been requested.
27496 */
27497-static struct platform_suspend_ops acpi_suspend_ops_old = {
27498+static const struct platform_suspend_ops acpi_suspend_ops_old = {
27499 .valid = acpi_suspend_state_valid,
27500 .begin = acpi_suspend_begin_old,
27501 .prepare_late = acpi_pm_disable_gpes,
27502@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
27503 acpi_enable_all_runtime_gpes();
27504 }
27505
27506-static struct platform_hibernation_ops acpi_hibernation_ops = {
27507+static const struct platform_hibernation_ops acpi_hibernation_ops = {
27508 .begin = acpi_hibernation_begin,
27509 .end = acpi_pm_end,
27510 .pre_snapshot = acpi_hibernation_pre_snapshot,
27511@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
27512 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27513 * been requested.
27514 */
27515-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
27516+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
27517 .begin = acpi_hibernation_begin_old,
27518 .end = acpi_pm_end,
27519 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
27520diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
27521index 05dff63..b662ab7 100644
27522--- a/drivers/acpi/video.c
27523+++ b/drivers/acpi/video.c
27524@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
27525 vd->brightness->levels[request_level]);
27526 }
27527
27528-static struct backlight_ops acpi_backlight_ops = {
27529+static const struct backlight_ops acpi_backlight_ops = {
27530 .get_brightness = acpi_video_get_brightness,
27531 .update_status = acpi_video_set_brightness,
27532 };
27533diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
27534index 6787aab..23ffb0e 100644
27535--- a/drivers/ata/ahci.c
27536+++ b/drivers/ata/ahci.c
27537@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sht = {
27538 .sdev_attrs = ahci_sdev_attrs,
27539 };
27540
27541-static struct ata_port_operations ahci_ops = {
27542+static const struct ata_port_operations ahci_ops = {
27543 .inherits = &sata_pmp_port_ops,
27544
27545 .qc_defer = sata_pmp_qc_defer_cmd_switch,
27546@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_ops = {
27547 .port_stop = ahci_port_stop,
27548 };
27549
27550-static struct ata_port_operations ahci_vt8251_ops = {
27551+static const struct ata_port_operations ahci_vt8251_ops = {
27552 .inherits = &ahci_ops,
27553 .hardreset = ahci_vt8251_hardreset,
27554 };
27555
27556-static struct ata_port_operations ahci_p5wdh_ops = {
27557+static const struct ata_port_operations ahci_p5wdh_ops = {
27558 .inherits = &ahci_ops,
27559 .hardreset = ahci_p5wdh_hardreset,
27560 };
27561
27562-static struct ata_port_operations ahci_sb600_ops = {
27563+static const struct ata_port_operations ahci_sb600_ops = {
27564 .inherits = &ahci_ops,
27565 .softreset = ahci_sb600_softreset,
27566 .pmp_softreset = ahci_sb600_softreset,
27567diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
27568index 99e7196..4968c77 100644
27569--- a/drivers/ata/ata_generic.c
27570+++ b/drivers/ata/ata_generic.c
27571@@ -104,7 +104,7 @@ static struct scsi_host_template generic_sht = {
27572 ATA_BMDMA_SHT(DRV_NAME),
27573 };
27574
27575-static struct ata_port_operations generic_port_ops = {
27576+static const struct ata_port_operations generic_port_ops = {
27577 .inherits = &ata_bmdma_port_ops,
27578 .cable_detect = ata_cable_unknown,
27579 .set_mode = generic_set_mode,
27580diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
27581index c33591d..000c121 100644
27582--- a/drivers/ata/ata_piix.c
27583+++ b/drivers/ata/ata_piix.c
27584@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sht = {
27585 ATA_BMDMA_SHT(DRV_NAME),
27586 };
27587
27588-static struct ata_port_operations piix_pata_ops = {
27589+static const struct ata_port_operations piix_pata_ops = {
27590 .inherits = &ata_bmdma32_port_ops,
27591 .cable_detect = ata_cable_40wire,
27592 .set_piomode = piix_set_piomode,
27593@@ -326,22 +326,22 @@ static struct ata_port_operations piix_pata_ops = {
27594 .prereset = piix_pata_prereset,
27595 };
27596
27597-static struct ata_port_operations piix_vmw_ops = {
27598+static const struct ata_port_operations piix_vmw_ops = {
27599 .inherits = &piix_pata_ops,
27600 .bmdma_status = piix_vmw_bmdma_status,
27601 };
27602
27603-static struct ata_port_operations ich_pata_ops = {
27604+static const struct ata_port_operations ich_pata_ops = {
27605 .inherits = &piix_pata_ops,
27606 .cable_detect = ich_pata_cable_detect,
27607 .set_dmamode = ich_set_dmamode,
27608 };
27609
27610-static struct ata_port_operations piix_sata_ops = {
27611+static const struct ata_port_operations piix_sata_ops = {
27612 .inherits = &ata_bmdma_port_ops,
27613 };
27614
27615-static struct ata_port_operations piix_sidpr_sata_ops = {
27616+static const struct ata_port_operations piix_sidpr_sata_ops = {
27617 .inherits = &piix_sata_ops,
27618 .hardreset = sata_std_hardreset,
27619 .scr_read = piix_sidpr_scr_read,
27620diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
27621index b0882cd..c295d65 100644
27622--- a/drivers/ata/libata-acpi.c
27623+++ b/drivers/ata/libata-acpi.c
27624@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_handle handle, u32 event, void *data)
27625 ata_acpi_uevent(dev->link->ap, dev, event);
27626 }
27627
27628-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27629+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27630 .handler = ata_acpi_dev_notify_dock,
27631 .uevent = ata_acpi_dev_uevent,
27632 };
27633
27634-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27635+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27636 .handler = ata_acpi_ap_notify_dock,
27637 .uevent = ata_acpi_ap_uevent,
27638 };
27639diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27640index d4f7f99..94f603e 100644
27641--- a/drivers/ata/libata-core.c
27642+++ b/drivers/ata/libata-core.c
27643@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27644 struct ata_port *ap;
27645 unsigned int tag;
27646
27647- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27648+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27649 ap = qc->ap;
27650
27651 qc->flags = 0;
27652@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27653 struct ata_port *ap;
27654 struct ata_link *link;
27655
27656- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27657+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27658 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27659 ap = qc->ap;
27660 link = qc->dev->link;
27661@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device *gendev, void *res)
27662 * LOCKING:
27663 * None.
27664 */
27665-static void ata_finalize_port_ops(struct ata_port_operations *ops)
27666+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
27667 {
27668 static DEFINE_SPINLOCK(lock);
27669 const struct ata_port_operations *cur;
27670@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27671 return;
27672
27673 spin_lock(&lock);
27674+ pax_open_kernel();
27675
27676 for (cur = ops->inherits; cur; cur = cur->inherits) {
27677 void **inherit = (void **)cur;
27678@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27679 if (IS_ERR(*pp))
27680 *pp = NULL;
27681
27682- ops->inherits = NULL;
27683+ *(struct ata_port_operations **)&ops->inherits = NULL;
27684
27685+ pax_close_kernel();
27686 spin_unlock(&lock);
27687 }
27688
27689@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host)
27690 */
27691 /* KILLME - the only user left is ipr */
27692 void ata_host_init(struct ata_host *host, struct device *dev,
27693- unsigned long flags, struct ata_port_operations *ops)
27694+ unsigned long flags, const struct ata_port_operations *ops)
27695 {
27696 spin_lock_init(&host->lock);
27697 host->dev = dev;
27698@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(struct ata_port *ap)
27699 /* truly dummy */
27700 }
27701
27702-struct ata_port_operations ata_dummy_port_ops = {
27703+const struct ata_port_operations ata_dummy_port_ops = {
27704 .qc_prep = ata_noop_qc_prep,
27705 .qc_issue = ata_dummy_qc_issue,
27706 .error_handler = ata_dummy_error_handler,
27707diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
27708index e5bdb9b..45a8e72 100644
27709--- a/drivers/ata/libata-eh.c
27710+++ b/drivers/ata/libata-eh.c
27711@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
27712 {
27713 struct ata_link *link;
27714
27715+ pax_track_stack();
27716+
27717 ata_for_each_link(link, ap, HOST_FIRST)
27718 ata_eh_link_report(link);
27719 }
27720@@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
27721 */
27722 void ata_std_error_handler(struct ata_port *ap)
27723 {
27724- struct ata_port_operations *ops = ap->ops;
27725+ const struct ata_port_operations *ops = ap->ops;
27726 ata_reset_fn_t hardreset = ops->hardreset;
27727
27728 /* ignore built-in hardreset if SCR access is not available */
27729diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
27730index 51f0ffb..19ce3e3 100644
27731--- a/drivers/ata/libata-pmp.c
27732+++ b/drivers/ata/libata-pmp.c
27733@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
27734 */
27735 static int sata_pmp_eh_recover(struct ata_port *ap)
27736 {
27737- struct ata_port_operations *ops = ap->ops;
27738+ const struct ata_port_operations *ops = ap->ops;
27739 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
27740 struct ata_link *pmp_link = &ap->link;
27741 struct ata_device *pmp_dev = pmp_link->device;
27742diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
27743index d8f35fe..288180a 100644
27744--- a/drivers/ata/pata_acpi.c
27745+++ b/drivers/ata/pata_acpi.c
27746@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_sht = {
27747 ATA_BMDMA_SHT(DRV_NAME),
27748 };
27749
27750-static struct ata_port_operations pacpi_ops = {
27751+static const struct ata_port_operations pacpi_ops = {
27752 .inherits = &ata_bmdma_port_ops,
27753 .qc_issue = pacpi_qc_issue,
27754 .cable_detect = pacpi_cable_detect,
27755diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
27756index 9434114..1f2f364 100644
27757--- a/drivers/ata/pata_ali.c
27758+++ b/drivers/ata/pata_ali.c
27759@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht = {
27760 * Port operations for PIO only ALi
27761 */
27762
27763-static struct ata_port_operations ali_early_port_ops = {
27764+static const struct ata_port_operations ali_early_port_ops = {
27765 .inherits = &ata_sff_port_ops,
27766 .cable_detect = ata_cable_40wire,
27767 .set_piomode = ali_set_piomode,
27768@@ -382,7 +382,7 @@ static const struct ata_port_operations ali_dma_base_ops = {
27769 * Port operations for DMA capable ALi without cable
27770 * detect
27771 */
27772-static struct ata_port_operations ali_20_port_ops = {
27773+static const struct ata_port_operations ali_20_port_ops = {
27774 .inherits = &ali_dma_base_ops,
27775 .cable_detect = ata_cable_40wire,
27776 .mode_filter = ali_20_filter,
27777@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20_port_ops = {
27778 /*
27779 * Port operations for DMA capable ALi with cable detect
27780 */
27781-static struct ata_port_operations ali_c2_port_ops = {
27782+static const struct ata_port_operations ali_c2_port_ops = {
27783 .inherits = &ali_dma_base_ops,
27784 .check_atapi_dma = ali_check_atapi_dma,
27785 .cable_detect = ali_c2_cable_detect,
27786@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2_port_ops = {
27787 /*
27788 * Port operations for DMA capable ALi with cable detect
27789 */
27790-static struct ata_port_operations ali_c4_port_ops = {
27791+static const struct ata_port_operations ali_c4_port_ops = {
27792 .inherits = &ali_dma_base_ops,
27793 .check_atapi_dma = ali_check_atapi_dma,
27794 .cable_detect = ali_c2_cable_detect,
27795@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4_port_ops = {
27796 /*
27797 * Port operations for DMA capable ALi with cable detect and LBA48
27798 */
27799-static struct ata_port_operations ali_c5_port_ops = {
27800+static const struct ata_port_operations ali_c5_port_ops = {
27801 .inherits = &ali_dma_base_ops,
27802 .check_atapi_dma = ali_check_atapi_dma,
27803 .dev_config = ali_warn_atapi_dma,
27804diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
27805index 567f3f7..c8ee0da 100644
27806--- a/drivers/ata/pata_amd.c
27807+++ b/drivers/ata/pata_amd.c
27808@@ -397,28 +397,28 @@ static const struct ata_port_operations amd_base_port_ops = {
27809 .prereset = amd_pre_reset,
27810 };
27811
27812-static struct ata_port_operations amd33_port_ops = {
27813+static const struct ata_port_operations amd33_port_ops = {
27814 .inherits = &amd_base_port_ops,
27815 .cable_detect = ata_cable_40wire,
27816 .set_piomode = amd33_set_piomode,
27817 .set_dmamode = amd33_set_dmamode,
27818 };
27819
27820-static struct ata_port_operations amd66_port_ops = {
27821+static const struct ata_port_operations amd66_port_ops = {
27822 .inherits = &amd_base_port_ops,
27823 .cable_detect = ata_cable_unknown,
27824 .set_piomode = amd66_set_piomode,
27825 .set_dmamode = amd66_set_dmamode,
27826 };
27827
27828-static struct ata_port_operations amd100_port_ops = {
27829+static const struct ata_port_operations amd100_port_ops = {
27830 .inherits = &amd_base_port_ops,
27831 .cable_detect = ata_cable_unknown,
27832 .set_piomode = amd100_set_piomode,
27833 .set_dmamode = amd100_set_dmamode,
27834 };
27835
27836-static struct ata_port_operations amd133_port_ops = {
27837+static const struct ata_port_operations amd133_port_ops = {
27838 .inherits = &amd_base_port_ops,
27839 .cable_detect = amd_cable_detect,
27840 .set_piomode = amd133_set_piomode,
27841@@ -433,13 +433,13 @@ static const struct ata_port_operations nv_base_port_ops = {
27842 .host_stop = nv_host_stop,
27843 };
27844
27845-static struct ata_port_operations nv100_port_ops = {
27846+static const struct ata_port_operations nv100_port_ops = {
27847 .inherits = &nv_base_port_ops,
27848 .set_piomode = nv100_set_piomode,
27849 .set_dmamode = nv100_set_dmamode,
27850 };
27851
27852-static struct ata_port_operations nv133_port_ops = {
27853+static const struct ata_port_operations nv133_port_ops = {
27854 .inherits = &nv_base_port_ops,
27855 .set_piomode = nv133_set_piomode,
27856 .set_dmamode = nv133_set_dmamode,
27857diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
27858index d332cfd..4b7eaae 100644
27859--- a/drivers/ata/pata_artop.c
27860+++ b/drivers/ata/pata_artop.c
27861@@ -311,7 +311,7 @@ static struct scsi_host_template artop_sht = {
27862 ATA_BMDMA_SHT(DRV_NAME),
27863 };
27864
27865-static struct ata_port_operations artop6210_ops = {
27866+static const struct ata_port_operations artop6210_ops = {
27867 .inherits = &ata_bmdma_port_ops,
27868 .cable_detect = ata_cable_40wire,
27869 .set_piomode = artop6210_set_piomode,
27870@@ -320,7 +320,7 @@ static struct ata_port_operations artop6210_ops = {
27871 .qc_defer = artop6210_qc_defer,
27872 };
27873
27874-static struct ata_port_operations artop6260_ops = {
27875+static const struct ata_port_operations artop6260_ops = {
27876 .inherits = &ata_bmdma_port_ops,
27877 .cable_detect = artop6260_cable_detect,
27878 .set_piomode = artop6260_set_piomode,
27879diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
27880index 5c129f9..7bb7ccb 100644
27881--- a/drivers/ata/pata_at32.c
27882+++ b/drivers/ata/pata_at32.c
27883@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sht = {
27884 ATA_PIO_SHT(DRV_NAME),
27885 };
27886
27887-static struct ata_port_operations at32_port_ops = {
27888+static const struct ata_port_operations at32_port_ops = {
27889 .inherits = &ata_sff_port_ops,
27890 .cable_detect = ata_cable_40wire,
27891 .set_piomode = pata_at32_set_piomode,
27892diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
27893index 41c94b1..829006d 100644
27894--- a/drivers/ata/pata_at91.c
27895+++ b/drivers/ata/pata_at91.c
27896@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at91_sht = {
27897 ATA_PIO_SHT(DRV_NAME),
27898 };
27899
27900-static struct ata_port_operations pata_at91_port_ops = {
27901+static const struct ata_port_operations pata_at91_port_ops = {
27902 .inherits = &ata_sff_port_ops,
27903
27904 .sff_data_xfer = pata_at91_data_xfer_noirq,
27905diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
27906index ae4454d..d391eb4 100644
27907--- a/drivers/ata/pata_atiixp.c
27908+++ b/drivers/ata/pata_atiixp.c
27909@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_sht = {
27910 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27911 };
27912
27913-static struct ata_port_operations atiixp_port_ops = {
27914+static const struct ata_port_operations atiixp_port_ops = {
27915 .inherits = &ata_bmdma_port_ops,
27916
27917 .qc_prep = ata_sff_dumb_qc_prep,
27918diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c
27919index 6fe7ded..2a425dc 100644
27920--- a/drivers/ata/pata_atp867x.c
27921+++ b/drivers/ata/pata_atp867x.c
27922@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x_sht = {
27923 ATA_BMDMA_SHT(DRV_NAME),
27924 };
27925
27926-static struct ata_port_operations atp867x_ops = {
27927+static const struct ata_port_operations atp867x_ops = {
27928 .inherits = &ata_bmdma_port_ops,
27929 .cable_detect = atp867x_cable_detect,
27930 .set_piomode = atp867x_set_piomode,
27931diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
27932index c4b47a3..b27a367 100644
27933--- a/drivers/ata/pata_bf54x.c
27934+++ b/drivers/ata/pata_bf54x.c
27935@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sht = {
27936 .dma_boundary = ATA_DMA_BOUNDARY,
27937 };
27938
27939-static struct ata_port_operations bfin_pata_ops = {
27940+static const struct ata_port_operations bfin_pata_ops = {
27941 .inherits = &ata_sff_port_ops,
27942
27943 .set_piomode = bfin_set_piomode,
27944diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
27945index 5acf9fa..84248be 100644
27946--- a/drivers/ata/pata_cmd640.c
27947+++ b/drivers/ata/pata_cmd640.c
27948@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_sht = {
27949 ATA_BMDMA_SHT(DRV_NAME),
27950 };
27951
27952-static struct ata_port_operations cmd640_port_ops = {
27953+static const struct ata_port_operations cmd640_port_ops = {
27954 .inherits = &ata_bmdma_port_ops,
27955 /* In theory xfer_noirq is not needed once we kill the prefetcher */
27956 .sff_data_xfer = ata_sff_data_xfer_noirq,
27957diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
27958index ccd2694..c869c3d 100644
27959--- a/drivers/ata/pata_cmd64x.c
27960+++ b/drivers/ata/pata_cmd64x.c
27961@@ -271,18 +271,18 @@ static const struct ata_port_operations cmd64x_base_ops = {
27962 .set_dmamode = cmd64x_set_dmamode,
27963 };
27964
27965-static struct ata_port_operations cmd64x_port_ops = {
27966+static const struct ata_port_operations cmd64x_port_ops = {
27967 .inherits = &cmd64x_base_ops,
27968 .cable_detect = ata_cable_40wire,
27969 };
27970
27971-static struct ata_port_operations cmd646r1_port_ops = {
27972+static const struct ata_port_operations cmd646r1_port_ops = {
27973 .inherits = &cmd64x_base_ops,
27974 .bmdma_stop = cmd646r1_bmdma_stop,
27975 .cable_detect = ata_cable_40wire,
27976 };
27977
27978-static struct ata_port_operations cmd648_port_ops = {
27979+static const struct ata_port_operations cmd648_port_ops = {
27980 .inherits = &cmd64x_base_ops,
27981 .bmdma_stop = cmd648_bmdma_stop,
27982 .cable_detect = cmd648_cable_detect,
27983diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
27984index 0df83cf..d7595b0 100644
27985--- a/drivers/ata/pata_cs5520.c
27986+++ b/drivers/ata/pata_cs5520.c
27987@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_sht = {
27988 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27989 };
27990
27991-static struct ata_port_operations cs5520_port_ops = {
27992+static const struct ata_port_operations cs5520_port_ops = {
27993 .inherits = &ata_bmdma_port_ops,
27994 .qc_prep = ata_sff_dumb_qc_prep,
27995 .cable_detect = ata_cable_40wire,
27996diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
27997index c974b05..6d26b11 100644
27998--- a/drivers/ata/pata_cs5530.c
27999+++ b/drivers/ata/pata_cs5530.c
28000@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_sht = {
28001 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28002 };
28003
28004-static struct ata_port_operations cs5530_port_ops = {
28005+static const struct ata_port_operations cs5530_port_ops = {
28006 .inherits = &ata_bmdma_port_ops,
28007
28008 .qc_prep = ata_sff_dumb_qc_prep,
28009diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
28010index 403f561..aacd26b 100644
28011--- a/drivers/ata/pata_cs5535.c
28012+++ b/drivers/ata/pata_cs5535.c
28013@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_sht = {
28014 ATA_BMDMA_SHT(DRV_NAME),
28015 };
28016
28017-static struct ata_port_operations cs5535_port_ops = {
28018+static const struct ata_port_operations cs5535_port_ops = {
28019 .inherits = &ata_bmdma_port_ops,
28020 .cable_detect = cs5535_cable_detect,
28021 .set_piomode = cs5535_set_piomode,
28022diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
28023index 6da4cb4..de24a25 100644
28024--- a/drivers/ata/pata_cs5536.c
28025+++ b/drivers/ata/pata_cs5536.c
28026@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_sht = {
28027 ATA_BMDMA_SHT(DRV_NAME),
28028 };
28029
28030-static struct ata_port_operations cs5536_port_ops = {
28031+static const struct ata_port_operations cs5536_port_ops = {
28032 .inherits = &ata_bmdma_port_ops,
28033 .cable_detect = cs5536_cable_detect,
28034 .set_piomode = cs5536_set_piomode,
28035diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
28036index 8fb040b..b16a9c9 100644
28037--- a/drivers/ata/pata_cypress.c
28038+++ b/drivers/ata/pata_cypress.c
28039@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c693_sht = {
28040 ATA_BMDMA_SHT(DRV_NAME),
28041 };
28042
28043-static struct ata_port_operations cy82c693_port_ops = {
28044+static const struct ata_port_operations cy82c693_port_ops = {
28045 .inherits = &ata_bmdma_port_ops,
28046 .cable_detect = ata_cable_40wire,
28047 .set_piomode = cy82c693_set_piomode,
28048diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
28049index 2a6412f..555ee11 100644
28050--- a/drivers/ata/pata_efar.c
28051+++ b/drivers/ata/pata_efar.c
28052@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sht = {
28053 ATA_BMDMA_SHT(DRV_NAME),
28054 };
28055
28056-static struct ata_port_operations efar_ops = {
28057+static const struct ata_port_operations efar_ops = {
28058 .inherits = &ata_bmdma_port_ops,
28059 .cable_detect = efar_cable_detect,
28060 .set_piomode = efar_set_piomode,
28061diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
28062index b9d8836..0b92030 100644
28063--- a/drivers/ata/pata_hpt366.c
28064+++ b/drivers/ata/pata_hpt366.c
28065@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_sht = {
28066 * Configuration for HPT366/68
28067 */
28068
28069-static struct ata_port_operations hpt366_port_ops = {
28070+static const struct ata_port_operations hpt366_port_ops = {
28071 .inherits = &ata_bmdma_port_ops,
28072 .cable_detect = hpt36x_cable_detect,
28073 .mode_filter = hpt366_filter,
28074diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
28075index 5af7f19..00c4980 100644
28076--- a/drivers/ata/pata_hpt37x.c
28077+++ b/drivers/ata/pata_hpt37x.c
28078@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_sht = {
28079 * Configuration for HPT370
28080 */
28081
28082-static struct ata_port_operations hpt370_port_ops = {
28083+static const struct ata_port_operations hpt370_port_ops = {
28084 .inherits = &ata_bmdma_port_ops,
28085
28086 .bmdma_stop = hpt370_bmdma_stop,
28087@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370_port_ops = {
28088 * Configuration for HPT370A. Close to 370 but less filters
28089 */
28090
28091-static struct ata_port_operations hpt370a_port_ops = {
28092+static const struct ata_port_operations hpt370a_port_ops = {
28093 .inherits = &hpt370_port_ops,
28094 .mode_filter = hpt370a_filter,
28095 };
28096@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370a_port_ops = {
28097 * and DMA mode setting functionality.
28098 */
28099
28100-static struct ata_port_operations hpt372_port_ops = {
28101+static const struct ata_port_operations hpt372_port_ops = {
28102 .inherits = &ata_bmdma_port_ops,
28103
28104 .bmdma_stop = hpt37x_bmdma_stop,
28105@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372_port_ops = {
28106 * but we have a different cable detection procedure for function 1.
28107 */
28108
28109-static struct ata_port_operations hpt374_fn1_port_ops = {
28110+static const struct ata_port_operations hpt374_fn1_port_ops = {
28111 .inherits = &hpt372_port_ops,
28112 .prereset = hpt374_fn1_pre_reset,
28113 };
28114diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
28115index 100f227..2e39382 100644
28116--- a/drivers/ata/pata_hpt3x2n.c
28117+++ b/drivers/ata/pata_hpt3x2n.c
28118@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n_sht = {
28119 * Configuration for HPT3x2n.
28120 */
28121
28122-static struct ata_port_operations hpt3x2n_port_ops = {
28123+static const struct ata_port_operations hpt3x2n_port_ops = {
28124 .inherits = &ata_bmdma_port_ops,
28125
28126 .bmdma_stop = hpt3x2n_bmdma_stop,
28127diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
28128index 7e31025..6fca8f4 100644
28129--- a/drivers/ata/pata_hpt3x3.c
28130+++ b/drivers/ata/pata_hpt3x3.c
28131@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_sht = {
28132 ATA_BMDMA_SHT(DRV_NAME),
28133 };
28134
28135-static struct ata_port_operations hpt3x3_port_ops = {
28136+static const struct ata_port_operations hpt3x3_port_ops = {
28137 .inherits = &ata_bmdma_port_ops,
28138 .cable_detect = ata_cable_40wire,
28139 .set_piomode = hpt3x3_set_piomode,
28140diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
28141index b663b7f..9a26c2a 100644
28142--- a/drivers/ata/pata_icside.c
28143+++ b/drivers/ata/pata_icside.c
28144@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct ata_link *link, unsigned int *classes)
28145 }
28146 }
28147
28148-static struct ata_port_operations pata_icside_port_ops = {
28149+static const struct ata_port_operations pata_icside_port_ops = {
28150 .inherits = &ata_sff_port_ops,
28151 /* no need to build any PRD tables for DMA */
28152 .qc_prep = ata_noop_qc_prep,
28153diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
28154index 4bceb88..457dfb6 100644
28155--- a/drivers/ata/pata_isapnp.c
28156+++ b/drivers/ata/pata_isapnp.c
28157@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_sht = {
28158 ATA_PIO_SHT(DRV_NAME),
28159 };
28160
28161-static struct ata_port_operations isapnp_port_ops = {
28162+static const struct ata_port_operations isapnp_port_ops = {
28163 .inherits = &ata_sff_port_ops,
28164 .cable_detect = ata_cable_40wire,
28165 };
28166
28167-static struct ata_port_operations isapnp_noalt_port_ops = {
28168+static const struct ata_port_operations isapnp_noalt_port_ops = {
28169 .inherits = &ata_sff_port_ops,
28170 .cable_detect = ata_cable_40wire,
28171 /* No altstatus so we don't want to use the lost interrupt poll */
28172diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
28173index f156da8..24976e2 100644
28174--- a/drivers/ata/pata_it8213.c
28175+++ b/drivers/ata/pata_it8213.c
28176@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_sht = {
28177 };
28178
28179
28180-static struct ata_port_operations it8213_ops = {
28181+static const struct ata_port_operations it8213_ops = {
28182 .inherits = &ata_bmdma_port_ops,
28183 .cable_detect = it8213_cable_detect,
28184 .set_piomode = it8213_set_piomode,
28185diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
28186index 188bc2f..ca9e785 100644
28187--- a/drivers/ata/pata_it821x.c
28188+++ b/drivers/ata/pata_it821x.c
28189@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_sht = {
28190 ATA_BMDMA_SHT(DRV_NAME),
28191 };
28192
28193-static struct ata_port_operations it821x_smart_port_ops = {
28194+static const struct ata_port_operations it821x_smart_port_ops = {
28195 .inherits = &ata_bmdma_port_ops,
28196
28197 .check_atapi_dma= it821x_check_atapi_dma,
28198@@ -814,7 +814,7 @@ static struct ata_port_operations it821x_smart_port_ops = {
28199 .port_start = it821x_port_start,
28200 };
28201
28202-static struct ata_port_operations it821x_passthru_port_ops = {
28203+static const struct ata_port_operations it821x_passthru_port_ops = {
28204 .inherits = &ata_bmdma_port_ops,
28205
28206 .check_atapi_dma= it821x_check_atapi_dma,
28207@@ -830,7 +830,7 @@ static struct ata_port_operations it821x_passthru_port_ops = {
28208 .port_start = it821x_port_start,
28209 };
28210
28211-static struct ata_port_operations it821x_rdc_port_ops = {
28212+static const struct ata_port_operations it821x_rdc_port_ops = {
28213 .inherits = &ata_bmdma_port_ops,
28214
28215 .check_atapi_dma= it821x_check_atapi_dma,
28216diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
28217index ba54b08..4b952b7 100644
28218--- a/drivers/ata/pata_ixp4xx_cf.c
28219+++ b/drivers/ata/pata_ixp4xx_cf.c
28220@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_sht = {
28221 ATA_PIO_SHT(DRV_NAME),
28222 };
28223
28224-static struct ata_port_operations ixp4xx_port_ops = {
28225+static const struct ata_port_operations ixp4xx_port_ops = {
28226 .inherits = &ata_sff_port_ops,
28227 .sff_data_xfer = ixp4xx_mmio_data_xfer,
28228 .cable_detect = ata_cable_40wire,
28229diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
28230index 3a1474a..434b0ff 100644
28231--- a/drivers/ata/pata_jmicron.c
28232+++ b/drivers/ata/pata_jmicron.c
28233@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron_sht = {
28234 ATA_BMDMA_SHT(DRV_NAME),
28235 };
28236
28237-static struct ata_port_operations jmicron_ops = {
28238+static const struct ata_port_operations jmicron_ops = {
28239 .inherits = &ata_bmdma_port_ops,
28240 .prereset = jmicron_pre_reset,
28241 };
28242diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
28243index 6932e56..220e71d 100644
28244--- a/drivers/ata/pata_legacy.c
28245+++ b/drivers/ata/pata_legacy.c
28246@@ -106,7 +106,7 @@ struct legacy_probe {
28247
28248 struct legacy_controller {
28249 const char *name;
28250- struct ata_port_operations *ops;
28251+ const struct ata_port_operations *ops;
28252 unsigned int pio_mask;
28253 unsigned int flags;
28254 unsigned int pflags;
28255@@ -223,12 +223,12 @@ static const struct ata_port_operations legacy_base_port_ops = {
28256 * pio_mask as well.
28257 */
28258
28259-static struct ata_port_operations simple_port_ops = {
28260+static const struct ata_port_operations simple_port_ops = {
28261 .inherits = &legacy_base_port_ops,
28262 .sff_data_xfer = ata_sff_data_xfer_noirq,
28263 };
28264
28265-static struct ata_port_operations legacy_port_ops = {
28266+static const struct ata_port_operations legacy_port_ops = {
28267 .inherits = &legacy_base_port_ops,
28268 .sff_data_xfer = ata_sff_data_xfer_noirq,
28269 .set_mode = legacy_set_mode,
28270@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
28271 return buflen;
28272 }
28273
28274-static struct ata_port_operations pdc20230_port_ops = {
28275+static const struct ata_port_operations pdc20230_port_ops = {
28276 .inherits = &legacy_base_port_ops,
28277 .set_piomode = pdc20230_set_piomode,
28278 .sff_data_xfer = pdc_data_xfer_vlb,
28279@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
28280 ioread8(ap->ioaddr.status_addr);
28281 }
28282
28283-static struct ata_port_operations ht6560a_port_ops = {
28284+static const struct ata_port_operations ht6560a_port_ops = {
28285 .inherits = &legacy_base_port_ops,
28286 .set_piomode = ht6560a_set_piomode,
28287 };
28288@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
28289 ioread8(ap->ioaddr.status_addr);
28290 }
28291
28292-static struct ata_port_operations ht6560b_port_ops = {
28293+static const struct ata_port_operations ht6560b_port_ops = {
28294 .inherits = &legacy_base_port_ops,
28295 .set_piomode = ht6560b_set_piomode,
28296 };
28297@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(struct ata_port *ap,
28298 }
28299
28300
28301-static struct ata_port_operations opti82c611a_port_ops = {
28302+static const struct ata_port_operations opti82c611a_port_ops = {
28303 .inherits = &legacy_base_port_ops,
28304 .set_piomode = opti82c611a_set_piomode,
28305 };
28306@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(struct ata_queued_cmd *qc)
28307 return ata_sff_qc_issue(qc);
28308 }
28309
28310-static struct ata_port_operations opti82c46x_port_ops = {
28311+static const struct ata_port_operations opti82c46x_port_ops = {
28312 .inherits = &legacy_base_port_ops,
28313 .set_piomode = opti82c46x_set_piomode,
28314 .qc_issue = opti82c46x_qc_issue,
28315@@ -771,20 +771,20 @@ static int qdi_port(struct platform_device *dev,
28316 return 0;
28317 }
28318
28319-static struct ata_port_operations qdi6500_port_ops = {
28320+static const struct ata_port_operations qdi6500_port_ops = {
28321 .inherits = &legacy_base_port_ops,
28322 .set_piomode = qdi6500_set_piomode,
28323 .qc_issue = qdi_qc_issue,
28324 .sff_data_xfer = vlb32_data_xfer,
28325 };
28326
28327-static struct ata_port_operations qdi6580_port_ops = {
28328+static const struct ata_port_operations qdi6580_port_ops = {
28329 .inherits = &legacy_base_port_ops,
28330 .set_piomode = qdi6580_set_piomode,
28331 .sff_data_xfer = vlb32_data_xfer,
28332 };
28333
28334-static struct ata_port_operations qdi6580dp_port_ops = {
28335+static const struct ata_port_operations qdi6580dp_port_ops = {
28336 .inherits = &legacy_base_port_ops,
28337 .set_piomode = qdi6580dp_set_piomode,
28338 .sff_data_xfer = vlb32_data_xfer,
28339@@ -855,7 +855,7 @@ static int winbond_port(struct platform_device *dev,
28340 return 0;
28341 }
28342
28343-static struct ata_port_operations winbond_port_ops = {
28344+static const struct ata_port_operations winbond_port_ops = {
28345 .inherits = &legacy_base_port_ops,
28346 .set_piomode = winbond_set_piomode,
28347 .sff_data_xfer = vlb32_data_xfer,
28348@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
28349 int pio_modes = controller->pio_mask;
28350 unsigned long io = probe->port;
28351 u32 mask = (1 << probe->slot);
28352- struct ata_port_operations *ops = controller->ops;
28353+ const struct ata_port_operations *ops = controller->ops;
28354 struct legacy_data *ld = &legacy_data[probe->slot];
28355 struct ata_host *host = NULL;
28356 struct ata_port *ap;
28357diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
28358index 2096fb7..4d090fc 100644
28359--- a/drivers/ata/pata_marvell.c
28360+++ b/drivers/ata/pata_marvell.c
28361@@ -100,7 +100,7 @@ static struct scsi_host_template marvell_sht = {
28362 ATA_BMDMA_SHT(DRV_NAME),
28363 };
28364
28365-static struct ata_port_operations marvell_ops = {
28366+static const struct ata_port_operations marvell_ops = {
28367 .inherits = &ata_bmdma_port_ops,
28368 .cable_detect = marvell_cable_detect,
28369 .prereset = marvell_pre_reset,
28370diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
28371index 99d41be..7d56aa8 100644
28372--- a/drivers/ata/pata_mpc52xx.c
28373+++ b/drivers/ata/pata_mpc52xx.c
28374@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx_ata_sht = {
28375 ATA_PIO_SHT(DRV_NAME),
28376 };
28377
28378-static struct ata_port_operations mpc52xx_ata_port_ops = {
28379+static const struct ata_port_operations mpc52xx_ata_port_ops = {
28380 .inherits = &ata_bmdma_port_ops,
28381 .sff_dev_select = mpc52xx_ata_dev_select,
28382 .set_piomode = mpc52xx_ata_set_piomode,
28383diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
28384index b21f002..0a27e7f 100644
28385--- a/drivers/ata/pata_mpiix.c
28386+++ b/drivers/ata/pata_mpiix.c
28387@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_sht = {
28388 ATA_PIO_SHT(DRV_NAME),
28389 };
28390
28391-static struct ata_port_operations mpiix_port_ops = {
28392+static const struct ata_port_operations mpiix_port_ops = {
28393 .inherits = &ata_sff_port_ops,
28394 .qc_issue = mpiix_qc_issue,
28395 .cable_detect = ata_cable_40wire,
28396diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
28397index f0d52f7..89c3be3 100644
28398--- a/drivers/ata/pata_netcell.c
28399+++ b/drivers/ata/pata_netcell.c
28400@@ -34,7 +34,7 @@ static struct scsi_host_template netcell_sht = {
28401 ATA_BMDMA_SHT(DRV_NAME),
28402 };
28403
28404-static struct ata_port_operations netcell_ops = {
28405+static const struct ata_port_operations netcell_ops = {
28406 .inherits = &ata_bmdma_port_ops,
28407 .cable_detect = ata_cable_80wire,
28408 .read_id = netcell_read_id,
28409diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
28410index dd53a66..a3f4317 100644
28411--- a/drivers/ata/pata_ninja32.c
28412+++ b/drivers/ata/pata_ninja32.c
28413@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32_sht = {
28414 ATA_BMDMA_SHT(DRV_NAME),
28415 };
28416
28417-static struct ata_port_operations ninja32_port_ops = {
28418+static const struct ata_port_operations ninja32_port_ops = {
28419 .inherits = &ata_bmdma_port_ops,
28420 .sff_dev_select = ninja32_dev_select,
28421 .cable_detect = ata_cable_40wire,
28422diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
28423index ca53fac..9aa93ef 100644
28424--- a/drivers/ata/pata_ns87410.c
28425+++ b/drivers/ata/pata_ns87410.c
28426@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410_sht = {
28427 ATA_PIO_SHT(DRV_NAME),
28428 };
28429
28430-static struct ata_port_operations ns87410_port_ops = {
28431+static const struct ata_port_operations ns87410_port_ops = {
28432 .inherits = &ata_sff_port_ops,
28433 .qc_issue = ns87410_qc_issue,
28434 .cable_detect = ata_cable_40wire,
28435diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
28436index 773b159..55f454e 100644
28437--- a/drivers/ata/pata_ns87415.c
28438+++ b/drivers/ata/pata_ns87415.c
28439@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct ata_port *ap)
28440 }
28441 #endif /* 87560 SuperIO Support */
28442
28443-static struct ata_port_operations ns87415_pata_ops = {
28444+static const struct ata_port_operations ns87415_pata_ops = {
28445 .inherits = &ata_bmdma_port_ops,
28446
28447 .check_atapi_dma = ns87415_check_atapi_dma,
28448@@ -313,7 +313,7 @@ static struct ata_port_operations ns87415_pata_ops = {
28449 };
28450
28451 #if defined(CONFIG_SUPERIO)
28452-static struct ata_port_operations ns87560_pata_ops = {
28453+static const struct ata_port_operations ns87560_pata_ops = {
28454 .inherits = &ns87415_pata_ops,
28455 .sff_tf_read = ns87560_tf_read,
28456 .sff_check_status = ns87560_check_status,
28457diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
28458index d6f6956..639295b 100644
28459--- a/drivers/ata/pata_octeon_cf.c
28460+++ b/drivers/ata/pata_octeon_cf.c
28461@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(struct ata_queued_cmd *qc)
28462 return 0;
28463 }
28464
28465+/* cannot be const */
28466 static struct ata_port_operations octeon_cf_ops = {
28467 .inherits = &ata_sff_port_ops,
28468 .check_atapi_dma = octeon_cf_check_atapi_dma,
28469diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
28470index 84ac503..adee1cd 100644
28471--- a/drivers/ata/pata_oldpiix.c
28472+++ b/drivers/ata/pata_oldpiix.c
28473@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix_sht = {
28474 ATA_BMDMA_SHT(DRV_NAME),
28475 };
28476
28477-static struct ata_port_operations oldpiix_pata_ops = {
28478+static const struct ata_port_operations oldpiix_pata_ops = {
28479 .inherits = &ata_bmdma_port_ops,
28480 .qc_issue = oldpiix_qc_issue,
28481 .cable_detect = ata_cable_40wire,
28482diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
28483index 99eddda..3a4c0aa 100644
28484--- a/drivers/ata/pata_opti.c
28485+++ b/drivers/ata/pata_opti.c
28486@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sht = {
28487 ATA_PIO_SHT(DRV_NAME),
28488 };
28489
28490-static struct ata_port_operations opti_port_ops = {
28491+static const struct ata_port_operations opti_port_ops = {
28492 .inherits = &ata_sff_port_ops,
28493 .cable_detect = ata_cable_40wire,
28494 .set_piomode = opti_set_piomode,
28495diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
28496index 86885a4..8e9968d 100644
28497--- a/drivers/ata/pata_optidma.c
28498+++ b/drivers/ata/pata_optidma.c
28499@@ -337,7 +337,7 @@ static struct scsi_host_template optidma_sht = {
28500 ATA_BMDMA_SHT(DRV_NAME),
28501 };
28502
28503-static struct ata_port_operations optidma_port_ops = {
28504+static const struct ata_port_operations optidma_port_ops = {
28505 .inherits = &ata_bmdma_port_ops,
28506 .cable_detect = ata_cable_40wire,
28507 .set_piomode = optidma_set_pio_mode,
28508@@ -346,7 +346,7 @@ static struct ata_port_operations optidma_port_ops = {
28509 .prereset = optidma_pre_reset,
28510 };
28511
28512-static struct ata_port_operations optiplus_port_ops = {
28513+static const struct ata_port_operations optiplus_port_ops = {
28514 .inherits = &optidma_port_ops,
28515 .set_piomode = optiplus_set_pio_mode,
28516 .set_dmamode = optiplus_set_dma_mode,
28517diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c
28518index 11fb4cc..1a14022 100644
28519--- a/drivers/ata/pata_palmld.c
28520+++ b/drivers/ata/pata_palmld.c
28521@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_sht = {
28522 ATA_PIO_SHT(DRV_NAME),
28523 };
28524
28525-static struct ata_port_operations palmld_port_ops = {
28526+static const struct ata_port_operations palmld_port_ops = {
28527 .inherits = &ata_sff_port_ops,
28528 .sff_data_xfer = ata_sff_data_xfer_noirq,
28529 .cable_detect = ata_cable_40wire,
28530diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
28531index dc99e26..7f4b1e4 100644
28532--- a/drivers/ata/pata_pcmcia.c
28533+++ b/drivers/ata/pata_pcmcia.c
28534@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_sht = {
28535 ATA_PIO_SHT(DRV_NAME),
28536 };
28537
28538-static struct ata_port_operations pcmcia_port_ops = {
28539+static const struct ata_port_operations pcmcia_port_ops = {
28540 .inherits = &ata_sff_port_ops,
28541 .sff_data_xfer = ata_sff_data_xfer_noirq,
28542 .cable_detect = ata_cable_40wire,
28543 .set_mode = pcmcia_set_mode,
28544 };
28545
28546-static struct ata_port_operations pcmcia_8bit_port_ops = {
28547+static const struct ata_port_operations pcmcia_8bit_port_ops = {
28548 .inherits = &ata_sff_port_ops,
28549 .sff_data_xfer = ata_data_xfer_8bit,
28550 .cable_detect = ata_cable_40wire,
28551@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
28552 unsigned long io_base, ctl_base;
28553 void __iomem *io_addr, *ctl_addr;
28554 int n_ports = 1;
28555- struct ata_port_operations *ops = &pcmcia_port_ops;
28556+ const struct ata_port_operations *ops = &pcmcia_port_ops;
28557
28558 info = kzalloc(sizeof(*info), GFP_KERNEL);
28559 if (info == NULL)
28560diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
28561index ca5cad0..3a1f125 100644
28562--- a/drivers/ata/pata_pdc2027x.c
28563+++ b/drivers/ata/pata_pdc2027x.c
28564@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027x_sht = {
28565 ATA_BMDMA_SHT(DRV_NAME),
28566 };
28567
28568-static struct ata_port_operations pdc2027x_pata100_ops = {
28569+static const struct ata_port_operations pdc2027x_pata100_ops = {
28570 .inherits = &ata_bmdma_port_ops,
28571 .check_atapi_dma = pdc2027x_check_atapi_dma,
28572 .cable_detect = pdc2027x_cable_detect,
28573 .prereset = pdc2027x_prereset,
28574 };
28575
28576-static struct ata_port_operations pdc2027x_pata133_ops = {
28577+static const struct ata_port_operations pdc2027x_pata133_ops = {
28578 .inherits = &pdc2027x_pata100_ops,
28579 .mode_filter = pdc2027x_mode_filter,
28580 .set_piomode = pdc2027x_set_piomode,
28581diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
28582index 2911120..4bf62aa 100644
28583--- a/drivers/ata/pata_pdc202xx_old.c
28584+++ b/drivers/ata/pata_pdc202xx_old.c
28585@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202xx_sht = {
28586 ATA_BMDMA_SHT(DRV_NAME),
28587 };
28588
28589-static struct ata_port_operations pdc2024x_port_ops = {
28590+static const struct ata_port_operations pdc2024x_port_ops = {
28591 .inherits = &ata_bmdma_port_ops,
28592
28593 .cable_detect = ata_cable_40wire,
28594@@ -284,7 +284,7 @@ static struct ata_port_operations pdc2024x_port_ops = {
28595 .sff_exec_command = pdc202xx_exec_command,
28596 };
28597
28598-static struct ata_port_operations pdc2026x_port_ops = {
28599+static const struct ata_port_operations pdc2026x_port_ops = {
28600 .inherits = &pdc2024x_port_ops,
28601
28602 .check_atapi_dma = pdc2026x_check_atapi_dma,
28603diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
28604index 3f6ebc6..a18c358 100644
28605--- a/drivers/ata/pata_platform.c
28606+++ b/drivers/ata/pata_platform.c
28607@@ -48,7 +48,7 @@ static struct scsi_host_template pata_platform_sht = {
28608 ATA_PIO_SHT(DRV_NAME),
28609 };
28610
28611-static struct ata_port_operations pata_platform_port_ops = {
28612+static const struct ata_port_operations pata_platform_port_ops = {
28613 .inherits = &ata_sff_port_ops,
28614 .sff_data_xfer = ata_sff_data_xfer_noirq,
28615 .cable_detect = ata_cable_unknown,
28616diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
28617index 45879dc..165a9f9 100644
28618--- a/drivers/ata/pata_qdi.c
28619+++ b/drivers/ata/pata_qdi.c
28620@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht = {
28621 ATA_PIO_SHT(DRV_NAME),
28622 };
28623
28624-static struct ata_port_operations qdi6500_port_ops = {
28625+static const struct ata_port_operations qdi6500_port_ops = {
28626 .inherits = &ata_sff_port_ops,
28627 .qc_issue = qdi_qc_issue,
28628 .sff_data_xfer = qdi_data_xfer,
28629@@ -165,7 +165,7 @@ static struct ata_port_operations qdi6500_port_ops = {
28630 .set_piomode = qdi6500_set_piomode,
28631 };
28632
28633-static struct ata_port_operations qdi6580_port_ops = {
28634+static const struct ata_port_operations qdi6580_port_ops = {
28635 .inherits = &qdi6500_port_ops,
28636 .set_piomode = qdi6580_set_piomode,
28637 };
28638diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
28639index 4401b33..716c5cc 100644
28640--- a/drivers/ata/pata_radisys.c
28641+++ b/drivers/ata/pata_radisys.c
28642@@ -187,7 +187,7 @@ static struct scsi_host_template radisys_sht = {
28643 ATA_BMDMA_SHT(DRV_NAME),
28644 };
28645
28646-static struct ata_port_operations radisys_pata_ops = {
28647+static const struct ata_port_operations radisys_pata_ops = {
28648 .inherits = &ata_bmdma_port_ops,
28649 .qc_issue = radisys_qc_issue,
28650 .cable_detect = ata_cable_unknown,
28651diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
28652index 45f1e10..fab6bca 100644
28653--- a/drivers/ata/pata_rb532_cf.c
28654+++ b/drivers/ata/pata_rb532_cf.c
28655@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
28656 return IRQ_HANDLED;
28657 }
28658
28659-static struct ata_port_operations rb532_pata_port_ops = {
28660+static const struct ata_port_operations rb532_pata_port_ops = {
28661 .inherits = &ata_sff_port_ops,
28662 .sff_data_xfer = ata_sff_data_xfer32,
28663 };
28664diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c
28665index c843a1e..b5853c3 100644
28666--- a/drivers/ata/pata_rdc.c
28667+++ b/drivers/ata/pata_rdc.c
28668@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
28669 pci_write_config_byte(dev, 0x48, udma_enable);
28670 }
28671
28672-static struct ata_port_operations rdc_pata_ops = {
28673+static const struct ata_port_operations rdc_pata_ops = {
28674 .inherits = &ata_bmdma32_port_ops,
28675 .cable_detect = rdc_pata_cable_detect,
28676 .set_piomode = rdc_set_piomode,
28677diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
28678index a5e4dfe..080c8c9 100644
28679--- a/drivers/ata/pata_rz1000.c
28680+++ b/drivers/ata/pata_rz1000.c
28681@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_sht = {
28682 ATA_PIO_SHT(DRV_NAME),
28683 };
28684
28685-static struct ata_port_operations rz1000_port_ops = {
28686+static const struct ata_port_operations rz1000_port_ops = {
28687 .inherits = &ata_sff_port_ops,
28688 .cable_detect = ata_cable_40wire,
28689 .set_mode = rz1000_set_mode,
28690diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
28691index 3bbed83..e309daf 100644
28692--- a/drivers/ata/pata_sc1200.c
28693+++ b/drivers/ata/pata_sc1200.c
28694@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_sht = {
28695 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28696 };
28697
28698-static struct ata_port_operations sc1200_port_ops = {
28699+static const struct ata_port_operations sc1200_port_ops = {
28700 .inherits = &ata_bmdma_port_ops,
28701 .qc_prep = ata_sff_dumb_qc_prep,
28702 .qc_issue = sc1200_qc_issue,
28703diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
28704index 4257d6b..4c1d9d5 100644
28705--- a/drivers/ata/pata_scc.c
28706+++ b/drivers/ata/pata_scc.c
28707@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht = {
28708 ATA_BMDMA_SHT(DRV_NAME),
28709 };
28710
28711-static struct ata_port_operations scc_pata_ops = {
28712+static const struct ata_port_operations scc_pata_ops = {
28713 .inherits = &ata_bmdma_port_ops,
28714
28715 .set_piomode = scc_set_piomode,
28716diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
28717index 99cceb4..e2e0a87 100644
28718--- a/drivers/ata/pata_sch.c
28719+++ b/drivers/ata/pata_sch.c
28720@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht = {
28721 ATA_BMDMA_SHT(DRV_NAME),
28722 };
28723
28724-static struct ata_port_operations sch_pata_ops = {
28725+static const struct ata_port_operations sch_pata_ops = {
28726 .inherits = &ata_bmdma_port_ops,
28727 .cable_detect = ata_cable_unknown,
28728 .set_piomode = sch_set_piomode,
28729diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
28730index beaed12..39969f1 100644
28731--- a/drivers/ata/pata_serverworks.c
28732+++ b/drivers/ata/pata_serverworks.c
28733@@ -299,7 +299,7 @@ static struct scsi_host_template serverworks_sht = {
28734 ATA_BMDMA_SHT(DRV_NAME),
28735 };
28736
28737-static struct ata_port_operations serverworks_osb4_port_ops = {
28738+static const struct ata_port_operations serverworks_osb4_port_ops = {
28739 .inherits = &ata_bmdma_port_ops,
28740 .cable_detect = serverworks_cable_detect,
28741 .mode_filter = serverworks_osb4_filter,
28742@@ -307,7 +307,7 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
28743 .set_dmamode = serverworks_set_dmamode,
28744 };
28745
28746-static struct ata_port_operations serverworks_csb_port_ops = {
28747+static const struct ata_port_operations serverworks_csb_port_ops = {
28748 .inherits = &serverworks_osb4_port_ops,
28749 .mode_filter = serverworks_csb_filter,
28750 };
28751diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
28752index a2ace48..0463b44 100644
28753--- a/drivers/ata/pata_sil680.c
28754+++ b/drivers/ata/pata_sil680.c
28755@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_sht = {
28756 ATA_BMDMA_SHT(DRV_NAME),
28757 };
28758
28759-static struct ata_port_operations sil680_port_ops = {
28760+static const struct ata_port_operations sil680_port_ops = {
28761 .inherits = &ata_bmdma32_port_ops,
28762 .cable_detect = sil680_cable_detect,
28763 .set_piomode = sil680_set_piomode,
28764diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
28765index 488e77b..b3724d5 100644
28766--- a/drivers/ata/pata_sis.c
28767+++ b/drivers/ata/pata_sis.c
28768@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht = {
28769 ATA_BMDMA_SHT(DRV_NAME),
28770 };
28771
28772-static struct ata_port_operations sis_133_for_sata_ops = {
28773+static const struct ata_port_operations sis_133_for_sata_ops = {
28774 .inherits = &ata_bmdma_port_ops,
28775 .set_piomode = sis_133_set_piomode,
28776 .set_dmamode = sis_133_set_dmamode,
28777 .cable_detect = sis_133_cable_detect,
28778 };
28779
28780-static struct ata_port_operations sis_base_ops = {
28781+static const struct ata_port_operations sis_base_ops = {
28782 .inherits = &ata_bmdma_port_ops,
28783 .prereset = sis_pre_reset,
28784 };
28785
28786-static struct ata_port_operations sis_133_ops = {
28787+static const struct ata_port_operations sis_133_ops = {
28788 .inherits = &sis_base_ops,
28789 .set_piomode = sis_133_set_piomode,
28790 .set_dmamode = sis_133_set_dmamode,
28791 .cable_detect = sis_133_cable_detect,
28792 };
28793
28794-static struct ata_port_operations sis_133_early_ops = {
28795+static const struct ata_port_operations sis_133_early_ops = {
28796 .inherits = &sis_base_ops,
28797 .set_piomode = sis_100_set_piomode,
28798 .set_dmamode = sis_133_early_set_dmamode,
28799 .cable_detect = sis_66_cable_detect,
28800 };
28801
28802-static struct ata_port_operations sis_100_ops = {
28803+static const struct ata_port_operations sis_100_ops = {
28804 .inherits = &sis_base_ops,
28805 .set_piomode = sis_100_set_piomode,
28806 .set_dmamode = sis_100_set_dmamode,
28807 .cable_detect = sis_66_cable_detect,
28808 };
28809
28810-static struct ata_port_operations sis_66_ops = {
28811+static const struct ata_port_operations sis_66_ops = {
28812 .inherits = &sis_base_ops,
28813 .set_piomode = sis_old_set_piomode,
28814 .set_dmamode = sis_66_set_dmamode,
28815 .cable_detect = sis_66_cable_detect,
28816 };
28817
28818-static struct ata_port_operations sis_old_ops = {
28819+static const struct ata_port_operations sis_old_ops = {
28820 .inherits = &sis_base_ops,
28821 .set_piomode = sis_old_set_piomode,
28822 .set_dmamode = sis_old_set_dmamode,
28823diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
28824index 29f733c..43e9ca0 100644
28825--- a/drivers/ata/pata_sl82c105.c
28826+++ b/drivers/ata/pata_sl82c105.c
28827@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c105_sht = {
28828 ATA_BMDMA_SHT(DRV_NAME),
28829 };
28830
28831-static struct ata_port_operations sl82c105_port_ops = {
28832+static const struct ata_port_operations sl82c105_port_ops = {
28833 .inherits = &ata_bmdma_port_ops,
28834 .qc_defer = sl82c105_qc_defer,
28835 .bmdma_start = sl82c105_bmdma_start,
28836diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
28837index f1f13ff..df39e99 100644
28838--- a/drivers/ata/pata_triflex.c
28839+++ b/drivers/ata/pata_triflex.c
28840@@ -178,7 +178,7 @@ static struct scsi_host_template triflex_sht = {
28841 ATA_BMDMA_SHT(DRV_NAME),
28842 };
28843
28844-static struct ata_port_operations triflex_port_ops = {
28845+static const struct ata_port_operations triflex_port_ops = {
28846 .inherits = &ata_bmdma_port_ops,
28847 .bmdma_start = triflex_bmdma_start,
28848 .bmdma_stop = triflex_bmdma_stop,
28849diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
28850index 1d73b8d..98a4b29 100644
28851--- a/drivers/ata/pata_via.c
28852+++ b/drivers/ata/pata_via.c
28853@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht = {
28854 ATA_BMDMA_SHT(DRV_NAME),
28855 };
28856
28857-static struct ata_port_operations via_port_ops = {
28858+static const struct ata_port_operations via_port_ops = {
28859 .inherits = &ata_bmdma_port_ops,
28860 .cable_detect = via_cable_detect,
28861 .set_piomode = via_set_piomode,
28862@@ -429,7 +429,7 @@ static struct ata_port_operations via_port_ops = {
28863 .port_start = via_port_start,
28864 };
28865
28866-static struct ata_port_operations via_port_ops_noirq = {
28867+static const struct ata_port_operations via_port_ops_noirq = {
28868 .inherits = &via_port_ops,
28869 .sff_data_xfer = ata_sff_data_xfer_noirq,
28870 };
28871diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
28872index 6d8619b..ad511c4 100644
28873--- a/drivers/ata/pata_winbond.c
28874+++ b/drivers/ata/pata_winbond.c
28875@@ -125,7 +125,7 @@ static struct scsi_host_template winbond_sht = {
28876 ATA_PIO_SHT(DRV_NAME),
28877 };
28878
28879-static struct ata_port_operations winbond_port_ops = {
28880+static const struct ata_port_operations winbond_port_ops = {
28881 .inherits = &ata_sff_port_ops,
28882 .sff_data_xfer = winbond_data_xfer,
28883 .cable_detect = ata_cable_40wire,
28884diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
28885index 6c65b07..f996ec7 100644
28886--- a/drivers/ata/pdc_adma.c
28887+++ b/drivers/ata/pdc_adma.c
28888@@ -145,7 +145,7 @@ static struct scsi_host_template adma_ata_sht = {
28889 .dma_boundary = ADMA_DMA_BOUNDARY,
28890 };
28891
28892-static struct ata_port_operations adma_ata_ops = {
28893+static const struct ata_port_operations adma_ata_ops = {
28894 .inherits = &ata_sff_port_ops,
28895
28896 .lost_interrupt = ATA_OP_NULL,
28897diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
28898index 172b57e..c49bc1e 100644
28899--- a/drivers/ata/sata_fsl.c
28900+++ b/drivers/ata/sata_fsl.c
28901@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fsl_sht = {
28902 .dma_boundary = ATA_DMA_BOUNDARY,
28903 };
28904
28905-static struct ata_port_operations sata_fsl_ops = {
28906+static const struct ata_port_operations sata_fsl_ops = {
28907 .inherits = &sata_pmp_port_ops,
28908
28909 .qc_defer = ata_std_qc_defer,
28910diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
28911index 4406902..60603ef 100644
28912--- a/drivers/ata/sata_inic162x.c
28913+++ b/drivers/ata/sata_inic162x.c
28914@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_port *ap)
28915 return 0;
28916 }
28917
28918-static struct ata_port_operations inic_port_ops = {
28919+static const struct ata_port_operations inic_port_ops = {
28920 .inherits = &sata_port_ops,
28921
28922 .check_atapi_dma = inic_check_atapi_dma,
28923diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
28924index cf41126..8107be6 100644
28925--- a/drivers/ata/sata_mv.c
28926+++ b/drivers/ata/sata_mv.c
28927@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht = {
28928 .dma_boundary = MV_DMA_BOUNDARY,
28929 };
28930
28931-static struct ata_port_operations mv5_ops = {
28932+static const struct ata_port_operations mv5_ops = {
28933 .inherits = &ata_sff_port_ops,
28934
28935 .lost_interrupt = ATA_OP_NULL,
28936@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_ops = {
28937 .port_stop = mv_port_stop,
28938 };
28939
28940-static struct ata_port_operations mv6_ops = {
28941+static const struct ata_port_operations mv6_ops = {
28942 .inherits = &mv5_ops,
28943 .dev_config = mv6_dev_config,
28944 .scr_read = mv_scr_read,
28945@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_ops = {
28946 .bmdma_status = mv_bmdma_status,
28947 };
28948
28949-static struct ata_port_operations mv_iie_ops = {
28950+static const struct ata_port_operations mv_iie_ops = {
28951 .inherits = &mv6_ops,
28952 .dev_config = ATA_OP_NULL,
28953 .qc_prep = mv_qc_prep_iie,
28954diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
28955index ae2297c..d5c9c33 100644
28956--- a/drivers/ata/sata_nv.c
28957+++ b/drivers/ata/sata_nv.c
28958@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swncq_sht = {
28959 * cases. Define nv_hardreset() which only kicks in for post-boot
28960 * probing and use it for all variants.
28961 */
28962-static struct ata_port_operations nv_generic_ops = {
28963+static const struct ata_port_operations nv_generic_ops = {
28964 .inherits = &ata_bmdma_port_ops,
28965 .lost_interrupt = ATA_OP_NULL,
28966 .scr_read = nv_scr_read,
28967@@ -472,20 +472,20 @@ static struct ata_port_operations nv_generic_ops = {
28968 .hardreset = nv_hardreset,
28969 };
28970
28971-static struct ata_port_operations nv_nf2_ops = {
28972+static const struct ata_port_operations nv_nf2_ops = {
28973 .inherits = &nv_generic_ops,
28974 .freeze = nv_nf2_freeze,
28975 .thaw = nv_nf2_thaw,
28976 };
28977
28978-static struct ata_port_operations nv_ck804_ops = {
28979+static const struct ata_port_operations nv_ck804_ops = {
28980 .inherits = &nv_generic_ops,
28981 .freeze = nv_ck804_freeze,
28982 .thaw = nv_ck804_thaw,
28983 .host_stop = nv_ck804_host_stop,
28984 };
28985
28986-static struct ata_port_operations nv_adma_ops = {
28987+static const struct ata_port_operations nv_adma_ops = {
28988 .inherits = &nv_ck804_ops,
28989
28990 .check_atapi_dma = nv_adma_check_atapi_dma,
28991@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adma_ops = {
28992 .host_stop = nv_adma_host_stop,
28993 };
28994
28995-static struct ata_port_operations nv_swncq_ops = {
28996+static const struct ata_port_operations nv_swncq_ops = {
28997 .inherits = &nv_generic_ops,
28998
28999 .qc_defer = ata_std_qc_defer,
29000diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
29001index 07d8d00..6cc70bb 100644
29002--- a/drivers/ata/sata_promise.c
29003+++ b/drivers/ata/sata_promise.c
29004@@ -195,7 +195,7 @@ static const struct ata_port_operations pdc_common_ops = {
29005 .error_handler = pdc_error_handler,
29006 };
29007
29008-static struct ata_port_operations pdc_sata_ops = {
29009+static const struct ata_port_operations pdc_sata_ops = {
29010 .inherits = &pdc_common_ops,
29011 .cable_detect = pdc_sata_cable_detect,
29012 .freeze = pdc_sata_freeze,
29013@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sata_ops = {
29014
29015 /* First-generation chips need a more restrictive ->check_atapi_dma op,
29016 and ->freeze/thaw that ignore the hotplug controls. */
29017-static struct ata_port_operations pdc_old_sata_ops = {
29018+static const struct ata_port_operations pdc_old_sata_ops = {
29019 .inherits = &pdc_sata_ops,
29020 .freeze = pdc_freeze,
29021 .thaw = pdc_thaw,
29022 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
29023 };
29024
29025-static struct ata_port_operations pdc_pata_ops = {
29026+static const struct ata_port_operations pdc_pata_ops = {
29027 .inherits = &pdc_common_ops,
29028 .cable_detect = pdc_pata_cable_detect,
29029 .freeze = pdc_freeze,
29030diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
29031index 326c0cf..36ecebe 100644
29032--- a/drivers/ata/sata_qstor.c
29033+++ b/drivers/ata/sata_qstor.c
29034@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_sht = {
29035 .dma_boundary = QS_DMA_BOUNDARY,
29036 };
29037
29038-static struct ata_port_operations qs_ata_ops = {
29039+static const struct ata_port_operations qs_ata_ops = {
29040 .inherits = &ata_sff_port_ops,
29041
29042 .check_atapi_dma = qs_check_atapi_dma,
29043diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
29044index 3cb69d5..0871d3c 100644
29045--- a/drivers/ata/sata_sil.c
29046+++ b/drivers/ata/sata_sil.c
29047@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht = {
29048 .sg_tablesize = ATA_MAX_PRD
29049 };
29050
29051-static struct ata_port_operations sil_ops = {
29052+static const struct ata_port_operations sil_ops = {
29053 .inherits = &ata_bmdma32_port_ops,
29054 .dev_config = sil_dev_config,
29055 .set_mode = sil_set_mode,
29056diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
29057index e6946fc..eddb794 100644
29058--- a/drivers/ata/sata_sil24.c
29059+++ b/drivers/ata/sata_sil24.c
29060@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_sht = {
29061 .dma_boundary = ATA_DMA_BOUNDARY,
29062 };
29063
29064-static struct ata_port_operations sil24_ops = {
29065+static const struct ata_port_operations sil24_ops = {
29066 .inherits = &sata_pmp_port_ops,
29067
29068 .qc_defer = sil24_qc_defer,
29069diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
29070index f8a91bf..9cb06b6 100644
29071--- a/drivers/ata/sata_sis.c
29072+++ b/drivers/ata/sata_sis.c
29073@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht = {
29074 ATA_BMDMA_SHT(DRV_NAME),
29075 };
29076
29077-static struct ata_port_operations sis_ops = {
29078+static const struct ata_port_operations sis_ops = {
29079 .inherits = &ata_bmdma_port_ops,
29080 .scr_read = sis_scr_read,
29081 .scr_write = sis_scr_write,
29082diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
29083index 7257f2d..d04c6f5 100644
29084--- a/drivers/ata/sata_svw.c
29085+++ b/drivers/ata/sata_svw.c
29086@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata_sht = {
29087 };
29088
29089
29090-static struct ata_port_operations k2_sata_ops = {
29091+static const struct ata_port_operations k2_sata_ops = {
29092 .inherits = &ata_bmdma_port_ops,
29093 .sff_tf_load = k2_sata_tf_load,
29094 .sff_tf_read = k2_sata_tf_read,
29095diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
29096index bbcf970..cd0df0d 100644
29097--- a/drivers/ata/sata_sx4.c
29098+++ b/drivers/ata/sata_sx4.c
29099@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sata_sht = {
29100 };
29101
29102 /* TODO: inherit from base port_ops after converting to new EH */
29103-static struct ata_port_operations pdc_20621_ops = {
29104+static const struct ata_port_operations pdc_20621_ops = {
29105 .inherits = &ata_sff_port_ops,
29106
29107 .check_atapi_dma = pdc_check_atapi_dma,
29108diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
29109index e5bff47..089d859 100644
29110--- a/drivers/ata/sata_uli.c
29111+++ b/drivers/ata/sata_uli.c
29112@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht = {
29113 ATA_BMDMA_SHT(DRV_NAME),
29114 };
29115
29116-static struct ata_port_operations uli_ops = {
29117+static const struct ata_port_operations uli_ops = {
29118 .inherits = &ata_bmdma_port_ops,
29119 .scr_read = uli_scr_read,
29120 .scr_write = uli_scr_write,
29121diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
29122index f5dcca7..77b94eb 100644
29123--- a/drivers/ata/sata_via.c
29124+++ b/drivers/ata/sata_via.c
29125@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sht = {
29126 ATA_BMDMA_SHT(DRV_NAME),
29127 };
29128
29129-static struct ata_port_operations svia_base_ops = {
29130+static const struct ata_port_operations svia_base_ops = {
29131 .inherits = &ata_bmdma_port_ops,
29132 .sff_tf_load = svia_tf_load,
29133 };
29134
29135-static struct ata_port_operations vt6420_sata_ops = {
29136+static const struct ata_port_operations vt6420_sata_ops = {
29137 .inherits = &svia_base_ops,
29138 .freeze = svia_noop_freeze,
29139 .prereset = vt6420_prereset,
29140 .bmdma_start = vt6420_bmdma_start,
29141 };
29142
29143-static struct ata_port_operations vt6421_pata_ops = {
29144+static const struct ata_port_operations vt6421_pata_ops = {
29145 .inherits = &svia_base_ops,
29146 .cable_detect = vt6421_pata_cable_detect,
29147 .set_piomode = vt6421_set_pio_mode,
29148 .set_dmamode = vt6421_set_dma_mode,
29149 };
29150
29151-static struct ata_port_operations vt6421_sata_ops = {
29152+static const struct ata_port_operations vt6421_sata_ops = {
29153 .inherits = &svia_base_ops,
29154 .scr_read = svia_scr_read,
29155 .scr_write = svia_scr_write,
29156 };
29157
29158-static struct ata_port_operations vt8251_ops = {
29159+static const struct ata_port_operations vt8251_ops = {
29160 .inherits = &svia_base_ops,
29161 .hardreset = sata_std_hardreset,
29162 .scr_read = vt8251_scr_read,
29163diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
29164index 8b2a278..51e65d3 100644
29165--- a/drivers/ata/sata_vsc.c
29166+++ b/drivers/ata/sata_vsc.c
29167@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sata_sht = {
29168 };
29169
29170
29171-static struct ata_port_operations vsc_sata_ops = {
29172+static const struct ata_port_operations vsc_sata_ops = {
29173 .inherits = &ata_bmdma_port_ops,
29174 /* The IRQ handling is not quite standard SFF behaviour so we
29175 cannot use the default lost interrupt handler */
29176diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29177index 5effec6..7e4019a 100644
29178--- a/drivers/atm/adummy.c
29179+++ b/drivers/atm/adummy.c
29180@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29181 vcc->pop(vcc, skb);
29182 else
29183 dev_kfree_skb_any(skb);
29184- atomic_inc(&vcc->stats->tx);
29185+ atomic_inc_unchecked(&vcc->stats->tx);
29186
29187 return 0;
29188 }
29189diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29190index 66e1813..26a27c6 100644
29191--- a/drivers/atm/ambassador.c
29192+++ b/drivers/atm/ambassador.c
29193@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29194 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29195
29196 // VC layer stats
29197- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29198+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29199
29200 // free the descriptor
29201 kfree (tx_descr);
29202@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29203 dump_skb ("<<<", vc, skb);
29204
29205 // VC layer stats
29206- atomic_inc(&atm_vcc->stats->rx);
29207+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29208 __net_timestamp(skb);
29209 // end of our responsability
29210 atm_vcc->push (atm_vcc, skb);
29211@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29212 } else {
29213 PRINTK (KERN_INFO, "dropped over-size frame");
29214 // should we count this?
29215- atomic_inc(&atm_vcc->stats->rx_drop);
29216+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29217 }
29218
29219 } else {
29220@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29221 }
29222
29223 if (check_area (skb->data, skb->len)) {
29224- atomic_inc(&atm_vcc->stats->tx_err);
29225+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29226 return -ENOMEM; // ?
29227 }
29228
29229diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29230index 02ad83d..6daffeb 100644
29231--- a/drivers/atm/atmtcp.c
29232+++ b/drivers/atm/atmtcp.c
29233@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29234 if (vcc->pop) vcc->pop(vcc,skb);
29235 else dev_kfree_skb(skb);
29236 if (dev_data) return 0;
29237- atomic_inc(&vcc->stats->tx_err);
29238+ atomic_inc_unchecked(&vcc->stats->tx_err);
29239 return -ENOLINK;
29240 }
29241 size = skb->len+sizeof(struct atmtcp_hdr);
29242@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29243 if (!new_skb) {
29244 if (vcc->pop) vcc->pop(vcc,skb);
29245 else dev_kfree_skb(skb);
29246- atomic_inc(&vcc->stats->tx_err);
29247+ atomic_inc_unchecked(&vcc->stats->tx_err);
29248 return -ENOBUFS;
29249 }
29250 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29251@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29252 if (vcc->pop) vcc->pop(vcc,skb);
29253 else dev_kfree_skb(skb);
29254 out_vcc->push(out_vcc,new_skb);
29255- atomic_inc(&vcc->stats->tx);
29256- atomic_inc(&out_vcc->stats->rx);
29257+ atomic_inc_unchecked(&vcc->stats->tx);
29258+ atomic_inc_unchecked(&out_vcc->stats->rx);
29259 return 0;
29260 }
29261
29262@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29263 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29264 read_unlock(&vcc_sklist_lock);
29265 if (!out_vcc) {
29266- atomic_inc(&vcc->stats->tx_err);
29267+ atomic_inc_unchecked(&vcc->stats->tx_err);
29268 goto done;
29269 }
29270 skb_pull(skb,sizeof(struct atmtcp_hdr));
29271@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29272 __net_timestamp(new_skb);
29273 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29274 out_vcc->push(out_vcc,new_skb);
29275- atomic_inc(&vcc->stats->tx);
29276- atomic_inc(&out_vcc->stats->rx);
29277+ atomic_inc_unchecked(&vcc->stats->tx);
29278+ atomic_inc_unchecked(&out_vcc->stats->rx);
29279 done:
29280 if (vcc->pop) vcc->pop(vcc,skb);
29281 else dev_kfree_skb(skb);
29282diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29283index 0c30261..3da356e 100644
29284--- a/drivers/atm/eni.c
29285+++ b/drivers/atm/eni.c
29286@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29287 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29288 vcc->dev->number);
29289 length = 0;
29290- atomic_inc(&vcc->stats->rx_err);
29291+ atomic_inc_unchecked(&vcc->stats->rx_err);
29292 }
29293 else {
29294 length = ATM_CELL_SIZE-1; /* no HEC */
29295@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29296 size);
29297 }
29298 eff = length = 0;
29299- atomic_inc(&vcc->stats->rx_err);
29300+ atomic_inc_unchecked(&vcc->stats->rx_err);
29301 }
29302 else {
29303 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29304@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29305 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29306 vcc->dev->number,vcc->vci,length,size << 2,descr);
29307 length = eff = 0;
29308- atomic_inc(&vcc->stats->rx_err);
29309+ atomic_inc_unchecked(&vcc->stats->rx_err);
29310 }
29311 }
29312 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29313@@ -770,7 +770,7 @@ rx_dequeued++;
29314 vcc->push(vcc,skb);
29315 pushed++;
29316 }
29317- atomic_inc(&vcc->stats->rx);
29318+ atomic_inc_unchecked(&vcc->stats->rx);
29319 }
29320 wake_up(&eni_dev->rx_wait);
29321 }
29322@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29323 PCI_DMA_TODEVICE);
29324 if (vcc->pop) vcc->pop(vcc,skb);
29325 else dev_kfree_skb_irq(skb);
29326- atomic_inc(&vcc->stats->tx);
29327+ atomic_inc_unchecked(&vcc->stats->tx);
29328 wake_up(&eni_dev->tx_wait);
29329 dma_complete++;
29330 }
29331@@ -1570,7 +1570,7 @@ tx_complete++;
29332 /*--------------------------------- entries ---------------------------------*/
29333
29334
29335-static const char *media_name[] __devinitdata = {
29336+static const char *media_name[] __devinitconst = {
29337 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
29338 "UTP", "05?", "06?", "07?", /* 4- 7 */
29339 "TAXI","09?", "10?", "11?", /* 8-11 */
29340diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29341index cd5049a..a51209f 100644
29342--- a/drivers/atm/firestream.c
29343+++ b/drivers/atm/firestream.c
29344@@ -748,7 +748,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29345 }
29346 }
29347
29348- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29349+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29350
29351 fs_dprintk (FS_DEBUG_TXMEM, "i");
29352 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29353@@ -815,7 +815,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29354 #endif
29355 skb_put (skb, qe->p1 & 0xffff);
29356 ATM_SKB(skb)->vcc = atm_vcc;
29357- atomic_inc(&atm_vcc->stats->rx);
29358+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29359 __net_timestamp(skb);
29360 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29361 atm_vcc->push (atm_vcc, skb);
29362@@ -836,12 +836,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29363 kfree (pe);
29364 }
29365 if (atm_vcc)
29366- atomic_inc(&atm_vcc->stats->rx_drop);
29367+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29368 break;
29369 case 0x1f: /* Reassembly abort: no buffers. */
29370 /* Silently increment error counter. */
29371 if (atm_vcc)
29372- atomic_inc(&atm_vcc->stats->rx_drop);
29373+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29374 break;
29375 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29376 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29377diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29378index f766cc4..a34002e 100644
29379--- a/drivers/atm/fore200e.c
29380+++ b/drivers/atm/fore200e.c
29381@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29382 #endif
29383 /* check error condition */
29384 if (*entry->status & STATUS_ERROR)
29385- atomic_inc(&vcc->stats->tx_err);
29386+ atomic_inc_unchecked(&vcc->stats->tx_err);
29387 else
29388- atomic_inc(&vcc->stats->tx);
29389+ atomic_inc_unchecked(&vcc->stats->tx);
29390 }
29391 }
29392
29393@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29394 if (skb == NULL) {
29395 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29396
29397- atomic_inc(&vcc->stats->rx_drop);
29398+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29399 return -ENOMEM;
29400 }
29401
29402@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29403
29404 dev_kfree_skb_any(skb);
29405
29406- atomic_inc(&vcc->stats->rx_drop);
29407+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29408 return -ENOMEM;
29409 }
29410
29411 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29412
29413 vcc->push(vcc, skb);
29414- atomic_inc(&vcc->stats->rx);
29415+ atomic_inc_unchecked(&vcc->stats->rx);
29416
29417 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29418
29419@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29420 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29421 fore200e->atm_dev->number,
29422 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29423- atomic_inc(&vcc->stats->rx_err);
29424+ atomic_inc_unchecked(&vcc->stats->rx_err);
29425 }
29426 }
29427
29428@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29429 goto retry_here;
29430 }
29431
29432- atomic_inc(&vcc->stats->tx_err);
29433+ atomic_inc_unchecked(&vcc->stats->tx_err);
29434
29435 fore200e->tx_sat++;
29436 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29437diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29438index 7066703..2b130de 100644
29439--- a/drivers/atm/he.c
29440+++ b/drivers/atm/he.c
29441@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29442
29443 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29444 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29445- atomic_inc(&vcc->stats->rx_drop);
29446+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29447 goto return_host_buffers;
29448 }
29449
29450@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29451 RBRQ_LEN_ERR(he_dev->rbrq_head)
29452 ? "LEN_ERR" : "",
29453 vcc->vpi, vcc->vci);
29454- atomic_inc(&vcc->stats->rx_err);
29455+ atomic_inc_unchecked(&vcc->stats->rx_err);
29456 goto return_host_buffers;
29457 }
29458
29459@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29460 vcc->push(vcc, skb);
29461 spin_lock(&he_dev->global_lock);
29462
29463- atomic_inc(&vcc->stats->rx);
29464+ atomic_inc_unchecked(&vcc->stats->rx);
29465
29466 return_host_buffers:
29467 ++pdus_assembled;
29468@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
29469 tpd->vcc->pop(tpd->vcc, tpd->skb);
29470 else
29471 dev_kfree_skb_any(tpd->skb);
29472- atomic_inc(&tpd->vcc->stats->tx_err);
29473+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
29474 }
29475 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
29476 return;
29477@@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29478 vcc->pop(vcc, skb);
29479 else
29480 dev_kfree_skb_any(skb);
29481- atomic_inc(&vcc->stats->tx_err);
29482+ atomic_inc_unchecked(&vcc->stats->tx_err);
29483 return -EINVAL;
29484 }
29485
29486@@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29487 vcc->pop(vcc, skb);
29488 else
29489 dev_kfree_skb_any(skb);
29490- atomic_inc(&vcc->stats->tx_err);
29491+ atomic_inc_unchecked(&vcc->stats->tx_err);
29492 return -EINVAL;
29493 }
29494 #endif
29495@@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29496 vcc->pop(vcc, skb);
29497 else
29498 dev_kfree_skb_any(skb);
29499- atomic_inc(&vcc->stats->tx_err);
29500+ atomic_inc_unchecked(&vcc->stats->tx_err);
29501 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29502 return -ENOMEM;
29503 }
29504@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29505 vcc->pop(vcc, skb);
29506 else
29507 dev_kfree_skb_any(skb);
29508- atomic_inc(&vcc->stats->tx_err);
29509+ atomic_inc_unchecked(&vcc->stats->tx_err);
29510 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29511 return -ENOMEM;
29512 }
29513@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29514 __enqueue_tpd(he_dev, tpd, cid);
29515 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29516
29517- atomic_inc(&vcc->stats->tx);
29518+ atomic_inc_unchecked(&vcc->stats->tx);
29519
29520 return 0;
29521 }
29522diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
29523index 4e49021..01b1512 100644
29524--- a/drivers/atm/horizon.c
29525+++ b/drivers/atm/horizon.c
29526@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
29527 {
29528 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
29529 // VC layer stats
29530- atomic_inc(&vcc->stats->rx);
29531+ atomic_inc_unchecked(&vcc->stats->rx);
29532 __net_timestamp(skb);
29533 // end of our responsability
29534 vcc->push (vcc, skb);
29535@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
29536 dev->tx_iovec = NULL;
29537
29538 // VC layer stats
29539- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29540+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29541
29542 // free the skb
29543 hrz_kfree_skb (skb);
29544diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
29545index e33ae00..9deb4ab 100644
29546--- a/drivers/atm/idt77252.c
29547+++ b/drivers/atm/idt77252.c
29548@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
29549 else
29550 dev_kfree_skb(skb);
29551
29552- atomic_inc(&vcc->stats->tx);
29553+ atomic_inc_unchecked(&vcc->stats->tx);
29554 }
29555
29556 atomic_dec(&scq->used);
29557@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29558 if ((sb = dev_alloc_skb(64)) == NULL) {
29559 printk("%s: Can't allocate buffers for aal0.\n",
29560 card->name);
29561- atomic_add(i, &vcc->stats->rx_drop);
29562+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
29563 break;
29564 }
29565 if (!atm_charge(vcc, sb->truesize)) {
29566 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
29567 card->name);
29568- atomic_add(i - 1, &vcc->stats->rx_drop);
29569+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
29570 dev_kfree_skb(sb);
29571 break;
29572 }
29573@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29574 ATM_SKB(sb)->vcc = vcc;
29575 __net_timestamp(sb);
29576 vcc->push(vcc, sb);
29577- atomic_inc(&vcc->stats->rx);
29578+ atomic_inc_unchecked(&vcc->stats->rx);
29579
29580 cell += ATM_CELL_PAYLOAD;
29581 }
29582@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29583 "(CDC: %08x)\n",
29584 card->name, len, rpp->len, readl(SAR_REG_CDC));
29585 recycle_rx_pool_skb(card, rpp);
29586- atomic_inc(&vcc->stats->rx_err);
29587+ atomic_inc_unchecked(&vcc->stats->rx_err);
29588 return;
29589 }
29590 if (stat & SAR_RSQE_CRC) {
29591 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
29592 recycle_rx_pool_skb(card, rpp);
29593- atomic_inc(&vcc->stats->rx_err);
29594+ atomic_inc_unchecked(&vcc->stats->rx_err);
29595 return;
29596 }
29597 if (skb_queue_len(&rpp->queue) > 1) {
29598@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29599 RXPRINTK("%s: Can't alloc RX skb.\n",
29600 card->name);
29601 recycle_rx_pool_skb(card, rpp);
29602- atomic_inc(&vcc->stats->rx_err);
29603+ atomic_inc_unchecked(&vcc->stats->rx_err);
29604 return;
29605 }
29606 if (!atm_charge(vcc, skb->truesize)) {
29607@@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29608 __net_timestamp(skb);
29609
29610 vcc->push(vcc, skb);
29611- atomic_inc(&vcc->stats->rx);
29612+ atomic_inc_unchecked(&vcc->stats->rx);
29613
29614 return;
29615 }
29616@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29617 __net_timestamp(skb);
29618
29619 vcc->push(vcc, skb);
29620- atomic_inc(&vcc->stats->rx);
29621+ atomic_inc_unchecked(&vcc->stats->rx);
29622
29623 if (skb->truesize > SAR_FB_SIZE_3)
29624 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
29625@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
29626 if (vcc->qos.aal != ATM_AAL0) {
29627 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
29628 card->name, vpi, vci);
29629- atomic_inc(&vcc->stats->rx_drop);
29630+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29631 goto drop;
29632 }
29633
29634 if ((sb = dev_alloc_skb(64)) == NULL) {
29635 printk("%s: Can't allocate buffers for AAL0.\n",
29636 card->name);
29637- atomic_inc(&vcc->stats->rx_err);
29638+ atomic_inc_unchecked(&vcc->stats->rx_err);
29639 goto drop;
29640 }
29641
29642@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
29643 ATM_SKB(sb)->vcc = vcc;
29644 __net_timestamp(sb);
29645 vcc->push(vcc, sb);
29646- atomic_inc(&vcc->stats->rx);
29647+ atomic_inc_unchecked(&vcc->stats->rx);
29648
29649 drop:
29650 skb_pull(queue, 64);
29651@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29652
29653 if (vc == NULL) {
29654 printk("%s: NULL connection in send().\n", card->name);
29655- atomic_inc(&vcc->stats->tx_err);
29656+ atomic_inc_unchecked(&vcc->stats->tx_err);
29657 dev_kfree_skb(skb);
29658 return -EINVAL;
29659 }
29660 if (!test_bit(VCF_TX, &vc->flags)) {
29661 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
29662- atomic_inc(&vcc->stats->tx_err);
29663+ atomic_inc_unchecked(&vcc->stats->tx_err);
29664 dev_kfree_skb(skb);
29665 return -EINVAL;
29666 }
29667@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29668 break;
29669 default:
29670 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
29671- atomic_inc(&vcc->stats->tx_err);
29672+ atomic_inc_unchecked(&vcc->stats->tx_err);
29673 dev_kfree_skb(skb);
29674 return -EINVAL;
29675 }
29676
29677 if (skb_shinfo(skb)->nr_frags != 0) {
29678 printk("%s: No scatter-gather yet.\n", card->name);
29679- atomic_inc(&vcc->stats->tx_err);
29680+ atomic_inc_unchecked(&vcc->stats->tx_err);
29681 dev_kfree_skb(skb);
29682 return -EINVAL;
29683 }
29684@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29685
29686 err = queue_skb(card, vc, skb, oam);
29687 if (err) {
29688- atomic_inc(&vcc->stats->tx_err);
29689+ atomic_inc_unchecked(&vcc->stats->tx_err);
29690 dev_kfree_skb(skb);
29691 return err;
29692 }
29693@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
29694 skb = dev_alloc_skb(64);
29695 if (!skb) {
29696 printk("%s: Out of memory in send_oam().\n", card->name);
29697- atomic_inc(&vcc->stats->tx_err);
29698+ atomic_inc_unchecked(&vcc->stats->tx_err);
29699 return -ENOMEM;
29700 }
29701 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
29702diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
29703index b2c1b37..faa672b 100644
29704--- a/drivers/atm/iphase.c
29705+++ b/drivers/atm/iphase.c
29706@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
29707 status = (u_short) (buf_desc_ptr->desc_mode);
29708 if (status & (RX_CER | RX_PTE | RX_OFL))
29709 {
29710- atomic_inc(&vcc->stats->rx_err);
29711+ atomic_inc_unchecked(&vcc->stats->rx_err);
29712 IF_ERR(printk("IA: bad packet, dropping it");)
29713 if (status & RX_CER) {
29714 IF_ERR(printk(" cause: packet CRC error\n");)
29715@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
29716 len = dma_addr - buf_addr;
29717 if (len > iadev->rx_buf_sz) {
29718 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
29719- atomic_inc(&vcc->stats->rx_err);
29720+ atomic_inc_unchecked(&vcc->stats->rx_err);
29721 goto out_free_desc;
29722 }
29723
29724@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29725 ia_vcc = INPH_IA_VCC(vcc);
29726 if (ia_vcc == NULL)
29727 {
29728- atomic_inc(&vcc->stats->rx_err);
29729+ atomic_inc_unchecked(&vcc->stats->rx_err);
29730 dev_kfree_skb_any(skb);
29731 atm_return(vcc, atm_guess_pdu2truesize(len));
29732 goto INCR_DLE;
29733@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29734 if ((length > iadev->rx_buf_sz) || (length >
29735 (skb->len - sizeof(struct cpcs_trailer))))
29736 {
29737- atomic_inc(&vcc->stats->rx_err);
29738+ atomic_inc_unchecked(&vcc->stats->rx_err);
29739 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
29740 length, skb->len);)
29741 dev_kfree_skb_any(skb);
29742@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29743
29744 IF_RX(printk("rx_dle_intr: skb push");)
29745 vcc->push(vcc,skb);
29746- atomic_inc(&vcc->stats->rx);
29747+ atomic_inc_unchecked(&vcc->stats->rx);
29748 iadev->rx_pkt_cnt++;
29749 }
29750 INCR_DLE:
29751@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
29752 {
29753 struct k_sonet_stats *stats;
29754 stats = &PRIV(_ia_dev[board])->sonet_stats;
29755- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
29756- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
29757- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
29758- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
29759- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
29760- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
29761- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
29762- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
29763- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
29764+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
29765+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
29766+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
29767+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
29768+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
29769+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
29770+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
29771+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
29772+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
29773 }
29774 ia_cmds.status = 0;
29775 break;
29776@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29777 if ((desc == 0) || (desc > iadev->num_tx_desc))
29778 {
29779 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
29780- atomic_inc(&vcc->stats->tx);
29781+ atomic_inc_unchecked(&vcc->stats->tx);
29782 if (vcc->pop)
29783 vcc->pop(vcc, skb);
29784 else
29785@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29786 ATM_DESC(skb) = vcc->vci;
29787 skb_queue_tail(&iadev->tx_dma_q, skb);
29788
29789- atomic_inc(&vcc->stats->tx);
29790+ atomic_inc_unchecked(&vcc->stats->tx);
29791 iadev->tx_pkt_cnt++;
29792 /* Increment transaction counter */
29793 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29794
29795 #if 0
29796 /* add flow control logic */
29797- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29798+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29799 if (iavcc->vc_desc_cnt > 10) {
29800 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29801 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29802diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29803index cf97c34..8d30655 100644
29804--- a/drivers/atm/lanai.c
29805+++ b/drivers/atm/lanai.c
29806@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29807 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29808 lanai_endtx(lanai, lvcc);
29809 lanai_free_skb(lvcc->tx.atmvcc, skb);
29810- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29811+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29812 }
29813
29814 /* Try to fill the buffer - don't call unless there is backlog */
29815@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29816 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29817 __net_timestamp(skb);
29818 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29819- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29820+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29821 out:
29822 lvcc->rx.buf.ptr = end;
29823 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29824@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29825 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29826 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29827 lanai->stats.service_rxnotaal5++;
29828- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29829+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29830 return 0;
29831 }
29832 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29833@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29834 int bytes;
29835 read_unlock(&vcc_sklist_lock);
29836 DPRINTK("got trashed rx pdu on vci %d\n", vci);
29837- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29838+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29839 lvcc->stats.x.aal5.service_trash++;
29840 bytes = (SERVICE_GET_END(s) * 16) -
29841 (((unsigned long) lvcc->rx.buf.ptr) -
29842@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29843 }
29844 if (s & SERVICE_STREAM) {
29845 read_unlock(&vcc_sklist_lock);
29846- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29847+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29848 lvcc->stats.x.aal5.service_stream++;
29849 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29850 "PDU on VCI %d!\n", lanai->number, vci);
29851@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29852 return 0;
29853 }
29854 DPRINTK("got rx crc error on vci %d\n", vci);
29855- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29856+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29857 lvcc->stats.x.aal5.service_rxcrc++;
29858 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29859 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29860diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29861index 3da804b..d3b0eed 100644
29862--- a/drivers/atm/nicstar.c
29863+++ b/drivers/atm/nicstar.c
29864@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29865 if ((vc = (vc_map *) vcc->dev_data) == NULL)
29866 {
29867 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
29868- atomic_inc(&vcc->stats->tx_err);
29869+ atomic_inc_unchecked(&vcc->stats->tx_err);
29870 dev_kfree_skb_any(skb);
29871 return -EINVAL;
29872 }
29873@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29874 if (!vc->tx)
29875 {
29876 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
29877- atomic_inc(&vcc->stats->tx_err);
29878+ atomic_inc_unchecked(&vcc->stats->tx_err);
29879 dev_kfree_skb_any(skb);
29880 return -EINVAL;
29881 }
29882@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29883 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
29884 {
29885 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
29886- atomic_inc(&vcc->stats->tx_err);
29887+ atomic_inc_unchecked(&vcc->stats->tx_err);
29888 dev_kfree_skb_any(skb);
29889 return -EINVAL;
29890 }
29891@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29892 if (skb_shinfo(skb)->nr_frags != 0)
29893 {
29894 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29895- atomic_inc(&vcc->stats->tx_err);
29896+ atomic_inc_unchecked(&vcc->stats->tx_err);
29897 dev_kfree_skb_any(skb);
29898 return -EINVAL;
29899 }
29900@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29901
29902 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
29903 {
29904- atomic_inc(&vcc->stats->tx_err);
29905+ atomic_inc_unchecked(&vcc->stats->tx_err);
29906 dev_kfree_skb_any(skb);
29907 return -EIO;
29908 }
29909- atomic_inc(&vcc->stats->tx);
29910+ atomic_inc_unchecked(&vcc->stats->tx);
29911
29912 return 0;
29913 }
29914@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29915 {
29916 printk("nicstar%d: Can't allocate buffers for aal0.\n",
29917 card->index);
29918- atomic_add(i,&vcc->stats->rx_drop);
29919+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
29920 break;
29921 }
29922 if (!atm_charge(vcc, sb->truesize))
29923 {
29924 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
29925 card->index);
29926- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
29927+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
29928 dev_kfree_skb_any(sb);
29929 break;
29930 }
29931@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29932 ATM_SKB(sb)->vcc = vcc;
29933 __net_timestamp(sb);
29934 vcc->push(vcc, sb);
29935- atomic_inc(&vcc->stats->rx);
29936+ atomic_inc_unchecked(&vcc->stats->rx);
29937 cell += ATM_CELL_PAYLOAD;
29938 }
29939
29940@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29941 if (iovb == NULL)
29942 {
29943 printk("nicstar%d: Out of iovec buffers.\n", card->index);
29944- atomic_inc(&vcc->stats->rx_drop);
29945+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29946 recycle_rx_buf(card, skb);
29947 return;
29948 }
29949@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29950 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
29951 {
29952 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29953- atomic_inc(&vcc->stats->rx_err);
29954+ atomic_inc_unchecked(&vcc->stats->rx_err);
29955 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
29956 NS_SKB(iovb)->iovcnt = 0;
29957 iovb->len = 0;
29958@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29959 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
29960 card->index);
29961 which_list(card, skb);
29962- atomic_inc(&vcc->stats->rx_err);
29963+ atomic_inc_unchecked(&vcc->stats->rx_err);
29964 recycle_rx_buf(card, skb);
29965 vc->rx_iov = NULL;
29966 recycle_iov_buf(card, iovb);
29967@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29968 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
29969 card->index);
29970 which_list(card, skb);
29971- atomic_inc(&vcc->stats->rx_err);
29972+ atomic_inc_unchecked(&vcc->stats->rx_err);
29973 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
29974 NS_SKB(iovb)->iovcnt);
29975 vc->rx_iov = NULL;
29976@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29977 printk(" - PDU size mismatch.\n");
29978 else
29979 printk(".\n");
29980- atomic_inc(&vcc->stats->rx_err);
29981+ atomic_inc_unchecked(&vcc->stats->rx_err);
29982 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
29983 NS_SKB(iovb)->iovcnt);
29984 vc->rx_iov = NULL;
29985@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29986 if (!atm_charge(vcc, skb->truesize))
29987 {
29988 push_rxbufs(card, skb);
29989- atomic_inc(&vcc->stats->rx_drop);
29990+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29991 }
29992 else
29993 {
29994@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29995 ATM_SKB(skb)->vcc = vcc;
29996 __net_timestamp(skb);
29997 vcc->push(vcc, skb);
29998- atomic_inc(&vcc->stats->rx);
29999+ atomic_inc_unchecked(&vcc->stats->rx);
30000 }
30001 }
30002 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
30003@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30004 if (!atm_charge(vcc, sb->truesize))
30005 {
30006 push_rxbufs(card, sb);
30007- atomic_inc(&vcc->stats->rx_drop);
30008+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30009 }
30010 else
30011 {
30012@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30013 ATM_SKB(sb)->vcc = vcc;
30014 __net_timestamp(sb);
30015 vcc->push(vcc, sb);
30016- atomic_inc(&vcc->stats->rx);
30017+ atomic_inc_unchecked(&vcc->stats->rx);
30018 }
30019
30020 push_rxbufs(card, skb);
30021@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30022 if (!atm_charge(vcc, skb->truesize))
30023 {
30024 push_rxbufs(card, skb);
30025- atomic_inc(&vcc->stats->rx_drop);
30026+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30027 }
30028 else
30029 {
30030@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30031 ATM_SKB(skb)->vcc = vcc;
30032 __net_timestamp(skb);
30033 vcc->push(vcc, skb);
30034- atomic_inc(&vcc->stats->rx);
30035+ atomic_inc_unchecked(&vcc->stats->rx);
30036 }
30037
30038 push_rxbufs(card, sb);
30039@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30040 if (hb == NULL)
30041 {
30042 printk("nicstar%d: Out of huge buffers.\n", card->index);
30043- atomic_inc(&vcc->stats->rx_drop);
30044+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30045 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30046 NS_SKB(iovb)->iovcnt);
30047 vc->rx_iov = NULL;
30048@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30049 }
30050 else
30051 dev_kfree_skb_any(hb);
30052- atomic_inc(&vcc->stats->rx_drop);
30053+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30054 }
30055 else
30056 {
30057@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30058 #endif /* NS_USE_DESTRUCTORS */
30059 __net_timestamp(hb);
30060 vcc->push(vcc, hb);
30061- atomic_inc(&vcc->stats->rx);
30062+ atomic_inc_unchecked(&vcc->stats->rx);
30063 }
30064 }
30065
30066diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30067index 84c93ff..e6ed269 100644
30068--- a/drivers/atm/solos-pci.c
30069+++ b/drivers/atm/solos-pci.c
30070@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
30071 }
30072 atm_charge(vcc, skb->truesize);
30073 vcc->push(vcc, skb);
30074- atomic_inc(&vcc->stats->rx);
30075+ atomic_inc_unchecked(&vcc->stats->rx);
30076 break;
30077
30078 case PKT_STATUS:
30079@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *buf)
30080 char msg[500];
30081 char item[10];
30082
30083+ pax_track_stack();
30084+
30085 len = buf->len;
30086 for (i = 0; i < len; i++){
30087 if(i % 8 == 0)
30088@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30089 vcc = SKB_CB(oldskb)->vcc;
30090
30091 if (vcc) {
30092- atomic_inc(&vcc->stats->tx);
30093+ atomic_inc_unchecked(&vcc->stats->tx);
30094 solos_pop(vcc, oldskb);
30095 } else
30096 dev_kfree_skb_irq(oldskb);
30097diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30098index 6dd3f59..ee377f3 100644
30099--- a/drivers/atm/suni.c
30100+++ b/drivers/atm/suni.c
30101@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30102
30103
30104 #define ADD_LIMITED(s,v) \
30105- atomic_add((v),&stats->s); \
30106- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30107+ atomic_add_unchecked((v),&stats->s); \
30108+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30109
30110
30111 static void suni_hz(unsigned long from_timer)
30112diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30113index fc8cb07..4a80e53 100644
30114--- a/drivers/atm/uPD98402.c
30115+++ b/drivers/atm/uPD98402.c
30116@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30117 struct sonet_stats tmp;
30118 int error = 0;
30119
30120- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30121+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30122 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30123 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30124 if (zero && !error) {
30125@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30126
30127
30128 #define ADD_LIMITED(s,v) \
30129- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30130- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30131- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30132+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30133+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30134+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30135
30136
30137 static void stat_event(struct atm_dev *dev)
30138@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev *dev)
30139 if (reason & uPD98402_INT_PFM) stat_event(dev);
30140 if (reason & uPD98402_INT_PCO) {
30141 (void) GET(PCOCR); /* clear interrupt cause */
30142- atomic_add(GET(HECCT),
30143+ atomic_add_unchecked(GET(HECCT),
30144 &PRIV(dev)->sonet_stats.uncorr_hcs);
30145 }
30146 if ((reason & uPD98402_INT_RFO) &&
30147@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev *dev)
30148 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30149 uPD98402_INT_LOS),PIMR); /* enable them */
30150 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30151- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30152- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30153- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30154+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30155+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30156+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30157 return 0;
30158 }
30159
30160diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30161index 2e9635b..32927b4 100644
30162--- a/drivers/atm/zatm.c
30163+++ b/drivers/atm/zatm.c
30164@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30165 }
30166 if (!size) {
30167 dev_kfree_skb_irq(skb);
30168- if (vcc) atomic_inc(&vcc->stats->rx_err);
30169+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30170 continue;
30171 }
30172 if (!atm_charge(vcc,skb->truesize)) {
30173@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30174 skb->len = size;
30175 ATM_SKB(skb)->vcc = vcc;
30176 vcc->push(vcc,skb);
30177- atomic_inc(&vcc->stats->rx);
30178+ atomic_inc_unchecked(&vcc->stats->rx);
30179 }
30180 zout(pos & 0xffff,MTA(mbx));
30181 #if 0 /* probably a stupid idea */
30182@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30183 skb_queue_head(&zatm_vcc->backlog,skb);
30184 break;
30185 }
30186- atomic_inc(&vcc->stats->tx);
30187+ atomic_inc_unchecked(&vcc->stats->tx);
30188 wake_up(&zatm_vcc->tx_wait);
30189 }
30190
30191diff --git a/drivers/base/bus.c b/drivers/base/bus.c
30192index 63c143e..fece183 100644
30193--- a/drivers/base/bus.c
30194+++ b/drivers/base/bus.c
30195@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
30196 return ret;
30197 }
30198
30199-static struct sysfs_ops driver_sysfs_ops = {
30200+static const struct sysfs_ops driver_sysfs_ops = {
30201 .show = drv_attr_show,
30202 .store = drv_attr_store,
30203 };
30204@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
30205 return ret;
30206 }
30207
30208-static struct sysfs_ops bus_sysfs_ops = {
30209+static const struct sysfs_ops bus_sysfs_ops = {
30210 .show = bus_attr_show,
30211 .store = bus_attr_store,
30212 };
30213@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
30214 return 0;
30215 }
30216
30217-static struct kset_uevent_ops bus_uevent_ops = {
30218+static const struct kset_uevent_ops bus_uevent_ops = {
30219 .filter = bus_uevent_filter,
30220 };
30221
30222diff --git a/drivers/base/class.c b/drivers/base/class.c
30223index 6e2c3b0..cb61871 100644
30224--- a/drivers/base/class.c
30225+++ b/drivers/base/class.c
30226@@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj)
30227 kfree(cp);
30228 }
30229
30230-static struct sysfs_ops class_sysfs_ops = {
30231+static const struct sysfs_ops class_sysfs_ops = {
30232 .show = class_attr_show,
30233 .store = class_attr_store,
30234 };
30235diff --git a/drivers/base/core.c b/drivers/base/core.c
30236index f33d768..a9358d0 100644
30237--- a/drivers/base/core.c
30238+++ b/drivers/base/core.c
30239@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
30240 return ret;
30241 }
30242
30243-static struct sysfs_ops dev_sysfs_ops = {
30244+static const struct sysfs_ops dev_sysfs_ops = {
30245 .show = dev_attr_show,
30246 .store = dev_attr_store,
30247 };
30248@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
30249 return retval;
30250 }
30251
30252-static struct kset_uevent_ops device_uevent_ops = {
30253+static const struct kset_uevent_ops device_uevent_ops = {
30254 .filter = dev_uevent_filter,
30255 .name = dev_uevent_name,
30256 .uevent = dev_uevent,
30257diff --git a/drivers/base/memory.c b/drivers/base/memory.c
30258index 989429c..2272b00 100644
30259--- a/drivers/base/memory.c
30260+++ b/drivers/base/memory.c
30261@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
30262 return retval;
30263 }
30264
30265-static struct kset_uevent_ops memory_uevent_ops = {
30266+static const struct kset_uevent_ops memory_uevent_ops = {
30267 .name = memory_uevent_name,
30268 .uevent = memory_uevent,
30269 };
30270diff --git a/drivers/base/sys.c b/drivers/base/sys.c
30271index 3f202f7..61c4a6f 100644
30272--- a/drivers/base/sys.c
30273+++ b/drivers/base/sys.c
30274@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr,
30275 return -EIO;
30276 }
30277
30278-static struct sysfs_ops sysfs_ops = {
30279+static const struct sysfs_ops sysfs_ops = {
30280 .show = sysdev_show,
30281 .store = sysdev_store,
30282 };
30283@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
30284 return -EIO;
30285 }
30286
30287-static struct sysfs_ops sysfs_class_ops = {
30288+static const struct sysfs_ops sysfs_class_ops = {
30289 .show = sysdev_class_show,
30290 .store = sysdev_class_store,
30291 };
30292diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
30293index eb4fa19..1954777 100644
30294--- a/drivers/block/DAC960.c
30295+++ b/drivers/block/DAC960.c
30296@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
30297 unsigned long flags;
30298 int Channel, TargetID;
30299
30300+ pax_track_stack();
30301+
30302 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
30303 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
30304 sizeof(DAC960_SCSI_Inquiry_T) +
30305diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30306index ca9c548..ca6899c 100644
30307--- a/drivers/block/cciss.c
30308+++ b/drivers/block/cciss.c
30309@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30310 int err;
30311 u32 cp;
30312
30313+ memset(&arg64, 0, sizeof(arg64));
30314+
30315 err = 0;
30316 err |=
30317 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30318@@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ctlr)
30319 /* Wait (up to 20 seconds) for a command to complete */
30320
30321 for (i = 20 * HZ; i > 0; i--) {
30322- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30323+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30324 if (done == FIFO_EMPTY)
30325 schedule_timeout_uninterruptible(1);
30326 else
30327@@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
30328 resend_cmd1:
30329
30330 /* Disable interrupt on the board. */
30331- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30332+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30333
30334 /* Make sure there is room in the command FIFO */
30335 /* Actually it should be completely empty at this time */
30336@@ -2884,13 +2886,13 @@ resend_cmd1:
30337 /* tape side of the driver. */
30338 for (i = 200000; i > 0; i--) {
30339 /* if fifo isn't full go */
30340- if (!(h->access.fifo_full(h)))
30341+ if (!(h->access->fifo_full(h)))
30342 break;
30343 udelay(10);
30344 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
30345 " waiting!\n", h->ctlr);
30346 }
30347- h->access.submit_command(h, c); /* Send the cmd */
30348+ h->access->submit_command(h, c); /* Send the cmd */
30349 do {
30350 complete = pollcomplete(h->ctlr);
30351
30352@@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
30353 while (!hlist_empty(&h->reqQ)) {
30354 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
30355 /* can't do anything if fifo is full */
30356- if ((h->access.fifo_full(h))) {
30357+ if ((h->access->fifo_full(h))) {
30358 printk(KERN_WARNING "cciss: fifo full\n");
30359 break;
30360 }
30361@@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
30362 h->Qdepth--;
30363
30364 /* Tell the controller execute command */
30365- h->access.submit_command(h, c);
30366+ h->access->submit_command(h, c);
30367
30368 /* Put job onto the completed Q */
30369 addQ(&h->cmpQ, c);
30370@@ -3393,17 +3395,17 @@ startio:
30371
30372 static inline unsigned long get_next_completion(ctlr_info_t *h)
30373 {
30374- return h->access.command_completed(h);
30375+ return h->access->command_completed(h);
30376 }
30377
30378 static inline int interrupt_pending(ctlr_info_t *h)
30379 {
30380- return h->access.intr_pending(h);
30381+ return h->access->intr_pending(h);
30382 }
30383
30384 static inline long interrupt_not_for_us(ctlr_info_t *h)
30385 {
30386- return (((h->access.intr_pending(h) == 0) ||
30387+ return (((h->access->intr_pending(h) == 0) ||
30388 (h->interrupts_enabled == 0)));
30389 }
30390
30391@@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
30392 */
30393 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
30394 c->product_name = products[prod_index].product_name;
30395- c->access = *(products[prod_index].access);
30396+ c->access = products[prod_index].access;
30397 c->nr_cmds = c->max_commands - 4;
30398 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
30399 (readb(&c->cfgtable->Signature[1]) != 'I') ||
30400@@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30401 }
30402
30403 /* make sure the board interrupts are off */
30404- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
30405+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
30406 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
30407 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
30408 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
30409@@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30410 cciss_scsi_setup(i);
30411
30412 /* Turn the interrupts on so we can service requests */
30413- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
30414+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
30415
30416 /* Get the firmware version */
30417 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30418diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30419index 04d6bf8..36e712d 100644
30420--- a/drivers/block/cciss.h
30421+++ b/drivers/block/cciss.h
30422@@ -90,7 +90,7 @@ struct ctlr_info
30423 // information about each logical volume
30424 drive_info_struct *drv[CISS_MAX_LUN];
30425
30426- struct access_method access;
30427+ struct access_method *access;
30428
30429 /* queue and queue Info */
30430 struct hlist_head reqQ;
30431diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30432index 6422651..bb1bdef 100644
30433--- a/drivers/block/cpqarray.c
30434+++ b/drivers/block/cpqarray.c
30435@@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30436 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30437 goto Enomem4;
30438 }
30439- hba[i]->access.set_intr_mask(hba[i], 0);
30440+ hba[i]->access->set_intr_mask(hba[i], 0);
30441 if (request_irq(hba[i]->intr, do_ida_intr,
30442 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30443 {
30444@@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30445 add_timer(&hba[i]->timer);
30446
30447 /* Enable IRQ now that spinlock and rate limit timer are set up */
30448- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30449+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30450
30451 for(j=0; j<NWD; j++) {
30452 struct gendisk *disk = ida_gendisk[i][j];
30453@@ -695,7 +695,7 @@ DBGINFO(
30454 for(i=0; i<NR_PRODUCTS; i++) {
30455 if (board_id == products[i].board_id) {
30456 c->product_name = products[i].product_name;
30457- c->access = *(products[i].access);
30458+ c->access = products[i].access;
30459 break;
30460 }
30461 }
30462@@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(void)
30463 hba[ctlr]->intr = intr;
30464 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30465 hba[ctlr]->product_name = products[j].product_name;
30466- hba[ctlr]->access = *(products[j].access);
30467+ hba[ctlr]->access = products[j].access;
30468 hba[ctlr]->ctlr = ctlr;
30469 hba[ctlr]->board_id = board_id;
30470 hba[ctlr]->pci_dev = NULL; /* not PCI */
30471@@ -896,6 +896,8 @@ static void do_ida_request(struct request_queue *q)
30472 struct scatterlist tmp_sg[SG_MAX];
30473 int i, dir, seg;
30474
30475+ pax_track_stack();
30476+
30477 if (blk_queue_plugged(q))
30478 goto startio;
30479
30480@@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
30481
30482 while((c = h->reqQ) != NULL) {
30483 /* Can't do anything if we're busy */
30484- if (h->access.fifo_full(h) == 0)
30485+ if (h->access->fifo_full(h) == 0)
30486 return;
30487
30488 /* Get the first entry from the request Q */
30489@@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
30490 h->Qdepth--;
30491
30492 /* Tell the controller to do our bidding */
30493- h->access.submit_command(h, c);
30494+ h->access->submit_command(h, c);
30495
30496 /* Get onto the completion Q */
30497 addQ(&h->cmpQ, c);
30498@@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30499 unsigned long flags;
30500 __u32 a,a1;
30501
30502- istat = h->access.intr_pending(h);
30503+ istat = h->access->intr_pending(h);
30504 /* Is this interrupt for us? */
30505 if (istat == 0)
30506 return IRQ_NONE;
30507@@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30508 */
30509 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30510 if (istat & FIFO_NOT_EMPTY) {
30511- while((a = h->access.command_completed(h))) {
30512+ while((a = h->access->command_completed(h))) {
30513 a1 = a; a &= ~3;
30514 if ((c = h->cmpQ) == NULL)
30515 {
30516@@ -1434,11 +1436,11 @@ static int sendcmd(
30517 /*
30518 * Disable interrupt
30519 */
30520- info_p->access.set_intr_mask(info_p, 0);
30521+ info_p->access->set_intr_mask(info_p, 0);
30522 /* Make sure there is room in the command FIFO */
30523 /* Actually it should be completely empty at this time. */
30524 for (i = 200000; i > 0; i--) {
30525- temp = info_p->access.fifo_full(info_p);
30526+ temp = info_p->access->fifo_full(info_p);
30527 if (temp != 0) {
30528 break;
30529 }
30530@@ -1451,7 +1453,7 @@ DBG(
30531 /*
30532 * Send the cmd
30533 */
30534- info_p->access.submit_command(info_p, c);
30535+ info_p->access->submit_command(info_p, c);
30536 complete = pollcomplete(ctlr);
30537
30538 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
30539@@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t *host)
30540 * we check the new geometry. Then turn interrupts back on when
30541 * we're done.
30542 */
30543- host->access.set_intr_mask(host, 0);
30544+ host->access->set_intr_mask(host, 0);
30545 getgeometry(ctlr);
30546- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
30547+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
30548
30549 for(i=0; i<NWD; i++) {
30550 struct gendisk *disk = ida_gendisk[ctlr][i];
30551@@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
30552 /* Wait (up to 2 seconds) for a command to complete */
30553
30554 for (i = 200000; i > 0; i--) {
30555- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30556+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30557 if (done == 0) {
30558 udelay(10); /* a short fixed delay */
30559 } else
30560diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
30561index be73e9d..7fbf140 100644
30562--- a/drivers/block/cpqarray.h
30563+++ b/drivers/block/cpqarray.h
30564@@ -99,7 +99,7 @@ struct ctlr_info {
30565 drv_info_t drv[NWD];
30566 struct proc_dir_entry *proc;
30567
30568- struct access_method access;
30569+ struct access_method *access;
30570
30571 cmdlist_t *reqQ;
30572 cmdlist_t *cmpQ;
30573diff --git a/drivers/block/loop.c b/drivers/block/loop.c
30574index 8ec2d70..2804b30 100644
30575--- a/drivers/block/loop.c
30576+++ b/drivers/block/loop.c
30577@@ -282,7 +282,7 @@ static int __do_lo_send_write(struct file *file,
30578 mm_segment_t old_fs = get_fs();
30579
30580 set_fs(get_ds());
30581- bw = file->f_op->write(file, buf, len, &pos);
30582+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
30583 set_fs(old_fs);
30584 if (likely(bw == len))
30585 return 0;
30586diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
30587index 26ada47..083c480 100644
30588--- a/drivers/block/nbd.c
30589+++ b/drivers/block/nbd.c
30590@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
30591 struct kvec iov;
30592 sigset_t blocked, oldset;
30593
30594+ pax_track_stack();
30595+
30596 if (unlikely(!sock)) {
30597 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
30598 lo->disk->disk_name, (send ? "send" : "recv"));
30599@@ -569,6 +571,8 @@ static void do_nbd_request(struct request_queue *q)
30600 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
30601 unsigned int cmd, unsigned long arg)
30602 {
30603+ pax_track_stack();
30604+
30605 switch (cmd) {
30606 case NBD_DISCONNECT: {
30607 struct request sreq;
30608diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
30609index a5d585d..d087be3 100644
30610--- a/drivers/block/pktcdvd.c
30611+++ b/drivers/block/pktcdvd.c
30612@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
30613 return len;
30614 }
30615
30616-static struct sysfs_ops kobj_pkt_ops = {
30617+static const struct sysfs_ops kobj_pkt_ops = {
30618 .show = kobj_pkt_show,
30619 .store = kobj_pkt_store
30620 };
30621diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
30622index 6aad99e..89cd142 100644
30623--- a/drivers/char/Kconfig
30624+++ b/drivers/char/Kconfig
30625@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
30626
30627 config DEVKMEM
30628 bool "/dev/kmem virtual device support"
30629- default y
30630+ default n
30631+ depends on !GRKERNSEC_KMEM
30632 help
30633 Say Y here if you want to support the /dev/kmem device. The
30634 /dev/kmem device is rarely used, but can be used for certain
30635@@ -1114,6 +1115,7 @@ config DEVPORT
30636 bool
30637 depends on !M68K
30638 depends on ISA || PCI
30639+ depends on !GRKERNSEC_KMEM
30640 default y
30641
30642 source "drivers/s390/char/Kconfig"
30643diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
30644index a96f319..a778a5b 100644
30645--- a/drivers/char/agp/frontend.c
30646+++ b/drivers/char/agp/frontend.c
30647@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
30648 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
30649 return -EFAULT;
30650
30651- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
30652+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
30653 return -EFAULT;
30654
30655 client = agp_find_client_by_pid(reserve.pid);
30656diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
30657index d8cff90..9628e70 100644
30658--- a/drivers/char/briq_panel.c
30659+++ b/drivers/char/briq_panel.c
30660@@ -10,6 +10,7 @@
30661 #include <linux/types.h>
30662 #include <linux/errno.h>
30663 #include <linux/tty.h>
30664+#include <linux/mutex.h>
30665 #include <linux/timer.h>
30666 #include <linux/kernel.h>
30667 #include <linux/wait.h>
30668@@ -36,6 +37,7 @@ static int vfd_is_open;
30669 static unsigned char vfd[40];
30670 static int vfd_cursor;
30671 static unsigned char ledpb, led;
30672+static DEFINE_MUTEX(vfd_mutex);
30673
30674 static void update_vfd(void)
30675 {
30676@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30677 if (!vfd_is_open)
30678 return -EBUSY;
30679
30680+ mutex_lock(&vfd_mutex);
30681 for (;;) {
30682 char c;
30683 if (!indx)
30684 break;
30685- if (get_user(c, buf))
30686+ if (get_user(c, buf)) {
30687+ mutex_unlock(&vfd_mutex);
30688 return -EFAULT;
30689+ }
30690 if (esc) {
30691 set_led(c);
30692 esc = 0;
30693@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30694 buf++;
30695 }
30696 update_vfd();
30697+ mutex_unlock(&vfd_mutex);
30698
30699 return len;
30700 }
30701diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
30702index 31e7c91..161afc0 100644
30703--- a/drivers/char/genrtc.c
30704+++ b/drivers/char/genrtc.c
30705@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
30706 switch (cmd) {
30707
30708 case RTC_PLL_GET:
30709+ memset(&pll, 0, sizeof(pll));
30710 if (get_rtc_pll(&pll))
30711 return -EINVAL;
30712 else
30713diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
30714index 006466d..a2bb21c 100644
30715--- a/drivers/char/hpet.c
30716+++ b/drivers/char/hpet.c
30717@@ -430,7 +430,7 @@ static int hpet_release(struct inode *inode, struct file *file)
30718 return 0;
30719 }
30720
30721-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
30722+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
30723
30724 static int
30725 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
30726@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
30727 }
30728
30729 static int
30730-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30731+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
30732 {
30733 struct hpet_timer __iomem *timer;
30734 struct hpet __iomem *hpet;
30735@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30736 {
30737 struct hpet_info info;
30738
30739+ memset(&info, 0, sizeof(info));
30740+
30741 if (devp->hd_ireqfreq)
30742 info.hi_ireqfreq =
30743 hpet_time_div(hpetp, devp->hd_ireqfreq);
30744- else
30745- info.hi_ireqfreq = 0;
30746 info.hi_flags =
30747 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
30748 info.hi_hpet = hpetp->hp_which;
30749diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c
30750index 0afc8b8..6913fc3 100644
30751--- a/drivers/char/hvc_beat.c
30752+++ b/drivers/char/hvc_beat.c
30753@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
30754 return cnt;
30755 }
30756
30757-static struct hv_ops hvc_beat_get_put_ops = {
30758+static const struct hv_ops hvc_beat_get_put_ops = {
30759 .get_chars = hvc_beat_get_chars,
30760 .put_chars = hvc_beat_put_chars,
30761 };
30762diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
30763index 98097f2..407dddc 100644
30764--- a/drivers/char/hvc_console.c
30765+++ b/drivers/char/hvc_console.c
30766@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
30767 * console interfaces but can still be used as a tty device. This has to be
30768 * static because kmalloc will not work during early console init.
30769 */
30770-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30771+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30772 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
30773 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
30774
30775@@ -249,7 +249,7 @@ static void destroy_hvc_struct(struct kref *kref)
30776 * vty adapters do NOT get an hvc_instantiate() callback since they
30777 * appear after early console init.
30778 */
30779-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
30780+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
30781 {
30782 struct hvc_struct *hp;
30783
30784@@ -758,7 +758,7 @@ static const struct tty_operations hvc_ops = {
30785 };
30786
30787 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
30788- struct hv_ops *ops, int outbuf_size)
30789+ const struct hv_ops *ops, int outbuf_size)
30790 {
30791 struct hvc_struct *hp;
30792 int i;
30793diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
30794index 10950ca..ed176c3 100644
30795--- a/drivers/char/hvc_console.h
30796+++ b/drivers/char/hvc_console.h
30797@@ -55,7 +55,7 @@ struct hvc_struct {
30798 int outbuf_size;
30799 int n_outbuf;
30800 uint32_t vtermno;
30801- struct hv_ops *ops;
30802+ const struct hv_ops *ops;
30803 int irq_requested;
30804 int data;
30805 struct winsize ws;
30806@@ -76,11 +76,11 @@ struct hv_ops {
30807 };
30808
30809 /* Register a vterm and a slot index for use as a console (console_init) */
30810-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
30811+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
30812
30813 /* register a vterm for hvc tty operation (module_init or hotplug add) */
30814 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
30815- struct hv_ops *ops, int outbuf_size);
30816+ const struct hv_ops *ops, int outbuf_size);
30817 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
30818 extern int hvc_remove(struct hvc_struct *hp);
30819
30820diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
30821index 936d05b..fd02426 100644
30822--- a/drivers/char/hvc_iseries.c
30823+++ b/drivers/char/hvc_iseries.c
30824@@ -197,7 +197,7 @@ done:
30825 return sent;
30826 }
30827
30828-static struct hv_ops hvc_get_put_ops = {
30829+static const struct hv_ops hvc_get_put_ops = {
30830 .get_chars = get_chars,
30831 .put_chars = put_chars,
30832 .notifier_add = notifier_add_irq,
30833diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
30834index b0e168f..69cda2a 100644
30835--- a/drivers/char/hvc_iucv.c
30836+++ b/drivers/char/hvc_iucv.c
30837@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
30838
30839
30840 /* HVC operations */
30841-static struct hv_ops hvc_iucv_ops = {
30842+static const struct hv_ops hvc_iucv_ops = {
30843 .get_chars = hvc_iucv_get_chars,
30844 .put_chars = hvc_iucv_put_chars,
30845 .notifier_add = hvc_iucv_notifier_add,
30846diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
30847index 88590d0..61c4a61 100644
30848--- a/drivers/char/hvc_rtas.c
30849+++ b/drivers/char/hvc_rtas.c
30850@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
30851 return i;
30852 }
30853
30854-static struct hv_ops hvc_rtas_get_put_ops = {
30855+static const struct hv_ops hvc_rtas_get_put_ops = {
30856 .get_chars = hvc_rtas_read_console,
30857 .put_chars = hvc_rtas_write_console,
30858 };
30859diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
30860index bd63ba8..b0957e6 100644
30861--- a/drivers/char/hvc_udbg.c
30862+++ b/drivers/char/hvc_udbg.c
30863@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
30864 return i;
30865 }
30866
30867-static struct hv_ops hvc_udbg_ops = {
30868+static const struct hv_ops hvc_udbg_ops = {
30869 .get_chars = hvc_udbg_get,
30870 .put_chars = hvc_udbg_put,
30871 };
30872diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
30873index 10be343..27370e9 100644
30874--- a/drivers/char/hvc_vio.c
30875+++ b/drivers/char/hvc_vio.c
30876@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
30877 return got;
30878 }
30879
30880-static struct hv_ops hvc_get_put_ops = {
30881+static const struct hv_ops hvc_get_put_ops = {
30882 .get_chars = filtered_get_chars,
30883 .put_chars = hvc_put_chars,
30884 .notifier_add = notifier_add_irq,
30885diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
30886index a6ee32b..94f8c26 100644
30887--- a/drivers/char/hvc_xen.c
30888+++ b/drivers/char/hvc_xen.c
30889@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
30890 return recv;
30891 }
30892
30893-static struct hv_ops hvc_ops = {
30894+static const struct hv_ops hvc_ops = {
30895 .get_chars = read_console,
30896 .put_chars = write_console,
30897 .notifier_add = notifier_add_irq,
30898diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
30899index 266b858..f3ee0bb 100644
30900--- a/drivers/char/hvcs.c
30901+++ b/drivers/char/hvcs.c
30902@@ -82,6 +82,7 @@
30903 #include <asm/hvcserver.h>
30904 #include <asm/uaccess.h>
30905 #include <asm/vio.h>
30906+#include <asm/local.h>
30907
30908 /*
30909 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
30910@@ -269,7 +270,7 @@ struct hvcs_struct {
30911 unsigned int index;
30912
30913 struct tty_struct *tty;
30914- int open_count;
30915+ local_t open_count;
30916
30917 /*
30918 * Used to tell the driver kernel_thread what operations need to take
30919@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
30920
30921 spin_lock_irqsave(&hvcsd->lock, flags);
30922
30923- if (hvcsd->open_count > 0) {
30924+ if (local_read(&hvcsd->open_count) > 0) {
30925 spin_unlock_irqrestore(&hvcsd->lock, flags);
30926 printk(KERN_INFO "HVCS: vterm state unchanged. "
30927 "The hvcs device node is still in use.\n");
30928@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
30929 if ((retval = hvcs_partner_connect(hvcsd)))
30930 goto error_release;
30931
30932- hvcsd->open_count = 1;
30933+ local_set(&hvcsd->open_count, 1);
30934 hvcsd->tty = tty;
30935 tty->driver_data = hvcsd;
30936
30937@@ -1169,7 +1170,7 @@ fast_open:
30938
30939 spin_lock_irqsave(&hvcsd->lock, flags);
30940 kref_get(&hvcsd->kref);
30941- hvcsd->open_count++;
30942+ local_inc(&hvcsd->open_count);
30943 hvcsd->todo_mask |= HVCS_SCHED_READ;
30944 spin_unlock_irqrestore(&hvcsd->lock, flags);
30945
30946@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
30947 hvcsd = tty->driver_data;
30948
30949 spin_lock_irqsave(&hvcsd->lock, flags);
30950- if (--hvcsd->open_count == 0) {
30951+ if (local_dec_and_test(&hvcsd->open_count)) {
30952
30953 vio_disable_interrupts(hvcsd->vdev);
30954
30955@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
30956 free_irq(irq, hvcsd);
30957 kref_put(&hvcsd->kref, destroy_hvcs_struct);
30958 return;
30959- } else if (hvcsd->open_count < 0) {
30960+ } else if (local_read(&hvcsd->open_count) < 0) {
30961 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
30962 " is missmanaged.\n",
30963- hvcsd->vdev->unit_address, hvcsd->open_count);
30964+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
30965 }
30966
30967 spin_unlock_irqrestore(&hvcsd->lock, flags);
30968@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struct * tty)
30969
30970 spin_lock_irqsave(&hvcsd->lock, flags);
30971 /* Preserve this so that we know how many kref refs to put */
30972- temp_open_count = hvcsd->open_count;
30973+ temp_open_count = local_read(&hvcsd->open_count);
30974
30975 /*
30976 * Don't kref put inside the spinlock because the destruction
30977@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struct * tty)
30978 hvcsd->tty->driver_data = NULL;
30979 hvcsd->tty = NULL;
30980
30981- hvcsd->open_count = 0;
30982+ local_set(&hvcsd->open_count, 0);
30983
30984 /* This will drop any buffered data on the floor which is OK in a hangup
30985 * scenario. */
30986@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct *tty,
30987 * the middle of a write operation? This is a crummy place to do this
30988 * but we want to keep it all in the spinlock.
30989 */
30990- if (hvcsd->open_count <= 0) {
30991+ if (local_read(&hvcsd->open_count) <= 0) {
30992 spin_unlock_irqrestore(&hvcsd->lock, flags);
30993 return -ENODEV;
30994 }
30995@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_struct *tty)
30996 {
30997 struct hvcs_struct *hvcsd = tty->driver_data;
30998
30999- if (!hvcsd || hvcsd->open_count <= 0)
31000+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
31001 return 0;
31002
31003 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
31004diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31005index ec5e3f8..02455ba 100644
31006--- a/drivers/char/ipmi/ipmi_msghandler.c
31007+++ b/drivers/char/ipmi/ipmi_msghandler.c
31008@@ -414,7 +414,7 @@ struct ipmi_smi {
31009 struct proc_dir_entry *proc_dir;
31010 char proc_dir_name[10];
31011
31012- atomic_t stats[IPMI_NUM_STATS];
31013+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31014
31015 /*
31016 * run_to_completion duplicate of smb_info, smi_info
31017@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31018
31019
31020 #define ipmi_inc_stat(intf, stat) \
31021- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31022+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31023 #define ipmi_get_stat(intf, stat) \
31024- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31025+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31026
31027 static int is_lan_addr(struct ipmi_addr *addr)
31028 {
31029@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31030 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31031 init_waitqueue_head(&intf->waitq);
31032 for (i = 0; i < IPMI_NUM_STATS; i++)
31033- atomic_set(&intf->stats[i], 0);
31034+ atomic_set_unchecked(&intf->stats[i], 0);
31035
31036 intf->proc_dir = NULL;
31037
31038@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
31039 struct ipmi_smi_msg smi_msg;
31040 struct ipmi_recv_msg recv_msg;
31041
31042+ pax_track_stack();
31043+
31044 si = (struct ipmi_system_interface_addr *) &addr;
31045 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
31046 si->channel = IPMI_BMC_CHANNEL;
31047diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31048index abae8c9..8021979 100644
31049--- a/drivers/char/ipmi/ipmi_si_intf.c
31050+++ b/drivers/char/ipmi/ipmi_si_intf.c
31051@@ -277,7 +277,7 @@ struct smi_info {
31052 unsigned char slave_addr;
31053
31054 /* Counters and things for the proc filesystem. */
31055- atomic_t stats[SI_NUM_STATS];
31056+ atomic_unchecked_t stats[SI_NUM_STATS];
31057
31058 struct task_struct *thread;
31059
31060@@ -285,9 +285,9 @@ struct smi_info {
31061 };
31062
31063 #define smi_inc_stat(smi, stat) \
31064- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31065+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31066 #define smi_get_stat(smi, stat) \
31067- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31068+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31069
31070 #define SI_MAX_PARMS 4
31071
31072@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info *new_smi)
31073 atomic_set(&new_smi->req_events, 0);
31074 new_smi->run_to_completion = 0;
31075 for (i = 0; i < SI_NUM_STATS; i++)
31076- atomic_set(&new_smi->stats[i], 0);
31077+ atomic_set_unchecked(&new_smi->stats[i], 0);
31078
31079 new_smi->interrupt_disabled = 0;
31080 atomic_set(&new_smi->stop_operation, 0);
31081diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
31082index 402838f..55e2200 100644
31083--- a/drivers/char/istallion.c
31084+++ b/drivers/char/istallion.c
31085@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios = {
31086 * re-used for each stats call.
31087 */
31088 static comstats_t stli_comstats;
31089-static combrd_t stli_brdstats;
31090 static struct asystats stli_cdkstats;
31091
31092 /*****************************************************************************/
31093@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
31094 {
31095 struct stlibrd *brdp;
31096 unsigned int i;
31097+ combrd_t stli_brdstats;
31098
31099 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
31100 return -EFAULT;
31101@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stliport __user *arg)
31102 struct stliport stli_dummyport;
31103 struct stliport *portp;
31104
31105+ pax_track_stack();
31106+
31107 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
31108 return -EFAULT;
31109 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
31110@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stlibrd __user *arg)
31111 struct stlibrd stli_dummybrd;
31112 struct stlibrd *brdp;
31113
31114+ pax_track_stack();
31115+
31116 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
31117 return -EFAULT;
31118 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
31119diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
31120index 950837c..e55a288 100644
31121--- a/drivers/char/keyboard.c
31122+++ b/drivers/char/keyboard.c
31123@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
31124 kbd->kbdmode == VC_MEDIUMRAW) &&
31125 value != KVAL(K_SAK))
31126 return; /* SAK is allowed even in raw mode */
31127+
31128+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
31129+ {
31130+ void *func = fn_handler[value];
31131+ if (func == fn_show_state || func == fn_show_ptregs ||
31132+ func == fn_show_mem)
31133+ return;
31134+ }
31135+#endif
31136+
31137 fn_handler[value](vc);
31138 }
31139
31140@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_ids[] = {
31141 .evbit = { BIT_MASK(EV_SND) },
31142 },
31143
31144- { }, /* Terminating entry */
31145+ { 0 }, /* Terminating entry */
31146 };
31147
31148 MODULE_DEVICE_TABLE(input, kbd_ids);
31149diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
31150index 87c67b4..230527a 100644
31151--- a/drivers/char/mbcs.c
31152+++ b/drivers/char/mbcs.c
31153@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
31154 return 0;
31155 }
31156
31157-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
31158+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
31159 {
31160 .part_num = MBCS_PART_NUM,
31161 .mfg_num = MBCS_MFG_NUM,
31162diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31163index 1270f64..8495f49 100644
31164--- a/drivers/char/mem.c
31165+++ b/drivers/char/mem.c
31166@@ -18,6 +18,7 @@
31167 #include <linux/raw.h>
31168 #include <linux/tty.h>
31169 #include <linux/capability.h>
31170+#include <linux/security.h>
31171 #include <linux/ptrace.h>
31172 #include <linux/device.h>
31173 #include <linux/highmem.h>
31174@@ -35,6 +36,10 @@
31175 # include <linux/efi.h>
31176 #endif
31177
31178+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31179+extern struct file_operations grsec_fops;
31180+#endif
31181+
31182 static inline unsigned long size_inside_page(unsigned long start,
31183 unsigned long size)
31184 {
31185@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31186
31187 while (cursor < to) {
31188 if (!devmem_is_allowed(pfn)) {
31189+#ifdef CONFIG_GRKERNSEC_KMEM
31190+ gr_handle_mem_readwrite(from, to);
31191+#else
31192 printk(KERN_INFO
31193 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31194 current->comm, from, to);
31195+#endif
31196 return 0;
31197 }
31198 cursor += PAGE_SIZE;
31199@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31200 }
31201 return 1;
31202 }
31203+#elif defined(CONFIG_GRKERNSEC_KMEM)
31204+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31205+{
31206+ return 0;
31207+}
31208 #else
31209 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31210 {
31211@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31212 #endif
31213
31214 while (count > 0) {
31215+ char *temp;
31216+
31217 /*
31218 * Handle first page in case it's not aligned
31219 */
31220@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31221 if (!ptr)
31222 return -EFAULT;
31223
31224- if (copy_to_user(buf, ptr, sz)) {
31225+#ifdef CONFIG_PAX_USERCOPY
31226+ temp = kmalloc(sz, GFP_KERNEL);
31227+ if (!temp) {
31228+ unxlate_dev_mem_ptr(p, ptr);
31229+ return -ENOMEM;
31230+ }
31231+ memcpy(temp, ptr, sz);
31232+#else
31233+ temp = ptr;
31234+#endif
31235+
31236+ if (copy_to_user(buf, temp, sz)) {
31237+
31238+#ifdef CONFIG_PAX_USERCOPY
31239+ kfree(temp);
31240+#endif
31241+
31242 unxlate_dev_mem_ptr(p, ptr);
31243 return -EFAULT;
31244 }
31245
31246+#ifdef CONFIG_PAX_USERCOPY
31247+ kfree(temp);
31248+#endif
31249+
31250 unxlate_dev_mem_ptr(p, ptr);
31251
31252 buf += sz;
31253@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31254 size_t count, loff_t *ppos)
31255 {
31256 unsigned long p = *ppos;
31257- ssize_t low_count, read, sz;
31258+ ssize_t low_count, read, sz, err = 0;
31259 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31260- int err = 0;
31261
31262 read = 0;
31263 if (p < (unsigned long) high_memory) {
31264@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31265 }
31266 #endif
31267 while (low_count > 0) {
31268+ char *temp;
31269+
31270 sz = size_inside_page(p, low_count);
31271
31272 /*
31273@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31274 */
31275 kbuf = xlate_dev_kmem_ptr((char *)p);
31276
31277- if (copy_to_user(buf, kbuf, sz))
31278+#ifdef CONFIG_PAX_USERCOPY
31279+ temp = kmalloc(sz, GFP_KERNEL);
31280+ if (!temp)
31281+ return -ENOMEM;
31282+ memcpy(temp, kbuf, sz);
31283+#else
31284+ temp = kbuf;
31285+#endif
31286+
31287+ err = copy_to_user(buf, temp, sz);
31288+
31289+#ifdef CONFIG_PAX_USERCOPY
31290+ kfree(temp);
31291+#endif
31292+
31293+ if (err)
31294 return -EFAULT;
31295 buf += sz;
31296 p += sz;
31297@@ -889,6 +941,9 @@ static const struct memdev {
31298 #ifdef CONFIG_CRASH_DUMP
31299 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31300 #endif
31301+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31302+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31303+#endif
31304 };
31305
31306 static int memory_open(struct inode *inode, struct file *filp)
31307diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
31308index 674b3ab..a8d1970 100644
31309--- a/drivers/char/pcmcia/ipwireless/tty.c
31310+++ b/drivers/char/pcmcia/ipwireless/tty.c
31311@@ -29,6 +29,7 @@
31312 #include <linux/tty_driver.h>
31313 #include <linux/tty_flip.h>
31314 #include <linux/uaccess.h>
31315+#include <asm/local.h>
31316
31317 #include "tty.h"
31318 #include "network.h"
31319@@ -51,7 +52,7 @@ struct ipw_tty {
31320 int tty_type;
31321 struct ipw_network *network;
31322 struct tty_struct *linux_tty;
31323- int open_count;
31324+ local_t open_count;
31325 unsigned int control_lines;
31326 struct mutex ipw_tty_mutex;
31327 int tx_bytes_queued;
31328@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31329 mutex_unlock(&tty->ipw_tty_mutex);
31330 return -ENODEV;
31331 }
31332- if (tty->open_count == 0)
31333+ if (local_read(&tty->open_count) == 0)
31334 tty->tx_bytes_queued = 0;
31335
31336- tty->open_count++;
31337+ local_inc(&tty->open_count);
31338
31339 tty->linux_tty = linux_tty;
31340 linux_tty->driver_data = tty;
31341@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31342
31343 static void do_ipw_close(struct ipw_tty *tty)
31344 {
31345- tty->open_count--;
31346-
31347- if (tty->open_count == 0) {
31348+ if (local_dec_return(&tty->open_count) == 0) {
31349 struct tty_struct *linux_tty = tty->linux_tty;
31350
31351 if (linux_tty != NULL) {
31352@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
31353 return;
31354
31355 mutex_lock(&tty->ipw_tty_mutex);
31356- if (tty->open_count == 0) {
31357+ if (local_read(&tty->open_count) == 0) {
31358 mutex_unlock(&tty->ipw_tty_mutex);
31359 return;
31360 }
31361@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
31362 return;
31363 }
31364
31365- if (!tty->open_count) {
31366+ if (!local_read(&tty->open_count)) {
31367 mutex_unlock(&tty->ipw_tty_mutex);
31368 return;
31369 }
31370@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
31371 return -ENODEV;
31372
31373 mutex_lock(&tty->ipw_tty_mutex);
31374- if (!tty->open_count) {
31375+ if (!local_read(&tty->open_count)) {
31376 mutex_unlock(&tty->ipw_tty_mutex);
31377 return -EINVAL;
31378 }
31379@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
31380 if (!tty)
31381 return -ENODEV;
31382
31383- if (!tty->open_count)
31384+ if (!local_read(&tty->open_count))
31385 return -EINVAL;
31386
31387 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
31388@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
31389 if (!tty)
31390 return 0;
31391
31392- if (!tty->open_count)
31393+ if (!local_read(&tty->open_count))
31394 return 0;
31395
31396 return tty->tx_bytes_queued;
31397@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
31398 if (!tty)
31399 return -ENODEV;
31400
31401- if (!tty->open_count)
31402+ if (!local_read(&tty->open_count))
31403 return -EINVAL;
31404
31405 return get_control_lines(tty);
31406@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
31407 if (!tty)
31408 return -ENODEV;
31409
31410- if (!tty->open_count)
31411+ if (!local_read(&tty->open_count))
31412 return -EINVAL;
31413
31414 return set_control_lines(tty, set, clear);
31415@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
31416 if (!tty)
31417 return -ENODEV;
31418
31419- if (!tty->open_count)
31420+ if (!local_read(&tty->open_count))
31421 return -EINVAL;
31422
31423 /* FIXME: Exactly how is the tty object locked here .. */
31424@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
31425 against a parallel ioctl etc */
31426 mutex_lock(&ttyj->ipw_tty_mutex);
31427 }
31428- while (ttyj->open_count)
31429+ while (local_read(&ttyj->open_count))
31430 do_ipw_close(ttyj);
31431 ipwireless_disassociate_network_ttys(network,
31432 ttyj->channel_idx);
31433diff --git a/drivers/char/pty.c b/drivers/char/pty.c
31434index 62f282e..e45c45c 100644
31435--- a/drivers/char/pty.c
31436+++ b/drivers/char/pty.c
31437@@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
31438 register_sysctl_table(pty_root_table);
31439
31440 /* Now create the /dev/ptmx special device */
31441+ pax_open_kernel();
31442 tty_default_fops(&ptmx_fops);
31443- ptmx_fops.open = ptmx_open;
31444+ *(void **)&ptmx_fops.open = ptmx_open;
31445+ pax_close_kernel();
31446
31447 cdev_init(&ptmx_cdev, &ptmx_fops);
31448 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
31449diff --git a/drivers/char/random.c b/drivers/char/random.c
31450index 3a19e2d..6ed09d3 100644
31451--- a/drivers/char/random.c
31452+++ b/drivers/char/random.c
31453@@ -254,8 +254,13 @@
31454 /*
31455 * Configuration information
31456 */
31457+#ifdef CONFIG_GRKERNSEC_RANDNET
31458+#define INPUT_POOL_WORDS 512
31459+#define OUTPUT_POOL_WORDS 128
31460+#else
31461 #define INPUT_POOL_WORDS 128
31462 #define OUTPUT_POOL_WORDS 32
31463+#endif
31464 #define SEC_XFER_SIZE 512
31465
31466 /*
31467@@ -292,10 +297,17 @@ static struct poolinfo {
31468 int poolwords;
31469 int tap1, tap2, tap3, tap4, tap5;
31470 } poolinfo_table[] = {
31471+#ifdef CONFIG_GRKERNSEC_RANDNET
31472+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31473+ { 512, 411, 308, 208, 104, 1 },
31474+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31475+ { 128, 103, 76, 51, 25, 1 },
31476+#else
31477 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31478 { 128, 103, 76, 51, 25, 1 },
31479 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31480 { 32, 26, 20, 14, 7, 1 },
31481+#endif
31482 #if 0
31483 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31484 { 2048, 1638, 1231, 819, 411, 1 },
31485@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31486 #include <linux/sysctl.h>
31487
31488 static int min_read_thresh = 8, min_write_thresh;
31489-static int max_read_thresh = INPUT_POOL_WORDS * 32;
31490+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31491 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31492 static char sysctl_bootid[16];
31493
31494diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
31495index 0e29a23..0efc2c2 100644
31496--- a/drivers/char/rocket.c
31497+++ b/drivers/char/rocket.c
31498@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
31499 struct rocket_ports tmp;
31500 int board;
31501
31502+ pax_track_stack();
31503+
31504 if (!retports)
31505 return -EFAULT;
31506 memset(&tmp, 0, sizeof (tmp));
31507diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31508index 8c262aa..4d3b058 100644
31509--- a/drivers/char/sonypi.c
31510+++ b/drivers/char/sonypi.c
31511@@ -55,6 +55,7 @@
31512 #include <asm/uaccess.h>
31513 #include <asm/io.h>
31514 #include <asm/system.h>
31515+#include <asm/local.h>
31516
31517 #include <linux/sonypi.h>
31518
31519@@ -491,7 +492,7 @@ static struct sonypi_device {
31520 spinlock_t fifo_lock;
31521 wait_queue_head_t fifo_proc_list;
31522 struct fasync_struct *fifo_async;
31523- int open_count;
31524+ local_t open_count;
31525 int model;
31526 struct input_dev *input_jog_dev;
31527 struct input_dev *input_key_dev;
31528@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31529 static int sonypi_misc_release(struct inode *inode, struct file *file)
31530 {
31531 mutex_lock(&sonypi_device.lock);
31532- sonypi_device.open_count--;
31533+ local_dec(&sonypi_device.open_count);
31534 mutex_unlock(&sonypi_device.lock);
31535 return 0;
31536 }
31537@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31538 lock_kernel();
31539 mutex_lock(&sonypi_device.lock);
31540 /* Flush input queue on first open */
31541- if (!sonypi_device.open_count)
31542+ if (!local_read(&sonypi_device.open_count))
31543 kfifo_reset(sonypi_device.fifo);
31544- sonypi_device.open_count++;
31545+ local_inc(&sonypi_device.open_count);
31546 mutex_unlock(&sonypi_device.lock);
31547 unlock_kernel();
31548 return 0;
31549diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
31550index db6dcfa..13834cb 100644
31551--- a/drivers/char/stallion.c
31552+++ b/drivers/char/stallion.c
31553@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlport __user *arg)
31554 struct stlport stl_dummyport;
31555 struct stlport *portp;
31556
31557+ pax_track_stack();
31558+
31559 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
31560 return -EFAULT;
31561 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
31562diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31563index a0789f6..cea3902 100644
31564--- a/drivers/char/tpm/tpm.c
31565+++ b/drivers/char/tpm/tpm.c
31566@@ -405,7 +405,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31567 chip->vendor.req_complete_val)
31568 goto out_recv;
31569
31570- if ((status == chip->vendor.req_canceled)) {
31571+ if (status == chip->vendor.req_canceled) {
31572 dev_err(chip->dev, "Operation Canceled\n");
31573 rc = -ECANCELED;
31574 goto out;
31575@@ -824,6 +824,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
31576
31577 struct tpm_chip *chip = dev_get_drvdata(dev);
31578
31579+ pax_track_stack();
31580+
31581 tpm_cmd.header.in = tpm_readpubek_header;
31582 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
31583 "attempting to read the PUBEK");
31584diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
31585index bf2170f..ce8cab9 100644
31586--- a/drivers/char/tpm/tpm_bios.c
31587+++ b/drivers/char/tpm/tpm_bios.c
31588@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31589 event = addr;
31590
31591 if ((event->event_type == 0 && event->event_size == 0) ||
31592- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31593+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31594 return NULL;
31595
31596 return addr;
31597@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31598 return NULL;
31599
31600 if ((event->event_type == 0 && event->event_size == 0) ||
31601- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31602+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31603 return NULL;
31604
31605 (*pos)++;
31606@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31607 int i;
31608
31609 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31610- seq_putc(m, data[i]);
31611+ if (!seq_putc(m, data[i]))
31612+ return -EFAULT;
31613
31614 return 0;
31615 }
31616@@ -409,8 +410,13 @@ static int read_log(struct tpm_bios_log *log)
31617 log->bios_event_log_end = log->bios_event_log + len;
31618
31619 virt = acpi_os_map_memory(start, len);
31620+ if (!virt) {
31621+ kfree(log->bios_event_log);
31622+ log->bios_event_log = NULL;
31623+ return -EFAULT;
31624+ }
31625
31626- memcpy(log->bios_event_log, virt, len);
31627+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
31628
31629 acpi_os_unmap_memory(virt, len);
31630 return 0;
31631diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
31632index 123cedf..137edef 100644
31633--- a/drivers/char/tty_io.c
31634+++ b/drivers/char/tty_io.c
31635@@ -1774,6 +1774,7 @@ got_driver:
31636
31637 if (IS_ERR(tty)) {
31638 mutex_unlock(&tty_mutex);
31639+ tty_driver_kref_put(driver);
31640 return PTR_ERR(tty);
31641 }
31642 }
31643@@ -2603,8 +2604,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31644 return retval;
31645 }
31646
31647+EXPORT_SYMBOL(tty_ioctl);
31648+
31649 #ifdef CONFIG_COMPAT
31650-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31651+long tty_compat_ioctl(struct file *file, unsigned int cmd,
31652 unsigned long arg)
31653 {
31654 struct inode *inode = file->f_dentry->d_inode;
31655@@ -2628,6 +2631,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31656
31657 return retval;
31658 }
31659+
31660+EXPORT_SYMBOL(tty_compat_ioctl);
31661 #endif
31662
31663 /*
31664@@ -3073,7 +3078,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
31665
31666 void tty_default_fops(struct file_operations *fops)
31667 {
31668- *fops = tty_fops;
31669+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
31670 }
31671
31672 /*
31673diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
31674index d814a3d..b55b9c9 100644
31675--- a/drivers/char/tty_ldisc.c
31676+++ b/drivers/char/tty_ldisc.c
31677@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *ld)
31678 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
31679 struct tty_ldisc_ops *ldo = ld->ops;
31680
31681- ldo->refcount--;
31682+ atomic_dec(&ldo->refcount);
31683 module_put(ldo->owner);
31684 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31685
31686@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
31687 spin_lock_irqsave(&tty_ldisc_lock, flags);
31688 tty_ldiscs[disc] = new_ldisc;
31689 new_ldisc->num = disc;
31690- new_ldisc->refcount = 0;
31691+ atomic_set(&new_ldisc->refcount, 0);
31692 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31693
31694 return ret;
31695@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
31696 return -EINVAL;
31697
31698 spin_lock_irqsave(&tty_ldisc_lock, flags);
31699- if (tty_ldiscs[disc]->refcount)
31700+ if (atomic_read(&tty_ldiscs[disc]->refcount))
31701 ret = -EBUSY;
31702 else
31703 tty_ldiscs[disc] = NULL;
31704@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
31705 if (ldops) {
31706 ret = ERR_PTR(-EAGAIN);
31707 if (try_module_get(ldops->owner)) {
31708- ldops->refcount++;
31709+ atomic_inc(&ldops->refcount);
31710 ret = ldops;
31711 }
31712 }
31713@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
31714 unsigned long flags;
31715
31716 spin_lock_irqsave(&tty_ldisc_lock, flags);
31717- ldops->refcount--;
31718+ atomic_dec(&ldops->refcount);
31719 module_put(ldops->owner);
31720 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31721 }
31722diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31723index a035ae3..c27fe2c 100644
31724--- a/drivers/char/virtio_console.c
31725+++ b/drivers/char/virtio_console.c
31726@@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *buf, int count)
31727 * virtqueue, so we let the drivers do some boutique early-output thing. */
31728 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
31729 {
31730- virtio_cons.put_chars = put_chars;
31731+ pax_open_kernel();
31732+ *(void **)&virtio_cons.put_chars = put_chars;
31733+ pax_close_kernel();
31734 return hvc_instantiate(0, 0, &virtio_cons);
31735 }
31736
31737@@ -213,11 +215,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
31738 out_vq = vqs[1];
31739
31740 /* Start using the new console output. */
31741- virtio_cons.get_chars = get_chars;
31742- virtio_cons.put_chars = put_chars;
31743- virtio_cons.notifier_add = notifier_add_vio;
31744- virtio_cons.notifier_del = notifier_del_vio;
31745- virtio_cons.notifier_hangup = notifier_del_vio;
31746+ pax_open_kernel();
31747+ *(void **)&virtio_cons.get_chars = get_chars;
31748+ *(void **)&virtio_cons.put_chars = put_chars;
31749+ *(void **)&virtio_cons.notifier_add = notifier_add_vio;
31750+ *(void **)&virtio_cons.notifier_del = notifier_del_vio;
31751+ *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
31752+ pax_close_kernel();
31753
31754 /* The first argument of hvc_alloc() is the virtual console number, so
31755 * we use zero. The second argument is the parameter for the
31756diff --git a/drivers/char/vt.c b/drivers/char/vt.c
31757index 0c80c68..53d59c1 100644
31758--- a/drivers/char/vt.c
31759+++ b/drivers/char/vt.c
31760@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
31761
31762 static void notify_write(struct vc_data *vc, unsigned int unicode)
31763 {
31764- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
31765+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
31766 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
31767 }
31768
31769diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
31770index 6351a26..999af95 100644
31771--- a/drivers/char/vt_ioctl.c
31772+++ b/drivers/char/vt_ioctl.c
31773@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31774 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
31775 return -EFAULT;
31776
31777- if (!capable(CAP_SYS_TTY_CONFIG))
31778- perm = 0;
31779-
31780 switch (cmd) {
31781 case KDGKBENT:
31782 key_map = key_maps[s];
31783@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31784 val = (i ? K_HOLE : K_NOSUCHMAP);
31785 return put_user(val, &user_kbe->kb_value);
31786 case KDSKBENT:
31787+ if (!capable(CAP_SYS_TTY_CONFIG))
31788+ perm = 0;
31789+
31790 if (!perm)
31791 return -EPERM;
31792+
31793 if (!i && v == K_NOSUCHMAP) {
31794 /* deallocate map */
31795 key_map = key_maps[s];
31796@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31797 int i, j, k;
31798 int ret;
31799
31800- if (!capable(CAP_SYS_TTY_CONFIG))
31801- perm = 0;
31802-
31803 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
31804 if (!kbs) {
31805 ret = -ENOMEM;
31806@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31807 kfree(kbs);
31808 return ((p && *p) ? -EOVERFLOW : 0);
31809 case KDSKBSENT:
31810+ if (!capable(CAP_SYS_TTY_CONFIG))
31811+ perm = 0;
31812+
31813 if (!perm) {
31814 ret = -EPERM;
31815 goto reterr;
31816diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
31817index c7ae026..1769c1d 100644
31818--- a/drivers/cpufreq/cpufreq.c
31819+++ b/drivers/cpufreq/cpufreq.c
31820@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct kobject *kobj)
31821 complete(&policy->kobj_unregister);
31822 }
31823
31824-static struct sysfs_ops sysfs_ops = {
31825+static const struct sysfs_ops sysfs_ops = {
31826 .show = show,
31827 .store = store,
31828 };
31829diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
31830index 97b0038..2056670 100644
31831--- a/drivers/cpuidle/sysfs.c
31832+++ b/drivers/cpuidle/sysfs.c
31833@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
31834 return ret;
31835 }
31836
31837-static struct sysfs_ops cpuidle_sysfs_ops = {
31838+static const struct sysfs_ops cpuidle_sysfs_ops = {
31839 .show = cpuidle_show,
31840 .store = cpuidle_store,
31841 };
31842@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct kobject * kobj,
31843 return ret;
31844 }
31845
31846-static struct sysfs_ops cpuidle_state_sysfs_ops = {
31847+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
31848 .show = cpuidle_state_show,
31849 };
31850
31851@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpuidle = {
31852 .release = cpuidle_state_sysfs_release,
31853 };
31854
31855-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31856+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31857 {
31858 kobject_put(&device->kobjs[i]->kobj);
31859 wait_for_completion(&device->kobjs[i]->kobj_unregister);
31860diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
31861index 5f753fc..0377ae9 100644
31862--- a/drivers/crypto/hifn_795x.c
31863+++ b/drivers/crypto/hifn_795x.c
31864@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
31865 0xCA, 0x34, 0x2B, 0x2E};
31866 struct scatterlist sg;
31867
31868+ pax_track_stack();
31869+
31870 memset(src, 0, sizeof(src));
31871 memset(ctx.key, 0, sizeof(ctx.key));
31872
31873diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
31874index 71e6482..de8d96c 100644
31875--- a/drivers/crypto/padlock-aes.c
31876+++ b/drivers/crypto/padlock-aes.c
31877@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
31878 struct crypto_aes_ctx gen_aes;
31879 int cpu;
31880
31881+ pax_track_stack();
31882+
31883 if (key_len % 8) {
31884 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
31885 return -EINVAL;
31886diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
31887index dcc4ab7..cc834bb 100644
31888--- a/drivers/dma/ioat/dma.c
31889+++ b/drivers/dma/ioat/dma.c
31890@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
31891 return entry->show(&chan->common, page);
31892 }
31893
31894-struct sysfs_ops ioat_sysfs_ops = {
31895+const struct sysfs_ops ioat_sysfs_ops = {
31896 .show = ioat_attr_show,
31897 };
31898
31899diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
31900index bbc3e78..f2db62c 100644
31901--- a/drivers/dma/ioat/dma.h
31902+++ b/drivers/dma/ioat/dma.h
31903@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
31904 unsigned long *phys_complete);
31905 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
31906 void ioat_kobject_del(struct ioatdma_device *device);
31907-extern struct sysfs_ops ioat_sysfs_ops;
31908+extern const struct sysfs_ops ioat_sysfs_ops;
31909 extern struct ioat_sysfs_entry ioat_version_attr;
31910 extern struct ioat_sysfs_entry ioat_cap_attr;
31911 #endif /* IOATDMA_H */
31912diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
31913index 9908c9e..3ceb0e5 100644
31914--- a/drivers/dma/ioat/dma_v3.c
31915+++ b/drivers/dma/ioat/dma_v3.c
31916@@ -71,10 +71,10 @@
31917 /* provide a lookup table for setting the source address in the base or
31918 * extended descriptor of an xor or pq descriptor
31919 */
31920-static const u8 xor_idx_to_desc __read_mostly = 0xd0;
31921-static const u8 xor_idx_to_field[] __read_mostly = { 1, 4, 5, 6, 7, 0, 1, 2 };
31922-static const u8 pq_idx_to_desc __read_mostly = 0xf8;
31923-static const u8 pq_idx_to_field[] __read_mostly = { 1, 4, 5, 0, 1, 2, 4, 5 };
31924+static const u8 xor_idx_to_desc = 0xd0;
31925+static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
31926+static const u8 pq_idx_to_desc = 0xf8;
31927+static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
31928
31929 static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
31930 {
31931diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
31932index 85c464a..afd1e73 100644
31933--- a/drivers/edac/amd64_edac.c
31934+++ b/drivers/edac/amd64_edac.c
31935@@ -3099,7 +3099,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
31936 * PCI core identifies what devices are on a system during boot, and then
31937 * inquiry this table to see if this driver is for a given device found.
31938 */
31939-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
31940+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
31941 {
31942 .vendor = PCI_VENDOR_ID_AMD,
31943 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
31944diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
31945index 2b95f1a..4f52793 100644
31946--- a/drivers/edac/amd76x_edac.c
31947+++ b/drivers/edac/amd76x_edac.c
31948@@ -322,7 +322,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
31949 edac_mc_free(mci);
31950 }
31951
31952-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
31953+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
31954 {
31955 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31956 AMD762},
31957diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
31958index d205d49..74c9672 100644
31959--- a/drivers/edac/e752x_edac.c
31960+++ b/drivers/edac/e752x_edac.c
31961@@ -1282,7 +1282,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
31962 edac_mc_free(mci);
31963 }
31964
31965-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
31966+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
31967 {
31968 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31969 E7520},
31970diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
31971index c7d11cc..c59c1ca 100644
31972--- a/drivers/edac/e7xxx_edac.c
31973+++ b/drivers/edac/e7xxx_edac.c
31974@@ -526,7 +526,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
31975 edac_mc_free(mci);
31976 }
31977
31978-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
31979+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
31980 {
31981 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
31982 E7205},
31983diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
31984index 5376457..5fdedbc 100644
31985--- a/drivers/edac/edac_device_sysfs.c
31986+++ b/drivers/edac/edac_device_sysfs.c
31987@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
31988 }
31989
31990 /* edac_dev file operations for an 'ctl_info' */
31991-static struct sysfs_ops device_ctl_info_ops = {
31992+static const struct sysfs_ops device_ctl_info_ops = {
31993 .show = edac_dev_ctl_info_show,
31994 .store = edac_dev_ctl_info_store
31995 };
31996@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(struct kobject *kobj,
31997 }
31998
31999 /* edac_dev file operations for an 'instance' */
32000-static struct sysfs_ops device_instance_ops = {
32001+static const struct sysfs_ops device_instance_ops = {
32002 .show = edac_dev_instance_show,
32003 .store = edac_dev_instance_store
32004 };
32005@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(struct kobject *kobj,
32006 }
32007
32008 /* edac_dev file operations for a 'block' */
32009-static struct sysfs_ops device_block_ops = {
32010+static const struct sysfs_ops device_block_ops = {
32011 .show = edac_dev_block_show,
32012 .store = edac_dev_block_store
32013 };
32014diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
32015index e1d4ce0..88840e9 100644
32016--- a/drivers/edac/edac_mc_sysfs.c
32017+++ b/drivers/edac/edac_mc_sysfs.c
32018@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
32019 return -EIO;
32020 }
32021
32022-static struct sysfs_ops csrowfs_ops = {
32023+static const struct sysfs_ops csrowfs_ops = {
32024 .show = csrowdev_show,
32025 .store = csrowdev_store
32026 };
32027@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
32028 }
32029
32030 /* Intermediate show/store table */
32031-static struct sysfs_ops mci_ops = {
32032+static const struct sysfs_ops mci_ops = {
32033 .show = mcidev_show,
32034 .store = mcidev_store
32035 };
32036diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32037index 422728c..d8d9c88 100644
32038--- a/drivers/edac/edac_pci_sysfs.c
32039+++ b/drivers/edac/edac_pci_sysfs.c
32040@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32041 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32042 static int edac_pci_poll_msec = 1000; /* one second workq period */
32043
32044-static atomic_t pci_parity_count = ATOMIC_INIT(0);
32045-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32046+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32047+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32048
32049 static struct kobject *edac_pci_top_main_kobj;
32050 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32051@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
32052 }
32053
32054 /* fs_ops table */
32055-static struct sysfs_ops pci_instance_ops = {
32056+static const struct sysfs_ops pci_instance_ops = {
32057 .show = edac_pci_instance_show,
32058 .store = edac_pci_instance_store
32059 };
32060@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct kobject *kobj,
32061 return -EIO;
32062 }
32063
32064-static struct sysfs_ops edac_pci_sysfs_ops = {
32065+static const struct sysfs_ops edac_pci_sysfs_ops = {
32066 .show = edac_pci_dev_show,
32067 .store = edac_pci_dev_store
32068 };
32069@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32070 edac_printk(KERN_CRIT, EDAC_PCI,
32071 "Signaled System Error on %s\n",
32072 pci_name(dev));
32073- atomic_inc(&pci_nonparity_count);
32074+ atomic_inc_unchecked(&pci_nonparity_count);
32075 }
32076
32077 if (status & (PCI_STATUS_PARITY)) {
32078@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32079 "Master Data Parity Error on %s\n",
32080 pci_name(dev));
32081
32082- atomic_inc(&pci_parity_count);
32083+ atomic_inc_unchecked(&pci_parity_count);
32084 }
32085
32086 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32087@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32088 "Detected Parity Error on %s\n",
32089 pci_name(dev));
32090
32091- atomic_inc(&pci_parity_count);
32092+ atomic_inc_unchecked(&pci_parity_count);
32093 }
32094 }
32095
32096@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32097 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32098 "Signaled System Error on %s\n",
32099 pci_name(dev));
32100- atomic_inc(&pci_nonparity_count);
32101+ atomic_inc_unchecked(&pci_nonparity_count);
32102 }
32103
32104 if (status & (PCI_STATUS_PARITY)) {
32105@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32106 "Master Data Parity Error on "
32107 "%s\n", pci_name(dev));
32108
32109- atomic_inc(&pci_parity_count);
32110+ atomic_inc_unchecked(&pci_parity_count);
32111 }
32112
32113 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32114@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32115 "Detected Parity Error on %s\n",
32116 pci_name(dev));
32117
32118- atomic_inc(&pci_parity_count);
32119+ atomic_inc_unchecked(&pci_parity_count);
32120 }
32121 }
32122 }
32123@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
32124 if (!check_pci_errors)
32125 return;
32126
32127- before_count = atomic_read(&pci_parity_count);
32128+ before_count = atomic_read_unchecked(&pci_parity_count);
32129
32130 /* scan all PCI devices looking for a Parity Error on devices and
32131 * bridges.
32132@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
32133 /* Only if operator has selected panic on PCI Error */
32134 if (edac_pci_get_panic_on_pe()) {
32135 /* If the count is different 'after' from 'before' */
32136- if (before_count != atomic_read(&pci_parity_count))
32137+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32138 panic("EDAC: PCI Parity Error");
32139 }
32140 }
32141diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
32142index 6c9a0f2..9c1cf7e 100644
32143--- a/drivers/edac/i3000_edac.c
32144+++ b/drivers/edac/i3000_edac.c
32145@@ -471,7 +471,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
32146 edac_mc_free(mci);
32147 }
32148
32149-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
32150+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
32151 {
32152 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32153 I3000},
32154diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
32155index fde4db9..fe108f9 100644
32156--- a/drivers/edac/i3200_edac.c
32157+++ b/drivers/edac/i3200_edac.c
32158@@ -444,7 +444,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
32159 edac_mc_free(mci);
32160 }
32161
32162-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
32163+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
32164 {
32165 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32166 I3200},
32167diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
32168index adc10a2..57d4ccf 100644
32169--- a/drivers/edac/i5000_edac.c
32170+++ b/drivers/edac/i5000_edac.c
32171@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
32172 *
32173 * The "E500P" device is the first device supported.
32174 */
32175-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
32176+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
32177 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
32178 .driver_data = I5000P},
32179
32180diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
32181index 22db05a..b2b5503 100644
32182--- a/drivers/edac/i5100_edac.c
32183+++ b/drivers/edac/i5100_edac.c
32184@@ -944,7 +944,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
32185 edac_mc_free(mci);
32186 }
32187
32188-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
32189+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
32190 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
32191 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
32192 { 0, }
32193diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
32194index f99d106..f050710 100644
32195--- a/drivers/edac/i5400_edac.c
32196+++ b/drivers/edac/i5400_edac.c
32197@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
32198 *
32199 * The "E500P" device is the first device supported.
32200 */
32201-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
32202+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
32203 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
32204 {0,} /* 0 terminated list. */
32205 };
32206diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
32207index 577760a..9ce16ce 100644
32208--- a/drivers/edac/i82443bxgx_edac.c
32209+++ b/drivers/edac/i82443bxgx_edac.c
32210@@ -381,7 +381,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
32211
32212 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
32213
32214-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
32215+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
32216 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
32217 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
32218 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
32219diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
32220index c0088ba..64a7b98 100644
32221--- a/drivers/edac/i82860_edac.c
32222+++ b/drivers/edac/i82860_edac.c
32223@@ -271,7 +271,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
32224 edac_mc_free(mci);
32225 }
32226
32227-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
32228+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
32229 {
32230 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32231 I82860},
32232diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
32233index b2d83b9..a34357b 100644
32234--- a/drivers/edac/i82875p_edac.c
32235+++ b/drivers/edac/i82875p_edac.c
32236@@ -512,7 +512,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
32237 edac_mc_free(mci);
32238 }
32239
32240-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
32241+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
32242 {
32243 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32244 I82875P},
32245diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
32246index 2eed3ea..87bbbd1 100644
32247--- a/drivers/edac/i82975x_edac.c
32248+++ b/drivers/edac/i82975x_edac.c
32249@@ -586,7 +586,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
32250 edac_mc_free(mci);
32251 }
32252
32253-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
32254+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
32255 {
32256 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32257 I82975X
32258diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
32259index 9900675..78ac2b6 100644
32260--- a/drivers/edac/r82600_edac.c
32261+++ b/drivers/edac/r82600_edac.c
32262@@ -374,7 +374,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
32263 edac_mc_free(mci);
32264 }
32265
32266-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
32267+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
32268 {
32269 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
32270 },
32271diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
32272index d4ec605..4cfec4e 100644
32273--- a/drivers/edac/x38_edac.c
32274+++ b/drivers/edac/x38_edac.c
32275@@ -441,7 +441,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
32276 edac_mc_free(mci);
32277 }
32278
32279-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
32280+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
32281 {
32282 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32283 X38},
32284diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32285index 3fc2ceb..daf098f 100644
32286--- a/drivers/firewire/core-card.c
32287+++ b/drivers/firewire/core-card.c
32288@@ -558,7 +558,7 @@ void fw_card_release(struct kref *kref)
32289
32290 void fw_core_remove_card(struct fw_card *card)
32291 {
32292- struct fw_card_driver dummy_driver = dummy_driver_template;
32293+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32294
32295 card->driver->update_phy_reg(card, 4,
32296 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32297diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32298index 4560d8f..36db24a 100644
32299--- a/drivers/firewire/core-cdev.c
32300+++ b/drivers/firewire/core-cdev.c
32301@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct client *client,
32302 int ret;
32303
32304 if ((request->channels == 0 && request->bandwidth == 0) ||
32305- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32306- request->bandwidth < 0)
32307+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32308 return -EINVAL;
32309
32310 r = kmalloc(sizeof(*r), GFP_KERNEL);
32311diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32312index da628c7..cf54a2c 100644
32313--- a/drivers/firewire/core-transaction.c
32314+++ b/drivers/firewire/core-transaction.c
32315@@ -36,6 +36,7 @@
32316 #include <linux/string.h>
32317 #include <linux/timer.h>
32318 #include <linux/types.h>
32319+#include <linux/sched.h>
32320
32321 #include <asm/byteorder.h>
32322
32323@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
32324 struct transaction_callback_data d;
32325 struct fw_transaction t;
32326
32327+ pax_track_stack();
32328+
32329 init_completion(&d.done);
32330 d.payload = payload;
32331 fw_send_request(card, &t, tcode, destination_id, generation, speed,
32332diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32333index 7ff6e75..a2965d9 100644
32334--- a/drivers/firewire/core.h
32335+++ b/drivers/firewire/core.h
32336@@ -86,6 +86,7 @@ struct fw_card_driver {
32337
32338 int (*stop_iso)(struct fw_iso_context *ctx);
32339 };
32340+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32341
32342 void fw_card_initialize(struct fw_card *card,
32343 const struct fw_card_driver *driver, struct device *device);
32344diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32345index 3a2ccb0..82fd7c4 100644
32346--- a/drivers/firmware/dmi_scan.c
32347+++ b/drivers/firmware/dmi_scan.c
32348@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
32349 }
32350 }
32351 else {
32352- /*
32353- * no iounmap() for that ioremap(); it would be a no-op, but
32354- * it's so early in setup that sucker gets confused into doing
32355- * what it shouldn't if we actually call it.
32356- */
32357 p = dmi_ioremap(0xF0000, 0x10000);
32358 if (p == NULL)
32359 goto error;
32360@@ -667,7 +662,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32361 if (buf == NULL)
32362 return -1;
32363
32364- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32365+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32366
32367 iounmap(buf);
32368 return 0;
32369diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
32370index 9e4f59d..110e24e 100644
32371--- a/drivers/firmware/edd.c
32372+++ b/drivers/firmware/edd.c
32373@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
32374 return ret;
32375 }
32376
32377-static struct sysfs_ops edd_attr_ops = {
32378+static const struct sysfs_ops edd_attr_ops = {
32379 .show = edd_attr_show,
32380 };
32381
32382diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32383index f4f709d..082f06e 100644
32384--- a/drivers/firmware/efivars.c
32385+++ b/drivers/firmware/efivars.c
32386@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
32387 return ret;
32388 }
32389
32390-static struct sysfs_ops efivar_attr_ops = {
32391+static const struct sysfs_ops efivar_attr_ops = {
32392 .show = efivar_attr_show,
32393 .store = efivar_attr_store,
32394 };
32395diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
32396index 051d1eb..0a5d4e7 100644
32397--- a/drivers/firmware/iscsi_ibft.c
32398+++ b/drivers/firmware/iscsi_ibft.c
32399@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struct kobject *kobj,
32400 return ret;
32401 }
32402
32403-static struct sysfs_ops ibft_attr_ops = {
32404+static const struct sysfs_ops ibft_attr_ops = {
32405 .show = ibft_show_attribute,
32406 };
32407
32408diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
32409index 56f9234..8c58c7b 100644
32410--- a/drivers/firmware/memmap.c
32411+++ b/drivers/firmware/memmap.c
32412@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
32413 NULL
32414 };
32415
32416-static struct sysfs_ops memmap_attr_ops = {
32417+static const struct sysfs_ops memmap_attr_ops = {
32418 .show = memmap_attr_show,
32419 };
32420
32421diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
32422index b16c9a8..2af7d3f 100644
32423--- a/drivers/gpio/vr41xx_giu.c
32424+++ b/drivers/gpio/vr41xx_giu.c
32425@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32426 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32427 maskl, pendl, maskh, pendh);
32428
32429- atomic_inc(&irq_err_count);
32430+ atomic_inc_unchecked(&irq_err_count);
32431
32432 return -EINVAL;
32433 }
32434diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
32435index bea6efc..3dc0f42 100644
32436--- a/drivers/gpu/drm/drm_crtc.c
32437+++ b/drivers/gpu/drm/drm_crtc.c
32438@@ -1323,7 +1323,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32439 */
32440 if ((out_resp->count_modes >= mode_count) && mode_count) {
32441 copied = 0;
32442- mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
32443+ mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
32444 list_for_each_entry(mode, &connector->modes, head) {
32445 drm_crtc_convert_to_umode(&u_mode, mode);
32446 if (copy_to_user(mode_ptr + copied,
32447@@ -1338,8 +1338,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32448
32449 if ((out_resp->count_props >= props_count) && props_count) {
32450 copied = 0;
32451- prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
32452- prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
32453+ prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
32454+ prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
32455 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
32456 if (connector->property_ids[i] != 0) {
32457 if (put_user(connector->property_ids[i],
32458@@ -1361,7 +1361,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32459
32460 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
32461 copied = 0;
32462- encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
32463+ encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
32464 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
32465 if (connector->encoder_ids[i] != 0) {
32466 if (put_user(connector->encoder_ids[i],
32467@@ -1513,7 +1513,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
32468 }
32469
32470 for (i = 0; i < crtc_req->count_connectors; i++) {
32471- set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
32472+ set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
32473 if (get_user(out_id, &set_connectors_ptr[i])) {
32474 ret = -EFAULT;
32475 goto out;
32476@@ -2118,7 +2118,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32477 out_resp->flags = property->flags;
32478
32479 if ((out_resp->count_values >= value_count) && value_count) {
32480- values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
32481+ values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
32482 for (i = 0; i < value_count; i++) {
32483 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
32484 ret = -EFAULT;
32485@@ -2131,7 +2131,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32486 if (property->flags & DRM_MODE_PROP_ENUM) {
32487 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
32488 copied = 0;
32489- enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
32490+ enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
32491 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
32492
32493 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
32494@@ -2154,7 +2154,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32495 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
32496 copied = 0;
32497 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
32498- blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
32499+ blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
32500
32501 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
32502 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
32503@@ -2226,7 +2226,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
32504 blob = obj_to_blob(obj);
32505
32506 if (out_resp->length == blob->length) {
32507- blob_ptr = (void *)(unsigned long)out_resp->data;
32508+ blob_ptr = (void __user *)(unsigned long)out_resp->data;
32509 if (copy_to_user(blob_ptr, blob->data, blob->length)){
32510 ret = -EFAULT;
32511 goto done;
32512diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32513index 1b8745d..92fdbf6 100644
32514--- a/drivers/gpu/drm/drm_crtc_helper.c
32515+++ b/drivers/gpu/drm/drm_crtc_helper.c
32516@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32517 struct drm_crtc *tmp;
32518 int crtc_mask = 1;
32519
32520- WARN(!crtc, "checking null crtc?");
32521+ BUG_ON(!crtc);
32522
32523 dev = crtc->dev;
32524
32525@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
32526
32527 adjusted_mode = drm_mode_duplicate(dev, mode);
32528
32529+ pax_track_stack();
32530+
32531 crtc->enabled = drm_helper_crtc_in_use(crtc);
32532
32533 if (!crtc->enabled)
32534diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32535index 0e27d98..dec8768 100644
32536--- a/drivers/gpu/drm/drm_drv.c
32537+++ b/drivers/gpu/drm/drm_drv.c
32538@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
32539 char *kdata = NULL;
32540
32541 atomic_inc(&dev->ioctl_count);
32542- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32543+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32544 ++file_priv->ioctl_count;
32545
32546 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32547diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32548index ba14553..182d0bb 100644
32549--- a/drivers/gpu/drm/drm_fops.c
32550+++ b/drivers/gpu/drm/drm_fops.c
32551@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device * dev)
32552 }
32553
32554 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32555- atomic_set(&dev->counts[i], 0);
32556+ atomic_set_unchecked(&dev->counts[i], 0);
32557
32558 dev->sigdata.lock = NULL;
32559
32560@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct file *filp)
32561
32562 retcode = drm_open_helper(inode, filp, dev);
32563 if (!retcode) {
32564- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32565+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32566 spin_lock(&dev->count_lock);
32567- if (!dev->open_count++) {
32568+ if (local_inc_return(&dev->open_count) == 1) {
32569 spin_unlock(&dev->count_lock);
32570 retcode = drm_setup(dev);
32571 goto out;
32572@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, struct file *filp)
32573
32574 lock_kernel();
32575
32576- DRM_DEBUG("open_count = %d\n", dev->open_count);
32577+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
32578
32579 if (dev->driver->preclose)
32580 dev->driver->preclose(dev, file_priv);
32581@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, struct file *filp)
32582 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32583 task_pid_nr(current),
32584 (long)old_encode_dev(file_priv->minor->device),
32585- dev->open_count);
32586+ local_read(&dev->open_count));
32587
32588 /* if the master has gone away we can't do anything with the lock */
32589 if (file_priv->minor->master)
32590@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, struct file *filp)
32591 * End inline drm_release
32592 */
32593
32594- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32595+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32596 spin_lock(&dev->count_lock);
32597- if (!--dev->open_count) {
32598+ if (local_dec_and_test(&dev->open_count)) {
32599 if (atomic_read(&dev->ioctl_count)) {
32600 DRM_ERROR("Device busy: %d\n",
32601 atomic_read(&dev->ioctl_count));
32602diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
32603index 8bf3770..7942280 100644
32604--- a/drivers/gpu/drm/drm_gem.c
32605+++ b/drivers/gpu/drm/drm_gem.c
32606@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
32607 spin_lock_init(&dev->object_name_lock);
32608 idr_init(&dev->object_name_idr);
32609 atomic_set(&dev->object_count, 0);
32610- atomic_set(&dev->object_memory, 0);
32611+ atomic_set_unchecked(&dev->object_memory, 0);
32612 atomic_set(&dev->pin_count, 0);
32613- atomic_set(&dev->pin_memory, 0);
32614+ atomic_set_unchecked(&dev->pin_memory, 0);
32615 atomic_set(&dev->gtt_count, 0);
32616- atomic_set(&dev->gtt_memory, 0);
32617+ atomic_set_unchecked(&dev->gtt_memory, 0);
32618
32619 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
32620 if (!mm) {
32621@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
32622 goto fput;
32623 }
32624 atomic_inc(&dev->object_count);
32625- atomic_add(obj->size, &dev->object_memory);
32626+ atomic_add_unchecked(obj->size, &dev->object_memory);
32627 return obj;
32628 fput:
32629 fput(obj->filp);
32630@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
32631
32632 fput(obj->filp);
32633 atomic_dec(&dev->object_count);
32634- atomic_sub(obj->size, &dev->object_memory);
32635+ atomic_sub_unchecked(obj->size, &dev->object_memory);
32636 kfree(obj);
32637 }
32638 EXPORT_SYMBOL(drm_gem_object_free);
32639diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32640index f0f6c6b..34af322 100644
32641--- a/drivers/gpu/drm/drm_info.c
32642+++ b/drivers/gpu/drm/drm_info.c
32643@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32644 struct drm_local_map *map;
32645 struct drm_map_list *r_list;
32646
32647- /* Hardcoded from _DRM_FRAME_BUFFER,
32648- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32649- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32650- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32651+ static const char * const types[] = {
32652+ [_DRM_FRAME_BUFFER] = "FB",
32653+ [_DRM_REGISTERS] = "REG",
32654+ [_DRM_SHM] = "SHM",
32655+ [_DRM_AGP] = "AGP",
32656+ [_DRM_SCATTER_GATHER] = "SG",
32657+ [_DRM_CONSISTENT] = "PCI",
32658+ [_DRM_GEM] = "GEM" };
32659 const char *type;
32660 int i;
32661
32662@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32663 map = r_list->map;
32664 if (!map)
32665 continue;
32666- if (map->type < 0 || map->type > 5)
32667+ if (map->type >= ARRAY_SIZE(types))
32668 type = "??";
32669 else
32670 type = types[map->type];
32671@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file *m, void* data)
32672 struct drm_device *dev = node->minor->dev;
32673
32674 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
32675- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
32676+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
32677 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
32678- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
32679- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
32680+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
32681+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
32682 seq_printf(m, "%d gtt total\n", dev->gtt_total);
32683 return 0;
32684 }
32685@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32686 mutex_lock(&dev->struct_mutex);
32687 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
32688 atomic_read(&dev->vma_count),
32689+#ifdef CONFIG_GRKERNSEC_HIDESYM
32690+ NULL, 0);
32691+#else
32692 high_memory, (u64)virt_to_phys(high_memory));
32693+#endif
32694
32695 list_for_each_entry(pt, &dev->vmalist, head) {
32696 vma = pt->vma;
32697@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, void *data)
32698 continue;
32699 seq_printf(m,
32700 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
32701- pt->pid, vma->vm_start, vma->vm_end,
32702+ pt->pid,
32703+#ifdef CONFIG_GRKERNSEC_HIDESYM
32704+ 0, 0,
32705+#else
32706+ vma->vm_start, vma->vm_end,
32707+#endif
32708 vma->vm_flags & VM_READ ? 'r' : '-',
32709 vma->vm_flags & VM_WRITE ? 'w' : '-',
32710 vma->vm_flags & VM_EXEC ? 'x' : '-',
32711 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32712 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32713 vma->vm_flags & VM_IO ? 'i' : '-',
32714+#ifdef CONFIG_GRKERNSEC_HIDESYM
32715+ 0);
32716+#else
32717 vma->vm_pgoff);
32718+#endif
32719
32720 #if defined(__i386__)
32721 pgprot = pgprot_val(vma->vm_page_prot);
32722diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32723index 282d9fd..71e5f11 100644
32724--- a/drivers/gpu/drm/drm_ioc32.c
32725+++ b/drivers/gpu/drm/drm_ioc32.c
32726@@ -463,7 +463,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32727 request = compat_alloc_user_space(nbytes);
32728 if (!access_ok(VERIFY_WRITE, request, nbytes))
32729 return -EFAULT;
32730- list = (struct drm_buf_desc *) (request + 1);
32731+ list = (struct drm_buf_desc __user *) (request + 1);
32732
32733 if (__put_user(count, &request->count)
32734 || __put_user(list, &request->list))
32735@@ -525,7 +525,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32736 request = compat_alloc_user_space(nbytes);
32737 if (!access_ok(VERIFY_WRITE, request, nbytes))
32738 return -EFAULT;
32739- list = (struct drm_buf_pub *) (request + 1);
32740+ list = (struct drm_buf_pub __user *) (request + 1);
32741
32742 if (__put_user(count, &request->count)
32743 || __put_user(list, &request->list))
32744diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32745index 9b9ff46..4ea724c 100644
32746--- a/drivers/gpu/drm/drm_ioctl.c
32747+++ b/drivers/gpu/drm/drm_ioctl.c
32748@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32749 stats->data[i].value =
32750 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32751 else
32752- stats->data[i].value = atomic_read(&dev->counts[i]);
32753+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32754 stats->data[i].type = dev->types[i];
32755 }
32756
32757diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32758index e2f70a5..c703e86 100644
32759--- a/drivers/gpu/drm/drm_lock.c
32760+++ b/drivers/gpu/drm/drm_lock.c
32761@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32762 if (drm_lock_take(&master->lock, lock->context)) {
32763 master->lock.file_priv = file_priv;
32764 master->lock.lock_time = jiffies;
32765- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32766+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32767 break; /* Got lock */
32768 }
32769
32770@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32771 return -EINVAL;
32772 }
32773
32774- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32775+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32776
32777 /* kernel_context_switch isn't used by any of the x86 drm
32778 * modules but is required by the Sparc driver.
32779diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32780index 7d1d88c..b9131b2 100644
32781--- a/drivers/gpu/drm/i810/i810_dma.c
32782+++ b/drivers/gpu/drm/i810/i810_dma.c
32783@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32784 dma->buflist[vertex->idx],
32785 vertex->discard, vertex->used);
32786
32787- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32788- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32789+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32790+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32791 sarea_priv->last_enqueue = dev_priv->counter - 1;
32792 sarea_priv->last_dispatch = (int)hw_status[5];
32793
32794@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32795 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32796 mc->last_render);
32797
32798- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32799- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32800+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32801+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32802 sarea_priv->last_enqueue = dev_priv->counter - 1;
32803 sarea_priv->last_dispatch = (int)hw_status[5];
32804
32805diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32806index 21e2691..7321edd 100644
32807--- a/drivers/gpu/drm/i810/i810_drv.h
32808+++ b/drivers/gpu/drm/i810/i810_drv.h
32809@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32810 int page_flipping;
32811
32812 wait_queue_head_t irq_queue;
32813- atomic_t irq_received;
32814- atomic_t irq_emitted;
32815+ atomic_unchecked_t irq_received;
32816+ atomic_unchecked_t irq_emitted;
32817
32818 int front_offset;
32819 } drm_i810_private_t;
32820diff --git a/drivers/gpu/drm/i830/i830_drv.h b/drivers/gpu/drm/i830/i830_drv.h
32821index da82afe..48a45de 100644
32822--- a/drivers/gpu/drm/i830/i830_drv.h
32823+++ b/drivers/gpu/drm/i830/i830_drv.h
32824@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
32825 int page_flipping;
32826
32827 wait_queue_head_t irq_queue;
32828- atomic_t irq_received;
32829- atomic_t irq_emitted;
32830+ atomic_unchecked_t irq_received;
32831+ atomic_unchecked_t irq_emitted;
32832
32833 int use_mi_batchbuffer_start;
32834
32835diff --git a/drivers/gpu/drm/i830/i830_irq.c b/drivers/gpu/drm/i830/i830_irq.c
32836index 91ec2bb..6f21fab 100644
32837--- a/drivers/gpu/drm/i830/i830_irq.c
32838+++ b/drivers/gpu/drm/i830/i830_irq.c
32839@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
32840
32841 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
32842
32843- atomic_inc(&dev_priv->irq_received);
32844+ atomic_inc_unchecked(&dev_priv->irq_received);
32845 wake_up_interruptible(&dev_priv->irq_queue);
32846
32847 return IRQ_HANDLED;
32848@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_device * dev)
32849
32850 DRM_DEBUG("%s\n", __func__);
32851
32852- atomic_inc(&dev_priv->irq_emitted);
32853+ atomic_inc_unchecked(&dev_priv->irq_emitted);
32854
32855 BEGIN_LP_RING(2);
32856 OUT_RING(0);
32857 OUT_RING(GFX_OP_USER_INTERRUPT);
32858 ADVANCE_LP_RING();
32859
32860- return atomic_read(&dev_priv->irq_emitted);
32861+ return atomic_read_unchecked(&dev_priv->irq_emitted);
32862 }
32863
32864 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32865@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32866
32867 DRM_DEBUG("%s\n", __func__);
32868
32869- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32870+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32871 return 0;
32872
32873 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
32874@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32875
32876 for (;;) {
32877 __set_current_state(TASK_INTERRUPTIBLE);
32878- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32879+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32880 break;
32881 if ((signed)(end - jiffies) <= 0) {
32882 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
32883@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct drm_device * dev)
32884 I830_WRITE16(I830REG_HWSTAM, 0xffff);
32885 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
32886 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
32887- atomic_set(&dev_priv->irq_received, 0);
32888- atomic_set(&dev_priv->irq_emitted, 0);
32889+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32890+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
32891 init_waitqueue_head(&dev_priv->irq_queue);
32892 }
32893
32894diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
32895index 288fc50..c6092055 100644
32896--- a/drivers/gpu/drm/i915/dvo.h
32897+++ b/drivers/gpu/drm/i915/dvo.h
32898@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
32899 *
32900 * \return singly-linked list of modes or NULL if no modes found.
32901 */
32902- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
32903+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
32904
32905 /**
32906 * Clean up driver-specific bits of the output
32907 */
32908- void (*destroy) (struct intel_dvo_device *dvo);
32909+ void (* const destroy) (struct intel_dvo_device *dvo);
32910
32911 /**
32912 * Debugging hook to dump device registers to log file
32913 */
32914- void (*dump_regs)(struct intel_dvo_device *dvo);
32915+ void (* const dump_regs)(struct intel_dvo_device *dvo);
32916 };
32917
32918-extern struct intel_dvo_dev_ops sil164_ops;
32919-extern struct intel_dvo_dev_ops ch7xxx_ops;
32920-extern struct intel_dvo_dev_ops ivch_ops;
32921-extern struct intel_dvo_dev_ops tfp410_ops;
32922-extern struct intel_dvo_dev_ops ch7017_ops;
32923+extern const struct intel_dvo_dev_ops sil164_ops;
32924+extern const struct intel_dvo_dev_ops ch7xxx_ops;
32925+extern const struct intel_dvo_dev_ops ivch_ops;
32926+extern const struct intel_dvo_dev_ops tfp410_ops;
32927+extern const struct intel_dvo_dev_ops ch7017_ops;
32928
32929 #endif /* _INTEL_DVO_H */
32930diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
32931index 621815b..499d82e 100644
32932--- a/drivers/gpu/drm/i915/dvo_ch7017.c
32933+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
32934@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_dvo_device *dvo)
32935 }
32936 }
32937
32938-struct intel_dvo_dev_ops ch7017_ops = {
32939+const struct intel_dvo_dev_ops ch7017_ops = {
32940 .init = ch7017_init,
32941 .detect = ch7017_detect,
32942 .mode_valid = ch7017_mode_valid,
32943diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
32944index a9b8962..ac769ba 100644
32945--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
32946+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
32947@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_dvo_device *dvo)
32948 }
32949 }
32950
32951-struct intel_dvo_dev_ops ch7xxx_ops = {
32952+const struct intel_dvo_dev_ops ch7xxx_ops = {
32953 .init = ch7xxx_init,
32954 .detect = ch7xxx_detect,
32955 .mode_valid = ch7xxx_mode_valid,
32956diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
32957index aa176f9..ed2930c 100644
32958--- a/drivers/gpu/drm/i915/dvo_ivch.c
32959+++ b/drivers/gpu/drm/i915/dvo_ivch.c
32960@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dvo_device *dvo)
32961 }
32962 }
32963
32964-struct intel_dvo_dev_ops ivch_ops= {
32965+const struct intel_dvo_dev_ops ivch_ops= {
32966 .init = ivch_init,
32967 .dpms = ivch_dpms,
32968 .save = ivch_save,
32969diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
32970index e1c1f73..7dbebcf 100644
32971--- a/drivers/gpu/drm/i915/dvo_sil164.c
32972+++ b/drivers/gpu/drm/i915/dvo_sil164.c
32973@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_dvo_device *dvo)
32974 }
32975 }
32976
32977-struct intel_dvo_dev_ops sil164_ops = {
32978+const struct intel_dvo_dev_ops sil164_ops = {
32979 .init = sil164_init,
32980 .detect = sil164_detect,
32981 .mode_valid = sil164_mode_valid,
32982diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
32983index 16dce84..7e1b6f8 100644
32984--- a/drivers/gpu/drm/i915/dvo_tfp410.c
32985+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
32986@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_dvo_device *dvo)
32987 }
32988 }
32989
32990-struct intel_dvo_dev_ops tfp410_ops = {
32991+const struct intel_dvo_dev_ops tfp410_ops = {
32992 .init = tfp410_init,
32993 .detect = tfp410_detect,
32994 .mode_valid = tfp410_mode_valid,
32995diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32996index 7e859d6..7d1cf2b 100644
32997--- a/drivers/gpu/drm/i915/i915_debugfs.c
32998+++ b/drivers/gpu/drm/i915/i915_debugfs.c
32999@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33000 I915_READ(GTIMR));
33001 }
33002 seq_printf(m, "Interrupts received: %d\n",
33003- atomic_read(&dev_priv->irq_received));
33004+ atomic_read_unchecked(&dev_priv->irq_received));
33005 if (dev_priv->hw_status_page != NULL) {
33006 seq_printf(m, "Current sequence: %d\n",
33007 i915_get_gem_seqno(dev));
33008diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
33009index 5449239..7e4f68d 100644
33010--- a/drivers/gpu/drm/i915/i915_drv.c
33011+++ b/drivers/gpu/drm/i915/i915_drv.c
33012@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
33013 return i915_resume(dev);
33014 }
33015
33016-static struct vm_operations_struct i915_gem_vm_ops = {
33017+static const struct vm_operations_struct i915_gem_vm_ops = {
33018 .fault = i915_gem_fault,
33019 .open = drm_gem_vm_open,
33020 .close = drm_gem_vm_close,
33021diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33022index 97163f7..c24c7c7 100644
33023--- a/drivers/gpu/drm/i915/i915_drv.h
33024+++ b/drivers/gpu/drm/i915/i915_drv.h
33025@@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
33026 /* display clock increase/decrease */
33027 /* pll clock increase/decrease */
33028 /* clock gating init */
33029-};
33030+} __no_const;
33031
33032 typedef struct drm_i915_private {
33033 struct drm_device *dev;
33034@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
33035 int page_flipping;
33036
33037 wait_queue_head_t irq_queue;
33038- atomic_t irq_received;
33039+ atomic_unchecked_t irq_received;
33040 /** Protects user_irq_refcount and irq_mask_reg */
33041 spinlock_t user_irq_lock;
33042 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
33043diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
33044index 27a3074..eb3f959 100644
33045--- a/drivers/gpu/drm/i915/i915_gem.c
33046+++ b/drivers/gpu/drm/i915/i915_gem.c
33047@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
33048
33049 args->aper_size = dev->gtt_total;
33050 args->aper_available_size = (args->aper_size -
33051- atomic_read(&dev->pin_memory));
33052+ atomic_read_unchecked(&dev->pin_memory));
33053
33054 return 0;
33055 }
33056@@ -2058,7 +2058,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
33057
33058 if (obj_priv->gtt_space) {
33059 atomic_dec(&dev->gtt_count);
33060- atomic_sub(obj->size, &dev->gtt_memory);
33061+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
33062
33063 drm_mm_put_block(obj_priv->gtt_space);
33064 obj_priv->gtt_space = NULL;
33065@@ -2701,7 +2701,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
33066 goto search_free;
33067 }
33068 atomic_inc(&dev->gtt_count);
33069- atomic_add(obj->size, &dev->gtt_memory);
33070+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
33071
33072 /* Assert that the object is not currently in any GPU domain. As it
33073 * wasn't in the GTT, there shouldn't be any way it could have been in
33074@@ -3755,9 +3755,9 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
33075 "%d/%d gtt bytes\n",
33076 atomic_read(&dev->object_count),
33077 atomic_read(&dev->pin_count),
33078- atomic_read(&dev->object_memory),
33079- atomic_read(&dev->pin_memory),
33080- atomic_read(&dev->gtt_memory),
33081+ atomic_read_unchecked(&dev->object_memory),
33082+ atomic_read_unchecked(&dev->pin_memory),
33083+ atomic_read_unchecked(&dev->gtt_memory),
33084 dev->gtt_total);
33085 }
33086 goto err;
33087@@ -3989,7 +3989,7 @@ i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment)
33088 */
33089 if (obj_priv->pin_count == 1) {
33090 atomic_inc(&dev->pin_count);
33091- atomic_add(obj->size, &dev->pin_memory);
33092+ atomic_add_unchecked(obj->size, &dev->pin_memory);
33093 if (!obj_priv->active &&
33094 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
33095 !list_empty(&obj_priv->list))
33096@@ -4022,7 +4022,7 @@ i915_gem_object_unpin(struct drm_gem_object *obj)
33097 list_move_tail(&obj_priv->list,
33098 &dev_priv->mm.inactive_list);
33099 atomic_dec(&dev->pin_count);
33100- atomic_sub(obj->size, &dev->pin_memory);
33101+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
33102 }
33103 i915_verify_inactive(dev, __FILE__, __LINE__);
33104 }
33105diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33106index 63f28ad..f5469da 100644
33107--- a/drivers/gpu/drm/i915/i915_irq.c
33108+++ b/drivers/gpu/drm/i915/i915_irq.c
33109@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
33110 int irq_received;
33111 int ret = IRQ_NONE;
33112
33113- atomic_inc(&dev_priv->irq_received);
33114+ atomic_inc_unchecked(&dev_priv->irq_received);
33115
33116 if (IS_IGDNG(dev))
33117 return igdng_irq_handler(dev);
33118@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct drm_device * dev)
33119 {
33120 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33121
33122- atomic_set(&dev_priv->irq_received, 0);
33123+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33124
33125 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
33126 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
33127diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
33128index 5d9c6a7..d1b0e29 100644
33129--- a/drivers/gpu/drm/i915/intel_sdvo.c
33130+++ b/drivers/gpu/drm/i915/intel_sdvo.c
33131@@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
33132 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
33133
33134 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
33135- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33136+ pax_open_kernel();
33137+ *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33138+ pax_close_kernel();
33139
33140 /* Read the regs to test if we can talk to the device */
33141 for (i = 0; i < 0x40; i++) {
33142diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33143index be6c6b9..8615d9c 100644
33144--- a/drivers/gpu/drm/mga/mga_drv.h
33145+++ b/drivers/gpu/drm/mga/mga_drv.h
33146@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33147 u32 clear_cmd;
33148 u32 maccess;
33149
33150- atomic_t vbl_received; /**< Number of vblanks received. */
33151+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33152 wait_queue_head_t fence_queue;
33153- atomic_t last_fence_retired;
33154+ atomic_unchecked_t last_fence_retired;
33155 u32 next_fence_to_post;
33156
33157 unsigned int fb_cpp;
33158diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33159index daa6041..a28a5da 100644
33160--- a/drivers/gpu/drm/mga/mga_irq.c
33161+++ b/drivers/gpu/drm/mga/mga_irq.c
33162@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33163 if (crtc != 0)
33164 return 0;
33165
33166- return atomic_read(&dev_priv->vbl_received);
33167+ return atomic_read_unchecked(&dev_priv->vbl_received);
33168 }
33169
33170
33171@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33172 /* VBLANK interrupt */
33173 if (status & MGA_VLINEPEN) {
33174 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33175- atomic_inc(&dev_priv->vbl_received);
33176+ atomic_inc_unchecked(&dev_priv->vbl_received);
33177 drm_handle_vblank(dev, 0);
33178 handled = 1;
33179 }
33180@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33181 MGA_WRITE(MGA_PRIMEND, prim_end);
33182 }
33183
33184- atomic_inc(&dev_priv->last_fence_retired);
33185+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33186 DRM_WAKEUP(&dev_priv->fence_queue);
33187 handled = 1;
33188 }
33189@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
33190 * using fences.
33191 */
33192 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33193- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33194+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33195 - *sequence) <= (1 << 23)));
33196
33197 *sequence = cur_fence;
33198diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33199index 4c39a40..b22a9ea 100644
33200--- a/drivers/gpu/drm/r128/r128_cce.c
33201+++ b/drivers/gpu/drm/r128/r128_cce.c
33202@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
33203
33204 /* GH: Simple idle check.
33205 */
33206- atomic_set(&dev_priv->idle_count, 0);
33207+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33208
33209 /* We don't support anything other than bus-mastering ring mode,
33210 * but the ring can be in either AGP or PCI space for the ring
33211diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33212index 3c60829..4faf484 100644
33213--- a/drivers/gpu/drm/r128/r128_drv.h
33214+++ b/drivers/gpu/drm/r128/r128_drv.h
33215@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33216 int is_pci;
33217 unsigned long cce_buffers_offset;
33218
33219- atomic_t idle_count;
33220+ atomic_unchecked_t idle_count;
33221
33222 int page_flipping;
33223 int current_page;
33224 u32 crtc_offset;
33225 u32 crtc_offset_cntl;
33226
33227- atomic_t vbl_received;
33228+ atomic_unchecked_t vbl_received;
33229
33230 u32 color_fmt;
33231 unsigned int front_offset;
33232diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33233index 69810fb..97bf17a 100644
33234--- a/drivers/gpu/drm/r128/r128_irq.c
33235+++ b/drivers/gpu/drm/r128/r128_irq.c
33236@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33237 if (crtc != 0)
33238 return 0;
33239
33240- return atomic_read(&dev_priv->vbl_received);
33241+ return atomic_read_unchecked(&dev_priv->vbl_received);
33242 }
33243
33244 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33245@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33246 /* VBLANK interrupt */
33247 if (status & R128_CRTC_VBLANK_INT) {
33248 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33249- atomic_inc(&dev_priv->vbl_received);
33250+ atomic_inc_unchecked(&dev_priv->vbl_received);
33251 drm_handle_vblank(dev, 0);
33252 return IRQ_HANDLED;
33253 }
33254diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33255index af2665c..51922d2 100644
33256--- a/drivers/gpu/drm/r128/r128_state.c
33257+++ b/drivers/gpu/drm/r128/r128_state.c
33258@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_private_t * dev_priv,
33259
33260 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
33261 {
33262- if (atomic_read(&dev_priv->idle_count) == 0) {
33263+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
33264 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33265 } else {
33266- atomic_set(&dev_priv->idle_count, 0);
33267+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33268 }
33269 }
33270
33271diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
33272index dd72b91..8644b3c 100644
33273--- a/drivers/gpu/drm/radeon/atom.c
33274+++ b/drivers/gpu/drm/radeon/atom.c
33275@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
33276 char name[512];
33277 int i;
33278
33279+ pax_track_stack();
33280+
33281 ctx->card = card;
33282 ctx->bios = bios;
33283
33284diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33285index 0d79577..efaa7a5 100644
33286--- a/drivers/gpu/drm/radeon/mkregtable.c
33287+++ b/drivers/gpu/drm/radeon/mkregtable.c
33288@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33289 regex_t mask_rex;
33290 regmatch_t match[4];
33291 char buf[1024];
33292- size_t end;
33293+ long end;
33294 int len;
33295 int done = 0;
33296 int r;
33297 unsigned o;
33298 struct offset *offset;
33299 char last_reg_s[10];
33300- int last_reg;
33301+ unsigned long last_reg;
33302
33303 if (regcomp
33304 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33305diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
33306index 6735213..38c2c67 100644
33307--- a/drivers/gpu/drm/radeon/radeon.h
33308+++ b/drivers/gpu/drm/radeon/radeon.h
33309@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device *rdev);
33310 */
33311 struct radeon_fence_driver {
33312 uint32_t scratch_reg;
33313- atomic_t seq;
33314+ atomic_unchecked_t seq;
33315 uint32_t last_seq;
33316 unsigned long count_timeout;
33317 wait_queue_head_t queue;
33318@@ -640,7 +640,7 @@ struct radeon_asic {
33319 uint32_t offset, uint32_t obj_size);
33320 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
33321 void (*bandwidth_update)(struct radeon_device *rdev);
33322-};
33323+} __no_const;
33324
33325 /*
33326 * Asic structures
33327diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
33328index 4e928b9..d8b6008 100644
33329--- a/drivers/gpu/drm/radeon/radeon_atombios.c
33330+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
33331@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
33332 bool linkb;
33333 struct radeon_i2c_bus_rec ddc_bus;
33334
33335+ pax_track_stack();
33336+
33337 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33338
33339 if (data_offset == 0)
33340@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
33341 }
33342 }
33343
33344-struct bios_connector {
33345+static struct bios_connector {
33346 bool valid;
33347 uint16_t line_mux;
33348 uint16_t devices;
33349 int connector_type;
33350 struct radeon_i2c_bus_rec ddc_bus;
33351-};
33352+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33353
33354 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33355 drm_device
33356@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33357 uint8_t dac;
33358 union atom_supported_devices *supported_devices;
33359 int i, j;
33360- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33361
33362 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33363
33364diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
33365index 083a181..ccccae0 100644
33366--- a/drivers/gpu/drm/radeon/radeon_display.c
33367+++ b/drivers/gpu/drm/radeon/radeon_display.c
33368@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pll *pll,
33369
33370 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
33371 error = freq - current_freq;
33372- error = error < 0 ? 0xffffffff : error;
33373+ error = (int32_t)error < 0 ? 0xffffffff : error;
33374 } else
33375 error = abs(current_freq - freq);
33376 vco_diff = abs(vco - best_vco);
33377diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33378index 76e4070..193fa7f 100644
33379--- a/drivers/gpu/drm/radeon/radeon_drv.h
33380+++ b/drivers/gpu/drm/radeon/radeon_drv.h
33381@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
33382
33383 /* SW interrupt */
33384 wait_queue_head_t swi_queue;
33385- atomic_t swi_emitted;
33386+ atomic_unchecked_t swi_emitted;
33387 int vblank_crtc;
33388 uint32_t irq_enable_reg;
33389 uint32_t r500_disp_irq_reg;
33390diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
33391index 3beb26d..6ce9c4a 100644
33392--- a/drivers/gpu/drm/radeon/radeon_fence.c
33393+++ b/drivers/gpu/drm/radeon/radeon_fence.c
33394@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
33395 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
33396 return 0;
33397 }
33398- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
33399+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
33400 if (!rdev->cp.ready) {
33401 /* FIXME: cp is not running assume everythings is done right
33402 * away
33403@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
33404 return r;
33405 }
33406 WREG32(rdev->fence_drv.scratch_reg, 0);
33407- atomic_set(&rdev->fence_drv.seq, 0);
33408+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
33409 INIT_LIST_HEAD(&rdev->fence_drv.created);
33410 INIT_LIST_HEAD(&rdev->fence_drv.emited);
33411 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
33412diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33413index a1bf11d..4a123c0 100644
33414--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33415+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33416@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33417 request = compat_alloc_user_space(sizeof(*request));
33418 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33419 || __put_user(req32.param, &request->param)
33420- || __put_user((void __user *)(unsigned long)req32.value,
33421+ || __put_user((unsigned long)req32.value,
33422 &request->value))
33423 return -EFAULT;
33424
33425diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33426index b79ecc4..8dab92d 100644
33427--- a/drivers/gpu/drm/radeon/radeon_irq.c
33428+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33429@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33430 unsigned int ret;
33431 RING_LOCALS;
33432
33433- atomic_inc(&dev_priv->swi_emitted);
33434- ret = atomic_read(&dev_priv->swi_emitted);
33435+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33436+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33437
33438 BEGIN_RING(4);
33439 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33440@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33441 drm_radeon_private_t *dev_priv =
33442 (drm_radeon_private_t *) dev->dev_private;
33443
33444- atomic_set(&dev_priv->swi_emitted, 0);
33445+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33446 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33447
33448 dev->max_vblank_count = 0x001fffff;
33449diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33450index 4747910..48ca4b3 100644
33451--- a/drivers/gpu/drm/radeon/radeon_state.c
33452+++ b/drivers/gpu/drm/radeon/radeon_state.c
33453@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33454 {
33455 drm_radeon_private_t *dev_priv = dev->dev_private;
33456 drm_radeon_getparam_t *param = data;
33457- int value;
33458+ int value = 0;
33459
33460 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33461
33462diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33463index 1381e06..0e53b17 100644
33464--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33465+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33466@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_device *rdev)
33467 DRM_INFO("radeon: ttm finalized\n");
33468 }
33469
33470-static struct vm_operations_struct radeon_ttm_vm_ops;
33471-static const struct vm_operations_struct *ttm_vm_ops = NULL;
33472-
33473-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33474-{
33475- struct ttm_buffer_object *bo;
33476- int r;
33477-
33478- bo = (struct ttm_buffer_object *)vma->vm_private_data;
33479- if (bo == NULL) {
33480- return VM_FAULT_NOPAGE;
33481- }
33482- r = ttm_vm_ops->fault(vma, vmf);
33483- return r;
33484-}
33485-
33486 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33487 {
33488 struct drm_file *file_priv;
33489 struct radeon_device *rdev;
33490- int r;
33491
33492 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
33493 return drm_mmap(filp, vma);
33494@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33495
33496 file_priv = (struct drm_file *)filp->private_data;
33497 rdev = file_priv->minor->dev->dev_private;
33498- if (rdev == NULL) {
33499+ if (!rdev)
33500 return -EINVAL;
33501- }
33502- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33503- if (unlikely(r != 0)) {
33504- return r;
33505- }
33506- if (unlikely(ttm_vm_ops == NULL)) {
33507- ttm_vm_ops = vma->vm_ops;
33508- radeon_ttm_vm_ops = *ttm_vm_ops;
33509- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33510- }
33511- vma->vm_ops = &radeon_ttm_vm_ops;
33512- return 0;
33513+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33514 }
33515
33516
33517diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33518index b12ff76..0bd0c6e 100644
33519--- a/drivers/gpu/drm/radeon/rs690.c
33520+++ b/drivers/gpu/drm/radeon/rs690.c
33521@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33522 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33523 rdev->pm.sideport_bandwidth.full)
33524 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33525- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
33526+ read_delay_latency.full = rfixed_const(800 * 1000);
33527 read_delay_latency.full = rfixed_div(read_delay_latency,
33528 rdev->pm.igp_sideport_mclk);
33529+ a.full = rfixed_const(370);
33530+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
33531 } else {
33532 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33533 rdev->pm.k8_bandwidth.full)
33534diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
33535index 0ed436e..e6e7ce3 100644
33536--- a/drivers/gpu/drm/ttm/ttm_bo.c
33537+++ b/drivers/gpu/drm/ttm/ttm_bo.c
33538@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_attrs[] = {
33539 NULL
33540 };
33541
33542-static struct sysfs_ops ttm_bo_global_ops = {
33543+static const struct sysfs_ops ttm_bo_global_ops = {
33544 .show = &ttm_bo_global_show
33545 };
33546
33547diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33548index 1c040d0..f9e4af8 100644
33549--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
33550+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33551@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33552 {
33553 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
33554 vma->vm_private_data;
33555- struct ttm_bo_device *bdev = bo->bdev;
33556+ struct ttm_bo_device *bdev;
33557 unsigned long bus_base;
33558 unsigned long bus_offset;
33559 unsigned long bus_size;
33560@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33561 unsigned long address = (unsigned long)vmf->virtual_address;
33562 int retval = VM_FAULT_NOPAGE;
33563
33564+ if (!bo)
33565+ return VM_FAULT_NOPAGE;
33566+ bdev = bo->bdev;
33567+
33568 /*
33569 * Work around locking order reversal in fault / nopfn
33570 * between mmap_sem and bo_reserve: Perform a trylock operation
33571diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
33572index b170071..28ae90e 100644
33573--- a/drivers/gpu/drm/ttm/ttm_global.c
33574+++ b/drivers/gpu/drm/ttm/ttm_global.c
33575@@ -36,7 +36,7 @@
33576 struct ttm_global_item {
33577 struct mutex mutex;
33578 void *object;
33579- int refcount;
33580+ atomic_t refcount;
33581 };
33582
33583 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
33584@@ -49,7 +49,7 @@ void ttm_global_init(void)
33585 struct ttm_global_item *item = &glob[i];
33586 mutex_init(&item->mutex);
33587 item->object = NULL;
33588- item->refcount = 0;
33589+ atomic_set(&item->refcount, 0);
33590 }
33591 }
33592
33593@@ -59,7 +59,7 @@ void ttm_global_release(void)
33594 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
33595 struct ttm_global_item *item = &glob[i];
33596 BUG_ON(item->object != NULL);
33597- BUG_ON(item->refcount != 0);
33598+ BUG_ON(atomic_read(&item->refcount) != 0);
33599 }
33600 }
33601
33602@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33603 void *object;
33604
33605 mutex_lock(&item->mutex);
33606- if (item->refcount == 0) {
33607+ if (atomic_read(&item->refcount) == 0) {
33608 item->object = kzalloc(ref->size, GFP_KERNEL);
33609 if (unlikely(item->object == NULL)) {
33610 ret = -ENOMEM;
33611@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33612 goto out_err;
33613
33614 }
33615- ++item->refcount;
33616+ atomic_inc(&item->refcount);
33617 ref->object = item->object;
33618 object = item->object;
33619 mutex_unlock(&item->mutex);
33620@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_global_reference *ref)
33621 struct ttm_global_item *item = &glob[ref->global_type];
33622
33623 mutex_lock(&item->mutex);
33624- BUG_ON(item->refcount == 0);
33625+ BUG_ON(atomic_read(&item->refcount) == 0);
33626 BUG_ON(ref->object != item->object);
33627- if (--item->refcount == 0) {
33628+ if (atomic_dec_and_test(&item->refcount)) {
33629 ref->release(ref);
33630 item->object = NULL;
33631 }
33632diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
33633index 072c281..d8ef483 100644
33634--- a/drivers/gpu/drm/ttm/ttm_memory.c
33635+++ b/drivers/gpu/drm/ttm/ttm_memory.c
33636@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_attrs[] = {
33637 NULL
33638 };
33639
33640-static struct sysfs_ops ttm_mem_zone_ops = {
33641+static const struct sysfs_ops ttm_mem_zone_ops = {
33642 .show = &ttm_mem_zone_show,
33643 .store = &ttm_mem_zone_store
33644 };
33645diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33646index cafcb84..b8e66cc 100644
33647--- a/drivers/gpu/drm/via/via_drv.h
33648+++ b/drivers/gpu/drm/via/via_drv.h
33649@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33650 typedef uint32_t maskarray_t[5];
33651
33652 typedef struct drm_via_irq {
33653- atomic_t irq_received;
33654+ atomic_unchecked_t irq_received;
33655 uint32_t pending_mask;
33656 uint32_t enable_mask;
33657 wait_queue_head_t irq_queue;
33658@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33659 struct timeval last_vblank;
33660 int last_vblank_valid;
33661 unsigned usec_per_vblank;
33662- atomic_t vbl_received;
33663+ atomic_unchecked_t vbl_received;
33664 drm_via_state_t hc_state;
33665 char pci_buf[VIA_PCI_BUF_SIZE];
33666 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33667diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33668index 5935b88..127a8a6 100644
33669--- a/drivers/gpu/drm/via/via_irq.c
33670+++ b/drivers/gpu/drm/via/via_irq.c
33671@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33672 if (crtc != 0)
33673 return 0;
33674
33675- return atomic_read(&dev_priv->vbl_received);
33676+ return atomic_read_unchecked(&dev_priv->vbl_received);
33677 }
33678
33679 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33680@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33681
33682 status = VIA_READ(VIA_REG_INTERRUPT);
33683 if (status & VIA_IRQ_VBLANK_PENDING) {
33684- atomic_inc(&dev_priv->vbl_received);
33685- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33686+ atomic_inc_unchecked(&dev_priv->vbl_received);
33687+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33688 do_gettimeofday(&cur_vblank);
33689 if (dev_priv->last_vblank_valid) {
33690 dev_priv->usec_per_vblank =
33691@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33692 dev_priv->last_vblank = cur_vblank;
33693 dev_priv->last_vblank_valid = 1;
33694 }
33695- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33696+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33697 DRM_DEBUG("US per vblank is: %u\n",
33698 dev_priv->usec_per_vblank);
33699 }
33700@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33701
33702 for (i = 0; i < dev_priv->num_irqs; ++i) {
33703 if (status & cur_irq->pending_mask) {
33704- atomic_inc(&cur_irq->irq_received);
33705+ atomic_inc_unchecked(&cur_irq->irq_received);
33706 DRM_WAKEUP(&cur_irq->irq_queue);
33707 handled = 1;
33708 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
33709@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequenc
33710 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33711 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33712 masks[irq][4]));
33713- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33714+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33715 } else {
33716 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33717 (((cur_irq_sequence =
33718- atomic_read(&cur_irq->irq_received)) -
33719+ atomic_read_unchecked(&cur_irq->irq_received)) -
33720 *sequence) <= (1 << 23)));
33721 }
33722 *sequence = cur_irq_sequence;
33723@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct drm_device * dev)
33724 }
33725
33726 for (i = 0; i < dev_priv->num_irqs; ++i) {
33727- atomic_set(&cur_irq->irq_received, 0);
33728+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33729 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33730 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33731 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33732@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33733 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33734 case VIA_IRQ_RELATIVE:
33735 irqwait->request.sequence +=
33736- atomic_read(&cur_irq->irq_received);
33737+ atomic_read_unchecked(&cur_irq->irq_received);
33738 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33739 case VIA_IRQ_ABSOLUTE:
33740 break;
33741diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
33742index aa8688d..6a0140c 100644
33743--- a/drivers/gpu/vga/vgaarb.c
33744+++ b/drivers/gpu/vga/vgaarb.c
33745@@ -894,14 +894,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
33746 uc = &priv->cards[i];
33747 }
33748
33749- if (!uc)
33750- return -EINVAL;
33751+ if (!uc) {
33752+ ret_val = -EINVAL;
33753+ goto done;
33754+ }
33755
33756- if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
33757- return -EINVAL;
33758+ if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
33759+ ret_val = -EINVAL;
33760+ goto done;
33761+ }
33762
33763- if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
33764- return -EINVAL;
33765+ if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
33766+ ret_val = -EINVAL;
33767+ goto done;
33768+ }
33769
33770 vga_put(pdev, io_state);
33771
33772diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33773index f3f1415..e561d90 100644
33774--- a/drivers/hid/hid-core.c
33775+++ b/drivers/hid/hid-core.c
33776@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device *hdev)
33777
33778 int hid_add_device(struct hid_device *hdev)
33779 {
33780- static atomic_t id = ATOMIC_INIT(0);
33781+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33782 int ret;
33783
33784 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33785@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hdev)
33786 /* XXX hack, any other cleaner solution after the driver core
33787 * is converted to allow more than 20 bytes as the device name? */
33788 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33789- hdev->vendor, hdev->product, atomic_inc_return(&id));
33790+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33791
33792 ret = device_add(&hdev->dev);
33793 if (!ret)
33794diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33795index 8b6ee24..70f657d 100644
33796--- a/drivers/hid/usbhid/hiddev.c
33797+++ b/drivers/hid/usbhid/hiddev.c
33798@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33799 return put_user(HID_VERSION, (int __user *)arg);
33800
33801 case HIDIOCAPPLICATION:
33802- if (arg < 0 || arg >= hid->maxapplication)
33803+ if (arg >= hid->maxapplication)
33804 return -EINVAL;
33805
33806 for (i = 0; i < hid->maxcollection; i++)
33807diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
33808index 5d5ed69..f40533e 100644
33809--- a/drivers/hwmon/lis3lv02d.c
33810+++ b/drivers/hwmon/lis3lv02d.c
33811@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
33812 * the lid is closed. This leads to interrupts as soon as a little move
33813 * is done.
33814 */
33815- atomic_inc(&lis3_dev.count);
33816+ atomic_inc_unchecked(&lis3_dev.count);
33817
33818 wake_up_interruptible(&lis3_dev.misc_wait);
33819 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33820@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33821 if (test_and_set_bit(0, &lis3_dev.misc_opened))
33822 return -EBUSY; /* already open */
33823
33824- atomic_set(&lis3_dev.count, 0);
33825+ atomic_set_unchecked(&lis3_dev.count, 0);
33826
33827 /*
33828 * The sensor can generate interrupts for free-fall and direction
33829@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33830 add_wait_queue(&lis3_dev.misc_wait, &wait);
33831 while (true) {
33832 set_current_state(TASK_INTERRUPTIBLE);
33833- data = atomic_xchg(&lis3_dev.count, 0);
33834+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33835 if (data)
33836 break;
33837
33838@@ -244,7 +244,7 @@ out:
33839 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33840 {
33841 poll_wait(file, &lis3_dev.misc_wait, wait);
33842- if (atomic_read(&lis3_dev.count))
33843+ if (atomic_read_unchecked(&lis3_dev.count))
33844 return POLLIN | POLLRDNORM;
33845 return 0;
33846 }
33847diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
33848index 7cdd76f..fe0efdf 100644
33849--- a/drivers/hwmon/lis3lv02d.h
33850+++ b/drivers/hwmon/lis3lv02d.h
33851@@ -201,7 +201,7 @@ struct lis3lv02d {
33852
33853 struct input_polled_dev *idev; /* input device */
33854 struct platform_device *pdev; /* platform device */
33855- atomic_t count; /* interrupt count after last read */
33856+ atomic_unchecked_t count; /* interrupt count after last read */
33857 int xcalib; /* calibrated null value for x */
33858 int ycalib; /* calibrated null value for y */
33859 int zcalib; /* calibrated null value for z */
33860diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33861index 2040507..706ec1e 100644
33862--- a/drivers/hwmon/sht15.c
33863+++ b/drivers/hwmon/sht15.c
33864@@ -112,7 +112,7 @@ struct sht15_data {
33865 int supply_uV;
33866 int supply_uV_valid;
33867 struct work_struct update_supply_work;
33868- atomic_t interrupt_handled;
33869+ atomic_unchecked_t interrupt_handled;
33870 };
33871
33872 /**
33873@@ -245,13 +245,13 @@ static inline int sht15_update_single_val(struct sht15_data *data,
33874 return ret;
33875
33876 gpio_direction_input(data->pdata->gpio_data);
33877- atomic_set(&data->interrupt_handled, 0);
33878+ atomic_set_unchecked(&data->interrupt_handled, 0);
33879
33880 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33881 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33882 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33883 /* Only relevant if the interrupt hasn't occured. */
33884- if (!atomic_read(&data->interrupt_handled))
33885+ if (!atomic_read_unchecked(&data->interrupt_handled))
33886 schedule_work(&data->read_work);
33887 }
33888 ret = wait_event_timeout(data->wait_queue,
33889@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33890 struct sht15_data *data = d;
33891 /* First disable the interrupt */
33892 disable_irq_nosync(irq);
33893- atomic_inc(&data->interrupt_handled);
33894+ atomic_inc_unchecked(&data->interrupt_handled);
33895 /* Then schedule a reading work struct */
33896 if (data->flag != SHT15_READING_NOTHING)
33897 schedule_work(&data->read_work);
33898@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33899 here as could have gone low in meantime so verify
33900 it hasn't!
33901 */
33902- atomic_set(&data->interrupt_handled, 0);
33903+ atomic_set_unchecked(&data->interrupt_handled, 0);
33904 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33905 /* If still not occured or another handler has been scheduled */
33906 if (gpio_get_value(data->pdata->gpio_data)
33907- || atomic_read(&data->interrupt_handled))
33908+ || atomic_read_unchecked(&data->interrupt_handled))
33909 return;
33910 }
33911 /* Read the data back from the device */
33912diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
33913index 97851c5..cb40626 100644
33914--- a/drivers/hwmon/w83791d.c
33915+++ b/drivers/hwmon/w83791d.c
33916@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_client *client, int kind,
33917 struct i2c_board_info *info);
33918 static int w83791d_remove(struct i2c_client *client);
33919
33920-static int w83791d_read(struct i2c_client *client, u8 register);
33921-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
33922+static int w83791d_read(struct i2c_client *client, u8 reg);
33923+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
33924 static struct w83791d_data *w83791d_update_device(struct device *dev);
33925
33926 #ifdef DEBUG
33927diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33928index 378fcb5..5e91fa8 100644
33929--- a/drivers/i2c/busses/i2c-amd756-s4882.c
33930+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33931@@ -43,7 +43,7 @@
33932 extern struct i2c_adapter amd756_smbus;
33933
33934 static struct i2c_adapter *s4882_adapter;
33935-static struct i2c_algorithm *s4882_algo;
33936+static i2c_algorithm_no_const *s4882_algo;
33937
33938 /* Wrapper access functions for multiplexed SMBus */
33939 static DEFINE_MUTEX(amd756_lock);
33940diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33941index 29015eb..af2d8e9 100644
33942--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33943+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33944@@ -41,7 +41,7 @@
33945 extern struct i2c_adapter *nforce2_smbus;
33946
33947 static struct i2c_adapter *s4985_adapter;
33948-static struct i2c_algorithm *s4985_algo;
33949+static i2c_algorithm_no_const *s4985_algo;
33950
33951 /* Wrapper access functions for multiplexed SMBus */
33952 static DEFINE_MUTEX(nforce2_lock);
33953diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
33954index 878f8ec..12376fc 100644
33955--- a/drivers/ide/aec62xx.c
33956+++ b/drivers/ide/aec62xx.c
33957@@ -180,7 +180,7 @@ static const struct ide_port_ops atp86x_port_ops = {
33958 .cable_detect = atp86x_cable_detect,
33959 };
33960
33961-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
33962+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
33963 { /* 0: AEC6210 */
33964 .name = DRV_NAME,
33965 .init_chipset = init_chipset_aec62xx,
33966diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
33967index e59b6de..4b4fc65 100644
33968--- a/drivers/ide/alim15x3.c
33969+++ b/drivers/ide/alim15x3.c
33970@@ -509,7 +509,7 @@ static const struct ide_dma_ops ali_dma_ops = {
33971 .dma_sff_read_status = ide_dma_sff_read_status,
33972 };
33973
33974-static const struct ide_port_info ali15x3_chipset __devinitdata = {
33975+static const struct ide_port_info ali15x3_chipset __devinitconst = {
33976 .name = DRV_NAME,
33977 .init_chipset = init_chipset_ali15x3,
33978 .init_hwif = init_hwif_ali15x3,
33979diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
33980index 628cd2e..087a414 100644
33981--- a/drivers/ide/amd74xx.c
33982+++ b/drivers/ide/amd74xx.c
33983@@ -221,7 +221,7 @@ static const struct ide_port_ops amd_port_ops = {
33984 .udma_mask = udma, \
33985 }
33986
33987-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
33988+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
33989 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
33990 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
33991 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
33992diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
33993index 837322b..837fd71 100644
33994--- a/drivers/ide/atiixp.c
33995+++ b/drivers/ide/atiixp.c
33996@@ -137,7 +137,7 @@ static const struct ide_port_ops atiixp_port_ops = {
33997 .cable_detect = atiixp_cable_detect,
33998 };
33999
34000-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
34001+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
34002 { /* 0: IXP200/300/400/700 */
34003 .name = DRV_NAME,
34004 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
34005diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
34006index ca0c46f..d55318a 100644
34007--- a/drivers/ide/cmd64x.c
34008+++ b/drivers/ide/cmd64x.c
34009@@ -372,7 +372,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
34010 .dma_sff_read_status = ide_dma_sff_read_status,
34011 };
34012
34013-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
34014+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
34015 { /* 0: CMD643 */
34016 .name = DRV_NAME,
34017 .init_chipset = init_chipset_cmd64x,
34018diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
34019index 09f98ed..cebc5bc 100644
34020--- a/drivers/ide/cs5520.c
34021+++ b/drivers/ide/cs5520.c
34022@@ -93,7 +93,7 @@ static const struct ide_port_ops cs5520_port_ops = {
34023 .set_dma_mode = cs5520_set_dma_mode,
34024 };
34025
34026-static const struct ide_port_info cyrix_chipset __devinitdata = {
34027+static const struct ide_port_info cyrix_chipset __devinitconst = {
34028 .name = DRV_NAME,
34029 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
34030 .port_ops = &cs5520_port_ops,
34031diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
34032index 40bf05e..7d58ca0 100644
34033--- a/drivers/ide/cs5530.c
34034+++ b/drivers/ide/cs5530.c
34035@@ -244,7 +244,7 @@ static const struct ide_port_ops cs5530_port_ops = {
34036 .udma_filter = cs5530_udma_filter,
34037 };
34038
34039-static const struct ide_port_info cs5530_chipset __devinitdata = {
34040+static const struct ide_port_info cs5530_chipset __devinitconst = {
34041 .name = DRV_NAME,
34042 .init_chipset = init_chipset_cs5530,
34043 .init_hwif = init_hwif_cs5530,
34044diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
34045index 983d957..53e6172 100644
34046--- a/drivers/ide/cs5535.c
34047+++ b/drivers/ide/cs5535.c
34048@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
34049 .cable_detect = cs5535_cable_detect,
34050 };
34051
34052-static const struct ide_port_info cs5535_chipset __devinitdata = {
34053+static const struct ide_port_info cs5535_chipset __devinitconst = {
34054 .name = DRV_NAME,
34055 .port_ops = &cs5535_port_ops,
34056 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
34057diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
34058index 74fc540..8e933d8 100644
34059--- a/drivers/ide/cy82c693.c
34060+++ b/drivers/ide/cy82c693.c
34061@@ -288,7 +288,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
34062 .set_dma_mode = cy82c693_set_dma_mode,
34063 };
34064
34065-static const struct ide_port_info cy82c693_chipset __devinitdata = {
34066+static const struct ide_port_info cy82c693_chipset __devinitconst = {
34067 .name = DRV_NAME,
34068 .init_iops = init_iops_cy82c693,
34069 .port_ops = &cy82c693_port_ops,
34070diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
34071index 7ce68ef..e78197d 100644
34072--- a/drivers/ide/hpt366.c
34073+++ b/drivers/ide/hpt366.c
34074@@ -507,7 +507,7 @@ static struct hpt_timings hpt37x_timings = {
34075 }
34076 };
34077
34078-static const struct hpt_info hpt36x __devinitdata = {
34079+static const struct hpt_info hpt36x __devinitconst = {
34080 .chip_name = "HPT36x",
34081 .chip_type = HPT36x,
34082 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
34083@@ -515,7 +515,7 @@ static const struct hpt_info hpt36x __devinitdata = {
34084 .timings = &hpt36x_timings
34085 };
34086
34087-static const struct hpt_info hpt370 __devinitdata = {
34088+static const struct hpt_info hpt370 __devinitconst = {
34089 .chip_name = "HPT370",
34090 .chip_type = HPT370,
34091 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34092@@ -523,7 +523,7 @@ static const struct hpt_info hpt370 __devinitdata = {
34093 .timings = &hpt37x_timings
34094 };
34095
34096-static const struct hpt_info hpt370a __devinitdata = {
34097+static const struct hpt_info hpt370a __devinitconst = {
34098 .chip_name = "HPT370A",
34099 .chip_type = HPT370A,
34100 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34101@@ -531,7 +531,7 @@ static const struct hpt_info hpt370a __devinitdata = {
34102 .timings = &hpt37x_timings
34103 };
34104
34105-static const struct hpt_info hpt374 __devinitdata = {
34106+static const struct hpt_info hpt374 __devinitconst = {
34107 .chip_name = "HPT374",
34108 .chip_type = HPT374,
34109 .udma_mask = ATA_UDMA5,
34110@@ -539,7 +539,7 @@ static const struct hpt_info hpt374 __devinitdata = {
34111 .timings = &hpt37x_timings
34112 };
34113
34114-static const struct hpt_info hpt372 __devinitdata = {
34115+static const struct hpt_info hpt372 __devinitconst = {
34116 .chip_name = "HPT372",
34117 .chip_type = HPT372,
34118 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34119@@ -547,7 +547,7 @@ static const struct hpt_info hpt372 __devinitdata = {
34120 .timings = &hpt37x_timings
34121 };
34122
34123-static const struct hpt_info hpt372a __devinitdata = {
34124+static const struct hpt_info hpt372a __devinitconst = {
34125 .chip_name = "HPT372A",
34126 .chip_type = HPT372A,
34127 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34128@@ -555,7 +555,7 @@ static const struct hpt_info hpt372a __devinitdata = {
34129 .timings = &hpt37x_timings
34130 };
34131
34132-static const struct hpt_info hpt302 __devinitdata = {
34133+static const struct hpt_info hpt302 __devinitconst = {
34134 .chip_name = "HPT302",
34135 .chip_type = HPT302,
34136 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34137@@ -563,7 +563,7 @@ static const struct hpt_info hpt302 __devinitdata = {
34138 .timings = &hpt37x_timings
34139 };
34140
34141-static const struct hpt_info hpt371 __devinitdata = {
34142+static const struct hpt_info hpt371 __devinitconst = {
34143 .chip_name = "HPT371",
34144 .chip_type = HPT371,
34145 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34146@@ -571,7 +571,7 @@ static const struct hpt_info hpt371 __devinitdata = {
34147 .timings = &hpt37x_timings
34148 };
34149
34150-static const struct hpt_info hpt372n __devinitdata = {
34151+static const struct hpt_info hpt372n __devinitconst = {
34152 .chip_name = "HPT372N",
34153 .chip_type = HPT372N,
34154 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34155@@ -579,7 +579,7 @@ static const struct hpt_info hpt372n __devinitdata = {
34156 .timings = &hpt37x_timings
34157 };
34158
34159-static const struct hpt_info hpt302n __devinitdata = {
34160+static const struct hpt_info hpt302n __devinitconst = {
34161 .chip_name = "HPT302N",
34162 .chip_type = HPT302N,
34163 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34164@@ -587,7 +587,7 @@ static const struct hpt_info hpt302n __devinitdata = {
34165 .timings = &hpt37x_timings
34166 };
34167
34168-static const struct hpt_info hpt371n __devinitdata = {
34169+static const struct hpt_info hpt371n __devinitconst = {
34170 .chip_name = "HPT371N",
34171 .chip_type = HPT371N,
34172 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34173@@ -1422,7 +1422,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
34174 .dma_sff_read_status = ide_dma_sff_read_status,
34175 };
34176
34177-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
34178+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
34179 { /* 0: HPT36x */
34180 .name = DRV_NAME,
34181 .init_chipset = init_chipset_hpt366,
34182diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34183index 2de76cc..74186a1 100644
34184--- a/drivers/ide/ide-cd.c
34185+++ b/drivers/ide/ide-cd.c
34186@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34187 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34188 if ((unsigned long)buf & alignment
34189 || blk_rq_bytes(rq) & q->dma_pad_mask
34190- || object_is_on_stack(buf))
34191+ || object_starts_on_stack(buf))
34192 drive->dma = 0;
34193 }
34194 }
34195diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
34196index fefbdfc..62ff465 100644
34197--- a/drivers/ide/ide-floppy.c
34198+++ b/drivers/ide/ide-floppy.c
34199@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
34200 u8 pc_buf[256], header_len, desc_cnt;
34201 int i, rc = 1, blocks, length;
34202
34203+ pax_track_stack();
34204+
34205 ide_debug_log(IDE_DBG_FUNC, "enter");
34206
34207 drive->bios_cyl = 0;
34208diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
34209index 39d4e01..11538ce 100644
34210--- a/drivers/ide/ide-pci-generic.c
34211+++ b/drivers/ide/ide-pci-generic.c
34212@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
34213 .udma_mask = ATA_UDMA6, \
34214 }
34215
34216-static const struct ide_port_info generic_chipsets[] __devinitdata = {
34217+static const struct ide_port_info generic_chipsets[] __devinitconst = {
34218 /* 0: Unknown */
34219 DECLARE_GENERIC_PCI_DEV(0),
34220
34221diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
34222index 0d266a5..aaca790 100644
34223--- a/drivers/ide/it8172.c
34224+++ b/drivers/ide/it8172.c
34225@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
34226 .set_dma_mode = it8172_set_dma_mode,
34227 };
34228
34229-static const struct ide_port_info it8172_port_info __devinitdata = {
34230+static const struct ide_port_info it8172_port_info __devinitconst = {
34231 .name = DRV_NAME,
34232 .port_ops = &it8172_port_ops,
34233 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
34234diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
34235index 4797616..4be488a 100644
34236--- a/drivers/ide/it8213.c
34237+++ b/drivers/ide/it8213.c
34238@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
34239 .cable_detect = it8213_cable_detect,
34240 };
34241
34242-static const struct ide_port_info it8213_chipset __devinitdata = {
34243+static const struct ide_port_info it8213_chipset __devinitconst = {
34244 .name = DRV_NAME,
34245 .enablebits = { {0x41, 0x80, 0x80} },
34246 .port_ops = &it8213_port_ops,
34247diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
34248index 51aa745..146ee60 100644
34249--- a/drivers/ide/it821x.c
34250+++ b/drivers/ide/it821x.c
34251@@ -627,7 +627,7 @@ static const struct ide_port_ops it821x_port_ops = {
34252 .cable_detect = it821x_cable_detect,
34253 };
34254
34255-static const struct ide_port_info it821x_chipset __devinitdata = {
34256+static const struct ide_port_info it821x_chipset __devinitconst = {
34257 .name = DRV_NAME,
34258 .init_chipset = init_chipset_it821x,
34259 .init_hwif = init_hwif_it821x,
34260diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
34261index bf2be64..9270098 100644
34262--- a/drivers/ide/jmicron.c
34263+++ b/drivers/ide/jmicron.c
34264@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
34265 .cable_detect = jmicron_cable_detect,
34266 };
34267
34268-static const struct ide_port_info jmicron_chipset __devinitdata = {
34269+static const struct ide_port_info jmicron_chipset __devinitconst = {
34270 .name = DRV_NAME,
34271 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
34272 .port_ops = &jmicron_port_ops,
34273diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
34274index 95327a2..73f78d8 100644
34275--- a/drivers/ide/ns87415.c
34276+++ b/drivers/ide/ns87415.c
34277@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
34278 .dma_sff_read_status = superio_dma_sff_read_status,
34279 };
34280
34281-static const struct ide_port_info ns87415_chipset __devinitdata = {
34282+static const struct ide_port_info ns87415_chipset __devinitconst = {
34283 .name = DRV_NAME,
34284 .init_hwif = init_hwif_ns87415,
34285 .tp_ops = &ns87415_tp_ops,
34286diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
34287index f1d70d6..e1de05b 100644
34288--- a/drivers/ide/opti621.c
34289+++ b/drivers/ide/opti621.c
34290@@ -202,7 +202,7 @@ static const struct ide_port_ops opti621_port_ops = {
34291 .set_pio_mode = opti621_set_pio_mode,
34292 };
34293
34294-static const struct ide_port_info opti621_chipset __devinitdata = {
34295+static const struct ide_port_info opti621_chipset __devinitconst = {
34296 .name = DRV_NAME,
34297 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
34298 .port_ops = &opti621_port_ops,
34299diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
34300index 65ba823..7311f4d 100644
34301--- a/drivers/ide/pdc202xx_new.c
34302+++ b/drivers/ide/pdc202xx_new.c
34303@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
34304 .udma_mask = udma, \
34305 }
34306
34307-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
34308+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
34309 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
34310 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
34311 };
34312diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
34313index cb812f3..af816ef 100644
34314--- a/drivers/ide/pdc202xx_old.c
34315+++ b/drivers/ide/pdc202xx_old.c
34316@@ -285,7 +285,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
34317 .max_sectors = sectors, \
34318 }
34319
34320-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
34321+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
34322 { /* 0: PDC20246 */
34323 .name = DRV_NAME,
34324 .init_chipset = init_chipset_pdc202xx,
34325diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
34326index bf14f39..15c4b98 100644
34327--- a/drivers/ide/piix.c
34328+++ b/drivers/ide/piix.c
34329@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
34330 .udma_mask = udma, \
34331 }
34332
34333-static const struct ide_port_info piix_pci_info[] __devinitdata = {
34334+static const struct ide_port_info piix_pci_info[] __devinitconst = {
34335 /* 0: MPIIX */
34336 { /*
34337 * MPIIX actually has only a single IDE channel mapped to
34338diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
34339index a6414a8..c04173e 100644
34340--- a/drivers/ide/rz1000.c
34341+++ b/drivers/ide/rz1000.c
34342@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
34343 }
34344 }
34345
34346-static const struct ide_port_info rz1000_chipset __devinitdata = {
34347+static const struct ide_port_info rz1000_chipset __devinitconst = {
34348 .name = DRV_NAME,
34349 .host_flags = IDE_HFLAG_NO_DMA,
34350 };
34351diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
34352index d467478..9203942 100644
34353--- a/drivers/ide/sc1200.c
34354+++ b/drivers/ide/sc1200.c
34355@@ -290,7 +290,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
34356 .dma_sff_read_status = ide_dma_sff_read_status,
34357 };
34358
34359-static const struct ide_port_info sc1200_chipset __devinitdata = {
34360+static const struct ide_port_info sc1200_chipset __devinitconst = {
34361 .name = DRV_NAME,
34362 .port_ops = &sc1200_port_ops,
34363 .dma_ops = &sc1200_dma_ops,
34364diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
34365index 1104bb3..59c5194 100644
34366--- a/drivers/ide/scc_pata.c
34367+++ b/drivers/ide/scc_pata.c
34368@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
34369 .dma_sff_read_status = scc_dma_sff_read_status,
34370 };
34371
34372-static const struct ide_port_info scc_chipset __devinitdata = {
34373+static const struct ide_port_info scc_chipset __devinitconst = {
34374 .name = "sccIDE",
34375 .init_iops = init_iops_scc,
34376 .init_dma = scc_init_dma,
34377diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
34378index b6554ef..6cc2cc3 100644
34379--- a/drivers/ide/serverworks.c
34380+++ b/drivers/ide/serverworks.c
34381@@ -353,7 +353,7 @@ static const struct ide_port_ops svwks_port_ops = {
34382 .cable_detect = svwks_cable_detect,
34383 };
34384
34385-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
34386+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
34387 { /* 0: OSB4 */
34388 .name = DRV_NAME,
34389 .init_chipset = init_chipset_svwks,
34390diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
34391index ab3db61..afed580 100644
34392--- a/drivers/ide/setup-pci.c
34393+++ b/drivers/ide/setup-pci.c
34394@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
34395 int ret, i, n_ports = dev2 ? 4 : 2;
34396 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
34397
34398+ pax_track_stack();
34399+
34400 for (i = 0; i < n_ports / 2; i++) {
34401 ret = ide_setup_pci_controller(pdev[i], d, !i);
34402 if (ret < 0)
34403diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
34404index d95df52..0b03a39 100644
34405--- a/drivers/ide/siimage.c
34406+++ b/drivers/ide/siimage.c
34407@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
34408 .udma_mask = ATA_UDMA6, \
34409 }
34410
34411-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
34412+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
34413 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
34414 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
34415 };
34416diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
34417index 3b88eba..ca8699d 100644
34418--- a/drivers/ide/sis5513.c
34419+++ b/drivers/ide/sis5513.c
34420@@ -561,7 +561,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
34421 .cable_detect = sis_cable_detect,
34422 };
34423
34424-static const struct ide_port_info sis5513_chipset __devinitdata = {
34425+static const struct ide_port_info sis5513_chipset __devinitconst = {
34426 .name = DRV_NAME,
34427 .init_chipset = init_chipset_sis5513,
34428 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
34429diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
34430index d698da4..fca42a4 100644
34431--- a/drivers/ide/sl82c105.c
34432+++ b/drivers/ide/sl82c105.c
34433@@ -319,7 +319,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
34434 .dma_sff_read_status = ide_dma_sff_read_status,
34435 };
34436
34437-static const struct ide_port_info sl82c105_chipset __devinitdata = {
34438+static const struct ide_port_info sl82c105_chipset __devinitconst = {
34439 .name = DRV_NAME,
34440 .init_chipset = init_chipset_sl82c105,
34441 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
34442diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
34443index 1ccfb40..83d5779 100644
34444--- a/drivers/ide/slc90e66.c
34445+++ b/drivers/ide/slc90e66.c
34446@@ -131,7 +131,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
34447 .cable_detect = slc90e66_cable_detect,
34448 };
34449
34450-static const struct ide_port_info slc90e66_chipset __devinitdata = {
34451+static const struct ide_port_info slc90e66_chipset __devinitconst = {
34452 .name = DRV_NAME,
34453 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
34454 .port_ops = &slc90e66_port_ops,
34455diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
34456index 05a93d6..5f9e325 100644
34457--- a/drivers/ide/tc86c001.c
34458+++ b/drivers/ide/tc86c001.c
34459@@ -190,7 +190,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
34460 .dma_sff_read_status = ide_dma_sff_read_status,
34461 };
34462
34463-static const struct ide_port_info tc86c001_chipset __devinitdata = {
34464+static const struct ide_port_info tc86c001_chipset __devinitconst = {
34465 .name = DRV_NAME,
34466 .init_hwif = init_hwif_tc86c001,
34467 .port_ops = &tc86c001_port_ops,
34468diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
34469index 8773c3b..7907d6c 100644
34470--- a/drivers/ide/triflex.c
34471+++ b/drivers/ide/triflex.c
34472@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
34473 .set_dma_mode = triflex_set_mode,
34474 };
34475
34476-static const struct ide_port_info triflex_device __devinitdata = {
34477+static const struct ide_port_info triflex_device __devinitconst = {
34478 .name = DRV_NAME,
34479 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
34480 .port_ops = &triflex_port_ops,
34481diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
34482index 4b42ca0..e494a98 100644
34483--- a/drivers/ide/trm290.c
34484+++ b/drivers/ide/trm290.c
34485@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
34486 .dma_check = trm290_dma_check,
34487 };
34488
34489-static const struct ide_port_info trm290_chipset __devinitdata = {
34490+static const struct ide_port_info trm290_chipset __devinitconst = {
34491 .name = DRV_NAME,
34492 .init_hwif = init_hwif_trm290,
34493 .tp_ops = &trm290_tp_ops,
34494diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
34495index 028de26..520d5d5 100644
34496--- a/drivers/ide/via82cxxx.c
34497+++ b/drivers/ide/via82cxxx.c
34498@@ -374,7 +374,7 @@ static const struct ide_port_ops via_port_ops = {
34499 .cable_detect = via82cxxx_cable_detect,
34500 };
34501
34502-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
34503+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
34504 .name = DRV_NAME,
34505 .init_chipset = init_chipset_via82cxxx,
34506 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
34507diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
34508index 2cd00b5..14de699 100644
34509--- a/drivers/ieee1394/dv1394.c
34510+++ b/drivers/ieee1394/dv1394.c
34511@@ -739,7 +739,7 @@ static void frame_prepare(struct video_card *video, unsigned int this_frame)
34512 based upon DIF section and sequence
34513 */
34514
34515-static void inline
34516+static inline void
34517 frame_put_packet (struct frame *f, struct packet *p)
34518 {
34519 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
34520diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
34521index e947d8f..6a966b9 100644
34522--- a/drivers/ieee1394/hosts.c
34523+++ b/drivers/ieee1394/hosts.c
34524@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command,
34525 }
34526
34527 static struct hpsb_host_driver dummy_driver = {
34528+ .name = "dummy",
34529 .transmit_packet = dummy_transmit_packet,
34530 .devctl = dummy_devctl,
34531 .isoctl = dummy_isoctl
34532diff --git a/drivers/ieee1394/init_ohci1394_dma.c b/drivers/ieee1394/init_ohci1394_dma.c
34533index ddaab6e..8d37435 100644
34534--- a/drivers/ieee1394/init_ohci1394_dma.c
34535+++ b/drivers/ieee1394/init_ohci1394_dma.c
34536@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_controllers(void)
34537 for (func = 0; func < 8; func++) {
34538 u32 class = read_pci_config(num,slot,func,
34539 PCI_CLASS_REVISION);
34540- if ((class == 0xffffffff))
34541+ if (class == 0xffffffff)
34542 continue; /* No device at this func */
34543
34544 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
34545diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
34546index 65c1429..5d8c11f 100644
34547--- a/drivers/ieee1394/ohci1394.c
34548+++ b/drivers/ieee1394/ohci1394.c
34549@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
34550 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
34551
34552 /* Module Parameters */
34553-static int phys_dma = 1;
34554+static int phys_dma;
34555 module_param(phys_dma, int, 0444);
34556-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
34557+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
34558
34559 static void dma_trm_tasklet(unsigned long data);
34560 static void dma_trm_reset(struct dma_trm_ctx *d);
34561diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
34562index f199896..78c9fc8 100644
34563--- a/drivers/ieee1394/sbp2.c
34564+++ b/drivers/ieee1394/sbp2.c
34565@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
34566 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
34567 MODULE_LICENSE("GPL");
34568
34569-static int sbp2_module_init(void)
34570+static int __init sbp2_module_init(void)
34571 {
34572 int ret;
34573
34574diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34575index a5dea6b..0cefe8f 100644
34576--- a/drivers/infiniband/core/cm.c
34577+++ b/drivers/infiniband/core/cm.c
34578@@ -112,7 +112,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34579
34580 struct cm_counter_group {
34581 struct kobject obj;
34582- atomic_long_t counter[CM_ATTR_COUNT];
34583+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34584 };
34585
34586 struct cm_counter_attribute {
34587@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34588 struct ib_mad_send_buf *msg = NULL;
34589 int ret;
34590
34591- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34592+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34593 counter[CM_REQ_COUNTER]);
34594
34595 /* Quick state check to discard duplicate REQs. */
34596@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34597 if (!cm_id_priv)
34598 return;
34599
34600- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34601+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34602 counter[CM_REP_COUNTER]);
34603 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34604 if (ret)
34605@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work *work)
34606 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34607 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34608 spin_unlock_irq(&cm_id_priv->lock);
34609- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34610+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34611 counter[CM_RTU_COUNTER]);
34612 goto out;
34613 }
34614@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_work *work)
34615 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34616 dreq_msg->local_comm_id);
34617 if (!cm_id_priv) {
34618- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34619+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34620 counter[CM_DREQ_COUNTER]);
34621 cm_issue_drep(work->port, work->mad_recv_wc);
34622 return -EINVAL;
34623@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_work *work)
34624 case IB_CM_MRA_REP_RCVD:
34625 break;
34626 case IB_CM_TIMEWAIT:
34627- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34628+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34629 counter[CM_DREQ_COUNTER]);
34630 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34631 goto unlock;
34632@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_work *work)
34633 cm_free_msg(msg);
34634 goto deref;
34635 case IB_CM_DREQ_RCVD:
34636- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34637+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34638 counter[CM_DREQ_COUNTER]);
34639 goto unlock;
34640 default:
34641@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work *work)
34642 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34643 cm_id_priv->msg, timeout)) {
34644 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34645- atomic_long_inc(&work->port->
34646+ atomic_long_inc_unchecked(&work->port->
34647 counter_group[CM_RECV_DUPLICATES].
34648 counter[CM_MRA_COUNTER]);
34649 goto out;
34650@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work *work)
34651 break;
34652 case IB_CM_MRA_REQ_RCVD:
34653 case IB_CM_MRA_REP_RCVD:
34654- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34655+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34656 counter[CM_MRA_COUNTER]);
34657 /* fall through */
34658 default:
34659@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work *work)
34660 case IB_CM_LAP_IDLE:
34661 break;
34662 case IB_CM_MRA_LAP_SENT:
34663- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34664+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34665 counter[CM_LAP_COUNTER]);
34666 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34667 goto unlock;
34668@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work *work)
34669 cm_free_msg(msg);
34670 goto deref;
34671 case IB_CM_LAP_RCVD:
34672- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34673+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34674 counter[CM_LAP_COUNTER]);
34675 goto unlock;
34676 default:
34677@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34678 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34679 if (cur_cm_id_priv) {
34680 spin_unlock_irq(&cm.lock);
34681- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34682+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34683 counter[CM_SIDR_REQ_COUNTER]);
34684 goto out; /* Duplicate message. */
34685 }
34686@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34687 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34688 msg->retries = 1;
34689
34690- atomic_long_add(1 + msg->retries,
34691+ atomic_long_add_unchecked(1 + msg->retries,
34692 &port->counter_group[CM_XMIT].counter[attr_index]);
34693 if (msg->retries)
34694- atomic_long_add(msg->retries,
34695+ atomic_long_add_unchecked(msg->retries,
34696 &port->counter_group[CM_XMIT_RETRIES].
34697 counter[attr_index]);
34698
34699@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34700 }
34701
34702 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34703- atomic_long_inc(&port->counter_group[CM_RECV].
34704+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34705 counter[attr_id - CM_ATTR_ID_OFFSET]);
34706
34707 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34708@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34709 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34710
34711 return sprintf(buf, "%ld\n",
34712- atomic_long_read(&group->counter[cm_attr->index]));
34713+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34714 }
34715
34716-static struct sysfs_ops cm_counter_ops = {
34717+static const struct sysfs_ops cm_counter_ops = {
34718 .show = cm_show_counter
34719 };
34720
34721diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34722index 4507043..14ad522 100644
34723--- a/drivers/infiniband/core/fmr_pool.c
34724+++ b/drivers/infiniband/core/fmr_pool.c
34725@@ -97,8 +97,8 @@ struct ib_fmr_pool {
34726
34727 struct task_struct *thread;
34728
34729- atomic_t req_ser;
34730- atomic_t flush_ser;
34731+ atomic_unchecked_t req_ser;
34732+ atomic_unchecked_t flush_ser;
34733
34734 wait_queue_head_t force_wait;
34735 };
34736@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34737 struct ib_fmr_pool *pool = pool_ptr;
34738
34739 do {
34740- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34741+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34742 ib_fmr_batch_release(pool);
34743
34744- atomic_inc(&pool->flush_ser);
34745+ atomic_inc_unchecked(&pool->flush_ser);
34746 wake_up_interruptible(&pool->force_wait);
34747
34748 if (pool->flush_function)
34749@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34750 }
34751
34752 set_current_state(TASK_INTERRUPTIBLE);
34753- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34754+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34755 !kthread_should_stop())
34756 schedule();
34757 __set_current_state(TASK_RUNNING);
34758@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34759 pool->dirty_watermark = params->dirty_watermark;
34760 pool->dirty_len = 0;
34761 spin_lock_init(&pool->pool_lock);
34762- atomic_set(&pool->req_ser, 0);
34763- atomic_set(&pool->flush_ser, 0);
34764+ atomic_set_unchecked(&pool->req_ser, 0);
34765+ atomic_set_unchecked(&pool->flush_ser, 0);
34766 init_waitqueue_head(&pool->force_wait);
34767
34768 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34769@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34770 }
34771 spin_unlock_irq(&pool->pool_lock);
34772
34773- serial = atomic_inc_return(&pool->req_ser);
34774+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34775 wake_up_process(pool->thread);
34776
34777 if (wait_event_interruptible(pool->force_wait,
34778- atomic_read(&pool->flush_ser) - serial >= 0))
34779+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34780 return -EINTR;
34781
34782 return 0;
34783@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34784 } else {
34785 list_add_tail(&fmr->list, &pool->dirty_list);
34786 if (++pool->dirty_len >= pool->dirty_watermark) {
34787- atomic_inc(&pool->req_ser);
34788+ atomic_inc_unchecked(&pool->req_ser);
34789 wake_up_process(pool->thread);
34790 }
34791 }
34792diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
34793index 158a214..1558bb7 100644
34794--- a/drivers/infiniband/core/sysfs.c
34795+++ b/drivers/infiniband/core/sysfs.c
34796@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kobject *kobj,
34797 return port_attr->show(p, port_attr, buf);
34798 }
34799
34800-static struct sysfs_ops port_sysfs_ops = {
34801+static const struct sysfs_ops port_sysfs_ops = {
34802 .show = port_attr_show
34803 };
34804
34805diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
34806index 5440da0..1194ecb 100644
34807--- a/drivers/infiniband/core/uverbs_marshall.c
34808+++ b/drivers/infiniband/core/uverbs_marshall.c
34809@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
34810 dst->grh.sgid_index = src->grh.sgid_index;
34811 dst->grh.hop_limit = src->grh.hop_limit;
34812 dst->grh.traffic_class = src->grh.traffic_class;
34813+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
34814 dst->dlid = src->dlid;
34815 dst->sl = src->sl;
34816 dst->src_path_bits = src->src_path_bits;
34817 dst->static_rate = src->static_rate;
34818 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
34819 dst->port_num = src->port_num;
34820+ dst->reserved = 0;
34821 }
34822 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
34823
34824 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34825 struct ib_qp_attr *src)
34826 {
34827+ dst->qp_state = src->qp_state;
34828 dst->cur_qp_state = src->cur_qp_state;
34829 dst->path_mtu = src->path_mtu;
34830 dst->path_mig_state = src->path_mig_state;
34831@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34832 dst->rnr_retry = src->rnr_retry;
34833 dst->alt_port_num = src->alt_port_num;
34834 dst->alt_timeout = src->alt_timeout;
34835+ memset(dst->reserved, 0, sizeof(dst->reserved));
34836 }
34837 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
34838
34839diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
34840index 100da85..62e6b88 100644
34841--- a/drivers/infiniband/hw/ipath/ipath_fs.c
34842+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
34843@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
34844 struct infinipath_counters counters;
34845 struct ipath_devdata *dd;
34846
34847+ pax_track_stack();
34848+
34849 dd = file->f_path.dentry->d_inode->i_private;
34850 dd->ipath_f_read_counters(dd, &counters);
34851
34852diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34853index cbde0cf..afaf55c 100644
34854--- a/drivers/infiniband/hw/nes/nes.c
34855+++ b/drivers/infiniband/hw/nes/nes.c
34856@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34857 LIST_HEAD(nes_adapter_list);
34858 static LIST_HEAD(nes_dev_list);
34859
34860-atomic_t qps_destroyed;
34861+atomic_unchecked_t qps_destroyed;
34862
34863 static unsigned int ee_flsh_adapter;
34864 static unsigned int sysfs_nonidx_addr;
34865@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34866 struct nes_adapter *nesadapter = nesdev->nesadapter;
34867 u32 qp_id;
34868
34869- atomic_inc(&qps_destroyed);
34870+ atomic_inc_unchecked(&qps_destroyed);
34871
34872 /* Free the control structures */
34873
34874diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34875index bcc6abc..9c76b2f 100644
34876--- a/drivers/infiniband/hw/nes/nes.h
34877+++ b/drivers/infiniband/hw/nes/nes.h
34878@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
34879 extern unsigned int wqm_quanta;
34880 extern struct list_head nes_adapter_list;
34881
34882-extern atomic_t cm_connects;
34883-extern atomic_t cm_accepts;
34884-extern atomic_t cm_disconnects;
34885-extern atomic_t cm_closes;
34886-extern atomic_t cm_connecteds;
34887-extern atomic_t cm_connect_reqs;
34888-extern atomic_t cm_rejects;
34889-extern atomic_t mod_qp_timouts;
34890-extern atomic_t qps_created;
34891-extern atomic_t qps_destroyed;
34892-extern atomic_t sw_qps_destroyed;
34893+extern atomic_unchecked_t cm_connects;
34894+extern atomic_unchecked_t cm_accepts;
34895+extern atomic_unchecked_t cm_disconnects;
34896+extern atomic_unchecked_t cm_closes;
34897+extern atomic_unchecked_t cm_connecteds;
34898+extern atomic_unchecked_t cm_connect_reqs;
34899+extern atomic_unchecked_t cm_rejects;
34900+extern atomic_unchecked_t mod_qp_timouts;
34901+extern atomic_unchecked_t qps_created;
34902+extern atomic_unchecked_t qps_destroyed;
34903+extern atomic_unchecked_t sw_qps_destroyed;
34904 extern u32 mh_detected;
34905 extern u32 mh_pauses_sent;
34906 extern u32 cm_packets_sent;
34907@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
34908 extern u32 cm_listens_created;
34909 extern u32 cm_listens_destroyed;
34910 extern u32 cm_backlog_drops;
34911-extern atomic_t cm_loopbacks;
34912-extern atomic_t cm_nodes_created;
34913-extern atomic_t cm_nodes_destroyed;
34914-extern atomic_t cm_accel_dropped_pkts;
34915-extern atomic_t cm_resets_recvd;
34916+extern atomic_unchecked_t cm_loopbacks;
34917+extern atomic_unchecked_t cm_nodes_created;
34918+extern atomic_unchecked_t cm_nodes_destroyed;
34919+extern atomic_unchecked_t cm_accel_dropped_pkts;
34920+extern atomic_unchecked_t cm_resets_recvd;
34921
34922 extern u32 int_mod_timer_init;
34923 extern u32 int_mod_cq_depth_256;
34924diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34925index 73473db..5ed06e8 100644
34926--- a/drivers/infiniband/hw/nes/nes_cm.c
34927+++ b/drivers/infiniband/hw/nes/nes_cm.c
34928@@ -69,11 +69,11 @@ u32 cm_packets_received;
34929 u32 cm_listens_created;
34930 u32 cm_listens_destroyed;
34931 u32 cm_backlog_drops;
34932-atomic_t cm_loopbacks;
34933-atomic_t cm_nodes_created;
34934-atomic_t cm_nodes_destroyed;
34935-atomic_t cm_accel_dropped_pkts;
34936-atomic_t cm_resets_recvd;
34937+atomic_unchecked_t cm_loopbacks;
34938+atomic_unchecked_t cm_nodes_created;
34939+atomic_unchecked_t cm_nodes_destroyed;
34940+atomic_unchecked_t cm_accel_dropped_pkts;
34941+atomic_unchecked_t cm_resets_recvd;
34942
34943 static inline int mini_cm_accelerated(struct nes_cm_core *,
34944 struct nes_cm_node *);
34945@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
34946
34947 static struct nes_cm_core *g_cm_core;
34948
34949-atomic_t cm_connects;
34950-atomic_t cm_accepts;
34951-atomic_t cm_disconnects;
34952-atomic_t cm_closes;
34953-atomic_t cm_connecteds;
34954-atomic_t cm_connect_reqs;
34955-atomic_t cm_rejects;
34956+atomic_unchecked_t cm_connects;
34957+atomic_unchecked_t cm_accepts;
34958+atomic_unchecked_t cm_disconnects;
34959+atomic_unchecked_t cm_closes;
34960+atomic_unchecked_t cm_connecteds;
34961+atomic_unchecked_t cm_connect_reqs;
34962+atomic_unchecked_t cm_rejects;
34963
34964
34965 /**
34966@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34967 cm_node->rem_mac);
34968
34969 add_hte_node(cm_core, cm_node);
34970- atomic_inc(&cm_nodes_created);
34971+ atomic_inc_unchecked(&cm_nodes_created);
34972
34973 return cm_node;
34974 }
34975@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34976 }
34977
34978 atomic_dec(&cm_core->node_cnt);
34979- atomic_inc(&cm_nodes_destroyed);
34980+ atomic_inc_unchecked(&cm_nodes_destroyed);
34981 nesqp = cm_node->nesqp;
34982 if (nesqp) {
34983 nesqp->cm_node = NULL;
34984@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34985
34986 static void drop_packet(struct sk_buff *skb)
34987 {
34988- atomic_inc(&cm_accel_dropped_pkts);
34989+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
34990 dev_kfree_skb_any(skb);
34991 }
34992
34993@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34994
34995 int reset = 0; /* whether to send reset in case of err.. */
34996 int passive_state;
34997- atomic_inc(&cm_resets_recvd);
34998+ atomic_inc_unchecked(&cm_resets_recvd);
34999 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35000 " refcnt=%d\n", cm_node, cm_node->state,
35001 atomic_read(&cm_node->ref_count));
35002@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35003 rem_ref_cm_node(cm_node->cm_core, cm_node);
35004 return NULL;
35005 }
35006- atomic_inc(&cm_loopbacks);
35007+ atomic_inc_unchecked(&cm_loopbacks);
35008 loopbackremotenode->loopbackpartner = cm_node;
35009 loopbackremotenode->tcp_cntxt.rcv_wscale =
35010 NES_CM_DEFAULT_RCV_WND_SCALE;
35011@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35012 add_ref_cm_node(cm_node);
35013 } else if (cm_node->state == NES_CM_STATE_TSA) {
35014 rem_ref_cm_node(cm_core, cm_node);
35015- atomic_inc(&cm_accel_dropped_pkts);
35016+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35017 dev_kfree_skb_any(skb);
35018 break;
35019 }
35020@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35021
35022 if ((cm_id) && (cm_id->event_handler)) {
35023 if (issue_disconn) {
35024- atomic_inc(&cm_disconnects);
35025+ atomic_inc_unchecked(&cm_disconnects);
35026 cm_event.event = IW_CM_EVENT_DISCONNECT;
35027 cm_event.status = disconn_status;
35028 cm_event.local_addr = cm_id->local_addr;
35029@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35030 }
35031
35032 if (issue_close) {
35033- atomic_inc(&cm_closes);
35034+ atomic_inc_unchecked(&cm_closes);
35035 nes_disconnect(nesqp, 1);
35036
35037 cm_id->provider_data = nesqp;
35038@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35039
35040 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35041 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35042- atomic_inc(&cm_accepts);
35043+ atomic_inc_unchecked(&cm_accepts);
35044
35045 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35046 atomic_read(&nesvnic->netdev->refcnt));
35047@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35048
35049 struct nes_cm_core *cm_core;
35050
35051- atomic_inc(&cm_rejects);
35052+ atomic_inc_unchecked(&cm_rejects);
35053 cm_node = (struct nes_cm_node *) cm_id->provider_data;
35054 loopback = cm_node->loopbackpartner;
35055 cm_core = cm_node->cm_core;
35056@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35057 ntohl(cm_id->local_addr.sin_addr.s_addr),
35058 ntohs(cm_id->local_addr.sin_port));
35059
35060- atomic_inc(&cm_connects);
35061+ atomic_inc_unchecked(&cm_connects);
35062 nesqp->active_conn = 1;
35063
35064 /* cache the cm_id in the qp */
35065@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35066 if (nesqp->destroyed) {
35067 return;
35068 }
35069- atomic_inc(&cm_connecteds);
35070+ atomic_inc_unchecked(&cm_connecteds);
35071 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35072 " local port 0x%04X. jiffies = %lu.\n",
35073 nesqp->hwqp.qp_id,
35074@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35075
35076 ret = cm_id->event_handler(cm_id, &cm_event);
35077 cm_id->add_ref(cm_id);
35078- atomic_inc(&cm_closes);
35079+ atomic_inc_unchecked(&cm_closes);
35080 cm_event.event = IW_CM_EVENT_CLOSE;
35081 cm_event.status = IW_CM_EVENT_STATUS_OK;
35082 cm_event.provider_data = cm_id->provider_data;
35083@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35084 return;
35085 cm_id = cm_node->cm_id;
35086
35087- atomic_inc(&cm_connect_reqs);
35088+ atomic_inc_unchecked(&cm_connect_reqs);
35089 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35090 cm_node, cm_id, jiffies);
35091
35092@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35093 return;
35094 cm_id = cm_node->cm_id;
35095
35096- atomic_inc(&cm_connect_reqs);
35097+ atomic_inc_unchecked(&cm_connect_reqs);
35098 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35099 cm_node, cm_id, jiffies);
35100
35101diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35102index e593af3..870694a 100644
35103--- a/drivers/infiniband/hw/nes/nes_nic.c
35104+++ b/drivers/infiniband/hw/nes/nes_nic.c
35105@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35106 target_stat_values[++index] = mh_detected;
35107 target_stat_values[++index] = mh_pauses_sent;
35108 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35109- target_stat_values[++index] = atomic_read(&cm_connects);
35110- target_stat_values[++index] = atomic_read(&cm_accepts);
35111- target_stat_values[++index] = atomic_read(&cm_disconnects);
35112- target_stat_values[++index] = atomic_read(&cm_connecteds);
35113- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35114- target_stat_values[++index] = atomic_read(&cm_rejects);
35115- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35116- target_stat_values[++index] = atomic_read(&qps_created);
35117- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35118- target_stat_values[++index] = atomic_read(&qps_destroyed);
35119- target_stat_values[++index] = atomic_read(&cm_closes);
35120+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35121+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35122+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35123+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35124+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35125+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35126+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35127+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35128+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35129+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35130+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35131 target_stat_values[++index] = cm_packets_sent;
35132 target_stat_values[++index] = cm_packets_bounced;
35133 target_stat_values[++index] = cm_packets_created;
35134@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35135 target_stat_values[++index] = cm_listens_created;
35136 target_stat_values[++index] = cm_listens_destroyed;
35137 target_stat_values[++index] = cm_backlog_drops;
35138- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35139- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35140- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35141- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35142- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35143+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35144+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35145+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35146+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35147+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35148 target_stat_values[++index] = int_mod_timer_init;
35149 target_stat_values[++index] = int_mod_cq_depth_1;
35150 target_stat_values[++index] = int_mod_cq_depth_4;
35151diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35152index a680c42..f914deb 100644
35153--- a/drivers/infiniband/hw/nes/nes_verbs.c
35154+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35155@@ -45,9 +45,9 @@
35156
35157 #include <rdma/ib_umem.h>
35158
35159-atomic_t mod_qp_timouts;
35160-atomic_t qps_created;
35161-atomic_t sw_qps_destroyed;
35162+atomic_unchecked_t mod_qp_timouts;
35163+atomic_unchecked_t qps_created;
35164+atomic_unchecked_t sw_qps_destroyed;
35165
35166 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35167
35168@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35169 if (init_attr->create_flags)
35170 return ERR_PTR(-EINVAL);
35171
35172- atomic_inc(&qps_created);
35173+ atomic_inc_unchecked(&qps_created);
35174 switch (init_attr->qp_type) {
35175 case IB_QPT_RC:
35176 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35177@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35178 struct iw_cm_event cm_event;
35179 int ret;
35180
35181- atomic_inc(&sw_qps_destroyed);
35182+ atomic_inc_unchecked(&sw_qps_destroyed);
35183 nesqp->destroyed = 1;
35184
35185 /* Blow away the connection if it exists. */
35186diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35187index ac11be0..3883c04 100644
35188--- a/drivers/input/gameport/gameport.c
35189+++ b/drivers/input/gameport/gameport.c
35190@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
35191 */
35192 static void gameport_init_port(struct gameport *gameport)
35193 {
35194- static atomic_t gameport_no = ATOMIC_INIT(0);
35195+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35196
35197 __module_get(THIS_MODULE);
35198
35199 mutex_init(&gameport->drv_mutex);
35200 device_initialize(&gameport->dev);
35201- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
35202+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35203 gameport->dev.bus = &gameport_bus;
35204 gameport->dev.release = gameport_release_port;
35205 if (gameport->parent)
35206diff --git a/drivers/input/input.c b/drivers/input/input.c
35207index c82ae82..8cfb9cb 100644
35208--- a/drivers/input/input.c
35209+++ b/drivers/input/input.c
35210@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
35211 */
35212 int input_register_device(struct input_dev *dev)
35213 {
35214- static atomic_t input_no = ATOMIC_INIT(0);
35215+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35216 struct input_handler *handler;
35217 const char *path;
35218 int error;
35219@@ -1585,7 +1585,7 @@ int input_register_device(struct input_dev *dev)
35220 dev->setkeycode = input_default_setkeycode;
35221
35222 dev_set_name(&dev->dev, "input%ld",
35223- (unsigned long) atomic_inc_return(&input_no) - 1);
35224+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35225
35226 error = device_add(&dev->dev);
35227 if (error)
35228diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35229index ca13a6b..b032b0c 100644
35230--- a/drivers/input/joystick/sidewinder.c
35231+++ b/drivers/input/joystick/sidewinder.c
35232@@ -30,6 +30,7 @@
35233 #include <linux/kernel.h>
35234 #include <linux/module.h>
35235 #include <linux/slab.h>
35236+#include <linux/sched.h>
35237 #include <linux/init.h>
35238 #include <linux/input.h>
35239 #include <linux/gameport.h>
35240@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
35241 unsigned char buf[SW_LENGTH];
35242 int i;
35243
35244+ pax_track_stack();
35245+
35246 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
35247
35248 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
35249diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35250index 79e3edc..01412b9 100644
35251--- a/drivers/input/joystick/xpad.c
35252+++ b/drivers/input/joystick/xpad.c
35253@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35254
35255 static int xpad_led_probe(struct usb_xpad *xpad)
35256 {
35257- static atomic_t led_seq = ATOMIC_INIT(0);
35258+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35259 long led_no;
35260 struct xpad_led *led;
35261 struct led_classdev *led_cdev;
35262@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35263 if (!led)
35264 return -ENOMEM;
35265
35266- led_no = (long)atomic_inc_return(&led_seq) - 1;
35267+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35268
35269 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35270 led->xpad = xpad;
35271diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35272index 0236f0d..c7327f1 100644
35273--- a/drivers/input/serio/serio.c
35274+++ b/drivers/input/serio/serio.c
35275@@ -527,7 +527,7 @@ static void serio_release_port(struct device *dev)
35276 */
35277 static void serio_init_port(struct serio *serio)
35278 {
35279- static atomic_t serio_no = ATOMIC_INIT(0);
35280+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35281
35282 __module_get(THIS_MODULE);
35283
35284@@ -536,7 +536,7 @@ static void serio_init_port(struct serio *serio)
35285 mutex_init(&serio->drv_mutex);
35286 device_initialize(&serio->dev);
35287 dev_set_name(&serio->dev, "serio%ld",
35288- (long)atomic_inc_return(&serio_no) - 1);
35289+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35290 serio->dev.bus = &serio_bus;
35291 serio->dev.release = serio_release_port;
35292 if (serio->parent) {
35293diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
35294index 33dcd8d..2783d25 100644
35295--- a/drivers/isdn/gigaset/common.c
35296+++ b/drivers/isdn/gigaset/common.c
35297@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
35298 cs->commands_pending = 0;
35299 cs->cur_at_seq = 0;
35300 cs->gotfwver = -1;
35301- cs->open_count = 0;
35302+ local_set(&cs->open_count, 0);
35303 cs->dev = NULL;
35304 cs->tty = NULL;
35305 cs->tty_dev = NULL;
35306diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
35307index a2f6125..6a70677 100644
35308--- a/drivers/isdn/gigaset/gigaset.h
35309+++ b/drivers/isdn/gigaset/gigaset.h
35310@@ -34,6 +34,7 @@
35311 #include <linux/tty_driver.h>
35312 #include <linux/list.h>
35313 #include <asm/atomic.h>
35314+#include <asm/local.h>
35315
35316 #define GIG_VERSION {0,5,0,0}
35317 #define GIG_COMPAT {0,4,0,0}
35318@@ -446,7 +447,7 @@ struct cardstate {
35319 spinlock_t cmdlock;
35320 unsigned curlen, cmdbytes;
35321
35322- unsigned open_count;
35323+ local_t open_count;
35324 struct tty_struct *tty;
35325 struct tasklet_struct if_wake_tasklet;
35326 unsigned control_state;
35327diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35328index b3065b8..c7e8cc9 100644
35329--- a/drivers/isdn/gigaset/interface.c
35330+++ b/drivers/isdn/gigaset/interface.c
35331@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35332 return -ERESTARTSYS; // FIXME -EINTR?
35333 tty->driver_data = cs;
35334
35335- ++cs->open_count;
35336-
35337- if (cs->open_count == 1) {
35338+ if (local_inc_return(&cs->open_count) == 1) {
35339 spin_lock_irqsave(&cs->lock, flags);
35340 cs->tty = tty;
35341 spin_unlock_irqrestore(&cs->lock, flags);
35342@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35343
35344 if (!cs->connected)
35345 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35346- else if (!cs->open_count)
35347+ else if (!local_read(&cs->open_count))
35348 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35349 else {
35350- if (!--cs->open_count) {
35351+ if (!local_dec_return(&cs->open_count)) {
35352 spin_lock_irqsave(&cs->lock, flags);
35353 cs->tty = NULL;
35354 spin_unlock_irqrestore(&cs->lock, flags);
35355@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
35356 if (!cs->connected) {
35357 gig_dbg(DEBUG_IF, "not connected");
35358 retval = -ENODEV;
35359- } else if (!cs->open_count)
35360+ } else if (!local_read(&cs->open_count))
35361 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35362 else {
35363 retval = 0;
35364@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
35365 if (!cs->connected) {
35366 gig_dbg(DEBUG_IF, "not connected");
35367 retval = -ENODEV;
35368- } else if (!cs->open_count)
35369+ } else if (!local_read(&cs->open_count))
35370 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35371 else if (cs->mstate != MS_LOCKED) {
35372 dev_warn(cs->dev, "can't write to unlocked device\n");
35373@@ -395,7 +393,7 @@ static int if_write_room(struct tty_struct *tty)
35374 if (!cs->connected) {
35375 gig_dbg(DEBUG_IF, "not connected");
35376 retval = -ENODEV;
35377- } else if (!cs->open_count)
35378+ } else if (!local_read(&cs->open_count))
35379 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35380 else if (cs->mstate != MS_LOCKED) {
35381 dev_warn(cs->dev, "can't write to unlocked device\n");
35382@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
35383
35384 if (!cs->connected)
35385 gig_dbg(DEBUG_IF, "not connected");
35386- else if (!cs->open_count)
35387+ else if (!local_read(&cs->open_count))
35388 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35389 else if (cs->mstate != MS_LOCKED)
35390 dev_warn(cs->dev, "can't write to unlocked device\n");
35391@@ -453,7 +451,7 @@ static void if_throttle(struct tty_struct *tty)
35392
35393 if (!cs->connected)
35394 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35395- else if (!cs->open_count)
35396+ else if (!local_read(&cs->open_count))
35397 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35398 else {
35399 //FIXME
35400@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_struct *tty)
35401
35402 if (!cs->connected)
35403 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35404- else if (!cs->open_count)
35405+ else if (!local_read(&cs->open_count))
35406 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35407 else {
35408 //FIXME
35409@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
35410 goto out;
35411 }
35412
35413- if (!cs->open_count) {
35414+ if (!local_read(&cs->open_count)) {
35415 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35416 goto out;
35417 }
35418diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35419index a7c0083..62a7cb6 100644
35420--- a/drivers/isdn/hardware/avm/b1.c
35421+++ b/drivers/isdn/hardware/avm/b1.c
35422@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
35423 }
35424 if (left) {
35425 if (t4file->user) {
35426- if (copy_from_user(buf, dp, left))
35427+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35428 return -EFAULT;
35429 } else {
35430 memcpy(buf, dp, left);
35431@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
35432 }
35433 if (left) {
35434 if (config->user) {
35435- if (copy_from_user(buf, dp, left))
35436+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35437 return -EFAULT;
35438 } else {
35439 memcpy(buf, dp, left);
35440diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
35441index f130724..c373c68 100644
35442--- a/drivers/isdn/hardware/eicon/capidtmf.c
35443+++ b/drivers/isdn/hardware/eicon/capidtmf.c
35444@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
35445 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
35446 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
35447
35448+ pax_track_stack();
35449
35450 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
35451 {
35452diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
35453index 4d425c6..a9be6c4 100644
35454--- a/drivers/isdn/hardware/eicon/capifunc.c
35455+++ b/drivers/isdn/hardware/eicon/capifunc.c
35456@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
35457 IDI_SYNC_REQ req;
35458 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35459
35460+ pax_track_stack();
35461+
35462 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35463
35464 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35465diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
35466index 3029234..ef0d9e2 100644
35467--- a/drivers/isdn/hardware/eicon/diddfunc.c
35468+++ b/drivers/isdn/hardware/eicon/diddfunc.c
35469@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35470 IDI_SYNC_REQ req;
35471 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35472
35473+ pax_track_stack();
35474+
35475 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35476
35477 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35478diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
35479index d36a4c0..11e7d1a 100644
35480--- a/drivers/isdn/hardware/eicon/divasfunc.c
35481+++ b/drivers/isdn/hardware/eicon/divasfunc.c
35482@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35483 IDI_SYNC_REQ req;
35484 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35485
35486+ pax_track_stack();
35487+
35488 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35489
35490 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35491diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
35492index 85784a7..a19ca98 100644
35493--- a/drivers/isdn/hardware/eicon/divasync.h
35494+++ b/drivers/isdn/hardware/eicon/divasync.h
35495@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
35496 } diva_didd_add_adapter_t;
35497 typedef struct _diva_didd_remove_adapter {
35498 IDI_CALL p_request;
35499-} diva_didd_remove_adapter_t;
35500+} __no_const diva_didd_remove_adapter_t;
35501 typedef struct _diva_didd_read_adapter_array {
35502 void * buffer;
35503 dword length;
35504diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
35505index db87d51..7d09acf 100644
35506--- a/drivers/isdn/hardware/eicon/idifunc.c
35507+++ b/drivers/isdn/hardware/eicon/idifunc.c
35508@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35509 IDI_SYNC_REQ req;
35510 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35511
35512+ pax_track_stack();
35513+
35514 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35515
35516 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35517diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
35518index ae89fb8..0fab299 100644
35519--- a/drivers/isdn/hardware/eicon/message.c
35520+++ b/drivers/isdn/hardware/eicon/message.c
35521@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
35522 dword d;
35523 word w;
35524
35525+ pax_track_stack();
35526+
35527 a = plci->adapter;
35528 Id = ((word)plci->Id<<8)|a->Id;
35529 PUT_WORD(&SS_Ind[4],0x0000);
35530@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
35531 word j, n, w;
35532 dword d;
35533
35534+ pax_track_stack();
35535+
35536
35537 for(i=0;i<8;i++) bp_parms[i].length = 0;
35538 for(i=0;i<2;i++) global_config[i].length = 0;
35539@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
35540 const byte llc3[] = {4,3,2,2,6,6,0};
35541 const byte header[] = {0,2,3,3,0,0,0};
35542
35543+ pax_track_stack();
35544+
35545 for(i=0;i<8;i++) bp_parms[i].length = 0;
35546 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
35547 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
35548@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
35549 word appl_number_group_type[MAX_APPL];
35550 PLCI *auxplci;
35551
35552+ pax_track_stack();
35553+
35554 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
35555
35556 if(!a->group_optimization_enabled)
35557diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
35558index a564b75..f3cf8b5 100644
35559--- a/drivers/isdn/hardware/eicon/mntfunc.c
35560+++ b/drivers/isdn/hardware/eicon/mntfunc.c
35561@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35562 IDI_SYNC_REQ req;
35563 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35564
35565+ pax_track_stack();
35566+
35567 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35568
35569 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35570diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
35571index a3bd163..8956575 100644
35572--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
35573+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
35574@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
35575 typedef struct _diva_os_idi_adapter_interface {
35576 diva_init_card_proc_t cleanup_adapter_proc;
35577 diva_cmd_card_proc_t cmd_proc;
35578-} diva_os_idi_adapter_interface_t;
35579+} __no_const diva_os_idi_adapter_interface_t;
35580
35581 typedef struct _diva_os_xdi_adapter {
35582 struct list_head link;
35583diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
35584index adb1e8c..21b590b 100644
35585--- a/drivers/isdn/i4l/isdn_common.c
35586+++ b/drivers/isdn/i4l/isdn_common.c
35587@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
35588 } iocpar;
35589 void __user *argp = (void __user *)arg;
35590
35591+ pax_track_stack();
35592+
35593 #define name iocpar.name
35594 #define bname iocpar.bname
35595 #define iocts iocpar.iocts
35596diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35597index bf7997a..cf091db 100644
35598--- a/drivers/isdn/icn/icn.c
35599+++ b/drivers/isdn/icn/icn.c
35600@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
35601 if (count > len)
35602 count = len;
35603 if (user) {
35604- if (copy_from_user(msg, buf, count))
35605+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35606 return -EFAULT;
35607 } else
35608 memcpy(msg, buf, count);
35609diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
35610index feb0fa4..f76f830 100644
35611--- a/drivers/isdn/mISDN/socket.c
35612+++ b/drivers/isdn/mISDN/socket.c
35613@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35614 if (dev) {
35615 struct mISDN_devinfo di;
35616
35617+ memset(&di, 0, sizeof(di));
35618 di.id = dev->id;
35619 di.Dprotocols = dev->Dprotocols;
35620 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35621@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35622 if (dev) {
35623 struct mISDN_devinfo di;
35624
35625+ memset(&di, 0, sizeof(di));
35626 di.id = dev->id;
35627 di.Dprotocols = dev->Dprotocols;
35628 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35629diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
35630index 485be8b..f0225bc 100644
35631--- a/drivers/isdn/sc/interrupt.c
35632+++ b/drivers/isdn/sc/interrupt.c
35633@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35634 }
35635 else if(callid>=0x0000 && callid<=0x7FFF)
35636 {
35637+ int len;
35638+
35639 pr_debug("%s: Got Incoming Call\n",
35640 sc_adapter[card]->devicename);
35641- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
35642- strcpy(setup.eazmsn,
35643- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
35644+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
35645+ sizeof(setup.phone));
35646+ if (len >= sizeof(setup.phone))
35647+ continue;
35648+ len = strlcpy(setup.eazmsn,
35649+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35650+ sizeof(setup.eazmsn));
35651+ if (len >= sizeof(setup.eazmsn))
35652+ continue;
35653 setup.si1 = 7;
35654 setup.si2 = 0;
35655 setup.plan = 0;
35656@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35657 * Handle a GetMyNumber Rsp
35658 */
35659 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
35660- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
35661+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35662+ rcvmsg.msg_data.byte_array,
35663+ sizeof(rcvmsg.msg_data.byte_array));
35664 continue;
35665 }
35666
35667diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35668index 8744d24..d1f9a9a 100644
35669--- a/drivers/lguest/core.c
35670+++ b/drivers/lguest/core.c
35671@@ -91,9 +91,17 @@ static __init int map_switcher(void)
35672 * it's worked so far. The end address needs +1 because __get_vm_area
35673 * allocates an extra guard page, so we need space for that.
35674 */
35675+
35676+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35677+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35678+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35679+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35680+#else
35681 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35682 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35683 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35684+#endif
35685+
35686 if (!switcher_vma) {
35687 err = -ENOMEM;
35688 printk("lguest: could not map switcher pages high\n");
35689@@ -118,7 +126,7 @@ static __init int map_switcher(void)
35690 * Now the Switcher is mapped at the right address, we can't fail!
35691 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
35692 */
35693- memcpy(switcher_vma->addr, start_switcher_text,
35694+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35695 end_switcher_text - start_switcher_text);
35696
35697 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35698diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35699index 6ae3888..8b38145 100644
35700--- a/drivers/lguest/x86/core.c
35701+++ b/drivers/lguest/x86/core.c
35702@@ -59,7 +59,7 @@ static struct {
35703 /* Offset from where switcher.S was compiled to where we've copied it */
35704 static unsigned long switcher_offset(void)
35705 {
35706- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35707+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35708 }
35709
35710 /* This cpu's struct lguest_pages. */
35711@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35712 * These copies are pretty cheap, so we do them unconditionally: */
35713 /* Save the current Host top-level page directory.
35714 */
35715+
35716+#ifdef CONFIG_PAX_PER_CPU_PGD
35717+ pages->state.host_cr3 = read_cr3();
35718+#else
35719 pages->state.host_cr3 = __pa(current->mm->pgd);
35720+#endif
35721+
35722 /*
35723 * Set up the Guest's page tables to see this CPU's pages (and no
35724 * other CPU's pages).
35725@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
35726 * compiled-in switcher code and the high-mapped copy we just made.
35727 */
35728 for (i = 0; i < IDT_ENTRIES; i++)
35729- default_idt_entries[i] += switcher_offset();
35730+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35731
35732 /*
35733 * Set up the Switcher's per-cpu areas.
35734@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
35735 * it will be undisturbed when we switch. To change %cs and jump we
35736 * need this structure to feed to Intel's "lcall" instruction.
35737 */
35738- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35739+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35740 lguest_entry.segment = LGUEST_CS;
35741
35742 /*
35743diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35744index 40634b0..4f5855e 100644
35745--- a/drivers/lguest/x86/switcher_32.S
35746+++ b/drivers/lguest/x86/switcher_32.S
35747@@ -87,6 +87,7 @@
35748 #include <asm/page.h>
35749 #include <asm/segment.h>
35750 #include <asm/lguest.h>
35751+#include <asm/processor-flags.h>
35752
35753 // We mark the start of the code to copy
35754 // It's placed in .text tho it's never run here
35755@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35756 // Changes type when we load it: damn Intel!
35757 // For after we switch over our page tables
35758 // That entry will be read-only: we'd crash.
35759+
35760+#ifdef CONFIG_PAX_KERNEXEC
35761+ mov %cr0, %edx
35762+ xor $X86_CR0_WP, %edx
35763+ mov %edx, %cr0
35764+#endif
35765+
35766 movl $(GDT_ENTRY_TSS*8), %edx
35767 ltr %dx
35768
35769@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35770 // Let's clear it again for our return.
35771 // The GDT descriptor of the Host
35772 // Points to the table after two "size" bytes
35773- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35774+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35775 // Clear "used" from type field (byte 5, bit 2)
35776- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35777+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35778+
35779+#ifdef CONFIG_PAX_KERNEXEC
35780+ mov %cr0, %eax
35781+ xor $X86_CR0_WP, %eax
35782+ mov %eax, %cr0
35783+#endif
35784
35785 // Once our page table's switched, the Guest is live!
35786 // The Host fades as we run this final step.
35787@@ -295,13 +309,12 @@ deliver_to_host:
35788 // I consulted gcc, and it gave
35789 // These instructions, which I gladly credit:
35790 leal (%edx,%ebx,8), %eax
35791- movzwl (%eax),%edx
35792- movl 4(%eax), %eax
35793- xorw %ax, %ax
35794- orl %eax, %edx
35795+ movl 4(%eax), %edx
35796+ movw (%eax), %dx
35797 // Now the address of the handler's in %edx
35798 // We call it now: its "iret" drops us home.
35799- jmp *%edx
35800+ ljmp $__KERNEL_CS, $1f
35801+1: jmp *%edx
35802
35803 // Every interrupt can come to us here
35804 // But we must truly tell each apart.
35805diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
35806index 588a5b0..b71db89 100644
35807--- a/drivers/macintosh/macio_asic.c
35808+++ b/drivers/macintosh/macio_asic.c
35809@@ -701,7 +701,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
35810 * MacIO is matched against any Apple ID, it's probe() function
35811 * will then decide wether it applies or not
35812 */
35813-static const struct pci_device_id __devinitdata pci_ids [] = { {
35814+static const struct pci_device_id __devinitconst pci_ids [] = { {
35815 .vendor = PCI_VENDOR_ID_APPLE,
35816 .device = PCI_ANY_ID,
35817 .subvendor = PCI_ANY_ID,
35818diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
35819index a348bb0..ecd9b3f 100644
35820--- a/drivers/macintosh/via-pmu-backlight.c
35821+++ b/drivers/macintosh/via-pmu-backlight.c
35822@@ -15,7 +15,7 @@
35823
35824 #define MAX_PMU_LEVEL 0xFF
35825
35826-static struct backlight_ops pmu_backlight_data;
35827+static const struct backlight_ops pmu_backlight_data;
35828 static DEFINE_SPINLOCK(pmu_backlight_lock);
35829 static int sleeping, uses_pmu_bl;
35830 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
35831@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(struct backlight_device *bd)
35832 return bd->props.brightness;
35833 }
35834
35835-static struct backlight_ops pmu_backlight_data = {
35836+static const struct backlight_ops pmu_backlight_data = {
35837 .get_brightness = pmu_backlight_get_brightness,
35838 .update_status = pmu_backlight_update_status,
35839
35840diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
35841index 6f308a4..b5f7ff7 100644
35842--- a/drivers/macintosh/via-pmu.c
35843+++ b/drivers/macintosh/via-pmu.c
35844@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state_t state)
35845 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
35846 }
35847
35848-static struct platform_suspend_ops pmu_pm_ops = {
35849+static const struct platform_suspend_ops pmu_pm_ops = {
35850 .enter = powerbook_sleep,
35851 .valid = pmu_sleep_valid,
35852 };
35853diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35854index 818b617..4656e38 100644
35855--- a/drivers/md/dm-ioctl.c
35856+++ b/drivers/md/dm-ioctl.c
35857@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35858 cmd == DM_LIST_VERSIONS_CMD)
35859 return 0;
35860
35861- if ((cmd == DM_DEV_CREATE_CMD)) {
35862+ if (cmd == DM_DEV_CREATE_CMD) {
35863 if (!*param->name) {
35864 DMWARN("name not supplied when creating device");
35865 return -EINVAL;
35866diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35867index 6021d0a..a878643 100644
35868--- a/drivers/md/dm-raid1.c
35869+++ b/drivers/md/dm-raid1.c
35870@@ -41,7 +41,7 @@ enum dm_raid1_error {
35871
35872 struct mirror {
35873 struct mirror_set *ms;
35874- atomic_t error_count;
35875+ atomic_unchecked_t error_count;
35876 unsigned long error_type;
35877 struct dm_dev *dev;
35878 sector_t offset;
35879@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35880 * simple way to tell if a device has encountered
35881 * errors.
35882 */
35883- atomic_inc(&m->error_count);
35884+ atomic_inc_unchecked(&m->error_count);
35885
35886 if (test_and_set_bit(error_type, &m->error_type))
35887 return;
35888@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35889 }
35890
35891 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
35892- if (!atomic_read(&new->error_count)) {
35893+ if (!atomic_read_unchecked(&new->error_count)) {
35894 set_default_mirror(new);
35895 break;
35896 }
35897@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35898 struct mirror *m = get_default_mirror(ms);
35899
35900 do {
35901- if (likely(!atomic_read(&m->error_count)))
35902+ if (likely(!atomic_read_unchecked(&m->error_count)))
35903 return m;
35904
35905 if (m-- == ms->mirror)
35906@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
35907 {
35908 struct mirror *default_mirror = get_default_mirror(m->ms);
35909
35910- return !atomic_read(&default_mirror->error_count);
35911+ return !atomic_read_unchecked(&default_mirror->error_count);
35912 }
35913
35914 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35915@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35916 */
35917 if (likely(region_in_sync(ms, region, 1)))
35918 m = choose_mirror(ms, bio->bi_sector);
35919- else if (m && atomic_read(&m->error_count))
35920+ else if (m && atomic_read_unchecked(&m->error_count))
35921 m = NULL;
35922
35923 if (likely(m))
35924@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35925 }
35926
35927 ms->mirror[mirror].ms = ms;
35928- atomic_set(&(ms->mirror[mirror].error_count), 0);
35929+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35930 ms->mirror[mirror].error_type = 0;
35931 ms->mirror[mirror].offset = offset;
35932
35933@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_target *ti)
35934 */
35935 static char device_status_char(struct mirror *m)
35936 {
35937- if (!atomic_read(&(m->error_count)))
35938+ if (!atomic_read_unchecked(&(m->error_count)))
35939 return 'A';
35940
35941 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
35942diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35943index bd58703..9f26571 100644
35944--- a/drivers/md/dm-stripe.c
35945+++ b/drivers/md/dm-stripe.c
35946@@ -20,7 +20,7 @@ struct stripe {
35947 struct dm_dev *dev;
35948 sector_t physical_start;
35949
35950- atomic_t error_count;
35951+ atomic_unchecked_t error_count;
35952 };
35953
35954 struct stripe_c {
35955@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35956 kfree(sc);
35957 return r;
35958 }
35959- atomic_set(&(sc->stripe[i].error_count), 0);
35960+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35961 }
35962
35963 ti->private = sc;
35964@@ -257,7 +257,7 @@ static int stripe_status(struct dm_target *ti,
35965 DMEMIT("%d ", sc->stripes);
35966 for (i = 0; i < sc->stripes; i++) {
35967 DMEMIT("%s ", sc->stripe[i].dev->name);
35968- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35969+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35970 'D' : 'A';
35971 }
35972 buffer[i] = '\0';
35973@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35974 */
35975 for (i = 0; i < sc->stripes; i++)
35976 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35977- atomic_inc(&(sc->stripe[i].error_count));
35978- if (atomic_read(&(sc->stripe[i].error_count)) <
35979+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
35980+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35981 DM_IO_ERROR_THRESHOLD)
35982 queue_work(kstriped, &sc->kstriped_ws);
35983 }
35984diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c
35985index 4b04590..13a77b2 100644
35986--- a/drivers/md/dm-sysfs.c
35987+++ b/drivers/md/dm-sysfs.c
35988@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
35989 NULL,
35990 };
35991
35992-static struct sysfs_ops dm_sysfs_ops = {
35993+static const struct sysfs_ops dm_sysfs_ops = {
35994 .show = dm_attr_show,
35995 };
35996
35997diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35998index 03345bb..332250d 100644
35999--- a/drivers/md/dm-table.c
36000+++ b/drivers/md/dm-table.c
36001@@ -376,7 +376,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
36002 if (!dev_size)
36003 return 0;
36004
36005- if ((start >= dev_size) || (start + len > dev_size)) {
36006+ if ((start >= dev_size) || (len > dev_size - start)) {
36007 DMWARN("%s: %s too small for target: "
36008 "start=%llu, len=%llu, dev_size=%llu",
36009 dm_device_name(ti->table->md), bdevname(bdev, b),
36010diff --git a/drivers/md/dm.c b/drivers/md/dm.c
36011index c988ac2..c418141 100644
36012--- a/drivers/md/dm.c
36013+++ b/drivers/md/dm.c
36014@@ -165,9 +165,9 @@ struct mapped_device {
36015 /*
36016 * Event handling.
36017 */
36018- atomic_t event_nr;
36019+ atomic_unchecked_t event_nr;
36020 wait_queue_head_t eventq;
36021- atomic_t uevent_seq;
36022+ atomic_unchecked_t uevent_seq;
36023 struct list_head uevent_list;
36024 spinlock_t uevent_lock; /* Protect access to uevent_list */
36025
36026@@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(int minor)
36027 rwlock_init(&md->map_lock);
36028 atomic_set(&md->holders, 1);
36029 atomic_set(&md->open_count, 0);
36030- atomic_set(&md->event_nr, 0);
36031- atomic_set(&md->uevent_seq, 0);
36032+ atomic_set_unchecked(&md->event_nr, 0);
36033+ atomic_set_unchecked(&md->uevent_seq, 0);
36034 INIT_LIST_HEAD(&md->uevent_list);
36035 spin_lock_init(&md->uevent_lock);
36036
36037@@ -1927,7 +1927,7 @@ static void event_callback(void *context)
36038
36039 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36040
36041- atomic_inc(&md->event_nr);
36042+ atomic_inc_unchecked(&md->event_nr);
36043 wake_up(&md->eventq);
36044 }
36045
36046@@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36047
36048 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36049 {
36050- return atomic_add_return(1, &md->uevent_seq);
36051+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36052 }
36053
36054 uint32_t dm_get_event_nr(struct mapped_device *md)
36055 {
36056- return atomic_read(&md->event_nr);
36057+ return atomic_read_unchecked(&md->event_nr);
36058 }
36059
36060 int dm_wait_event(struct mapped_device *md, int event_nr)
36061 {
36062 return wait_event_interruptible(md->eventq,
36063- (event_nr != atomic_read(&md->event_nr)));
36064+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36065 }
36066
36067 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36068diff --git a/drivers/md/md.c b/drivers/md/md.c
36069index 4ce6e2f..7a9530a 100644
36070--- a/drivers/md/md.c
36071+++ b/drivers/md/md.c
36072@@ -153,10 +153,10 @@ static int start_readonly;
36073 * start build, activate spare
36074 */
36075 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36076-static atomic_t md_event_count;
36077+static atomic_unchecked_t md_event_count;
36078 void md_new_event(mddev_t *mddev)
36079 {
36080- atomic_inc(&md_event_count);
36081+ atomic_inc_unchecked(&md_event_count);
36082 wake_up(&md_event_waiters);
36083 }
36084 EXPORT_SYMBOL_GPL(md_new_event);
36085@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36086 */
36087 static void md_new_event_inintr(mddev_t *mddev)
36088 {
36089- atomic_inc(&md_event_count);
36090+ atomic_inc_unchecked(&md_event_count);
36091 wake_up(&md_event_waiters);
36092 }
36093
36094@@ -1226,7 +1226,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
36095
36096 rdev->preferred_minor = 0xffff;
36097 rdev->data_offset = le64_to_cpu(sb->data_offset);
36098- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36099+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36100
36101 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36102 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36103@@ -1400,7 +1400,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
36104 else
36105 sb->resync_offset = cpu_to_le64(0);
36106
36107- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36108+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36109
36110 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36111 sb->size = cpu_to_le64(mddev->dev_sectors);
36112@@ -2222,7 +2222,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36113 static ssize_t
36114 errors_show(mdk_rdev_t *rdev, char *page)
36115 {
36116- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36117+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36118 }
36119
36120 static ssize_t
36121@@ -2231,7 +2231,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
36122 char *e;
36123 unsigned long n = simple_strtoul(buf, &e, 10);
36124 if (*buf && (*e == 0 || *e == '\n')) {
36125- atomic_set(&rdev->corrected_errors, n);
36126+ atomic_set_unchecked(&rdev->corrected_errors, n);
36127 return len;
36128 }
36129 return -EINVAL;
36130@@ -2525,7 +2525,7 @@ static void rdev_free(struct kobject *ko)
36131 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
36132 kfree(rdev);
36133 }
36134-static struct sysfs_ops rdev_sysfs_ops = {
36135+static const struct sysfs_ops rdev_sysfs_ops = {
36136 .show = rdev_attr_show,
36137 .store = rdev_attr_store,
36138 };
36139@@ -2574,8 +2574,8 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
36140 rdev->data_offset = 0;
36141 rdev->sb_events = 0;
36142 atomic_set(&rdev->nr_pending, 0);
36143- atomic_set(&rdev->read_errors, 0);
36144- atomic_set(&rdev->corrected_errors, 0);
36145+ atomic_set_unchecked(&rdev->read_errors, 0);
36146+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36147
36148 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
36149 if (!size) {
36150@@ -3895,7 +3895,7 @@ static void md_free(struct kobject *ko)
36151 kfree(mddev);
36152 }
36153
36154-static struct sysfs_ops md_sysfs_ops = {
36155+static const struct sysfs_ops md_sysfs_ops = {
36156 .show = md_attr_show,
36157 .store = md_attr_store,
36158 };
36159@@ -4482,7 +4482,8 @@ out:
36160 err = 0;
36161 blk_integrity_unregister(disk);
36162 md_new_event(mddev);
36163- sysfs_notify_dirent(mddev->sysfs_state);
36164+ if (mddev->sysfs_state)
36165+ sysfs_notify_dirent(mddev->sysfs_state);
36166 return err;
36167 }
36168
36169@@ -5962,7 +5963,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36170
36171 spin_unlock(&pers_lock);
36172 seq_printf(seq, "\n");
36173- mi->event = atomic_read(&md_event_count);
36174+ mi->event = atomic_read_unchecked(&md_event_count);
36175 return 0;
36176 }
36177 if (v == (void*)2) {
36178@@ -6051,7 +6052,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36179 chunk_kb ? "KB" : "B");
36180 if (bitmap->file) {
36181 seq_printf(seq, ", file: ");
36182- seq_path(seq, &bitmap->file->f_path, " \t\n");
36183+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
36184 }
36185
36186 seq_printf(seq, "\n");
36187@@ -6085,7 +6086,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36188 else {
36189 struct seq_file *p = file->private_data;
36190 p->private = mi;
36191- mi->event = atomic_read(&md_event_count);
36192+ mi->event = atomic_read_unchecked(&md_event_count);
36193 }
36194 return error;
36195 }
36196@@ -6101,7 +6102,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36197 /* always allow read */
36198 mask = POLLIN | POLLRDNORM;
36199
36200- if (mi->event != atomic_read(&md_event_count))
36201+ if (mi->event != atomic_read_unchecked(&md_event_count))
36202 mask |= POLLERR | POLLPRI;
36203 return mask;
36204 }
36205@@ -6145,7 +6146,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
36206 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36207 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36208 (int)part_stat_read(&disk->part0, sectors[1]) -
36209- atomic_read(&disk->sync_io);
36210+ atomic_read_unchecked(&disk->sync_io);
36211 /* sync IO will cause sync_io to increase before the disk_stats
36212 * as sync_io is counted when a request starts, and
36213 * disk_stats is counted when it completes.
36214diff --git a/drivers/md/md.h b/drivers/md/md.h
36215index 87430fe..0024a4c 100644
36216--- a/drivers/md/md.h
36217+++ b/drivers/md/md.h
36218@@ -94,10 +94,10 @@ struct mdk_rdev_s
36219 * only maintained for arrays that
36220 * support hot removal
36221 */
36222- atomic_t read_errors; /* number of consecutive read errors that
36223+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36224 * we have tried to ignore.
36225 */
36226- atomic_t corrected_errors; /* number of corrected read errors,
36227+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36228 * for reporting to userspace and storing
36229 * in superblock.
36230 */
36231@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
36232
36233 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36234 {
36235- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36236+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36237 }
36238
36239 struct mdk_personality
36240diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36241index 968cb14..f0ad2e4 100644
36242--- a/drivers/md/raid1.c
36243+++ b/drivers/md/raid1.c
36244@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
36245 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
36246 continue;
36247 rdev = conf->mirrors[d].rdev;
36248- atomic_add(s, &rdev->corrected_errors);
36249+ atomic_add_unchecked(s, &rdev->corrected_errors);
36250 if (sync_page_io(rdev->bdev,
36251 sect + rdev->data_offset,
36252 s<<9,
36253@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
36254 /* Well, this device is dead */
36255 md_error(mddev, rdev);
36256 else {
36257- atomic_add(s, &rdev->corrected_errors);
36258+ atomic_add_unchecked(s, &rdev->corrected_errors);
36259 printk(KERN_INFO
36260 "raid1:%s: read error corrected "
36261 "(%d sectors at %llu on %s)\n",
36262diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36263index 1b4e232..cf0f534 100644
36264--- a/drivers/md/raid10.c
36265+++ b/drivers/md/raid10.c
36266@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bio, int error)
36267 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
36268 set_bit(R10BIO_Uptodate, &r10_bio->state);
36269 else {
36270- atomic_add(r10_bio->sectors,
36271+ atomic_add_unchecked(r10_bio->sectors,
36272 &conf->mirrors[d].rdev->corrected_errors);
36273 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
36274 md_error(r10_bio->mddev,
36275@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
36276 test_bit(In_sync, &rdev->flags)) {
36277 atomic_inc(&rdev->nr_pending);
36278 rcu_read_unlock();
36279- atomic_add(s, &rdev->corrected_errors);
36280+ atomic_add_unchecked(s, &rdev->corrected_errors);
36281 if (sync_page_io(rdev->bdev,
36282 r10_bio->devs[sl].addr +
36283 sect + rdev->data_offset,
36284diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36285index 883215d..675bf47 100644
36286--- a/drivers/md/raid5.c
36287+++ b/drivers/md/raid5.c
36288@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
36289 bi->bi_next = NULL;
36290 if ((rw & WRITE) &&
36291 test_bit(R5_ReWrite, &sh->dev[i].flags))
36292- atomic_add(STRIPE_SECTORS,
36293+ atomic_add_unchecked(STRIPE_SECTORS,
36294 &rdev->corrected_errors);
36295 generic_make_request(bi);
36296 } else {
36297@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struct bio * bi, int error)
36298 clear_bit(R5_ReadError, &sh->dev[i].flags);
36299 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36300 }
36301- if (atomic_read(&conf->disks[i].rdev->read_errors))
36302- atomic_set(&conf->disks[i].rdev->read_errors, 0);
36303+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
36304+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
36305 } else {
36306 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
36307 int retry = 0;
36308 rdev = conf->disks[i].rdev;
36309
36310 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36311- atomic_inc(&rdev->read_errors);
36312+ atomic_inc_unchecked(&rdev->read_errors);
36313 if (conf->mddev->degraded >= conf->max_degraded)
36314 printk_rl(KERN_WARNING
36315 "raid5:%s: read error not correctable "
36316@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36317 (unsigned long long)(sh->sector
36318 + rdev->data_offset),
36319 bdn);
36320- else if (atomic_read(&rdev->read_errors)
36321+ else if (atomic_read_unchecked(&rdev->read_errors)
36322 > conf->max_nr_stripes)
36323 printk(KERN_WARNING
36324 "raid5:%s: Too many read errors, failing device %s.\n",
36325@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
36326 sector_t r_sector;
36327 struct stripe_head sh2;
36328
36329+ pax_track_stack();
36330
36331 chunk_offset = sector_div(new_sector, sectors_per_chunk);
36332 stripe = new_sector;
36333diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
36334index 05bde9c..2f31d40 100644
36335--- a/drivers/media/common/saa7146_hlp.c
36336+++ b/drivers/media/common/saa7146_hlp.c
36337@@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
36338
36339 int x[32], y[32], w[32], h[32];
36340
36341+ pax_track_stack();
36342+
36343 /* clear out memory */
36344 memset(&line_list[0], 0x00, sizeof(u32)*32);
36345 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
36346diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36347index cb22da5..82b686e 100644
36348--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36349+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36350@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
36351 u8 buf[HOST_LINK_BUF_SIZE];
36352 int i;
36353
36354+ pax_track_stack();
36355+
36356 dprintk("%s\n", __func__);
36357
36358 /* check if we have space for a link buf in the rx_buffer */
36359@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
36360 unsigned long timeout;
36361 int written;
36362
36363+ pax_track_stack();
36364+
36365 dprintk("%s\n", __func__);
36366
36367 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
36368diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
36369index 2fe05d0..a3289c4 100644
36370--- a/drivers/media/dvb/dvb-core/dvb_demux.h
36371+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
36372@@ -71,7 +71,7 @@ struct dvb_demux_feed {
36373 union {
36374 dmx_ts_cb ts;
36375 dmx_section_cb sec;
36376- } cb;
36377+ } __no_const cb;
36378
36379 struct dvb_demux *demux;
36380 void *priv;
36381diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
36382index 94159b9..376bd8e 100644
36383--- a/drivers/media/dvb/dvb-core/dvbdev.c
36384+++ b/drivers/media/dvb/dvb-core/dvbdev.c
36385@@ -191,7 +191,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36386 const struct dvb_device *template, void *priv, int type)
36387 {
36388 struct dvb_device *dvbdev;
36389- struct file_operations *dvbdevfops;
36390+ file_operations_no_const *dvbdevfops;
36391 struct device *clsdev;
36392 int minor;
36393 int id;
36394diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
36395index 2a53dd0..db8c07a 100644
36396--- a/drivers/media/dvb/dvb-usb/cxusb.c
36397+++ b/drivers/media/dvb/dvb-usb/cxusb.c
36398@@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36399 struct dib0700_adapter_state {
36400 int (*set_param_save) (struct dvb_frontend *,
36401 struct dvb_frontend_parameters *);
36402-};
36403+} __no_const;
36404
36405 static int dib7070_set_param_override(struct dvb_frontend *fe,
36406 struct dvb_frontend_parameters *fep)
36407diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
36408index db7f7f7..f55e96f 100644
36409--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
36410+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
36411@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
36412
36413 u8 buf[260];
36414
36415+ pax_track_stack();
36416+
36417 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
36418 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
36419
36420diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36421index 524acf5..5ffc403 100644
36422--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
36423+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36424@@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
36425
36426 struct dib0700_adapter_state {
36427 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
36428-};
36429+} __no_const;
36430
36431 /* Hauppauge Nova-T 500 (aka Bristol)
36432 * has a LNA on GPIO0 which is enabled by setting 1 */
36433diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
36434index ba91735..4261d84 100644
36435--- a/drivers/media/dvb/frontends/dib3000.h
36436+++ b/drivers/media/dvb/frontends/dib3000.h
36437@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36438 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36439 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36440 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36441-};
36442+} __no_const;
36443
36444 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36445 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36446diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
36447index c709ce6..b3fe620 100644
36448--- a/drivers/media/dvb/frontends/or51211.c
36449+++ b/drivers/media/dvb/frontends/or51211.c
36450@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
36451 u8 tudata[585];
36452 int i;
36453
36454+ pax_track_stack();
36455+
36456 dprintk("Firmware is %zd bytes\n",fw->size);
36457
36458 /* Get eprom data */
36459diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36460index 482d0f3..ee1e202 100644
36461--- a/drivers/media/radio/radio-cadet.c
36462+++ b/drivers/media/radio/radio-cadet.c
36463@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36464 while (i < count && dev->rdsin != dev->rdsout)
36465 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36466
36467- if (copy_to_user(data, readbuf, i))
36468+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
36469 return -EFAULT;
36470 return i;
36471 }
36472diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
36473index 6dd51e2..0359b92 100644
36474--- a/drivers/media/video/cx18/cx18-driver.c
36475+++ b/drivers/media/video/cx18/cx18-driver.c
36476@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
36477
36478 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
36479
36480-static atomic_t cx18_instance = ATOMIC_INIT(0);
36481+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
36482
36483 /* Parameter declarations */
36484 static int cardtype[CX18_MAX_CARDS];
36485@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
36486 struct i2c_client c;
36487 u8 eedata[256];
36488
36489+ pax_track_stack();
36490+
36491 memset(&c, 0, sizeof(c));
36492 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
36493 c.adapter = &cx->i2c_adap[0];
36494@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
36495 struct cx18 *cx;
36496
36497 /* FIXME - module parameter arrays constrain max instances */
36498- i = atomic_inc_return(&cx18_instance) - 1;
36499+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
36500 if (i >= CX18_MAX_CARDS) {
36501 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
36502 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
36503diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
36504index 463ec34..2f4625a 100644
36505--- a/drivers/media/video/ivtv/ivtv-driver.c
36506+++ b/drivers/media/video/ivtv/ivtv-driver.c
36507@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
36508 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
36509
36510 /* ivtv instance counter */
36511-static atomic_t ivtv_instance = ATOMIC_INIT(0);
36512+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
36513
36514 /* Parameter declarations */
36515 static int cardtype[IVTV_MAX_CARDS];
36516diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
36517index 5fc4ac0..652a54a 100644
36518--- a/drivers/media/video/omap24xxcam.c
36519+++ b/drivers/media/video/omap24xxcam.c
36520@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
36521 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
36522
36523 do_gettimeofday(&vb->ts);
36524- vb->field_count = atomic_add_return(2, &fh->field_count);
36525+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
36526 if (csr & csr_error) {
36527 vb->state = VIDEOBUF_ERROR;
36528 if (!atomic_read(&fh->cam->in_reset)) {
36529diff --git a/drivers/media/video/omap24xxcam.h b/drivers/media/video/omap24xxcam.h
36530index 2ce67f5..cf26a5b 100644
36531--- a/drivers/media/video/omap24xxcam.h
36532+++ b/drivers/media/video/omap24xxcam.h
36533@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
36534 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
36535 struct videobuf_queue vbq;
36536 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
36537- atomic_t field_count; /* field counter for videobuf_buffer */
36538+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
36539 /* accessing cam here doesn't need serialisation: it's constant */
36540 struct omap24xxcam_device *cam;
36541 };
36542diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36543index 299afa4..eb47459 100644
36544--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36545+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36546@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
36547 u8 *eeprom;
36548 struct tveeprom tvdata;
36549
36550+ pax_track_stack();
36551+
36552 memset(&tvdata,0,sizeof(tvdata));
36553
36554 eeprom = pvr2_eeprom_fetch(hdw);
36555diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36556index 5b152ff..3320638 100644
36557--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36558+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36559@@ -195,7 +195,7 @@ struct pvr2_hdw {
36560
36561 /* I2C stuff */
36562 struct i2c_adapter i2c_adap;
36563- struct i2c_algorithm i2c_algo;
36564+ i2c_algorithm_no_const i2c_algo;
36565 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
36566 int i2c_cx25840_hack_state;
36567 int i2c_linked;
36568diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
36569index 1eabff6..8e2313a 100644
36570--- a/drivers/media/video/saa7134/saa6752hs.c
36571+++ b/drivers/media/video/saa7134/saa6752hs.c
36572@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
36573 unsigned char localPAT[256];
36574 unsigned char localPMT[256];
36575
36576+ pax_track_stack();
36577+
36578 /* Set video format - must be done first as it resets other settings */
36579 set_reg8(client, 0x41, h->video_format);
36580
36581diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
36582index 9c1d3ac..b1b49e9 100644
36583--- a/drivers/media/video/saa7164/saa7164-cmd.c
36584+++ b/drivers/media/video/saa7164/saa7164-cmd.c
36585@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
36586 wait_queue_head_t *q = 0;
36587 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36588
36589+ pax_track_stack();
36590+
36591 /* While any outstand message on the bus exists... */
36592 do {
36593
36594@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
36595 u8 tmp[512];
36596 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36597
36598+ pax_track_stack();
36599+
36600 while (loop) {
36601
36602 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
36603diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
36604index b085496..cde0270 100644
36605--- a/drivers/media/video/usbvideo/ibmcam.c
36606+++ b/drivers/media/video/usbvideo/ibmcam.c
36607@@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] = {
36608 static int __init ibmcam_init(void)
36609 {
36610 struct usbvideo_cb cbTbl;
36611- memset(&cbTbl, 0, sizeof(cbTbl));
36612- cbTbl.probe = ibmcam_probe;
36613- cbTbl.setupOnOpen = ibmcam_setup_on_open;
36614- cbTbl.videoStart = ibmcam_video_start;
36615- cbTbl.videoStop = ibmcam_video_stop;
36616- cbTbl.processData = ibmcam_ProcessIsocData;
36617- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36618- cbTbl.adjustPicture = ibmcam_adjust_picture;
36619- cbTbl.getFPS = ibmcam_calculate_fps;
36620+ memset((void *)&cbTbl, 0, sizeof(cbTbl));
36621+ *(void **)&cbTbl.probe = ibmcam_probe;
36622+ *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
36623+ *(void **)&cbTbl.videoStart = ibmcam_video_start;
36624+ *(void **)&cbTbl.videoStop = ibmcam_video_stop;
36625+ *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
36626+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36627+ *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
36628+ *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
36629 return usbvideo_register(
36630 &cams,
36631 MAX_IBMCAM,
36632diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
36633index 31d57f2..600b735 100644
36634--- a/drivers/media/video/usbvideo/konicawc.c
36635+++ b/drivers/media/video/usbvideo/konicawc.c
36636@@ -225,7 +225,7 @@ static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev
36637 int error;
36638
36639 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36640- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36641+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36642
36643 cam->input = input_dev = input_allocate_device();
36644 if (!input_dev) {
36645@@ -935,16 +935,16 @@ static int __init konicawc_init(void)
36646 struct usbvideo_cb cbTbl;
36647 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
36648 DRIVER_DESC "\n");
36649- memset(&cbTbl, 0, sizeof(cbTbl));
36650- cbTbl.probe = konicawc_probe;
36651- cbTbl.setupOnOpen = konicawc_setup_on_open;
36652- cbTbl.processData = konicawc_process_isoc;
36653- cbTbl.getFPS = konicawc_calculate_fps;
36654- cbTbl.setVideoMode = konicawc_set_video_mode;
36655- cbTbl.startDataPump = konicawc_start_data;
36656- cbTbl.stopDataPump = konicawc_stop_data;
36657- cbTbl.adjustPicture = konicawc_adjust_picture;
36658- cbTbl.userFree = konicawc_free_uvd;
36659+ memset((void * )&cbTbl, 0, sizeof(cbTbl));
36660+ *(void **)&cbTbl.probe = konicawc_probe;
36661+ *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
36662+ *(void **)&cbTbl.processData = konicawc_process_isoc;
36663+ *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
36664+ *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
36665+ *(void **)&cbTbl.startDataPump = konicawc_start_data;
36666+ *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
36667+ *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
36668+ *(void **)&cbTbl.userFree = konicawc_free_uvd;
36669 return usbvideo_register(
36670 &cams,
36671 MAX_CAMERAS,
36672diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
36673index 803d3e4..c4d1b96 100644
36674--- a/drivers/media/video/usbvideo/quickcam_messenger.c
36675+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
36676@@ -89,7 +89,7 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
36677 int error;
36678
36679 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36680- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36681+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36682
36683 cam->input = input_dev = input_allocate_device();
36684 if (!input_dev) {
36685diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
36686index fbd1b63..292f9f0 100644
36687--- a/drivers/media/video/usbvideo/ultracam.c
36688+++ b/drivers/media/video/usbvideo/ultracam.c
36689@@ -655,14 +655,14 @@ static int __init ultracam_init(void)
36690 {
36691 struct usbvideo_cb cbTbl;
36692 memset(&cbTbl, 0, sizeof(cbTbl));
36693- cbTbl.probe = ultracam_probe;
36694- cbTbl.setupOnOpen = ultracam_setup_on_open;
36695- cbTbl.videoStart = ultracam_video_start;
36696- cbTbl.videoStop = ultracam_video_stop;
36697- cbTbl.processData = ultracam_ProcessIsocData;
36698- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36699- cbTbl.adjustPicture = ultracam_adjust_picture;
36700- cbTbl.getFPS = ultracam_calculate_fps;
36701+ *(void **)&cbTbl.probe = ultracam_probe;
36702+ *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
36703+ *(void **)&cbTbl.videoStart = ultracam_video_start;
36704+ *(void **)&cbTbl.videoStop = ultracam_video_stop;
36705+ *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
36706+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36707+ *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
36708+ *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
36709 return usbvideo_register(
36710 &cams,
36711 MAX_CAMERAS,
36712diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
36713index dea8b32..34f6878 100644
36714--- a/drivers/media/video/usbvideo/usbvideo.c
36715+++ b/drivers/media/video/usbvideo/usbvideo.c
36716@@ -697,15 +697,15 @@ int usbvideo_register(
36717 __func__, cams, base_size, num_cams);
36718
36719 /* Copy callbacks, apply defaults for those that are not set */
36720- memmove(&cams->cb, cbTbl, sizeof(cams->cb));
36721+ memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
36722 if (cams->cb.getFrame == NULL)
36723- cams->cb.getFrame = usbvideo_GetFrame;
36724+ *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
36725 if (cams->cb.disconnect == NULL)
36726- cams->cb.disconnect = usbvideo_Disconnect;
36727+ *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
36728 if (cams->cb.startDataPump == NULL)
36729- cams->cb.startDataPump = usbvideo_StartDataPump;
36730+ *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
36731 if (cams->cb.stopDataPump == NULL)
36732- cams->cb.stopDataPump = usbvideo_StopDataPump;
36733+ *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
36734
36735 cams->num_cameras = num_cams;
36736 cams->cam = (struct uvd *) &cams[1];
36737diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
36738index c66985b..7fa143a 100644
36739--- a/drivers/media/video/usbvideo/usbvideo.h
36740+++ b/drivers/media/video/usbvideo/usbvideo.h
36741@@ -268,7 +268,7 @@ struct usbvideo_cb {
36742 int (*startDataPump)(struct uvd *uvd);
36743 void (*stopDataPump)(struct uvd *uvd);
36744 int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
36745-};
36746+} __no_const;
36747
36748 struct usbvideo {
36749 int num_cameras; /* As allocated */
36750diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
36751index e0f91e4..37554ea 100644
36752--- a/drivers/media/video/usbvision/usbvision-core.c
36753+++ b/drivers/media/video/usbvision/usbvision-core.c
36754@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
36755 unsigned char rv, gv, bv;
36756 static unsigned char *Y, *U, *V;
36757
36758+ pax_track_stack();
36759+
36760 frame = usbvision->curFrame;
36761 imageSize = frame->frmwidth * frame->frmheight;
36762 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
36763diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
36764index 0d06e7c..3d17d24 100644
36765--- a/drivers/media/video/v4l2-device.c
36766+++ b/drivers/media/video/v4l2-device.c
36767@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
36768 EXPORT_SYMBOL_GPL(v4l2_device_register);
36769
36770 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
36771- atomic_t *instance)
36772+ atomic_unchecked_t *instance)
36773 {
36774- int num = atomic_inc_return(instance) - 1;
36775+ int num = atomic_inc_return_unchecked(instance) - 1;
36776 int len = strlen(basename);
36777
36778 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
36779diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
36780index 032ebae..6a3532c 100644
36781--- a/drivers/media/video/videobuf-dma-sg.c
36782+++ b/drivers/media/video/videobuf-dma-sg.c
36783@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
36784 {
36785 struct videobuf_queue q;
36786
36787+ pax_track_stack();
36788+
36789 /* Required to make generic handler to call __videobuf_alloc */
36790 q.int_ops = &sg_ops;
36791
36792diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36793index b6992b7..9fa7547 100644
36794--- a/drivers/message/fusion/mptbase.c
36795+++ b/drivers/message/fusion/mptbase.c
36796@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
36797 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36798 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36799
36800+#ifdef CONFIG_GRKERNSEC_HIDESYM
36801+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36802+ NULL, NULL);
36803+#else
36804 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36805 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36806+#endif
36807+
36808 /*
36809 * Rounding UP to nearest 4-kB boundary here...
36810 */
36811diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36812index 83873e3..e360e9a 100644
36813--- a/drivers/message/fusion/mptsas.c
36814+++ b/drivers/message/fusion/mptsas.c
36815@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36816 return 0;
36817 }
36818
36819+static inline void
36820+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36821+{
36822+ if (phy_info->port_details) {
36823+ phy_info->port_details->rphy = rphy;
36824+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36825+ ioc->name, rphy));
36826+ }
36827+
36828+ if (rphy) {
36829+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36830+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36831+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36832+ ioc->name, rphy, rphy->dev.release));
36833+ }
36834+}
36835+
36836 /* no mutex */
36837 static void
36838 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36839@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36840 return NULL;
36841 }
36842
36843-static inline void
36844-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36845-{
36846- if (phy_info->port_details) {
36847- phy_info->port_details->rphy = rphy;
36848- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36849- ioc->name, rphy));
36850- }
36851-
36852- if (rphy) {
36853- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36854- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36855- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36856- ioc->name, rphy, rphy->dev.release));
36857- }
36858-}
36859-
36860 static inline struct sas_port *
36861 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36862 {
36863diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36864index bd096ca..332cf76 100644
36865--- a/drivers/message/fusion/mptscsih.c
36866+++ b/drivers/message/fusion/mptscsih.c
36867@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36868
36869 h = shost_priv(SChost);
36870
36871- if (h) {
36872- if (h->info_kbuf == NULL)
36873- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36874- return h->info_kbuf;
36875- h->info_kbuf[0] = '\0';
36876+ if (!h)
36877+ return NULL;
36878
36879- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36880- h->info_kbuf[size-1] = '\0';
36881- }
36882+ if (h->info_kbuf == NULL)
36883+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36884+ return h->info_kbuf;
36885+ h->info_kbuf[0] = '\0';
36886+
36887+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36888+ h->info_kbuf[size-1] = '\0';
36889
36890 return h->info_kbuf;
36891 }
36892diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
36893index efba702..59b2c0f 100644
36894--- a/drivers/message/i2o/i2o_config.c
36895+++ b/drivers/message/i2o/i2o_config.c
36896@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned long arg)
36897 struct i2o_message *msg;
36898 unsigned int iop;
36899
36900+ pax_track_stack();
36901+
36902 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
36903 return -EFAULT;
36904
36905diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36906index 7045c45..c07b170 100644
36907--- a/drivers/message/i2o/i2o_proc.c
36908+++ b/drivers/message/i2o/i2o_proc.c
36909@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
36910 "Array Controller Device"
36911 };
36912
36913-static char *chtostr(u8 * chars, int n)
36914-{
36915- char tmp[256];
36916- tmp[0] = 0;
36917- return strncat(tmp, (char *)chars, n);
36918-}
36919-
36920 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36921 char *group)
36922 {
36923@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36924
36925 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36926 seq_printf(seq, "%-#8x", ddm_table.module_id);
36927- seq_printf(seq, "%-29s",
36928- chtostr(ddm_table.module_name_version, 28));
36929+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36930 seq_printf(seq, "%9d ", ddm_table.data_size);
36931 seq_printf(seq, "%8d", ddm_table.code_size);
36932
36933@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36934
36935 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36936 seq_printf(seq, "%-#8x", dst->module_id);
36937- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
36938- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
36939+ seq_printf(seq, "%-.28s", dst->module_name_version);
36940+ seq_printf(seq, "%-.8s", dst->date);
36941 seq_printf(seq, "%8d ", dst->module_size);
36942 seq_printf(seq, "%8d ", dst->mpb_size);
36943 seq_printf(seq, "0x%04x", dst->module_flags);
36944@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36945 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36946 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36947 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36948- seq_printf(seq, "Vendor info : %s\n",
36949- chtostr((u8 *) (work32 + 2), 16));
36950- seq_printf(seq, "Product info : %s\n",
36951- chtostr((u8 *) (work32 + 6), 16));
36952- seq_printf(seq, "Description : %s\n",
36953- chtostr((u8 *) (work32 + 10), 16));
36954- seq_printf(seq, "Product rev. : %s\n",
36955- chtostr((u8 *) (work32 + 14), 8));
36956+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36957+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36958+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36959+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36960
36961 seq_printf(seq, "Serial number : ");
36962 print_serial_number(seq, (u8 *) (work32 + 16),
36963@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36964 }
36965
36966 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36967- seq_printf(seq, "Module name : %s\n",
36968- chtostr(result.module_name, 24));
36969- seq_printf(seq, "Module revision : %s\n",
36970- chtostr(result.module_rev, 8));
36971+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
36972+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36973
36974 seq_printf(seq, "Serial number : ");
36975 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36976@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36977 return 0;
36978 }
36979
36980- seq_printf(seq, "Device name : %s\n",
36981- chtostr(result.device_name, 64));
36982- seq_printf(seq, "Service name : %s\n",
36983- chtostr(result.service_name, 64));
36984- seq_printf(seq, "Physical name : %s\n",
36985- chtostr(result.physical_location, 64));
36986- seq_printf(seq, "Instance number : %s\n",
36987- chtostr(result.instance_number, 4));
36988+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
36989+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
36990+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36991+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36992
36993 return 0;
36994 }
36995diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36996index 27cf4af..b1205b8 100644
36997--- a/drivers/message/i2o/iop.c
36998+++ b/drivers/message/i2o/iop.c
36999@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
37000
37001 spin_lock_irqsave(&c->context_list_lock, flags);
37002
37003- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
37004- atomic_inc(&c->context_list_counter);
37005+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
37006+ atomic_inc_unchecked(&c->context_list_counter);
37007
37008- entry->context = atomic_read(&c->context_list_counter);
37009+ entry->context = atomic_read_unchecked(&c->context_list_counter);
37010
37011 list_add(&entry->list, &c->context_list);
37012
37013@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
37014
37015 #if BITS_PER_LONG == 64
37016 spin_lock_init(&c->context_list_lock);
37017- atomic_set(&c->context_list_counter, 0);
37018+ atomic_set_unchecked(&c->context_list_counter, 0);
37019 INIT_LIST_HEAD(&c->context_list);
37020 #endif
37021
37022diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
37023index 78e3e85..66c9a0d 100644
37024--- a/drivers/mfd/ab3100-core.c
37025+++ b/drivers/mfd/ab3100-core.c
37026@@ -777,7 +777,7 @@ struct ab_family_id {
37027 char *name;
37028 };
37029
37030-static const struct ab_family_id ids[] __initdata = {
37031+static const struct ab_family_id ids[] __initconst = {
37032 /* AB3100 */
37033 {
37034 .id = 0xc0,
37035diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
37036index 8d8c932..8104515 100644
37037--- a/drivers/mfd/wm8350-i2c.c
37038+++ b/drivers/mfd/wm8350-i2c.c
37039@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
37040 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
37041 int ret;
37042
37043+ pax_track_stack();
37044+
37045 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
37046 return -EINVAL;
37047
37048diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
37049index e4ff50b..4cc3f04 100644
37050--- a/drivers/misc/kgdbts.c
37051+++ b/drivers/misc/kgdbts.c
37052@@ -118,7 +118,7 @@
37053 } while (0)
37054 #define MAX_CONFIG_LEN 40
37055
37056-static struct kgdb_io kgdbts_io_ops;
37057+static const struct kgdb_io kgdbts_io_ops;
37058 static char get_buf[BUFMAX];
37059 static int get_buf_cnt;
37060 static char put_buf[BUFMAX];
37061@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void)
37062 module_put(THIS_MODULE);
37063 }
37064
37065-static struct kgdb_io kgdbts_io_ops = {
37066+static const struct kgdb_io kgdbts_io_ops = {
37067 .name = "kgdbts",
37068 .read_char = kgdbts_get_char,
37069 .write_char = kgdbts_put_char,
37070diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
37071index 37e7cfc..67cfb76 100644
37072--- a/drivers/misc/sgi-gru/gruhandles.c
37073+++ b/drivers/misc/sgi-gru/gruhandles.c
37074@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37075
37076 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
37077 {
37078- atomic_long_inc(&mcs_op_statistics[op].count);
37079- atomic_long_add(clks, &mcs_op_statistics[op].total);
37080+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
37081+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
37082 if (mcs_op_statistics[op].max < clks)
37083 mcs_op_statistics[op].max = clks;
37084 }
37085diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
37086index 3f2375c..467c6e6 100644
37087--- a/drivers/misc/sgi-gru/gruprocfs.c
37088+++ b/drivers/misc/sgi-gru/gruprocfs.c
37089@@ -32,9 +32,9 @@
37090
37091 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
37092
37093-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
37094+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
37095 {
37096- unsigned long val = atomic_long_read(v);
37097+ unsigned long val = atomic_long_read_unchecked(v);
37098
37099 if (val)
37100 seq_printf(s, "%16lu %s\n", val, id);
37101@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
37102 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
37103
37104 for (op = 0; op < mcsop_last; op++) {
37105- count = atomic_long_read(&mcs_op_statistics[op].count);
37106- total = atomic_long_read(&mcs_op_statistics[op].total);
37107+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
37108+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
37109 max = mcs_op_statistics[op].max;
37110 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
37111 count ? total / count : 0, max);
37112diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
37113index 46990bc..4a251b5 100644
37114--- a/drivers/misc/sgi-gru/grutables.h
37115+++ b/drivers/misc/sgi-gru/grutables.h
37116@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
37117 * GRU statistics.
37118 */
37119 struct gru_stats_s {
37120- atomic_long_t vdata_alloc;
37121- atomic_long_t vdata_free;
37122- atomic_long_t gts_alloc;
37123- atomic_long_t gts_free;
37124- atomic_long_t vdata_double_alloc;
37125- atomic_long_t gts_double_allocate;
37126- atomic_long_t assign_context;
37127- atomic_long_t assign_context_failed;
37128- atomic_long_t free_context;
37129- atomic_long_t load_user_context;
37130- atomic_long_t load_kernel_context;
37131- atomic_long_t lock_kernel_context;
37132- atomic_long_t unlock_kernel_context;
37133- atomic_long_t steal_user_context;
37134- atomic_long_t steal_kernel_context;
37135- atomic_long_t steal_context_failed;
37136- atomic_long_t nopfn;
37137- atomic_long_t break_cow;
37138- atomic_long_t asid_new;
37139- atomic_long_t asid_next;
37140- atomic_long_t asid_wrap;
37141- atomic_long_t asid_reuse;
37142- atomic_long_t intr;
37143- atomic_long_t intr_mm_lock_failed;
37144- atomic_long_t call_os;
37145- atomic_long_t call_os_offnode_reference;
37146- atomic_long_t call_os_check_for_bug;
37147- atomic_long_t call_os_wait_queue;
37148- atomic_long_t user_flush_tlb;
37149- atomic_long_t user_unload_context;
37150- atomic_long_t user_exception;
37151- atomic_long_t set_context_option;
37152- atomic_long_t migrate_check;
37153- atomic_long_t migrated_retarget;
37154- atomic_long_t migrated_unload;
37155- atomic_long_t migrated_unload_delay;
37156- atomic_long_t migrated_nopfn_retarget;
37157- atomic_long_t migrated_nopfn_unload;
37158- atomic_long_t tlb_dropin;
37159- atomic_long_t tlb_dropin_fail_no_asid;
37160- atomic_long_t tlb_dropin_fail_upm;
37161- atomic_long_t tlb_dropin_fail_invalid;
37162- atomic_long_t tlb_dropin_fail_range_active;
37163- atomic_long_t tlb_dropin_fail_idle;
37164- atomic_long_t tlb_dropin_fail_fmm;
37165- atomic_long_t tlb_dropin_fail_no_exception;
37166- atomic_long_t tlb_dropin_fail_no_exception_war;
37167- atomic_long_t tfh_stale_on_fault;
37168- atomic_long_t mmu_invalidate_range;
37169- atomic_long_t mmu_invalidate_page;
37170- atomic_long_t mmu_clear_flush_young;
37171- atomic_long_t flush_tlb;
37172- atomic_long_t flush_tlb_gru;
37173- atomic_long_t flush_tlb_gru_tgh;
37174- atomic_long_t flush_tlb_gru_zero_asid;
37175+ atomic_long_unchecked_t vdata_alloc;
37176+ atomic_long_unchecked_t vdata_free;
37177+ atomic_long_unchecked_t gts_alloc;
37178+ atomic_long_unchecked_t gts_free;
37179+ atomic_long_unchecked_t vdata_double_alloc;
37180+ atomic_long_unchecked_t gts_double_allocate;
37181+ atomic_long_unchecked_t assign_context;
37182+ atomic_long_unchecked_t assign_context_failed;
37183+ atomic_long_unchecked_t free_context;
37184+ atomic_long_unchecked_t load_user_context;
37185+ atomic_long_unchecked_t load_kernel_context;
37186+ atomic_long_unchecked_t lock_kernel_context;
37187+ atomic_long_unchecked_t unlock_kernel_context;
37188+ atomic_long_unchecked_t steal_user_context;
37189+ atomic_long_unchecked_t steal_kernel_context;
37190+ atomic_long_unchecked_t steal_context_failed;
37191+ atomic_long_unchecked_t nopfn;
37192+ atomic_long_unchecked_t break_cow;
37193+ atomic_long_unchecked_t asid_new;
37194+ atomic_long_unchecked_t asid_next;
37195+ atomic_long_unchecked_t asid_wrap;
37196+ atomic_long_unchecked_t asid_reuse;
37197+ atomic_long_unchecked_t intr;
37198+ atomic_long_unchecked_t intr_mm_lock_failed;
37199+ atomic_long_unchecked_t call_os;
37200+ atomic_long_unchecked_t call_os_offnode_reference;
37201+ atomic_long_unchecked_t call_os_check_for_bug;
37202+ atomic_long_unchecked_t call_os_wait_queue;
37203+ atomic_long_unchecked_t user_flush_tlb;
37204+ atomic_long_unchecked_t user_unload_context;
37205+ atomic_long_unchecked_t user_exception;
37206+ atomic_long_unchecked_t set_context_option;
37207+ atomic_long_unchecked_t migrate_check;
37208+ atomic_long_unchecked_t migrated_retarget;
37209+ atomic_long_unchecked_t migrated_unload;
37210+ atomic_long_unchecked_t migrated_unload_delay;
37211+ atomic_long_unchecked_t migrated_nopfn_retarget;
37212+ atomic_long_unchecked_t migrated_nopfn_unload;
37213+ atomic_long_unchecked_t tlb_dropin;
37214+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37215+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37216+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37217+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37218+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37219+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37220+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37221+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
37222+ atomic_long_unchecked_t tfh_stale_on_fault;
37223+ atomic_long_unchecked_t mmu_invalidate_range;
37224+ atomic_long_unchecked_t mmu_invalidate_page;
37225+ atomic_long_unchecked_t mmu_clear_flush_young;
37226+ atomic_long_unchecked_t flush_tlb;
37227+ atomic_long_unchecked_t flush_tlb_gru;
37228+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37229+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37230
37231- atomic_long_t copy_gpa;
37232+ atomic_long_unchecked_t copy_gpa;
37233
37234- atomic_long_t mesq_receive;
37235- atomic_long_t mesq_receive_none;
37236- atomic_long_t mesq_send;
37237- atomic_long_t mesq_send_failed;
37238- atomic_long_t mesq_noop;
37239- atomic_long_t mesq_send_unexpected_error;
37240- atomic_long_t mesq_send_lb_overflow;
37241- atomic_long_t mesq_send_qlimit_reached;
37242- atomic_long_t mesq_send_amo_nacked;
37243- atomic_long_t mesq_send_put_nacked;
37244- atomic_long_t mesq_qf_not_full;
37245- atomic_long_t mesq_qf_locked;
37246- atomic_long_t mesq_qf_noop_not_full;
37247- atomic_long_t mesq_qf_switch_head_failed;
37248- atomic_long_t mesq_qf_unexpected_error;
37249- atomic_long_t mesq_noop_unexpected_error;
37250- atomic_long_t mesq_noop_lb_overflow;
37251- atomic_long_t mesq_noop_qlimit_reached;
37252- atomic_long_t mesq_noop_amo_nacked;
37253- atomic_long_t mesq_noop_put_nacked;
37254+ atomic_long_unchecked_t mesq_receive;
37255+ atomic_long_unchecked_t mesq_receive_none;
37256+ atomic_long_unchecked_t mesq_send;
37257+ atomic_long_unchecked_t mesq_send_failed;
37258+ atomic_long_unchecked_t mesq_noop;
37259+ atomic_long_unchecked_t mesq_send_unexpected_error;
37260+ atomic_long_unchecked_t mesq_send_lb_overflow;
37261+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37262+ atomic_long_unchecked_t mesq_send_amo_nacked;
37263+ atomic_long_unchecked_t mesq_send_put_nacked;
37264+ atomic_long_unchecked_t mesq_qf_not_full;
37265+ atomic_long_unchecked_t mesq_qf_locked;
37266+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37267+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37268+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37269+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37270+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37271+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37272+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37273+ atomic_long_unchecked_t mesq_noop_put_nacked;
37274
37275 };
37276
37277@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37278 cchop_deallocate, tghop_invalidate, mcsop_last};
37279
37280 struct mcs_op_statistic {
37281- atomic_long_t count;
37282- atomic_long_t total;
37283+ atomic_long_unchecked_t count;
37284+ atomic_long_unchecked_t total;
37285 unsigned long max;
37286 };
37287
37288@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37289
37290 #define STAT(id) do { \
37291 if (gru_options & OPT_STATS) \
37292- atomic_long_inc(&gru_stats.id); \
37293+ atomic_long_inc_unchecked(&gru_stats.id); \
37294 } while (0)
37295
37296 #ifdef CONFIG_SGI_GRU_DEBUG
37297diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37298index 2275126..12a9dbfb 100644
37299--- a/drivers/misc/sgi-xp/xp.h
37300+++ b/drivers/misc/sgi-xp/xp.h
37301@@ -289,7 +289,7 @@ struct xpc_interface {
37302 xpc_notify_func, void *);
37303 void (*received) (short, int, void *);
37304 enum xp_retval (*partid_to_nasids) (short, void *);
37305-};
37306+} __no_const;
37307
37308 extern struct xpc_interface xpc_interface;
37309
37310diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37311index b94d5f7..7f494c5 100644
37312--- a/drivers/misc/sgi-xp/xpc.h
37313+++ b/drivers/misc/sgi-xp/xpc.h
37314@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37315 void (*received_payload) (struct xpc_channel *, void *);
37316 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37317 };
37318+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37319
37320 /* struct xpc_partition act_state values (for XPC HB) */
37321
37322@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37323 /* found in xpc_main.c */
37324 extern struct device *xpc_part;
37325 extern struct device *xpc_chan;
37326-extern struct xpc_arch_operations xpc_arch_ops;
37327+extern xpc_arch_operations_no_const xpc_arch_ops;
37328 extern int xpc_disengage_timelimit;
37329 extern int xpc_disengage_timedout;
37330 extern int xpc_activate_IRQ_rcvd;
37331diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37332index fd3688a..7e211a4 100644
37333--- a/drivers/misc/sgi-xp/xpc_main.c
37334+++ b/drivers/misc/sgi-xp/xpc_main.c
37335@@ -169,7 +169,7 @@ static struct notifier_block xpc_die_notifier = {
37336 .notifier_call = xpc_system_die,
37337 };
37338
37339-struct xpc_arch_operations xpc_arch_ops;
37340+xpc_arch_operations_no_const xpc_arch_ops;
37341
37342 /*
37343 * Timer function to enforce the timelimit on the partition disengage.
37344diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
37345index 8b70e03..700bda6 100644
37346--- a/drivers/misc/sgi-xp/xpc_sn2.c
37347+++ b/drivers/misc/sgi-xp/xpc_sn2.c
37348@@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_channel *ch, void *payload)
37349 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
37350 }
37351
37352-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
37353+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
37354 .setup_partitions = xpc_setup_partitions_sn2,
37355 .teardown_partitions = xpc_teardown_partitions_sn2,
37356 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
37357@@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
37358 int ret;
37359 size_t buf_size;
37360
37361- xpc_arch_ops = xpc_arch_ops_sn2;
37362+ pax_open_kernel();
37363+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
37364+ pax_close_kernel();
37365
37366 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
37367 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
37368diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
37369index 8e08d71..7cb8c9b 100644
37370--- a/drivers/misc/sgi-xp/xpc_uv.c
37371+++ b/drivers/misc/sgi-xp/xpc_uv.c
37372@@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
37373 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
37374 }
37375
37376-static struct xpc_arch_operations xpc_arch_ops_uv = {
37377+static const struct xpc_arch_operations xpc_arch_ops_uv = {
37378 .setup_partitions = xpc_setup_partitions_uv,
37379 .teardown_partitions = xpc_teardown_partitions_uv,
37380 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
37381@@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_arch_ops_uv = {
37382 int
37383 xpc_init_uv(void)
37384 {
37385- xpc_arch_ops = xpc_arch_ops_uv;
37386+ pax_open_kernel();
37387+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
37388+ pax_close_kernel();
37389
37390 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
37391 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
37392diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
37393index 6fd20b42..650efe3 100644
37394--- a/drivers/mmc/host/sdhci-pci.c
37395+++ b/drivers/mmc/host/sdhci-pci.c
37396@@ -297,7 +297,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
37397 .probe = via_probe,
37398 };
37399
37400-static const struct pci_device_id pci_ids[] __devinitdata = {
37401+static const struct pci_device_id pci_ids[] __devinitconst = {
37402 {
37403 .vendor = PCI_VENDOR_ID_RICOH,
37404 .device = PCI_DEVICE_ID_RICOH_R5C822,
37405diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
37406index e7563a9..5f90ce5 100644
37407--- a/drivers/mtd/chips/cfi_cmdset_0001.c
37408+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
37409@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
37410 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
37411 unsigned long timeo = jiffies + HZ;
37412
37413+ pax_track_stack();
37414+
37415 /* Prevent setting state FL_SYNCING for chip in suspended state. */
37416 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
37417 goto sleep;
37418@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
37419 unsigned long initial_adr;
37420 int initial_len = len;
37421
37422+ pax_track_stack();
37423+
37424 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
37425 adr += chip->start;
37426 initial_adr = adr;
37427@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
37428 int retries = 3;
37429 int ret;
37430
37431+ pax_track_stack();
37432+
37433 adr += chip->start;
37434
37435 retry:
37436diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
37437index 0667a67..3ab97ed 100644
37438--- a/drivers/mtd/chips/cfi_cmdset_0020.c
37439+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
37440@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
37441 unsigned long cmd_addr;
37442 struct cfi_private *cfi = map->fldrv_priv;
37443
37444+ pax_track_stack();
37445+
37446 adr += chip->start;
37447
37448 /* Ensure cmd read/writes are aligned. */
37449@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
37450 DECLARE_WAITQUEUE(wait, current);
37451 int wbufsize, z;
37452
37453+ pax_track_stack();
37454+
37455 /* M58LW064A requires bus alignment for buffer wriets -- saw */
37456 if (adr & (map_bankwidth(map)-1))
37457 return -EINVAL;
37458@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
37459 DECLARE_WAITQUEUE(wait, current);
37460 int ret = 0;
37461
37462+ pax_track_stack();
37463+
37464 adr += chip->start;
37465
37466 /* Let's determine this according to the interleave only once */
37467@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
37468 unsigned long timeo = jiffies + HZ;
37469 DECLARE_WAITQUEUE(wait, current);
37470
37471+ pax_track_stack();
37472+
37473 adr += chip->start;
37474
37475 /* Let's determine this according to the interleave only once */
37476@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
37477 unsigned long timeo = jiffies + HZ;
37478 DECLARE_WAITQUEUE(wait, current);
37479
37480+ pax_track_stack();
37481+
37482 adr += chip->start;
37483
37484 /* Let's determine this according to the interleave only once */
37485diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37486index 5bf5f46..c5de373 100644
37487--- a/drivers/mtd/devices/doc2000.c
37488+++ b/drivers/mtd/devices/doc2000.c
37489@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37490
37491 /* The ECC will not be calculated correctly if less than 512 is written */
37492 /* DBB-
37493- if (len != 0x200 && eccbuf)
37494+ if (len != 0x200)
37495 printk(KERN_WARNING
37496 "ECC needs a full sector write (adr: %lx size %lx)\n",
37497 (long) to, (long) len);
37498diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
37499index 0990f78..bb4e8a4 100644
37500--- a/drivers/mtd/devices/doc2001.c
37501+++ b/drivers/mtd/devices/doc2001.c
37502@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
37503 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
37504
37505 /* Don't allow read past end of device */
37506- if (from >= this->totlen)
37507+ if (from >= this->totlen || !len)
37508 return -EINVAL;
37509
37510 /* Don't allow a single read to cross a 512-byte block boundary */
37511diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
37512index e56d6b4..f07e6cf 100644
37513--- a/drivers/mtd/ftl.c
37514+++ b/drivers/mtd/ftl.c
37515@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
37516 loff_t offset;
37517 uint16_t srcunitswap = cpu_to_le16(srcunit);
37518
37519+ pax_track_stack();
37520+
37521 eun = &part->EUNInfo[srcunit];
37522 xfer = &part->XferInfo[xferunit];
37523 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
37524diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
37525index 8aca552..146446e 100755
37526--- a/drivers/mtd/inftlcore.c
37527+++ b/drivers/mtd/inftlcore.c
37528@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
37529 struct inftl_oob oob;
37530 size_t retlen;
37531
37532+ pax_track_stack();
37533+
37534 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
37535 "pending=%d)\n", inftl, thisVUC, pendingblock);
37536
37537diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
37538index 32e82ae..ed50953 100644
37539--- a/drivers/mtd/inftlmount.c
37540+++ b/drivers/mtd/inftlmount.c
37541@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
37542 struct INFTLPartition *ip;
37543 size_t retlen;
37544
37545+ pax_track_stack();
37546+
37547 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
37548
37549 /*
37550diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
37551index 79bf40f..fe5f8fd 100644
37552--- a/drivers/mtd/lpddr/qinfo_probe.c
37553+++ b/drivers/mtd/lpddr/qinfo_probe.c
37554@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
37555 {
37556 map_word pfow_val[4];
37557
37558+ pax_track_stack();
37559+
37560 /* Check identification string */
37561 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
37562 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
37563diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
37564index 726a1b8..f46b460 100644
37565--- a/drivers/mtd/mtdchar.c
37566+++ b/drivers/mtd/mtdchar.c
37567@@ -461,6 +461,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
37568 u_long size;
37569 struct mtd_info_user info;
37570
37571+ pax_track_stack();
37572+
37573 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
37574
37575 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
37576diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
37577index 1002e18..26d82d5 100644
37578--- a/drivers/mtd/nftlcore.c
37579+++ b/drivers/mtd/nftlcore.c
37580@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
37581 int inplace = 1;
37582 size_t retlen;
37583
37584+ pax_track_stack();
37585+
37586 memset(BlockMap, 0xff, sizeof(BlockMap));
37587 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
37588
37589diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37590index 8b22b18..6fada85 100644
37591--- a/drivers/mtd/nftlmount.c
37592+++ b/drivers/mtd/nftlmount.c
37593@@ -23,6 +23,7 @@
37594 #include <asm/errno.h>
37595 #include <linux/delay.h>
37596 #include <linux/slab.h>
37597+#include <linux/sched.h>
37598 #include <linux/mtd/mtd.h>
37599 #include <linux/mtd/nand.h>
37600 #include <linux/mtd/nftl.h>
37601@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
37602 struct mtd_info *mtd = nftl->mbd.mtd;
37603 unsigned int i;
37604
37605+ pax_track_stack();
37606+
37607 /* Assume logical EraseSize == physical erasesize for starting the scan.
37608 We'll sort it out later if we find a MediaHeader which says otherwise */
37609 /* Actually, we won't. The new DiskOnChip driver has already scanned
37610diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
37611index 14cec04..d775b87 100644
37612--- a/drivers/mtd/ubi/build.c
37613+++ b/drivers/mtd/ubi/build.c
37614@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
37615 static int __init bytes_str_to_int(const char *str)
37616 {
37617 char *endp;
37618- unsigned long result;
37619+ unsigned long result, scale = 1;
37620
37621 result = simple_strtoul(str, &endp, 0);
37622 if (str == endp || result >= INT_MAX) {
37623@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const char *str)
37624
37625 switch (*endp) {
37626 case 'G':
37627- result *= 1024;
37628+ scale *= 1024;
37629 case 'M':
37630- result *= 1024;
37631+ scale *= 1024;
37632 case 'K':
37633- result *= 1024;
37634+ scale *= 1024;
37635 if (endp[1] == 'i' && endp[2] == 'B')
37636 endp += 2;
37637 case '\0':
37638@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const char *str)
37639 return -EINVAL;
37640 }
37641
37642- return result;
37643+ if ((intoverflow_t)result*scale >= INT_MAX) {
37644+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
37645+ str);
37646+ return -EINVAL;
37647+ }
37648+
37649+ return result*scale;
37650 }
37651
37652 /**
37653diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
37654index ab68886..ca405e8 100644
37655--- a/drivers/net/atlx/atl2.c
37656+++ b/drivers/net/atlx/atl2.c
37657@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
37658 */
37659
37660 #define ATL2_PARAM(X, desc) \
37661- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37662+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37663 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
37664 MODULE_PARM_DESC(X, desc);
37665 #else
37666diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
37667index 4874b2b..67f8526 100644
37668--- a/drivers/net/bnx2.c
37669+++ b/drivers/net/bnx2.c
37670@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
37671 int rc = 0;
37672 u32 magic, csum;
37673
37674+ pax_track_stack();
37675+
37676 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
37677 goto test_nvram_done;
37678
37679diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
37680index fd3eb07..8a6978d 100644
37681--- a/drivers/net/cxgb3/l2t.h
37682+++ b/drivers/net/cxgb3/l2t.h
37683@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37684 */
37685 struct l2t_skb_cb {
37686 arp_failure_handler_func arp_failure_handler;
37687-};
37688+} __no_const;
37689
37690 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37691
37692diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
37693index 032cfe0..411af379 100644
37694--- a/drivers/net/cxgb3/t3_hw.c
37695+++ b/drivers/net/cxgb3/t3_hw.c
37696@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
37697 int i, addr, ret;
37698 struct t3_vpd vpd;
37699
37700+ pax_track_stack();
37701+
37702 /*
37703 * Card information is normally at VPD_BASE but some early cards had
37704 * it at 0.
37705diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
37706index d1e0563..b9e129c 100644
37707--- a/drivers/net/e1000e/82571.c
37708+++ b/drivers/net/e1000e/82571.c
37709@@ -212,7 +212,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
37710 {
37711 struct e1000_hw *hw = &adapter->hw;
37712 struct e1000_mac_info *mac = &hw->mac;
37713- struct e1000_mac_operations *func = &mac->ops;
37714+ e1000_mac_operations_no_const *func = &mac->ops;
37715 u32 swsm = 0;
37716 u32 swsm2 = 0;
37717 bool force_clear_smbi = false;
37718@@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
37719 temp = er32(ICRXDMTC);
37720 }
37721
37722-static struct e1000_mac_operations e82571_mac_ops = {
37723+static const struct e1000_mac_operations e82571_mac_ops = {
37724 /* .check_mng_mode: mac type dependent */
37725 /* .check_for_link: media type dependent */
37726 .id_led_init = e1000e_id_led_init,
37727@@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e82571_mac_ops = {
37728 .setup_led = e1000e_setup_led_generic,
37729 };
37730
37731-static struct e1000_phy_operations e82_phy_ops_igp = {
37732+static const struct e1000_phy_operations e82_phy_ops_igp = {
37733 .acquire_phy = e1000_get_hw_semaphore_82571,
37734 .check_reset_block = e1000e_check_reset_block_generic,
37735 .commit_phy = NULL,
37736@@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_phy_ops_igp = {
37737 .cfg_on_link_up = NULL,
37738 };
37739
37740-static struct e1000_phy_operations e82_phy_ops_m88 = {
37741+static const struct e1000_phy_operations e82_phy_ops_m88 = {
37742 .acquire_phy = e1000_get_hw_semaphore_82571,
37743 .check_reset_block = e1000e_check_reset_block_generic,
37744 .commit_phy = e1000e_phy_sw_reset,
37745@@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_phy_ops_m88 = {
37746 .cfg_on_link_up = NULL,
37747 };
37748
37749-static struct e1000_phy_operations e82_phy_ops_bm = {
37750+static const struct e1000_phy_operations e82_phy_ops_bm = {
37751 .acquire_phy = e1000_get_hw_semaphore_82571,
37752 .check_reset_block = e1000e_check_reset_block_generic,
37753 .commit_phy = e1000e_phy_sw_reset,
37754@@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_phy_ops_bm = {
37755 .cfg_on_link_up = NULL,
37756 };
37757
37758-static struct e1000_nvm_operations e82571_nvm_ops = {
37759+static const struct e1000_nvm_operations e82571_nvm_ops = {
37760 .acquire_nvm = e1000_acquire_nvm_82571,
37761 .read_nvm = e1000e_read_nvm_eerd,
37762 .release_nvm = e1000_release_nvm_82571,
37763diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
37764index 47db9bd..fa58ccd 100644
37765--- a/drivers/net/e1000e/e1000.h
37766+++ b/drivers/net/e1000e/e1000.h
37767@@ -375,9 +375,9 @@ struct e1000_info {
37768 u32 pba;
37769 u32 max_hw_frame_size;
37770 s32 (*get_variants)(struct e1000_adapter *);
37771- struct e1000_mac_operations *mac_ops;
37772- struct e1000_phy_operations *phy_ops;
37773- struct e1000_nvm_operations *nvm_ops;
37774+ const struct e1000_mac_operations *mac_ops;
37775+ const struct e1000_phy_operations *phy_ops;
37776+ const struct e1000_nvm_operations *nvm_ops;
37777 };
37778
37779 /* hardware capability, feature, and workaround flags */
37780diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
37781index ae5d736..e9a93a1 100644
37782--- a/drivers/net/e1000e/es2lan.c
37783+++ b/drivers/net/e1000e/es2lan.c
37784@@ -207,7 +207,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
37785 {
37786 struct e1000_hw *hw = &adapter->hw;
37787 struct e1000_mac_info *mac = &hw->mac;
37788- struct e1000_mac_operations *func = &mac->ops;
37789+ e1000_mac_operations_no_const *func = &mac->ops;
37790
37791 /* Set media type */
37792 switch (adapter->pdev->device) {
37793@@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
37794 temp = er32(ICRXDMTC);
37795 }
37796
37797-static struct e1000_mac_operations es2_mac_ops = {
37798+static const struct e1000_mac_operations es2_mac_ops = {
37799 .id_led_init = e1000e_id_led_init,
37800 .check_mng_mode = e1000e_check_mng_mode_generic,
37801 /* check_for_link dependent on media type */
37802@@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_mac_ops = {
37803 .setup_led = e1000e_setup_led_generic,
37804 };
37805
37806-static struct e1000_phy_operations es2_phy_ops = {
37807+static const struct e1000_phy_operations es2_phy_ops = {
37808 .acquire_phy = e1000_acquire_phy_80003es2lan,
37809 .check_reset_block = e1000e_check_reset_block_generic,
37810 .commit_phy = e1000e_phy_sw_reset,
37811@@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_phy_ops = {
37812 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
37813 };
37814
37815-static struct e1000_nvm_operations es2_nvm_ops = {
37816+static const struct e1000_nvm_operations es2_nvm_ops = {
37817 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
37818 .read_nvm = e1000e_read_nvm_eerd,
37819 .release_nvm = e1000_release_nvm_80003es2lan,
37820diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
37821index 11f3b7c..6381887 100644
37822--- a/drivers/net/e1000e/hw.h
37823+++ b/drivers/net/e1000e/hw.h
37824@@ -753,6 +753,7 @@ struct e1000_mac_operations {
37825 s32 (*setup_physical_interface)(struct e1000_hw *);
37826 s32 (*setup_led)(struct e1000_hw *);
37827 };
37828+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37829
37830 /* Function pointers for the PHY. */
37831 struct e1000_phy_operations {
37832@@ -774,6 +775,7 @@ struct e1000_phy_operations {
37833 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
37834 s32 (*cfg_on_link_up)(struct e1000_hw *);
37835 };
37836+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37837
37838 /* Function pointers for the NVM. */
37839 struct e1000_nvm_operations {
37840@@ -785,9 +787,10 @@ struct e1000_nvm_operations {
37841 s32 (*validate_nvm)(struct e1000_hw *);
37842 s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
37843 };
37844+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
37845
37846 struct e1000_mac_info {
37847- struct e1000_mac_operations ops;
37848+ e1000_mac_operations_no_const ops;
37849
37850 u8 addr[6];
37851 u8 perm_addr[6];
37852@@ -823,7 +826,7 @@ struct e1000_mac_info {
37853 };
37854
37855 struct e1000_phy_info {
37856- struct e1000_phy_operations ops;
37857+ e1000_phy_operations_no_const ops;
37858
37859 enum e1000_phy_type type;
37860
37861@@ -857,7 +860,7 @@ struct e1000_phy_info {
37862 };
37863
37864 struct e1000_nvm_info {
37865- struct e1000_nvm_operations ops;
37866+ e1000_nvm_operations_no_const ops;
37867
37868 enum e1000_nvm_type type;
37869 enum e1000_nvm_override override;
37870diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
37871index de39f9a..e28d3e0 100644
37872--- a/drivers/net/e1000e/ich8lan.c
37873+++ b/drivers/net/e1000e/ich8lan.c
37874@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
37875 }
37876 }
37877
37878-static struct e1000_mac_operations ich8_mac_ops = {
37879+static const struct e1000_mac_operations ich8_mac_ops = {
37880 .id_led_init = e1000e_id_led_init,
37881 .check_mng_mode = e1000_check_mng_mode_ich8lan,
37882 .check_for_link = e1000_check_for_copper_link_ich8lan,
37883@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_mac_ops = {
37884 /* id_led_init dependent on mac type */
37885 };
37886
37887-static struct e1000_phy_operations ich8_phy_ops = {
37888+static const struct e1000_phy_operations ich8_phy_ops = {
37889 .acquire_phy = e1000_acquire_swflag_ich8lan,
37890 .check_reset_block = e1000_check_reset_block_ich8lan,
37891 .commit_phy = NULL,
37892@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_phy_ops = {
37893 .write_phy_reg = e1000e_write_phy_reg_igp,
37894 };
37895
37896-static struct e1000_nvm_operations ich8_nvm_ops = {
37897+static const struct e1000_nvm_operations ich8_nvm_ops = {
37898 .acquire_nvm = e1000_acquire_nvm_ich8lan,
37899 .read_nvm = e1000_read_nvm_ich8lan,
37900 .release_nvm = e1000_release_nvm_ich8lan,
37901diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
37902index 18d5fbb..542d96d 100644
37903--- a/drivers/net/fealnx.c
37904+++ b/drivers/net/fealnx.c
37905@@ -151,7 +151,7 @@ struct chip_info {
37906 int flags;
37907 };
37908
37909-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
37910+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
37911 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37912 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
37913 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37914diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
37915index 0e5b54b..b503f82 100644
37916--- a/drivers/net/hamradio/6pack.c
37917+++ b/drivers/net/hamradio/6pack.c
37918@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
37919 unsigned char buf[512];
37920 int count1;
37921
37922+ pax_track_stack();
37923+
37924 if (!count)
37925 return;
37926
37927diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
37928index 5862282..7cce8cb 100644
37929--- a/drivers/net/ibmveth.c
37930+++ b/drivers/net/ibmveth.c
37931@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attrs[] = {
37932 NULL,
37933 };
37934
37935-static struct sysfs_ops veth_pool_ops = {
37936+static const struct sysfs_ops veth_pool_ops = {
37937 .show = veth_pool_show,
37938 .store = veth_pool_store,
37939 };
37940diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
37941index d617f2d..57b5309 100644
37942--- a/drivers/net/igb/e1000_82575.c
37943+++ b/drivers/net/igb/e1000_82575.c
37944@@ -1411,7 +1411,7 @@ void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
37945 wr32(E1000_VT_CTL, vt_ctl);
37946 }
37947
37948-static struct e1000_mac_operations e1000_mac_ops_82575 = {
37949+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
37950 .reset_hw = igb_reset_hw_82575,
37951 .init_hw = igb_init_hw_82575,
37952 .check_for_link = igb_check_for_link_82575,
37953@@ -1420,13 +1420,13 @@ static struct e1000_mac_operations e1000_mac_ops_82575 = {
37954 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
37955 };
37956
37957-static struct e1000_phy_operations e1000_phy_ops_82575 = {
37958+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
37959 .acquire = igb_acquire_phy_82575,
37960 .get_cfg_done = igb_get_cfg_done_82575,
37961 .release = igb_release_phy_82575,
37962 };
37963
37964-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
37965+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
37966 .acquire = igb_acquire_nvm_82575,
37967 .read = igb_read_nvm_eerd,
37968 .release = igb_release_nvm_82575,
37969diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
37970index 72081df..d855cf5 100644
37971--- a/drivers/net/igb/e1000_hw.h
37972+++ b/drivers/net/igb/e1000_hw.h
37973@@ -288,6 +288,7 @@ struct e1000_mac_operations {
37974 s32 (*read_mac_addr)(struct e1000_hw *);
37975 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
37976 };
37977+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37978
37979 struct e1000_phy_operations {
37980 s32 (*acquire)(struct e1000_hw *);
37981@@ -303,6 +304,7 @@ struct e1000_phy_operations {
37982 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
37983 s32 (*write_reg)(struct e1000_hw *, u32, u16);
37984 };
37985+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37986
37987 struct e1000_nvm_operations {
37988 s32 (*acquire)(struct e1000_hw *);
37989@@ -310,6 +312,7 @@ struct e1000_nvm_operations {
37990 void (*release)(struct e1000_hw *);
37991 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
37992 };
37993+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
37994
37995 struct e1000_info {
37996 s32 (*get_invariants)(struct e1000_hw *);
37997@@ -321,7 +324,7 @@ struct e1000_info {
37998 extern const struct e1000_info e1000_82575_info;
37999
38000 struct e1000_mac_info {
38001- struct e1000_mac_operations ops;
38002+ e1000_mac_operations_no_const ops;
38003
38004 u8 addr[6];
38005 u8 perm_addr[6];
38006@@ -365,7 +368,7 @@ struct e1000_mac_info {
38007 };
38008
38009 struct e1000_phy_info {
38010- struct e1000_phy_operations ops;
38011+ e1000_phy_operations_no_const ops;
38012
38013 enum e1000_phy_type type;
38014
38015@@ -400,7 +403,7 @@ struct e1000_phy_info {
38016 };
38017
38018 struct e1000_nvm_info {
38019- struct e1000_nvm_operations ops;
38020+ e1000_nvm_operations_no_const ops;
38021
38022 enum e1000_nvm_type type;
38023 enum e1000_nvm_override override;
38024@@ -446,6 +449,7 @@ struct e1000_mbx_operations {
38025 s32 (*check_for_ack)(struct e1000_hw *, u16);
38026 s32 (*check_for_rst)(struct e1000_hw *, u16);
38027 };
38028+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38029
38030 struct e1000_mbx_stats {
38031 u32 msgs_tx;
38032@@ -457,7 +461,7 @@ struct e1000_mbx_stats {
38033 };
38034
38035 struct e1000_mbx_info {
38036- struct e1000_mbx_operations ops;
38037+ e1000_mbx_operations_no_const ops;
38038 struct e1000_mbx_stats stats;
38039 u32 timeout;
38040 u32 usec_delay;
38041diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
38042index 1e8ce37..549c453 100644
38043--- a/drivers/net/igbvf/vf.h
38044+++ b/drivers/net/igbvf/vf.h
38045@@ -187,9 +187,10 @@ struct e1000_mac_operations {
38046 s32 (*read_mac_addr)(struct e1000_hw *);
38047 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
38048 };
38049+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38050
38051 struct e1000_mac_info {
38052- struct e1000_mac_operations ops;
38053+ e1000_mac_operations_no_const ops;
38054 u8 addr[6];
38055 u8 perm_addr[6];
38056
38057@@ -211,6 +212,7 @@ struct e1000_mbx_operations {
38058 s32 (*check_for_ack)(struct e1000_hw *);
38059 s32 (*check_for_rst)(struct e1000_hw *);
38060 };
38061+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38062
38063 struct e1000_mbx_stats {
38064 u32 msgs_tx;
38065@@ -222,7 +224,7 @@ struct e1000_mbx_stats {
38066 };
38067
38068 struct e1000_mbx_info {
38069- struct e1000_mbx_operations ops;
38070+ e1000_mbx_operations_no_const ops;
38071 struct e1000_mbx_stats stats;
38072 u32 timeout;
38073 u32 usec_delay;
38074diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
38075index aa7286b..a61394f 100644
38076--- a/drivers/net/iseries_veth.c
38077+++ b/drivers/net/iseries_veth.c
38078@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_default_attrs[] = {
38079 NULL
38080 };
38081
38082-static struct sysfs_ops veth_cnx_sysfs_ops = {
38083+static const struct sysfs_ops veth_cnx_sysfs_ops = {
38084 .show = veth_cnx_attribute_show
38085 };
38086
38087@@ -441,7 +441,7 @@ static struct attribute *veth_port_default_attrs[] = {
38088 NULL
38089 };
38090
38091-static struct sysfs_ops veth_port_sysfs_ops = {
38092+static const struct sysfs_ops veth_port_sysfs_ops = {
38093 .show = veth_port_attribute_show
38094 };
38095
38096diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
38097index 8aa44dc..fa1e797 100644
38098--- a/drivers/net/ixgb/ixgb_main.c
38099+++ b/drivers/net/ixgb/ixgb_main.c
38100@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev)
38101 u32 rctl;
38102 int i;
38103
38104+ pax_track_stack();
38105+
38106 /* Check for Promiscuous and All Multicast modes */
38107
38108 rctl = IXGB_READ_REG(hw, RCTL);
38109diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
38110index af35e1d..8781785 100644
38111--- a/drivers/net/ixgb/ixgb_param.c
38112+++ b/drivers/net/ixgb/ixgb_param.c
38113@@ -260,6 +260,9 @@ void __devinit
38114 ixgb_check_options(struct ixgb_adapter *adapter)
38115 {
38116 int bd = adapter->bd_number;
38117+
38118+ pax_track_stack();
38119+
38120 if (bd >= IXGB_MAX_NIC) {
38121 printk(KERN_NOTICE
38122 "Warning: no configuration for board #%i\n", bd);
38123diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
38124index b17aa73..ed74540 100644
38125--- a/drivers/net/ixgbe/ixgbe_type.h
38126+++ b/drivers/net/ixgbe/ixgbe_type.h
38127@@ -2327,6 +2327,7 @@ struct ixgbe_eeprom_operations {
38128 s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
38129 s32 (*update_checksum)(struct ixgbe_hw *);
38130 };
38131+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
38132
38133 struct ixgbe_mac_operations {
38134 s32 (*init_hw)(struct ixgbe_hw *);
38135@@ -2376,6 +2377,7 @@ struct ixgbe_mac_operations {
38136 /* Flow Control */
38137 s32 (*fc_enable)(struct ixgbe_hw *, s32);
38138 };
38139+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
38140
38141 struct ixgbe_phy_operations {
38142 s32 (*identify)(struct ixgbe_hw *);
38143@@ -2394,9 +2396,10 @@ struct ixgbe_phy_operations {
38144 s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
38145 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
38146 };
38147+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
38148
38149 struct ixgbe_eeprom_info {
38150- struct ixgbe_eeprom_operations ops;
38151+ ixgbe_eeprom_operations_no_const ops;
38152 enum ixgbe_eeprom_type type;
38153 u32 semaphore_delay;
38154 u16 word_size;
38155@@ -2404,7 +2407,7 @@ struct ixgbe_eeprom_info {
38156 };
38157
38158 struct ixgbe_mac_info {
38159- struct ixgbe_mac_operations ops;
38160+ ixgbe_mac_operations_no_const ops;
38161 enum ixgbe_mac_type type;
38162 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38163 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38164@@ -2423,7 +2426,7 @@ struct ixgbe_mac_info {
38165 };
38166
38167 struct ixgbe_phy_info {
38168- struct ixgbe_phy_operations ops;
38169+ ixgbe_phy_operations_no_const ops;
38170 struct mdio_if_info mdio;
38171 enum ixgbe_phy_type type;
38172 u32 id;
38173diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
38174index 291a505..2543756 100644
38175--- a/drivers/net/mlx4/main.c
38176+++ b/drivers/net/mlx4/main.c
38177@@ -38,6 +38,7 @@
38178 #include <linux/errno.h>
38179 #include <linux/pci.h>
38180 #include <linux/dma-mapping.h>
38181+#include <linux/sched.h>
38182
38183 #include <linux/mlx4/device.h>
38184 #include <linux/mlx4/doorbell.h>
38185@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
38186 u64 icm_size;
38187 int err;
38188
38189+ pax_track_stack();
38190+
38191 err = mlx4_QUERY_FW(dev);
38192 if (err) {
38193 if (err == -EACCES)
38194diff --git a/drivers/net/niu.c b/drivers/net/niu.c
38195index 2dce134..fa5ce75 100644
38196--- a/drivers/net/niu.c
38197+++ b/drivers/net/niu.c
38198@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
38199 int i, num_irqs, err;
38200 u8 first_ldg;
38201
38202+ pax_track_stack();
38203+
38204 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
38205 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
38206 ldg_num_map[i] = first_ldg + i;
38207diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
38208index c1b3f09..97cd8c4 100644
38209--- a/drivers/net/pcnet32.c
38210+++ b/drivers/net/pcnet32.c
38211@@ -79,7 +79,7 @@ static int cards_found;
38212 /*
38213 * VLB I/O addresses
38214 */
38215-static unsigned int pcnet32_portlist[] __initdata =
38216+static unsigned int pcnet32_portlist[] __devinitdata =
38217 { 0x300, 0x320, 0x340, 0x360, 0 };
38218
38219 static int pcnet32_debug = 0;
38220@@ -267,7 +267,7 @@ struct pcnet32_private {
38221 struct sk_buff **rx_skbuff;
38222 dma_addr_t *tx_dma_addr;
38223 dma_addr_t *rx_dma_addr;
38224- struct pcnet32_access a;
38225+ struct pcnet32_access *a;
38226 spinlock_t lock; /* Guard lock */
38227 unsigned int cur_rx, cur_tx; /* The next free ring entry */
38228 unsigned int rx_ring_size; /* current rx ring size */
38229@@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct net_device *dev)
38230 u16 val;
38231
38232 netif_wake_queue(dev);
38233- val = lp->a.read_csr(ioaddr, CSR3);
38234+ val = lp->a->read_csr(ioaddr, CSR3);
38235 val &= 0x00ff;
38236- lp->a.write_csr(ioaddr, CSR3, val);
38237+ lp->a->write_csr(ioaddr, CSR3, val);
38238 napi_enable(&lp->napi);
38239 }
38240
38241@@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
38242 r = mii_link_ok(&lp->mii_if);
38243 } else if (lp->chip_version >= PCNET32_79C970A) {
38244 ulong ioaddr = dev->base_addr; /* card base I/O address */
38245- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38246+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38247 } else { /* can not detect link on really old chips */
38248 r = 1;
38249 }
38250@@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
38251 pcnet32_netif_stop(dev);
38252
38253 spin_lock_irqsave(&lp->lock, flags);
38254- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38255+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38256
38257 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
38258
38259@@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
38260 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38261 {
38262 struct pcnet32_private *lp = netdev_priv(dev);
38263- struct pcnet32_access *a = &lp->a; /* access to registers */
38264+ struct pcnet32_access *a = lp->a; /* access to registers */
38265 ulong ioaddr = dev->base_addr; /* card base I/O address */
38266 struct sk_buff *skb; /* sk buff */
38267 int x, i; /* counters */
38268@@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38269 pcnet32_netif_stop(dev);
38270
38271 spin_lock_irqsave(&lp->lock, flags);
38272- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38273+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38274
38275 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
38276
38277 /* Reset the PCNET32 */
38278- lp->a.reset(ioaddr);
38279- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38280+ lp->a->reset(ioaddr);
38281+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38282
38283 /* switch pcnet32 to 32bit mode */
38284- lp->a.write_bcr(ioaddr, 20, 2);
38285+ lp->a->write_bcr(ioaddr, 20, 2);
38286
38287 /* purge & init rings but don't actually restart */
38288 pcnet32_restart(dev, 0x0000);
38289
38290- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38291+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38292
38293 /* Initialize Transmit buffers. */
38294 size = data_len + 15;
38295@@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38296
38297 /* set int loopback in CSR15 */
38298 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
38299- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
38300+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
38301
38302 teststatus = cpu_to_le16(0x8000);
38303- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38304+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38305
38306 /* Check status of descriptors */
38307 for (x = 0; x < numbuffs; x++) {
38308@@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38309 }
38310 }
38311
38312- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38313+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38314 wmb();
38315 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
38316 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
38317@@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38318 pcnet32_restart(dev, CSR0_NORMAL);
38319 } else {
38320 pcnet32_purge_rx_ring(dev);
38321- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38322+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38323 }
38324 spin_unlock_irqrestore(&lp->lock, flags);
38325
38326@@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38327 static void pcnet32_led_blink_callback(struct net_device *dev)
38328 {
38329 struct pcnet32_private *lp = netdev_priv(dev);
38330- struct pcnet32_access *a = &lp->a;
38331+ struct pcnet32_access *a = lp->a;
38332 ulong ioaddr = dev->base_addr;
38333 unsigned long flags;
38334 int i;
38335@@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(struct net_device *dev)
38336 static int pcnet32_phys_id(struct net_device *dev, u32 data)
38337 {
38338 struct pcnet32_private *lp = netdev_priv(dev);
38339- struct pcnet32_access *a = &lp->a;
38340+ struct pcnet32_access *a = lp->a;
38341 ulong ioaddr = dev->base_addr;
38342 unsigned long flags;
38343 int i, regs[4];
38344@@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
38345 {
38346 int csr5;
38347 struct pcnet32_private *lp = netdev_priv(dev);
38348- struct pcnet32_access *a = &lp->a;
38349+ struct pcnet32_access *a = lp->a;
38350 ulong ioaddr = dev->base_addr;
38351 int ticks;
38352
38353@@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38354 spin_lock_irqsave(&lp->lock, flags);
38355 if (pcnet32_tx(dev)) {
38356 /* reset the chip to clear the error condition, then restart */
38357- lp->a.reset(ioaddr);
38358- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38359+ lp->a->reset(ioaddr);
38360+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38361 pcnet32_restart(dev, CSR0_START);
38362 netif_wake_queue(dev);
38363 }
38364@@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38365 __napi_complete(napi);
38366
38367 /* clear interrupt masks */
38368- val = lp->a.read_csr(ioaddr, CSR3);
38369+ val = lp->a->read_csr(ioaddr, CSR3);
38370 val &= 0x00ff;
38371- lp->a.write_csr(ioaddr, CSR3, val);
38372+ lp->a->write_csr(ioaddr, CSR3, val);
38373
38374 /* Set interrupt enable. */
38375- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
38376+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
38377
38378 spin_unlock_irqrestore(&lp->lock, flags);
38379 }
38380@@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38381 int i, csr0;
38382 u16 *buff = ptr;
38383 struct pcnet32_private *lp = netdev_priv(dev);
38384- struct pcnet32_access *a = &lp->a;
38385+ struct pcnet32_access *a = lp->a;
38386 ulong ioaddr = dev->base_addr;
38387 unsigned long flags;
38388
38389@@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38390 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
38391 if (lp->phymask & (1 << j)) {
38392 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
38393- lp->a.write_bcr(ioaddr, 33,
38394+ lp->a->write_bcr(ioaddr, 33,
38395 (j << 5) | i);
38396- *buff++ = lp->a.read_bcr(ioaddr, 34);
38397+ *buff++ = lp->a->read_bcr(ioaddr, 34);
38398 }
38399 }
38400 }
38401@@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38402 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
38403 lp->options |= PCNET32_PORT_FD;
38404
38405- lp->a = *a;
38406+ lp->a = a;
38407
38408 /* prior to register_netdev, dev->name is not yet correct */
38409 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
38410@@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38411 if (lp->mii) {
38412 /* lp->phycount and lp->phymask are set to 0 by memset above */
38413
38414- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38415+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38416 /* scan for PHYs */
38417 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38418 unsigned short id1, id2;
38419@@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38420 "Found PHY %04x:%04x at address %d.\n",
38421 id1, id2, i);
38422 }
38423- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38424+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38425 if (lp->phycount > 1) {
38426 lp->options |= PCNET32_PORT_MII;
38427 }
38428@@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_device *dev)
38429 }
38430
38431 /* Reset the PCNET32 */
38432- lp->a.reset(ioaddr);
38433+ lp->a->reset(ioaddr);
38434
38435 /* switch pcnet32 to 32bit mode */
38436- lp->a.write_bcr(ioaddr, 20, 2);
38437+ lp->a->write_bcr(ioaddr, 20, 2);
38438
38439 if (netif_msg_ifup(lp))
38440 printk(KERN_DEBUG
38441@@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_device *dev)
38442 (u32) (lp->init_dma_addr));
38443
38444 /* set/reset autoselect bit */
38445- val = lp->a.read_bcr(ioaddr, 2) & ~2;
38446+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
38447 if (lp->options & PCNET32_PORT_ASEL)
38448 val |= 2;
38449- lp->a.write_bcr(ioaddr, 2, val);
38450+ lp->a->write_bcr(ioaddr, 2, val);
38451
38452 /* handle full duplex setting */
38453 if (lp->mii_if.full_duplex) {
38454- val = lp->a.read_bcr(ioaddr, 9) & ~3;
38455+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
38456 if (lp->options & PCNET32_PORT_FD) {
38457 val |= 1;
38458 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
38459@@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_device *dev)
38460 if (lp->chip_version == 0x2627)
38461 val |= 3;
38462 }
38463- lp->a.write_bcr(ioaddr, 9, val);
38464+ lp->a->write_bcr(ioaddr, 9, val);
38465 }
38466
38467 /* set/reset GPSI bit in test register */
38468- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
38469+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
38470 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
38471 val |= 0x10;
38472- lp->a.write_csr(ioaddr, 124, val);
38473+ lp->a->write_csr(ioaddr, 124, val);
38474
38475 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
38476 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
38477@@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_device *dev)
38478 * duplex, and/or enable auto negotiation, and clear DANAS
38479 */
38480 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
38481- lp->a.write_bcr(ioaddr, 32,
38482- lp->a.read_bcr(ioaddr, 32) | 0x0080);
38483+ lp->a->write_bcr(ioaddr, 32,
38484+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
38485 /* disable Auto Negotiation, set 10Mpbs, HD */
38486- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
38487+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
38488 if (lp->options & PCNET32_PORT_FD)
38489 val |= 0x10;
38490 if (lp->options & PCNET32_PORT_100)
38491 val |= 0x08;
38492- lp->a.write_bcr(ioaddr, 32, val);
38493+ lp->a->write_bcr(ioaddr, 32, val);
38494 } else {
38495 if (lp->options & PCNET32_PORT_ASEL) {
38496- lp->a.write_bcr(ioaddr, 32,
38497- lp->a.read_bcr(ioaddr,
38498+ lp->a->write_bcr(ioaddr, 32,
38499+ lp->a->read_bcr(ioaddr,
38500 32) | 0x0080);
38501 /* enable auto negotiate, setup, disable fd */
38502- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
38503+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
38504 val |= 0x20;
38505- lp->a.write_bcr(ioaddr, 32, val);
38506+ lp->a->write_bcr(ioaddr, 32, val);
38507 }
38508 }
38509 } else {
38510@@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_device *dev)
38511 * There is really no good other way to handle multiple PHYs
38512 * other than turning off all automatics
38513 */
38514- val = lp->a.read_bcr(ioaddr, 2);
38515- lp->a.write_bcr(ioaddr, 2, val & ~2);
38516- val = lp->a.read_bcr(ioaddr, 32);
38517- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38518+ val = lp->a->read_bcr(ioaddr, 2);
38519+ lp->a->write_bcr(ioaddr, 2, val & ~2);
38520+ val = lp->a->read_bcr(ioaddr, 32);
38521+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38522
38523 if (!(lp->options & PCNET32_PORT_ASEL)) {
38524 /* setup ecmd */
38525@@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_device *dev)
38526 ecmd.speed =
38527 lp->
38528 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
38529- bcr9 = lp->a.read_bcr(ioaddr, 9);
38530+ bcr9 = lp->a->read_bcr(ioaddr, 9);
38531
38532 if (lp->options & PCNET32_PORT_FD) {
38533 ecmd.duplex = DUPLEX_FULL;
38534@@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_device *dev)
38535 ecmd.duplex = DUPLEX_HALF;
38536 bcr9 |= ~(1 << 0);
38537 }
38538- lp->a.write_bcr(ioaddr, 9, bcr9);
38539+ lp->a->write_bcr(ioaddr, 9, bcr9);
38540 }
38541
38542 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38543@@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_device *dev)
38544
38545 #ifdef DO_DXSUFLO
38546 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
38547- val = lp->a.read_csr(ioaddr, CSR3);
38548+ val = lp->a->read_csr(ioaddr, CSR3);
38549 val |= 0x40;
38550- lp->a.write_csr(ioaddr, CSR3, val);
38551+ lp->a->write_csr(ioaddr, CSR3, val);
38552 }
38553 #endif
38554
38555@@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_device *dev)
38556 napi_enable(&lp->napi);
38557
38558 /* Re-initialize the PCNET32, and start it when done. */
38559- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38560- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38561+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38562+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38563
38564- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38565- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38566+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38567+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38568
38569 netif_start_queue(dev);
38570
38571@@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_device *dev)
38572
38573 i = 0;
38574 while (i++ < 100)
38575- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38576+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38577 break;
38578 /*
38579 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
38580 * reports that doing so triggers a bug in the '974.
38581 */
38582- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
38583+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
38584
38585 if (netif_msg_ifup(lp))
38586 printk(KERN_DEBUG
38587 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
38588 dev->name, i,
38589 (u32) (lp->init_dma_addr),
38590- lp->a.read_csr(ioaddr, CSR0));
38591+ lp->a->read_csr(ioaddr, CSR0));
38592
38593 spin_unlock_irqrestore(&lp->lock, flags);
38594
38595@@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_device *dev)
38596 * Switch back to 16bit mode to avoid problems with dumb
38597 * DOS packet driver after a warm reboot
38598 */
38599- lp->a.write_bcr(ioaddr, 20, 4);
38600+ lp->a->write_bcr(ioaddr, 20, 4);
38601
38602 err_free_irq:
38603 spin_unlock_irqrestore(&lp->lock, flags);
38604@@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38605
38606 /* wait for stop */
38607 for (i = 0; i < 100; i++)
38608- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
38609+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
38610 break;
38611
38612 if (i >= 100 && netif_msg_drv(lp))
38613@@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38614 return;
38615
38616 /* ReInit Ring */
38617- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38618+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38619 i = 0;
38620 while (i++ < 1000)
38621- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38622+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38623 break;
38624
38625- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
38626+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
38627 }
38628
38629 static void pcnet32_tx_timeout(struct net_device *dev)
38630@@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
38631 if (pcnet32_debug & NETIF_MSG_DRV)
38632 printk(KERN_ERR
38633 "%s: transmit timed out, status %4.4x, resetting.\n",
38634- dev->name, lp->a.read_csr(ioaddr, CSR0));
38635- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38636+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38637+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38638 dev->stats.tx_errors++;
38639 if (netif_msg_tx_err(lp)) {
38640 int i;
38641@@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38642 if (netif_msg_tx_queued(lp)) {
38643 printk(KERN_DEBUG
38644 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
38645- dev->name, lp->a.read_csr(ioaddr, CSR0));
38646+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38647 }
38648
38649 /* Default status -- will not enable Successful-TxDone
38650@@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38651 dev->stats.tx_bytes += skb->len;
38652
38653 /* Trigger an immediate send poll. */
38654- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38655+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38656
38657 dev->trans_start = jiffies;
38658
38659@@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
38660
38661 spin_lock(&lp->lock);
38662
38663- csr0 = lp->a.read_csr(ioaddr, CSR0);
38664+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38665 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
38666 if (csr0 == 0xffff) {
38667 break; /* PCMCIA remove happened */
38668 }
38669 /* Acknowledge all of the current interrupt sources ASAP. */
38670- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38671+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38672
38673 if (netif_msg_intr(lp))
38674 printk(KERN_DEBUG
38675 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
38676- dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
38677+ dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
38678
38679 /* Log misc errors. */
38680 if (csr0 & 0x4000)
38681@@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
38682 if (napi_schedule_prep(&lp->napi)) {
38683 u16 val;
38684 /* set interrupt masks */
38685- val = lp->a.read_csr(ioaddr, CSR3);
38686+ val = lp->a->read_csr(ioaddr, CSR3);
38687 val |= 0x5f00;
38688- lp->a.write_csr(ioaddr, CSR3, val);
38689+ lp->a->write_csr(ioaddr, CSR3, val);
38690
38691 __napi_schedule(&lp->napi);
38692 break;
38693 }
38694- csr0 = lp->a.read_csr(ioaddr, CSR0);
38695+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38696 }
38697
38698 if (netif_msg_intr(lp))
38699 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
38700- dev->name, lp->a.read_csr(ioaddr, CSR0));
38701+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38702
38703 spin_unlock(&lp->lock);
38704
38705@@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_device *dev)
38706
38707 spin_lock_irqsave(&lp->lock, flags);
38708
38709- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38710+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38711
38712 if (netif_msg_ifdown(lp))
38713 printk(KERN_DEBUG
38714 "%s: Shutting down ethercard, status was %2.2x.\n",
38715- dev->name, lp->a.read_csr(ioaddr, CSR0));
38716+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38717
38718 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
38719- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38720+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38721
38722 /*
38723 * Switch back to 16bit mode to avoid problems with dumb
38724 * DOS packet driver after a warm reboot
38725 */
38726- lp->a.write_bcr(ioaddr, 20, 4);
38727+ lp->a->write_bcr(ioaddr, 20, 4);
38728
38729 spin_unlock_irqrestore(&lp->lock, flags);
38730
38731@@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
38732 unsigned long flags;
38733
38734 spin_lock_irqsave(&lp->lock, flags);
38735- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38736+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38737 spin_unlock_irqrestore(&lp->lock, flags);
38738
38739 return &dev->stats;
38740@@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
38741 if (dev->flags & IFF_ALLMULTI) {
38742 ib->filter[0] = cpu_to_le32(~0U);
38743 ib->filter[1] = cpu_to_le32(~0U);
38744- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38745- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38746- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38747- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38748+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38749+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38750+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38751+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38752 return;
38753 }
38754 /* clear the multicast filter */
38755@@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
38756 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
38757 }
38758 for (i = 0; i < 4; i++)
38759- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
38760+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
38761 le16_to_cpu(mcast_table[i]));
38762 return;
38763 }
38764@@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38765
38766 spin_lock_irqsave(&lp->lock, flags);
38767 suspended = pcnet32_suspend(dev, &flags, 0);
38768- csr15 = lp->a.read_csr(ioaddr, CSR15);
38769+ csr15 = lp->a->read_csr(ioaddr, CSR15);
38770 if (dev->flags & IFF_PROMISC) {
38771 /* Log any net taps. */
38772 if (netif_msg_hw(lp))
38773@@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38774 lp->init_block->mode =
38775 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
38776 7);
38777- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
38778+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
38779 } else {
38780 lp->init_block->mode =
38781 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
38782- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38783+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38784 pcnet32_load_multicast(dev);
38785 }
38786
38787 if (suspended) {
38788 int csr5;
38789 /* clear SUSPEND (SPND) - CSR5 bit 0 */
38790- csr5 = lp->a.read_csr(ioaddr, CSR5);
38791- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38792+ csr5 = lp->a->read_csr(ioaddr, CSR5);
38793+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38794 } else {
38795- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38796+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38797 pcnet32_restart(dev, CSR0_NORMAL);
38798 netif_wake_queue(dev);
38799 }
38800@@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
38801 if (!lp->mii)
38802 return 0;
38803
38804- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38805- val_out = lp->a.read_bcr(ioaddr, 34);
38806+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38807+ val_out = lp->a->read_bcr(ioaddr, 34);
38808
38809 return val_out;
38810 }
38811@@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
38812 if (!lp->mii)
38813 return;
38814
38815- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38816- lp->a.write_bcr(ioaddr, 34, val);
38817+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38818+ lp->a->write_bcr(ioaddr, 34, val);
38819 }
38820
38821 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38822@@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38823 curr_link = mii_link_ok(&lp->mii_if);
38824 } else {
38825 ulong ioaddr = dev->base_addr; /* card base I/O address */
38826- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38827+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38828 }
38829 if (!curr_link) {
38830 if (prev_link || verbose) {
38831@@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38832 (ecmd.duplex ==
38833 DUPLEX_FULL) ? "full" : "half");
38834 }
38835- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
38836+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
38837 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
38838 if (lp->mii_if.full_duplex)
38839 bcr9 |= (1 << 0);
38840 else
38841 bcr9 &= ~(1 << 0);
38842- lp->a.write_bcr(dev->base_addr, 9, bcr9);
38843+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
38844 }
38845 } else {
38846 if (netif_msg_link(lp))
38847diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
38848index 7cc9898..6eb50d3 100644
38849--- a/drivers/net/sis190.c
38850+++ b/drivers/net/sis190.c
38851@@ -1598,7 +1598,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
38852 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
38853 struct net_device *dev)
38854 {
38855- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
38856+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
38857 struct sis190_private *tp = netdev_priv(dev);
38858 struct pci_dev *isa_bridge;
38859 u8 reg, tmp8;
38860diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
38861index e13685a..60c948c 100644
38862--- a/drivers/net/sundance.c
38863+++ b/drivers/net/sundance.c
38864@@ -225,7 +225,7 @@ enum {
38865 struct pci_id_info {
38866 const char *name;
38867 };
38868-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
38869+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
38870 {"D-Link DFE-550TX FAST Ethernet Adapter"},
38871 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
38872 {"D-Link DFE-580TX 4 port Server Adapter"},
38873diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
38874index 529f55a..cccaa18 100644
38875--- a/drivers/net/tg3.h
38876+++ b/drivers/net/tg3.h
38877@@ -95,6 +95,7 @@
38878 #define CHIPREV_ID_5750_A0 0x4000
38879 #define CHIPREV_ID_5750_A1 0x4001
38880 #define CHIPREV_ID_5750_A3 0x4003
38881+#define CHIPREV_ID_5750_C1 0x4201
38882 #define CHIPREV_ID_5750_C2 0x4202
38883 #define CHIPREV_ID_5752_A0_HW 0x5000
38884 #define CHIPREV_ID_5752_A0 0x6000
38885diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
38886index b9db1b5..720f9ce 100644
38887--- a/drivers/net/tokenring/abyss.c
38888+++ b/drivers/net/tokenring/abyss.c
38889@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
38890
38891 static int __init abyss_init (void)
38892 {
38893- abyss_netdev_ops = tms380tr_netdev_ops;
38894+ pax_open_kernel();
38895+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38896
38897- abyss_netdev_ops.ndo_open = abyss_open;
38898- abyss_netdev_ops.ndo_stop = abyss_close;
38899+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
38900+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
38901+ pax_close_kernel();
38902
38903 return pci_register_driver(&abyss_driver);
38904 }
38905diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
38906index 456f8bf..373e56d 100644
38907--- a/drivers/net/tokenring/madgemc.c
38908+++ b/drivers/net/tokenring/madgemc.c
38909@@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver = {
38910
38911 static int __init madgemc_init (void)
38912 {
38913- madgemc_netdev_ops = tms380tr_netdev_ops;
38914- madgemc_netdev_ops.ndo_open = madgemc_open;
38915- madgemc_netdev_ops.ndo_stop = madgemc_close;
38916+ pax_open_kernel();
38917+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38918+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
38919+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
38920+ pax_close_kernel();
38921
38922 return mca_register_driver (&madgemc_driver);
38923 }
38924diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
38925index 16e8783..925bd49 100644
38926--- a/drivers/net/tokenring/proteon.c
38927+++ b/drivers/net/tokenring/proteon.c
38928@@ -353,9 +353,11 @@ static int __init proteon_init(void)
38929 struct platform_device *pdev;
38930 int i, num = 0, err = 0;
38931
38932- proteon_netdev_ops = tms380tr_netdev_ops;
38933- proteon_netdev_ops.ndo_open = proteon_open;
38934- proteon_netdev_ops.ndo_stop = tms380tr_close;
38935+ pax_open_kernel();
38936+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38937+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
38938+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
38939+ pax_close_kernel();
38940
38941 err = platform_driver_register(&proteon_driver);
38942 if (err)
38943diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
38944index 46db5c5..37c1536 100644
38945--- a/drivers/net/tokenring/skisa.c
38946+++ b/drivers/net/tokenring/skisa.c
38947@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
38948 struct platform_device *pdev;
38949 int i, num = 0, err = 0;
38950
38951- sk_isa_netdev_ops = tms380tr_netdev_ops;
38952- sk_isa_netdev_ops.ndo_open = sk_isa_open;
38953- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
38954+ pax_open_kernel();
38955+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38956+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
38957+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
38958+ pax_close_kernel();
38959
38960 err = platform_driver_register(&sk_isa_driver);
38961 if (err)
38962diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
38963index 74e5ba4..5cf6bc9 100644
38964--- a/drivers/net/tulip/de2104x.c
38965+++ b/drivers/net/tulip/de2104x.c
38966@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
38967 struct de_srom_info_leaf *il;
38968 void *bufp;
38969
38970+ pax_track_stack();
38971+
38972 /* download entire eeprom */
38973 for (i = 0; i < DE_EEPROM_WORDS; i++)
38974 ((__le16 *)ee_data)[i] =
38975diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
38976index a8349b7..90f9dfe 100644
38977--- a/drivers/net/tulip/de4x5.c
38978+++ b/drivers/net/tulip/de4x5.c
38979@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38980 for (i=0; i<ETH_ALEN; i++) {
38981 tmp.addr[i] = dev->dev_addr[i];
38982 }
38983- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38984+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38985 break;
38986
38987 case DE4X5_SET_HWADDR: /* Set the hardware address */
38988@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38989 spin_lock_irqsave(&lp->lock, flags);
38990 memcpy(&statbuf, &lp->pktStats, ioc->len);
38991 spin_unlock_irqrestore(&lp->lock, flags);
38992- if (copy_to_user(ioc->data, &statbuf, ioc->len))
38993+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
38994 return -EFAULT;
38995 break;
38996 }
38997diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
38998index 391acd3..56d11cd 100644
38999--- a/drivers/net/tulip/eeprom.c
39000+++ b/drivers/net/tulip/eeprom.c
39001@@ -80,7 +80,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
39002 {NULL}};
39003
39004
39005-static const char *block_name[] __devinitdata = {
39006+static const char *block_name[] __devinitconst = {
39007 "21140 non-MII",
39008 "21140 MII PHY",
39009 "21142 Serial PHY",
39010diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
39011index b38d3b7..b1cff23 100644
39012--- a/drivers/net/tulip/winbond-840.c
39013+++ b/drivers/net/tulip/winbond-840.c
39014@@ -235,7 +235,7 @@ struct pci_id_info {
39015 int drv_flags; /* Driver use, intended as capability flags. */
39016 };
39017
39018-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
39019+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
39020 { /* Sometime a Level-One switch card. */
39021 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
39022 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
39023diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39024index f450bc9..2b747c8 100644
39025--- a/drivers/net/usb/hso.c
39026+++ b/drivers/net/usb/hso.c
39027@@ -71,7 +71,7 @@
39028 #include <asm/byteorder.h>
39029 #include <linux/serial_core.h>
39030 #include <linux/serial.h>
39031-
39032+#include <asm/local.h>
39033
39034 #define DRIVER_VERSION "1.2"
39035 #define MOD_AUTHOR "Option Wireless"
39036@@ -258,7 +258,7 @@ struct hso_serial {
39037
39038 /* from usb_serial_port */
39039 struct tty_struct *tty;
39040- int open_count;
39041+ local_t open_count;
39042 spinlock_t serial_lock;
39043
39044 int (*write_data) (struct hso_serial *serial);
39045@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39046 struct urb *urb;
39047
39048 urb = serial->rx_urb[0];
39049- if (serial->open_count > 0) {
39050+ if (local_read(&serial->open_count) > 0) {
39051 count = put_rxbuf_data(urb, serial);
39052 if (count == -1)
39053 return;
39054@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39055 DUMP1(urb->transfer_buffer, urb->actual_length);
39056
39057 /* Anyone listening? */
39058- if (serial->open_count == 0)
39059+ if (local_read(&serial->open_count) == 0)
39060 return;
39061
39062 if (status == 0) {
39063@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39064 spin_unlock_irq(&serial->serial_lock);
39065
39066 /* check for port already opened, if not set the termios */
39067- serial->open_count++;
39068- if (serial->open_count == 1) {
39069+ if (local_inc_return(&serial->open_count) == 1) {
39070 tty->low_latency = 1;
39071 serial->rx_state = RX_IDLE;
39072 /* Force default termio settings */
39073@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39074 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39075 if (result) {
39076 hso_stop_serial_device(serial->parent);
39077- serial->open_count--;
39078+ local_dec(&serial->open_count);
39079 kref_put(&serial->parent->ref, hso_serial_ref_free);
39080 }
39081 } else {
39082@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39083
39084 /* reset the rts and dtr */
39085 /* do the actual close */
39086- serial->open_count--;
39087+ local_dec(&serial->open_count);
39088
39089- if (serial->open_count <= 0) {
39090- serial->open_count = 0;
39091+ if (local_read(&serial->open_count) <= 0) {
39092+ local_set(&serial->open_count, 0);
39093 spin_lock_irq(&serial->serial_lock);
39094 if (serial->tty == tty) {
39095 serial->tty->driver_data = NULL;
39096@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39097
39098 /* the actual setup */
39099 spin_lock_irqsave(&serial->serial_lock, flags);
39100- if (serial->open_count)
39101+ if (local_read(&serial->open_count))
39102 _hso_serial_set_termios(tty, old);
39103 else
39104 tty->termios = old;
39105@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interface *iface)
39106 /* Start all serial ports */
39107 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39108 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39109- if (dev2ser(serial_table[i])->open_count) {
39110+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
39111 result =
39112 hso_start_serial_device(serial_table[i], GFP_NOIO);
39113 hso_kick_transmit(dev2ser(serial_table[i]));
39114diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
39115index 3e94f0c..ffdd926 100644
39116--- a/drivers/net/vxge/vxge-config.h
39117+++ b/drivers/net/vxge/vxge-config.h
39118@@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
39119 void (*link_down)(struct __vxge_hw_device *devh);
39120 void (*crit_err)(struct __vxge_hw_device *devh,
39121 enum vxge_hw_event type, u64 ext_data);
39122-};
39123+} __no_const;
39124
39125 /*
39126 * struct __vxge_hw_blockpool_entry - Block private data structure
39127diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
39128index 068d7a9..35293de 100644
39129--- a/drivers/net/vxge/vxge-main.c
39130+++ b/drivers/net/vxge/vxge-main.c
39131@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
39132 struct sk_buff *completed[NR_SKB_COMPLETED];
39133 int more;
39134
39135+ pax_track_stack();
39136+
39137 do {
39138 more = 0;
39139 skb_ptr = completed;
39140@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
39141 u8 mtable[256] = {0}; /* CPU to vpath mapping */
39142 int index;
39143
39144+ pax_track_stack();
39145+
39146 /*
39147 * Filling
39148 * - itable with bucket numbers
39149diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
39150index 461742b..81be42e 100644
39151--- a/drivers/net/vxge/vxge-traffic.h
39152+++ b/drivers/net/vxge/vxge-traffic.h
39153@@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
39154 struct vxge_hw_mempool_dma *dma_object,
39155 u32 index,
39156 u32 is_last);
39157-};
39158+} __no_const;
39159
39160 void
39161 __vxge_hw_mempool_destroy(
39162diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
39163index cd8cb95..4153b79 100644
39164--- a/drivers/net/wan/cycx_x25.c
39165+++ b/drivers/net/wan/cycx_x25.c
39166@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned char *p, int len)
39167 unsigned char hex[1024],
39168 * phex = hex;
39169
39170+ pax_track_stack();
39171+
39172 if (len >= (sizeof(hex) / 2))
39173 len = (sizeof(hex) / 2) - 1;
39174
39175diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
39176index aa9248f..a4e3c3b 100644
39177--- a/drivers/net/wan/hdlc_x25.c
39178+++ b/drivers/net/wan/hdlc_x25.c
39179@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
39180
39181 static int x25_open(struct net_device *dev)
39182 {
39183- struct lapb_register_struct cb;
39184+ static struct lapb_register_struct cb = {
39185+ .connect_confirmation = x25_connected,
39186+ .connect_indication = x25_connected,
39187+ .disconnect_confirmation = x25_disconnected,
39188+ .disconnect_indication = x25_disconnected,
39189+ .data_indication = x25_data_indication,
39190+ .data_transmit = x25_data_transmit
39191+ };
39192 int result;
39193
39194- cb.connect_confirmation = x25_connected;
39195- cb.connect_indication = x25_connected;
39196- cb.disconnect_confirmation = x25_disconnected;
39197- cb.disconnect_indication = x25_disconnected;
39198- cb.data_indication = x25_data_indication;
39199- cb.data_transmit = x25_data_transmit;
39200-
39201 result = lapb_register(dev, &cb);
39202 if (result != LAPB_OK)
39203 return result;
39204diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
39205index 5ad287c..783b020 100644
39206--- a/drivers/net/wimax/i2400m/usb-fw.c
39207+++ b/drivers/net/wimax/i2400m/usb-fw.c
39208@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
39209 int do_autopm = 1;
39210 DECLARE_COMPLETION_ONSTACK(notif_completion);
39211
39212+ pax_track_stack();
39213+
39214 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
39215 i2400m, ack, ack_size);
39216 BUG_ON(_ack == i2400m->bm_ack_buf);
39217diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
39218index 6c26840..62c97c3 100644
39219--- a/drivers/net/wireless/airo.c
39220+++ b/drivers/net/wireless/airo.c
39221@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
39222 BSSListElement * loop_net;
39223 BSSListElement * tmp_net;
39224
39225+ pax_track_stack();
39226+
39227 /* Blow away current list of scan results */
39228 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
39229 list_move_tail (&loop_net->list, &ai->network_free_list);
39230@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
39231 WepKeyRid wkr;
39232 int rc;
39233
39234+ pax_track_stack();
39235+
39236 memset( &mySsid, 0, sizeof( mySsid ) );
39237 kfree (ai->flash);
39238 ai->flash = NULL;
39239@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct inode *inode,
39240 __le32 *vals = stats.vals;
39241 int len;
39242
39243+ pax_track_stack();
39244+
39245 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39246 return -ENOMEM;
39247 data = (struct proc_data *)file->private_data;
39248@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
39249 /* If doLoseSync is not 1, we won't do a Lose Sync */
39250 int doLoseSync = -1;
39251
39252+ pax_track_stack();
39253+
39254 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39255 return -ENOMEM;
39256 data = (struct proc_data *)file->private_data;
39257@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_device *dev,
39258 int i;
39259 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
39260
39261+ pax_track_stack();
39262+
39263 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
39264 if (!qual)
39265 return -ENOMEM;
39266@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
39267 CapabilityRid cap_rid;
39268 __le32 *vals = stats_rid.vals;
39269
39270+ pax_track_stack();
39271+
39272 /* Get stats out of the card */
39273 clear_bit(JOB_WSTATS, &local->jobs);
39274 if (local->power.event) {
39275diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
39276index 747508c..82e965d 100644
39277--- a/drivers/net/wireless/ath/ath5k/debug.c
39278+++ b/drivers/net/wireless/ath/ath5k/debug.c
39279@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
39280 unsigned int v;
39281 u64 tsf;
39282
39283+ pax_track_stack();
39284+
39285 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
39286 len += snprintf(buf+len, sizeof(buf)-len,
39287 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
39288@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
39289 unsigned int len = 0;
39290 unsigned int i;
39291
39292+ pax_track_stack();
39293+
39294 len += snprintf(buf+len, sizeof(buf)-len,
39295 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
39296
39297diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
39298index 2be4c22..593b1eb 100644
39299--- a/drivers/net/wireless/ath/ath9k/debug.c
39300+++ b/drivers/net/wireless/ath/ath9k/debug.c
39301@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
39302 char buf[512];
39303 unsigned int len = 0;
39304
39305+ pax_track_stack();
39306+
39307 len += snprintf(buf + len, sizeof(buf) - len,
39308 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
39309 len += snprintf(buf + len, sizeof(buf) - len,
39310@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
39311 int i;
39312 u8 addr[ETH_ALEN];
39313
39314+ pax_track_stack();
39315+
39316 len += snprintf(buf + len, sizeof(buf) - len,
39317 "primary: %s (%s chan=%d ht=%d)\n",
39318 wiphy_name(sc->pri_wiphy->hw->wiphy),
39319diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
39320index 80b19a4..dab3a45 100644
39321--- a/drivers/net/wireless/b43/debugfs.c
39322+++ b/drivers/net/wireless/b43/debugfs.c
39323@@ -43,7 +43,7 @@ static struct dentry *rootdir;
39324 struct b43_debugfs_fops {
39325 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
39326 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
39327- struct file_operations fops;
39328+ const struct file_operations fops;
39329 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
39330 size_t file_struct_offset;
39331 };
39332diff --git a/drivers/net/wireless/b43legacy/debugfs.c b/drivers/net/wireless/b43legacy/debugfs.c
39333index 1f85ac5..c99b4b4 100644
39334--- a/drivers/net/wireless/b43legacy/debugfs.c
39335+++ b/drivers/net/wireless/b43legacy/debugfs.c
39336@@ -44,7 +44,7 @@ static struct dentry *rootdir;
39337 struct b43legacy_debugfs_fops {
39338 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
39339 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
39340- struct file_operations fops;
39341+ const struct file_operations fops;
39342 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
39343 size_t file_struct_offset;
39344 /* Take wl->irq_lock before calling read/write? */
39345diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
39346index 43102bf..3b569c3 100644
39347--- a/drivers/net/wireless/ipw2x00/ipw2100.c
39348+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
39349@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
39350 int err;
39351 DECLARE_SSID_BUF(ssid);
39352
39353+ pax_track_stack();
39354+
39355 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
39356
39357 if (ssid_len)
39358@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
39359 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
39360 int err;
39361
39362+ pax_track_stack();
39363+
39364 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
39365 idx, keylen, len);
39366
39367diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
39368index 282b1f7..169f0cf 100644
39369--- a/drivers/net/wireless/ipw2x00/libipw_rx.c
39370+++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
39371@@ -1566,6 +1566,8 @@ static void libipw_process_probe_response(struct libipw_device
39372 unsigned long flags;
39373 DECLARE_SSID_BUF(ssid);
39374
39375+ pax_track_stack();
39376+
39377 LIBIPW_DEBUG_SCAN("'%s' (%pM"
39378 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
39379 print_ssid(ssid, info_element->data, info_element->len),
39380diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
39381index 950267a..80d5fd2 100644
39382--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
39383+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
39384@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib = {
39385 },
39386 };
39387
39388-static struct iwl_ops iwl1000_ops = {
39389+static const struct iwl_ops iwl1000_ops = {
39390 .ucode = &iwl5000_ucode,
39391 .lib = &iwl1000_lib,
39392 .hcmd = &iwl5000_hcmd,
39393diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
39394index 56bfcc3..b348020 100644
39395--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
39396+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
39397@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
39398 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
39399 };
39400
39401-static struct iwl_ops iwl3945_ops = {
39402+static const struct iwl_ops iwl3945_ops = {
39403 .ucode = &iwl3945_ucode,
39404 .lib = &iwl3945_lib,
39405 .hcmd = &iwl3945_hcmd,
39406diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
39407index 585b8d4..e142963 100644
39408--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
39409+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
39410@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib = {
39411 },
39412 };
39413
39414-static struct iwl_ops iwl4965_ops = {
39415+static const struct iwl_ops iwl4965_ops = {
39416 .ucode = &iwl4965_ucode,
39417 .lib = &iwl4965_lib,
39418 .hcmd = &iwl4965_hcmd,
39419diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
39420index 1f423f2..e37c192 100644
39421--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
39422+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
39423@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib = {
39424 },
39425 };
39426
39427-struct iwl_ops iwl5000_ops = {
39428+const struct iwl_ops iwl5000_ops = {
39429 .ucode = &iwl5000_ucode,
39430 .lib = &iwl5000_lib,
39431 .hcmd = &iwl5000_hcmd,
39432 .utils = &iwl5000_hcmd_utils,
39433 };
39434
39435-static struct iwl_ops iwl5150_ops = {
39436+static const struct iwl_ops iwl5150_ops = {
39437 .ucode = &iwl5000_ucode,
39438 .lib = &iwl5150_lib,
39439 .hcmd = &iwl5000_hcmd,
39440diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
39441index 1473452..f07d5e1 100644
39442--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
39443+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
39444@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000_hcmd_utils = {
39445 .calc_rssi = iwl5000_calc_rssi,
39446 };
39447
39448-static struct iwl_ops iwl6000_ops = {
39449+static const struct iwl_ops iwl6000_ops = {
39450 .ucode = &iwl5000_ucode,
39451 .lib = &iwl6000_lib,
39452 .hcmd = &iwl5000_hcmd,
39453diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39454index 1a3dfa2..b3e0a61 100644
39455--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39456+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39457@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
39458 u8 active_index = 0;
39459 s32 tpt = 0;
39460
39461+ pax_track_stack();
39462+
39463 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
39464
39465 if (!ieee80211_is_data(hdr->frame_control) ||
39466@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
39467 u8 valid_tx_ant = 0;
39468 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
39469
39470+ pax_track_stack();
39471+
39472 /* Override starting rate (index 0) if needed for debug purposes */
39473 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
39474
39475diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
39476index 0e56d78..6a3c107 100644
39477--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
39478+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
39479@@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39480 if (iwl_debug_level & IWL_DL_INFO)
39481 dev_printk(KERN_DEBUG, &(pdev->dev),
39482 "Disabling hw_scan\n");
39483- iwl_hw_ops.hw_scan = NULL;
39484+ pax_open_kernel();
39485+ *(void **)&iwl_hw_ops.hw_scan = NULL;
39486+ pax_close_kernel();
39487 }
39488
39489 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
39490diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
39491index cbc6290..eb323d7 100644
39492--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
39493+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
39494@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv);
39495 #endif
39496
39497 #else
39498-#define IWL_DEBUG(__priv, level, fmt, args...)
39499-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
39500+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
39501+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
39502 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
39503 void *p, u32 len)
39504 {}
39505diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39506index a198bcf..8e68233 100644
39507--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39508+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39509@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
39510 int pos = 0;
39511 const size_t bufsz = sizeof(buf);
39512
39513+ pax_track_stack();
39514+
39515 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
39516 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
39517 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
39518@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
39519 const size_t bufsz = sizeof(buf);
39520 ssize_t ret;
39521
39522+ pax_track_stack();
39523+
39524 for (i = 0; i < AC_NUM; i++) {
39525 pos += scnprintf(buf + pos, bufsz - pos,
39526 "\tcw_min\tcw_max\taifsn\ttxop\n");
39527diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
39528index 3539ea4..b174bfa 100644
39529--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
39530+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
39531@@ -68,7 +68,7 @@ struct iwl_tx_queue;
39532
39533 /* shared structures from iwl-5000.c */
39534 extern struct iwl_mod_params iwl50_mod_params;
39535-extern struct iwl_ops iwl5000_ops;
39536+extern const struct iwl_ops iwl5000_ops;
39537 extern struct iwl_ucode_ops iwl5000_ucode;
39538 extern struct iwl_lib_ops iwl5000_lib;
39539 extern struct iwl_hcmd_ops iwl5000_hcmd;
39540diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39541index 619590d..69235ee 100644
39542--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
39543+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39544@@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
39545 */
39546 if (iwl3945_mod_params.disable_hw_scan) {
39547 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
39548- iwl3945_hw_ops.hw_scan = NULL;
39549+ pax_open_kernel();
39550+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
39551+ pax_close_kernel();
39552 }
39553
39554
39555diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39556index 1465379..fe4d78b 100644
39557--- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
39558+++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39559@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
39560 int buf_len = 512;
39561 size_t len = 0;
39562
39563+ pax_track_stack();
39564+
39565 if (*ppos != 0)
39566 return 0;
39567 if (count < sizeof(buf))
39568diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
39569index 893a55c..7f66a50 100644
39570--- a/drivers/net/wireless/libertas/debugfs.c
39571+++ b/drivers/net/wireless/libertas/debugfs.c
39572@@ -708,7 +708,7 @@ out_unlock:
39573 struct lbs_debugfs_files {
39574 const char *name;
39575 int perm;
39576- struct file_operations fops;
39577+ const struct file_operations fops;
39578 };
39579
39580 static const struct lbs_debugfs_files debugfs_files[] = {
39581diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39582index 2ecbedb..42704f0 100644
39583--- a/drivers/net/wireless/rndis_wlan.c
39584+++ b/drivers/net/wireless/rndis_wlan.c
39585@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39586
39587 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
39588
39589- if (rts_threshold < 0 || rts_threshold > 2347)
39590+ if (rts_threshold > 2347)
39591 rts_threshold = 2347;
39592
39593 tmp = cpu_to_le32(rts_threshold);
39594diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39595index 334ccd6..47f8944 100644
39596--- a/drivers/oprofile/buffer_sync.c
39597+++ b/drivers/oprofile/buffer_sync.c
39598@@ -342,7 +342,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39599 if (cookie == NO_COOKIE)
39600 offset = pc;
39601 if (cookie == INVALID_COOKIE) {
39602- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39603+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39604 offset = pc;
39605 }
39606 if (cookie != last_cookie) {
39607@@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39608 /* add userspace sample */
39609
39610 if (!mm) {
39611- atomic_inc(&oprofile_stats.sample_lost_no_mm);
39612+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39613 return 0;
39614 }
39615
39616 cookie = lookup_dcookie(mm, s->eip, &offset);
39617
39618 if (cookie == INVALID_COOKIE) {
39619- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39620+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39621 return 0;
39622 }
39623
39624@@ -562,7 +562,7 @@ void sync_buffer(int cpu)
39625 /* ignore backtraces if failed to add a sample */
39626 if (state == sb_bt_start) {
39627 state = sb_bt_ignore;
39628- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39629+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39630 }
39631 }
39632 release_mm(mm);
39633diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39634index 5df60a6..72f5c1c 100644
39635--- a/drivers/oprofile/event_buffer.c
39636+++ b/drivers/oprofile/event_buffer.c
39637@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39638 }
39639
39640 if (buffer_pos == buffer_size) {
39641- atomic_inc(&oprofile_stats.event_lost_overflow);
39642+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39643 return;
39644 }
39645
39646diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39647index dc8a042..fe5f315 100644
39648--- a/drivers/oprofile/oprof.c
39649+++ b/drivers/oprofile/oprof.c
39650@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39651 if (oprofile_ops.switch_events())
39652 return;
39653
39654- atomic_inc(&oprofile_stats.multiplex_counter);
39655+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39656 start_switch_worker();
39657 }
39658
39659diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39660index 61689e8..387f7f8 100644
39661--- a/drivers/oprofile/oprofile_stats.c
39662+++ b/drivers/oprofile/oprofile_stats.c
39663@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39664 cpu_buf->sample_invalid_eip = 0;
39665 }
39666
39667- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39668- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39669- atomic_set(&oprofile_stats.event_lost_overflow, 0);
39670- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39671- atomic_set(&oprofile_stats.multiplex_counter, 0);
39672+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39673+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39674+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39675+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39676+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39677 }
39678
39679
39680diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39681index 0b54e46..a37c527 100644
39682--- a/drivers/oprofile/oprofile_stats.h
39683+++ b/drivers/oprofile/oprofile_stats.h
39684@@ -13,11 +13,11 @@
39685 #include <asm/atomic.h>
39686
39687 struct oprofile_stat_struct {
39688- atomic_t sample_lost_no_mm;
39689- atomic_t sample_lost_no_mapping;
39690- atomic_t bt_lost_no_mapping;
39691- atomic_t event_lost_overflow;
39692- atomic_t multiplex_counter;
39693+ atomic_unchecked_t sample_lost_no_mm;
39694+ atomic_unchecked_t sample_lost_no_mapping;
39695+ atomic_unchecked_t bt_lost_no_mapping;
39696+ atomic_unchecked_t event_lost_overflow;
39697+ atomic_unchecked_t multiplex_counter;
39698 };
39699
39700 extern struct oprofile_stat_struct oprofile_stats;
39701diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39702index 2766a6d..80c77e2 100644
39703--- a/drivers/oprofile/oprofilefs.c
39704+++ b/drivers/oprofile/oprofilefs.c
39705@@ -187,7 +187,7 @@ static const struct file_operations atomic_ro_fops = {
39706
39707
39708 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39709- char const *name, atomic_t *val)
39710+ char const *name, atomic_unchecked_t *val)
39711 {
39712 struct dentry *d = __oprofilefs_create_file(sb, root, name,
39713 &atomic_ro_fops, 0444);
39714diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
39715index 13a64bc..ad62835 100644
39716--- a/drivers/parisc/pdc_stable.c
39717+++ b/drivers/parisc/pdc_stable.c
39718@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
39719 return ret;
39720 }
39721
39722-static struct sysfs_ops pdcspath_attr_ops = {
39723+static const struct sysfs_ops pdcspath_attr_ops = {
39724 .show = pdcspath_attr_show,
39725 .store = pdcspath_attr_store,
39726 };
39727diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39728index 8eefe56..40751a7 100644
39729--- a/drivers/parport/procfs.c
39730+++ b/drivers/parport/procfs.c
39731@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
39732
39733 *ppos += len;
39734
39735- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
39736+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
39737 }
39738
39739 #ifdef CONFIG_PARPORT_1284
39740@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39741
39742 *ppos += len;
39743
39744- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39745+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39746 }
39747 #endif /* IEEE1284.3 support. */
39748
39749diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
39750index 73e7d8e..c80f3d2 100644
39751--- a/drivers/pci/hotplug/acpiphp_glue.c
39752+++ b/drivers/pci/hotplug/acpiphp_glue.c
39753@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notifier_block *nb, unsigned long val,
39754 }
39755
39756
39757-static struct acpi_dock_ops acpiphp_dock_ops = {
39758+static const struct acpi_dock_ops acpiphp_dock_ops = {
39759 .handler = handle_hotplug_event_func,
39760 };
39761
39762diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
39763index 9fff878..ad0ad53 100644
39764--- a/drivers/pci/hotplug/cpci_hotplug.h
39765+++ b/drivers/pci/hotplug/cpci_hotplug.h
39766@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
39767 int (*hardware_test) (struct slot* slot, u32 value);
39768 u8 (*get_power) (struct slot* slot);
39769 int (*set_power) (struct slot* slot, int value);
39770-};
39771+} __no_const;
39772
39773 struct cpci_hp_controller {
39774 unsigned int irq;
39775diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
39776index 76ba8a1..20ca857 100644
39777--- a/drivers/pci/hotplug/cpqphp_nvram.c
39778+++ b/drivers/pci/hotplug/cpqphp_nvram.c
39779@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
39780
39781 void compaq_nvram_init (void __iomem *rom_start)
39782 {
39783+
39784+#ifndef CONFIG_PAX_KERNEXEC
39785 if (rom_start) {
39786 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
39787 }
39788+#endif
39789+
39790 dbg("int15 entry = %p\n", compaq_int15_entry_point);
39791
39792 /* initialize our int15 lock */
39793diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
39794index 6151389..0a894ef 100644
39795--- a/drivers/pci/hotplug/fakephp.c
39796+++ b/drivers/pci/hotplug/fakephp.c
39797@@ -73,7 +73,7 @@ static void legacy_release(struct kobject *kobj)
39798 }
39799
39800 static struct kobj_type legacy_ktype = {
39801- .sysfs_ops = &(struct sysfs_ops){
39802+ .sysfs_ops = &(const struct sysfs_ops){
39803 .store = legacy_store, .show = legacy_show
39804 },
39805 .release = &legacy_release,
39806diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
39807index 5b680df..fe05b7e 100644
39808--- a/drivers/pci/intel-iommu.c
39809+++ b/drivers/pci/intel-iommu.c
39810@@ -2643,7 +2643,7 @@ error:
39811 return 0;
39812 }
39813
39814-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
39815+dma_addr_t intel_map_page(struct device *dev, struct page *page,
39816 unsigned long offset, size_t size,
39817 enum dma_data_direction dir,
39818 struct dma_attrs *attrs)
39819@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
39820 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
39821 }
39822
39823-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39824+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39825 size_t size, enum dma_data_direction dir,
39826 struct dma_attrs *attrs)
39827 {
39828@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39829 }
39830 }
39831
39832-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39833+void *intel_alloc_coherent(struct device *hwdev, size_t size,
39834 dma_addr_t *dma_handle, gfp_t flags)
39835 {
39836 void *vaddr;
39837@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39838 return NULL;
39839 }
39840
39841-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39842+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39843 dma_addr_t dma_handle)
39844 {
39845 int order;
39846@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39847 free_pages((unsigned long)vaddr, order);
39848 }
39849
39850-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39851+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39852 int nelems, enum dma_data_direction dir,
39853 struct dma_attrs *attrs)
39854 {
39855@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(struct device *hddev,
39856 return nelems;
39857 }
39858
39859-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39860+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39861 enum dma_data_direction dir, struct dma_attrs *attrs)
39862 {
39863 int i;
39864@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
39865 return nelems;
39866 }
39867
39868-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39869+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39870 {
39871 return !dma_addr;
39872 }
39873
39874-struct dma_map_ops intel_dma_ops = {
39875+const struct dma_map_ops intel_dma_ops = {
39876 .alloc_coherent = intel_alloc_coherent,
39877 .free_coherent = intel_free_coherent,
39878 .map_sg = intel_map_sg,
39879diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
39880index 5b7056c..607bc94 100644
39881--- a/drivers/pci/pcie/aspm.c
39882+++ b/drivers/pci/pcie/aspm.c
39883@@ -27,9 +27,9 @@
39884 #define MODULE_PARAM_PREFIX "pcie_aspm."
39885
39886 /* Note: those are not register definitions */
39887-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
39888-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
39889-#define ASPM_STATE_L1 (4) /* L1 state */
39890+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
39891+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
39892+#define ASPM_STATE_L1 (4U) /* L1 state */
39893 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
39894 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
39895
39896diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
39897index 8105e32..ca10419 100644
39898--- a/drivers/pci/probe.c
39899+++ b/drivers/pci/probe.c
39900@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
39901 return ret;
39902 }
39903
39904-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
39905+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
39906 struct device_attribute *attr,
39907 char *buf)
39908 {
39909 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
39910 }
39911
39912-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
39913+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
39914 struct device_attribute *attr,
39915 char *buf)
39916 {
39917diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
39918index a03ad8c..024b0da 100644
39919--- a/drivers/pci/proc.c
39920+++ b/drivers/pci/proc.c
39921@@ -480,7 +480,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
39922 static int __init pci_proc_init(void)
39923 {
39924 struct pci_dev *dev = NULL;
39925+
39926+#ifdef CONFIG_GRKERNSEC_PROC_ADD
39927+#ifdef CONFIG_GRKERNSEC_PROC_USER
39928+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
39929+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
39930+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
39931+#endif
39932+#else
39933 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
39934+#endif
39935 proc_create("devices", 0, proc_bus_pci_dir,
39936 &proc_bus_pci_dev_operations);
39937 proc_initialized = 1;
39938diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
39939index 8c02b6c..5584d8e 100644
39940--- a/drivers/pci/slot.c
39941+++ b/drivers/pci/slot.c
39942@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struct kobject *kobj,
39943 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
39944 }
39945
39946-static struct sysfs_ops pci_slot_sysfs_ops = {
39947+static const struct sysfs_ops pci_slot_sysfs_ops = {
39948 .show = pci_slot_attr_show,
39949 .store = pci_slot_attr_store,
39950 };
39951diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
39952index 30cf71d2..50938f1 100644
39953--- a/drivers/pcmcia/pcmcia_ioctl.c
39954+++ b/drivers/pcmcia/pcmcia_ioctl.c
39955@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
39956 return -EFAULT;
39957 }
39958 }
39959- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
39960+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
39961 if (!buf)
39962 return -ENOMEM;
39963
39964diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
39965index 52183c4..b224c69 100644
39966--- a/drivers/platform/x86/acer-wmi.c
39967+++ b/drivers/platform/x86/acer-wmi.c
39968@@ -918,7 +918,7 @@ static int update_bl_status(struct backlight_device *bd)
39969 return 0;
39970 }
39971
39972-static struct backlight_ops acer_bl_ops = {
39973+static const struct backlight_ops acer_bl_ops = {
39974 .get_brightness = read_brightness,
39975 .update_status = update_bl_status,
39976 };
39977diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
39978index 767cb61..a87380b 100644
39979--- a/drivers/platform/x86/asus-laptop.c
39980+++ b/drivers/platform/x86/asus-laptop.c
39981@@ -250,7 +250,7 @@ static struct backlight_device *asus_backlight_device;
39982 */
39983 static int read_brightness(struct backlight_device *bd);
39984 static int update_bl_status(struct backlight_device *bd);
39985-static struct backlight_ops asusbl_ops = {
39986+static const struct backlight_ops asusbl_ops = {
39987 .get_brightness = read_brightness,
39988 .update_status = update_bl_status,
39989 };
39990diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
39991index d66c07a..a4abaac 100644
39992--- a/drivers/platform/x86/asus_acpi.c
39993+++ b/drivers/platform/x86/asus_acpi.c
39994@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
39995 return 0;
39996 }
39997
39998-static struct backlight_ops asus_backlight_data = {
39999+static const struct backlight_ops asus_backlight_data = {
40000 .get_brightness = read_brightness,
40001 .update_status = set_brightness_status,
40002 };
40003diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
40004index 11003bb..550ff1b 100644
40005--- a/drivers/platform/x86/compal-laptop.c
40006+++ b/drivers/platform/x86/compal-laptop.c
40007@@ -163,7 +163,7 @@ static int bl_update_status(struct backlight_device *b)
40008 return set_lcd_level(b->props.brightness);
40009 }
40010
40011-static struct backlight_ops compalbl_ops = {
40012+static const struct backlight_ops compalbl_ops = {
40013 .get_brightness = bl_get_brightness,
40014 .update_status = bl_update_status,
40015 };
40016diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
40017index 07a74da..9dc99fa 100644
40018--- a/drivers/platform/x86/dell-laptop.c
40019+++ b/drivers/platform/x86/dell-laptop.c
40020@@ -318,7 +318,7 @@ static int dell_get_intensity(struct backlight_device *bd)
40021 return buffer.output[1];
40022 }
40023
40024-static struct backlight_ops dell_ops = {
40025+static const struct backlight_ops dell_ops = {
40026 .get_brightness = dell_get_intensity,
40027 .update_status = dell_send_intensity,
40028 };
40029diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
40030index c533b1c..5c81f22 100644
40031--- a/drivers/platform/x86/eeepc-laptop.c
40032+++ b/drivers/platform/x86/eeepc-laptop.c
40033@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device;
40034 */
40035 static int read_brightness(struct backlight_device *bd);
40036 static int update_bl_status(struct backlight_device *bd);
40037-static struct backlight_ops eeepcbl_ops = {
40038+static const struct backlight_ops eeepcbl_ops = {
40039 .get_brightness = read_brightness,
40040 .update_status = update_bl_status,
40041 };
40042diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
40043index bcd4ba8..a249b35 100644
40044--- a/drivers/platform/x86/fujitsu-laptop.c
40045+++ b/drivers/platform/x86/fujitsu-laptop.c
40046@@ -436,7 +436,7 @@ static int bl_update_status(struct backlight_device *b)
40047 return ret;
40048 }
40049
40050-static struct backlight_ops fujitsubl_ops = {
40051+static const struct backlight_ops fujitsubl_ops = {
40052 .get_brightness = bl_get_brightness,
40053 .update_status = bl_update_status,
40054 };
40055diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40056index 759763d..1093ba2 100644
40057--- a/drivers/platform/x86/msi-laptop.c
40058+++ b/drivers/platform/x86/msi-laptop.c
40059@@ -161,7 +161,7 @@ static int bl_update_status(struct backlight_device *b)
40060 return set_lcd_level(b->props.brightness);
40061 }
40062
40063-static struct backlight_ops msibl_ops = {
40064+static const struct backlight_ops msibl_ops = {
40065 .get_brightness = bl_get_brightness,
40066 .update_status = bl_update_status,
40067 };
40068diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
40069index fe7cf01..9012d8d 100644
40070--- a/drivers/platform/x86/panasonic-laptop.c
40071+++ b/drivers/platform/x86/panasonic-laptop.c
40072@@ -352,7 +352,7 @@ static int bl_set_status(struct backlight_device *bd)
40073 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
40074 }
40075
40076-static struct backlight_ops pcc_backlight_ops = {
40077+static const struct backlight_ops pcc_backlight_ops = {
40078 .get_brightness = bl_get,
40079 .update_status = bl_set_status,
40080 };
40081diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40082index a2a742c..b37e25e 100644
40083--- a/drivers/platform/x86/sony-laptop.c
40084+++ b/drivers/platform/x86/sony-laptop.c
40085@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
40086 }
40087
40088 static struct backlight_device *sony_backlight_device;
40089-static struct backlight_ops sony_backlight_ops = {
40090+static const struct backlight_ops sony_backlight_ops = {
40091 .update_status = sony_backlight_update_status,
40092 .get_brightness = sony_backlight_get_brightness,
40093 };
40094diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40095index 68271ae..5e8fb10 100644
40096--- a/drivers/platform/x86/thinkpad_acpi.c
40097+++ b/drivers/platform/x86/thinkpad_acpi.c
40098@@ -2139,7 +2139,7 @@ static int hotkey_mask_get(void)
40099 return 0;
40100 }
40101
40102-void static hotkey_mask_warn_incomplete_mask(void)
40103+static void hotkey_mask_warn_incomplete_mask(void)
40104 {
40105 /* log only what the user can fix... */
40106 const u32 wantedmask = hotkey_driver_mask &
40107@@ -6125,7 +6125,7 @@ static void tpacpi_brightness_notify_change(void)
40108 BACKLIGHT_UPDATE_HOTKEY);
40109 }
40110
40111-static struct backlight_ops ibm_backlight_data = {
40112+static const struct backlight_ops ibm_backlight_data = {
40113 .get_brightness = brightness_get,
40114 .update_status = brightness_update_status,
40115 };
40116diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
40117index 51c0a8b..0786629 100644
40118--- a/drivers/platform/x86/toshiba_acpi.c
40119+++ b/drivers/platform/x86/toshiba_acpi.c
40120@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
40121 return AE_OK;
40122 }
40123
40124-static struct backlight_ops toshiba_backlight_data = {
40125+static const struct backlight_ops toshiba_backlight_data = {
40126 .get_brightness = get_lcd,
40127 .update_status = set_lcd_status,
40128 };
40129diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40130index fc83783c..cf370d7 100644
40131--- a/drivers/pnp/pnpbios/bioscalls.c
40132+++ b/drivers/pnp/pnpbios/bioscalls.c
40133@@ -60,7 +60,7 @@ do { \
40134 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40135 } while(0)
40136
40137-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40138+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40139 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40140
40141 /*
40142@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40143
40144 cpu = get_cpu();
40145 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40146+
40147+ pax_open_kernel();
40148 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40149+ pax_close_kernel();
40150
40151 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40152 spin_lock_irqsave(&pnp_bios_lock, flags);
40153@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40154 :"memory");
40155 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40156
40157+ pax_open_kernel();
40158 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40159+ pax_close_kernel();
40160+
40161 put_cpu();
40162
40163 /* If we get here and this is set then the PnP BIOS faulted on us. */
40164@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40165 return status;
40166 }
40167
40168-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40169+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40170 {
40171 int i;
40172
40173@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40174 pnp_bios_callpoint.offset = header->fields.pm16offset;
40175 pnp_bios_callpoint.segment = PNP_CS16;
40176
40177+ pax_open_kernel();
40178+
40179 for_each_possible_cpu(i) {
40180 struct desc_struct *gdt = get_cpu_gdt_table(i);
40181 if (!gdt)
40182@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40183 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40184 (unsigned long)__va(header->fields.pm16dseg));
40185 }
40186+
40187+ pax_close_kernel();
40188 }
40189diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40190index ba97654..66b99d4 100644
40191--- a/drivers/pnp/resource.c
40192+++ b/drivers/pnp/resource.c
40193@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40194 return 1;
40195
40196 /* check if the resource is valid */
40197- if (*irq < 0 || *irq > 15)
40198+ if (*irq > 15)
40199 return 0;
40200
40201 /* check if the resource is reserved */
40202@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40203 return 1;
40204
40205 /* check if the resource is valid */
40206- if (*dma < 0 || *dma == 4 || *dma > 7)
40207+ if (*dma == 4 || *dma > 7)
40208 return 0;
40209
40210 /* check if the resource is reserved */
40211diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
40212index 62bb981..24a2dc9 100644
40213--- a/drivers/power/bq27x00_battery.c
40214+++ b/drivers/power/bq27x00_battery.c
40215@@ -44,7 +44,7 @@ struct bq27x00_device_info;
40216 struct bq27x00_access_methods {
40217 int (*read)(u8 reg, int *rt_value, int b_single,
40218 struct bq27x00_device_info *di);
40219-};
40220+} __no_const;
40221
40222 struct bq27x00_device_info {
40223 struct device *dev;
40224diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40225index 62227cd..b5b538b 100644
40226--- a/drivers/rtc/rtc-dev.c
40227+++ b/drivers/rtc/rtc-dev.c
40228@@ -14,6 +14,7 @@
40229 #include <linux/module.h>
40230 #include <linux/rtc.h>
40231 #include <linux/sched.h>
40232+#include <linux/grsecurity.h>
40233 #include "rtc-core.h"
40234
40235 static dev_t rtc_devt;
40236@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *file,
40237 if (copy_from_user(&tm, uarg, sizeof(tm)))
40238 return -EFAULT;
40239
40240+ gr_log_timechange();
40241+
40242 return rtc_set_time(rtc, &tm);
40243
40244 case RTC_PIE_ON:
40245diff --git a/drivers/s390/cio/qdio_perf.c b/drivers/s390/cio/qdio_perf.c
40246index 968e3c7..fbc637a 100644
40247--- a/drivers/s390/cio/qdio_perf.c
40248+++ b/drivers/s390/cio/qdio_perf.c
40249@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_pde;
40250 static int qdio_perf_proc_show(struct seq_file *m, void *v)
40251 {
40252 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
40253- (long)atomic_long_read(&perf_stats.qdio_int));
40254+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
40255 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
40256- (long)atomic_long_read(&perf_stats.pci_int));
40257+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
40258 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
40259- (long)atomic_long_read(&perf_stats.thin_int));
40260+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
40261 seq_printf(m, "\n");
40262 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
40263- (long)atomic_long_read(&perf_stats.tasklet_inbound));
40264+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
40265 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
40266- (long)atomic_long_read(&perf_stats.tasklet_outbound));
40267+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
40268 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
40269- (long)atomic_long_read(&perf_stats.tasklet_thinint),
40270- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
40271+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
40272+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
40273 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
40274- (long)atomic_long_read(&perf_stats.thinint_inbound),
40275- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
40276+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
40277+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
40278 seq_printf(m, "\n");
40279 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
40280- (long)atomic_long_read(&perf_stats.siga_in));
40281+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
40282 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
40283- (long)atomic_long_read(&perf_stats.siga_out));
40284+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
40285 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
40286- (long)atomic_long_read(&perf_stats.siga_sync));
40287+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
40288 seq_printf(m, "\n");
40289 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
40290- (long)atomic_long_read(&perf_stats.inbound_handler));
40291+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
40292 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
40293- (long)atomic_long_read(&perf_stats.outbound_handler));
40294+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
40295 seq_printf(m, "\n");
40296 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
40297- (long)atomic_long_read(&perf_stats.fast_requeue));
40298+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
40299 seq_printf(m, "Number of outbound target full condition\t: %li\n",
40300- (long)atomic_long_read(&perf_stats.outbound_target_full));
40301+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
40302 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
40303- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
40304+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
40305 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
40306- (long)atomic_long_read(&perf_stats.debug_stop_polling));
40307+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
40308 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
40309- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
40310+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
40311 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
40312- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
40313- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
40314+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
40315+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
40316 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
40317- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
40318- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
40319+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
40320+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
40321 seq_printf(m, "\n");
40322 return 0;
40323 }
40324diff --git a/drivers/s390/cio/qdio_perf.h b/drivers/s390/cio/qdio_perf.h
40325index ff4504c..b3604c3 100644
40326--- a/drivers/s390/cio/qdio_perf.h
40327+++ b/drivers/s390/cio/qdio_perf.h
40328@@ -13,46 +13,46 @@
40329
40330 struct qdio_perf_stats {
40331 /* interrupt handler calls */
40332- atomic_long_t qdio_int;
40333- atomic_long_t pci_int;
40334- atomic_long_t thin_int;
40335+ atomic_long_unchecked_t qdio_int;
40336+ atomic_long_unchecked_t pci_int;
40337+ atomic_long_unchecked_t thin_int;
40338
40339 /* tasklet runs */
40340- atomic_long_t tasklet_inbound;
40341- atomic_long_t tasklet_outbound;
40342- atomic_long_t tasklet_thinint;
40343- atomic_long_t tasklet_thinint_loop;
40344- atomic_long_t thinint_inbound;
40345- atomic_long_t thinint_inbound_loop;
40346- atomic_long_t thinint_inbound_loop2;
40347+ atomic_long_unchecked_t tasklet_inbound;
40348+ atomic_long_unchecked_t tasklet_outbound;
40349+ atomic_long_unchecked_t tasklet_thinint;
40350+ atomic_long_unchecked_t tasklet_thinint_loop;
40351+ atomic_long_unchecked_t thinint_inbound;
40352+ atomic_long_unchecked_t thinint_inbound_loop;
40353+ atomic_long_unchecked_t thinint_inbound_loop2;
40354
40355 /* signal adapter calls */
40356- atomic_long_t siga_out;
40357- atomic_long_t siga_in;
40358- atomic_long_t siga_sync;
40359+ atomic_long_unchecked_t siga_out;
40360+ atomic_long_unchecked_t siga_in;
40361+ atomic_long_unchecked_t siga_sync;
40362
40363 /* misc */
40364- atomic_long_t inbound_handler;
40365- atomic_long_t outbound_handler;
40366- atomic_long_t fast_requeue;
40367- atomic_long_t outbound_target_full;
40368+ atomic_long_unchecked_t inbound_handler;
40369+ atomic_long_unchecked_t outbound_handler;
40370+ atomic_long_unchecked_t fast_requeue;
40371+ atomic_long_unchecked_t outbound_target_full;
40372
40373 /* for debugging */
40374- atomic_long_t debug_tl_out_timer;
40375- atomic_long_t debug_stop_polling;
40376- atomic_long_t debug_eqbs_all;
40377- atomic_long_t debug_eqbs_incomplete;
40378- atomic_long_t debug_sqbs_all;
40379- atomic_long_t debug_sqbs_incomplete;
40380+ atomic_long_unchecked_t debug_tl_out_timer;
40381+ atomic_long_unchecked_t debug_stop_polling;
40382+ atomic_long_unchecked_t debug_eqbs_all;
40383+ atomic_long_unchecked_t debug_eqbs_incomplete;
40384+ atomic_long_unchecked_t debug_sqbs_all;
40385+ atomic_long_unchecked_t debug_sqbs_incomplete;
40386 };
40387
40388 extern struct qdio_perf_stats perf_stats;
40389 extern int qdio_performance_stats;
40390
40391-static inline void qdio_perf_stat_inc(atomic_long_t *count)
40392+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
40393 {
40394 if (qdio_performance_stats)
40395- atomic_long_inc(count);
40396+ atomic_long_inc_unchecked(count);
40397 }
40398
40399 int qdio_setup_perf_stats(void);
40400diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
40401index 1ddcf40..a85f062 100644
40402--- a/drivers/scsi/BusLogic.c
40403+++ b/drivers/scsi/BusLogic.c
40404@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
40405 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
40406 *PrototypeHostAdapter)
40407 {
40408+ pax_track_stack();
40409+
40410 /*
40411 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
40412 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
40413diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
40414index cdbdec9..b7d560b 100644
40415--- a/drivers/scsi/aacraid/aacraid.h
40416+++ b/drivers/scsi/aacraid/aacraid.h
40417@@ -471,7 +471,7 @@ struct adapter_ops
40418 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
40419 /* Administrative operations */
40420 int (*adapter_comm)(struct aac_dev * dev, int comm);
40421-};
40422+} __no_const;
40423
40424 /*
40425 * Define which interrupt handler needs to be installed
40426diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
40427index a5b8e7b..a6a0e43 100644
40428--- a/drivers/scsi/aacraid/commctrl.c
40429+++ b/drivers/scsi/aacraid/commctrl.c
40430@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
40431 u32 actual_fibsize64, actual_fibsize = 0;
40432 int i;
40433
40434+ pax_track_stack();
40435
40436 if (dev->in_reset) {
40437 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
40438diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
40439index 9b97c3e..f099725 100644
40440--- a/drivers/scsi/aacraid/linit.c
40441+++ b/drivers/scsi/aacraid/linit.c
40442@@ -91,7 +91,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
40443 #elif defined(__devinitconst)
40444 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40445 #else
40446-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
40447+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40448 #endif
40449 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
40450 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
40451diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
40452index 996f722..9127845 100644
40453--- a/drivers/scsi/aic94xx/aic94xx_init.c
40454+++ b/drivers/scsi/aic94xx/aic94xx_init.c
40455@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(struct device *dev,
40456 flash_error_table[i].reason);
40457 }
40458
40459-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
40460+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
40461 asd_show_update_bios, asd_store_update_bios);
40462
40463 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
40464@@ -1011,7 +1011,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
40465 .lldd_control_phy = asd_control_phy,
40466 };
40467
40468-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
40469+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
40470 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
40471 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
40472 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
40473diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40474index 58efd4b..cb48dc7 100644
40475--- a/drivers/scsi/bfa/bfa_ioc.h
40476+++ b/drivers/scsi/bfa/bfa_ioc.h
40477@@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
40478 bfa_ioc_disable_cbfn_t disable_cbfn;
40479 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40480 bfa_ioc_reset_cbfn_t reset_cbfn;
40481-};
40482+} __no_const;
40483
40484 /**
40485 * Heartbeat failure notification queue element.
40486diff --git a/drivers/scsi/bfa/bfa_iocfc.h b/drivers/scsi/bfa/bfa_iocfc.h
40487index 7ad177e..5503586 100644
40488--- a/drivers/scsi/bfa/bfa_iocfc.h
40489+++ b/drivers/scsi/bfa/bfa_iocfc.h
40490@@ -61,7 +61,7 @@ struct bfa_hwif_s {
40491 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
40492 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
40493 u32 *nvecs, u32 *maxvec);
40494-};
40495+} __no_const;
40496 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
40497
40498 struct bfa_iocfc_s {
40499diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
40500index 4967643..cbec06b 100644
40501--- a/drivers/scsi/dpt_i2o.c
40502+++ b/drivers/scsi/dpt_i2o.c
40503@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
40504 dma_addr_t addr;
40505 ulong flags = 0;
40506
40507+ pax_track_stack();
40508+
40509 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
40510 // get user msg size in u32s
40511 if(get_user(size, &user_msg[0])){
40512@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
40513 s32 rcode;
40514 dma_addr_t addr;
40515
40516+ pax_track_stack();
40517+
40518 memset(msg, 0 , sizeof(msg));
40519 len = scsi_bufflen(cmd);
40520 direction = 0x00000000;
40521diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
40522index c7076ce..e20c67c 100644
40523--- a/drivers/scsi/eata.c
40524+++ b/drivers/scsi/eata.c
40525@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
40526 struct hostdata *ha;
40527 char name[16];
40528
40529+ pax_track_stack();
40530+
40531 sprintf(name, "%s%d", driver_name, j);
40532
40533 if (!request_region(port_base, REGION_SIZE, driver_name)) {
40534diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
40535index 11ae5c9..891daec 100644
40536--- a/drivers/scsi/fcoe/libfcoe.c
40537+++ b/drivers/scsi/fcoe/libfcoe.c
40538@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
40539 size_t rlen;
40540 size_t dlen;
40541
40542+ pax_track_stack();
40543+
40544 fiph = (struct fip_header *)skb->data;
40545 sub = fiph->fip_subcode;
40546 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
40547diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
40548index 71c7bbe..e93088a 100644
40549--- a/drivers/scsi/fnic/fnic_main.c
40550+++ b/drivers/scsi/fnic/fnic_main.c
40551@@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
40552 /* Start local port initiatialization */
40553
40554 lp->link_up = 0;
40555- lp->tt = fnic_transport_template;
40556+ memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
40557
40558 lp->max_retry_count = fnic->config.flogi_retries;
40559 lp->max_rport_retry_count = fnic->config.plogi_retries;
40560diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
40561index bb96d74..9ec3ce4 100644
40562--- a/drivers/scsi/gdth.c
40563+++ b/drivers/scsi/gdth.c
40564@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
40565 ulong flags;
40566 gdth_ha_str *ha;
40567
40568+ pax_track_stack();
40569+
40570 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
40571 return -EFAULT;
40572 ha = gdth_find_ha(ldrv.ionode);
40573@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
40574 gdth_ha_str *ha;
40575 int rval;
40576
40577+ pax_track_stack();
40578+
40579 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
40580 res.number >= MAX_HDRIVES)
40581 return -EFAULT;
40582@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg, char *cmnd)
40583 gdth_ha_str *ha;
40584 int rval;
40585
40586+ pax_track_stack();
40587+
40588 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
40589 return -EFAULT;
40590 ha = gdth_find_ha(gen.ionode);
40591@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
40592 int i;
40593 gdth_cmd_str gdtcmd;
40594 char cmnd[MAX_COMMAND_SIZE];
40595+
40596+ pax_track_stack();
40597+
40598 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
40599
40600 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
40601diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
40602index 1258da3..20d8ae6 100644
40603--- a/drivers/scsi/gdth_proc.c
40604+++ b/drivers/scsi/gdth_proc.c
40605@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
40606 ulong64 paddr;
40607
40608 char cmnd[MAX_COMMAND_SIZE];
40609+
40610+ pax_track_stack();
40611+
40612 memset(cmnd, 0xff, 12);
40613 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
40614
40615@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
40616 gdth_hget_str *phg;
40617 char cmnd[MAX_COMMAND_SIZE];
40618
40619+ pax_track_stack();
40620+
40621 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
40622 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
40623 if (!gdtcmd || !estr)
40624diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40625index d03a926..f324286 100644
40626--- a/drivers/scsi/hosts.c
40627+++ b/drivers/scsi/hosts.c
40628@@ -40,7 +40,7 @@
40629 #include "scsi_logging.h"
40630
40631
40632-static atomic_t scsi_host_next_hn; /* host_no for next new host */
40633+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
40634
40635
40636 static void scsi_host_cls_release(struct device *dev)
40637@@ -347,7 +347,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40638 * subtract one because we increment first then return, but we need to
40639 * know what the next host number was before increment
40640 */
40641- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40642+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40643 shost->dma_channel = 0xff;
40644
40645 /* These three are default values which can be overridden */
40646diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
40647index a601159..55e19d2 100644
40648--- a/drivers/scsi/ipr.c
40649+++ b/drivers/scsi/ipr.c
40650@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
40651 return true;
40652 }
40653
40654-static struct ata_port_operations ipr_sata_ops = {
40655+static const struct ata_port_operations ipr_sata_ops = {
40656 .phy_reset = ipr_ata_phy_reset,
40657 .hardreset = ipr_sata_reset,
40658 .post_internal_cmd = ipr_ata_post_internal,
40659diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
40660index 4e49fbc..97907ff 100644
40661--- a/drivers/scsi/ips.h
40662+++ b/drivers/scsi/ips.h
40663@@ -1027,7 +1027,7 @@ typedef struct {
40664 int (*intr)(struct ips_ha *);
40665 void (*enableint)(struct ips_ha *);
40666 uint32_t (*statupd)(struct ips_ha *);
40667-} ips_hw_func_t;
40668+} __no_const ips_hw_func_t;
40669
40670 typedef struct ips_ha {
40671 uint8_t ha_id[IPS_MAX_CHANNELS+1];
40672diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40673index c1c1574..a9c9348 100644
40674--- a/drivers/scsi/libfc/fc_exch.c
40675+++ b/drivers/scsi/libfc/fc_exch.c
40676@@ -86,12 +86,12 @@ struct fc_exch_mgr {
40677 * all together if not used XXX
40678 */
40679 struct {
40680- atomic_t no_free_exch;
40681- atomic_t no_free_exch_xid;
40682- atomic_t xid_not_found;
40683- atomic_t xid_busy;
40684- atomic_t seq_not_found;
40685- atomic_t non_bls_resp;
40686+ atomic_unchecked_t no_free_exch;
40687+ atomic_unchecked_t no_free_exch_xid;
40688+ atomic_unchecked_t xid_not_found;
40689+ atomic_unchecked_t xid_busy;
40690+ atomic_unchecked_t seq_not_found;
40691+ atomic_unchecked_t non_bls_resp;
40692 } stats;
40693 };
40694 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
40695@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40696 /* allocate memory for exchange */
40697 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40698 if (!ep) {
40699- atomic_inc(&mp->stats.no_free_exch);
40700+ atomic_inc_unchecked(&mp->stats.no_free_exch);
40701 goto out;
40702 }
40703 memset(ep, 0, sizeof(*ep));
40704@@ -557,7 +557,7 @@ out:
40705 return ep;
40706 err:
40707 spin_unlock_bh(&pool->lock);
40708- atomic_inc(&mp->stats.no_free_exch_xid);
40709+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40710 mempool_free(ep, mp->ep_pool);
40711 return NULL;
40712 }
40713@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40714 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40715 ep = fc_exch_find(mp, xid);
40716 if (!ep) {
40717- atomic_inc(&mp->stats.xid_not_found);
40718+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40719 reject = FC_RJT_OX_ID;
40720 goto out;
40721 }
40722@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40723 ep = fc_exch_find(mp, xid);
40724 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40725 if (ep) {
40726- atomic_inc(&mp->stats.xid_busy);
40727+ atomic_inc_unchecked(&mp->stats.xid_busy);
40728 reject = FC_RJT_RX_ID;
40729 goto rel;
40730 }
40731@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40732 }
40733 xid = ep->xid; /* get our XID */
40734 } else if (!ep) {
40735- atomic_inc(&mp->stats.xid_not_found);
40736+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40737 reject = FC_RJT_RX_ID; /* XID not found */
40738 goto out;
40739 }
40740@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40741 } else {
40742 sp = &ep->seq;
40743 if (sp->id != fh->fh_seq_id) {
40744- atomic_inc(&mp->stats.seq_not_found);
40745+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40746 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
40747 goto rel;
40748 }
40749@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40750
40751 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40752 if (!ep) {
40753- atomic_inc(&mp->stats.xid_not_found);
40754+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40755 goto out;
40756 }
40757 if (ep->esb_stat & ESB_ST_COMPLETE) {
40758- atomic_inc(&mp->stats.xid_not_found);
40759+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40760 goto out;
40761 }
40762 if (ep->rxid == FC_XID_UNKNOWN)
40763 ep->rxid = ntohs(fh->fh_rx_id);
40764 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40765- atomic_inc(&mp->stats.xid_not_found);
40766+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40767 goto rel;
40768 }
40769 if (ep->did != ntoh24(fh->fh_s_id) &&
40770 ep->did != FC_FID_FLOGI) {
40771- atomic_inc(&mp->stats.xid_not_found);
40772+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40773 goto rel;
40774 }
40775 sof = fr_sof(fp);
40776@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40777 } else {
40778 sp = &ep->seq;
40779 if (sp->id != fh->fh_seq_id) {
40780- atomic_inc(&mp->stats.seq_not_found);
40781+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40782 goto rel;
40783 }
40784 }
40785@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40786 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40787
40788 if (!sp)
40789- atomic_inc(&mp->stats.xid_not_found);
40790+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40791 else
40792- atomic_inc(&mp->stats.non_bls_resp);
40793+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
40794
40795 fc_frame_free(fp);
40796 }
40797diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40798index 0ee989f..a582241 100644
40799--- a/drivers/scsi/libsas/sas_ata.c
40800+++ b/drivers/scsi/libsas/sas_ata.c
40801@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_link *link, unsigned int sc_reg_in,
40802 }
40803 }
40804
40805-static struct ata_port_operations sas_sata_ops = {
40806+static const struct ata_port_operations sas_sata_ops = {
40807 .phy_reset = sas_ata_phy_reset,
40808 .post_internal_cmd = sas_ata_post_internal,
40809 .qc_defer = ata_std_qc_defer,
40810diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40811index aa10f79..5cc79e4 100644
40812--- a/drivers/scsi/lpfc/lpfc.h
40813+++ b/drivers/scsi/lpfc/lpfc.h
40814@@ -400,7 +400,7 @@ struct lpfc_vport {
40815 struct dentry *debug_nodelist;
40816 struct dentry *vport_debugfs_root;
40817 struct lpfc_debugfs_trc *disc_trc;
40818- atomic_t disc_trc_cnt;
40819+ atomic_unchecked_t disc_trc_cnt;
40820 #endif
40821 uint8_t stat_data_enabled;
40822 uint8_t stat_data_blocked;
40823@@ -725,8 +725,8 @@ struct lpfc_hba {
40824 struct timer_list fabric_block_timer;
40825 unsigned long bit_flags;
40826 #define FABRIC_COMANDS_BLOCKED 0
40827- atomic_t num_rsrc_err;
40828- atomic_t num_cmd_success;
40829+ atomic_unchecked_t num_rsrc_err;
40830+ atomic_unchecked_t num_cmd_success;
40831 unsigned long last_rsrc_error_time;
40832 unsigned long last_ramp_down_time;
40833 unsigned long last_ramp_up_time;
40834@@ -740,7 +740,7 @@ struct lpfc_hba {
40835 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
40836 struct dentry *debug_slow_ring_trc;
40837 struct lpfc_debugfs_trc *slow_ring_trc;
40838- atomic_t slow_ring_trc_cnt;
40839+ atomic_unchecked_t slow_ring_trc_cnt;
40840 #endif
40841
40842 /* Used for deferred freeing of ELS data buffers */
40843diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
40844index 8d0f0de..7c77a62 100644
40845--- a/drivers/scsi/lpfc/lpfc_debugfs.c
40846+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
40847@@ -124,7 +124,7 @@ struct lpfc_debug {
40848 int len;
40849 };
40850
40851-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40852+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40853 static unsigned long lpfc_debugfs_start_time = 0L;
40854
40855 /**
40856@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
40857 lpfc_debugfs_enable = 0;
40858
40859 len = 0;
40860- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
40861+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
40862 (lpfc_debugfs_max_disc_trc - 1);
40863 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
40864 dtp = vport->disc_trc + i;
40865@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
40866 lpfc_debugfs_enable = 0;
40867
40868 len = 0;
40869- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
40870+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
40871 (lpfc_debugfs_max_slow_ring_trc - 1);
40872 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
40873 dtp = phba->slow_ring_trc + i;
40874@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
40875 uint32_t *ptr;
40876 char buffer[1024];
40877
40878+ pax_track_stack();
40879+
40880 off = 0;
40881 spin_lock_irq(&phba->hbalock);
40882
40883@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
40884 !vport || !vport->disc_trc)
40885 return;
40886
40887- index = atomic_inc_return(&vport->disc_trc_cnt) &
40888+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
40889 (lpfc_debugfs_max_disc_trc - 1);
40890 dtp = vport->disc_trc + index;
40891 dtp->fmt = fmt;
40892 dtp->data1 = data1;
40893 dtp->data2 = data2;
40894 dtp->data3 = data3;
40895- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40896+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40897 dtp->jif = jiffies;
40898 #endif
40899 return;
40900@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
40901 !phba || !phba->slow_ring_trc)
40902 return;
40903
40904- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
40905+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
40906 (lpfc_debugfs_max_slow_ring_trc - 1);
40907 dtp = phba->slow_ring_trc + index;
40908 dtp->fmt = fmt;
40909 dtp->data1 = data1;
40910 dtp->data2 = data2;
40911 dtp->data3 = data3;
40912- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40913+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40914 dtp->jif = jiffies;
40915 #endif
40916 return;
40917@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40918 "slow_ring buffer\n");
40919 goto debug_failed;
40920 }
40921- atomic_set(&phba->slow_ring_trc_cnt, 0);
40922+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
40923 memset(phba->slow_ring_trc, 0,
40924 (sizeof(struct lpfc_debugfs_trc) *
40925 lpfc_debugfs_max_slow_ring_trc));
40926@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40927 "buffer\n");
40928 goto debug_failed;
40929 }
40930- atomic_set(&vport->disc_trc_cnt, 0);
40931+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
40932
40933 snprintf(name, sizeof(name), "discovery_trace");
40934 vport->debug_disc_trc =
40935diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
40936index 549bc7d..8189dbb 100644
40937--- a/drivers/scsi/lpfc/lpfc_init.c
40938+++ b/drivers/scsi/lpfc/lpfc_init.c
40939@@ -8021,8 +8021,10 @@ lpfc_init(void)
40940 printk(LPFC_COPYRIGHT "\n");
40941
40942 if (lpfc_enable_npiv) {
40943- lpfc_transport_functions.vport_create = lpfc_vport_create;
40944- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
40945+ pax_open_kernel();
40946+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
40947+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
40948+ pax_close_kernel();
40949 }
40950 lpfc_transport_template =
40951 fc_attach_transport(&lpfc_transport_functions);
40952diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
40953index c88f59f..ff2a42f 100644
40954--- a/drivers/scsi/lpfc/lpfc_scsi.c
40955+++ b/drivers/scsi/lpfc/lpfc_scsi.c
40956@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
40957 uint32_t evt_posted;
40958
40959 spin_lock_irqsave(&phba->hbalock, flags);
40960- atomic_inc(&phba->num_rsrc_err);
40961+ atomic_inc_unchecked(&phba->num_rsrc_err);
40962 phba->last_rsrc_error_time = jiffies;
40963
40964 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
40965@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
40966 unsigned long flags;
40967 struct lpfc_hba *phba = vport->phba;
40968 uint32_t evt_posted;
40969- atomic_inc(&phba->num_cmd_success);
40970+ atomic_inc_unchecked(&phba->num_cmd_success);
40971
40972 if (vport->cfg_lun_queue_depth <= queue_depth)
40973 return;
40974@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
40975 int i;
40976 struct lpfc_rport_data *rdata;
40977
40978- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
40979- num_cmd_success = atomic_read(&phba->num_cmd_success);
40980+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
40981+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
40982
40983 vports = lpfc_create_vport_work_array(phba);
40984 if (vports != NULL)
40985@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
40986 }
40987 }
40988 lpfc_destroy_vport_work_array(phba, vports);
40989- atomic_set(&phba->num_rsrc_err, 0);
40990- atomic_set(&phba->num_cmd_success, 0);
40991+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
40992+ atomic_set_unchecked(&phba->num_cmd_success, 0);
40993 }
40994
40995 /**
40996@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
40997 }
40998 }
40999 lpfc_destroy_vport_work_array(phba, vports);
41000- atomic_set(&phba->num_rsrc_err, 0);
41001- atomic_set(&phba->num_cmd_success, 0);
41002+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41003+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41004 }
41005
41006 /**
41007diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
41008index 234f0b7..3020aea 100644
41009--- a/drivers/scsi/megaraid/megaraid_mbox.c
41010+++ b/drivers/scsi/megaraid/megaraid_mbox.c
41011@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
41012 int rval;
41013 int i;
41014
41015+ pax_track_stack();
41016+
41017 // Allocate memory for the base list of scb for management module.
41018 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
41019
41020diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
41021index 7a117c1..ee01e9e 100644
41022--- a/drivers/scsi/osd/osd_initiator.c
41023+++ b/drivers/scsi/osd/osd_initiator.c
41024@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
41025 int nelem = ARRAY_SIZE(get_attrs), a = 0;
41026 int ret;
41027
41028+ pax_track_stack();
41029+
41030 or = osd_start_request(od, GFP_KERNEL);
41031 if (!or)
41032 return -ENOMEM;
41033diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41034index 9ab8c86..9425ad3 100644
41035--- a/drivers/scsi/pmcraid.c
41036+++ b/drivers/scsi/pmcraid.c
41037@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41038 res->scsi_dev = scsi_dev;
41039 scsi_dev->hostdata = res;
41040 res->change_detected = 0;
41041- atomic_set(&res->read_failures, 0);
41042- atomic_set(&res->write_failures, 0);
41043+ atomic_set_unchecked(&res->read_failures, 0);
41044+ atomic_set_unchecked(&res->write_failures, 0);
41045 rc = 0;
41046 }
41047 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41048@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41049
41050 /* If this was a SCSI read/write command keep count of errors */
41051 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41052- atomic_inc(&res->read_failures);
41053+ atomic_inc_unchecked(&res->read_failures);
41054 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41055- atomic_inc(&res->write_failures);
41056+ atomic_inc_unchecked(&res->write_failures);
41057
41058 if (!RES_IS_GSCSI(res->cfg_entry) &&
41059 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41060@@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41061
41062 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41063 /* add resources only after host is added into system */
41064- if (!atomic_read(&pinstance->expose_resources))
41065+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41066 return;
41067
41068 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
41069@@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instance(
41070 init_waitqueue_head(&pinstance->reset_wait_q);
41071
41072 atomic_set(&pinstance->outstanding_cmds, 0);
41073- atomic_set(&pinstance->expose_resources, 0);
41074+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41075
41076 INIT_LIST_HEAD(&pinstance->free_res_q);
41077 INIT_LIST_HEAD(&pinstance->used_res_q);
41078@@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
41079 /* Schedule worker thread to handle CCN and take care of adding and
41080 * removing devices to OS
41081 */
41082- atomic_set(&pinstance->expose_resources, 1);
41083+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41084 schedule_work(&pinstance->worker_q);
41085 return rc;
41086
41087diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41088index 3441b3f..6cbe8f7 100644
41089--- a/drivers/scsi/pmcraid.h
41090+++ b/drivers/scsi/pmcraid.h
41091@@ -690,7 +690,7 @@ struct pmcraid_instance {
41092 atomic_t outstanding_cmds;
41093
41094 /* should add/delete resources to mid-layer now ?*/
41095- atomic_t expose_resources;
41096+ atomic_unchecked_t expose_resources;
41097
41098 /* Tasklet to handle deferred processing */
41099 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
41100@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
41101 struct list_head queue; /* link to "to be exposed" resources */
41102 struct pmcraid_config_table_entry cfg_entry;
41103 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41104- atomic_t read_failures; /* count of failed READ commands */
41105- atomic_t write_failures; /* count of failed WRITE commands */
41106+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41107+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41108
41109 /* To indicate add/delete/modify during CCN */
41110 u8 change_detected;
41111diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
41112index 2150618..7034215 100644
41113--- a/drivers/scsi/qla2xxx/qla_def.h
41114+++ b/drivers/scsi/qla2xxx/qla_def.h
41115@@ -2089,7 +2089,7 @@ struct isp_operations {
41116
41117 int (*get_flash_version) (struct scsi_qla_host *, void *);
41118 int (*start_scsi) (srb_t *);
41119-};
41120+} __no_const;
41121
41122 /* MSI-X Support *************************************************************/
41123
41124diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41125index 81b5f29..2ae1fad 100644
41126--- a/drivers/scsi/qla4xxx/ql4_def.h
41127+++ b/drivers/scsi/qla4xxx/ql4_def.h
41128@@ -240,7 +240,7 @@ struct ddb_entry {
41129 atomic_t retry_relogin_timer; /* Min Time between relogins
41130 * (4000 only) */
41131 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
41132- atomic_t relogin_retry_count; /* Num of times relogin has been
41133+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41134 * retried */
41135
41136 uint16_t port;
41137diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
41138index af8c323..515dd51 100644
41139--- a/drivers/scsi/qla4xxx/ql4_init.c
41140+++ b/drivers/scsi/qla4xxx/ql4_init.c
41141@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
41142 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
41143 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41144 atomic_set(&ddb_entry->relogin_timer, 0);
41145- atomic_set(&ddb_entry->relogin_retry_count, 0);
41146+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41147 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41148 list_add_tail(&ddb_entry->list, &ha->ddb_list);
41149 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
41150@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
41151 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41152 atomic_set(&ddb_entry->port_down_timer,
41153 ha->port_down_retry_count);
41154- atomic_set(&ddb_entry->relogin_retry_count, 0);
41155+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41156 atomic_set(&ddb_entry->relogin_timer, 0);
41157 clear_bit(DF_RELOGIN, &ddb_entry->flags);
41158 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
41159diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41160index 83c8b5e..a82b348 100644
41161--- a/drivers/scsi/qla4xxx/ql4_os.c
41162+++ b/drivers/scsi/qla4xxx/ql4_os.c
41163@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
41164 ddb_entry->fw_ddb_device_state ==
41165 DDB_DS_SESSION_FAILED) {
41166 /* Reset retry relogin timer */
41167- atomic_inc(&ddb_entry->relogin_retry_count);
41168+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41169 DEBUG2(printk("scsi%ld: index[%d] relogin"
41170 " timed out-retrying"
41171 " relogin (%d)\n",
41172 ha->host_no,
41173 ddb_entry->fw_ddb_index,
41174- atomic_read(&ddb_entry->
41175+ atomic_read_unchecked(&ddb_entry->
41176 relogin_retry_count))
41177 );
41178 start_dpc++;
41179diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41180index dd098ca..686ce01 100644
41181--- a/drivers/scsi/scsi.c
41182+++ b/drivers/scsi/scsi.c
41183@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41184 unsigned long timeout;
41185 int rtn = 0;
41186
41187- atomic_inc(&cmd->device->iorequest_cnt);
41188+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41189
41190 /* check if the device is still usable */
41191 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41192diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
41193index bc3e363..e1a8e50 100644
41194--- a/drivers/scsi/scsi_debug.c
41195+++ b/drivers/scsi/scsi_debug.c
41196@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
41197 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
41198 unsigned char *cmd = (unsigned char *)scp->cmnd;
41199
41200+ pax_track_stack();
41201+
41202 if ((errsts = check_readiness(scp, 1, devip)))
41203 return errsts;
41204 memset(arr, 0, sizeof(arr));
41205@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
41206 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
41207 unsigned char *cmd = (unsigned char *)scp->cmnd;
41208
41209+ pax_track_stack();
41210+
41211 if ((errsts = check_readiness(scp, 1, devip)))
41212 return errsts;
41213 memset(arr, 0, sizeof(arr));
41214diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41215index 8df12522..c4c1472 100644
41216--- a/drivers/scsi/scsi_lib.c
41217+++ b/drivers/scsi/scsi_lib.c
41218@@ -1389,7 +1389,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41219 shost = sdev->host;
41220 scsi_init_cmd_errh(cmd);
41221 cmd->result = DID_NO_CONNECT << 16;
41222- atomic_inc(&cmd->device->iorequest_cnt);
41223+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41224
41225 /*
41226 * SCSI request completion path will do scsi_device_unbusy(),
41227@@ -1420,9 +1420,9 @@ static void scsi_softirq_done(struct request *rq)
41228 */
41229 cmd->serial_number = 0;
41230
41231- atomic_inc(&cmd->device->iodone_cnt);
41232+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41233 if (cmd->result)
41234- atomic_inc(&cmd->device->ioerr_cnt);
41235+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41236
41237 disposition = scsi_decide_disposition(cmd);
41238 if (disposition != SUCCESS &&
41239diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41240index 91a93e0..eae0fe3 100644
41241--- a/drivers/scsi/scsi_sysfs.c
41242+++ b/drivers/scsi/scsi_sysfs.c
41243@@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41244 char *buf) \
41245 { \
41246 struct scsi_device *sdev = to_scsi_device(dev); \
41247- unsigned long long count = atomic_read(&sdev->field); \
41248+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41249 return snprintf(buf, 20, "0x%llx\n", count); \
41250 } \
41251 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41252diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41253index 1030327..f91fd30 100644
41254--- a/drivers/scsi/scsi_tgt_lib.c
41255+++ b/drivers/scsi/scsi_tgt_lib.c
41256@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41257 int err;
41258
41259 dprintk("%lx %u\n", uaddr, len);
41260- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41261+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41262 if (err) {
41263 /*
41264 * TODO: need to fixup sg_tablesize, max_segment_size,
41265diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41266index db02e31..1b42ea9 100644
41267--- a/drivers/scsi/scsi_transport_fc.c
41268+++ b/drivers/scsi/scsi_transport_fc.c
41269@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
41270 * Netlink Infrastructure
41271 */
41272
41273-static atomic_t fc_event_seq;
41274+static atomic_unchecked_t fc_event_seq;
41275
41276 /**
41277 * fc_get_event_number - Obtain the next sequential FC event number
41278@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
41279 u32
41280 fc_get_event_number(void)
41281 {
41282- return atomic_add_return(1, &fc_event_seq);
41283+ return atomic_add_return_unchecked(1, &fc_event_seq);
41284 }
41285 EXPORT_SYMBOL(fc_get_event_number);
41286
41287@@ -641,7 +641,7 @@ static __init int fc_transport_init(void)
41288 {
41289 int error;
41290
41291- atomic_set(&fc_event_seq, 0);
41292+ atomic_set_unchecked(&fc_event_seq, 0);
41293
41294 error = transport_class_register(&fc_host_class);
41295 if (error)
41296diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41297index de2f8c4..63c5278 100644
41298--- a/drivers/scsi/scsi_transport_iscsi.c
41299+++ b/drivers/scsi/scsi_transport_iscsi.c
41300@@ -81,7 +81,7 @@ struct iscsi_internal {
41301 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
41302 };
41303
41304-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41305+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41306 static struct workqueue_struct *iscsi_eh_timer_workq;
41307
41308 /*
41309@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41310 int err;
41311
41312 ihost = shost->shost_data;
41313- session->sid = atomic_add_return(1, &iscsi_session_nr);
41314+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41315
41316 if (id == ISCSI_MAX_TARGET) {
41317 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
41318@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(void)
41319 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41320 ISCSI_TRANSPORT_VERSION);
41321
41322- atomic_set(&iscsi_session_nr, 0);
41323+ atomic_set_unchecked(&iscsi_session_nr, 0);
41324
41325 err = class_register(&iscsi_transport_class);
41326 if (err)
41327diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41328index 21a045e..ec89e03 100644
41329--- a/drivers/scsi/scsi_transport_srp.c
41330+++ b/drivers/scsi/scsi_transport_srp.c
41331@@ -33,7 +33,7 @@
41332 #include "scsi_transport_srp_internal.h"
41333
41334 struct srp_host_attrs {
41335- atomic_t next_port_id;
41336+ atomic_unchecked_t next_port_id;
41337 };
41338 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41339
41340@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41341 struct Scsi_Host *shost = dev_to_shost(dev);
41342 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41343
41344- atomic_set(&srp_host->next_port_id, 0);
41345+ atomic_set_unchecked(&srp_host->next_port_id, 0);
41346 return 0;
41347 }
41348
41349@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41350 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41351 rport->roles = ids->roles;
41352
41353- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41354+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41355 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41356
41357 transport_setup_device(&rport->dev);
41358diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41359index 040f751..98a5ed2 100644
41360--- a/drivers/scsi/sg.c
41361+++ b/drivers/scsi/sg.c
41362@@ -1064,7 +1064,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
41363 sdp->disk->disk_name,
41364 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41365 NULL,
41366- (char *)arg);
41367+ (char __user *)arg);
41368 case BLKTRACESTART:
41369 return blk_trace_startstop(sdp->device->request_queue, 1);
41370 case BLKTRACESTOP:
41371@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
41372 const struct file_operations * fops;
41373 };
41374
41375-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
41376+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
41377 {"allow_dio", &adio_fops},
41378 {"debug", &debug_fops},
41379 {"def_reserved_size", &dressz_fops},
41380@@ -2307,7 +2307,7 @@ sg_proc_init(void)
41381 {
41382 int k, mask;
41383 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
41384- struct sg_proc_leaf * leaf;
41385+ const struct sg_proc_leaf * leaf;
41386
41387 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
41388 if (!sg_proc_sgp)
41389diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
41390index 45374d6..61ee484 100644
41391--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
41392+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
41393@@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
41394 int do_iounmap = 0;
41395 int do_disable_device = 1;
41396
41397+ pax_track_stack();
41398+
41399 memset(&sym_dev, 0, sizeof(sym_dev));
41400 memset(&nvram, 0, sizeof(nvram));
41401 sym_dev.pdev = pdev;
41402diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
41403index eadc1ab..2d81457 100644
41404--- a/drivers/serial/kgdboc.c
41405+++ b/drivers/serial/kgdboc.c
41406@@ -18,7 +18,7 @@
41407
41408 #define MAX_CONFIG_LEN 40
41409
41410-static struct kgdb_io kgdboc_io_ops;
41411+static const struct kgdb_io kgdboc_io_ops;
41412
41413 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41414 static int configured = -1;
41415@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void)
41416 module_put(THIS_MODULE);
41417 }
41418
41419-static struct kgdb_io kgdboc_io_ops = {
41420+static const struct kgdb_io kgdboc_io_ops = {
41421 .name = "kgdboc",
41422 .read_char = kgdboc_get_char,
41423 .write_char = kgdboc_put_char,
41424diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41425index b76f246..7f41af7 100644
41426--- a/drivers/spi/spi.c
41427+++ b/drivers/spi/spi.c
41428@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
41429 EXPORT_SYMBOL_GPL(spi_sync);
41430
41431 /* portable code must never pass more than 32 bytes */
41432-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41433+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
41434
41435 static u8 *buf;
41436
41437diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
41438index 99010d4..6bad87b 100644
41439--- a/drivers/staging/android/binder.c
41440+++ b/drivers/staging/android/binder.c
41441@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_area_struct *vma)
41442 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
41443 }
41444
41445-static struct vm_operations_struct binder_vm_ops = {
41446+static const struct vm_operations_struct binder_vm_ops = {
41447 .open = binder_vma_open,
41448 .close = binder_vma_close,
41449 };
41450diff --git a/drivers/staging/b3dfg/b3dfg.c b/drivers/staging/b3dfg/b3dfg.c
41451index cda26bb..39fed3f 100644
41452--- a/drivers/staging/b3dfg/b3dfg.c
41453+++ b/drivers/staging/b3dfg/b3dfg.c
41454@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_area_struct *vma,
41455 return VM_FAULT_NOPAGE;
41456 }
41457
41458-static struct vm_operations_struct b3dfg_vm_ops = {
41459+static const struct vm_operations_struct b3dfg_vm_ops = {
41460 .fault = b3dfg_vma_fault,
41461 };
41462
41463@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp, struct vm_area_struct *vma)
41464 return r;
41465 }
41466
41467-static struct file_operations b3dfg_fops = {
41468+static const struct file_operations b3dfg_fops = {
41469 .owner = THIS_MODULE,
41470 .open = b3dfg_open,
41471 .release = b3dfg_release,
41472diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
41473index 908f25a..c9a579b 100644
41474--- a/drivers/staging/comedi/comedi_fops.c
41475+++ b/drivers/staging/comedi/comedi_fops.c
41476@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct *area)
41477 mutex_unlock(&dev->mutex);
41478 }
41479
41480-static struct vm_operations_struct comedi_vm_ops = {
41481+static const struct vm_operations_struct comedi_vm_ops = {
41482 .close = comedi_unmap,
41483 };
41484
41485diff --git a/drivers/staging/dream/qdsp5/adsp_driver.c b/drivers/staging/dream/qdsp5/adsp_driver.c
41486index e55a0db..577b776 100644
41487--- a/drivers/staging/dream/qdsp5/adsp_driver.c
41488+++ b/drivers/staging/dream/qdsp5/adsp_driver.c
41489@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_device(struct inode *inode)
41490 static dev_t adsp_devno;
41491 static struct class *adsp_class;
41492
41493-static struct file_operations adsp_fops = {
41494+static const struct file_operations adsp_fops = {
41495 .owner = THIS_MODULE,
41496 .open = adsp_open,
41497 .unlocked_ioctl = adsp_ioctl,
41498diff --git a/drivers/staging/dream/qdsp5/audio_aac.c b/drivers/staging/dream/qdsp5/audio_aac.c
41499index ad2390f..4116ee8 100644
41500--- a/drivers/staging/dream/qdsp5/audio_aac.c
41501+++ b/drivers/staging/dream/qdsp5/audio_aac.c
41502@@ -1022,7 +1022,7 @@ done:
41503 return rc;
41504 }
41505
41506-static struct file_operations audio_aac_fops = {
41507+static const struct file_operations audio_aac_fops = {
41508 .owner = THIS_MODULE,
41509 .open = audio_open,
41510 .release = audio_release,
41511diff --git a/drivers/staging/dream/qdsp5/audio_amrnb.c b/drivers/staging/dream/qdsp5/audio_amrnb.c
41512index cd818a5..870b37b 100644
41513--- a/drivers/staging/dream/qdsp5/audio_amrnb.c
41514+++ b/drivers/staging/dream/qdsp5/audio_amrnb.c
41515@@ -833,7 +833,7 @@ done:
41516 return rc;
41517 }
41518
41519-static struct file_operations audio_amrnb_fops = {
41520+static const struct file_operations audio_amrnb_fops = {
41521 .owner = THIS_MODULE,
41522 .open = audamrnb_open,
41523 .release = audamrnb_release,
41524diff --git a/drivers/staging/dream/qdsp5/audio_evrc.c b/drivers/staging/dream/qdsp5/audio_evrc.c
41525index 4b43e18..cedafda 100644
41526--- a/drivers/staging/dream/qdsp5/audio_evrc.c
41527+++ b/drivers/staging/dream/qdsp5/audio_evrc.c
41528@@ -805,7 +805,7 @@ dma_fail:
41529 return rc;
41530 }
41531
41532-static struct file_operations audio_evrc_fops = {
41533+static const struct file_operations audio_evrc_fops = {
41534 .owner = THIS_MODULE,
41535 .open = audevrc_open,
41536 .release = audevrc_release,
41537diff --git a/drivers/staging/dream/qdsp5/audio_in.c b/drivers/staging/dream/qdsp5/audio_in.c
41538index 3d950a2..9431118 100644
41539--- a/drivers/staging/dream/qdsp5/audio_in.c
41540+++ b/drivers/staging/dream/qdsp5/audio_in.c
41541@@ -913,7 +913,7 @@ static int audpre_open(struct inode *inode, struct file *file)
41542 return 0;
41543 }
41544
41545-static struct file_operations audio_fops = {
41546+static const struct file_operations audio_fops = {
41547 .owner = THIS_MODULE,
41548 .open = audio_in_open,
41549 .release = audio_in_release,
41550@@ -922,7 +922,7 @@ static struct file_operations audio_fops = {
41551 .unlocked_ioctl = audio_in_ioctl,
41552 };
41553
41554-static struct file_operations audpre_fops = {
41555+static const struct file_operations audpre_fops = {
41556 .owner = THIS_MODULE,
41557 .open = audpre_open,
41558 .unlocked_ioctl = audpre_ioctl,
41559diff --git a/drivers/staging/dream/qdsp5/audio_mp3.c b/drivers/staging/dream/qdsp5/audio_mp3.c
41560index b95574f..286c2f4 100644
41561--- a/drivers/staging/dream/qdsp5/audio_mp3.c
41562+++ b/drivers/staging/dream/qdsp5/audio_mp3.c
41563@@ -941,7 +941,7 @@ done:
41564 return rc;
41565 }
41566
41567-static struct file_operations audio_mp3_fops = {
41568+static const struct file_operations audio_mp3_fops = {
41569 .owner = THIS_MODULE,
41570 .open = audio_open,
41571 .release = audio_release,
41572diff --git a/drivers/staging/dream/qdsp5/audio_out.c b/drivers/staging/dream/qdsp5/audio_out.c
41573index d1adcf6..f8f9833 100644
41574--- a/drivers/staging/dream/qdsp5/audio_out.c
41575+++ b/drivers/staging/dream/qdsp5/audio_out.c
41576@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inode, struct file *file)
41577 return 0;
41578 }
41579
41580-static struct file_operations audio_fops = {
41581+static const struct file_operations audio_fops = {
41582 .owner = THIS_MODULE,
41583 .open = audio_open,
41584 .release = audio_release,
41585@@ -819,7 +819,7 @@ static struct file_operations audio_fops = {
41586 .unlocked_ioctl = audio_ioctl,
41587 };
41588
41589-static struct file_operations audpp_fops = {
41590+static const struct file_operations audpp_fops = {
41591 .owner = THIS_MODULE,
41592 .open = audpp_open,
41593 .unlocked_ioctl = audpp_ioctl,
41594diff --git a/drivers/staging/dream/qdsp5/audio_qcelp.c b/drivers/staging/dream/qdsp5/audio_qcelp.c
41595index f0f50e3..f6b9dbc 100644
41596--- a/drivers/staging/dream/qdsp5/audio_qcelp.c
41597+++ b/drivers/staging/dream/qdsp5/audio_qcelp.c
41598@@ -816,7 +816,7 @@ err:
41599 return rc;
41600 }
41601
41602-static struct file_operations audio_qcelp_fops = {
41603+static const struct file_operations audio_qcelp_fops = {
41604 .owner = THIS_MODULE,
41605 .open = audqcelp_open,
41606 .release = audqcelp_release,
41607diff --git a/drivers/staging/dream/qdsp5/snd.c b/drivers/staging/dream/qdsp5/snd.c
41608index 037d7ff..5469ec3 100644
41609--- a/drivers/staging/dream/qdsp5/snd.c
41610+++ b/drivers/staging/dream/qdsp5/snd.c
41611@@ -242,7 +242,7 @@ err:
41612 return rc;
41613 }
41614
41615-static struct file_operations snd_fops = {
41616+static const struct file_operations snd_fops = {
41617 .owner = THIS_MODULE,
41618 .open = snd_open,
41619 .release = snd_release,
41620diff --git a/drivers/staging/dream/smd/smd_qmi.c b/drivers/staging/dream/smd/smd_qmi.c
41621index d4e7d88..0ea632a 100644
41622--- a/drivers/staging/dream/smd/smd_qmi.c
41623+++ b/drivers/staging/dream/smd/smd_qmi.c
41624@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip, struct file *fp)
41625 return 0;
41626 }
41627
41628-static struct file_operations qmi_fops = {
41629+static const struct file_operations qmi_fops = {
41630 .owner = THIS_MODULE,
41631 .read = qmi_read,
41632 .write = qmi_write,
41633diff --git a/drivers/staging/dream/smd/smd_rpcrouter_device.c b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41634index cd3910b..ff053d3 100644
41635--- a/drivers/staging/dream/smd/smd_rpcrouter_device.c
41636+++ b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41637@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file *filp, unsigned int cmd,
41638 return rc;
41639 }
41640
41641-static struct file_operations rpcrouter_server_fops = {
41642+static const struct file_operations rpcrouter_server_fops = {
41643 .owner = THIS_MODULE,
41644 .open = rpcrouter_open,
41645 .release = rpcrouter_release,
41646@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_server_fops = {
41647 .unlocked_ioctl = rpcrouter_ioctl,
41648 };
41649
41650-static struct file_operations rpcrouter_router_fops = {
41651+static const struct file_operations rpcrouter_router_fops = {
41652 .owner = THIS_MODULE,
41653 .open = rpcrouter_open,
41654 .release = rpcrouter_release,
41655diff --git a/drivers/staging/dst/dcore.c b/drivers/staging/dst/dcore.c
41656index c24e4e0..07665be 100644
41657--- a/drivers/staging/dst/dcore.c
41658+++ b/drivers/staging/dst/dcore.c
41659@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendisk *disk, fmode_t mode)
41660 return 0;
41661 }
41662
41663-static struct block_device_operations dst_blk_ops = {
41664+static const struct block_device_operations dst_blk_ops = {
41665 .open = dst_bdev_open,
41666 .release = dst_bdev_release,
41667 .owner = THIS_MODULE,
41668@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(struct dst_ctl *ctl,
41669 n->size = ctl->size;
41670
41671 atomic_set(&n->refcnt, 1);
41672- atomic_long_set(&n->gen, 0);
41673+ atomic_long_set_unchecked(&n->gen, 0);
41674 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
41675
41676 err = dst_node_sysfs_init(n);
41677diff --git a/drivers/staging/dst/trans.c b/drivers/staging/dst/trans.c
41678index 557d372..8d84422 100644
41679--- a/drivers/staging/dst/trans.c
41680+++ b/drivers/staging/dst/trans.c
41681@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n, struct bio *bio)
41682 t->error = 0;
41683 t->retries = 0;
41684 atomic_set(&t->refcnt, 1);
41685- t->gen = atomic_long_inc_return(&n->gen);
41686+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
41687
41688 t->enc = bio_data_dir(bio);
41689 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
41690diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
41691index 94f7752..d051514 100644
41692--- a/drivers/staging/et131x/et1310_tx.c
41693+++ b/drivers/staging/et131x/et1310_tx.c
41694@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
41695 struct net_device_stats *stats = &etdev->net_stats;
41696
41697 if (pMpTcb->Flags & fMP_DEST_BROAD)
41698- atomic_inc(&etdev->Stats.brdcstxmt);
41699+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
41700 else if (pMpTcb->Flags & fMP_DEST_MULTI)
41701- atomic_inc(&etdev->Stats.multixmt);
41702+ atomic_inc_unchecked(&etdev->Stats.multixmt);
41703 else
41704- atomic_inc(&etdev->Stats.unixmt);
41705+ atomic_inc_unchecked(&etdev->Stats.unixmt);
41706
41707 if (pMpTcb->Packet) {
41708 stats->tx_bytes += pMpTcb->Packet->len;
41709diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
41710index 1dfe06f..f469b4d 100644
41711--- a/drivers/staging/et131x/et131x_adapter.h
41712+++ b/drivers/staging/et131x/et131x_adapter.h
41713@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
41714 * operations
41715 */
41716 u32 unircv; /* # multicast packets received */
41717- atomic_t unixmt; /* # multicast packets for Tx */
41718+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
41719 u32 multircv; /* # multicast packets received */
41720- atomic_t multixmt; /* # multicast packets for Tx */
41721+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
41722 u32 brdcstrcv; /* # broadcast packets received */
41723- atomic_t brdcstxmt; /* # broadcast packets for Tx */
41724+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
41725 u32 norcvbuf; /* # Rx packets discarded */
41726 u32 noxmtbuf; /* # Tx packets discarded */
41727
41728diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/go7007/go7007-v4l2.c
41729index 4bd353a..e28f455 100644
41730--- a/drivers/staging/go7007/go7007-v4l2.c
41731+++ b/drivers/staging/go7007/go7007-v4l2.c
41732@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41733 return 0;
41734 }
41735
41736-static struct vm_operations_struct go7007_vm_ops = {
41737+static const struct vm_operations_struct go7007_vm_ops = {
41738 .open = go7007_vm_open,
41739 .close = go7007_vm_close,
41740 .fault = go7007_vm_fault,
41741diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
41742index 366dc95..b974d87 100644
41743--- a/drivers/staging/hv/Channel.c
41744+++ b/drivers/staging/hv/Channel.c
41745@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
41746
41747 DPRINT_ENTER(VMBUS);
41748
41749- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
41750- atomic_inc(&gVmbusConnection.NextGpadlHandle);
41751+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
41752+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
41753
41754 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
41755 ASSERT(msgInfo != NULL);
41756diff --git a/drivers/staging/hv/Hv.c b/drivers/staging/hv/Hv.c
41757index b12237f..01ae28a 100644
41758--- a/drivers/staging/hv/Hv.c
41759+++ b/drivers/staging/hv/Hv.c
41760@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, void *Input, void *Output)
41761 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
41762 u32 outputAddressHi = outputAddress >> 32;
41763 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
41764- volatile void *hypercallPage = gHvContext.HypercallPage;
41765+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
41766
41767 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
41768 Control, Input, Output);
41769diff --git a/drivers/staging/hv/VmbusApi.h b/drivers/staging/hv/VmbusApi.h
41770index d089bb1..2ebc158 100644
41771--- a/drivers/staging/hv/VmbusApi.h
41772+++ b/drivers/staging/hv/VmbusApi.h
41773@@ -109,7 +109,7 @@ struct vmbus_channel_interface {
41774 u32 *GpadlHandle);
41775 int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle);
41776 void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo);
41777-};
41778+} __no_const;
41779
41780 /* Base driver object */
41781 struct hv_driver {
41782diff --git a/drivers/staging/hv/VmbusPrivate.h b/drivers/staging/hv/VmbusPrivate.h
41783index 5a37cce..6ecc88c 100644
41784--- a/drivers/staging/hv/VmbusPrivate.h
41785+++ b/drivers/staging/hv/VmbusPrivate.h
41786@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
41787 struct VMBUS_CONNECTION {
41788 enum VMBUS_CONNECT_STATE ConnectState;
41789
41790- atomic_t NextGpadlHandle;
41791+ atomic_unchecked_t NextGpadlHandle;
41792
41793 /*
41794 * Represents channel interrupts. Each bit position represents a
41795diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
41796index 871a202..ca50ddf 100644
41797--- a/drivers/staging/hv/blkvsc_drv.c
41798+++ b/drivers/staging/hv/blkvsc_drv.c
41799@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
41800 /* The one and only one */
41801 static struct blkvsc_driver_context g_blkvsc_drv;
41802
41803-static struct block_device_operations block_ops = {
41804+static const struct block_device_operations block_ops = {
41805 .owner = THIS_MODULE,
41806 .open = blkvsc_open,
41807 .release = blkvsc_release,
41808diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
41809index 6acc49a..fbc8d46 100644
41810--- a/drivers/staging/hv/vmbus_drv.c
41811+++ b/drivers/staging/hv/vmbus_drv.c
41812@@ -532,7 +532,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41813 to_device_context(root_device_obj);
41814 struct device_context *child_device_ctx =
41815 to_device_context(child_device_obj);
41816- static atomic_t device_num = ATOMIC_INIT(0);
41817+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41818
41819 DPRINT_ENTER(VMBUS_DRV);
41820
41821@@ -541,7 +541,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41822
41823 /* Set the device name. Otherwise, device_register() will fail. */
41824 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
41825- atomic_inc_return(&device_num));
41826+ atomic_inc_return_unchecked(&device_num));
41827
41828 /* The new device belongs to this bus */
41829 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
41830diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
41831index d926189..17b19fd 100644
41832--- a/drivers/staging/iio/ring_generic.h
41833+++ b/drivers/staging/iio/ring_generic.h
41834@@ -87,7 +87,7 @@ struct iio_ring_access_funcs {
41835
41836 int (*is_enabled)(struct iio_ring_buffer *ring);
41837 int (*enable)(struct iio_ring_buffer *ring);
41838-};
41839+} __no_const;
41840
41841 /**
41842 * struct iio_ring_buffer - general ring buffer structure
41843diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41844index 1b237b7..88c624e 100644
41845--- a/drivers/staging/octeon/ethernet-rx.c
41846+++ b/drivers/staging/octeon/ethernet-rx.c
41847@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41848 /* Increment RX stats for virtual ports */
41849 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41850 #ifdef CONFIG_64BIT
41851- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41852- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41853+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41854+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41855 #else
41856- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41857- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41858+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41859+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41860 #endif
41861 }
41862 netif_receive_skb(skb);
41863@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41864 dev->name);
41865 */
41866 #ifdef CONFIG_64BIT
41867- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41868+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
41869 #else
41870- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41871+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
41872 #endif
41873 dev_kfree_skb_irq(skb);
41874 }
41875diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41876index 492c502..d9909f1 100644
41877--- a/drivers/staging/octeon/ethernet.c
41878+++ b/drivers/staging/octeon/ethernet.c
41879@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41880 * since the RX tasklet also increments it.
41881 */
41882 #ifdef CONFIG_64BIT
41883- atomic64_add(rx_status.dropped_packets,
41884- (atomic64_t *)&priv->stats.rx_dropped);
41885+ atomic64_add_unchecked(rx_status.dropped_packets,
41886+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41887 #else
41888- atomic_add(rx_status.dropped_packets,
41889- (atomic_t *)&priv->stats.rx_dropped);
41890+ atomic_add_unchecked(rx_status.dropped_packets,
41891+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
41892 #endif
41893 }
41894
41895diff --git a/drivers/staging/otus/80211core/pub_zfi.h b/drivers/staging/otus/80211core/pub_zfi.h
41896index a35bd5d..28fff45 100644
41897--- a/drivers/staging/otus/80211core/pub_zfi.h
41898+++ b/drivers/staging/otus/80211core/pub_zfi.h
41899@@ -531,7 +531,7 @@ struct zsCbFuncTbl
41900 u8_t (*zfcbClassifyTxPacket)(zdev_t* dev, zbuf_t* buf);
41901
41902 void (*zfcbHwWatchDogNotify)(zdev_t* dev);
41903-};
41904+} __no_const;
41905
41906 extern void zfZeroMemory(u8_t* va, u16_t length);
41907 #define ZM_INIT_CB_FUNC_TABLE(p) zfZeroMemory((u8_t *)p, sizeof(struct zsCbFuncTbl));
41908diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
41909index c39a25f..696f5aa 100644
41910--- a/drivers/staging/panel/panel.c
41911+++ b/drivers/staging/panel/panel.c
41912@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *inode, struct file *file)
41913 return 0;
41914 }
41915
41916-static struct file_operations lcd_fops = {
41917+static const struct file_operations lcd_fops = {
41918 .write = lcd_write,
41919 .open = lcd_open,
41920 .release = lcd_release,
41921@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *inode, struct file *file)
41922 return 0;
41923 }
41924
41925-static struct file_operations keypad_fops = {
41926+static const struct file_operations keypad_fops = {
41927 .read = keypad_read, /* read */
41928 .open = keypad_open, /* open */
41929 .release = keypad_release, /* close */
41930diff --git a/drivers/staging/phison/phison.c b/drivers/staging/phison/phison.c
41931index 270ebcb..37e46af 100644
41932--- a/drivers/staging/phison/phison.c
41933+++ b/drivers/staging/phison/phison.c
41934@@ -43,7 +43,7 @@ static struct scsi_host_template phison_sht = {
41935 ATA_BMDMA_SHT(DRV_NAME),
41936 };
41937
41938-static struct ata_port_operations phison_ops = {
41939+static const struct ata_port_operations phison_ops = {
41940 .inherits = &ata_bmdma_port_ops,
41941 .prereset = phison_pre_reset,
41942 };
41943diff --git a/drivers/staging/poch/poch.c b/drivers/staging/poch/poch.c
41944index 2eb8e3d..57616a7 100644
41945--- a/drivers/staging/poch/poch.c
41946+++ b/drivers/staging/poch/poch.c
41947@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inode, struct file *filp,
41948 return 0;
41949 }
41950
41951-static struct file_operations poch_fops = {
41952+static const struct file_operations poch_fops = {
41953 .owner = THIS_MODULE,
41954 .open = poch_open,
41955 .release = poch_release,
41956diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
41957index c94de31..19402bc 100644
41958--- a/drivers/staging/pohmelfs/inode.c
41959+++ b/drivers/staging/pohmelfs/inode.c
41960@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
41961 mutex_init(&psb->mcache_lock);
41962 psb->mcache_root = RB_ROOT;
41963 psb->mcache_timeout = msecs_to_jiffies(5000);
41964- atomic_long_set(&psb->mcache_gen, 0);
41965+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
41966
41967 psb->trans_max_pages = 100;
41968
41969@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
41970 INIT_LIST_HEAD(&psb->crypto_ready_list);
41971 INIT_LIST_HEAD(&psb->crypto_active_list);
41972
41973- atomic_set(&psb->trans_gen, 1);
41974+ atomic_set_unchecked(&psb->trans_gen, 1);
41975 atomic_long_set(&psb->total_inodes, 0);
41976
41977 mutex_init(&psb->state_lock);
41978diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
41979index e22665c..a2a9390 100644
41980--- a/drivers/staging/pohmelfs/mcache.c
41981+++ b/drivers/staging/pohmelfs/mcache.c
41982@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
41983 m->data = data;
41984 m->start = start;
41985 m->size = size;
41986- m->gen = atomic_long_inc_return(&psb->mcache_gen);
41987+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
41988
41989 mutex_lock(&psb->mcache_lock);
41990 err = pohmelfs_mcache_insert(psb, m);
41991diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
41992index 623a07d..4035c19 100644
41993--- a/drivers/staging/pohmelfs/netfs.h
41994+++ b/drivers/staging/pohmelfs/netfs.h
41995@@ -570,14 +570,14 @@ struct pohmelfs_config;
41996 struct pohmelfs_sb {
41997 struct rb_root mcache_root;
41998 struct mutex mcache_lock;
41999- atomic_long_t mcache_gen;
42000+ atomic_long_unchecked_t mcache_gen;
42001 unsigned long mcache_timeout;
42002
42003 unsigned int idx;
42004
42005 unsigned int trans_retries;
42006
42007- atomic_t trans_gen;
42008+ atomic_unchecked_t trans_gen;
42009
42010 unsigned int crypto_attached_size;
42011 unsigned int crypto_align_size;
42012diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
42013index 36a2535..0591bf4 100644
42014--- a/drivers/staging/pohmelfs/trans.c
42015+++ b/drivers/staging/pohmelfs/trans.c
42016@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
42017 int err;
42018 struct netfs_cmd *cmd = t->iovec.iov_base;
42019
42020- t->gen = atomic_inc_return(&psb->trans_gen);
42021+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
42022
42023 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
42024 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
42025diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
42026index f890a16..509ece8 100644
42027--- a/drivers/staging/sep/sep_driver.c
42028+++ b/drivers/staging/sep/sep_driver.c
42029@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver = {
42030 static dev_t sep_devno;
42031
42032 /* the files operations structure of the driver */
42033-static struct file_operations sep_file_operations = {
42034+static const struct file_operations sep_file_operations = {
42035 .owner = THIS_MODULE,
42036 .ioctl = sep_ioctl,
42037 .poll = sep_poll,
42038diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
42039index 5e16bc3..7655b10 100644
42040--- a/drivers/staging/usbip/usbip_common.h
42041+++ b/drivers/staging/usbip/usbip_common.h
42042@@ -374,7 +374,7 @@ struct usbip_device {
42043 void (*shutdown)(struct usbip_device *);
42044 void (*reset)(struct usbip_device *);
42045 void (*unusable)(struct usbip_device *);
42046- } eh_ops;
42047+ } __no_const eh_ops;
42048 };
42049
42050
42051diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42052index 57f7946..d9df23d 100644
42053--- a/drivers/staging/usbip/vhci.h
42054+++ b/drivers/staging/usbip/vhci.h
42055@@ -92,7 +92,7 @@ struct vhci_hcd {
42056 unsigned resuming:1;
42057 unsigned long re_timeout;
42058
42059- atomic_t seqnum;
42060+ atomic_unchecked_t seqnum;
42061
42062 /*
42063 * NOTE:
42064diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42065index 20cd7db..c2693ff 100644
42066--- a/drivers/staging/usbip/vhci_hcd.c
42067+++ b/drivers/staging/usbip/vhci_hcd.c
42068@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
42069 return;
42070 }
42071
42072- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42073+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42074 if (priv->seqnum == 0xffff)
42075 usbip_uinfo("seqnum max\n");
42076
42077@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42078 return -ENOMEM;
42079 }
42080
42081- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42082+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42083 if (unlink->seqnum == 0xffff)
42084 usbip_uinfo("seqnum max\n");
42085
42086@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hcd)
42087 vdev->rhport = rhport;
42088 }
42089
42090- atomic_set(&vhci->seqnum, 0);
42091+ atomic_set_unchecked(&vhci->seqnum, 0);
42092 spin_lock_init(&vhci->lock);
42093
42094
42095diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42096index 7fd76fe..673695a 100644
42097--- a/drivers/staging/usbip/vhci_rx.c
42098+++ b/drivers/staging/usbip/vhci_rx.c
42099@@ -79,7 +79,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42100 usbip_uerr("cannot find a urb of seqnum %u\n",
42101 pdu->base.seqnum);
42102 usbip_uinfo("max seqnum %d\n",
42103- atomic_read(&the_controller->seqnum));
42104+ atomic_read_unchecked(&the_controller->seqnum));
42105 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42106 return;
42107 }
42108diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
42109index 7891288..8e31300 100644
42110--- a/drivers/staging/vme/devices/vme_user.c
42111+++ b/drivers/staging/vme/devices/vme_user.c
42112@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *, struct file *, unsigned int,
42113 static int __init vme_user_probe(struct device *, int, int);
42114 static int __exit vme_user_remove(struct device *, int, int);
42115
42116-static struct file_operations vme_user_fops = {
42117+static const struct file_operations vme_user_fops = {
42118 .open = vme_user_open,
42119 .release = vme_user_release,
42120 .read = vme_user_read,
42121diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42122index 58abf44..00c1fc8 100644
42123--- a/drivers/staging/vt6655/hostap.c
42124+++ b/drivers/staging/vt6655/hostap.c
42125@@ -84,7 +84,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42126 PSDevice apdev_priv;
42127 struct net_device *dev = pDevice->dev;
42128 int ret;
42129- const struct net_device_ops apdev_netdev_ops = {
42130+ net_device_ops_no_const apdev_netdev_ops = {
42131 .ndo_start_xmit = pDevice->tx_80211,
42132 };
42133
42134diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42135index 0c8267a..db1f363 100644
42136--- a/drivers/staging/vt6656/hostap.c
42137+++ b/drivers/staging/vt6656/hostap.c
42138@@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42139 PSDevice apdev_priv;
42140 struct net_device *dev = pDevice->dev;
42141 int ret;
42142- const struct net_device_ops apdev_netdev_ops = {
42143+ net_device_ops_no_const apdev_netdev_ops = {
42144 .ndo_start_xmit = pDevice->tx_80211,
42145 };
42146
42147diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
42148index 925678b..da7f5ed 100644
42149--- a/drivers/staging/wlan-ng/hfa384x_usb.c
42150+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
42151@@ -205,7 +205,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
42152
42153 struct usbctlx_completor {
42154 int (*complete) (struct usbctlx_completor *);
42155-};
42156+} __no_const;
42157 typedef struct usbctlx_completor usbctlx_completor_t;
42158
42159 static int
42160diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
42161index 40de151..924f268 100644
42162--- a/drivers/telephony/ixj.c
42163+++ b/drivers/telephony/ixj.c
42164@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
42165 bool mContinue;
42166 char *pIn, *pOut;
42167
42168+ pax_track_stack();
42169+
42170 if (!SCI_Prepare(j))
42171 return 0;
42172
42173diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
42174index e941367..b631f5a 100644
42175--- a/drivers/uio/uio.c
42176+++ b/drivers/uio/uio.c
42177@@ -23,6 +23,7 @@
42178 #include <linux/string.h>
42179 #include <linux/kobject.h>
42180 #include <linux/uio_driver.h>
42181+#include <asm/local.h>
42182
42183 #define UIO_MAX_DEVICES 255
42184
42185@@ -30,10 +31,10 @@ struct uio_device {
42186 struct module *owner;
42187 struct device *dev;
42188 int minor;
42189- atomic_t event;
42190+ atomic_unchecked_t event;
42191 struct fasync_struct *async_queue;
42192 wait_queue_head_t wait;
42193- int vma_count;
42194+ local_t vma_count;
42195 struct uio_info *info;
42196 struct kobject *map_dir;
42197 struct kobject *portio_dir;
42198@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
42199 return entry->show(mem, buf);
42200 }
42201
42202-static struct sysfs_ops map_sysfs_ops = {
42203+static const struct sysfs_ops map_sysfs_ops = {
42204 .show = map_type_show,
42205 };
42206
42207@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
42208 return entry->show(port, buf);
42209 }
42210
42211-static struct sysfs_ops portio_sysfs_ops = {
42212+static const struct sysfs_ops portio_sysfs_ops = {
42213 .show = portio_type_show,
42214 };
42215
42216@@ -255,7 +256,7 @@ static ssize_t show_event(struct device *dev,
42217 struct uio_device *idev = dev_get_drvdata(dev);
42218 if (idev)
42219 return sprintf(buf, "%u\n",
42220- (unsigned int)atomic_read(&idev->event));
42221+ (unsigned int)atomic_read_unchecked(&idev->event));
42222 else
42223 return -ENODEV;
42224 }
42225@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *info)
42226 {
42227 struct uio_device *idev = info->uio_dev;
42228
42229- atomic_inc(&idev->event);
42230+ atomic_inc_unchecked(&idev->event);
42231 wake_up_interruptible(&idev->wait);
42232 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
42233 }
42234@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode, struct file *filep)
42235 }
42236
42237 listener->dev = idev;
42238- listener->event_count = atomic_read(&idev->event);
42239+ listener->event_count = atomic_read_unchecked(&idev->event);
42240 filep->private_data = listener;
42241
42242 if (idev->info->open) {
42243@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
42244 return -EIO;
42245
42246 poll_wait(filep, &idev->wait, wait);
42247- if (listener->event_count != atomic_read(&idev->event))
42248+ if (listener->event_count != atomic_read_unchecked(&idev->event))
42249 return POLLIN | POLLRDNORM;
42250 return 0;
42251 }
42252@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
42253 do {
42254 set_current_state(TASK_INTERRUPTIBLE);
42255
42256- event_count = atomic_read(&idev->event);
42257+ event_count = atomic_read_unchecked(&idev->event);
42258 if (event_count != listener->event_count) {
42259 if (copy_to_user(buf, &event_count, count))
42260 retval = -EFAULT;
42261@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
42262 static void uio_vma_open(struct vm_area_struct *vma)
42263 {
42264 struct uio_device *idev = vma->vm_private_data;
42265- idev->vma_count++;
42266+ local_inc(&idev->vma_count);
42267 }
42268
42269 static void uio_vma_close(struct vm_area_struct *vma)
42270 {
42271 struct uio_device *idev = vma->vm_private_data;
42272- idev->vma_count--;
42273+ local_dec(&idev->vma_count);
42274 }
42275
42276 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42277@@ -840,7 +841,7 @@ int __uio_register_device(struct module *owner,
42278 idev->owner = owner;
42279 idev->info = info;
42280 init_waitqueue_head(&idev->wait);
42281- atomic_set(&idev->event, 0);
42282+ atomic_set_unchecked(&idev->event, 0);
42283
42284 ret = uio_get_minor(idev);
42285 if (ret)
42286diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
42287index fbea856..06efea6 100644
42288--- a/drivers/usb/atm/usbatm.c
42289+++ b/drivers/usb/atm/usbatm.c
42290@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42291 if (printk_ratelimit())
42292 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42293 __func__, vpi, vci);
42294- atomic_inc(&vcc->stats->rx_err);
42295+ atomic_inc_unchecked(&vcc->stats->rx_err);
42296 return;
42297 }
42298
42299@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42300 if (length > ATM_MAX_AAL5_PDU) {
42301 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42302 __func__, length, vcc);
42303- atomic_inc(&vcc->stats->rx_err);
42304+ atomic_inc_unchecked(&vcc->stats->rx_err);
42305 goto out;
42306 }
42307
42308@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42309 if (sarb->len < pdu_length) {
42310 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42311 __func__, pdu_length, sarb->len, vcc);
42312- atomic_inc(&vcc->stats->rx_err);
42313+ atomic_inc_unchecked(&vcc->stats->rx_err);
42314 goto out;
42315 }
42316
42317 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42318 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42319 __func__, vcc);
42320- atomic_inc(&vcc->stats->rx_err);
42321+ atomic_inc_unchecked(&vcc->stats->rx_err);
42322 goto out;
42323 }
42324
42325@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42326 if (printk_ratelimit())
42327 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42328 __func__, length);
42329- atomic_inc(&vcc->stats->rx_drop);
42330+ atomic_inc_unchecked(&vcc->stats->rx_drop);
42331 goto out;
42332 }
42333
42334@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42335
42336 vcc->push(vcc, skb);
42337
42338- atomic_inc(&vcc->stats->rx);
42339+ atomic_inc_unchecked(&vcc->stats->rx);
42340 out:
42341 skb_trim(sarb, 0);
42342 }
42343@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned long data)
42344 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42345
42346 usbatm_pop(vcc, skb);
42347- atomic_inc(&vcc->stats->tx);
42348+ atomic_inc_unchecked(&vcc->stats->tx);
42349
42350 skb = skb_dequeue(&instance->sndqueue);
42351 }
42352@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
42353 if (!left--)
42354 return sprintf(page,
42355 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42356- atomic_read(&atm_dev->stats.aal5.tx),
42357- atomic_read(&atm_dev->stats.aal5.tx_err),
42358- atomic_read(&atm_dev->stats.aal5.rx),
42359- atomic_read(&atm_dev->stats.aal5.rx_err),
42360- atomic_read(&atm_dev->stats.aal5.rx_drop));
42361+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42362+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42363+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42364+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42365+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42366
42367 if (!left--) {
42368 if (instance->disconnected)
42369diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
42370index 3e564bf..949b448 100644
42371--- a/drivers/usb/class/cdc-wdm.c
42372+++ b/drivers/usb/class/cdc-wdm.c
42373@@ -314,7 +314,7 @@ static ssize_t wdm_write
42374 if (r < 0)
42375 goto outnp;
42376
42377- if (!file->f_flags && O_NONBLOCK)
42378+ if (!(file->f_flags & O_NONBLOCK))
42379 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
42380 &desc->flags));
42381 else
42382diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
42383index 24e6205..fe5a5d4 100644
42384--- a/drivers/usb/core/hcd.c
42385+++ b/drivers/usb/core/hcd.c
42386@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
42387
42388 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42389
42390-struct usb_mon_operations *mon_ops;
42391+const struct usb_mon_operations *mon_ops;
42392
42393 /*
42394 * The registration is unlocked.
42395@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
42396 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42397 */
42398
42399-int usb_mon_register (struct usb_mon_operations *ops)
42400+int usb_mon_register (const struct usb_mon_operations *ops)
42401 {
42402
42403 if (mon_ops)
42404diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
42405index bcbe104..9cfd1c6 100644
42406--- a/drivers/usb/core/hcd.h
42407+++ b/drivers/usb/core/hcd.h
42408@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) { }
42409 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42410
42411 struct usb_mon_operations {
42412- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
42413- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42414- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42415+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
42416+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42417+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42418 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
42419 };
42420
42421-extern struct usb_mon_operations *mon_ops;
42422+extern const struct usb_mon_operations *mon_ops;
42423
42424 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
42425 {
42426@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
42427 (*mon_ops->urb_complete)(bus, urb, status);
42428 }
42429
42430-int usb_mon_register(struct usb_mon_operations *ops);
42431+int usb_mon_register(const struct usb_mon_operations *ops);
42432 void usb_mon_deregister(void);
42433
42434 #else
42435diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
42436index 409cc94..a673bad 100644
42437--- a/drivers/usb/core/message.c
42438+++ b/drivers/usb/core/message.c
42439@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
42440 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42441 if (buf) {
42442 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42443- if (len > 0) {
42444- smallbuf = kmalloc(++len, GFP_NOIO);
42445+ if (len++ > 0) {
42446+ smallbuf = kmalloc(len, GFP_NOIO);
42447 if (!smallbuf)
42448 return buf;
42449 memcpy(smallbuf, buf, len);
42450diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
42451index 62ff5e7..530b74e 100644
42452--- a/drivers/usb/misc/appledisplay.c
42453+++ b/drivers/usb/misc/appledisplay.c
42454@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
42455 return pdata->msgdata[1];
42456 }
42457
42458-static struct backlight_ops appledisplay_bl_data = {
42459+static const struct backlight_ops appledisplay_bl_data = {
42460 .get_brightness = appledisplay_bl_get_brightness,
42461 .update_status = appledisplay_bl_update_status,
42462 };
42463diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
42464index e0c2db3..bd8cb66 100644
42465--- a/drivers/usb/mon/mon_main.c
42466+++ b/drivers/usb/mon/mon_main.c
42467@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42468 /*
42469 * Ops
42470 */
42471-static struct usb_mon_operations mon_ops_0 = {
42472+static const struct usb_mon_operations mon_ops_0 = {
42473 .urb_submit = mon_submit,
42474 .urb_submit_error = mon_submit_error,
42475 .urb_complete = mon_complete,
42476diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
42477index d6bea3e..60b250e 100644
42478--- a/drivers/usb/wusbcore/wa-hc.h
42479+++ b/drivers/usb/wusbcore/wa-hc.h
42480@@ -192,7 +192,7 @@ struct wahc {
42481 struct list_head xfer_delayed_list;
42482 spinlock_t xfer_list_lock;
42483 struct work_struct xfer_work;
42484- atomic_t xfer_id_count;
42485+ atomic_unchecked_t xfer_id_count;
42486 };
42487
42488
42489@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
42490 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42491 spin_lock_init(&wa->xfer_list_lock);
42492 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42493- atomic_set(&wa->xfer_id_count, 1);
42494+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42495 }
42496
42497 /**
42498diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
42499index 613a5fc..3174865 100644
42500--- a/drivers/usb/wusbcore/wa-xfer.c
42501+++ b/drivers/usb/wusbcore/wa-xfer.c
42502@@ -293,7 +293,7 @@ out:
42503 */
42504 static void wa_xfer_id_init(struct wa_xfer *xfer)
42505 {
42506- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42507+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42508 }
42509
42510 /*
42511diff --git a/drivers/uwb/wlp/messages.c b/drivers/uwb/wlp/messages.c
42512index aa42fce..f8a828c 100644
42513--- a/drivers/uwb/wlp/messages.c
42514+++ b/drivers/uwb/wlp/messages.c
42515@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct sk_buff *skb)
42516 size_t len = skb->len;
42517 size_t used;
42518 ssize_t result;
42519- struct wlp_nonce enonce, rnonce;
42520+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
42521 enum wlp_assc_error assc_err;
42522 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
42523 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
42524diff --git a/drivers/uwb/wlp/sysfs.c b/drivers/uwb/wlp/sysfs.c
42525index 0370399..6627c94 100644
42526--- a/drivers/uwb/wlp/sysfs.c
42527+++ b/drivers/uwb/wlp/sysfs.c
42528@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobject *kobj, struct attribute *attr,
42529 return ret;
42530 }
42531
42532-static
42533-struct sysfs_ops wss_sysfs_ops = {
42534+static const struct sysfs_ops wss_sysfs_ops = {
42535 .show = wlp_wss_attr_show,
42536 .store = wlp_wss_attr_store,
42537 };
42538diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
42539index d5e8010..5687b56 100644
42540--- a/drivers/video/atmel_lcdfb.c
42541+++ b/drivers/video/atmel_lcdfb.c
42542@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struct backlight_device *bl)
42543 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
42544 }
42545
42546-static struct backlight_ops atmel_lcdc_bl_ops = {
42547+static const struct backlight_ops atmel_lcdc_bl_ops = {
42548 .update_status = atmel_bl_update_status,
42549 .get_brightness = atmel_bl_get_brightness,
42550 };
42551diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42552index e4e4d43..66bcbcc 100644
42553--- a/drivers/video/aty/aty128fb.c
42554+++ b/drivers/video/aty/aty128fb.c
42555@@ -149,7 +149,7 @@ enum {
42556 };
42557
42558 /* Must match above enum */
42559-static const char *r128_family[] __devinitdata = {
42560+static const char *r128_family[] __devinitconst = {
42561 "AGP",
42562 "PCI",
42563 "PRO AGP",
42564@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(struct backlight_device *bd)
42565 return bd->props.brightness;
42566 }
42567
42568-static struct backlight_ops aty128_bl_data = {
42569+static const struct backlight_ops aty128_bl_data = {
42570 .get_brightness = aty128_bl_get_brightness,
42571 .update_status = aty128_bl_update_status,
42572 };
42573diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
42574index 913b4a4..9295a38 100644
42575--- a/drivers/video/aty/atyfb_base.c
42576+++ b/drivers/video/aty/atyfb_base.c
42577@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct backlight_device *bd)
42578 return bd->props.brightness;
42579 }
42580
42581-static struct backlight_ops aty_bl_data = {
42582+static const struct backlight_ops aty_bl_data = {
42583 .get_brightness = aty_bl_get_brightness,
42584 .update_status = aty_bl_update_status,
42585 };
42586diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
42587index 1a056ad..221bd6a 100644
42588--- a/drivers/video/aty/radeon_backlight.c
42589+++ b/drivers/video/aty/radeon_backlight.c
42590@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(struct backlight_device *bd)
42591 return bd->props.brightness;
42592 }
42593
42594-static struct backlight_ops radeon_bl_data = {
42595+static const struct backlight_ops radeon_bl_data = {
42596 .get_brightness = radeon_bl_get_brightness,
42597 .update_status = radeon_bl_update_status,
42598 };
42599diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
42600index ad05da5..3cb2cb9 100644
42601--- a/drivers/video/backlight/adp5520_bl.c
42602+++ b/drivers/video/backlight/adp5520_bl.c
42603@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl)
42604 return error ? data->current_brightness : reg_val;
42605 }
42606
42607-static struct backlight_ops adp5520_bl_ops = {
42608+static const struct backlight_ops adp5520_bl_ops = {
42609 .update_status = adp5520_bl_update_status,
42610 .get_brightness = adp5520_bl_get_brightness,
42611 };
42612diff --git a/drivers/video/backlight/adx_bl.c b/drivers/video/backlight/adx_bl.c
42613index 2c3bdfc..d769b0b 100644
42614--- a/drivers/video/backlight/adx_bl.c
42615+++ b/drivers/video/backlight/adx_bl.c
42616@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct fb_info *fb)
42617 return 1;
42618 }
42619
42620-static struct backlight_ops adx_backlight_ops = {
42621+static const struct backlight_ops adx_backlight_ops = {
42622 .options = 0,
42623 .update_status = adx_backlight_update_status,
42624 .get_brightness = adx_backlight_get_brightness,
42625diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
42626index 505c082..6b6b3cc 100644
42627--- a/drivers/video/backlight/atmel-pwm-bl.c
42628+++ b/drivers/video/backlight/atmel-pwm-bl.c
42629@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
42630 return pwm_channel_enable(&pwmbl->pwmc);
42631 }
42632
42633-static struct backlight_ops atmel_pwm_bl_ops = {
42634+static const struct backlight_ops atmel_pwm_bl_ops = {
42635 .get_brightness = atmel_pwm_bl_get_intensity,
42636 .update_status = atmel_pwm_bl_set_intensity,
42637 };
42638diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
42639index 5e20e6e..89025e6 100644
42640--- a/drivers/video/backlight/backlight.c
42641+++ b/drivers/video/backlight/backlight.c
42642@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
42643 * ERR_PTR() or a pointer to the newly allocated device.
42644 */
42645 struct backlight_device *backlight_device_register(const char *name,
42646- struct device *parent, void *devdata, struct backlight_ops *ops)
42647+ struct device *parent, void *devdata, const struct backlight_ops *ops)
42648 {
42649 struct backlight_device *new_bd;
42650 int rc;
42651diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
42652index 9677494..b4bcf80 100644
42653--- a/drivers/video/backlight/corgi_lcd.c
42654+++ b/drivers/video/backlight/corgi_lcd.c
42655@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit)
42656 }
42657 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
42658
42659-static struct backlight_ops corgi_bl_ops = {
42660+static const struct backlight_ops corgi_bl_ops = {
42661 .get_brightness = corgi_bl_get_intensity,
42662 .update_status = corgi_bl_update_status,
42663 };
42664diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
42665index b9fe62b..2914bf1 100644
42666--- a/drivers/video/backlight/cr_bllcd.c
42667+++ b/drivers/video/backlight/cr_bllcd.c
42668@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(struct backlight_device *bd)
42669 return intensity;
42670 }
42671
42672-static struct backlight_ops cr_backlight_ops = {
42673+static const struct backlight_ops cr_backlight_ops = {
42674 .get_brightness = cr_backlight_get_intensity,
42675 .update_status = cr_backlight_set_intensity,
42676 };
42677diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
42678index 701a108..feacfd5 100644
42679--- a/drivers/video/backlight/da903x_bl.c
42680+++ b/drivers/video/backlight/da903x_bl.c
42681@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightness(struct backlight_device *bl)
42682 return data->current_brightness;
42683 }
42684
42685-static struct backlight_ops da903x_backlight_ops = {
42686+static const struct backlight_ops da903x_backlight_ops = {
42687 .update_status = da903x_backlight_update_status,
42688 .get_brightness = da903x_backlight_get_brightness,
42689 };
42690diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
42691index 6d27f62..e6d348e 100644
42692--- a/drivers/video/backlight/generic_bl.c
42693+++ b/drivers/video/backlight/generic_bl.c
42694@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
42695 }
42696 EXPORT_SYMBOL(corgibl_limit_intensity);
42697
42698-static struct backlight_ops genericbl_ops = {
42699+static const struct backlight_ops genericbl_ops = {
42700 .options = BL_CORE_SUSPENDRESUME,
42701 .get_brightness = genericbl_get_intensity,
42702 .update_status = genericbl_send_intensity,
42703diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
42704index 7fb4eef..f7cc528 100644
42705--- a/drivers/video/backlight/hp680_bl.c
42706+++ b/drivers/video/backlight/hp680_bl.c
42707@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
42708 return current_intensity;
42709 }
42710
42711-static struct backlight_ops hp680bl_ops = {
42712+static const struct backlight_ops hp680bl_ops = {
42713 .get_brightness = hp680bl_get_intensity,
42714 .update_status = hp680bl_set_intensity,
42715 };
42716diff --git a/drivers/video/backlight/jornada720_bl.c b/drivers/video/backlight/jornada720_bl.c
42717index 7aed256..db9071f 100644
42718--- a/drivers/video/backlight/jornada720_bl.c
42719+++ b/drivers/video/backlight/jornada720_bl.c
42720@@ -93,7 +93,7 @@ out:
42721 return ret;
42722 }
42723
42724-static struct backlight_ops jornada_bl_ops = {
42725+static const struct backlight_ops jornada_bl_ops = {
42726 .get_brightness = jornada_bl_get_brightness,
42727 .update_status = jornada_bl_update_status,
42728 .options = BL_CORE_SUSPENDRESUME,
42729diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
42730index a38fda1..939e7b8 100644
42731--- a/drivers/video/backlight/kb3886_bl.c
42732+++ b/drivers/video/backlight/kb3886_bl.c
42733@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct backlight_device *bd)
42734 return kb3886bl_intensity;
42735 }
42736
42737-static struct backlight_ops kb3886bl_ops = {
42738+static const struct backlight_ops kb3886bl_ops = {
42739 .get_brightness = kb3886bl_get_intensity,
42740 .update_status = kb3886bl_send_intensity,
42741 };
42742diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
42743index 6b488b8..00a9591 100644
42744--- a/drivers/video/backlight/locomolcd.c
42745+++ b/drivers/video/backlight/locomolcd.c
42746@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struct backlight_device *bd)
42747 return current_intensity;
42748 }
42749
42750-static struct backlight_ops locomobl_data = {
42751+static const struct backlight_ops locomobl_data = {
42752 .get_brightness = locomolcd_get_intensity,
42753 .update_status = locomolcd_set_intensity,
42754 };
42755diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
42756index 99bdfa8..3dac448 100644
42757--- a/drivers/video/backlight/mbp_nvidia_bl.c
42758+++ b/drivers/video/backlight/mbp_nvidia_bl.c
42759@@ -33,7 +33,7 @@ struct dmi_match_data {
42760 unsigned long iostart;
42761 unsigned long iolen;
42762 /* Backlight operations structure. */
42763- struct backlight_ops backlight_ops;
42764+ const struct backlight_ops backlight_ops;
42765 };
42766
42767 /* Module parameters. */
42768diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
42769index cbad67e..3cf900e 100644
42770--- a/drivers/video/backlight/omap1_bl.c
42771+++ b/drivers/video/backlight/omap1_bl.c
42772@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct backlight_device *dev)
42773 return bl->current_intensity;
42774 }
42775
42776-static struct backlight_ops omapbl_ops = {
42777+static const struct backlight_ops omapbl_ops = {
42778 .get_brightness = omapbl_get_intensity,
42779 .update_status = omapbl_update_status,
42780 };
42781diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
42782index 9edaf24..075786e 100644
42783--- a/drivers/video/backlight/progear_bl.c
42784+++ b/drivers/video/backlight/progear_bl.c
42785@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struct backlight_device *bd)
42786 return intensity - HW_LEVEL_MIN;
42787 }
42788
42789-static struct backlight_ops progearbl_ops = {
42790+static const struct backlight_ops progearbl_ops = {
42791 .get_brightness = progearbl_get_intensity,
42792 .update_status = progearbl_set_intensity,
42793 };
42794diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
42795index 8871662..df9e0b3 100644
42796--- a/drivers/video/backlight/pwm_bl.c
42797+++ b/drivers/video/backlight/pwm_bl.c
42798@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(struct backlight_device *bl)
42799 return bl->props.brightness;
42800 }
42801
42802-static struct backlight_ops pwm_backlight_ops = {
42803+static const struct backlight_ops pwm_backlight_ops = {
42804 .update_status = pwm_backlight_update_status,
42805 .get_brightness = pwm_backlight_get_brightness,
42806 };
42807diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
42808index 43edbad..e14ce4d 100644
42809--- a/drivers/video/backlight/tosa_bl.c
42810+++ b/drivers/video/backlight/tosa_bl.c
42811@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct backlight_device *dev)
42812 return props->brightness;
42813 }
42814
42815-static struct backlight_ops bl_ops = {
42816+static const struct backlight_ops bl_ops = {
42817 .get_brightness = tosa_bl_get_brightness,
42818 .update_status = tosa_bl_update_status,
42819 };
42820diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
42821index 467bdb7..e32add3 100644
42822--- a/drivers/video/backlight/wm831x_bl.c
42823+++ b/drivers/video/backlight/wm831x_bl.c
42824@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightness(struct backlight_device *bl)
42825 return data->current_brightness;
42826 }
42827
42828-static struct backlight_ops wm831x_backlight_ops = {
42829+static const struct backlight_ops wm831x_backlight_ops = {
42830 .options = BL_CORE_SUSPENDRESUME,
42831 .update_status = wm831x_backlight_update_status,
42832 .get_brightness = wm831x_backlight_get_brightness,
42833diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
42834index e49ae5e..db4e6f7 100644
42835--- a/drivers/video/bf54x-lq043fb.c
42836+++ b/drivers/video/bf54x-lq043fb.c
42837@@ -463,7 +463,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42838 return 0;
42839 }
42840
42841-static struct backlight_ops bfin_lq043fb_bl_ops = {
42842+static const struct backlight_ops bfin_lq043fb_bl_ops = {
42843 .get_brightness = bl_get_brightness,
42844 };
42845
42846diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
42847index 2c72a7c..d523e52 100644
42848--- a/drivers/video/bfin-t350mcqb-fb.c
42849+++ b/drivers/video/bfin-t350mcqb-fb.c
42850@@ -381,7 +381,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42851 return 0;
42852 }
42853
42854-static struct backlight_ops bfin_lq043fb_bl_ops = {
42855+static const struct backlight_ops bfin_lq043fb_bl_ops = {
42856 .get_brightness = bl_get_brightness,
42857 };
42858
42859diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42860index f53b9f1..958bf4e 100644
42861--- a/drivers/video/fbcmap.c
42862+++ b/drivers/video/fbcmap.c
42863@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42864 rc = -ENODEV;
42865 goto out;
42866 }
42867- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42868- !info->fbops->fb_setcmap)) {
42869+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42870 rc = -EINVAL;
42871 goto out1;
42872 }
42873diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42874index 99bbd28..ad3829e 100644
42875--- a/drivers/video/fbmem.c
42876+++ b/drivers/video/fbmem.c
42877@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42878 image->dx += image->width + 8;
42879 }
42880 } else if (rotate == FB_ROTATE_UD) {
42881- for (x = 0; x < num && image->dx >= 0; x++) {
42882+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42883 info->fbops->fb_imageblit(info, image);
42884 image->dx -= image->width + 8;
42885 }
42886@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42887 image->dy += image->height + 8;
42888 }
42889 } else if (rotate == FB_ROTATE_CCW) {
42890- for (x = 0; x < num && image->dy >= 0; x++) {
42891+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42892 info->fbops->fb_imageblit(info, image);
42893 image->dy -= image->height + 8;
42894 }
42895@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
42896 int flags = info->flags;
42897 int ret = 0;
42898
42899+ pax_track_stack();
42900+
42901 if (var->activate & FB_ACTIVATE_INV_MODE) {
42902 struct fb_videomode mode1, mode2;
42903
42904@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42905 void __user *argp = (void __user *)arg;
42906 long ret = 0;
42907
42908+ pax_track_stack();
42909+
42910 switch (cmd) {
42911 case FBIOGET_VSCREENINFO:
42912 if (!lock_fb_info(info))
42913@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42914 return -EFAULT;
42915 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42916 return -EINVAL;
42917- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42918+ if (con2fb.framebuffer >= FB_MAX)
42919 return -EINVAL;
42920 if (!registered_fb[con2fb.framebuffer])
42921 request_module("fb%d", con2fb.framebuffer);
42922diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
42923index f20eff8..3e4f622 100644
42924--- a/drivers/video/geode/gx1fb_core.c
42925+++ b/drivers/video/geode/gx1fb_core.c
42926@@ -30,7 +30,7 @@ static int crt_option = 1;
42927 static char panel_option[32] = "";
42928
42929 /* Modes relevant to the GX1 (taken from modedb.c) */
42930-static const struct fb_videomode __initdata gx1_modedb[] = {
42931+static const struct fb_videomode __initconst gx1_modedb[] = {
42932 /* 640x480-60 VESA */
42933 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
42934 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
42935diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
42936index 896e53d..4d87d0b 100644
42937--- a/drivers/video/gxt4500.c
42938+++ b/drivers/video/gxt4500.c
42939@@ -156,7 +156,7 @@ struct gxt4500_par {
42940 static char *mode_option;
42941
42942 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
42943-static const struct fb_videomode defaultmode __devinitdata = {
42944+static const struct fb_videomode defaultmode __devinitconst = {
42945 .refresh = 60,
42946 .xres = 1280,
42947 .yres = 1024,
42948@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
42949 return 0;
42950 }
42951
42952-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
42953+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
42954 .id = "IBM GXT4500P",
42955 .type = FB_TYPE_PACKED_PIXELS,
42956 .visual = FB_VISUAL_PSEUDOCOLOR,
42957diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42958index f5bedee..28c6028 100644
42959--- a/drivers/video/i810/i810_accel.c
42960+++ b/drivers/video/i810/i810_accel.c
42961@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42962 }
42963 }
42964 printk("ringbuffer lockup!!!\n");
42965+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42966 i810_report_error(mmio);
42967 par->dev_flags |= LOCKUP;
42968 info->pixmap.scan_align = 1;
42969diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
42970index 5743ea2..457f82c 100644
42971--- a/drivers/video/i810/i810_main.c
42972+++ b/drivers/video/i810/i810_main.c
42973@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
42974 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
42975
42976 /* PCI */
42977-static const char *i810_pci_list[] __devinitdata = {
42978+static const char *i810_pci_list[] __devinitconst = {
42979 "Intel(R) 810 Framebuffer Device" ,
42980 "Intel(R) 810-DC100 Framebuffer Device" ,
42981 "Intel(R) 810E Framebuffer Device" ,
42982diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42983index 3c14e43..eafa544 100644
42984--- a/drivers/video/logo/logo_linux_clut224.ppm
42985+++ b/drivers/video/logo/logo_linux_clut224.ppm
42986@@ -1,1604 +1,1123 @@
42987 P3
42988-# Standard 224-color Linux logo
42989 80 80
42990 255
42991- 0 0 0 0 0 0 0 0 0 0 0 0
42992- 0 0 0 0 0 0 0 0 0 0 0 0
42993- 0 0 0 0 0 0 0 0 0 0 0 0
42994- 0 0 0 0 0 0 0 0 0 0 0 0
42995- 0 0 0 0 0 0 0 0 0 0 0 0
42996- 0 0 0 0 0 0 0 0 0 0 0 0
42997- 0 0 0 0 0 0 0 0 0 0 0 0
42998- 0 0 0 0 0 0 0 0 0 0 0 0
42999- 0 0 0 0 0 0 0 0 0 0 0 0
43000- 6 6 6 6 6 6 10 10 10 10 10 10
43001- 10 10 10 6 6 6 6 6 6 6 6 6
43002- 0 0 0 0 0 0 0 0 0 0 0 0
43003- 0 0 0 0 0 0 0 0 0 0 0 0
43004- 0 0 0 0 0 0 0 0 0 0 0 0
43005- 0 0 0 0 0 0 0 0 0 0 0 0
43006- 0 0 0 0 0 0 0 0 0 0 0 0
43007- 0 0 0 0 0 0 0 0 0 0 0 0
43008- 0 0 0 0 0 0 0 0 0 0 0 0
43009- 0 0 0 0 0 0 0 0 0 0 0 0
43010- 0 0 0 0 0 0 0 0 0 0 0 0
43011- 0 0 0 0 0 0 0 0 0 0 0 0
43012- 0 0 0 0 0 0 0 0 0 0 0 0
43013- 0 0 0 0 0 0 0 0 0 0 0 0
43014- 0 0 0 0 0 0 0 0 0 0 0 0
43015- 0 0 0 0 0 0 0 0 0 0 0 0
43016- 0 0 0 0 0 0 0 0 0 0 0 0
43017- 0 0 0 0 0 0 0 0 0 0 0 0
43018- 0 0 0 0 0 0 0 0 0 0 0 0
43019- 0 0 0 6 6 6 10 10 10 14 14 14
43020- 22 22 22 26 26 26 30 30 30 34 34 34
43021- 30 30 30 30 30 30 26 26 26 18 18 18
43022- 14 14 14 10 10 10 6 6 6 0 0 0
43023- 0 0 0 0 0 0 0 0 0 0 0 0
43024- 0 0 0 0 0 0 0 0 0 0 0 0
43025- 0 0 0 0 0 0 0 0 0 0 0 0
43026- 0 0 0 0 0 0 0 0 0 0 0 0
43027- 0 0 0 0 0 0 0 0 0 0 0 0
43028- 0 0 0 0 0 0 0 0 0 0 0 0
43029- 0 0 0 0 0 0 0 0 0 0 0 0
43030- 0 0 0 0 0 0 0 0 0 0 0 0
43031- 0 0 0 0 0 0 0 0 0 0 0 0
43032- 0 0 0 0 0 1 0 0 1 0 0 0
43033- 0 0 0 0 0 0 0 0 0 0 0 0
43034- 0 0 0 0 0 0 0 0 0 0 0 0
43035- 0 0 0 0 0 0 0 0 0 0 0 0
43036- 0 0 0 0 0 0 0 0 0 0 0 0
43037- 0 0 0 0 0 0 0 0 0 0 0 0
43038- 0 0 0 0 0 0 0 0 0 0 0 0
43039- 6 6 6 14 14 14 26 26 26 42 42 42
43040- 54 54 54 66 66 66 78 78 78 78 78 78
43041- 78 78 78 74 74 74 66 66 66 54 54 54
43042- 42 42 42 26 26 26 18 18 18 10 10 10
43043- 6 6 6 0 0 0 0 0 0 0 0 0
43044- 0 0 0 0 0 0 0 0 0 0 0 0
43045- 0 0 0 0 0 0 0 0 0 0 0 0
43046- 0 0 0 0 0 0 0 0 0 0 0 0
43047- 0 0 0 0 0 0 0 0 0 0 0 0
43048- 0 0 0 0 0 0 0 0 0 0 0 0
43049- 0 0 0 0 0 0 0 0 0 0 0 0
43050- 0 0 0 0 0 0 0 0 0 0 0 0
43051- 0 0 0 0 0 0 0 0 0 0 0 0
43052- 0 0 1 0 0 0 0 0 0 0 0 0
43053- 0 0 0 0 0 0 0 0 0 0 0 0
43054- 0 0 0 0 0 0 0 0 0 0 0 0
43055- 0 0 0 0 0 0 0 0 0 0 0 0
43056- 0 0 0 0 0 0 0 0 0 0 0 0
43057- 0 0 0 0 0 0 0 0 0 0 0 0
43058- 0 0 0 0 0 0 0 0 0 10 10 10
43059- 22 22 22 42 42 42 66 66 66 86 86 86
43060- 66 66 66 38 38 38 38 38 38 22 22 22
43061- 26 26 26 34 34 34 54 54 54 66 66 66
43062- 86 86 86 70 70 70 46 46 46 26 26 26
43063- 14 14 14 6 6 6 0 0 0 0 0 0
43064- 0 0 0 0 0 0 0 0 0 0 0 0
43065- 0 0 0 0 0 0 0 0 0 0 0 0
43066- 0 0 0 0 0 0 0 0 0 0 0 0
43067- 0 0 0 0 0 0 0 0 0 0 0 0
43068- 0 0 0 0 0 0 0 0 0 0 0 0
43069- 0 0 0 0 0 0 0 0 0 0 0 0
43070- 0 0 0 0 0 0 0 0 0 0 0 0
43071- 0 0 0 0 0 0 0 0 0 0 0 0
43072- 0 0 1 0 0 1 0 0 1 0 0 0
43073- 0 0 0 0 0 0 0 0 0 0 0 0
43074- 0 0 0 0 0 0 0 0 0 0 0 0
43075- 0 0 0 0 0 0 0 0 0 0 0 0
43076- 0 0 0 0 0 0 0 0 0 0 0 0
43077- 0 0 0 0 0 0 0 0 0 0 0 0
43078- 0 0 0 0 0 0 10 10 10 26 26 26
43079- 50 50 50 82 82 82 58 58 58 6 6 6
43080- 2 2 6 2 2 6 2 2 6 2 2 6
43081- 2 2 6 2 2 6 2 2 6 2 2 6
43082- 6 6 6 54 54 54 86 86 86 66 66 66
43083- 38 38 38 18 18 18 6 6 6 0 0 0
43084- 0 0 0 0 0 0 0 0 0 0 0 0
43085- 0 0 0 0 0 0 0 0 0 0 0 0
43086- 0 0 0 0 0 0 0 0 0 0 0 0
43087- 0 0 0 0 0 0 0 0 0 0 0 0
43088- 0 0 0 0 0 0 0 0 0 0 0 0
43089- 0 0 0 0 0 0 0 0 0 0 0 0
43090- 0 0 0 0 0 0 0 0 0 0 0 0
43091- 0 0 0 0 0 0 0 0 0 0 0 0
43092- 0 0 0 0 0 0 0 0 0 0 0 0
43093- 0 0 0 0 0 0 0 0 0 0 0 0
43094- 0 0 0 0 0 0 0 0 0 0 0 0
43095- 0 0 0 0 0 0 0 0 0 0 0 0
43096- 0 0 0 0 0 0 0 0 0 0 0 0
43097- 0 0 0 0 0 0 0 0 0 0 0 0
43098- 0 0 0 6 6 6 22 22 22 50 50 50
43099- 78 78 78 34 34 34 2 2 6 2 2 6
43100- 2 2 6 2 2 6 2 2 6 2 2 6
43101- 2 2 6 2 2 6 2 2 6 2 2 6
43102- 2 2 6 2 2 6 6 6 6 70 70 70
43103- 78 78 78 46 46 46 22 22 22 6 6 6
43104- 0 0 0 0 0 0 0 0 0 0 0 0
43105- 0 0 0 0 0 0 0 0 0 0 0 0
43106- 0 0 0 0 0 0 0 0 0 0 0 0
43107- 0 0 0 0 0 0 0 0 0 0 0 0
43108- 0 0 0 0 0 0 0 0 0 0 0 0
43109- 0 0 0 0 0 0 0 0 0 0 0 0
43110- 0 0 0 0 0 0 0 0 0 0 0 0
43111- 0 0 0 0 0 0 0 0 0 0 0 0
43112- 0 0 1 0 0 1 0 0 1 0 0 0
43113- 0 0 0 0 0 0 0 0 0 0 0 0
43114- 0 0 0 0 0 0 0 0 0 0 0 0
43115- 0 0 0 0 0 0 0 0 0 0 0 0
43116- 0 0 0 0 0 0 0 0 0 0 0 0
43117- 0 0 0 0 0 0 0 0 0 0 0 0
43118- 6 6 6 18 18 18 42 42 42 82 82 82
43119- 26 26 26 2 2 6 2 2 6 2 2 6
43120- 2 2 6 2 2 6 2 2 6 2 2 6
43121- 2 2 6 2 2 6 2 2 6 14 14 14
43122- 46 46 46 34 34 34 6 6 6 2 2 6
43123- 42 42 42 78 78 78 42 42 42 18 18 18
43124- 6 6 6 0 0 0 0 0 0 0 0 0
43125- 0 0 0 0 0 0 0 0 0 0 0 0
43126- 0 0 0 0 0 0 0 0 0 0 0 0
43127- 0 0 0 0 0 0 0 0 0 0 0 0
43128- 0 0 0 0 0 0 0 0 0 0 0 0
43129- 0 0 0 0 0 0 0 0 0 0 0 0
43130- 0 0 0 0 0 0 0 0 0 0 0 0
43131- 0 0 0 0 0 0 0 0 0 0 0 0
43132- 0 0 1 0 0 0 0 0 1 0 0 0
43133- 0 0 0 0 0 0 0 0 0 0 0 0
43134- 0 0 0 0 0 0 0 0 0 0 0 0
43135- 0 0 0 0 0 0 0 0 0 0 0 0
43136- 0 0 0 0 0 0 0 0 0 0 0 0
43137- 0 0 0 0 0 0 0 0 0 0 0 0
43138- 10 10 10 30 30 30 66 66 66 58 58 58
43139- 2 2 6 2 2 6 2 2 6 2 2 6
43140- 2 2 6 2 2 6 2 2 6 2 2 6
43141- 2 2 6 2 2 6 2 2 6 26 26 26
43142- 86 86 86 101 101 101 46 46 46 10 10 10
43143- 2 2 6 58 58 58 70 70 70 34 34 34
43144- 10 10 10 0 0 0 0 0 0 0 0 0
43145- 0 0 0 0 0 0 0 0 0 0 0 0
43146- 0 0 0 0 0 0 0 0 0 0 0 0
43147- 0 0 0 0 0 0 0 0 0 0 0 0
43148- 0 0 0 0 0 0 0 0 0 0 0 0
43149- 0 0 0 0 0 0 0 0 0 0 0 0
43150- 0 0 0 0 0 0 0 0 0 0 0 0
43151- 0 0 0 0 0 0 0 0 0 0 0 0
43152- 0 0 1 0 0 1 0 0 1 0 0 0
43153- 0 0 0 0 0 0 0 0 0 0 0 0
43154- 0 0 0 0 0 0 0 0 0 0 0 0
43155- 0 0 0 0 0 0 0 0 0 0 0 0
43156- 0 0 0 0 0 0 0 0 0 0 0 0
43157- 0 0 0 0 0 0 0 0 0 0 0 0
43158- 14 14 14 42 42 42 86 86 86 10 10 10
43159- 2 2 6 2 2 6 2 2 6 2 2 6
43160- 2 2 6 2 2 6 2 2 6 2 2 6
43161- 2 2 6 2 2 6 2 2 6 30 30 30
43162- 94 94 94 94 94 94 58 58 58 26 26 26
43163- 2 2 6 6 6 6 78 78 78 54 54 54
43164- 22 22 22 6 6 6 0 0 0 0 0 0
43165- 0 0 0 0 0 0 0 0 0 0 0 0
43166- 0 0 0 0 0 0 0 0 0 0 0 0
43167- 0 0 0 0 0 0 0 0 0 0 0 0
43168- 0 0 0 0 0 0 0 0 0 0 0 0
43169- 0 0 0 0 0 0 0 0 0 0 0 0
43170- 0 0 0 0 0 0 0 0 0 0 0 0
43171- 0 0 0 0 0 0 0 0 0 0 0 0
43172- 0 0 0 0 0 0 0 0 0 0 0 0
43173- 0 0 0 0 0 0 0 0 0 0 0 0
43174- 0 0 0 0 0 0 0 0 0 0 0 0
43175- 0 0 0 0 0 0 0 0 0 0 0 0
43176- 0 0 0 0 0 0 0 0 0 0 0 0
43177- 0 0 0 0 0 0 0 0 0 6 6 6
43178- 22 22 22 62 62 62 62 62 62 2 2 6
43179- 2 2 6 2 2 6 2 2 6 2 2 6
43180- 2 2 6 2 2 6 2 2 6 2 2 6
43181- 2 2 6 2 2 6 2 2 6 26 26 26
43182- 54 54 54 38 38 38 18 18 18 10 10 10
43183- 2 2 6 2 2 6 34 34 34 82 82 82
43184- 38 38 38 14 14 14 0 0 0 0 0 0
43185- 0 0 0 0 0 0 0 0 0 0 0 0
43186- 0 0 0 0 0 0 0 0 0 0 0 0
43187- 0 0 0 0 0 0 0 0 0 0 0 0
43188- 0 0 0 0 0 0 0 0 0 0 0 0
43189- 0 0 0 0 0 0 0 0 0 0 0 0
43190- 0 0 0 0 0 0 0 0 0 0 0 0
43191- 0 0 0 0 0 0 0 0 0 0 0 0
43192- 0 0 0 0 0 1 0 0 1 0 0 0
43193- 0 0 0 0 0 0 0 0 0 0 0 0
43194- 0 0 0 0 0 0 0 0 0 0 0 0
43195- 0 0 0 0 0 0 0 0 0 0 0 0
43196- 0 0 0 0 0 0 0 0 0 0 0 0
43197- 0 0 0 0 0 0 0 0 0 6 6 6
43198- 30 30 30 78 78 78 30 30 30 2 2 6
43199- 2 2 6 2 2 6 2 2 6 2 2 6
43200- 2 2 6 2 2 6 2 2 6 2 2 6
43201- 2 2 6 2 2 6 2 2 6 10 10 10
43202- 10 10 10 2 2 6 2 2 6 2 2 6
43203- 2 2 6 2 2 6 2 2 6 78 78 78
43204- 50 50 50 18 18 18 6 6 6 0 0 0
43205- 0 0 0 0 0 0 0 0 0 0 0 0
43206- 0 0 0 0 0 0 0 0 0 0 0 0
43207- 0 0 0 0 0 0 0 0 0 0 0 0
43208- 0 0 0 0 0 0 0 0 0 0 0 0
43209- 0 0 0 0 0 0 0 0 0 0 0 0
43210- 0 0 0 0 0 0 0 0 0 0 0 0
43211- 0 0 0 0 0 0 0 0 0 0 0 0
43212- 0 0 1 0 0 0 0 0 0 0 0 0
43213- 0 0 0 0 0 0 0 0 0 0 0 0
43214- 0 0 0 0 0 0 0 0 0 0 0 0
43215- 0 0 0 0 0 0 0 0 0 0 0 0
43216- 0 0 0 0 0 0 0 0 0 0 0 0
43217- 0 0 0 0 0 0 0 0 0 10 10 10
43218- 38 38 38 86 86 86 14 14 14 2 2 6
43219- 2 2 6 2 2 6 2 2 6 2 2 6
43220- 2 2 6 2 2 6 2 2 6 2 2 6
43221- 2 2 6 2 2 6 2 2 6 2 2 6
43222- 2 2 6 2 2 6 2 2 6 2 2 6
43223- 2 2 6 2 2 6 2 2 6 54 54 54
43224- 66 66 66 26 26 26 6 6 6 0 0 0
43225- 0 0 0 0 0 0 0 0 0 0 0 0
43226- 0 0 0 0 0 0 0 0 0 0 0 0
43227- 0 0 0 0 0 0 0 0 0 0 0 0
43228- 0 0 0 0 0 0 0 0 0 0 0 0
43229- 0 0 0 0 0 0 0 0 0 0 0 0
43230- 0 0 0 0 0 0 0 0 0 0 0 0
43231- 0 0 0 0 0 0 0 0 0 0 0 0
43232- 0 0 0 0 0 1 0 0 1 0 0 0
43233- 0 0 0 0 0 0 0 0 0 0 0 0
43234- 0 0 0 0 0 0 0 0 0 0 0 0
43235- 0 0 0 0 0 0 0 0 0 0 0 0
43236- 0 0 0 0 0 0 0 0 0 0 0 0
43237- 0 0 0 0 0 0 0 0 0 14 14 14
43238- 42 42 42 82 82 82 2 2 6 2 2 6
43239- 2 2 6 6 6 6 10 10 10 2 2 6
43240- 2 2 6 2 2 6 2 2 6 2 2 6
43241- 2 2 6 2 2 6 2 2 6 6 6 6
43242- 14 14 14 10 10 10 2 2 6 2 2 6
43243- 2 2 6 2 2 6 2 2 6 18 18 18
43244- 82 82 82 34 34 34 10 10 10 0 0 0
43245- 0 0 0 0 0 0 0 0 0 0 0 0
43246- 0 0 0 0 0 0 0 0 0 0 0 0
43247- 0 0 0 0 0 0 0 0 0 0 0 0
43248- 0 0 0 0 0 0 0 0 0 0 0 0
43249- 0 0 0 0 0 0 0 0 0 0 0 0
43250- 0 0 0 0 0 0 0 0 0 0 0 0
43251- 0 0 0 0 0 0 0 0 0 0 0 0
43252- 0 0 1 0 0 0 0 0 0 0 0 0
43253- 0 0 0 0 0 0 0 0 0 0 0 0
43254- 0 0 0 0 0 0 0 0 0 0 0 0
43255- 0 0 0 0 0 0 0 0 0 0 0 0
43256- 0 0 0 0 0 0 0 0 0 0 0 0
43257- 0 0 0 0 0 0 0 0 0 14 14 14
43258- 46 46 46 86 86 86 2 2 6 2 2 6
43259- 6 6 6 6 6 6 22 22 22 34 34 34
43260- 6 6 6 2 2 6 2 2 6 2 2 6
43261- 2 2 6 2 2 6 18 18 18 34 34 34
43262- 10 10 10 50 50 50 22 22 22 2 2 6
43263- 2 2 6 2 2 6 2 2 6 10 10 10
43264- 86 86 86 42 42 42 14 14 14 0 0 0
43265- 0 0 0 0 0 0 0 0 0 0 0 0
43266- 0 0 0 0 0 0 0 0 0 0 0 0
43267- 0 0 0 0 0 0 0 0 0 0 0 0
43268- 0 0 0 0 0 0 0 0 0 0 0 0
43269- 0 0 0 0 0 0 0 0 0 0 0 0
43270- 0 0 0 0 0 0 0 0 0 0 0 0
43271- 0 0 0 0 0 0 0 0 0 0 0 0
43272- 0 0 1 0 0 1 0 0 1 0 0 0
43273- 0 0 0 0 0 0 0 0 0 0 0 0
43274- 0 0 0 0 0 0 0 0 0 0 0 0
43275- 0 0 0 0 0 0 0 0 0 0 0 0
43276- 0 0 0 0 0 0 0 0 0 0 0 0
43277- 0 0 0 0 0 0 0 0 0 14 14 14
43278- 46 46 46 86 86 86 2 2 6 2 2 6
43279- 38 38 38 116 116 116 94 94 94 22 22 22
43280- 22 22 22 2 2 6 2 2 6 2 2 6
43281- 14 14 14 86 86 86 138 138 138 162 162 162
43282-154 154 154 38 38 38 26 26 26 6 6 6
43283- 2 2 6 2 2 6 2 2 6 2 2 6
43284- 86 86 86 46 46 46 14 14 14 0 0 0
43285- 0 0 0 0 0 0 0 0 0 0 0 0
43286- 0 0 0 0 0 0 0 0 0 0 0 0
43287- 0 0 0 0 0 0 0 0 0 0 0 0
43288- 0 0 0 0 0 0 0 0 0 0 0 0
43289- 0 0 0 0 0 0 0 0 0 0 0 0
43290- 0 0 0 0 0 0 0 0 0 0 0 0
43291- 0 0 0 0 0 0 0 0 0 0 0 0
43292- 0 0 0 0 0 0 0 0 0 0 0 0
43293- 0 0 0 0 0 0 0 0 0 0 0 0
43294- 0 0 0 0 0 0 0 0 0 0 0 0
43295- 0 0 0 0 0 0 0 0 0 0 0 0
43296- 0 0 0 0 0 0 0 0 0 0 0 0
43297- 0 0 0 0 0 0 0 0 0 14 14 14
43298- 46 46 46 86 86 86 2 2 6 14 14 14
43299-134 134 134 198 198 198 195 195 195 116 116 116
43300- 10 10 10 2 2 6 2 2 6 6 6 6
43301-101 98 89 187 187 187 210 210 210 218 218 218
43302-214 214 214 134 134 134 14 14 14 6 6 6
43303- 2 2 6 2 2 6 2 2 6 2 2 6
43304- 86 86 86 50 50 50 18 18 18 6 6 6
43305- 0 0 0 0 0 0 0 0 0 0 0 0
43306- 0 0 0 0 0 0 0 0 0 0 0 0
43307- 0 0 0 0 0 0 0 0 0 0 0 0
43308- 0 0 0 0 0 0 0 0 0 0 0 0
43309- 0 0 0 0 0 0 0 0 0 0 0 0
43310- 0 0 0 0 0 0 0 0 0 0 0 0
43311- 0 0 0 0 0 0 0 0 1 0 0 0
43312- 0 0 1 0 0 1 0 0 1 0 0 0
43313- 0 0 0 0 0 0 0 0 0 0 0 0
43314- 0 0 0 0 0 0 0 0 0 0 0 0
43315- 0 0 0 0 0 0 0 0 0 0 0 0
43316- 0 0 0 0 0 0 0 0 0 0 0 0
43317- 0 0 0 0 0 0 0 0 0 14 14 14
43318- 46 46 46 86 86 86 2 2 6 54 54 54
43319-218 218 218 195 195 195 226 226 226 246 246 246
43320- 58 58 58 2 2 6 2 2 6 30 30 30
43321-210 210 210 253 253 253 174 174 174 123 123 123
43322-221 221 221 234 234 234 74 74 74 2 2 6
43323- 2 2 6 2 2 6 2 2 6 2 2 6
43324- 70 70 70 58 58 58 22 22 22 6 6 6
43325- 0 0 0 0 0 0 0 0 0 0 0 0
43326- 0 0 0 0 0 0 0 0 0 0 0 0
43327- 0 0 0 0 0 0 0 0 0 0 0 0
43328- 0 0 0 0 0 0 0 0 0 0 0 0
43329- 0 0 0 0 0 0 0 0 0 0 0 0
43330- 0 0 0 0 0 0 0 0 0 0 0 0
43331- 0 0 0 0 0 0 0 0 0 0 0 0
43332- 0 0 0 0 0 0 0 0 0 0 0 0
43333- 0 0 0 0 0 0 0 0 0 0 0 0
43334- 0 0 0 0 0 0 0 0 0 0 0 0
43335- 0 0 0 0 0 0 0 0 0 0 0 0
43336- 0 0 0 0 0 0 0 0 0 0 0 0
43337- 0 0 0 0 0 0 0 0 0 14 14 14
43338- 46 46 46 82 82 82 2 2 6 106 106 106
43339-170 170 170 26 26 26 86 86 86 226 226 226
43340-123 123 123 10 10 10 14 14 14 46 46 46
43341-231 231 231 190 190 190 6 6 6 70 70 70
43342- 90 90 90 238 238 238 158 158 158 2 2 6
43343- 2 2 6 2 2 6 2 2 6 2 2 6
43344- 70 70 70 58 58 58 22 22 22 6 6 6
43345- 0 0 0 0 0 0 0 0 0 0 0 0
43346- 0 0 0 0 0 0 0 0 0 0 0 0
43347- 0 0 0 0 0 0 0 0 0 0 0 0
43348- 0 0 0 0 0 0 0 0 0 0 0 0
43349- 0 0 0 0 0 0 0 0 0 0 0 0
43350- 0 0 0 0 0 0 0 0 0 0 0 0
43351- 0 0 0 0 0 0 0 0 1 0 0 0
43352- 0 0 1 0 0 1 0 0 1 0 0 0
43353- 0 0 0 0 0 0 0 0 0 0 0 0
43354- 0 0 0 0 0 0 0 0 0 0 0 0
43355- 0 0 0 0 0 0 0 0 0 0 0 0
43356- 0 0 0 0 0 0 0 0 0 0 0 0
43357- 0 0 0 0 0 0 0 0 0 14 14 14
43358- 42 42 42 86 86 86 6 6 6 116 116 116
43359-106 106 106 6 6 6 70 70 70 149 149 149
43360-128 128 128 18 18 18 38 38 38 54 54 54
43361-221 221 221 106 106 106 2 2 6 14 14 14
43362- 46 46 46 190 190 190 198 198 198 2 2 6
43363- 2 2 6 2 2 6 2 2 6 2 2 6
43364- 74 74 74 62 62 62 22 22 22 6 6 6
43365- 0 0 0 0 0 0 0 0 0 0 0 0
43366- 0 0 0 0 0 0 0 0 0 0 0 0
43367- 0 0 0 0 0 0 0 0 0 0 0 0
43368- 0 0 0 0 0 0 0 0 0 0 0 0
43369- 0 0 0 0 0 0 0 0 0 0 0 0
43370- 0 0 0 0 0 0 0 0 0 0 0 0
43371- 0 0 0 0 0 0 0 0 1 0 0 0
43372- 0 0 1 0 0 0 0 0 1 0 0 0
43373- 0 0 0 0 0 0 0 0 0 0 0 0
43374- 0 0 0 0 0 0 0 0 0 0 0 0
43375- 0 0 0 0 0 0 0 0 0 0 0 0
43376- 0 0 0 0 0 0 0 0 0 0 0 0
43377- 0 0 0 0 0 0 0 0 0 14 14 14
43378- 42 42 42 94 94 94 14 14 14 101 101 101
43379-128 128 128 2 2 6 18 18 18 116 116 116
43380-118 98 46 121 92 8 121 92 8 98 78 10
43381-162 162 162 106 106 106 2 2 6 2 2 6
43382- 2 2 6 195 195 195 195 195 195 6 6 6
43383- 2 2 6 2 2 6 2 2 6 2 2 6
43384- 74 74 74 62 62 62 22 22 22 6 6 6
43385- 0 0 0 0 0 0 0 0 0 0 0 0
43386- 0 0 0 0 0 0 0 0 0 0 0 0
43387- 0 0 0 0 0 0 0 0 0 0 0 0
43388- 0 0 0 0 0 0 0 0 0 0 0 0
43389- 0 0 0 0 0 0 0 0 0 0 0 0
43390- 0 0 0 0 0 0 0 0 0 0 0 0
43391- 0 0 0 0 0 0 0 0 1 0 0 1
43392- 0 0 1 0 0 0 0 0 1 0 0 0
43393- 0 0 0 0 0 0 0 0 0 0 0 0
43394- 0 0 0 0 0 0 0 0 0 0 0 0
43395- 0 0 0 0 0 0 0 0 0 0 0 0
43396- 0 0 0 0 0 0 0 0 0 0 0 0
43397- 0 0 0 0 0 0 0 0 0 10 10 10
43398- 38 38 38 90 90 90 14 14 14 58 58 58
43399-210 210 210 26 26 26 54 38 6 154 114 10
43400-226 170 11 236 186 11 225 175 15 184 144 12
43401-215 174 15 175 146 61 37 26 9 2 2 6
43402- 70 70 70 246 246 246 138 138 138 2 2 6
43403- 2 2 6 2 2 6 2 2 6 2 2 6
43404- 70 70 70 66 66 66 26 26 26 6 6 6
43405- 0 0 0 0 0 0 0 0 0 0 0 0
43406- 0 0 0 0 0 0 0 0 0 0 0 0
43407- 0 0 0 0 0 0 0 0 0 0 0 0
43408- 0 0 0 0 0 0 0 0 0 0 0 0
43409- 0 0 0 0 0 0 0 0 0 0 0 0
43410- 0 0 0 0 0 0 0 0 0 0 0 0
43411- 0 0 0 0 0 0 0 0 0 0 0 0
43412- 0 0 0 0 0 0 0 0 0 0 0 0
43413- 0 0 0 0 0 0 0 0 0 0 0 0
43414- 0 0 0 0 0 0 0 0 0 0 0 0
43415- 0 0 0 0 0 0 0 0 0 0 0 0
43416- 0 0 0 0 0 0 0 0 0 0 0 0
43417- 0 0 0 0 0 0 0 0 0 10 10 10
43418- 38 38 38 86 86 86 14 14 14 10 10 10
43419-195 195 195 188 164 115 192 133 9 225 175 15
43420-239 182 13 234 190 10 232 195 16 232 200 30
43421-245 207 45 241 208 19 232 195 16 184 144 12
43422-218 194 134 211 206 186 42 42 42 2 2 6
43423- 2 2 6 2 2 6 2 2 6 2 2 6
43424- 50 50 50 74 74 74 30 30 30 6 6 6
43425- 0 0 0 0 0 0 0 0 0 0 0 0
43426- 0 0 0 0 0 0 0 0 0 0 0 0
43427- 0 0 0 0 0 0 0 0 0 0 0 0
43428- 0 0 0 0 0 0 0 0 0 0 0 0
43429- 0 0 0 0 0 0 0 0 0 0 0 0
43430- 0 0 0 0 0 0 0 0 0 0 0 0
43431- 0 0 0 0 0 0 0 0 0 0 0 0
43432- 0 0 0 0 0 0 0 0 0 0 0 0
43433- 0 0 0 0 0 0 0 0 0 0 0 0
43434- 0 0 0 0 0 0 0 0 0 0 0 0
43435- 0 0 0 0 0 0 0 0 0 0 0 0
43436- 0 0 0 0 0 0 0 0 0 0 0 0
43437- 0 0 0 0 0 0 0 0 0 10 10 10
43438- 34 34 34 86 86 86 14 14 14 2 2 6
43439-121 87 25 192 133 9 219 162 10 239 182 13
43440-236 186 11 232 195 16 241 208 19 244 214 54
43441-246 218 60 246 218 38 246 215 20 241 208 19
43442-241 208 19 226 184 13 121 87 25 2 2 6
43443- 2 2 6 2 2 6 2 2 6 2 2 6
43444- 50 50 50 82 82 82 34 34 34 10 10 10
43445- 0 0 0 0 0 0 0 0 0 0 0 0
43446- 0 0 0 0 0 0 0 0 0 0 0 0
43447- 0 0 0 0 0 0 0 0 0 0 0 0
43448- 0 0 0 0 0 0 0 0 0 0 0 0
43449- 0 0 0 0 0 0 0 0 0 0 0 0
43450- 0 0 0 0 0 0 0 0 0 0 0 0
43451- 0 0 0 0 0 0 0 0 0 0 0 0
43452- 0 0 0 0 0 0 0 0 0 0 0 0
43453- 0 0 0 0 0 0 0 0 0 0 0 0
43454- 0 0 0 0 0 0 0 0 0 0 0 0
43455- 0 0 0 0 0 0 0 0 0 0 0 0
43456- 0 0 0 0 0 0 0 0 0 0 0 0
43457- 0 0 0 0 0 0 0 0 0 10 10 10
43458- 34 34 34 82 82 82 30 30 30 61 42 6
43459-180 123 7 206 145 10 230 174 11 239 182 13
43460-234 190 10 238 202 15 241 208 19 246 218 74
43461-246 218 38 246 215 20 246 215 20 246 215 20
43462-226 184 13 215 174 15 184 144 12 6 6 6
43463- 2 2 6 2 2 6 2 2 6 2 2 6
43464- 26 26 26 94 94 94 42 42 42 14 14 14
43465- 0 0 0 0 0 0 0 0 0 0 0 0
43466- 0 0 0 0 0 0 0 0 0 0 0 0
43467- 0 0 0 0 0 0 0 0 0 0 0 0
43468- 0 0 0 0 0 0 0 0 0 0 0 0
43469- 0 0 0 0 0 0 0 0 0 0 0 0
43470- 0 0 0 0 0 0 0 0 0 0 0 0
43471- 0 0 0 0 0 0 0 0 0 0 0 0
43472- 0 0 0 0 0 0 0 0 0 0 0 0
43473- 0 0 0 0 0 0 0 0 0 0 0 0
43474- 0 0 0 0 0 0 0 0 0 0 0 0
43475- 0 0 0 0 0 0 0 0 0 0 0 0
43476- 0 0 0 0 0 0 0 0 0 0 0 0
43477- 0 0 0 0 0 0 0 0 0 10 10 10
43478- 30 30 30 78 78 78 50 50 50 104 69 6
43479-192 133 9 216 158 10 236 178 12 236 186 11
43480-232 195 16 241 208 19 244 214 54 245 215 43
43481-246 215 20 246 215 20 241 208 19 198 155 10
43482-200 144 11 216 158 10 156 118 10 2 2 6
43483- 2 2 6 2 2 6 2 2 6 2 2 6
43484- 6 6 6 90 90 90 54 54 54 18 18 18
43485- 6 6 6 0 0 0 0 0 0 0 0 0
43486- 0 0 0 0 0 0 0 0 0 0 0 0
43487- 0 0 0 0 0 0 0 0 0 0 0 0
43488- 0 0 0 0 0 0 0 0 0 0 0 0
43489- 0 0 0 0 0 0 0 0 0 0 0 0
43490- 0 0 0 0 0 0 0 0 0 0 0 0
43491- 0 0 0 0 0 0 0 0 0 0 0 0
43492- 0 0 0 0 0 0 0 0 0 0 0 0
43493- 0 0 0 0 0 0 0 0 0 0 0 0
43494- 0 0 0 0 0 0 0 0 0 0 0 0
43495- 0 0 0 0 0 0 0 0 0 0 0 0
43496- 0 0 0 0 0 0 0 0 0 0 0 0
43497- 0 0 0 0 0 0 0 0 0 10 10 10
43498- 30 30 30 78 78 78 46 46 46 22 22 22
43499-137 92 6 210 162 10 239 182 13 238 190 10
43500-238 202 15 241 208 19 246 215 20 246 215 20
43501-241 208 19 203 166 17 185 133 11 210 150 10
43502-216 158 10 210 150 10 102 78 10 2 2 6
43503- 6 6 6 54 54 54 14 14 14 2 2 6
43504- 2 2 6 62 62 62 74 74 74 30 30 30
43505- 10 10 10 0 0 0 0 0 0 0 0 0
43506- 0 0 0 0 0 0 0 0 0 0 0 0
43507- 0 0 0 0 0 0 0 0 0 0 0 0
43508- 0 0 0 0 0 0 0 0 0 0 0 0
43509- 0 0 0 0 0 0 0 0 0 0 0 0
43510- 0 0 0 0 0 0 0 0 0 0 0 0
43511- 0 0 0 0 0 0 0 0 0 0 0 0
43512- 0 0 0 0 0 0 0 0 0 0 0 0
43513- 0 0 0 0 0 0 0 0 0 0 0 0
43514- 0 0 0 0 0 0 0 0 0 0 0 0
43515- 0 0 0 0 0 0 0 0 0 0 0 0
43516- 0 0 0 0 0 0 0 0 0 0 0 0
43517- 0 0 0 0 0 0 0 0 0 10 10 10
43518- 34 34 34 78 78 78 50 50 50 6 6 6
43519- 94 70 30 139 102 15 190 146 13 226 184 13
43520-232 200 30 232 195 16 215 174 15 190 146 13
43521-168 122 10 192 133 9 210 150 10 213 154 11
43522-202 150 34 182 157 106 101 98 89 2 2 6
43523- 2 2 6 78 78 78 116 116 116 58 58 58
43524- 2 2 6 22 22 22 90 90 90 46 46 46
43525- 18 18 18 6 6 6 0 0 0 0 0 0
43526- 0 0 0 0 0 0 0 0 0 0 0 0
43527- 0 0 0 0 0 0 0 0 0 0 0 0
43528- 0 0 0 0 0 0 0 0 0 0 0 0
43529- 0 0 0 0 0 0 0 0 0 0 0 0
43530- 0 0 0 0 0 0 0 0 0 0 0 0
43531- 0 0 0 0 0 0 0 0 0 0 0 0
43532- 0 0 0 0 0 0 0 0 0 0 0 0
43533- 0 0 0 0 0 0 0 0 0 0 0 0
43534- 0 0 0 0 0 0 0 0 0 0 0 0
43535- 0 0 0 0 0 0 0 0 0 0 0 0
43536- 0 0 0 0 0 0 0 0 0 0 0 0
43537- 0 0 0 0 0 0 0 0 0 10 10 10
43538- 38 38 38 86 86 86 50 50 50 6 6 6
43539-128 128 128 174 154 114 156 107 11 168 122 10
43540-198 155 10 184 144 12 197 138 11 200 144 11
43541-206 145 10 206 145 10 197 138 11 188 164 115
43542-195 195 195 198 198 198 174 174 174 14 14 14
43543- 2 2 6 22 22 22 116 116 116 116 116 116
43544- 22 22 22 2 2 6 74 74 74 70 70 70
43545- 30 30 30 10 10 10 0 0 0 0 0 0
43546- 0 0 0 0 0 0 0 0 0 0 0 0
43547- 0 0 0 0 0 0 0 0 0 0 0 0
43548- 0 0 0 0 0 0 0 0 0 0 0 0
43549- 0 0 0 0 0 0 0 0 0 0 0 0
43550- 0 0 0 0 0 0 0 0 0 0 0 0
43551- 0 0 0 0 0 0 0 0 0 0 0 0
43552- 0 0 0 0 0 0 0 0 0 0 0 0
43553- 0 0 0 0 0 0 0 0 0 0 0 0
43554- 0 0 0 0 0 0 0 0 0 0 0 0
43555- 0 0 0 0 0 0 0 0 0 0 0 0
43556- 0 0 0 0 0 0 0 0 0 0 0 0
43557- 0 0 0 0 0 0 6 6 6 18 18 18
43558- 50 50 50 101 101 101 26 26 26 10 10 10
43559-138 138 138 190 190 190 174 154 114 156 107 11
43560-197 138 11 200 144 11 197 138 11 192 133 9
43561-180 123 7 190 142 34 190 178 144 187 187 187
43562-202 202 202 221 221 221 214 214 214 66 66 66
43563- 2 2 6 2 2 6 50 50 50 62 62 62
43564- 6 6 6 2 2 6 10 10 10 90 90 90
43565- 50 50 50 18 18 18 6 6 6 0 0 0
43566- 0 0 0 0 0 0 0 0 0 0 0 0
43567- 0 0 0 0 0 0 0 0 0 0 0 0
43568- 0 0 0 0 0 0 0 0 0 0 0 0
43569- 0 0 0 0 0 0 0 0 0 0 0 0
43570- 0 0 0 0 0 0 0 0 0 0 0 0
43571- 0 0 0 0 0 0 0 0 0 0 0 0
43572- 0 0 0 0 0 0 0 0 0 0 0 0
43573- 0 0 0 0 0 0 0 0 0 0 0 0
43574- 0 0 0 0 0 0 0 0 0 0 0 0
43575- 0 0 0 0 0 0 0 0 0 0 0 0
43576- 0 0 0 0 0 0 0 0 0 0 0 0
43577- 0 0 0 0 0 0 10 10 10 34 34 34
43578- 74 74 74 74 74 74 2 2 6 6 6 6
43579-144 144 144 198 198 198 190 190 190 178 166 146
43580-154 121 60 156 107 11 156 107 11 168 124 44
43581-174 154 114 187 187 187 190 190 190 210 210 210
43582-246 246 246 253 253 253 253 253 253 182 182 182
43583- 6 6 6 2 2 6 2 2 6 2 2 6
43584- 2 2 6 2 2 6 2 2 6 62 62 62
43585- 74 74 74 34 34 34 14 14 14 0 0 0
43586- 0 0 0 0 0 0 0 0 0 0 0 0
43587- 0 0 0 0 0 0 0 0 0 0 0 0
43588- 0 0 0 0 0 0 0 0 0 0 0 0
43589- 0 0 0 0 0 0 0 0 0 0 0 0
43590- 0 0 0 0 0 0 0 0 0 0 0 0
43591- 0 0 0 0 0 0 0 0 0 0 0 0
43592- 0 0 0 0 0 0 0 0 0 0 0 0
43593- 0 0 0 0 0 0 0 0 0 0 0 0
43594- 0 0 0 0 0 0 0 0 0 0 0 0
43595- 0 0 0 0 0 0 0 0 0 0 0 0
43596- 0 0 0 0 0 0 0 0 0 0 0 0
43597- 0 0 0 10 10 10 22 22 22 54 54 54
43598- 94 94 94 18 18 18 2 2 6 46 46 46
43599-234 234 234 221 221 221 190 190 190 190 190 190
43600-190 190 190 187 187 187 187 187 187 190 190 190
43601-190 190 190 195 195 195 214 214 214 242 242 242
43602-253 253 253 253 253 253 253 253 253 253 253 253
43603- 82 82 82 2 2 6 2 2 6 2 2 6
43604- 2 2 6 2 2 6 2 2 6 14 14 14
43605- 86 86 86 54 54 54 22 22 22 6 6 6
43606- 0 0 0 0 0 0 0 0 0 0 0 0
43607- 0 0 0 0 0 0 0 0 0 0 0 0
43608- 0 0 0 0 0 0 0 0 0 0 0 0
43609- 0 0 0 0 0 0 0 0 0 0 0 0
43610- 0 0 0 0 0 0 0 0 0 0 0 0
43611- 0 0 0 0 0 0 0 0 0 0 0 0
43612- 0 0 0 0 0 0 0 0 0 0 0 0
43613- 0 0 0 0 0 0 0 0 0 0 0 0
43614- 0 0 0 0 0 0 0 0 0 0 0 0
43615- 0 0 0 0 0 0 0 0 0 0 0 0
43616- 0 0 0 0 0 0 0 0 0 0 0 0
43617- 6 6 6 18 18 18 46 46 46 90 90 90
43618- 46 46 46 18 18 18 6 6 6 182 182 182
43619-253 253 253 246 246 246 206 206 206 190 190 190
43620-190 190 190 190 190 190 190 190 190 190 190 190
43621-206 206 206 231 231 231 250 250 250 253 253 253
43622-253 253 253 253 253 253 253 253 253 253 253 253
43623-202 202 202 14 14 14 2 2 6 2 2 6
43624- 2 2 6 2 2 6 2 2 6 2 2 6
43625- 42 42 42 86 86 86 42 42 42 18 18 18
43626- 6 6 6 0 0 0 0 0 0 0 0 0
43627- 0 0 0 0 0 0 0 0 0 0 0 0
43628- 0 0 0 0 0 0 0 0 0 0 0 0
43629- 0 0 0 0 0 0 0 0 0 0 0 0
43630- 0 0 0 0 0 0 0 0 0 0 0 0
43631- 0 0 0 0 0 0 0 0 0 0 0 0
43632- 0 0 0 0 0 0 0 0 0 0 0 0
43633- 0 0 0 0 0 0 0 0 0 0 0 0
43634- 0 0 0 0 0 0 0 0 0 0 0 0
43635- 0 0 0 0 0 0 0 0 0 0 0 0
43636- 0 0 0 0 0 0 0 0 0 6 6 6
43637- 14 14 14 38 38 38 74 74 74 66 66 66
43638- 2 2 6 6 6 6 90 90 90 250 250 250
43639-253 253 253 253 253 253 238 238 238 198 198 198
43640-190 190 190 190 190 190 195 195 195 221 221 221
43641-246 246 246 253 253 253 253 253 253 253 253 253
43642-253 253 253 253 253 253 253 253 253 253 253 253
43643-253 253 253 82 82 82 2 2 6 2 2 6
43644- 2 2 6 2 2 6 2 2 6 2 2 6
43645- 2 2 6 78 78 78 70 70 70 34 34 34
43646- 14 14 14 6 6 6 0 0 0 0 0 0
43647- 0 0 0 0 0 0 0 0 0 0 0 0
43648- 0 0 0 0 0 0 0 0 0 0 0 0
43649- 0 0 0 0 0 0 0 0 0 0 0 0
43650- 0 0 0 0 0 0 0 0 0 0 0 0
43651- 0 0 0 0 0 0 0 0 0 0 0 0
43652- 0 0 0 0 0 0 0 0 0 0 0 0
43653- 0 0 0 0 0 0 0 0 0 0 0 0
43654- 0 0 0 0 0 0 0 0 0 0 0 0
43655- 0 0 0 0 0 0 0 0 0 0 0 0
43656- 0 0 0 0 0 0 0 0 0 14 14 14
43657- 34 34 34 66 66 66 78 78 78 6 6 6
43658- 2 2 6 18 18 18 218 218 218 253 253 253
43659-253 253 253 253 253 253 253 253 253 246 246 246
43660-226 226 226 231 231 231 246 246 246 253 253 253
43661-253 253 253 253 253 253 253 253 253 253 253 253
43662-253 253 253 253 253 253 253 253 253 253 253 253
43663-253 253 253 178 178 178 2 2 6 2 2 6
43664- 2 2 6 2 2 6 2 2 6 2 2 6
43665- 2 2 6 18 18 18 90 90 90 62 62 62
43666- 30 30 30 10 10 10 0 0 0 0 0 0
43667- 0 0 0 0 0 0 0 0 0 0 0 0
43668- 0 0 0 0 0 0 0 0 0 0 0 0
43669- 0 0 0 0 0 0 0 0 0 0 0 0
43670- 0 0 0 0 0 0 0 0 0 0 0 0
43671- 0 0 0 0 0 0 0 0 0 0 0 0
43672- 0 0 0 0 0 0 0 0 0 0 0 0
43673- 0 0 0 0 0 0 0 0 0 0 0 0
43674- 0 0 0 0 0 0 0 0 0 0 0 0
43675- 0 0 0 0 0 0 0 0 0 0 0 0
43676- 0 0 0 0 0 0 10 10 10 26 26 26
43677- 58 58 58 90 90 90 18 18 18 2 2 6
43678- 2 2 6 110 110 110 253 253 253 253 253 253
43679-253 253 253 253 253 253 253 253 253 253 253 253
43680-250 250 250 253 253 253 253 253 253 253 253 253
43681-253 253 253 253 253 253 253 253 253 253 253 253
43682-253 253 253 253 253 253 253 253 253 253 253 253
43683-253 253 253 231 231 231 18 18 18 2 2 6
43684- 2 2 6 2 2 6 2 2 6 2 2 6
43685- 2 2 6 2 2 6 18 18 18 94 94 94
43686- 54 54 54 26 26 26 10 10 10 0 0 0
43687- 0 0 0 0 0 0 0 0 0 0 0 0
43688- 0 0 0 0 0 0 0 0 0 0 0 0
43689- 0 0 0 0 0 0 0 0 0 0 0 0
43690- 0 0 0 0 0 0 0 0 0 0 0 0
43691- 0 0 0 0 0 0 0 0 0 0 0 0
43692- 0 0 0 0 0 0 0 0 0 0 0 0
43693- 0 0 0 0 0 0 0 0 0 0 0 0
43694- 0 0 0 0 0 0 0 0 0 0 0 0
43695- 0 0 0 0 0 0 0 0 0 0 0 0
43696- 0 0 0 6 6 6 22 22 22 50 50 50
43697- 90 90 90 26 26 26 2 2 6 2 2 6
43698- 14 14 14 195 195 195 250 250 250 253 253 253
43699-253 253 253 253 253 253 253 253 253 253 253 253
43700-253 253 253 253 253 253 253 253 253 253 253 253
43701-253 253 253 253 253 253 253 253 253 253 253 253
43702-253 253 253 253 253 253 253 253 253 253 253 253
43703-250 250 250 242 242 242 54 54 54 2 2 6
43704- 2 2 6 2 2 6 2 2 6 2 2 6
43705- 2 2 6 2 2 6 2 2 6 38 38 38
43706- 86 86 86 50 50 50 22 22 22 6 6 6
43707- 0 0 0 0 0 0 0 0 0 0 0 0
43708- 0 0 0 0 0 0 0 0 0 0 0 0
43709- 0 0 0 0 0 0 0 0 0 0 0 0
43710- 0 0 0 0 0 0 0 0 0 0 0 0
43711- 0 0 0 0 0 0 0 0 0 0 0 0
43712- 0 0 0 0 0 0 0 0 0 0 0 0
43713- 0 0 0 0 0 0 0 0 0 0 0 0
43714- 0 0 0 0 0 0 0 0 0 0 0 0
43715- 0 0 0 0 0 0 0 0 0 0 0 0
43716- 6 6 6 14 14 14 38 38 38 82 82 82
43717- 34 34 34 2 2 6 2 2 6 2 2 6
43718- 42 42 42 195 195 195 246 246 246 253 253 253
43719-253 253 253 253 253 253 253 253 253 250 250 250
43720-242 242 242 242 242 242 250 250 250 253 253 253
43721-253 253 253 253 253 253 253 253 253 253 253 253
43722-253 253 253 250 250 250 246 246 246 238 238 238
43723-226 226 226 231 231 231 101 101 101 6 6 6
43724- 2 2 6 2 2 6 2 2 6 2 2 6
43725- 2 2 6 2 2 6 2 2 6 2 2 6
43726- 38 38 38 82 82 82 42 42 42 14 14 14
43727- 6 6 6 0 0 0 0 0 0 0 0 0
43728- 0 0 0 0 0 0 0 0 0 0 0 0
43729- 0 0 0 0 0 0 0 0 0 0 0 0
43730- 0 0 0 0 0 0 0 0 0 0 0 0
43731- 0 0 0 0 0 0 0 0 0 0 0 0
43732- 0 0 0 0 0 0 0 0 0 0 0 0
43733- 0 0 0 0 0 0 0 0 0 0 0 0
43734- 0 0 0 0 0 0 0 0 0 0 0 0
43735- 0 0 0 0 0 0 0 0 0 0 0 0
43736- 10 10 10 26 26 26 62 62 62 66 66 66
43737- 2 2 6 2 2 6 2 2 6 6 6 6
43738- 70 70 70 170 170 170 206 206 206 234 234 234
43739-246 246 246 250 250 250 250 250 250 238 238 238
43740-226 226 226 231 231 231 238 238 238 250 250 250
43741-250 250 250 250 250 250 246 246 246 231 231 231
43742-214 214 214 206 206 206 202 202 202 202 202 202
43743-198 198 198 202 202 202 182 182 182 18 18 18
43744- 2 2 6 2 2 6 2 2 6 2 2 6
43745- 2 2 6 2 2 6 2 2 6 2 2 6
43746- 2 2 6 62 62 62 66 66 66 30 30 30
43747- 10 10 10 0 0 0 0 0 0 0 0 0
43748- 0 0 0 0 0 0 0 0 0 0 0 0
43749- 0 0 0 0 0 0 0 0 0 0 0 0
43750- 0 0 0 0 0 0 0 0 0 0 0 0
43751- 0 0 0 0 0 0 0 0 0 0 0 0
43752- 0 0 0 0 0 0 0 0 0 0 0 0
43753- 0 0 0 0 0 0 0 0 0 0 0 0
43754- 0 0 0 0 0 0 0 0 0 0 0 0
43755- 0 0 0 0 0 0 0 0 0 0 0 0
43756- 14 14 14 42 42 42 82 82 82 18 18 18
43757- 2 2 6 2 2 6 2 2 6 10 10 10
43758- 94 94 94 182 182 182 218 218 218 242 242 242
43759-250 250 250 253 253 253 253 253 253 250 250 250
43760-234 234 234 253 253 253 253 253 253 253 253 253
43761-253 253 253 253 253 253 253 253 253 246 246 246
43762-238 238 238 226 226 226 210 210 210 202 202 202
43763-195 195 195 195 195 195 210 210 210 158 158 158
43764- 6 6 6 14 14 14 50 50 50 14 14 14
43765- 2 2 6 2 2 6 2 2 6 2 2 6
43766- 2 2 6 6 6 6 86 86 86 46 46 46
43767- 18 18 18 6 6 6 0 0 0 0 0 0
43768- 0 0 0 0 0 0 0 0 0 0 0 0
43769- 0 0 0 0 0 0 0 0 0 0 0 0
43770- 0 0 0 0 0 0 0 0 0 0 0 0
43771- 0 0 0 0 0 0 0 0 0 0 0 0
43772- 0 0 0 0 0 0 0 0 0 0 0 0
43773- 0 0 0 0 0 0 0 0 0 0 0 0
43774- 0 0 0 0 0 0 0 0 0 0 0 0
43775- 0 0 0 0 0 0 0 0 0 6 6 6
43776- 22 22 22 54 54 54 70 70 70 2 2 6
43777- 2 2 6 10 10 10 2 2 6 22 22 22
43778-166 166 166 231 231 231 250 250 250 253 253 253
43779-253 253 253 253 253 253 253 253 253 250 250 250
43780-242 242 242 253 253 253 253 253 253 253 253 253
43781-253 253 253 253 253 253 253 253 253 253 253 253
43782-253 253 253 253 253 253 253 253 253 246 246 246
43783-231 231 231 206 206 206 198 198 198 226 226 226
43784- 94 94 94 2 2 6 6 6 6 38 38 38
43785- 30 30 30 2 2 6 2 2 6 2 2 6
43786- 2 2 6 2 2 6 62 62 62 66 66 66
43787- 26 26 26 10 10 10 0 0 0 0 0 0
43788- 0 0 0 0 0 0 0 0 0 0 0 0
43789- 0 0 0 0 0 0 0 0 0 0 0 0
43790- 0 0 0 0 0 0 0 0 0 0 0 0
43791- 0 0 0 0 0 0 0 0 0 0 0 0
43792- 0 0 0 0 0 0 0 0 0 0 0 0
43793- 0 0 0 0 0 0 0 0 0 0 0 0
43794- 0 0 0 0 0 0 0 0 0 0 0 0
43795- 0 0 0 0 0 0 0 0 0 10 10 10
43796- 30 30 30 74 74 74 50 50 50 2 2 6
43797- 26 26 26 26 26 26 2 2 6 106 106 106
43798-238 238 238 253 253 253 253 253 253 253 253 253
43799-253 253 253 253 253 253 253 253 253 253 253 253
43800-253 253 253 253 253 253 253 253 253 253 253 253
43801-253 253 253 253 253 253 253 253 253 253 253 253
43802-253 253 253 253 253 253 253 253 253 253 253 253
43803-253 253 253 246 246 246 218 218 218 202 202 202
43804-210 210 210 14 14 14 2 2 6 2 2 6
43805- 30 30 30 22 22 22 2 2 6 2 2 6
43806- 2 2 6 2 2 6 18 18 18 86 86 86
43807- 42 42 42 14 14 14 0 0 0 0 0 0
43808- 0 0 0 0 0 0 0 0 0 0 0 0
43809- 0 0 0 0 0 0 0 0 0 0 0 0
43810- 0 0 0 0 0 0 0 0 0 0 0 0
43811- 0 0 0 0 0 0 0 0 0 0 0 0
43812- 0 0 0 0 0 0 0 0 0 0 0 0
43813- 0 0 0 0 0 0 0 0 0 0 0 0
43814- 0 0 0 0 0 0 0 0 0 0 0 0
43815- 0 0 0 0 0 0 0 0 0 14 14 14
43816- 42 42 42 90 90 90 22 22 22 2 2 6
43817- 42 42 42 2 2 6 18 18 18 218 218 218
43818-253 253 253 253 253 253 253 253 253 253 253 253
43819-253 253 253 253 253 253 253 253 253 253 253 253
43820-253 253 253 253 253 253 253 253 253 253 253 253
43821-253 253 253 253 253 253 253 253 253 253 253 253
43822-253 253 253 253 253 253 253 253 253 253 253 253
43823-253 253 253 253 253 253 250 250 250 221 221 221
43824-218 218 218 101 101 101 2 2 6 14 14 14
43825- 18 18 18 38 38 38 10 10 10 2 2 6
43826- 2 2 6 2 2 6 2 2 6 78 78 78
43827- 58 58 58 22 22 22 6 6 6 0 0 0
43828- 0 0 0 0 0 0 0 0 0 0 0 0
43829- 0 0 0 0 0 0 0 0 0 0 0 0
43830- 0 0 0 0 0 0 0 0 0 0 0 0
43831- 0 0 0 0 0 0 0 0 0 0 0 0
43832- 0 0 0 0 0 0 0 0 0 0 0 0
43833- 0 0 0 0 0 0 0 0 0 0 0 0
43834- 0 0 0 0 0 0 0 0 0 0 0 0
43835- 0 0 0 0 0 0 6 6 6 18 18 18
43836- 54 54 54 82 82 82 2 2 6 26 26 26
43837- 22 22 22 2 2 6 123 123 123 253 253 253
43838-253 253 253 253 253 253 253 253 253 253 253 253
43839-253 253 253 253 253 253 253 253 253 253 253 253
43840-253 253 253 253 253 253 253 253 253 253 253 253
43841-253 253 253 253 253 253 253 253 253 253 253 253
43842-253 253 253 253 253 253 253 253 253 253 253 253
43843-253 253 253 253 253 253 253 253 253 250 250 250
43844-238 238 238 198 198 198 6 6 6 38 38 38
43845- 58 58 58 26 26 26 38 38 38 2 2 6
43846- 2 2 6 2 2 6 2 2 6 46 46 46
43847- 78 78 78 30 30 30 10 10 10 0 0 0
43848- 0 0 0 0 0 0 0 0 0 0 0 0
43849- 0 0 0 0 0 0 0 0 0 0 0 0
43850- 0 0 0 0 0 0 0 0 0 0 0 0
43851- 0 0 0 0 0 0 0 0 0 0 0 0
43852- 0 0 0 0 0 0 0 0 0 0 0 0
43853- 0 0 0 0 0 0 0 0 0 0 0 0
43854- 0 0 0 0 0 0 0 0 0 0 0 0
43855- 0 0 0 0 0 0 10 10 10 30 30 30
43856- 74 74 74 58 58 58 2 2 6 42 42 42
43857- 2 2 6 22 22 22 231 231 231 253 253 253
43858-253 253 253 253 253 253 253 253 253 253 253 253
43859-253 253 253 253 253 253 253 253 253 250 250 250
43860-253 253 253 253 253 253 253 253 253 253 253 253
43861-253 253 253 253 253 253 253 253 253 253 253 253
43862-253 253 253 253 253 253 253 253 253 253 253 253
43863-253 253 253 253 253 253 253 253 253 253 253 253
43864-253 253 253 246 246 246 46 46 46 38 38 38
43865- 42 42 42 14 14 14 38 38 38 14 14 14
43866- 2 2 6 2 2 6 2 2 6 6 6 6
43867- 86 86 86 46 46 46 14 14 14 0 0 0
43868- 0 0 0 0 0 0 0 0 0 0 0 0
43869- 0 0 0 0 0 0 0 0 0 0 0 0
43870- 0 0 0 0 0 0 0 0 0 0 0 0
43871- 0 0 0 0 0 0 0 0 0 0 0 0
43872- 0 0 0 0 0 0 0 0 0 0 0 0
43873- 0 0 0 0 0 0 0 0 0 0 0 0
43874- 0 0 0 0 0 0 0 0 0 0 0 0
43875- 0 0 0 6 6 6 14 14 14 42 42 42
43876- 90 90 90 18 18 18 18 18 18 26 26 26
43877- 2 2 6 116 116 116 253 253 253 253 253 253
43878-253 253 253 253 253 253 253 253 253 253 253 253
43879-253 253 253 253 253 253 250 250 250 238 238 238
43880-253 253 253 253 253 253 253 253 253 253 253 253
43881-253 253 253 253 253 253 253 253 253 253 253 253
43882-253 253 253 253 253 253 253 253 253 253 253 253
43883-253 253 253 253 253 253 253 253 253 253 253 253
43884-253 253 253 253 253 253 94 94 94 6 6 6
43885- 2 2 6 2 2 6 10 10 10 34 34 34
43886- 2 2 6 2 2 6 2 2 6 2 2 6
43887- 74 74 74 58 58 58 22 22 22 6 6 6
43888- 0 0 0 0 0 0 0 0 0 0 0 0
43889- 0 0 0 0 0 0 0 0 0 0 0 0
43890- 0 0 0 0 0 0 0 0 0 0 0 0
43891- 0 0 0 0 0 0 0 0 0 0 0 0
43892- 0 0 0 0 0 0 0 0 0 0 0 0
43893- 0 0 0 0 0 0 0 0 0 0 0 0
43894- 0 0 0 0 0 0 0 0 0 0 0 0
43895- 0 0 0 10 10 10 26 26 26 66 66 66
43896- 82 82 82 2 2 6 38 38 38 6 6 6
43897- 14 14 14 210 210 210 253 253 253 253 253 253
43898-253 253 253 253 253 253 253 253 253 253 253 253
43899-253 253 253 253 253 253 246 246 246 242 242 242
43900-253 253 253 253 253 253 253 253 253 253 253 253
43901-253 253 253 253 253 253 253 253 253 253 253 253
43902-253 253 253 253 253 253 253 253 253 253 253 253
43903-253 253 253 253 253 253 253 253 253 253 253 253
43904-253 253 253 253 253 253 144 144 144 2 2 6
43905- 2 2 6 2 2 6 2 2 6 46 46 46
43906- 2 2 6 2 2 6 2 2 6 2 2 6
43907- 42 42 42 74 74 74 30 30 30 10 10 10
43908- 0 0 0 0 0 0 0 0 0 0 0 0
43909- 0 0 0 0 0 0 0 0 0 0 0 0
43910- 0 0 0 0 0 0 0 0 0 0 0 0
43911- 0 0 0 0 0 0 0 0 0 0 0 0
43912- 0 0 0 0 0 0 0 0 0 0 0 0
43913- 0 0 0 0 0 0 0 0 0 0 0 0
43914- 0 0 0 0 0 0 0 0 0 0 0 0
43915- 6 6 6 14 14 14 42 42 42 90 90 90
43916- 26 26 26 6 6 6 42 42 42 2 2 6
43917- 74 74 74 250 250 250 253 253 253 253 253 253
43918-253 253 253 253 253 253 253 253 253 253 253 253
43919-253 253 253 253 253 253 242 242 242 242 242 242
43920-253 253 253 253 253 253 253 253 253 253 253 253
43921-253 253 253 253 253 253 253 253 253 253 253 253
43922-253 253 253 253 253 253 253 253 253 253 253 253
43923-253 253 253 253 253 253 253 253 253 253 253 253
43924-253 253 253 253 253 253 182 182 182 2 2 6
43925- 2 2 6 2 2 6 2 2 6 46 46 46
43926- 2 2 6 2 2 6 2 2 6 2 2 6
43927- 10 10 10 86 86 86 38 38 38 10 10 10
43928- 0 0 0 0 0 0 0 0 0 0 0 0
43929- 0 0 0 0 0 0 0 0 0 0 0 0
43930- 0 0 0 0 0 0 0 0 0 0 0 0
43931- 0 0 0 0 0 0 0 0 0 0 0 0
43932- 0 0 0 0 0 0 0 0 0 0 0 0
43933- 0 0 0 0 0 0 0 0 0 0 0 0
43934- 0 0 0 0 0 0 0 0 0 0 0 0
43935- 10 10 10 26 26 26 66 66 66 82 82 82
43936- 2 2 6 22 22 22 18 18 18 2 2 6
43937-149 149 149 253 253 253 253 253 253 253 253 253
43938-253 253 253 253 253 253 253 253 253 253 253 253
43939-253 253 253 253 253 253 234 234 234 242 242 242
43940-253 253 253 253 253 253 253 253 253 253 253 253
43941-253 253 253 253 253 253 253 253 253 253 253 253
43942-253 253 253 253 253 253 253 253 253 253 253 253
43943-253 253 253 253 253 253 253 253 253 253 253 253
43944-253 253 253 253 253 253 206 206 206 2 2 6
43945- 2 2 6 2 2 6 2 2 6 38 38 38
43946- 2 2 6 2 2 6 2 2 6 2 2 6
43947- 6 6 6 86 86 86 46 46 46 14 14 14
43948- 0 0 0 0 0 0 0 0 0 0 0 0
43949- 0 0 0 0 0 0 0 0 0 0 0 0
43950- 0 0 0 0 0 0 0 0 0 0 0 0
43951- 0 0 0 0 0 0 0 0 0 0 0 0
43952- 0 0 0 0 0 0 0 0 0 0 0 0
43953- 0 0 0 0 0 0 0 0 0 0 0 0
43954- 0 0 0 0 0 0 0 0 0 6 6 6
43955- 18 18 18 46 46 46 86 86 86 18 18 18
43956- 2 2 6 34 34 34 10 10 10 6 6 6
43957-210 210 210 253 253 253 253 253 253 253 253 253
43958-253 253 253 253 253 253 253 253 253 253 253 253
43959-253 253 253 253 253 253 234 234 234 242 242 242
43960-253 253 253 253 253 253 253 253 253 253 253 253
43961-253 253 253 253 253 253 253 253 253 253 253 253
43962-253 253 253 253 253 253 253 253 253 253 253 253
43963-253 253 253 253 253 253 253 253 253 253 253 253
43964-253 253 253 253 253 253 221 221 221 6 6 6
43965- 2 2 6 2 2 6 6 6 6 30 30 30
43966- 2 2 6 2 2 6 2 2 6 2 2 6
43967- 2 2 6 82 82 82 54 54 54 18 18 18
43968- 6 6 6 0 0 0 0 0 0 0 0 0
43969- 0 0 0 0 0 0 0 0 0 0 0 0
43970- 0 0 0 0 0 0 0 0 0 0 0 0
43971- 0 0 0 0 0 0 0 0 0 0 0 0
43972- 0 0 0 0 0 0 0 0 0 0 0 0
43973- 0 0 0 0 0 0 0 0 0 0 0 0
43974- 0 0 0 0 0 0 0 0 0 10 10 10
43975- 26 26 26 66 66 66 62 62 62 2 2 6
43976- 2 2 6 38 38 38 10 10 10 26 26 26
43977-238 238 238 253 253 253 253 253 253 253 253 253
43978-253 253 253 253 253 253 253 253 253 253 253 253
43979-253 253 253 253 253 253 231 231 231 238 238 238
43980-253 253 253 253 253 253 253 253 253 253 253 253
43981-253 253 253 253 253 253 253 253 253 253 253 253
43982-253 253 253 253 253 253 253 253 253 253 253 253
43983-253 253 253 253 253 253 253 253 253 253 253 253
43984-253 253 253 253 253 253 231 231 231 6 6 6
43985- 2 2 6 2 2 6 10 10 10 30 30 30
43986- 2 2 6 2 2 6 2 2 6 2 2 6
43987- 2 2 6 66 66 66 58 58 58 22 22 22
43988- 6 6 6 0 0 0 0 0 0 0 0 0
43989- 0 0 0 0 0 0 0 0 0 0 0 0
43990- 0 0 0 0 0 0 0 0 0 0 0 0
43991- 0 0 0 0 0 0 0 0 0 0 0 0
43992- 0 0 0 0 0 0 0 0 0 0 0 0
43993- 0 0 0 0 0 0 0 0 0 0 0 0
43994- 0 0 0 0 0 0 0 0 0 10 10 10
43995- 38 38 38 78 78 78 6 6 6 2 2 6
43996- 2 2 6 46 46 46 14 14 14 42 42 42
43997-246 246 246 253 253 253 253 253 253 253 253 253
43998-253 253 253 253 253 253 253 253 253 253 253 253
43999-253 253 253 253 253 253 231 231 231 242 242 242
44000-253 253 253 253 253 253 253 253 253 253 253 253
44001-253 253 253 253 253 253 253 253 253 253 253 253
44002-253 253 253 253 253 253 253 253 253 253 253 253
44003-253 253 253 253 253 253 253 253 253 253 253 253
44004-253 253 253 253 253 253 234 234 234 10 10 10
44005- 2 2 6 2 2 6 22 22 22 14 14 14
44006- 2 2 6 2 2 6 2 2 6 2 2 6
44007- 2 2 6 66 66 66 62 62 62 22 22 22
44008- 6 6 6 0 0 0 0 0 0 0 0 0
44009- 0 0 0 0 0 0 0 0 0 0 0 0
44010- 0 0 0 0 0 0 0 0 0 0 0 0
44011- 0 0 0 0 0 0 0 0 0 0 0 0
44012- 0 0 0 0 0 0 0 0 0 0 0 0
44013- 0 0 0 0 0 0 0 0 0 0 0 0
44014- 0 0 0 0 0 0 6 6 6 18 18 18
44015- 50 50 50 74 74 74 2 2 6 2 2 6
44016- 14 14 14 70 70 70 34 34 34 62 62 62
44017-250 250 250 253 253 253 253 253 253 253 253 253
44018-253 253 253 253 253 253 253 253 253 253 253 253
44019-253 253 253 253 253 253 231 231 231 246 246 246
44020-253 253 253 253 253 253 253 253 253 253 253 253
44021-253 253 253 253 253 253 253 253 253 253 253 253
44022-253 253 253 253 253 253 253 253 253 253 253 253
44023-253 253 253 253 253 253 253 253 253 253 253 253
44024-253 253 253 253 253 253 234 234 234 14 14 14
44025- 2 2 6 2 2 6 30 30 30 2 2 6
44026- 2 2 6 2 2 6 2 2 6 2 2 6
44027- 2 2 6 66 66 66 62 62 62 22 22 22
44028- 6 6 6 0 0 0 0 0 0 0 0 0
44029- 0 0 0 0 0 0 0 0 0 0 0 0
44030- 0 0 0 0 0 0 0 0 0 0 0 0
44031- 0 0 0 0 0 0 0 0 0 0 0 0
44032- 0 0 0 0 0 0 0 0 0 0 0 0
44033- 0 0 0 0 0 0 0 0 0 0 0 0
44034- 0 0 0 0 0 0 6 6 6 18 18 18
44035- 54 54 54 62 62 62 2 2 6 2 2 6
44036- 2 2 6 30 30 30 46 46 46 70 70 70
44037-250 250 250 253 253 253 253 253 253 253 253 253
44038-253 253 253 253 253 253 253 253 253 253 253 253
44039-253 253 253 253 253 253 231 231 231 246 246 246
44040-253 253 253 253 253 253 253 253 253 253 253 253
44041-253 253 253 253 253 253 253 253 253 253 253 253
44042-253 253 253 253 253 253 253 253 253 253 253 253
44043-253 253 253 253 253 253 253 253 253 253 253 253
44044-253 253 253 253 253 253 226 226 226 10 10 10
44045- 2 2 6 6 6 6 30 30 30 2 2 6
44046- 2 2 6 2 2 6 2 2 6 2 2 6
44047- 2 2 6 66 66 66 58 58 58 22 22 22
44048- 6 6 6 0 0 0 0 0 0 0 0 0
44049- 0 0 0 0 0 0 0 0 0 0 0 0
44050- 0 0 0 0 0 0 0 0 0 0 0 0
44051- 0 0 0 0 0 0 0 0 0 0 0 0
44052- 0 0 0 0 0 0 0 0 0 0 0 0
44053- 0 0 0 0 0 0 0 0 0 0 0 0
44054- 0 0 0 0 0 0 6 6 6 22 22 22
44055- 58 58 58 62 62 62 2 2 6 2 2 6
44056- 2 2 6 2 2 6 30 30 30 78 78 78
44057-250 250 250 253 253 253 253 253 253 253 253 253
44058-253 253 253 253 253 253 253 253 253 253 253 253
44059-253 253 253 253 253 253 231 231 231 246 246 246
44060-253 253 253 253 253 253 253 253 253 253 253 253
44061-253 253 253 253 253 253 253 253 253 253 253 253
44062-253 253 253 253 253 253 253 253 253 253 253 253
44063-253 253 253 253 253 253 253 253 253 253 253 253
44064-253 253 253 253 253 253 206 206 206 2 2 6
44065- 22 22 22 34 34 34 18 14 6 22 22 22
44066- 26 26 26 18 18 18 6 6 6 2 2 6
44067- 2 2 6 82 82 82 54 54 54 18 18 18
44068- 6 6 6 0 0 0 0 0 0 0 0 0
44069- 0 0 0 0 0 0 0 0 0 0 0 0
44070- 0 0 0 0 0 0 0 0 0 0 0 0
44071- 0 0 0 0 0 0 0 0 0 0 0 0
44072- 0 0 0 0 0 0 0 0 0 0 0 0
44073- 0 0 0 0 0 0 0 0 0 0 0 0
44074- 0 0 0 0 0 0 6 6 6 26 26 26
44075- 62 62 62 106 106 106 74 54 14 185 133 11
44076-210 162 10 121 92 8 6 6 6 62 62 62
44077-238 238 238 253 253 253 253 253 253 253 253 253
44078-253 253 253 253 253 253 253 253 253 253 253 253
44079-253 253 253 253 253 253 231 231 231 246 246 246
44080-253 253 253 253 253 253 253 253 253 253 253 253
44081-253 253 253 253 253 253 253 253 253 253 253 253
44082-253 253 253 253 253 253 253 253 253 253 253 253
44083-253 253 253 253 253 253 253 253 253 253 253 253
44084-253 253 253 253 253 253 158 158 158 18 18 18
44085- 14 14 14 2 2 6 2 2 6 2 2 6
44086- 6 6 6 18 18 18 66 66 66 38 38 38
44087- 6 6 6 94 94 94 50 50 50 18 18 18
44088- 6 6 6 0 0 0 0 0 0 0 0 0
44089- 0 0 0 0 0 0 0 0 0 0 0 0
44090- 0 0 0 0 0 0 0 0 0 0 0 0
44091- 0 0 0 0 0 0 0 0 0 0 0 0
44092- 0 0 0 0 0 0 0 0 0 0 0 0
44093- 0 0 0 0 0 0 0 0 0 6 6 6
44094- 10 10 10 10 10 10 18 18 18 38 38 38
44095- 78 78 78 142 134 106 216 158 10 242 186 14
44096-246 190 14 246 190 14 156 118 10 10 10 10
44097- 90 90 90 238 238 238 253 253 253 253 253 253
44098-253 253 253 253 253 253 253 253 253 253 253 253
44099-253 253 253 253 253 253 231 231 231 250 250 250
44100-253 253 253 253 253 253 253 253 253 253 253 253
44101-253 253 253 253 253 253 253 253 253 253 253 253
44102-253 253 253 253 253 253 253 253 253 253 253 253
44103-253 253 253 253 253 253 253 253 253 246 230 190
44104-238 204 91 238 204 91 181 142 44 37 26 9
44105- 2 2 6 2 2 6 2 2 6 2 2 6
44106- 2 2 6 2 2 6 38 38 38 46 46 46
44107- 26 26 26 106 106 106 54 54 54 18 18 18
44108- 6 6 6 0 0 0 0 0 0 0 0 0
44109- 0 0 0 0 0 0 0 0 0 0 0 0
44110- 0 0 0 0 0 0 0 0 0 0 0 0
44111- 0 0 0 0 0 0 0 0 0 0 0 0
44112- 0 0 0 0 0 0 0 0 0 0 0 0
44113- 0 0 0 6 6 6 14 14 14 22 22 22
44114- 30 30 30 38 38 38 50 50 50 70 70 70
44115-106 106 106 190 142 34 226 170 11 242 186 14
44116-246 190 14 246 190 14 246 190 14 154 114 10
44117- 6 6 6 74 74 74 226 226 226 253 253 253
44118-253 253 253 253 253 253 253 253 253 253 253 253
44119-253 253 253 253 253 253 231 231 231 250 250 250
44120-253 253 253 253 253 253 253 253 253 253 253 253
44121-253 253 253 253 253 253 253 253 253 253 253 253
44122-253 253 253 253 253 253 253 253 253 253 253 253
44123-253 253 253 253 253 253 253 253 253 228 184 62
44124-241 196 14 241 208 19 232 195 16 38 30 10
44125- 2 2 6 2 2 6 2 2 6 2 2 6
44126- 2 2 6 6 6 6 30 30 30 26 26 26
44127-203 166 17 154 142 90 66 66 66 26 26 26
44128- 6 6 6 0 0 0 0 0 0 0 0 0
44129- 0 0 0 0 0 0 0 0 0 0 0 0
44130- 0 0 0 0 0 0 0 0 0 0 0 0
44131- 0 0 0 0 0 0 0 0 0 0 0 0
44132- 0 0 0 0 0 0 0 0 0 0 0 0
44133- 6 6 6 18 18 18 38 38 38 58 58 58
44134- 78 78 78 86 86 86 101 101 101 123 123 123
44135-175 146 61 210 150 10 234 174 13 246 186 14
44136-246 190 14 246 190 14 246 190 14 238 190 10
44137-102 78 10 2 2 6 46 46 46 198 198 198
44138-253 253 253 253 253 253 253 253 253 253 253 253
44139-253 253 253 253 253 253 234 234 234 242 242 242
44140-253 253 253 253 253 253 253 253 253 253 253 253
44141-253 253 253 253 253 253 253 253 253 253 253 253
44142-253 253 253 253 253 253 253 253 253 253 253 253
44143-253 253 253 253 253 253 253 253 253 224 178 62
44144-242 186 14 241 196 14 210 166 10 22 18 6
44145- 2 2 6 2 2 6 2 2 6 2 2 6
44146- 2 2 6 2 2 6 6 6 6 121 92 8
44147-238 202 15 232 195 16 82 82 82 34 34 34
44148- 10 10 10 0 0 0 0 0 0 0 0 0
44149- 0 0 0 0 0 0 0 0 0 0 0 0
44150- 0 0 0 0 0 0 0 0 0 0 0 0
44151- 0 0 0 0 0 0 0 0 0 0 0 0
44152- 0 0 0 0 0 0 0 0 0 0 0 0
44153- 14 14 14 38 38 38 70 70 70 154 122 46
44154-190 142 34 200 144 11 197 138 11 197 138 11
44155-213 154 11 226 170 11 242 186 14 246 190 14
44156-246 190 14 246 190 14 246 190 14 246 190 14
44157-225 175 15 46 32 6 2 2 6 22 22 22
44158-158 158 158 250 250 250 253 253 253 253 253 253
44159-253 253 253 253 253 253 253 253 253 253 253 253
44160-253 253 253 253 253 253 253 253 253 253 253 253
44161-253 253 253 253 253 253 253 253 253 253 253 253
44162-253 253 253 253 253 253 253 253 253 253 253 253
44163-253 253 253 250 250 250 242 242 242 224 178 62
44164-239 182 13 236 186 11 213 154 11 46 32 6
44165- 2 2 6 2 2 6 2 2 6 2 2 6
44166- 2 2 6 2 2 6 61 42 6 225 175 15
44167-238 190 10 236 186 11 112 100 78 42 42 42
44168- 14 14 14 0 0 0 0 0 0 0 0 0
44169- 0 0 0 0 0 0 0 0 0 0 0 0
44170- 0 0 0 0 0 0 0 0 0 0 0 0
44171- 0 0 0 0 0 0 0 0 0 0 0 0
44172- 0 0 0 0 0 0 0 0 0 6 6 6
44173- 22 22 22 54 54 54 154 122 46 213 154 11
44174-226 170 11 230 174 11 226 170 11 226 170 11
44175-236 178 12 242 186 14 246 190 14 246 190 14
44176-246 190 14 246 190 14 246 190 14 246 190 14
44177-241 196 14 184 144 12 10 10 10 2 2 6
44178- 6 6 6 116 116 116 242 242 242 253 253 253
44179-253 253 253 253 253 253 253 253 253 253 253 253
44180-253 253 253 253 253 253 253 253 253 253 253 253
44181-253 253 253 253 253 253 253 253 253 253 253 253
44182-253 253 253 253 253 253 253 253 253 253 253 253
44183-253 253 253 231 231 231 198 198 198 214 170 54
44184-236 178 12 236 178 12 210 150 10 137 92 6
44185- 18 14 6 2 2 6 2 2 6 2 2 6
44186- 6 6 6 70 47 6 200 144 11 236 178 12
44187-239 182 13 239 182 13 124 112 88 58 58 58
44188- 22 22 22 6 6 6 0 0 0 0 0 0
44189- 0 0 0 0 0 0 0 0 0 0 0 0
44190- 0 0 0 0 0 0 0 0 0 0 0 0
44191- 0 0 0 0 0 0 0 0 0 0 0 0
44192- 0 0 0 0 0 0 0 0 0 10 10 10
44193- 30 30 30 70 70 70 180 133 36 226 170 11
44194-239 182 13 242 186 14 242 186 14 246 186 14
44195-246 190 14 246 190 14 246 190 14 246 190 14
44196-246 190 14 246 190 14 246 190 14 246 190 14
44197-246 190 14 232 195 16 98 70 6 2 2 6
44198- 2 2 6 2 2 6 66 66 66 221 221 221
44199-253 253 253 253 253 253 253 253 253 253 253 253
44200-253 253 253 253 253 253 253 253 253 253 253 253
44201-253 253 253 253 253 253 253 253 253 253 253 253
44202-253 253 253 253 253 253 253 253 253 253 253 253
44203-253 253 253 206 206 206 198 198 198 214 166 58
44204-230 174 11 230 174 11 216 158 10 192 133 9
44205-163 110 8 116 81 8 102 78 10 116 81 8
44206-167 114 7 197 138 11 226 170 11 239 182 13
44207-242 186 14 242 186 14 162 146 94 78 78 78
44208- 34 34 34 14 14 14 6 6 6 0 0 0
44209- 0 0 0 0 0 0 0 0 0 0 0 0
44210- 0 0 0 0 0 0 0 0 0 0 0 0
44211- 0 0 0 0 0 0 0 0 0 0 0 0
44212- 0 0 0 0 0 0 0 0 0 6 6 6
44213- 30 30 30 78 78 78 190 142 34 226 170 11
44214-239 182 13 246 190 14 246 190 14 246 190 14
44215-246 190 14 246 190 14 246 190 14 246 190 14
44216-246 190 14 246 190 14 246 190 14 246 190 14
44217-246 190 14 241 196 14 203 166 17 22 18 6
44218- 2 2 6 2 2 6 2 2 6 38 38 38
44219-218 218 218 253 253 253 253 253 253 253 253 253
44220-253 253 253 253 253 253 253 253 253 253 253 253
44221-253 253 253 253 253 253 253 253 253 253 253 253
44222-253 253 253 253 253 253 253 253 253 253 253 253
44223-250 250 250 206 206 206 198 198 198 202 162 69
44224-226 170 11 236 178 12 224 166 10 210 150 10
44225-200 144 11 197 138 11 192 133 9 197 138 11
44226-210 150 10 226 170 11 242 186 14 246 190 14
44227-246 190 14 246 186 14 225 175 15 124 112 88
44228- 62 62 62 30 30 30 14 14 14 6 6 6
44229- 0 0 0 0 0 0 0 0 0 0 0 0
44230- 0 0 0 0 0 0 0 0 0 0 0 0
44231- 0 0 0 0 0 0 0 0 0 0 0 0
44232- 0 0 0 0 0 0 0 0 0 10 10 10
44233- 30 30 30 78 78 78 174 135 50 224 166 10
44234-239 182 13 246 190 14 246 190 14 246 190 14
44235-246 190 14 246 190 14 246 190 14 246 190 14
44236-246 190 14 246 190 14 246 190 14 246 190 14
44237-246 190 14 246 190 14 241 196 14 139 102 15
44238- 2 2 6 2 2 6 2 2 6 2 2 6
44239- 78 78 78 250 250 250 253 253 253 253 253 253
44240-253 253 253 253 253 253 253 253 253 253 253 253
44241-253 253 253 253 253 253 253 253 253 253 253 253
44242-253 253 253 253 253 253 253 253 253 253 253 253
44243-250 250 250 214 214 214 198 198 198 190 150 46
44244-219 162 10 236 178 12 234 174 13 224 166 10
44245-216 158 10 213 154 11 213 154 11 216 158 10
44246-226 170 11 239 182 13 246 190 14 246 190 14
44247-246 190 14 246 190 14 242 186 14 206 162 42
44248-101 101 101 58 58 58 30 30 30 14 14 14
44249- 6 6 6 0 0 0 0 0 0 0 0 0
44250- 0 0 0 0 0 0 0 0 0 0 0 0
44251- 0 0 0 0 0 0 0 0 0 0 0 0
44252- 0 0 0 0 0 0 0 0 0 10 10 10
44253- 30 30 30 74 74 74 174 135 50 216 158 10
44254-236 178 12 246 190 14 246 190 14 246 190 14
44255-246 190 14 246 190 14 246 190 14 246 190 14
44256-246 190 14 246 190 14 246 190 14 246 190 14
44257-246 190 14 246 190 14 241 196 14 226 184 13
44258- 61 42 6 2 2 6 2 2 6 2 2 6
44259- 22 22 22 238 238 238 253 253 253 253 253 253
44260-253 253 253 253 253 253 253 253 253 253 253 253
44261-253 253 253 253 253 253 253 253 253 253 253 253
44262-253 253 253 253 253 253 253 253 253 253 253 253
44263-253 253 253 226 226 226 187 187 187 180 133 36
44264-216 158 10 236 178 12 239 182 13 236 178 12
44265-230 174 11 226 170 11 226 170 11 230 174 11
44266-236 178 12 242 186 14 246 190 14 246 190 14
44267-246 190 14 246 190 14 246 186 14 239 182 13
44268-206 162 42 106 106 106 66 66 66 34 34 34
44269- 14 14 14 6 6 6 0 0 0 0 0 0
44270- 0 0 0 0 0 0 0 0 0 0 0 0
44271- 0 0 0 0 0 0 0 0 0 0 0 0
44272- 0 0 0 0 0 0 0 0 0 6 6 6
44273- 26 26 26 70 70 70 163 133 67 213 154 11
44274-236 178 12 246 190 14 246 190 14 246 190 14
44275-246 190 14 246 190 14 246 190 14 246 190 14
44276-246 190 14 246 190 14 246 190 14 246 190 14
44277-246 190 14 246 190 14 246 190 14 241 196 14
44278-190 146 13 18 14 6 2 2 6 2 2 6
44279- 46 46 46 246 246 246 253 253 253 253 253 253
44280-253 253 253 253 253 253 253 253 253 253 253 253
44281-253 253 253 253 253 253 253 253 253 253 253 253
44282-253 253 253 253 253 253 253 253 253 253 253 253
44283-253 253 253 221 221 221 86 86 86 156 107 11
44284-216 158 10 236 178 12 242 186 14 246 186 14
44285-242 186 14 239 182 13 239 182 13 242 186 14
44286-242 186 14 246 186 14 246 190 14 246 190 14
44287-246 190 14 246 190 14 246 190 14 246 190 14
44288-242 186 14 225 175 15 142 122 72 66 66 66
44289- 30 30 30 10 10 10 0 0 0 0 0 0
44290- 0 0 0 0 0 0 0 0 0 0 0 0
44291- 0 0 0 0 0 0 0 0 0 0 0 0
44292- 0 0 0 0 0 0 0 0 0 6 6 6
44293- 26 26 26 70 70 70 163 133 67 210 150 10
44294-236 178 12 246 190 14 246 190 14 246 190 14
44295-246 190 14 246 190 14 246 190 14 246 190 14
44296-246 190 14 246 190 14 246 190 14 246 190 14
44297-246 190 14 246 190 14 246 190 14 246 190 14
44298-232 195 16 121 92 8 34 34 34 106 106 106
44299-221 221 221 253 253 253 253 253 253 253 253 253
44300-253 253 253 253 253 253 253 253 253 253 253 253
44301-253 253 253 253 253 253 253 253 253 253 253 253
44302-253 253 253 253 253 253 253 253 253 253 253 253
44303-242 242 242 82 82 82 18 14 6 163 110 8
44304-216 158 10 236 178 12 242 186 14 246 190 14
44305-246 190 14 246 190 14 246 190 14 246 190 14
44306-246 190 14 246 190 14 246 190 14 246 190 14
44307-246 190 14 246 190 14 246 190 14 246 190 14
44308-246 190 14 246 190 14 242 186 14 163 133 67
44309- 46 46 46 18 18 18 6 6 6 0 0 0
44310- 0 0 0 0 0 0 0 0 0 0 0 0
44311- 0 0 0 0 0 0 0 0 0 0 0 0
44312- 0 0 0 0 0 0 0 0 0 10 10 10
44313- 30 30 30 78 78 78 163 133 67 210 150 10
44314-236 178 12 246 186 14 246 190 14 246 190 14
44315-246 190 14 246 190 14 246 190 14 246 190 14
44316-246 190 14 246 190 14 246 190 14 246 190 14
44317-246 190 14 246 190 14 246 190 14 246 190 14
44318-241 196 14 215 174 15 190 178 144 253 253 253
44319-253 253 253 253 253 253 253 253 253 253 253 253
44320-253 253 253 253 253 253 253 253 253 253 253 253
44321-253 253 253 253 253 253 253 253 253 253 253 253
44322-253 253 253 253 253 253 253 253 253 218 218 218
44323- 58 58 58 2 2 6 22 18 6 167 114 7
44324-216 158 10 236 178 12 246 186 14 246 190 14
44325-246 190 14 246 190 14 246 190 14 246 190 14
44326-246 190 14 246 190 14 246 190 14 246 190 14
44327-246 190 14 246 190 14 246 190 14 246 190 14
44328-246 190 14 246 186 14 242 186 14 190 150 46
44329- 54 54 54 22 22 22 6 6 6 0 0 0
44330- 0 0 0 0 0 0 0 0 0 0 0 0
44331- 0 0 0 0 0 0 0 0 0 0 0 0
44332- 0 0 0 0 0 0 0 0 0 14 14 14
44333- 38 38 38 86 86 86 180 133 36 213 154 11
44334-236 178 12 246 186 14 246 190 14 246 190 14
44335-246 190 14 246 190 14 246 190 14 246 190 14
44336-246 190 14 246 190 14 246 190 14 246 190 14
44337-246 190 14 246 190 14 246 190 14 246 190 14
44338-246 190 14 232 195 16 190 146 13 214 214 214
44339-253 253 253 253 253 253 253 253 253 253 253 253
44340-253 253 253 253 253 253 253 253 253 253 253 253
44341-253 253 253 253 253 253 253 253 253 253 253 253
44342-253 253 253 250 250 250 170 170 170 26 26 26
44343- 2 2 6 2 2 6 37 26 9 163 110 8
44344-219 162 10 239 182 13 246 186 14 246 190 14
44345-246 190 14 246 190 14 246 190 14 246 190 14
44346-246 190 14 246 190 14 246 190 14 246 190 14
44347-246 190 14 246 190 14 246 190 14 246 190 14
44348-246 186 14 236 178 12 224 166 10 142 122 72
44349- 46 46 46 18 18 18 6 6 6 0 0 0
44350- 0 0 0 0 0 0 0 0 0 0 0 0
44351- 0 0 0 0 0 0 0 0 0 0 0 0
44352- 0 0 0 0 0 0 6 6 6 18 18 18
44353- 50 50 50 109 106 95 192 133 9 224 166 10
44354-242 186 14 246 190 14 246 190 14 246 190 14
44355-246 190 14 246 190 14 246 190 14 246 190 14
44356-246 190 14 246 190 14 246 190 14 246 190 14
44357-246 190 14 246 190 14 246 190 14 246 190 14
44358-242 186 14 226 184 13 210 162 10 142 110 46
44359-226 226 226 253 253 253 253 253 253 253 253 253
44360-253 253 253 253 253 253 253 253 253 253 253 253
44361-253 253 253 253 253 253 253 253 253 253 253 253
44362-198 198 198 66 66 66 2 2 6 2 2 6
44363- 2 2 6 2 2 6 50 34 6 156 107 11
44364-219 162 10 239 182 13 246 186 14 246 190 14
44365-246 190 14 246 190 14 246 190 14 246 190 14
44366-246 190 14 246 190 14 246 190 14 246 190 14
44367-246 190 14 246 190 14 246 190 14 242 186 14
44368-234 174 13 213 154 11 154 122 46 66 66 66
44369- 30 30 30 10 10 10 0 0 0 0 0 0
44370- 0 0 0 0 0 0 0 0 0 0 0 0
44371- 0 0 0 0 0 0 0 0 0 0 0 0
44372- 0 0 0 0 0 0 6 6 6 22 22 22
44373- 58 58 58 154 121 60 206 145 10 234 174 13
44374-242 186 14 246 186 14 246 190 14 246 190 14
44375-246 190 14 246 190 14 246 190 14 246 190 14
44376-246 190 14 246 190 14 246 190 14 246 190 14
44377-246 190 14 246 190 14 246 190 14 246 190 14
44378-246 186 14 236 178 12 210 162 10 163 110 8
44379- 61 42 6 138 138 138 218 218 218 250 250 250
44380-253 253 253 253 253 253 253 253 253 250 250 250
44381-242 242 242 210 210 210 144 144 144 66 66 66
44382- 6 6 6 2 2 6 2 2 6 2 2 6
44383- 2 2 6 2 2 6 61 42 6 163 110 8
44384-216 158 10 236 178 12 246 190 14 246 190 14
44385-246 190 14 246 190 14 246 190 14 246 190 14
44386-246 190 14 246 190 14 246 190 14 246 190 14
44387-246 190 14 239 182 13 230 174 11 216 158 10
44388-190 142 34 124 112 88 70 70 70 38 38 38
44389- 18 18 18 6 6 6 0 0 0 0 0 0
44390- 0 0 0 0 0 0 0 0 0 0 0 0
44391- 0 0 0 0 0 0 0 0 0 0 0 0
44392- 0 0 0 0 0 0 6 6 6 22 22 22
44393- 62 62 62 168 124 44 206 145 10 224 166 10
44394-236 178 12 239 182 13 242 186 14 242 186 14
44395-246 186 14 246 190 14 246 190 14 246 190 14
44396-246 190 14 246 190 14 246 190 14 246 190 14
44397-246 190 14 246 190 14 246 190 14 246 190 14
44398-246 190 14 236 178 12 216 158 10 175 118 6
44399- 80 54 7 2 2 6 6 6 6 30 30 30
44400- 54 54 54 62 62 62 50 50 50 38 38 38
44401- 14 14 14 2 2 6 2 2 6 2 2 6
44402- 2 2 6 2 2 6 2 2 6 2 2 6
44403- 2 2 6 6 6 6 80 54 7 167 114 7
44404-213 154 11 236 178 12 246 190 14 246 190 14
44405-246 190 14 246 190 14 246 190 14 246 190 14
44406-246 190 14 242 186 14 239 182 13 239 182 13
44407-230 174 11 210 150 10 174 135 50 124 112 88
44408- 82 82 82 54 54 54 34 34 34 18 18 18
44409- 6 6 6 0 0 0 0 0 0 0 0 0
44410- 0 0 0 0 0 0 0 0 0 0 0 0
44411- 0 0 0 0 0 0 0 0 0 0 0 0
44412- 0 0 0 0 0 0 6 6 6 18 18 18
44413- 50 50 50 158 118 36 192 133 9 200 144 11
44414-216 158 10 219 162 10 224 166 10 226 170 11
44415-230 174 11 236 178 12 239 182 13 239 182 13
44416-242 186 14 246 186 14 246 190 14 246 190 14
44417-246 190 14 246 190 14 246 190 14 246 190 14
44418-246 186 14 230 174 11 210 150 10 163 110 8
44419-104 69 6 10 10 10 2 2 6 2 2 6
44420- 2 2 6 2 2 6 2 2 6 2 2 6
44421- 2 2 6 2 2 6 2 2 6 2 2 6
44422- 2 2 6 2 2 6 2 2 6 2 2 6
44423- 2 2 6 6 6 6 91 60 6 167 114 7
44424-206 145 10 230 174 11 242 186 14 246 190 14
44425-246 190 14 246 190 14 246 186 14 242 186 14
44426-239 182 13 230 174 11 224 166 10 213 154 11
44427-180 133 36 124 112 88 86 86 86 58 58 58
44428- 38 38 38 22 22 22 10 10 10 6 6 6
44429- 0 0 0 0 0 0 0 0 0 0 0 0
44430- 0 0 0 0 0 0 0 0 0 0 0 0
44431- 0 0 0 0 0 0 0 0 0 0 0 0
44432- 0 0 0 0 0 0 0 0 0 14 14 14
44433- 34 34 34 70 70 70 138 110 50 158 118 36
44434-167 114 7 180 123 7 192 133 9 197 138 11
44435-200 144 11 206 145 10 213 154 11 219 162 10
44436-224 166 10 230 174 11 239 182 13 242 186 14
44437-246 186 14 246 186 14 246 186 14 246 186 14
44438-239 182 13 216 158 10 185 133 11 152 99 6
44439-104 69 6 18 14 6 2 2 6 2 2 6
44440- 2 2 6 2 2 6 2 2 6 2 2 6
44441- 2 2 6 2 2 6 2 2 6 2 2 6
44442- 2 2 6 2 2 6 2 2 6 2 2 6
44443- 2 2 6 6 6 6 80 54 7 152 99 6
44444-192 133 9 219 162 10 236 178 12 239 182 13
44445-246 186 14 242 186 14 239 182 13 236 178 12
44446-224 166 10 206 145 10 192 133 9 154 121 60
44447- 94 94 94 62 62 62 42 42 42 22 22 22
44448- 14 14 14 6 6 6 0 0 0 0 0 0
44449- 0 0 0 0 0 0 0 0 0 0 0 0
44450- 0 0 0 0 0 0 0 0 0 0 0 0
44451- 0 0 0 0 0 0 0 0 0 0 0 0
44452- 0 0 0 0 0 0 0 0 0 6 6 6
44453- 18 18 18 34 34 34 58 58 58 78 78 78
44454-101 98 89 124 112 88 142 110 46 156 107 11
44455-163 110 8 167 114 7 175 118 6 180 123 7
44456-185 133 11 197 138 11 210 150 10 219 162 10
44457-226 170 11 236 178 12 236 178 12 234 174 13
44458-219 162 10 197 138 11 163 110 8 130 83 6
44459- 91 60 6 10 10 10 2 2 6 2 2 6
44460- 18 18 18 38 38 38 38 38 38 38 38 38
44461- 38 38 38 38 38 38 38 38 38 38 38 38
44462- 38 38 38 38 38 38 26 26 26 2 2 6
44463- 2 2 6 6 6 6 70 47 6 137 92 6
44464-175 118 6 200 144 11 219 162 10 230 174 11
44465-234 174 13 230 174 11 219 162 10 210 150 10
44466-192 133 9 163 110 8 124 112 88 82 82 82
44467- 50 50 50 30 30 30 14 14 14 6 6 6
44468- 0 0 0 0 0 0 0 0 0 0 0 0
44469- 0 0 0 0 0 0 0 0 0 0 0 0
44470- 0 0 0 0 0 0 0 0 0 0 0 0
44471- 0 0 0 0 0 0 0 0 0 0 0 0
44472- 0 0 0 0 0 0 0 0 0 0 0 0
44473- 6 6 6 14 14 14 22 22 22 34 34 34
44474- 42 42 42 58 58 58 74 74 74 86 86 86
44475-101 98 89 122 102 70 130 98 46 121 87 25
44476-137 92 6 152 99 6 163 110 8 180 123 7
44477-185 133 11 197 138 11 206 145 10 200 144 11
44478-180 123 7 156 107 11 130 83 6 104 69 6
44479- 50 34 6 54 54 54 110 110 110 101 98 89
44480- 86 86 86 82 82 82 78 78 78 78 78 78
44481- 78 78 78 78 78 78 78 78 78 78 78 78
44482- 78 78 78 82 82 82 86 86 86 94 94 94
44483-106 106 106 101 101 101 86 66 34 124 80 6
44484-156 107 11 180 123 7 192 133 9 200 144 11
44485-206 145 10 200 144 11 192 133 9 175 118 6
44486-139 102 15 109 106 95 70 70 70 42 42 42
44487- 22 22 22 10 10 10 0 0 0 0 0 0
44488- 0 0 0 0 0 0 0 0 0 0 0 0
44489- 0 0 0 0 0 0 0 0 0 0 0 0
44490- 0 0 0 0 0 0 0 0 0 0 0 0
44491- 0 0 0 0 0 0 0 0 0 0 0 0
44492- 0 0 0 0 0 0 0 0 0 0 0 0
44493- 0 0 0 0 0 0 6 6 6 10 10 10
44494- 14 14 14 22 22 22 30 30 30 38 38 38
44495- 50 50 50 62 62 62 74 74 74 90 90 90
44496-101 98 89 112 100 78 121 87 25 124 80 6
44497-137 92 6 152 99 6 152 99 6 152 99 6
44498-138 86 6 124 80 6 98 70 6 86 66 30
44499-101 98 89 82 82 82 58 58 58 46 46 46
44500- 38 38 38 34 34 34 34 34 34 34 34 34
44501- 34 34 34 34 34 34 34 34 34 34 34 34
44502- 34 34 34 34 34 34 38 38 38 42 42 42
44503- 54 54 54 82 82 82 94 86 76 91 60 6
44504-134 86 6 156 107 11 167 114 7 175 118 6
44505-175 118 6 167 114 7 152 99 6 121 87 25
44506-101 98 89 62 62 62 34 34 34 18 18 18
44507- 6 6 6 0 0 0 0 0 0 0 0 0
44508- 0 0 0 0 0 0 0 0 0 0 0 0
44509- 0 0 0 0 0 0 0 0 0 0 0 0
44510- 0 0 0 0 0 0 0 0 0 0 0 0
44511- 0 0 0 0 0 0 0 0 0 0 0 0
44512- 0 0 0 0 0 0 0 0 0 0 0 0
44513- 0 0 0 0 0 0 0 0 0 0 0 0
44514- 0 0 0 6 6 6 6 6 6 10 10 10
44515- 18 18 18 22 22 22 30 30 30 42 42 42
44516- 50 50 50 66 66 66 86 86 86 101 98 89
44517-106 86 58 98 70 6 104 69 6 104 69 6
44518-104 69 6 91 60 6 82 62 34 90 90 90
44519- 62 62 62 38 38 38 22 22 22 14 14 14
44520- 10 10 10 10 10 10 10 10 10 10 10 10
44521- 10 10 10 10 10 10 6 6 6 10 10 10
44522- 10 10 10 10 10 10 10 10 10 14 14 14
44523- 22 22 22 42 42 42 70 70 70 89 81 66
44524- 80 54 7 104 69 6 124 80 6 137 92 6
44525-134 86 6 116 81 8 100 82 52 86 86 86
44526- 58 58 58 30 30 30 14 14 14 6 6 6
44527- 0 0 0 0 0 0 0 0 0 0 0 0
44528- 0 0 0 0 0 0 0 0 0 0 0 0
44529- 0 0 0 0 0 0 0 0 0 0 0 0
44530- 0 0 0 0 0 0 0 0 0 0 0 0
44531- 0 0 0 0 0 0 0 0 0 0 0 0
44532- 0 0 0 0 0 0 0 0 0 0 0 0
44533- 0 0 0 0 0 0 0 0 0 0 0 0
44534- 0 0 0 0 0 0 0 0 0 0 0 0
44535- 0 0 0 6 6 6 10 10 10 14 14 14
44536- 18 18 18 26 26 26 38 38 38 54 54 54
44537- 70 70 70 86 86 86 94 86 76 89 81 66
44538- 89 81 66 86 86 86 74 74 74 50 50 50
44539- 30 30 30 14 14 14 6 6 6 0 0 0
44540- 0 0 0 0 0 0 0 0 0 0 0 0
44541- 0 0 0 0 0 0 0 0 0 0 0 0
44542- 0 0 0 0 0 0 0 0 0 0 0 0
44543- 6 6 6 18 18 18 34 34 34 58 58 58
44544- 82 82 82 89 81 66 89 81 66 89 81 66
44545- 94 86 66 94 86 76 74 74 74 50 50 50
44546- 26 26 26 14 14 14 6 6 6 0 0 0
44547- 0 0 0 0 0 0 0 0 0 0 0 0
44548- 0 0 0 0 0 0 0 0 0 0 0 0
44549- 0 0 0 0 0 0 0 0 0 0 0 0
44550- 0 0 0 0 0 0 0 0 0 0 0 0
44551- 0 0 0 0 0 0 0 0 0 0 0 0
44552- 0 0 0 0 0 0 0 0 0 0 0 0
44553- 0 0 0 0 0 0 0 0 0 0 0 0
44554- 0 0 0 0 0 0 0 0 0 0 0 0
44555- 0 0 0 0 0 0 0 0 0 0 0 0
44556- 6 6 6 6 6 6 14 14 14 18 18 18
44557- 30 30 30 38 38 38 46 46 46 54 54 54
44558- 50 50 50 42 42 42 30 30 30 18 18 18
44559- 10 10 10 0 0 0 0 0 0 0 0 0
44560- 0 0 0 0 0 0 0 0 0 0 0 0
44561- 0 0 0 0 0 0 0 0 0 0 0 0
44562- 0 0 0 0 0 0 0 0 0 0 0 0
44563- 0 0 0 6 6 6 14 14 14 26 26 26
44564- 38 38 38 50 50 50 58 58 58 58 58 58
44565- 54 54 54 42 42 42 30 30 30 18 18 18
44566- 10 10 10 0 0 0 0 0 0 0 0 0
44567- 0 0 0 0 0 0 0 0 0 0 0 0
44568- 0 0 0 0 0 0 0 0 0 0 0 0
44569- 0 0 0 0 0 0 0 0 0 0 0 0
44570- 0 0 0 0 0 0 0 0 0 0 0 0
44571- 0 0 0 0 0 0 0 0 0 0 0 0
44572- 0 0 0 0 0 0 0 0 0 0 0 0
44573- 0 0 0 0 0 0 0 0 0 0 0 0
44574- 0 0 0 0 0 0 0 0 0 0 0 0
44575- 0 0 0 0 0 0 0 0 0 0 0 0
44576- 0 0 0 0 0 0 0 0 0 6 6 6
44577- 6 6 6 10 10 10 14 14 14 18 18 18
44578- 18 18 18 14 14 14 10 10 10 6 6 6
44579- 0 0 0 0 0 0 0 0 0 0 0 0
44580- 0 0 0 0 0 0 0 0 0 0 0 0
44581- 0 0 0 0 0 0 0 0 0 0 0 0
44582- 0 0 0 0 0 0 0 0 0 0 0 0
44583- 0 0 0 0 0 0 0 0 0 6 6 6
44584- 14 14 14 18 18 18 22 22 22 22 22 22
44585- 18 18 18 14 14 14 10 10 10 6 6 6
44586- 0 0 0 0 0 0 0 0 0 0 0 0
44587- 0 0 0 0 0 0 0 0 0 0 0 0
44588- 0 0 0 0 0 0 0 0 0 0 0 0
44589- 0 0 0 0 0 0 0 0 0 0 0 0
44590- 0 0 0 0 0 0 0 0 0 0 0 0
44591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44604+4 4 4 4 4 4
44605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44618+4 4 4 4 4 4
44619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44632+4 4 4 4 4 4
44633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44646+4 4 4 4 4 4
44647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44660+4 4 4 4 4 4
44661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674+4 4 4 4 4 4
44675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44679+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
44680+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
44681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
44685+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44686+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
44687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688+4 4 4 4 4 4
44689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44693+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
44694+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
44695+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
44699+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
44700+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
44701+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702+4 4 4 4 4 4
44703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44707+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
44708+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
44709+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
44713+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
44714+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
44715+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
44716+4 4 4 4 4 4
44717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44720+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
44721+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
44722+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
44723+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
44724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44726+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
44727+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
44728+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
44729+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
44730+4 4 4 4 4 4
44731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44734+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
44735+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
44736+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
44737+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
44738+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44739+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
44740+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
44741+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
44742+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
44743+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
44744+4 4 4 4 4 4
44745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44748+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
44749+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
44750+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
44751+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
44752+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44753+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
44754+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
44755+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
44756+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
44757+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
44758+4 4 4 4 4 4
44759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44761+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
44762+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
44763+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
44764+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
44765+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
44766+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
44767+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
44768+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
44769+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
44770+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
44771+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
44772+4 4 4 4 4 4
44773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44775+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
44776+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
44777+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
44778+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
44779+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
44780+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
44781+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
44782+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
44783+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
44784+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
44785+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
44786+4 4 4 4 4 4
44787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44789+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
44790+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
44791+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
44792+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
44793+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
44794+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
44795+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
44796+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
44797+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
44798+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
44799+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44800+4 4 4 4 4 4
44801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44803+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
44804+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
44805+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
44806+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
44807+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
44808+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
44809+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
44810+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
44811+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
44812+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
44813+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
44814+4 4 4 4 4 4
44815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44816+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
44817+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
44818+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
44819+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
44820+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
44821+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
44822+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
44823+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
44824+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
44825+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
44826+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
44827+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
44828+4 4 4 4 4 4
44829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44830+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
44831+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
44832+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
44833+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44834+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
44835+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
44836+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
44837+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
44838+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
44839+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
44840+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
44841+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
44842+0 0 0 4 4 4
44843+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44844+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
44845+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
44846+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
44847+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
44848+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
44849+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
44850+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
44851+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
44852+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
44853+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
44854+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
44855+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
44856+2 0 0 0 0 0
44857+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
44858+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
44859+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
44860+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
44861+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
44862+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
44863+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
44864+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
44865+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
44866+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
44867+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
44868+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
44869+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
44870+37 38 37 0 0 0
44871+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44872+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
44873+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
44874+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
44875+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
44876+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
44877+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
44878+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
44879+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
44880+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
44881+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
44882+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
44883+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
44884+85 115 134 4 0 0
44885+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
44886+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
44887+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
44888+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
44889+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
44890+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
44891+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
44892+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
44893+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
44894+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
44895+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
44896+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
44897+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
44898+60 73 81 4 0 0
44899+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
44900+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
44901+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
44902+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
44903+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
44904+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
44905+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
44906+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
44907+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
44908+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
44909+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
44910+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
44911+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
44912+16 19 21 4 0 0
44913+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44914+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44915+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44916+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44917+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44918+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44919+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
44920+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
44921+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
44922+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
44923+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
44924+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
44925+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44926+4 0 0 4 3 3
44927+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44928+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44929+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44931+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44932+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44933+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44934+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44935+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44936+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44937+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44938+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44939+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44940+3 2 2 4 4 4
44941+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44942+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44943+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44944+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44945+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44946+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44947+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44948+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44949+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44950+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44951+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44952+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44953+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44954+4 4 4 4 4 4
44955+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44956+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44957+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44958+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44959+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44960+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44961+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44962+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44963+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44964+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44965+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44966+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44967+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44968+4 4 4 4 4 4
44969+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44970+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44971+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44972+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44973+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44974+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44975+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44976+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44977+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44978+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44979+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44980+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44981+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44982+5 5 5 5 5 5
44983+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44984+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44985+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44986+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44987+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44988+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44989+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44990+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44991+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44992+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44993+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44994+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44995+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44996+5 5 5 4 4 4
44997+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44998+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44999+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45000+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45001+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45002+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45003+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45004+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45005+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45006+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45007+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45008+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45010+4 4 4 4 4 4
45011+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45012+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45013+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45014+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45015+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45016+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45017+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45018+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45019+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45020+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45021+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45022+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45024+4 4 4 4 4 4
45025+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45026+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45027+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45028+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45029+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45030+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45031+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45032+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45033+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45034+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45035+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45038+4 4 4 4 4 4
45039+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
45040+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
45041+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
45042+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
45043+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45044+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45045+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45046+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
45047+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
45048+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
45049+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
45050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45052+4 4 4 4 4 4
45053+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
45054+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
45055+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
45056+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
45057+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45058+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
45059+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45060+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
45061+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
45062+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
45063+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45066+4 4 4 4 4 4
45067+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
45068+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
45069+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
45070+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
45071+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45072+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
45073+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
45074+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
45075+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
45076+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
45077+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
45078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45080+4 4 4 4 4 4
45081+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
45082+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
45083+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
45084+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
45085+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45086+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
45087+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
45088+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
45089+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
45090+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
45091+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
45092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45094+4 4 4 4 4 4
45095+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
45096+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
45097+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
45098+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45099+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
45100+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
45101+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
45102+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
45103+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
45104+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
45105+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45108+4 4 4 4 4 4
45109+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
45110+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
45111+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
45112+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45113+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45114+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
45115+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
45116+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
45117+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
45118+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
45119+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45122+4 4 4 4 4 4
45123+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
45124+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
45125+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45126+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45127+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45128+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
45129+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
45130+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
45131+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
45132+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
45133+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45136+4 4 4 4 4 4
45137+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
45138+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
45139+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45140+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45141+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45142+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
45143+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
45144+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
45145+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45146+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45147+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45150+4 4 4 4 4 4
45151+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45152+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
45153+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45154+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
45155+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
45156+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
45157+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
45158+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
45159+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45160+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45161+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45164+4 4 4 4 4 4
45165+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45166+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
45167+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45168+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
45169+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45170+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
45171+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
45172+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
45173+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45174+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45175+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45178+4 4 4 4 4 4
45179+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
45180+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
45181+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45182+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
45183+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
45184+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
45185+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
45186+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
45187+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45188+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45189+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45192+4 4 4 4 4 4
45193+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
45194+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
45195+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45196+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
45197+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
45198+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
45199+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
45200+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
45201+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45202+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45203+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45206+4 4 4 4 4 4
45207+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45208+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
45209+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45210+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
45211+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
45212+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
45213+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
45214+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
45215+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45216+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45217+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45220+4 4 4 4 4 4
45221+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
45222+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
45223+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45224+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
45225+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
45226+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
45227+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
45228+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
45229+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
45230+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45231+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45234+4 4 4 4 4 4
45235+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45236+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
45237+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
45238+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
45239+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
45240+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
45241+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
45242+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
45243+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45244+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45245+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45248+4 4 4 4 4 4
45249+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45250+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
45251+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45252+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
45253+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
45254+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
45255+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
45256+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
45257+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45258+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45259+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45262+4 4 4 4 4 4
45263+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45264+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
45265+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
45266+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
45267+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
45268+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
45269+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45270+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
45271+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45272+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45273+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45276+4 4 4 4 4 4
45277+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45278+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
45279+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
45280+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45281+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
45282+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
45283+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45284+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
45285+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45286+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45287+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45290+4 4 4 4 4 4
45291+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45292+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
45293+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
45294+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
45295+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
45296+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
45297+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
45298+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
45299+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
45300+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45301+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45304+4 4 4 4 4 4
45305+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45306+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
45307+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
45308+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
45309+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
45310+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
45311+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
45312+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
45313+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
45314+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45315+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45318+4 4 4 4 4 4
45319+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
45320+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
45321+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
45322+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
45323+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45324+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
45325+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
45326+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
45327+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
45328+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45329+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45332+4 4 4 4 4 4
45333+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45334+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
45335+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
45336+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
45337+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
45338+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
45339+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
45340+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
45341+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
45342+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45343+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45346+4 4 4 4 4 4
45347+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
45348+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
45349+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
45350+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
45351+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
45352+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
45353+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
45354+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
45355+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
45356+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
45357+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45360+4 4 4 4 4 4
45361+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
45362+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45363+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
45364+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
45365+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
45366+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
45367+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
45368+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
45369+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
45370+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
45371+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45374+4 4 4 4 4 4
45375+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
45376+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45377+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
45378+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
45379+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
45380+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
45381+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45382+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
45383+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
45384+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
45385+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45388+4 4 4 4 4 4
45389+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
45390+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
45391+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
45392+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
45393+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
45394+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
45395+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
45396+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
45397+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
45398+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
45399+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45402+4 4 4 4 4 4
45403+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
45404+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
45405+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45406+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
45407+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
45408+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
45409+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
45410+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
45411+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
45412+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
45413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45416+4 4 4 4 4 4
45417+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45418+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
45419+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
45420+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
45421+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
45422+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
45423+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
45424+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
45425+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
45426+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45430+4 4 4 4 4 4
45431+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
45432+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
45433+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
45434+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
45435+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
45436+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
45437+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
45438+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
45439+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
45440+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45444+4 4 4 4 4 4
45445+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
45446+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
45447+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
45448+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
45449+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
45450+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
45451+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
45452+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
45453+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45454+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45458+4 4 4 4 4 4
45459+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
45460+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45461+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
45462+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45463+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
45464+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
45465+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
45466+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
45467+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
45468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45472+4 4 4 4 4 4
45473+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
45474+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
45475+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
45476+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
45477+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
45478+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
45479+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
45480+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
45481+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
45482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45486+4 4 4 4 4 4
45487+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45488+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
45489+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
45490+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
45491+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
45492+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
45493+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
45494+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
45495+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45500+4 4 4 4 4 4
45501+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
45502+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
45503+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45504+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
45505+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
45506+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
45507+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
45508+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
45509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45514+4 4 4 4 4 4
45515+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45516+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
45517+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
45518+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
45519+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
45520+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
45521+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
45522+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45528+4 4 4 4 4 4
45529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45530+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
45531+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45532+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
45533+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
45534+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
45535+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
45536+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
45537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45542+4 4 4 4 4 4
45543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45544+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
45545+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
45546+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
45547+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
45548+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
45549+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
45550+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
45551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45556+4 4 4 4 4 4
45557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45558+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45559+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
45560+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45561+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
45562+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
45563+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
45564+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45570+4 4 4 4 4 4
45571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45573+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45574+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
45575+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
45576+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
45577+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
45578+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45584+4 4 4 4 4 4
45585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45588+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45589+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
45590+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
45591+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
45592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45598+4 4 4 4 4 4
45599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45602+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45603+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45604+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
45605+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
45606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45612+4 4 4 4 4 4
45613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45616+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45617+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45618+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45619+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
45620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45626+4 4 4 4 4 4
45627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45630+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
45631+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
45632+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
45633+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
45634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45640+4 4 4 4 4 4
45641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45645+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
45646+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45647+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45654+4 4 4 4 4 4
45655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45659+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
45660+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
45661+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45668+4 4 4 4 4 4
45669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45673+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
45674+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
45675+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45682+4 4 4 4 4 4
45683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45687+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
45688+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
45689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45696+4 4 4 4 4 4
45697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45701+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45702+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
45703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45710+4 4 4 4 4 4
45711diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
45712index 443e3c8..c443d6a 100644
45713--- a/drivers/video/nvidia/nv_backlight.c
45714+++ b/drivers/video/nvidia/nv_backlight.c
45715@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(struct backlight_device *bd)
45716 return bd->props.brightness;
45717 }
45718
45719-static struct backlight_ops nvidia_bl_ops = {
45720+static const struct backlight_ops nvidia_bl_ops = {
45721 .get_brightness = nvidia_bl_get_brightness,
45722 .update_status = nvidia_bl_update_status,
45723 };
45724diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
45725index d94c57f..912984c 100644
45726--- a/drivers/video/riva/fbdev.c
45727+++ b/drivers/video/riva/fbdev.c
45728@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct backlight_device *bd)
45729 return bd->props.brightness;
45730 }
45731
45732-static struct backlight_ops riva_bl_ops = {
45733+static const struct backlight_ops riva_bl_ops = {
45734 .get_brightness = riva_bl_get_brightness,
45735 .update_status = riva_bl_update_status,
45736 };
45737diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
45738index 54fbb29..2c108fc 100644
45739--- a/drivers/video/uvesafb.c
45740+++ b/drivers/video/uvesafb.c
45741@@ -18,6 +18,7 @@
45742 #include <linux/fb.h>
45743 #include <linux/io.h>
45744 #include <linux/mutex.h>
45745+#include <linux/moduleloader.h>
45746 #include <video/edid.h>
45747 #include <video/uvesafb.h>
45748 #ifdef CONFIG_X86
45749@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
45750 NULL,
45751 };
45752
45753- return call_usermodehelper(v86d_path, argv, envp, 1);
45754+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
45755 }
45756
45757 /*
45758@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
45759 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
45760 par->pmi_setpal = par->ypan = 0;
45761 } else {
45762+
45763+#ifdef CONFIG_PAX_KERNEXEC
45764+#ifdef CONFIG_MODULES
45765+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
45766+#endif
45767+ if (!par->pmi_code) {
45768+ par->pmi_setpal = par->ypan = 0;
45769+ return 0;
45770+ }
45771+#endif
45772+
45773 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
45774 + task->t.regs.edi);
45775+
45776+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45777+ pax_open_kernel();
45778+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
45779+ pax_close_kernel();
45780+
45781+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
45782+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
45783+#else
45784 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
45785 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
45786+#endif
45787+
45788 printk(KERN_INFO "uvesafb: protected mode interface info at "
45789 "%04x:%04x\n",
45790 (u16)task->t.regs.es, (u16)task->t.regs.edi);
45791@@ -1799,6 +1822,11 @@ out:
45792 if (par->vbe_modes)
45793 kfree(par->vbe_modes);
45794
45795+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45796+ if (par->pmi_code)
45797+ module_free_exec(NULL, par->pmi_code);
45798+#endif
45799+
45800 framebuffer_release(info);
45801 return err;
45802 }
45803@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platform_device *dev)
45804 kfree(par->vbe_state_orig);
45805 if (par->vbe_state_saved)
45806 kfree(par->vbe_state_saved);
45807+
45808+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45809+ if (par->pmi_code)
45810+ module_free_exec(NULL, par->pmi_code);
45811+#endif
45812+
45813 }
45814
45815 framebuffer_release(info);
45816diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
45817index bd37ee1..cb827e8 100644
45818--- a/drivers/video/vesafb.c
45819+++ b/drivers/video/vesafb.c
45820@@ -9,6 +9,7 @@
45821 */
45822
45823 #include <linux/module.h>
45824+#include <linux/moduleloader.h>
45825 #include <linux/kernel.h>
45826 #include <linux/errno.h>
45827 #include <linux/string.h>
45828@@ -53,8 +54,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
45829 static int vram_total __initdata; /* Set total amount of memory */
45830 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
45831 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
45832-static void (*pmi_start)(void) __read_mostly;
45833-static void (*pmi_pal) (void) __read_mostly;
45834+static void (*pmi_start)(void) __read_only;
45835+static void (*pmi_pal) (void) __read_only;
45836 static int depth __read_mostly;
45837 static int vga_compat __read_mostly;
45838 /* --------------------------------------------------------------------- */
45839@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
45840 unsigned int size_vmode;
45841 unsigned int size_remap;
45842 unsigned int size_total;
45843+ void *pmi_code = NULL;
45844
45845 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45846 return -ENODEV;
45847@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45848 size_remap = size_total;
45849 vesafb_fix.smem_len = size_remap;
45850
45851-#ifndef __i386__
45852- screen_info.vesapm_seg = 0;
45853-#endif
45854-
45855 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45856 printk(KERN_WARNING
45857 "vesafb: cannot reserve video memory at 0x%lx\n",
45858@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45859 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45860 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45861
45862+#ifdef __i386__
45863+
45864+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45865+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45866+ if (!pmi_code)
45867+#elif !defined(CONFIG_PAX_KERNEXEC)
45868+ if (0)
45869+#endif
45870+
45871+#endif
45872+ screen_info.vesapm_seg = 0;
45873+
45874 if (screen_info.vesapm_seg) {
45875- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45876- screen_info.vesapm_seg,screen_info.vesapm_off);
45877+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45878+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45879 }
45880
45881 if (screen_info.vesapm_seg < 0xc000)
45882@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45883
45884 if (ypan || pmi_setpal) {
45885 unsigned short *pmi_base;
45886+
45887 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45888- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45889- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45890+
45891+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45892+ pax_open_kernel();
45893+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45894+#else
45895+ pmi_code = pmi_base;
45896+#endif
45897+
45898+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45899+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45900+
45901+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45902+ pmi_start = ktva_ktla(pmi_start);
45903+ pmi_pal = ktva_ktla(pmi_pal);
45904+ pax_close_kernel();
45905+#endif
45906+
45907 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45908 if (pmi_base[3]) {
45909 printk(KERN_INFO "vesafb: pmi: ports = ");
45910@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45911 info->node, info->fix.id);
45912 return 0;
45913 err:
45914+
45915+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45916+ module_free_exec(NULL, pmi_code);
45917+#endif
45918+
45919 if (info->screen_base)
45920 iounmap(info->screen_base);
45921 framebuffer_release(info);
45922diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c
45923index 88a60e0..6783cc2 100644
45924--- a/drivers/xen/sys-hypervisor.c
45925+++ b/drivers/xen/sys-hypervisor.c
45926@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct kobject *kobj,
45927 return 0;
45928 }
45929
45930-static struct sysfs_ops hyp_sysfs_ops = {
45931+static const struct sysfs_ops hyp_sysfs_ops = {
45932 .show = hyp_sysfs_show,
45933 .store = hyp_sysfs_store,
45934 };
45935diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45936index 18f74ec..3227009 100644
45937--- a/fs/9p/vfs_inode.c
45938+++ b/fs/9p/vfs_inode.c
45939@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45940 static void
45941 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45942 {
45943- char *s = nd_get_link(nd);
45944+ const char *s = nd_get_link(nd);
45945
45946 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
45947 IS_ERR(s) ? "<error>" : s);
45948diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45949index bb4cc5b..df5eaa0 100644
45950--- a/fs/Kconfig.binfmt
45951+++ b/fs/Kconfig.binfmt
45952@@ -86,7 +86,7 @@ config HAVE_AOUT
45953
45954 config BINFMT_AOUT
45955 tristate "Kernel support for a.out and ECOFF binaries"
45956- depends on HAVE_AOUT
45957+ depends on HAVE_AOUT && BROKEN
45958 ---help---
45959 A.out (Assembler.OUTput) is a set of formats for libraries and
45960 executables used in the earliest versions of UNIX. Linux used
45961diff --git a/fs/aio.c b/fs/aio.c
45962index 22a19ad..d484e5b 100644
45963--- a/fs/aio.c
45964+++ b/fs/aio.c
45965@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45966 size += sizeof(struct io_event) * nr_events;
45967 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45968
45969- if (nr_pages < 0)
45970+ if (nr_pages <= 0)
45971 return -EINVAL;
45972
45973 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45974@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ctx,
45975 struct aio_timeout to;
45976 int retry = 0;
45977
45978+ pax_track_stack();
45979+
45980 /* needed to zero any padding within an entry (there shouldn't be
45981 * any, but C is fun!
45982 */
45983@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45984 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
45985 {
45986 ssize_t ret;
45987+ struct iovec iovstack;
45988
45989 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
45990 kiocb->ki_nbytes, 1,
45991- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
45992+ &iovstack, &kiocb->ki_iovec);
45993 if (ret < 0)
45994 goto out;
45995
45996+ if (kiocb->ki_iovec == &iovstack) {
45997+ kiocb->ki_inline_vec = iovstack;
45998+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
45999+ }
46000 kiocb->ki_nr_segs = kiocb->ki_nbytes;
46001 kiocb->ki_cur_seg = 0;
46002 /* ki_nbytes/left now reflect bytes instead of segs */
46003diff --git a/fs/attr.c b/fs/attr.c
46004index 96d394b..33cf5b4 100644
46005--- a/fs/attr.c
46006+++ b/fs/attr.c
46007@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
46008 unsigned long limit;
46009
46010 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
46011+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
46012 if (limit != RLIM_INFINITY && offset > limit)
46013 goto out_sig;
46014 if (offset > inode->i_sb->s_maxbytes)
46015diff --git a/fs/autofs/root.c b/fs/autofs/root.c
46016index 4a1401c..05eb5ca 100644
46017--- a/fs/autofs/root.c
46018+++ b/fs/autofs/root.c
46019@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
46020 set_bit(n,sbi->symlink_bitmap);
46021 sl = &sbi->symlink[n];
46022 sl->len = strlen(symname);
46023- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
46024+ slsize = sl->len+1;
46025+ sl->data = kmalloc(slsize, GFP_KERNEL);
46026 if (!sl->data) {
46027 clear_bit(n,sbi->symlink_bitmap);
46028 unlock_kernel();
46029diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
46030index b4ea829..e63ef18 100644
46031--- a/fs/autofs4/symlink.c
46032+++ b/fs/autofs4/symlink.c
46033@@ -15,7 +15,7 @@
46034 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
46035 {
46036 struct autofs_info *ino = autofs4_dentry_ino(dentry);
46037- nd_set_link(nd, (char *)ino->u.symlink);
46038+ nd_set_link(nd, ino->u.symlink);
46039 return NULL;
46040 }
46041
46042diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
46043index 2341375..df9d1c2 100644
46044--- a/fs/autofs4/waitq.c
46045+++ b/fs/autofs4/waitq.c
46046@@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
46047 {
46048 unsigned long sigpipe, flags;
46049 mm_segment_t fs;
46050- const char *data = (const char *)addr;
46051+ const char __user *data = (const char __force_user *)addr;
46052 ssize_t wr = 0;
46053
46054 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
46055diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
46056index 9158c07..3f06659 100644
46057--- a/fs/befs/linuxvfs.c
46058+++ b/fs/befs/linuxvfs.c
46059@@ -498,7 +498,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46060 {
46061 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
46062 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
46063- char *link = nd_get_link(nd);
46064+ const char *link = nd_get_link(nd);
46065 if (!IS_ERR(link))
46066 kfree(link);
46067 }
46068diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
46069index 0133b5a..b3baa9f 100644
46070--- a/fs/binfmt_aout.c
46071+++ b/fs/binfmt_aout.c
46072@@ -16,6 +16,7 @@
46073 #include <linux/string.h>
46074 #include <linux/fs.h>
46075 #include <linux/file.h>
46076+#include <linux/security.h>
46077 #include <linux/stat.h>
46078 #include <linux/fcntl.h>
46079 #include <linux/ptrace.h>
46080@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46081 #endif
46082 # define START_STACK(u) (u.start_stack)
46083
46084+ memset(&dump, 0, sizeof(dump));
46085+
46086 fs = get_fs();
46087 set_fs(KERNEL_DS);
46088 has_dumped = 1;
46089@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46090
46091 /* If the size of the dump file exceeds the rlimit, then see what would happen
46092 if we wrote the stack, but not the data area. */
46093+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
46094 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
46095 dump.u_dsize = 0;
46096
46097 /* Make sure we have enough room to write the stack and data areas. */
46098+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
46099 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
46100 dump.u_ssize = 0;
46101
46102@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46103 dump_size = dump.u_ssize << PAGE_SHIFT;
46104 DUMP_WRITE(dump_start,dump_size);
46105 }
46106-/* Finally dump the task struct. Not be used by gdb, but could be useful */
46107- set_fs(KERNEL_DS);
46108- DUMP_WRITE(current,sizeof(*current));
46109+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
46110 end_coredump:
46111 set_fs(fs);
46112 return has_dumped;
46113@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46114 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
46115 if (rlim >= RLIM_INFINITY)
46116 rlim = ~0;
46117+
46118+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
46119 if (ex.a_data + ex.a_bss > rlim)
46120 return -ENOMEM;
46121
46122@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46123 install_exec_creds(bprm);
46124 current->flags &= ~PF_FORKNOEXEC;
46125
46126+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46127+ current->mm->pax_flags = 0UL;
46128+#endif
46129+
46130+#ifdef CONFIG_PAX_PAGEEXEC
46131+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
46132+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
46133+
46134+#ifdef CONFIG_PAX_EMUTRAMP
46135+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
46136+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
46137+#endif
46138+
46139+#ifdef CONFIG_PAX_MPROTECT
46140+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
46141+ current->mm->pax_flags |= MF_PAX_MPROTECT;
46142+#endif
46143+
46144+ }
46145+#endif
46146+
46147 if (N_MAGIC(ex) == OMAGIC) {
46148 unsigned long text_addr, map_size;
46149 loff_t pos;
46150@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46151
46152 down_write(&current->mm->mmap_sem);
46153 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
46154- PROT_READ | PROT_WRITE | PROT_EXEC,
46155+ PROT_READ | PROT_WRITE,
46156 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
46157 fd_offset + ex.a_text);
46158 up_write(&current->mm->mmap_sem);
46159diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
46160index 1ed37ba..32cc555 100644
46161--- a/fs/binfmt_elf.c
46162+++ b/fs/binfmt_elf.c
46163@@ -50,6 +50,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46164 #define elf_core_dump NULL
46165 #endif
46166
46167+#ifdef CONFIG_PAX_MPROTECT
46168+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
46169+#endif
46170+
46171 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
46172 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
46173 #else
46174@@ -69,6 +73,11 @@ static struct linux_binfmt elf_format = {
46175 .load_binary = load_elf_binary,
46176 .load_shlib = load_elf_library,
46177 .core_dump = elf_core_dump,
46178+
46179+#ifdef CONFIG_PAX_MPROTECT
46180+ .handle_mprotect= elf_handle_mprotect,
46181+#endif
46182+
46183 .min_coredump = ELF_EXEC_PAGESIZE,
46184 .hasvdso = 1
46185 };
46186@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format = {
46187
46188 static int set_brk(unsigned long start, unsigned long end)
46189 {
46190+ unsigned long e = end;
46191+
46192 start = ELF_PAGEALIGN(start);
46193 end = ELF_PAGEALIGN(end);
46194 if (end > start) {
46195@@ -87,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
46196 if (BAD_ADDR(addr))
46197 return addr;
46198 }
46199- current->mm->start_brk = current->mm->brk = end;
46200+ current->mm->start_brk = current->mm->brk = e;
46201 return 0;
46202 }
46203
46204@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46205 elf_addr_t __user *u_rand_bytes;
46206 const char *k_platform = ELF_PLATFORM;
46207 const char *k_base_platform = ELF_BASE_PLATFORM;
46208- unsigned char k_rand_bytes[16];
46209+ u32 k_rand_bytes[4];
46210 int items;
46211 elf_addr_t *elf_info;
46212 int ei_index = 0;
46213 const struct cred *cred = current_cred();
46214 struct vm_area_struct *vma;
46215+ unsigned long saved_auxv[AT_VECTOR_SIZE];
46216+
46217+ pax_track_stack();
46218
46219 /*
46220 * In some cases (e.g. Hyper-Threading), we want to avoid L1
46221@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46222 * Generate 16 random bytes for userspace PRNG seeding.
46223 */
46224 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
46225- u_rand_bytes = (elf_addr_t __user *)
46226- STACK_ALLOC(p, sizeof(k_rand_bytes));
46227+ srandom32(k_rand_bytes[0] ^ random32());
46228+ srandom32(k_rand_bytes[1] ^ random32());
46229+ srandom32(k_rand_bytes[2] ^ random32());
46230+ srandom32(k_rand_bytes[3] ^ random32());
46231+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
46232+ u_rand_bytes = (elf_addr_t __user *) p;
46233 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
46234 return -EFAULT;
46235
46236@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46237 return -EFAULT;
46238 current->mm->env_end = p;
46239
46240+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
46241+
46242 /* Put the elf_info on the stack in the right place. */
46243 sp = (elf_addr_t __user *)envp + 1;
46244- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
46245+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
46246 return -EFAULT;
46247 return 0;
46248 }
46249@@ -385,10 +405,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46250 {
46251 struct elf_phdr *elf_phdata;
46252 struct elf_phdr *eppnt;
46253- unsigned long load_addr = 0;
46254+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
46255 int load_addr_set = 0;
46256 unsigned long last_bss = 0, elf_bss = 0;
46257- unsigned long error = ~0UL;
46258+ unsigned long error = -EINVAL;
46259 unsigned long total_size;
46260 int retval, i, size;
46261
46262@@ -434,6 +454,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46263 goto out_close;
46264 }
46265
46266+#ifdef CONFIG_PAX_SEGMEXEC
46267+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
46268+ pax_task_size = SEGMEXEC_TASK_SIZE;
46269+#endif
46270+
46271 eppnt = elf_phdata;
46272 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
46273 if (eppnt->p_type == PT_LOAD) {
46274@@ -477,8 +502,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46275 k = load_addr + eppnt->p_vaddr;
46276 if (BAD_ADDR(k) ||
46277 eppnt->p_filesz > eppnt->p_memsz ||
46278- eppnt->p_memsz > TASK_SIZE ||
46279- TASK_SIZE - eppnt->p_memsz < k) {
46280+ eppnt->p_memsz > pax_task_size ||
46281+ pax_task_size - eppnt->p_memsz < k) {
46282 error = -ENOMEM;
46283 goto out_close;
46284 }
46285@@ -532,6 +557,194 @@ out:
46286 return error;
46287 }
46288
46289+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
46290+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
46291+{
46292+ unsigned long pax_flags = 0UL;
46293+
46294+#ifdef CONFIG_PAX_PAGEEXEC
46295+ if (elf_phdata->p_flags & PF_PAGEEXEC)
46296+ pax_flags |= MF_PAX_PAGEEXEC;
46297+#endif
46298+
46299+#ifdef CONFIG_PAX_SEGMEXEC
46300+ if (elf_phdata->p_flags & PF_SEGMEXEC)
46301+ pax_flags |= MF_PAX_SEGMEXEC;
46302+#endif
46303+
46304+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46305+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46306+ if (nx_enabled)
46307+ pax_flags &= ~MF_PAX_SEGMEXEC;
46308+ else
46309+ pax_flags &= ~MF_PAX_PAGEEXEC;
46310+ }
46311+#endif
46312+
46313+#ifdef CONFIG_PAX_EMUTRAMP
46314+ if (elf_phdata->p_flags & PF_EMUTRAMP)
46315+ pax_flags |= MF_PAX_EMUTRAMP;
46316+#endif
46317+
46318+#ifdef CONFIG_PAX_MPROTECT
46319+ if (elf_phdata->p_flags & PF_MPROTECT)
46320+ pax_flags |= MF_PAX_MPROTECT;
46321+#endif
46322+
46323+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46324+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
46325+ pax_flags |= MF_PAX_RANDMMAP;
46326+#endif
46327+
46328+ return pax_flags;
46329+}
46330+#endif
46331+
46332+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46333+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
46334+{
46335+ unsigned long pax_flags = 0UL;
46336+
46337+#ifdef CONFIG_PAX_PAGEEXEC
46338+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
46339+ pax_flags |= MF_PAX_PAGEEXEC;
46340+#endif
46341+
46342+#ifdef CONFIG_PAX_SEGMEXEC
46343+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
46344+ pax_flags |= MF_PAX_SEGMEXEC;
46345+#endif
46346+
46347+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46348+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46349+ if (nx_enabled)
46350+ pax_flags &= ~MF_PAX_SEGMEXEC;
46351+ else
46352+ pax_flags &= ~MF_PAX_PAGEEXEC;
46353+ }
46354+#endif
46355+
46356+#ifdef CONFIG_PAX_EMUTRAMP
46357+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
46358+ pax_flags |= MF_PAX_EMUTRAMP;
46359+#endif
46360+
46361+#ifdef CONFIG_PAX_MPROTECT
46362+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
46363+ pax_flags |= MF_PAX_MPROTECT;
46364+#endif
46365+
46366+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46367+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
46368+ pax_flags |= MF_PAX_RANDMMAP;
46369+#endif
46370+
46371+ return pax_flags;
46372+}
46373+#endif
46374+
46375+#ifdef CONFIG_PAX_EI_PAX
46376+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
46377+{
46378+ unsigned long pax_flags = 0UL;
46379+
46380+#ifdef CONFIG_PAX_PAGEEXEC
46381+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
46382+ pax_flags |= MF_PAX_PAGEEXEC;
46383+#endif
46384+
46385+#ifdef CONFIG_PAX_SEGMEXEC
46386+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
46387+ pax_flags |= MF_PAX_SEGMEXEC;
46388+#endif
46389+
46390+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46391+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46392+ if (nx_enabled)
46393+ pax_flags &= ~MF_PAX_SEGMEXEC;
46394+ else
46395+ pax_flags &= ~MF_PAX_PAGEEXEC;
46396+ }
46397+#endif
46398+
46399+#ifdef CONFIG_PAX_EMUTRAMP
46400+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
46401+ pax_flags |= MF_PAX_EMUTRAMP;
46402+#endif
46403+
46404+#ifdef CONFIG_PAX_MPROTECT
46405+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
46406+ pax_flags |= MF_PAX_MPROTECT;
46407+#endif
46408+
46409+#ifdef CONFIG_PAX_ASLR
46410+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
46411+ pax_flags |= MF_PAX_RANDMMAP;
46412+#endif
46413+
46414+ return pax_flags;
46415+}
46416+#endif
46417+
46418+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
46419+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
46420+{
46421+ unsigned long pax_flags = 0UL;
46422+
46423+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46424+ unsigned long i;
46425+ int found_flags = 0;
46426+#endif
46427+
46428+#ifdef CONFIG_PAX_EI_PAX
46429+ pax_flags = pax_parse_ei_pax(elf_ex);
46430+#endif
46431+
46432+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46433+ for (i = 0UL; i < elf_ex->e_phnum; i++)
46434+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
46435+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
46436+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
46437+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
46438+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
46439+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
46440+ return -EINVAL;
46441+
46442+#ifdef CONFIG_PAX_SOFTMODE
46443+ if (pax_softmode)
46444+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
46445+ else
46446+#endif
46447+
46448+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
46449+ found_flags = 1;
46450+ break;
46451+ }
46452+#endif
46453+
46454+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
46455+ if (found_flags == 0) {
46456+ struct elf_phdr phdr;
46457+ memset(&phdr, 0, sizeof(phdr));
46458+ phdr.p_flags = PF_NOEMUTRAMP;
46459+#ifdef CONFIG_PAX_SOFTMODE
46460+ if (pax_softmode)
46461+ pax_flags = pax_parse_softmode(&phdr);
46462+ else
46463+#endif
46464+ pax_flags = pax_parse_hardmode(&phdr);
46465+ }
46466+#endif
46467+
46468+
46469+ if (0 > pax_check_flags(&pax_flags))
46470+ return -EINVAL;
46471+
46472+ current->mm->pax_flags = pax_flags;
46473+ return 0;
46474+}
46475+#endif
46476+
46477 /*
46478 * These are the functions used to load ELF style executables and shared
46479 * libraries. There is no binary dependent code anywhere else.
46480@@ -548,6 +761,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
46481 {
46482 unsigned int random_variable = 0;
46483
46484+#ifdef CONFIG_PAX_RANDUSTACK
46485+ if (randomize_va_space)
46486+ return stack_top - current->mm->delta_stack;
46487+#endif
46488+
46489 if ((current->flags & PF_RANDOMIZE) &&
46490 !(current->personality & ADDR_NO_RANDOMIZE)) {
46491 random_variable = get_random_int() & STACK_RND_MASK;
46492@@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46493 unsigned long load_addr = 0, load_bias = 0;
46494 int load_addr_set = 0;
46495 char * elf_interpreter = NULL;
46496- unsigned long error;
46497+ unsigned long error = 0;
46498 struct elf_phdr *elf_ppnt, *elf_phdata;
46499 unsigned long elf_bss, elf_brk;
46500 int retval, i;
46501@@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46502 unsigned long start_code, end_code, start_data, end_data;
46503 unsigned long reloc_func_desc = 0;
46504 int executable_stack = EXSTACK_DEFAULT;
46505- unsigned long def_flags = 0;
46506 struct {
46507 struct elfhdr elf_ex;
46508 struct elfhdr interp_elf_ex;
46509 } *loc;
46510+ unsigned long pax_task_size = TASK_SIZE;
46511
46512 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
46513 if (!loc) {
46514@@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46515
46516 /* OK, This is the point of no return */
46517 current->flags &= ~PF_FORKNOEXEC;
46518- current->mm->def_flags = def_flags;
46519+
46520+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46521+ current->mm->pax_flags = 0UL;
46522+#endif
46523+
46524+#ifdef CONFIG_PAX_DLRESOLVE
46525+ current->mm->call_dl_resolve = 0UL;
46526+#endif
46527+
46528+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46529+ current->mm->call_syscall = 0UL;
46530+#endif
46531+
46532+#ifdef CONFIG_PAX_ASLR
46533+ current->mm->delta_mmap = 0UL;
46534+ current->mm->delta_stack = 0UL;
46535+#endif
46536+
46537+ current->mm->def_flags = 0;
46538+
46539+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
46540+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
46541+ send_sig(SIGKILL, current, 0);
46542+ goto out_free_dentry;
46543+ }
46544+#endif
46545+
46546+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46547+ pax_set_initial_flags(bprm);
46548+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
46549+ if (pax_set_initial_flags_func)
46550+ (pax_set_initial_flags_func)(bprm);
46551+#endif
46552+
46553+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46554+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
46555+ current->mm->context.user_cs_limit = PAGE_SIZE;
46556+ current->mm->def_flags |= VM_PAGEEXEC;
46557+ }
46558+#endif
46559+
46560+#ifdef CONFIG_PAX_SEGMEXEC
46561+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
46562+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
46563+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
46564+ pax_task_size = SEGMEXEC_TASK_SIZE;
46565+ }
46566+#endif
46567+
46568+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
46569+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46570+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
46571+ put_cpu();
46572+ }
46573+#endif
46574
46575 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
46576 may depend on the personality. */
46577 SET_PERSONALITY(loc->elf_ex);
46578+
46579+#ifdef CONFIG_PAX_ASLR
46580+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
46581+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
46582+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
46583+ }
46584+#endif
46585+
46586+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46587+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46588+ executable_stack = EXSTACK_DISABLE_X;
46589+ current->personality &= ~READ_IMPLIES_EXEC;
46590+ } else
46591+#endif
46592+
46593 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
46594 current->personality |= READ_IMPLIES_EXEC;
46595
46596@@ -800,10 +1087,27 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46597 * might try to exec. This is because the brk will
46598 * follow the loader, and is not movable. */
46599 #ifdef CONFIG_X86
46600- load_bias = 0;
46601+ if (current->flags & PF_RANDOMIZE)
46602+ load_bias = 0;
46603+ else
46604+ load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46605 #else
46606 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46607 #endif
46608+
46609+#ifdef CONFIG_PAX_RANDMMAP
46610+ /* PaX: randomize base address at the default exe base if requested */
46611+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
46612+#ifdef CONFIG_SPARC64
46613+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
46614+#else
46615+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
46616+#endif
46617+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
46618+ elf_flags |= MAP_FIXED;
46619+ }
46620+#endif
46621+
46622 }
46623
46624 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
46625@@ -836,9 +1140,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46626 * allowed task size. Note that p_filesz must always be
46627 * <= p_memsz so it is only necessary to check p_memsz.
46628 */
46629- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46630- elf_ppnt->p_memsz > TASK_SIZE ||
46631- TASK_SIZE - elf_ppnt->p_memsz < k) {
46632+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46633+ elf_ppnt->p_memsz > pax_task_size ||
46634+ pax_task_size - elf_ppnt->p_memsz < k) {
46635 /* set_brk can never work. Avoid overflows. */
46636 send_sig(SIGKILL, current, 0);
46637 retval = -EINVAL;
46638@@ -866,6 +1170,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46639 start_data += load_bias;
46640 end_data += load_bias;
46641
46642+#ifdef CONFIG_PAX_RANDMMAP
46643+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
46644+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
46645+#endif
46646+
46647 /* Calling set_brk effectively mmaps the pages that we need
46648 * for the bss and break sections. We must do this before
46649 * mapping in the interpreter, to make sure it doesn't wind
46650@@ -877,9 +1186,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46651 goto out_free_dentry;
46652 }
46653 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
46654- send_sig(SIGSEGV, current, 0);
46655- retval = -EFAULT; /* Nobody gets to see this, but.. */
46656- goto out_free_dentry;
46657+ /*
46658+ * This bss-zeroing can fail if the ELF
46659+ * file specifies odd protections. So
46660+ * we don't check the return value
46661+ */
46662 }
46663
46664 if (elf_interpreter) {
46665@@ -1112,8 +1423,10 @@ static int dump_seek(struct file *file, loff_t off)
46666 unsigned long n = off;
46667 if (n > PAGE_SIZE)
46668 n = PAGE_SIZE;
46669- if (!dump_write(file, buf, n))
46670+ if (!dump_write(file, buf, n)) {
46671+ free_page((unsigned long)buf);
46672 return 0;
46673+ }
46674 off -= n;
46675 }
46676 free_page((unsigned long)buf);
46677@@ -1125,7 +1438,7 @@ static int dump_seek(struct file *file, loff_t off)
46678 * Decide what to dump of a segment, part, all or none.
46679 */
46680 static unsigned long vma_dump_size(struct vm_area_struct *vma,
46681- unsigned long mm_flags)
46682+ unsigned long mm_flags, long signr)
46683 {
46684 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
46685
46686@@ -1159,7 +1472,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
46687 if (vma->vm_file == NULL)
46688 return 0;
46689
46690- if (FILTER(MAPPED_PRIVATE))
46691+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46692 goto whole;
46693
46694 /*
46695@@ -1255,8 +1568,11 @@ static int writenote(struct memelfnote *men, struct file *file,
46696 #undef DUMP_WRITE
46697
46698 #define DUMP_WRITE(addr, nr) \
46699+ do { \
46700+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
46701 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
46702- goto end_coredump;
46703+ goto end_coredump; \
46704+ } while (0);
46705
46706 static void fill_elf_header(struct elfhdr *elf, int segs,
46707 u16 machine, u32 flags, u8 osabi)
46708@@ -1385,9 +1701,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46709 {
46710 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46711 int i = 0;
46712- do
46713+ do {
46714 i += 2;
46715- while (auxv[i - 2] != AT_NULL);
46716+ } while (auxv[i - 2] != AT_NULL);
46717 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46718 }
46719
46720@@ -1973,7 +2289,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46721 phdr.p_offset = offset;
46722 phdr.p_vaddr = vma->vm_start;
46723 phdr.p_paddr = 0;
46724- phdr.p_filesz = vma_dump_size(vma, mm_flags);
46725+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
46726 phdr.p_memsz = vma->vm_end - vma->vm_start;
46727 offset += phdr.p_filesz;
46728 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46729@@ -2006,7 +2322,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46730 unsigned long addr;
46731 unsigned long end;
46732
46733- end = vma->vm_start + vma_dump_size(vma, mm_flags);
46734+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
46735
46736 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46737 struct page *page;
46738@@ -2015,6 +2331,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46739 page = get_dump_page(addr);
46740 if (page) {
46741 void *kaddr = kmap(page);
46742+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46743 stop = ((size += PAGE_SIZE) > limit) ||
46744 !dump_write(file, kaddr, PAGE_SIZE);
46745 kunmap(page);
46746@@ -2042,6 +2359,97 @@ out:
46747
46748 #endif /* USE_ELF_CORE_DUMP */
46749
46750+#ifdef CONFIG_PAX_MPROTECT
46751+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46752+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46753+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46754+ *
46755+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46756+ * basis because we want to allow the common case and not the special ones.
46757+ */
46758+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46759+{
46760+ struct elfhdr elf_h;
46761+ struct elf_phdr elf_p;
46762+ unsigned long i;
46763+ unsigned long oldflags;
46764+ bool is_textrel_rw, is_textrel_rx, is_relro;
46765+
46766+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46767+ return;
46768+
46769+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46770+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46771+
46772+#ifdef CONFIG_PAX_ELFRELOCS
46773+ /* possible TEXTREL */
46774+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46775+ is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
46776+#else
46777+ is_textrel_rw = false;
46778+ is_textrel_rx = false;
46779+#endif
46780+
46781+ /* possible RELRO */
46782+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46783+
46784+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46785+ return;
46786+
46787+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46788+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46789+
46790+#ifdef CONFIG_PAX_ETEXECRELOCS
46791+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46792+#else
46793+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46794+#endif
46795+
46796+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46797+ !elf_check_arch(&elf_h) ||
46798+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46799+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46800+ return;
46801+
46802+ for (i = 0UL; i < elf_h.e_phnum; i++) {
46803+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46804+ return;
46805+ switch (elf_p.p_type) {
46806+ case PT_DYNAMIC:
46807+ if (!is_textrel_rw && !is_textrel_rx)
46808+ continue;
46809+ i = 0UL;
46810+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46811+ elf_dyn dyn;
46812+
46813+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46814+ return;
46815+ if (dyn.d_tag == DT_NULL)
46816+ return;
46817+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46818+ gr_log_textrel(vma);
46819+ if (is_textrel_rw)
46820+ vma->vm_flags |= VM_MAYWRITE;
46821+ else
46822+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46823+ vma->vm_flags &= ~VM_MAYWRITE;
46824+ return;
46825+ }
46826+ i++;
46827+ }
46828+ return;
46829+
46830+ case PT_GNU_RELRO:
46831+ if (!is_relro)
46832+ continue;
46833+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46834+ vma->vm_flags &= ~VM_MAYWRITE;
46835+ return;
46836+ }
46837+ }
46838+}
46839+#endif
46840+
46841 static int __init init_elf_binfmt(void)
46842 {
46843 return register_binfmt(&elf_format);
46844diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46845index ca88c46..f155a60 100644
46846--- a/fs/binfmt_flat.c
46847+++ b/fs/binfmt_flat.c
46848@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46849 realdatastart = (unsigned long) -ENOMEM;
46850 printk("Unable to allocate RAM for process data, errno %d\n",
46851 (int)-realdatastart);
46852+ down_write(&current->mm->mmap_sem);
46853 do_munmap(current->mm, textpos, text_len);
46854+ up_write(&current->mm->mmap_sem);
46855 ret = realdatastart;
46856 goto err;
46857 }
46858@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46859 }
46860 if (IS_ERR_VALUE(result)) {
46861 printk("Unable to read data+bss, errno %d\n", (int)-result);
46862+ down_write(&current->mm->mmap_sem);
46863 do_munmap(current->mm, textpos, text_len);
46864 do_munmap(current->mm, realdatastart, data_len + extra);
46865+ up_write(&current->mm->mmap_sem);
46866 ret = result;
46867 goto err;
46868 }
46869@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46870 }
46871 if (IS_ERR_VALUE(result)) {
46872 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46873+ down_write(&current->mm->mmap_sem);
46874 do_munmap(current->mm, textpos, text_len + data_len + extra +
46875 MAX_SHARED_LIBS * sizeof(unsigned long));
46876+ up_write(&current->mm->mmap_sem);
46877 ret = result;
46878 goto err;
46879 }
46880diff --git a/fs/bio.c b/fs/bio.c
46881index e696713..83de133 100644
46882--- a/fs/bio.c
46883+++ b/fs/bio.c
46884@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
46885
46886 i = 0;
46887 while (i < bio_slab_nr) {
46888- struct bio_slab *bslab = &bio_slabs[i];
46889+ bslab = &bio_slabs[i];
46890
46891 if (!bslab->slab && entry == -1)
46892 entry = i;
46893@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46894 const int read = bio_data_dir(bio) == READ;
46895 struct bio_map_data *bmd = bio->bi_private;
46896 int i;
46897- char *p = bmd->sgvecs[0].iov_base;
46898+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46899
46900 __bio_for_each_segment(bvec, bio, i, 0) {
46901 char *addr = page_address(bvec->bv_page);
46902diff --git a/fs/block_dev.c b/fs/block_dev.c
46903index e65efa2..04fae57 100644
46904--- a/fs/block_dev.c
46905+++ b/fs/block_dev.c
46906@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev, void *holder)
46907 else if (bdev->bd_contains == bdev)
46908 res = 0; /* is a whole device which isn't held */
46909
46910- else if (bdev->bd_contains->bd_holder == bd_claim)
46911+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
46912 res = 0; /* is a partition of a device that is being partitioned */
46913 else if (bdev->bd_contains->bd_holder != NULL)
46914 res = -EBUSY; /* is a partition of a held device */
46915diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46916index c4bc570..42acd8d 100644
46917--- a/fs/btrfs/ctree.c
46918+++ b/fs/btrfs/ctree.c
46919@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46920 free_extent_buffer(buf);
46921 add_root_to_dirty_list(root);
46922 } else {
46923- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46924- parent_start = parent->start;
46925- else
46926+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46927+ if (parent)
46928+ parent_start = parent->start;
46929+ else
46930+ parent_start = 0;
46931+ } else
46932 parent_start = 0;
46933
46934 WARN_ON(trans->transid != btrfs_header_generation(parent));
46935@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_trans_handle *trans,
46936
46937 ret = 0;
46938 if (slot == 0) {
46939- struct btrfs_disk_key disk_key;
46940 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
46941 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
46942 }
46943diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
46944index f447188..59c17c5 100644
46945--- a/fs/btrfs/disk-io.c
46946+++ b/fs/btrfs/disk-io.c
46947@@ -39,7 +39,7 @@
46948 #include "tree-log.h"
46949 #include "free-space-cache.h"
46950
46951-static struct extent_io_ops btree_extent_io_ops;
46952+static const struct extent_io_ops btree_extent_io_ops;
46953 static void end_workqueue_fn(struct btrfs_work *work);
46954 static void free_fs_root(struct btrfs_root *root);
46955
46956@@ -2607,7 +2607,7 @@ out:
46957 return 0;
46958 }
46959
46960-static struct extent_io_ops btree_extent_io_ops = {
46961+static const struct extent_io_ops btree_extent_io_ops = {
46962 .write_cache_pages_lock_hook = btree_lock_page_hook,
46963 .readpage_end_io_hook = btree_readpage_end_io_hook,
46964 .submit_bio_hook = btree_submit_bio_hook,
46965diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
46966index 559f724..a026171 100644
46967--- a/fs/btrfs/extent-tree.c
46968+++ b/fs/btrfs/extent-tree.c
46969@@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,
46970 u64 group_start = group->key.objectid;
46971 new_extents = kmalloc(sizeof(*new_extents),
46972 GFP_NOFS);
46973+ if (!new_extents) {
46974+ ret = -ENOMEM;
46975+ goto out;
46976+ }
46977 nr_extents = 1;
46978 ret = get_new_locations(reloc_inode,
46979 extent_key,
46980diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
46981index 36de250..7ec75c7 100644
46982--- a/fs/btrfs/extent_io.h
46983+++ b/fs/btrfs/extent_io.h
46984@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
46985 struct bio *bio, int mirror_num,
46986 unsigned long bio_flags);
46987 struct extent_io_ops {
46988- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
46989+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
46990 u64 start, u64 end, int *page_started,
46991 unsigned long *nr_written);
46992- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
46993- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
46994+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
46995+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
46996 extent_submit_bio_hook_t *submit_bio_hook;
46997- int (*merge_bio_hook)(struct page *page, unsigned long offset,
46998+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
46999 size_t size, struct bio *bio,
47000 unsigned long bio_flags);
47001- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
47002- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47003+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
47004+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
47005 u64 start, u64 end,
47006 struct extent_state *state);
47007- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
47008+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
47009 u64 start, u64 end,
47010 struct extent_state *state);
47011- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47012+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47013 struct extent_state *state);
47014- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47015+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47016 struct extent_state *state, int uptodate);
47017- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
47018+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
47019 unsigned long old, unsigned long bits);
47020- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
47021+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
47022 unsigned long bits);
47023- int (*merge_extent_hook)(struct inode *inode,
47024+ int (* const merge_extent_hook)(struct inode *inode,
47025 struct extent_state *new,
47026 struct extent_state *other);
47027- int (*split_extent_hook)(struct inode *inode,
47028+ int (* const split_extent_hook)(struct inode *inode,
47029 struct extent_state *orig, u64 split);
47030- int (*write_cache_pages_lock_hook)(struct page *page);
47031+ int (* const write_cache_pages_lock_hook)(struct page *page);
47032 };
47033
47034 struct extent_io_tree {
47035@@ -88,7 +88,7 @@ struct extent_io_tree {
47036 u64 dirty_bytes;
47037 spinlock_t lock;
47038 spinlock_t buffer_lock;
47039- struct extent_io_ops *ops;
47040+ const struct extent_io_ops *ops;
47041 };
47042
47043 struct extent_state {
47044diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
47045index cb2849f..3718fb4 100644
47046--- a/fs/btrfs/free-space-cache.c
47047+++ b/fs/btrfs/free-space-cache.c
47048@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
47049
47050 while(1) {
47051 if (entry->bytes < bytes || entry->offset < min_start) {
47052- struct rb_node *node;
47053-
47054 node = rb_next(&entry->offset_index);
47055 if (!node)
47056 break;
47057@@ -1226,7 +1224,7 @@ again:
47058 */
47059 while (entry->bitmap || found_bitmap ||
47060 (!entry->bitmap && entry->bytes < min_bytes)) {
47061- struct rb_node *node = rb_next(&entry->offset_index);
47062+ node = rb_next(&entry->offset_index);
47063
47064 if (entry->bitmap && entry->bytes > bytes + empty_size) {
47065 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
47066diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
47067index e03a836..323837e 100644
47068--- a/fs/btrfs/inode.c
47069+++ b/fs/btrfs/inode.c
47070@@ -63,7 +63,7 @@ static const struct inode_operations btrfs_file_inode_operations;
47071 static const struct address_space_operations btrfs_aops;
47072 static const struct address_space_operations btrfs_symlink_aops;
47073 static const struct file_operations btrfs_dir_file_operations;
47074-static struct extent_io_ops btrfs_extent_io_ops;
47075+static const struct extent_io_ops btrfs_extent_io_ops;
47076
47077 static struct kmem_cache *btrfs_inode_cachep;
47078 struct kmem_cache *btrfs_trans_handle_cachep;
47079@@ -925,6 +925,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
47080 1, 0, NULL, GFP_NOFS);
47081 while (start < end) {
47082 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
47083+ BUG_ON(!async_cow);
47084 async_cow->inode = inode;
47085 async_cow->root = root;
47086 async_cow->locked_page = locked_page;
47087@@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(struct btrfs_path *path,
47088 inline_size = btrfs_file_extent_inline_item_len(leaf,
47089 btrfs_item_nr(leaf, path->slots[0]));
47090 tmp = kmalloc(inline_size, GFP_NOFS);
47091+ if (!tmp)
47092+ return -ENOMEM;
47093 ptr = btrfs_file_extent_inline_start(item);
47094
47095 read_extent_buffer(leaf, tmp, ptr, inline_size);
47096@@ -5410,7 +5413,7 @@ fail:
47097 return -ENOMEM;
47098 }
47099
47100-static int btrfs_getattr(struct vfsmount *mnt,
47101+int btrfs_getattr(struct vfsmount *mnt,
47102 struct dentry *dentry, struct kstat *stat)
47103 {
47104 struct inode *inode = dentry->d_inode;
47105@@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
47106 return 0;
47107 }
47108
47109+EXPORT_SYMBOL(btrfs_getattr);
47110+
47111+dev_t get_btrfs_dev_from_inode(struct inode *inode)
47112+{
47113+ return BTRFS_I(inode)->root->anon_super.s_dev;
47114+}
47115+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
47116+
47117 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
47118 struct inode *new_dir, struct dentry *new_dentry)
47119 {
47120@@ -5972,7 +5983,7 @@ static const struct file_operations btrfs_dir_file_operations = {
47121 .fsync = btrfs_sync_file,
47122 };
47123
47124-static struct extent_io_ops btrfs_extent_io_ops = {
47125+static const struct extent_io_ops btrfs_extent_io_ops = {
47126 .fill_delalloc = run_delalloc_range,
47127 .submit_bio_hook = btrfs_submit_bio_hook,
47128 .merge_bio_hook = btrfs_merge_bio_hook,
47129diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
47130index ab7ab53..94e0781 100644
47131--- a/fs/btrfs/relocation.c
47132+++ b/fs/btrfs/relocation.c
47133@@ -884,7 +884,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
47134 }
47135 spin_unlock(&rc->reloc_root_tree.lock);
47136
47137- BUG_ON((struct btrfs_root *)node->data != root);
47138+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
47139
47140 if (!del) {
47141 spin_lock(&rc->reloc_root_tree.lock);
47142diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
47143index a240b6f..4ce16ef 100644
47144--- a/fs/btrfs/sysfs.c
47145+++ b/fs/btrfs/sysfs.c
47146@@ -164,12 +164,12 @@ static void btrfs_root_release(struct kobject *kobj)
47147 complete(&root->kobj_unregister);
47148 }
47149
47150-static struct sysfs_ops btrfs_super_attr_ops = {
47151+static const struct sysfs_ops btrfs_super_attr_ops = {
47152 .show = btrfs_super_attr_show,
47153 .store = btrfs_super_attr_store,
47154 };
47155
47156-static struct sysfs_ops btrfs_root_attr_ops = {
47157+static const struct sysfs_ops btrfs_root_attr_ops = {
47158 .show = btrfs_root_attr_show,
47159 .store = btrfs_root_attr_store,
47160 };
47161diff --git a/fs/buffer.c b/fs/buffer.c
47162index 6fa5302..395d9f6 100644
47163--- a/fs/buffer.c
47164+++ b/fs/buffer.c
47165@@ -25,6 +25,7 @@
47166 #include <linux/percpu.h>
47167 #include <linux/slab.h>
47168 #include <linux/capability.h>
47169+#include <linux/security.h>
47170 #include <linux/blkdev.h>
47171 #include <linux/file.h>
47172 #include <linux/quotaops.h>
47173diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
47174index 3797e00..ce776f6 100644
47175--- a/fs/cachefiles/bind.c
47176+++ b/fs/cachefiles/bind.c
47177@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
47178 args);
47179
47180 /* start by checking things over */
47181- ASSERT(cache->fstop_percent >= 0 &&
47182- cache->fstop_percent < cache->fcull_percent &&
47183+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
47184 cache->fcull_percent < cache->frun_percent &&
47185 cache->frun_percent < 100);
47186
47187- ASSERT(cache->bstop_percent >= 0 &&
47188- cache->bstop_percent < cache->bcull_percent &&
47189+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
47190 cache->bcull_percent < cache->brun_percent &&
47191 cache->brun_percent < 100);
47192
47193diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
47194index 4618516..bb30d01 100644
47195--- a/fs/cachefiles/daemon.c
47196+++ b/fs/cachefiles/daemon.c
47197@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
47198 if (test_bit(CACHEFILES_DEAD, &cache->flags))
47199 return -EIO;
47200
47201- if (datalen < 0 || datalen > PAGE_SIZE - 1)
47202+ if (datalen > PAGE_SIZE - 1)
47203 return -EOPNOTSUPP;
47204
47205 /* drag the command string into the kernel so we can parse it */
47206@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
47207 if (args[0] != '%' || args[1] != '\0')
47208 return -EINVAL;
47209
47210- if (fstop < 0 || fstop >= cache->fcull_percent)
47211+ if (fstop >= cache->fcull_percent)
47212 return cachefiles_daemon_range_error(cache, args);
47213
47214 cache->fstop_percent = fstop;
47215@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
47216 if (args[0] != '%' || args[1] != '\0')
47217 return -EINVAL;
47218
47219- if (bstop < 0 || bstop >= cache->bcull_percent)
47220+ if (bstop >= cache->bcull_percent)
47221 return cachefiles_daemon_range_error(cache, args);
47222
47223 cache->bstop_percent = bstop;
47224diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
47225index f7c255f..fcd61de 100644
47226--- a/fs/cachefiles/internal.h
47227+++ b/fs/cachefiles/internal.h
47228@@ -56,7 +56,7 @@ struct cachefiles_cache {
47229 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
47230 struct rb_root active_nodes; /* active nodes (can't be culled) */
47231 rwlock_t active_lock; /* lock for active_nodes */
47232- atomic_t gravecounter; /* graveyard uniquifier */
47233+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
47234 unsigned frun_percent; /* when to stop culling (% files) */
47235 unsigned fcull_percent; /* when to start culling (% files) */
47236 unsigned fstop_percent; /* when to stop allocating (% files) */
47237@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
47238 * proc.c
47239 */
47240 #ifdef CONFIG_CACHEFILES_HISTOGRAM
47241-extern atomic_t cachefiles_lookup_histogram[HZ];
47242-extern atomic_t cachefiles_mkdir_histogram[HZ];
47243-extern atomic_t cachefiles_create_histogram[HZ];
47244+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47245+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47246+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
47247
47248 extern int __init cachefiles_proc_init(void);
47249 extern void cachefiles_proc_cleanup(void);
47250 static inline
47251-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
47252+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
47253 {
47254 unsigned long jif = jiffies - start_jif;
47255 if (jif >= HZ)
47256 jif = HZ - 1;
47257- atomic_inc(&histogram[jif]);
47258+ atomic_inc_unchecked(&histogram[jif]);
47259 }
47260
47261 #else
47262diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
47263index 14ac480..a62766c 100644
47264--- a/fs/cachefiles/namei.c
47265+++ b/fs/cachefiles/namei.c
47266@@ -250,7 +250,7 @@ try_again:
47267 /* first step is to make up a grave dentry in the graveyard */
47268 sprintf(nbuffer, "%08x%08x",
47269 (uint32_t) get_seconds(),
47270- (uint32_t) atomic_inc_return(&cache->gravecounter));
47271+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
47272
47273 /* do the multiway lock magic */
47274 trap = lock_rename(cache->graveyard, dir);
47275diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
47276index eccd339..4c1d995 100644
47277--- a/fs/cachefiles/proc.c
47278+++ b/fs/cachefiles/proc.c
47279@@ -14,9 +14,9 @@
47280 #include <linux/seq_file.h>
47281 #include "internal.h"
47282
47283-atomic_t cachefiles_lookup_histogram[HZ];
47284-atomic_t cachefiles_mkdir_histogram[HZ];
47285-atomic_t cachefiles_create_histogram[HZ];
47286+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47287+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47288+atomic_unchecked_t cachefiles_create_histogram[HZ];
47289
47290 /*
47291 * display the latency histogram
47292@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
47293 return 0;
47294 default:
47295 index = (unsigned long) v - 3;
47296- x = atomic_read(&cachefiles_lookup_histogram[index]);
47297- y = atomic_read(&cachefiles_mkdir_histogram[index]);
47298- z = atomic_read(&cachefiles_create_histogram[index]);
47299+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
47300+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
47301+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
47302 if (x == 0 && y == 0 && z == 0)
47303 return 0;
47304
47305diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
47306index a6c8c6f..5cf8517 100644
47307--- a/fs/cachefiles/rdwr.c
47308+++ b/fs/cachefiles/rdwr.c
47309@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
47310 old_fs = get_fs();
47311 set_fs(KERNEL_DS);
47312 ret = file->f_op->write(
47313- file, (const void __user *) data, len, &pos);
47314+ file, (const void __force_user *) data, len, &pos);
47315 set_fs(old_fs);
47316 kunmap(page);
47317 if (ret != len)
47318diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
47319index 42cec2a..2aba466 100644
47320--- a/fs/cifs/cifs_debug.c
47321+++ b/fs/cifs/cifs_debug.c
47322@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
47323 tcon = list_entry(tmp3,
47324 struct cifsTconInfo,
47325 tcon_list);
47326- atomic_set(&tcon->num_smbs_sent, 0);
47327- atomic_set(&tcon->num_writes, 0);
47328- atomic_set(&tcon->num_reads, 0);
47329- atomic_set(&tcon->num_oplock_brks, 0);
47330- atomic_set(&tcon->num_opens, 0);
47331- atomic_set(&tcon->num_posixopens, 0);
47332- atomic_set(&tcon->num_posixmkdirs, 0);
47333- atomic_set(&tcon->num_closes, 0);
47334- atomic_set(&tcon->num_deletes, 0);
47335- atomic_set(&tcon->num_mkdirs, 0);
47336- atomic_set(&tcon->num_rmdirs, 0);
47337- atomic_set(&tcon->num_renames, 0);
47338- atomic_set(&tcon->num_t2renames, 0);
47339- atomic_set(&tcon->num_ffirst, 0);
47340- atomic_set(&tcon->num_fnext, 0);
47341- atomic_set(&tcon->num_fclose, 0);
47342- atomic_set(&tcon->num_hardlinks, 0);
47343- atomic_set(&tcon->num_symlinks, 0);
47344- atomic_set(&tcon->num_locks, 0);
47345+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
47346+ atomic_set_unchecked(&tcon->num_writes, 0);
47347+ atomic_set_unchecked(&tcon->num_reads, 0);
47348+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
47349+ atomic_set_unchecked(&tcon->num_opens, 0);
47350+ atomic_set_unchecked(&tcon->num_posixopens, 0);
47351+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
47352+ atomic_set_unchecked(&tcon->num_closes, 0);
47353+ atomic_set_unchecked(&tcon->num_deletes, 0);
47354+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
47355+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
47356+ atomic_set_unchecked(&tcon->num_renames, 0);
47357+ atomic_set_unchecked(&tcon->num_t2renames, 0);
47358+ atomic_set_unchecked(&tcon->num_ffirst, 0);
47359+ atomic_set_unchecked(&tcon->num_fnext, 0);
47360+ atomic_set_unchecked(&tcon->num_fclose, 0);
47361+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
47362+ atomic_set_unchecked(&tcon->num_symlinks, 0);
47363+ atomic_set_unchecked(&tcon->num_locks, 0);
47364 }
47365 }
47366 }
47367@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
47368 if (tcon->need_reconnect)
47369 seq_puts(m, "\tDISCONNECTED ");
47370 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
47371- atomic_read(&tcon->num_smbs_sent),
47372- atomic_read(&tcon->num_oplock_brks));
47373+ atomic_read_unchecked(&tcon->num_smbs_sent),
47374+ atomic_read_unchecked(&tcon->num_oplock_brks));
47375 seq_printf(m, "\nReads: %d Bytes: %lld",
47376- atomic_read(&tcon->num_reads),
47377+ atomic_read_unchecked(&tcon->num_reads),
47378 (long long)(tcon->bytes_read));
47379 seq_printf(m, "\nWrites: %d Bytes: %lld",
47380- atomic_read(&tcon->num_writes),
47381+ atomic_read_unchecked(&tcon->num_writes),
47382 (long long)(tcon->bytes_written));
47383 seq_printf(m, "\nFlushes: %d",
47384- atomic_read(&tcon->num_flushes));
47385+ atomic_read_unchecked(&tcon->num_flushes));
47386 seq_printf(m, "\nLocks: %d HardLinks: %d "
47387 "Symlinks: %d",
47388- atomic_read(&tcon->num_locks),
47389- atomic_read(&tcon->num_hardlinks),
47390- atomic_read(&tcon->num_symlinks));
47391+ atomic_read_unchecked(&tcon->num_locks),
47392+ atomic_read_unchecked(&tcon->num_hardlinks),
47393+ atomic_read_unchecked(&tcon->num_symlinks));
47394 seq_printf(m, "\nOpens: %d Closes: %d "
47395 "Deletes: %d",
47396- atomic_read(&tcon->num_opens),
47397- atomic_read(&tcon->num_closes),
47398- atomic_read(&tcon->num_deletes));
47399+ atomic_read_unchecked(&tcon->num_opens),
47400+ atomic_read_unchecked(&tcon->num_closes),
47401+ atomic_read_unchecked(&tcon->num_deletes));
47402 seq_printf(m, "\nPosix Opens: %d "
47403 "Posix Mkdirs: %d",
47404- atomic_read(&tcon->num_posixopens),
47405- atomic_read(&tcon->num_posixmkdirs));
47406+ atomic_read_unchecked(&tcon->num_posixopens),
47407+ atomic_read_unchecked(&tcon->num_posixmkdirs));
47408 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
47409- atomic_read(&tcon->num_mkdirs),
47410- atomic_read(&tcon->num_rmdirs));
47411+ atomic_read_unchecked(&tcon->num_mkdirs),
47412+ atomic_read_unchecked(&tcon->num_rmdirs));
47413 seq_printf(m, "\nRenames: %d T2 Renames %d",
47414- atomic_read(&tcon->num_renames),
47415- atomic_read(&tcon->num_t2renames));
47416+ atomic_read_unchecked(&tcon->num_renames),
47417+ atomic_read_unchecked(&tcon->num_t2renames));
47418 seq_printf(m, "\nFindFirst: %d FNext %d "
47419 "FClose %d",
47420- atomic_read(&tcon->num_ffirst),
47421- atomic_read(&tcon->num_fnext),
47422- atomic_read(&tcon->num_fclose));
47423+ atomic_read_unchecked(&tcon->num_ffirst),
47424+ atomic_read_unchecked(&tcon->num_fnext),
47425+ atomic_read_unchecked(&tcon->num_fclose));
47426 }
47427 }
47428 }
47429diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
47430index 1445407..68cb0dc 100644
47431--- a/fs/cifs/cifsfs.c
47432+++ b/fs/cifs/cifsfs.c
47433@@ -869,7 +869,7 @@ cifs_init_request_bufs(void)
47434 cifs_req_cachep = kmem_cache_create("cifs_request",
47435 CIFSMaxBufSize +
47436 MAX_CIFS_HDR_SIZE, 0,
47437- SLAB_HWCACHE_ALIGN, NULL);
47438+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
47439 if (cifs_req_cachep == NULL)
47440 return -ENOMEM;
47441
47442@@ -896,7 +896,7 @@ cifs_init_request_bufs(void)
47443 efficient to alloc 1 per page off the slab compared to 17K (5page)
47444 alloc of large cifs buffers even when page debugging is on */
47445 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
47446- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
47447+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
47448 NULL);
47449 if (cifs_sm_req_cachep == NULL) {
47450 mempool_destroy(cifs_req_poolp);
47451@@ -991,8 +991,8 @@ init_cifs(void)
47452 atomic_set(&bufAllocCount, 0);
47453 atomic_set(&smBufAllocCount, 0);
47454 #ifdef CONFIG_CIFS_STATS2
47455- atomic_set(&totBufAllocCount, 0);
47456- atomic_set(&totSmBufAllocCount, 0);
47457+ atomic_set_unchecked(&totBufAllocCount, 0);
47458+ atomic_set_unchecked(&totSmBufAllocCount, 0);
47459 #endif /* CONFIG_CIFS_STATS2 */
47460
47461 atomic_set(&midCount, 0);
47462diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
47463index e29581e..1c22bab 100644
47464--- a/fs/cifs/cifsglob.h
47465+++ b/fs/cifs/cifsglob.h
47466@@ -252,28 +252,28 @@ struct cifsTconInfo {
47467 __u16 Flags; /* optional support bits */
47468 enum statusEnum tidStatus;
47469 #ifdef CONFIG_CIFS_STATS
47470- atomic_t num_smbs_sent;
47471- atomic_t num_writes;
47472- atomic_t num_reads;
47473- atomic_t num_flushes;
47474- atomic_t num_oplock_brks;
47475- atomic_t num_opens;
47476- atomic_t num_closes;
47477- atomic_t num_deletes;
47478- atomic_t num_mkdirs;
47479- atomic_t num_posixopens;
47480- atomic_t num_posixmkdirs;
47481- atomic_t num_rmdirs;
47482- atomic_t num_renames;
47483- atomic_t num_t2renames;
47484- atomic_t num_ffirst;
47485- atomic_t num_fnext;
47486- atomic_t num_fclose;
47487- atomic_t num_hardlinks;
47488- atomic_t num_symlinks;
47489- atomic_t num_locks;
47490- atomic_t num_acl_get;
47491- atomic_t num_acl_set;
47492+ atomic_unchecked_t num_smbs_sent;
47493+ atomic_unchecked_t num_writes;
47494+ atomic_unchecked_t num_reads;
47495+ atomic_unchecked_t num_flushes;
47496+ atomic_unchecked_t num_oplock_brks;
47497+ atomic_unchecked_t num_opens;
47498+ atomic_unchecked_t num_closes;
47499+ atomic_unchecked_t num_deletes;
47500+ atomic_unchecked_t num_mkdirs;
47501+ atomic_unchecked_t num_posixopens;
47502+ atomic_unchecked_t num_posixmkdirs;
47503+ atomic_unchecked_t num_rmdirs;
47504+ atomic_unchecked_t num_renames;
47505+ atomic_unchecked_t num_t2renames;
47506+ atomic_unchecked_t num_ffirst;
47507+ atomic_unchecked_t num_fnext;
47508+ atomic_unchecked_t num_fclose;
47509+ atomic_unchecked_t num_hardlinks;
47510+ atomic_unchecked_t num_symlinks;
47511+ atomic_unchecked_t num_locks;
47512+ atomic_unchecked_t num_acl_get;
47513+ atomic_unchecked_t num_acl_set;
47514 #ifdef CONFIG_CIFS_STATS2
47515 unsigned long long time_writes;
47516 unsigned long long time_reads;
47517@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
47518 }
47519
47520 #ifdef CONFIG_CIFS_STATS
47521-#define cifs_stats_inc atomic_inc
47522+#define cifs_stats_inc atomic_inc_unchecked
47523
47524 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
47525 unsigned int bytes)
47526@@ -701,8 +701,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
47527 /* Various Debug counters */
47528 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
47529 #ifdef CONFIG_CIFS_STATS2
47530-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
47531-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
47532+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
47533+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
47534 #endif
47535 GLOBAL_EXTERN atomic_t smBufAllocCount;
47536 GLOBAL_EXTERN atomic_t midCount;
47537diff --git a/fs/cifs/link.c b/fs/cifs/link.c
47538index fc1e048..28b3441 100644
47539--- a/fs/cifs/link.c
47540+++ b/fs/cifs/link.c
47541@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
47542
47543 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
47544 {
47545- char *p = nd_get_link(nd);
47546+ const char *p = nd_get_link(nd);
47547 if (!IS_ERR(p))
47548 kfree(p);
47549 }
47550diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
47551index 95b82e8..12a538d 100644
47552--- a/fs/cifs/misc.c
47553+++ b/fs/cifs/misc.c
47554@@ -155,7 +155,7 @@ cifs_buf_get(void)
47555 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
47556 atomic_inc(&bufAllocCount);
47557 #ifdef CONFIG_CIFS_STATS2
47558- atomic_inc(&totBufAllocCount);
47559+ atomic_inc_unchecked(&totBufAllocCount);
47560 #endif /* CONFIG_CIFS_STATS2 */
47561 }
47562
47563@@ -190,7 +190,7 @@ cifs_small_buf_get(void)
47564 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
47565 atomic_inc(&smBufAllocCount);
47566 #ifdef CONFIG_CIFS_STATS2
47567- atomic_inc(&totSmBufAllocCount);
47568+ atomic_inc_unchecked(&totSmBufAllocCount);
47569 #endif /* CONFIG_CIFS_STATS2 */
47570
47571 }
47572diff --git a/fs/coda/cache.c b/fs/coda/cache.c
47573index a5bf577..6d19845 100644
47574--- a/fs/coda/cache.c
47575+++ b/fs/coda/cache.c
47576@@ -24,14 +24,14 @@
47577 #include <linux/coda_fs_i.h>
47578 #include <linux/coda_cache.h>
47579
47580-static atomic_t permission_epoch = ATOMIC_INIT(0);
47581+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
47582
47583 /* replace or extend an acl cache hit */
47584 void coda_cache_enter(struct inode *inode, int mask)
47585 {
47586 struct coda_inode_info *cii = ITOC(inode);
47587
47588- cii->c_cached_epoch = atomic_read(&permission_epoch);
47589+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47590 if (cii->c_uid != current_fsuid()) {
47591 cii->c_uid = current_fsuid();
47592 cii->c_cached_perm = mask;
47593@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inode, int mask)
47594 void coda_cache_clear_inode(struct inode *inode)
47595 {
47596 struct coda_inode_info *cii = ITOC(inode);
47597- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47598+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47599 }
47600
47601 /* remove all acl caches */
47602 void coda_cache_clear_all(struct super_block *sb)
47603 {
47604- atomic_inc(&permission_epoch);
47605+ atomic_inc_unchecked(&permission_epoch);
47606 }
47607
47608
47609@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode, int mask)
47610
47611 hit = (mask & cii->c_cached_perm) == mask &&
47612 cii->c_uid == current_fsuid() &&
47613- cii->c_cached_epoch == atomic_read(&permission_epoch);
47614+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47615
47616 return hit;
47617 }
47618diff --git a/fs/compat.c b/fs/compat.c
47619index d1e2411..27064e4 100644
47620--- a/fs/compat.c
47621+++ b/fs/compat.c
47622@@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
47623 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
47624 {
47625 compat_ino_t ino = stat->ino;
47626- typeof(ubuf->st_uid) uid = 0;
47627- typeof(ubuf->st_gid) gid = 0;
47628+ typeof(((struct compat_stat *)0)->st_uid) uid = 0;
47629+ typeof(((struct compat_stat *)0)->st_gid) gid = 0;
47630 int err;
47631
47632 SET_UID(uid, stat->uid);
47633@@ -533,7 +533,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47634
47635 set_fs(KERNEL_DS);
47636 /* The __user pointer cast is valid because of the set_fs() */
47637- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47638+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47639 set_fs(oldfs);
47640 /* truncating is ok because it's a user address */
47641 if (!ret)
47642@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
47643
47644 struct compat_readdir_callback {
47645 struct compat_old_linux_dirent __user *dirent;
47646+ struct file * file;
47647 int result;
47648 };
47649
47650@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47651 buf->result = -EOVERFLOW;
47652 return -EOVERFLOW;
47653 }
47654+
47655+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47656+ return 0;
47657+
47658 buf->result++;
47659 dirent = buf->dirent;
47660 if (!access_ok(VERIFY_WRITE, dirent,
47661@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47662
47663 buf.result = 0;
47664 buf.dirent = dirent;
47665+ buf.file = file;
47666
47667 error = vfs_readdir(file, compat_fillonedir, &buf);
47668 if (buf.result)
47669@@ -899,6 +905,7 @@ struct compat_linux_dirent {
47670 struct compat_getdents_callback {
47671 struct compat_linux_dirent __user *current_dir;
47672 struct compat_linux_dirent __user *previous;
47673+ struct file * file;
47674 int count;
47675 int error;
47676 };
47677@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47678 buf->error = -EOVERFLOW;
47679 return -EOVERFLOW;
47680 }
47681+
47682+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47683+ return 0;
47684+
47685 dirent = buf->previous;
47686 if (dirent) {
47687 if (__put_user(offset, &dirent->d_off))
47688@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47689 buf.previous = NULL;
47690 buf.count = count;
47691 buf.error = 0;
47692+ buf.file = file;
47693
47694 error = vfs_readdir(file, compat_filldir, &buf);
47695 if (error >= 0)
47696@@ -987,6 +999,7 @@ out:
47697 struct compat_getdents_callback64 {
47698 struct linux_dirent64 __user *current_dir;
47699 struct linux_dirent64 __user *previous;
47700+ struct file * file;
47701 int count;
47702 int error;
47703 };
47704@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47705 buf->error = -EINVAL; /* only used if we fail.. */
47706 if (reclen > buf->count)
47707 return -EINVAL;
47708+
47709+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47710+ return 0;
47711+
47712 dirent = buf->previous;
47713
47714 if (dirent) {
47715@@ -1054,13 +1071,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47716 buf.previous = NULL;
47717 buf.count = count;
47718 buf.error = 0;
47719+ buf.file = file;
47720
47721 error = vfs_readdir(file, compat_filldir64, &buf);
47722 if (error >= 0)
47723 error = buf.error;
47724 lastdirent = buf.previous;
47725 if (lastdirent) {
47726- typeof(lastdirent->d_off) d_off = file->f_pos;
47727+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47728 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47729 error = -EFAULT;
47730 else
47731@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
47732 * verify all the pointers
47733 */
47734 ret = -EINVAL;
47735- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
47736+ if (nr_segs > UIO_MAXIOV)
47737 goto out;
47738 if (!file->f_op)
47739 goto out;
47740@@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
47741 compat_uptr_t __user *envp,
47742 struct pt_regs * regs)
47743 {
47744+#ifdef CONFIG_GRKERNSEC
47745+ struct file *old_exec_file;
47746+ struct acl_subject_label *old_acl;
47747+ struct rlimit old_rlim[RLIM_NLIMITS];
47748+#endif
47749 struct linux_binprm *bprm;
47750 struct file *file;
47751 struct files_struct *displaced;
47752 bool clear_in_exec;
47753 int retval;
47754+ const struct cred *cred = current_cred();
47755+
47756+ /*
47757+ * We move the actual failure in case of RLIMIT_NPROC excess from
47758+ * set*uid() to execve() because too many poorly written programs
47759+ * don't check setuid() return code. Here we additionally recheck
47760+ * whether NPROC limit is still exceeded.
47761+ */
47762+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47763+
47764+ if ((current->flags & PF_NPROC_EXCEEDED) &&
47765+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
47766+ retval = -EAGAIN;
47767+ goto out_ret;
47768+ }
47769+
47770+ /* We're below the limit (still or again), so we don't want to make
47771+ * further execve() calls fail. */
47772+ current->flags &= ~PF_NPROC_EXCEEDED;
47773
47774 retval = unshare_files(&displaced);
47775 if (retval)
47776@@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
47777 bprm->filename = filename;
47778 bprm->interp = filename;
47779
47780+ if (gr_process_user_ban()) {
47781+ retval = -EPERM;
47782+ goto out_file;
47783+ }
47784+
47785+ retval = -EACCES;
47786+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
47787+ goto out_file;
47788+
47789 retval = bprm_mm_init(bprm);
47790 if (retval)
47791 goto out_file;
47792@@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
47793 if (retval < 0)
47794 goto out;
47795
47796+ if (!gr_tpe_allow(file)) {
47797+ retval = -EACCES;
47798+ goto out;
47799+ }
47800+
47801+ if (gr_check_crash_exec(file)) {
47802+ retval = -EACCES;
47803+ goto out;
47804+ }
47805+
47806+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47807+
47808+ gr_handle_exec_args_compat(bprm, argv);
47809+
47810+#ifdef CONFIG_GRKERNSEC
47811+ old_acl = current->acl;
47812+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47813+ old_exec_file = current->exec_file;
47814+ get_file(file);
47815+ current->exec_file = file;
47816+#endif
47817+
47818+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47819+ bprm->unsafe & LSM_UNSAFE_SHARE);
47820+ if (retval < 0)
47821+ goto out_fail;
47822+
47823 retval = search_binary_handler(bprm, regs);
47824 if (retval < 0)
47825- goto out;
47826+ goto out_fail;
47827+#ifdef CONFIG_GRKERNSEC
47828+ if (old_exec_file)
47829+ fput(old_exec_file);
47830+#endif
47831
47832 /* execve succeeded */
47833 current->fs->in_exec = 0;
47834@@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
47835 put_files_struct(displaced);
47836 return retval;
47837
47838+out_fail:
47839+#ifdef CONFIG_GRKERNSEC
47840+ current->acl = old_acl;
47841+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47842+ fput(current->exec_file);
47843+ current->exec_file = old_exec_file;
47844+#endif
47845+
47846 out:
47847 if (bprm->mm) {
47848 acct_arg_size(bprm, 0);
47849@@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
47850 struct fdtable *fdt;
47851 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
47852
47853+ pax_track_stack();
47854+
47855 if (n < 0)
47856 goto out_nofds;
47857
47858@@ -2151,7 +2243,7 @@ asmlinkage long compat_sys_nfsservctl(int cmd,
47859 oldfs = get_fs();
47860 set_fs(KERNEL_DS);
47861 /* The __user pointer casts are valid because of the set_fs() */
47862- err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
47863+ err = sys_nfsservctl(cmd, (void __force_user *) karg, (void __force_user *) kres);
47864 set_fs(oldfs);
47865
47866 if (err)
47867diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47868index 0adced2..bbb1b0d 100644
47869--- a/fs/compat_binfmt_elf.c
47870+++ b/fs/compat_binfmt_elf.c
47871@@ -29,10 +29,12 @@
47872 #undef elfhdr
47873 #undef elf_phdr
47874 #undef elf_note
47875+#undef elf_dyn
47876 #undef elf_addr_t
47877 #define elfhdr elf32_hdr
47878 #define elf_phdr elf32_phdr
47879 #define elf_note elf32_note
47880+#define elf_dyn Elf32_Dyn
47881 #define elf_addr_t Elf32_Addr
47882
47883 /*
47884diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47885index d84e705..d8c364c 100644
47886--- a/fs/compat_ioctl.c
47887+++ b/fs/compat_ioctl.c
47888@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned
47889 up = (struct compat_video_spu_palette __user *) arg;
47890 err = get_user(palp, &up->palette);
47891 err |= get_user(length, &up->length);
47892+ if (err)
47893+ return -EFAULT;
47894
47895 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
47896 err = put_user(compat_ptr(palp), &up_native->palette);
47897@@ -1513,7 +1515,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
47898 return -EFAULT;
47899 if (__get_user(udata, &ss32->iomem_base))
47900 return -EFAULT;
47901- ss.iomem_base = compat_ptr(udata);
47902+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47903 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47904 __get_user(ss.port_high, &ss32->port_high))
47905 return -EFAULT;
47906@@ -1809,7 +1811,7 @@ static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
47907 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47908 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47909 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47910- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47911+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47912 return -EFAULT;
47913
47914 return ioctl_preallocate(file, p);
47915diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47916index 8e48b52..f01ed91 100644
47917--- a/fs/configfs/dir.c
47918+++ b/fs/configfs/dir.c
47919@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47920 }
47921 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47922 struct configfs_dirent *next;
47923- const char * name;
47924+ const unsigned char * name;
47925+ char d_name[sizeof(next->s_dentry->d_iname)];
47926 int len;
47927
47928 next = list_entry(p, struct configfs_dirent,
47929@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47930 continue;
47931
47932 name = configfs_get_name(next);
47933- len = strlen(name);
47934+ if (next->s_dentry && name == next->s_dentry->d_iname) {
47935+ len = next->s_dentry->d_name.len;
47936+ memcpy(d_name, name, len);
47937+ name = d_name;
47938+ } else
47939+ len = strlen(name);
47940 if (next->s_dentry)
47941 ino = next->s_dentry->d_inode->i_ino;
47942 else
47943diff --git a/fs/dcache.c b/fs/dcache.c
47944index 44c0aea..2529092 100644
47945--- a/fs/dcache.c
47946+++ b/fs/dcache.c
47947@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
47948
47949 static struct kmem_cache *dentry_cache __read_mostly;
47950
47951-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
47952-
47953 /*
47954 * This is the single most critical data structure when it comes
47955 * to the dcache: the hashtable for lookups. Somebody should try
47956@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned long mempages)
47957 mempages -= reserve;
47958
47959 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47960- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47961+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47962
47963 dcache_init();
47964 inode_init();
47965diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
47966index c010ecf..a8d8c59 100644
47967--- a/fs/dlm/lockspace.c
47968+++ b/fs/dlm/lockspace.c
47969@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struct kobject *k)
47970 kfree(ls);
47971 }
47972
47973-static struct sysfs_ops dlm_attr_ops = {
47974+static const struct sysfs_ops dlm_attr_ops = {
47975 .show = dlm_attr_show,
47976 .store = dlm_attr_store,
47977 };
47978diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47979index 88ba4d4..073f003 100644
47980--- a/fs/ecryptfs/inode.c
47981+++ b/fs/ecryptfs/inode.c
47982@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47983 old_fs = get_fs();
47984 set_fs(get_ds());
47985 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47986- (char __user *)lower_buf,
47987+ (char __force_user *)lower_buf,
47988 lower_bufsiz);
47989 set_fs(old_fs);
47990 if (rc < 0)
47991@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47992 }
47993 old_fs = get_fs();
47994 set_fs(get_ds());
47995- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
47996+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
47997 set_fs(old_fs);
47998 if (rc < 0)
47999 goto out_free;
48000diff --git a/fs/exec.c b/fs/exec.c
48001index 86fafc6..b307bfa 100644
48002--- a/fs/exec.c
48003+++ b/fs/exec.c
48004@@ -56,12 +56,24 @@
48005 #include <linux/fsnotify.h>
48006 #include <linux/fs_struct.h>
48007 #include <linux/pipe_fs_i.h>
48008+#include <linux/random.h>
48009+#include <linux/seq_file.h>
48010+
48011+#ifdef CONFIG_PAX_REFCOUNT
48012+#include <linux/kallsyms.h>
48013+#include <linux/kdebug.h>
48014+#endif
48015
48016 #include <asm/uaccess.h>
48017 #include <asm/mmu_context.h>
48018 #include <asm/tlb.h>
48019 #include "internal.h"
48020
48021+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
48022+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
48023+EXPORT_SYMBOL(pax_set_initial_flags_func);
48024+#endif
48025+
48026 int core_uses_pid;
48027 char core_pattern[CORENAME_MAX_SIZE] = "core";
48028 unsigned int core_pipe_limit;
48029@@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
48030 int write)
48031 {
48032 struct page *page;
48033- int ret;
48034
48035-#ifdef CONFIG_STACK_GROWSUP
48036- if (write) {
48037- ret = expand_stack_downwards(bprm->vma, pos);
48038- if (ret < 0)
48039- return NULL;
48040- }
48041-#endif
48042- ret = get_user_pages(current, bprm->mm, pos,
48043- 1, write, 1, &page, NULL);
48044- if (ret <= 0)
48045+ if (0 > expand_stack_downwards(bprm->vma, pos))
48046+ return NULL;
48047+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
48048 return NULL;
48049
48050 if (write) {
48051@@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48052 vma->vm_end = STACK_TOP_MAX;
48053 vma->vm_start = vma->vm_end - PAGE_SIZE;
48054 vma->vm_flags = VM_STACK_FLAGS;
48055+
48056+#ifdef CONFIG_PAX_SEGMEXEC
48057+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
48058+#endif
48059+
48060 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
48061
48062 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
48063@@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48064 mm->stack_vm = mm->total_vm = 1;
48065 up_write(&mm->mmap_sem);
48066 bprm->p = vma->vm_end - sizeof(void *);
48067+
48068+#ifdef CONFIG_PAX_RANDUSTACK
48069+ if (randomize_va_space)
48070+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
48071+#endif
48072+
48073 return 0;
48074 err:
48075 up_write(&mm->mmap_sem);
48076@@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
48077 int r;
48078 mm_segment_t oldfs = get_fs();
48079 set_fs(KERNEL_DS);
48080- r = copy_strings(argc, (char __user * __user *)argv, bprm);
48081+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
48082 set_fs(oldfs);
48083 return r;
48084 }
48085@@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48086 unsigned long new_end = old_end - shift;
48087 struct mmu_gather *tlb;
48088
48089- BUG_ON(new_start > new_end);
48090+ if (new_start >= new_end || new_start < mmap_min_addr)
48091+ return -ENOMEM;
48092
48093 /*
48094 * ensure there are no vmas between where we want to go
48095@@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48096 if (vma != find_vma(mm, new_start))
48097 return -EFAULT;
48098
48099+#ifdef CONFIG_PAX_SEGMEXEC
48100+ BUG_ON(pax_find_mirror_vma(vma));
48101+#endif
48102+
48103 /*
48104 * cover the whole range: [new_start, old_end)
48105 */
48106@@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
48107 stack_top = arch_align_stack(stack_top);
48108 stack_top = PAGE_ALIGN(stack_top);
48109
48110- if (unlikely(stack_top < mmap_min_addr) ||
48111- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
48112- return -ENOMEM;
48113-
48114 stack_shift = vma->vm_end - stack_top;
48115
48116 bprm->p -= stack_shift;
48117@@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm *bprm,
48118 bprm->exec -= stack_shift;
48119
48120 down_write(&mm->mmap_sem);
48121+
48122+ /* Move stack pages down in memory. */
48123+ if (stack_shift) {
48124+ ret = shift_arg_pages(vma, stack_shift);
48125+ if (ret)
48126+ goto out_unlock;
48127+ }
48128+
48129 vm_flags = VM_STACK_FLAGS;
48130
48131 /*
48132@@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm *bprm,
48133 vm_flags &= ~VM_EXEC;
48134 vm_flags |= mm->def_flags;
48135
48136+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48137+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48138+ vm_flags &= ~VM_EXEC;
48139+
48140+#ifdef CONFIG_PAX_MPROTECT
48141+ if (mm->pax_flags & MF_PAX_MPROTECT)
48142+ vm_flags &= ~VM_MAYEXEC;
48143+#endif
48144+
48145+ }
48146+#endif
48147+
48148 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
48149 vm_flags);
48150 if (ret)
48151 goto out_unlock;
48152 BUG_ON(prev != vma);
48153
48154- /* Move stack pages down in memory. */
48155- if (stack_shift) {
48156- ret = shift_arg_pages(vma, stack_shift);
48157- if (ret)
48158- goto out_unlock;
48159- }
48160-
48161 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
48162 stack_size = vma->vm_end - vma->vm_start;
48163 /*
48164@@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_t offset,
48165 old_fs = get_fs();
48166 set_fs(get_ds());
48167 /* The cast to a user pointer is valid due to the set_fs() */
48168- result = vfs_read(file, (void __user *)addr, count, &pos);
48169+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
48170 set_fs(old_fs);
48171 return result;
48172 }
48173@@ -1152,7 +1181,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
48174 }
48175 rcu_read_unlock();
48176
48177- if (p->fs->users > n_fs) {
48178+ if (atomic_read(&p->fs->users) > n_fs) {
48179 bprm->unsafe |= LSM_UNSAFE_SHARE;
48180 } else {
48181 res = -EAGAIN;
48182@@ -1347,11 +1376,35 @@ int do_execve(char * filename,
48183 char __user *__user *envp,
48184 struct pt_regs * regs)
48185 {
48186+#ifdef CONFIG_GRKERNSEC
48187+ struct file *old_exec_file;
48188+ struct acl_subject_label *old_acl;
48189+ struct rlimit old_rlim[RLIM_NLIMITS];
48190+#endif
48191 struct linux_binprm *bprm;
48192 struct file *file;
48193 struct files_struct *displaced;
48194 bool clear_in_exec;
48195 int retval;
48196+ const struct cred *cred = current_cred();
48197+
48198+ /*
48199+ * We move the actual failure in case of RLIMIT_NPROC excess from
48200+ * set*uid() to execve() because too many poorly written programs
48201+ * don't check setuid() return code. Here we additionally recheck
48202+ * whether NPROC limit is still exceeded.
48203+ */
48204+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48205+
48206+ if ((current->flags & PF_NPROC_EXCEEDED) &&
48207+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48208+ retval = -EAGAIN;
48209+ goto out_ret;
48210+ }
48211+
48212+ /* We're below the limit (still or again), so we don't want to make
48213+ * further execve() calls fail. */
48214+ current->flags &= ~PF_NPROC_EXCEEDED;
48215
48216 retval = unshare_files(&displaced);
48217 if (retval)
48218@@ -1383,6 +1436,16 @@ int do_execve(char * filename,
48219 bprm->filename = filename;
48220 bprm->interp = filename;
48221
48222+ if (gr_process_user_ban()) {
48223+ retval = -EPERM;
48224+ goto out_file;
48225+ }
48226+
48227+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
48228+ retval = -EACCES;
48229+ goto out_file;
48230+ }
48231+
48232 retval = bprm_mm_init(bprm);
48233 if (retval)
48234 goto out_file;
48235@@ -1412,10 +1475,41 @@ int do_execve(char * filename,
48236 if (retval < 0)
48237 goto out;
48238
48239+ if (!gr_tpe_allow(file)) {
48240+ retval = -EACCES;
48241+ goto out;
48242+ }
48243+
48244+ if (gr_check_crash_exec(file)) {
48245+ retval = -EACCES;
48246+ goto out;
48247+ }
48248+
48249+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48250+
48251+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
48252+
48253+#ifdef CONFIG_GRKERNSEC
48254+ old_acl = current->acl;
48255+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48256+ old_exec_file = current->exec_file;
48257+ get_file(file);
48258+ current->exec_file = file;
48259+#endif
48260+
48261+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48262+ bprm->unsafe & LSM_UNSAFE_SHARE);
48263+ if (retval < 0)
48264+ goto out_fail;
48265+
48266 current->flags &= ~PF_KTHREAD;
48267 retval = search_binary_handler(bprm,regs);
48268 if (retval < 0)
48269- goto out;
48270+ goto out_fail;
48271+#ifdef CONFIG_GRKERNSEC
48272+ if (old_exec_file)
48273+ fput(old_exec_file);
48274+#endif
48275
48276 /* execve succeeded */
48277 current->fs->in_exec = 0;
48278@@ -1426,6 +1520,14 @@ int do_execve(char * filename,
48279 put_files_struct(displaced);
48280 return retval;
48281
48282+out_fail:
48283+#ifdef CONFIG_GRKERNSEC
48284+ current->acl = old_acl;
48285+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48286+ fput(current->exec_file);
48287+ current->exec_file = old_exec_file;
48288+#endif
48289+
48290 out:
48291 if (bprm->mm) {
48292 acct_arg_size(bprm, 0);
48293@@ -1591,6 +1693,220 @@ out:
48294 return ispipe;
48295 }
48296
48297+int pax_check_flags(unsigned long *flags)
48298+{
48299+ int retval = 0;
48300+
48301+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
48302+ if (*flags & MF_PAX_SEGMEXEC)
48303+ {
48304+ *flags &= ~MF_PAX_SEGMEXEC;
48305+ retval = -EINVAL;
48306+ }
48307+#endif
48308+
48309+ if ((*flags & MF_PAX_PAGEEXEC)
48310+
48311+#ifdef CONFIG_PAX_PAGEEXEC
48312+ && (*flags & MF_PAX_SEGMEXEC)
48313+#endif
48314+
48315+ )
48316+ {
48317+ *flags &= ~MF_PAX_PAGEEXEC;
48318+ retval = -EINVAL;
48319+ }
48320+
48321+ if ((*flags & MF_PAX_MPROTECT)
48322+
48323+#ifdef CONFIG_PAX_MPROTECT
48324+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48325+#endif
48326+
48327+ )
48328+ {
48329+ *flags &= ~MF_PAX_MPROTECT;
48330+ retval = -EINVAL;
48331+ }
48332+
48333+ if ((*flags & MF_PAX_EMUTRAMP)
48334+
48335+#ifdef CONFIG_PAX_EMUTRAMP
48336+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48337+#endif
48338+
48339+ )
48340+ {
48341+ *flags &= ~MF_PAX_EMUTRAMP;
48342+ retval = -EINVAL;
48343+ }
48344+
48345+ return retval;
48346+}
48347+
48348+EXPORT_SYMBOL(pax_check_flags);
48349+
48350+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48351+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
48352+{
48353+ struct task_struct *tsk = current;
48354+ struct mm_struct *mm = current->mm;
48355+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
48356+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
48357+ char *path_exec = NULL;
48358+ char *path_fault = NULL;
48359+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
48360+
48361+ if (buffer_exec && buffer_fault) {
48362+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
48363+
48364+ down_read(&mm->mmap_sem);
48365+ vma = mm->mmap;
48366+ while (vma && (!vma_exec || !vma_fault)) {
48367+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
48368+ vma_exec = vma;
48369+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
48370+ vma_fault = vma;
48371+ vma = vma->vm_next;
48372+ }
48373+ if (vma_exec) {
48374+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
48375+ if (IS_ERR(path_exec))
48376+ path_exec = "<path too long>";
48377+ else {
48378+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
48379+ if (path_exec) {
48380+ *path_exec = 0;
48381+ path_exec = buffer_exec;
48382+ } else
48383+ path_exec = "<path too long>";
48384+ }
48385+ }
48386+ if (vma_fault) {
48387+ start = vma_fault->vm_start;
48388+ end = vma_fault->vm_end;
48389+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48390+ if (vma_fault->vm_file) {
48391+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48392+ if (IS_ERR(path_fault))
48393+ path_fault = "<path too long>";
48394+ else {
48395+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48396+ if (path_fault) {
48397+ *path_fault = 0;
48398+ path_fault = buffer_fault;
48399+ } else
48400+ path_fault = "<path too long>";
48401+ }
48402+ } else
48403+ path_fault = "<anonymous mapping>";
48404+ }
48405+ up_read(&mm->mmap_sem);
48406+ }
48407+ if (tsk->signal->curr_ip)
48408+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48409+ else
48410+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48411+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
48412+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
48413+ task_uid(tsk), task_euid(tsk), pc, sp);
48414+ free_page((unsigned long)buffer_exec);
48415+ free_page((unsigned long)buffer_fault);
48416+ pax_report_insns(regs, pc, sp);
48417+ do_coredump(SIGKILL, SIGKILL, regs);
48418+}
48419+#endif
48420+
48421+#ifdef CONFIG_PAX_REFCOUNT
48422+void pax_report_refcount_overflow(struct pt_regs *regs)
48423+{
48424+ if (current->signal->curr_ip)
48425+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48426+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
48427+ else
48428+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48429+ current->comm, task_pid_nr(current), current_uid(), current_euid());
48430+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48431+ show_regs(regs);
48432+ force_sig_specific(SIGKILL, current);
48433+}
48434+#endif
48435+
48436+#ifdef CONFIG_PAX_USERCOPY
48437+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48438+int object_is_on_stack(const void *obj, unsigned long len)
48439+{
48440+ const void * const stack = task_stack_page(current);
48441+ const void * const stackend = stack + THREAD_SIZE;
48442+
48443+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48444+ const void *frame = NULL;
48445+ const void *oldframe;
48446+#endif
48447+
48448+ if (obj + len < obj)
48449+ return -1;
48450+
48451+ if (obj + len <= stack || stackend <= obj)
48452+ return 0;
48453+
48454+ if (obj < stack || stackend < obj + len)
48455+ return -1;
48456+
48457+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48458+ oldframe = __builtin_frame_address(1);
48459+ if (oldframe)
48460+ frame = __builtin_frame_address(2);
48461+ /*
48462+ low ----------------------------------------------> high
48463+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48464+ ^----------------^
48465+ allow copies only within here
48466+ */
48467+ while (stack <= frame && frame < stackend) {
48468+ /* if obj + len extends past the last frame, this
48469+ check won't pass and the next frame will be 0,
48470+ causing us to bail out and correctly report
48471+ the copy as invalid
48472+ */
48473+ if (obj + len <= frame)
48474+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48475+ oldframe = frame;
48476+ frame = *(const void * const *)frame;
48477+ }
48478+ return -1;
48479+#else
48480+ return 1;
48481+#endif
48482+}
48483+
48484+
48485+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48486+{
48487+ if (current->signal->curr_ip)
48488+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48489+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48490+ else
48491+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48492+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48493+
48494+ dump_stack();
48495+ gr_handle_kernel_exploit();
48496+ do_group_exit(SIGKILL);
48497+}
48498+#endif
48499+
48500+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48501+void pax_track_stack(void)
48502+{
48503+ unsigned long sp = (unsigned long)&sp;
48504+ if (sp < current_thread_info()->lowest_stack &&
48505+ sp > (unsigned long)task_stack_page(current))
48506+ current_thread_info()->lowest_stack = sp;
48507+}
48508+EXPORT_SYMBOL(pax_track_stack);
48509+#endif
48510+
48511 static int zap_process(struct task_struct *start)
48512 {
48513 struct task_struct *t;
48514@@ -1793,17 +2109,17 @@ static void wait_for_dump_helpers(struct file *file)
48515 pipe = file->f_path.dentry->d_inode->i_pipe;
48516
48517 pipe_lock(pipe);
48518- pipe->readers++;
48519- pipe->writers--;
48520+ atomic_inc(&pipe->readers);
48521+ atomic_dec(&pipe->writers);
48522
48523- while ((pipe->readers > 1) && (!signal_pending(current))) {
48524+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
48525 wake_up_interruptible_sync(&pipe->wait);
48526 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48527 pipe_wait(pipe);
48528 }
48529
48530- pipe->readers--;
48531- pipe->writers++;
48532+ atomic_dec(&pipe->readers);
48533+ atomic_inc(&pipe->writers);
48534 pipe_unlock(pipe);
48535
48536 }
48537@@ -1826,10 +2142,13 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48538 char **helper_argv = NULL;
48539 int helper_argc = 0;
48540 int dump_count = 0;
48541- static atomic_t core_dump_count = ATOMIC_INIT(0);
48542+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
48543
48544 audit_core_dumps(signr);
48545
48546+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
48547+ gr_handle_brute_attach(current, mm->flags);
48548+
48549 binfmt = mm->binfmt;
48550 if (!binfmt || !binfmt->core_dump)
48551 goto fail;
48552@@ -1874,6 +2193,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48553 */
48554 clear_thread_flag(TIF_SIGPENDING);
48555
48556+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
48557+
48558 /*
48559 * lock_kernel() because format_corename() is controlled by sysctl, which
48560 * uses lock_kernel()
48561@@ -1908,7 +2229,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48562 goto fail_unlock;
48563 }
48564
48565- dump_count = atomic_inc_return(&core_dump_count);
48566+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
48567 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
48568 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
48569 task_tgid_vnr(current), current->comm);
48570@@ -1972,7 +2293,7 @@ close_fail:
48571 filp_close(file, NULL);
48572 fail_dropcount:
48573 if (dump_count)
48574- atomic_dec(&core_dump_count);
48575+ atomic_dec_unchecked(&core_dump_count);
48576 fail_unlock:
48577 if (helper_argv)
48578 argv_free(helper_argv);
48579diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48580index 7f8d2e5..a1abdbb 100644
48581--- a/fs/ext2/balloc.c
48582+++ b/fs/ext2/balloc.c
48583@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48584
48585 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48586 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48587- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48588+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48589 sbi->s_resuid != current_fsuid() &&
48590 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48591 return 0;
48592diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48593index 27967f9..9f2a5fb 100644
48594--- a/fs/ext3/balloc.c
48595+++ b/fs/ext3/balloc.c
48596@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
48597
48598 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48599 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48600- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48601+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48602 sbi->s_resuid != current_fsuid() &&
48603 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48604 return 0;
48605diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48606index e85b63c..80398e6 100644
48607--- a/fs/ext4/balloc.c
48608+++ b/fs/ext4/balloc.c
48609@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
48610 /* Hm, nope. Are (enough) root reserved blocks available? */
48611 if (sbi->s_resuid == current_fsuid() ||
48612 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
48613- capable(CAP_SYS_RESOURCE)) {
48614+ capable_nolog(CAP_SYS_RESOURCE)) {
48615 if (free_blocks >= (nblocks + dirty_blocks))
48616 return 1;
48617 }
48618diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48619index 67c46ed..1f237e5 100644
48620--- a/fs/ext4/ext4.h
48621+++ b/fs/ext4/ext4.h
48622@@ -1077,19 +1077,19 @@ struct ext4_sb_info {
48623
48624 /* stats for buddy allocator */
48625 spinlock_t s_mb_pa_lock;
48626- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48627- atomic_t s_bal_success; /* we found long enough chunks */
48628- atomic_t s_bal_allocated; /* in blocks */
48629- atomic_t s_bal_ex_scanned; /* total extents scanned */
48630- atomic_t s_bal_goals; /* goal hits */
48631- atomic_t s_bal_breaks; /* too long searches */
48632- atomic_t s_bal_2orders; /* 2^order hits */
48633+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48634+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48635+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48636+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48637+ atomic_unchecked_t s_bal_goals; /* goal hits */
48638+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48639+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48640 spinlock_t s_bal_lock;
48641 unsigned long s_mb_buddies_generated;
48642 unsigned long long s_mb_generation_time;
48643- atomic_t s_mb_lost_chunks;
48644- atomic_t s_mb_preallocated;
48645- atomic_t s_mb_discarded;
48646+ atomic_unchecked_t s_mb_lost_chunks;
48647+ atomic_unchecked_t s_mb_preallocated;
48648+ atomic_unchecked_t s_mb_discarded;
48649 atomic_t s_lock_busy;
48650
48651 /* locality groups */
48652diff --git a/fs/ext4/file.c b/fs/ext4/file.c
48653index 2a60541..7439d61 100644
48654--- a/fs/ext4/file.c
48655+++ b/fs/ext4/file.c
48656@@ -122,8 +122,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
48657 cp = d_path(&path, buf, sizeof(buf));
48658 path_put(&path);
48659 if (!IS_ERR(cp)) {
48660- memcpy(sbi->s_es->s_last_mounted, cp,
48661- sizeof(sbi->s_es->s_last_mounted));
48662+ strlcpy(sbi->s_es->s_last_mounted, cp,
48663+ sizeof(sbi->s_es->s_last_mounted));
48664 sb->s_dirt = 1;
48665 }
48666 }
48667diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48668index 42bac1b..0aab9d8 100644
48669--- a/fs/ext4/mballoc.c
48670+++ b/fs/ext4/mballoc.c
48671@@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48672 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48673
48674 if (EXT4_SB(sb)->s_mb_stats)
48675- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48676+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48677
48678 break;
48679 }
48680@@ -2131,7 +2131,7 @@ repeat:
48681 ac->ac_status = AC_STATUS_CONTINUE;
48682 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48683 cr = 3;
48684- atomic_inc(&sbi->s_mb_lost_chunks);
48685+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48686 goto repeat;
48687 }
48688 }
48689@@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
48690 ext4_grpblk_t counters[16];
48691 } sg;
48692
48693+ pax_track_stack();
48694+
48695 group--;
48696 if (group == 0)
48697 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
48698@@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *sb)
48699 if (sbi->s_mb_stats) {
48700 printk(KERN_INFO
48701 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
48702- atomic_read(&sbi->s_bal_allocated),
48703- atomic_read(&sbi->s_bal_reqs),
48704- atomic_read(&sbi->s_bal_success));
48705+ atomic_read_unchecked(&sbi->s_bal_allocated),
48706+ atomic_read_unchecked(&sbi->s_bal_reqs),
48707+ atomic_read_unchecked(&sbi->s_bal_success));
48708 printk(KERN_INFO
48709 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
48710 "%u 2^N hits, %u breaks, %u lost\n",
48711- atomic_read(&sbi->s_bal_ex_scanned),
48712- atomic_read(&sbi->s_bal_goals),
48713- atomic_read(&sbi->s_bal_2orders),
48714- atomic_read(&sbi->s_bal_breaks),
48715- atomic_read(&sbi->s_mb_lost_chunks));
48716+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48717+ atomic_read_unchecked(&sbi->s_bal_goals),
48718+ atomic_read_unchecked(&sbi->s_bal_2orders),
48719+ atomic_read_unchecked(&sbi->s_bal_breaks),
48720+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48721 printk(KERN_INFO
48722 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
48723 sbi->s_mb_buddies_generated++,
48724 sbi->s_mb_generation_time);
48725 printk(KERN_INFO
48726 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
48727- atomic_read(&sbi->s_mb_preallocated),
48728- atomic_read(&sbi->s_mb_discarded));
48729+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48730+ atomic_read_unchecked(&sbi->s_mb_discarded));
48731 }
48732
48733 free_percpu(sbi->s_locality_groups);
48734@@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48735 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48736
48737 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48738- atomic_inc(&sbi->s_bal_reqs);
48739- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48740+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48741+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48742 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
48743- atomic_inc(&sbi->s_bal_success);
48744- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48745+ atomic_inc_unchecked(&sbi->s_bal_success);
48746+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48747 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48748 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48749- atomic_inc(&sbi->s_bal_goals);
48750+ atomic_inc_unchecked(&sbi->s_bal_goals);
48751 if (ac->ac_found > sbi->s_mb_max_to_scan)
48752- atomic_inc(&sbi->s_bal_breaks);
48753+ atomic_inc_unchecked(&sbi->s_bal_breaks);
48754 }
48755
48756 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48757@@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48758 trace_ext4_mb_new_inode_pa(ac, pa);
48759
48760 ext4_mb_use_inode_pa(ac, pa);
48761- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48762+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48763
48764 ei = EXT4_I(ac->ac_inode);
48765 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48766@@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48767 trace_ext4_mb_new_group_pa(ac, pa);
48768
48769 ext4_mb_use_group_pa(ac, pa);
48770- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48771+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48772
48773 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48774 lg = ac->ac_lg;
48775@@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48776 * from the bitmap and continue.
48777 */
48778 }
48779- atomic_add(free, &sbi->s_mb_discarded);
48780+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
48781
48782 return err;
48783 }
48784@@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48785 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48786 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48787 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48788- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48789+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48790
48791 if (ac) {
48792 ac->ac_sb = sb;
48793diff --git a/fs/ext4/super.c b/fs/ext4/super.c
48794index f27e045..be5a1c3 100644
48795--- a/fs/ext4/super.c
48796+++ b/fs/ext4/super.c
48797@@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobject *kobj)
48798 }
48799
48800
48801-static struct sysfs_ops ext4_attr_ops = {
48802+static const struct sysfs_ops ext4_attr_ops = {
48803 .show = ext4_attr_show,
48804 .store = ext4_attr_store,
48805 };
48806diff --git a/fs/fcntl.c b/fs/fcntl.c
48807index 97e01dc..e9aab2d 100644
48808--- a/fs/fcntl.c
48809+++ b/fs/fcntl.c
48810@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48811 if (err)
48812 return err;
48813
48814+ if (gr_handle_chroot_fowner(pid, type))
48815+ return -ENOENT;
48816+ if (gr_check_protected_task_fowner(pid, type))
48817+ return -EACCES;
48818+
48819 f_modown(filp, pid, type, force);
48820 return 0;
48821 }
48822@@ -265,7 +270,7 @@ pid_t f_getown(struct file *filp)
48823
48824 static int f_setown_ex(struct file *filp, unsigned long arg)
48825 {
48826- struct f_owner_ex * __user owner_p = (void * __user)arg;
48827+ struct f_owner_ex __user *owner_p = (void __user *)arg;
48828 struct f_owner_ex owner;
48829 struct pid *pid;
48830 int type;
48831@@ -305,7 +310,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
48832
48833 static int f_getown_ex(struct file *filp, unsigned long arg)
48834 {
48835- struct f_owner_ex * __user owner_p = (void * __user)arg;
48836+ struct f_owner_ex __user *owner_p = (void __user *)arg;
48837 struct f_owner_ex owner;
48838 int ret = 0;
48839
48840@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
48841 switch (cmd) {
48842 case F_DUPFD:
48843 case F_DUPFD_CLOEXEC:
48844+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
48845 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
48846 break;
48847 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
48848diff --git a/fs/fifo.c b/fs/fifo.c
48849index f8f97b8..b1f2259 100644
48850--- a/fs/fifo.c
48851+++ b/fs/fifo.c
48852@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48853 */
48854 filp->f_op = &read_pipefifo_fops;
48855 pipe->r_counter++;
48856- if (pipe->readers++ == 0)
48857+ if (atomic_inc_return(&pipe->readers) == 1)
48858 wake_up_partner(inode);
48859
48860- if (!pipe->writers) {
48861+ if (!atomic_read(&pipe->writers)) {
48862 if ((filp->f_flags & O_NONBLOCK)) {
48863 /* suppress POLLHUP until we have
48864 * seen a writer */
48865@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48866 * errno=ENXIO when there is no process reading the FIFO.
48867 */
48868 ret = -ENXIO;
48869- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48870+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48871 goto err;
48872
48873 filp->f_op = &write_pipefifo_fops;
48874 pipe->w_counter++;
48875- if (!pipe->writers++)
48876+ if (atomic_inc_return(&pipe->writers) == 1)
48877 wake_up_partner(inode);
48878
48879- if (!pipe->readers) {
48880+ if (!atomic_read(&pipe->readers)) {
48881 wait_for_partner(inode, &pipe->r_counter);
48882 if (signal_pending(current))
48883 goto err_wr;
48884@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48885 */
48886 filp->f_op = &rdwr_pipefifo_fops;
48887
48888- pipe->readers++;
48889- pipe->writers++;
48890+ atomic_inc(&pipe->readers);
48891+ atomic_inc(&pipe->writers);
48892 pipe->r_counter++;
48893 pipe->w_counter++;
48894- if (pipe->readers == 1 || pipe->writers == 1)
48895+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48896 wake_up_partner(inode);
48897 break;
48898
48899@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48900 return 0;
48901
48902 err_rd:
48903- if (!--pipe->readers)
48904+ if (atomic_dec_and_test(&pipe->readers))
48905 wake_up_interruptible(&pipe->wait);
48906 ret = -ERESTARTSYS;
48907 goto err;
48908
48909 err_wr:
48910- if (!--pipe->writers)
48911+ if (atomic_dec_and_test(&pipe->writers))
48912 wake_up_interruptible(&pipe->wait);
48913 ret = -ERESTARTSYS;
48914 goto err;
48915
48916 err:
48917- if (!pipe->readers && !pipe->writers)
48918+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48919 free_pipe_info(inode);
48920
48921 err_nocleanup:
48922diff --git a/fs/file.c b/fs/file.c
48923index 87e1290..a930cc4 100644
48924--- a/fs/file.c
48925+++ b/fs/file.c
48926@@ -14,6 +14,7 @@
48927 #include <linux/slab.h>
48928 #include <linux/vmalloc.h>
48929 #include <linux/file.h>
48930+#include <linux/security.h>
48931 #include <linux/fdtable.h>
48932 #include <linux/bitops.h>
48933 #include <linux/interrupt.h>
48934@@ -257,6 +258,8 @@ int expand_files(struct files_struct *files, int nr)
48935 * N.B. For clone tasks sharing a files structure, this test
48936 * will limit the total number of files that can be opened.
48937 */
48938+
48939+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
48940 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
48941 return -EMFILE;
48942
48943diff --git a/fs/filesystems.c b/fs/filesystems.c
48944index a24c58e..53f91ee 100644
48945--- a/fs/filesystems.c
48946+++ b/fs/filesystems.c
48947@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(const char *name)
48948 int len = dot ? dot - name : strlen(name);
48949
48950 fs = __get_fs_type(name, len);
48951+
48952+#ifdef CONFIG_GRKERNSEC_MODHARDEN
48953+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48954+#else
48955 if (!fs && (request_module("%.*s", len, name) == 0))
48956+#endif
48957 fs = __get_fs_type(name, len);
48958
48959 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48960diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48961index eee0590..ef5bc0e 100644
48962--- a/fs/fs_struct.c
48963+++ b/fs/fs_struct.c
48964@@ -4,6 +4,7 @@
48965 #include <linux/path.h>
48966 #include <linux/slab.h>
48967 #include <linux/fs_struct.h>
48968+#include <linux/grsecurity.h>
48969
48970 /*
48971 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
48972@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48973 old_root = fs->root;
48974 fs->root = *path;
48975 path_get(path);
48976+ gr_set_chroot_entries(current, path);
48977 write_unlock(&fs->lock);
48978 if (old_root.dentry)
48979 path_put(&old_root);
48980@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48981 && fs->root.mnt == old_root->mnt) {
48982 path_get(new_root);
48983 fs->root = *new_root;
48984+ gr_set_chroot_entries(p, new_root);
48985 count++;
48986 }
48987 if (fs->pwd.dentry == old_root->dentry
48988@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
48989 task_lock(tsk);
48990 write_lock(&fs->lock);
48991 tsk->fs = NULL;
48992- kill = !--fs->users;
48993+ gr_clear_chroot_entries(tsk);
48994+ kill = !atomic_dec_return(&fs->users);
48995 write_unlock(&fs->lock);
48996 task_unlock(tsk);
48997 if (kill)
48998@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48999 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
49000 /* We don't need to lock fs - think why ;-) */
49001 if (fs) {
49002- fs->users = 1;
49003+ atomic_set(&fs->users, 1);
49004 fs->in_exec = 0;
49005 rwlock_init(&fs->lock);
49006 fs->umask = old->umask;
49007@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
49008
49009 task_lock(current);
49010 write_lock(&fs->lock);
49011- kill = !--fs->users;
49012+ kill = !atomic_dec_return(&fs->users);
49013 current->fs = new_fs;
49014+ gr_set_chroot_entries(current, &new_fs->root);
49015 write_unlock(&fs->lock);
49016 task_unlock(current);
49017
49018@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
49019
49020 /* to be mentioned only in INIT_TASK */
49021 struct fs_struct init_fs = {
49022- .users = 1,
49023+ .users = ATOMIC_INIT(1),
49024 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
49025 .umask = 0022,
49026 };
49027@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
49028 task_lock(current);
49029
49030 write_lock(&init_fs.lock);
49031- init_fs.users++;
49032+ atomic_inc(&init_fs.users);
49033 write_unlock(&init_fs.lock);
49034
49035 write_lock(&fs->lock);
49036 current->fs = &init_fs;
49037- kill = !--fs->users;
49038+ gr_set_chroot_entries(current, &current->fs->root);
49039+ kill = !atomic_dec_return(&fs->users);
49040 write_unlock(&fs->lock);
49041
49042 task_unlock(current);
49043diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
49044index 9905350..02eaec4 100644
49045--- a/fs/fscache/cookie.c
49046+++ b/fs/fscache/cookie.c
49047@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
49048 parent ? (char *) parent->def->name : "<no-parent>",
49049 def->name, netfs_data);
49050
49051- fscache_stat(&fscache_n_acquires);
49052+ fscache_stat_unchecked(&fscache_n_acquires);
49053
49054 /* if there's no parent cookie, then we don't create one here either */
49055 if (!parent) {
49056- fscache_stat(&fscache_n_acquires_null);
49057+ fscache_stat_unchecked(&fscache_n_acquires_null);
49058 _leave(" [no parent]");
49059 return NULL;
49060 }
49061@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
49062 /* allocate and initialise a cookie */
49063 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
49064 if (!cookie) {
49065- fscache_stat(&fscache_n_acquires_oom);
49066+ fscache_stat_unchecked(&fscache_n_acquires_oom);
49067 _leave(" [ENOMEM]");
49068 return NULL;
49069 }
49070@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49071
49072 switch (cookie->def->type) {
49073 case FSCACHE_COOKIE_TYPE_INDEX:
49074- fscache_stat(&fscache_n_cookie_index);
49075+ fscache_stat_unchecked(&fscache_n_cookie_index);
49076 break;
49077 case FSCACHE_COOKIE_TYPE_DATAFILE:
49078- fscache_stat(&fscache_n_cookie_data);
49079+ fscache_stat_unchecked(&fscache_n_cookie_data);
49080 break;
49081 default:
49082- fscache_stat(&fscache_n_cookie_special);
49083+ fscache_stat_unchecked(&fscache_n_cookie_special);
49084 break;
49085 }
49086
49087@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49088 if (fscache_acquire_non_index_cookie(cookie) < 0) {
49089 atomic_dec(&parent->n_children);
49090 __fscache_cookie_put(cookie);
49091- fscache_stat(&fscache_n_acquires_nobufs);
49092+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
49093 _leave(" = NULL");
49094 return NULL;
49095 }
49096 }
49097
49098- fscache_stat(&fscache_n_acquires_ok);
49099+ fscache_stat_unchecked(&fscache_n_acquires_ok);
49100 _leave(" = %p", cookie);
49101 return cookie;
49102 }
49103@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
49104 cache = fscache_select_cache_for_object(cookie->parent);
49105 if (!cache) {
49106 up_read(&fscache_addremove_sem);
49107- fscache_stat(&fscache_n_acquires_no_cache);
49108+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
49109 _leave(" = -ENOMEDIUM [no cache]");
49110 return -ENOMEDIUM;
49111 }
49112@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
49113 object = cache->ops->alloc_object(cache, cookie);
49114 fscache_stat_d(&fscache_n_cop_alloc_object);
49115 if (IS_ERR(object)) {
49116- fscache_stat(&fscache_n_object_no_alloc);
49117+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
49118 ret = PTR_ERR(object);
49119 goto error;
49120 }
49121
49122- fscache_stat(&fscache_n_object_alloc);
49123+ fscache_stat_unchecked(&fscache_n_object_alloc);
49124
49125 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
49126
49127@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
49128 struct fscache_object *object;
49129 struct hlist_node *_p;
49130
49131- fscache_stat(&fscache_n_updates);
49132+ fscache_stat_unchecked(&fscache_n_updates);
49133
49134 if (!cookie) {
49135- fscache_stat(&fscache_n_updates_null);
49136+ fscache_stat_unchecked(&fscache_n_updates_null);
49137 _leave(" [no cookie]");
49138 return;
49139 }
49140@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49141 struct fscache_object *object;
49142 unsigned long event;
49143
49144- fscache_stat(&fscache_n_relinquishes);
49145+ fscache_stat_unchecked(&fscache_n_relinquishes);
49146 if (retire)
49147- fscache_stat(&fscache_n_relinquishes_retire);
49148+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
49149
49150 if (!cookie) {
49151- fscache_stat(&fscache_n_relinquishes_null);
49152+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
49153 _leave(" [no cookie]");
49154 return;
49155 }
49156@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49157
49158 /* wait for the cookie to finish being instantiated (or to fail) */
49159 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
49160- fscache_stat(&fscache_n_relinquishes_waitcrt);
49161+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
49162 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
49163 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
49164 }
49165diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
49166index edd7434..0725e66 100644
49167--- a/fs/fscache/internal.h
49168+++ b/fs/fscache/internal.h
49169@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
49170 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
49171 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
49172
49173-extern atomic_t fscache_n_op_pend;
49174-extern atomic_t fscache_n_op_run;
49175-extern atomic_t fscache_n_op_enqueue;
49176-extern atomic_t fscache_n_op_deferred_release;
49177-extern atomic_t fscache_n_op_release;
49178-extern atomic_t fscache_n_op_gc;
49179-extern atomic_t fscache_n_op_cancelled;
49180-extern atomic_t fscache_n_op_rejected;
49181+extern atomic_unchecked_t fscache_n_op_pend;
49182+extern atomic_unchecked_t fscache_n_op_run;
49183+extern atomic_unchecked_t fscache_n_op_enqueue;
49184+extern atomic_unchecked_t fscache_n_op_deferred_release;
49185+extern atomic_unchecked_t fscache_n_op_release;
49186+extern atomic_unchecked_t fscache_n_op_gc;
49187+extern atomic_unchecked_t fscache_n_op_cancelled;
49188+extern atomic_unchecked_t fscache_n_op_rejected;
49189
49190-extern atomic_t fscache_n_attr_changed;
49191-extern atomic_t fscache_n_attr_changed_ok;
49192-extern atomic_t fscache_n_attr_changed_nobufs;
49193-extern atomic_t fscache_n_attr_changed_nomem;
49194-extern atomic_t fscache_n_attr_changed_calls;
49195+extern atomic_unchecked_t fscache_n_attr_changed;
49196+extern atomic_unchecked_t fscache_n_attr_changed_ok;
49197+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
49198+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
49199+extern atomic_unchecked_t fscache_n_attr_changed_calls;
49200
49201-extern atomic_t fscache_n_allocs;
49202-extern atomic_t fscache_n_allocs_ok;
49203-extern atomic_t fscache_n_allocs_wait;
49204-extern atomic_t fscache_n_allocs_nobufs;
49205-extern atomic_t fscache_n_allocs_intr;
49206-extern atomic_t fscache_n_allocs_object_dead;
49207-extern atomic_t fscache_n_alloc_ops;
49208-extern atomic_t fscache_n_alloc_op_waits;
49209+extern atomic_unchecked_t fscache_n_allocs;
49210+extern atomic_unchecked_t fscache_n_allocs_ok;
49211+extern atomic_unchecked_t fscache_n_allocs_wait;
49212+extern atomic_unchecked_t fscache_n_allocs_nobufs;
49213+extern atomic_unchecked_t fscache_n_allocs_intr;
49214+extern atomic_unchecked_t fscache_n_allocs_object_dead;
49215+extern atomic_unchecked_t fscache_n_alloc_ops;
49216+extern atomic_unchecked_t fscache_n_alloc_op_waits;
49217
49218-extern atomic_t fscache_n_retrievals;
49219-extern atomic_t fscache_n_retrievals_ok;
49220-extern atomic_t fscache_n_retrievals_wait;
49221-extern atomic_t fscache_n_retrievals_nodata;
49222-extern atomic_t fscache_n_retrievals_nobufs;
49223-extern atomic_t fscache_n_retrievals_intr;
49224-extern atomic_t fscache_n_retrievals_nomem;
49225-extern atomic_t fscache_n_retrievals_object_dead;
49226-extern atomic_t fscache_n_retrieval_ops;
49227-extern atomic_t fscache_n_retrieval_op_waits;
49228+extern atomic_unchecked_t fscache_n_retrievals;
49229+extern atomic_unchecked_t fscache_n_retrievals_ok;
49230+extern atomic_unchecked_t fscache_n_retrievals_wait;
49231+extern atomic_unchecked_t fscache_n_retrievals_nodata;
49232+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
49233+extern atomic_unchecked_t fscache_n_retrievals_intr;
49234+extern atomic_unchecked_t fscache_n_retrievals_nomem;
49235+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
49236+extern atomic_unchecked_t fscache_n_retrieval_ops;
49237+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
49238
49239-extern atomic_t fscache_n_stores;
49240-extern atomic_t fscache_n_stores_ok;
49241-extern atomic_t fscache_n_stores_again;
49242-extern atomic_t fscache_n_stores_nobufs;
49243-extern atomic_t fscache_n_stores_oom;
49244-extern atomic_t fscache_n_store_ops;
49245-extern atomic_t fscache_n_store_calls;
49246-extern atomic_t fscache_n_store_pages;
49247-extern atomic_t fscache_n_store_radix_deletes;
49248-extern atomic_t fscache_n_store_pages_over_limit;
49249+extern atomic_unchecked_t fscache_n_stores;
49250+extern atomic_unchecked_t fscache_n_stores_ok;
49251+extern atomic_unchecked_t fscache_n_stores_again;
49252+extern atomic_unchecked_t fscache_n_stores_nobufs;
49253+extern atomic_unchecked_t fscache_n_stores_oom;
49254+extern atomic_unchecked_t fscache_n_store_ops;
49255+extern atomic_unchecked_t fscache_n_store_calls;
49256+extern atomic_unchecked_t fscache_n_store_pages;
49257+extern atomic_unchecked_t fscache_n_store_radix_deletes;
49258+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
49259
49260-extern atomic_t fscache_n_store_vmscan_not_storing;
49261-extern atomic_t fscache_n_store_vmscan_gone;
49262-extern atomic_t fscache_n_store_vmscan_busy;
49263-extern atomic_t fscache_n_store_vmscan_cancelled;
49264+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49265+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
49266+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
49267+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49268
49269-extern atomic_t fscache_n_marks;
49270-extern atomic_t fscache_n_uncaches;
49271+extern atomic_unchecked_t fscache_n_marks;
49272+extern atomic_unchecked_t fscache_n_uncaches;
49273
49274-extern atomic_t fscache_n_acquires;
49275-extern atomic_t fscache_n_acquires_null;
49276-extern atomic_t fscache_n_acquires_no_cache;
49277-extern atomic_t fscache_n_acquires_ok;
49278-extern atomic_t fscache_n_acquires_nobufs;
49279-extern atomic_t fscache_n_acquires_oom;
49280+extern atomic_unchecked_t fscache_n_acquires;
49281+extern atomic_unchecked_t fscache_n_acquires_null;
49282+extern atomic_unchecked_t fscache_n_acquires_no_cache;
49283+extern atomic_unchecked_t fscache_n_acquires_ok;
49284+extern atomic_unchecked_t fscache_n_acquires_nobufs;
49285+extern atomic_unchecked_t fscache_n_acquires_oom;
49286
49287-extern atomic_t fscache_n_updates;
49288-extern atomic_t fscache_n_updates_null;
49289-extern atomic_t fscache_n_updates_run;
49290+extern atomic_unchecked_t fscache_n_updates;
49291+extern atomic_unchecked_t fscache_n_updates_null;
49292+extern atomic_unchecked_t fscache_n_updates_run;
49293
49294-extern atomic_t fscache_n_relinquishes;
49295-extern atomic_t fscache_n_relinquishes_null;
49296-extern atomic_t fscache_n_relinquishes_waitcrt;
49297-extern atomic_t fscache_n_relinquishes_retire;
49298+extern atomic_unchecked_t fscache_n_relinquishes;
49299+extern atomic_unchecked_t fscache_n_relinquishes_null;
49300+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49301+extern atomic_unchecked_t fscache_n_relinquishes_retire;
49302
49303-extern atomic_t fscache_n_cookie_index;
49304-extern atomic_t fscache_n_cookie_data;
49305-extern atomic_t fscache_n_cookie_special;
49306+extern atomic_unchecked_t fscache_n_cookie_index;
49307+extern atomic_unchecked_t fscache_n_cookie_data;
49308+extern atomic_unchecked_t fscache_n_cookie_special;
49309
49310-extern atomic_t fscache_n_object_alloc;
49311-extern atomic_t fscache_n_object_no_alloc;
49312-extern atomic_t fscache_n_object_lookups;
49313-extern atomic_t fscache_n_object_lookups_negative;
49314-extern atomic_t fscache_n_object_lookups_positive;
49315-extern atomic_t fscache_n_object_lookups_timed_out;
49316-extern atomic_t fscache_n_object_created;
49317-extern atomic_t fscache_n_object_avail;
49318-extern atomic_t fscache_n_object_dead;
49319+extern atomic_unchecked_t fscache_n_object_alloc;
49320+extern atomic_unchecked_t fscache_n_object_no_alloc;
49321+extern atomic_unchecked_t fscache_n_object_lookups;
49322+extern atomic_unchecked_t fscache_n_object_lookups_negative;
49323+extern atomic_unchecked_t fscache_n_object_lookups_positive;
49324+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
49325+extern atomic_unchecked_t fscache_n_object_created;
49326+extern atomic_unchecked_t fscache_n_object_avail;
49327+extern atomic_unchecked_t fscache_n_object_dead;
49328
49329-extern atomic_t fscache_n_checkaux_none;
49330-extern atomic_t fscache_n_checkaux_okay;
49331-extern atomic_t fscache_n_checkaux_update;
49332-extern atomic_t fscache_n_checkaux_obsolete;
49333+extern atomic_unchecked_t fscache_n_checkaux_none;
49334+extern atomic_unchecked_t fscache_n_checkaux_okay;
49335+extern atomic_unchecked_t fscache_n_checkaux_update;
49336+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
49337
49338 extern atomic_t fscache_n_cop_alloc_object;
49339 extern atomic_t fscache_n_cop_lookup_object;
49340@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t *stat)
49341 atomic_inc(stat);
49342 }
49343
49344+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
49345+{
49346+ atomic_inc_unchecked(stat);
49347+}
49348+
49349 static inline void fscache_stat_d(atomic_t *stat)
49350 {
49351 atomic_dec(stat);
49352@@ -259,6 +264,7 @@ extern const struct file_operations fscache_stats_fops;
49353
49354 #define __fscache_stat(stat) (NULL)
49355 #define fscache_stat(stat) do {} while (0)
49356+#define fscache_stat_unchecked(stat) do {} while (0)
49357 #define fscache_stat_d(stat) do {} while (0)
49358 #endif
49359
49360diff --git a/fs/fscache/object.c b/fs/fscache/object.c
49361index e513ac5..e888d34 100644
49362--- a/fs/fscache/object.c
49363+++ b/fs/fscache/object.c
49364@@ -144,7 +144,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49365 /* update the object metadata on disk */
49366 case FSCACHE_OBJECT_UPDATING:
49367 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
49368- fscache_stat(&fscache_n_updates_run);
49369+ fscache_stat_unchecked(&fscache_n_updates_run);
49370 fscache_stat(&fscache_n_cop_update_object);
49371 object->cache->ops->update_object(object);
49372 fscache_stat_d(&fscache_n_cop_update_object);
49373@@ -233,7 +233,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49374 spin_lock(&object->lock);
49375 object->state = FSCACHE_OBJECT_DEAD;
49376 spin_unlock(&object->lock);
49377- fscache_stat(&fscache_n_object_dead);
49378+ fscache_stat_unchecked(&fscache_n_object_dead);
49379 goto terminal_transit;
49380
49381 /* handle the parent cache of this object being withdrawn from
49382@@ -248,7 +248,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49383 spin_lock(&object->lock);
49384 object->state = FSCACHE_OBJECT_DEAD;
49385 spin_unlock(&object->lock);
49386- fscache_stat(&fscache_n_object_dead);
49387+ fscache_stat_unchecked(&fscache_n_object_dead);
49388 goto terminal_transit;
49389
49390 /* complain about the object being woken up once it is
49391@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49392 parent->cookie->def->name, cookie->def->name,
49393 object->cache->tag->name);
49394
49395- fscache_stat(&fscache_n_object_lookups);
49396+ fscache_stat_unchecked(&fscache_n_object_lookups);
49397 fscache_stat(&fscache_n_cop_lookup_object);
49398 ret = object->cache->ops->lookup_object(object);
49399 fscache_stat_d(&fscache_n_cop_lookup_object);
49400@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49401 if (ret == -ETIMEDOUT) {
49402 /* probably stuck behind another object, so move this one to
49403 * the back of the queue */
49404- fscache_stat(&fscache_n_object_lookups_timed_out);
49405+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49406 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49407 }
49408
49409@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49410
49411 spin_lock(&object->lock);
49412 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49413- fscache_stat(&fscache_n_object_lookups_negative);
49414+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49415
49416 /* transit here to allow write requests to begin stacking up
49417 * and read requests to begin returning ENODATA */
49418@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fscache_object *object)
49419 * result, in which case there may be data available */
49420 spin_lock(&object->lock);
49421 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49422- fscache_stat(&fscache_n_object_lookups_positive);
49423+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49424
49425 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49426
49427@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fscache_object *object)
49428 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49429 } else {
49430 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49431- fscache_stat(&fscache_n_object_created);
49432+ fscache_stat_unchecked(&fscache_n_object_created);
49433
49434 object->state = FSCACHE_OBJECT_AVAILABLE;
49435 spin_unlock(&object->lock);
49436@@ -633,7 +633,7 @@ static void fscache_object_available(struct fscache_object *object)
49437 fscache_enqueue_dependents(object);
49438
49439 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49440- fscache_stat(&fscache_n_object_avail);
49441+ fscache_stat_unchecked(&fscache_n_object_avail);
49442
49443 _leave("");
49444 }
49445@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49446 enum fscache_checkaux result;
49447
49448 if (!object->cookie->def->check_aux) {
49449- fscache_stat(&fscache_n_checkaux_none);
49450+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49451 return FSCACHE_CHECKAUX_OKAY;
49452 }
49453
49454@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49455 switch (result) {
49456 /* entry okay as is */
49457 case FSCACHE_CHECKAUX_OKAY:
49458- fscache_stat(&fscache_n_checkaux_okay);
49459+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49460 break;
49461
49462 /* entry requires update */
49463 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49464- fscache_stat(&fscache_n_checkaux_update);
49465+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49466 break;
49467
49468 /* entry requires deletion */
49469 case FSCACHE_CHECKAUX_OBSOLETE:
49470- fscache_stat(&fscache_n_checkaux_obsolete);
49471+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49472 break;
49473
49474 default:
49475diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49476index 313e79a..775240f 100644
49477--- a/fs/fscache/operation.c
49478+++ b/fs/fscache/operation.c
49479@@ -16,7 +16,7 @@
49480 #include <linux/seq_file.h>
49481 #include "internal.h"
49482
49483-atomic_t fscache_op_debug_id;
49484+atomic_unchecked_t fscache_op_debug_id;
49485 EXPORT_SYMBOL(fscache_op_debug_id);
49486
49487 /**
49488@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49489 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
49490 ASSERTCMP(atomic_read(&op->usage), >, 0);
49491
49492- fscache_stat(&fscache_n_op_enqueue);
49493+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49494 switch (op->flags & FSCACHE_OP_TYPE) {
49495 case FSCACHE_OP_FAST:
49496 _debug("queue fast");
49497@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscache_object *object,
49498 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49499 if (op->processor)
49500 fscache_enqueue_operation(op);
49501- fscache_stat(&fscache_n_op_run);
49502+ fscache_stat_unchecked(&fscache_n_op_run);
49503 }
49504
49505 /*
49506@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49507 if (object->n_ops > 0) {
49508 atomic_inc(&op->usage);
49509 list_add_tail(&op->pend_link, &object->pending_ops);
49510- fscache_stat(&fscache_n_op_pend);
49511+ fscache_stat_unchecked(&fscache_n_op_pend);
49512 } else if (!list_empty(&object->pending_ops)) {
49513 atomic_inc(&op->usage);
49514 list_add_tail(&op->pend_link, &object->pending_ops);
49515- fscache_stat(&fscache_n_op_pend);
49516+ fscache_stat_unchecked(&fscache_n_op_pend);
49517 fscache_start_operations(object);
49518 } else {
49519 ASSERTCMP(object->n_in_progress, ==, 0);
49520@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49521 object->n_exclusive++; /* reads and writes must wait */
49522 atomic_inc(&op->usage);
49523 list_add_tail(&op->pend_link, &object->pending_ops);
49524- fscache_stat(&fscache_n_op_pend);
49525+ fscache_stat_unchecked(&fscache_n_op_pend);
49526 ret = 0;
49527 } else {
49528 /* not allowed to submit ops in any other state */
49529@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_object *object,
49530 if (object->n_exclusive > 0) {
49531 atomic_inc(&op->usage);
49532 list_add_tail(&op->pend_link, &object->pending_ops);
49533- fscache_stat(&fscache_n_op_pend);
49534+ fscache_stat_unchecked(&fscache_n_op_pend);
49535 } else if (!list_empty(&object->pending_ops)) {
49536 atomic_inc(&op->usage);
49537 list_add_tail(&op->pend_link, &object->pending_ops);
49538- fscache_stat(&fscache_n_op_pend);
49539+ fscache_stat_unchecked(&fscache_n_op_pend);
49540 fscache_start_operations(object);
49541 } else {
49542 ASSERTCMP(object->n_exclusive, ==, 0);
49543@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_object *object,
49544 object->n_ops++;
49545 atomic_inc(&op->usage);
49546 list_add_tail(&op->pend_link, &object->pending_ops);
49547- fscache_stat(&fscache_n_op_pend);
49548+ fscache_stat_unchecked(&fscache_n_op_pend);
49549 ret = 0;
49550 } else if (object->state == FSCACHE_OBJECT_DYING ||
49551 object->state == FSCACHE_OBJECT_LC_DYING ||
49552 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49553- fscache_stat(&fscache_n_op_rejected);
49554+ fscache_stat_unchecked(&fscache_n_op_rejected);
49555 ret = -ENOBUFS;
49556 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49557 fscache_report_unexpected_submission(object, op, ostate);
49558@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_operation *op)
49559
49560 ret = -EBUSY;
49561 if (!list_empty(&op->pend_link)) {
49562- fscache_stat(&fscache_n_op_cancelled);
49563+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49564 list_del_init(&op->pend_link);
49565 object->n_ops--;
49566 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
49567@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscache_operation *op)
49568 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
49569 BUG();
49570
49571- fscache_stat(&fscache_n_op_release);
49572+ fscache_stat_unchecked(&fscache_n_op_release);
49573
49574 if (op->release) {
49575 op->release(op);
49576@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscache_operation *op)
49577 * lock, and defer it otherwise */
49578 if (!spin_trylock(&object->lock)) {
49579 _debug("defer put");
49580- fscache_stat(&fscache_n_op_deferred_release);
49581+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49582
49583 cache = object->cache;
49584 spin_lock(&cache->op_gc_list_lock);
49585@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_struct *work)
49586
49587 _debug("GC DEFERRED REL OBJ%x OP%x",
49588 object->debug_id, op->debug_id);
49589- fscache_stat(&fscache_n_op_gc);
49590+ fscache_stat_unchecked(&fscache_n_op_gc);
49591
49592 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49593
49594diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49595index c598ea4..6aac13e 100644
49596--- a/fs/fscache/page.c
49597+++ b/fs/fscache/page.c
49598@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49599 val = radix_tree_lookup(&cookie->stores, page->index);
49600 if (!val) {
49601 rcu_read_unlock();
49602- fscache_stat(&fscache_n_store_vmscan_not_storing);
49603+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49604 __fscache_uncache_page(cookie, page);
49605 return true;
49606 }
49607@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49608 spin_unlock(&cookie->stores_lock);
49609
49610 if (xpage) {
49611- fscache_stat(&fscache_n_store_vmscan_cancelled);
49612- fscache_stat(&fscache_n_store_radix_deletes);
49613+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49614+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49615 ASSERTCMP(xpage, ==, page);
49616 } else {
49617- fscache_stat(&fscache_n_store_vmscan_gone);
49618+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49619 }
49620
49621 wake_up_bit(&cookie->flags, 0);
49622@@ -106,7 +106,7 @@ page_busy:
49623 /* we might want to wait here, but that could deadlock the allocator as
49624 * the slow-work threads writing to the cache may all end up sleeping
49625 * on memory allocation */
49626- fscache_stat(&fscache_n_store_vmscan_busy);
49627+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49628 return false;
49629 }
49630 EXPORT_SYMBOL(__fscache_maybe_release_page);
49631@@ -130,7 +130,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49632 FSCACHE_COOKIE_STORING_TAG);
49633 if (!radix_tree_tag_get(&cookie->stores, page->index,
49634 FSCACHE_COOKIE_PENDING_TAG)) {
49635- fscache_stat(&fscache_n_store_radix_deletes);
49636+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49637 xpage = radix_tree_delete(&cookie->stores, page->index);
49638 }
49639 spin_unlock(&cookie->stores_lock);
49640@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49641
49642 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49643
49644- fscache_stat(&fscache_n_attr_changed_calls);
49645+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49646
49647 if (fscache_object_is_active(object)) {
49648 fscache_set_op_state(op, "CallFS");
49649@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49650
49651 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49652
49653- fscache_stat(&fscache_n_attr_changed);
49654+ fscache_stat_unchecked(&fscache_n_attr_changed);
49655
49656 op = kzalloc(sizeof(*op), GFP_KERNEL);
49657 if (!op) {
49658- fscache_stat(&fscache_n_attr_changed_nomem);
49659+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49660 _leave(" = -ENOMEM");
49661 return -ENOMEM;
49662 }
49663@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49664 if (fscache_submit_exclusive_op(object, op) < 0)
49665 goto nobufs;
49666 spin_unlock(&cookie->lock);
49667- fscache_stat(&fscache_n_attr_changed_ok);
49668+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49669 fscache_put_operation(op);
49670 _leave(" = 0");
49671 return 0;
49672@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49673 nobufs:
49674 spin_unlock(&cookie->lock);
49675 kfree(op);
49676- fscache_stat(&fscache_n_attr_changed_nobufs);
49677+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49678 _leave(" = %d", -ENOBUFS);
49679 return -ENOBUFS;
49680 }
49681@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49682 /* allocate a retrieval operation and attempt to submit it */
49683 op = kzalloc(sizeof(*op), GFP_NOIO);
49684 if (!op) {
49685- fscache_stat(&fscache_n_retrievals_nomem);
49686+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49687 return NULL;
49688 }
49689
49690@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49691 return 0;
49692 }
49693
49694- fscache_stat(&fscache_n_retrievals_wait);
49695+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49696
49697 jif = jiffies;
49698 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49699 fscache_wait_bit_interruptible,
49700 TASK_INTERRUPTIBLE) != 0) {
49701- fscache_stat(&fscache_n_retrievals_intr);
49702+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49703 _leave(" = -ERESTARTSYS");
49704 return -ERESTARTSYS;
49705 }
49706@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49707 */
49708 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49709 struct fscache_retrieval *op,
49710- atomic_t *stat_op_waits,
49711- atomic_t *stat_object_dead)
49712+ atomic_unchecked_t *stat_op_waits,
49713+ atomic_unchecked_t *stat_object_dead)
49714 {
49715 int ret;
49716
49717@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49718 goto check_if_dead;
49719
49720 _debug(">>> WT");
49721- fscache_stat(stat_op_waits);
49722+ fscache_stat_unchecked(stat_op_waits);
49723 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49724 fscache_wait_bit_interruptible,
49725 TASK_INTERRUPTIBLE) < 0) {
49726@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49727
49728 check_if_dead:
49729 if (unlikely(fscache_object_is_dead(object))) {
49730- fscache_stat(stat_object_dead);
49731+ fscache_stat_unchecked(stat_object_dead);
49732 return -ENOBUFS;
49733 }
49734 return 0;
49735@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49736
49737 _enter("%p,%p,,,", cookie, page);
49738
49739- fscache_stat(&fscache_n_retrievals);
49740+ fscache_stat_unchecked(&fscache_n_retrievals);
49741
49742 if (hlist_empty(&cookie->backing_objects))
49743 goto nobufs;
49744@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49745 goto nobufs_unlock;
49746 spin_unlock(&cookie->lock);
49747
49748- fscache_stat(&fscache_n_retrieval_ops);
49749+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49750
49751 /* pin the netfs read context in case we need to do the actual netfs
49752 * read because we've encountered a cache read failure */
49753@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49754
49755 error:
49756 if (ret == -ENOMEM)
49757- fscache_stat(&fscache_n_retrievals_nomem);
49758+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49759 else if (ret == -ERESTARTSYS)
49760- fscache_stat(&fscache_n_retrievals_intr);
49761+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49762 else if (ret == -ENODATA)
49763- fscache_stat(&fscache_n_retrievals_nodata);
49764+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49765 else if (ret < 0)
49766- fscache_stat(&fscache_n_retrievals_nobufs);
49767+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49768 else
49769- fscache_stat(&fscache_n_retrievals_ok);
49770+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49771
49772 fscache_put_retrieval(op);
49773 _leave(" = %d", ret);
49774@@ -453,7 +453,7 @@ nobufs_unlock:
49775 spin_unlock(&cookie->lock);
49776 kfree(op);
49777 nobufs:
49778- fscache_stat(&fscache_n_retrievals_nobufs);
49779+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49780 _leave(" = -ENOBUFS");
49781 return -ENOBUFS;
49782 }
49783@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49784
49785 _enter("%p,,%d,,,", cookie, *nr_pages);
49786
49787- fscache_stat(&fscache_n_retrievals);
49788+ fscache_stat_unchecked(&fscache_n_retrievals);
49789
49790 if (hlist_empty(&cookie->backing_objects))
49791 goto nobufs;
49792@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49793 goto nobufs_unlock;
49794 spin_unlock(&cookie->lock);
49795
49796- fscache_stat(&fscache_n_retrieval_ops);
49797+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49798
49799 /* pin the netfs read context in case we need to do the actual netfs
49800 * read because we've encountered a cache read failure */
49801@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49802
49803 error:
49804 if (ret == -ENOMEM)
49805- fscache_stat(&fscache_n_retrievals_nomem);
49806+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49807 else if (ret == -ERESTARTSYS)
49808- fscache_stat(&fscache_n_retrievals_intr);
49809+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49810 else if (ret == -ENODATA)
49811- fscache_stat(&fscache_n_retrievals_nodata);
49812+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49813 else if (ret < 0)
49814- fscache_stat(&fscache_n_retrievals_nobufs);
49815+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49816 else
49817- fscache_stat(&fscache_n_retrievals_ok);
49818+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49819
49820 fscache_put_retrieval(op);
49821 _leave(" = %d", ret);
49822@@ -570,7 +570,7 @@ nobufs_unlock:
49823 spin_unlock(&cookie->lock);
49824 kfree(op);
49825 nobufs:
49826- fscache_stat(&fscache_n_retrievals_nobufs);
49827+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49828 _leave(" = -ENOBUFS");
49829 return -ENOBUFS;
49830 }
49831@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49832
49833 _enter("%p,%p,,,", cookie, page);
49834
49835- fscache_stat(&fscache_n_allocs);
49836+ fscache_stat_unchecked(&fscache_n_allocs);
49837
49838 if (hlist_empty(&cookie->backing_objects))
49839 goto nobufs;
49840@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49841 goto nobufs_unlock;
49842 spin_unlock(&cookie->lock);
49843
49844- fscache_stat(&fscache_n_alloc_ops);
49845+ fscache_stat_unchecked(&fscache_n_alloc_ops);
49846
49847 ret = fscache_wait_for_retrieval_activation(
49848 object, op,
49849@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49850
49851 error:
49852 if (ret == -ERESTARTSYS)
49853- fscache_stat(&fscache_n_allocs_intr);
49854+ fscache_stat_unchecked(&fscache_n_allocs_intr);
49855 else if (ret < 0)
49856- fscache_stat(&fscache_n_allocs_nobufs);
49857+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49858 else
49859- fscache_stat(&fscache_n_allocs_ok);
49860+ fscache_stat_unchecked(&fscache_n_allocs_ok);
49861
49862 fscache_put_retrieval(op);
49863 _leave(" = %d", ret);
49864@@ -651,7 +651,7 @@ nobufs_unlock:
49865 spin_unlock(&cookie->lock);
49866 kfree(op);
49867 nobufs:
49868- fscache_stat(&fscache_n_allocs_nobufs);
49869+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49870 _leave(" = -ENOBUFS");
49871 return -ENOBUFS;
49872 }
49873@@ -694,7 +694,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49874
49875 spin_lock(&cookie->stores_lock);
49876
49877- fscache_stat(&fscache_n_store_calls);
49878+ fscache_stat_unchecked(&fscache_n_store_calls);
49879
49880 /* find a page to store */
49881 page = NULL;
49882@@ -705,7 +705,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49883 page = results[0];
49884 _debug("gang %d [%lx]", n, page->index);
49885 if (page->index > op->store_limit) {
49886- fscache_stat(&fscache_n_store_pages_over_limit);
49887+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49888 goto superseded;
49889 }
49890
49891@@ -721,7 +721,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49892
49893 if (page) {
49894 fscache_set_op_state(&op->op, "Store");
49895- fscache_stat(&fscache_n_store_pages);
49896+ fscache_stat_unchecked(&fscache_n_store_pages);
49897 fscache_stat(&fscache_n_cop_write_page);
49898 ret = object->cache->ops->write_page(op, page);
49899 fscache_stat_d(&fscache_n_cop_write_page);
49900@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49901 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49902 ASSERT(PageFsCache(page));
49903
49904- fscache_stat(&fscache_n_stores);
49905+ fscache_stat_unchecked(&fscache_n_stores);
49906
49907 op = kzalloc(sizeof(*op), GFP_NOIO);
49908 if (!op)
49909@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49910 spin_unlock(&cookie->stores_lock);
49911 spin_unlock(&object->lock);
49912
49913- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49914+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49915 op->store_limit = object->store_limit;
49916
49917 if (fscache_submit_op(object, &op->op) < 0)
49918@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49919
49920 spin_unlock(&cookie->lock);
49921 radix_tree_preload_end();
49922- fscache_stat(&fscache_n_store_ops);
49923- fscache_stat(&fscache_n_stores_ok);
49924+ fscache_stat_unchecked(&fscache_n_store_ops);
49925+ fscache_stat_unchecked(&fscache_n_stores_ok);
49926
49927 /* the slow work queue now carries its own ref on the object */
49928 fscache_put_operation(&op->op);
49929@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49930 return 0;
49931
49932 already_queued:
49933- fscache_stat(&fscache_n_stores_again);
49934+ fscache_stat_unchecked(&fscache_n_stores_again);
49935 already_pending:
49936 spin_unlock(&cookie->stores_lock);
49937 spin_unlock(&object->lock);
49938 spin_unlock(&cookie->lock);
49939 radix_tree_preload_end();
49940 kfree(op);
49941- fscache_stat(&fscache_n_stores_ok);
49942+ fscache_stat_unchecked(&fscache_n_stores_ok);
49943 _leave(" = 0");
49944 return 0;
49945
49946@@ -886,14 +886,14 @@ nobufs:
49947 spin_unlock(&cookie->lock);
49948 radix_tree_preload_end();
49949 kfree(op);
49950- fscache_stat(&fscache_n_stores_nobufs);
49951+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
49952 _leave(" = -ENOBUFS");
49953 return -ENOBUFS;
49954
49955 nomem_free:
49956 kfree(op);
49957 nomem:
49958- fscache_stat(&fscache_n_stores_oom);
49959+ fscache_stat_unchecked(&fscache_n_stores_oom);
49960 _leave(" = -ENOMEM");
49961 return -ENOMEM;
49962 }
49963@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49964 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49965 ASSERTCMP(page, !=, NULL);
49966
49967- fscache_stat(&fscache_n_uncaches);
49968+ fscache_stat_unchecked(&fscache_n_uncaches);
49969
49970 /* cache withdrawal may beat us to it */
49971 if (!PageFsCache(page))
49972@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
49973 unsigned long loop;
49974
49975 #ifdef CONFIG_FSCACHE_STATS
49976- atomic_add(pagevec->nr, &fscache_n_marks);
49977+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
49978 #endif
49979
49980 for (loop = 0; loop < pagevec->nr; loop++) {
49981diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49982index 46435f3..8cddf18 100644
49983--- a/fs/fscache/stats.c
49984+++ b/fs/fscache/stats.c
49985@@ -18,95 +18,95 @@
49986 /*
49987 * operation counters
49988 */
49989-atomic_t fscache_n_op_pend;
49990-atomic_t fscache_n_op_run;
49991-atomic_t fscache_n_op_enqueue;
49992-atomic_t fscache_n_op_requeue;
49993-atomic_t fscache_n_op_deferred_release;
49994-atomic_t fscache_n_op_release;
49995-atomic_t fscache_n_op_gc;
49996-atomic_t fscache_n_op_cancelled;
49997-atomic_t fscache_n_op_rejected;
49998+atomic_unchecked_t fscache_n_op_pend;
49999+atomic_unchecked_t fscache_n_op_run;
50000+atomic_unchecked_t fscache_n_op_enqueue;
50001+atomic_unchecked_t fscache_n_op_requeue;
50002+atomic_unchecked_t fscache_n_op_deferred_release;
50003+atomic_unchecked_t fscache_n_op_release;
50004+atomic_unchecked_t fscache_n_op_gc;
50005+atomic_unchecked_t fscache_n_op_cancelled;
50006+atomic_unchecked_t fscache_n_op_rejected;
50007
50008-atomic_t fscache_n_attr_changed;
50009-atomic_t fscache_n_attr_changed_ok;
50010-atomic_t fscache_n_attr_changed_nobufs;
50011-atomic_t fscache_n_attr_changed_nomem;
50012-atomic_t fscache_n_attr_changed_calls;
50013+atomic_unchecked_t fscache_n_attr_changed;
50014+atomic_unchecked_t fscache_n_attr_changed_ok;
50015+atomic_unchecked_t fscache_n_attr_changed_nobufs;
50016+atomic_unchecked_t fscache_n_attr_changed_nomem;
50017+atomic_unchecked_t fscache_n_attr_changed_calls;
50018
50019-atomic_t fscache_n_allocs;
50020-atomic_t fscache_n_allocs_ok;
50021-atomic_t fscache_n_allocs_wait;
50022-atomic_t fscache_n_allocs_nobufs;
50023-atomic_t fscache_n_allocs_intr;
50024-atomic_t fscache_n_allocs_object_dead;
50025-atomic_t fscache_n_alloc_ops;
50026-atomic_t fscache_n_alloc_op_waits;
50027+atomic_unchecked_t fscache_n_allocs;
50028+atomic_unchecked_t fscache_n_allocs_ok;
50029+atomic_unchecked_t fscache_n_allocs_wait;
50030+atomic_unchecked_t fscache_n_allocs_nobufs;
50031+atomic_unchecked_t fscache_n_allocs_intr;
50032+atomic_unchecked_t fscache_n_allocs_object_dead;
50033+atomic_unchecked_t fscache_n_alloc_ops;
50034+atomic_unchecked_t fscache_n_alloc_op_waits;
50035
50036-atomic_t fscache_n_retrievals;
50037-atomic_t fscache_n_retrievals_ok;
50038-atomic_t fscache_n_retrievals_wait;
50039-atomic_t fscache_n_retrievals_nodata;
50040-atomic_t fscache_n_retrievals_nobufs;
50041-atomic_t fscache_n_retrievals_intr;
50042-atomic_t fscache_n_retrievals_nomem;
50043-atomic_t fscache_n_retrievals_object_dead;
50044-atomic_t fscache_n_retrieval_ops;
50045-atomic_t fscache_n_retrieval_op_waits;
50046+atomic_unchecked_t fscache_n_retrievals;
50047+atomic_unchecked_t fscache_n_retrievals_ok;
50048+atomic_unchecked_t fscache_n_retrievals_wait;
50049+atomic_unchecked_t fscache_n_retrievals_nodata;
50050+atomic_unchecked_t fscache_n_retrievals_nobufs;
50051+atomic_unchecked_t fscache_n_retrievals_intr;
50052+atomic_unchecked_t fscache_n_retrievals_nomem;
50053+atomic_unchecked_t fscache_n_retrievals_object_dead;
50054+atomic_unchecked_t fscache_n_retrieval_ops;
50055+atomic_unchecked_t fscache_n_retrieval_op_waits;
50056
50057-atomic_t fscache_n_stores;
50058-atomic_t fscache_n_stores_ok;
50059-atomic_t fscache_n_stores_again;
50060-atomic_t fscache_n_stores_nobufs;
50061-atomic_t fscache_n_stores_oom;
50062-atomic_t fscache_n_store_ops;
50063-atomic_t fscache_n_store_calls;
50064-atomic_t fscache_n_store_pages;
50065-atomic_t fscache_n_store_radix_deletes;
50066-atomic_t fscache_n_store_pages_over_limit;
50067+atomic_unchecked_t fscache_n_stores;
50068+atomic_unchecked_t fscache_n_stores_ok;
50069+atomic_unchecked_t fscache_n_stores_again;
50070+atomic_unchecked_t fscache_n_stores_nobufs;
50071+atomic_unchecked_t fscache_n_stores_oom;
50072+atomic_unchecked_t fscache_n_store_ops;
50073+atomic_unchecked_t fscache_n_store_calls;
50074+atomic_unchecked_t fscache_n_store_pages;
50075+atomic_unchecked_t fscache_n_store_radix_deletes;
50076+atomic_unchecked_t fscache_n_store_pages_over_limit;
50077
50078-atomic_t fscache_n_store_vmscan_not_storing;
50079-atomic_t fscache_n_store_vmscan_gone;
50080-atomic_t fscache_n_store_vmscan_busy;
50081-atomic_t fscache_n_store_vmscan_cancelled;
50082+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50083+atomic_unchecked_t fscache_n_store_vmscan_gone;
50084+atomic_unchecked_t fscache_n_store_vmscan_busy;
50085+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50086
50087-atomic_t fscache_n_marks;
50088-atomic_t fscache_n_uncaches;
50089+atomic_unchecked_t fscache_n_marks;
50090+atomic_unchecked_t fscache_n_uncaches;
50091
50092-atomic_t fscache_n_acquires;
50093-atomic_t fscache_n_acquires_null;
50094-atomic_t fscache_n_acquires_no_cache;
50095-atomic_t fscache_n_acquires_ok;
50096-atomic_t fscache_n_acquires_nobufs;
50097-atomic_t fscache_n_acquires_oom;
50098+atomic_unchecked_t fscache_n_acquires;
50099+atomic_unchecked_t fscache_n_acquires_null;
50100+atomic_unchecked_t fscache_n_acquires_no_cache;
50101+atomic_unchecked_t fscache_n_acquires_ok;
50102+atomic_unchecked_t fscache_n_acquires_nobufs;
50103+atomic_unchecked_t fscache_n_acquires_oom;
50104
50105-atomic_t fscache_n_updates;
50106-atomic_t fscache_n_updates_null;
50107-atomic_t fscache_n_updates_run;
50108+atomic_unchecked_t fscache_n_updates;
50109+atomic_unchecked_t fscache_n_updates_null;
50110+atomic_unchecked_t fscache_n_updates_run;
50111
50112-atomic_t fscache_n_relinquishes;
50113-atomic_t fscache_n_relinquishes_null;
50114-atomic_t fscache_n_relinquishes_waitcrt;
50115-atomic_t fscache_n_relinquishes_retire;
50116+atomic_unchecked_t fscache_n_relinquishes;
50117+atomic_unchecked_t fscache_n_relinquishes_null;
50118+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50119+atomic_unchecked_t fscache_n_relinquishes_retire;
50120
50121-atomic_t fscache_n_cookie_index;
50122-atomic_t fscache_n_cookie_data;
50123-atomic_t fscache_n_cookie_special;
50124+atomic_unchecked_t fscache_n_cookie_index;
50125+atomic_unchecked_t fscache_n_cookie_data;
50126+atomic_unchecked_t fscache_n_cookie_special;
50127
50128-atomic_t fscache_n_object_alloc;
50129-atomic_t fscache_n_object_no_alloc;
50130-atomic_t fscache_n_object_lookups;
50131-atomic_t fscache_n_object_lookups_negative;
50132-atomic_t fscache_n_object_lookups_positive;
50133-atomic_t fscache_n_object_lookups_timed_out;
50134-atomic_t fscache_n_object_created;
50135-atomic_t fscache_n_object_avail;
50136-atomic_t fscache_n_object_dead;
50137+atomic_unchecked_t fscache_n_object_alloc;
50138+atomic_unchecked_t fscache_n_object_no_alloc;
50139+atomic_unchecked_t fscache_n_object_lookups;
50140+atomic_unchecked_t fscache_n_object_lookups_negative;
50141+atomic_unchecked_t fscache_n_object_lookups_positive;
50142+atomic_unchecked_t fscache_n_object_lookups_timed_out;
50143+atomic_unchecked_t fscache_n_object_created;
50144+atomic_unchecked_t fscache_n_object_avail;
50145+atomic_unchecked_t fscache_n_object_dead;
50146
50147-atomic_t fscache_n_checkaux_none;
50148-atomic_t fscache_n_checkaux_okay;
50149-atomic_t fscache_n_checkaux_update;
50150-atomic_t fscache_n_checkaux_obsolete;
50151+atomic_unchecked_t fscache_n_checkaux_none;
50152+atomic_unchecked_t fscache_n_checkaux_okay;
50153+atomic_unchecked_t fscache_n_checkaux_update;
50154+atomic_unchecked_t fscache_n_checkaux_obsolete;
50155
50156 atomic_t fscache_n_cop_alloc_object;
50157 atomic_t fscache_n_cop_lookup_object;
50158@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
50159 seq_puts(m, "FS-Cache statistics\n");
50160
50161 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
50162- atomic_read(&fscache_n_cookie_index),
50163- atomic_read(&fscache_n_cookie_data),
50164- atomic_read(&fscache_n_cookie_special));
50165+ atomic_read_unchecked(&fscache_n_cookie_index),
50166+ atomic_read_unchecked(&fscache_n_cookie_data),
50167+ atomic_read_unchecked(&fscache_n_cookie_special));
50168
50169 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
50170- atomic_read(&fscache_n_object_alloc),
50171- atomic_read(&fscache_n_object_no_alloc),
50172- atomic_read(&fscache_n_object_avail),
50173- atomic_read(&fscache_n_object_dead));
50174+ atomic_read_unchecked(&fscache_n_object_alloc),
50175+ atomic_read_unchecked(&fscache_n_object_no_alloc),
50176+ atomic_read_unchecked(&fscache_n_object_avail),
50177+ atomic_read_unchecked(&fscache_n_object_dead));
50178 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
50179- atomic_read(&fscache_n_checkaux_none),
50180- atomic_read(&fscache_n_checkaux_okay),
50181- atomic_read(&fscache_n_checkaux_update),
50182- atomic_read(&fscache_n_checkaux_obsolete));
50183+ atomic_read_unchecked(&fscache_n_checkaux_none),
50184+ atomic_read_unchecked(&fscache_n_checkaux_okay),
50185+ atomic_read_unchecked(&fscache_n_checkaux_update),
50186+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
50187
50188 seq_printf(m, "Pages : mrk=%u unc=%u\n",
50189- atomic_read(&fscache_n_marks),
50190- atomic_read(&fscache_n_uncaches));
50191+ atomic_read_unchecked(&fscache_n_marks),
50192+ atomic_read_unchecked(&fscache_n_uncaches));
50193
50194 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
50195 " oom=%u\n",
50196- atomic_read(&fscache_n_acquires),
50197- atomic_read(&fscache_n_acquires_null),
50198- atomic_read(&fscache_n_acquires_no_cache),
50199- atomic_read(&fscache_n_acquires_ok),
50200- atomic_read(&fscache_n_acquires_nobufs),
50201- atomic_read(&fscache_n_acquires_oom));
50202+ atomic_read_unchecked(&fscache_n_acquires),
50203+ atomic_read_unchecked(&fscache_n_acquires_null),
50204+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
50205+ atomic_read_unchecked(&fscache_n_acquires_ok),
50206+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
50207+ atomic_read_unchecked(&fscache_n_acquires_oom));
50208
50209 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
50210- atomic_read(&fscache_n_object_lookups),
50211- atomic_read(&fscache_n_object_lookups_negative),
50212- atomic_read(&fscache_n_object_lookups_positive),
50213- atomic_read(&fscache_n_object_lookups_timed_out),
50214- atomic_read(&fscache_n_object_created));
50215+ atomic_read_unchecked(&fscache_n_object_lookups),
50216+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
50217+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
50218+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
50219+ atomic_read_unchecked(&fscache_n_object_created));
50220
50221 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
50222- atomic_read(&fscache_n_updates),
50223- atomic_read(&fscache_n_updates_null),
50224- atomic_read(&fscache_n_updates_run));
50225+ atomic_read_unchecked(&fscache_n_updates),
50226+ atomic_read_unchecked(&fscache_n_updates_null),
50227+ atomic_read_unchecked(&fscache_n_updates_run));
50228
50229 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
50230- atomic_read(&fscache_n_relinquishes),
50231- atomic_read(&fscache_n_relinquishes_null),
50232- atomic_read(&fscache_n_relinquishes_waitcrt),
50233- atomic_read(&fscache_n_relinquishes_retire));
50234+ atomic_read_unchecked(&fscache_n_relinquishes),
50235+ atomic_read_unchecked(&fscache_n_relinquishes_null),
50236+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
50237+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
50238
50239 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
50240- atomic_read(&fscache_n_attr_changed),
50241- atomic_read(&fscache_n_attr_changed_ok),
50242- atomic_read(&fscache_n_attr_changed_nobufs),
50243- atomic_read(&fscache_n_attr_changed_nomem),
50244- atomic_read(&fscache_n_attr_changed_calls));
50245+ atomic_read_unchecked(&fscache_n_attr_changed),
50246+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
50247+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
50248+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
50249+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
50250
50251 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
50252- atomic_read(&fscache_n_allocs),
50253- atomic_read(&fscache_n_allocs_ok),
50254- atomic_read(&fscache_n_allocs_wait),
50255- atomic_read(&fscache_n_allocs_nobufs),
50256- atomic_read(&fscache_n_allocs_intr));
50257+ atomic_read_unchecked(&fscache_n_allocs),
50258+ atomic_read_unchecked(&fscache_n_allocs_ok),
50259+ atomic_read_unchecked(&fscache_n_allocs_wait),
50260+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
50261+ atomic_read_unchecked(&fscache_n_allocs_intr));
50262 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
50263- atomic_read(&fscache_n_alloc_ops),
50264- atomic_read(&fscache_n_alloc_op_waits),
50265- atomic_read(&fscache_n_allocs_object_dead));
50266+ atomic_read_unchecked(&fscache_n_alloc_ops),
50267+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
50268+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
50269
50270 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
50271 " int=%u oom=%u\n",
50272- atomic_read(&fscache_n_retrievals),
50273- atomic_read(&fscache_n_retrievals_ok),
50274- atomic_read(&fscache_n_retrievals_wait),
50275- atomic_read(&fscache_n_retrievals_nodata),
50276- atomic_read(&fscache_n_retrievals_nobufs),
50277- atomic_read(&fscache_n_retrievals_intr),
50278- atomic_read(&fscache_n_retrievals_nomem));
50279+ atomic_read_unchecked(&fscache_n_retrievals),
50280+ atomic_read_unchecked(&fscache_n_retrievals_ok),
50281+ atomic_read_unchecked(&fscache_n_retrievals_wait),
50282+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
50283+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
50284+ atomic_read_unchecked(&fscache_n_retrievals_intr),
50285+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
50286 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
50287- atomic_read(&fscache_n_retrieval_ops),
50288- atomic_read(&fscache_n_retrieval_op_waits),
50289- atomic_read(&fscache_n_retrievals_object_dead));
50290+ atomic_read_unchecked(&fscache_n_retrieval_ops),
50291+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
50292+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
50293
50294 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
50295- atomic_read(&fscache_n_stores),
50296- atomic_read(&fscache_n_stores_ok),
50297- atomic_read(&fscache_n_stores_again),
50298- atomic_read(&fscache_n_stores_nobufs),
50299- atomic_read(&fscache_n_stores_oom));
50300+ atomic_read_unchecked(&fscache_n_stores),
50301+ atomic_read_unchecked(&fscache_n_stores_ok),
50302+ atomic_read_unchecked(&fscache_n_stores_again),
50303+ atomic_read_unchecked(&fscache_n_stores_nobufs),
50304+ atomic_read_unchecked(&fscache_n_stores_oom));
50305 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
50306- atomic_read(&fscache_n_store_ops),
50307- atomic_read(&fscache_n_store_calls),
50308- atomic_read(&fscache_n_store_pages),
50309- atomic_read(&fscache_n_store_radix_deletes),
50310- atomic_read(&fscache_n_store_pages_over_limit));
50311+ atomic_read_unchecked(&fscache_n_store_ops),
50312+ atomic_read_unchecked(&fscache_n_store_calls),
50313+ atomic_read_unchecked(&fscache_n_store_pages),
50314+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
50315+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
50316
50317 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
50318- atomic_read(&fscache_n_store_vmscan_not_storing),
50319- atomic_read(&fscache_n_store_vmscan_gone),
50320- atomic_read(&fscache_n_store_vmscan_busy),
50321- atomic_read(&fscache_n_store_vmscan_cancelled));
50322+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
50323+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
50324+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
50325+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
50326
50327 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
50328- atomic_read(&fscache_n_op_pend),
50329- atomic_read(&fscache_n_op_run),
50330- atomic_read(&fscache_n_op_enqueue),
50331- atomic_read(&fscache_n_op_cancelled),
50332- atomic_read(&fscache_n_op_rejected));
50333+ atomic_read_unchecked(&fscache_n_op_pend),
50334+ atomic_read_unchecked(&fscache_n_op_run),
50335+ atomic_read_unchecked(&fscache_n_op_enqueue),
50336+ atomic_read_unchecked(&fscache_n_op_cancelled),
50337+ atomic_read_unchecked(&fscache_n_op_rejected));
50338 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
50339- atomic_read(&fscache_n_op_deferred_release),
50340- atomic_read(&fscache_n_op_release),
50341- atomic_read(&fscache_n_op_gc));
50342+ atomic_read_unchecked(&fscache_n_op_deferred_release),
50343+ atomic_read_unchecked(&fscache_n_op_release),
50344+ atomic_read_unchecked(&fscache_n_op_gc));
50345
50346 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
50347 atomic_read(&fscache_n_cop_alloc_object),
50348diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50349index de792dc..448b532 100644
50350--- a/fs/fuse/cuse.c
50351+++ b/fs/fuse/cuse.c
50352@@ -576,10 +576,12 @@ static int __init cuse_init(void)
50353 INIT_LIST_HEAD(&cuse_conntbl[i]);
50354
50355 /* inherit and extend fuse_dev_operations */
50356- cuse_channel_fops = fuse_dev_operations;
50357- cuse_channel_fops.owner = THIS_MODULE;
50358- cuse_channel_fops.open = cuse_channel_open;
50359- cuse_channel_fops.release = cuse_channel_release;
50360+ pax_open_kernel();
50361+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50362+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50363+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50364+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50365+ pax_close_kernel();
50366
50367 cuse_class = class_create(THIS_MODULE, "cuse");
50368 if (IS_ERR(cuse_class))
50369diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50370index 1facb39..7f48557 100644
50371--- a/fs/fuse/dev.c
50372+++ b/fs/fuse/dev.c
50373@@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50374 {
50375 struct fuse_notify_inval_entry_out outarg;
50376 int err = -EINVAL;
50377- char buf[FUSE_NAME_MAX+1];
50378+ char *buf = NULL;
50379 struct qstr name;
50380
50381 if (size < sizeof(outarg))
50382@@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50383 if (outarg.namelen > FUSE_NAME_MAX)
50384 goto err;
50385
50386+ err = -ENOMEM;
50387+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
50388+ if (!buf)
50389+ goto err;
50390+
50391 err = -EINVAL;
50392 if (size != sizeof(outarg) + outarg.namelen + 1)
50393 goto err;
50394@@ -914,17 +919,15 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50395
50396 down_read(&fc->killsb);
50397 err = -ENOENT;
50398- if (!fc->sb)
50399- goto err_unlock;
50400-
50401- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50402-
50403-err_unlock:
50404+ if (fc->sb)
50405+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50406 up_read(&fc->killsb);
50407+ kfree(buf);
50408 return err;
50409
50410 err:
50411 fuse_copy_finish(cs);
50412+ kfree(buf);
50413 return err;
50414 }
50415
50416diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50417index 4787ae6..73efff7 100644
50418--- a/fs/fuse/dir.c
50419+++ b/fs/fuse/dir.c
50420@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *dentry)
50421 return link;
50422 }
50423
50424-static void free_link(char *link)
50425+static void free_link(const char *link)
50426 {
50427 if (!IS_ERR(link))
50428 free_page((unsigned long) link);
50429diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
50430index 247436c..e650ccb 100644
50431--- a/fs/gfs2/ops_inode.c
50432+++ b/fs/gfs2/ops_inode.c
50433@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
50434 unsigned int x;
50435 int error;
50436
50437+ pax_track_stack();
50438+
50439 if (ndentry->d_inode) {
50440 nip = GFS2_I(ndentry->d_inode);
50441 if (ip == nip)
50442diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
50443index 4463297..4fed53b 100644
50444--- a/fs/gfs2/sys.c
50445+++ b/fs/gfs2/sys.c
50446@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
50447 return a->store ? a->store(sdp, buf, len) : len;
50448 }
50449
50450-static struct sysfs_ops gfs2_attr_ops = {
50451+static const struct sysfs_ops gfs2_attr_ops = {
50452 .show = gfs2_attr_show,
50453 .store = gfs2_attr_store,
50454 };
50455@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
50456 return 0;
50457 }
50458
50459-static struct kset_uevent_ops gfs2_uevent_ops = {
50460+static const struct kset_uevent_ops gfs2_uevent_ops = {
50461 .uevent = gfs2_uevent,
50462 };
50463
50464diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
50465index f6874ac..7cd98a8 100644
50466--- a/fs/hfsplus/catalog.c
50467+++ b/fs/hfsplus/catalog.c
50468@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
50469 int err;
50470 u16 type;
50471
50472+ pax_track_stack();
50473+
50474 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
50475 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
50476 if (err)
50477@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino
50478 int entry_size;
50479 int err;
50480
50481+ pax_track_stack();
50482+
50483 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
50484 sb = dir->i_sb;
50485 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
50486@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
50487 int entry_size, type;
50488 int err = 0;
50489
50490+ pax_track_stack();
50491+
50492 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
50493 dst_dir->i_ino, dst_name->name);
50494 sb = src_dir->i_sb;
50495diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
50496index 5f40236..dac3421 100644
50497--- a/fs/hfsplus/dir.c
50498+++ b/fs/hfsplus/dir.c
50499@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
50500 struct hfsplus_readdir_data *rd;
50501 u16 type;
50502
50503+ pax_track_stack();
50504+
50505 if (filp->f_pos >= inode->i_size)
50506 return 0;
50507
50508diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
50509index 1bcf597..905a251 100644
50510--- a/fs/hfsplus/inode.c
50511+++ b/fs/hfsplus/inode.c
50512@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
50513 int res = 0;
50514 u16 type;
50515
50516+ pax_track_stack();
50517+
50518 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
50519
50520 HFSPLUS_I(inode).dev = 0;
50521@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
50522 struct hfs_find_data fd;
50523 hfsplus_cat_entry entry;
50524
50525+ pax_track_stack();
50526+
50527 if (HFSPLUS_IS_RSRC(inode))
50528 main_inode = HFSPLUS_I(inode).rsrc_inode;
50529
50530diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
50531index f457d2c..7ef4ad5 100644
50532--- a/fs/hfsplus/ioctl.c
50533+++ b/fs/hfsplus/ioctl.c
50534@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
50535 struct hfsplus_cat_file *file;
50536 int res;
50537
50538+ pax_track_stack();
50539+
50540 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50541 return -EOPNOTSUPP;
50542
50543@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
50544 struct hfsplus_cat_file *file;
50545 ssize_t res = 0;
50546
50547+ pax_track_stack();
50548+
50549 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50550 return -EOPNOTSUPP;
50551
50552diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
50553index 43022f3..7298079 100644
50554--- a/fs/hfsplus/super.c
50555+++ b/fs/hfsplus/super.c
50556@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
50557 struct nls_table *nls = NULL;
50558 int err = -EINVAL;
50559
50560+ pax_track_stack();
50561+
50562 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
50563 if (!sbi)
50564 return -ENOMEM;
50565diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50566index 87a1258..5694d91 100644
50567--- a/fs/hugetlbfs/inode.c
50568+++ b/fs/hugetlbfs/inode.c
50569@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50570 .kill_sb = kill_litter_super,
50571 };
50572
50573-static struct vfsmount *hugetlbfs_vfsmount;
50574+struct vfsmount *hugetlbfs_vfsmount;
50575
50576 static int can_do_hugetlb_shm(void)
50577 {
50578diff --git a/fs/ioctl.c b/fs/ioctl.c
50579index 6c75110..19d2c3c 100644
50580--- a/fs/ioctl.c
50581+++ b/fs/ioctl.c
50582@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
50583 u64 phys, u64 len, u32 flags)
50584 {
50585 struct fiemap_extent extent;
50586- struct fiemap_extent *dest = fieinfo->fi_extents_start;
50587+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
50588
50589 /* only count the extents */
50590 if (fieinfo->fi_extents_max == 0) {
50591@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50592
50593 fieinfo.fi_flags = fiemap.fm_flags;
50594 fieinfo.fi_extents_max = fiemap.fm_extent_count;
50595- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
50596+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
50597
50598 if (fiemap.fm_extent_count != 0 &&
50599 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
50600@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50601 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
50602 fiemap.fm_flags = fieinfo.fi_flags;
50603 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
50604- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
50605+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
50606 error = -EFAULT;
50607
50608 return error;
50609diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
50610index b0435dd..81ee0be 100644
50611--- a/fs/jbd/checkpoint.c
50612+++ b/fs/jbd/checkpoint.c
50613@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal)
50614 tid_t this_tid;
50615 int result;
50616
50617+ pax_track_stack();
50618+
50619 jbd_debug(1, "Start checkpoint\n");
50620
50621 /*
50622diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
50623index 546d153..736896c 100644
50624--- a/fs/jffs2/compr_rtime.c
50625+++ b/fs/jffs2/compr_rtime.c
50626@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
50627 int outpos = 0;
50628 int pos=0;
50629
50630+ pax_track_stack();
50631+
50632 memset(positions,0,sizeof(positions));
50633
50634 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
50635@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
50636 int outpos = 0;
50637 int pos=0;
50638
50639+ pax_track_stack();
50640+
50641 memset(positions,0,sizeof(positions));
50642
50643 while (outpos<destlen) {
50644diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
50645index 170d289..3254b98 100644
50646--- a/fs/jffs2/compr_rubin.c
50647+++ b/fs/jffs2/compr_rubin.c
50648@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
50649 int ret;
50650 uint32_t mysrclen, mydstlen;
50651
50652+ pax_track_stack();
50653+
50654 mysrclen = *sourcelen;
50655 mydstlen = *dstlen - 8;
50656
50657diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50658index b47679b..00d65d3 100644
50659--- a/fs/jffs2/erase.c
50660+++ b/fs/jffs2/erase.c
50661@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50662 struct jffs2_unknown_node marker = {
50663 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50664 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50665- .totlen = cpu_to_je32(c->cleanmarker_size)
50666+ .totlen = cpu_to_je32(c->cleanmarker_size),
50667+ .hdr_crc = cpu_to_je32(0)
50668 };
50669
50670 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50671diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50672index 5ef7bac..4fd1e3c 100644
50673--- a/fs/jffs2/wbuf.c
50674+++ b/fs/jffs2/wbuf.c
50675@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50676 {
50677 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50678 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50679- .totlen = constant_cpu_to_je32(8)
50680+ .totlen = constant_cpu_to_je32(8),
50681+ .hdr_crc = constant_cpu_to_je32(0)
50682 };
50683
50684 /*
50685diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
50686index 082e844..52012a1 100644
50687--- a/fs/jffs2/xattr.c
50688+++ b/fs/jffs2/xattr.c
50689@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
50690
50691 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
50692
50693+ pax_track_stack();
50694+
50695 /* Phase.1 : Merge same xref */
50696 for (i=0; i < XREF_TMPHASH_SIZE; i++)
50697 xref_tmphash[i] = NULL;
50698diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50699index 2234c73..f6e6e6b 100644
50700--- a/fs/jfs/super.c
50701+++ b/fs/jfs/super.c
50702@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
50703
50704 jfs_inode_cachep =
50705 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50706- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50707+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50708 init_once);
50709 if (jfs_inode_cachep == NULL)
50710 return -ENOMEM;
50711diff --git a/fs/libfs.c b/fs/libfs.c
50712index ba36e93..3153fce 100644
50713--- a/fs/libfs.c
50714+++ b/fs/libfs.c
50715@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50716
50717 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50718 struct dentry *next;
50719+ char d_name[sizeof(next->d_iname)];
50720+ const unsigned char *name;
50721+
50722 next = list_entry(p, struct dentry, d_u.d_child);
50723 if (d_unhashed(next) || !next->d_inode)
50724 continue;
50725
50726 spin_unlock(&dcache_lock);
50727- if (filldir(dirent, next->d_name.name,
50728+ name = next->d_name.name;
50729+ if (name == next->d_iname) {
50730+ memcpy(d_name, name, next->d_name.len);
50731+ name = d_name;
50732+ }
50733+ if (filldir(dirent, name,
50734 next->d_name.len, filp->f_pos,
50735 next->d_inode->i_ino,
50736 dt_type(next->d_inode)) < 0)
50737diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50738index c325a83..d15b07b 100644
50739--- a/fs/lockd/clntproc.c
50740+++ b/fs/lockd/clntproc.c
50741@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50742 /*
50743 * Cookie counter for NLM requests
50744 */
50745-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50746+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50747
50748 void nlmclnt_next_cookie(struct nlm_cookie *c)
50749 {
50750- u32 cookie = atomic_inc_return(&nlm_cookie);
50751+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50752
50753 memcpy(c->data, &cookie, 4);
50754 c->len=4;
50755@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
50756 struct nlm_rqst reqst, *req;
50757 int status;
50758
50759+ pax_track_stack();
50760+
50761 req = &reqst;
50762 memset(req, 0, sizeof(*req));
50763 locks_init_lock(&req->a_args.lock.fl);
50764diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
50765index 1a54ae1..6a16c27 100644
50766--- a/fs/lockd/svc.c
50767+++ b/fs/lockd/svc.c
50768@@ -43,7 +43,7 @@
50769
50770 static struct svc_program nlmsvc_program;
50771
50772-struct nlmsvc_binding * nlmsvc_ops;
50773+const struct nlmsvc_binding * nlmsvc_ops;
50774 EXPORT_SYMBOL_GPL(nlmsvc_ops);
50775
50776 static DEFINE_MUTEX(nlmsvc_mutex);
50777diff --git a/fs/locks.c b/fs/locks.c
50778index a8794f2..4041e55 100644
50779--- a/fs/locks.c
50780+++ b/fs/locks.c
50781@@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
50782
50783 static struct kmem_cache *filelock_cache __read_mostly;
50784
50785+static void locks_init_lock_always(struct file_lock *fl)
50786+{
50787+ fl->fl_next = NULL;
50788+ fl->fl_fasync = NULL;
50789+ fl->fl_owner = NULL;
50790+ fl->fl_pid = 0;
50791+ fl->fl_nspid = NULL;
50792+ fl->fl_file = NULL;
50793+ fl->fl_flags = 0;
50794+ fl->fl_type = 0;
50795+ fl->fl_start = fl->fl_end = 0;
50796+}
50797+
50798 /* Allocate an empty lock structure. */
50799 static struct file_lock *locks_alloc_lock(void)
50800 {
50801- return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
50802+ struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
50803+
50804+ if (fl)
50805+ locks_init_lock_always(fl);
50806+
50807+ return fl;
50808 }
50809
50810 void locks_release_private(struct file_lock *fl)
50811@@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *fl)
50812 INIT_LIST_HEAD(&fl->fl_link);
50813 INIT_LIST_HEAD(&fl->fl_block);
50814 init_waitqueue_head(&fl->fl_wait);
50815- fl->fl_next = NULL;
50816- fl->fl_fasync = NULL;
50817- fl->fl_owner = NULL;
50818- fl->fl_pid = 0;
50819- fl->fl_nspid = NULL;
50820- fl->fl_file = NULL;
50821- fl->fl_flags = 0;
50822- fl->fl_type = 0;
50823- fl->fl_start = fl->fl_end = 0;
50824 fl->fl_ops = NULL;
50825 fl->fl_lmops = NULL;
50826+ locks_init_lock_always(fl);
50827 }
50828
50829 EXPORT_SYMBOL(locks_init_lock);
50830@@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *filp)
50831 return;
50832
50833 if (filp->f_op && filp->f_op->flock) {
50834- struct file_lock fl = {
50835+ struct file_lock flock = {
50836 .fl_pid = current->tgid,
50837 .fl_file = filp,
50838 .fl_flags = FL_FLOCK,
50839 .fl_type = F_UNLCK,
50840 .fl_end = OFFSET_MAX,
50841 };
50842- filp->f_op->flock(filp, F_SETLKW, &fl);
50843- if (fl.fl_ops && fl.fl_ops->fl_release_private)
50844- fl.fl_ops->fl_release_private(&fl);
50845+ filp->f_op->flock(filp, F_SETLKW, &flock);
50846+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
50847+ flock.fl_ops->fl_release_private(&flock);
50848 }
50849
50850 lock_kernel();
50851diff --git a/fs/mbcache.c b/fs/mbcache.c
50852index ec88ff3..b843a82 100644
50853--- a/fs/mbcache.c
50854+++ b/fs/mbcache.c
50855@@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct mb_cache_op *cache_op,
50856 if (!cache)
50857 goto fail;
50858 cache->c_name = name;
50859- cache->c_op.free = NULL;
50860+ *(void **)&cache->c_op.free = NULL;
50861 if (cache_op)
50862- cache->c_op.free = cache_op->free;
50863+ *(void **)&cache->c_op.free = cache_op->free;
50864 atomic_set(&cache->c_entry_count, 0);
50865 cache->c_bucket_bits = bucket_bits;
50866 #ifdef MB_CACHE_INDEXES_COUNT
50867diff --git a/fs/namei.c b/fs/namei.c
50868index b0afbd4..8d065a1 100644
50869--- a/fs/namei.c
50870+++ b/fs/namei.c
50871@@ -224,6 +224,14 @@ int generic_permission(struct inode *inode, int mask,
50872 return ret;
50873
50874 /*
50875+ * Searching includes executable on directories, else just read.
50876+ */
50877+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50878+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
50879+ if (capable(CAP_DAC_READ_SEARCH))
50880+ return 0;
50881+
50882+ /*
50883 * Read/write DACs are always overridable.
50884 * Executable DACs are overridable if at least one exec bit is set.
50885 */
50886@@ -231,14 +239,6 @@ int generic_permission(struct inode *inode, int mask,
50887 if (capable(CAP_DAC_OVERRIDE))
50888 return 0;
50889
50890- /*
50891- * Searching includes executable on directories, else just read.
50892- */
50893- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50894- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
50895- if (capable(CAP_DAC_READ_SEARCH))
50896- return 0;
50897-
50898 return -EACCES;
50899 }
50900
50901@@ -458,7 +458,8 @@ static int exec_permission_lite(struct inode *inode)
50902 if (!ret)
50903 goto ok;
50904
50905- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
50906+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
50907+ capable(CAP_DAC_OVERRIDE))
50908 goto ok;
50909
50910 return ret;
50911@@ -638,7 +639,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
50912 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
50913 error = PTR_ERR(cookie);
50914 if (!IS_ERR(cookie)) {
50915- char *s = nd_get_link(nd);
50916+ const char *s = nd_get_link(nd);
50917 error = 0;
50918 if (s)
50919 error = __vfs_follow_link(nd, s);
50920@@ -669,6 +670,13 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
50921 err = security_inode_follow_link(path->dentry, nd);
50922 if (err)
50923 goto loop;
50924+
50925+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
50926+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
50927+ err = -EACCES;
50928+ goto loop;
50929+ }
50930+
50931 current->link_count++;
50932 current->total_link_count++;
50933 nd->depth++;
50934@@ -1016,11 +1024,19 @@ return_reval:
50935 break;
50936 }
50937 return_base:
50938+ if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT)) &&
50939+ !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50940+ path_put(&nd->path);
50941+ return -ENOENT;
50942+ }
50943 return 0;
50944 out_dput:
50945 path_put_conditional(&next, nd);
50946 break;
50947 }
50948+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
50949+ err = -ENOENT;
50950+
50951 path_put(&nd->path);
50952 return_err:
50953 return err;
50954@@ -1091,13 +1107,20 @@ static int do_path_lookup(int dfd, const char *name,
50955 int retval = path_init(dfd, name, flags, nd);
50956 if (!retval)
50957 retval = path_walk(name, nd);
50958- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
50959- nd->path.dentry->d_inode))
50960- audit_inode(name, nd->path.dentry);
50961+
50962+ if (likely(!retval)) {
50963+ if (nd->path.dentry && nd->path.dentry->d_inode) {
50964+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50965+ retval = -ENOENT;
50966+ if (!audit_dummy_context())
50967+ audit_inode(name, nd->path.dentry);
50968+ }
50969+ }
50970 if (nd->root.mnt) {
50971 path_put(&nd->root);
50972 nd->root.mnt = NULL;
50973 }
50974+
50975 return retval;
50976 }
50977
50978@@ -1576,6 +1599,20 @@ int may_open(struct path *path, int acc_mode, int flag)
50979 if (error)
50980 goto err_out;
50981
50982+
50983+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
50984+ error = -EPERM;
50985+ goto err_out;
50986+ }
50987+ if (gr_handle_rawio(inode)) {
50988+ error = -EPERM;
50989+ goto err_out;
50990+ }
50991+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
50992+ error = -EACCES;
50993+ goto err_out;
50994+ }
50995+
50996 if (flag & O_TRUNC) {
50997 error = get_write_access(inode);
50998 if (error)
50999@@ -1620,6 +1657,17 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51000 {
51001 int error;
51002 struct dentry *dir = nd->path.dentry;
51003+ int acc_mode = ACC_MODE(flag);
51004+
51005+ if (flag & O_TRUNC)
51006+ acc_mode |= MAY_WRITE;
51007+ if (flag & O_APPEND)
51008+ acc_mode |= MAY_APPEND;
51009+
51010+ if (!gr_acl_handle_creat(path->dentry, dir, nd->path.mnt, flag, acc_mode, mode)) {
51011+ error = -EACCES;
51012+ goto out_unlock;
51013+ }
51014
51015 if (!IS_POSIXACL(dir->d_inode))
51016 mode &= ~current_umask();
51017@@ -1627,6 +1675,8 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51018 if (error)
51019 goto out_unlock;
51020 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
51021+ if (!error)
51022+ gr_handle_create(path->dentry, nd->path.mnt);
51023 out_unlock:
51024 mutex_unlock(&dir->d_inode->i_mutex);
51025 dput(nd->path.dentry);
51026@@ -1709,6 +1759,22 @@ struct file *do_filp_open(int dfd, const char *pathname,
51027 &nd, flag);
51028 if (error)
51029 return ERR_PTR(error);
51030+
51031+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
51032+ error = -EPERM;
51033+ goto exit;
51034+ }
51035+
51036+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
51037+ error = -EPERM;
51038+ goto exit;
51039+ }
51040+
51041+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, acc_mode)) {
51042+ error = -EACCES;
51043+ goto exit;
51044+ }
51045+
51046 goto ok;
51047 }
51048
51049@@ -1795,6 +1861,19 @@ do_last:
51050 /*
51051 * It already exists.
51052 */
51053+
51054+ if (!gr_acl_handle_hidden_file(path.dentry, path.mnt)) {
51055+ error = -ENOENT;
51056+ goto exit_mutex_unlock;
51057+ }
51058+
51059+ /* only check if O_CREAT is specified, all other checks need
51060+ to go into may_open */
51061+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
51062+ error = -EACCES;
51063+ goto exit_mutex_unlock;
51064+ }
51065+
51066 mutex_unlock(&dir->d_inode->i_mutex);
51067 audit_inode(pathname, path.dentry);
51068
51069@@ -1887,6 +1966,13 @@ do_link:
51070 error = security_inode_follow_link(path.dentry, &nd);
51071 if (error)
51072 goto exit_dput;
51073+
51074+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
51075+ path.dentry, nd.path.mnt)) {
51076+ error = -EACCES;
51077+ goto exit_dput;
51078+ }
51079+
51080 error = __do_follow_link(&path, &nd);
51081 if (error) {
51082 /* Does someone understand code flow here? Or it is only
51083@@ -1984,6 +2070,10 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
51084 }
51085 return dentry;
51086 eexist:
51087+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
51088+ dput(dentry);
51089+ return ERR_PTR(-ENOENT);
51090+ }
51091 dput(dentry);
51092 dentry = ERR_PTR(-EEXIST);
51093 fail:
51094@@ -2061,6 +2151,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51095 error = may_mknod(mode);
51096 if (error)
51097 goto out_dput;
51098+
51099+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
51100+ error = -EPERM;
51101+ goto out_dput;
51102+ }
51103+
51104+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
51105+ error = -EACCES;
51106+ goto out_dput;
51107+ }
51108+
51109 error = mnt_want_write(nd.path.mnt);
51110 if (error)
51111 goto out_dput;
51112@@ -2081,6 +2182,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51113 }
51114 out_drop_write:
51115 mnt_drop_write(nd.path.mnt);
51116+
51117+ if (!error)
51118+ gr_handle_create(dentry, nd.path.mnt);
51119 out_dput:
51120 dput(dentry);
51121 out_unlock:
51122@@ -2134,6 +2238,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51123 if (IS_ERR(dentry))
51124 goto out_unlock;
51125
51126+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
51127+ error = -EACCES;
51128+ goto out_dput;
51129+ }
51130+
51131 if (!IS_POSIXACL(nd.path.dentry->d_inode))
51132 mode &= ~current_umask();
51133 error = mnt_want_write(nd.path.mnt);
51134@@ -2145,6 +2254,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51135 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
51136 out_drop_write:
51137 mnt_drop_write(nd.path.mnt);
51138+
51139+ if (!error)
51140+ gr_handle_create(dentry, nd.path.mnt);
51141+
51142 out_dput:
51143 dput(dentry);
51144 out_unlock:
51145@@ -2226,6 +2339,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51146 char * name;
51147 struct dentry *dentry;
51148 struct nameidata nd;
51149+ ino_t saved_ino = 0;
51150+ dev_t saved_dev = 0;
51151
51152 error = user_path_parent(dfd, pathname, &nd, &name);
51153 if (error)
51154@@ -2250,6 +2365,17 @@ static long do_rmdir(int dfd, const char __user *pathname)
51155 error = PTR_ERR(dentry);
51156 if (IS_ERR(dentry))
51157 goto exit2;
51158+
51159+ if (dentry->d_inode != NULL) {
51160+ saved_ino = dentry->d_inode->i_ino;
51161+ saved_dev = gr_get_dev_from_dentry(dentry);
51162+
51163+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
51164+ error = -EACCES;
51165+ goto exit3;
51166+ }
51167+ }
51168+
51169 error = mnt_want_write(nd.path.mnt);
51170 if (error)
51171 goto exit3;
51172@@ -2257,6 +2383,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51173 if (error)
51174 goto exit4;
51175 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
51176+ if (!error && (saved_dev || saved_ino))
51177+ gr_handle_delete(saved_ino, saved_dev);
51178 exit4:
51179 mnt_drop_write(nd.path.mnt);
51180 exit3:
51181@@ -2318,6 +2446,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51182 struct dentry *dentry;
51183 struct nameidata nd;
51184 struct inode *inode = NULL;
51185+ ino_t saved_ino = 0;
51186+ dev_t saved_dev = 0;
51187
51188 error = user_path_parent(dfd, pathname, &nd, &name);
51189 if (error)
51190@@ -2337,8 +2467,19 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51191 if (nd.last.name[nd.last.len])
51192 goto slashes;
51193 inode = dentry->d_inode;
51194- if (inode)
51195+ if (inode) {
51196+ if (inode->i_nlink <= 1) {
51197+ saved_ino = inode->i_ino;
51198+ saved_dev = gr_get_dev_from_dentry(dentry);
51199+ }
51200+
51201 atomic_inc(&inode->i_count);
51202+
51203+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
51204+ error = -EACCES;
51205+ goto exit2;
51206+ }
51207+ }
51208 error = mnt_want_write(nd.path.mnt);
51209 if (error)
51210 goto exit2;
51211@@ -2346,6 +2487,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51212 if (error)
51213 goto exit3;
51214 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
51215+ if (!error && (saved_ino || saved_dev))
51216+ gr_handle_delete(saved_ino, saved_dev);
51217 exit3:
51218 mnt_drop_write(nd.path.mnt);
51219 exit2:
51220@@ -2424,6 +2567,11 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51221 if (IS_ERR(dentry))
51222 goto out_unlock;
51223
51224+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
51225+ error = -EACCES;
51226+ goto out_dput;
51227+ }
51228+
51229 error = mnt_want_write(nd.path.mnt);
51230 if (error)
51231 goto out_dput;
51232@@ -2431,6 +2579,8 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51233 if (error)
51234 goto out_drop_write;
51235 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
51236+ if (!error)
51237+ gr_handle_create(dentry, nd.path.mnt);
51238 out_drop_write:
51239 mnt_drop_write(nd.path.mnt);
51240 out_dput:
51241@@ -2524,6 +2674,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51242 error = PTR_ERR(new_dentry);
51243 if (IS_ERR(new_dentry))
51244 goto out_unlock;
51245+
51246+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
51247+ old_path.dentry->d_inode,
51248+ old_path.dentry->d_inode->i_mode, to)) {
51249+ error = -EACCES;
51250+ goto out_dput;
51251+ }
51252+
51253+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
51254+ old_path.dentry, old_path.mnt, to)) {
51255+ error = -EACCES;
51256+ goto out_dput;
51257+ }
51258+
51259 error = mnt_want_write(nd.path.mnt);
51260 if (error)
51261 goto out_dput;
51262@@ -2531,6 +2695,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51263 if (error)
51264 goto out_drop_write;
51265 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
51266+ if (!error)
51267+ gr_handle_create(new_dentry, nd.path.mnt);
51268 out_drop_write:
51269 mnt_drop_write(nd.path.mnt);
51270 out_dput:
51271@@ -2708,6 +2874,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51272 char *to;
51273 int error;
51274
51275+ pax_track_stack();
51276+
51277 error = user_path_parent(olddfd, oldname, &oldnd, &from);
51278 if (error)
51279 goto exit;
51280@@ -2764,6 +2932,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51281 if (new_dentry == trap)
51282 goto exit5;
51283
51284+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
51285+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
51286+ to);
51287+ if (error)
51288+ goto exit5;
51289+
51290 error = mnt_want_write(oldnd.path.mnt);
51291 if (error)
51292 goto exit5;
51293@@ -2773,6 +2947,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51294 goto exit6;
51295 error = vfs_rename(old_dir->d_inode, old_dentry,
51296 new_dir->d_inode, new_dentry);
51297+ if (!error)
51298+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
51299+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
51300 exit6:
51301 mnt_drop_write(oldnd.path.mnt);
51302 exit5:
51303@@ -2798,6 +2975,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
51304
51305 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
51306 {
51307+ char tmpbuf[64];
51308+ const char *newlink;
51309 int len;
51310
51311 len = PTR_ERR(link);
51312@@ -2807,7 +2986,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
51313 len = strlen(link);
51314 if (len > (unsigned) buflen)
51315 len = buflen;
51316- if (copy_to_user(buffer, link, len))
51317+
51318+ if (len < sizeof(tmpbuf)) {
51319+ memcpy(tmpbuf, link, len);
51320+ newlink = tmpbuf;
51321+ } else
51322+ newlink = link;
51323+
51324+ if (copy_to_user(buffer, newlink, len))
51325 len = -EFAULT;
51326 out:
51327 return len;
51328diff --git a/fs/namespace.c b/fs/namespace.c
51329index 2beb0fb..11a95a5 100644
51330--- a/fs/namespace.c
51331+++ b/fs/namespace.c
51332@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51333 if (!(sb->s_flags & MS_RDONLY))
51334 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
51335 up_write(&sb->s_umount);
51336+
51337+ gr_log_remount(mnt->mnt_devname, retval);
51338+
51339 return retval;
51340 }
51341
51342@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51343 security_sb_umount_busy(mnt);
51344 up_write(&namespace_sem);
51345 release_mounts(&umount_list);
51346+
51347+ gr_log_unmount(mnt->mnt_devname, retval);
51348+
51349 return retval;
51350 }
51351
51352@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51353 if (retval)
51354 goto dput_out;
51355
51356+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
51357+ retval = -EPERM;
51358+ goto dput_out;
51359+ }
51360+
51361+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
51362+ retval = -EPERM;
51363+ goto dput_out;
51364+ }
51365+
51366 if (flags & MS_REMOUNT)
51367 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
51368 data_page);
51369@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51370 dev_name, data_page);
51371 dput_out:
51372 path_put(&path);
51373+
51374+ gr_log_mount(dev_name, dir_name, retval);
51375+
51376 return retval;
51377 }
51378
51379@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
51380 goto out1;
51381 }
51382
51383+ if (gr_handle_chroot_pivot()) {
51384+ error = -EPERM;
51385+ path_put(&old);
51386+ goto out1;
51387+ }
51388+
51389 read_lock(&current->fs->lock);
51390 root = current->fs->root;
51391 path_get(&current->fs->root);
51392diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
51393index b8b5b30..2bd9ccb 100644
51394--- a/fs/ncpfs/dir.c
51395+++ b/fs/ncpfs/dir.c
51396@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *dentry)
51397 int res, val = 0, len;
51398 __u8 __name[NCP_MAXPATHLEN + 1];
51399
51400+ pax_track_stack();
51401+
51402 parent = dget_parent(dentry);
51403 dir = parent->d_inode;
51404
51405@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
51406 int error, res, len;
51407 __u8 __name[NCP_MAXPATHLEN + 1];
51408
51409+ pax_track_stack();
51410+
51411 lock_kernel();
51412 error = -EIO;
51413 if (!ncp_conn_valid(server))
51414@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
51415 int error, result, len;
51416 int opmode;
51417 __u8 __name[NCP_MAXPATHLEN + 1];
51418-
51419+
51420 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
51421 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
51422
51423+ pax_track_stack();
51424+
51425 error = -EIO;
51426 lock_kernel();
51427 if (!ncp_conn_valid(server))
51428@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51429 int error, len;
51430 __u8 __name[NCP_MAXPATHLEN + 1];
51431
51432+ pax_track_stack();
51433+
51434 DPRINTK("ncp_mkdir: making %s/%s\n",
51435 dentry->d_parent->d_name.name, dentry->d_name.name);
51436
51437@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51438 if (!ncp_conn_valid(server))
51439 goto out;
51440
51441+ pax_track_stack();
51442+
51443 ncp_age_dentry(server, dentry);
51444 len = sizeof(__name);
51445 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
51446@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
51447 int old_len, new_len;
51448 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
51449
51450+ pax_track_stack();
51451+
51452 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
51453 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
51454 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
51455diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
51456index cf98da1..da890a9 100644
51457--- a/fs/ncpfs/inode.c
51458+++ b/fs/ncpfs/inode.c
51459@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
51460 #endif
51461 struct ncp_entry_info finfo;
51462
51463+ pax_track_stack();
51464+
51465 data.wdog_pid = NULL;
51466 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
51467 if (!server)
51468diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
51469index bfaef7b..e9d03ca 100644
51470--- a/fs/nfs/inode.c
51471+++ b/fs/nfs/inode.c
51472@@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
51473 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
51474 nfsi->attrtimeo_timestamp = jiffies;
51475
51476- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
51477+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
51478 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
51479 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
51480 else
51481@@ -973,16 +973,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51482 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51483 }
51484
51485-static atomic_long_t nfs_attr_generation_counter;
51486+static atomic_long_unchecked_t nfs_attr_generation_counter;
51487
51488 static unsigned long nfs_read_attr_generation_counter(void)
51489 {
51490- return atomic_long_read(&nfs_attr_generation_counter);
51491+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51492 }
51493
51494 unsigned long nfs_inc_attr_generation_counter(void)
51495 {
51496- return atomic_long_inc_return(&nfs_attr_generation_counter);
51497+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51498 }
51499
51500 void nfs_fattr_init(struct nfs_fattr *fattr)
51501diff --git a/fs/nfsd/lockd.c b/fs/nfsd/lockd.c
51502index cc2f505..f6a236f 100644
51503--- a/fs/nfsd/lockd.c
51504+++ b/fs/nfsd/lockd.c
51505@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
51506 fput(filp);
51507 }
51508
51509-static struct nlmsvc_binding nfsd_nlm_ops = {
51510+static const struct nlmsvc_binding nfsd_nlm_ops = {
51511 .fopen = nlm_fopen, /* open file for locking */
51512 .fclose = nlm_fclose, /* close file */
51513 };
51514diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
51515index cfc3391..dcc083a 100644
51516--- a/fs/nfsd/nfs4state.c
51517+++ b/fs/nfsd/nfs4state.c
51518@@ -3459,6 +3459,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
51519 unsigned int cmd;
51520 int err;
51521
51522+ pax_track_stack();
51523+
51524 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
51525 (long long) lock->lk_offset,
51526 (long long) lock->lk_length);
51527diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
51528index 4a82a96..0d5fb49 100644
51529--- a/fs/nfsd/nfs4xdr.c
51530+++ b/fs/nfsd/nfs4xdr.c
51531@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
51532 struct nfsd4_compoundres *resp = rqstp->rq_resp;
51533 u32 minorversion = resp->cstate.minorversion;
51534
51535+ pax_track_stack();
51536+
51537 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
51538 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
51539 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
51540diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51541index 2e09588..596421d 100644
51542--- a/fs/nfsd/vfs.c
51543+++ b/fs/nfsd/vfs.c
51544@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51545 } else {
51546 oldfs = get_fs();
51547 set_fs(KERNEL_DS);
51548- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51549+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51550 set_fs(oldfs);
51551 }
51552
51553@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51554
51555 /* Write the data. */
51556 oldfs = get_fs(); set_fs(KERNEL_DS);
51557- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51558+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51559 set_fs(oldfs);
51560 if (host_err < 0)
51561 goto out_nfserr;
51562@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51563 */
51564
51565 oldfs = get_fs(); set_fs(KERNEL_DS);
51566- host_err = inode->i_op->readlink(dentry, buf, *lenp);
51567+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
51568 set_fs(oldfs);
51569
51570 if (host_err < 0)
51571diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
51572index f6af760..d6b2b83 100644
51573--- a/fs/nilfs2/ioctl.c
51574+++ b/fs/nilfs2/ioctl.c
51575@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
51576 unsigned int cmd, void __user *argp)
51577 {
51578 struct nilfs_argv argv[5];
51579- const static size_t argsz[5] = {
51580+ static const size_t argsz[5] = {
51581 sizeof(struct nilfs_vdesc),
51582 sizeof(struct nilfs_period),
51583 sizeof(__u64),
51584diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
51585index 7e54e52..9337248 100644
51586--- a/fs/notify/dnotify/dnotify.c
51587+++ b/fs/notify/dnotify/dnotify.c
51588@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsnotify_mark_entry *entry)
51589 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
51590 }
51591
51592-static struct fsnotify_ops dnotify_fsnotify_ops = {
51593+static const struct fsnotify_ops dnotify_fsnotify_ops = {
51594 .handle_event = dnotify_handle_event,
51595 .should_send_event = dnotify_should_send_event,
51596 .free_group_priv = NULL,
51597diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51598index b8bf53b..c518688 100644
51599--- a/fs/notify/notification.c
51600+++ b/fs/notify/notification.c
51601@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51602 * get set to 0 so it will never get 'freed'
51603 */
51604 static struct fsnotify_event q_overflow_event;
51605-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51606+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51607
51608 /**
51609 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51610@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51611 */
51612 u32 fsnotify_get_cookie(void)
51613 {
51614- return atomic_inc_return(&fsnotify_sync_cookie);
51615+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51616 }
51617 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51618
51619diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51620index 5a9e344..0f8cd28 100644
51621--- a/fs/ntfs/dir.c
51622+++ b/fs/ntfs/dir.c
51623@@ -1328,7 +1328,7 @@ find_next_index_buffer:
51624 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51625 ~(s64)(ndir->itype.index.block_size - 1)));
51626 /* Bounds checks. */
51627- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51628+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51629 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51630 "inode 0x%lx or driver bug.", vdir->i_ino);
51631 goto err_out;
51632diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51633index 663c0e3..b6868e9 100644
51634--- a/fs/ntfs/file.c
51635+++ b/fs/ntfs/file.c
51636@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51637 #endif /* NTFS_RW */
51638 };
51639
51640-const struct file_operations ntfs_empty_file_ops = {};
51641+const struct file_operations ntfs_empty_file_ops __read_only;
51642
51643-const struct inode_operations ntfs_empty_inode_ops = {};
51644+const struct inode_operations ntfs_empty_inode_ops __read_only;
51645diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
51646index 1cd2934..880b5d2 100644
51647--- a/fs/ocfs2/cluster/masklog.c
51648+++ b/fs/ocfs2/cluster/masklog.c
51649@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
51650 return mlog_mask_store(mlog_attr->mask, buf, count);
51651 }
51652
51653-static struct sysfs_ops mlog_attr_ops = {
51654+static const struct sysfs_ops mlog_attr_ops = {
51655 .show = mlog_show,
51656 .store = mlog_store,
51657 };
51658diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51659index ac10f83..2cd2607 100644
51660--- a/fs/ocfs2/localalloc.c
51661+++ b/fs/ocfs2/localalloc.c
51662@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51663 goto bail;
51664 }
51665
51666- atomic_inc(&osb->alloc_stats.moves);
51667+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51668
51669 status = 0;
51670 bail:
51671diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
51672index f010b22..9f9ed34 100644
51673--- a/fs/ocfs2/namei.c
51674+++ b/fs/ocfs2/namei.c
51675@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *old_dir,
51676 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
51677 struct ocfs2_dir_lookup_result target_insert = { NULL, };
51678
51679+ pax_track_stack();
51680+
51681 /* At some point it might be nice to break this function up a
51682 * bit. */
51683
51684diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51685index d963d86..914cfbd 100644
51686--- a/fs/ocfs2/ocfs2.h
51687+++ b/fs/ocfs2/ocfs2.h
51688@@ -217,11 +217,11 @@ enum ocfs2_vol_state
51689
51690 struct ocfs2_alloc_stats
51691 {
51692- atomic_t moves;
51693- atomic_t local_data;
51694- atomic_t bitmap_data;
51695- atomic_t bg_allocs;
51696- atomic_t bg_extends;
51697+ atomic_unchecked_t moves;
51698+ atomic_unchecked_t local_data;
51699+ atomic_unchecked_t bitmap_data;
51700+ atomic_unchecked_t bg_allocs;
51701+ atomic_unchecked_t bg_extends;
51702 };
51703
51704 enum ocfs2_local_alloc_state
51705diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51706index 79b5dac..d322952 100644
51707--- a/fs/ocfs2/suballoc.c
51708+++ b/fs/ocfs2/suballoc.c
51709@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51710 mlog_errno(status);
51711 goto bail;
51712 }
51713- atomic_inc(&osb->alloc_stats.bg_extends);
51714+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51715
51716 /* You should never ask for this much metadata */
51717 BUG_ON(bits_wanted >
51718@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb,
51719 mlog_errno(status);
51720 goto bail;
51721 }
51722- atomic_inc(&osb->alloc_stats.bg_allocs);
51723+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51724
51725 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
51726 ac->ac_bits_given += (*num_bits);
51727@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb,
51728 mlog_errno(status);
51729 goto bail;
51730 }
51731- atomic_inc(&osb->alloc_stats.bg_allocs);
51732+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51733
51734 BUG_ON(num_bits != 1);
51735
51736@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51737 cluster_start,
51738 num_clusters);
51739 if (!status)
51740- atomic_inc(&osb->alloc_stats.local_data);
51741+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51742 } else {
51743 if (min_clusters > (osb->bitmap_cpg - 1)) {
51744 /* The only paths asking for contiguousness
51745@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51746 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51747 bg_blkno,
51748 bg_bit_off);
51749- atomic_inc(&osb->alloc_stats.bitmap_data);
51750+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51751 }
51752 }
51753 if (status < 0) {
51754diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51755index 9f55be4..a3f8048 100644
51756--- a/fs/ocfs2/super.c
51757+++ b/fs/ocfs2/super.c
51758@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51759 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51760 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51761 "Stats",
51762- atomic_read(&osb->alloc_stats.bitmap_data),
51763- atomic_read(&osb->alloc_stats.local_data),
51764- atomic_read(&osb->alloc_stats.bg_allocs),
51765- atomic_read(&osb->alloc_stats.moves),
51766- atomic_read(&osb->alloc_stats.bg_extends));
51767+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51768+ atomic_read_unchecked(&osb->alloc_stats.local_data),
51769+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51770+ atomic_read_unchecked(&osb->alloc_stats.moves),
51771+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51772
51773 out += snprintf(buf + out, len - out,
51774 "%10s => State: %u Descriptor: %llu Size: %u bits "
51775@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51776 spin_lock_init(&osb->osb_xattr_lock);
51777 ocfs2_init_inode_steal_slot(osb);
51778
51779- atomic_set(&osb->alloc_stats.moves, 0);
51780- atomic_set(&osb->alloc_stats.local_data, 0);
51781- atomic_set(&osb->alloc_stats.bitmap_data, 0);
51782- atomic_set(&osb->alloc_stats.bg_allocs, 0);
51783- atomic_set(&osb->alloc_stats.bg_extends, 0);
51784+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51785+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51786+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51787+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51788+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51789
51790 /* Copy the blockcheck stats from the superblock probe */
51791 osb->osb_ecc_stats = *stats;
51792diff --git a/fs/open.c b/fs/open.c
51793index 4f01e06..091f6c3 100644
51794--- a/fs/open.c
51795+++ b/fs/open.c
51796@@ -275,6 +275,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
51797 error = locks_verify_truncate(inode, NULL, length);
51798 if (!error)
51799 error = security_path_truncate(&path, length, 0);
51800+
51801+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
51802+ error = -EACCES;
51803+
51804 if (!error) {
51805 vfs_dq_init(inode);
51806 error = do_truncate(path.dentry, length, 0, NULL);
51807@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
51808 if (__mnt_is_readonly(path.mnt))
51809 res = -EROFS;
51810
51811+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51812+ res = -EACCES;
51813+
51814 out_path_release:
51815 path_put(&path);
51816 out:
51817@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
51818 if (error)
51819 goto dput_and_out;
51820
51821+ gr_log_chdir(path.dentry, path.mnt);
51822+
51823 set_fs_pwd(current->fs, &path);
51824
51825 dput_and_out:
51826@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51827 goto out_putf;
51828
51829 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
51830+
51831+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
51832+ error = -EPERM;
51833+
51834+ if (!error)
51835+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
51836+
51837 if (!error)
51838 set_fs_pwd(current->fs, &file->f_path);
51839 out_putf:
51840@@ -588,7 +604,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
51841 if (!capable(CAP_SYS_CHROOT))
51842 goto dput_and_out;
51843
51844+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51845+ goto dput_and_out;
51846+
51847 set_fs_root(current->fs, &path);
51848+
51849+ gr_handle_chroot_chdir(&path);
51850+
51851 error = 0;
51852 dput_and_out:
51853 path_put(&path);
51854@@ -616,12 +638,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
51855 err = mnt_want_write_file(file);
51856 if (err)
51857 goto out_putf;
51858+
51859 mutex_lock(&inode->i_mutex);
51860+
51861+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
51862+ err = -EACCES;
51863+ goto out_unlock;
51864+ }
51865+
51866 if (mode == (mode_t) -1)
51867 mode = inode->i_mode;
51868+
51869+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
51870+ err = -EPERM;
51871+ goto out_unlock;
51872+ }
51873+
51874 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
51875 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
51876 err = notify_change(dentry, &newattrs);
51877+
51878+out_unlock:
51879 mutex_unlock(&inode->i_mutex);
51880 mnt_drop_write(file->f_path.mnt);
51881 out_putf:
51882@@ -645,12 +682,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
51883 error = mnt_want_write(path.mnt);
51884 if (error)
51885 goto dput_and_out;
51886+
51887 mutex_lock(&inode->i_mutex);
51888+
51889+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
51890+ error = -EACCES;
51891+ goto out_unlock;
51892+ }
51893+
51894 if (mode == (mode_t) -1)
51895 mode = inode->i_mode;
51896+
51897+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
51898+ error = -EACCES;
51899+ goto out_unlock;
51900+ }
51901+
51902 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
51903 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
51904 error = notify_change(path.dentry, &newattrs);
51905+
51906+out_unlock:
51907 mutex_unlock(&inode->i_mutex);
51908 mnt_drop_write(path.mnt);
51909 dput_and_out:
51910@@ -664,12 +716,15 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode)
51911 return sys_fchmodat(AT_FDCWD, filename, mode);
51912 }
51913
51914-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
51915+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
51916 {
51917 struct inode *inode = dentry->d_inode;
51918 int error;
51919 struct iattr newattrs;
51920
51921+ if (!gr_acl_handle_chown(dentry, mnt))
51922+ return -EACCES;
51923+
51924 newattrs.ia_valid = ATTR_CTIME;
51925 if (user != (uid_t) -1) {
51926 newattrs.ia_valid |= ATTR_UID;
51927@@ -700,7 +755,7 @@ SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
51928 error = mnt_want_write(path.mnt);
51929 if (error)
51930 goto out_release;
51931- error = chown_common(path.dentry, user, group);
51932+ error = chown_common(path.dentry, user, group, path.mnt);
51933 mnt_drop_write(path.mnt);
51934 out_release:
51935 path_put(&path);
51936@@ -725,7 +780,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
51937 error = mnt_want_write(path.mnt);
51938 if (error)
51939 goto out_release;
51940- error = chown_common(path.dentry, user, group);
51941+ error = chown_common(path.dentry, user, group, path.mnt);
51942 mnt_drop_write(path.mnt);
51943 out_release:
51944 path_put(&path);
51945@@ -744,7 +799,7 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
51946 error = mnt_want_write(path.mnt);
51947 if (error)
51948 goto out_release;
51949- error = chown_common(path.dentry, user, group);
51950+ error = chown_common(path.dentry, user, group, path.mnt);
51951 mnt_drop_write(path.mnt);
51952 out_release:
51953 path_put(&path);
51954@@ -767,7 +822,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
51955 goto out_fput;
51956 dentry = file->f_path.dentry;
51957 audit_inode(NULL, dentry);
51958- error = chown_common(dentry, user, group);
51959+ error = chown_common(dentry, user, group, file->f_path.mnt);
51960 mnt_drop_write(file->f_path.mnt);
51961 out_fput:
51962 fput(file);
51963@@ -1036,7 +1091,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
51964 if (!IS_ERR(tmp)) {
51965 fd = get_unused_fd_flags(flags);
51966 if (fd >= 0) {
51967- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
51968+ struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
51969 if (IS_ERR(f)) {
51970 put_unused_fd(fd);
51971 fd = PTR_ERR(f);
51972diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
51973index 6ab70f4..f4103d1 100644
51974--- a/fs/partitions/efi.c
51975+++ b/fs/partitions/efi.c
51976@@ -231,14 +231,14 @@ alloc_read_gpt_entries(struct block_device *bdev, gpt_header *gpt)
51977 if (!bdev || !gpt)
51978 return NULL;
51979
51980+ if (!le32_to_cpu(gpt->num_partition_entries))
51981+ return NULL;
51982+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
51983+ if (!pte)
51984+ return NULL;
51985+
51986 count = le32_to_cpu(gpt->num_partition_entries) *
51987 le32_to_cpu(gpt->sizeof_partition_entry);
51988- if (!count)
51989- return NULL;
51990- pte = kzalloc(count, GFP_KERNEL);
51991- if (!pte)
51992- return NULL;
51993-
51994 if (read_lba(bdev, le64_to_cpu(gpt->partition_entry_lba),
51995 (u8 *) pte,
51996 count) < count) {
51997diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
51998index dd6efdb..3babc6c 100644
51999--- a/fs/partitions/ldm.c
52000+++ b/fs/partitions/ldm.c
52001@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52002 ldm_error ("A VBLK claims to have %d parts.", num);
52003 return false;
52004 }
52005+
52006 if (rec >= num) {
52007 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
52008 return false;
52009@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52010 goto found;
52011 }
52012
52013- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
52014+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
52015 if (!f) {
52016 ldm_crit ("Out of memory.");
52017 return false;
52018diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
52019index 5765198..7f8e9e0 100644
52020--- a/fs/partitions/mac.c
52021+++ b/fs/partitions/mac.c
52022@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
52023 return 0; /* not a MacOS disk */
52024 }
52025 blocks_in_map = be32_to_cpu(part->map_count);
52026- if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52027- put_dev_sector(sect);
52028- return 0;
52029- }
52030 printk(" [mac]");
52031+ if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52032+ put_dev_sector(sect);
52033+ return 0;
52034+ }
52035 for (slot = 1; slot <= blocks_in_map; ++slot) {
52036 int pos = slot * secsize;
52037 put_dev_sector(sect);
52038diff --git a/fs/pipe.c b/fs/pipe.c
52039index d0cc080..8a6f211 100644
52040--- a/fs/pipe.c
52041+++ b/fs/pipe.c
52042@@ -401,9 +401,9 @@ redo:
52043 }
52044 if (bufs) /* More to do? */
52045 continue;
52046- if (!pipe->writers)
52047+ if (!atomic_read(&pipe->writers))
52048 break;
52049- if (!pipe->waiting_writers) {
52050+ if (!atomic_read(&pipe->waiting_writers)) {
52051 /* syscall merging: Usually we must not sleep
52052 * if O_NONBLOCK is set, or if we got some data.
52053 * But if a writer sleeps in kernel space, then
52054@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
52055 mutex_lock(&inode->i_mutex);
52056 pipe = inode->i_pipe;
52057
52058- if (!pipe->readers) {
52059+ if (!atomic_read(&pipe->readers)) {
52060 send_sig(SIGPIPE, current, 0);
52061 ret = -EPIPE;
52062 goto out;
52063@@ -511,7 +511,7 @@ redo1:
52064 for (;;) {
52065 int bufs;
52066
52067- if (!pipe->readers) {
52068+ if (!atomic_read(&pipe->readers)) {
52069 send_sig(SIGPIPE, current, 0);
52070 if (!ret)
52071 ret = -EPIPE;
52072@@ -597,9 +597,9 @@ redo2:
52073 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
52074 do_wakeup = 0;
52075 }
52076- pipe->waiting_writers++;
52077+ atomic_inc(&pipe->waiting_writers);
52078 pipe_wait(pipe);
52079- pipe->waiting_writers--;
52080+ atomic_dec(&pipe->waiting_writers);
52081 }
52082 out:
52083 mutex_unlock(&inode->i_mutex);
52084@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52085 mask = 0;
52086 if (filp->f_mode & FMODE_READ) {
52087 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
52088- if (!pipe->writers && filp->f_version != pipe->w_counter)
52089+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
52090 mask |= POLLHUP;
52091 }
52092
52093@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52094 * Most Unices do not set POLLERR for FIFOs but on Linux they
52095 * behave exactly like pipes for poll().
52096 */
52097- if (!pipe->readers)
52098+ if (!atomic_read(&pipe->readers))
52099 mask |= POLLERR;
52100 }
52101
52102@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int decr, int decw)
52103
52104 mutex_lock(&inode->i_mutex);
52105 pipe = inode->i_pipe;
52106- pipe->readers -= decr;
52107- pipe->writers -= decw;
52108+ atomic_sub(decr, &pipe->readers);
52109+ atomic_sub(decw, &pipe->writers);
52110
52111- if (!pipe->readers && !pipe->writers) {
52112+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
52113 free_pipe_info(inode);
52114 } else {
52115 wake_up_interruptible_sync(&pipe->wait);
52116@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
52117
52118 if (inode->i_pipe) {
52119 ret = 0;
52120- inode->i_pipe->readers++;
52121+ atomic_inc(&inode->i_pipe->readers);
52122 }
52123
52124 mutex_unlock(&inode->i_mutex);
52125@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
52126
52127 if (inode->i_pipe) {
52128 ret = 0;
52129- inode->i_pipe->writers++;
52130+ atomic_inc(&inode->i_pipe->writers);
52131 }
52132
52133 mutex_unlock(&inode->i_mutex);
52134@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
52135 if (inode->i_pipe) {
52136 ret = 0;
52137 if (filp->f_mode & FMODE_READ)
52138- inode->i_pipe->readers++;
52139+ atomic_inc(&inode->i_pipe->readers);
52140 if (filp->f_mode & FMODE_WRITE)
52141- inode->i_pipe->writers++;
52142+ atomic_inc(&inode->i_pipe->writers);
52143 }
52144
52145 mutex_unlock(&inode->i_mutex);
52146@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
52147 inode->i_pipe = NULL;
52148 }
52149
52150-static struct vfsmount *pipe_mnt __read_mostly;
52151+struct vfsmount *pipe_mnt __read_mostly;
52152 static int pipefs_delete_dentry(struct dentry *dentry)
52153 {
52154 /*
52155@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(void)
52156 goto fail_iput;
52157 inode->i_pipe = pipe;
52158
52159- pipe->readers = pipe->writers = 1;
52160+ atomic_set(&pipe->readers, 1);
52161+ atomic_set(&pipe->writers, 1);
52162 inode->i_fop = &rdwr_pipefifo_fops;
52163
52164 /*
52165diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
52166index 50f8f06..c5755df 100644
52167--- a/fs/proc/Kconfig
52168+++ b/fs/proc/Kconfig
52169@@ -30,12 +30,12 @@ config PROC_FS
52170
52171 config PROC_KCORE
52172 bool "/proc/kcore support" if !ARM
52173- depends on PROC_FS && MMU
52174+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
52175
52176 config PROC_VMCORE
52177 bool "/proc/vmcore support (EXPERIMENTAL)"
52178- depends on PROC_FS && CRASH_DUMP
52179- default y
52180+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
52181+ default n
52182 help
52183 Exports the dump image of crashed kernel in ELF format.
52184
52185@@ -59,8 +59,8 @@ config PROC_SYSCTL
52186 limited in memory.
52187
52188 config PROC_PAGE_MONITOR
52189- default y
52190- depends on PROC_FS && MMU
52191+ default n
52192+ depends on PROC_FS && MMU && !GRKERNSEC
52193 bool "Enable /proc page monitoring" if EMBEDDED
52194 help
52195 Various /proc files exist to monitor process memory utilization:
52196diff --git a/fs/proc/array.c b/fs/proc/array.c
52197index c5ef152..1363194 100644
52198--- a/fs/proc/array.c
52199+++ b/fs/proc/array.c
52200@@ -60,6 +60,7 @@
52201 #include <linux/tty.h>
52202 #include <linux/string.h>
52203 #include <linux/mman.h>
52204+#include <linux/grsecurity.h>
52205 #include <linux/proc_fs.h>
52206 #include <linux/ioport.h>
52207 #include <linux/uaccess.h>
52208@@ -321,6 +322,21 @@ static inline void task_context_switch_counts(struct seq_file *m,
52209 p->nivcsw);
52210 }
52211
52212+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52213+static inline void task_pax(struct seq_file *m, struct task_struct *p)
52214+{
52215+ if (p->mm)
52216+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
52217+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
52218+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
52219+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
52220+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
52221+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
52222+ else
52223+ seq_printf(m, "PaX:\t-----\n");
52224+}
52225+#endif
52226+
52227 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52228 struct pid *pid, struct task_struct *task)
52229 {
52230@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52231 task_cap(m, task);
52232 cpuset_task_status_allowed(m, task);
52233 task_context_switch_counts(m, task);
52234+
52235+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52236+ task_pax(m, task);
52237+#endif
52238+
52239+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
52240+ task_grsec_rbac(m, task);
52241+#endif
52242+
52243 return 0;
52244 }
52245
52246+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52247+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52248+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52249+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52250+#endif
52251+
52252 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52253 struct pid *pid, struct task_struct *task, int whole)
52254 {
52255@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52256 cputime_t cutime, cstime, utime, stime;
52257 cputime_t cgtime, gtime;
52258 unsigned long rsslim = 0;
52259- char tcomm[sizeof(task->comm)];
52260+ char tcomm[sizeof(task->comm)] = { 0 };
52261 unsigned long flags;
52262
52263+ pax_track_stack();
52264+
52265 state = *get_task_state(task);
52266 vsize = eip = esp = 0;
52267 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
52268@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52269 gtime = task_gtime(task);
52270 }
52271
52272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52273+ if (PAX_RAND_FLAGS(mm)) {
52274+ eip = 0;
52275+ esp = 0;
52276+ wchan = 0;
52277+ }
52278+#endif
52279+#ifdef CONFIG_GRKERNSEC_HIDESYM
52280+ wchan = 0;
52281+ eip =0;
52282+ esp =0;
52283+#endif
52284+
52285 /* scale priority and nice values from timeslices to -20..20 */
52286 /* to make it look like a "normal" Unix priority/nice value */
52287 priority = task_prio(task);
52288@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52289 vsize,
52290 mm ? get_mm_rss(mm) : 0,
52291 rsslim,
52292+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52293+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
52294+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
52295+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
52296+#else
52297 mm ? (permitted ? mm->start_code : 1) : 0,
52298 mm ? (permitted ? mm->end_code : 1) : 0,
52299 (permitted && mm) ? mm->start_stack : 0,
52300+#endif
52301 esp,
52302 eip,
52303 /* The signal information here is obsolete.
52304@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52305
52306 return 0;
52307 }
52308+
52309+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52310+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
52311+{
52312+ u32 curr_ip = 0;
52313+ unsigned long flags;
52314+
52315+ if (lock_task_sighand(task, &flags)) {
52316+ curr_ip = task->signal->curr_ip;
52317+ unlock_task_sighand(task, &flags);
52318+ }
52319+
52320+ return sprintf(buffer, "%pI4\n", &curr_ip);
52321+}
52322+#endif
52323diff --git a/fs/proc/base.c b/fs/proc/base.c
52324index 67f7dc0..e95ea4f 100644
52325--- a/fs/proc/base.c
52326+++ b/fs/proc/base.c
52327@@ -102,6 +102,22 @@ struct pid_entry {
52328 union proc_op op;
52329 };
52330
52331+struct getdents_callback {
52332+ struct linux_dirent __user * current_dir;
52333+ struct linux_dirent __user * previous;
52334+ struct file * file;
52335+ int count;
52336+ int error;
52337+};
52338+
52339+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
52340+ loff_t offset, u64 ino, unsigned int d_type)
52341+{
52342+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
52343+ buf->error = -EINVAL;
52344+ return 0;
52345+}
52346+
52347 #define NOD(NAME, MODE, IOP, FOP, OP) { \
52348 .name = (NAME), \
52349 .len = sizeof(NAME) - 1, \
52350@@ -213,6 +229,9 @@ static int check_mem_permission(struct task_struct *task)
52351 if (task == current)
52352 return 0;
52353
52354+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
52355+ return -EPERM;
52356+
52357 /*
52358 * If current is actively ptrace'ing, and would also be
52359 * permitted to freshly attach with ptrace now, permit it.
52360@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
52361 if (!mm->arg_end)
52362 goto out_mm; /* Shh! No looking before we're done */
52363
52364+ if (gr_acl_handle_procpidmem(task))
52365+ goto out_mm;
52366+
52367 len = mm->arg_end - mm->arg_start;
52368
52369 if (len > PAGE_SIZE)
52370@@ -287,12 +309,28 @@ out:
52371 return res;
52372 }
52373
52374+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52375+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52376+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52377+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52378+#endif
52379+
52380 static int proc_pid_auxv(struct task_struct *task, char *buffer)
52381 {
52382 int res = 0;
52383 struct mm_struct *mm = get_task_mm(task);
52384 if (mm) {
52385 unsigned int nwords = 0;
52386+
52387+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52388+ /* allow if we're currently ptracing this task */
52389+ if (PAX_RAND_FLAGS(mm) &&
52390+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
52391+ mmput(mm);
52392+ return 0;
52393+ }
52394+#endif
52395+
52396 do {
52397 nwords += 2;
52398 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
52399@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
52400 }
52401
52402
52403-#ifdef CONFIG_KALLSYMS
52404+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52405 /*
52406 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
52407 * Returns the resolved symbol. If that fails, simply return the address.
52408@@ -345,7 +383,7 @@ static void unlock_trace(struct task_struct *task)
52409 mutex_unlock(&task->cred_guard_mutex);
52410 }
52411
52412-#ifdef CONFIG_STACKTRACE
52413+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52414
52415 #define MAX_STACK_TRACE_DEPTH 64
52416
52417@@ -545,7 +583,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
52418 return count;
52419 }
52420
52421-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52422+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52423 static int proc_pid_syscall(struct task_struct *task, char *buffer)
52424 {
52425 long nr;
52426@@ -574,7 +612,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
52427 /************************************************************************/
52428
52429 /* permission checks */
52430-static int proc_fd_access_allowed(struct inode *inode)
52431+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
52432 {
52433 struct task_struct *task;
52434 int allowed = 0;
52435@@ -584,7 +622,10 @@ static int proc_fd_access_allowed(struct inode *inode)
52436 */
52437 task = get_proc_task(inode);
52438 if (task) {
52439- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52440+ if (log)
52441+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
52442+ else
52443+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52444 put_task_struct(task);
52445 }
52446 return allowed;
52447@@ -963,6 +1004,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
52448 if (!task)
52449 goto out_no_task;
52450
52451+ if (gr_acl_handle_procpidmem(task))
52452+ goto out;
52453+
52454 if (!ptrace_may_access(task, PTRACE_MODE_READ))
52455 goto out;
52456
52457@@ -1377,7 +1421,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
52458 path_put(&nd->path);
52459
52460 /* Are we allowed to snoop on the tasks file descriptors? */
52461- if (!proc_fd_access_allowed(inode))
52462+ if (!proc_fd_access_allowed(inode,0))
52463 goto out;
52464
52465 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
52466@@ -1417,8 +1461,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
52467 struct path path;
52468
52469 /* Are we allowed to snoop on the tasks file descriptors? */
52470- if (!proc_fd_access_allowed(inode))
52471- goto out;
52472+ /* logging this is needed for learning on chromium to work properly,
52473+ but we don't want to flood the logs from 'ps' which does a readlink
52474+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
52475+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
52476+ */
52477+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
52478+ if (!proc_fd_access_allowed(inode,0))
52479+ goto out;
52480+ } else {
52481+ if (!proc_fd_access_allowed(inode,1))
52482+ goto out;
52483+ }
52484
52485 error = PROC_I(inode)->op.proc_get_link(inode, &path);
52486 if (error)
52487@@ -1483,7 +1537,11 @@ static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_st
52488 rcu_read_lock();
52489 cred = __task_cred(task);
52490 inode->i_uid = cred->euid;
52491+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52492+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52493+#else
52494 inode->i_gid = cred->egid;
52495+#endif
52496 rcu_read_unlock();
52497 }
52498 security_task_to_inode(task, inode);
52499@@ -1501,6 +1559,9 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52500 struct inode *inode = dentry->d_inode;
52501 struct task_struct *task;
52502 const struct cred *cred;
52503+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52504+ const struct cred *tmpcred = current_cred();
52505+#endif
52506
52507 generic_fillattr(inode, stat);
52508
52509@@ -1508,13 +1569,41 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52510 stat->uid = 0;
52511 stat->gid = 0;
52512 task = pid_task(proc_pid(inode), PIDTYPE_PID);
52513+
52514+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
52515+ rcu_read_unlock();
52516+ return -ENOENT;
52517+ }
52518+
52519 if (task) {
52520+ cred = __task_cred(task);
52521+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52522+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
52523+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52524+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52525+#endif
52526+ ) {
52527+#endif
52528 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52529+#ifdef CONFIG_GRKERNSEC_PROC_USER
52530+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52531+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52532+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52533+#endif
52534 task_dumpable(task)) {
52535- cred = __task_cred(task);
52536 stat->uid = cred->euid;
52537+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52538+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
52539+#else
52540 stat->gid = cred->egid;
52541+#endif
52542 }
52543+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52544+ } else {
52545+ rcu_read_unlock();
52546+ return -ENOENT;
52547+ }
52548+#endif
52549 }
52550 rcu_read_unlock();
52551 return 0;
52552@@ -1545,11 +1634,20 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
52553
52554 if (task) {
52555 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52556+#ifdef CONFIG_GRKERNSEC_PROC_USER
52557+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52558+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52559+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52560+#endif
52561 task_dumpable(task)) {
52562 rcu_read_lock();
52563 cred = __task_cred(task);
52564 inode->i_uid = cred->euid;
52565+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52566+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52567+#else
52568 inode->i_gid = cred->egid;
52569+#endif
52570 rcu_read_unlock();
52571 } else {
52572 inode->i_uid = 0;
52573@@ -1670,7 +1768,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
52574 int fd = proc_fd(inode);
52575
52576 if (task) {
52577- files = get_files_struct(task);
52578+ if (!gr_acl_handle_procpidmem(task))
52579+ files = get_files_struct(task);
52580 put_task_struct(task);
52581 }
52582 if (files) {
52583@@ -1922,12 +2021,22 @@ static const struct file_operations proc_fd_operations = {
52584 static int proc_fd_permission(struct inode *inode, int mask)
52585 {
52586 int rv;
52587+ struct task_struct *task;
52588
52589 rv = generic_permission(inode, mask, NULL);
52590- if (rv == 0)
52591- return 0;
52592+
52593 if (task_pid(current) == proc_pid(inode))
52594 rv = 0;
52595+
52596+ task = get_proc_task(inode);
52597+ if (task == NULL)
52598+ return rv;
52599+
52600+ if (gr_acl_handle_procpidmem(task))
52601+ rv = -EACCES;
52602+
52603+ put_task_struct(task);
52604+
52605 return rv;
52606 }
52607
52608@@ -2036,6 +2145,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
52609 if (!task)
52610 goto out_no_task;
52611
52612+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52613+ goto out;
52614+
52615 /*
52616 * Yes, it does not scale. And it should not. Don't add
52617 * new entries into /proc/<tgid>/ without very good reasons.
52618@@ -2080,6 +2192,9 @@ static int proc_pident_readdir(struct file *filp,
52619 if (!task)
52620 goto out_no_task;
52621
52622+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52623+ goto out;
52624+
52625 ret = 0;
52626 i = filp->f_pos;
52627 switch (i) {
52628@@ -2347,7 +2462,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52629 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52630 void *cookie)
52631 {
52632- char *s = nd_get_link(nd);
52633+ const char *s = nd_get_link(nd);
52634 if (!IS_ERR(s))
52635 __putname(s);
52636 }
52637@@ -2553,7 +2668,7 @@ static const struct pid_entry tgid_base_stuff[] = {
52638 #ifdef CONFIG_SCHED_DEBUG
52639 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52640 #endif
52641-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52642+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52643 INF("syscall", S_IRUGO, proc_pid_syscall),
52644 #endif
52645 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52646@@ -2578,10 +2693,10 @@ static const struct pid_entry tgid_base_stuff[] = {
52647 #ifdef CONFIG_SECURITY
52648 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52649 #endif
52650-#ifdef CONFIG_KALLSYMS
52651+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52652 INF("wchan", S_IRUGO, proc_pid_wchan),
52653 #endif
52654-#ifdef CONFIG_STACKTRACE
52655+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52656 ONE("stack", S_IRUGO, proc_pid_stack),
52657 #endif
52658 #ifdef CONFIG_SCHEDSTATS
52659@@ -2611,6 +2726,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52660 #ifdef CONFIG_TASK_IO_ACCOUNTING
52661 INF("io", S_IRUSR, proc_tgid_io_accounting),
52662 #endif
52663+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52664+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52665+#endif
52666 };
52667
52668 static int proc_tgid_base_readdir(struct file * filp,
52669@@ -2735,7 +2853,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52670 if (!inode)
52671 goto out;
52672
52673+#ifdef CONFIG_GRKERNSEC_PROC_USER
52674+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52675+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52676+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52677+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52678+#else
52679 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52680+#endif
52681 inode->i_op = &proc_tgid_base_inode_operations;
52682 inode->i_fop = &proc_tgid_base_operations;
52683 inode->i_flags|=S_IMMUTABLE;
52684@@ -2777,7 +2902,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
52685 if (!task)
52686 goto out;
52687
52688+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52689+ goto out_put_task;
52690+
52691 result = proc_pid_instantiate(dir, dentry, task, NULL);
52692+out_put_task:
52693 put_task_struct(task);
52694 out:
52695 return result;
52696@@ -2842,6 +2971,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52697 {
52698 unsigned int nr;
52699 struct task_struct *reaper;
52700+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52701+ const struct cred *tmpcred = current_cred();
52702+ const struct cred *itercred;
52703+#endif
52704+ filldir_t __filldir = filldir;
52705 struct tgid_iter iter;
52706 struct pid_namespace *ns;
52707
52708@@ -2865,8 +2999,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52709 for (iter = next_tgid(ns, iter);
52710 iter.task;
52711 iter.tgid += 1, iter = next_tgid(ns, iter)) {
52712+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52713+ rcu_read_lock();
52714+ itercred = __task_cred(iter.task);
52715+#endif
52716+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
52717+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52718+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
52719+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52720+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52721+#endif
52722+ )
52723+#endif
52724+ )
52725+ __filldir = &gr_fake_filldir;
52726+ else
52727+ __filldir = filldir;
52728+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52729+ rcu_read_unlock();
52730+#endif
52731 filp->f_pos = iter.tgid + TGID_OFFSET;
52732- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
52733+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
52734 put_task_struct(iter.task);
52735 goto out;
52736 }
52737@@ -2892,7 +3045,7 @@ static const struct pid_entry tid_base_stuff[] = {
52738 #ifdef CONFIG_SCHED_DEBUG
52739 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52740 #endif
52741-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52742+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52743 INF("syscall", S_IRUGO, proc_pid_syscall),
52744 #endif
52745 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52746@@ -2916,10 +3069,10 @@ static const struct pid_entry tid_base_stuff[] = {
52747 #ifdef CONFIG_SECURITY
52748 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52749 #endif
52750-#ifdef CONFIG_KALLSYMS
52751+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52752 INF("wchan", S_IRUGO, proc_pid_wchan),
52753 #endif
52754-#ifdef CONFIG_STACKTRACE
52755+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52756 ONE("stack", S_IRUGO, proc_pid_stack),
52757 #endif
52758 #ifdef CONFIG_SCHEDSTATS
52759diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52760index 82676e3..5f8518a 100644
52761--- a/fs/proc/cmdline.c
52762+++ b/fs/proc/cmdline.c
52763@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52764
52765 static int __init proc_cmdline_init(void)
52766 {
52767+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52768+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52769+#else
52770 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52771+#endif
52772 return 0;
52773 }
52774 module_init(proc_cmdline_init);
52775diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52776index 59ee7da..469b4b6 100644
52777--- a/fs/proc/devices.c
52778+++ b/fs/proc/devices.c
52779@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52780
52781 static int __init proc_devices_init(void)
52782 {
52783+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52784+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52785+#else
52786 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52787+#endif
52788 return 0;
52789 }
52790 module_init(proc_devices_init);
52791diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52792index d78ade3..81767f9 100644
52793--- a/fs/proc/inode.c
52794+++ b/fs/proc/inode.c
52795@@ -18,12 +18,19 @@
52796 #include <linux/module.h>
52797 #include <linux/smp_lock.h>
52798 #include <linux/sysctl.h>
52799+#include <linux/grsecurity.h>
52800
52801 #include <asm/system.h>
52802 #include <asm/uaccess.h>
52803
52804 #include "internal.h"
52805
52806+#ifdef CONFIG_PROC_SYSCTL
52807+extern const struct inode_operations proc_sys_inode_operations;
52808+extern const struct inode_operations proc_sys_dir_operations;
52809+#endif
52810+
52811+
52812 struct proc_dir_entry *de_get(struct proc_dir_entry *de)
52813 {
52814 atomic_inc(&de->count);
52815@@ -62,6 +69,13 @@ static void proc_delete_inode(struct inode *inode)
52816 de_put(de);
52817 if (PROC_I(inode)->sysctl)
52818 sysctl_head_put(PROC_I(inode)->sysctl);
52819+
52820+#ifdef CONFIG_PROC_SYSCTL
52821+ if (inode->i_op == &proc_sys_inode_operations ||
52822+ inode->i_op == &proc_sys_dir_operations)
52823+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52824+#endif
52825+
52826 clear_inode(inode);
52827 }
52828
52829@@ -457,7 +471,11 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
52830 if (de->mode) {
52831 inode->i_mode = de->mode;
52832 inode->i_uid = de->uid;
52833+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52834+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52835+#else
52836 inode->i_gid = de->gid;
52837+#endif
52838 }
52839 if (de->size)
52840 inode->i_size = de->size;
52841diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52842index 753ca37..26bcf3b 100644
52843--- a/fs/proc/internal.h
52844+++ b/fs/proc/internal.h
52845@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52846 struct pid *pid, struct task_struct *task);
52847 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52848 struct pid *pid, struct task_struct *task);
52849+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52850+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52851+#endif
52852 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52853
52854 extern const struct file_operations proc_maps_operations;
52855diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52856index b442dac..aab29cb 100644
52857--- a/fs/proc/kcore.c
52858+++ b/fs/proc/kcore.c
52859@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
52860 off_t offset = 0;
52861 struct kcore_list *m;
52862
52863+ pax_track_stack();
52864+
52865 /* setup ELF header */
52866 elf = (struct elfhdr *) bufp;
52867 bufp += sizeof(struct elfhdr);
52868@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52869 * the addresses in the elf_phdr on our list.
52870 */
52871 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52872- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52873+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52874+ if (tsz > buflen)
52875 tsz = buflen;
52876-
52877+
52878 while (buflen) {
52879 struct kcore_list *m;
52880
52881@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52882 kfree(elf_buf);
52883 } else {
52884 if (kern_addr_valid(start)) {
52885- unsigned long n;
52886+ char *elf_buf;
52887+ mm_segment_t oldfs;
52888
52889- n = copy_to_user(buffer, (char *)start, tsz);
52890- /*
52891- * We cannot distingush between fault on source
52892- * and fault on destination. When this happens
52893- * we clear too and hope it will trigger the
52894- * EFAULT again.
52895- */
52896- if (n) {
52897- if (clear_user(buffer + tsz - n,
52898- n))
52899+ elf_buf = kmalloc(tsz, GFP_KERNEL);
52900+ if (!elf_buf)
52901+ return -ENOMEM;
52902+ oldfs = get_fs();
52903+ set_fs(KERNEL_DS);
52904+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52905+ set_fs(oldfs);
52906+ if (copy_to_user(buffer, elf_buf, tsz)) {
52907+ kfree(elf_buf);
52908 return -EFAULT;
52909+ }
52910 }
52911+ set_fs(oldfs);
52912+ kfree(elf_buf);
52913 } else {
52914 if (clear_user(buffer, tsz))
52915 return -EFAULT;
52916@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52917
52918 static int open_kcore(struct inode *inode, struct file *filp)
52919 {
52920+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52921+ return -EPERM;
52922+#endif
52923 if (!capable(CAP_SYS_RAWIO))
52924 return -EPERM;
52925 if (kcore_need_update)
52926diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52927index a65239c..ad1182a 100644
52928--- a/fs/proc/meminfo.c
52929+++ b/fs/proc/meminfo.c
52930@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52931 unsigned long pages[NR_LRU_LISTS];
52932 int lru;
52933
52934+ pax_track_stack();
52935+
52936 /*
52937 * display in kilobytes.
52938 */
52939@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52940 vmi.used >> 10,
52941 vmi.largest_chunk >> 10
52942 #ifdef CONFIG_MEMORY_FAILURE
52943- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52944+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52945 #endif
52946 );
52947
52948diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52949index 9fe7d7e..cdb62c9 100644
52950--- a/fs/proc/nommu.c
52951+++ b/fs/proc/nommu.c
52952@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52953 if (len < 1)
52954 len = 1;
52955 seq_printf(m, "%*c", len, ' ');
52956- seq_path(m, &file->f_path, "");
52957+ seq_path(m, &file->f_path, "\n\\");
52958 }
52959
52960 seq_putc(m, '\n');
52961diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52962index 04d1270..25e1173 100644
52963--- a/fs/proc/proc_net.c
52964+++ b/fs/proc/proc_net.c
52965@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52966 struct task_struct *task;
52967 struct nsproxy *ns;
52968 struct net *net = NULL;
52969+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52970+ const struct cred *cred = current_cred();
52971+#endif
52972+
52973+#ifdef CONFIG_GRKERNSEC_PROC_USER
52974+ if (cred->fsuid)
52975+ return net;
52976+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52977+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
52978+ return net;
52979+#endif
52980
52981 rcu_read_lock();
52982 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52983diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52984index f667e8a..55f4d96 100644
52985--- a/fs/proc/proc_sysctl.c
52986+++ b/fs/proc/proc_sysctl.c
52987@@ -7,11 +7,13 @@
52988 #include <linux/security.h>
52989 #include "internal.h"
52990
52991+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
52992+
52993 static const struct dentry_operations proc_sys_dentry_operations;
52994 static const struct file_operations proc_sys_file_operations;
52995-static const struct inode_operations proc_sys_inode_operations;
52996+const struct inode_operations proc_sys_inode_operations;
52997 static const struct file_operations proc_sys_dir_file_operations;
52998-static const struct inode_operations proc_sys_dir_operations;
52999+const struct inode_operations proc_sys_dir_operations;
53000
53001 static struct inode *proc_sys_make_inode(struct super_block *sb,
53002 struct ctl_table_header *head, struct ctl_table *table)
53003@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53004 if (!p)
53005 goto out;
53006
53007+ if (gr_handle_sysctl(p, MAY_EXEC))
53008+ goto out;
53009+
53010 err = ERR_PTR(-ENOMEM);
53011 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
53012 if (h)
53013@@ -119,6 +124,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53014
53015 err = NULL;
53016 dentry->d_op = &proc_sys_dentry_operations;
53017+
53018+ gr_handle_proc_create(dentry, inode);
53019+
53020 d_add(dentry, inode);
53021
53022 out:
53023@@ -200,6 +208,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
53024 return -ENOMEM;
53025 } else {
53026 child->d_op = &proc_sys_dentry_operations;
53027+
53028+ gr_handle_proc_create(child, inode);
53029+
53030 d_add(child, inode);
53031 }
53032 } else {
53033@@ -228,6 +239,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
53034 if (*pos < file->f_pos)
53035 continue;
53036
53037+ if (gr_handle_sysctl(table, 0))
53038+ continue;
53039+
53040 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
53041 if (res)
53042 return res;
53043@@ -344,6 +358,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
53044 if (IS_ERR(head))
53045 return PTR_ERR(head);
53046
53047+ if (table && gr_handle_sysctl(table, MAY_EXEC))
53048+ return -ENOENT;
53049+
53050 generic_fillattr(inode, stat);
53051 if (table)
53052 stat->mode = (stat->mode & S_IFMT) | table->mode;
53053@@ -358,17 +375,18 @@ static const struct file_operations proc_sys_file_operations = {
53054 };
53055
53056 static const struct file_operations proc_sys_dir_file_operations = {
53057+ .read = generic_read_dir,
53058 .readdir = proc_sys_readdir,
53059 .llseek = generic_file_llseek,
53060 };
53061
53062-static const struct inode_operations proc_sys_inode_operations = {
53063+const struct inode_operations proc_sys_inode_operations = {
53064 .permission = proc_sys_permission,
53065 .setattr = proc_sys_setattr,
53066 .getattr = proc_sys_getattr,
53067 };
53068
53069-static const struct inode_operations proc_sys_dir_operations = {
53070+const struct inode_operations proc_sys_dir_operations = {
53071 .lookup = proc_sys_lookup,
53072 .permission = proc_sys_permission,
53073 .setattr = proc_sys_setattr,
53074diff --git a/fs/proc/root.c b/fs/proc/root.c
53075index b080b79..d957e63 100644
53076--- a/fs/proc/root.c
53077+++ b/fs/proc/root.c
53078@@ -134,7 +134,15 @@ void __init proc_root_init(void)
53079 #ifdef CONFIG_PROC_DEVICETREE
53080 proc_device_tree_init();
53081 #endif
53082+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53083+#ifdef CONFIG_GRKERNSEC_PROC_USER
53084+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
53085+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53086+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
53087+#endif
53088+#else
53089 proc_mkdir("bus", NULL);
53090+#endif
53091 proc_sys_init();
53092 }
53093
53094diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
53095index 3b7b82a..7dbb571 100644
53096--- a/fs/proc/task_mmu.c
53097+++ b/fs/proc/task_mmu.c
53098@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53099 "VmStk:\t%8lu kB\n"
53100 "VmExe:\t%8lu kB\n"
53101 "VmLib:\t%8lu kB\n"
53102- "VmPTE:\t%8lu kB\n",
53103- hiwater_vm << (PAGE_SHIFT-10),
53104+ "VmPTE:\t%8lu kB\n"
53105+
53106+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53107+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
53108+#endif
53109+
53110+ ,hiwater_vm << (PAGE_SHIFT-10),
53111 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
53112 mm->locked_vm << (PAGE_SHIFT-10),
53113 hiwater_rss << (PAGE_SHIFT-10),
53114 total_rss << (PAGE_SHIFT-10),
53115 data << (PAGE_SHIFT-10),
53116 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
53117- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
53118+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
53119+
53120+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53121+ , mm->context.user_cs_base, mm->context.user_cs_limit
53122+#endif
53123+
53124+ );
53125 }
53126
53127 unsigned long task_vsize(struct mm_struct *mm)
53128@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, void *v)
53129 struct proc_maps_private *priv = m->private;
53130 struct vm_area_struct *vma = v;
53131
53132- vma_stop(priv, vma);
53133+ if (!IS_ERR(vma))
53134+ vma_stop(priv, vma);
53135 if (priv->task)
53136 put_task_struct(priv->task);
53137 }
53138@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
53139 return ret;
53140 }
53141
53142+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53143+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53144+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
53145+ _mm->pax_flags & MF_PAX_SEGMEXEC))
53146+#endif
53147+
53148 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53149 {
53150 struct mm_struct *mm = vma->vm_mm;
53151@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53152 int flags = vma->vm_flags;
53153 unsigned long ino = 0;
53154 unsigned long long pgoff = 0;
53155- unsigned long start;
53156 dev_t dev = 0;
53157 int len;
53158
53159@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53160 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
53161 }
53162
53163- /* We don't show the stack guard page in /proc/maps */
53164- start = vma->vm_start;
53165- if (vma->vm_flags & VM_GROWSDOWN)
53166- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
53167- start += PAGE_SIZE;
53168-
53169 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
53170- start,
53171+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53172+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
53173+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
53174+#else
53175+ vma->vm_start,
53176 vma->vm_end,
53177+#endif
53178 flags & VM_READ ? 'r' : '-',
53179 flags & VM_WRITE ? 'w' : '-',
53180 flags & VM_EXEC ? 'x' : '-',
53181 flags & VM_MAYSHARE ? 's' : 'p',
53182+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53183+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
53184+#else
53185 pgoff,
53186+#endif
53187 MAJOR(dev), MINOR(dev), ino, &len);
53188
53189 /*
53190@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53191 */
53192 if (file) {
53193 pad_len_spaces(m, len);
53194- seq_path(m, &file->f_path, "\n");
53195+ seq_path(m, &file->f_path, "\n\\");
53196 } else {
53197 const char *name = arch_vma_name(vma);
53198 if (!name) {
53199@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53200 if (vma->vm_start <= mm->brk &&
53201 vma->vm_end >= mm->start_brk) {
53202 name = "[heap]";
53203- } else if (vma->vm_start <= mm->start_stack &&
53204- vma->vm_end >= mm->start_stack) {
53205+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
53206+ (vma->vm_start <= mm->start_stack &&
53207+ vma->vm_end >= mm->start_stack)) {
53208 name = "[stack]";
53209 }
53210 } else {
53211@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m, void *v)
53212 };
53213
53214 memset(&mss, 0, sizeof mss);
53215- mss.vma = vma;
53216- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53217- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53218+
53219+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53220+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
53221+#endif
53222+ mss.vma = vma;
53223+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53224+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53225+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53226+ }
53227+#endif
53228
53229 show_map_vma(m, vma);
53230
53231@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m, void *v)
53232 "Swap: %8lu kB\n"
53233 "KernelPageSize: %8lu kB\n"
53234 "MMUPageSize: %8lu kB\n",
53235+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53236+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
53237+#else
53238 (vma->vm_end - vma->vm_start) >> 10,
53239+#endif
53240 mss.resident >> 10,
53241 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
53242 mss.shared_clean >> 10,
53243diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
53244index 8f5c05d..c99c76d 100644
53245--- a/fs/proc/task_nommu.c
53246+++ b/fs/proc/task_nommu.c
53247@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53248 else
53249 bytes += kobjsize(mm);
53250
53251- if (current->fs && current->fs->users > 1)
53252+ if (current->fs && atomic_read(&current->fs->users) > 1)
53253 sbytes += kobjsize(current->fs);
53254 else
53255 bytes += kobjsize(current->fs);
53256@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
53257 if (len < 1)
53258 len = 1;
53259 seq_printf(m, "%*c", len, ' ');
53260- seq_path(m, &file->f_path, "");
53261+ seq_path(m, &file->f_path, "\n\\");
53262 }
53263
53264 seq_putc(m, '\n');
53265diff --git a/fs/readdir.c b/fs/readdir.c
53266index 7723401..30059a6 100644
53267--- a/fs/readdir.c
53268+++ b/fs/readdir.c
53269@@ -16,6 +16,7 @@
53270 #include <linux/security.h>
53271 #include <linux/syscalls.h>
53272 #include <linux/unistd.h>
53273+#include <linux/namei.h>
53274
53275 #include <asm/uaccess.h>
53276
53277@@ -67,6 +68,7 @@ struct old_linux_dirent {
53278
53279 struct readdir_callback {
53280 struct old_linux_dirent __user * dirent;
53281+ struct file * file;
53282 int result;
53283 };
53284
53285@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
53286 buf->result = -EOVERFLOW;
53287 return -EOVERFLOW;
53288 }
53289+
53290+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53291+ return 0;
53292+
53293 buf->result++;
53294 dirent = buf->dirent;
53295 if (!access_ok(VERIFY_WRITE, dirent,
53296@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
53297
53298 buf.result = 0;
53299 buf.dirent = dirent;
53300+ buf.file = file;
53301
53302 error = vfs_readdir(file, fillonedir, &buf);
53303 if (buf.result)
53304@@ -142,6 +149,7 @@ struct linux_dirent {
53305 struct getdents_callback {
53306 struct linux_dirent __user * current_dir;
53307 struct linux_dirent __user * previous;
53308+ struct file * file;
53309 int count;
53310 int error;
53311 };
53312@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
53313 buf->error = -EOVERFLOW;
53314 return -EOVERFLOW;
53315 }
53316+
53317+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53318+ return 0;
53319+
53320 dirent = buf->previous;
53321 if (dirent) {
53322 if (__put_user(offset, &dirent->d_off))
53323@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
53324 buf.previous = NULL;
53325 buf.count = count;
53326 buf.error = 0;
53327+ buf.file = file;
53328
53329 error = vfs_readdir(file, filldir, &buf);
53330 if (error >= 0)
53331@@ -228,6 +241,7 @@ out:
53332 struct getdents_callback64 {
53333 struct linux_dirent64 __user * current_dir;
53334 struct linux_dirent64 __user * previous;
53335+ struct file *file;
53336 int count;
53337 int error;
53338 };
53339@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
53340 buf->error = -EINVAL; /* only used if we fail.. */
53341 if (reclen > buf->count)
53342 return -EINVAL;
53343+
53344+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53345+ return 0;
53346+
53347 dirent = buf->previous;
53348 if (dirent) {
53349 if (__put_user(offset, &dirent->d_off))
53350@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53351
53352 buf.current_dir = dirent;
53353 buf.previous = NULL;
53354+ buf.file = file;
53355 buf.count = count;
53356 buf.error = 0;
53357
53358@@ -297,7 +316,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53359 error = buf.error;
53360 lastdirent = buf.previous;
53361 if (lastdirent) {
53362- typeof(lastdirent->d_off) d_off = file->f_pos;
53363+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
53364 if (__put_user(d_off, &lastdirent->d_off))
53365 error = -EFAULT;
53366 else
53367diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
53368index d42c30c..4fd8718 100644
53369--- a/fs/reiserfs/dir.c
53370+++ b/fs/reiserfs/dir.c
53371@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
53372 struct reiserfs_dir_entry de;
53373 int ret = 0;
53374
53375+ pax_track_stack();
53376+
53377 reiserfs_write_lock(inode->i_sb);
53378
53379 reiserfs_check_lock_depth(inode->i_sb, "readdir");
53380diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
53381index 128d3f7..8840d44 100644
53382--- a/fs/reiserfs/do_balan.c
53383+++ b/fs/reiserfs/do_balan.c
53384@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
53385 return;
53386 }
53387
53388- atomic_inc(&(fs_generation(tb->tb_sb)));
53389+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
53390 do_balance_starts(tb);
53391
53392 /* balance leaf returns 0 except if combining L R and S into
53393diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
53394index 72cb1cc..d0e3181 100644
53395--- a/fs/reiserfs/item_ops.c
53396+++ b/fs/reiserfs/item_ops.c
53397@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_item *vi)
53398 vi->vi_index, vi->vi_type, vi->vi_ih);
53399 }
53400
53401-static struct item_operations stat_data_ops = {
53402+static const struct item_operations stat_data_ops = {
53403 .bytes_number = sd_bytes_number,
53404 .decrement_key = sd_decrement_key,
53405 .is_left_mergeable = sd_is_left_mergeable,
53406@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtual_item *vi)
53407 vi->vi_index, vi->vi_type, vi->vi_ih);
53408 }
53409
53410-static struct item_operations direct_ops = {
53411+static const struct item_operations direct_ops = {
53412 .bytes_number = direct_bytes_number,
53413 .decrement_key = direct_decrement_key,
53414 .is_left_mergeable = direct_is_left_mergeable,
53415@@ -341,7 +341,7 @@ static void indirect_print_vi(struct virtual_item *vi)
53416 vi->vi_index, vi->vi_type, vi->vi_ih);
53417 }
53418
53419-static struct item_operations indirect_ops = {
53420+static const struct item_operations indirect_ops = {
53421 .bytes_number = indirect_bytes_number,
53422 .decrement_key = indirect_decrement_key,
53423 .is_left_mergeable = indirect_is_left_mergeable,
53424@@ -628,7 +628,7 @@ static void direntry_print_vi(struct virtual_item *vi)
53425 printk("\n");
53426 }
53427
53428-static struct item_operations direntry_ops = {
53429+static const struct item_operations direntry_ops = {
53430 .bytes_number = direntry_bytes_number,
53431 .decrement_key = direntry_decrement_key,
53432 .is_left_mergeable = direntry_is_left_mergeable,
53433@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct virtual_item *vi)
53434 "Invalid item type observed, run fsck ASAP");
53435 }
53436
53437-static struct item_operations errcatch_ops = {
53438+static const struct item_operations errcatch_ops = {
53439 errcatch_bytes_number,
53440 errcatch_decrement_key,
53441 errcatch_is_left_mergeable,
53442@@ -746,7 +746,7 @@ static struct item_operations errcatch_ops = {
53443 #error Item types must use disk-format assigned values.
53444 #endif
53445
53446-struct item_operations *item_ops[TYPE_ANY + 1] = {
53447+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
53448 &stat_data_ops,
53449 &indirect_ops,
53450 &direct_ops,
53451diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
53452index b5fe0aa..e0e25c4 100644
53453--- a/fs/reiserfs/journal.c
53454+++ b/fs/reiserfs/journal.c
53455@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
53456 struct buffer_head *bh;
53457 int i, j;
53458
53459+ pax_track_stack();
53460+
53461 bh = __getblk(dev, block, bufsize);
53462 if (buffer_uptodate(bh))
53463 return (bh);
53464diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
53465index 2715791..b8996db 100644
53466--- a/fs/reiserfs/namei.c
53467+++ b/fs/reiserfs/namei.c
53468@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
53469 unsigned long savelink = 1;
53470 struct timespec ctime;
53471
53472+ pax_track_stack();
53473+
53474 /* three balancings: (1) old name removal, (2) new name insertion
53475 and (3) maybe "save" link insertion
53476 stat data updates: (1) old directory,
53477diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
53478index 9229e55..3d2e3b7 100644
53479--- a/fs/reiserfs/procfs.c
53480+++ b/fs/reiserfs/procfs.c
53481@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
53482 "SMALL_TAILS " : "NO_TAILS ",
53483 replay_only(sb) ? "REPLAY_ONLY " : "",
53484 convert_reiserfs(sb) ? "CONV " : "",
53485- atomic_read(&r->s_generation_counter),
53486+ atomic_read_unchecked(&r->s_generation_counter),
53487 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
53488 SF(s_do_balance), SF(s_unneeded_left_neighbor),
53489 SF(s_good_search_by_key_reada), SF(s_bmaps),
53490@@ -309,6 +309,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
53491 struct journal_params *jp = &rs->s_v1.s_journal;
53492 char b[BDEVNAME_SIZE];
53493
53494+ pax_track_stack();
53495+
53496 seq_printf(m, /* on-disk fields */
53497 "jp_journal_1st_block: \t%i\n"
53498 "jp_journal_dev: \t%s[%x]\n"
53499diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
53500index d036ee5..4c7dca1 100644
53501--- a/fs/reiserfs/stree.c
53502+++ b/fs/reiserfs/stree.c
53503@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
53504 int iter = 0;
53505 #endif
53506
53507+ pax_track_stack();
53508+
53509 BUG_ON(!th->t_trans_id);
53510
53511 init_tb_struct(th, &s_del_balance, sb, path,
53512@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
53513 int retval;
53514 int quota_cut_bytes = 0;
53515
53516+ pax_track_stack();
53517+
53518 BUG_ON(!th->t_trans_id);
53519
53520 le_key2cpu_key(&cpu_key, key);
53521@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
53522 int quota_cut_bytes;
53523 loff_t tail_pos = 0;
53524
53525+ pax_track_stack();
53526+
53527 BUG_ON(!th->t_trans_id);
53528
53529 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
53530@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
53531 int retval;
53532 int fs_gen;
53533
53534+ pax_track_stack();
53535+
53536 BUG_ON(!th->t_trans_id);
53537
53538 fs_gen = get_generation(inode->i_sb);
53539@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
53540 int fs_gen = 0;
53541 int quota_bytes = 0;
53542
53543+ pax_track_stack();
53544+
53545 BUG_ON(!th->t_trans_id);
53546
53547 if (inode) { /* Do we count quotas for item? */
53548diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
53549index f0ad05f..af3306f 100644
53550--- a/fs/reiserfs/super.c
53551+++ b/fs/reiserfs/super.c
53552@@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
53553 {.option_name = NULL}
53554 };
53555
53556+ pax_track_stack();
53557+
53558 *blocks = 0;
53559 if (!options || !*options)
53560 /* use default configuration: create tails, journaling on, no
53561diff --git a/fs/select.c b/fs/select.c
53562index fd38ce2..f5381b8 100644
53563--- a/fs/select.c
53564+++ b/fs/select.c
53565@@ -20,6 +20,7 @@
53566 #include <linux/module.h>
53567 #include <linux/slab.h>
53568 #include <linux/poll.h>
53569+#include <linux/security.h>
53570 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
53571 #include <linux/file.h>
53572 #include <linux/fdtable.h>
53573@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
53574 int retval, i, timed_out = 0;
53575 unsigned long slack = 0;
53576
53577+ pax_track_stack();
53578+
53579 rcu_read_lock();
53580 retval = max_select_fd(n, fds);
53581 rcu_read_unlock();
53582@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
53583 /* Allocate small arguments on the stack to save memory and be faster */
53584 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
53585
53586+ pax_track_stack();
53587+
53588 ret = -EINVAL;
53589 if (n < 0)
53590 goto out_nofds;
53591@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
53592 struct poll_list *walk = head;
53593 unsigned long todo = nfds;
53594
53595+ pax_track_stack();
53596+
53597+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
53598 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
53599 return -EINVAL;
53600
53601diff --git a/fs/seq_file.c b/fs/seq_file.c
53602index eae7d9d..679f099 100644
53603--- a/fs/seq_file.c
53604+++ b/fs/seq_file.c
53605@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53606 return 0;
53607 }
53608 if (!m->buf) {
53609- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53610+ m->size = PAGE_SIZE;
53611+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53612 if (!m->buf)
53613 return -ENOMEM;
53614 }
53615@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53616 Eoverflow:
53617 m->op->stop(m, p);
53618 kfree(m->buf);
53619- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53620+ m->size <<= 1;
53621+ m->buf = kmalloc(m->size, GFP_KERNEL);
53622 return !m->buf ? -ENOMEM : -EAGAIN;
53623 }
53624
53625@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53626 m->version = file->f_version;
53627 /* grab buffer if we didn't have one */
53628 if (!m->buf) {
53629- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53630+ m->size = PAGE_SIZE;
53631+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53632 if (!m->buf)
53633 goto Enomem;
53634 }
53635@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53636 goto Fill;
53637 m->op->stop(m, p);
53638 kfree(m->buf);
53639- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53640+ m->size <<= 1;
53641+ m->buf = kmalloc(m->size, GFP_KERNEL);
53642 if (!m->buf)
53643 goto Enomem;
53644 m->count = 0;
53645@@ -551,7 +555,7 @@ static void single_stop(struct seq_file *p, void *v)
53646 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
53647 void *data)
53648 {
53649- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
53650+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
53651 int res = -ENOMEM;
53652
53653 if (op) {
53654diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
53655index 71c29b6..54694dd 100644
53656--- a/fs/smbfs/proc.c
53657+++ b/fs/smbfs/proc.c
53658@@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *server, struct smb_nls_codepage *cp)
53659
53660 out:
53661 if (server->local_nls != NULL && server->remote_nls != NULL)
53662- server->ops->convert = convert_cp;
53663+ *(void **)&server->ops->convert = convert_cp;
53664 else
53665- server->ops->convert = convert_memcpy;
53666+ *(void **)&server->ops->convert = convert_memcpy;
53667
53668 smb_unlock_server(server);
53669 return n;
53670@@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
53671
53672 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
53673 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
53674- server->ops->getattr = smb_proc_getattr_core;
53675+ *(void **)&server->ops->getattr = smb_proc_getattr_core;
53676 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
53677- server->ops->getattr = smb_proc_getattr_ff;
53678+ *(void **)&server->ops->getattr = smb_proc_getattr_ff;
53679 }
53680
53681 /* Decode server capabilities */
53682@@ -3439,7 +3439,7 @@ out:
53683 static void
53684 install_ops(struct smb_ops *dst, struct smb_ops *src)
53685 {
53686- memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53687+ memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53688 }
53689
53690 /* < LANMAN2 */
53691diff --git a/fs/smbfs/symlink.c b/fs/smbfs/symlink.c
53692index 00b2909..2ace383 100644
53693--- a/fs/smbfs/symlink.c
53694+++ b/fs/smbfs/symlink.c
53695@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dentry *dentry, struct nameidata *nd)
53696
53697 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53698 {
53699- char *s = nd_get_link(nd);
53700+ const char *s = nd_get_link(nd);
53701 if (!IS_ERR(s))
53702 __putname(s);
53703 }
53704diff --git a/fs/splice.c b/fs/splice.c
53705index bb92b7c..5aa72b0 100644
53706--- a/fs/splice.c
53707+++ b/fs/splice.c
53708@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
53709 pipe_lock(pipe);
53710
53711 for (;;) {
53712- if (!pipe->readers) {
53713+ if (!atomic_read(&pipe->readers)) {
53714 send_sig(SIGPIPE, current, 0);
53715 if (!ret)
53716 ret = -EPIPE;
53717@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
53718 do_wakeup = 0;
53719 }
53720
53721- pipe->waiting_writers++;
53722+ atomic_inc(&pipe->waiting_writers);
53723 pipe_wait(pipe);
53724- pipe->waiting_writers--;
53725+ atomic_dec(&pipe->waiting_writers);
53726 }
53727
53728 pipe_unlock(pipe);
53729@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
53730 .spd_release = spd_release_page,
53731 };
53732
53733+ pax_track_stack();
53734+
53735 index = *ppos >> PAGE_CACHE_SHIFT;
53736 loff = *ppos & ~PAGE_CACHE_MASK;
53737 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
53738@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
53739 old_fs = get_fs();
53740 set_fs(get_ds());
53741 /* The cast to a user pointer is valid due to the set_fs() */
53742- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
53743+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
53744 set_fs(old_fs);
53745
53746 return res;
53747@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
53748 old_fs = get_fs();
53749 set_fs(get_ds());
53750 /* The cast to a user pointer is valid due to the set_fs() */
53751- res = vfs_write(file, (const char __user *)buf, count, &pos);
53752+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
53753 set_fs(old_fs);
53754
53755 return res;
53756@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53757 .spd_release = spd_release_page,
53758 };
53759
53760+ pax_track_stack();
53761+
53762 index = *ppos >> PAGE_CACHE_SHIFT;
53763 offset = *ppos & ~PAGE_CACHE_MASK;
53764 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
53765@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53766 goto err;
53767
53768 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
53769- vec[i].iov_base = (void __user *) page_address(page);
53770+ vec[i].iov_base = (__force void __user *) page_address(page);
53771 vec[i].iov_len = this_len;
53772 pages[i] = page;
53773 spd.nr_pages++;
53774@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
53775 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
53776 {
53777 while (!pipe->nrbufs) {
53778- if (!pipe->writers)
53779+ if (!atomic_read(&pipe->writers))
53780 return 0;
53781
53782- if (!pipe->waiting_writers && sd->num_spliced)
53783+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
53784 return 0;
53785
53786 if (sd->flags & SPLICE_F_NONBLOCK)
53787@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
53788 * out of the pipe right after the splice_to_pipe(). So set
53789 * PIPE_READERS appropriately.
53790 */
53791- pipe->readers = 1;
53792+ atomic_set(&pipe->readers, 1);
53793
53794 current->splice_pipe = pipe;
53795 }
53796@@ -1593,6 +1597,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
53797 .spd_release = spd_release_page,
53798 };
53799
53800+ pax_track_stack();
53801+
53802 pipe = pipe_info(file->f_path.dentry->d_inode);
53803 if (!pipe)
53804 return -EBADF;
53805@@ -1701,9 +1707,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53806 ret = -ERESTARTSYS;
53807 break;
53808 }
53809- if (!pipe->writers)
53810+ if (!atomic_read(&pipe->writers))
53811 break;
53812- if (!pipe->waiting_writers) {
53813+ if (!atomic_read(&pipe->waiting_writers)) {
53814 if (flags & SPLICE_F_NONBLOCK) {
53815 ret = -EAGAIN;
53816 break;
53817@@ -1735,7 +1741,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53818 pipe_lock(pipe);
53819
53820 while (pipe->nrbufs >= PIPE_BUFFERS) {
53821- if (!pipe->readers) {
53822+ if (!atomic_read(&pipe->readers)) {
53823 send_sig(SIGPIPE, current, 0);
53824 ret = -EPIPE;
53825 break;
53826@@ -1748,9 +1754,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53827 ret = -ERESTARTSYS;
53828 break;
53829 }
53830- pipe->waiting_writers++;
53831+ atomic_inc(&pipe->waiting_writers);
53832 pipe_wait(pipe);
53833- pipe->waiting_writers--;
53834+ atomic_dec(&pipe->waiting_writers);
53835 }
53836
53837 pipe_unlock(pipe);
53838@@ -1786,14 +1792,14 @@ retry:
53839 pipe_double_lock(ipipe, opipe);
53840
53841 do {
53842- if (!opipe->readers) {
53843+ if (!atomic_read(&opipe->readers)) {
53844 send_sig(SIGPIPE, current, 0);
53845 if (!ret)
53846 ret = -EPIPE;
53847 break;
53848 }
53849
53850- if (!ipipe->nrbufs && !ipipe->writers)
53851+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53852 break;
53853
53854 /*
53855@@ -1893,7 +1899,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53856 pipe_double_lock(ipipe, opipe);
53857
53858 do {
53859- if (!opipe->readers) {
53860+ if (!atomic_read(&opipe->readers)) {
53861 send_sig(SIGPIPE, current, 0);
53862 if (!ret)
53863 ret = -EPIPE;
53864@@ -1938,7 +1944,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53865 * return EAGAIN if we have the potential of some data in the
53866 * future, otherwise just return 0
53867 */
53868- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53869+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53870 ret = -EAGAIN;
53871
53872 pipe_unlock(ipipe);
53873diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53874index 7118a38..70af853 100644
53875--- a/fs/sysfs/file.c
53876+++ b/fs/sysfs/file.c
53877@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53878
53879 struct sysfs_open_dirent {
53880 atomic_t refcnt;
53881- atomic_t event;
53882+ atomic_unchecked_t event;
53883 wait_queue_head_t poll;
53884 struct list_head buffers; /* goes through sysfs_buffer.list */
53885 };
53886@@ -53,7 +53,7 @@ struct sysfs_buffer {
53887 size_t count;
53888 loff_t pos;
53889 char * page;
53890- struct sysfs_ops * ops;
53891+ const struct sysfs_ops * ops;
53892 struct mutex mutex;
53893 int needs_read_fill;
53894 int event;
53895@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53896 {
53897 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
53898 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53899- struct sysfs_ops * ops = buffer->ops;
53900+ const struct sysfs_ops * ops = buffer->ops;
53901 int ret = 0;
53902 ssize_t count;
53903
53904@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53905 if (!sysfs_get_active_two(attr_sd))
53906 return -ENODEV;
53907
53908- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53909+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53910 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53911
53912 sysfs_put_active_two(attr_sd);
53913@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
53914 {
53915 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
53916 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53917- struct sysfs_ops * ops = buffer->ops;
53918+ const struct sysfs_ops * ops = buffer->ops;
53919 int rc;
53920
53921 /* need attr_sd for attr and ops, its parent for kobj */
53922@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53923 return -ENOMEM;
53924
53925 atomic_set(&new_od->refcnt, 0);
53926- atomic_set(&new_od->event, 1);
53927+ atomic_set_unchecked(&new_od->event, 1);
53928 init_waitqueue_head(&new_od->poll);
53929 INIT_LIST_HEAD(&new_od->buffers);
53930 goto retry;
53931@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
53932 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
53933 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
53934 struct sysfs_buffer *buffer;
53935- struct sysfs_ops *ops;
53936+ const struct sysfs_ops *ops;
53937 int error = -EACCES;
53938 char *p;
53939
53940@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53941
53942 sysfs_put_active_two(attr_sd);
53943
53944- if (buffer->event != atomic_read(&od->event))
53945+ if (buffer->event != atomic_read_unchecked(&od->event))
53946 goto trigger;
53947
53948 return DEFAULT_POLLMASK;
53949@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53950
53951 od = sd->s_attr.open;
53952 if (od) {
53953- atomic_inc(&od->event);
53954+ atomic_inc_unchecked(&od->event);
53955 wake_up_interruptible(&od->poll);
53956 }
53957
53958diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
53959index 4974995..c26609c 100644
53960--- a/fs/sysfs/mount.c
53961+++ b/fs/sysfs/mount.c
53962@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
53963 .s_name = "",
53964 .s_count = ATOMIC_INIT(1),
53965 .s_flags = SYSFS_DIR,
53966+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53967+ .s_mode = S_IFDIR | S_IRWXU,
53968+#else
53969 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
53970+#endif
53971 .s_ino = 1,
53972 };
53973
53974diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53975index c5081ad..342ea86 100644
53976--- a/fs/sysfs/symlink.c
53977+++ b/fs/sysfs/symlink.c
53978@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53979
53980 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53981 {
53982- char *page = nd_get_link(nd);
53983+ const char *page = nd_get_link(nd);
53984 if (!IS_ERR(page))
53985 free_page((unsigned long)page);
53986 }
53987diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
53988index 1e06853..b06d325 100644
53989--- a/fs/udf/balloc.c
53990+++ b/fs/udf/balloc.c
53991@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
53992
53993 mutex_lock(&sbi->s_alloc_mutex);
53994 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
53995- if (bloc->logicalBlockNum < 0 ||
53996- (bloc->logicalBlockNum + count) >
53997- partmap->s_partition_len) {
53998+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
53999 udf_debug("%d < %d || %d + %d > %d\n",
54000 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
54001 count, partmap->s_partition_len);
54002@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct super_block *sb,
54003
54004 mutex_lock(&sbi->s_alloc_mutex);
54005 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54006- if (bloc->logicalBlockNum < 0 ||
54007- (bloc->logicalBlockNum + count) >
54008- partmap->s_partition_len) {
54009+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54010 udf_debug("%d < %d || %d + %d > %d\n",
54011 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
54012 partmap->s_partition_len);
54013diff --git a/fs/udf/inode.c b/fs/udf/inode.c
54014index 6d24c2c..fff470f 100644
54015--- a/fs/udf/inode.c
54016+++ b/fs/udf/inode.c
54017@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
54018 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
54019 int lastblock = 0;
54020
54021+ pax_track_stack();
54022+
54023 prev_epos.offset = udf_file_entry_alloc_offset(inode);
54024 prev_epos.block = iinfo->i_location;
54025 prev_epos.bh = NULL;
54026diff --git a/fs/udf/misc.c b/fs/udf/misc.c
54027index 9215700..bf1f68e 100644
54028--- a/fs/udf/misc.c
54029+++ b/fs/udf/misc.c
54030@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
54031
54032 u8 udf_tag_checksum(const struct tag *t)
54033 {
54034- u8 *data = (u8 *)t;
54035+ const u8 *data = (const u8 *)t;
54036 u8 checksum = 0;
54037 int i;
54038 for (i = 0; i < sizeof(struct tag); ++i)
54039diff --git a/fs/utimes.c b/fs/utimes.c
54040index e4c75db..b4df0e0 100644
54041--- a/fs/utimes.c
54042+++ b/fs/utimes.c
54043@@ -1,6 +1,7 @@
54044 #include <linux/compiler.h>
54045 #include <linux/file.h>
54046 #include <linux/fs.h>
54047+#include <linux/security.h>
54048 #include <linux/linkage.h>
54049 #include <linux/mount.h>
54050 #include <linux/namei.h>
54051@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
54052 goto mnt_drop_write_and_out;
54053 }
54054 }
54055+
54056+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
54057+ error = -EACCES;
54058+ goto mnt_drop_write_and_out;
54059+ }
54060+
54061 mutex_lock(&inode->i_mutex);
54062 error = notify_change(path->dentry, &newattrs);
54063 mutex_unlock(&inode->i_mutex);
54064diff --git a/fs/xattr.c b/fs/xattr.c
54065index 6d4f6d3..cda3958 100644
54066--- a/fs/xattr.c
54067+++ b/fs/xattr.c
54068@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
54069 * Extended attribute SET operations
54070 */
54071 static long
54072-setxattr(struct dentry *d, const char __user *name, const void __user *value,
54073+setxattr(struct path *path, const char __user *name, const void __user *value,
54074 size_t size, int flags)
54075 {
54076 int error;
54077@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
54078 return PTR_ERR(kvalue);
54079 }
54080
54081- error = vfs_setxattr(d, kname, kvalue, size, flags);
54082+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
54083+ error = -EACCES;
54084+ goto out;
54085+ }
54086+
54087+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
54088+out:
54089 kfree(kvalue);
54090 return error;
54091 }
54092@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
54093 return error;
54094 error = mnt_want_write(path.mnt);
54095 if (!error) {
54096- error = setxattr(path.dentry, name, value, size, flags);
54097+ error = setxattr(&path, name, value, size, flags);
54098 mnt_drop_write(path.mnt);
54099 }
54100 path_put(&path);
54101@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
54102 return error;
54103 error = mnt_want_write(path.mnt);
54104 if (!error) {
54105- error = setxattr(path.dentry, name, value, size, flags);
54106+ error = setxattr(&path, name, value, size, flags);
54107 mnt_drop_write(path.mnt);
54108 }
54109 path_put(&path);
54110@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
54111 const void __user *,value, size_t, size, int, flags)
54112 {
54113 struct file *f;
54114- struct dentry *dentry;
54115 int error = -EBADF;
54116
54117 f = fget(fd);
54118 if (!f)
54119 return error;
54120- dentry = f->f_path.dentry;
54121- audit_inode(NULL, dentry);
54122+ audit_inode(NULL, f->f_path.dentry);
54123 error = mnt_want_write_file(f);
54124 if (!error) {
54125- error = setxattr(dentry, name, value, size, flags);
54126+ error = setxattr(&f->f_path, name, value, size, flags);
54127 mnt_drop_write(f->f_path.mnt);
54128 }
54129 fput(f);
54130diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
54131index c6ad7c7..f2847a7 100644
54132--- a/fs/xattr_acl.c
54133+++ b/fs/xattr_acl.c
54134@@ -17,8 +17,8 @@
54135 struct posix_acl *
54136 posix_acl_from_xattr(const void *value, size_t size)
54137 {
54138- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
54139- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
54140+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
54141+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
54142 int count;
54143 struct posix_acl *acl;
54144 struct posix_acl_entry *acl_e;
54145diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
54146index 942362f..88f96f5 100644
54147--- a/fs/xfs/linux-2.6/xfs_ioctl.c
54148+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
54149@@ -134,7 +134,7 @@ xfs_find_handle(
54150 }
54151
54152 error = -EFAULT;
54153- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
54154+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
54155 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
54156 goto out_put;
54157
54158@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
54159 if (IS_ERR(dentry))
54160 return PTR_ERR(dentry);
54161
54162- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
54163+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
54164 if (!kbuf)
54165 goto out_dput;
54166
54167@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
54168 xfs_mount_t *mp,
54169 void __user *arg)
54170 {
54171- xfs_fsop_geom_t fsgeo;
54172+ xfs_fsop_geom_t fsgeo;
54173 int error;
54174
54175 error = xfs_fs_geometry(mp, &fsgeo, 3);
54176diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
54177index bad485a..479bd32 100644
54178--- a/fs/xfs/linux-2.6/xfs_ioctl32.c
54179+++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
54180@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
54181 xfs_fsop_geom_t fsgeo;
54182 int error;
54183
54184+ memset(&fsgeo, 0, sizeof(fsgeo));
54185 error = xfs_fs_geometry(mp, &fsgeo, 3);
54186 if (error)
54187 return -error;
54188diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
54189index 1f3b4b8..6102f6d 100644
54190--- a/fs/xfs/linux-2.6/xfs_iops.c
54191+++ b/fs/xfs/linux-2.6/xfs_iops.c
54192@@ -468,7 +468,7 @@ xfs_vn_put_link(
54193 struct nameidata *nd,
54194 void *p)
54195 {
54196- char *s = nd_get_link(nd);
54197+ const char *s = nd_get_link(nd);
54198
54199 if (!IS_ERR(s))
54200 kfree(s);
54201diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
54202index 8971fb0..5fc1eb2 100644
54203--- a/fs/xfs/xfs_bmap.c
54204+++ b/fs/xfs/xfs_bmap.c
54205@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
54206 int nmap,
54207 int ret_nmap);
54208 #else
54209-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
54210+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
54211 #endif /* DEBUG */
54212
54213 #if defined(XFS_RW_TRACE)
54214diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
54215index e89734e..5e84d8d 100644
54216--- a/fs/xfs/xfs_dir2_sf.c
54217+++ b/fs/xfs/xfs_dir2_sf.c
54218@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
54219 }
54220
54221 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
54222- if (filldir(dirent, sfep->name, sfep->namelen,
54223+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
54224+ char name[sfep->namelen];
54225+ memcpy(name, sfep->name, sfep->namelen);
54226+ if (filldir(dirent, name, sfep->namelen,
54227+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
54228+ *offset = off & 0x7fffffff;
54229+ return 0;
54230+ }
54231+ } else if (filldir(dirent, sfep->name, sfep->namelen,
54232 off & 0x7fffffff, ino, DT_UNKNOWN)) {
54233 *offset = off & 0x7fffffff;
54234 return 0;
54235diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
54236index 8f32f50..859e8a3 100644
54237--- a/fs/xfs/xfs_vnodeops.c
54238+++ b/fs/xfs/xfs_vnodeops.c
54239@@ -564,13 +564,17 @@ xfs_readlink(
54240
54241 xfs_ilock(ip, XFS_ILOCK_SHARED);
54242
54243- ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFLNK);
54244- ASSERT(ip->i_d.di_size <= MAXPATHLEN);
54245-
54246 pathlen = ip->i_d.di_size;
54247 if (!pathlen)
54248 goto out;
54249
54250+ if (pathlen > MAXPATHLEN) {
54251+ xfs_fs_cmn_err(CE_ALERT, mp, "%s: inode (%llu) symlink length (%d) too long",
54252+ __func__, (unsigned long long)ip->i_ino, pathlen);
54253+ ASSERT(0);
54254+ return XFS_ERROR(EFSCORRUPTED);
54255+ }
54256+
54257 if (ip->i_df.if_flags & XFS_IFINLINE) {
54258 memcpy(link, ip->i_df.if_u1.if_data, pathlen);
54259 link[pathlen] = '\0';
54260diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
54261new file mode 100644
54262index 0000000..f27a8e8
54263--- /dev/null
54264+++ b/grsecurity/Kconfig
54265@@ -0,0 +1,1036 @@
54266+#
54267+# grecurity configuration
54268+#
54269+
54270+menu "Grsecurity"
54271+
54272+config GRKERNSEC
54273+ bool "Grsecurity"
54274+ select CRYPTO
54275+ select CRYPTO_SHA256
54276+ help
54277+ If you say Y here, you will be able to configure many features
54278+ that will enhance the security of your system. It is highly
54279+ recommended that you say Y here and read through the help
54280+ for each option so that you fully understand the features and
54281+ can evaluate their usefulness for your machine.
54282+
54283+choice
54284+ prompt "Security Level"
54285+ depends on GRKERNSEC
54286+ default GRKERNSEC_CUSTOM
54287+
54288+config GRKERNSEC_LOW
54289+ bool "Low"
54290+ select GRKERNSEC_LINK
54291+ select GRKERNSEC_FIFO
54292+ select GRKERNSEC_RANDNET
54293+ select GRKERNSEC_DMESG
54294+ select GRKERNSEC_CHROOT
54295+ select GRKERNSEC_CHROOT_CHDIR
54296+
54297+ help
54298+ If you choose this option, several of the grsecurity options will
54299+ be enabled that will give you greater protection against a number
54300+ of attacks, while assuring that none of your software will have any
54301+ conflicts with the additional security measures. If you run a lot
54302+ of unusual software, or you are having problems with the higher
54303+ security levels, you should say Y here. With this option, the
54304+ following features are enabled:
54305+
54306+ - Linking restrictions
54307+ - FIFO restrictions
54308+ - Restricted dmesg
54309+ - Enforced chdir("/") on chroot
54310+ - Runtime module disabling
54311+
54312+config GRKERNSEC_MEDIUM
54313+ bool "Medium"
54314+ select PAX
54315+ select PAX_EI_PAX
54316+ select PAX_PT_PAX_FLAGS
54317+ select PAX_HAVE_ACL_FLAGS
54318+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54319+ select GRKERNSEC_CHROOT
54320+ select GRKERNSEC_CHROOT_SYSCTL
54321+ select GRKERNSEC_LINK
54322+ select GRKERNSEC_FIFO
54323+ select GRKERNSEC_DMESG
54324+ select GRKERNSEC_RANDNET
54325+ select GRKERNSEC_FORKFAIL
54326+ select GRKERNSEC_TIME
54327+ select GRKERNSEC_SIGNAL
54328+ select GRKERNSEC_CHROOT
54329+ select GRKERNSEC_CHROOT_UNIX
54330+ select GRKERNSEC_CHROOT_MOUNT
54331+ select GRKERNSEC_CHROOT_PIVOT
54332+ select GRKERNSEC_CHROOT_DOUBLE
54333+ select GRKERNSEC_CHROOT_CHDIR
54334+ select GRKERNSEC_CHROOT_MKNOD
54335+ select GRKERNSEC_PROC
54336+ select GRKERNSEC_PROC_USERGROUP
54337+ select PAX_RANDUSTACK
54338+ select PAX_ASLR
54339+ select PAX_RANDMMAP
54340+ select PAX_REFCOUNT if (X86 || SPARC64)
54341+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54342+
54343+ help
54344+ If you say Y here, several features in addition to those included
54345+ in the low additional security level will be enabled. These
54346+ features provide even more security to your system, though in rare
54347+ cases they may be incompatible with very old or poorly written
54348+ software. If you enable this option, make sure that your auth
54349+ service (identd) is running as gid 1001. With this option,
54350+ the following features (in addition to those provided in the
54351+ low additional security level) will be enabled:
54352+
54353+ - Failed fork logging
54354+ - Time change logging
54355+ - Signal logging
54356+ - Deny mounts in chroot
54357+ - Deny double chrooting
54358+ - Deny sysctl writes in chroot
54359+ - Deny mknod in chroot
54360+ - Deny access to abstract AF_UNIX sockets out of chroot
54361+ - Deny pivot_root in chroot
54362+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
54363+ - /proc restrictions with special GID set to 10 (usually wheel)
54364+ - Address Space Layout Randomization (ASLR)
54365+ - Prevent exploitation of most refcount overflows
54366+ - Bounds checking of copying between the kernel and userland
54367+
54368+config GRKERNSEC_HIGH
54369+ bool "High"
54370+ select GRKERNSEC_LINK
54371+ select GRKERNSEC_FIFO
54372+ select GRKERNSEC_DMESG
54373+ select GRKERNSEC_FORKFAIL
54374+ select GRKERNSEC_TIME
54375+ select GRKERNSEC_SIGNAL
54376+ select GRKERNSEC_CHROOT
54377+ select GRKERNSEC_CHROOT_SHMAT
54378+ select GRKERNSEC_CHROOT_UNIX
54379+ select GRKERNSEC_CHROOT_MOUNT
54380+ select GRKERNSEC_CHROOT_FCHDIR
54381+ select GRKERNSEC_CHROOT_PIVOT
54382+ select GRKERNSEC_CHROOT_DOUBLE
54383+ select GRKERNSEC_CHROOT_CHDIR
54384+ select GRKERNSEC_CHROOT_MKNOD
54385+ select GRKERNSEC_CHROOT_CAPS
54386+ select GRKERNSEC_CHROOT_SYSCTL
54387+ select GRKERNSEC_CHROOT_FINDTASK
54388+ select GRKERNSEC_SYSFS_RESTRICT
54389+ select GRKERNSEC_PROC
54390+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54391+ select GRKERNSEC_HIDESYM
54392+ select GRKERNSEC_BRUTE
54393+ select GRKERNSEC_PROC_USERGROUP
54394+ select GRKERNSEC_KMEM
54395+ select GRKERNSEC_RESLOG
54396+ select GRKERNSEC_RANDNET
54397+ select GRKERNSEC_PROC_ADD
54398+ select GRKERNSEC_CHROOT_CHMOD
54399+ select GRKERNSEC_CHROOT_NICE
54400+ select GRKERNSEC_AUDIT_MOUNT
54401+ select GRKERNSEC_MODHARDEN if (MODULES)
54402+ select GRKERNSEC_HARDEN_PTRACE
54403+ select GRKERNSEC_VM86 if (X86_32)
54404+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
54405+ select PAX
54406+ select PAX_RANDUSTACK
54407+ select PAX_ASLR
54408+ select PAX_RANDMMAP
54409+ select PAX_NOEXEC
54410+ select PAX_MPROTECT
54411+ select PAX_EI_PAX
54412+ select PAX_PT_PAX_FLAGS
54413+ select PAX_HAVE_ACL_FLAGS
54414+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
54415+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
54416+ select PAX_RANDKSTACK if (X86_TSC && X86)
54417+ select PAX_SEGMEXEC if (X86_32)
54418+ select PAX_PAGEEXEC
54419+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
54420+ select PAX_EMUTRAMP if (PARISC)
54421+ select PAX_EMUSIGRT if (PARISC)
54422+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
54423+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
54424+ select PAX_REFCOUNT if (X86 || SPARC64)
54425+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54426+ help
54427+ If you say Y here, many of the features of grsecurity will be
54428+ enabled, which will protect you against many kinds of attacks
54429+ against your system. The heightened security comes at a cost
54430+ of an increased chance of incompatibilities with rare software
54431+ on your machine. Since this security level enables PaX, you should
54432+ view <http://pax.grsecurity.net> and read about the PaX
54433+ project. While you are there, download chpax and run it on
54434+ binaries that cause problems with PaX. Also remember that
54435+ since the /proc restrictions are enabled, you must run your
54436+ identd as gid 1001. This security level enables the following
54437+ features in addition to those listed in the low and medium
54438+ security levels:
54439+
54440+ - Additional /proc restrictions
54441+ - Chmod restrictions in chroot
54442+ - No signals, ptrace, or viewing of processes outside of chroot
54443+ - Capability restrictions in chroot
54444+ - Deny fchdir out of chroot
54445+ - Priority restrictions in chroot
54446+ - Segmentation-based implementation of PaX
54447+ - Mprotect restrictions
54448+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
54449+ - Kernel stack randomization
54450+ - Mount/unmount/remount logging
54451+ - Kernel symbol hiding
54452+ - Hardening of module auto-loading
54453+ - Ptrace restrictions
54454+ - Restricted vm86 mode
54455+ - Restricted sysfs/debugfs
54456+ - Active kernel exploit response
54457+
54458+config GRKERNSEC_CUSTOM
54459+ bool "Custom"
54460+ help
54461+ If you say Y here, you will be able to configure every grsecurity
54462+ option, which allows you to enable many more features that aren't
54463+ covered in the basic security levels. These additional features
54464+ include TPE, socket restrictions, and the sysctl system for
54465+ grsecurity. It is advised that you read through the help for
54466+ each option to determine its usefulness in your situation.
54467+
54468+endchoice
54469+
54470+menu "Address Space Protection"
54471+depends on GRKERNSEC
54472+
54473+config GRKERNSEC_KMEM
54474+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
54475+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
54476+ help
54477+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
54478+ be written to or read from to modify or leak the contents of the running
54479+ kernel. /dev/port will also not be allowed to be opened. If you have module
54480+ support disabled, enabling this will close up four ways that are
54481+ currently used to insert malicious code into the running kernel.
54482+ Even with all these features enabled, we still highly recommend that
54483+ you use the RBAC system, as it is still possible for an attacker to
54484+ modify the running kernel through privileged I/O granted by ioperm/iopl.
54485+ If you are not using XFree86, you may be able to stop this additional
54486+ case by enabling the 'Disable privileged I/O' option. Though nothing
54487+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
54488+ but only to video memory, which is the only writing we allow in this
54489+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
54490+ not be allowed to mprotect it with PROT_WRITE later.
54491+ It is highly recommended that you say Y here if you meet all the
54492+ conditions above.
54493+
54494+config GRKERNSEC_VM86
54495+ bool "Restrict VM86 mode"
54496+ depends on X86_32
54497+
54498+ help
54499+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
54500+ make use of a special execution mode on 32bit x86 processors called
54501+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
54502+ video cards and will still work with this option enabled. The purpose
54503+ of the option is to prevent exploitation of emulation errors in
54504+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
54505+ Nearly all users should be able to enable this option.
54506+
54507+config GRKERNSEC_IO
54508+ bool "Disable privileged I/O"
54509+ depends on X86
54510+ select RTC_CLASS
54511+ select RTC_INTF_DEV
54512+ select RTC_DRV_CMOS
54513+
54514+ help
54515+ If you say Y here, all ioperm and iopl calls will return an error.
54516+ Ioperm and iopl can be used to modify the running kernel.
54517+ Unfortunately, some programs need this access to operate properly,
54518+ the most notable of which are XFree86 and hwclock. hwclock can be
54519+ remedied by having RTC support in the kernel, so real-time
54520+ clock support is enabled if this option is enabled, to ensure
54521+ that hwclock operates correctly. XFree86 still will not
54522+ operate correctly with this option enabled, so DO NOT CHOOSE Y
54523+ IF YOU USE XFree86. If you use XFree86 and you still want to
54524+ protect your kernel against modification, use the RBAC system.
54525+
54526+config GRKERNSEC_PROC_MEMMAP
54527+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
54528+ default y if (PAX_NOEXEC || PAX_ASLR)
54529+ depends on PAX_NOEXEC || PAX_ASLR
54530+ help
54531+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
54532+ give no information about the addresses of its mappings if
54533+ PaX features that rely on random addresses are enabled on the task.
54534+ If you use PaX it is greatly recommended that you say Y here as it
54535+ closes up a hole that makes the full ASLR useless for suid
54536+ binaries.
54537+
54538+config GRKERNSEC_BRUTE
54539+ bool "Deter exploit bruteforcing"
54540+ help
54541+ If you say Y here, attempts to bruteforce exploits against forking
54542+ daemons such as apache or sshd, as well as against suid/sgid binaries
54543+ will be deterred. When a child of a forking daemon is killed by PaX
54544+ or crashes due to an illegal instruction or other suspicious signal,
54545+ the parent process will be delayed 30 seconds upon every subsequent
54546+ fork until the administrator is able to assess the situation and
54547+ restart the daemon.
54548+ In the suid/sgid case, the attempt is logged, the user has all their
54549+ processes terminated, and they are prevented from executing any further
54550+ processes for 15 minutes.
54551+ It is recommended that you also enable signal logging in the auditing
54552+ section so that logs are generated when a process triggers a suspicious
54553+ signal.
54554+ If the sysctl option is enabled, a sysctl option with name
54555+ "deter_bruteforce" is created.
54556+
54557+config GRKERNSEC_MODHARDEN
54558+ bool "Harden module auto-loading"
54559+ depends on MODULES
54560+ help
54561+ If you say Y here, module auto-loading in response to use of some
54562+ feature implemented by an unloaded module will be restricted to
54563+ root users. Enabling this option helps defend against attacks
54564+ by unprivileged users who abuse the auto-loading behavior to
54565+ cause a vulnerable module to load that is then exploited.
54566+
54567+ If this option prevents a legitimate use of auto-loading for a
54568+ non-root user, the administrator can execute modprobe manually
54569+ with the exact name of the module mentioned in the alert log.
54570+ Alternatively, the administrator can add the module to the list
54571+ of modules loaded at boot by modifying init scripts.
54572+
54573+ Modification of init scripts will most likely be needed on
54574+ Ubuntu servers with encrypted home directory support enabled,
54575+ as the first non-root user logging in will cause the ecb(aes),
54576+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
54577+
54578+config GRKERNSEC_HIDESYM
54579+ bool "Hide kernel symbols"
54580+ help
54581+ If you say Y here, getting information on loaded modules, and
54582+ displaying all kernel symbols through a syscall will be restricted
54583+ to users with CAP_SYS_MODULE. For software compatibility reasons,
54584+ /proc/kallsyms will be restricted to the root user. The RBAC
54585+ system can hide that entry even from root.
54586+
54587+ This option also prevents leaking of kernel addresses through
54588+ several /proc entries.
54589+
54590+ Note that this option is only effective provided the following
54591+ conditions are met:
54592+ 1) The kernel using grsecurity is not precompiled by some distribution
54593+ 2) You have also enabled GRKERNSEC_DMESG
54594+ 3) You are using the RBAC system and hiding other files such as your
54595+ kernel image and System.map. Alternatively, enabling this option
54596+ causes the permissions on /boot, /lib/modules, and the kernel
54597+ source directory to change at compile time to prevent
54598+ reading by non-root users.
54599+ If the above conditions are met, this option will aid in providing a
54600+ useful protection against local kernel exploitation of overflows
54601+ and arbitrary read/write vulnerabilities.
54602+
54603+config GRKERNSEC_KERN_LOCKOUT
54604+ bool "Active kernel exploit response"
54605+ depends on X86 || ARM || PPC || SPARC
54606+ help
54607+ If you say Y here, when a PaX alert is triggered due to suspicious
54608+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
54609+ or an OOPs occurs due to bad memory accesses, instead of just
54610+ terminating the offending process (and potentially allowing
54611+ a subsequent exploit from the same user), we will take one of two
54612+ actions:
54613+ If the user was root, we will panic the system
54614+ If the user was non-root, we will log the attempt, terminate
54615+ all processes owned by the user, then prevent them from creating
54616+ any new processes until the system is restarted
54617+ This deters repeated kernel exploitation/bruteforcing attempts
54618+ and is useful for later forensics.
54619+
54620+endmenu
54621+menu "Role Based Access Control Options"
54622+depends on GRKERNSEC
54623+
54624+config GRKERNSEC_RBAC_DEBUG
54625+ bool
54626+
54627+config GRKERNSEC_NO_RBAC
54628+ bool "Disable RBAC system"
54629+ help
54630+ If you say Y here, the /dev/grsec device will be removed from the kernel,
54631+ preventing the RBAC system from being enabled. You should only say Y
54632+ here if you have no intention of using the RBAC system, so as to prevent
54633+ an attacker with root access from misusing the RBAC system to hide files
54634+ and processes when loadable module support and /dev/[k]mem have been
54635+ locked down.
54636+
54637+config GRKERNSEC_ACL_HIDEKERN
54638+ bool "Hide kernel processes"
54639+ help
54640+ If you say Y here, all kernel threads will be hidden to all
54641+ processes but those whose subject has the "view hidden processes"
54642+ flag.
54643+
54644+config GRKERNSEC_ACL_MAXTRIES
54645+ int "Maximum tries before password lockout"
54646+ default 3
54647+ help
54648+ This option enforces the maximum number of times a user can attempt
54649+ to authorize themselves with the grsecurity RBAC system before being
54650+ denied the ability to attempt authorization again for a specified time.
54651+ The lower the number, the harder it will be to brute-force a password.
54652+
54653+config GRKERNSEC_ACL_TIMEOUT
54654+ int "Time to wait after max password tries, in seconds"
54655+ default 30
54656+ help
54657+ This option specifies the time the user must wait after attempting to
54658+ authorize to the RBAC system with the maximum number of invalid
54659+ passwords. The higher the number, the harder it will be to brute-force
54660+ a password.
54661+
54662+endmenu
54663+menu "Filesystem Protections"
54664+depends on GRKERNSEC
54665+
54666+config GRKERNSEC_PROC
54667+ bool "Proc restrictions"
54668+ help
54669+ If you say Y here, the permissions of the /proc filesystem
54670+ will be altered to enhance system security and privacy. You MUST
54671+ choose either a user only restriction or a user and group restriction.
54672+ Depending upon the option you choose, you can either restrict users to
54673+ see only the processes they themselves run, or choose a group that can
54674+ view all processes and files normally restricted to root if you choose
54675+ the "restrict to user only" option. NOTE: If you're running identd as
54676+ a non-root user, you will have to run it as the group you specify here.
54677+
54678+config GRKERNSEC_PROC_USER
54679+ bool "Restrict /proc to user only"
54680+ depends on GRKERNSEC_PROC
54681+ help
54682+ If you say Y here, non-root users will only be able to view their own
54683+ processes, and restricts them from viewing network-related information,
54684+ and viewing kernel symbol and module information.
54685+
54686+config GRKERNSEC_PROC_USERGROUP
54687+ bool "Allow special group"
54688+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
54689+ help
54690+ If you say Y here, you will be able to select a group that will be
54691+ able to view all processes and network-related information. If you've
54692+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
54693+ remain hidden. This option is useful if you want to run identd as
54694+ a non-root user.
54695+
54696+config GRKERNSEC_PROC_GID
54697+ int "GID for special group"
54698+ depends on GRKERNSEC_PROC_USERGROUP
54699+ default 1001
54700+
54701+config GRKERNSEC_PROC_ADD
54702+ bool "Additional restrictions"
54703+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
54704+ help
54705+ If you say Y here, additional restrictions will be placed on
54706+ /proc that keep normal users from viewing device information and
54707+ slabinfo information that could be useful for exploits.
54708+
54709+config GRKERNSEC_LINK
54710+ bool "Linking restrictions"
54711+ help
54712+ If you say Y here, /tmp race exploits will be prevented, since users
54713+ will no longer be able to follow symlinks owned by other users in
54714+ world-writable +t directories (e.g. /tmp), unless the owner of the
54715+ symlink is the owner of the directory. users will also not be
54716+ able to hardlink to files they do not own. If the sysctl option is
54717+ enabled, a sysctl option with name "linking_restrictions" is created.
54718+
54719+config GRKERNSEC_FIFO
54720+ bool "FIFO restrictions"
54721+ help
54722+ If you say Y here, users will not be able to write to FIFOs they don't
54723+ own in world-writable +t directories (e.g. /tmp), unless the owner of
54724+ the FIFO is the same owner of the directory it's held in. If the sysctl
54725+ option is enabled, a sysctl option with name "fifo_restrictions" is
54726+ created.
54727+
54728+config GRKERNSEC_SYSFS_RESTRICT
54729+ bool "Sysfs/debugfs restriction"
54730+ depends on SYSFS
54731+ help
54732+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
54733+ any filesystem normally mounted under it (e.g. debugfs) will only
54734+ be accessible by root. These filesystems generally provide access
54735+ to hardware and debug information that isn't appropriate for unprivileged
54736+ users of the system. Sysfs and debugfs have also become a large source
54737+ of new vulnerabilities, ranging from infoleaks to local compromise.
54738+ There has been very little oversight with an eye toward security involved
54739+ in adding new exporters of information to these filesystems, so their
54740+ use is discouraged.
54741+ This option is equivalent to a chmod 0700 of the mount paths.
54742+
54743+config GRKERNSEC_ROFS
54744+ bool "Runtime read-only mount protection"
54745+ help
54746+ If you say Y here, a sysctl option with name "romount_protect" will
54747+ be created. By setting this option to 1 at runtime, filesystems
54748+ will be protected in the following ways:
54749+ * No new writable mounts will be allowed
54750+ * Existing read-only mounts won't be able to be remounted read/write
54751+ * Write operations will be denied on all block devices
54752+ This option acts independently of grsec_lock: once it is set to 1,
54753+ it cannot be turned off. Therefore, please be mindful of the resulting
54754+ behavior if this option is enabled in an init script on a read-only
54755+ filesystem. This feature is mainly intended for secure embedded systems.
54756+
54757+config GRKERNSEC_CHROOT
54758+ bool "Chroot jail restrictions"
54759+ help
54760+ If you say Y here, you will be able to choose several options that will
54761+ make breaking out of a chrooted jail much more difficult. If you
54762+ encounter no software incompatibilities with the following options, it
54763+ is recommended that you enable each one.
54764+
54765+config GRKERNSEC_CHROOT_MOUNT
54766+ bool "Deny mounts"
54767+ depends on GRKERNSEC_CHROOT
54768+ help
54769+ If you say Y here, processes inside a chroot will not be able to
54770+ mount or remount filesystems. If the sysctl option is enabled, a
54771+ sysctl option with name "chroot_deny_mount" is created.
54772+
54773+config GRKERNSEC_CHROOT_DOUBLE
54774+ bool "Deny double-chroots"
54775+ depends on GRKERNSEC_CHROOT
54776+ help
54777+ If you say Y here, processes inside a chroot will not be able to chroot
54778+ again outside the chroot. This is a widely used method of breaking
54779+ out of a chroot jail and should not be allowed. If the sysctl
54780+ option is enabled, a sysctl option with name
54781+ "chroot_deny_chroot" is created.
54782+
54783+config GRKERNSEC_CHROOT_PIVOT
54784+ bool "Deny pivot_root in chroot"
54785+ depends on GRKERNSEC_CHROOT
54786+ help
54787+ If you say Y here, processes inside a chroot will not be able to use
54788+ a function called pivot_root() that was introduced in Linux 2.3.41. It
54789+ works similar to chroot in that it changes the root filesystem. This
54790+ function could be misused in a chrooted process to attempt to break out
54791+ of the chroot, and therefore should not be allowed. If the sysctl
54792+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
54793+ created.
54794+
54795+config GRKERNSEC_CHROOT_CHDIR
54796+ bool "Enforce chdir(\"/\") on all chroots"
54797+ depends on GRKERNSEC_CHROOT
54798+ help
54799+ If you say Y here, the current working directory of all newly-chrooted
54800+ applications will be set to the the root directory of the chroot.
54801+ The man page on chroot(2) states:
54802+ Note that this call does not change the current working
54803+ directory, so that `.' can be outside the tree rooted at
54804+ `/'. In particular, the super-user can escape from a
54805+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
54806+
54807+ It is recommended that you say Y here, since it's not known to break
54808+ any software. If the sysctl option is enabled, a sysctl option with
54809+ name "chroot_enforce_chdir" is created.
54810+
54811+config GRKERNSEC_CHROOT_CHMOD
54812+ bool "Deny (f)chmod +s"
54813+ depends on GRKERNSEC_CHROOT
54814+ help
54815+ If you say Y here, processes inside a chroot will not be able to chmod
54816+ or fchmod files to make them have suid or sgid bits. This protects
54817+ against another published method of breaking a chroot. If the sysctl
54818+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
54819+ created.
54820+
54821+config GRKERNSEC_CHROOT_FCHDIR
54822+ bool "Deny fchdir out of chroot"
54823+ depends on GRKERNSEC_CHROOT
54824+ help
54825+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
54826+ to a file descriptor of the chrooting process that points to a directory
54827+ outside the filesystem will be stopped. If the sysctl option
54828+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
54829+
54830+config GRKERNSEC_CHROOT_MKNOD
54831+ bool "Deny mknod"
54832+ depends on GRKERNSEC_CHROOT
54833+ help
54834+ If you say Y here, processes inside a chroot will not be allowed to
54835+ mknod. The problem with using mknod inside a chroot is that it
54836+ would allow an attacker to create a device entry that is the same
54837+ as one on the physical root of your system, which could range from
54838+ anything from the console device to a device for your harddrive (which
54839+ they could then use to wipe the drive or steal data). It is recommended
54840+ that you say Y here, unless you run into software incompatibilities.
54841+ If the sysctl option is enabled, a sysctl option with name
54842+ "chroot_deny_mknod" is created.
54843+
54844+config GRKERNSEC_CHROOT_SHMAT
54845+ bool "Deny shmat() out of chroot"
54846+ depends on GRKERNSEC_CHROOT
54847+ help
54848+ If you say Y here, processes inside a chroot will not be able to attach
54849+ to shared memory segments that were created outside of the chroot jail.
54850+ It is recommended that you say Y here. If the sysctl option is enabled,
54851+ a sysctl option with name "chroot_deny_shmat" is created.
54852+
54853+config GRKERNSEC_CHROOT_UNIX
54854+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
54855+ depends on GRKERNSEC_CHROOT
54856+ help
54857+ If you say Y here, processes inside a chroot will not be able to
54858+ connect to abstract (meaning not belonging to a filesystem) Unix
54859+ domain sockets that were bound outside of a chroot. It is recommended
54860+ that you say Y here. If the sysctl option is enabled, a sysctl option
54861+ with name "chroot_deny_unix" is created.
54862+
54863+config GRKERNSEC_CHROOT_FINDTASK
54864+ bool "Protect outside processes"
54865+ depends on GRKERNSEC_CHROOT
54866+ help
54867+ If you say Y here, processes inside a chroot will not be able to
54868+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
54869+ getsid, or view any process outside of the chroot. If the sysctl
54870+ option is enabled, a sysctl option with name "chroot_findtask" is
54871+ created.
54872+
54873+config GRKERNSEC_CHROOT_NICE
54874+ bool "Restrict priority changes"
54875+ depends on GRKERNSEC_CHROOT
54876+ help
54877+ If you say Y here, processes inside a chroot will not be able to raise
54878+ the priority of processes in the chroot, or alter the priority of
54879+ processes outside the chroot. This provides more security than simply
54880+ removing CAP_SYS_NICE from the process' capability set. If the
54881+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
54882+ is created.
54883+
54884+config GRKERNSEC_CHROOT_SYSCTL
54885+ bool "Deny sysctl writes"
54886+ depends on GRKERNSEC_CHROOT
54887+ help
54888+ If you say Y here, an attacker in a chroot will not be able to
54889+ write to sysctl entries, either by sysctl(2) or through a /proc
54890+ interface. It is strongly recommended that you say Y here. If the
54891+ sysctl option is enabled, a sysctl option with name
54892+ "chroot_deny_sysctl" is created.
54893+
54894+config GRKERNSEC_CHROOT_CAPS
54895+ bool "Capability restrictions"
54896+ depends on GRKERNSEC_CHROOT
54897+ help
54898+ If you say Y here, the capabilities on all processes within a
54899+ chroot jail will be lowered to stop module insertion, raw i/o,
54900+ system and net admin tasks, rebooting the system, modifying immutable
54901+ files, modifying IPC owned by another, and changing the system time.
54902+ This is left an option because it can break some apps. Disable this
54903+ if your chrooted apps are having problems performing those kinds of
54904+ tasks. If the sysctl option is enabled, a sysctl option with
54905+ name "chroot_caps" is created.
54906+
54907+endmenu
54908+menu "Kernel Auditing"
54909+depends on GRKERNSEC
54910+
54911+config GRKERNSEC_AUDIT_GROUP
54912+ bool "Single group for auditing"
54913+ help
54914+ If you say Y here, the exec, chdir, and (un)mount logging features
54915+ will only operate on a group you specify. This option is recommended
54916+ if you only want to watch certain users instead of having a large
54917+ amount of logs from the entire system. If the sysctl option is enabled,
54918+ a sysctl option with name "audit_group" is created.
54919+
54920+config GRKERNSEC_AUDIT_GID
54921+ int "GID for auditing"
54922+ depends on GRKERNSEC_AUDIT_GROUP
54923+ default 1007
54924+
54925+config GRKERNSEC_EXECLOG
54926+ bool "Exec logging"
54927+ help
54928+ If you say Y here, all execve() calls will be logged (since the
54929+ other exec*() calls are frontends to execve(), all execution
54930+ will be logged). Useful for shell-servers that like to keep track
54931+ of their users. If the sysctl option is enabled, a sysctl option with
54932+ name "exec_logging" is created.
54933+ WARNING: This option when enabled will produce a LOT of logs, especially
54934+ on an active system.
54935+
54936+config GRKERNSEC_RESLOG
54937+ bool "Resource logging"
54938+ help
54939+ If you say Y here, all attempts to overstep resource limits will
54940+ be logged with the resource name, the requested size, and the current
54941+ limit. It is highly recommended that you say Y here. If the sysctl
54942+ option is enabled, a sysctl option with name "resource_logging" is
54943+ created. If the RBAC system is enabled, the sysctl value is ignored.
54944+
54945+config GRKERNSEC_CHROOT_EXECLOG
54946+ bool "Log execs within chroot"
54947+ help
54948+ If you say Y here, all executions inside a chroot jail will be logged
54949+ to syslog. This can cause a large amount of logs if certain
54950+ applications (eg. djb's daemontools) are installed on the system, and
54951+ is therefore left as an option. If the sysctl option is enabled, a
54952+ sysctl option with name "chroot_execlog" is created.
54953+
54954+config GRKERNSEC_AUDIT_PTRACE
54955+ bool "Ptrace logging"
54956+ help
54957+ If you say Y here, all attempts to attach to a process via ptrace
54958+ will be logged. If the sysctl option is enabled, a sysctl option
54959+ with name "audit_ptrace" is created.
54960+
54961+config GRKERNSEC_AUDIT_CHDIR
54962+ bool "Chdir logging"
54963+ help
54964+ If you say Y here, all chdir() calls will be logged. If the sysctl
54965+ option is enabled, a sysctl option with name "audit_chdir" is created.
54966+
54967+config GRKERNSEC_AUDIT_MOUNT
54968+ bool "(Un)Mount logging"
54969+ help
54970+ If you say Y here, all mounts and unmounts will be logged. If the
54971+ sysctl option is enabled, a sysctl option with name "audit_mount" is
54972+ created.
54973+
54974+config GRKERNSEC_SIGNAL
54975+ bool "Signal logging"
54976+ help
54977+ If you say Y here, certain important signals will be logged, such as
54978+ SIGSEGV, which will as a result inform you of when a error in a program
54979+ occurred, which in some cases could mean a possible exploit attempt.
54980+ If the sysctl option is enabled, a sysctl option with name
54981+ "signal_logging" is created.
54982+
54983+config GRKERNSEC_FORKFAIL
54984+ bool "Fork failure logging"
54985+ help
54986+ If you say Y here, all failed fork() attempts will be logged.
54987+ This could suggest a fork bomb, or someone attempting to overstep
54988+ their process limit. If the sysctl option is enabled, a sysctl option
54989+ with name "forkfail_logging" is created.
54990+
54991+config GRKERNSEC_TIME
54992+ bool "Time change logging"
54993+ help
54994+ If you say Y here, any changes of the system clock will be logged.
54995+ If the sysctl option is enabled, a sysctl option with name
54996+ "timechange_logging" is created.
54997+
54998+config GRKERNSEC_PROC_IPADDR
54999+ bool "/proc/<pid>/ipaddr support"
55000+ help
55001+ If you say Y here, a new entry will be added to each /proc/<pid>
55002+ directory that contains the IP address of the person using the task.
55003+ The IP is carried across local TCP and AF_UNIX stream sockets.
55004+ This information can be useful for IDS/IPSes to perform remote response
55005+ to a local attack. The entry is readable by only the owner of the
55006+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
55007+ the RBAC system), and thus does not create privacy concerns.
55008+
55009+config GRKERNSEC_RWXMAP_LOG
55010+ bool 'Denied RWX mmap/mprotect logging'
55011+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
55012+ help
55013+ If you say Y here, calls to mmap() and mprotect() with explicit
55014+ usage of PROT_WRITE and PROT_EXEC together will be logged when
55015+ denied by the PAX_MPROTECT feature. If the sysctl option is
55016+ enabled, a sysctl option with name "rwxmap_logging" is created.
55017+
55018+config GRKERNSEC_AUDIT_TEXTREL
55019+ bool 'ELF text relocations logging (READ HELP)'
55020+ depends on PAX_MPROTECT
55021+ help
55022+ If you say Y here, text relocations will be logged with the filename
55023+ of the offending library or binary. The purpose of the feature is
55024+ to help Linux distribution developers get rid of libraries and
55025+ binaries that need text relocations which hinder the future progress
55026+ of PaX. Only Linux distribution developers should say Y here, and
55027+ never on a production machine, as this option creates an information
55028+ leak that could aid an attacker in defeating the randomization of
55029+ a single memory region. If the sysctl option is enabled, a sysctl
55030+ option with name "audit_textrel" is created.
55031+
55032+endmenu
55033+
55034+menu "Executable Protections"
55035+depends on GRKERNSEC
55036+
55037+config GRKERNSEC_DMESG
55038+ bool "Dmesg(8) restriction"
55039+ help
55040+ If you say Y here, non-root users will not be able to use dmesg(8)
55041+ to view up to the last 4kb of messages in the kernel's log buffer.
55042+ The kernel's log buffer often contains kernel addresses and other
55043+ identifying information useful to an attacker in fingerprinting a
55044+ system for a targeted exploit.
55045+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
55046+ created.
55047+
55048+config GRKERNSEC_HARDEN_PTRACE
55049+ bool "Deter ptrace-based process snooping"
55050+ help
55051+ If you say Y here, TTY sniffers and other malicious monitoring
55052+ programs implemented through ptrace will be defeated. If you
55053+ have been using the RBAC system, this option has already been
55054+ enabled for several years for all users, with the ability to make
55055+ fine-grained exceptions.
55056+
55057+ This option only affects the ability of non-root users to ptrace
55058+ processes that are not a descendent of the ptracing process.
55059+ This means that strace ./binary and gdb ./binary will still work,
55060+ but attaching to arbitrary processes will not. If the sysctl
55061+ option is enabled, a sysctl option with name "harden_ptrace" is
55062+ created.
55063+
55064+config GRKERNSEC_TPE
55065+ bool "Trusted Path Execution (TPE)"
55066+ help
55067+ If you say Y here, you will be able to choose a gid to add to the
55068+ supplementary groups of users you want to mark as "untrusted."
55069+ These users will not be able to execute any files that are not in
55070+ root-owned directories writable only by root. If the sysctl option
55071+ is enabled, a sysctl option with name "tpe" is created.
55072+
55073+config GRKERNSEC_TPE_ALL
55074+ bool "Partially restrict all non-root users"
55075+ depends on GRKERNSEC_TPE
55076+ help
55077+ If you say Y here, all non-root users will be covered under
55078+ a weaker TPE restriction. This is separate from, and in addition to,
55079+ the main TPE options that you have selected elsewhere. Thus, if a
55080+ "trusted" GID is chosen, this restriction applies to even that GID.
55081+ Under this restriction, all non-root users will only be allowed to
55082+ execute files in directories they own that are not group or
55083+ world-writable, or in directories owned by root and writable only by
55084+ root. If the sysctl option is enabled, a sysctl option with name
55085+ "tpe_restrict_all" is created.
55086+
55087+config GRKERNSEC_TPE_INVERT
55088+ bool "Invert GID option"
55089+ depends on GRKERNSEC_TPE
55090+ help
55091+ If you say Y here, the group you specify in the TPE configuration will
55092+ decide what group TPE restrictions will be *disabled* for. This
55093+ option is useful if you want TPE restrictions to be applied to most
55094+ users on the system. If the sysctl option is enabled, a sysctl option
55095+ with name "tpe_invert" is created. Unlike other sysctl options, this
55096+ entry will default to on for backward-compatibility.
55097+
55098+config GRKERNSEC_TPE_GID
55099+ int "GID for untrusted users"
55100+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
55101+ default 1005
55102+ help
55103+ Setting this GID determines what group TPE restrictions will be
55104+ *enabled* for. If the sysctl option is enabled, a sysctl option
55105+ with name "tpe_gid" is created.
55106+
55107+config GRKERNSEC_TPE_GID
55108+ int "GID for trusted users"
55109+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
55110+ default 1005
55111+ help
55112+ Setting this GID determines what group TPE restrictions will be
55113+ *disabled* for. If the sysctl option is enabled, a sysctl option
55114+ with name "tpe_gid" is created.
55115+
55116+endmenu
55117+menu "Network Protections"
55118+depends on GRKERNSEC
55119+
55120+config GRKERNSEC_RANDNET
55121+ bool "Larger entropy pools"
55122+ help
55123+ If you say Y here, the entropy pools used for many features of Linux
55124+ and grsecurity will be doubled in size. Since several grsecurity
55125+ features use additional randomness, it is recommended that you say Y
55126+ here. Saying Y here has a similar effect as modifying
55127+ /proc/sys/kernel/random/poolsize.
55128+
55129+config GRKERNSEC_BLACKHOLE
55130+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
55131+ depends on NET
55132+ help
55133+ If you say Y here, neither TCP resets nor ICMP
55134+ destination-unreachable packets will be sent in response to packets
55135+ sent to ports for which no associated listening process exists.
55136+ This feature supports both IPV4 and IPV6 and exempts the
55137+ loopback interface from blackholing. Enabling this feature
55138+ makes a host more resilient to DoS attacks and reduces network
55139+ visibility against scanners.
55140+
55141+ The blackhole feature as-implemented is equivalent to the FreeBSD
55142+ blackhole feature, as it prevents RST responses to all packets, not
55143+ just SYNs. Under most application behavior this causes no
55144+ problems, but applications (like haproxy) may not close certain
55145+ connections in a way that cleanly terminates them on the remote
55146+ end, leaving the remote host in LAST_ACK state. Because of this
55147+ side-effect and to prevent intentional LAST_ACK DoSes, this
55148+ feature also adds automatic mitigation against such attacks.
55149+ The mitigation drastically reduces the amount of time a socket
55150+ can spend in LAST_ACK state. If you're using haproxy and not
55151+ all servers it connects to have this option enabled, consider
55152+ disabling this feature on the haproxy host.
55153+
55154+ If the sysctl option is enabled, two sysctl options with names
55155+ "ip_blackhole" and "lastack_retries" will be created.
55156+ While "ip_blackhole" takes the standard zero/non-zero on/off
55157+ toggle, "lastack_retries" uses the same kinds of values as
55158+ "tcp_retries1" and "tcp_retries2". The default value of 4
55159+ prevents a socket from lasting more than 45 seconds in LAST_ACK
55160+ state.
55161+
55162+config GRKERNSEC_SOCKET
55163+ bool "Socket restrictions"
55164+ depends on NET
55165+ help
55166+ If you say Y here, you will be able to choose from several options.
55167+ If you assign a GID on your system and add it to the supplementary
55168+ groups of users you want to restrict socket access to, this patch
55169+ will perform up to three things, based on the option(s) you choose.
55170+
55171+config GRKERNSEC_SOCKET_ALL
55172+ bool "Deny any sockets to group"
55173+ depends on GRKERNSEC_SOCKET
55174+ help
55175+ If you say Y here, you will be able to choose a GID of whose users will
55176+ be unable to connect to other hosts from your machine or run server
55177+ applications from your machine. If the sysctl option is enabled, a
55178+ sysctl option with name "socket_all" is created.
55179+
55180+config GRKERNSEC_SOCKET_ALL_GID
55181+ int "GID to deny all sockets for"
55182+ depends on GRKERNSEC_SOCKET_ALL
55183+ default 1004
55184+ help
55185+ Here you can choose the GID to disable socket access for. Remember to
55186+ add the users you want socket access disabled for to the GID
55187+ specified here. If the sysctl option is enabled, a sysctl option
55188+ with name "socket_all_gid" is created.
55189+
55190+config GRKERNSEC_SOCKET_CLIENT
55191+ bool "Deny client sockets to group"
55192+ depends on GRKERNSEC_SOCKET
55193+ help
55194+ If you say Y here, you will be able to choose a GID of whose users will
55195+ be unable to connect to other hosts from your machine, but will be
55196+ able to run servers. If this option is enabled, all users in the group
55197+ you specify will have to use passive mode when initiating ftp transfers
55198+ from the shell on your machine. If the sysctl option is enabled, a
55199+ sysctl option with name "socket_client" is created.
55200+
55201+config GRKERNSEC_SOCKET_CLIENT_GID
55202+ int "GID to deny client sockets for"
55203+ depends on GRKERNSEC_SOCKET_CLIENT
55204+ default 1003
55205+ help
55206+ Here you can choose the GID to disable client socket access for.
55207+ Remember to add the users you want client socket access disabled for to
55208+ the GID specified here. If the sysctl option is enabled, a sysctl
55209+ option with name "socket_client_gid" is created.
55210+
55211+config GRKERNSEC_SOCKET_SERVER
55212+ bool "Deny server sockets to group"
55213+ depends on GRKERNSEC_SOCKET
55214+ help
55215+ If you say Y here, you will be able to choose a GID of whose users will
55216+ be unable to run server applications from your machine. If the sysctl
55217+ option is enabled, a sysctl option with name "socket_server" is created.
55218+
55219+config GRKERNSEC_SOCKET_SERVER_GID
55220+ int "GID to deny server sockets for"
55221+ depends on GRKERNSEC_SOCKET_SERVER
55222+ default 1002
55223+ help
55224+ Here you can choose the GID to disable server socket access for.
55225+ Remember to add the users you want server socket access disabled for to
55226+ the GID specified here. If the sysctl option is enabled, a sysctl
55227+ option with name "socket_server_gid" is created.
55228+
55229+endmenu
55230+menu "Sysctl support"
55231+depends on GRKERNSEC && SYSCTL
55232+
55233+config GRKERNSEC_SYSCTL
55234+ bool "Sysctl support"
55235+ help
55236+ If you say Y here, you will be able to change the options that
55237+ grsecurity runs with at bootup, without having to recompile your
55238+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
55239+ to enable (1) or disable (0) various features. All the sysctl entries
55240+ are mutable until the "grsec_lock" entry is set to a non-zero value.
55241+ All features enabled in the kernel configuration are disabled at boot
55242+ if you do not say Y to the "Turn on features by default" option.
55243+ All options should be set at startup, and the grsec_lock entry should
55244+ be set to a non-zero value after all the options are set.
55245+ *THIS IS EXTREMELY IMPORTANT*
55246+
55247+config GRKERNSEC_SYSCTL_DISTRO
55248+ bool "Extra sysctl support for distro makers (READ HELP)"
55249+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
55250+ help
55251+ If you say Y here, additional sysctl options will be created
55252+ for features that affect processes running as root. Therefore,
55253+ it is critical when using this option that the grsec_lock entry be
55254+ enabled after boot. Only distros with prebuilt kernel packages
55255+ with this option enabled that can ensure grsec_lock is enabled
55256+ after boot should use this option.
55257+ *Failure to set grsec_lock after boot makes all grsec features
55258+ this option covers useless*
55259+
55260+ Currently this option creates the following sysctl entries:
55261+ "Disable Privileged I/O": "disable_priv_io"
55262+
55263+config GRKERNSEC_SYSCTL_ON
55264+ bool "Turn on features by default"
55265+ depends on GRKERNSEC_SYSCTL
55266+ help
55267+ If you say Y here, instead of having all features enabled in the
55268+ kernel configuration disabled at boot time, the features will be
55269+ enabled at boot time. It is recommended you say Y here unless
55270+ there is some reason you would want all sysctl-tunable features to
55271+ be disabled by default. As mentioned elsewhere, it is important
55272+ to enable the grsec_lock entry once you have finished modifying
55273+ the sysctl entries.
55274+
55275+endmenu
55276+menu "Logging Options"
55277+depends on GRKERNSEC
55278+
55279+config GRKERNSEC_FLOODTIME
55280+ int "Seconds in between log messages (minimum)"
55281+ default 10
55282+ help
55283+ This option allows you to enforce the number of seconds between
55284+ grsecurity log messages. The default should be suitable for most
55285+ people, however, if you choose to change it, choose a value small enough
55286+ to allow informative logs to be produced, but large enough to
55287+ prevent flooding.
55288+
55289+config GRKERNSEC_FLOODBURST
55290+ int "Number of messages in a burst (maximum)"
55291+ default 6
55292+ help
55293+ This option allows you to choose the maximum number of messages allowed
55294+ within the flood time interval you chose in a separate option. The
55295+ default should be suitable for most people, however if you find that
55296+ many of your logs are being interpreted as flooding, you may want to
55297+ raise this value.
55298+
55299+endmenu
55300+
55301+endmenu
55302diff --git a/grsecurity/Makefile b/grsecurity/Makefile
55303new file mode 100644
55304index 0000000..be9ae3a
55305--- /dev/null
55306+++ b/grsecurity/Makefile
55307@@ -0,0 +1,36 @@
55308+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
55309+# during 2001-2009 it has been completely redesigned by Brad Spengler
55310+# into an RBAC system
55311+#
55312+# All code in this directory and various hooks inserted throughout the kernel
55313+# are copyright Brad Spengler - Open Source Security, Inc., and released
55314+# under the GPL v2 or higher
55315+
55316+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
55317+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
55318+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
55319+
55320+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
55321+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
55322+ gracl_learn.o grsec_log.o
55323+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
55324+
55325+ifdef CONFIG_NET
55326+obj-y += grsec_sock.o
55327+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
55328+endif
55329+
55330+ifndef CONFIG_GRKERNSEC
55331+obj-y += grsec_disabled.o
55332+endif
55333+
55334+ifdef CONFIG_GRKERNSEC_HIDESYM
55335+extra-y := grsec_hidesym.o
55336+$(obj)/grsec_hidesym.o:
55337+ @-chmod -f 500 /boot
55338+ @-chmod -f 500 /lib/modules
55339+ @-chmod -f 500 /lib64/modules
55340+ @-chmod -f 500 /lib32/modules
55341+ @-chmod -f 700 .
55342+ @echo ' grsec: protected kernel image paths'
55343+endif
55344diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
55345new file mode 100644
55346index 0000000..6bd68d6
55347--- /dev/null
55348+++ b/grsecurity/gracl.c
55349@@ -0,0 +1,4141 @@
55350+#include <linux/kernel.h>
55351+#include <linux/module.h>
55352+#include <linux/sched.h>
55353+#include <linux/mm.h>
55354+#include <linux/file.h>
55355+#include <linux/fs.h>
55356+#include <linux/namei.h>
55357+#include <linux/mount.h>
55358+#include <linux/tty.h>
55359+#include <linux/proc_fs.h>
55360+#include <linux/smp_lock.h>
55361+#include <linux/slab.h>
55362+#include <linux/vmalloc.h>
55363+#include <linux/types.h>
55364+#include <linux/sysctl.h>
55365+#include <linux/netdevice.h>
55366+#include <linux/ptrace.h>
55367+#include <linux/gracl.h>
55368+#include <linux/gralloc.h>
55369+#include <linux/grsecurity.h>
55370+#include <linux/grinternal.h>
55371+#include <linux/pid_namespace.h>
55372+#include <linux/fdtable.h>
55373+#include <linux/percpu.h>
55374+
55375+#include <asm/uaccess.h>
55376+#include <asm/errno.h>
55377+#include <asm/mman.h>
55378+
55379+static struct acl_role_db acl_role_set;
55380+static struct name_db name_set;
55381+static struct inodev_db inodev_set;
55382+
55383+/* for keeping track of userspace pointers used for subjects, so we
55384+ can share references in the kernel as well
55385+*/
55386+
55387+static struct dentry *real_root;
55388+static struct vfsmount *real_root_mnt;
55389+
55390+static struct acl_subj_map_db subj_map_set;
55391+
55392+static struct acl_role_label *default_role;
55393+
55394+static struct acl_role_label *role_list;
55395+
55396+static u16 acl_sp_role_value;
55397+
55398+extern char *gr_shared_page[4];
55399+static DEFINE_MUTEX(gr_dev_mutex);
55400+DEFINE_RWLOCK(gr_inode_lock);
55401+
55402+struct gr_arg *gr_usermode;
55403+
55404+static unsigned int gr_status __read_only = GR_STATUS_INIT;
55405+
55406+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
55407+extern void gr_clear_learn_entries(void);
55408+
55409+#ifdef CONFIG_GRKERNSEC_RESLOG
55410+extern void gr_log_resource(const struct task_struct *task,
55411+ const int res, const unsigned long wanted, const int gt);
55412+#endif
55413+
55414+unsigned char *gr_system_salt;
55415+unsigned char *gr_system_sum;
55416+
55417+static struct sprole_pw **acl_special_roles = NULL;
55418+static __u16 num_sprole_pws = 0;
55419+
55420+static struct acl_role_label *kernel_role = NULL;
55421+
55422+static unsigned int gr_auth_attempts = 0;
55423+static unsigned long gr_auth_expires = 0UL;
55424+
55425+#ifdef CONFIG_NET
55426+extern struct vfsmount *sock_mnt;
55427+#endif
55428+extern struct vfsmount *pipe_mnt;
55429+extern struct vfsmount *shm_mnt;
55430+#ifdef CONFIG_HUGETLBFS
55431+extern struct vfsmount *hugetlbfs_vfsmount;
55432+#endif
55433+
55434+static struct acl_object_label *fakefs_obj_rw;
55435+static struct acl_object_label *fakefs_obj_rwx;
55436+
55437+extern int gr_init_uidset(void);
55438+extern void gr_free_uidset(void);
55439+extern void gr_remove_uid(uid_t uid);
55440+extern int gr_find_uid(uid_t uid);
55441+
55442+__inline__ int
55443+gr_acl_is_enabled(void)
55444+{
55445+ return (gr_status & GR_READY);
55446+}
55447+
55448+#ifdef CONFIG_BTRFS_FS
55449+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55450+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55451+#endif
55452+
55453+static inline dev_t __get_dev(const struct dentry *dentry)
55454+{
55455+#ifdef CONFIG_BTRFS_FS
55456+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55457+ return get_btrfs_dev_from_inode(dentry->d_inode);
55458+ else
55459+#endif
55460+ return dentry->d_inode->i_sb->s_dev;
55461+}
55462+
55463+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55464+{
55465+ return __get_dev(dentry);
55466+}
55467+
55468+static char gr_task_roletype_to_char(struct task_struct *task)
55469+{
55470+ switch (task->role->roletype &
55471+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
55472+ GR_ROLE_SPECIAL)) {
55473+ case GR_ROLE_DEFAULT:
55474+ return 'D';
55475+ case GR_ROLE_USER:
55476+ return 'U';
55477+ case GR_ROLE_GROUP:
55478+ return 'G';
55479+ case GR_ROLE_SPECIAL:
55480+ return 'S';
55481+ }
55482+
55483+ return 'X';
55484+}
55485+
55486+char gr_roletype_to_char(void)
55487+{
55488+ return gr_task_roletype_to_char(current);
55489+}
55490+
55491+__inline__ int
55492+gr_acl_tpe_check(void)
55493+{
55494+ if (unlikely(!(gr_status & GR_READY)))
55495+ return 0;
55496+ if (current->role->roletype & GR_ROLE_TPE)
55497+ return 1;
55498+ else
55499+ return 0;
55500+}
55501+
55502+int
55503+gr_handle_rawio(const struct inode *inode)
55504+{
55505+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55506+ if (inode && S_ISBLK(inode->i_mode) &&
55507+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55508+ !capable(CAP_SYS_RAWIO))
55509+ return 1;
55510+#endif
55511+ return 0;
55512+}
55513+
55514+static int
55515+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
55516+{
55517+ if (likely(lena != lenb))
55518+ return 0;
55519+
55520+ return !memcmp(a, b, lena);
55521+}
55522+
55523+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
55524+{
55525+ *buflen -= namelen;
55526+ if (*buflen < 0)
55527+ return -ENAMETOOLONG;
55528+ *buffer -= namelen;
55529+ memcpy(*buffer, str, namelen);
55530+ return 0;
55531+}
55532+
55533+/* this must be called with vfsmount_lock and dcache_lock held */
55534+
55535+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55536+ struct dentry *root, struct vfsmount *rootmnt,
55537+ char *buffer, int buflen)
55538+{
55539+ char * end = buffer+buflen;
55540+ char * retval;
55541+ int namelen;
55542+
55543+ *--end = '\0';
55544+ buflen--;
55545+
55546+ if (buflen < 1)
55547+ goto Elong;
55548+ /* Get '/' right */
55549+ retval = end-1;
55550+ *retval = '/';
55551+
55552+ for (;;) {
55553+ struct dentry * parent;
55554+
55555+ if (dentry == root && vfsmnt == rootmnt)
55556+ break;
55557+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
55558+ /* Global root? */
55559+ if (vfsmnt->mnt_parent == vfsmnt)
55560+ goto global_root;
55561+ dentry = vfsmnt->mnt_mountpoint;
55562+ vfsmnt = vfsmnt->mnt_parent;
55563+ continue;
55564+ }
55565+ parent = dentry->d_parent;
55566+ prefetch(parent);
55567+ namelen = dentry->d_name.len;
55568+ buflen -= namelen + 1;
55569+ if (buflen < 0)
55570+ goto Elong;
55571+ end -= namelen;
55572+ memcpy(end, dentry->d_name.name, namelen);
55573+ *--end = '/';
55574+ retval = end;
55575+ dentry = parent;
55576+ }
55577+
55578+out:
55579+ return retval;
55580+
55581+global_root:
55582+ namelen = dentry->d_name.len;
55583+ buflen -= namelen;
55584+ if (buflen < 0)
55585+ goto Elong;
55586+ retval -= namelen-1; /* hit the slash */
55587+ memcpy(retval, dentry->d_name.name, namelen);
55588+ goto out;
55589+Elong:
55590+ retval = ERR_PTR(-ENAMETOOLONG);
55591+ goto out;
55592+}
55593+
55594+static char *
55595+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55596+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
55597+{
55598+ char *retval;
55599+
55600+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
55601+ if (unlikely(IS_ERR(retval)))
55602+ retval = strcpy(buf, "<path too long>");
55603+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
55604+ retval[1] = '\0';
55605+
55606+ return retval;
55607+}
55608+
55609+static char *
55610+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55611+ char *buf, int buflen)
55612+{
55613+ char *res;
55614+
55615+ /* we can use real_root, real_root_mnt, because this is only called
55616+ by the RBAC system */
55617+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
55618+
55619+ return res;
55620+}
55621+
55622+static char *
55623+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55624+ char *buf, int buflen)
55625+{
55626+ char *res;
55627+ struct dentry *root;
55628+ struct vfsmount *rootmnt;
55629+ struct task_struct *reaper = &init_task;
55630+
55631+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
55632+ read_lock(&reaper->fs->lock);
55633+ root = dget(reaper->fs->root.dentry);
55634+ rootmnt = mntget(reaper->fs->root.mnt);
55635+ read_unlock(&reaper->fs->lock);
55636+
55637+ spin_lock(&dcache_lock);
55638+ spin_lock(&vfsmount_lock);
55639+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
55640+ spin_unlock(&vfsmount_lock);
55641+ spin_unlock(&dcache_lock);
55642+
55643+ dput(root);
55644+ mntput(rootmnt);
55645+ return res;
55646+}
55647+
55648+static char *
55649+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55650+{
55651+ char *ret;
55652+ spin_lock(&dcache_lock);
55653+ spin_lock(&vfsmount_lock);
55654+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55655+ PAGE_SIZE);
55656+ spin_unlock(&vfsmount_lock);
55657+ spin_unlock(&dcache_lock);
55658+ return ret;
55659+}
55660+
55661+static char *
55662+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55663+{
55664+ char *ret;
55665+ char *buf;
55666+ int buflen;
55667+
55668+ spin_lock(&dcache_lock);
55669+ spin_lock(&vfsmount_lock);
55670+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55671+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
55672+ buflen = (int)(ret - buf);
55673+ if (buflen >= 5)
55674+ prepend(&ret, &buflen, "/proc", 5);
55675+ else
55676+ ret = strcpy(buf, "<path too long>");
55677+ spin_unlock(&vfsmount_lock);
55678+ spin_unlock(&dcache_lock);
55679+ return ret;
55680+}
55681+
55682+char *
55683+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
55684+{
55685+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55686+ PAGE_SIZE);
55687+}
55688+
55689+char *
55690+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
55691+{
55692+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55693+ PAGE_SIZE);
55694+}
55695+
55696+char *
55697+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
55698+{
55699+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
55700+ PAGE_SIZE);
55701+}
55702+
55703+char *
55704+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
55705+{
55706+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
55707+ PAGE_SIZE);
55708+}
55709+
55710+char *
55711+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
55712+{
55713+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
55714+ PAGE_SIZE);
55715+}
55716+
55717+__inline__ __u32
55718+to_gr_audit(const __u32 reqmode)
55719+{
55720+ /* masks off auditable permission flags, then shifts them to create
55721+ auditing flags, and adds the special case of append auditing if
55722+ we're requesting write */
55723+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
55724+}
55725+
55726+struct acl_subject_label *
55727+lookup_subject_map(const struct acl_subject_label *userp)
55728+{
55729+ unsigned int index = shash(userp, subj_map_set.s_size);
55730+ struct subject_map *match;
55731+
55732+ match = subj_map_set.s_hash[index];
55733+
55734+ while (match && match->user != userp)
55735+ match = match->next;
55736+
55737+ if (match != NULL)
55738+ return match->kernel;
55739+ else
55740+ return NULL;
55741+}
55742+
55743+static void
55744+insert_subj_map_entry(struct subject_map *subjmap)
55745+{
55746+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
55747+ struct subject_map **curr;
55748+
55749+ subjmap->prev = NULL;
55750+
55751+ curr = &subj_map_set.s_hash[index];
55752+ if (*curr != NULL)
55753+ (*curr)->prev = subjmap;
55754+
55755+ subjmap->next = *curr;
55756+ *curr = subjmap;
55757+
55758+ return;
55759+}
55760+
55761+static struct acl_role_label *
55762+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
55763+ const gid_t gid)
55764+{
55765+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
55766+ struct acl_role_label *match;
55767+ struct role_allowed_ip *ipp;
55768+ unsigned int x;
55769+ u32 curr_ip = task->signal->curr_ip;
55770+
55771+ task->signal->saved_ip = curr_ip;
55772+
55773+ match = acl_role_set.r_hash[index];
55774+
55775+ while (match) {
55776+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
55777+ for (x = 0; x < match->domain_child_num; x++) {
55778+ if (match->domain_children[x] == uid)
55779+ goto found;
55780+ }
55781+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
55782+ break;
55783+ match = match->next;
55784+ }
55785+found:
55786+ if (match == NULL) {
55787+ try_group:
55788+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
55789+ match = acl_role_set.r_hash[index];
55790+
55791+ while (match) {
55792+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
55793+ for (x = 0; x < match->domain_child_num; x++) {
55794+ if (match->domain_children[x] == gid)
55795+ goto found2;
55796+ }
55797+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
55798+ break;
55799+ match = match->next;
55800+ }
55801+found2:
55802+ if (match == NULL)
55803+ match = default_role;
55804+ if (match->allowed_ips == NULL)
55805+ return match;
55806+ else {
55807+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
55808+ if (likely
55809+ ((ntohl(curr_ip) & ipp->netmask) ==
55810+ (ntohl(ipp->addr) & ipp->netmask)))
55811+ return match;
55812+ }
55813+ match = default_role;
55814+ }
55815+ } else if (match->allowed_ips == NULL) {
55816+ return match;
55817+ } else {
55818+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
55819+ if (likely
55820+ ((ntohl(curr_ip) & ipp->netmask) ==
55821+ (ntohl(ipp->addr) & ipp->netmask)))
55822+ return match;
55823+ }
55824+ goto try_group;
55825+ }
55826+
55827+ return match;
55828+}
55829+
55830+struct acl_subject_label *
55831+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
55832+ const struct acl_role_label *role)
55833+{
55834+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
55835+ struct acl_subject_label *match;
55836+
55837+ match = role->subj_hash[index];
55838+
55839+ while (match && (match->inode != ino || match->device != dev ||
55840+ (match->mode & GR_DELETED))) {
55841+ match = match->next;
55842+ }
55843+
55844+ if (match && !(match->mode & GR_DELETED))
55845+ return match;
55846+ else
55847+ return NULL;
55848+}
55849+
55850+struct acl_subject_label *
55851+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
55852+ const struct acl_role_label *role)
55853+{
55854+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
55855+ struct acl_subject_label *match;
55856+
55857+ match = role->subj_hash[index];
55858+
55859+ while (match && (match->inode != ino || match->device != dev ||
55860+ !(match->mode & GR_DELETED))) {
55861+ match = match->next;
55862+ }
55863+
55864+ if (match && (match->mode & GR_DELETED))
55865+ return match;
55866+ else
55867+ return NULL;
55868+}
55869+
55870+static struct acl_object_label *
55871+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
55872+ const struct acl_subject_label *subj)
55873+{
55874+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
55875+ struct acl_object_label *match;
55876+
55877+ match = subj->obj_hash[index];
55878+
55879+ while (match && (match->inode != ino || match->device != dev ||
55880+ (match->mode & GR_DELETED))) {
55881+ match = match->next;
55882+ }
55883+
55884+ if (match && !(match->mode & GR_DELETED))
55885+ return match;
55886+ else
55887+ return NULL;
55888+}
55889+
55890+static struct acl_object_label *
55891+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
55892+ const struct acl_subject_label *subj)
55893+{
55894+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
55895+ struct acl_object_label *match;
55896+
55897+ match = subj->obj_hash[index];
55898+
55899+ while (match && (match->inode != ino || match->device != dev ||
55900+ !(match->mode & GR_DELETED))) {
55901+ match = match->next;
55902+ }
55903+
55904+ if (match && (match->mode & GR_DELETED))
55905+ return match;
55906+
55907+ match = subj->obj_hash[index];
55908+
55909+ while (match && (match->inode != ino || match->device != dev ||
55910+ (match->mode & GR_DELETED))) {
55911+ match = match->next;
55912+ }
55913+
55914+ if (match && !(match->mode & GR_DELETED))
55915+ return match;
55916+ else
55917+ return NULL;
55918+}
55919+
55920+static struct name_entry *
55921+lookup_name_entry(const char *name)
55922+{
55923+ unsigned int len = strlen(name);
55924+ unsigned int key = full_name_hash(name, len);
55925+ unsigned int index = key % name_set.n_size;
55926+ struct name_entry *match;
55927+
55928+ match = name_set.n_hash[index];
55929+
55930+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55931+ match = match->next;
55932+
55933+ return match;
55934+}
55935+
55936+static struct name_entry *
55937+lookup_name_entry_create(const char *name)
55938+{
55939+ unsigned int len = strlen(name);
55940+ unsigned int key = full_name_hash(name, len);
55941+ unsigned int index = key % name_set.n_size;
55942+ struct name_entry *match;
55943+
55944+ match = name_set.n_hash[index];
55945+
55946+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55947+ !match->deleted))
55948+ match = match->next;
55949+
55950+ if (match && match->deleted)
55951+ return match;
55952+
55953+ match = name_set.n_hash[index];
55954+
55955+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55956+ match->deleted))
55957+ match = match->next;
55958+
55959+ if (match && !match->deleted)
55960+ return match;
55961+ else
55962+ return NULL;
55963+}
55964+
55965+static struct inodev_entry *
55966+lookup_inodev_entry(const ino_t ino, const dev_t dev)
55967+{
55968+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
55969+ struct inodev_entry *match;
55970+
55971+ match = inodev_set.i_hash[index];
55972+
55973+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
55974+ match = match->next;
55975+
55976+ return match;
55977+}
55978+
55979+static void
55980+insert_inodev_entry(struct inodev_entry *entry)
55981+{
55982+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
55983+ inodev_set.i_size);
55984+ struct inodev_entry **curr;
55985+
55986+ entry->prev = NULL;
55987+
55988+ curr = &inodev_set.i_hash[index];
55989+ if (*curr != NULL)
55990+ (*curr)->prev = entry;
55991+
55992+ entry->next = *curr;
55993+ *curr = entry;
55994+
55995+ return;
55996+}
55997+
55998+static void
55999+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
56000+{
56001+ unsigned int index =
56002+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
56003+ struct acl_role_label **curr;
56004+ struct acl_role_label *tmp;
56005+
56006+ curr = &acl_role_set.r_hash[index];
56007+
56008+ /* if role was already inserted due to domains and already has
56009+ a role in the same bucket as it attached, then we need to
56010+ combine these two buckets
56011+ */
56012+ if (role->next) {
56013+ tmp = role->next;
56014+ while (tmp->next)
56015+ tmp = tmp->next;
56016+ tmp->next = *curr;
56017+ } else
56018+ role->next = *curr;
56019+ *curr = role;
56020+
56021+ return;
56022+}
56023+
56024+static void
56025+insert_acl_role_label(struct acl_role_label *role)
56026+{
56027+ int i;
56028+
56029+ if (role_list == NULL) {
56030+ role_list = role;
56031+ role->prev = NULL;
56032+ } else {
56033+ role->prev = role_list;
56034+ role_list = role;
56035+ }
56036+
56037+ /* used for hash chains */
56038+ role->next = NULL;
56039+
56040+ if (role->roletype & GR_ROLE_DOMAIN) {
56041+ for (i = 0; i < role->domain_child_num; i++)
56042+ __insert_acl_role_label(role, role->domain_children[i]);
56043+ } else
56044+ __insert_acl_role_label(role, role->uidgid);
56045+}
56046+
56047+static int
56048+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
56049+{
56050+ struct name_entry **curr, *nentry;
56051+ struct inodev_entry *ientry;
56052+ unsigned int len = strlen(name);
56053+ unsigned int key = full_name_hash(name, len);
56054+ unsigned int index = key % name_set.n_size;
56055+
56056+ curr = &name_set.n_hash[index];
56057+
56058+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
56059+ curr = &((*curr)->next);
56060+
56061+ if (*curr != NULL)
56062+ return 1;
56063+
56064+ nentry = acl_alloc(sizeof (struct name_entry));
56065+ if (nentry == NULL)
56066+ return 0;
56067+ ientry = acl_alloc(sizeof (struct inodev_entry));
56068+ if (ientry == NULL)
56069+ return 0;
56070+ ientry->nentry = nentry;
56071+
56072+ nentry->key = key;
56073+ nentry->name = name;
56074+ nentry->inode = inode;
56075+ nentry->device = device;
56076+ nentry->len = len;
56077+ nentry->deleted = deleted;
56078+
56079+ nentry->prev = NULL;
56080+ curr = &name_set.n_hash[index];
56081+ if (*curr != NULL)
56082+ (*curr)->prev = nentry;
56083+ nentry->next = *curr;
56084+ *curr = nentry;
56085+
56086+ /* insert us into the table searchable by inode/dev */
56087+ insert_inodev_entry(ientry);
56088+
56089+ return 1;
56090+}
56091+
56092+static void
56093+insert_acl_obj_label(struct acl_object_label *obj,
56094+ struct acl_subject_label *subj)
56095+{
56096+ unsigned int index =
56097+ fhash(obj->inode, obj->device, subj->obj_hash_size);
56098+ struct acl_object_label **curr;
56099+
56100+
56101+ obj->prev = NULL;
56102+
56103+ curr = &subj->obj_hash[index];
56104+ if (*curr != NULL)
56105+ (*curr)->prev = obj;
56106+
56107+ obj->next = *curr;
56108+ *curr = obj;
56109+
56110+ return;
56111+}
56112+
56113+static void
56114+insert_acl_subj_label(struct acl_subject_label *obj,
56115+ struct acl_role_label *role)
56116+{
56117+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
56118+ struct acl_subject_label **curr;
56119+
56120+ obj->prev = NULL;
56121+
56122+ curr = &role->subj_hash[index];
56123+ if (*curr != NULL)
56124+ (*curr)->prev = obj;
56125+
56126+ obj->next = *curr;
56127+ *curr = obj;
56128+
56129+ return;
56130+}
56131+
56132+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
56133+
56134+static void *
56135+create_table(__u32 * len, int elementsize)
56136+{
56137+ unsigned int table_sizes[] = {
56138+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
56139+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
56140+ 4194301, 8388593, 16777213, 33554393, 67108859
56141+ };
56142+ void *newtable = NULL;
56143+ unsigned int pwr = 0;
56144+
56145+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
56146+ table_sizes[pwr] <= *len)
56147+ pwr++;
56148+
56149+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
56150+ return newtable;
56151+
56152+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
56153+ newtable =
56154+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
56155+ else
56156+ newtable = vmalloc(table_sizes[pwr] * elementsize);
56157+
56158+ *len = table_sizes[pwr];
56159+
56160+ return newtable;
56161+}
56162+
56163+static int
56164+init_variables(const struct gr_arg *arg)
56165+{
56166+ struct task_struct *reaper = &init_task;
56167+ unsigned int stacksize;
56168+
56169+ subj_map_set.s_size = arg->role_db.num_subjects;
56170+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
56171+ name_set.n_size = arg->role_db.num_objects;
56172+ inodev_set.i_size = arg->role_db.num_objects;
56173+
56174+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
56175+ !name_set.n_size || !inodev_set.i_size)
56176+ return 1;
56177+
56178+ if (!gr_init_uidset())
56179+ return 1;
56180+
56181+ /* set up the stack that holds allocation info */
56182+
56183+ stacksize = arg->role_db.num_pointers + 5;
56184+
56185+ if (!acl_alloc_stack_init(stacksize))
56186+ return 1;
56187+
56188+ /* grab reference for the real root dentry and vfsmount */
56189+ read_lock(&reaper->fs->lock);
56190+ real_root = dget(reaper->fs->root.dentry);
56191+ real_root_mnt = mntget(reaper->fs->root.mnt);
56192+ read_unlock(&reaper->fs->lock);
56193+
56194+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56195+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
56196+#endif
56197+
56198+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
56199+ if (fakefs_obj_rw == NULL)
56200+ return 1;
56201+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
56202+
56203+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
56204+ if (fakefs_obj_rwx == NULL)
56205+ return 1;
56206+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
56207+
56208+ subj_map_set.s_hash =
56209+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
56210+ acl_role_set.r_hash =
56211+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
56212+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
56213+ inodev_set.i_hash =
56214+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
56215+
56216+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
56217+ !name_set.n_hash || !inodev_set.i_hash)
56218+ return 1;
56219+
56220+ memset(subj_map_set.s_hash, 0,
56221+ sizeof(struct subject_map *) * subj_map_set.s_size);
56222+ memset(acl_role_set.r_hash, 0,
56223+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
56224+ memset(name_set.n_hash, 0,
56225+ sizeof (struct name_entry *) * name_set.n_size);
56226+ memset(inodev_set.i_hash, 0,
56227+ sizeof (struct inodev_entry *) * inodev_set.i_size);
56228+
56229+ return 0;
56230+}
56231+
56232+/* free information not needed after startup
56233+ currently contains user->kernel pointer mappings for subjects
56234+*/
56235+
56236+static void
56237+free_init_variables(void)
56238+{
56239+ __u32 i;
56240+
56241+ if (subj_map_set.s_hash) {
56242+ for (i = 0; i < subj_map_set.s_size; i++) {
56243+ if (subj_map_set.s_hash[i]) {
56244+ kfree(subj_map_set.s_hash[i]);
56245+ subj_map_set.s_hash[i] = NULL;
56246+ }
56247+ }
56248+
56249+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
56250+ PAGE_SIZE)
56251+ kfree(subj_map_set.s_hash);
56252+ else
56253+ vfree(subj_map_set.s_hash);
56254+ }
56255+
56256+ return;
56257+}
56258+
56259+static void
56260+free_variables(void)
56261+{
56262+ struct acl_subject_label *s;
56263+ struct acl_role_label *r;
56264+ struct task_struct *task, *task2;
56265+ unsigned int x;
56266+
56267+ gr_clear_learn_entries();
56268+
56269+ read_lock(&tasklist_lock);
56270+ do_each_thread(task2, task) {
56271+ task->acl_sp_role = 0;
56272+ task->acl_role_id = 0;
56273+ task->acl = NULL;
56274+ task->role = NULL;
56275+ } while_each_thread(task2, task);
56276+ read_unlock(&tasklist_lock);
56277+
56278+ /* release the reference to the real root dentry and vfsmount */
56279+ if (real_root)
56280+ dput(real_root);
56281+ real_root = NULL;
56282+ if (real_root_mnt)
56283+ mntput(real_root_mnt);
56284+ real_root_mnt = NULL;
56285+
56286+ /* free all object hash tables */
56287+
56288+ FOR_EACH_ROLE_START(r)
56289+ if (r->subj_hash == NULL)
56290+ goto next_role;
56291+ FOR_EACH_SUBJECT_START(r, s, x)
56292+ if (s->obj_hash == NULL)
56293+ break;
56294+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56295+ kfree(s->obj_hash);
56296+ else
56297+ vfree(s->obj_hash);
56298+ FOR_EACH_SUBJECT_END(s, x)
56299+ FOR_EACH_NESTED_SUBJECT_START(r, s)
56300+ if (s->obj_hash == NULL)
56301+ break;
56302+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56303+ kfree(s->obj_hash);
56304+ else
56305+ vfree(s->obj_hash);
56306+ FOR_EACH_NESTED_SUBJECT_END(s)
56307+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
56308+ kfree(r->subj_hash);
56309+ else
56310+ vfree(r->subj_hash);
56311+ r->subj_hash = NULL;
56312+next_role:
56313+ FOR_EACH_ROLE_END(r)
56314+
56315+ acl_free_all();
56316+
56317+ if (acl_role_set.r_hash) {
56318+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
56319+ PAGE_SIZE)
56320+ kfree(acl_role_set.r_hash);
56321+ else
56322+ vfree(acl_role_set.r_hash);
56323+ }
56324+ if (name_set.n_hash) {
56325+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
56326+ PAGE_SIZE)
56327+ kfree(name_set.n_hash);
56328+ else
56329+ vfree(name_set.n_hash);
56330+ }
56331+
56332+ if (inodev_set.i_hash) {
56333+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
56334+ PAGE_SIZE)
56335+ kfree(inodev_set.i_hash);
56336+ else
56337+ vfree(inodev_set.i_hash);
56338+ }
56339+
56340+ gr_free_uidset();
56341+
56342+ memset(&name_set, 0, sizeof (struct name_db));
56343+ memset(&inodev_set, 0, sizeof (struct inodev_db));
56344+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
56345+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
56346+
56347+ default_role = NULL;
56348+ role_list = NULL;
56349+
56350+ return;
56351+}
56352+
56353+static __u32
56354+count_user_objs(struct acl_object_label *userp)
56355+{
56356+ struct acl_object_label o_tmp;
56357+ __u32 num = 0;
56358+
56359+ while (userp) {
56360+ if (copy_from_user(&o_tmp, userp,
56361+ sizeof (struct acl_object_label)))
56362+ break;
56363+
56364+ userp = o_tmp.prev;
56365+ num++;
56366+ }
56367+
56368+ return num;
56369+}
56370+
56371+static struct acl_subject_label *
56372+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
56373+
56374+static int
56375+copy_user_glob(struct acl_object_label *obj)
56376+{
56377+ struct acl_object_label *g_tmp, **guser;
56378+ unsigned int len;
56379+ char *tmp;
56380+
56381+ if (obj->globbed == NULL)
56382+ return 0;
56383+
56384+ guser = &obj->globbed;
56385+ while (*guser) {
56386+ g_tmp = (struct acl_object_label *)
56387+ acl_alloc(sizeof (struct acl_object_label));
56388+ if (g_tmp == NULL)
56389+ return -ENOMEM;
56390+
56391+ if (copy_from_user(g_tmp, *guser,
56392+ sizeof (struct acl_object_label)))
56393+ return -EFAULT;
56394+
56395+ len = strnlen_user(g_tmp->filename, PATH_MAX);
56396+
56397+ if (!len || len >= PATH_MAX)
56398+ return -EINVAL;
56399+
56400+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56401+ return -ENOMEM;
56402+
56403+ if (copy_from_user(tmp, g_tmp->filename, len))
56404+ return -EFAULT;
56405+ tmp[len-1] = '\0';
56406+ g_tmp->filename = tmp;
56407+
56408+ *guser = g_tmp;
56409+ guser = &(g_tmp->next);
56410+ }
56411+
56412+ return 0;
56413+}
56414+
56415+static int
56416+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
56417+ struct acl_role_label *role)
56418+{
56419+ struct acl_object_label *o_tmp;
56420+ unsigned int len;
56421+ int ret;
56422+ char *tmp;
56423+
56424+ while (userp) {
56425+ if ((o_tmp = (struct acl_object_label *)
56426+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
56427+ return -ENOMEM;
56428+
56429+ if (copy_from_user(o_tmp, userp,
56430+ sizeof (struct acl_object_label)))
56431+ return -EFAULT;
56432+
56433+ userp = o_tmp->prev;
56434+
56435+ len = strnlen_user(o_tmp->filename, PATH_MAX);
56436+
56437+ if (!len || len >= PATH_MAX)
56438+ return -EINVAL;
56439+
56440+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56441+ return -ENOMEM;
56442+
56443+ if (copy_from_user(tmp, o_tmp->filename, len))
56444+ return -EFAULT;
56445+ tmp[len-1] = '\0';
56446+ o_tmp->filename = tmp;
56447+
56448+ insert_acl_obj_label(o_tmp, subj);
56449+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
56450+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
56451+ return -ENOMEM;
56452+
56453+ ret = copy_user_glob(o_tmp);
56454+ if (ret)
56455+ return ret;
56456+
56457+ if (o_tmp->nested) {
56458+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
56459+ if (IS_ERR(o_tmp->nested))
56460+ return PTR_ERR(o_tmp->nested);
56461+
56462+ /* insert into nested subject list */
56463+ o_tmp->nested->next = role->hash->first;
56464+ role->hash->first = o_tmp->nested;
56465+ }
56466+ }
56467+
56468+ return 0;
56469+}
56470+
56471+static __u32
56472+count_user_subjs(struct acl_subject_label *userp)
56473+{
56474+ struct acl_subject_label s_tmp;
56475+ __u32 num = 0;
56476+
56477+ while (userp) {
56478+ if (copy_from_user(&s_tmp, userp,
56479+ sizeof (struct acl_subject_label)))
56480+ break;
56481+
56482+ userp = s_tmp.prev;
56483+ /* do not count nested subjects against this count, since
56484+ they are not included in the hash table, but are
56485+ attached to objects. We have already counted
56486+ the subjects in userspace for the allocation
56487+ stack
56488+ */
56489+ if (!(s_tmp.mode & GR_NESTED))
56490+ num++;
56491+ }
56492+
56493+ return num;
56494+}
56495+
56496+static int
56497+copy_user_allowedips(struct acl_role_label *rolep)
56498+{
56499+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
56500+
56501+ ruserip = rolep->allowed_ips;
56502+
56503+ while (ruserip) {
56504+ rlast = rtmp;
56505+
56506+ if ((rtmp = (struct role_allowed_ip *)
56507+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
56508+ return -ENOMEM;
56509+
56510+ if (copy_from_user(rtmp, ruserip,
56511+ sizeof (struct role_allowed_ip)))
56512+ return -EFAULT;
56513+
56514+ ruserip = rtmp->prev;
56515+
56516+ if (!rlast) {
56517+ rtmp->prev = NULL;
56518+ rolep->allowed_ips = rtmp;
56519+ } else {
56520+ rlast->next = rtmp;
56521+ rtmp->prev = rlast;
56522+ }
56523+
56524+ if (!ruserip)
56525+ rtmp->next = NULL;
56526+ }
56527+
56528+ return 0;
56529+}
56530+
56531+static int
56532+copy_user_transitions(struct acl_role_label *rolep)
56533+{
56534+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
56535+
56536+ unsigned int len;
56537+ char *tmp;
56538+
56539+ rusertp = rolep->transitions;
56540+
56541+ while (rusertp) {
56542+ rlast = rtmp;
56543+
56544+ if ((rtmp = (struct role_transition *)
56545+ acl_alloc(sizeof (struct role_transition))) == NULL)
56546+ return -ENOMEM;
56547+
56548+ if (copy_from_user(rtmp, rusertp,
56549+ sizeof (struct role_transition)))
56550+ return -EFAULT;
56551+
56552+ rusertp = rtmp->prev;
56553+
56554+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
56555+
56556+ if (!len || len >= GR_SPROLE_LEN)
56557+ return -EINVAL;
56558+
56559+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56560+ return -ENOMEM;
56561+
56562+ if (copy_from_user(tmp, rtmp->rolename, len))
56563+ return -EFAULT;
56564+ tmp[len-1] = '\0';
56565+ rtmp->rolename = tmp;
56566+
56567+ if (!rlast) {
56568+ rtmp->prev = NULL;
56569+ rolep->transitions = rtmp;
56570+ } else {
56571+ rlast->next = rtmp;
56572+ rtmp->prev = rlast;
56573+ }
56574+
56575+ if (!rusertp)
56576+ rtmp->next = NULL;
56577+ }
56578+
56579+ return 0;
56580+}
56581+
56582+static struct acl_subject_label *
56583+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
56584+{
56585+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
56586+ unsigned int len;
56587+ char *tmp;
56588+ __u32 num_objs;
56589+ struct acl_ip_label **i_tmp, *i_utmp2;
56590+ struct gr_hash_struct ghash;
56591+ struct subject_map *subjmap;
56592+ unsigned int i_num;
56593+ int err;
56594+
56595+ s_tmp = lookup_subject_map(userp);
56596+
56597+ /* we've already copied this subject into the kernel, just return
56598+ the reference to it, and don't copy it over again
56599+ */
56600+ if (s_tmp)
56601+ return(s_tmp);
56602+
56603+ if ((s_tmp = (struct acl_subject_label *)
56604+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
56605+ return ERR_PTR(-ENOMEM);
56606+
56607+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
56608+ if (subjmap == NULL)
56609+ return ERR_PTR(-ENOMEM);
56610+
56611+ subjmap->user = userp;
56612+ subjmap->kernel = s_tmp;
56613+ insert_subj_map_entry(subjmap);
56614+
56615+ if (copy_from_user(s_tmp, userp,
56616+ sizeof (struct acl_subject_label)))
56617+ return ERR_PTR(-EFAULT);
56618+
56619+ len = strnlen_user(s_tmp->filename, PATH_MAX);
56620+
56621+ if (!len || len >= PATH_MAX)
56622+ return ERR_PTR(-EINVAL);
56623+
56624+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56625+ return ERR_PTR(-ENOMEM);
56626+
56627+ if (copy_from_user(tmp, s_tmp->filename, len))
56628+ return ERR_PTR(-EFAULT);
56629+ tmp[len-1] = '\0';
56630+ s_tmp->filename = tmp;
56631+
56632+ if (!strcmp(s_tmp->filename, "/"))
56633+ role->root_label = s_tmp;
56634+
56635+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
56636+ return ERR_PTR(-EFAULT);
56637+
56638+ /* copy user and group transition tables */
56639+
56640+ if (s_tmp->user_trans_num) {
56641+ uid_t *uidlist;
56642+
56643+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
56644+ if (uidlist == NULL)
56645+ return ERR_PTR(-ENOMEM);
56646+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
56647+ return ERR_PTR(-EFAULT);
56648+
56649+ s_tmp->user_transitions = uidlist;
56650+ }
56651+
56652+ if (s_tmp->group_trans_num) {
56653+ gid_t *gidlist;
56654+
56655+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
56656+ if (gidlist == NULL)
56657+ return ERR_PTR(-ENOMEM);
56658+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
56659+ return ERR_PTR(-EFAULT);
56660+
56661+ s_tmp->group_transitions = gidlist;
56662+ }
56663+
56664+ /* set up object hash table */
56665+ num_objs = count_user_objs(ghash.first);
56666+
56667+ s_tmp->obj_hash_size = num_objs;
56668+ s_tmp->obj_hash =
56669+ (struct acl_object_label **)
56670+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
56671+
56672+ if (!s_tmp->obj_hash)
56673+ return ERR_PTR(-ENOMEM);
56674+
56675+ memset(s_tmp->obj_hash, 0,
56676+ s_tmp->obj_hash_size *
56677+ sizeof (struct acl_object_label *));
56678+
56679+ /* add in objects */
56680+ err = copy_user_objs(ghash.first, s_tmp, role);
56681+
56682+ if (err)
56683+ return ERR_PTR(err);
56684+
56685+ /* set pointer for parent subject */
56686+ if (s_tmp->parent_subject) {
56687+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
56688+
56689+ if (IS_ERR(s_tmp2))
56690+ return s_tmp2;
56691+
56692+ s_tmp->parent_subject = s_tmp2;
56693+ }
56694+
56695+ /* add in ip acls */
56696+
56697+ if (!s_tmp->ip_num) {
56698+ s_tmp->ips = NULL;
56699+ goto insert;
56700+ }
56701+
56702+ i_tmp =
56703+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
56704+ sizeof (struct acl_ip_label *));
56705+
56706+ if (!i_tmp)
56707+ return ERR_PTR(-ENOMEM);
56708+
56709+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
56710+ *(i_tmp + i_num) =
56711+ (struct acl_ip_label *)
56712+ acl_alloc(sizeof (struct acl_ip_label));
56713+ if (!*(i_tmp + i_num))
56714+ return ERR_PTR(-ENOMEM);
56715+
56716+ if (copy_from_user
56717+ (&i_utmp2, s_tmp->ips + i_num,
56718+ sizeof (struct acl_ip_label *)))
56719+ return ERR_PTR(-EFAULT);
56720+
56721+ if (copy_from_user
56722+ (*(i_tmp + i_num), i_utmp2,
56723+ sizeof (struct acl_ip_label)))
56724+ return ERR_PTR(-EFAULT);
56725+
56726+ if ((*(i_tmp + i_num))->iface == NULL)
56727+ continue;
56728+
56729+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
56730+ if (!len || len >= IFNAMSIZ)
56731+ return ERR_PTR(-EINVAL);
56732+ tmp = acl_alloc(len);
56733+ if (tmp == NULL)
56734+ return ERR_PTR(-ENOMEM);
56735+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
56736+ return ERR_PTR(-EFAULT);
56737+ (*(i_tmp + i_num))->iface = tmp;
56738+ }
56739+
56740+ s_tmp->ips = i_tmp;
56741+
56742+insert:
56743+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
56744+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
56745+ return ERR_PTR(-ENOMEM);
56746+
56747+ return s_tmp;
56748+}
56749+
56750+static int
56751+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
56752+{
56753+ struct acl_subject_label s_pre;
56754+ struct acl_subject_label * ret;
56755+ int err;
56756+
56757+ while (userp) {
56758+ if (copy_from_user(&s_pre, userp,
56759+ sizeof (struct acl_subject_label)))
56760+ return -EFAULT;
56761+
56762+ /* do not add nested subjects here, add
56763+ while parsing objects
56764+ */
56765+
56766+ if (s_pre.mode & GR_NESTED) {
56767+ userp = s_pre.prev;
56768+ continue;
56769+ }
56770+
56771+ ret = do_copy_user_subj(userp, role);
56772+
56773+ err = PTR_ERR(ret);
56774+ if (IS_ERR(ret))
56775+ return err;
56776+
56777+ insert_acl_subj_label(ret, role);
56778+
56779+ userp = s_pre.prev;
56780+ }
56781+
56782+ return 0;
56783+}
56784+
56785+static int
56786+copy_user_acl(struct gr_arg *arg)
56787+{
56788+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
56789+ struct sprole_pw *sptmp;
56790+ struct gr_hash_struct *ghash;
56791+ uid_t *domainlist;
56792+ unsigned int r_num;
56793+ unsigned int len;
56794+ char *tmp;
56795+ int err = 0;
56796+ __u16 i;
56797+ __u32 num_subjs;
56798+
56799+ /* we need a default and kernel role */
56800+ if (arg->role_db.num_roles < 2)
56801+ return -EINVAL;
56802+
56803+ /* copy special role authentication info from userspace */
56804+
56805+ num_sprole_pws = arg->num_sprole_pws;
56806+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
56807+
56808+ if (!acl_special_roles) {
56809+ err = -ENOMEM;
56810+ goto cleanup;
56811+ }
56812+
56813+ for (i = 0; i < num_sprole_pws; i++) {
56814+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
56815+ if (!sptmp) {
56816+ err = -ENOMEM;
56817+ goto cleanup;
56818+ }
56819+ if (copy_from_user(sptmp, arg->sprole_pws + i,
56820+ sizeof (struct sprole_pw))) {
56821+ err = -EFAULT;
56822+ goto cleanup;
56823+ }
56824+
56825+ len =
56826+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
56827+
56828+ if (!len || len >= GR_SPROLE_LEN) {
56829+ err = -EINVAL;
56830+ goto cleanup;
56831+ }
56832+
56833+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
56834+ err = -ENOMEM;
56835+ goto cleanup;
56836+ }
56837+
56838+ if (copy_from_user(tmp, sptmp->rolename, len)) {
56839+ err = -EFAULT;
56840+ goto cleanup;
56841+ }
56842+ tmp[len-1] = '\0';
56843+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56844+ printk(KERN_ALERT "Copying special role %s\n", tmp);
56845+#endif
56846+ sptmp->rolename = tmp;
56847+ acl_special_roles[i] = sptmp;
56848+ }
56849+
56850+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
56851+
56852+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
56853+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
56854+
56855+ if (!r_tmp) {
56856+ err = -ENOMEM;
56857+ goto cleanup;
56858+ }
56859+
56860+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
56861+ sizeof (struct acl_role_label *))) {
56862+ err = -EFAULT;
56863+ goto cleanup;
56864+ }
56865+
56866+ if (copy_from_user(r_tmp, r_utmp2,
56867+ sizeof (struct acl_role_label))) {
56868+ err = -EFAULT;
56869+ goto cleanup;
56870+ }
56871+
56872+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
56873+
56874+ if (!len || len >= PATH_MAX) {
56875+ err = -EINVAL;
56876+ goto cleanup;
56877+ }
56878+
56879+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
56880+ err = -ENOMEM;
56881+ goto cleanup;
56882+ }
56883+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
56884+ err = -EFAULT;
56885+ goto cleanup;
56886+ }
56887+ tmp[len-1] = '\0';
56888+ r_tmp->rolename = tmp;
56889+
56890+ if (!strcmp(r_tmp->rolename, "default")
56891+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
56892+ default_role = r_tmp;
56893+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56894+ kernel_role = r_tmp;
56895+ }
56896+
56897+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
56898+ err = -ENOMEM;
56899+ goto cleanup;
56900+ }
56901+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
56902+ err = -EFAULT;
56903+ goto cleanup;
56904+ }
56905+
56906+ r_tmp->hash = ghash;
56907+
56908+ num_subjs = count_user_subjs(r_tmp->hash->first);
56909+
56910+ r_tmp->subj_hash_size = num_subjs;
56911+ r_tmp->subj_hash =
56912+ (struct acl_subject_label **)
56913+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56914+
56915+ if (!r_tmp->subj_hash) {
56916+ err = -ENOMEM;
56917+ goto cleanup;
56918+ }
56919+
56920+ err = copy_user_allowedips(r_tmp);
56921+ if (err)
56922+ goto cleanup;
56923+
56924+ /* copy domain info */
56925+ if (r_tmp->domain_children != NULL) {
56926+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56927+ if (domainlist == NULL) {
56928+ err = -ENOMEM;
56929+ goto cleanup;
56930+ }
56931+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
56932+ err = -EFAULT;
56933+ goto cleanup;
56934+ }
56935+ r_tmp->domain_children = domainlist;
56936+ }
56937+
56938+ err = copy_user_transitions(r_tmp);
56939+ if (err)
56940+ goto cleanup;
56941+
56942+ memset(r_tmp->subj_hash, 0,
56943+ r_tmp->subj_hash_size *
56944+ sizeof (struct acl_subject_label *));
56945+
56946+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
56947+
56948+ if (err)
56949+ goto cleanup;
56950+
56951+ /* set nested subject list to null */
56952+ r_tmp->hash->first = NULL;
56953+
56954+ insert_acl_role_label(r_tmp);
56955+ }
56956+
56957+ goto return_err;
56958+ cleanup:
56959+ free_variables();
56960+ return_err:
56961+ return err;
56962+
56963+}
56964+
56965+static int
56966+gracl_init(struct gr_arg *args)
56967+{
56968+ int error = 0;
56969+
56970+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
56971+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
56972+
56973+ if (init_variables(args)) {
56974+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
56975+ error = -ENOMEM;
56976+ free_variables();
56977+ goto out;
56978+ }
56979+
56980+ error = copy_user_acl(args);
56981+ free_init_variables();
56982+ if (error) {
56983+ free_variables();
56984+ goto out;
56985+ }
56986+
56987+ if ((error = gr_set_acls(0))) {
56988+ free_variables();
56989+ goto out;
56990+ }
56991+
56992+ pax_open_kernel();
56993+ gr_status |= GR_READY;
56994+ pax_close_kernel();
56995+
56996+ out:
56997+ return error;
56998+}
56999+
57000+/* derived from glibc fnmatch() 0: match, 1: no match*/
57001+
57002+static int
57003+glob_match(const char *p, const char *n)
57004+{
57005+ char c;
57006+
57007+ while ((c = *p++) != '\0') {
57008+ switch (c) {
57009+ case '?':
57010+ if (*n == '\0')
57011+ return 1;
57012+ else if (*n == '/')
57013+ return 1;
57014+ break;
57015+ case '\\':
57016+ if (*n != c)
57017+ return 1;
57018+ break;
57019+ case '*':
57020+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
57021+ if (*n == '/')
57022+ return 1;
57023+ else if (c == '?') {
57024+ if (*n == '\0')
57025+ return 1;
57026+ else
57027+ ++n;
57028+ }
57029+ }
57030+ if (c == '\0') {
57031+ return 0;
57032+ } else {
57033+ const char *endp;
57034+
57035+ if ((endp = strchr(n, '/')) == NULL)
57036+ endp = n + strlen(n);
57037+
57038+ if (c == '[') {
57039+ for (--p; n < endp; ++n)
57040+ if (!glob_match(p, n))
57041+ return 0;
57042+ } else if (c == '/') {
57043+ while (*n != '\0' && *n != '/')
57044+ ++n;
57045+ if (*n == '/' && !glob_match(p, n + 1))
57046+ return 0;
57047+ } else {
57048+ for (--p; n < endp; ++n)
57049+ if (*n == c && !glob_match(p, n))
57050+ return 0;
57051+ }
57052+
57053+ return 1;
57054+ }
57055+ case '[':
57056+ {
57057+ int not;
57058+ char cold;
57059+
57060+ if (*n == '\0' || *n == '/')
57061+ return 1;
57062+
57063+ not = (*p == '!' || *p == '^');
57064+ if (not)
57065+ ++p;
57066+
57067+ c = *p++;
57068+ for (;;) {
57069+ unsigned char fn = (unsigned char)*n;
57070+
57071+ if (c == '\0')
57072+ return 1;
57073+ else {
57074+ if (c == fn)
57075+ goto matched;
57076+ cold = c;
57077+ c = *p++;
57078+
57079+ if (c == '-' && *p != ']') {
57080+ unsigned char cend = *p++;
57081+
57082+ if (cend == '\0')
57083+ return 1;
57084+
57085+ if (cold <= fn && fn <= cend)
57086+ goto matched;
57087+
57088+ c = *p++;
57089+ }
57090+ }
57091+
57092+ if (c == ']')
57093+ break;
57094+ }
57095+ if (!not)
57096+ return 1;
57097+ break;
57098+ matched:
57099+ while (c != ']') {
57100+ if (c == '\0')
57101+ return 1;
57102+
57103+ c = *p++;
57104+ }
57105+ if (not)
57106+ return 1;
57107+ }
57108+ break;
57109+ default:
57110+ if (c != *n)
57111+ return 1;
57112+ }
57113+
57114+ ++n;
57115+ }
57116+
57117+ if (*n == '\0')
57118+ return 0;
57119+
57120+ if (*n == '/')
57121+ return 0;
57122+
57123+ return 1;
57124+}
57125+
57126+static struct acl_object_label *
57127+chk_glob_label(struct acl_object_label *globbed,
57128+ struct dentry *dentry, struct vfsmount *mnt, char **path)
57129+{
57130+ struct acl_object_label *tmp;
57131+
57132+ if (*path == NULL)
57133+ *path = gr_to_filename_nolock(dentry, mnt);
57134+
57135+ tmp = globbed;
57136+
57137+ while (tmp) {
57138+ if (!glob_match(tmp->filename, *path))
57139+ return tmp;
57140+ tmp = tmp->next;
57141+ }
57142+
57143+ return NULL;
57144+}
57145+
57146+static struct acl_object_label *
57147+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57148+ const ino_t curr_ino, const dev_t curr_dev,
57149+ const struct acl_subject_label *subj, char **path, const int checkglob)
57150+{
57151+ struct acl_subject_label *tmpsubj;
57152+ struct acl_object_label *retval;
57153+ struct acl_object_label *retval2;
57154+
57155+ tmpsubj = (struct acl_subject_label *) subj;
57156+ read_lock(&gr_inode_lock);
57157+ do {
57158+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
57159+ if (retval) {
57160+ if (checkglob && retval->globbed) {
57161+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
57162+ (struct vfsmount *)orig_mnt, path);
57163+ if (retval2)
57164+ retval = retval2;
57165+ }
57166+ break;
57167+ }
57168+ } while ((tmpsubj = tmpsubj->parent_subject));
57169+ read_unlock(&gr_inode_lock);
57170+
57171+ return retval;
57172+}
57173+
57174+static __inline__ struct acl_object_label *
57175+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57176+ const struct dentry *curr_dentry,
57177+ const struct acl_subject_label *subj, char **path, const int checkglob)
57178+{
57179+ int newglob = checkglob;
57180+
57181+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
57182+ as we don't want a / * rule to match instead of the / object
57183+ don't do this for create lookups that call this function though, since they're looking up
57184+ on the parent and thus need globbing checks on all paths
57185+ */
57186+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
57187+ newglob = GR_NO_GLOB;
57188+
57189+ return __full_lookup(orig_dentry, orig_mnt,
57190+ curr_dentry->d_inode->i_ino,
57191+ __get_dev(curr_dentry), subj, path, newglob);
57192+}
57193+
57194+static struct acl_object_label *
57195+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57196+ const struct acl_subject_label *subj, char *path, const int checkglob)
57197+{
57198+ struct dentry *dentry = (struct dentry *) l_dentry;
57199+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57200+ struct acl_object_label *retval;
57201+
57202+ spin_lock(&dcache_lock);
57203+ spin_lock(&vfsmount_lock);
57204+
57205+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
57206+#ifdef CONFIG_NET
57207+ mnt == sock_mnt ||
57208+#endif
57209+#ifdef CONFIG_HUGETLBFS
57210+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
57211+#endif
57212+ /* ignore Eric Biederman */
57213+ IS_PRIVATE(l_dentry->d_inode))) {
57214+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
57215+ goto out;
57216+ }
57217+
57218+ for (;;) {
57219+ if (dentry == real_root && mnt == real_root_mnt)
57220+ break;
57221+
57222+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57223+ if (mnt->mnt_parent == mnt)
57224+ break;
57225+
57226+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57227+ if (retval != NULL)
57228+ goto out;
57229+
57230+ dentry = mnt->mnt_mountpoint;
57231+ mnt = mnt->mnt_parent;
57232+ continue;
57233+ }
57234+
57235+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57236+ if (retval != NULL)
57237+ goto out;
57238+
57239+ dentry = dentry->d_parent;
57240+ }
57241+
57242+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57243+
57244+ if (retval == NULL)
57245+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
57246+out:
57247+ spin_unlock(&vfsmount_lock);
57248+ spin_unlock(&dcache_lock);
57249+
57250+ BUG_ON(retval == NULL);
57251+
57252+ return retval;
57253+}
57254+
57255+static __inline__ struct acl_object_label *
57256+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57257+ const struct acl_subject_label *subj)
57258+{
57259+ char *path = NULL;
57260+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
57261+}
57262+
57263+static __inline__ struct acl_object_label *
57264+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57265+ const struct acl_subject_label *subj)
57266+{
57267+ char *path = NULL;
57268+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
57269+}
57270+
57271+static __inline__ struct acl_object_label *
57272+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57273+ const struct acl_subject_label *subj, char *path)
57274+{
57275+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
57276+}
57277+
57278+static struct acl_subject_label *
57279+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57280+ const struct acl_role_label *role)
57281+{
57282+ struct dentry *dentry = (struct dentry *) l_dentry;
57283+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57284+ struct acl_subject_label *retval;
57285+
57286+ spin_lock(&dcache_lock);
57287+ spin_lock(&vfsmount_lock);
57288+
57289+ for (;;) {
57290+ if (dentry == real_root && mnt == real_root_mnt)
57291+ break;
57292+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57293+ if (mnt->mnt_parent == mnt)
57294+ break;
57295+
57296+ read_lock(&gr_inode_lock);
57297+ retval =
57298+ lookup_acl_subj_label(dentry->d_inode->i_ino,
57299+ __get_dev(dentry), role);
57300+ read_unlock(&gr_inode_lock);
57301+ if (retval != NULL)
57302+ goto out;
57303+
57304+ dentry = mnt->mnt_mountpoint;
57305+ mnt = mnt->mnt_parent;
57306+ continue;
57307+ }
57308+
57309+ read_lock(&gr_inode_lock);
57310+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57311+ __get_dev(dentry), role);
57312+ read_unlock(&gr_inode_lock);
57313+ if (retval != NULL)
57314+ goto out;
57315+
57316+ dentry = dentry->d_parent;
57317+ }
57318+
57319+ read_lock(&gr_inode_lock);
57320+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57321+ __get_dev(dentry), role);
57322+ read_unlock(&gr_inode_lock);
57323+
57324+ if (unlikely(retval == NULL)) {
57325+ read_lock(&gr_inode_lock);
57326+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
57327+ __get_dev(real_root), role);
57328+ read_unlock(&gr_inode_lock);
57329+ }
57330+out:
57331+ spin_unlock(&vfsmount_lock);
57332+ spin_unlock(&dcache_lock);
57333+
57334+ BUG_ON(retval == NULL);
57335+
57336+ return retval;
57337+}
57338+
57339+static void
57340+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
57341+{
57342+ struct task_struct *task = current;
57343+ const struct cred *cred = current_cred();
57344+
57345+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57346+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57347+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57348+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
57349+
57350+ return;
57351+}
57352+
57353+static void
57354+gr_log_learn_sysctl(const char *path, const __u32 mode)
57355+{
57356+ struct task_struct *task = current;
57357+ const struct cred *cred = current_cred();
57358+
57359+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57360+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57361+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57362+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
57363+
57364+ return;
57365+}
57366+
57367+static void
57368+gr_log_learn_id_change(const char type, const unsigned int real,
57369+ const unsigned int effective, const unsigned int fs)
57370+{
57371+ struct task_struct *task = current;
57372+ const struct cred *cred = current_cred();
57373+
57374+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
57375+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57376+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57377+ type, real, effective, fs, &task->signal->saved_ip);
57378+
57379+ return;
57380+}
57381+
57382+__u32
57383+gr_search_file(const struct dentry * dentry, const __u32 mode,
57384+ const struct vfsmount * mnt)
57385+{
57386+ __u32 retval = mode;
57387+ struct acl_subject_label *curracl;
57388+ struct acl_object_label *currobj;
57389+
57390+ if (unlikely(!(gr_status & GR_READY)))
57391+ return (mode & ~GR_AUDITS);
57392+
57393+ curracl = current->acl;
57394+
57395+ currobj = chk_obj_label(dentry, mnt, curracl);
57396+ retval = currobj->mode & mode;
57397+
57398+ /* if we're opening a specified transfer file for writing
57399+ (e.g. /dev/initctl), then transfer our role to init
57400+ */
57401+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
57402+ current->role->roletype & GR_ROLE_PERSIST)) {
57403+ struct task_struct *task = init_pid_ns.child_reaper;
57404+
57405+ if (task->role != current->role) {
57406+ task->acl_sp_role = 0;
57407+ task->acl_role_id = current->acl_role_id;
57408+ task->role = current->role;
57409+ rcu_read_lock();
57410+ read_lock(&grsec_exec_file_lock);
57411+ gr_apply_subject_to_task(task);
57412+ read_unlock(&grsec_exec_file_lock);
57413+ rcu_read_unlock();
57414+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
57415+ }
57416+ }
57417+
57418+ if (unlikely
57419+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
57420+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
57421+ __u32 new_mode = mode;
57422+
57423+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57424+
57425+ retval = new_mode;
57426+
57427+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
57428+ new_mode |= GR_INHERIT;
57429+
57430+ if (!(mode & GR_NOLEARN))
57431+ gr_log_learn(dentry, mnt, new_mode);
57432+ }
57433+
57434+ return retval;
57435+}
57436+
57437+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
57438+ const struct dentry *parent,
57439+ const struct vfsmount *mnt)
57440+{
57441+ struct name_entry *match;
57442+ struct acl_object_label *matchpo;
57443+ struct acl_subject_label *curracl;
57444+ char *path;
57445+
57446+ if (unlikely(!(gr_status & GR_READY)))
57447+ return NULL;
57448+
57449+ preempt_disable();
57450+ path = gr_to_filename_rbac(new_dentry, mnt);
57451+ match = lookup_name_entry_create(path);
57452+
57453+ curracl = current->acl;
57454+
57455+ if (match) {
57456+ read_lock(&gr_inode_lock);
57457+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
57458+ read_unlock(&gr_inode_lock);
57459+
57460+ if (matchpo) {
57461+ preempt_enable();
57462+ return matchpo;
57463+ }
57464+ }
57465+
57466+ // lookup parent
57467+
57468+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
57469+
57470+ preempt_enable();
57471+ return matchpo;
57472+}
57473+
57474+__u32
57475+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
57476+ const struct vfsmount * mnt, const __u32 mode)
57477+{
57478+ struct acl_object_label *matchpo;
57479+ __u32 retval;
57480+
57481+ if (unlikely(!(gr_status & GR_READY)))
57482+ return (mode & ~GR_AUDITS);
57483+
57484+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
57485+
57486+ retval = matchpo->mode & mode;
57487+
57488+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
57489+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57490+ __u32 new_mode = mode;
57491+
57492+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57493+
57494+ gr_log_learn(new_dentry, mnt, new_mode);
57495+ return new_mode;
57496+ }
57497+
57498+ return retval;
57499+}
57500+
57501+__u32
57502+gr_check_link(const struct dentry * new_dentry,
57503+ const struct dentry * parent_dentry,
57504+ const struct vfsmount * parent_mnt,
57505+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
57506+{
57507+ struct acl_object_label *obj;
57508+ __u32 oldmode, newmode;
57509+ __u32 needmode;
57510+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
57511+ GR_DELETE | GR_INHERIT;
57512+
57513+ if (unlikely(!(gr_status & GR_READY)))
57514+ return (GR_CREATE | GR_LINK);
57515+
57516+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
57517+ oldmode = obj->mode;
57518+
57519+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
57520+ newmode = obj->mode;
57521+
57522+ needmode = newmode & checkmodes;
57523+
57524+ // old name for hardlink must have at least the permissions of the new name
57525+ if ((oldmode & needmode) != needmode)
57526+ goto bad;
57527+
57528+ // if old name had restrictions/auditing, make sure the new name does as well
57529+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
57530+
57531+ // don't allow hardlinking of suid/sgid files without permission
57532+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57533+ needmode |= GR_SETID;
57534+
57535+ if ((newmode & needmode) != needmode)
57536+ goto bad;
57537+
57538+ // enforce minimum permissions
57539+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
57540+ return newmode;
57541+bad:
57542+ needmode = oldmode;
57543+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57544+ needmode |= GR_SETID;
57545+
57546+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
57547+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
57548+ return (GR_CREATE | GR_LINK);
57549+ } else if (newmode & GR_SUPPRESS)
57550+ return GR_SUPPRESS;
57551+ else
57552+ return 0;
57553+}
57554+
57555+int
57556+gr_check_hidden_task(const struct task_struct *task)
57557+{
57558+ if (unlikely(!(gr_status & GR_READY)))
57559+ return 0;
57560+
57561+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
57562+ return 1;
57563+
57564+ return 0;
57565+}
57566+
57567+int
57568+gr_check_protected_task(const struct task_struct *task)
57569+{
57570+ if (unlikely(!(gr_status & GR_READY) || !task))
57571+ return 0;
57572+
57573+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57574+ task->acl != current->acl)
57575+ return 1;
57576+
57577+ return 0;
57578+}
57579+
57580+int
57581+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57582+{
57583+ struct task_struct *p;
57584+ int ret = 0;
57585+
57586+ if (unlikely(!(gr_status & GR_READY) || !pid))
57587+ return ret;
57588+
57589+ read_lock(&tasklist_lock);
57590+ do_each_pid_task(pid, type, p) {
57591+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57592+ p->acl != current->acl) {
57593+ ret = 1;
57594+ goto out;
57595+ }
57596+ } while_each_pid_task(pid, type, p);
57597+out:
57598+ read_unlock(&tasklist_lock);
57599+
57600+ return ret;
57601+}
57602+
57603+void
57604+gr_copy_label(struct task_struct *tsk)
57605+{
57606+ tsk->signal->used_accept = 0;
57607+ tsk->acl_sp_role = 0;
57608+ tsk->acl_role_id = current->acl_role_id;
57609+ tsk->acl = current->acl;
57610+ tsk->role = current->role;
57611+ tsk->signal->curr_ip = current->signal->curr_ip;
57612+ tsk->signal->saved_ip = current->signal->saved_ip;
57613+ if (current->exec_file)
57614+ get_file(current->exec_file);
57615+ tsk->exec_file = current->exec_file;
57616+ tsk->is_writable = current->is_writable;
57617+ if (unlikely(current->signal->used_accept)) {
57618+ current->signal->curr_ip = 0;
57619+ current->signal->saved_ip = 0;
57620+ }
57621+
57622+ return;
57623+}
57624+
57625+static void
57626+gr_set_proc_res(struct task_struct *task)
57627+{
57628+ struct acl_subject_label *proc;
57629+ unsigned short i;
57630+
57631+ proc = task->acl;
57632+
57633+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
57634+ return;
57635+
57636+ for (i = 0; i < RLIM_NLIMITS; i++) {
57637+ if (!(proc->resmask & (1 << i)))
57638+ continue;
57639+
57640+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
57641+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
57642+ }
57643+
57644+ return;
57645+}
57646+
57647+extern int __gr_process_user_ban(struct user_struct *user);
57648+
57649+int
57650+gr_check_user_change(int real, int effective, int fs)
57651+{
57652+ unsigned int i;
57653+ __u16 num;
57654+ uid_t *uidlist;
57655+ int curuid;
57656+ int realok = 0;
57657+ int effectiveok = 0;
57658+ int fsok = 0;
57659+
57660+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57661+ struct user_struct *user;
57662+
57663+ if (real == -1)
57664+ goto skipit;
57665+
57666+ user = find_user(real);
57667+ if (user == NULL)
57668+ goto skipit;
57669+
57670+ if (__gr_process_user_ban(user)) {
57671+ /* for find_user */
57672+ free_uid(user);
57673+ return 1;
57674+ }
57675+
57676+ /* for find_user */
57677+ free_uid(user);
57678+
57679+skipit:
57680+#endif
57681+
57682+ if (unlikely(!(gr_status & GR_READY)))
57683+ return 0;
57684+
57685+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57686+ gr_log_learn_id_change('u', real, effective, fs);
57687+
57688+ num = current->acl->user_trans_num;
57689+ uidlist = current->acl->user_transitions;
57690+
57691+ if (uidlist == NULL)
57692+ return 0;
57693+
57694+ if (real == -1)
57695+ realok = 1;
57696+ if (effective == -1)
57697+ effectiveok = 1;
57698+ if (fs == -1)
57699+ fsok = 1;
57700+
57701+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
57702+ for (i = 0; i < num; i++) {
57703+ curuid = (int)uidlist[i];
57704+ if (real == curuid)
57705+ realok = 1;
57706+ if (effective == curuid)
57707+ effectiveok = 1;
57708+ if (fs == curuid)
57709+ fsok = 1;
57710+ }
57711+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
57712+ for (i = 0; i < num; i++) {
57713+ curuid = (int)uidlist[i];
57714+ if (real == curuid)
57715+ break;
57716+ if (effective == curuid)
57717+ break;
57718+ if (fs == curuid)
57719+ break;
57720+ }
57721+ /* not in deny list */
57722+ if (i == num) {
57723+ realok = 1;
57724+ effectiveok = 1;
57725+ fsok = 1;
57726+ }
57727+ }
57728+
57729+ if (realok && effectiveok && fsok)
57730+ return 0;
57731+ else {
57732+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
57733+ return 1;
57734+ }
57735+}
57736+
57737+int
57738+gr_check_group_change(int real, int effective, int fs)
57739+{
57740+ unsigned int i;
57741+ __u16 num;
57742+ gid_t *gidlist;
57743+ int curgid;
57744+ int realok = 0;
57745+ int effectiveok = 0;
57746+ int fsok = 0;
57747+
57748+ if (unlikely(!(gr_status & GR_READY)))
57749+ return 0;
57750+
57751+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57752+ gr_log_learn_id_change('g', real, effective, fs);
57753+
57754+ num = current->acl->group_trans_num;
57755+ gidlist = current->acl->group_transitions;
57756+
57757+ if (gidlist == NULL)
57758+ return 0;
57759+
57760+ if (real == -1)
57761+ realok = 1;
57762+ if (effective == -1)
57763+ effectiveok = 1;
57764+ if (fs == -1)
57765+ fsok = 1;
57766+
57767+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
57768+ for (i = 0; i < num; i++) {
57769+ curgid = (int)gidlist[i];
57770+ if (real == curgid)
57771+ realok = 1;
57772+ if (effective == curgid)
57773+ effectiveok = 1;
57774+ if (fs == curgid)
57775+ fsok = 1;
57776+ }
57777+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
57778+ for (i = 0; i < num; i++) {
57779+ curgid = (int)gidlist[i];
57780+ if (real == curgid)
57781+ break;
57782+ if (effective == curgid)
57783+ break;
57784+ if (fs == curgid)
57785+ break;
57786+ }
57787+ /* not in deny list */
57788+ if (i == num) {
57789+ realok = 1;
57790+ effectiveok = 1;
57791+ fsok = 1;
57792+ }
57793+ }
57794+
57795+ if (realok && effectiveok && fsok)
57796+ return 0;
57797+ else {
57798+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
57799+ return 1;
57800+ }
57801+}
57802+
57803+void
57804+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
57805+{
57806+ struct acl_role_label *role = task->role;
57807+ struct acl_subject_label *subj = NULL;
57808+ struct acl_object_label *obj;
57809+ struct file *filp;
57810+
57811+ if (unlikely(!(gr_status & GR_READY)))
57812+ return;
57813+
57814+ filp = task->exec_file;
57815+
57816+ /* kernel process, we'll give them the kernel role */
57817+ if (unlikely(!filp)) {
57818+ task->role = kernel_role;
57819+ task->acl = kernel_role->root_label;
57820+ return;
57821+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
57822+ role = lookup_acl_role_label(task, uid, gid);
57823+
57824+ /* perform subject lookup in possibly new role
57825+ we can use this result below in the case where role == task->role
57826+ */
57827+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
57828+
57829+ /* if we changed uid/gid, but result in the same role
57830+ and are using inheritance, don't lose the inherited subject
57831+ if current subject is other than what normal lookup
57832+ would result in, we arrived via inheritance, don't
57833+ lose subject
57834+ */
57835+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
57836+ (subj == task->acl)))
57837+ task->acl = subj;
57838+
57839+ task->role = role;
57840+
57841+ task->is_writable = 0;
57842+
57843+ /* ignore additional mmap checks for processes that are writable
57844+ by the default ACL */
57845+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57846+ if (unlikely(obj->mode & GR_WRITE))
57847+ task->is_writable = 1;
57848+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57849+ if (unlikely(obj->mode & GR_WRITE))
57850+ task->is_writable = 1;
57851+
57852+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57853+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57854+#endif
57855+
57856+ gr_set_proc_res(task);
57857+
57858+ return;
57859+}
57860+
57861+int
57862+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57863+ const int unsafe_share)
57864+{
57865+ struct task_struct *task = current;
57866+ struct acl_subject_label *newacl;
57867+ struct acl_object_label *obj;
57868+ __u32 retmode;
57869+
57870+ if (unlikely(!(gr_status & GR_READY)))
57871+ return 0;
57872+
57873+ newacl = chk_subj_label(dentry, mnt, task->role);
57874+
57875+ task_lock(task);
57876+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
57877+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57878+ !(task->role->roletype & GR_ROLE_GOD) &&
57879+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57880+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
57881+ task_unlock(task);
57882+ if (unsafe_share)
57883+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57884+ else
57885+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57886+ return -EACCES;
57887+ }
57888+ task_unlock(task);
57889+
57890+ obj = chk_obj_label(dentry, mnt, task->acl);
57891+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57892+
57893+ if (!(task->acl->mode & GR_INHERITLEARN) &&
57894+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57895+ if (obj->nested)
57896+ task->acl = obj->nested;
57897+ else
57898+ task->acl = newacl;
57899+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57900+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57901+
57902+ task->is_writable = 0;
57903+
57904+ /* ignore additional mmap checks for processes that are writable
57905+ by the default ACL */
57906+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
57907+ if (unlikely(obj->mode & GR_WRITE))
57908+ task->is_writable = 1;
57909+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
57910+ if (unlikely(obj->mode & GR_WRITE))
57911+ task->is_writable = 1;
57912+
57913+ gr_set_proc_res(task);
57914+
57915+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57916+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57917+#endif
57918+ return 0;
57919+}
57920+
57921+/* always called with valid inodev ptr */
57922+static void
57923+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57924+{
57925+ struct acl_object_label *matchpo;
57926+ struct acl_subject_label *matchps;
57927+ struct acl_subject_label *subj;
57928+ struct acl_role_label *role;
57929+ unsigned int x;
57930+
57931+ FOR_EACH_ROLE_START(role)
57932+ FOR_EACH_SUBJECT_START(role, subj, x)
57933+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57934+ matchpo->mode |= GR_DELETED;
57935+ FOR_EACH_SUBJECT_END(subj,x)
57936+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57937+ if (subj->inode == ino && subj->device == dev)
57938+ subj->mode |= GR_DELETED;
57939+ FOR_EACH_NESTED_SUBJECT_END(subj)
57940+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57941+ matchps->mode |= GR_DELETED;
57942+ FOR_EACH_ROLE_END(role)
57943+
57944+ inodev->nentry->deleted = 1;
57945+
57946+ return;
57947+}
57948+
57949+void
57950+gr_handle_delete(const ino_t ino, const dev_t dev)
57951+{
57952+ struct inodev_entry *inodev;
57953+
57954+ if (unlikely(!(gr_status & GR_READY)))
57955+ return;
57956+
57957+ write_lock(&gr_inode_lock);
57958+ inodev = lookup_inodev_entry(ino, dev);
57959+ if (inodev != NULL)
57960+ do_handle_delete(inodev, ino, dev);
57961+ write_unlock(&gr_inode_lock);
57962+
57963+ return;
57964+}
57965+
57966+static void
57967+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57968+ const ino_t newinode, const dev_t newdevice,
57969+ struct acl_subject_label *subj)
57970+{
57971+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
57972+ struct acl_object_label *match;
57973+
57974+ match = subj->obj_hash[index];
57975+
57976+ while (match && (match->inode != oldinode ||
57977+ match->device != olddevice ||
57978+ !(match->mode & GR_DELETED)))
57979+ match = match->next;
57980+
57981+ if (match && (match->inode == oldinode)
57982+ && (match->device == olddevice)
57983+ && (match->mode & GR_DELETED)) {
57984+ if (match->prev == NULL) {
57985+ subj->obj_hash[index] = match->next;
57986+ if (match->next != NULL)
57987+ match->next->prev = NULL;
57988+ } else {
57989+ match->prev->next = match->next;
57990+ if (match->next != NULL)
57991+ match->next->prev = match->prev;
57992+ }
57993+ match->prev = NULL;
57994+ match->next = NULL;
57995+ match->inode = newinode;
57996+ match->device = newdevice;
57997+ match->mode &= ~GR_DELETED;
57998+
57999+ insert_acl_obj_label(match, subj);
58000+ }
58001+
58002+ return;
58003+}
58004+
58005+static void
58006+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
58007+ const ino_t newinode, const dev_t newdevice,
58008+ struct acl_role_label *role)
58009+{
58010+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
58011+ struct acl_subject_label *match;
58012+
58013+ match = role->subj_hash[index];
58014+
58015+ while (match && (match->inode != oldinode ||
58016+ match->device != olddevice ||
58017+ !(match->mode & GR_DELETED)))
58018+ match = match->next;
58019+
58020+ if (match && (match->inode == oldinode)
58021+ && (match->device == olddevice)
58022+ && (match->mode & GR_DELETED)) {
58023+ if (match->prev == NULL) {
58024+ role->subj_hash[index] = match->next;
58025+ if (match->next != NULL)
58026+ match->next->prev = NULL;
58027+ } else {
58028+ match->prev->next = match->next;
58029+ if (match->next != NULL)
58030+ match->next->prev = match->prev;
58031+ }
58032+ match->prev = NULL;
58033+ match->next = NULL;
58034+ match->inode = newinode;
58035+ match->device = newdevice;
58036+ match->mode &= ~GR_DELETED;
58037+
58038+ insert_acl_subj_label(match, role);
58039+ }
58040+
58041+ return;
58042+}
58043+
58044+static void
58045+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
58046+ const ino_t newinode, const dev_t newdevice)
58047+{
58048+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
58049+ struct inodev_entry *match;
58050+
58051+ match = inodev_set.i_hash[index];
58052+
58053+ while (match && (match->nentry->inode != oldinode ||
58054+ match->nentry->device != olddevice || !match->nentry->deleted))
58055+ match = match->next;
58056+
58057+ if (match && (match->nentry->inode == oldinode)
58058+ && (match->nentry->device == olddevice) &&
58059+ match->nentry->deleted) {
58060+ if (match->prev == NULL) {
58061+ inodev_set.i_hash[index] = match->next;
58062+ if (match->next != NULL)
58063+ match->next->prev = NULL;
58064+ } else {
58065+ match->prev->next = match->next;
58066+ if (match->next != NULL)
58067+ match->next->prev = match->prev;
58068+ }
58069+ match->prev = NULL;
58070+ match->next = NULL;
58071+ match->nentry->inode = newinode;
58072+ match->nentry->device = newdevice;
58073+ match->nentry->deleted = 0;
58074+
58075+ insert_inodev_entry(match);
58076+ }
58077+
58078+ return;
58079+}
58080+
58081+static void
58082+__do_handle_create(const struct name_entry *matchn, ino_t inode, dev_t dev)
58083+{
58084+ struct acl_subject_label *subj;
58085+ struct acl_role_label *role;
58086+ unsigned int x;
58087+
58088+ FOR_EACH_ROLE_START(role)
58089+ update_acl_subj_label(matchn->inode, matchn->device,
58090+ inode, dev, role);
58091+
58092+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
58093+ if ((subj->inode == inode) && (subj->device == dev)) {
58094+ subj->inode = inode;
58095+ subj->device = dev;
58096+ }
58097+ FOR_EACH_NESTED_SUBJECT_END(subj)
58098+ FOR_EACH_SUBJECT_START(role, subj, x)
58099+ update_acl_obj_label(matchn->inode, matchn->device,
58100+ inode, dev, subj);
58101+ FOR_EACH_SUBJECT_END(subj,x)
58102+ FOR_EACH_ROLE_END(role)
58103+
58104+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
58105+
58106+ return;
58107+}
58108+
58109+static void
58110+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
58111+ const struct vfsmount *mnt)
58112+{
58113+ ino_t ino = dentry->d_inode->i_ino;
58114+ dev_t dev = __get_dev(dentry);
58115+
58116+ __do_handle_create(matchn, ino, dev);
58117+
58118+ return;
58119+}
58120+
58121+void
58122+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58123+{
58124+ struct name_entry *matchn;
58125+
58126+ if (unlikely(!(gr_status & GR_READY)))
58127+ return;
58128+
58129+ preempt_disable();
58130+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
58131+
58132+ if (unlikely((unsigned long)matchn)) {
58133+ write_lock(&gr_inode_lock);
58134+ do_handle_create(matchn, dentry, mnt);
58135+ write_unlock(&gr_inode_lock);
58136+ }
58137+ preempt_enable();
58138+
58139+ return;
58140+}
58141+
58142+void
58143+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58144+{
58145+ struct name_entry *matchn;
58146+
58147+ if (unlikely(!(gr_status & GR_READY)))
58148+ return;
58149+
58150+ preempt_disable();
58151+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
58152+
58153+ if (unlikely((unsigned long)matchn)) {
58154+ write_lock(&gr_inode_lock);
58155+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
58156+ write_unlock(&gr_inode_lock);
58157+ }
58158+ preempt_enable();
58159+
58160+ return;
58161+}
58162+
58163+void
58164+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58165+ struct dentry *old_dentry,
58166+ struct dentry *new_dentry,
58167+ struct vfsmount *mnt, const __u8 replace)
58168+{
58169+ struct name_entry *matchn;
58170+ struct inodev_entry *inodev;
58171+ struct inode *inode = new_dentry->d_inode;
58172+ ino_t oldinode = old_dentry->d_inode->i_ino;
58173+ dev_t olddev = __get_dev(old_dentry);
58174+
58175+ /* vfs_rename swaps the name and parent link for old_dentry and
58176+ new_dentry
58177+ at this point, old_dentry has the new name, parent link, and inode
58178+ for the renamed file
58179+ if a file is being replaced by a rename, new_dentry has the inode
58180+ and name for the replaced file
58181+ */
58182+
58183+ if (unlikely(!(gr_status & GR_READY)))
58184+ return;
58185+
58186+ preempt_disable();
58187+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
58188+
58189+ /* we wouldn't have to check d_inode if it weren't for
58190+ NFS silly-renaming
58191+ */
58192+
58193+ write_lock(&gr_inode_lock);
58194+ if (unlikely(replace && inode)) {
58195+ ino_t newinode = inode->i_ino;
58196+ dev_t newdev = __get_dev(new_dentry);
58197+ inodev = lookup_inodev_entry(newinode, newdev);
58198+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
58199+ do_handle_delete(inodev, newinode, newdev);
58200+ }
58201+
58202+ inodev = lookup_inodev_entry(oldinode, olddev);
58203+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
58204+ do_handle_delete(inodev, oldinode, olddev);
58205+
58206+ if (unlikely((unsigned long)matchn))
58207+ do_handle_create(matchn, old_dentry, mnt);
58208+
58209+ write_unlock(&gr_inode_lock);
58210+ preempt_enable();
58211+
58212+ return;
58213+}
58214+
58215+static int
58216+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
58217+ unsigned char **sum)
58218+{
58219+ struct acl_role_label *r;
58220+ struct role_allowed_ip *ipp;
58221+ struct role_transition *trans;
58222+ unsigned int i;
58223+ int found = 0;
58224+ u32 curr_ip = current->signal->curr_ip;
58225+
58226+ current->signal->saved_ip = curr_ip;
58227+
58228+ /* check transition table */
58229+
58230+ for (trans = current->role->transitions; trans; trans = trans->next) {
58231+ if (!strcmp(rolename, trans->rolename)) {
58232+ found = 1;
58233+ break;
58234+ }
58235+ }
58236+
58237+ if (!found)
58238+ return 0;
58239+
58240+ /* handle special roles that do not require authentication
58241+ and check ip */
58242+
58243+ FOR_EACH_ROLE_START(r)
58244+ if (!strcmp(rolename, r->rolename) &&
58245+ (r->roletype & GR_ROLE_SPECIAL)) {
58246+ found = 0;
58247+ if (r->allowed_ips != NULL) {
58248+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
58249+ if ((ntohl(curr_ip) & ipp->netmask) ==
58250+ (ntohl(ipp->addr) & ipp->netmask))
58251+ found = 1;
58252+ }
58253+ } else
58254+ found = 2;
58255+ if (!found)
58256+ return 0;
58257+
58258+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
58259+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
58260+ *salt = NULL;
58261+ *sum = NULL;
58262+ return 1;
58263+ }
58264+ }
58265+ FOR_EACH_ROLE_END(r)
58266+
58267+ for (i = 0; i < num_sprole_pws; i++) {
58268+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
58269+ *salt = acl_special_roles[i]->salt;
58270+ *sum = acl_special_roles[i]->sum;
58271+ return 1;
58272+ }
58273+ }
58274+
58275+ return 0;
58276+}
58277+
58278+static void
58279+assign_special_role(char *rolename)
58280+{
58281+ struct acl_object_label *obj;
58282+ struct acl_role_label *r;
58283+ struct acl_role_label *assigned = NULL;
58284+ struct task_struct *tsk;
58285+ struct file *filp;
58286+
58287+ FOR_EACH_ROLE_START(r)
58288+ if (!strcmp(rolename, r->rolename) &&
58289+ (r->roletype & GR_ROLE_SPECIAL)) {
58290+ assigned = r;
58291+ break;
58292+ }
58293+ FOR_EACH_ROLE_END(r)
58294+
58295+ if (!assigned)
58296+ return;
58297+
58298+ read_lock(&tasklist_lock);
58299+ read_lock(&grsec_exec_file_lock);
58300+
58301+ tsk = current->real_parent;
58302+ if (tsk == NULL)
58303+ goto out_unlock;
58304+
58305+ filp = tsk->exec_file;
58306+ if (filp == NULL)
58307+ goto out_unlock;
58308+
58309+ tsk->is_writable = 0;
58310+
58311+ tsk->acl_sp_role = 1;
58312+ tsk->acl_role_id = ++acl_sp_role_value;
58313+ tsk->role = assigned;
58314+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
58315+
58316+ /* ignore additional mmap checks for processes that are writable
58317+ by the default ACL */
58318+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58319+ if (unlikely(obj->mode & GR_WRITE))
58320+ tsk->is_writable = 1;
58321+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
58322+ if (unlikely(obj->mode & GR_WRITE))
58323+ tsk->is_writable = 1;
58324+
58325+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58326+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
58327+#endif
58328+
58329+out_unlock:
58330+ read_unlock(&grsec_exec_file_lock);
58331+ read_unlock(&tasklist_lock);
58332+ return;
58333+}
58334+
58335+int gr_check_secure_terminal(struct task_struct *task)
58336+{
58337+ struct task_struct *p, *p2, *p3;
58338+ struct files_struct *files;
58339+ struct fdtable *fdt;
58340+ struct file *our_file = NULL, *file;
58341+ int i;
58342+
58343+ if (task->signal->tty == NULL)
58344+ return 1;
58345+
58346+ files = get_files_struct(task);
58347+ if (files != NULL) {
58348+ rcu_read_lock();
58349+ fdt = files_fdtable(files);
58350+ for (i=0; i < fdt->max_fds; i++) {
58351+ file = fcheck_files(files, i);
58352+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
58353+ get_file(file);
58354+ our_file = file;
58355+ }
58356+ }
58357+ rcu_read_unlock();
58358+ put_files_struct(files);
58359+ }
58360+
58361+ if (our_file == NULL)
58362+ return 1;
58363+
58364+ read_lock(&tasklist_lock);
58365+ do_each_thread(p2, p) {
58366+ files = get_files_struct(p);
58367+ if (files == NULL ||
58368+ (p->signal && p->signal->tty == task->signal->tty)) {
58369+ if (files != NULL)
58370+ put_files_struct(files);
58371+ continue;
58372+ }
58373+ rcu_read_lock();
58374+ fdt = files_fdtable(files);
58375+ for (i=0; i < fdt->max_fds; i++) {
58376+ file = fcheck_files(files, i);
58377+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
58378+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
58379+ p3 = task;
58380+ while (p3->pid > 0) {
58381+ if (p3 == p)
58382+ break;
58383+ p3 = p3->real_parent;
58384+ }
58385+ if (p3 == p)
58386+ break;
58387+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
58388+ gr_handle_alertkill(p);
58389+ rcu_read_unlock();
58390+ put_files_struct(files);
58391+ read_unlock(&tasklist_lock);
58392+ fput(our_file);
58393+ return 0;
58394+ }
58395+ }
58396+ rcu_read_unlock();
58397+ put_files_struct(files);
58398+ } while_each_thread(p2, p);
58399+ read_unlock(&tasklist_lock);
58400+
58401+ fput(our_file);
58402+ return 1;
58403+}
58404+
58405+ssize_t
58406+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
58407+{
58408+ struct gr_arg_wrapper uwrap;
58409+ unsigned char *sprole_salt = NULL;
58410+ unsigned char *sprole_sum = NULL;
58411+ int error = sizeof (struct gr_arg_wrapper);
58412+ int error2 = 0;
58413+
58414+ mutex_lock(&gr_dev_mutex);
58415+
58416+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
58417+ error = -EPERM;
58418+ goto out;
58419+ }
58420+
58421+ if (count != sizeof (struct gr_arg_wrapper)) {
58422+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
58423+ error = -EINVAL;
58424+ goto out;
58425+ }
58426+
58427+
58428+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
58429+ gr_auth_expires = 0;
58430+ gr_auth_attempts = 0;
58431+ }
58432+
58433+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
58434+ error = -EFAULT;
58435+ goto out;
58436+ }
58437+
58438+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
58439+ error = -EINVAL;
58440+ goto out;
58441+ }
58442+
58443+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
58444+ error = -EFAULT;
58445+ goto out;
58446+ }
58447+
58448+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58449+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58450+ time_after(gr_auth_expires, get_seconds())) {
58451+ error = -EBUSY;
58452+ goto out;
58453+ }
58454+
58455+ /* if non-root trying to do anything other than use a special role,
58456+ do not attempt authentication, do not count towards authentication
58457+ locking
58458+ */
58459+
58460+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
58461+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58462+ current_uid()) {
58463+ error = -EPERM;
58464+ goto out;
58465+ }
58466+
58467+ /* ensure pw and special role name are null terminated */
58468+
58469+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
58470+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
58471+
58472+ /* Okay.
58473+ * We have our enough of the argument structure..(we have yet
58474+ * to copy_from_user the tables themselves) . Copy the tables
58475+ * only if we need them, i.e. for loading operations. */
58476+
58477+ switch (gr_usermode->mode) {
58478+ case GR_STATUS:
58479+ if (gr_status & GR_READY) {
58480+ error = 1;
58481+ if (!gr_check_secure_terminal(current))
58482+ error = 3;
58483+ } else
58484+ error = 2;
58485+ goto out;
58486+ case GR_SHUTDOWN:
58487+ if ((gr_status & GR_READY)
58488+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58489+ pax_open_kernel();
58490+ gr_status &= ~GR_READY;
58491+ pax_close_kernel();
58492+
58493+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
58494+ free_variables();
58495+ memset(gr_usermode, 0, sizeof (struct gr_arg));
58496+ memset(gr_system_salt, 0, GR_SALT_LEN);
58497+ memset(gr_system_sum, 0, GR_SHA_LEN);
58498+ } else if (gr_status & GR_READY) {
58499+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
58500+ error = -EPERM;
58501+ } else {
58502+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
58503+ error = -EAGAIN;
58504+ }
58505+ break;
58506+ case GR_ENABLE:
58507+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
58508+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
58509+ else {
58510+ if (gr_status & GR_READY)
58511+ error = -EAGAIN;
58512+ else
58513+ error = error2;
58514+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
58515+ }
58516+ break;
58517+ case GR_RELOAD:
58518+ if (!(gr_status & GR_READY)) {
58519+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
58520+ error = -EAGAIN;
58521+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58522+ lock_kernel();
58523+
58524+ pax_open_kernel();
58525+ gr_status &= ~GR_READY;
58526+ pax_close_kernel();
58527+
58528+ free_variables();
58529+ if (!(error2 = gracl_init(gr_usermode))) {
58530+ unlock_kernel();
58531+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
58532+ } else {
58533+ unlock_kernel();
58534+ error = error2;
58535+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58536+ }
58537+ } else {
58538+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58539+ error = -EPERM;
58540+ }
58541+ break;
58542+ case GR_SEGVMOD:
58543+ if (unlikely(!(gr_status & GR_READY))) {
58544+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
58545+ error = -EAGAIN;
58546+ break;
58547+ }
58548+
58549+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58550+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
58551+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
58552+ struct acl_subject_label *segvacl;
58553+ segvacl =
58554+ lookup_acl_subj_label(gr_usermode->segv_inode,
58555+ gr_usermode->segv_device,
58556+ current->role);
58557+ if (segvacl) {
58558+ segvacl->crashes = 0;
58559+ segvacl->expires = 0;
58560+ }
58561+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
58562+ gr_remove_uid(gr_usermode->segv_uid);
58563+ }
58564+ } else {
58565+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
58566+ error = -EPERM;
58567+ }
58568+ break;
58569+ case GR_SPROLE:
58570+ case GR_SPROLEPAM:
58571+ if (unlikely(!(gr_status & GR_READY))) {
58572+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
58573+ error = -EAGAIN;
58574+ break;
58575+ }
58576+
58577+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
58578+ current->role->expires = 0;
58579+ current->role->auth_attempts = 0;
58580+ }
58581+
58582+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58583+ time_after(current->role->expires, get_seconds())) {
58584+ error = -EBUSY;
58585+ goto out;
58586+ }
58587+
58588+ if (lookup_special_role_auth
58589+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
58590+ && ((!sprole_salt && !sprole_sum)
58591+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
58592+ char *p = "";
58593+ assign_special_role(gr_usermode->sp_role);
58594+ read_lock(&tasklist_lock);
58595+ if (current->real_parent)
58596+ p = current->real_parent->role->rolename;
58597+ read_unlock(&tasklist_lock);
58598+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
58599+ p, acl_sp_role_value);
58600+ } else {
58601+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
58602+ error = -EPERM;
58603+ if(!(current->role->auth_attempts++))
58604+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58605+
58606+ goto out;
58607+ }
58608+ break;
58609+ case GR_UNSPROLE:
58610+ if (unlikely(!(gr_status & GR_READY))) {
58611+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
58612+ error = -EAGAIN;
58613+ break;
58614+ }
58615+
58616+ if (current->role->roletype & GR_ROLE_SPECIAL) {
58617+ char *p = "";
58618+ int i = 0;
58619+
58620+ read_lock(&tasklist_lock);
58621+ if (current->real_parent) {
58622+ p = current->real_parent->role->rolename;
58623+ i = current->real_parent->acl_role_id;
58624+ }
58625+ read_unlock(&tasklist_lock);
58626+
58627+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
58628+ gr_set_acls(1);
58629+ } else {
58630+ error = -EPERM;
58631+ goto out;
58632+ }
58633+ break;
58634+ default:
58635+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
58636+ error = -EINVAL;
58637+ break;
58638+ }
58639+
58640+ if (error != -EPERM)
58641+ goto out;
58642+
58643+ if(!(gr_auth_attempts++))
58644+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58645+
58646+ out:
58647+ mutex_unlock(&gr_dev_mutex);
58648+ return error;
58649+}
58650+
58651+/* must be called with
58652+ rcu_read_lock();
58653+ read_lock(&tasklist_lock);
58654+ read_lock(&grsec_exec_file_lock);
58655+*/
58656+int gr_apply_subject_to_task(struct task_struct *task)
58657+{
58658+ struct acl_object_label *obj;
58659+ char *tmpname;
58660+ struct acl_subject_label *tmpsubj;
58661+ struct file *filp;
58662+ struct name_entry *nmatch;
58663+
58664+ filp = task->exec_file;
58665+ if (filp == NULL)
58666+ return 0;
58667+
58668+ /* the following is to apply the correct subject
58669+ on binaries running when the RBAC system
58670+ is enabled, when the binaries have been
58671+ replaced or deleted since their execution
58672+ -----
58673+ when the RBAC system starts, the inode/dev
58674+ from exec_file will be one the RBAC system
58675+ is unaware of. It only knows the inode/dev
58676+ of the present file on disk, or the absence
58677+ of it.
58678+ */
58679+ preempt_disable();
58680+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
58681+
58682+ nmatch = lookup_name_entry(tmpname);
58683+ preempt_enable();
58684+ tmpsubj = NULL;
58685+ if (nmatch) {
58686+ if (nmatch->deleted)
58687+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
58688+ else
58689+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
58690+ if (tmpsubj != NULL)
58691+ task->acl = tmpsubj;
58692+ }
58693+ if (tmpsubj == NULL)
58694+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
58695+ task->role);
58696+ if (task->acl) {
58697+ task->is_writable = 0;
58698+ /* ignore additional mmap checks for processes that are writable
58699+ by the default ACL */
58700+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58701+ if (unlikely(obj->mode & GR_WRITE))
58702+ task->is_writable = 1;
58703+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
58704+ if (unlikely(obj->mode & GR_WRITE))
58705+ task->is_writable = 1;
58706+
58707+ gr_set_proc_res(task);
58708+
58709+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58710+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58711+#endif
58712+ } else {
58713+ return 1;
58714+ }
58715+
58716+ return 0;
58717+}
58718+
58719+int
58720+gr_set_acls(const int type)
58721+{
58722+ struct task_struct *task, *task2;
58723+ struct acl_role_label *role = current->role;
58724+ __u16 acl_role_id = current->acl_role_id;
58725+ const struct cred *cred;
58726+ int ret;
58727+
58728+ rcu_read_lock();
58729+ read_lock(&tasklist_lock);
58730+ read_lock(&grsec_exec_file_lock);
58731+ do_each_thread(task2, task) {
58732+ /* check to see if we're called from the exit handler,
58733+ if so, only replace ACLs that have inherited the admin
58734+ ACL */
58735+
58736+ if (type && (task->role != role ||
58737+ task->acl_role_id != acl_role_id))
58738+ continue;
58739+
58740+ task->acl_role_id = 0;
58741+ task->acl_sp_role = 0;
58742+
58743+ if (task->exec_file) {
58744+ cred = __task_cred(task);
58745+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
58746+
58747+ ret = gr_apply_subject_to_task(task);
58748+ if (ret) {
58749+ read_unlock(&grsec_exec_file_lock);
58750+ read_unlock(&tasklist_lock);
58751+ rcu_read_unlock();
58752+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
58753+ return ret;
58754+ }
58755+ } else {
58756+ // it's a kernel process
58757+ task->role = kernel_role;
58758+ task->acl = kernel_role->root_label;
58759+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
58760+ task->acl->mode &= ~GR_PROCFIND;
58761+#endif
58762+ }
58763+ } while_each_thread(task2, task);
58764+ read_unlock(&grsec_exec_file_lock);
58765+ read_unlock(&tasklist_lock);
58766+ rcu_read_unlock();
58767+
58768+ return 0;
58769+}
58770+
58771+void
58772+gr_learn_resource(const struct task_struct *task,
58773+ const int res, const unsigned long wanted, const int gt)
58774+{
58775+ struct acl_subject_label *acl;
58776+ const struct cred *cred;
58777+
58778+ if (unlikely((gr_status & GR_READY) &&
58779+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
58780+ goto skip_reslog;
58781+
58782+#ifdef CONFIG_GRKERNSEC_RESLOG
58783+ gr_log_resource(task, res, wanted, gt);
58784+#endif
58785+ skip_reslog:
58786+
58787+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
58788+ return;
58789+
58790+ acl = task->acl;
58791+
58792+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
58793+ !(acl->resmask & (1 << (unsigned short) res))))
58794+ return;
58795+
58796+ if (wanted >= acl->res[res].rlim_cur) {
58797+ unsigned long res_add;
58798+
58799+ res_add = wanted;
58800+ switch (res) {
58801+ case RLIMIT_CPU:
58802+ res_add += GR_RLIM_CPU_BUMP;
58803+ break;
58804+ case RLIMIT_FSIZE:
58805+ res_add += GR_RLIM_FSIZE_BUMP;
58806+ break;
58807+ case RLIMIT_DATA:
58808+ res_add += GR_RLIM_DATA_BUMP;
58809+ break;
58810+ case RLIMIT_STACK:
58811+ res_add += GR_RLIM_STACK_BUMP;
58812+ break;
58813+ case RLIMIT_CORE:
58814+ res_add += GR_RLIM_CORE_BUMP;
58815+ break;
58816+ case RLIMIT_RSS:
58817+ res_add += GR_RLIM_RSS_BUMP;
58818+ break;
58819+ case RLIMIT_NPROC:
58820+ res_add += GR_RLIM_NPROC_BUMP;
58821+ break;
58822+ case RLIMIT_NOFILE:
58823+ res_add += GR_RLIM_NOFILE_BUMP;
58824+ break;
58825+ case RLIMIT_MEMLOCK:
58826+ res_add += GR_RLIM_MEMLOCK_BUMP;
58827+ break;
58828+ case RLIMIT_AS:
58829+ res_add += GR_RLIM_AS_BUMP;
58830+ break;
58831+ case RLIMIT_LOCKS:
58832+ res_add += GR_RLIM_LOCKS_BUMP;
58833+ break;
58834+ case RLIMIT_SIGPENDING:
58835+ res_add += GR_RLIM_SIGPENDING_BUMP;
58836+ break;
58837+ case RLIMIT_MSGQUEUE:
58838+ res_add += GR_RLIM_MSGQUEUE_BUMP;
58839+ break;
58840+ case RLIMIT_NICE:
58841+ res_add += GR_RLIM_NICE_BUMP;
58842+ break;
58843+ case RLIMIT_RTPRIO:
58844+ res_add += GR_RLIM_RTPRIO_BUMP;
58845+ break;
58846+ case RLIMIT_RTTIME:
58847+ res_add += GR_RLIM_RTTIME_BUMP;
58848+ break;
58849+ }
58850+
58851+ acl->res[res].rlim_cur = res_add;
58852+
58853+ if (wanted > acl->res[res].rlim_max)
58854+ acl->res[res].rlim_max = res_add;
58855+
58856+ /* only log the subject filename, since resource logging is supported for
58857+ single-subject learning only */
58858+ rcu_read_lock();
58859+ cred = __task_cred(task);
58860+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58861+ task->role->roletype, cred->uid, cred->gid, acl->filename,
58862+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
58863+ "", (unsigned long) res, &task->signal->saved_ip);
58864+ rcu_read_unlock();
58865+ }
58866+
58867+ return;
58868+}
58869+
58870+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
58871+void
58872+pax_set_initial_flags(struct linux_binprm *bprm)
58873+{
58874+ struct task_struct *task = current;
58875+ struct acl_subject_label *proc;
58876+ unsigned long flags;
58877+
58878+ if (unlikely(!(gr_status & GR_READY)))
58879+ return;
58880+
58881+ flags = pax_get_flags(task);
58882+
58883+ proc = task->acl;
58884+
58885+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58886+ flags &= ~MF_PAX_PAGEEXEC;
58887+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58888+ flags &= ~MF_PAX_SEGMEXEC;
58889+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58890+ flags &= ~MF_PAX_RANDMMAP;
58891+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58892+ flags &= ~MF_PAX_EMUTRAMP;
58893+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58894+ flags &= ~MF_PAX_MPROTECT;
58895+
58896+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58897+ flags |= MF_PAX_PAGEEXEC;
58898+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58899+ flags |= MF_PAX_SEGMEXEC;
58900+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58901+ flags |= MF_PAX_RANDMMAP;
58902+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58903+ flags |= MF_PAX_EMUTRAMP;
58904+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58905+ flags |= MF_PAX_MPROTECT;
58906+
58907+ pax_set_flags(task, flags);
58908+
58909+ return;
58910+}
58911+#endif
58912+
58913+#ifdef CONFIG_SYSCTL
58914+/* Eric Biederman likes breaking userland ABI and every inode-based security
58915+ system to save 35kb of memory */
58916+
58917+/* we modify the passed in filename, but adjust it back before returning */
58918+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
58919+{
58920+ struct name_entry *nmatch;
58921+ char *p, *lastp = NULL;
58922+ struct acl_object_label *obj = NULL, *tmp;
58923+ struct acl_subject_label *tmpsubj;
58924+ char c = '\0';
58925+
58926+ read_lock(&gr_inode_lock);
58927+
58928+ p = name + len - 1;
58929+ do {
58930+ nmatch = lookup_name_entry(name);
58931+ if (lastp != NULL)
58932+ *lastp = c;
58933+
58934+ if (nmatch == NULL)
58935+ goto next_component;
58936+ tmpsubj = current->acl;
58937+ do {
58938+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
58939+ if (obj != NULL) {
58940+ tmp = obj->globbed;
58941+ while (tmp) {
58942+ if (!glob_match(tmp->filename, name)) {
58943+ obj = tmp;
58944+ goto found_obj;
58945+ }
58946+ tmp = tmp->next;
58947+ }
58948+ goto found_obj;
58949+ }
58950+ } while ((tmpsubj = tmpsubj->parent_subject));
58951+next_component:
58952+ /* end case */
58953+ if (p == name)
58954+ break;
58955+
58956+ while (*p != '/')
58957+ p--;
58958+ if (p == name)
58959+ lastp = p + 1;
58960+ else {
58961+ lastp = p;
58962+ p--;
58963+ }
58964+ c = *lastp;
58965+ *lastp = '\0';
58966+ } while (1);
58967+found_obj:
58968+ read_unlock(&gr_inode_lock);
58969+ /* obj returned will always be non-null */
58970+ return obj;
58971+}
58972+
58973+/* returns 0 when allowing, non-zero on error
58974+ op of 0 is used for readdir, so we don't log the names of hidden files
58975+*/
58976+__u32
58977+gr_handle_sysctl(const struct ctl_table *table, const int op)
58978+{
58979+ ctl_table *tmp;
58980+ const char *proc_sys = "/proc/sys";
58981+ char *path;
58982+ struct acl_object_label *obj;
58983+ unsigned short len = 0, pos = 0, depth = 0, i;
58984+ __u32 err = 0;
58985+ __u32 mode = 0;
58986+
58987+ if (unlikely(!(gr_status & GR_READY)))
58988+ return 0;
58989+
58990+ /* for now, ignore operations on non-sysctl entries if it's not a
58991+ readdir*/
58992+ if (table->child != NULL && op != 0)
58993+ return 0;
58994+
58995+ mode |= GR_FIND;
58996+ /* it's only a read if it's an entry, read on dirs is for readdir */
58997+ if (op & MAY_READ)
58998+ mode |= GR_READ;
58999+ if (op & MAY_WRITE)
59000+ mode |= GR_WRITE;
59001+
59002+ preempt_disable();
59003+
59004+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
59005+
59006+ /* it's only a read/write if it's an actual entry, not a dir
59007+ (which are opened for readdir)
59008+ */
59009+
59010+ /* convert the requested sysctl entry into a pathname */
59011+
59012+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59013+ len += strlen(tmp->procname);
59014+ len++;
59015+ depth++;
59016+ }
59017+
59018+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
59019+ /* deny */
59020+ goto out;
59021+ }
59022+
59023+ memset(path, 0, PAGE_SIZE);
59024+
59025+ memcpy(path, proc_sys, strlen(proc_sys));
59026+
59027+ pos += strlen(proc_sys);
59028+
59029+ for (; depth > 0; depth--) {
59030+ path[pos] = '/';
59031+ pos++;
59032+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59033+ if (depth == i) {
59034+ memcpy(path + pos, tmp->procname,
59035+ strlen(tmp->procname));
59036+ pos += strlen(tmp->procname);
59037+ }
59038+ i++;
59039+ }
59040+ }
59041+
59042+ obj = gr_lookup_by_name(path, pos);
59043+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
59044+
59045+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
59046+ ((err & mode) != mode))) {
59047+ __u32 new_mode = mode;
59048+
59049+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59050+
59051+ err = 0;
59052+ gr_log_learn_sysctl(path, new_mode);
59053+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
59054+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
59055+ err = -ENOENT;
59056+ } else if (!(err & GR_FIND)) {
59057+ err = -ENOENT;
59058+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
59059+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
59060+ path, (mode & GR_READ) ? " reading" : "",
59061+ (mode & GR_WRITE) ? " writing" : "");
59062+ err = -EACCES;
59063+ } else if ((err & mode) != mode) {
59064+ err = -EACCES;
59065+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
59066+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
59067+ path, (mode & GR_READ) ? " reading" : "",
59068+ (mode & GR_WRITE) ? " writing" : "");
59069+ err = 0;
59070+ } else
59071+ err = 0;
59072+
59073+ out:
59074+ preempt_enable();
59075+
59076+ return err;
59077+}
59078+#endif
59079+
59080+int
59081+gr_handle_proc_ptrace(struct task_struct *task)
59082+{
59083+ struct file *filp;
59084+ struct task_struct *tmp = task;
59085+ struct task_struct *curtemp = current;
59086+ __u32 retmode;
59087+
59088+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59089+ if (unlikely(!(gr_status & GR_READY)))
59090+ return 0;
59091+#endif
59092+
59093+ read_lock(&tasklist_lock);
59094+ read_lock(&grsec_exec_file_lock);
59095+ filp = task->exec_file;
59096+
59097+ while (tmp->pid > 0) {
59098+ if (tmp == curtemp)
59099+ break;
59100+ tmp = tmp->real_parent;
59101+ }
59102+
59103+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59104+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
59105+ read_unlock(&grsec_exec_file_lock);
59106+ read_unlock(&tasklist_lock);
59107+ return 1;
59108+ }
59109+
59110+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59111+ if (!(gr_status & GR_READY)) {
59112+ read_unlock(&grsec_exec_file_lock);
59113+ read_unlock(&tasklist_lock);
59114+ return 0;
59115+ }
59116+#endif
59117+
59118+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
59119+ read_unlock(&grsec_exec_file_lock);
59120+ read_unlock(&tasklist_lock);
59121+
59122+ if (retmode & GR_NOPTRACE)
59123+ return 1;
59124+
59125+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
59126+ && (current->acl != task->acl || (current->acl != current->role->root_label
59127+ && current->pid != task->pid)))
59128+ return 1;
59129+
59130+ return 0;
59131+}
59132+
59133+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
59134+{
59135+ if (unlikely(!(gr_status & GR_READY)))
59136+ return;
59137+
59138+ if (!(current->role->roletype & GR_ROLE_GOD))
59139+ return;
59140+
59141+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
59142+ p->role->rolename, gr_task_roletype_to_char(p),
59143+ p->acl->filename);
59144+}
59145+
59146+int
59147+gr_handle_ptrace(struct task_struct *task, const long request)
59148+{
59149+ struct task_struct *tmp = task;
59150+ struct task_struct *curtemp = current;
59151+ __u32 retmode;
59152+
59153+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59154+ if (unlikely(!(gr_status & GR_READY)))
59155+ return 0;
59156+#endif
59157+
59158+ read_lock(&tasklist_lock);
59159+ while (tmp->pid > 0) {
59160+ if (tmp == curtemp)
59161+ break;
59162+ tmp = tmp->real_parent;
59163+ }
59164+
59165+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59166+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
59167+ read_unlock(&tasklist_lock);
59168+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59169+ return 1;
59170+ }
59171+ read_unlock(&tasklist_lock);
59172+
59173+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59174+ if (!(gr_status & GR_READY))
59175+ return 0;
59176+#endif
59177+
59178+ read_lock(&grsec_exec_file_lock);
59179+ if (unlikely(!task->exec_file)) {
59180+ read_unlock(&grsec_exec_file_lock);
59181+ return 0;
59182+ }
59183+
59184+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
59185+ read_unlock(&grsec_exec_file_lock);
59186+
59187+ if (retmode & GR_NOPTRACE) {
59188+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59189+ return 1;
59190+ }
59191+
59192+ if (retmode & GR_PTRACERD) {
59193+ switch (request) {
59194+ case PTRACE_POKETEXT:
59195+ case PTRACE_POKEDATA:
59196+ case PTRACE_POKEUSR:
59197+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
59198+ case PTRACE_SETREGS:
59199+ case PTRACE_SETFPREGS:
59200+#endif
59201+#ifdef CONFIG_X86
59202+ case PTRACE_SETFPXREGS:
59203+#endif
59204+#ifdef CONFIG_ALTIVEC
59205+ case PTRACE_SETVRREGS:
59206+#endif
59207+ return 1;
59208+ default:
59209+ return 0;
59210+ }
59211+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
59212+ !(current->role->roletype & GR_ROLE_GOD) &&
59213+ (current->acl != task->acl)) {
59214+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59215+ return 1;
59216+ }
59217+
59218+ return 0;
59219+}
59220+
59221+static int is_writable_mmap(const struct file *filp)
59222+{
59223+ struct task_struct *task = current;
59224+ struct acl_object_label *obj, *obj2;
59225+
59226+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
59227+ !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))) {
59228+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59229+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
59230+ task->role->root_label);
59231+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
59232+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
59233+ return 1;
59234+ }
59235+ }
59236+ return 0;
59237+}
59238+
59239+int
59240+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
59241+{
59242+ __u32 mode;
59243+
59244+ if (unlikely(!file || !(prot & PROT_EXEC)))
59245+ return 1;
59246+
59247+ if (is_writable_mmap(file))
59248+ return 0;
59249+
59250+ mode =
59251+ gr_search_file(file->f_path.dentry,
59252+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59253+ file->f_path.mnt);
59254+
59255+ if (!gr_tpe_allow(file))
59256+ return 0;
59257+
59258+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59259+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59260+ return 0;
59261+ } else if (unlikely(!(mode & GR_EXEC))) {
59262+ return 0;
59263+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59264+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59265+ return 1;
59266+ }
59267+
59268+ return 1;
59269+}
59270+
59271+int
59272+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59273+{
59274+ __u32 mode;
59275+
59276+ if (unlikely(!file || !(prot & PROT_EXEC)))
59277+ return 1;
59278+
59279+ if (is_writable_mmap(file))
59280+ return 0;
59281+
59282+ mode =
59283+ gr_search_file(file->f_path.dentry,
59284+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59285+ file->f_path.mnt);
59286+
59287+ if (!gr_tpe_allow(file))
59288+ return 0;
59289+
59290+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59291+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59292+ return 0;
59293+ } else if (unlikely(!(mode & GR_EXEC))) {
59294+ return 0;
59295+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59296+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59297+ return 1;
59298+ }
59299+
59300+ return 1;
59301+}
59302+
59303+void
59304+gr_acl_handle_psacct(struct task_struct *task, const long code)
59305+{
59306+ unsigned long runtime;
59307+ unsigned long cputime;
59308+ unsigned int wday, cday;
59309+ __u8 whr, chr;
59310+ __u8 wmin, cmin;
59311+ __u8 wsec, csec;
59312+ struct timespec timeval;
59313+
59314+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
59315+ !(task->acl->mode & GR_PROCACCT)))
59316+ return;
59317+
59318+ do_posix_clock_monotonic_gettime(&timeval);
59319+ runtime = timeval.tv_sec - task->start_time.tv_sec;
59320+ wday = runtime / (3600 * 24);
59321+ runtime -= wday * (3600 * 24);
59322+ whr = runtime / 3600;
59323+ runtime -= whr * 3600;
59324+ wmin = runtime / 60;
59325+ runtime -= wmin * 60;
59326+ wsec = runtime;
59327+
59328+ cputime = (task->utime + task->stime) / HZ;
59329+ cday = cputime / (3600 * 24);
59330+ cputime -= cday * (3600 * 24);
59331+ chr = cputime / 3600;
59332+ cputime -= chr * 3600;
59333+ cmin = cputime / 60;
59334+ cputime -= cmin * 60;
59335+ csec = cputime;
59336+
59337+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
59338+
59339+ return;
59340+}
59341+
59342+void gr_set_kernel_label(struct task_struct *task)
59343+{
59344+ if (gr_status & GR_READY) {
59345+ task->role = kernel_role;
59346+ task->acl = kernel_role->root_label;
59347+ }
59348+ return;
59349+}
59350+
59351+#ifdef CONFIG_TASKSTATS
59352+int gr_is_taskstats_denied(int pid)
59353+{
59354+ struct task_struct *task;
59355+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59356+ const struct cred *cred;
59357+#endif
59358+ int ret = 0;
59359+
59360+ /* restrict taskstats viewing to un-chrooted root users
59361+ who have the 'view' subject flag if the RBAC system is enabled
59362+ */
59363+
59364+ rcu_read_lock();
59365+ read_lock(&tasklist_lock);
59366+ task = find_task_by_vpid(pid);
59367+ if (task) {
59368+#ifdef CONFIG_GRKERNSEC_CHROOT
59369+ if (proc_is_chrooted(task))
59370+ ret = -EACCES;
59371+#endif
59372+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59373+ cred = __task_cred(task);
59374+#ifdef CONFIG_GRKERNSEC_PROC_USER
59375+ if (cred->uid != 0)
59376+ ret = -EACCES;
59377+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59378+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
59379+ ret = -EACCES;
59380+#endif
59381+#endif
59382+ if (gr_status & GR_READY) {
59383+ if (!(task->acl->mode & GR_VIEW))
59384+ ret = -EACCES;
59385+ }
59386+ } else
59387+ ret = -ENOENT;
59388+
59389+ read_unlock(&tasklist_lock);
59390+ rcu_read_unlock();
59391+
59392+ return ret;
59393+}
59394+#endif
59395+
59396+/* AUXV entries are filled via a descendant of search_binary_handler
59397+ after we've already applied the subject for the target
59398+*/
59399+int gr_acl_enable_at_secure(void)
59400+{
59401+ if (unlikely(!(gr_status & GR_READY)))
59402+ return 0;
59403+
59404+ if (current->acl->mode & GR_ATSECURE)
59405+ return 1;
59406+
59407+ return 0;
59408+}
59409+
59410+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
59411+{
59412+ struct task_struct *task = current;
59413+ struct dentry *dentry = file->f_path.dentry;
59414+ struct vfsmount *mnt = file->f_path.mnt;
59415+ struct acl_object_label *obj, *tmp;
59416+ struct acl_subject_label *subj;
59417+ unsigned int bufsize;
59418+ int is_not_root;
59419+ char *path;
59420+ dev_t dev = __get_dev(dentry);
59421+
59422+ if (unlikely(!(gr_status & GR_READY)))
59423+ return 1;
59424+
59425+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59426+ return 1;
59427+
59428+ /* ignore Eric Biederman */
59429+ if (IS_PRIVATE(dentry->d_inode))
59430+ return 1;
59431+
59432+ subj = task->acl;
59433+ do {
59434+ obj = lookup_acl_obj_label(ino, dev, subj);
59435+ if (obj != NULL)
59436+ return (obj->mode & GR_FIND) ? 1 : 0;
59437+ } while ((subj = subj->parent_subject));
59438+
59439+ /* this is purely an optimization since we're looking for an object
59440+ for the directory we're doing a readdir on
59441+ if it's possible for any globbed object to match the entry we're
59442+ filling into the directory, then the object we find here will be
59443+ an anchor point with attached globbed objects
59444+ */
59445+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
59446+ if (obj->globbed == NULL)
59447+ return (obj->mode & GR_FIND) ? 1 : 0;
59448+
59449+ is_not_root = ((obj->filename[0] == '/') &&
59450+ (obj->filename[1] == '\0')) ? 0 : 1;
59451+ bufsize = PAGE_SIZE - namelen - is_not_root;
59452+
59453+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
59454+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
59455+ return 1;
59456+
59457+ preempt_disable();
59458+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
59459+ bufsize);
59460+
59461+ bufsize = strlen(path);
59462+
59463+ /* if base is "/", don't append an additional slash */
59464+ if (is_not_root)
59465+ *(path + bufsize) = '/';
59466+ memcpy(path + bufsize + is_not_root, name, namelen);
59467+ *(path + bufsize + namelen + is_not_root) = '\0';
59468+
59469+ tmp = obj->globbed;
59470+ while (tmp) {
59471+ if (!glob_match(tmp->filename, path)) {
59472+ preempt_enable();
59473+ return (tmp->mode & GR_FIND) ? 1 : 0;
59474+ }
59475+ tmp = tmp->next;
59476+ }
59477+ preempt_enable();
59478+ return (obj->mode & GR_FIND) ? 1 : 0;
59479+}
59480+
59481+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
59482+EXPORT_SYMBOL(gr_acl_is_enabled);
59483+#endif
59484+EXPORT_SYMBOL(gr_learn_resource);
59485+EXPORT_SYMBOL(gr_set_kernel_label);
59486+#ifdef CONFIG_SECURITY
59487+EXPORT_SYMBOL(gr_check_user_change);
59488+EXPORT_SYMBOL(gr_check_group_change);
59489+#endif
59490+
59491diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
59492new file mode 100644
59493index 0000000..34fefda
59494--- /dev/null
59495+++ b/grsecurity/gracl_alloc.c
59496@@ -0,0 +1,105 @@
59497+#include <linux/kernel.h>
59498+#include <linux/mm.h>
59499+#include <linux/slab.h>
59500+#include <linux/vmalloc.h>
59501+#include <linux/gracl.h>
59502+#include <linux/grsecurity.h>
59503+
59504+static unsigned long alloc_stack_next = 1;
59505+static unsigned long alloc_stack_size = 1;
59506+static void **alloc_stack;
59507+
59508+static __inline__ int
59509+alloc_pop(void)
59510+{
59511+ if (alloc_stack_next == 1)
59512+ return 0;
59513+
59514+ kfree(alloc_stack[alloc_stack_next - 2]);
59515+
59516+ alloc_stack_next--;
59517+
59518+ return 1;
59519+}
59520+
59521+static __inline__ int
59522+alloc_push(void *buf)
59523+{
59524+ if (alloc_stack_next >= alloc_stack_size)
59525+ return 1;
59526+
59527+ alloc_stack[alloc_stack_next - 1] = buf;
59528+
59529+ alloc_stack_next++;
59530+
59531+ return 0;
59532+}
59533+
59534+void *
59535+acl_alloc(unsigned long len)
59536+{
59537+ void *ret = NULL;
59538+
59539+ if (!len || len > PAGE_SIZE)
59540+ goto out;
59541+
59542+ ret = kmalloc(len, GFP_KERNEL);
59543+
59544+ if (ret) {
59545+ if (alloc_push(ret)) {
59546+ kfree(ret);
59547+ ret = NULL;
59548+ }
59549+ }
59550+
59551+out:
59552+ return ret;
59553+}
59554+
59555+void *
59556+acl_alloc_num(unsigned long num, unsigned long len)
59557+{
59558+ if (!len || (num > (PAGE_SIZE / len)))
59559+ return NULL;
59560+
59561+ return acl_alloc(num * len);
59562+}
59563+
59564+void
59565+acl_free_all(void)
59566+{
59567+ if (gr_acl_is_enabled() || !alloc_stack)
59568+ return;
59569+
59570+ while (alloc_pop()) ;
59571+
59572+ if (alloc_stack) {
59573+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
59574+ kfree(alloc_stack);
59575+ else
59576+ vfree(alloc_stack);
59577+ }
59578+
59579+ alloc_stack = NULL;
59580+ alloc_stack_size = 1;
59581+ alloc_stack_next = 1;
59582+
59583+ return;
59584+}
59585+
59586+int
59587+acl_alloc_stack_init(unsigned long size)
59588+{
59589+ if ((size * sizeof (void *)) <= PAGE_SIZE)
59590+ alloc_stack =
59591+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
59592+ else
59593+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
59594+
59595+ alloc_stack_size = size;
59596+
59597+ if (!alloc_stack)
59598+ return 0;
59599+ else
59600+ return 1;
59601+}
59602diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
59603new file mode 100644
59604index 0000000..955ddfb
59605--- /dev/null
59606+++ b/grsecurity/gracl_cap.c
59607@@ -0,0 +1,101 @@
59608+#include <linux/kernel.h>
59609+#include <linux/module.h>
59610+#include <linux/sched.h>
59611+#include <linux/gracl.h>
59612+#include <linux/grsecurity.h>
59613+#include <linux/grinternal.h>
59614+
59615+extern const char *captab_log[];
59616+extern int captab_log_entries;
59617+
59618+int
59619+gr_acl_is_capable(const int cap)
59620+{
59621+ struct task_struct *task = current;
59622+ const struct cred *cred = current_cred();
59623+ struct acl_subject_label *curracl;
59624+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59625+ kernel_cap_t cap_audit = __cap_empty_set;
59626+
59627+ if (!gr_acl_is_enabled())
59628+ return 1;
59629+
59630+ curracl = task->acl;
59631+
59632+ cap_drop = curracl->cap_lower;
59633+ cap_mask = curracl->cap_mask;
59634+ cap_audit = curracl->cap_invert_audit;
59635+
59636+ while ((curracl = curracl->parent_subject)) {
59637+ /* if the cap isn't specified in the current computed mask but is specified in the
59638+ current level subject, and is lowered in the current level subject, then add
59639+ it to the set of dropped capabilities
59640+ otherwise, add the current level subject's mask to the current computed mask
59641+ */
59642+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59643+ cap_raise(cap_mask, cap);
59644+ if (cap_raised(curracl->cap_lower, cap))
59645+ cap_raise(cap_drop, cap);
59646+ if (cap_raised(curracl->cap_invert_audit, cap))
59647+ cap_raise(cap_audit, cap);
59648+ }
59649+ }
59650+
59651+ if (!cap_raised(cap_drop, cap)) {
59652+ if (cap_raised(cap_audit, cap))
59653+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
59654+ return 1;
59655+ }
59656+
59657+ curracl = task->acl;
59658+
59659+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
59660+ && cap_raised(cred->cap_effective, cap)) {
59661+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
59662+ task->role->roletype, cred->uid,
59663+ cred->gid, task->exec_file ?
59664+ gr_to_filename(task->exec_file->f_path.dentry,
59665+ task->exec_file->f_path.mnt) : curracl->filename,
59666+ curracl->filename, 0UL,
59667+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
59668+ return 1;
59669+ }
59670+
59671+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
59672+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
59673+ return 0;
59674+}
59675+
59676+int
59677+gr_acl_is_capable_nolog(const int cap)
59678+{
59679+ struct acl_subject_label *curracl;
59680+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59681+
59682+ if (!gr_acl_is_enabled())
59683+ return 1;
59684+
59685+ curracl = current->acl;
59686+
59687+ cap_drop = curracl->cap_lower;
59688+ cap_mask = curracl->cap_mask;
59689+
59690+ while ((curracl = curracl->parent_subject)) {
59691+ /* if the cap isn't specified in the current computed mask but is specified in the
59692+ current level subject, and is lowered in the current level subject, then add
59693+ it to the set of dropped capabilities
59694+ otherwise, add the current level subject's mask to the current computed mask
59695+ */
59696+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59697+ cap_raise(cap_mask, cap);
59698+ if (cap_raised(curracl->cap_lower, cap))
59699+ cap_raise(cap_drop, cap);
59700+ }
59701+ }
59702+
59703+ if (!cap_raised(cap_drop, cap))
59704+ return 1;
59705+
59706+ return 0;
59707+}
59708+
59709diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
59710new file mode 100644
59711index 0000000..d5f210c
59712--- /dev/null
59713+++ b/grsecurity/gracl_fs.c
59714@@ -0,0 +1,433 @@
59715+#include <linux/kernel.h>
59716+#include <linux/sched.h>
59717+#include <linux/types.h>
59718+#include <linux/fs.h>
59719+#include <linux/file.h>
59720+#include <linux/stat.h>
59721+#include <linux/grsecurity.h>
59722+#include <linux/grinternal.h>
59723+#include <linux/gracl.h>
59724+
59725+__u32
59726+gr_acl_handle_hidden_file(const struct dentry * dentry,
59727+ const struct vfsmount * mnt)
59728+{
59729+ __u32 mode;
59730+
59731+ if (unlikely(!dentry->d_inode))
59732+ return GR_FIND;
59733+
59734+ mode =
59735+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
59736+
59737+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
59738+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
59739+ return mode;
59740+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
59741+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
59742+ return 0;
59743+ } else if (unlikely(!(mode & GR_FIND)))
59744+ return 0;
59745+
59746+ return GR_FIND;
59747+}
59748+
59749+__u32
59750+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59751+ int acc_mode)
59752+{
59753+ __u32 reqmode = GR_FIND;
59754+ __u32 mode;
59755+
59756+ if (unlikely(!dentry->d_inode))
59757+ return reqmode;
59758+
59759+ if (acc_mode & MAY_APPEND)
59760+ reqmode |= GR_APPEND;
59761+ else if (acc_mode & MAY_WRITE)
59762+ reqmode |= GR_WRITE;
59763+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
59764+ reqmode |= GR_READ;
59765+
59766+ mode =
59767+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
59768+ mnt);
59769+
59770+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59771+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
59772+ reqmode & GR_READ ? " reading" : "",
59773+ reqmode & GR_WRITE ? " writing" : reqmode &
59774+ GR_APPEND ? " appending" : "");
59775+ return reqmode;
59776+ } else
59777+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59778+ {
59779+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
59780+ reqmode & GR_READ ? " reading" : "",
59781+ reqmode & GR_WRITE ? " writing" : reqmode &
59782+ GR_APPEND ? " appending" : "");
59783+ return 0;
59784+ } else if (unlikely((mode & reqmode) != reqmode))
59785+ return 0;
59786+
59787+ return reqmode;
59788+}
59789+
59790+__u32
59791+gr_acl_handle_creat(const struct dentry * dentry,
59792+ const struct dentry * p_dentry,
59793+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59794+ const int imode)
59795+{
59796+ __u32 reqmode = GR_WRITE | GR_CREATE;
59797+ __u32 mode;
59798+
59799+ if (acc_mode & MAY_APPEND)
59800+ reqmode |= GR_APPEND;
59801+ // if a directory was required or the directory already exists, then
59802+ // don't count this open as a read
59803+ if ((acc_mode & MAY_READ) &&
59804+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
59805+ reqmode |= GR_READ;
59806+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
59807+ reqmode |= GR_SETID;
59808+
59809+ mode =
59810+ gr_check_create(dentry, p_dentry, p_mnt,
59811+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59812+
59813+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59814+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
59815+ reqmode & GR_READ ? " reading" : "",
59816+ reqmode & GR_WRITE ? " writing" : reqmode &
59817+ GR_APPEND ? " appending" : "");
59818+ return reqmode;
59819+ } else
59820+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59821+ {
59822+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
59823+ reqmode & GR_READ ? " reading" : "",
59824+ reqmode & GR_WRITE ? " writing" : reqmode &
59825+ GR_APPEND ? " appending" : "");
59826+ return 0;
59827+ } else if (unlikely((mode & reqmode) != reqmode))
59828+ return 0;
59829+
59830+ return reqmode;
59831+}
59832+
59833+__u32
59834+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
59835+ const int fmode)
59836+{
59837+ __u32 mode, reqmode = GR_FIND;
59838+
59839+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
59840+ reqmode |= GR_EXEC;
59841+ if (fmode & S_IWOTH)
59842+ reqmode |= GR_WRITE;
59843+ if (fmode & S_IROTH)
59844+ reqmode |= GR_READ;
59845+
59846+ mode =
59847+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
59848+ mnt);
59849+
59850+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59851+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
59852+ reqmode & GR_READ ? " reading" : "",
59853+ reqmode & GR_WRITE ? " writing" : "",
59854+ reqmode & GR_EXEC ? " executing" : "");
59855+ return reqmode;
59856+ } else
59857+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
59858+ {
59859+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
59860+ reqmode & GR_READ ? " reading" : "",
59861+ reqmode & GR_WRITE ? " writing" : "",
59862+ reqmode & GR_EXEC ? " executing" : "");
59863+ return 0;
59864+ } else if (unlikely((mode & reqmode) != reqmode))
59865+ return 0;
59866+
59867+ return reqmode;
59868+}
59869+
59870+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
59871+{
59872+ __u32 mode;
59873+
59874+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
59875+
59876+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59877+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
59878+ return mode;
59879+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59880+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
59881+ return 0;
59882+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
59883+ return 0;
59884+
59885+ return (reqmode);
59886+}
59887+
59888+__u32
59889+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59890+{
59891+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
59892+}
59893+
59894+__u32
59895+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
59896+{
59897+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
59898+}
59899+
59900+__u32
59901+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
59902+{
59903+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
59904+}
59905+
59906+__u32
59907+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
59908+{
59909+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
59910+}
59911+
59912+__u32
59913+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
59914+ mode_t mode)
59915+{
59916+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
59917+ return 1;
59918+
59919+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
59920+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
59921+ GR_FCHMOD_ACL_MSG);
59922+ } else {
59923+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
59924+ }
59925+}
59926+
59927+__u32
59928+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
59929+ mode_t mode)
59930+{
59931+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
59932+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
59933+ GR_CHMOD_ACL_MSG);
59934+ } else {
59935+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
59936+ }
59937+}
59938+
59939+__u32
59940+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
59941+{
59942+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
59943+}
59944+
59945+__u32
59946+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
59947+{
59948+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
59949+}
59950+
59951+__u32
59952+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
59953+{
59954+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
59955+}
59956+
59957+__u32
59958+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
59959+{
59960+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
59961+ GR_UNIXCONNECT_ACL_MSG);
59962+}
59963+
59964+/* hardlinks require at minimum create and link permission,
59965+ any additional privilege required is based on the
59966+ privilege of the file being linked to
59967+*/
59968+__u32
59969+gr_acl_handle_link(const struct dentry * new_dentry,
59970+ const struct dentry * parent_dentry,
59971+ const struct vfsmount * parent_mnt,
59972+ const struct dentry * old_dentry,
59973+ const struct vfsmount * old_mnt, const char *to)
59974+{
59975+ __u32 mode;
59976+ __u32 needmode = GR_CREATE | GR_LINK;
59977+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
59978+
59979+ mode =
59980+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
59981+ old_mnt);
59982+
59983+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
59984+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
59985+ return mode;
59986+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
59987+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
59988+ return 0;
59989+ } else if (unlikely((mode & needmode) != needmode))
59990+ return 0;
59991+
59992+ return 1;
59993+}
59994+
59995+__u32
59996+gr_acl_handle_symlink(const struct dentry * new_dentry,
59997+ const struct dentry * parent_dentry,
59998+ const struct vfsmount * parent_mnt, const char *from)
59999+{
60000+ __u32 needmode = GR_WRITE | GR_CREATE;
60001+ __u32 mode;
60002+
60003+ mode =
60004+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
60005+ GR_CREATE | GR_AUDIT_CREATE |
60006+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
60007+
60008+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
60009+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60010+ return mode;
60011+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60012+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60013+ return 0;
60014+ } else if (unlikely((mode & needmode) != needmode))
60015+ return 0;
60016+
60017+ return (GR_WRITE | GR_CREATE);
60018+}
60019+
60020+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)
60021+{
60022+ __u32 mode;
60023+
60024+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60025+
60026+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60027+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
60028+ return mode;
60029+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60030+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
60031+ return 0;
60032+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
60033+ return 0;
60034+
60035+ return (reqmode);
60036+}
60037+
60038+__u32
60039+gr_acl_handle_mknod(const struct dentry * new_dentry,
60040+ const struct dentry * parent_dentry,
60041+ const struct vfsmount * parent_mnt,
60042+ const int mode)
60043+{
60044+ __u32 reqmode = GR_WRITE | GR_CREATE;
60045+ if (unlikely(mode & (S_ISUID | S_ISGID)))
60046+ reqmode |= GR_SETID;
60047+
60048+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60049+ reqmode, GR_MKNOD_ACL_MSG);
60050+}
60051+
60052+__u32
60053+gr_acl_handle_mkdir(const struct dentry *new_dentry,
60054+ const struct dentry *parent_dentry,
60055+ const struct vfsmount *parent_mnt)
60056+{
60057+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60058+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
60059+}
60060+
60061+#define RENAME_CHECK_SUCCESS(old, new) \
60062+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
60063+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
60064+
60065+int
60066+gr_acl_handle_rename(struct dentry *new_dentry,
60067+ struct dentry *parent_dentry,
60068+ const struct vfsmount *parent_mnt,
60069+ struct dentry *old_dentry,
60070+ struct inode *old_parent_inode,
60071+ struct vfsmount *old_mnt, const char *newname)
60072+{
60073+ __u32 comp1, comp2;
60074+ int error = 0;
60075+
60076+ if (unlikely(!gr_acl_is_enabled()))
60077+ return 0;
60078+
60079+ if (!new_dentry->d_inode) {
60080+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
60081+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
60082+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
60083+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
60084+ GR_DELETE | GR_AUDIT_DELETE |
60085+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60086+ GR_SUPPRESS, old_mnt);
60087+ } else {
60088+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
60089+ GR_CREATE | GR_DELETE |
60090+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
60091+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60092+ GR_SUPPRESS, parent_mnt);
60093+ comp2 =
60094+ gr_search_file(old_dentry,
60095+ GR_READ | GR_WRITE | GR_AUDIT_READ |
60096+ GR_DELETE | GR_AUDIT_DELETE |
60097+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
60098+ }
60099+
60100+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
60101+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
60102+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60103+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
60104+ && !(comp2 & GR_SUPPRESS)) {
60105+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60106+ error = -EACCES;
60107+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
60108+ error = -EACCES;
60109+
60110+ return error;
60111+}
60112+
60113+void
60114+gr_acl_handle_exit(void)
60115+{
60116+ u16 id;
60117+ char *rolename;
60118+ struct file *exec_file;
60119+
60120+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
60121+ !(current->role->roletype & GR_ROLE_PERSIST))) {
60122+ id = current->acl_role_id;
60123+ rolename = current->role->rolename;
60124+ gr_set_acls(1);
60125+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
60126+ }
60127+
60128+ write_lock(&grsec_exec_file_lock);
60129+ exec_file = current->exec_file;
60130+ current->exec_file = NULL;
60131+ write_unlock(&grsec_exec_file_lock);
60132+
60133+ if (exec_file)
60134+ fput(exec_file);
60135+}
60136+
60137+int
60138+gr_acl_handle_procpidmem(const struct task_struct *task)
60139+{
60140+ if (unlikely(!gr_acl_is_enabled()))
60141+ return 0;
60142+
60143+ if (task != current && task->acl->mode & GR_PROTPROCFD)
60144+ return -EACCES;
60145+
60146+ return 0;
60147+}
60148diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
60149new file mode 100644
60150index 0000000..cd07b96
60151--- /dev/null
60152+++ b/grsecurity/gracl_ip.c
60153@@ -0,0 +1,382 @@
60154+#include <linux/kernel.h>
60155+#include <asm/uaccess.h>
60156+#include <asm/errno.h>
60157+#include <net/sock.h>
60158+#include <linux/file.h>
60159+#include <linux/fs.h>
60160+#include <linux/net.h>
60161+#include <linux/in.h>
60162+#include <linux/skbuff.h>
60163+#include <linux/ip.h>
60164+#include <linux/udp.h>
60165+#include <linux/smp_lock.h>
60166+#include <linux/types.h>
60167+#include <linux/sched.h>
60168+#include <linux/netdevice.h>
60169+#include <linux/inetdevice.h>
60170+#include <linux/gracl.h>
60171+#include <linux/grsecurity.h>
60172+#include <linux/grinternal.h>
60173+
60174+#define GR_BIND 0x01
60175+#define GR_CONNECT 0x02
60176+#define GR_INVERT 0x04
60177+#define GR_BINDOVERRIDE 0x08
60178+#define GR_CONNECTOVERRIDE 0x10
60179+#define GR_SOCK_FAMILY 0x20
60180+
60181+static const char * gr_protocols[IPPROTO_MAX] = {
60182+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
60183+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
60184+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
60185+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
60186+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
60187+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
60188+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
60189+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
60190+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
60191+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
60192+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
60193+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
60194+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
60195+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
60196+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
60197+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
60198+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
60199+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
60200+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
60201+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
60202+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
60203+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
60204+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
60205+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
60206+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
60207+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
60208+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
60209+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
60210+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
60211+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
60212+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
60213+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
60214+ };
60215+
60216+static const char * gr_socktypes[SOCK_MAX] = {
60217+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
60218+ "unknown:7", "unknown:8", "unknown:9", "packet"
60219+ };
60220+
60221+static const char * gr_sockfamilies[AF_MAX+1] = {
60222+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
60223+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
60224+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
60225+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
60226+ };
60227+
60228+const char *
60229+gr_proto_to_name(unsigned char proto)
60230+{
60231+ return gr_protocols[proto];
60232+}
60233+
60234+const char *
60235+gr_socktype_to_name(unsigned char type)
60236+{
60237+ return gr_socktypes[type];
60238+}
60239+
60240+const char *
60241+gr_sockfamily_to_name(unsigned char family)
60242+{
60243+ return gr_sockfamilies[family];
60244+}
60245+
60246+int
60247+gr_search_socket(const int domain, const int type, const int protocol)
60248+{
60249+ struct acl_subject_label *curr;
60250+ const struct cred *cred = current_cred();
60251+
60252+ if (unlikely(!gr_acl_is_enabled()))
60253+ goto exit;
60254+
60255+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
60256+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
60257+ goto exit; // let the kernel handle it
60258+
60259+ curr = current->acl;
60260+
60261+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
60262+ /* the family is allowed, if this is PF_INET allow it only if
60263+ the extra sock type/protocol checks pass */
60264+ if (domain == PF_INET)
60265+ goto inet_check;
60266+ goto exit;
60267+ } else {
60268+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60269+ __u32 fakeip = 0;
60270+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60271+ current->role->roletype, cred->uid,
60272+ cred->gid, current->exec_file ?
60273+ gr_to_filename(current->exec_file->f_path.dentry,
60274+ current->exec_file->f_path.mnt) :
60275+ curr->filename, curr->filename,
60276+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
60277+ &current->signal->saved_ip);
60278+ goto exit;
60279+ }
60280+ goto exit_fail;
60281+ }
60282+
60283+inet_check:
60284+ /* the rest of this checking is for IPv4 only */
60285+ if (!curr->ips)
60286+ goto exit;
60287+
60288+ if ((curr->ip_type & (1 << type)) &&
60289+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
60290+ goto exit;
60291+
60292+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60293+ /* we don't place acls on raw sockets , and sometimes
60294+ dgram/ip sockets are opened for ioctl and not
60295+ bind/connect, so we'll fake a bind learn log */
60296+ if (type == SOCK_RAW || type == SOCK_PACKET) {
60297+ __u32 fakeip = 0;
60298+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60299+ current->role->roletype, cred->uid,
60300+ cred->gid, current->exec_file ?
60301+ gr_to_filename(current->exec_file->f_path.dentry,
60302+ current->exec_file->f_path.mnt) :
60303+ curr->filename, curr->filename,
60304+ &fakeip, 0, type,
60305+ protocol, GR_CONNECT, &current->signal->saved_ip);
60306+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
60307+ __u32 fakeip = 0;
60308+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60309+ current->role->roletype, cred->uid,
60310+ cred->gid, current->exec_file ?
60311+ gr_to_filename(current->exec_file->f_path.dentry,
60312+ current->exec_file->f_path.mnt) :
60313+ curr->filename, curr->filename,
60314+ &fakeip, 0, type,
60315+ protocol, GR_BIND, &current->signal->saved_ip);
60316+ }
60317+ /* we'll log when they use connect or bind */
60318+ goto exit;
60319+ }
60320+
60321+exit_fail:
60322+ if (domain == PF_INET)
60323+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
60324+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
60325+ else
60326+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
60327+ gr_socktype_to_name(type), protocol);
60328+
60329+ return 0;
60330+exit:
60331+ return 1;
60332+}
60333+
60334+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)
60335+{
60336+ if ((ip->mode & mode) &&
60337+ (ip_port >= ip->low) &&
60338+ (ip_port <= ip->high) &&
60339+ ((ntohl(ip_addr) & our_netmask) ==
60340+ (ntohl(our_addr) & our_netmask))
60341+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
60342+ && (ip->type & (1 << type))) {
60343+ if (ip->mode & GR_INVERT)
60344+ return 2; // specifically denied
60345+ else
60346+ return 1; // allowed
60347+ }
60348+
60349+ return 0; // not specifically allowed, may continue parsing
60350+}
60351+
60352+static int
60353+gr_search_connectbind(const int full_mode, struct sock *sk,
60354+ struct sockaddr_in *addr, const int type)
60355+{
60356+ char iface[IFNAMSIZ] = {0};
60357+ struct acl_subject_label *curr;
60358+ struct acl_ip_label *ip;
60359+ struct inet_sock *isk;
60360+ struct net_device *dev;
60361+ struct in_device *idev;
60362+ unsigned long i;
60363+ int ret;
60364+ int mode = full_mode & (GR_BIND | GR_CONNECT);
60365+ __u32 ip_addr = 0;
60366+ __u32 our_addr;
60367+ __u32 our_netmask;
60368+ char *p;
60369+ __u16 ip_port = 0;
60370+ const struct cred *cred = current_cred();
60371+
60372+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
60373+ return 0;
60374+
60375+ curr = current->acl;
60376+ isk = inet_sk(sk);
60377+
60378+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
60379+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
60380+ addr->sin_addr.s_addr = curr->inaddr_any_override;
60381+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
60382+ struct sockaddr_in saddr;
60383+ int err;
60384+
60385+ saddr.sin_family = AF_INET;
60386+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
60387+ saddr.sin_port = isk->sport;
60388+
60389+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60390+ if (err)
60391+ return err;
60392+
60393+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60394+ if (err)
60395+ return err;
60396+ }
60397+
60398+ if (!curr->ips)
60399+ return 0;
60400+
60401+ ip_addr = addr->sin_addr.s_addr;
60402+ ip_port = ntohs(addr->sin_port);
60403+
60404+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60405+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60406+ current->role->roletype, cred->uid,
60407+ cred->gid, current->exec_file ?
60408+ gr_to_filename(current->exec_file->f_path.dentry,
60409+ current->exec_file->f_path.mnt) :
60410+ curr->filename, curr->filename,
60411+ &ip_addr, ip_port, type,
60412+ sk->sk_protocol, mode, &current->signal->saved_ip);
60413+ return 0;
60414+ }
60415+
60416+ for (i = 0; i < curr->ip_num; i++) {
60417+ ip = *(curr->ips + i);
60418+ if (ip->iface != NULL) {
60419+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
60420+ p = strchr(iface, ':');
60421+ if (p != NULL)
60422+ *p = '\0';
60423+ dev = dev_get_by_name(sock_net(sk), iface);
60424+ if (dev == NULL)
60425+ continue;
60426+ idev = in_dev_get(dev);
60427+ if (idev == NULL) {
60428+ dev_put(dev);
60429+ continue;
60430+ }
60431+ rcu_read_lock();
60432+ for_ifa(idev) {
60433+ if (!strcmp(ip->iface, ifa->ifa_label)) {
60434+ our_addr = ifa->ifa_address;
60435+ our_netmask = 0xffffffff;
60436+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60437+ if (ret == 1) {
60438+ rcu_read_unlock();
60439+ in_dev_put(idev);
60440+ dev_put(dev);
60441+ return 0;
60442+ } else if (ret == 2) {
60443+ rcu_read_unlock();
60444+ in_dev_put(idev);
60445+ dev_put(dev);
60446+ goto denied;
60447+ }
60448+ }
60449+ } endfor_ifa(idev);
60450+ rcu_read_unlock();
60451+ in_dev_put(idev);
60452+ dev_put(dev);
60453+ } else {
60454+ our_addr = ip->addr;
60455+ our_netmask = ip->netmask;
60456+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60457+ if (ret == 1)
60458+ return 0;
60459+ else if (ret == 2)
60460+ goto denied;
60461+ }
60462+ }
60463+
60464+denied:
60465+ if (mode == GR_BIND)
60466+ 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));
60467+ else if (mode == GR_CONNECT)
60468+ 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));
60469+
60470+ return -EACCES;
60471+}
60472+
60473+int
60474+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
60475+{
60476+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
60477+}
60478+
60479+int
60480+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
60481+{
60482+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
60483+}
60484+
60485+int gr_search_listen(struct socket *sock)
60486+{
60487+ struct sock *sk = sock->sk;
60488+ struct sockaddr_in addr;
60489+
60490+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60491+ addr.sin_port = inet_sk(sk)->sport;
60492+
60493+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60494+}
60495+
60496+int gr_search_accept(struct socket *sock)
60497+{
60498+ struct sock *sk = sock->sk;
60499+ struct sockaddr_in addr;
60500+
60501+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60502+ addr.sin_port = inet_sk(sk)->sport;
60503+
60504+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60505+}
60506+
60507+int
60508+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
60509+{
60510+ if (addr)
60511+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
60512+ else {
60513+ struct sockaddr_in sin;
60514+ const struct inet_sock *inet = inet_sk(sk);
60515+
60516+ sin.sin_addr.s_addr = inet->daddr;
60517+ sin.sin_port = inet->dport;
60518+
60519+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60520+ }
60521+}
60522+
60523+int
60524+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
60525+{
60526+ struct sockaddr_in sin;
60527+
60528+ if (unlikely(skb->len < sizeof (struct udphdr)))
60529+ return 0; // skip this packet
60530+
60531+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
60532+ sin.sin_port = udp_hdr(skb)->source;
60533+
60534+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60535+}
60536diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
60537new file mode 100644
60538index 0000000..34bdd46
60539--- /dev/null
60540+++ b/grsecurity/gracl_learn.c
60541@@ -0,0 +1,208 @@
60542+#include <linux/kernel.h>
60543+#include <linux/mm.h>
60544+#include <linux/sched.h>
60545+#include <linux/poll.h>
60546+#include <linux/smp_lock.h>
60547+#include <linux/string.h>
60548+#include <linux/file.h>
60549+#include <linux/types.h>
60550+#include <linux/vmalloc.h>
60551+#include <linux/grinternal.h>
60552+
60553+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
60554+ size_t count, loff_t *ppos);
60555+extern int gr_acl_is_enabled(void);
60556+
60557+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
60558+static int gr_learn_attached;
60559+
60560+/* use a 512k buffer */
60561+#define LEARN_BUFFER_SIZE (512 * 1024)
60562+
60563+static DEFINE_SPINLOCK(gr_learn_lock);
60564+static DEFINE_MUTEX(gr_learn_user_mutex);
60565+
60566+/* we need to maintain two buffers, so that the kernel context of grlearn
60567+ uses a semaphore around the userspace copying, and the other kernel contexts
60568+ use a spinlock when copying into the buffer, since they cannot sleep
60569+*/
60570+static char *learn_buffer;
60571+static char *learn_buffer_user;
60572+static int learn_buffer_len;
60573+static int learn_buffer_user_len;
60574+
60575+static ssize_t
60576+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
60577+{
60578+ DECLARE_WAITQUEUE(wait, current);
60579+ ssize_t retval = 0;
60580+
60581+ add_wait_queue(&learn_wait, &wait);
60582+ set_current_state(TASK_INTERRUPTIBLE);
60583+ do {
60584+ mutex_lock(&gr_learn_user_mutex);
60585+ spin_lock(&gr_learn_lock);
60586+ if (learn_buffer_len)
60587+ break;
60588+ spin_unlock(&gr_learn_lock);
60589+ mutex_unlock(&gr_learn_user_mutex);
60590+ if (file->f_flags & O_NONBLOCK) {
60591+ retval = -EAGAIN;
60592+ goto out;
60593+ }
60594+ if (signal_pending(current)) {
60595+ retval = -ERESTARTSYS;
60596+ goto out;
60597+ }
60598+
60599+ schedule();
60600+ } while (1);
60601+
60602+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
60603+ learn_buffer_user_len = learn_buffer_len;
60604+ retval = learn_buffer_len;
60605+ learn_buffer_len = 0;
60606+
60607+ spin_unlock(&gr_learn_lock);
60608+
60609+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
60610+ retval = -EFAULT;
60611+
60612+ mutex_unlock(&gr_learn_user_mutex);
60613+out:
60614+ set_current_state(TASK_RUNNING);
60615+ remove_wait_queue(&learn_wait, &wait);
60616+ return retval;
60617+}
60618+
60619+static unsigned int
60620+poll_learn(struct file * file, poll_table * wait)
60621+{
60622+ poll_wait(file, &learn_wait, wait);
60623+
60624+ if (learn_buffer_len)
60625+ return (POLLIN | POLLRDNORM);
60626+
60627+ return 0;
60628+}
60629+
60630+void
60631+gr_clear_learn_entries(void)
60632+{
60633+ char *tmp;
60634+
60635+ mutex_lock(&gr_learn_user_mutex);
60636+ spin_lock(&gr_learn_lock);
60637+ tmp = learn_buffer;
60638+ learn_buffer = NULL;
60639+ spin_unlock(&gr_learn_lock);
60640+ if (tmp)
60641+ vfree(tmp);
60642+ if (learn_buffer_user != NULL) {
60643+ vfree(learn_buffer_user);
60644+ learn_buffer_user = NULL;
60645+ }
60646+ learn_buffer_len = 0;
60647+ mutex_unlock(&gr_learn_user_mutex);
60648+
60649+ return;
60650+}
60651+
60652+void
60653+gr_add_learn_entry(const char *fmt, ...)
60654+{
60655+ va_list args;
60656+ unsigned int len;
60657+
60658+ if (!gr_learn_attached)
60659+ return;
60660+
60661+ spin_lock(&gr_learn_lock);
60662+
60663+ /* leave a gap at the end so we know when it's "full" but don't have to
60664+ compute the exact length of the string we're trying to append
60665+ */
60666+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
60667+ spin_unlock(&gr_learn_lock);
60668+ wake_up_interruptible(&learn_wait);
60669+ return;
60670+ }
60671+ if (learn_buffer == NULL) {
60672+ spin_unlock(&gr_learn_lock);
60673+ return;
60674+ }
60675+
60676+ va_start(args, fmt);
60677+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
60678+ va_end(args);
60679+
60680+ learn_buffer_len += len + 1;
60681+
60682+ spin_unlock(&gr_learn_lock);
60683+ wake_up_interruptible(&learn_wait);
60684+
60685+ return;
60686+}
60687+
60688+static int
60689+open_learn(struct inode *inode, struct file *file)
60690+{
60691+ if (file->f_mode & FMODE_READ && gr_learn_attached)
60692+ return -EBUSY;
60693+ if (file->f_mode & FMODE_READ) {
60694+ int retval = 0;
60695+ mutex_lock(&gr_learn_user_mutex);
60696+ if (learn_buffer == NULL)
60697+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
60698+ if (learn_buffer_user == NULL)
60699+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
60700+ if (learn_buffer == NULL) {
60701+ retval = -ENOMEM;
60702+ goto out_error;
60703+ }
60704+ if (learn_buffer_user == NULL) {
60705+ retval = -ENOMEM;
60706+ goto out_error;
60707+ }
60708+ learn_buffer_len = 0;
60709+ learn_buffer_user_len = 0;
60710+ gr_learn_attached = 1;
60711+out_error:
60712+ mutex_unlock(&gr_learn_user_mutex);
60713+ return retval;
60714+ }
60715+ return 0;
60716+}
60717+
60718+static int
60719+close_learn(struct inode *inode, struct file *file)
60720+{
60721+ if (file->f_mode & FMODE_READ) {
60722+ char *tmp = NULL;
60723+ mutex_lock(&gr_learn_user_mutex);
60724+ spin_lock(&gr_learn_lock);
60725+ tmp = learn_buffer;
60726+ learn_buffer = NULL;
60727+ spin_unlock(&gr_learn_lock);
60728+ if (tmp)
60729+ vfree(tmp);
60730+ if (learn_buffer_user != NULL) {
60731+ vfree(learn_buffer_user);
60732+ learn_buffer_user = NULL;
60733+ }
60734+ learn_buffer_len = 0;
60735+ learn_buffer_user_len = 0;
60736+ gr_learn_attached = 0;
60737+ mutex_unlock(&gr_learn_user_mutex);
60738+ }
60739+
60740+ return 0;
60741+}
60742+
60743+const struct file_operations grsec_fops = {
60744+ .read = read_learn,
60745+ .write = write_grsec_handler,
60746+ .open = open_learn,
60747+ .release = close_learn,
60748+ .poll = poll_learn,
60749+};
60750diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
60751new file mode 100644
60752index 0000000..70b2179
60753--- /dev/null
60754+++ b/grsecurity/gracl_res.c
60755@@ -0,0 +1,67 @@
60756+#include <linux/kernel.h>
60757+#include <linux/sched.h>
60758+#include <linux/gracl.h>
60759+#include <linux/grinternal.h>
60760+
60761+static const char *restab_log[] = {
60762+ [RLIMIT_CPU] = "RLIMIT_CPU",
60763+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
60764+ [RLIMIT_DATA] = "RLIMIT_DATA",
60765+ [RLIMIT_STACK] = "RLIMIT_STACK",
60766+ [RLIMIT_CORE] = "RLIMIT_CORE",
60767+ [RLIMIT_RSS] = "RLIMIT_RSS",
60768+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
60769+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
60770+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
60771+ [RLIMIT_AS] = "RLIMIT_AS",
60772+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
60773+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
60774+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
60775+ [RLIMIT_NICE] = "RLIMIT_NICE",
60776+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
60777+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
60778+ [GR_CRASH_RES] = "RLIMIT_CRASH"
60779+};
60780+
60781+void
60782+gr_log_resource(const struct task_struct *task,
60783+ const int res, const unsigned long wanted, const int gt)
60784+{
60785+ const struct cred *cred;
60786+ unsigned long rlim;
60787+
60788+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
60789+ return;
60790+
60791+ // not yet supported resource
60792+ if (unlikely(!restab_log[res]))
60793+ return;
60794+
60795+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
60796+ rlim = task->signal->rlim[res].rlim_max;
60797+ else
60798+ rlim = task->signal->rlim[res].rlim_cur;
60799+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
60800+ return;
60801+
60802+ rcu_read_lock();
60803+ cred = __task_cred(task);
60804+
60805+ if (res == RLIMIT_NPROC &&
60806+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
60807+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
60808+ goto out_rcu_unlock;
60809+ else if (res == RLIMIT_MEMLOCK &&
60810+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
60811+ goto out_rcu_unlock;
60812+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
60813+ goto out_rcu_unlock;
60814+ rcu_read_unlock();
60815+
60816+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
60817+
60818+ return;
60819+out_rcu_unlock:
60820+ rcu_read_unlock();
60821+ return;
60822+}
60823diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
60824new file mode 100644
60825index 0000000..1d1b734
60826--- /dev/null
60827+++ b/grsecurity/gracl_segv.c
60828@@ -0,0 +1,284 @@
60829+#include <linux/kernel.h>
60830+#include <linux/mm.h>
60831+#include <asm/uaccess.h>
60832+#include <asm/errno.h>
60833+#include <asm/mman.h>
60834+#include <net/sock.h>
60835+#include <linux/file.h>
60836+#include <linux/fs.h>
60837+#include <linux/net.h>
60838+#include <linux/in.h>
60839+#include <linux/smp_lock.h>
60840+#include <linux/slab.h>
60841+#include <linux/types.h>
60842+#include <linux/sched.h>
60843+#include <linux/timer.h>
60844+#include <linux/gracl.h>
60845+#include <linux/grsecurity.h>
60846+#include <linux/grinternal.h>
60847+
60848+static struct crash_uid *uid_set;
60849+static unsigned short uid_used;
60850+static DEFINE_SPINLOCK(gr_uid_lock);
60851+extern rwlock_t gr_inode_lock;
60852+extern struct acl_subject_label *
60853+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
60854+ struct acl_role_label *role);
60855+extern int gr_fake_force_sig(int sig, struct task_struct *t);
60856+
60857+int
60858+gr_init_uidset(void)
60859+{
60860+ uid_set =
60861+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
60862+ uid_used = 0;
60863+
60864+ return uid_set ? 1 : 0;
60865+}
60866+
60867+void
60868+gr_free_uidset(void)
60869+{
60870+ if (uid_set)
60871+ kfree(uid_set);
60872+
60873+ return;
60874+}
60875+
60876+int
60877+gr_find_uid(const uid_t uid)
60878+{
60879+ struct crash_uid *tmp = uid_set;
60880+ uid_t buid;
60881+ int low = 0, high = uid_used - 1, mid;
60882+
60883+ while (high >= low) {
60884+ mid = (low + high) >> 1;
60885+ buid = tmp[mid].uid;
60886+ if (buid == uid)
60887+ return mid;
60888+ if (buid > uid)
60889+ high = mid - 1;
60890+ if (buid < uid)
60891+ low = mid + 1;
60892+ }
60893+
60894+ return -1;
60895+}
60896+
60897+static __inline__ void
60898+gr_insertsort(void)
60899+{
60900+ unsigned short i, j;
60901+ struct crash_uid index;
60902+
60903+ for (i = 1; i < uid_used; i++) {
60904+ index = uid_set[i];
60905+ j = i;
60906+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
60907+ uid_set[j] = uid_set[j - 1];
60908+ j--;
60909+ }
60910+ uid_set[j] = index;
60911+ }
60912+
60913+ return;
60914+}
60915+
60916+static __inline__ void
60917+gr_insert_uid(const uid_t uid, const unsigned long expires)
60918+{
60919+ int loc;
60920+
60921+ if (uid_used == GR_UIDTABLE_MAX)
60922+ return;
60923+
60924+ loc = gr_find_uid(uid);
60925+
60926+ if (loc >= 0) {
60927+ uid_set[loc].expires = expires;
60928+ return;
60929+ }
60930+
60931+ uid_set[uid_used].uid = uid;
60932+ uid_set[uid_used].expires = expires;
60933+ uid_used++;
60934+
60935+ gr_insertsort();
60936+
60937+ return;
60938+}
60939+
60940+void
60941+gr_remove_uid(const unsigned short loc)
60942+{
60943+ unsigned short i;
60944+
60945+ for (i = loc + 1; i < uid_used; i++)
60946+ uid_set[i - 1] = uid_set[i];
60947+
60948+ uid_used--;
60949+
60950+ return;
60951+}
60952+
60953+int
60954+gr_check_crash_uid(const uid_t uid)
60955+{
60956+ int loc;
60957+ int ret = 0;
60958+
60959+ if (unlikely(!gr_acl_is_enabled()))
60960+ return 0;
60961+
60962+ spin_lock(&gr_uid_lock);
60963+ loc = gr_find_uid(uid);
60964+
60965+ if (loc < 0)
60966+ goto out_unlock;
60967+
60968+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
60969+ gr_remove_uid(loc);
60970+ else
60971+ ret = 1;
60972+
60973+out_unlock:
60974+ spin_unlock(&gr_uid_lock);
60975+ return ret;
60976+}
60977+
60978+static __inline__ int
60979+proc_is_setxid(const struct cred *cred)
60980+{
60981+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
60982+ cred->uid != cred->fsuid)
60983+ return 1;
60984+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
60985+ cred->gid != cred->fsgid)
60986+ return 1;
60987+
60988+ return 0;
60989+}
60990+
60991+void
60992+gr_handle_crash(struct task_struct *task, const int sig)
60993+{
60994+ struct acl_subject_label *curr;
60995+ struct task_struct *tsk, *tsk2;
60996+ const struct cred *cred;
60997+ const struct cred *cred2;
60998+
60999+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
61000+ return;
61001+
61002+ if (unlikely(!gr_acl_is_enabled()))
61003+ return;
61004+
61005+ curr = task->acl;
61006+
61007+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
61008+ return;
61009+
61010+ if (time_before_eq(curr->expires, get_seconds())) {
61011+ curr->expires = 0;
61012+ curr->crashes = 0;
61013+ }
61014+
61015+ curr->crashes++;
61016+
61017+ if (!curr->expires)
61018+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
61019+
61020+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61021+ time_after(curr->expires, get_seconds())) {
61022+ rcu_read_lock();
61023+ cred = __task_cred(task);
61024+ if (cred->uid && proc_is_setxid(cred)) {
61025+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61026+ spin_lock(&gr_uid_lock);
61027+ gr_insert_uid(cred->uid, curr->expires);
61028+ spin_unlock(&gr_uid_lock);
61029+ curr->expires = 0;
61030+ curr->crashes = 0;
61031+ read_lock(&tasklist_lock);
61032+ do_each_thread(tsk2, tsk) {
61033+ cred2 = __task_cred(tsk);
61034+ if (tsk != task && cred2->uid == cred->uid)
61035+ gr_fake_force_sig(SIGKILL, tsk);
61036+ } while_each_thread(tsk2, tsk);
61037+ read_unlock(&tasklist_lock);
61038+ } else {
61039+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61040+ read_lock(&tasklist_lock);
61041+ read_lock(&grsec_exec_file_lock);
61042+ do_each_thread(tsk2, tsk) {
61043+ if (likely(tsk != task)) {
61044+ // if this thread has the same subject as the one that triggered
61045+ // RES_CRASH and it's the same binary, kill it
61046+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
61047+ gr_fake_force_sig(SIGKILL, tsk);
61048+ }
61049+ } while_each_thread(tsk2, tsk);
61050+ read_unlock(&grsec_exec_file_lock);
61051+ read_unlock(&tasklist_lock);
61052+ }
61053+ rcu_read_unlock();
61054+ }
61055+
61056+ return;
61057+}
61058+
61059+int
61060+gr_check_crash_exec(const struct file *filp)
61061+{
61062+ struct acl_subject_label *curr;
61063+
61064+ if (unlikely(!gr_acl_is_enabled()))
61065+ return 0;
61066+
61067+ read_lock(&gr_inode_lock);
61068+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
61069+ filp->f_path.dentry->d_inode->i_sb->s_dev,
61070+ current->role);
61071+ read_unlock(&gr_inode_lock);
61072+
61073+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
61074+ (!curr->crashes && !curr->expires))
61075+ return 0;
61076+
61077+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61078+ time_after(curr->expires, get_seconds()))
61079+ return 1;
61080+ else if (time_before_eq(curr->expires, get_seconds())) {
61081+ curr->crashes = 0;
61082+ curr->expires = 0;
61083+ }
61084+
61085+ return 0;
61086+}
61087+
61088+void
61089+gr_handle_alertkill(struct task_struct *task)
61090+{
61091+ struct acl_subject_label *curracl;
61092+ __u32 curr_ip;
61093+ struct task_struct *p, *p2;
61094+
61095+ if (unlikely(!gr_acl_is_enabled()))
61096+ return;
61097+
61098+ curracl = task->acl;
61099+ curr_ip = task->signal->curr_ip;
61100+
61101+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
61102+ read_lock(&tasklist_lock);
61103+ do_each_thread(p2, p) {
61104+ if (p->signal->curr_ip == curr_ip)
61105+ gr_fake_force_sig(SIGKILL, p);
61106+ } while_each_thread(p2, p);
61107+ read_unlock(&tasklist_lock);
61108+ } else if (curracl->mode & GR_KILLPROC)
61109+ gr_fake_force_sig(SIGKILL, task);
61110+
61111+ return;
61112+}
61113diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
61114new file mode 100644
61115index 0000000..9d83a69
61116--- /dev/null
61117+++ b/grsecurity/gracl_shm.c
61118@@ -0,0 +1,40 @@
61119+#include <linux/kernel.h>
61120+#include <linux/mm.h>
61121+#include <linux/sched.h>
61122+#include <linux/file.h>
61123+#include <linux/ipc.h>
61124+#include <linux/gracl.h>
61125+#include <linux/grsecurity.h>
61126+#include <linux/grinternal.h>
61127+
61128+int
61129+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61130+ const time_t shm_createtime, const uid_t cuid, const int shmid)
61131+{
61132+ struct task_struct *task;
61133+
61134+ if (!gr_acl_is_enabled())
61135+ return 1;
61136+
61137+ rcu_read_lock();
61138+ read_lock(&tasklist_lock);
61139+
61140+ task = find_task_by_vpid(shm_cprid);
61141+
61142+ if (unlikely(!task))
61143+ task = find_task_by_vpid(shm_lapid);
61144+
61145+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
61146+ (task->pid == shm_lapid)) &&
61147+ (task->acl->mode & GR_PROTSHM) &&
61148+ (task->acl != current->acl))) {
61149+ read_unlock(&tasklist_lock);
61150+ rcu_read_unlock();
61151+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
61152+ return 0;
61153+ }
61154+ read_unlock(&tasklist_lock);
61155+ rcu_read_unlock();
61156+
61157+ return 1;
61158+}
61159diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
61160new file mode 100644
61161index 0000000..bc0be01
61162--- /dev/null
61163+++ b/grsecurity/grsec_chdir.c
61164@@ -0,0 +1,19 @@
61165+#include <linux/kernel.h>
61166+#include <linux/sched.h>
61167+#include <linux/fs.h>
61168+#include <linux/file.h>
61169+#include <linux/grsecurity.h>
61170+#include <linux/grinternal.h>
61171+
61172+void
61173+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
61174+{
61175+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61176+ if ((grsec_enable_chdir && grsec_enable_group &&
61177+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
61178+ !grsec_enable_group)) {
61179+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
61180+ }
61181+#endif
61182+ return;
61183+}
61184diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
61185new file mode 100644
61186index 0000000..197bdd5
61187--- /dev/null
61188+++ b/grsecurity/grsec_chroot.c
61189@@ -0,0 +1,386 @@
61190+#include <linux/kernel.h>
61191+#include <linux/module.h>
61192+#include <linux/sched.h>
61193+#include <linux/file.h>
61194+#include <linux/fs.h>
61195+#include <linux/mount.h>
61196+#include <linux/types.h>
61197+#include <linux/pid_namespace.h>
61198+#include <linux/grsecurity.h>
61199+#include <linux/grinternal.h>
61200+
61201+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
61202+{
61203+#ifdef CONFIG_GRKERNSEC
61204+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
61205+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
61206+ task->gr_is_chrooted = 1;
61207+ else
61208+ task->gr_is_chrooted = 0;
61209+
61210+ task->gr_chroot_dentry = path->dentry;
61211+#endif
61212+ return;
61213+}
61214+
61215+void gr_clear_chroot_entries(struct task_struct *task)
61216+{
61217+#ifdef CONFIG_GRKERNSEC
61218+ task->gr_is_chrooted = 0;
61219+ task->gr_chroot_dentry = NULL;
61220+#endif
61221+ return;
61222+}
61223+
61224+int
61225+gr_handle_chroot_unix(const pid_t pid)
61226+{
61227+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61228+ struct task_struct *p;
61229+
61230+ if (unlikely(!grsec_enable_chroot_unix))
61231+ return 1;
61232+
61233+ if (likely(!proc_is_chrooted(current)))
61234+ return 1;
61235+
61236+ rcu_read_lock();
61237+ read_lock(&tasklist_lock);
61238+
61239+ p = find_task_by_vpid_unrestricted(pid);
61240+ if (unlikely(p && !have_same_root(current, p))) {
61241+ read_unlock(&tasklist_lock);
61242+ rcu_read_unlock();
61243+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
61244+ return 0;
61245+ }
61246+ read_unlock(&tasklist_lock);
61247+ rcu_read_unlock();
61248+#endif
61249+ return 1;
61250+}
61251+
61252+int
61253+gr_handle_chroot_nice(void)
61254+{
61255+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61256+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
61257+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
61258+ return -EPERM;
61259+ }
61260+#endif
61261+ return 0;
61262+}
61263+
61264+int
61265+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
61266+{
61267+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61268+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
61269+ && proc_is_chrooted(current)) {
61270+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
61271+ return -EACCES;
61272+ }
61273+#endif
61274+ return 0;
61275+}
61276+
61277+int
61278+gr_handle_chroot_rawio(const struct inode *inode)
61279+{
61280+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61281+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
61282+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
61283+ return 1;
61284+#endif
61285+ return 0;
61286+}
61287+
61288+int
61289+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
61290+{
61291+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61292+ struct task_struct *p;
61293+ int ret = 0;
61294+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
61295+ return ret;
61296+
61297+ read_lock(&tasklist_lock);
61298+ do_each_pid_task(pid, type, p) {
61299+ if (!have_same_root(current, p)) {
61300+ ret = 1;
61301+ goto out;
61302+ }
61303+ } while_each_pid_task(pid, type, p);
61304+out:
61305+ read_unlock(&tasklist_lock);
61306+ return ret;
61307+#endif
61308+ return 0;
61309+}
61310+
61311+int
61312+gr_pid_is_chrooted(struct task_struct *p)
61313+{
61314+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61315+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
61316+ return 0;
61317+
61318+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
61319+ !have_same_root(current, p)) {
61320+ return 1;
61321+ }
61322+#endif
61323+ return 0;
61324+}
61325+
61326+EXPORT_SYMBOL(gr_pid_is_chrooted);
61327+
61328+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
61329+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
61330+{
61331+ struct dentry *dentry = (struct dentry *)u_dentry;
61332+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
61333+ struct dentry *realroot;
61334+ struct vfsmount *realrootmnt;
61335+ struct dentry *currentroot;
61336+ struct vfsmount *currentmnt;
61337+ struct task_struct *reaper = &init_task;
61338+ int ret = 1;
61339+
61340+ read_lock(&reaper->fs->lock);
61341+ realrootmnt = mntget(reaper->fs->root.mnt);
61342+ realroot = dget(reaper->fs->root.dentry);
61343+ read_unlock(&reaper->fs->lock);
61344+
61345+ read_lock(&current->fs->lock);
61346+ currentmnt = mntget(current->fs->root.mnt);
61347+ currentroot = dget(current->fs->root.dentry);
61348+ read_unlock(&current->fs->lock);
61349+
61350+ spin_lock(&dcache_lock);
61351+ for (;;) {
61352+ if (unlikely((dentry == realroot && mnt == realrootmnt)
61353+ || (dentry == currentroot && mnt == currentmnt)))
61354+ break;
61355+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
61356+ if (mnt->mnt_parent == mnt)
61357+ break;
61358+ dentry = mnt->mnt_mountpoint;
61359+ mnt = mnt->mnt_parent;
61360+ continue;
61361+ }
61362+ dentry = dentry->d_parent;
61363+ }
61364+ spin_unlock(&dcache_lock);
61365+
61366+ dput(currentroot);
61367+ mntput(currentmnt);
61368+
61369+ /* access is outside of chroot */
61370+ if (dentry == realroot && mnt == realrootmnt)
61371+ ret = 0;
61372+
61373+ dput(realroot);
61374+ mntput(realrootmnt);
61375+ return ret;
61376+}
61377+#endif
61378+
61379+int
61380+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
61381+{
61382+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61383+ if (!grsec_enable_chroot_fchdir)
61384+ return 1;
61385+
61386+ if (!proc_is_chrooted(current))
61387+ return 1;
61388+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
61389+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
61390+ return 0;
61391+ }
61392+#endif
61393+ return 1;
61394+}
61395+
61396+int
61397+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61398+ const time_t shm_createtime)
61399+{
61400+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61401+ struct task_struct *p;
61402+ time_t starttime;
61403+
61404+ if (unlikely(!grsec_enable_chroot_shmat))
61405+ return 1;
61406+
61407+ if (likely(!proc_is_chrooted(current)))
61408+ return 1;
61409+
61410+ rcu_read_lock();
61411+ read_lock(&tasklist_lock);
61412+
61413+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
61414+ starttime = p->start_time.tv_sec;
61415+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
61416+ if (have_same_root(current, p)) {
61417+ goto allow;
61418+ } else {
61419+ read_unlock(&tasklist_lock);
61420+ rcu_read_unlock();
61421+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61422+ return 0;
61423+ }
61424+ }
61425+ /* creator exited, pid reuse, fall through to next check */
61426+ }
61427+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
61428+ if (unlikely(!have_same_root(current, p))) {
61429+ read_unlock(&tasklist_lock);
61430+ rcu_read_unlock();
61431+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61432+ return 0;
61433+ }
61434+ }
61435+
61436+allow:
61437+ read_unlock(&tasklist_lock);
61438+ rcu_read_unlock();
61439+#endif
61440+ return 1;
61441+}
61442+
61443+void
61444+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
61445+{
61446+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61447+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
61448+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
61449+#endif
61450+ return;
61451+}
61452+
61453+int
61454+gr_handle_chroot_mknod(const struct dentry *dentry,
61455+ const struct vfsmount *mnt, const int mode)
61456+{
61457+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61458+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
61459+ proc_is_chrooted(current)) {
61460+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
61461+ return -EPERM;
61462+ }
61463+#endif
61464+ return 0;
61465+}
61466+
61467+int
61468+gr_handle_chroot_mount(const struct dentry *dentry,
61469+ const struct vfsmount *mnt, const char *dev_name)
61470+{
61471+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61472+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
61473+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
61474+ return -EPERM;
61475+ }
61476+#endif
61477+ return 0;
61478+}
61479+
61480+int
61481+gr_handle_chroot_pivot(void)
61482+{
61483+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61484+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
61485+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
61486+ return -EPERM;
61487+ }
61488+#endif
61489+ return 0;
61490+}
61491+
61492+int
61493+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
61494+{
61495+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61496+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
61497+ !gr_is_outside_chroot(dentry, mnt)) {
61498+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
61499+ return -EPERM;
61500+ }
61501+#endif
61502+ return 0;
61503+}
61504+
61505+extern const char *captab_log[];
61506+extern int captab_log_entries;
61507+
61508+int
61509+gr_chroot_is_capable(const int cap)
61510+{
61511+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61512+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61513+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61514+ if (cap_raised(chroot_caps, cap)) {
61515+ const struct cred *creds = current_cred();
61516+ if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
61517+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
61518+ }
61519+ return 0;
61520+ }
61521+ }
61522+#endif
61523+ return 1;
61524+}
61525+
61526+int
61527+gr_chroot_is_capable_nolog(const int cap)
61528+{
61529+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61530+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61531+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61532+ if (cap_raised(chroot_caps, cap)) {
61533+ return 0;
61534+ }
61535+ }
61536+#endif
61537+ return 1;
61538+}
61539+
61540+int
61541+gr_handle_chroot_sysctl(const int op)
61542+{
61543+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61544+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
61545+ && (op & MAY_WRITE))
61546+ return -EACCES;
61547+#endif
61548+ return 0;
61549+}
61550+
61551+void
61552+gr_handle_chroot_chdir(struct path *path)
61553+{
61554+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61555+ if (grsec_enable_chroot_chdir)
61556+ set_fs_pwd(current->fs, path);
61557+#endif
61558+ return;
61559+}
61560+
61561+int
61562+gr_handle_chroot_chmod(const struct dentry *dentry,
61563+ const struct vfsmount *mnt, const int mode)
61564+{
61565+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61566+ /* allow chmod +s on directories, but not on files */
61567+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
61568+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
61569+ proc_is_chrooted(current)) {
61570+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
61571+ return -EPERM;
61572+ }
61573+#endif
61574+ return 0;
61575+}
61576diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
61577new file mode 100644
61578index 0000000..b81db5b
61579--- /dev/null
61580+++ b/grsecurity/grsec_disabled.c
61581@@ -0,0 +1,439 @@
61582+#include <linux/kernel.h>
61583+#include <linux/module.h>
61584+#include <linux/sched.h>
61585+#include <linux/file.h>
61586+#include <linux/fs.h>
61587+#include <linux/kdev_t.h>
61588+#include <linux/net.h>
61589+#include <linux/in.h>
61590+#include <linux/ip.h>
61591+#include <linux/skbuff.h>
61592+#include <linux/sysctl.h>
61593+
61594+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61595+void
61596+pax_set_initial_flags(struct linux_binprm *bprm)
61597+{
61598+ return;
61599+}
61600+#endif
61601+
61602+#ifdef CONFIG_SYSCTL
61603+__u32
61604+gr_handle_sysctl(const struct ctl_table * table, const int op)
61605+{
61606+ return 0;
61607+}
61608+#endif
61609+
61610+#ifdef CONFIG_TASKSTATS
61611+int gr_is_taskstats_denied(int pid)
61612+{
61613+ return 0;
61614+}
61615+#endif
61616+
61617+int
61618+gr_acl_is_enabled(void)
61619+{
61620+ return 0;
61621+}
61622+
61623+void
61624+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61625+{
61626+ return;
61627+}
61628+
61629+int
61630+gr_handle_rawio(const struct inode *inode)
61631+{
61632+ return 0;
61633+}
61634+
61635+void
61636+gr_acl_handle_psacct(struct task_struct *task, const long code)
61637+{
61638+ return;
61639+}
61640+
61641+int
61642+gr_handle_ptrace(struct task_struct *task, const long request)
61643+{
61644+ return 0;
61645+}
61646+
61647+int
61648+gr_handle_proc_ptrace(struct task_struct *task)
61649+{
61650+ return 0;
61651+}
61652+
61653+void
61654+gr_learn_resource(const struct task_struct *task,
61655+ const int res, const unsigned long wanted, const int gt)
61656+{
61657+ return;
61658+}
61659+
61660+int
61661+gr_set_acls(const int type)
61662+{
61663+ return 0;
61664+}
61665+
61666+int
61667+gr_check_hidden_task(const struct task_struct *tsk)
61668+{
61669+ return 0;
61670+}
61671+
61672+int
61673+gr_check_protected_task(const struct task_struct *task)
61674+{
61675+ return 0;
61676+}
61677+
61678+int
61679+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
61680+{
61681+ return 0;
61682+}
61683+
61684+void
61685+gr_copy_label(struct task_struct *tsk)
61686+{
61687+ return;
61688+}
61689+
61690+void
61691+gr_set_pax_flags(struct task_struct *task)
61692+{
61693+ return;
61694+}
61695+
61696+int
61697+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
61698+ const int unsafe_share)
61699+{
61700+ return 0;
61701+}
61702+
61703+void
61704+gr_handle_delete(const ino_t ino, const dev_t dev)
61705+{
61706+ return;
61707+}
61708+
61709+void
61710+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61711+{
61712+ return;
61713+}
61714+
61715+void
61716+gr_handle_crash(struct task_struct *task, const int sig)
61717+{
61718+ return;
61719+}
61720+
61721+int
61722+gr_check_crash_exec(const struct file *filp)
61723+{
61724+ return 0;
61725+}
61726+
61727+int
61728+gr_check_crash_uid(const uid_t uid)
61729+{
61730+ return 0;
61731+}
61732+
61733+void
61734+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61735+ struct dentry *old_dentry,
61736+ struct dentry *new_dentry,
61737+ struct vfsmount *mnt, const __u8 replace)
61738+{
61739+ return;
61740+}
61741+
61742+int
61743+gr_search_socket(const int family, const int type, const int protocol)
61744+{
61745+ return 1;
61746+}
61747+
61748+int
61749+gr_search_connectbind(const int mode, const struct socket *sock,
61750+ const struct sockaddr_in *addr)
61751+{
61752+ return 0;
61753+}
61754+
61755+void
61756+gr_handle_alertkill(struct task_struct *task)
61757+{
61758+ return;
61759+}
61760+
61761+__u32
61762+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
61763+{
61764+ return 1;
61765+}
61766+
61767+__u32
61768+gr_acl_handle_hidden_file(const struct dentry * dentry,
61769+ const struct vfsmount * mnt)
61770+{
61771+ return 1;
61772+}
61773+
61774+__u32
61775+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61776+ int acc_mode)
61777+{
61778+ return 1;
61779+}
61780+
61781+__u32
61782+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61783+{
61784+ return 1;
61785+}
61786+
61787+__u32
61788+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
61789+{
61790+ return 1;
61791+}
61792+
61793+int
61794+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
61795+ unsigned int *vm_flags)
61796+{
61797+ return 1;
61798+}
61799+
61800+__u32
61801+gr_acl_handle_truncate(const struct dentry * dentry,
61802+ const struct vfsmount * mnt)
61803+{
61804+ return 1;
61805+}
61806+
61807+__u32
61808+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
61809+{
61810+ return 1;
61811+}
61812+
61813+__u32
61814+gr_acl_handle_access(const struct dentry * dentry,
61815+ const struct vfsmount * mnt, const int fmode)
61816+{
61817+ return 1;
61818+}
61819+
61820+__u32
61821+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
61822+ mode_t mode)
61823+{
61824+ return 1;
61825+}
61826+
61827+__u32
61828+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
61829+ mode_t mode)
61830+{
61831+ return 1;
61832+}
61833+
61834+__u32
61835+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
61836+{
61837+ return 1;
61838+}
61839+
61840+__u32
61841+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
61842+{
61843+ return 1;
61844+}
61845+
61846+void
61847+grsecurity_init(void)
61848+{
61849+ return;
61850+}
61851+
61852+__u32
61853+gr_acl_handle_mknod(const struct dentry * new_dentry,
61854+ const struct dentry * parent_dentry,
61855+ const struct vfsmount * parent_mnt,
61856+ const int mode)
61857+{
61858+ return 1;
61859+}
61860+
61861+__u32
61862+gr_acl_handle_mkdir(const struct dentry * new_dentry,
61863+ const struct dentry * parent_dentry,
61864+ const struct vfsmount * parent_mnt)
61865+{
61866+ return 1;
61867+}
61868+
61869+__u32
61870+gr_acl_handle_symlink(const struct dentry * new_dentry,
61871+ const struct dentry * parent_dentry,
61872+ const struct vfsmount * parent_mnt, const char *from)
61873+{
61874+ return 1;
61875+}
61876+
61877+__u32
61878+gr_acl_handle_link(const struct dentry * new_dentry,
61879+ const struct dentry * parent_dentry,
61880+ const struct vfsmount * parent_mnt,
61881+ const struct dentry * old_dentry,
61882+ const struct vfsmount * old_mnt, const char *to)
61883+{
61884+ return 1;
61885+}
61886+
61887+int
61888+gr_acl_handle_rename(const struct dentry *new_dentry,
61889+ const struct dentry *parent_dentry,
61890+ const struct vfsmount *parent_mnt,
61891+ const struct dentry *old_dentry,
61892+ const struct inode *old_parent_inode,
61893+ const struct vfsmount *old_mnt, const char *newname)
61894+{
61895+ return 0;
61896+}
61897+
61898+int
61899+gr_acl_handle_filldir(const struct file *file, const char *name,
61900+ const int namelen, const ino_t ino)
61901+{
61902+ return 1;
61903+}
61904+
61905+int
61906+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61907+ const time_t shm_createtime, const uid_t cuid, const int shmid)
61908+{
61909+ return 1;
61910+}
61911+
61912+int
61913+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
61914+{
61915+ return 0;
61916+}
61917+
61918+int
61919+gr_search_accept(const struct socket *sock)
61920+{
61921+ return 0;
61922+}
61923+
61924+int
61925+gr_search_listen(const struct socket *sock)
61926+{
61927+ return 0;
61928+}
61929+
61930+int
61931+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
61932+{
61933+ return 0;
61934+}
61935+
61936+__u32
61937+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
61938+{
61939+ return 1;
61940+}
61941+
61942+__u32
61943+gr_acl_handle_creat(const struct dentry * dentry,
61944+ const struct dentry * p_dentry,
61945+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61946+ const int imode)
61947+{
61948+ return 1;
61949+}
61950+
61951+void
61952+gr_acl_handle_exit(void)
61953+{
61954+ return;
61955+}
61956+
61957+int
61958+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61959+{
61960+ return 1;
61961+}
61962+
61963+void
61964+gr_set_role_label(const uid_t uid, const gid_t gid)
61965+{
61966+ return;
61967+}
61968+
61969+int
61970+gr_acl_handle_procpidmem(const struct task_struct *task)
61971+{
61972+ return 0;
61973+}
61974+
61975+int
61976+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
61977+{
61978+ return 0;
61979+}
61980+
61981+int
61982+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
61983+{
61984+ return 0;
61985+}
61986+
61987+void
61988+gr_set_kernel_label(struct task_struct *task)
61989+{
61990+ return;
61991+}
61992+
61993+int
61994+gr_check_user_change(int real, int effective, int fs)
61995+{
61996+ return 0;
61997+}
61998+
61999+int
62000+gr_check_group_change(int real, int effective, int fs)
62001+{
62002+ return 0;
62003+}
62004+
62005+int gr_acl_enable_at_secure(void)
62006+{
62007+ return 0;
62008+}
62009+
62010+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62011+{
62012+ return dentry->d_inode->i_sb->s_dev;
62013+}
62014+
62015+EXPORT_SYMBOL(gr_learn_resource);
62016+EXPORT_SYMBOL(gr_set_kernel_label);
62017+#ifdef CONFIG_SECURITY
62018+EXPORT_SYMBOL(gr_check_user_change);
62019+EXPORT_SYMBOL(gr_check_group_change);
62020+#endif
62021diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
62022new file mode 100644
62023index 0000000..a96e155
62024--- /dev/null
62025+++ b/grsecurity/grsec_exec.c
62026@@ -0,0 +1,204 @@
62027+#include <linux/kernel.h>
62028+#include <linux/sched.h>
62029+#include <linux/file.h>
62030+#include <linux/binfmts.h>
62031+#include <linux/smp_lock.h>
62032+#include <linux/fs.h>
62033+#include <linux/types.h>
62034+#include <linux/grdefs.h>
62035+#include <linux/grinternal.h>
62036+#include <linux/capability.h>
62037+#include <linux/compat.h>
62038+#include <linux/module.h>
62039+
62040+#include <asm/uaccess.h>
62041+
62042+#ifdef CONFIG_GRKERNSEC_EXECLOG
62043+static char gr_exec_arg_buf[132];
62044+static DEFINE_MUTEX(gr_exec_arg_mutex);
62045+#endif
62046+
62047+void
62048+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
62049+{
62050+#ifdef CONFIG_GRKERNSEC_EXECLOG
62051+ char *grarg = gr_exec_arg_buf;
62052+ unsigned int i, x, execlen = 0;
62053+ char c;
62054+
62055+ if (!((grsec_enable_execlog && grsec_enable_group &&
62056+ in_group_p(grsec_audit_gid))
62057+ || (grsec_enable_execlog && !grsec_enable_group)))
62058+ return;
62059+
62060+ mutex_lock(&gr_exec_arg_mutex);
62061+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62062+
62063+ if (unlikely(argv == NULL))
62064+ goto log;
62065+
62066+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62067+ const char __user *p;
62068+ unsigned int len;
62069+
62070+ if (copy_from_user(&p, argv + i, sizeof(p)))
62071+ goto log;
62072+ if (!p)
62073+ goto log;
62074+ len = strnlen_user(p, 128 - execlen);
62075+ if (len > 128 - execlen)
62076+ len = 128 - execlen;
62077+ else if (len > 0)
62078+ len--;
62079+ if (copy_from_user(grarg + execlen, p, len))
62080+ goto log;
62081+
62082+ /* rewrite unprintable characters */
62083+ for (x = 0; x < len; x++) {
62084+ c = *(grarg + execlen + x);
62085+ if (c < 32 || c > 126)
62086+ *(grarg + execlen + x) = ' ';
62087+ }
62088+
62089+ execlen += len;
62090+ *(grarg + execlen) = ' ';
62091+ *(grarg + execlen + 1) = '\0';
62092+ execlen++;
62093+ }
62094+
62095+ log:
62096+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62097+ bprm->file->f_path.mnt, grarg);
62098+ mutex_unlock(&gr_exec_arg_mutex);
62099+#endif
62100+ return;
62101+}
62102+
62103+#ifdef CONFIG_COMPAT
62104+void
62105+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
62106+{
62107+#ifdef CONFIG_GRKERNSEC_EXECLOG
62108+ char *grarg = gr_exec_arg_buf;
62109+ unsigned int i, x, execlen = 0;
62110+ char c;
62111+
62112+ if (!((grsec_enable_execlog && grsec_enable_group &&
62113+ in_group_p(grsec_audit_gid))
62114+ || (grsec_enable_execlog && !grsec_enable_group)))
62115+ return;
62116+
62117+ mutex_lock(&gr_exec_arg_mutex);
62118+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62119+
62120+ if (unlikely(argv == NULL))
62121+ goto log;
62122+
62123+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62124+ compat_uptr_t p;
62125+ unsigned int len;
62126+
62127+ if (get_user(p, argv + i))
62128+ goto log;
62129+ len = strnlen_user(compat_ptr(p), 128 - execlen);
62130+ if (len > 128 - execlen)
62131+ len = 128 - execlen;
62132+ else if (len > 0)
62133+ len--;
62134+ else
62135+ goto log;
62136+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
62137+ goto log;
62138+
62139+ /* rewrite unprintable characters */
62140+ for (x = 0; x < len; x++) {
62141+ c = *(grarg + execlen + x);
62142+ if (c < 32 || c > 126)
62143+ *(grarg + execlen + x) = ' ';
62144+ }
62145+
62146+ execlen += len;
62147+ *(grarg + execlen) = ' ';
62148+ *(grarg + execlen + 1) = '\0';
62149+ execlen++;
62150+ }
62151+
62152+ log:
62153+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62154+ bprm->file->f_path.mnt, grarg);
62155+ mutex_unlock(&gr_exec_arg_mutex);
62156+#endif
62157+ return;
62158+}
62159+#endif
62160+
62161+#ifdef CONFIG_GRKERNSEC
62162+extern int gr_acl_is_capable(const int cap);
62163+extern int gr_acl_is_capable_nolog(const int cap);
62164+extern int gr_chroot_is_capable(const int cap);
62165+extern int gr_chroot_is_capable_nolog(const int cap);
62166+#endif
62167+
62168+const char *captab_log[] = {
62169+ "CAP_CHOWN",
62170+ "CAP_DAC_OVERRIDE",
62171+ "CAP_DAC_READ_SEARCH",
62172+ "CAP_FOWNER",
62173+ "CAP_FSETID",
62174+ "CAP_KILL",
62175+ "CAP_SETGID",
62176+ "CAP_SETUID",
62177+ "CAP_SETPCAP",
62178+ "CAP_LINUX_IMMUTABLE",
62179+ "CAP_NET_BIND_SERVICE",
62180+ "CAP_NET_BROADCAST",
62181+ "CAP_NET_ADMIN",
62182+ "CAP_NET_RAW",
62183+ "CAP_IPC_LOCK",
62184+ "CAP_IPC_OWNER",
62185+ "CAP_SYS_MODULE",
62186+ "CAP_SYS_RAWIO",
62187+ "CAP_SYS_CHROOT",
62188+ "CAP_SYS_PTRACE",
62189+ "CAP_SYS_PACCT",
62190+ "CAP_SYS_ADMIN",
62191+ "CAP_SYS_BOOT",
62192+ "CAP_SYS_NICE",
62193+ "CAP_SYS_RESOURCE",
62194+ "CAP_SYS_TIME",
62195+ "CAP_SYS_TTY_CONFIG",
62196+ "CAP_MKNOD",
62197+ "CAP_LEASE",
62198+ "CAP_AUDIT_WRITE",
62199+ "CAP_AUDIT_CONTROL",
62200+ "CAP_SETFCAP",
62201+ "CAP_MAC_OVERRIDE",
62202+ "CAP_MAC_ADMIN"
62203+};
62204+
62205+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
62206+
62207+int gr_is_capable(const int cap)
62208+{
62209+#ifdef CONFIG_GRKERNSEC
62210+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
62211+ return 1;
62212+ return 0;
62213+#else
62214+ return 1;
62215+#endif
62216+}
62217+
62218+int gr_is_capable_nolog(const int cap)
62219+{
62220+#ifdef CONFIG_GRKERNSEC
62221+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
62222+ return 1;
62223+ return 0;
62224+#else
62225+ return 1;
62226+#endif
62227+}
62228+
62229+EXPORT_SYMBOL(gr_is_capable);
62230+EXPORT_SYMBOL(gr_is_capable_nolog);
62231diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
62232new file mode 100644
62233index 0000000..d3ee748
62234--- /dev/null
62235+++ b/grsecurity/grsec_fifo.c
62236@@ -0,0 +1,24 @@
62237+#include <linux/kernel.h>
62238+#include <linux/sched.h>
62239+#include <linux/fs.h>
62240+#include <linux/file.h>
62241+#include <linux/grinternal.h>
62242+
62243+int
62244+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
62245+ const struct dentry *dir, const int flag, const int acc_mode)
62246+{
62247+#ifdef CONFIG_GRKERNSEC_FIFO
62248+ const struct cred *cred = current_cred();
62249+
62250+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
62251+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
62252+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
62253+ (cred->fsuid != dentry->d_inode->i_uid)) {
62254+ if (!inode_permission(dentry->d_inode, acc_mode))
62255+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
62256+ return -EACCES;
62257+ }
62258+#endif
62259+ return 0;
62260+}
62261diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
62262new file mode 100644
62263index 0000000..8ca18bf
62264--- /dev/null
62265+++ b/grsecurity/grsec_fork.c
62266@@ -0,0 +1,23 @@
62267+#include <linux/kernel.h>
62268+#include <linux/sched.h>
62269+#include <linux/grsecurity.h>
62270+#include <linux/grinternal.h>
62271+#include <linux/errno.h>
62272+
62273+void
62274+gr_log_forkfail(const int retval)
62275+{
62276+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62277+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
62278+ switch (retval) {
62279+ case -EAGAIN:
62280+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
62281+ break;
62282+ case -ENOMEM:
62283+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
62284+ break;
62285+ }
62286+ }
62287+#endif
62288+ return;
62289+}
62290diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
62291new file mode 100644
62292index 0000000..f813c26
62293--- /dev/null
62294+++ b/grsecurity/grsec_init.c
62295@@ -0,0 +1,270 @@
62296+#include <linux/kernel.h>
62297+#include <linux/sched.h>
62298+#include <linux/mm.h>
62299+#include <linux/smp_lock.h>
62300+#include <linux/gracl.h>
62301+#include <linux/slab.h>
62302+#include <linux/vmalloc.h>
62303+#include <linux/percpu.h>
62304+#include <linux/module.h>
62305+
62306+int grsec_enable_brute;
62307+int grsec_enable_link;
62308+int grsec_enable_dmesg;
62309+int grsec_enable_harden_ptrace;
62310+int grsec_enable_fifo;
62311+int grsec_enable_execlog;
62312+int grsec_enable_signal;
62313+int grsec_enable_forkfail;
62314+int grsec_enable_audit_ptrace;
62315+int grsec_enable_time;
62316+int grsec_enable_audit_textrel;
62317+int grsec_enable_group;
62318+int grsec_audit_gid;
62319+int grsec_enable_chdir;
62320+int grsec_enable_mount;
62321+int grsec_enable_rofs;
62322+int grsec_enable_chroot_findtask;
62323+int grsec_enable_chroot_mount;
62324+int grsec_enable_chroot_shmat;
62325+int grsec_enable_chroot_fchdir;
62326+int grsec_enable_chroot_double;
62327+int grsec_enable_chroot_pivot;
62328+int grsec_enable_chroot_chdir;
62329+int grsec_enable_chroot_chmod;
62330+int grsec_enable_chroot_mknod;
62331+int grsec_enable_chroot_nice;
62332+int grsec_enable_chroot_execlog;
62333+int grsec_enable_chroot_caps;
62334+int grsec_enable_chroot_sysctl;
62335+int grsec_enable_chroot_unix;
62336+int grsec_enable_tpe;
62337+int grsec_tpe_gid;
62338+int grsec_enable_blackhole;
62339+#ifdef CONFIG_IPV6_MODULE
62340+EXPORT_SYMBOL(grsec_enable_blackhole);
62341+#endif
62342+int grsec_lastack_retries;
62343+int grsec_enable_tpe_all;
62344+int grsec_enable_tpe_invert;
62345+int grsec_enable_socket_all;
62346+int grsec_socket_all_gid;
62347+int grsec_enable_socket_client;
62348+int grsec_socket_client_gid;
62349+int grsec_enable_socket_server;
62350+int grsec_socket_server_gid;
62351+int grsec_resource_logging;
62352+int grsec_disable_privio;
62353+int grsec_enable_log_rwxmaps;
62354+int grsec_lock;
62355+
62356+DEFINE_SPINLOCK(grsec_alert_lock);
62357+unsigned long grsec_alert_wtime = 0;
62358+unsigned long grsec_alert_fyet = 0;
62359+
62360+DEFINE_SPINLOCK(grsec_audit_lock);
62361+
62362+DEFINE_RWLOCK(grsec_exec_file_lock);
62363+
62364+char *gr_shared_page[4];
62365+
62366+char *gr_alert_log_fmt;
62367+char *gr_audit_log_fmt;
62368+char *gr_alert_log_buf;
62369+char *gr_audit_log_buf;
62370+
62371+extern struct gr_arg *gr_usermode;
62372+extern unsigned char *gr_system_salt;
62373+extern unsigned char *gr_system_sum;
62374+
62375+void __init
62376+grsecurity_init(void)
62377+{
62378+ int j;
62379+ /* create the per-cpu shared pages */
62380+
62381+#ifdef CONFIG_X86
62382+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
62383+#endif
62384+
62385+ for (j = 0; j < 4; j++) {
62386+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
62387+ if (gr_shared_page[j] == NULL) {
62388+ panic("Unable to allocate grsecurity shared page");
62389+ return;
62390+ }
62391+ }
62392+
62393+ /* allocate log buffers */
62394+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
62395+ if (!gr_alert_log_fmt) {
62396+ panic("Unable to allocate grsecurity alert log format buffer");
62397+ return;
62398+ }
62399+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
62400+ if (!gr_audit_log_fmt) {
62401+ panic("Unable to allocate grsecurity audit log format buffer");
62402+ return;
62403+ }
62404+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62405+ if (!gr_alert_log_buf) {
62406+ panic("Unable to allocate grsecurity alert log buffer");
62407+ return;
62408+ }
62409+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62410+ if (!gr_audit_log_buf) {
62411+ panic("Unable to allocate grsecurity audit log buffer");
62412+ return;
62413+ }
62414+
62415+ /* allocate memory for authentication structure */
62416+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
62417+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
62418+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
62419+
62420+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
62421+ panic("Unable to allocate grsecurity authentication structure");
62422+ return;
62423+ }
62424+
62425+
62426+#ifdef CONFIG_GRKERNSEC_IO
62427+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
62428+ grsec_disable_privio = 1;
62429+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62430+ grsec_disable_privio = 1;
62431+#else
62432+ grsec_disable_privio = 0;
62433+#endif
62434+#endif
62435+
62436+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62437+ /* for backward compatibility, tpe_invert always defaults to on if
62438+ enabled in the kernel
62439+ */
62440+ grsec_enable_tpe_invert = 1;
62441+#endif
62442+
62443+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62444+#ifndef CONFIG_GRKERNSEC_SYSCTL
62445+ grsec_lock = 1;
62446+#endif
62447+
62448+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62449+ grsec_enable_audit_textrel = 1;
62450+#endif
62451+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62452+ grsec_enable_log_rwxmaps = 1;
62453+#endif
62454+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62455+ grsec_enable_group = 1;
62456+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
62457+#endif
62458+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62459+ grsec_enable_chdir = 1;
62460+#endif
62461+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62462+ grsec_enable_harden_ptrace = 1;
62463+#endif
62464+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62465+ grsec_enable_mount = 1;
62466+#endif
62467+#ifdef CONFIG_GRKERNSEC_LINK
62468+ grsec_enable_link = 1;
62469+#endif
62470+#ifdef CONFIG_GRKERNSEC_BRUTE
62471+ grsec_enable_brute = 1;
62472+#endif
62473+#ifdef CONFIG_GRKERNSEC_DMESG
62474+ grsec_enable_dmesg = 1;
62475+#endif
62476+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62477+ grsec_enable_blackhole = 1;
62478+ grsec_lastack_retries = 4;
62479+#endif
62480+#ifdef CONFIG_GRKERNSEC_FIFO
62481+ grsec_enable_fifo = 1;
62482+#endif
62483+#ifdef CONFIG_GRKERNSEC_EXECLOG
62484+ grsec_enable_execlog = 1;
62485+#endif
62486+#ifdef CONFIG_GRKERNSEC_SIGNAL
62487+ grsec_enable_signal = 1;
62488+#endif
62489+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62490+ grsec_enable_forkfail = 1;
62491+#endif
62492+#ifdef CONFIG_GRKERNSEC_TIME
62493+ grsec_enable_time = 1;
62494+#endif
62495+#ifdef CONFIG_GRKERNSEC_RESLOG
62496+ grsec_resource_logging = 1;
62497+#endif
62498+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62499+ grsec_enable_chroot_findtask = 1;
62500+#endif
62501+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62502+ grsec_enable_chroot_unix = 1;
62503+#endif
62504+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62505+ grsec_enable_chroot_mount = 1;
62506+#endif
62507+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62508+ grsec_enable_chroot_fchdir = 1;
62509+#endif
62510+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62511+ grsec_enable_chroot_shmat = 1;
62512+#endif
62513+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62514+ grsec_enable_audit_ptrace = 1;
62515+#endif
62516+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62517+ grsec_enable_chroot_double = 1;
62518+#endif
62519+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62520+ grsec_enable_chroot_pivot = 1;
62521+#endif
62522+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62523+ grsec_enable_chroot_chdir = 1;
62524+#endif
62525+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62526+ grsec_enable_chroot_chmod = 1;
62527+#endif
62528+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62529+ grsec_enable_chroot_mknod = 1;
62530+#endif
62531+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62532+ grsec_enable_chroot_nice = 1;
62533+#endif
62534+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62535+ grsec_enable_chroot_execlog = 1;
62536+#endif
62537+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62538+ grsec_enable_chroot_caps = 1;
62539+#endif
62540+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62541+ grsec_enable_chroot_sysctl = 1;
62542+#endif
62543+#ifdef CONFIG_GRKERNSEC_TPE
62544+ grsec_enable_tpe = 1;
62545+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
62546+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62547+ grsec_enable_tpe_all = 1;
62548+#endif
62549+#endif
62550+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62551+ grsec_enable_socket_all = 1;
62552+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
62553+#endif
62554+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62555+ grsec_enable_socket_client = 1;
62556+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
62557+#endif
62558+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62559+ grsec_enable_socket_server = 1;
62560+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
62561+#endif
62562+#endif
62563+
62564+ return;
62565+}
62566diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
62567new file mode 100644
62568index 0000000..3efe141
62569--- /dev/null
62570+++ b/grsecurity/grsec_link.c
62571@@ -0,0 +1,43 @@
62572+#include <linux/kernel.h>
62573+#include <linux/sched.h>
62574+#include <linux/fs.h>
62575+#include <linux/file.h>
62576+#include <linux/grinternal.h>
62577+
62578+int
62579+gr_handle_follow_link(const struct inode *parent,
62580+ const struct inode *inode,
62581+ const struct dentry *dentry, const struct vfsmount *mnt)
62582+{
62583+#ifdef CONFIG_GRKERNSEC_LINK
62584+ const struct cred *cred = current_cred();
62585+
62586+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
62587+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
62588+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
62589+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
62590+ return -EACCES;
62591+ }
62592+#endif
62593+ return 0;
62594+}
62595+
62596+int
62597+gr_handle_hardlink(const struct dentry *dentry,
62598+ const struct vfsmount *mnt,
62599+ struct inode *inode, const int mode, const char *to)
62600+{
62601+#ifdef CONFIG_GRKERNSEC_LINK
62602+ const struct cred *cred = current_cred();
62603+
62604+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
62605+ (!S_ISREG(mode) || (mode & S_ISUID) ||
62606+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
62607+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
62608+ !capable(CAP_FOWNER) && cred->uid) {
62609+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
62610+ return -EPERM;
62611+ }
62612+#endif
62613+ return 0;
62614+}
62615diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
62616new file mode 100644
62617index 0000000..a45d2e9
62618--- /dev/null
62619+++ b/grsecurity/grsec_log.c
62620@@ -0,0 +1,322 @@
62621+#include <linux/kernel.h>
62622+#include <linux/sched.h>
62623+#include <linux/file.h>
62624+#include <linux/tty.h>
62625+#include <linux/fs.h>
62626+#include <linux/grinternal.h>
62627+
62628+#ifdef CONFIG_TREE_PREEMPT_RCU
62629+#define DISABLE_PREEMPT() preempt_disable()
62630+#define ENABLE_PREEMPT() preempt_enable()
62631+#else
62632+#define DISABLE_PREEMPT()
62633+#define ENABLE_PREEMPT()
62634+#endif
62635+
62636+#define BEGIN_LOCKS(x) \
62637+ DISABLE_PREEMPT(); \
62638+ rcu_read_lock(); \
62639+ read_lock(&tasklist_lock); \
62640+ read_lock(&grsec_exec_file_lock); \
62641+ if (x != GR_DO_AUDIT) \
62642+ spin_lock(&grsec_alert_lock); \
62643+ else \
62644+ spin_lock(&grsec_audit_lock)
62645+
62646+#define END_LOCKS(x) \
62647+ if (x != GR_DO_AUDIT) \
62648+ spin_unlock(&grsec_alert_lock); \
62649+ else \
62650+ spin_unlock(&grsec_audit_lock); \
62651+ read_unlock(&grsec_exec_file_lock); \
62652+ read_unlock(&tasklist_lock); \
62653+ rcu_read_unlock(); \
62654+ ENABLE_PREEMPT(); \
62655+ if (x == GR_DONT_AUDIT) \
62656+ gr_handle_alertkill(current)
62657+
62658+enum {
62659+ FLOODING,
62660+ NO_FLOODING
62661+};
62662+
62663+extern char *gr_alert_log_fmt;
62664+extern char *gr_audit_log_fmt;
62665+extern char *gr_alert_log_buf;
62666+extern char *gr_audit_log_buf;
62667+
62668+static int gr_log_start(int audit)
62669+{
62670+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
62671+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
62672+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62673+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
62674+ unsigned long curr_secs = get_seconds();
62675+
62676+ if (audit == GR_DO_AUDIT)
62677+ goto set_fmt;
62678+
62679+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
62680+ grsec_alert_wtime = curr_secs;
62681+ grsec_alert_fyet = 0;
62682+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
62683+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
62684+ grsec_alert_fyet++;
62685+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
62686+ grsec_alert_wtime = curr_secs;
62687+ grsec_alert_fyet++;
62688+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
62689+ return FLOODING;
62690+ }
62691+ else return FLOODING;
62692+
62693+set_fmt:
62694+#endif
62695+ memset(buf, 0, PAGE_SIZE);
62696+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
62697+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
62698+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62699+ } else if (current->signal->curr_ip) {
62700+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
62701+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
62702+ } else if (gr_acl_is_enabled()) {
62703+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
62704+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62705+ } else {
62706+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
62707+ strcpy(buf, fmt);
62708+ }
62709+
62710+ return NO_FLOODING;
62711+}
62712+
62713+static void gr_log_middle(int audit, const char *msg, va_list ap)
62714+ __attribute__ ((format (printf, 2, 0)));
62715+
62716+static void gr_log_middle(int audit, const char *msg, va_list ap)
62717+{
62718+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62719+ unsigned int len = strlen(buf);
62720+
62721+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
62722+
62723+ return;
62724+}
62725+
62726+static void gr_log_middle_varargs(int audit, const char *msg, ...)
62727+ __attribute__ ((format (printf, 2, 3)));
62728+
62729+static void gr_log_middle_varargs(int audit, const char *msg, ...)
62730+{
62731+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62732+ unsigned int len = strlen(buf);
62733+ va_list ap;
62734+
62735+ va_start(ap, msg);
62736+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
62737+ va_end(ap);
62738+
62739+ return;
62740+}
62741+
62742+static void gr_log_end(int audit, int append_default)
62743+{
62744+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62745+
62746+ if (append_default) {
62747+ unsigned int len = strlen(buf);
62748+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
62749+ }
62750+
62751+ printk("%s\n", buf);
62752+
62753+ return;
62754+}
62755+
62756+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
62757+{
62758+ int logtype;
62759+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
62760+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
62761+ void *voidptr = NULL;
62762+ int num1 = 0, num2 = 0;
62763+ unsigned long ulong1 = 0, ulong2 = 0;
62764+ struct dentry *dentry = NULL;
62765+ struct vfsmount *mnt = NULL;
62766+ struct file *file = NULL;
62767+ struct task_struct *task = NULL;
62768+ const struct cred *cred, *pcred;
62769+ va_list ap;
62770+
62771+ BEGIN_LOCKS(audit);
62772+ logtype = gr_log_start(audit);
62773+ if (logtype == FLOODING) {
62774+ END_LOCKS(audit);
62775+ return;
62776+ }
62777+ va_start(ap, argtypes);
62778+ switch (argtypes) {
62779+ case GR_TTYSNIFF:
62780+ task = va_arg(ap, struct task_struct *);
62781+ 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);
62782+ break;
62783+ case GR_SYSCTL_HIDDEN:
62784+ str1 = va_arg(ap, char *);
62785+ gr_log_middle_varargs(audit, msg, result, str1);
62786+ break;
62787+ case GR_RBAC:
62788+ dentry = va_arg(ap, struct dentry *);
62789+ mnt = va_arg(ap, struct vfsmount *);
62790+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
62791+ break;
62792+ case GR_RBAC_STR:
62793+ dentry = va_arg(ap, struct dentry *);
62794+ mnt = va_arg(ap, struct vfsmount *);
62795+ str1 = va_arg(ap, char *);
62796+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
62797+ break;
62798+ case GR_STR_RBAC:
62799+ str1 = va_arg(ap, char *);
62800+ dentry = va_arg(ap, struct dentry *);
62801+ mnt = va_arg(ap, struct vfsmount *);
62802+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
62803+ break;
62804+ case GR_RBAC_MODE2:
62805+ dentry = va_arg(ap, struct dentry *);
62806+ mnt = va_arg(ap, struct vfsmount *);
62807+ str1 = va_arg(ap, char *);
62808+ str2 = va_arg(ap, char *);
62809+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
62810+ break;
62811+ case GR_RBAC_MODE3:
62812+ dentry = va_arg(ap, struct dentry *);
62813+ mnt = va_arg(ap, struct vfsmount *);
62814+ str1 = va_arg(ap, char *);
62815+ str2 = va_arg(ap, char *);
62816+ str3 = va_arg(ap, char *);
62817+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
62818+ break;
62819+ case GR_FILENAME:
62820+ dentry = va_arg(ap, struct dentry *);
62821+ mnt = va_arg(ap, struct vfsmount *);
62822+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
62823+ break;
62824+ case GR_STR_FILENAME:
62825+ str1 = va_arg(ap, char *);
62826+ dentry = va_arg(ap, struct dentry *);
62827+ mnt = va_arg(ap, struct vfsmount *);
62828+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
62829+ break;
62830+ case GR_FILENAME_STR:
62831+ dentry = va_arg(ap, struct dentry *);
62832+ mnt = va_arg(ap, struct vfsmount *);
62833+ str1 = va_arg(ap, char *);
62834+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
62835+ break;
62836+ case GR_FILENAME_TWO_INT:
62837+ dentry = va_arg(ap, struct dentry *);
62838+ mnt = va_arg(ap, struct vfsmount *);
62839+ num1 = va_arg(ap, int);
62840+ num2 = va_arg(ap, int);
62841+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
62842+ break;
62843+ case GR_FILENAME_TWO_INT_STR:
62844+ dentry = va_arg(ap, struct dentry *);
62845+ mnt = va_arg(ap, struct vfsmount *);
62846+ num1 = va_arg(ap, int);
62847+ num2 = va_arg(ap, int);
62848+ str1 = va_arg(ap, char *);
62849+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
62850+ break;
62851+ case GR_TEXTREL:
62852+ file = va_arg(ap, struct file *);
62853+ ulong1 = va_arg(ap, unsigned long);
62854+ ulong2 = va_arg(ap, unsigned long);
62855+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
62856+ break;
62857+ case GR_PTRACE:
62858+ task = va_arg(ap, struct task_struct *);
62859+ 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);
62860+ break;
62861+ case GR_RESOURCE:
62862+ task = va_arg(ap, struct task_struct *);
62863+ cred = __task_cred(task);
62864+ pcred = __task_cred(task->real_parent);
62865+ ulong1 = va_arg(ap, unsigned long);
62866+ str1 = va_arg(ap, char *);
62867+ ulong2 = va_arg(ap, unsigned long);
62868+ 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);
62869+ break;
62870+ case GR_CAP:
62871+ task = va_arg(ap, struct task_struct *);
62872+ cred = __task_cred(task);
62873+ pcred = __task_cred(task->real_parent);
62874+ str1 = va_arg(ap, char *);
62875+ 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);
62876+ break;
62877+ case GR_SIG:
62878+ str1 = va_arg(ap, char *);
62879+ voidptr = va_arg(ap, void *);
62880+ gr_log_middle_varargs(audit, msg, str1, voidptr);
62881+ break;
62882+ case GR_SIG2:
62883+ task = va_arg(ap, struct task_struct *);
62884+ cred = __task_cred(task);
62885+ pcred = __task_cred(task->real_parent);
62886+ num1 = va_arg(ap, int);
62887+ 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);
62888+ break;
62889+ case GR_CRASH1:
62890+ task = va_arg(ap, struct task_struct *);
62891+ cred = __task_cred(task);
62892+ pcred = __task_cred(task->real_parent);
62893+ ulong1 = va_arg(ap, unsigned long);
62894+ 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);
62895+ break;
62896+ case GR_CRASH2:
62897+ task = va_arg(ap, struct task_struct *);
62898+ cred = __task_cred(task);
62899+ pcred = __task_cred(task->real_parent);
62900+ ulong1 = va_arg(ap, unsigned long);
62901+ 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);
62902+ break;
62903+ case GR_RWXMAP:
62904+ file = va_arg(ap, struct file *);
62905+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
62906+ break;
62907+ case GR_PSACCT:
62908+ {
62909+ unsigned int wday, cday;
62910+ __u8 whr, chr;
62911+ __u8 wmin, cmin;
62912+ __u8 wsec, csec;
62913+ char cur_tty[64] = { 0 };
62914+ char parent_tty[64] = { 0 };
62915+
62916+ task = va_arg(ap, struct task_struct *);
62917+ wday = va_arg(ap, unsigned int);
62918+ cday = va_arg(ap, unsigned int);
62919+ whr = va_arg(ap, int);
62920+ chr = va_arg(ap, int);
62921+ wmin = va_arg(ap, int);
62922+ cmin = va_arg(ap, int);
62923+ wsec = va_arg(ap, int);
62924+ csec = va_arg(ap, int);
62925+ ulong1 = va_arg(ap, unsigned long);
62926+ cred = __task_cred(task);
62927+ pcred = __task_cred(task->real_parent);
62928+
62929+ 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);
62930+ }
62931+ break;
62932+ default:
62933+ gr_log_middle(audit, msg, ap);
62934+ }
62935+ va_end(ap);
62936+ // these don't need DEFAULTSECARGS printed on the end
62937+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
62938+ gr_log_end(audit, 0);
62939+ else
62940+ gr_log_end(audit, 1);
62941+ END_LOCKS(audit);
62942+}
62943diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
62944new file mode 100644
62945index 0000000..6c0416b
62946--- /dev/null
62947+++ b/grsecurity/grsec_mem.c
62948@@ -0,0 +1,33 @@
62949+#include <linux/kernel.h>
62950+#include <linux/sched.h>
62951+#include <linux/mm.h>
62952+#include <linux/mman.h>
62953+#include <linux/grinternal.h>
62954+
62955+void
62956+gr_handle_ioperm(void)
62957+{
62958+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
62959+ return;
62960+}
62961+
62962+void
62963+gr_handle_iopl(void)
62964+{
62965+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
62966+ return;
62967+}
62968+
62969+void
62970+gr_handle_mem_readwrite(u64 from, u64 to)
62971+{
62972+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
62973+ return;
62974+}
62975+
62976+void
62977+gr_handle_vm86(void)
62978+{
62979+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
62980+ return;
62981+}
62982diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
62983new file mode 100644
62984index 0000000..2131422
62985--- /dev/null
62986+++ b/grsecurity/grsec_mount.c
62987@@ -0,0 +1,62 @@
62988+#include <linux/kernel.h>
62989+#include <linux/sched.h>
62990+#include <linux/mount.h>
62991+#include <linux/grsecurity.h>
62992+#include <linux/grinternal.h>
62993+
62994+void
62995+gr_log_remount(const char *devname, const int retval)
62996+{
62997+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62998+ if (grsec_enable_mount && (retval >= 0))
62999+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
63000+#endif
63001+ return;
63002+}
63003+
63004+void
63005+gr_log_unmount(const char *devname, const int retval)
63006+{
63007+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63008+ if (grsec_enable_mount && (retval >= 0))
63009+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
63010+#endif
63011+ return;
63012+}
63013+
63014+void
63015+gr_log_mount(const char *from, const char *to, const int retval)
63016+{
63017+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63018+ if (grsec_enable_mount && (retval >= 0))
63019+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
63020+#endif
63021+ return;
63022+}
63023+
63024+int
63025+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
63026+{
63027+#ifdef CONFIG_GRKERNSEC_ROFS
63028+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
63029+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
63030+ return -EPERM;
63031+ } else
63032+ return 0;
63033+#endif
63034+ return 0;
63035+}
63036+
63037+int
63038+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
63039+{
63040+#ifdef CONFIG_GRKERNSEC_ROFS
63041+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
63042+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
63043+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
63044+ return -EPERM;
63045+ } else
63046+ return 0;
63047+#endif
63048+ return 0;
63049+}
63050diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
63051new file mode 100644
63052index 0000000..a3b12a0
63053--- /dev/null
63054+++ b/grsecurity/grsec_pax.c
63055@@ -0,0 +1,36 @@
63056+#include <linux/kernel.h>
63057+#include <linux/sched.h>
63058+#include <linux/mm.h>
63059+#include <linux/file.h>
63060+#include <linux/grinternal.h>
63061+#include <linux/grsecurity.h>
63062+
63063+void
63064+gr_log_textrel(struct vm_area_struct * vma)
63065+{
63066+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63067+ if (grsec_enable_audit_textrel)
63068+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
63069+#endif
63070+ return;
63071+}
63072+
63073+void
63074+gr_log_rwxmmap(struct file *file)
63075+{
63076+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63077+ if (grsec_enable_log_rwxmaps)
63078+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
63079+#endif
63080+ return;
63081+}
63082+
63083+void
63084+gr_log_rwxmprotect(struct file *file)
63085+{
63086+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63087+ if (grsec_enable_log_rwxmaps)
63088+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
63089+#endif
63090+ return;
63091+}
63092diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
63093new file mode 100644
63094index 0000000..472c1d6
63095--- /dev/null
63096+++ b/grsecurity/grsec_ptrace.c
63097@@ -0,0 +1,14 @@
63098+#include <linux/kernel.h>
63099+#include <linux/sched.h>
63100+#include <linux/grinternal.h>
63101+#include <linux/grsecurity.h>
63102+
63103+void
63104+gr_audit_ptrace(struct task_struct *task)
63105+{
63106+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63107+ if (grsec_enable_audit_ptrace)
63108+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
63109+#endif
63110+ return;
63111+}
63112diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
63113new file mode 100644
63114index 0000000..dc73fe9
63115--- /dev/null
63116+++ b/grsecurity/grsec_sig.c
63117@@ -0,0 +1,205 @@
63118+#include <linux/kernel.h>
63119+#include <linux/sched.h>
63120+#include <linux/delay.h>
63121+#include <linux/grsecurity.h>
63122+#include <linux/grinternal.h>
63123+#include <linux/hardirq.h>
63124+
63125+char *signames[] = {
63126+ [SIGSEGV] = "Segmentation fault",
63127+ [SIGILL] = "Illegal instruction",
63128+ [SIGABRT] = "Abort",
63129+ [SIGBUS] = "Invalid alignment/Bus error"
63130+};
63131+
63132+void
63133+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
63134+{
63135+#ifdef CONFIG_GRKERNSEC_SIGNAL
63136+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
63137+ (sig == SIGABRT) || (sig == SIGBUS))) {
63138+ if (t->pid == current->pid) {
63139+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
63140+ } else {
63141+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
63142+ }
63143+ }
63144+#endif
63145+ return;
63146+}
63147+
63148+int
63149+gr_handle_signal(const struct task_struct *p, const int sig)
63150+{
63151+#ifdef CONFIG_GRKERNSEC
63152+ if (current->pid > 1 && gr_check_protected_task(p)) {
63153+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
63154+ return -EPERM;
63155+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
63156+ return -EPERM;
63157+ }
63158+#endif
63159+ return 0;
63160+}
63161+
63162+#ifdef CONFIG_GRKERNSEC
63163+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
63164+
63165+int gr_fake_force_sig(int sig, struct task_struct *t)
63166+{
63167+ unsigned long int flags;
63168+ int ret, blocked, ignored;
63169+ struct k_sigaction *action;
63170+
63171+ spin_lock_irqsave(&t->sighand->siglock, flags);
63172+ action = &t->sighand->action[sig-1];
63173+ ignored = action->sa.sa_handler == SIG_IGN;
63174+ blocked = sigismember(&t->blocked, sig);
63175+ if (blocked || ignored) {
63176+ action->sa.sa_handler = SIG_DFL;
63177+ if (blocked) {
63178+ sigdelset(&t->blocked, sig);
63179+ recalc_sigpending_and_wake(t);
63180+ }
63181+ }
63182+ if (action->sa.sa_handler == SIG_DFL)
63183+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
63184+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
63185+
63186+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
63187+
63188+ return ret;
63189+}
63190+#endif
63191+
63192+#ifdef CONFIG_GRKERNSEC_BRUTE
63193+#define GR_USER_BAN_TIME (15 * 60)
63194+
63195+static int __get_dumpable(unsigned long mm_flags)
63196+{
63197+ int ret;
63198+
63199+ ret = mm_flags & MMF_DUMPABLE_MASK;
63200+ return (ret >= 2) ? 2 : ret;
63201+}
63202+#endif
63203+
63204+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
63205+{
63206+#ifdef CONFIG_GRKERNSEC_BRUTE
63207+ uid_t uid = 0;
63208+
63209+ if (!grsec_enable_brute)
63210+ return;
63211+
63212+ rcu_read_lock();
63213+ read_lock(&tasklist_lock);
63214+ read_lock(&grsec_exec_file_lock);
63215+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
63216+ p->real_parent->brute = 1;
63217+ else {
63218+ const struct cred *cred = __task_cred(p), *cred2;
63219+ struct task_struct *tsk, *tsk2;
63220+
63221+ if (!__get_dumpable(mm_flags) && cred->uid) {
63222+ struct user_struct *user;
63223+
63224+ uid = cred->uid;
63225+
63226+ /* this is put upon execution past expiration */
63227+ user = find_user(uid);
63228+ if (user == NULL)
63229+ goto unlock;
63230+ user->banned = 1;
63231+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
63232+ if (user->ban_expires == ~0UL)
63233+ user->ban_expires--;
63234+
63235+ do_each_thread(tsk2, tsk) {
63236+ cred2 = __task_cred(tsk);
63237+ if (tsk != p && cred2->uid == uid)
63238+ gr_fake_force_sig(SIGKILL, tsk);
63239+ } while_each_thread(tsk2, tsk);
63240+ }
63241+ }
63242+unlock:
63243+ read_unlock(&grsec_exec_file_lock);
63244+ read_unlock(&tasklist_lock);
63245+ rcu_read_unlock();
63246+
63247+ if (uid)
63248+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
63249+#endif
63250+ return;
63251+}
63252+
63253+void gr_handle_brute_check(void)
63254+{
63255+#ifdef CONFIG_GRKERNSEC_BRUTE
63256+ if (current->brute)
63257+ msleep(30 * 1000);
63258+#endif
63259+ return;
63260+}
63261+
63262+void gr_handle_kernel_exploit(void)
63263+{
63264+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
63265+ const struct cred *cred;
63266+ struct task_struct *tsk, *tsk2;
63267+ struct user_struct *user;
63268+ uid_t uid;
63269+
63270+ if (in_irq() || in_serving_softirq() || in_nmi())
63271+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
63272+
63273+ uid = current_uid();
63274+
63275+ if (uid == 0)
63276+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
63277+ else {
63278+ /* kill all the processes of this user, hold a reference
63279+ to their creds struct, and prevent them from creating
63280+ another process until system reset
63281+ */
63282+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
63283+ /* we intentionally leak this ref */
63284+ user = get_uid(current->cred->user);
63285+ if (user) {
63286+ user->banned = 1;
63287+ user->ban_expires = ~0UL;
63288+ }
63289+
63290+ read_lock(&tasklist_lock);
63291+ do_each_thread(tsk2, tsk) {
63292+ cred = __task_cred(tsk);
63293+ if (cred->uid == uid)
63294+ gr_fake_force_sig(SIGKILL, tsk);
63295+ } while_each_thread(tsk2, tsk);
63296+ read_unlock(&tasklist_lock);
63297+ }
63298+#endif
63299+}
63300+
63301+int __gr_process_user_ban(struct user_struct *user)
63302+{
63303+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63304+ if (unlikely(user->banned)) {
63305+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
63306+ user->banned = 0;
63307+ user->ban_expires = 0;
63308+ free_uid(user);
63309+ } else
63310+ return -EPERM;
63311+ }
63312+#endif
63313+ return 0;
63314+}
63315+
63316+int gr_process_user_ban(void)
63317+{
63318+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63319+ return __gr_process_user_ban(current->cred->user);
63320+#endif
63321+ return 0;
63322+}
63323diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
63324new file mode 100644
63325index 0000000..7512ea9
63326--- /dev/null
63327+++ b/grsecurity/grsec_sock.c
63328@@ -0,0 +1,275 @@
63329+#include <linux/kernel.h>
63330+#include <linux/module.h>
63331+#include <linux/sched.h>
63332+#include <linux/file.h>
63333+#include <linux/net.h>
63334+#include <linux/in.h>
63335+#include <linux/ip.h>
63336+#include <net/sock.h>
63337+#include <net/inet_sock.h>
63338+#include <linux/grsecurity.h>
63339+#include <linux/grinternal.h>
63340+#include <linux/gracl.h>
63341+
63342+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
63343+EXPORT_SYMBOL(gr_cap_rtnetlink);
63344+
63345+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
63346+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
63347+
63348+EXPORT_SYMBOL(gr_search_udp_recvmsg);
63349+EXPORT_SYMBOL(gr_search_udp_sendmsg);
63350+
63351+#ifdef CONFIG_UNIX_MODULE
63352+EXPORT_SYMBOL(gr_acl_handle_unix);
63353+EXPORT_SYMBOL(gr_acl_handle_mknod);
63354+EXPORT_SYMBOL(gr_handle_chroot_unix);
63355+EXPORT_SYMBOL(gr_handle_create);
63356+#endif
63357+
63358+#ifdef CONFIG_GRKERNSEC
63359+#define gr_conn_table_size 32749
63360+struct conn_table_entry {
63361+ struct conn_table_entry *next;
63362+ struct signal_struct *sig;
63363+};
63364+
63365+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
63366+DEFINE_SPINLOCK(gr_conn_table_lock);
63367+
63368+extern const char * gr_socktype_to_name(unsigned char type);
63369+extern const char * gr_proto_to_name(unsigned char proto);
63370+extern const char * gr_sockfamily_to_name(unsigned char family);
63371+
63372+static __inline__ int
63373+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
63374+{
63375+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
63376+}
63377+
63378+static __inline__ int
63379+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
63380+ __u16 sport, __u16 dport)
63381+{
63382+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
63383+ sig->gr_sport == sport && sig->gr_dport == dport))
63384+ return 1;
63385+ else
63386+ return 0;
63387+}
63388+
63389+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
63390+{
63391+ struct conn_table_entry **match;
63392+ unsigned int index;
63393+
63394+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63395+ sig->gr_sport, sig->gr_dport,
63396+ gr_conn_table_size);
63397+
63398+ newent->sig = sig;
63399+
63400+ match = &gr_conn_table[index];
63401+ newent->next = *match;
63402+ *match = newent;
63403+
63404+ return;
63405+}
63406+
63407+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
63408+{
63409+ struct conn_table_entry *match, *last = NULL;
63410+ unsigned int index;
63411+
63412+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63413+ sig->gr_sport, sig->gr_dport,
63414+ gr_conn_table_size);
63415+
63416+ match = gr_conn_table[index];
63417+ while (match && !conn_match(match->sig,
63418+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
63419+ sig->gr_dport)) {
63420+ last = match;
63421+ match = match->next;
63422+ }
63423+
63424+ if (match) {
63425+ if (last)
63426+ last->next = match->next;
63427+ else
63428+ gr_conn_table[index] = NULL;
63429+ kfree(match);
63430+ }
63431+
63432+ return;
63433+}
63434+
63435+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
63436+ __u16 sport, __u16 dport)
63437+{
63438+ struct conn_table_entry *match;
63439+ unsigned int index;
63440+
63441+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
63442+
63443+ match = gr_conn_table[index];
63444+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
63445+ match = match->next;
63446+
63447+ if (match)
63448+ return match->sig;
63449+ else
63450+ return NULL;
63451+}
63452+
63453+#endif
63454+
63455+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
63456+{
63457+#ifdef CONFIG_GRKERNSEC
63458+ struct signal_struct *sig = task->signal;
63459+ struct conn_table_entry *newent;
63460+
63461+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
63462+ if (newent == NULL)
63463+ return;
63464+ /* no bh lock needed since we are called with bh disabled */
63465+ spin_lock(&gr_conn_table_lock);
63466+ gr_del_task_from_ip_table_nolock(sig);
63467+ sig->gr_saddr = inet->rcv_saddr;
63468+ sig->gr_daddr = inet->daddr;
63469+ sig->gr_sport = inet->sport;
63470+ sig->gr_dport = inet->dport;
63471+ gr_add_to_task_ip_table_nolock(sig, newent);
63472+ spin_unlock(&gr_conn_table_lock);
63473+#endif
63474+ return;
63475+}
63476+
63477+void gr_del_task_from_ip_table(struct task_struct *task)
63478+{
63479+#ifdef CONFIG_GRKERNSEC
63480+ spin_lock_bh(&gr_conn_table_lock);
63481+ gr_del_task_from_ip_table_nolock(task->signal);
63482+ spin_unlock_bh(&gr_conn_table_lock);
63483+#endif
63484+ return;
63485+}
63486+
63487+void
63488+gr_attach_curr_ip(const struct sock *sk)
63489+{
63490+#ifdef CONFIG_GRKERNSEC
63491+ struct signal_struct *p, *set;
63492+ const struct inet_sock *inet = inet_sk(sk);
63493+
63494+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
63495+ return;
63496+
63497+ set = current->signal;
63498+
63499+ spin_lock_bh(&gr_conn_table_lock);
63500+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
63501+ inet->dport, inet->sport);
63502+ if (unlikely(p != NULL)) {
63503+ set->curr_ip = p->curr_ip;
63504+ set->used_accept = 1;
63505+ gr_del_task_from_ip_table_nolock(p);
63506+ spin_unlock_bh(&gr_conn_table_lock);
63507+ return;
63508+ }
63509+ spin_unlock_bh(&gr_conn_table_lock);
63510+
63511+ set->curr_ip = inet->daddr;
63512+ set->used_accept = 1;
63513+#endif
63514+ return;
63515+}
63516+
63517+int
63518+gr_handle_sock_all(const int family, const int type, const int protocol)
63519+{
63520+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63521+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
63522+ (family != AF_UNIX)) {
63523+ if (family == AF_INET)
63524+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
63525+ else
63526+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
63527+ return -EACCES;
63528+ }
63529+#endif
63530+ return 0;
63531+}
63532+
63533+int
63534+gr_handle_sock_server(const struct sockaddr *sck)
63535+{
63536+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63537+ if (grsec_enable_socket_server &&
63538+ in_group_p(grsec_socket_server_gid) &&
63539+ sck && (sck->sa_family != AF_UNIX) &&
63540+ (sck->sa_family != AF_LOCAL)) {
63541+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63542+ return -EACCES;
63543+ }
63544+#endif
63545+ return 0;
63546+}
63547+
63548+int
63549+gr_handle_sock_server_other(const struct sock *sck)
63550+{
63551+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63552+ if (grsec_enable_socket_server &&
63553+ in_group_p(grsec_socket_server_gid) &&
63554+ sck && (sck->sk_family != AF_UNIX) &&
63555+ (sck->sk_family != AF_LOCAL)) {
63556+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63557+ return -EACCES;
63558+ }
63559+#endif
63560+ return 0;
63561+}
63562+
63563+int
63564+gr_handle_sock_client(const struct sockaddr *sck)
63565+{
63566+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63567+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
63568+ sck && (sck->sa_family != AF_UNIX) &&
63569+ (sck->sa_family != AF_LOCAL)) {
63570+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
63571+ return -EACCES;
63572+ }
63573+#endif
63574+ return 0;
63575+}
63576+
63577+kernel_cap_t
63578+gr_cap_rtnetlink(struct sock *sock)
63579+{
63580+#ifdef CONFIG_GRKERNSEC
63581+ if (!gr_acl_is_enabled())
63582+ return current_cap();
63583+ else if (sock->sk_protocol == NETLINK_ISCSI &&
63584+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
63585+ gr_is_capable(CAP_SYS_ADMIN))
63586+ return current_cap();
63587+ else if (sock->sk_protocol == NETLINK_AUDIT &&
63588+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
63589+ gr_is_capable(CAP_AUDIT_WRITE) &&
63590+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
63591+ gr_is_capable(CAP_AUDIT_CONTROL))
63592+ return current_cap();
63593+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
63594+ ((sock->sk_protocol == NETLINK_ROUTE) ?
63595+ gr_is_capable_nolog(CAP_NET_ADMIN) :
63596+ gr_is_capable(CAP_NET_ADMIN)))
63597+ return current_cap();
63598+ else
63599+ return __cap_empty_set;
63600+#else
63601+ return current_cap();
63602+#endif
63603+}
63604diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
63605new file mode 100644
63606index 0000000..2753505
63607--- /dev/null
63608+++ b/grsecurity/grsec_sysctl.c
63609@@ -0,0 +1,479 @@
63610+#include <linux/kernel.h>
63611+#include <linux/sched.h>
63612+#include <linux/sysctl.h>
63613+#include <linux/grsecurity.h>
63614+#include <linux/grinternal.h>
63615+
63616+int
63617+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
63618+{
63619+#ifdef CONFIG_GRKERNSEC_SYSCTL
63620+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
63621+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
63622+ return -EACCES;
63623+ }
63624+#endif
63625+ return 0;
63626+}
63627+
63628+#ifdef CONFIG_GRKERNSEC_ROFS
63629+static int __maybe_unused one = 1;
63630+#endif
63631+
63632+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
63633+ctl_table grsecurity_table[] = {
63634+#ifdef CONFIG_GRKERNSEC_SYSCTL
63635+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
63636+#ifdef CONFIG_GRKERNSEC_IO
63637+ {
63638+ .ctl_name = CTL_UNNUMBERED,
63639+ .procname = "disable_priv_io",
63640+ .data = &grsec_disable_privio,
63641+ .maxlen = sizeof(int),
63642+ .mode = 0600,
63643+ .proc_handler = &proc_dointvec,
63644+ },
63645+#endif
63646+#endif
63647+#ifdef CONFIG_GRKERNSEC_LINK
63648+ {
63649+ .ctl_name = CTL_UNNUMBERED,
63650+ .procname = "linking_restrictions",
63651+ .data = &grsec_enable_link,
63652+ .maxlen = sizeof(int),
63653+ .mode = 0600,
63654+ .proc_handler = &proc_dointvec,
63655+ },
63656+#endif
63657+#ifdef CONFIG_GRKERNSEC_BRUTE
63658+ {
63659+ .ctl_name = CTL_UNNUMBERED,
63660+ .procname = "deter_bruteforce",
63661+ .data = &grsec_enable_brute,
63662+ .maxlen = sizeof(int),
63663+ .mode = 0600,
63664+ .proc_handler = &proc_dointvec,
63665+ },
63666+#endif
63667+#ifdef CONFIG_GRKERNSEC_FIFO
63668+ {
63669+ .ctl_name = CTL_UNNUMBERED,
63670+ .procname = "fifo_restrictions",
63671+ .data = &grsec_enable_fifo,
63672+ .maxlen = sizeof(int),
63673+ .mode = 0600,
63674+ .proc_handler = &proc_dointvec,
63675+ },
63676+#endif
63677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63678+ {
63679+ .ctl_name = CTL_UNNUMBERED,
63680+ .procname = "ip_blackhole",
63681+ .data = &grsec_enable_blackhole,
63682+ .maxlen = sizeof(int),
63683+ .mode = 0600,
63684+ .proc_handler = &proc_dointvec,
63685+ },
63686+ {
63687+ .ctl_name = CTL_UNNUMBERED,
63688+ .procname = "lastack_retries",
63689+ .data = &grsec_lastack_retries,
63690+ .maxlen = sizeof(int),
63691+ .mode = 0600,
63692+ .proc_handler = &proc_dointvec,
63693+ },
63694+#endif
63695+#ifdef CONFIG_GRKERNSEC_EXECLOG
63696+ {
63697+ .ctl_name = CTL_UNNUMBERED,
63698+ .procname = "exec_logging",
63699+ .data = &grsec_enable_execlog,
63700+ .maxlen = sizeof(int),
63701+ .mode = 0600,
63702+ .proc_handler = &proc_dointvec,
63703+ },
63704+#endif
63705+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63706+ {
63707+ .ctl_name = CTL_UNNUMBERED,
63708+ .procname = "rwxmap_logging",
63709+ .data = &grsec_enable_log_rwxmaps,
63710+ .maxlen = sizeof(int),
63711+ .mode = 0600,
63712+ .proc_handler = &proc_dointvec,
63713+ },
63714+#endif
63715+#ifdef CONFIG_GRKERNSEC_SIGNAL
63716+ {
63717+ .ctl_name = CTL_UNNUMBERED,
63718+ .procname = "signal_logging",
63719+ .data = &grsec_enable_signal,
63720+ .maxlen = sizeof(int),
63721+ .mode = 0600,
63722+ .proc_handler = &proc_dointvec,
63723+ },
63724+#endif
63725+#ifdef CONFIG_GRKERNSEC_FORKFAIL
63726+ {
63727+ .ctl_name = CTL_UNNUMBERED,
63728+ .procname = "forkfail_logging",
63729+ .data = &grsec_enable_forkfail,
63730+ .maxlen = sizeof(int),
63731+ .mode = 0600,
63732+ .proc_handler = &proc_dointvec,
63733+ },
63734+#endif
63735+#ifdef CONFIG_GRKERNSEC_TIME
63736+ {
63737+ .ctl_name = CTL_UNNUMBERED,
63738+ .procname = "timechange_logging",
63739+ .data = &grsec_enable_time,
63740+ .maxlen = sizeof(int),
63741+ .mode = 0600,
63742+ .proc_handler = &proc_dointvec,
63743+ },
63744+#endif
63745+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63746+ {
63747+ .ctl_name = CTL_UNNUMBERED,
63748+ .procname = "chroot_deny_shmat",
63749+ .data = &grsec_enable_chroot_shmat,
63750+ .maxlen = sizeof(int),
63751+ .mode = 0600,
63752+ .proc_handler = &proc_dointvec,
63753+ },
63754+#endif
63755+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63756+ {
63757+ .ctl_name = CTL_UNNUMBERED,
63758+ .procname = "chroot_deny_unix",
63759+ .data = &grsec_enable_chroot_unix,
63760+ .maxlen = sizeof(int),
63761+ .mode = 0600,
63762+ .proc_handler = &proc_dointvec,
63763+ },
63764+#endif
63765+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63766+ {
63767+ .ctl_name = CTL_UNNUMBERED,
63768+ .procname = "chroot_deny_mount",
63769+ .data = &grsec_enable_chroot_mount,
63770+ .maxlen = sizeof(int),
63771+ .mode = 0600,
63772+ .proc_handler = &proc_dointvec,
63773+ },
63774+#endif
63775+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63776+ {
63777+ .ctl_name = CTL_UNNUMBERED,
63778+ .procname = "chroot_deny_fchdir",
63779+ .data = &grsec_enable_chroot_fchdir,
63780+ .maxlen = sizeof(int),
63781+ .mode = 0600,
63782+ .proc_handler = &proc_dointvec,
63783+ },
63784+#endif
63785+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63786+ {
63787+ .ctl_name = CTL_UNNUMBERED,
63788+ .procname = "chroot_deny_chroot",
63789+ .data = &grsec_enable_chroot_double,
63790+ .maxlen = sizeof(int),
63791+ .mode = 0600,
63792+ .proc_handler = &proc_dointvec,
63793+ },
63794+#endif
63795+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63796+ {
63797+ .ctl_name = CTL_UNNUMBERED,
63798+ .procname = "chroot_deny_pivot",
63799+ .data = &grsec_enable_chroot_pivot,
63800+ .maxlen = sizeof(int),
63801+ .mode = 0600,
63802+ .proc_handler = &proc_dointvec,
63803+ },
63804+#endif
63805+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63806+ {
63807+ .ctl_name = CTL_UNNUMBERED,
63808+ .procname = "chroot_enforce_chdir",
63809+ .data = &grsec_enable_chroot_chdir,
63810+ .maxlen = sizeof(int),
63811+ .mode = 0600,
63812+ .proc_handler = &proc_dointvec,
63813+ },
63814+#endif
63815+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63816+ {
63817+ .ctl_name = CTL_UNNUMBERED,
63818+ .procname = "chroot_deny_chmod",
63819+ .data = &grsec_enable_chroot_chmod,
63820+ .maxlen = sizeof(int),
63821+ .mode = 0600,
63822+ .proc_handler = &proc_dointvec,
63823+ },
63824+#endif
63825+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63826+ {
63827+ .ctl_name = CTL_UNNUMBERED,
63828+ .procname = "chroot_deny_mknod",
63829+ .data = &grsec_enable_chroot_mknod,
63830+ .maxlen = sizeof(int),
63831+ .mode = 0600,
63832+ .proc_handler = &proc_dointvec,
63833+ },
63834+#endif
63835+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63836+ {
63837+ .ctl_name = CTL_UNNUMBERED,
63838+ .procname = "chroot_restrict_nice",
63839+ .data = &grsec_enable_chroot_nice,
63840+ .maxlen = sizeof(int),
63841+ .mode = 0600,
63842+ .proc_handler = &proc_dointvec,
63843+ },
63844+#endif
63845+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63846+ {
63847+ .ctl_name = CTL_UNNUMBERED,
63848+ .procname = "chroot_execlog",
63849+ .data = &grsec_enable_chroot_execlog,
63850+ .maxlen = sizeof(int),
63851+ .mode = 0600,
63852+ .proc_handler = &proc_dointvec,
63853+ },
63854+#endif
63855+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63856+ {
63857+ .ctl_name = CTL_UNNUMBERED,
63858+ .procname = "chroot_caps",
63859+ .data = &grsec_enable_chroot_caps,
63860+ .maxlen = sizeof(int),
63861+ .mode = 0600,
63862+ .proc_handler = &proc_dointvec,
63863+ },
63864+#endif
63865+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63866+ {
63867+ .ctl_name = CTL_UNNUMBERED,
63868+ .procname = "chroot_deny_sysctl",
63869+ .data = &grsec_enable_chroot_sysctl,
63870+ .maxlen = sizeof(int),
63871+ .mode = 0600,
63872+ .proc_handler = &proc_dointvec,
63873+ },
63874+#endif
63875+#ifdef CONFIG_GRKERNSEC_TPE
63876+ {
63877+ .ctl_name = CTL_UNNUMBERED,
63878+ .procname = "tpe",
63879+ .data = &grsec_enable_tpe,
63880+ .maxlen = sizeof(int),
63881+ .mode = 0600,
63882+ .proc_handler = &proc_dointvec,
63883+ },
63884+ {
63885+ .ctl_name = CTL_UNNUMBERED,
63886+ .procname = "tpe_gid",
63887+ .data = &grsec_tpe_gid,
63888+ .maxlen = sizeof(int),
63889+ .mode = 0600,
63890+ .proc_handler = &proc_dointvec,
63891+ },
63892+#endif
63893+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63894+ {
63895+ .ctl_name = CTL_UNNUMBERED,
63896+ .procname = "tpe_invert",
63897+ .data = &grsec_enable_tpe_invert,
63898+ .maxlen = sizeof(int),
63899+ .mode = 0600,
63900+ .proc_handler = &proc_dointvec,
63901+ },
63902+#endif
63903+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63904+ {
63905+ .ctl_name = CTL_UNNUMBERED,
63906+ .procname = "tpe_restrict_all",
63907+ .data = &grsec_enable_tpe_all,
63908+ .maxlen = sizeof(int),
63909+ .mode = 0600,
63910+ .proc_handler = &proc_dointvec,
63911+ },
63912+#endif
63913+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63914+ {
63915+ .ctl_name = CTL_UNNUMBERED,
63916+ .procname = "socket_all",
63917+ .data = &grsec_enable_socket_all,
63918+ .maxlen = sizeof(int),
63919+ .mode = 0600,
63920+ .proc_handler = &proc_dointvec,
63921+ },
63922+ {
63923+ .ctl_name = CTL_UNNUMBERED,
63924+ .procname = "socket_all_gid",
63925+ .data = &grsec_socket_all_gid,
63926+ .maxlen = sizeof(int),
63927+ .mode = 0600,
63928+ .proc_handler = &proc_dointvec,
63929+ },
63930+#endif
63931+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63932+ {
63933+ .ctl_name = CTL_UNNUMBERED,
63934+ .procname = "socket_client",
63935+ .data = &grsec_enable_socket_client,
63936+ .maxlen = sizeof(int),
63937+ .mode = 0600,
63938+ .proc_handler = &proc_dointvec,
63939+ },
63940+ {
63941+ .ctl_name = CTL_UNNUMBERED,
63942+ .procname = "socket_client_gid",
63943+ .data = &grsec_socket_client_gid,
63944+ .maxlen = sizeof(int),
63945+ .mode = 0600,
63946+ .proc_handler = &proc_dointvec,
63947+ },
63948+#endif
63949+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63950+ {
63951+ .ctl_name = CTL_UNNUMBERED,
63952+ .procname = "socket_server",
63953+ .data = &grsec_enable_socket_server,
63954+ .maxlen = sizeof(int),
63955+ .mode = 0600,
63956+ .proc_handler = &proc_dointvec,
63957+ },
63958+ {
63959+ .ctl_name = CTL_UNNUMBERED,
63960+ .procname = "socket_server_gid",
63961+ .data = &grsec_socket_server_gid,
63962+ .maxlen = sizeof(int),
63963+ .mode = 0600,
63964+ .proc_handler = &proc_dointvec,
63965+ },
63966+#endif
63967+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
63968+ {
63969+ .ctl_name = CTL_UNNUMBERED,
63970+ .procname = "audit_group",
63971+ .data = &grsec_enable_group,
63972+ .maxlen = sizeof(int),
63973+ .mode = 0600,
63974+ .proc_handler = &proc_dointvec,
63975+ },
63976+ {
63977+ .ctl_name = CTL_UNNUMBERED,
63978+ .procname = "audit_gid",
63979+ .data = &grsec_audit_gid,
63980+ .maxlen = sizeof(int),
63981+ .mode = 0600,
63982+ .proc_handler = &proc_dointvec,
63983+ },
63984+#endif
63985+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63986+ {
63987+ .ctl_name = CTL_UNNUMBERED,
63988+ .procname = "audit_chdir",
63989+ .data = &grsec_enable_chdir,
63990+ .maxlen = sizeof(int),
63991+ .mode = 0600,
63992+ .proc_handler = &proc_dointvec,
63993+ },
63994+#endif
63995+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63996+ {
63997+ .ctl_name = CTL_UNNUMBERED,
63998+ .procname = "audit_mount",
63999+ .data = &grsec_enable_mount,
64000+ .maxlen = sizeof(int),
64001+ .mode = 0600,
64002+ .proc_handler = &proc_dointvec,
64003+ },
64004+#endif
64005+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64006+ {
64007+ .ctl_name = CTL_UNNUMBERED,
64008+ .procname = "audit_textrel",
64009+ .data = &grsec_enable_audit_textrel,
64010+ .maxlen = sizeof(int),
64011+ .mode = 0600,
64012+ .proc_handler = &proc_dointvec,
64013+ },
64014+#endif
64015+#ifdef CONFIG_GRKERNSEC_DMESG
64016+ {
64017+ .ctl_name = CTL_UNNUMBERED,
64018+ .procname = "dmesg",
64019+ .data = &grsec_enable_dmesg,
64020+ .maxlen = sizeof(int),
64021+ .mode = 0600,
64022+ .proc_handler = &proc_dointvec,
64023+ },
64024+#endif
64025+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64026+ {
64027+ .ctl_name = CTL_UNNUMBERED,
64028+ .procname = "chroot_findtask",
64029+ .data = &grsec_enable_chroot_findtask,
64030+ .maxlen = sizeof(int),
64031+ .mode = 0600,
64032+ .proc_handler = &proc_dointvec,
64033+ },
64034+#endif
64035+#ifdef CONFIG_GRKERNSEC_RESLOG
64036+ {
64037+ .ctl_name = CTL_UNNUMBERED,
64038+ .procname = "resource_logging",
64039+ .data = &grsec_resource_logging,
64040+ .maxlen = sizeof(int),
64041+ .mode = 0600,
64042+ .proc_handler = &proc_dointvec,
64043+ },
64044+#endif
64045+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64046+ {
64047+ .ctl_name = CTL_UNNUMBERED,
64048+ .procname = "audit_ptrace",
64049+ .data = &grsec_enable_audit_ptrace,
64050+ .maxlen = sizeof(int),
64051+ .mode = 0600,
64052+ .proc_handler = &proc_dointvec,
64053+ },
64054+#endif
64055+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64056+ {
64057+ .ctl_name = CTL_UNNUMBERED,
64058+ .procname = "harden_ptrace",
64059+ .data = &grsec_enable_harden_ptrace,
64060+ .maxlen = sizeof(int),
64061+ .mode = 0600,
64062+ .proc_handler = &proc_dointvec,
64063+ },
64064+#endif
64065+ {
64066+ .ctl_name = CTL_UNNUMBERED,
64067+ .procname = "grsec_lock",
64068+ .data = &grsec_lock,
64069+ .maxlen = sizeof(int),
64070+ .mode = 0600,
64071+ .proc_handler = &proc_dointvec,
64072+ },
64073+#endif
64074+#ifdef CONFIG_GRKERNSEC_ROFS
64075+ {
64076+ .ctl_name = CTL_UNNUMBERED,
64077+ .procname = "romount_protect",
64078+ .data = &grsec_enable_rofs,
64079+ .maxlen = sizeof(int),
64080+ .mode = 0600,
64081+ .proc_handler = &proc_dointvec_minmax,
64082+ .extra1 = &one,
64083+ .extra2 = &one,
64084+ },
64085+#endif
64086+ { .ctl_name = 0 }
64087+};
64088+#endif
64089diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
64090new file mode 100644
64091index 0000000..0dc13c3
64092--- /dev/null
64093+++ b/grsecurity/grsec_time.c
64094@@ -0,0 +1,16 @@
64095+#include <linux/kernel.h>
64096+#include <linux/sched.h>
64097+#include <linux/grinternal.h>
64098+#include <linux/module.h>
64099+
64100+void
64101+gr_log_timechange(void)
64102+{
64103+#ifdef CONFIG_GRKERNSEC_TIME
64104+ if (grsec_enable_time)
64105+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
64106+#endif
64107+ return;
64108+}
64109+
64110+EXPORT_SYMBOL(gr_log_timechange);
64111diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
64112new file mode 100644
64113index 0000000..4a78774
64114--- /dev/null
64115+++ b/grsecurity/grsec_tpe.c
64116@@ -0,0 +1,39 @@
64117+#include <linux/kernel.h>
64118+#include <linux/sched.h>
64119+#include <linux/file.h>
64120+#include <linux/fs.h>
64121+#include <linux/grinternal.h>
64122+
64123+extern int gr_acl_tpe_check(void);
64124+
64125+int
64126+gr_tpe_allow(const struct file *file)
64127+{
64128+#ifdef CONFIG_GRKERNSEC
64129+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
64130+ const struct cred *cred = current_cred();
64131+
64132+ if (cred->uid && ((grsec_enable_tpe &&
64133+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64134+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
64135+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
64136+#else
64137+ in_group_p(grsec_tpe_gid)
64138+#endif
64139+ ) || gr_acl_tpe_check()) &&
64140+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
64141+ (inode->i_mode & S_IWOTH))))) {
64142+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64143+ return 0;
64144+ }
64145+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64146+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
64147+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
64148+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
64149+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64150+ return 0;
64151+ }
64152+#endif
64153+#endif
64154+ return 1;
64155+}
64156diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
64157new file mode 100644
64158index 0000000..9f7b1ac
64159--- /dev/null
64160+++ b/grsecurity/grsum.c
64161@@ -0,0 +1,61 @@
64162+#include <linux/err.h>
64163+#include <linux/kernel.h>
64164+#include <linux/sched.h>
64165+#include <linux/mm.h>
64166+#include <linux/scatterlist.h>
64167+#include <linux/crypto.h>
64168+#include <linux/gracl.h>
64169+
64170+
64171+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
64172+#error "crypto and sha256 must be built into the kernel"
64173+#endif
64174+
64175+int
64176+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
64177+{
64178+ char *p;
64179+ struct crypto_hash *tfm;
64180+ struct hash_desc desc;
64181+ struct scatterlist sg;
64182+ unsigned char temp_sum[GR_SHA_LEN];
64183+ volatile int retval = 0;
64184+ volatile int dummy = 0;
64185+ unsigned int i;
64186+
64187+ sg_init_table(&sg, 1);
64188+
64189+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
64190+ if (IS_ERR(tfm)) {
64191+ /* should never happen, since sha256 should be built in */
64192+ return 1;
64193+ }
64194+
64195+ desc.tfm = tfm;
64196+ desc.flags = 0;
64197+
64198+ crypto_hash_init(&desc);
64199+
64200+ p = salt;
64201+ sg_set_buf(&sg, p, GR_SALT_LEN);
64202+ crypto_hash_update(&desc, &sg, sg.length);
64203+
64204+ p = entry->pw;
64205+ sg_set_buf(&sg, p, strlen(p));
64206+
64207+ crypto_hash_update(&desc, &sg, sg.length);
64208+
64209+ crypto_hash_final(&desc, temp_sum);
64210+
64211+ memset(entry->pw, 0, GR_PW_LEN);
64212+
64213+ for (i = 0; i < GR_SHA_LEN; i++)
64214+ if (sum[i] != temp_sum[i])
64215+ retval = 1;
64216+ else
64217+ dummy = 1; // waste a cycle
64218+
64219+ crypto_free_hash(tfm);
64220+
64221+ return retval;
64222+}
64223diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
64224index 3cd9ccd..fe16d47 100644
64225--- a/include/acpi/acpi_bus.h
64226+++ b/include/acpi/acpi_bus.h
64227@@ -107,7 +107,7 @@ struct acpi_device_ops {
64228 acpi_op_bind bind;
64229 acpi_op_unbind unbind;
64230 acpi_op_notify notify;
64231-};
64232+} __no_const;
64233
64234 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
64235
64236diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
64237index f4906f6..71feb73 100644
64238--- a/include/acpi/acpi_drivers.h
64239+++ b/include/acpi/acpi_drivers.h
64240@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type);
64241 Dock Station
64242 -------------------------------------------------------------------------- */
64243 struct acpi_dock_ops {
64244- acpi_notify_handler handler;
64245- acpi_notify_handler uevent;
64246+ const acpi_notify_handler handler;
64247+ const acpi_notify_handler uevent;
64248 };
64249
64250 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
64251@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle handle);
64252 extern int register_dock_notifier(struct notifier_block *nb);
64253 extern void unregister_dock_notifier(struct notifier_block *nb);
64254 extern int register_hotplug_dock_device(acpi_handle handle,
64255- struct acpi_dock_ops *ops,
64256+ const struct acpi_dock_ops *ops,
64257 void *context);
64258 extern void unregister_hotplug_dock_device(acpi_handle handle);
64259 #else
64260@@ -144,7 +144,7 @@ static inline void unregister_dock_notifier(struct notifier_block *nb)
64261 {
64262 }
64263 static inline int register_hotplug_dock_device(acpi_handle handle,
64264- struct acpi_dock_ops *ops,
64265+ const struct acpi_dock_ops *ops,
64266 void *context)
64267 {
64268 return -ENODEV;
64269diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
64270index b7babf0..a9ac9fc 100644
64271--- a/include/asm-generic/atomic-long.h
64272+++ b/include/asm-generic/atomic-long.h
64273@@ -22,6 +22,12 @@
64274
64275 typedef atomic64_t atomic_long_t;
64276
64277+#ifdef CONFIG_PAX_REFCOUNT
64278+typedef atomic64_unchecked_t atomic_long_unchecked_t;
64279+#else
64280+typedef atomic64_t atomic_long_unchecked_t;
64281+#endif
64282+
64283 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
64284
64285 static inline long atomic_long_read(atomic_long_t *l)
64286@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64287 return (long)atomic64_read(v);
64288 }
64289
64290+#ifdef CONFIG_PAX_REFCOUNT
64291+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64292+{
64293+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64294+
64295+ return (long)atomic64_read_unchecked(v);
64296+}
64297+#endif
64298+
64299 static inline void atomic_long_set(atomic_long_t *l, long i)
64300 {
64301 atomic64_t *v = (atomic64_t *)l;
64302@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64303 atomic64_set(v, i);
64304 }
64305
64306+#ifdef CONFIG_PAX_REFCOUNT
64307+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64308+{
64309+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64310+
64311+ atomic64_set_unchecked(v, i);
64312+}
64313+#endif
64314+
64315 static inline void atomic_long_inc(atomic_long_t *l)
64316 {
64317 atomic64_t *v = (atomic64_t *)l;
64318@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64319 atomic64_inc(v);
64320 }
64321
64322+#ifdef CONFIG_PAX_REFCOUNT
64323+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64324+{
64325+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64326+
64327+ atomic64_inc_unchecked(v);
64328+}
64329+#endif
64330+
64331 static inline void atomic_long_dec(atomic_long_t *l)
64332 {
64333 atomic64_t *v = (atomic64_t *)l;
64334@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64335 atomic64_dec(v);
64336 }
64337
64338+#ifdef CONFIG_PAX_REFCOUNT
64339+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64340+{
64341+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64342+
64343+ atomic64_dec_unchecked(v);
64344+}
64345+#endif
64346+
64347 static inline void atomic_long_add(long i, atomic_long_t *l)
64348 {
64349 atomic64_t *v = (atomic64_t *)l;
64350@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64351 atomic64_add(i, v);
64352 }
64353
64354+#ifdef CONFIG_PAX_REFCOUNT
64355+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64356+{
64357+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64358+
64359+ atomic64_add_unchecked(i, v);
64360+}
64361+#endif
64362+
64363 static inline void atomic_long_sub(long i, atomic_long_t *l)
64364 {
64365 atomic64_t *v = (atomic64_t *)l;
64366@@ -115,6 +166,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64367 return (long)atomic64_inc_return(v);
64368 }
64369
64370+#ifdef CONFIG_PAX_REFCOUNT
64371+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64372+{
64373+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64374+
64375+ return (long)atomic64_inc_return_unchecked(v);
64376+}
64377+#endif
64378+
64379 static inline long atomic_long_dec_return(atomic_long_t *l)
64380 {
64381 atomic64_t *v = (atomic64_t *)l;
64382@@ -140,6 +200,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64383
64384 typedef atomic_t atomic_long_t;
64385
64386+#ifdef CONFIG_PAX_REFCOUNT
64387+typedef atomic_unchecked_t atomic_long_unchecked_t;
64388+#else
64389+typedef atomic_t atomic_long_unchecked_t;
64390+#endif
64391+
64392 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
64393 static inline long atomic_long_read(atomic_long_t *l)
64394 {
64395@@ -148,6 +214,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64396 return (long)atomic_read(v);
64397 }
64398
64399+#ifdef CONFIG_PAX_REFCOUNT
64400+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64401+{
64402+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64403+
64404+ return (long)atomic_read_unchecked(v);
64405+}
64406+#endif
64407+
64408 static inline void atomic_long_set(atomic_long_t *l, long i)
64409 {
64410 atomic_t *v = (atomic_t *)l;
64411@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64412 atomic_set(v, i);
64413 }
64414
64415+#ifdef CONFIG_PAX_REFCOUNT
64416+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64417+{
64418+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64419+
64420+ atomic_set_unchecked(v, i);
64421+}
64422+#endif
64423+
64424 static inline void atomic_long_inc(atomic_long_t *l)
64425 {
64426 atomic_t *v = (atomic_t *)l;
64427@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64428 atomic_inc(v);
64429 }
64430
64431+#ifdef CONFIG_PAX_REFCOUNT
64432+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64433+{
64434+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64435+
64436+ atomic_inc_unchecked(v);
64437+}
64438+#endif
64439+
64440 static inline void atomic_long_dec(atomic_long_t *l)
64441 {
64442 atomic_t *v = (atomic_t *)l;
64443@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64444 atomic_dec(v);
64445 }
64446
64447+#ifdef CONFIG_PAX_REFCOUNT
64448+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64449+{
64450+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64451+
64452+ atomic_dec_unchecked(v);
64453+}
64454+#endif
64455+
64456 static inline void atomic_long_add(long i, atomic_long_t *l)
64457 {
64458 atomic_t *v = (atomic_t *)l;
64459@@ -176,6 +278,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64460 atomic_add(i, v);
64461 }
64462
64463+#ifdef CONFIG_PAX_REFCOUNT
64464+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64465+{
64466+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64467+
64468+ atomic_add_unchecked(i, v);
64469+}
64470+#endif
64471+
64472 static inline void atomic_long_sub(long i, atomic_long_t *l)
64473 {
64474 atomic_t *v = (atomic_t *)l;
64475@@ -232,6 +343,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64476 return (long)atomic_inc_return(v);
64477 }
64478
64479+#ifdef CONFIG_PAX_REFCOUNT
64480+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64481+{
64482+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64483+
64484+ return (long)atomic_inc_return_unchecked(v);
64485+}
64486+#endif
64487+
64488 static inline long atomic_long_dec_return(atomic_long_t *l)
64489 {
64490 atomic_t *v = (atomic_t *)l;
64491@@ -255,4 +375,47 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64492
64493 #endif /* BITS_PER_LONG == 64 */
64494
64495+#ifdef CONFIG_PAX_REFCOUNT
64496+static inline void pax_refcount_needs_these_functions(void)
64497+{
64498+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
64499+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
64500+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
64501+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
64502+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
64503+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
64504+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
64505+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
64506+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
64507+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
64508+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
64509+
64510+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
64511+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
64512+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
64513+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
64514+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
64515+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
64516+}
64517+#else
64518+#define atomic_read_unchecked(v) atomic_read(v)
64519+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
64520+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
64521+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
64522+#define atomic_inc_unchecked(v) atomic_inc(v)
64523+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
64524+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
64525+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
64526+#define atomic_dec_unchecked(v) atomic_dec(v)
64527+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
64528+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
64529+
64530+#define atomic_long_read_unchecked(v) atomic_long_read(v)
64531+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
64532+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
64533+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
64534+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
64535+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
64536+#endif
64537+
64538 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
64539diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
64540index b18ce4f..2ee2843 100644
64541--- a/include/asm-generic/atomic64.h
64542+++ b/include/asm-generic/atomic64.h
64543@@ -16,6 +16,8 @@ typedef struct {
64544 long long counter;
64545 } atomic64_t;
64546
64547+typedef atomic64_t atomic64_unchecked_t;
64548+
64549 #define ATOMIC64_INIT(i) { (i) }
64550
64551 extern long long atomic64_read(const atomic64_t *v);
64552@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
64553 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
64554 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
64555
64556+#define atomic64_read_unchecked(v) atomic64_read(v)
64557+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
64558+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
64559+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
64560+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
64561+#define atomic64_inc_unchecked(v) atomic64_inc(v)
64562+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
64563+#define atomic64_dec_unchecked(v) atomic64_dec(v)
64564+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
64565+
64566 #endif /* _ASM_GENERIC_ATOMIC64_H */
64567diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
64568index d48ddf0..656a0ac 100644
64569--- a/include/asm-generic/bug.h
64570+++ b/include/asm-generic/bug.h
64571@@ -105,11 +105,11 @@ extern void warn_slowpath_null(const char *file, const int line);
64572
64573 #else /* !CONFIG_BUG */
64574 #ifndef HAVE_ARCH_BUG
64575-#define BUG() do {} while(0)
64576+#define BUG() do { for (;;) ; } while(0)
64577 #endif
64578
64579 #ifndef HAVE_ARCH_BUG_ON
64580-#define BUG_ON(condition) do { if (condition) ; } while(0)
64581+#define BUG_ON(condition) do { if (condition) for (;;) ; } while(0)
64582 #endif
64583
64584 #ifndef HAVE_ARCH_WARN_ON
64585diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
64586index 1bfcfe5..e04c5c9 100644
64587--- a/include/asm-generic/cache.h
64588+++ b/include/asm-generic/cache.h
64589@@ -6,7 +6,7 @@
64590 * cache lines need to provide their own cache.h.
64591 */
64592
64593-#define L1_CACHE_SHIFT 5
64594-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
64595+#define L1_CACHE_SHIFT 5UL
64596+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
64597
64598 #endif /* __ASM_GENERIC_CACHE_H */
64599diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
64600index 6920695..41038bc 100644
64601--- a/include/asm-generic/dma-mapping-common.h
64602+++ b/include/asm-generic/dma-mapping-common.h
64603@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
64604 enum dma_data_direction dir,
64605 struct dma_attrs *attrs)
64606 {
64607- struct dma_map_ops *ops = get_dma_ops(dev);
64608+ const struct dma_map_ops *ops = get_dma_ops(dev);
64609 dma_addr_t addr;
64610
64611 kmemcheck_mark_initialized(ptr, size);
64612@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
64613 enum dma_data_direction dir,
64614 struct dma_attrs *attrs)
64615 {
64616- struct dma_map_ops *ops = get_dma_ops(dev);
64617+ const struct dma_map_ops *ops = get_dma_ops(dev);
64618
64619 BUG_ON(!valid_dma_direction(dir));
64620 if (ops->unmap_page)
64621@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
64622 int nents, enum dma_data_direction dir,
64623 struct dma_attrs *attrs)
64624 {
64625- struct dma_map_ops *ops = get_dma_ops(dev);
64626+ const struct dma_map_ops *ops = get_dma_ops(dev);
64627 int i, ents;
64628 struct scatterlist *s;
64629
64630@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg
64631 int nents, enum dma_data_direction dir,
64632 struct dma_attrs *attrs)
64633 {
64634- struct dma_map_ops *ops = get_dma_ops(dev);
64635+ const struct dma_map_ops *ops = get_dma_ops(dev);
64636
64637 BUG_ON(!valid_dma_direction(dir));
64638 debug_dma_unmap_sg(dev, sg, nents, dir);
64639@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64640 size_t offset, size_t size,
64641 enum dma_data_direction dir)
64642 {
64643- struct dma_map_ops *ops = get_dma_ops(dev);
64644+ const struct dma_map_ops *ops = get_dma_ops(dev);
64645 dma_addr_t addr;
64646
64647 kmemcheck_mark_initialized(page_address(page) + offset, size);
64648@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64649 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
64650 size_t size, enum dma_data_direction dir)
64651 {
64652- struct dma_map_ops *ops = get_dma_ops(dev);
64653+ const struct dma_map_ops *ops = get_dma_ops(dev);
64654
64655 BUG_ON(!valid_dma_direction(dir));
64656 if (ops->unmap_page)
64657@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
64658 size_t size,
64659 enum dma_data_direction dir)
64660 {
64661- struct dma_map_ops *ops = get_dma_ops(dev);
64662+ const struct dma_map_ops *ops = get_dma_ops(dev);
64663
64664 BUG_ON(!valid_dma_direction(dir));
64665 if (ops->sync_single_for_cpu)
64666@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_device(struct device *dev,
64667 dma_addr_t addr, size_t size,
64668 enum dma_data_direction dir)
64669 {
64670- struct dma_map_ops *ops = get_dma_ops(dev);
64671+ const struct dma_map_ops *ops = get_dma_ops(dev);
64672
64673 BUG_ON(!valid_dma_direction(dir));
64674 if (ops->sync_single_for_device)
64675@@ -123,7 +123,7 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
64676 size_t size,
64677 enum dma_data_direction dir)
64678 {
64679- struct dma_map_ops *ops = get_dma_ops(dev);
64680+ const struct dma_map_ops *ops = get_dma_ops(dev);
64681
64682 BUG_ON(!valid_dma_direction(dir));
64683 if (ops->sync_single_range_for_cpu) {
64684@@ -140,7 +140,7 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
64685 size_t size,
64686 enum dma_data_direction dir)
64687 {
64688- struct dma_map_ops *ops = get_dma_ops(dev);
64689+ const struct dma_map_ops *ops = get_dma_ops(dev);
64690
64691 BUG_ON(!valid_dma_direction(dir));
64692 if (ops->sync_single_range_for_device) {
64693@@ -155,7 +155,7 @@ static inline void
64694 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
64695 int nelems, enum dma_data_direction dir)
64696 {
64697- struct dma_map_ops *ops = get_dma_ops(dev);
64698+ const struct dma_map_ops *ops = get_dma_ops(dev);
64699
64700 BUG_ON(!valid_dma_direction(dir));
64701 if (ops->sync_sg_for_cpu)
64702@@ -167,7 +167,7 @@ static inline void
64703 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
64704 int nelems, enum dma_data_direction dir)
64705 {
64706- struct dma_map_ops *ops = get_dma_ops(dev);
64707+ const struct dma_map_ops *ops = get_dma_ops(dev);
64708
64709 BUG_ON(!valid_dma_direction(dir));
64710 if (ops->sync_sg_for_device)
64711diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
64712index 0d68a1e..b74a761 100644
64713--- a/include/asm-generic/emergency-restart.h
64714+++ b/include/asm-generic/emergency-restart.h
64715@@ -1,7 +1,7 @@
64716 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
64717 #define _ASM_GENERIC_EMERGENCY_RESTART_H
64718
64719-static inline void machine_emergency_restart(void)
64720+static inline __noreturn void machine_emergency_restart(void)
64721 {
64722 machine_restart(NULL);
64723 }
64724diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
64725index 3c2344f..4590a7d 100644
64726--- a/include/asm-generic/futex.h
64727+++ b/include/asm-generic/futex.h
64728@@ -6,7 +6,7 @@
64729 #include <asm/errno.h>
64730
64731 static inline int
64732-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
64733+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
64734 {
64735 int op = (encoded_op >> 28) & 7;
64736 int cmp = (encoded_op >> 24) & 15;
64737@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
64738 }
64739
64740 static inline int
64741-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
64742+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
64743 {
64744 return -ENOSYS;
64745 }
64746diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
64747index 1ca3efc..e3dc852 100644
64748--- a/include/asm-generic/int-l64.h
64749+++ b/include/asm-generic/int-l64.h
64750@@ -46,6 +46,8 @@ typedef unsigned int u32;
64751 typedef signed long s64;
64752 typedef unsigned long u64;
64753
64754+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
64755+
64756 #define S8_C(x) x
64757 #define U8_C(x) x ## U
64758 #define S16_C(x) x
64759diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
64760index f394147..b6152b9 100644
64761--- a/include/asm-generic/int-ll64.h
64762+++ b/include/asm-generic/int-ll64.h
64763@@ -51,6 +51,8 @@ typedef unsigned int u32;
64764 typedef signed long long s64;
64765 typedef unsigned long long u64;
64766
64767+typedef unsigned long long intoverflow_t;
64768+
64769 #define S8_C(x) x
64770 #define U8_C(x) x ## U
64771 #define S16_C(x) x
64772diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
64773index e5f234a..cdb16b3 100644
64774--- a/include/asm-generic/kmap_types.h
64775+++ b/include/asm-generic/kmap_types.h
64776@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
64777 KMAP_D(16) KM_IRQ_PTE,
64778 KMAP_D(17) KM_NMI,
64779 KMAP_D(18) KM_NMI_PTE,
64780-KMAP_D(19) KM_TYPE_NR
64781+KMAP_D(19) KM_CLEARPAGE,
64782+KMAP_D(20) KM_TYPE_NR
64783 };
64784
64785 #undef KMAP_D
64786diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
64787index 725612b..9cc513a 100644
64788--- a/include/asm-generic/pgtable-nopmd.h
64789+++ b/include/asm-generic/pgtable-nopmd.h
64790@@ -1,14 +1,19 @@
64791 #ifndef _PGTABLE_NOPMD_H
64792 #define _PGTABLE_NOPMD_H
64793
64794-#ifndef __ASSEMBLY__
64795-
64796 #include <asm-generic/pgtable-nopud.h>
64797
64798-struct mm_struct;
64799-
64800 #define __PAGETABLE_PMD_FOLDED
64801
64802+#define PMD_SHIFT PUD_SHIFT
64803+#define PTRS_PER_PMD 1
64804+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
64805+#define PMD_MASK (~(PMD_SIZE-1))
64806+
64807+#ifndef __ASSEMBLY__
64808+
64809+struct mm_struct;
64810+
64811 /*
64812 * Having the pmd type consist of a pud gets the size right, and allows
64813 * us to conceptually access the pud entry that this pmd is folded into
64814@@ -16,11 +21,6 @@ struct mm_struct;
64815 */
64816 typedef struct { pud_t pud; } pmd_t;
64817
64818-#define PMD_SHIFT PUD_SHIFT
64819-#define PTRS_PER_PMD 1
64820-#define PMD_SIZE (1UL << PMD_SHIFT)
64821-#define PMD_MASK (~(PMD_SIZE-1))
64822-
64823 /*
64824 * The "pud_xxx()" functions here are trivial for a folded two-level
64825 * setup: the pmd is never bad, and a pmd always exists (as it's folded
64826diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
64827index 810431d..ccc3638 100644
64828--- a/include/asm-generic/pgtable-nopud.h
64829+++ b/include/asm-generic/pgtable-nopud.h
64830@@ -1,10 +1,15 @@
64831 #ifndef _PGTABLE_NOPUD_H
64832 #define _PGTABLE_NOPUD_H
64833
64834-#ifndef __ASSEMBLY__
64835-
64836 #define __PAGETABLE_PUD_FOLDED
64837
64838+#define PUD_SHIFT PGDIR_SHIFT
64839+#define PTRS_PER_PUD 1
64840+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
64841+#define PUD_MASK (~(PUD_SIZE-1))
64842+
64843+#ifndef __ASSEMBLY__
64844+
64845 /*
64846 * Having the pud type consist of a pgd gets the size right, and allows
64847 * us to conceptually access the pgd entry that this pud is folded into
64848@@ -12,11 +17,6 @@
64849 */
64850 typedef struct { pgd_t pgd; } pud_t;
64851
64852-#define PUD_SHIFT PGDIR_SHIFT
64853-#define PTRS_PER_PUD 1
64854-#define PUD_SIZE (1UL << PUD_SHIFT)
64855-#define PUD_MASK (~(PUD_SIZE-1))
64856-
64857 /*
64858 * The "pgd_xxx()" functions here are trivial for a folded two-level
64859 * setup: the pud is never bad, and a pud always exists (as it's folded
64860diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
64861index e2bd73e..fea8ed3 100644
64862--- a/include/asm-generic/pgtable.h
64863+++ b/include/asm-generic/pgtable.h
64864@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_area_struct *vma, unsigned long pfn,
64865 unsigned long size);
64866 #endif
64867
64868+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
64869+static inline unsigned long pax_open_kernel(void) { return 0; }
64870+#endif
64871+
64872+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
64873+static inline unsigned long pax_close_kernel(void) { return 0; }
64874+#endif
64875+
64876 #endif /* !__ASSEMBLY__ */
64877
64878 #endif /* _ASM_GENERIC_PGTABLE_H */
64879diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
64880index b6e818f..21aa58a 100644
64881--- a/include/asm-generic/vmlinux.lds.h
64882+++ b/include/asm-generic/vmlinux.lds.h
64883@@ -199,6 +199,7 @@
64884 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
64885 VMLINUX_SYMBOL(__start_rodata) = .; \
64886 *(.rodata) *(.rodata.*) \
64887+ *(.data.read_only) \
64888 *(__vermagic) /* Kernel version magic */ \
64889 *(__markers_strings) /* Markers: strings */ \
64890 *(__tracepoints_strings)/* Tracepoints: strings */ \
64891@@ -656,22 +657,24 @@
64892 * section in the linker script will go there too. @phdr should have
64893 * a leading colon.
64894 *
64895- * Note that this macros defines __per_cpu_load as an absolute symbol.
64896+ * Note that this macros defines per_cpu_load as an absolute symbol.
64897 * If there is no need to put the percpu section at a predetermined
64898 * address, use PERCPU().
64899 */
64900 #define PERCPU_VADDR(vaddr, phdr) \
64901- VMLINUX_SYMBOL(__per_cpu_load) = .; \
64902- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
64903+ per_cpu_load = .; \
64904+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
64905 - LOAD_OFFSET) { \
64906+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
64907 VMLINUX_SYMBOL(__per_cpu_start) = .; \
64908 *(.data.percpu.first) \
64909- *(.data.percpu.page_aligned) \
64910 *(.data.percpu) \
64911+ . = ALIGN(PAGE_SIZE); \
64912+ *(.data.percpu.page_aligned) \
64913 *(.data.percpu.shared_aligned) \
64914 VMLINUX_SYMBOL(__per_cpu_end) = .; \
64915 } phdr \
64916- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
64917+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
64918
64919 /**
64920 * PERCPU - define output section for percpu area, simple version
64921diff --git a/include/drm/drmP.h b/include/drm/drmP.h
64922index 66713c6..98c0460 100644
64923--- a/include/drm/drmP.h
64924+++ b/include/drm/drmP.h
64925@@ -71,6 +71,7 @@
64926 #include <linux/workqueue.h>
64927 #include <linux/poll.h>
64928 #include <asm/pgalloc.h>
64929+#include <asm/local.h>
64930 #include "drm.h"
64931
64932 #include <linux/idr.h>
64933@@ -814,7 +815,7 @@ struct drm_driver {
64934 void (*vgaarb_irq)(struct drm_device *dev, bool state);
64935
64936 /* Driver private ops for this object */
64937- struct vm_operations_struct *gem_vm_ops;
64938+ const struct vm_operations_struct *gem_vm_ops;
64939
64940 int major;
64941 int minor;
64942@@ -917,7 +918,7 @@ struct drm_device {
64943
64944 /** \name Usage Counters */
64945 /*@{ */
64946- int open_count; /**< Outstanding files open */
64947+ local_t open_count; /**< Outstanding files open */
64948 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
64949 atomic_t vma_count; /**< Outstanding vma areas open */
64950 int buf_use; /**< Buffers in use -- cannot alloc */
64951@@ -928,7 +929,7 @@ struct drm_device {
64952 /*@{ */
64953 unsigned long counters;
64954 enum drm_stat_type types[15];
64955- atomic_t counts[15];
64956+ atomic_unchecked_t counts[15];
64957 /*@} */
64958
64959 struct list_head filelist;
64960@@ -1016,7 +1017,7 @@ struct drm_device {
64961 struct pci_controller *hose;
64962 #endif
64963 struct drm_sg_mem *sg; /**< Scatter gather memory */
64964- unsigned int num_crtcs; /**< Number of CRTCs on this device */
64965+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
64966 void *dev_private; /**< device private data */
64967 void *mm_private;
64968 struct address_space *dev_mapping;
64969@@ -1042,11 +1043,11 @@ struct drm_device {
64970 spinlock_t object_name_lock;
64971 struct idr object_name_idr;
64972 atomic_t object_count;
64973- atomic_t object_memory;
64974+ atomic_unchecked_t object_memory;
64975 atomic_t pin_count;
64976- atomic_t pin_memory;
64977+ atomic_unchecked_t pin_memory;
64978 atomic_t gtt_count;
64979- atomic_t gtt_memory;
64980+ atomic_unchecked_t gtt_memory;
64981 uint32_t gtt_total;
64982 uint32_t invalidate_domains; /* domains pending invalidation */
64983 uint32_t flush_domains; /* domains pending flush */
64984diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
64985index b29e201..3413cc9 100644
64986--- a/include/drm/drm_crtc_helper.h
64987+++ b/include/drm/drm_crtc_helper.h
64988@@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
64989
64990 /* reload the current crtc LUT */
64991 void (*load_lut)(struct drm_crtc *crtc);
64992-};
64993+} __no_const;
64994
64995 struct drm_encoder_helper_funcs {
64996 void (*dpms)(struct drm_encoder *encoder, int mode);
64997@@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
64998 struct drm_connector *connector);
64999 /* disable encoder when not in use - more explicit than dpms off */
65000 void (*disable)(struct drm_encoder *encoder);
65001-};
65002+} __no_const;
65003
65004 struct drm_connector_helper_funcs {
65005 int (*get_modes)(struct drm_connector *connector);
65006diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
65007index b199170..6f9e64c 100644
65008--- a/include/drm/ttm/ttm_memory.h
65009+++ b/include/drm/ttm/ttm_memory.h
65010@@ -47,7 +47,7 @@
65011
65012 struct ttm_mem_shrink {
65013 int (*do_shrink) (struct ttm_mem_shrink *);
65014-};
65015+} __no_const;
65016
65017 /**
65018 * struct ttm_mem_global - Global memory accounting structure.
65019diff --git a/include/linux/a.out.h b/include/linux/a.out.h
65020index e86dfca..40cc55f 100644
65021--- a/include/linux/a.out.h
65022+++ b/include/linux/a.out.h
65023@@ -39,6 +39,14 @@ enum machine_type {
65024 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65025 };
65026
65027+/* Constants for the N_FLAGS field */
65028+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65029+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65030+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65031+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65032+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65033+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65034+
65035 #if !defined (N_MAGIC)
65036 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65037 #endif
65038diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
65039index 817b237..62c10bc 100644
65040--- a/include/linux/atmdev.h
65041+++ b/include/linux/atmdev.h
65042@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
65043 #endif
65044
65045 struct k_atm_aal_stats {
65046-#define __HANDLE_ITEM(i) atomic_t i
65047+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65048 __AAL_STAT_ITEMS
65049 #undef __HANDLE_ITEM
65050 };
65051diff --git a/include/linux/backlight.h b/include/linux/backlight.h
65052index 0f5f578..8c4f884 100644
65053--- a/include/linux/backlight.h
65054+++ b/include/linux/backlight.h
65055@@ -36,18 +36,18 @@ struct backlight_device;
65056 struct fb_info;
65057
65058 struct backlight_ops {
65059- unsigned int options;
65060+ const unsigned int options;
65061
65062 #define BL_CORE_SUSPENDRESUME (1 << 0)
65063
65064 /* Notify the backlight driver some property has changed */
65065- int (*update_status)(struct backlight_device *);
65066+ int (* const update_status)(struct backlight_device *);
65067 /* Return the current backlight brightness (accounting for power,
65068 fb_blank etc.) */
65069- int (*get_brightness)(struct backlight_device *);
65070+ int (* const get_brightness)(struct backlight_device *);
65071 /* Check if given framebuffer device is the one bound to this backlight;
65072 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
65073- int (*check_fb)(struct fb_info *);
65074+ int (* const check_fb)(struct fb_info *);
65075 };
65076
65077 /* This structure defines all the properties of a backlight */
65078@@ -86,7 +86,7 @@ struct backlight_device {
65079 registered this device has been unloaded, and if class_get_devdata()
65080 points to something in the body of that driver, it is also invalid. */
65081 struct mutex ops_lock;
65082- struct backlight_ops *ops;
65083+ const struct backlight_ops *ops;
65084
65085 /* The framebuffer notifier block */
65086 struct notifier_block fb_notif;
65087@@ -103,7 +103,7 @@ static inline void backlight_update_status(struct backlight_device *bd)
65088 }
65089
65090 extern struct backlight_device *backlight_device_register(const char *name,
65091- struct device *dev, void *devdata, struct backlight_ops *ops);
65092+ struct device *dev, void *devdata, const struct backlight_ops *ops);
65093 extern void backlight_device_unregister(struct backlight_device *bd);
65094 extern void backlight_force_update(struct backlight_device *bd,
65095 enum backlight_update_reason reason);
65096diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
65097index a3d802e..482f69c 100644
65098--- a/include/linux/binfmts.h
65099+++ b/include/linux/binfmts.h
65100@@ -83,6 +83,7 @@ struct linux_binfmt {
65101 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
65102 int (*load_shlib)(struct file *);
65103 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
65104+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
65105 unsigned long min_coredump; /* minimal dump size */
65106 int hasvdso;
65107 };
65108diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
65109index a06bfab..4fa38bb 100644
65110--- a/include/linux/blkdev.h
65111+++ b/include/linux/blkdev.h
65112@@ -1278,7 +1278,7 @@ struct block_device_operations {
65113 int (*revalidate_disk) (struct gendisk *);
65114 int (*getgeo)(struct block_device *, struct hd_geometry *);
65115 struct module *owner;
65116-};
65117+} __do_const;
65118
65119 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
65120 unsigned long);
65121diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
65122index 3b73b99..629d21b 100644
65123--- a/include/linux/blktrace_api.h
65124+++ b/include/linux/blktrace_api.h
65125@@ -160,7 +160,7 @@ struct blk_trace {
65126 struct dentry *dir;
65127 struct dentry *dropped_file;
65128 struct dentry *msg_file;
65129- atomic_t dropped;
65130+ atomic_unchecked_t dropped;
65131 };
65132
65133 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
65134diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
65135index 83195fb..0b0f77d 100644
65136--- a/include/linux/byteorder/little_endian.h
65137+++ b/include/linux/byteorder/little_endian.h
65138@@ -42,51 +42,51 @@
65139
65140 static inline __le64 __cpu_to_le64p(const __u64 *p)
65141 {
65142- return (__force __le64)*p;
65143+ return (__force const __le64)*p;
65144 }
65145 static inline __u64 __le64_to_cpup(const __le64 *p)
65146 {
65147- return (__force __u64)*p;
65148+ return (__force const __u64)*p;
65149 }
65150 static inline __le32 __cpu_to_le32p(const __u32 *p)
65151 {
65152- return (__force __le32)*p;
65153+ return (__force const __le32)*p;
65154 }
65155 static inline __u32 __le32_to_cpup(const __le32 *p)
65156 {
65157- return (__force __u32)*p;
65158+ return (__force const __u32)*p;
65159 }
65160 static inline __le16 __cpu_to_le16p(const __u16 *p)
65161 {
65162- return (__force __le16)*p;
65163+ return (__force const __le16)*p;
65164 }
65165 static inline __u16 __le16_to_cpup(const __le16 *p)
65166 {
65167- return (__force __u16)*p;
65168+ return (__force const __u16)*p;
65169 }
65170 static inline __be64 __cpu_to_be64p(const __u64 *p)
65171 {
65172- return (__force __be64)__swab64p(p);
65173+ return (__force const __be64)__swab64p(p);
65174 }
65175 static inline __u64 __be64_to_cpup(const __be64 *p)
65176 {
65177- return __swab64p((__u64 *)p);
65178+ return __swab64p((const __u64 *)p);
65179 }
65180 static inline __be32 __cpu_to_be32p(const __u32 *p)
65181 {
65182- return (__force __be32)__swab32p(p);
65183+ return (__force const __be32)__swab32p(p);
65184 }
65185 static inline __u32 __be32_to_cpup(const __be32 *p)
65186 {
65187- return __swab32p((__u32 *)p);
65188+ return __swab32p((const __u32 *)p);
65189 }
65190 static inline __be16 __cpu_to_be16p(const __u16 *p)
65191 {
65192- return (__force __be16)__swab16p(p);
65193+ return (__force const __be16)__swab16p(p);
65194 }
65195 static inline __u16 __be16_to_cpup(const __be16 *p)
65196 {
65197- return __swab16p((__u16 *)p);
65198+ return __swab16p((const __u16 *)p);
65199 }
65200 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65201 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65202diff --git a/include/linux/cache.h b/include/linux/cache.h
65203index 97e2488..e7576b9 100644
65204--- a/include/linux/cache.h
65205+++ b/include/linux/cache.h
65206@@ -16,6 +16,10 @@
65207 #define __read_mostly
65208 #endif
65209
65210+#ifndef __read_only
65211+#define __read_only __read_mostly
65212+#endif
65213+
65214 #ifndef ____cacheline_aligned
65215 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
65216 #endif
65217diff --git a/include/linux/capability.h b/include/linux/capability.h
65218index c8f2a5f7..1618a5c 100644
65219--- a/include/linux/capability.h
65220+++ b/include/linux/capability.h
65221@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff_set;
65222 (security_real_capable_noaudit((t), (cap)) == 0)
65223
65224 extern int capable(int cap);
65225+int capable_nolog(int cap);
65226
65227 /* audit system wants to get cap info from files as well */
65228 struct dentry;
65229diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
65230index 450fa59..86019fb 100644
65231--- a/include/linux/compiler-gcc4.h
65232+++ b/include/linux/compiler-gcc4.h
65233@@ -36,4 +36,16 @@
65234 the kernel context */
65235 #define __cold __attribute__((__cold__))
65236
65237+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
65238+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
65239+#define __bos0(ptr) __bos((ptr), 0)
65240+#define __bos1(ptr) __bos((ptr), 1)
65241+
65242+#if __GNUC_MINOR__ >= 5
65243+#ifdef CONSTIFY_PLUGIN
65244+#define __no_const __attribute__((no_const))
65245+#define __do_const __attribute__((do_const))
65246+#endif
65247+#endif
65248+
65249 #endif
65250diff --git a/include/linux/compiler.h b/include/linux/compiler.h
65251index 04fb513..fd6477b 100644
65252--- a/include/linux/compiler.h
65253+++ b/include/linux/compiler.h
65254@@ -5,11 +5,14 @@
65255
65256 #ifdef __CHECKER__
65257 # define __user __attribute__((noderef, address_space(1)))
65258+# define __force_user __force __user
65259 # define __kernel /* default address space */
65260+# define __force_kernel __force __kernel
65261 # define __safe __attribute__((safe))
65262 # define __force __attribute__((force))
65263 # define __nocast __attribute__((nocast))
65264 # define __iomem __attribute__((noderef, address_space(2)))
65265+# define __force_iomem __force __iomem
65266 # define __acquires(x) __attribute__((context(x,0,1)))
65267 # define __releases(x) __attribute__((context(x,1,0)))
65268 # define __acquire(x) __context__(x,1)
65269@@ -17,13 +20,34 @@
65270 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
65271 extern void __chk_user_ptr(const volatile void __user *);
65272 extern void __chk_io_ptr(const volatile void __iomem *);
65273+#elif defined(CHECKER_PLUGIN)
65274+//# define __user
65275+//# define __force_user
65276+//# define __kernel
65277+//# define __force_kernel
65278+# define __safe
65279+# define __force
65280+# define __nocast
65281+# define __iomem
65282+# define __force_iomem
65283+# define __chk_user_ptr(x) (void)0
65284+# define __chk_io_ptr(x) (void)0
65285+# define __builtin_warning(x, y...) (1)
65286+# define __acquires(x)
65287+# define __releases(x)
65288+# define __acquire(x) (void)0
65289+# define __release(x) (void)0
65290+# define __cond_lock(x,c) (c)
65291 #else
65292 # define __user
65293+# define __force_user
65294 # define __kernel
65295+# define __force_kernel
65296 # define __safe
65297 # define __force
65298 # define __nocast
65299 # define __iomem
65300+# define __force_iomem
65301 # define __chk_user_ptr(x) (void)0
65302 # define __chk_io_ptr(x) (void)0
65303 # define __builtin_warning(x, y...) (1)
65304@@ -247,6 +271,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65305 # define __attribute_const__ /* unimplemented */
65306 #endif
65307
65308+#ifndef __no_const
65309+# define __no_const
65310+#endif
65311+
65312+#ifndef __do_const
65313+# define __do_const
65314+#endif
65315+
65316 /*
65317 * Tell gcc if a function is cold. The compiler will assume any path
65318 * directly leading to the call is unlikely.
65319@@ -256,6 +288,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65320 #define __cold
65321 #endif
65322
65323+#ifndef __alloc_size
65324+#define __alloc_size(...)
65325+#endif
65326+
65327+#ifndef __bos
65328+#define __bos(ptr, arg)
65329+#endif
65330+
65331+#ifndef __bos0
65332+#define __bos0(ptr)
65333+#endif
65334+
65335+#ifndef __bos1
65336+#define __bos1(ptr)
65337+#endif
65338+
65339 /* Simple shorthand for a section definition */
65340 #ifndef __section
65341 # define __section(S) __attribute__ ((__section__(#S)))
65342@@ -278,6 +326,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65343 * use is to mediate communication between process-level code and irq/NMI
65344 * handlers, all running on the same CPU.
65345 */
65346-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
65347+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
65348+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
65349
65350 #endif /* __LINUX_COMPILER_H */
65351diff --git a/include/linux/crypto.h b/include/linux/crypto.h
65352index fd92988..a3164bd 100644
65353--- a/include/linux/crypto.h
65354+++ b/include/linux/crypto.h
65355@@ -394,7 +394,7 @@ struct cipher_tfm {
65356 const u8 *key, unsigned int keylen);
65357 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65358 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65359-};
65360+} __no_const;
65361
65362 struct hash_tfm {
65363 int (*init)(struct hash_desc *desc);
65364@@ -415,13 +415,13 @@ struct compress_tfm {
65365 int (*cot_decompress)(struct crypto_tfm *tfm,
65366 const u8 *src, unsigned int slen,
65367 u8 *dst, unsigned int *dlen);
65368-};
65369+} __no_const;
65370
65371 struct rng_tfm {
65372 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
65373 unsigned int dlen);
65374 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
65375-};
65376+} __no_const;
65377
65378 #define crt_ablkcipher crt_u.ablkcipher
65379 #define crt_aead crt_u.aead
65380diff --git a/include/linux/dcache.h b/include/linux/dcache.h
65381index 30b93b2..cd7a8db 100644
65382--- a/include/linux/dcache.h
65383+++ b/include/linux/dcache.h
65384@@ -119,6 +119,8 @@ struct dentry {
65385 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
65386 };
65387
65388+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
65389+
65390 /*
65391 * dentry->d_lock spinlock nesting subclasses:
65392 *
65393diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
65394index 3e9bd6a..f4e1aa0 100644
65395--- a/include/linux/decompress/mm.h
65396+++ b/include/linux/decompress/mm.h
65397@@ -78,7 +78,7 @@ static void free(void *where)
65398 * warnings when not needed (indeed large_malloc / large_free are not
65399 * needed by inflate */
65400
65401-#define malloc(a) kmalloc(a, GFP_KERNEL)
65402+#define malloc(a) kmalloc((a), GFP_KERNEL)
65403 #define free(a) kfree(a)
65404
65405 #define large_malloc(a) vmalloc(a)
65406diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
65407index 91b7618..92a93d32 100644
65408--- a/include/linux/dma-mapping.h
65409+++ b/include/linux/dma-mapping.h
65410@@ -16,51 +16,51 @@ enum dma_data_direction {
65411 };
65412
65413 struct dma_map_ops {
65414- void* (*alloc_coherent)(struct device *dev, size_t size,
65415+ void* (* const alloc_coherent)(struct device *dev, size_t size,
65416 dma_addr_t *dma_handle, gfp_t gfp);
65417- void (*free_coherent)(struct device *dev, size_t size,
65418+ void (* const free_coherent)(struct device *dev, size_t size,
65419 void *vaddr, dma_addr_t dma_handle);
65420- dma_addr_t (*map_page)(struct device *dev, struct page *page,
65421+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
65422 unsigned long offset, size_t size,
65423 enum dma_data_direction dir,
65424 struct dma_attrs *attrs);
65425- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
65426+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
65427 size_t size, enum dma_data_direction dir,
65428 struct dma_attrs *attrs);
65429- int (*map_sg)(struct device *dev, struct scatterlist *sg,
65430+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
65431 int nents, enum dma_data_direction dir,
65432 struct dma_attrs *attrs);
65433- void (*unmap_sg)(struct device *dev,
65434+ void (* const unmap_sg)(struct device *dev,
65435 struct scatterlist *sg, int nents,
65436 enum dma_data_direction dir,
65437 struct dma_attrs *attrs);
65438- void (*sync_single_for_cpu)(struct device *dev,
65439+ void (* const sync_single_for_cpu)(struct device *dev,
65440 dma_addr_t dma_handle, size_t size,
65441 enum dma_data_direction dir);
65442- void (*sync_single_for_device)(struct device *dev,
65443+ void (* const sync_single_for_device)(struct device *dev,
65444 dma_addr_t dma_handle, size_t size,
65445 enum dma_data_direction dir);
65446- void (*sync_single_range_for_cpu)(struct device *dev,
65447+ void (* const sync_single_range_for_cpu)(struct device *dev,
65448 dma_addr_t dma_handle,
65449 unsigned long offset,
65450 size_t size,
65451 enum dma_data_direction dir);
65452- void (*sync_single_range_for_device)(struct device *dev,
65453+ void (* const sync_single_range_for_device)(struct device *dev,
65454 dma_addr_t dma_handle,
65455 unsigned long offset,
65456 size_t size,
65457 enum dma_data_direction dir);
65458- void (*sync_sg_for_cpu)(struct device *dev,
65459+ void (* const sync_sg_for_cpu)(struct device *dev,
65460 struct scatterlist *sg, int nents,
65461 enum dma_data_direction dir);
65462- void (*sync_sg_for_device)(struct device *dev,
65463+ void (* const sync_sg_for_device)(struct device *dev,
65464 struct scatterlist *sg, int nents,
65465 enum dma_data_direction dir);
65466- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
65467- int (*dma_supported)(struct device *dev, u64 mask);
65468+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
65469+ int (* const dma_supported)(struct device *dev, u64 mask);
65470 int (*set_dma_mask)(struct device *dev, u64 mask);
65471 int is_phys;
65472-};
65473+} __do_const;
65474
65475 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
65476
65477diff --git a/include/linux/dst.h b/include/linux/dst.h
65478index e26fed8..b976d9f 100644
65479--- a/include/linux/dst.h
65480+++ b/include/linux/dst.h
65481@@ -380,7 +380,7 @@ struct dst_node
65482 struct thread_pool *pool;
65483
65484 /* Transaction IDs live here */
65485- atomic_long_t gen;
65486+ atomic_long_unchecked_t gen;
65487
65488 /*
65489 * How frequently and how many times transaction
65490diff --git a/include/linux/elf.h b/include/linux/elf.h
65491index 90a4ed0..d652617 100644
65492--- a/include/linux/elf.h
65493+++ b/include/linux/elf.h
65494@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
65495 #define PT_GNU_EH_FRAME 0x6474e550
65496
65497 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65498+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65499+
65500+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65501+
65502+/* Constants for the e_flags field */
65503+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65504+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65505+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65506+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65507+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65508+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65509
65510 /* These constants define the different elf file types */
65511 #define ET_NONE 0
65512@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
65513 #define DT_DEBUG 21
65514 #define DT_TEXTREL 22
65515 #define DT_JMPREL 23
65516+#define DT_FLAGS 30
65517+ #define DF_TEXTREL 0x00000004
65518 #define DT_ENCODING 32
65519 #define OLD_DT_LOOS 0x60000000
65520 #define DT_LOOS 0x6000000d
65521@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
65522 #define PF_W 0x2
65523 #define PF_X 0x1
65524
65525+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65526+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65527+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65528+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65529+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65530+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65531+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65532+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65533+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65534+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65535+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65536+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65537+
65538 typedef struct elf32_phdr{
65539 Elf32_Word p_type;
65540 Elf32_Off p_offset;
65541@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
65542 #define EI_OSABI 7
65543 #define EI_PAD 8
65544
65545+#define EI_PAX 14
65546+
65547 #define ELFMAG0 0x7f /* EI_MAG */
65548 #define ELFMAG1 'E'
65549 #define ELFMAG2 'L'
65550@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
65551 #define elf_phdr elf32_phdr
65552 #define elf_note elf32_note
65553 #define elf_addr_t Elf32_Off
65554+#define elf_dyn Elf32_Dyn
65555
65556 #else
65557
65558@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
65559 #define elf_phdr elf64_phdr
65560 #define elf_note elf64_note
65561 #define elf_addr_t Elf64_Off
65562+#define elf_dyn Elf64_Dyn
65563
65564 #endif
65565
65566diff --git a/include/linux/fs.h b/include/linux/fs.h
65567index 1b9a47a..6fe2934 100644
65568--- a/include/linux/fs.h
65569+++ b/include/linux/fs.h
65570@@ -568,41 +568,41 @@ typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
65571 unsigned long, unsigned long);
65572
65573 struct address_space_operations {
65574- int (*writepage)(struct page *page, struct writeback_control *wbc);
65575- int (*readpage)(struct file *, struct page *);
65576- void (*sync_page)(struct page *);
65577+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
65578+ int (* const readpage)(struct file *, struct page *);
65579+ void (* const sync_page)(struct page *);
65580
65581 /* Write back some dirty pages from this mapping. */
65582- int (*writepages)(struct address_space *, struct writeback_control *);
65583+ int (* const writepages)(struct address_space *, struct writeback_control *);
65584
65585 /* Set a page dirty. Return true if this dirtied it */
65586- int (*set_page_dirty)(struct page *page);
65587+ int (* const set_page_dirty)(struct page *page);
65588
65589- int (*readpages)(struct file *filp, struct address_space *mapping,
65590+ int (* const readpages)(struct file *filp, struct address_space *mapping,
65591 struct list_head *pages, unsigned nr_pages);
65592
65593- int (*write_begin)(struct file *, struct address_space *mapping,
65594+ int (* const write_begin)(struct file *, struct address_space *mapping,
65595 loff_t pos, unsigned len, unsigned flags,
65596 struct page **pagep, void **fsdata);
65597- int (*write_end)(struct file *, struct address_space *mapping,
65598+ int (* const write_end)(struct file *, struct address_space *mapping,
65599 loff_t pos, unsigned len, unsigned copied,
65600 struct page *page, void *fsdata);
65601
65602 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
65603- sector_t (*bmap)(struct address_space *, sector_t);
65604- void (*invalidatepage) (struct page *, unsigned long);
65605- int (*releasepage) (struct page *, gfp_t);
65606- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
65607+ sector_t (* const bmap)(struct address_space *, sector_t);
65608+ void (* const invalidatepage) (struct page *, unsigned long);
65609+ int (* const releasepage) (struct page *, gfp_t);
65610+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
65611 loff_t offset, unsigned long nr_segs);
65612- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
65613+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
65614 void **, unsigned long *);
65615 /* migrate the contents of a page to the specified target */
65616- int (*migratepage) (struct address_space *,
65617+ int (* const migratepage) (struct address_space *,
65618 struct page *, struct page *);
65619- int (*launder_page) (struct page *);
65620- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
65621+ int (* const launder_page) (struct page *);
65622+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
65623 unsigned long);
65624- int (*error_remove_page)(struct address_space *, struct page *);
65625+ int (* const error_remove_page)(struct address_space *, struct page *);
65626 };
65627
65628 /*
65629@@ -1031,19 +1031,19 @@ static inline int file_check_writeable(struct file *filp)
65630 typedef struct files_struct *fl_owner_t;
65631
65632 struct file_lock_operations {
65633- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65634- void (*fl_release_private)(struct file_lock *);
65635+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65636+ void (* const fl_release_private)(struct file_lock *);
65637 };
65638
65639 struct lock_manager_operations {
65640- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
65641- void (*fl_notify)(struct file_lock *); /* unblock callback */
65642- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
65643- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65644- void (*fl_release_private)(struct file_lock *);
65645- void (*fl_break)(struct file_lock *);
65646- int (*fl_mylease)(struct file_lock *, struct file_lock *);
65647- int (*fl_change)(struct file_lock **, int);
65648+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
65649+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
65650+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
65651+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65652+ void (* const fl_release_private)(struct file_lock *);
65653+ void (* const fl_break)(struct file_lock *);
65654+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
65655+ int (* const fl_change)(struct file_lock **, int);
65656 };
65657
65658 struct lock_manager {
65659@@ -1442,7 +1442,7 @@ struct fiemap_extent_info {
65660 unsigned int fi_flags; /* Flags as passed from user */
65661 unsigned int fi_extents_mapped; /* Number of mapped extents */
65662 unsigned int fi_extents_max; /* Size of fiemap_extent array */
65663- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
65664+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
65665 * array */
65666 };
65667 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
65668@@ -1512,7 +1512,8 @@ struct file_operations {
65669 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
65670 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
65671 int (*setlease)(struct file *, long, struct file_lock **);
65672-};
65673+} __do_const;
65674+typedef struct file_operations __no_const file_operations_no_const;
65675
65676 struct inode_operations {
65677 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
65678@@ -1559,30 +1560,30 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
65679 unsigned long, loff_t *);
65680
65681 struct super_operations {
65682- struct inode *(*alloc_inode)(struct super_block *sb);
65683- void (*destroy_inode)(struct inode *);
65684+ struct inode *(* const alloc_inode)(struct super_block *sb);
65685+ void (* const destroy_inode)(struct inode *);
65686
65687- void (*dirty_inode) (struct inode *);
65688- int (*write_inode) (struct inode *, int);
65689- void (*drop_inode) (struct inode *);
65690- void (*delete_inode) (struct inode *);
65691- void (*put_super) (struct super_block *);
65692- void (*write_super) (struct super_block *);
65693- int (*sync_fs)(struct super_block *sb, int wait);
65694- int (*freeze_fs) (struct super_block *);
65695- int (*unfreeze_fs) (struct super_block *);
65696- int (*statfs) (struct dentry *, struct kstatfs *);
65697- int (*remount_fs) (struct super_block *, int *, char *);
65698- void (*clear_inode) (struct inode *);
65699- void (*umount_begin) (struct super_block *);
65700+ void (* const dirty_inode) (struct inode *);
65701+ int (* const write_inode) (struct inode *, int);
65702+ void (* const drop_inode) (struct inode *);
65703+ void (* const delete_inode) (struct inode *);
65704+ void (* const put_super) (struct super_block *);
65705+ void (* const write_super) (struct super_block *);
65706+ int (* const sync_fs)(struct super_block *sb, int wait);
65707+ int (* const freeze_fs) (struct super_block *);
65708+ int (* const unfreeze_fs) (struct super_block *);
65709+ int (* const statfs) (struct dentry *, struct kstatfs *);
65710+ int (* const remount_fs) (struct super_block *, int *, char *);
65711+ void (* const clear_inode) (struct inode *);
65712+ void (* const umount_begin) (struct super_block *);
65713
65714- int (*show_options)(struct seq_file *, struct vfsmount *);
65715- int (*show_stats)(struct seq_file *, struct vfsmount *);
65716+ int (* const show_options)(struct seq_file *, struct vfsmount *);
65717+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
65718 #ifdef CONFIG_QUOTA
65719- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
65720- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
65721+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
65722+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
65723 #endif
65724- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
65725+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
65726 };
65727
65728 /*
65729diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
65730index 78a05bf..2a7d3e1 100644
65731--- a/include/linux/fs_struct.h
65732+++ b/include/linux/fs_struct.h
65733@@ -4,7 +4,7 @@
65734 #include <linux/path.h>
65735
65736 struct fs_struct {
65737- int users;
65738+ atomic_t users;
65739 rwlock_t lock;
65740 int umask;
65741 int in_exec;
65742diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
65743index 7be0c6f..2f63a2b 100644
65744--- a/include/linux/fscache-cache.h
65745+++ b/include/linux/fscache-cache.h
65746@@ -116,7 +116,7 @@ struct fscache_operation {
65747 #endif
65748 };
65749
65750-extern atomic_t fscache_op_debug_id;
65751+extern atomic_unchecked_t fscache_op_debug_id;
65752 extern const struct slow_work_ops fscache_op_slow_work_ops;
65753
65754 extern void fscache_enqueue_operation(struct fscache_operation *);
65755@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
65756 fscache_operation_release_t release)
65757 {
65758 atomic_set(&op->usage, 1);
65759- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
65760+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
65761 op->release = release;
65762 INIT_LIST_HEAD(&op->pend_link);
65763 fscache_set_op_state(op, "Init");
65764diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
65765index 4ec5e67..42f1eb9 100644
65766--- a/include/linux/ftrace_event.h
65767+++ b/include/linux/ftrace_event.h
65768@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftrace_event_call *call,
65769 int filter_type);
65770 extern int trace_define_common_fields(struct ftrace_event_call *call);
65771
65772-#define is_signed_type(type) (((type)(-1)) < 0)
65773+#define is_signed_type(type) (((type)(-1)) < (type)1)
65774
65775 int trace_set_clr_event(const char *system, const char *event, int set);
65776
65777diff --git a/include/linux/genhd.h b/include/linux/genhd.h
65778index 297df45..b6a74ff 100644
65779--- a/include/linux/genhd.h
65780+++ b/include/linux/genhd.h
65781@@ -161,7 +161,7 @@ struct gendisk {
65782
65783 struct timer_rand_state *random;
65784
65785- atomic_t sync_io; /* RAID */
65786+ atomic_unchecked_t sync_io; /* RAID */
65787 struct work_struct async_notify;
65788 #ifdef CONFIG_BLK_DEV_INTEGRITY
65789 struct blk_integrity *integrity;
65790diff --git a/include/linux/gracl.h b/include/linux/gracl.h
65791new file mode 100644
65792index 0000000..0dc3943
65793--- /dev/null
65794+++ b/include/linux/gracl.h
65795@@ -0,0 +1,317 @@
65796+#ifndef GR_ACL_H
65797+#define GR_ACL_H
65798+
65799+#include <linux/grdefs.h>
65800+#include <linux/resource.h>
65801+#include <linux/capability.h>
65802+#include <linux/dcache.h>
65803+#include <asm/resource.h>
65804+
65805+/* Major status information */
65806+
65807+#define GR_VERSION "grsecurity 2.2.2"
65808+#define GRSECURITY_VERSION 0x2202
65809+
65810+enum {
65811+ GR_SHUTDOWN = 0,
65812+ GR_ENABLE = 1,
65813+ GR_SPROLE = 2,
65814+ GR_RELOAD = 3,
65815+ GR_SEGVMOD = 4,
65816+ GR_STATUS = 5,
65817+ GR_UNSPROLE = 6,
65818+ GR_PASSSET = 7,
65819+ GR_SPROLEPAM = 8,
65820+};
65821+
65822+/* Password setup definitions
65823+ * kernel/grhash.c */
65824+enum {
65825+ GR_PW_LEN = 128,
65826+ GR_SALT_LEN = 16,
65827+ GR_SHA_LEN = 32,
65828+};
65829+
65830+enum {
65831+ GR_SPROLE_LEN = 64,
65832+};
65833+
65834+enum {
65835+ GR_NO_GLOB = 0,
65836+ GR_REG_GLOB,
65837+ GR_CREATE_GLOB
65838+};
65839+
65840+#define GR_NLIMITS 32
65841+
65842+/* Begin Data Structures */
65843+
65844+struct sprole_pw {
65845+ unsigned char *rolename;
65846+ unsigned char salt[GR_SALT_LEN];
65847+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
65848+};
65849+
65850+struct name_entry {
65851+ __u32 key;
65852+ ino_t inode;
65853+ dev_t device;
65854+ char *name;
65855+ __u16 len;
65856+ __u8 deleted;
65857+ struct name_entry *prev;
65858+ struct name_entry *next;
65859+};
65860+
65861+struct inodev_entry {
65862+ struct name_entry *nentry;
65863+ struct inodev_entry *prev;
65864+ struct inodev_entry *next;
65865+};
65866+
65867+struct acl_role_db {
65868+ struct acl_role_label **r_hash;
65869+ __u32 r_size;
65870+};
65871+
65872+struct inodev_db {
65873+ struct inodev_entry **i_hash;
65874+ __u32 i_size;
65875+};
65876+
65877+struct name_db {
65878+ struct name_entry **n_hash;
65879+ __u32 n_size;
65880+};
65881+
65882+struct crash_uid {
65883+ uid_t uid;
65884+ unsigned long expires;
65885+};
65886+
65887+struct gr_hash_struct {
65888+ void **table;
65889+ void **nametable;
65890+ void *first;
65891+ __u32 table_size;
65892+ __u32 used_size;
65893+ int type;
65894+};
65895+
65896+/* Userspace Grsecurity ACL data structures */
65897+
65898+struct acl_subject_label {
65899+ char *filename;
65900+ ino_t inode;
65901+ dev_t device;
65902+ __u32 mode;
65903+ kernel_cap_t cap_mask;
65904+ kernel_cap_t cap_lower;
65905+ kernel_cap_t cap_invert_audit;
65906+
65907+ struct rlimit res[GR_NLIMITS];
65908+ __u32 resmask;
65909+
65910+ __u8 user_trans_type;
65911+ __u8 group_trans_type;
65912+ uid_t *user_transitions;
65913+ gid_t *group_transitions;
65914+ __u16 user_trans_num;
65915+ __u16 group_trans_num;
65916+
65917+ __u32 sock_families[2];
65918+ __u32 ip_proto[8];
65919+ __u32 ip_type;
65920+ struct acl_ip_label **ips;
65921+ __u32 ip_num;
65922+ __u32 inaddr_any_override;
65923+
65924+ __u32 crashes;
65925+ unsigned long expires;
65926+
65927+ struct acl_subject_label *parent_subject;
65928+ struct gr_hash_struct *hash;
65929+ struct acl_subject_label *prev;
65930+ struct acl_subject_label *next;
65931+
65932+ struct acl_object_label **obj_hash;
65933+ __u32 obj_hash_size;
65934+ __u16 pax_flags;
65935+};
65936+
65937+struct role_allowed_ip {
65938+ __u32 addr;
65939+ __u32 netmask;
65940+
65941+ struct role_allowed_ip *prev;
65942+ struct role_allowed_ip *next;
65943+};
65944+
65945+struct role_transition {
65946+ char *rolename;
65947+
65948+ struct role_transition *prev;
65949+ struct role_transition *next;
65950+};
65951+
65952+struct acl_role_label {
65953+ char *rolename;
65954+ uid_t uidgid;
65955+ __u16 roletype;
65956+
65957+ __u16 auth_attempts;
65958+ unsigned long expires;
65959+
65960+ struct acl_subject_label *root_label;
65961+ struct gr_hash_struct *hash;
65962+
65963+ struct acl_role_label *prev;
65964+ struct acl_role_label *next;
65965+
65966+ struct role_transition *transitions;
65967+ struct role_allowed_ip *allowed_ips;
65968+ uid_t *domain_children;
65969+ __u16 domain_child_num;
65970+
65971+ struct acl_subject_label **subj_hash;
65972+ __u32 subj_hash_size;
65973+};
65974+
65975+struct user_acl_role_db {
65976+ struct acl_role_label **r_table;
65977+ __u32 num_pointers; /* Number of allocations to track */
65978+ __u32 num_roles; /* Number of roles */
65979+ __u32 num_domain_children; /* Number of domain children */
65980+ __u32 num_subjects; /* Number of subjects */
65981+ __u32 num_objects; /* Number of objects */
65982+};
65983+
65984+struct acl_object_label {
65985+ char *filename;
65986+ ino_t inode;
65987+ dev_t device;
65988+ __u32 mode;
65989+
65990+ struct acl_subject_label *nested;
65991+ struct acl_object_label *globbed;
65992+
65993+ /* next two structures not used */
65994+
65995+ struct acl_object_label *prev;
65996+ struct acl_object_label *next;
65997+};
65998+
65999+struct acl_ip_label {
66000+ char *iface;
66001+ __u32 addr;
66002+ __u32 netmask;
66003+ __u16 low, high;
66004+ __u8 mode;
66005+ __u32 type;
66006+ __u32 proto[8];
66007+
66008+ /* next two structures not used */
66009+
66010+ struct acl_ip_label *prev;
66011+ struct acl_ip_label *next;
66012+};
66013+
66014+struct gr_arg {
66015+ struct user_acl_role_db role_db;
66016+ unsigned char pw[GR_PW_LEN];
66017+ unsigned char salt[GR_SALT_LEN];
66018+ unsigned char sum[GR_SHA_LEN];
66019+ unsigned char sp_role[GR_SPROLE_LEN];
66020+ struct sprole_pw *sprole_pws;
66021+ dev_t segv_device;
66022+ ino_t segv_inode;
66023+ uid_t segv_uid;
66024+ __u16 num_sprole_pws;
66025+ __u16 mode;
66026+};
66027+
66028+struct gr_arg_wrapper {
66029+ struct gr_arg *arg;
66030+ __u32 version;
66031+ __u32 size;
66032+};
66033+
66034+struct subject_map {
66035+ struct acl_subject_label *user;
66036+ struct acl_subject_label *kernel;
66037+ struct subject_map *prev;
66038+ struct subject_map *next;
66039+};
66040+
66041+struct acl_subj_map_db {
66042+ struct subject_map **s_hash;
66043+ __u32 s_size;
66044+};
66045+
66046+/* End Data Structures Section */
66047+
66048+/* Hash functions generated by empirical testing by Brad Spengler
66049+ Makes good use of the low bits of the inode. Generally 0-1 times
66050+ in loop for successful match. 0-3 for unsuccessful match.
66051+ Shift/add algorithm with modulus of table size and an XOR*/
66052+
66053+static __inline__ unsigned int
66054+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
66055+{
66056+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
66057+}
66058+
66059+ static __inline__ unsigned int
66060+shash(const struct acl_subject_label *userp, const unsigned int sz)
66061+{
66062+ return ((const unsigned long)userp % sz);
66063+}
66064+
66065+static __inline__ unsigned int
66066+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
66067+{
66068+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
66069+}
66070+
66071+static __inline__ unsigned int
66072+nhash(const char *name, const __u16 len, const unsigned int sz)
66073+{
66074+ return full_name_hash((const unsigned char *)name, len) % sz;
66075+}
66076+
66077+#define FOR_EACH_ROLE_START(role) \
66078+ role = role_list; \
66079+ while (role) {
66080+
66081+#define FOR_EACH_ROLE_END(role) \
66082+ role = role->prev; \
66083+ }
66084+
66085+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
66086+ subj = NULL; \
66087+ iter = 0; \
66088+ while (iter < role->subj_hash_size) { \
66089+ if (subj == NULL) \
66090+ subj = role->subj_hash[iter]; \
66091+ if (subj == NULL) { \
66092+ iter++; \
66093+ continue; \
66094+ }
66095+
66096+#define FOR_EACH_SUBJECT_END(subj,iter) \
66097+ subj = subj->next; \
66098+ if (subj == NULL) \
66099+ iter++; \
66100+ }
66101+
66102+
66103+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
66104+ subj = role->hash->first; \
66105+ while (subj != NULL) {
66106+
66107+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
66108+ subj = subj->next; \
66109+ }
66110+
66111+#endif
66112+
66113diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
66114new file mode 100644
66115index 0000000..323ecf2
66116--- /dev/null
66117+++ b/include/linux/gralloc.h
66118@@ -0,0 +1,9 @@
66119+#ifndef __GRALLOC_H
66120+#define __GRALLOC_H
66121+
66122+void acl_free_all(void);
66123+int acl_alloc_stack_init(unsigned long size);
66124+void *acl_alloc(unsigned long len);
66125+void *acl_alloc_num(unsigned long num, unsigned long len);
66126+
66127+#endif
66128diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
66129new file mode 100644
66130index 0000000..70d6cd5
66131--- /dev/null
66132+++ b/include/linux/grdefs.h
66133@@ -0,0 +1,140 @@
66134+#ifndef GRDEFS_H
66135+#define GRDEFS_H
66136+
66137+/* Begin grsecurity status declarations */
66138+
66139+enum {
66140+ GR_READY = 0x01,
66141+ GR_STATUS_INIT = 0x00 // disabled state
66142+};
66143+
66144+/* Begin ACL declarations */
66145+
66146+/* Role flags */
66147+
66148+enum {
66149+ GR_ROLE_USER = 0x0001,
66150+ GR_ROLE_GROUP = 0x0002,
66151+ GR_ROLE_DEFAULT = 0x0004,
66152+ GR_ROLE_SPECIAL = 0x0008,
66153+ GR_ROLE_AUTH = 0x0010,
66154+ GR_ROLE_NOPW = 0x0020,
66155+ GR_ROLE_GOD = 0x0040,
66156+ GR_ROLE_LEARN = 0x0080,
66157+ GR_ROLE_TPE = 0x0100,
66158+ GR_ROLE_DOMAIN = 0x0200,
66159+ GR_ROLE_PAM = 0x0400,
66160+ GR_ROLE_PERSIST = 0x800
66161+};
66162+
66163+/* ACL Subject and Object mode flags */
66164+enum {
66165+ GR_DELETED = 0x80000000
66166+};
66167+
66168+/* ACL Object-only mode flags */
66169+enum {
66170+ GR_READ = 0x00000001,
66171+ GR_APPEND = 0x00000002,
66172+ GR_WRITE = 0x00000004,
66173+ GR_EXEC = 0x00000008,
66174+ GR_FIND = 0x00000010,
66175+ GR_INHERIT = 0x00000020,
66176+ GR_SETID = 0x00000040,
66177+ GR_CREATE = 0x00000080,
66178+ GR_DELETE = 0x00000100,
66179+ GR_LINK = 0x00000200,
66180+ GR_AUDIT_READ = 0x00000400,
66181+ GR_AUDIT_APPEND = 0x00000800,
66182+ GR_AUDIT_WRITE = 0x00001000,
66183+ GR_AUDIT_EXEC = 0x00002000,
66184+ GR_AUDIT_FIND = 0x00004000,
66185+ GR_AUDIT_INHERIT= 0x00008000,
66186+ GR_AUDIT_SETID = 0x00010000,
66187+ GR_AUDIT_CREATE = 0x00020000,
66188+ GR_AUDIT_DELETE = 0x00040000,
66189+ GR_AUDIT_LINK = 0x00080000,
66190+ GR_PTRACERD = 0x00100000,
66191+ GR_NOPTRACE = 0x00200000,
66192+ GR_SUPPRESS = 0x00400000,
66193+ GR_NOLEARN = 0x00800000,
66194+ GR_INIT_TRANSFER= 0x01000000
66195+};
66196+
66197+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
66198+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
66199+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
66200+
66201+/* ACL subject-only mode flags */
66202+enum {
66203+ GR_KILL = 0x00000001,
66204+ GR_VIEW = 0x00000002,
66205+ GR_PROTECTED = 0x00000004,
66206+ GR_LEARN = 0x00000008,
66207+ GR_OVERRIDE = 0x00000010,
66208+ /* just a placeholder, this mode is only used in userspace */
66209+ GR_DUMMY = 0x00000020,
66210+ GR_PROTSHM = 0x00000040,
66211+ GR_KILLPROC = 0x00000080,
66212+ GR_KILLIPPROC = 0x00000100,
66213+ /* just a placeholder, this mode is only used in userspace */
66214+ GR_NOTROJAN = 0x00000200,
66215+ GR_PROTPROCFD = 0x00000400,
66216+ GR_PROCACCT = 0x00000800,
66217+ GR_RELAXPTRACE = 0x00001000,
66218+ GR_NESTED = 0x00002000,
66219+ GR_INHERITLEARN = 0x00004000,
66220+ GR_PROCFIND = 0x00008000,
66221+ GR_POVERRIDE = 0x00010000,
66222+ GR_KERNELAUTH = 0x00020000,
66223+ GR_ATSECURE = 0x00040000,
66224+ GR_SHMEXEC = 0x00080000
66225+};
66226+
66227+enum {
66228+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
66229+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
66230+ GR_PAX_ENABLE_MPROTECT = 0x0004,
66231+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
66232+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
66233+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
66234+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
66235+ GR_PAX_DISABLE_MPROTECT = 0x0400,
66236+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
66237+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
66238+};
66239+
66240+enum {
66241+ GR_ID_USER = 0x01,
66242+ GR_ID_GROUP = 0x02,
66243+};
66244+
66245+enum {
66246+ GR_ID_ALLOW = 0x01,
66247+ GR_ID_DENY = 0x02,
66248+};
66249+
66250+#define GR_CRASH_RES 31
66251+#define GR_UIDTABLE_MAX 500
66252+
66253+/* begin resource learning section */
66254+enum {
66255+ GR_RLIM_CPU_BUMP = 60,
66256+ GR_RLIM_FSIZE_BUMP = 50000,
66257+ GR_RLIM_DATA_BUMP = 10000,
66258+ GR_RLIM_STACK_BUMP = 1000,
66259+ GR_RLIM_CORE_BUMP = 10000,
66260+ GR_RLIM_RSS_BUMP = 500000,
66261+ GR_RLIM_NPROC_BUMP = 1,
66262+ GR_RLIM_NOFILE_BUMP = 5,
66263+ GR_RLIM_MEMLOCK_BUMP = 50000,
66264+ GR_RLIM_AS_BUMP = 500000,
66265+ GR_RLIM_LOCKS_BUMP = 2,
66266+ GR_RLIM_SIGPENDING_BUMP = 5,
66267+ GR_RLIM_MSGQUEUE_BUMP = 10000,
66268+ GR_RLIM_NICE_BUMP = 1,
66269+ GR_RLIM_RTPRIO_BUMP = 1,
66270+ GR_RLIM_RTTIME_BUMP = 1000000
66271+};
66272+
66273+#endif
66274diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
66275new file mode 100644
66276index 0000000..e5817d7
66277--- /dev/null
66278+++ b/include/linux/grinternal.h
66279@@ -0,0 +1,218 @@
66280+#ifndef __GRINTERNAL_H
66281+#define __GRINTERNAL_H
66282+
66283+#ifdef CONFIG_GRKERNSEC
66284+
66285+#include <linux/fs.h>
66286+#include <linux/mnt_namespace.h>
66287+#include <linux/nsproxy.h>
66288+#include <linux/gracl.h>
66289+#include <linux/grdefs.h>
66290+#include <linux/grmsg.h>
66291+
66292+void gr_add_learn_entry(const char *fmt, ...)
66293+ __attribute__ ((format (printf, 1, 2)));
66294+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
66295+ const struct vfsmount *mnt);
66296+__u32 gr_check_create(const struct dentry *new_dentry,
66297+ const struct dentry *parent,
66298+ const struct vfsmount *mnt, const __u32 mode);
66299+int gr_check_protected_task(const struct task_struct *task);
66300+__u32 to_gr_audit(const __u32 reqmode);
66301+int gr_set_acls(const int type);
66302+int gr_apply_subject_to_task(struct task_struct *task);
66303+int gr_acl_is_enabled(void);
66304+char gr_roletype_to_char(void);
66305+
66306+void gr_handle_alertkill(struct task_struct *task);
66307+char *gr_to_filename(const struct dentry *dentry,
66308+ const struct vfsmount *mnt);
66309+char *gr_to_filename1(const struct dentry *dentry,
66310+ const struct vfsmount *mnt);
66311+char *gr_to_filename2(const struct dentry *dentry,
66312+ const struct vfsmount *mnt);
66313+char *gr_to_filename3(const struct dentry *dentry,
66314+ const struct vfsmount *mnt);
66315+
66316+extern int grsec_enable_harden_ptrace;
66317+extern int grsec_enable_link;
66318+extern int grsec_enable_fifo;
66319+extern int grsec_enable_shm;
66320+extern int grsec_enable_execlog;
66321+extern int grsec_enable_signal;
66322+extern int grsec_enable_audit_ptrace;
66323+extern int grsec_enable_forkfail;
66324+extern int grsec_enable_time;
66325+extern int grsec_enable_rofs;
66326+extern int grsec_enable_chroot_shmat;
66327+extern int grsec_enable_chroot_mount;
66328+extern int grsec_enable_chroot_double;
66329+extern int grsec_enable_chroot_pivot;
66330+extern int grsec_enable_chroot_chdir;
66331+extern int grsec_enable_chroot_chmod;
66332+extern int grsec_enable_chroot_mknod;
66333+extern int grsec_enable_chroot_fchdir;
66334+extern int grsec_enable_chroot_nice;
66335+extern int grsec_enable_chroot_execlog;
66336+extern int grsec_enable_chroot_caps;
66337+extern int grsec_enable_chroot_sysctl;
66338+extern int grsec_enable_chroot_unix;
66339+extern int grsec_enable_tpe;
66340+extern int grsec_tpe_gid;
66341+extern int grsec_enable_tpe_all;
66342+extern int grsec_enable_tpe_invert;
66343+extern int grsec_enable_socket_all;
66344+extern int grsec_socket_all_gid;
66345+extern int grsec_enable_socket_client;
66346+extern int grsec_socket_client_gid;
66347+extern int grsec_enable_socket_server;
66348+extern int grsec_socket_server_gid;
66349+extern int grsec_audit_gid;
66350+extern int grsec_enable_group;
66351+extern int grsec_enable_audit_textrel;
66352+extern int grsec_enable_log_rwxmaps;
66353+extern int grsec_enable_mount;
66354+extern int grsec_enable_chdir;
66355+extern int grsec_resource_logging;
66356+extern int grsec_enable_blackhole;
66357+extern int grsec_lastack_retries;
66358+extern int grsec_enable_brute;
66359+extern int grsec_lock;
66360+
66361+extern spinlock_t grsec_alert_lock;
66362+extern unsigned long grsec_alert_wtime;
66363+extern unsigned long grsec_alert_fyet;
66364+
66365+extern spinlock_t grsec_audit_lock;
66366+
66367+extern rwlock_t grsec_exec_file_lock;
66368+
66369+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
66370+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
66371+ (tsk)->exec_file->f_vfsmnt) : "/")
66372+
66373+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
66374+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
66375+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66376+
66377+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
66378+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
66379+ (tsk)->exec_file->f_vfsmnt) : "/")
66380+
66381+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
66382+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
66383+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66384+
66385+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
66386+
66387+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
66388+
66389+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
66390+ (task)->pid, (cred)->uid, \
66391+ (cred)->euid, (cred)->gid, (cred)->egid, \
66392+ gr_parent_task_fullpath(task), \
66393+ (task)->real_parent->comm, (task)->real_parent->pid, \
66394+ (pcred)->uid, (pcred)->euid, \
66395+ (pcred)->gid, (pcred)->egid
66396+
66397+#define GR_CHROOT_CAPS {{ \
66398+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
66399+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
66400+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
66401+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
66402+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
66403+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
66404+ CAP_TO_MASK(CAP_MAC_ADMIN) }}
66405+
66406+#define security_learn(normal_msg,args...) \
66407+({ \
66408+ read_lock(&grsec_exec_file_lock); \
66409+ gr_add_learn_entry(normal_msg "\n", ## args); \
66410+ read_unlock(&grsec_exec_file_lock); \
66411+})
66412+
66413+enum {
66414+ GR_DO_AUDIT,
66415+ GR_DONT_AUDIT,
66416+ GR_DONT_AUDIT_GOOD
66417+};
66418+
66419+enum {
66420+ GR_TTYSNIFF,
66421+ GR_RBAC,
66422+ GR_RBAC_STR,
66423+ GR_STR_RBAC,
66424+ GR_RBAC_MODE2,
66425+ GR_RBAC_MODE3,
66426+ GR_FILENAME,
66427+ GR_SYSCTL_HIDDEN,
66428+ GR_NOARGS,
66429+ GR_ONE_INT,
66430+ GR_ONE_INT_TWO_STR,
66431+ GR_ONE_STR,
66432+ GR_STR_INT,
66433+ GR_TWO_STR_INT,
66434+ GR_TWO_INT,
66435+ GR_TWO_U64,
66436+ GR_THREE_INT,
66437+ GR_FIVE_INT_TWO_STR,
66438+ GR_TWO_STR,
66439+ GR_THREE_STR,
66440+ GR_FOUR_STR,
66441+ GR_STR_FILENAME,
66442+ GR_FILENAME_STR,
66443+ GR_FILENAME_TWO_INT,
66444+ GR_FILENAME_TWO_INT_STR,
66445+ GR_TEXTREL,
66446+ GR_PTRACE,
66447+ GR_RESOURCE,
66448+ GR_CAP,
66449+ GR_SIG,
66450+ GR_SIG2,
66451+ GR_CRASH1,
66452+ GR_CRASH2,
66453+ GR_PSACCT,
66454+ GR_RWXMAP
66455+};
66456+
66457+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
66458+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
66459+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
66460+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
66461+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
66462+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
66463+#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)
66464+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
66465+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
66466+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
66467+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
66468+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
66469+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
66470+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
66471+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
66472+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
66473+#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)
66474+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
66475+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
66476+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
66477+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
66478+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
66479+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
66480+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
66481+#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)
66482+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
66483+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
66484+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
66485+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
66486+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
66487+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
66488+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
66489+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
66490+#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)
66491+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
66492+
66493+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
66494+
66495+#endif
66496+
66497+#endif
66498diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
66499new file mode 100644
66500index 0000000..9d5fd4a
66501--- /dev/null
66502+++ b/include/linux/grmsg.h
66503@@ -0,0 +1,108 @@
66504+#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"
66505+#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"
66506+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
66507+#define GR_STOPMOD_MSG "denied modification of module state by "
66508+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
66509+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
66510+#define GR_IOPERM_MSG "denied use of ioperm() by "
66511+#define GR_IOPL_MSG "denied use of iopl() by "
66512+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
66513+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
66514+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
66515+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
66516+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
66517+#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"
66518+#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"
66519+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
66520+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
66521+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
66522+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
66523+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
66524+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
66525+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
66526+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
66527+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
66528+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
66529+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
66530+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
66531+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
66532+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
66533+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
66534+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
66535+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
66536+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
66537+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
66538+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
66539+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
66540+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
66541+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
66542+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
66543+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
66544+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
66545+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
66546+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
66547+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
66548+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
66549+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
66550+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
66551+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
66552+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
66553+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
66554+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
66555+#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"
66556+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
66557+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
66558+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
66559+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
66560+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
66561+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
66562+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
66563+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
66564+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
66565+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
66566+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
66567+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
66568+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
66569+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
66570+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
66571+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
66572+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
66573+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
66574+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
66575+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
66576+#define GR_FAILFORK_MSG "failed fork with errno %s by "
66577+#define GR_NICE_CHROOT_MSG "denied priority change by "
66578+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
66579+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
66580+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
66581+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
66582+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
66583+#define GR_TIME_MSG "time set by "
66584+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
66585+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
66586+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
66587+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
66588+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
66589+#define GR_BIND_MSG "denied bind() by "
66590+#define GR_CONNECT_MSG "denied connect() by "
66591+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
66592+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
66593+#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"
66594+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
66595+#define GR_CAP_ACL_MSG "use of %s denied for "
66596+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
66597+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
66598+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
66599+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
66600+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
66601+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
66602+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
66603+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
66604+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
66605+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
66606+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
66607+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
66608+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
66609+#define GR_VM86_MSG "denied use of vm86 by "
66610+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
66611+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
66612diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
66613new file mode 100644
66614index 0000000..24676f4
66615--- /dev/null
66616+++ b/include/linux/grsecurity.h
66617@@ -0,0 +1,218 @@
66618+#ifndef GR_SECURITY_H
66619+#define GR_SECURITY_H
66620+#include <linux/fs.h>
66621+#include <linux/fs_struct.h>
66622+#include <linux/binfmts.h>
66623+#include <linux/gracl.h>
66624+#include <linux/compat.h>
66625+
66626+/* notify of brain-dead configs */
66627+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66628+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
66629+#endif
66630+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
66631+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
66632+#endif
66633+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66634+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66635+#endif
66636+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66637+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66638+#endif
66639+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
66640+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
66641+#endif
66642+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
66643+#error "CONFIG_PAX enabled, but no PaX options are enabled."
66644+#endif
66645+
66646+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
66647+void gr_handle_brute_check(void);
66648+void gr_handle_kernel_exploit(void);
66649+int gr_process_user_ban(void);
66650+
66651+char gr_roletype_to_char(void);
66652+
66653+int gr_acl_enable_at_secure(void);
66654+
66655+int gr_check_user_change(int real, int effective, int fs);
66656+int gr_check_group_change(int real, int effective, int fs);
66657+
66658+void gr_del_task_from_ip_table(struct task_struct *p);
66659+
66660+int gr_pid_is_chrooted(struct task_struct *p);
66661+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
66662+int gr_handle_chroot_nice(void);
66663+int gr_handle_chroot_sysctl(const int op);
66664+int gr_handle_chroot_setpriority(struct task_struct *p,
66665+ const int niceval);
66666+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
66667+int gr_handle_chroot_chroot(const struct dentry *dentry,
66668+ const struct vfsmount *mnt);
66669+void gr_handle_chroot_chdir(struct path *path);
66670+int gr_handle_chroot_chmod(const struct dentry *dentry,
66671+ const struct vfsmount *mnt, const int mode);
66672+int gr_handle_chroot_mknod(const struct dentry *dentry,
66673+ const struct vfsmount *mnt, const int mode);
66674+int gr_handle_chroot_mount(const struct dentry *dentry,
66675+ const struct vfsmount *mnt,
66676+ const char *dev_name);
66677+int gr_handle_chroot_pivot(void);
66678+int gr_handle_chroot_unix(const pid_t pid);
66679+
66680+int gr_handle_rawio(const struct inode *inode);
66681+
66682+void gr_handle_ioperm(void);
66683+void gr_handle_iopl(void);
66684+
66685+int gr_tpe_allow(const struct file *file);
66686+
66687+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
66688+void gr_clear_chroot_entries(struct task_struct *task);
66689+
66690+void gr_log_forkfail(const int retval);
66691+void gr_log_timechange(void);
66692+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
66693+void gr_log_chdir(const struct dentry *dentry,
66694+ const struct vfsmount *mnt);
66695+void gr_log_chroot_exec(const struct dentry *dentry,
66696+ const struct vfsmount *mnt);
66697+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
66698+#ifdef CONFIG_COMPAT
66699+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
66700+#endif
66701+void gr_log_remount(const char *devname, const int retval);
66702+void gr_log_unmount(const char *devname, const int retval);
66703+void gr_log_mount(const char *from, const char *to, const int retval);
66704+void gr_log_textrel(struct vm_area_struct *vma);
66705+void gr_log_rwxmmap(struct file *file);
66706+void gr_log_rwxmprotect(struct file *file);
66707+
66708+int gr_handle_follow_link(const struct inode *parent,
66709+ const struct inode *inode,
66710+ const struct dentry *dentry,
66711+ const struct vfsmount *mnt);
66712+int gr_handle_fifo(const struct dentry *dentry,
66713+ const struct vfsmount *mnt,
66714+ const struct dentry *dir, const int flag,
66715+ const int acc_mode);
66716+int gr_handle_hardlink(const struct dentry *dentry,
66717+ const struct vfsmount *mnt,
66718+ struct inode *inode,
66719+ const int mode, const char *to);
66720+
66721+int gr_is_capable(const int cap);
66722+int gr_is_capable_nolog(const int cap);
66723+void gr_learn_resource(const struct task_struct *task, const int limit,
66724+ const unsigned long wanted, const int gt);
66725+void gr_copy_label(struct task_struct *tsk);
66726+void gr_handle_crash(struct task_struct *task, const int sig);
66727+int gr_handle_signal(const struct task_struct *p, const int sig);
66728+int gr_check_crash_uid(const uid_t uid);
66729+int gr_check_protected_task(const struct task_struct *task);
66730+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
66731+int gr_acl_handle_mmap(const struct file *file,
66732+ const unsigned long prot);
66733+int gr_acl_handle_mprotect(const struct file *file,
66734+ const unsigned long prot);
66735+int gr_check_hidden_task(const struct task_struct *tsk);
66736+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
66737+ const struct vfsmount *mnt);
66738+__u32 gr_acl_handle_utime(const struct dentry *dentry,
66739+ const struct vfsmount *mnt);
66740+__u32 gr_acl_handle_access(const struct dentry *dentry,
66741+ const struct vfsmount *mnt, const int fmode);
66742+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
66743+ const struct vfsmount *mnt, mode_t mode);
66744+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
66745+ const struct vfsmount *mnt, mode_t mode);
66746+__u32 gr_acl_handle_chown(const struct dentry *dentry,
66747+ const struct vfsmount *mnt);
66748+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
66749+ const struct vfsmount *mnt);
66750+int gr_handle_ptrace(struct task_struct *task, const long request);
66751+int gr_handle_proc_ptrace(struct task_struct *task);
66752+__u32 gr_acl_handle_execve(const struct dentry *dentry,
66753+ const struct vfsmount *mnt);
66754+int gr_check_crash_exec(const struct file *filp);
66755+int gr_acl_is_enabled(void);
66756+void gr_set_kernel_label(struct task_struct *task);
66757+void gr_set_role_label(struct task_struct *task, const uid_t uid,
66758+ const gid_t gid);
66759+int gr_set_proc_label(const struct dentry *dentry,
66760+ const struct vfsmount *mnt,
66761+ const int unsafe_share);
66762+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
66763+ const struct vfsmount *mnt);
66764+__u32 gr_acl_handle_open(const struct dentry *dentry,
66765+ const struct vfsmount *mnt, int acc_mode);
66766+__u32 gr_acl_handle_creat(const struct dentry *dentry,
66767+ const struct dentry *p_dentry,
66768+ const struct vfsmount *p_mnt,
66769+ int open_flags, int acc_mode, const int imode);
66770+void gr_handle_create(const struct dentry *dentry,
66771+ const struct vfsmount *mnt);
66772+void gr_handle_proc_create(const struct dentry *dentry,
66773+ const struct inode *inode);
66774+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
66775+ const struct dentry *parent_dentry,
66776+ const struct vfsmount *parent_mnt,
66777+ const int mode);
66778+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
66779+ const struct dentry *parent_dentry,
66780+ const struct vfsmount *parent_mnt);
66781+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
66782+ const struct vfsmount *mnt);
66783+void gr_handle_delete(const ino_t ino, const dev_t dev);
66784+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
66785+ const struct vfsmount *mnt);
66786+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
66787+ const struct dentry *parent_dentry,
66788+ const struct vfsmount *parent_mnt,
66789+ const char *from);
66790+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
66791+ const struct dentry *parent_dentry,
66792+ const struct vfsmount *parent_mnt,
66793+ const struct dentry *old_dentry,
66794+ const struct vfsmount *old_mnt, const char *to);
66795+int gr_acl_handle_rename(struct dentry *new_dentry,
66796+ struct dentry *parent_dentry,
66797+ const struct vfsmount *parent_mnt,
66798+ struct dentry *old_dentry,
66799+ struct inode *old_parent_inode,
66800+ struct vfsmount *old_mnt, const char *newname);
66801+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
66802+ struct dentry *old_dentry,
66803+ struct dentry *new_dentry,
66804+ struct vfsmount *mnt, const __u8 replace);
66805+__u32 gr_check_link(const struct dentry *new_dentry,
66806+ const struct dentry *parent_dentry,
66807+ const struct vfsmount *parent_mnt,
66808+ const struct dentry *old_dentry,
66809+ const struct vfsmount *old_mnt);
66810+int gr_acl_handle_filldir(const struct file *file, const char *name,
66811+ const unsigned int namelen, const ino_t ino);
66812+
66813+__u32 gr_acl_handle_unix(const struct dentry *dentry,
66814+ const struct vfsmount *mnt);
66815+void gr_acl_handle_exit(void);
66816+void gr_acl_handle_psacct(struct task_struct *task, const long code);
66817+int gr_acl_handle_procpidmem(const struct task_struct *task);
66818+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
66819+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
66820+void gr_audit_ptrace(struct task_struct *task);
66821+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
66822+
66823+#ifdef CONFIG_GRKERNSEC
66824+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
66825+void gr_handle_vm86(void);
66826+void gr_handle_mem_readwrite(u64 from, u64 to);
66827+
66828+extern int grsec_enable_dmesg;
66829+extern int grsec_disable_privio;
66830+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66831+extern int grsec_enable_chroot_findtask;
66832+#endif
66833+#endif
66834+
66835+#endif
66836diff --git a/include/linux/hdpu_features.h b/include/linux/hdpu_features.h
66837index 6a87154..a3ce57b 100644
66838--- a/include/linux/hdpu_features.h
66839+++ b/include/linux/hdpu_features.h
66840@@ -3,7 +3,7 @@
66841 struct cpustate_t {
66842 spinlock_t lock;
66843 int excl;
66844- int open_count;
66845+ atomic_t open_count;
66846 unsigned char cached_val;
66847 int inited;
66848 unsigned long *set_addr;
66849diff --git a/include/linux/highmem.h b/include/linux/highmem.h
66850index 211ff44..00ab6d7 100644
66851--- a/include/linux/highmem.h
66852+++ b/include/linux/highmem.h
66853@@ -137,6 +137,18 @@ static inline void clear_highpage(struct page *page)
66854 kunmap_atomic(kaddr, KM_USER0);
66855 }
66856
66857+static inline void sanitize_highpage(struct page *page)
66858+{
66859+ void *kaddr;
66860+ unsigned long flags;
66861+
66862+ local_irq_save(flags);
66863+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
66864+ clear_page(kaddr);
66865+ kunmap_atomic(kaddr, KM_CLEARPAGE);
66866+ local_irq_restore(flags);
66867+}
66868+
66869 static inline void zero_user_segments(struct page *page,
66870 unsigned start1, unsigned end1,
66871 unsigned start2, unsigned end2)
66872diff --git a/include/linux/i2c.h b/include/linux/i2c.h
66873index 7b40cda..24eb44e 100644
66874--- a/include/linux/i2c.h
66875+++ b/include/linux/i2c.h
66876@@ -325,6 +325,7 @@ struct i2c_algorithm {
66877 /* To determine what the adapter supports */
66878 u32 (*functionality) (struct i2c_adapter *);
66879 };
66880+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
66881
66882 /*
66883 * i2c_adapter is the structure used to identify a physical i2c bus along
66884diff --git a/include/linux/i2o.h b/include/linux/i2o.h
66885index 4c4e57d..f3c5303 100644
66886--- a/include/linux/i2o.h
66887+++ b/include/linux/i2o.h
66888@@ -564,7 +564,7 @@ struct i2o_controller {
66889 struct i2o_device *exec; /* Executive */
66890 #if BITS_PER_LONG == 64
66891 spinlock_t context_list_lock; /* lock for context_list */
66892- atomic_t context_list_counter; /* needed for unique contexts */
66893+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
66894 struct list_head context_list; /* list of context id's
66895 and pointers */
66896 #endif
66897diff --git a/include/linux/init_task.h b/include/linux/init_task.h
66898index 21a6f5d..dc42eab 100644
66899--- a/include/linux/init_task.h
66900+++ b/include/linux/init_task.h
66901@@ -83,6 +83,12 @@ extern struct group_info init_groups;
66902 #define INIT_IDS
66903 #endif
66904
66905+#ifdef CONFIG_X86
66906+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
66907+#else
66908+#define INIT_TASK_THREAD_INFO
66909+#endif
66910+
66911 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
66912 /*
66913 * Because of the reduced scope of CAP_SETPCAP when filesystem
66914@@ -156,6 +162,7 @@ extern struct cred init_cred;
66915 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
66916 .comm = "swapper", \
66917 .thread = INIT_THREAD, \
66918+ INIT_TASK_THREAD_INFO \
66919 .fs = &init_fs, \
66920 .files = &init_files, \
66921 .signal = &init_signals, \
66922diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
66923index 4f0a72a..a849599 100644
66924--- a/include/linux/intel-iommu.h
66925+++ b/include/linux/intel-iommu.h
66926@@ -296,7 +296,7 @@ struct iommu_flush {
66927 u8 fm, u64 type);
66928 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
66929 unsigned int size_order, u64 type);
66930-};
66931+} __no_const;
66932
66933 enum {
66934 SR_DMAR_FECTL_REG,
66935diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
66936index c739150..be577b5 100644
66937--- a/include/linux/interrupt.h
66938+++ b/include/linux/interrupt.h
66939@@ -369,7 +369,7 @@ enum
66940 /* map softirq index to softirq name. update 'softirq_to_name' in
66941 * kernel/softirq.c when adding a new softirq.
66942 */
66943-extern char *softirq_to_name[NR_SOFTIRQS];
66944+extern const char * const softirq_to_name[NR_SOFTIRQS];
66945
66946 /* softirq mask and active fields moved to irq_cpustat_t in
66947 * asm/hardirq.h to get better cache usage. KAO
66948@@ -377,12 +377,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
66949
66950 struct softirq_action
66951 {
66952- void (*action)(struct softirq_action *);
66953+ void (*action)(void);
66954 };
66955
66956 asmlinkage void do_softirq(void);
66957 asmlinkage void __do_softirq(void);
66958-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
66959+extern void open_softirq(int nr, void (*action)(void));
66960 extern void softirq_init(void);
66961 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
66962 extern void raise_softirq_irqoff(unsigned int nr);
66963diff --git a/include/linux/irq.h b/include/linux/irq.h
66964index 9e5f45a..025865b 100644
66965--- a/include/linux/irq.h
66966+++ b/include/linux/irq.h
66967@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
66968 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
66969 bool boot)
66970 {
66971+#ifdef CONFIG_CPUMASK_OFFSTACK
66972 gfp_t gfp = GFP_ATOMIC;
66973
66974 if (boot)
66975 gfp = GFP_NOWAIT;
66976
66977-#ifdef CONFIG_CPUMASK_OFFSTACK
66978 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
66979 return false;
66980
66981diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
66982index 7922742..27306a2 100644
66983--- a/include/linux/kallsyms.h
66984+++ b/include/linux/kallsyms.h
66985@@ -15,7 +15,8 @@
66986
66987 struct module;
66988
66989-#ifdef CONFIG_KALLSYMS
66990+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
66991+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66992 /* Lookup the address for a symbol. Returns 0 if not found. */
66993 unsigned long kallsyms_lookup_name(const char *name);
66994
66995@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
66996 /* Stupid that this does nothing, but I didn't create this mess. */
66997 #define __print_symbol(fmt, addr)
66998 #endif /*CONFIG_KALLSYMS*/
66999+#else /* when included by kallsyms.c, vsnprintf.c, or
67000+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
67001+extern void __print_symbol(const char *fmt, unsigned long address);
67002+extern int sprint_symbol(char *buffer, unsigned long address);
67003+const char *kallsyms_lookup(unsigned long addr,
67004+ unsigned long *symbolsize,
67005+ unsigned long *offset,
67006+ char **modname, char *namebuf);
67007+#endif
67008
67009 /* This macro allows us to keep printk typechecking */
67010 static void __check_printsym_format(const char *fmt, ...)
67011diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
67012index 6adcc29..13369e8 100644
67013--- a/include/linux/kgdb.h
67014+++ b/include/linux/kgdb.h
67015@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
67016
67017 extern int kgdb_connected;
67018
67019-extern atomic_t kgdb_setting_breakpoint;
67020-extern atomic_t kgdb_cpu_doing_single_step;
67021+extern atomic_unchecked_t kgdb_setting_breakpoint;
67022+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
67023
67024 extern struct task_struct *kgdb_usethread;
67025 extern struct task_struct *kgdb_contthread;
67026@@ -235,7 +235,7 @@ struct kgdb_arch {
67027 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
67028 void (*remove_all_hw_break)(void);
67029 void (*correct_hw_break)(void);
67030-};
67031+} __do_const;
67032
67033 /**
67034 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
67035@@ -257,14 +257,14 @@ struct kgdb_io {
67036 int (*init) (void);
67037 void (*pre_exception) (void);
67038 void (*post_exception) (void);
67039-};
67040+} __do_const;
67041
67042-extern struct kgdb_arch arch_kgdb_ops;
67043+extern const struct kgdb_arch arch_kgdb_ops;
67044
67045 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
67046
67047-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
67048-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
67049+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
67050+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
67051
67052 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
67053 extern int kgdb_mem2hex(char *mem, char *buf, int count);
67054diff --git a/include/linux/kmod.h b/include/linux/kmod.h
67055index 384ca8b..83dd97d 100644
67056--- a/include/linux/kmod.h
67057+++ b/include/linux/kmod.h
67058@@ -31,6 +31,8 @@
67059 * usually useless though. */
67060 extern int __request_module(bool wait, const char *name, ...) \
67061 __attribute__((format(printf, 2, 3)));
67062+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
67063+ __attribute__((format(printf, 3, 4)));
67064 #define request_module(mod...) __request_module(true, mod)
67065 #define request_module_nowait(mod...) __request_module(false, mod)
67066 #define try_then_request_module(x, mod...) \
67067diff --git a/include/linux/kobject.h b/include/linux/kobject.h
67068index 58ae8e0..3950d3c 100644
67069--- a/include/linux/kobject.h
67070+++ b/include/linux/kobject.h
67071@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
67072
67073 struct kobj_type {
67074 void (*release)(struct kobject *kobj);
67075- struct sysfs_ops *sysfs_ops;
67076+ const struct sysfs_ops *sysfs_ops;
67077 struct attribute **default_attrs;
67078 };
67079
67080@@ -118,9 +118,9 @@ struct kobj_uevent_env {
67081 };
67082
67083 struct kset_uevent_ops {
67084- int (*filter)(struct kset *kset, struct kobject *kobj);
67085- const char *(*name)(struct kset *kset, struct kobject *kobj);
67086- int (*uevent)(struct kset *kset, struct kobject *kobj,
67087+ int (* const filter)(struct kset *kset, struct kobject *kobj);
67088+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
67089+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
67090 struct kobj_uevent_env *env);
67091 };
67092
67093@@ -132,7 +132,7 @@ struct kobj_attribute {
67094 const char *buf, size_t count);
67095 };
67096
67097-extern struct sysfs_ops kobj_sysfs_ops;
67098+extern const struct sysfs_ops kobj_sysfs_ops;
67099
67100 /**
67101 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
67102@@ -155,14 +155,14 @@ struct kset {
67103 struct list_head list;
67104 spinlock_t list_lock;
67105 struct kobject kobj;
67106- struct kset_uevent_ops *uevent_ops;
67107+ const struct kset_uevent_ops *uevent_ops;
67108 };
67109
67110 extern void kset_init(struct kset *kset);
67111 extern int __must_check kset_register(struct kset *kset);
67112 extern void kset_unregister(struct kset *kset);
67113 extern struct kset * __must_check kset_create_and_add(const char *name,
67114- struct kset_uevent_ops *u,
67115+ const struct kset_uevent_ops *u,
67116 struct kobject *parent_kobj);
67117
67118 static inline struct kset *to_kset(struct kobject *kobj)
67119diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
67120index c728a50..752d821 100644
67121--- a/include/linux/kvm_host.h
67122+++ b/include/linux/kvm_host.h
67123@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
67124 void vcpu_load(struct kvm_vcpu *vcpu);
67125 void vcpu_put(struct kvm_vcpu *vcpu);
67126
67127-int kvm_init(void *opaque, unsigned int vcpu_size,
67128+int kvm_init(const void *opaque, unsigned int vcpu_size,
67129 struct module *module);
67130 void kvm_exit(void);
67131
67132@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
67133 struct kvm_guest_debug *dbg);
67134 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
67135
67136-int kvm_arch_init(void *opaque);
67137+int kvm_arch_init(const void *opaque);
67138 void kvm_arch_exit(void);
67139
67140 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
67141diff --git a/include/linux/libata.h b/include/linux/libata.h
67142index a069916..223edde 100644
67143--- a/include/linux/libata.h
67144+++ b/include/linux/libata.h
67145@@ -525,11 +525,11 @@ struct ata_ioports {
67146
67147 struct ata_host {
67148 spinlock_t lock;
67149- struct device *dev;
67150+ struct device *dev;
67151 void __iomem * const *iomap;
67152 unsigned int n_ports;
67153 void *private_data;
67154- struct ata_port_operations *ops;
67155+ const struct ata_port_operations *ops;
67156 unsigned long flags;
67157 #ifdef CONFIG_ATA_ACPI
67158 acpi_handle acpi_handle;
67159@@ -710,7 +710,7 @@ struct ata_link {
67160
67161 struct ata_port {
67162 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
67163- struct ata_port_operations *ops;
67164+ const struct ata_port_operations *ops;
67165 spinlock_t *lock;
67166 /* Flags owned by the EH context. Only EH should touch these once the
67167 port is active */
67168@@ -884,7 +884,7 @@ struct ata_port_operations {
67169 * fields must be pointers.
67170 */
67171 const struct ata_port_operations *inherits;
67172-};
67173+} __do_const;
67174
67175 struct ata_port_info {
67176 unsigned long flags;
67177@@ -892,7 +892,7 @@ struct ata_port_info {
67178 unsigned long pio_mask;
67179 unsigned long mwdma_mask;
67180 unsigned long udma_mask;
67181- struct ata_port_operations *port_ops;
67182+ const struct ata_port_operations *port_ops;
67183 void *private_data;
67184 };
67185
67186@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timing_normal[];
67187 extern const unsigned long sata_deb_timing_hotplug[];
67188 extern const unsigned long sata_deb_timing_long[];
67189
67190-extern struct ata_port_operations ata_dummy_port_ops;
67191+extern const struct ata_port_operations ata_dummy_port_ops;
67192 extern const struct ata_port_info ata_dummy_port_info;
67193
67194 static inline const unsigned long *
67195@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_host *host, int irq,
67196 struct scsi_host_template *sht);
67197 extern void ata_host_detach(struct ata_host *host);
67198 extern void ata_host_init(struct ata_host *, struct device *,
67199- unsigned long, struct ata_port_operations *);
67200+ unsigned long, const struct ata_port_operations *);
67201 extern int ata_scsi_detect(struct scsi_host_template *sht);
67202 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
67203 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
67204diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h
67205index fbc48f8..0886e57 100644
67206--- a/include/linux/lockd/bind.h
67207+++ b/include/linux/lockd/bind.h
67208@@ -23,13 +23,13 @@ struct svc_rqst;
67209 * This is the set of functions for lockd->nfsd communication
67210 */
67211 struct nlmsvc_binding {
67212- __be32 (*fopen)(struct svc_rqst *,
67213+ __be32 (* const fopen)(struct svc_rqst *,
67214 struct nfs_fh *,
67215 struct file **);
67216- void (*fclose)(struct file *);
67217+ void (* const fclose)(struct file *);
67218 };
67219
67220-extern struct nlmsvc_binding * nlmsvc_ops;
67221+extern const struct nlmsvc_binding * nlmsvc_ops;
67222
67223 /*
67224 * Similar to nfs_client_initdata, but without the NFS-specific
67225diff --git a/include/linux/mca.h b/include/linux/mca.h
67226index 3797270..7765ede 100644
67227--- a/include/linux/mca.h
67228+++ b/include/linux/mca.h
67229@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
67230 int region);
67231 void * (*mca_transform_memory)(struct mca_device *,
67232 void *memory);
67233-};
67234+} __no_const;
67235
67236 struct mca_bus {
67237 u64 default_dma_mask;
67238diff --git a/include/linux/memory.h b/include/linux/memory.h
67239index 37fa19b..b597c85 100644
67240--- a/include/linux/memory.h
67241+++ b/include/linux/memory.h
67242@@ -108,7 +108,7 @@ struct memory_accessor {
67243 size_t count);
67244 ssize_t (*write)(struct memory_accessor *, const char *buf,
67245 off_t offset, size_t count);
67246-};
67247+} __no_const;
67248
67249 /*
67250 * Kernel text modification mutex, used for code patching. Users of this lock
67251diff --git a/include/linux/mm.h b/include/linux/mm.h
67252index 11e5be6..1ff2423 100644
67253--- a/include/linux/mm.h
67254+++ b/include/linux/mm.h
67255@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void *objp);
67256
67257 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
67258 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
67259+
67260+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
67261+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
67262+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
67263+#else
67264 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
67265+#endif
67266+
67267 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
67268 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
67269
67270@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
67271 int set_page_dirty_lock(struct page *page);
67272 int clear_page_dirty_for_io(struct page *page);
67273
67274-/* Is the vma a continuation of the stack vma above it? */
67275-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
67276-{
67277- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
67278-}
67279-
67280 extern unsigned long move_page_tables(struct vm_area_struct *vma,
67281 unsigned long old_addr, struct vm_area_struct *new_vma,
67282 unsigned long new_addr, unsigned long len);
67283@@ -890,6 +891,8 @@ struct shrinker {
67284 extern void register_shrinker(struct shrinker *);
67285 extern void unregister_shrinker(struct shrinker *);
67286
67287+pgprot_t vm_get_page_prot(unsigned long vm_flags);
67288+
67289 int vma_wants_writenotify(struct vm_area_struct *vma);
67290
67291 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
67292@@ -1162,6 +1165,7 @@ out:
67293 }
67294
67295 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
67296+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
67297
67298 extern unsigned long do_brk(unsigned long, unsigned long);
67299
67300@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
67301 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
67302 struct vm_area_struct **pprev);
67303
67304+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
67305+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
67306+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
67307+
67308 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
67309 NULL if none. Assume start_addr < end_addr. */
67310 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
67311@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
67312 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
67313 }
67314
67315-pgprot_t vm_get_page_prot(unsigned long vm_flags);
67316 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
67317 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
67318 unsigned long pfn, unsigned long size, pgprot_t);
67319@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long pfn, int trapno);
67320 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
67321 extern int sysctl_memory_failure_early_kill;
67322 extern int sysctl_memory_failure_recovery;
67323-extern atomic_long_t mce_bad_pages;
67324+extern atomic_long_unchecked_t mce_bad_pages;
67325+
67326+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67327+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
67328+#else
67329+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
67330+#endif
67331
67332 #endif /* __KERNEL__ */
67333 #endif /* _LINUX_MM_H */
67334diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
67335index 9d12ed5..8023125 100644
67336--- a/include/linux/mm_types.h
67337+++ b/include/linux/mm_types.h
67338@@ -186,6 +186,8 @@ struct vm_area_struct {
67339 #ifdef CONFIG_NUMA
67340 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
67341 #endif
67342+
67343+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
67344 };
67345
67346 struct core_thread {
67347@@ -287,6 +289,24 @@ struct mm_struct {
67348 #ifdef CONFIG_MMU_NOTIFIER
67349 struct mmu_notifier_mm *mmu_notifier_mm;
67350 #endif
67351+
67352+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67353+ unsigned long pax_flags;
67354+#endif
67355+
67356+#ifdef CONFIG_PAX_DLRESOLVE
67357+ unsigned long call_dl_resolve;
67358+#endif
67359+
67360+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
67361+ unsigned long call_syscall;
67362+#endif
67363+
67364+#ifdef CONFIG_PAX_ASLR
67365+ unsigned long delta_mmap; /* randomized offset */
67366+ unsigned long delta_stack; /* randomized offset */
67367+#endif
67368+
67369 };
67370
67371 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
67372diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
67373index 4e02ee2..afb159e 100644
67374--- a/include/linux/mmu_notifier.h
67375+++ b/include/linux/mmu_notifier.h
67376@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
67377 */
67378 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
67379 ({ \
67380- pte_t __pte; \
67381+ pte_t ___pte; \
67382 struct vm_area_struct *___vma = __vma; \
67383 unsigned long ___address = __address; \
67384- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
67385+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
67386 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
67387- __pte; \
67388+ ___pte; \
67389 })
67390
67391 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
67392diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
67393index 6c31a2a..4b0e930 100644
67394--- a/include/linux/mmzone.h
67395+++ b/include/linux/mmzone.h
67396@@ -350,7 +350,7 @@ struct zone {
67397 unsigned long flags; /* zone flags, see below */
67398
67399 /* Zone statistics */
67400- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67401+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67402
67403 /*
67404 * prev_priority holds the scanning priority for this zone. It is
67405diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
67406index f58e9d8..3503935 100644
67407--- a/include/linux/mod_devicetable.h
67408+++ b/include/linux/mod_devicetable.h
67409@@ -12,7 +12,7 @@
67410 typedef unsigned long kernel_ulong_t;
67411 #endif
67412
67413-#define PCI_ANY_ID (~0)
67414+#define PCI_ANY_ID ((__u16)~0)
67415
67416 struct pci_device_id {
67417 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
67418@@ -131,7 +131,7 @@ struct usb_device_id {
67419 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
67420 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
67421
67422-#define HID_ANY_ID (~0)
67423+#define HID_ANY_ID (~0U)
67424
67425 struct hid_device_id {
67426 __u16 bus;
67427diff --git a/include/linux/module.h b/include/linux/module.h
67428index 482efc8..642032b 100644
67429--- a/include/linux/module.h
67430+++ b/include/linux/module.h
67431@@ -16,6 +16,7 @@
67432 #include <linux/kobject.h>
67433 #include <linux/moduleparam.h>
67434 #include <linux/tracepoint.h>
67435+#include <linux/fs.h>
67436
67437 #include <asm/local.h>
67438 #include <asm/module.h>
67439@@ -287,16 +288,16 @@ struct module
67440 int (*init)(void);
67441
67442 /* If this is non-NULL, vfree after init() returns */
67443- void *module_init;
67444+ void *module_init_rx, *module_init_rw;
67445
67446 /* Here is the actual code + data, vfree'd on unload. */
67447- void *module_core;
67448+ void *module_core_rx, *module_core_rw;
67449
67450 /* Here are the sizes of the init and core sections */
67451- unsigned int init_size, core_size;
67452+ unsigned int init_size_rw, core_size_rw;
67453
67454 /* The size of the executable code in each section. */
67455- unsigned int init_text_size, core_text_size;
67456+ unsigned int init_size_rx, core_size_rx;
67457
67458 /* Arch-specific module values */
67459 struct mod_arch_specific arch;
67460@@ -345,6 +346,10 @@ struct module
67461 #ifdef CONFIG_EVENT_TRACING
67462 struct ftrace_event_call *trace_events;
67463 unsigned int num_trace_events;
67464+ struct file_operations trace_id;
67465+ struct file_operations trace_enable;
67466+ struct file_operations trace_format;
67467+ struct file_operations trace_filter;
67468 #endif
67469 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
67470 unsigned long *ftrace_callsites;
67471@@ -393,16 +398,46 @@ struct module *__module_address(unsigned long addr);
67472 bool is_module_address(unsigned long addr);
67473 bool is_module_text_address(unsigned long addr);
67474
67475+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
67476+{
67477+
67478+#ifdef CONFIG_PAX_KERNEXEC
67479+ if (ktla_ktva(addr) >= (unsigned long)start &&
67480+ ktla_ktva(addr) < (unsigned long)start + size)
67481+ return 1;
67482+#endif
67483+
67484+ return ((void *)addr >= start && (void *)addr < start + size);
67485+}
67486+
67487+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
67488+{
67489+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
67490+}
67491+
67492+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
67493+{
67494+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
67495+}
67496+
67497+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
67498+{
67499+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
67500+}
67501+
67502+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
67503+{
67504+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
67505+}
67506+
67507 static inline int within_module_core(unsigned long addr, struct module *mod)
67508 {
67509- return (unsigned long)mod->module_core <= addr &&
67510- addr < (unsigned long)mod->module_core + mod->core_size;
67511+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
67512 }
67513
67514 static inline int within_module_init(unsigned long addr, struct module *mod)
67515 {
67516- return (unsigned long)mod->module_init <= addr &&
67517- addr < (unsigned long)mod->module_init + mod->init_size;
67518+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
67519 }
67520
67521 /* Search for module by name: must hold module_mutex. */
67522diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
67523index c1f40c2..682ca53 100644
67524--- a/include/linux/moduleloader.h
67525+++ b/include/linux/moduleloader.h
67526@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
67527 sections. Returns NULL on failure. */
67528 void *module_alloc(unsigned long size);
67529
67530+#ifdef CONFIG_PAX_KERNEXEC
67531+void *module_alloc_exec(unsigned long size);
67532+#else
67533+#define module_alloc_exec(x) module_alloc(x)
67534+#endif
67535+
67536 /* Free memory returned from module_alloc. */
67537 void module_free(struct module *mod, void *module_region);
67538
67539+#ifdef CONFIG_PAX_KERNEXEC
67540+void module_free_exec(struct module *mod, void *module_region);
67541+#else
67542+#define module_free_exec(x, y) module_free((x), (y))
67543+#endif
67544+
67545 /* Apply the given relocation to the (simplified) ELF. Return -error
67546 or 0. */
67547 int apply_relocate(Elf_Shdr *sechdrs,
67548diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
67549index 82a9124..8a5f622 100644
67550--- a/include/linux/moduleparam.h
67551+++ b/include/linux/moduleparam.h
67552@@ -132,7 +132,7 @@ struct kparam_array
67553
67554 /* Actually copy string: maxlen param is usually sizeof(string). */
67555 #define module_param_string(name, string, len, perm) \
67556- static const struct kparam_string __param_string_##name \
67557+ static const struct kparam_string __param_string_##name __used \
67558 = { len, string }; \
67559 __module_param_call(MODULE_PARAM_PREFIX, name, \
67560 param_set_copystring, param_get_string, \
67561@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp);
67562
67563 /* Comma-separated array: *nump is set to number they actually specified. */
67564 #define module_param_array_named(name, array, type, nump, perm) \
67565- static const struct kparam_array __param_arr_##name \
67566+ static const struct kparam_array __param_arr_##name __used \
67567 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
67568 sizeof(array[0]), array }; \
67569 __module_param_call(MODULE_PARAM_PREFIX, name, \
67570diff --git a/include/linux/mutex.h b/include/linux/mutex.h
67571index 878cab4..c92cb3e 100644
67572--- a/include/linux/mutex.h
67573+++ b/include/linux/mutex.h
67574@@ -51,7 +51,7 @@ struct mutex {
67575 spinlock_t wait_lock;
67576 struct list_head wait_list;
67577 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
67578- struct thread_info *owner;
67579+ struct task_struct *owner;
67580 #endif
67581 #ifdef CONFIG_DEBUG_MUTEXES
67582 const char *name;
67583diff --git a/include/linux/namei.h b/include/linux/namei.h
67584index ec0f607..d19e675 100644
67585--- a/include/linux/namei.h
67586+++ b/include/linux/namei.h
67587@@ -22,7 +22,7 @@ struct nameidata {
67588 unsigned int flags;
67589 int last_type;
67590 unsigned depth;
67591- char *saved_names[MAX_NESTED_LINKS + 1];
67592+ const char *saved_names[MAX_NESTED_LINKS + 1];
67593
67594 /* Intent data */
67595 union {
67596@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
67597 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
67598 extern void unlock_rename(struct dentry *, struct dentry *);
67599
67600-static inline void nd_set_link(struct nameidata *nd, char *path)
67601+static inline void nd_set_link(struct nameidata *nd, const char *path)
67602 {
67603 nd->saved_names[nd->depth] = path;
67604 }
67605
67606-static inline char *nd_get_link(struct nameidata *nd)
67607+static inline const char *nd_get_link(const struct nameidata *nd)
67608 {
67609 return nd->saved_names[nd->depth];
67610 }
67611diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
67612index 9d7e8f7..04428c5 100644
67613--- a/include/linux/netdevice.h
67614+++ b/include/linux/netdevice.h
67615@@ -637,6 +637,7 @@ struct net_device_ops {
67616 u16 xid);
67617 #endif
67618 };
67619+typedef struct net_device_ops __no_const net_device_ops_no_const;
67620
67621 /*
67622 * The DEVICE structure.
67623diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
67624new file mode 100644
67625index 0000000..33f4af8
67626--- /dev/null
67627+++ b/include/linux/netfilter/xt_gradm.h
67628@@ -0,0 +1,9 @@
67629+#ifndef _LINUX_NETFILTER_XT_GRADM_H
67630+#define _LINUX_NETFILTER_XT_GRADM_H 1
67631+
67632+struct xt_gradm_mtinfo {
67633+ __u16 flags;
67634+ __u16 invflags;
67635+};
67636+
67637+#endif
67638diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
67639index b359c4a..c08b334 100644
67640--- a/include/linux/nodemask.h
67641+++ b/include/linux/nodemask.h
67642@@ -464,11 +464,11 @@ static inline int num_node_state(enum node_states state)
67643
67644 #define any_online_node(mask) \
67645 ({ \
67646- int node; \
67647- for_each_node_mask(node, (mask)) \
67648- if (node_online(node)) \
67649+ int __node; \
67650+ for_each_node_mask(__node, (mask)) \
67651+ if (node_online(__node)) \
67652 break; \
67653- node; \
67654+ __node; \
67655 })
67656
67657 #define num_online_nodes() num_node_state(N_ONLINE)
67658diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
67659index 5171639..7cf4235 100644
67660--- a/include/linux/oprofile.h
67661+++ b/include/linux/oprofile.h
67662@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
67663 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
67664 char const * name, ulong * val);
67665
67666-/** Create a file for read-only access to an atomic_t. */
67667+/** Create a file for read-only access to an atomic_unchecked_t. */
67668 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
67669- char const * name, atomic_t * val);
67670+ char const * name, atomic_unchecked_t * val);
67671
67672 /** create a directory */
67673 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
67674diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
67675index 3c62ed4..8924c7c 100644
67676--- a/include/linux/pagemap.h
67677+++ b/include/linux/pagemap.h
67678@@ -425,7 +425,9 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)
67679 if (((unsigned long)uaddr & PAGE_MASK) !=
67680 ((unsigned long)end & PAGE_MASK))
67681 ret = __get_user(c, end);
67682+ (void)c;
67683 }
67684+ (void)c;
67685 return ret;
67686 }
67687
67688diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
67689index 81c9689..a567a55 100644
67690--- a/include/linux/perf_event.h
67691+++ b/include/linux/perf_event.h
67692@@ -476,7 +476,7 @@ struct hw_perf_event {
67693 struct hrtimer hrtimer;
67694 };
67695 };
67696- atomic64_t prev_count;
67697+ atomic64_unchecked_t prev_count;
67698 u64 sample_period;
67699 u64 last_period;
67700 atomic64_t period_left;
67701@@ -557,7 +557,7 @@ struct perf_event {
67702 const struct pmu *pmu;
67703
67704 enum perf_event_active_state state;
67705- atomic64_t count;
67706+ atomic64_unchecked_t count;
67707
67708 /*
67709 * These are the total time in nanoseconds that the event
67710@@ -595,8 +595,8 @@ struct perf_event {
67711 * These accumulate total time (in nanoseconds) that children
67712 * events have been enabled and running, respectively.
67713 */
67714- atomic64_t child_total_time_enabled;
67715- atomic64_t child_total_time_running;
67716+ atomic64_unchecked_t child_total_time_enabled;
67717+ atomic64_unchecked_t child_total_time_running;
67718
67719 /*
67720 * Protect attach/detach and child_list:
67721diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
67722index b43a9e0..b77d869 100644
67723--- a/include/linux/pipe_fs_i.h
67724+++ b/include/linux/pipe_fs_i.h
67725@@ -46,9 +46,9 @@ struct pipe_inode_info {
67726 wait_queue_head_t wait;
67727 unsigned int nrbufs, curbuf;
67728 struct page *tmp_page;
67729- unsigned int readers;
67730- unsigned int writers;
67731- unsigned int waiting_writers;
67732+ atomic_t readers;
67733+ atomic_t writers;
67734+ atomic_t waiting_writers;
67735 unsigned int r_counter;
67736 unsigned int w_counter;
67737 struct fasync_struct *fasync_readers;
67738diff --git a/include/linux/poison.h b/include/linux/poison.h
67739index 34066ff..e95d744 100644
67740--- a/include/linux/poison.h
67741+++ b/include/linux/poison.h
67742@@ -19,8 +19,8 @@
67743 * under normal circumstances, used to verify that nobody uses
67744 * non-initialized list entries.
67745 */
67746-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
67747-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
67748+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
67749+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
67750
67751 /********** include/linux/timer.h **********/
67752 /*
67753diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
67754index 4f71bf4..77ffa64 100644
67755--- a/include/linux/posix-timers.h
67756+++ b/include/linux/posix-timers.h
67757@@ -67,7 +67,7 @@ struct k_itimer {
67758 };
67759
67760 struct k_clock {
67761- int res; /* in nanoseconds */
67762+ const int res; /* in nanoseconds */
67763 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
67764 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
67765 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
67766diff --git a/include/linux/preempt.h b/include/linux/preempt.h
67767index 72b1a10..13303a9 100644
67768--- a/include/linux/preempt.h
67769+++ b/include/linux/preempt.h
67770@@ -110,7 +110,7 @@ struct preempt_ops {
67771 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
67772 void (*sched_out)(struct preempt_notifier *notifier,
67773 struct task_struct *next);
67774-};
67775+} __no_const;
67776
67777 /**
67778 * preempt_notifier - key for installing preemption notifiers
67779diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
67780index 379eaed..1bf73e3 100644
67781--- a/include/linux/proc_fs.h
67782+++ b/include/linux/proc_fs.h
67783@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
67784 return proc_create_data(name, mode, parent, proc_fops, NULL);
67785 }
67786
67787+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
67788+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
67789+{
67790+#ifdef CONFIG_GRKERNSEC_PROC_USER
67791+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
67792+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67793+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
67794+#else
67795+ return proc_create_data(name, mode, parent, proc_fops, NULL);
67796+#endif
67797+}
67798+
67799+
67800 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
67801 mode_t mode, struct proc_dir_entry *base,
67802 read_proc_t *read_proc, void * data)
67803@@ -256,7 +269,7 @@ union proc_op {
67804 int (*proc_show)(struct seq_file *m,
67805 struct pid_namespace *ns, struct pid *pid,
67806 struct task_struct *task);
67807-};
67808+} __no_const;
67809
67810 struct ctl_table_header;
67811 struct ctl_table;
67812diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
67813index 7456d7d..6c1cfc9 100644
67814--- a/include/linux/ptrace.h
67815+++ b/include/linux/ptrace.h
67816@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_struct *child);
67817 extern void exit_ptrace(struct task_struct *tracer);
67818 #define PTRACE_MODE_READ 1
67819 #define PTRACE_MODE_ATTACH 2
67820-/* Returns 0 on success, -errno on denial. */
67821-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
67822 /* Returns true on success, false on denial. */
67823 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
67824+/* Returns true on success, false on denial. */
67825+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
67826
67827 static inline int ptrace_reparented(struct task_struct *child)
67828 {
67829diff --git a/include/linux/random.h b/include/linux/random.h
67830index 2948046..3262567 100644
67831--- a/include/linux/random.h
67832+++ b/include/linux/random.h
67833@@ -63,6 +63,11 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
67834 u32 random32(void);
67835 void srandom32(u32 seed);
67836
67837+static inline unsigned long pax_get_random_long(void)
67838+{
67839+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
67840+}
67841+
67842 #endif /* __KERNEL___ */
67843
67844 #endif /* _LINUX_RANDOM_H */
67845diff --git a/include/linux/reboot.h b/include/linux/reboot.h
67846index 988e55f..17cb4ef 100644
67847--- a/include/linux/reboot.h
67848+++ b/include/linux/reboot.h
67849@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
67850 * Architecture-specific implementations of sys_reboot commands.
67851 */
67852
67853-extern void machine_restart(char *cmd);
67854-extern void machine_halt(void);
67855-extern void machine_power_off(void);
67856+extern void machine_restart(char *cmd) __noreturn;
67857+extern void machine_halt(void) __noreturn;
67858+extern void machine_power_off(void) __noreturn;
67859
67860 extern void machine_shutdown(void);
67861 struct pt_regs;
67862@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
67863 */
67864
67865 extern void kernel_restart_prepare(char *cmd);
67866-extern void kernel_restart(char *cmd);
67867-extern void kernel_halt(void);
67868-extern void kernel_power_off(void);
67869+extern void kernel_restart(char *cmd) __noreturn;
67870+extern void kernel_halt(void) __noreturn;
67871+extern void kernel_power_off(void) __noreturn;
67872
67873 void ctrl_alt_del(void);
67874
67875@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
67876 * Emergency restart, callable from an interrupt handler.
67877 */
67878
67879-extern void emergency_restart(void);
67880+extern void emergency_restart(void) __noreturn;
67881 #include <asm/emergency-restart.h>
67882
67883 #endif
67884diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
67885index dd31e7b..5b03c5c 100644
67886--- a/include/linux/reiserfs_fs.h
67887+++ b/include/linux/reiserfs_fs.h
67888@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67889 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
67890
67891 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67892-#define get_generation(s) atomic_read (&fs_generation(s))
67893+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67894 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67895 #define __fs_changed(gen,s) (gen != get_generation (s))
67896 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
67897@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_from_bi(struct buffer_info *bi)
67898 */
67899
67900 struct item_operations {
67901- int (*bytes_number) (struct item_head * ih, int block_size);
67902- void (*decrement_key) (struct cpu_key *);
67903- int (*is_left_mergeable) (struct reiserfs_key * ih,
67904+ int (* const bytes_number) (struct item_head * ih, int block_size);
67905+ void (* const decrement_key) (struct cpu_key *);
67906+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
67907 unsigned long bsize);
67908- void (*print_item) (struct item_head *, char *item);
67909- void (*check_item) (struct item_head *, char *item);
67910+ void (* const print_item) (struct item_head *, char *item);
67911+ void (* const check_item) (struct item_head *, char *item);
67912
67913- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
67914+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
67915 int is_affected, int insert_size);
67916- int (*check_left) (struct virtual_item * vi, int free,
67917+ int (* const check_left) (struct virtual_item * vi, int free,
67918 int start_skip, int end_skip);
67919- int (*check_right) (struct virtual_item * vi, int free);
67920- int (*part_size) (struct virtual_item * vi, int from, int to);
67921- int (*unit_num) (struct virtual_item * vi);
67922- void (*print_vi) (struct virtual_item * vi);
67923+ int (* const check_right) (struct virtual_item * vi, int free);
67924+ int (* const part_size) (struct virtual_item * vi, int from, int to);
67925+ int (* const unit_num) (struct virtual_item * vi);
67926+ void (* const print_vi) (struct virtual_item * vi);
67927 };
67928
67929-extern struct item_operations *item_ops[TYPE_ANY + 1];
67930+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
67931
67932 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
67933 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
67934diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
67935index dab68bb..0688727 100644
67936--- a/include/linux/reiserfs_fs_sb.h
67937+++ b/include/linux/reiserfs_fs_sb.h
67938@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
67939 /* Comment? -Hans */
67940 wait_queue_head_t s_wait;
67941 /* To be obsoleted soon by per buffer seals.. -Hans */
67942- atomic_t s_generation_counter; // increased by one every time the
67943+ atomic_unchecked_t s_generation_counter; // increased by one every time the
67944 // tree gets re-balanced
67945 unsigned long s_properties; /* File system properties. Currently holds
67946 on-disk FS format */
67947diff --git a/include/linux/relay.h b/include/linux/relay.h
67948index 14a86bc..17d0700 100644
67949--- a/include/linux/relay.h
67950+++ b/include/linux/relay.h
67951@@ -159,7 +159,7 @@ struct rchan_callbacks
67952 * The callback should return 0 if successful, negative if not.
67953 */
67954 int (*remove_buf_file)(struct dentry *dentry);
67955-};
67956+} __no_const;
67957
67958 /*
67959 * CONFIG_RELAY kernel API, kernel/relay.c
67960diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
67961index 3392c59..a746428 100644
67962--- a/include/linux/rfkill.h
67963+++ b/include/linux/rfkill.h
67964@@ -144,6 +144,7 @@ struct rfkill_ops {
67965 void (*query)(struct rfkill *rfkill, void *data);
67966 int (*set_block)(void *data, bool blocked);
67967 };
67968+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
67969
67970 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
67971 /**
67972diff --git a/include/linux/sched.h b/include/linux/sched.h
67973index 71849bf..40217dc 100644
67974--- a/include/linux/sched.h
67975+++ b/include/linux/sched.h
67976@@ -101,6 +101,7 @@ struct bio;
67977 struct fs_struct;
67978 struct bts_context;
67979 struct perf_event_context;
67980+struct linux_binprm;
67981
67982 /*
67983 * List of flags we want to share for kernel threads,
67984@@ -350,7 +351,7 @@ extern signed long schedule_timeout_killable(signed long timeout);
67985 extern signed long schedule_timeout_uninterruptible(signed long timeout);
67986 asmlinkage void __schedule(void);
67987 asmlinkage void schedule(void);
67988-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
67989+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
67990
67991 struct nsproxy;
67992 struct user_namespace;
67993@@ -371,9 +372,12 @@ struct user_namespace;
67994 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
67995
67996 extern int sysctl_max_map_count;
67997+extern unsigned long sysctl_heap_stack_gap;
67998
67999 #include <linux/aio.h>
68000
68001+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
68002+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
68003 extern unsigned long
68004 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
68005 unsigned long, unsigned long);
68006@@ -666,6 +670,16 @@ struct signal_struct {
68007 struct tty_audit_buf *tty_audit_buf;
68008 #endif
68009
68010+#ifdef CONFIG_GRKERNSEC
68011+ u32 curr_ip;
68012+ u32 saved_ip;
68013+ u32 gr_saddr;
68014+ u32 gr_daddr;
68015+ u16 gr_sport;
68016+ u16 gr_dport;
68017+ u8 used_accept:1;
68018+#endif
68019+
68020 int oom_adj; /* OOM kill score adjustment (bit shift) */
68021 };
68022
68023@@ -723,6 +737,11 @@ struct user_struct {
68024 struct key *session_keyring; /* UID's default session keyring */
68025 #endif
68026
68027+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
68028+ unsigned int banned;
68029+ unsigned long ban_expires;
68030+#endif
68031+
68032 /* Hash table maintenance information */
68033 struct hlist_node uidhash_node;
68034 uid_t uid;
68035@@ -1328,8 +1347,8 @@ struct task_struct {
68036 struct list_head thread_group;
68037
68038 struct completion *vfork_done; /* for vfork() */
68039- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
68040- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68041+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
68042+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68043
68044 cputime_t utime, stime, utimescaled, stimescaled;
68045 cputime_t gtime;
68046@@ -1343,16 +1362,6 @@ struct task_struct {
68047 struct task_cputime cputime_expires;
68048 struct list_head cpu_timers[3];
68049
68050-/* process credentials */
68051- const struct cred *real_cred; /* objective and real subjective task
68052- * credentials (COW) */
68053- const struct cred *cred; /* effective (overridable) subjective task
68054- * credentials (COW) */
68055- struct mutex cred_guard_mutex; /* guard against foreign influences on
68056- * credential calculations
68057- * (notably. ptrace) */
68058- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68059-
68060 char comm[TASK_COMM_LEN]; /* executable name excluding path
68061 - access with [gs]et_task_comm (which lock
68062 it with task_lock())
68063@@ -1369,6 +1378,10 @@ struct task_struct {
68064 #endif
68065 /* CPU-specific state of this task */
68066 struct thread_struct thread;
68067+/* thread_info moved to task_struct */
68068+#ifdef CONFIG_X86
68069+ struct thread_info tinfo;
68070+#endif
68071 /* filesystem information */
68072 struct fs_struct *fs;
68073 /* open file information */
68074@@ -1436,6 +1449,15 @@ struct task_struct {
68075 int hardirq_context;
68076 int softirq_context;
68077 #endif
68078+
68079+/* process credentials */
68080+ const struct cred *real_cred; /* objective and real subjective task
68081+ * credentials (COW) */
68082+ struct mutex cred_guard_mutex; /* guard against foreign influences on
68083+ * credential calculations
68084+ * (notably. ptrace) */
68085+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68086+
68087 #ifdef CONFIG_LOCKDEP
68088 # define MAX_LOCK_DEPTH 48UL
68089 u64 curr_chain_key;
68090@@ -1456,6 +1478,9 @@ struct task_struct {
68091
68092 struct backing_dev_info *backing_dev_info;
68093
68094+ const struct cred *cred; /* effective (overridable) subjective task
68095+ * credentials (COW) */
68096+
68097 struct io_context *io_context;
68098
68099 unsigned long ptrace_message;
68100@@ -1519,6 +1544,21 @@ struct task_struct {
68101 unsigned long default_timer_slack_ns;
68102
68103 struct list_head *scm_work_list;
68104+
68105+#ifdef CONFIG_GRKERNSEC
68106+ /* grsecurity */
68107+ struct dentry *gr_chroot_dentry;
68108+ struct acl_subject_label *acl;
68109+ struct acl_role_label *role;
68110+ struct file *exec_file;
68111+ u16 acl_role_id;
68112+ /* is this the task that authenticated to the special role */
68113+ u8 acl_sp_role;
68114+ u8 is_writable;
68115+ u8 brute;
68116+ u8 gr_is_chrooted;
68117+#endif
68118+
68119 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
68120 /* Index of current stored adress in ret_stack */
68121 int curr_ret_stack;
68122@@ -1542,6 +1582,57 @@ struct task_struct {
68123 #endif /* CONFIG_TRACING */
68124 };
68125
68126+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
68127+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
68128+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
68129+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
68130+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
68131+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
68132+
68133+#ifdef CONFIG_PAX_SOFTMODE
68134+extern int pax_softmode;
68135+#endif
68136+
68137+extern int pax_check_flags(unsigned long *);
68138+
68139+/* if tsk != current then task_lock must be held on it */
68140+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68141+static inline unsigned long pax_get_flags(struct task_struct *tsk)
68142+{
68143+ if (likely(tsk->mm))
68144+ return tsk->mm->pax_flags;
68145+ else
68146+ return 0UL;
68147+}
68148+
68149+/* if tsk != current then task_lock must be held on it */
68150+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
68151+{
68152+ if (likely(tsk->mm)) {
68153+ tsk->mm->pax_flags = flags;
68154+ return 0;
68155+ }
68156+ return -EINVAL;
68157+}
68158+#endif
68159+
68160+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68161+extern void pax_set_initial_flags(struct linux_binprm *bprm);
68162+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
68163+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
68164+#endif
68165+
68166+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
68167+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
68168+extern void pax_report_refcount_overflow(struct pt_regs *regs);
68169+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
68170+
68171+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
68172+extern void pax_track_stack(void);
68173+#else
68174+static inline void pax_track_stack(void) {}
68175+#endif
68176+
68177 /* Future-safe accessor for struct task_struct's cpus_allowed. */
68178 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
68179
68180@@ -1740,7 +1831,7 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
68181 #define PF_DUMPCORE 0x00000200 /* dumped core */
68182 #define PF_SIGNALED 0x00000400 /* killed by a signal */
68183 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
68184-#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
68185+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
68186 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
68187 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
68188 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
68189@@ -1978,7 +2069,9 @@ void yield(void);
68190 extern struct exec_domain default_exec_domain;
68191
68192 union thread_union {
68193+#ifndef CONFIG_X86
68194 struct thread_info thread_info;
68195+#endif
68196 unsigned long stack[THREAD_SIZE/sizeof(long)];
68197 };
68198
68199@@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
68200 */
68201
68202 extern struct task_struct *find_task_by_vpid(pid_t nr);
68203+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
68204 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
68205 struct pid_namespace *ns);
68206
68207@@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
68208 extern void exit_itimers(struct signal_struct *);
68209 extern void flush_itimer_signals(void);
68210
68211-extern NORET_TYPE void do_group_exit(int);
68212+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
68213
68214 extern void daemonize(const char *, ...);
68215 extern int allow_signal(int);
68216@@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
68217
68218 #endif
68219
68220-static inline int object_is_on_stack(void *obj)
68221+static inline int object_starts_on_stack(void *obj)
68222 {
68223- void *stack = task_stack_page(current);
68224+ const void *stack = task_stack_page(current);
68225
68226 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
68227 }
68228
68229+#ifdef CONFIG_PAX_USERCOPY
68230+extern int object_is_on_stack(const void *obj, unsigned long len);
68231+#endif
68232+
68233 extern void thread_info_cache_init(void);
68234
68235 #ifdef CONFIG_DEBUG_STACK_USAGE
68236diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
68237index 1ee2c05..81b7ec4 100644
68238--- a/include/linux/screen_info.h
68239+++ b/include/linux/screen_info.h
68240@@ -42,7 +42,8 @@ struct screen_info {
68241 __u16 pages; /* 0x32 */
68242 __u16 vesa_attributes; /* 0x34 */
68243 __u32 capabilities; /* 0x36 */
68244- __u8 _reserved[6]; /* 0x3a */
68245+ __u16 vesapm_size; /* 0x3a */
68246+ __u8 _reserved[4]; /* 0x3c */
68247 } __attribute__((packed));
68248
68249 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68250diff --git a/include/linux/security.h b/include/linux/security.h
68251index d40d23f..253bd14 100644
68252--- a/include/linux/security.h
68253+++ b/include/linux/security.h
68254@@ -34,6 +34,7 @@
68255 #include <linux/key.h>
68256 #include <linux/xfrm.h>
68257 #include <linux/gfp.h>
68258+#include <linux/grsecurity.h>
68259 #include <net/flow.h>
68260
68261 /* Maximum number of letters for an LSM name string */
68262diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
68263index 8366d8f..2307490 100644
68264--- a/include/linux/seq_file.h
68265+++ b/include/linux/seq_file.h
68266@@ -32,6 +32,7 @@ struct seq_operations {
68267 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
68268 int (*show) (struct seq_file *m, void *v);
68269 };
68270+typedef struct seq_operations __no_const seq_operations_no_const;
68271
68272 #define SEQ_SKIP 1
68273
68274diff --git a/include/linux/shm.h b/include/linux/shm.h
68275index eca6235..c7417ed 100644
68276--- a/include/linux/shm.h
68277+++ b/include/linux/shm.h
68278@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the kernel */
68279 pid_t shm_cprid;
68280 pid_t shm_lprid;
68281 struct user_struct *mlock_user;
68282+#ifdef CONFIG_GRKERNSEC
68283+ time_t shm_createtime;
68284+ pid_t shm_lapid;
68285+#endif
68286 };
68287
68288 /* shm_mode upper byte flags */
68289diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
68290index bcdd660..6e12e11 100644
68291--- a/include/linux/skbuff.h
68292+++ b/include/linux/skbuff.h
68293@@ -14,6 +14,7 @@
68294 #ifndef _LINUX_SKBUFF_H
68295 #define _LINUX_SKBUFF_H
68296
68297+#include <linux/const.h>
68298 #include <linux/kernel.h>
68299 #include <linux/kmemcheck.h>
68300 #include <linux/compiler.h>
68301@@ -544,7 +545,7 @@ static inline union skb_shared_tx *skb_tx(struct sk_buff *skb)
68302 */
68303 static inline int skb_queue_empty(const struct sk_buff_head *list)
68304 {
68305- return list->next == (struct sk_buff *)list;
68306+ return list->next == (const struct sk_buff *)list;
68307 }
68308
68309 /**
68310@@ -557,7 +558,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
68311 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68312 const struct sk_buff *skb)
68313 {
68314- return (skb->next == (struct sk_buff *) list);
68315+ return (skb->next == (const struct sk_buff *) list);
68316 }
68317
68318 /**
68319@@ -570,7 +571,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68320 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
68321 const struct sk_buff *skb)
68322 {
68323- return (skb->prev == (struct sk_buff *) list);
68324+ return (skb->prev == (const struct sk_buff *) list);
68325 }
68326
68327 /**
68328@@ -1367,7 +1368,7 @@ static inline int skb_network_offset(const struct sk_buff *skb)
68329 * headroom, you should not reduce this.
68330 */
68331 #ifndef NET_SKB_PAD
68332-#define NET_SKB_PAD 32
68333+#define NET_SKB_PAD (_AC(32,UL))
68334 #endif
68335
68336 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
68337diff --git a/include/linux/slab.h b/include/linux/slab.h
68338index 2da8372..a3be824 100644
68339--- a/include/linux/slab.h
68340+++ b/include/linux/slab.h
68341@@ -11,12 +11,20 @@
68342
68343 #include <linux/gfp.h>
68344 #include <linux/types.h>
68345+#include <linux/err.h>
68346
68347 /*
68348 * Flags to pass to kmem_cache_create().
68349 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
68350 */
68351 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
68352+
68353+#ifdef CONFIG_PAX_USERCOPY
68354+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
68355+#else
68356+#define SLAB_USERCOPY 0x00000000UL
68357+#endif
68358+
68359 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
68360 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
68361 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
68362@@ -82,10 +90,13 @@
68363 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
68364 * Both make kfree a no-op.
68365 */
68366-#define ZERO_SIZE_PTR ((void *)16)
68367+#define ZERO_SIZE_PTR \
68368+({ \
68369+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
68370+ (void *)(-MAX_ERRNO-1L); \
68371+})
68372
68373-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
68374- (unsigned long)ZERO_SIZE_PTR)
68375+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
68376
68377 /*
68378 * struct kmem_cache related prototypes
68379@@ -138,6 +149,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
68380 void kfree(const void *);
68381 void kzfree(const void *);
68382 size_t ksize(const void *);
68383+void check_object_size(const void *ptr, unsigned long n, bool to);
68384
68385 /*
68386 * Allocator specific definitions. These are mainly used to establish optimized
68387@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
68388
68389 void __init kmem_cache_init_late(void);
68390
68391+#define kmalloc(x, y) \
68392+({ \
68393+ void *___retval; \
68394+ intoverflow_t ___x = (intoverflow_t)x; \
68395+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
68396+ ___retval = NULL; \
68397+ else \
68398+ ___retval = kmalloc((size_t)___x, (y)); \
68399+ ___retval; \
68400+})
68401+
68402+#define kmalloc_node(x, y, z) \
68403+({ \
68404+ void *___retval; \
68405+ intoverflow_t ___x = (intoverflow_t)x; \
68406+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
68407+ ___retval = NULL; \
68408+ else \
68409+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
68410+ ___retval; \
68411+})
68412+
68413+#define kzalloc(x, y) \
68414+({ \
68415+ void *___retval; \
68416+ intoverflow_t ___x = (intoverflow_t)x; \
68417+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
68418+ ___retval = NULL; \
68419+ else \
68420+ ___retval = kzalloc((size_t)___x, (y)); \
68421+ ___retval; \
68422+})
68423+
68424 #endif /* _LINUX_SLAB_H */
68425diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
68426index 850d057..d9dfe3c 100644
68427--- a/include/linux/slab_def.h
68428+++ b/include/linux/slab_def.h
68429@@ -69,10 +69,10 @@ struct kmem_cache {
68430 unsigned long node_allocs;
68431 unsigned long node_frees;
68432 unsigned long node_overflow;
68433- atomic_t allochit;
68434- atomic_t allocmiss;
68435- atomic_t freehit;
68436- atomic_t freemiss;
68437+ atomic_unchecked_t allochit;
68438+ atomic_unchecked_t allocmiss;
68439+ atomic_unchecked_t freehit;
68440+ atomic_unchecked_t freemiss;
68441
68442 /*
68443 * If debugging is enabled, then the allocator can add additional
68444diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
68445index 5ad70a6..57f9f65 100644
68446--- a/include/linux/slub_def.h
68447+++ b/include/linux/slub_def.h
68448@@ -86,7 +86,7 @@ struct kmem_cache {
68449 struct kmem_cache_order_objects max;
68450 struct kmem_cache_order_objects min;
68451 gfp_t allocflags; /* gfp flags to use on each alloc */
68452- int refcount; /* Refcount for slab cache destroy */
68453+ atomic_t refcount; /* Refcount for slab cache destroy */
68454 void (*ctor)(void *);
68455 int inuse; /* Offset to metadata */
68456 int align; /* Alignment */
68457@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
68458 #endif
68459
68460 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
68461-void *__kmalloc(size_t size, gfp_t flags);
68462+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
68463
68464 #ifdef CONFIG_KMEMTRACE
68465 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
68466diff --git a/include/linux/sonet.h b/include/linux/sonet.h
68467index 67ad11f..0bbd8af 100644
68468--- a/include/linux/sonet.h
68469+++ b/include/linux/sonet.h
68470@@ -61,7 +61,7 @@ struct sonet_stats {
68471 #include <asm/atomic.h>
68472
68473 struct k_sonet_stats {
68474-#define __HANDLE_ITEM(i) atomic_t i
68475+#define __HANDLE_ITEM(i) atomic_unchecked_t i
68476 __SONET_ITEMS
68477 #undef __HANDLE_ITEM
68478 };
68479diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
68480index 6f52b4d..5500323 100644
68481--- a/include/linux/sunrpc/cache.h
68482+++ b/include/linux/sunrpc/cache.h
68483@@ -125,7 +125,7 @@ struct cache_detail {
68484 */
68485 struct cache_req {
68486 struct cache_deferred_req *(*defer)(struct cache_req *req);
68487-};
68488+} __no_const;
68489 /* this must be embedded in a deferred_request that is being
68490 * delayed awaiting cache-fill
68491 */
68492diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
68493index 8ed9642..101ceab 100644
68494--- a/include/linux/sunrpc/clnt.h
68495+++ b/include/linux/sunrpc/clnt.h
68496@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
68497 {
68498 switch (sap->sa_family) {
68499 case AF_INET:
68500- return ntohs(((struct sockaddr_in *)sap)->sin_port);
68501+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
68502 case AF_INET6:
68503- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
68504+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
68505 }
68506 return 0;
68507 }
68508@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
68509 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
68510 const struct sockaddr *src)
68511 {
68512- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
68513+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
68514 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
68515
68516 dsin->sin_family = ssin->sin_family;
68517@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
68518 if (sa->sa_family != AF_INET6)
68519 return 0;
68520
68521- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
68522+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
68523 }
68524
68525 #endif /* __KERNEL__ */
68526diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
68527index c14fe86..393245e 100644
68528--- a/include/linux/sunrpc/svc_rdma.h
68529+++ b/include/linux/sunrpc/svc_rdma.h
68530@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
68531 extern unsigned int svcrdma_max_requests;
68532 extern unsigned int svcrdma_max_req_size;
68533
68534-extern atomic_t rdma_stat_recv;
68535-extern atomic_t rdma_stat_read;
68536-extern atomic_t rdma_stat_write;
68537-extern atomic_t rdma_stat_sq_starve;
68538-extern atomic_t rdma_stat_rq_starve;
68539-extern atomic_t rdma_stat_rq_poll;
68540-extern atomic_t rdma_stat_rq_prod;
68541-extern atomic_t rdma_stat_sq_poll;
68542-extern atomic_t rdma_stat_sq_prod;
68543+extern atomic_unchecked_t rdma_stat_recv;
68544+extern atomic_unchecked_t rdma_stat_read;
68545+extern atomic_unchecked_t rdma_stat_write;
68546+extern atomic_unchecked_t rdma_stat_sq_starve;
68547+extern atomic_unchecked_t rdma_stat_rq_starve;
68548+extern atomic_unchecked_t rdma_stat_rq_poll;
68549+extern atomic_unchecked_t rdma_stat_rq_prod;
68550+extern atomic_unchecked_t rdma_stat_sq_poll;
68551+extern atomic_unchecked_t rdma_stat_sq_prod;
68552
68553 #define RPCRDMA_VERSION 1
68554
68555diff --git a/include/linux/suspend.h b/include/linux/suspend.h
68556index 5e781d8..1e62818 100644
68557--- a/include/linux/suspend.h
68558+++ b/include/linux/suspend.h
68559@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
68560 * which require special recovery actions in that situation.
68561 */
68562 struct platform_suspend_ops {
68563- int (*valid)(suspend_state_t state);
68564- int (*begin)(suspend_state_t state);
68565- int (*prepare)(void);
68566- int (*prepare_late)(void);
68567- int (*enter)(suspend_state_t state);
68568- void (*wake)(void);
68569- void (*finish)(void);
68570- void (*end)(void);
68571- void (*recover)(void);
68572+ int (* const valid)(suspend_state_t state);
68573+ int (* const begin)(suspend_state_t state);
68574+ int (* const prepare)(void);
68575+ int (* const prepare_late)(void);
68576+ int (* const enter)(suspend_state_t state);
68577+ void (* const wake)(void);
68578+ void (* const finish)(void);
68579+ void (* const end)(void);
68580+ void (* const recover)(void);
68581 };
68582
68583 #ifdef CONFIG_SUSPEND
68584@@ -120,7 +120,7 @@ struct platform_suspend_ops {
68585 * suspend_set_ops - set platform dependent suspend operations
68586 * @ops: The new suspend operations to set.
68587 */
68588-extern void suspend_set_ops(struct platform_suspend_ops *ops);
68589+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
68590 extern int suspend_valid_only_mem(suspend_state_t state);
68591
68592 /**
68593@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t state);
68594 #else /* !CONFIG_SUSPEND */
68595 #define suspend_valid_only_mem NULL
68596
68597-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
68598+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
68599 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
68600 #endif /* !CONFIG_SUSPEND */
68601
68602@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone *zone);
68603 * platforms which require special recovery actions in that situation.
68604 */
68605 struct platform_hibernation_ops {
68606- int (*begin)(void);
68607- void (*end)(void);
68608- int (*pre_snapshot)(void);
68609- void (*finish)(void);
68610- int (*prepare)(void);
68611- int (*enter)(void);
68612- void (*leave)(void);
68613- int (*pre_restore)(void);
68614- void (*restore_cleanup)(void);
68615- void (*recover)(void);
68616+ int (* const begin)(void);
68617+ void (* const end)(void);
68618+ int (* const pre_snapshot)(void);
68619+ void (* const finish)(void);
68620+ int (* const prepare)(void);
68621+ int (* const enter)(void);
68622+ void (* const leave)(void);
68623+ int (* const pre_restore)(void);
68624+ void (* const restore_cleanup)(void);
68625+ void (* const recover)(void);
68626 };
68627
68628 #ifdef CONFIG_HIBERNATION
68629@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct page *);
68630 extern void swsusp_unset_page_free(struct page *);
68631 extern unsigned long get_safe_page(gfp_t gfp_mask);
68632
68633-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
68634+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
68635 extern int hibernate(void);
68636 extern bool system_entering_hibernation(void);
68637 #else /* CONFIG_HIBERNATION */
68638@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
68639 static inline void swsusp_set_page_free(struct page *p) {}
68640 static inline void swsusp_unset_page_free(struct page *p) {}
68641
68642-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
68643+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
68644 static inline int hibernate(void) { return -ENOSYS; }
68645 static inline bool system_entering_hibernation(void) { return false; }
68646 #endif /* CONFIG_HIBERNATION */
68647diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
68648index 0eb6942..a805cb6 100644
68649--- a/include/linux/sysctl.h
68650+++ b/include/linux/sysctl.h
68651@@ -164,7 +164,11 @@ enum
68652 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68653 };
68654
68655-
68656+#ifdef CONFIG_PAX_SOFTMODE
68657+enum {
68658+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68659+};
68660+#endif
68661
68662 /* CTL_VM names: */
68663 enum
68664@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
68665
68666 extern int proc_dostring(struct ctl_table *, int,
68667 void __user *, size_t *, loff_t *);
68668+extern int proc_dostring_modpriv(struct ctl_table *, int,
68669+ void __user *, size_t *, loff_t *);
68670 extern int proc_dointvec(struct ctl_table *, int,
68671 void __user *, size_t *, loff_t *);
68672 extern int proc_dointvec_minmax(struct ctl_table *, int,
68673@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name, int nlen,
68674
68675 extern ctl_handler sysctl_data;
68676 extern ctl_handler sysctl_string;
68677+extern ctl_handler sysctl_string_modpriv;
68678 extern ctl_handler sysctl_intvec;
68679 extern ctl_handler sysctl_jiffies;
68680 extern ctl_handler sysctl_ms_jiffies;
68681diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
68682index 9d68fed..71f02cc 100644
68683--- a/include/linux/sysfs.h
68684+++ b/include/linux/sysfs.h
68685@@ -75,8 +75,8 @@ struct bin_attribute {
68686 };
68687
68688 struct sysfs_ops {
68689- ssize_t (*show)(struct kobject *, struct attribute *,char *);
68690- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
68691+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
68692+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
68693 };
68694
68695 struct sysfs_dirent;
68696diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
68697index a8cc4e1..98d3b85 100644
68698--- a/include/linux/thread_info.h
68699+++ b/include/linux/thread_info.h
68700@@ -23,7 +23,7 @@ struct restart_block {
68701 };
68702 /* For futex_wait and futex_wait_requeue_pi */
68703 struct {
68704- u32 *uaddr;
68705+ u32 __user *uaddr;
68706 u32 val;
68707 u32 flags;
68708 u32 bitset;
68709diff --git a/include/linux/tty.h b/include/linux/tty.h
68710index e9c57e9..ee6d489 100644
68711--- a/include/linux/tty.h
68712+++ b/include/linux/tty.h
68713@@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
68714 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
68715 extern void tty_ldisc_enable(struct tty_struct *tty);
68716
68717-
68718 /* n_tty.c */
68719 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
68720
68721diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
68722index 0c4ee9b..9f7c426 100644
68723--- a/include/linux/tty_ldisc.h
68724+++ b/include/linux/tty_ldisc.h
68725@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
68726
68727 struct module *owner;
68728
68729- int refcount;
68730+ atomic_t refcount;
68731 };
68732
68733 struct tty_ldisc {
68734diff --git a/include/linux/types.h b/include/linux/types.h
68735index c42724f..d190eee 100644
68736--- a/include/linux/types.h
68737+++ b/include/linux/types.h
68738@@ -191,10 +191,26 @@ typedef struct {
68739 volatile int counter;
68740 } atomic_t;
68741
68742+#ifdef CONFIG_PAX_REFCOUNT
68743+typedef struct {
68744+ volatile int counter;
68745+} atomic_unchecked_t;
68746+#else
68747+typedef atomic_t atomic_unchecked_t;
68748+#endif
68749+
68750 #ifdef CONFIG_64BIT
68751 typedef struct {
68752 volatile long counter;
68753 } atomic64_t;
68754+
68755+#ifdef CONFIG_PAX_REFCOUNT
68756+typedef struct {
68757+ volatile long counter;
68758+} atomic64_unchecked_t;
68759+#else
68760+typedef atomic64_t atomic64_unchecked_t;
68761+#endif
68762 #endif
68763
68764 struct ustat {
68765diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
68766index 6b58367..53a3e8e 100644
68767--- a/include/linux/uaccess.h
68768+++ b/include/linux/uaccess.h
68769@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
68770 long ret; \
68771 mm_segment_t old_fs = get_fs(); \
68772 \
68773- set_fs(KERNEL_DS); \
68774 pagefault_disable(); \
68775- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
68776- pagefault_enable(); \
68777+ set_fs(KERNEL_DS); \
68778+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
68779 set_fs(old_fs); \
68780+ pagefault_enable(); \
68781 ret; \
68782 })
68783
68784@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_user_nocache(void *to,
68785 * Safely read from address @src to the buffer at @dst. If a kernel fault
68786 * happens, handle that and return -EFAULT.
68787 */
68788-extern long probe_kernel_read(void *dst, void *src, size_t size);
68789+extern long probe_kernel_read(void *dst, const void *src, size_t size);
68790
68791 /*
68792 * probe_kernel_write(): safely attempt to write to a location
68793@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst, void *src, size_t size);
68794 * Safely write to address @dst from the buffer at @src. If a kernel fault
68795 * happens, handle that and return -EFAULT.
68796 */
68797-extern long probe_kernel_write(void *dst, void *src, size_t size);
68798+extern long probe_kernel_write(void *dst, const void *src, size_t size);
68799
68800 #endif /* __LINUX_UACCESS_H__ */
68801diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
68802index 99c1b4d..bb94261 100644
68803--- a/include/linux/unaligned/access_ok.h
68804+++ b/include/linux/unaligned/access_ok.h
68805@@ -6,32 +6,32 @@
68806
68807 static inline u16 get_unaligned_le16(const void *p)
68808 {
68809- return le16_to_cpup((__le16 *)p);
68810+ return le16_to_cpup((const __le16 *)p);
68811 }
68812
68813 static inline u32 get_unaligned_le32(const void *p)
68814 {
68815- return le32_to_cpup((__le32 *)p);
68816+ return le32_to_cpup((const __le32 *)p);
68817 }
68818
68819 static inline u64 get_unaligned_le64(const void *p)
68820 {
68821- return le64_to_cpup((__le64 *)p);
68822+ return le64_to_cpup((const __le64 *)p);
68823 }
68824
68825 static inline u16 get_unaligned_be16(const void *p)
68826 {
68827- return be16_to_cpup((__be16 *)p);
68828+ return be16_to_cpup((const __be16 *)p);
68829 }
68830
68831 static inline u32 get_unaligned_be32(const void *p)
68832 {
68833- return be32_to_cpup((__be32 *)p);
68834+ return be32_to_cpup((const __be32 *)p);
68835 }
68836
68837 static inline u64 get_unaligned_be64(const void *p)
68838 {
68839- return be64_to_cpup((__be64 *)p);
68840+ return be64_to_cpup((const __be64 *)p);
68841 }
68842
68843 static inline void put_unaligned_le16(u16 val, void *p)
68844diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
68845index 79b9837..b5a56f9 100644
68846--- a/include/linux/vermagic.h
68847+++ b/include/linux/vermagic.h
68848@@ -26,9 +26,35 @@
68849 #define MODULE_ARCH_VERMAGIC ""
68850 #endif
68851
68852+#ifdef CONFIG_PAX_REFCOUNT
68853+#define MODULE_PAX_REFCOUNT "REFCOUNT "
68854+#else
68855+#define MODULE_PAX_REFCOUNT ""
68856+#endif
68857+
68858+#ifdef CONSTIFY_PLUGIN
68859+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
68860+#else
68861+#define MODULE_CONSTIFY_PLUGIN ""
68862+#endif
68863+
68864+#ifdef STACKLEAK_PLUGIN
68865+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
68866+#else
68867+#define MODULE_STACKLEAK_PLUGIN ""
68868+#endif
68869+
68870+#ifdef CONFIG_GRKERNSEC
68871+#define MODULE_GRSEC "GRSEC "
68872+#else
68873+#define MODULE_GRSEC ""
68874+#endif
68875+
68876 #define VERMAGIC_STRING \
68877 UTS_RELEASE " " \
68878 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
68879 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
68880- MODULE_ARCH_VERMAGIC
68881+ MODULE_ARCH_VERMAGIC \
68882+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
68883+ MODULE_GRSEC
68884
68885diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
68886index 819a634..462ac12 100644
68887--- a/include/linux/vmalloc.h
68888+++ b/include/linux/vmalloc.h
68889@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
68890 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
68891 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
68892 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
68893+
68894+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
68895+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
68896+#endif
68897+
68898 /* bits [20..32] reserved for arch specific ioremap internals */
68899
68900 /*
68901@@ -124,4 +129,81 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
68902
68903 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
68904
68905+#define vmalloc(x) \
68906+({ \
68907+ void *___retval; \
68908+ intoverflow_t ___x = (intoverflow_t)x; \
68909+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
68910+ ___retval = NULL; \
68911+ else \
68912+ ___retval = vmalloc((unsigned long)___x); \
68913+ ___retval; \
68914+})
68915+
68916+#define __vmalloc(x, y, z) \
68917+({ \
68918+ void *___retval; \
68919+ intoverflow_t ___x = (intoverflow_t)x; \
68920+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
68921+ ___retval = NULL; \
68922+ else \
68923+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
68924+ ___retval; \
68925+})
68926+
68927+#define vmalloc_user(x) \
68928+({ \
68929+ void *___retval; \
68930+ intoverflow_t ___x = (intoverflow_t)x; \
68931+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
68932+ ___retval = NULL; \
68933+ else \
68934+ ___retval = vmalloc_user((unsigned long)___x); \
68935+ ___retval; \
68936+})
68937+
68938+#define vmalloc_exec(x) \
68939+({ \
68940+ void *___retval; \
68941+ intoverflow_t ___x = (intoverflow_t)x; \
68942+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
68943+ ___retval = NULL; \
68944+ else \
68945+ ___retval = vmalloc_exec((unsigned long)___x); \
68946+ ___retval; \
68947+})
68948+
68949+#define vmalloc_node(x, y) \
68950+({ \
68951+ void *___retval; \
68952+ intoverflow_t ___x = (intoverflow_t)x; \
68953+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
68954+ ___retval = NULL; \
68955+ else \
68956+ ___retval = vmalloc_node((unsigned long)___x, (y));\
68957+ ___retval; \
68958+})
68959+
68960+#define vmalloc_32(x) \
68961+({ \
68962+ void *___retval; \
68963+ intoverflow_t ___x = (intoverflow_t)x; \
68964+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
68965+ ___retval = NULL; \
68966+ else \
68967+ ___retval = vmalloc_32((unsigned long)___x); \
68968+ ___retval; \
68969+})
68970+
68971+#define vmalloc_32_user(x) \
68972+({ \
68973+ void *___retval; \
68974+ intoverflow_t ___x = (intoverflow_t)x; \
68975+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
68976+ ___retval = NULL; \
68977+ else \
68978+ ___retval = vmalloc_32_user((unsigned long)___x);\
68979+ ___retval; \
68980+})
68981+
68982 #endif /* _LINUX_VMALLOC_H */
68983diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
68984index 13070d6..aa4159a 100644
68985--- a/include/linux/vmstat.h
68986+++ b/include/linux/vmstat.h
68987@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(int cpu)
68988 /*
68989 * Zone based page accounting with per cpu differentials.
68990 */
68991-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68992+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68993
68994 static inline void zone_page_state_add(long x, struct zone *zone,
68995 enum zone_stat_item item)
68996 {
68997- atomic_long_add(x, &zone->vm_stat[item]);
68998- atomic_long_add(x, &vm_stat[item]);
68999+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
69000+ atomic_long_add_unchecked(x, &vm_stat[item]);
69001 }
69002
69003 static inline unsigned long global_page_state(enum zone_stat_item item)
69004 {
69005- long x = atomic_long_read(&vm_stat[item]);
69006+ long x = atomic_long_read_unchecked(&vm_stat[item]);
69007 #ifdef CONFIG_SMP
69008 if (x < 0)
69009 x = 0;
69010@@ -158,7 +158,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
69011 static inline unsigned long zone_page_state(struct zone *zone,
69012 enum zone_stat_item item)
69013 {
69014- long x = atomic_long_read(&zone->vm_stat[item]);
69015+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69016 #ifdef CONFIG_SMP
69017 if (x < 0)
69018 x = 0;
69019@@ -175,7 +175,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
69020 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
69021 enum zone_stat_item item)
69022 {
69023- long x = atomic_long_read(&zone->vm_stat[item]);
69024+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69025
69026 #ifdef CONFIG_SMP
69027 int cpu;
69028@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
69029
69030 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
69031 {
69032- atomic_long_inc(&zone->vm_stat[item]);
69033- atomic_long_inc(&vm_stat[item]);
69034+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
69035+ atomic_long_inc_unchecked(&vm_stat[item]);
69036 }
69037
69038 static inline void __inc_zone_page_state(struct page *page,
69039@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state(struct page *page,
69040
69041 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
69042 {
69043- atomic_long_dec(&zone->vm_stat[item]);
69044- atomic_long_dec(&vm_stat[item]);
69045+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
69046+ atomic_long_dec_unchecked(&vm_stat[item]);
69047 }
69048
69049 static inline void __dec_zone_page_state(struct page *page,
69050diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
69051index eed5fcc..5080d24 100644
69052--- a/include/media/saa7146_vv.h
69053+++ b/include/media/saa7146_vv.h
69054@@ -167,7 +167,7 @@ struct saa7146_ext_vv
69055 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
69056
69057 /* the extension can override this */
69058- struct v4l2_ioctl_ops ops;
69059+ v4l2_ioctl_ops_no_const ops;
69060 /* pointer to the saa7146 core ops */
69061 const struct v4l2_ioctl_ops *core_ops;
69062
69063diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
69064index 73c9867..2da8837 100644
69065--- a/include/media/v4l2-dev.h
69066+++ b/include/media/v4l2-dev.h
69067@@ -34,7 +34,7 @@ struct v4l2_device;
69068 #define V4L2_FL_UNREGISTERED (0)
69069
69070 struct v4l2_file_operations {
69071- struct module *owner;
69072+ struct module * const owner;
69073 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
69074 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
69075 unsigned int (*poll) (struct file *, struct poll_table_struct *);
69076@@ -46,6 +46,7 @@ struct v4l2_file_operations {
69077 int (*open) (struct file *);
69078 int (*release) (struct file *);
69079 };
69080+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
69081
69082 /*
69083 * Newer version of video_device, handled by videodev2.c
69084diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
69085index 5d5d550..f559ef1 100644
69086--- a/include/media/v4l2-device.h
69087+++ b/include/media/v4l2-device.h
69088@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
69089 this function returns 0. If the name ends with a digit (e.g. cx18),
69090 then the name will be set to cx18-0 since cx180 looks really odd. */
69091 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
69092- atomic_t *instance);
69093+ atomic_unchecked_t *instance);
69094
69095 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
69096 Since the parent disappears this ensures that v4l2_dev doesn't have an
69097diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
69098index 7a4529d..7244290 100644
69099--- a/include/media/v4l2-ioctl.h
69100+++ b/include/media/v4l2-ioctl.h
69101@@ -243,6 +243,7 @@ struct v4l2_ioctl_ops {
69102 long (*vidioc_default) (struct file *file, void *fh,
69103 int cmd, void *arg);
69104 };
69105+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
69106
69107
69108 /* v4l debugging and diagnostics */
69109diff --git a/include/net/flow.h b/include/net/flow.h
69110index 809970b..c3df4f3 100644
69111--- a/include/net/flow.h
69112+++ b/include/net/flow.h
69113@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net *net, struct flowi *key, u16 family,
69114 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
69115 u8 dir, flow_resolve_t resolver);
69116 extern void flow_cache_flush(void);
69117-extern atomic_t flow_cache_genid;
69118+extern atomic_unchecked_t flow_cache_genid;
69119
69120 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
69121 {
69122diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
69123index 15e1f8fe..668837c 100644
69124--- a/include/net/inetpeer.h
69125+++ b/include/net/inetpeer.h
69126@@ -24,7 +24,7 @@ struct inet_peer
69127 __u32 dtime; /* the time of last use of not
69128 * referenced entries */
69129 atomic_t refcnt;
69130- atomic_t rid; /* Frag reception counter */
69131+ atomic_unchecked_t rid; /* Frag reception counter */
69132 __u32 tcp_ts;
69133 unsigned long tcp_ts_stamp;
69134 };
69135diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
69136index 98978e7..2243a3d 100644
69137--- a/include/net/ip_vs.h
69138+++ b/include/net/ip_vs.h
69139@@ -365,7 +365,7 @@ struct ip_vs_conn {
69140 struct ip_vs_conn *control; /* Master control connection */
69141 atomic_t n_control; /* Number of controlled ones */
69142 struct ip_vs_dest *dest; /* real server */
69143- atomic_t in_pkts; /* incoming packet counter */
69144+ atomic_unchecked_t in_pkts; /* incoming packet counter */
69145
69146 /* packet transmitter for different forwarding methods. If it
69147 mangles the packet, it must return NF_DROP or better NF_STOLEN,
69148@@ -466,7 +466,7 @@ struct ip_vs_dest {
69149 union nf_inet_addr addr; /* IP address of the server */
69150 __be16 port; /* port number of the server */
69151 volatile unsigned flags; /* dest status flags */
69152- atomic_t conn_flags; /* flags to copy to conn */
69153+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
69154 atomic_t weight; /* server weight */
69155
69156 atomic_t refcnt; /* reference counter */
69157diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
69158index 69b610a..fe3962c 100644
69159--- a/include/net/irda/ircomm_core.h
69160+++ b/include/net/irda/ircomm_core.h
69161@@ -51,7 +51,7 @@ typedef struct {
69162 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
69163 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
69164 struct ircomm_info *);
69165-} call_t;
69166+} __no_const call_t;
69167
69168 struct ircomm_cb {
69169 irda_queue_t queue;
69170diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
69171index eea2e61..08c692d 100644
69172--- a/include/net/irda/ircomm_tty.h
69173+++ b/include/net/irda/ircomm_tty.h
69174@@ -35,6 +35,7 @@
69175 #include <linux/termios.h>
69176 #include <linux/timer.h>
69177 #include <linux/tty.h> /* struct tty_struct */
69178+#include <asm/local.h>
69179
69180 #include <net/irda/irias_object.h>
69181 #include <net/irda/ircomm_core.h>
69182@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
69183 unsigned short close_delay;
69184 unsigned short closing_wait; /* time to wait before closing */
69185
69186- int open_count;
69187- int blocked_open; /* # of blocked opens */
69188+ local_t open_count;
69189+ local_t blocked_open; /* # of blocked opens */
69190
69191 /* Protect concurent access to :
69192 * o self->open_count
69193diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
69194index f82a1e8..82d81e8 100644
69195--- a/include/net/iucv/af_iucv.h
69196+++ b/include/net/iucv/af_iucv.h
69197@@ -87,7 +87,7 @@ struct iucv_sock {
69198 struct iucv_sock_list {
69199 struct hlist_head head;
69200 rwlock_t lock;
69201- atomic_t autobind_name;
69202+ atomic_unchecked_t autobind_name;
69203 };
69204
69205 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
69206diff --git a/include/net/lapb.h b/include/net/lapb.h
69207index 96cb5dd..25e8d4f 100644
69208--- a/include/net/lapb.h
69209+++ b/include/net/lapb.h
69210@@ -95,7 +95,7 @@ struct lapb_cb {
69211 struct sk_buff_head write_queue;
69212 struct sk_buff_head ack_queue;
69213 unsigned char window;
69214- struct lapb_register_struct callbacks;
69215+ struct lapb_register_struct *callbacks;
69216
69217 /* FRMR control information */
69218 struct lapb_frame frmr_data;
69219diff --git a/include/net/neighbour.h b/include/net/neighbour.h
69220index 3817fda..cdb2343 100644
69221--- a/include/net/neighbour.h
69222+++ b/include/net/neighbour.h
69223@@ -131,7 +131,7 @@ struct neigh_ops
69224 int (*connected_output)(struct sk_buff*);
69225 int (*hh_output)(struct sk_buff*);
69226 int (*queue_xmit)(struct sk_buff*);
69227-};
69228+} __do_const;
69229
69230 struct pneigh_entry
69231 {
69232diff --git a/include/net/netlink.h b/include/net/netlink.h
69233index c344646..4778c71 100644
69234--- a/include/net/netlink.h
69235+++ b/include/net/netlink.h
69236@@ -335,7 +335,7 @@ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
69237 {
69238 return (remaining >= (int) sizeof(struct nlmsghdr) &&
69239 nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
69240- nlh->nlmsg_len <= remaining);
69241+ nlh->nlmsg_len <= (unsigned int)remaining);
69242 }
69243
69244 /**
69245@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
69246 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
69247 {
69248 if (mark)
69249- skb_trim(skb, (unsigned char *) mark - skb->data);
69250+ skb_trim(skb, (const unsigned char *) mark - skb->data);
69251 }
69252
69253 /**
69254diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
69255index 9a4b8b7..e49e077 100644
69256--- a/include/net/netns/ipv4.h
69257+++ b/include/net/netns/ipv4.h
69258@@ -54,7 +54,7 @@ struct netns_ipv4 {
69259 int current_rt_cache_rebuild_count;
69260
69261 struct timer_list rt_secret_timer;
69262- atomic_t rt_genid;
69263+ atomic_unchecked_t rt_genid;
69264
69265 #ifdef CONFIG_IP_MROUTE
69266 struct sock *mroute_sk;
69267diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
69268index 8a6d529..171f401 100644
69269--- a/include/net/sctp/sctp.h
69270+++ b/include/net/sctp/sctp.h
69271@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
69272
69273 #else /* SCTP_DEBUG */
69274
69275-#define SCTP_DEBUG_PRINTK(whatever...)
69276-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
69277+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
69278+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
69279 #define SCTP_ENABLE_DEBUG
69280 #define SCTP_DISABLE_DEBUG
69281 #define SCTP_ASSERT(expr, str, func)
69282diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
69283index d97f689..f3b90ab 100644
69284--- a/include/net/secure_seq.h
69285+++ b/include/net/secure_seq.h
69286@@ -7,14 +7,14 @@ extern __u32 secure_ip_id(__be32 daddr);
69287 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
69288 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
69289 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
69290- __be16 dport);
69291+ __be16 dport);
69292 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
69293 __be16 sport, __be16 dport);
69294 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69295- __be16 sport, __be16 dport);
69296+ __be16 sport, __be16 dport);
69297 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
69298- __be16 sport, __be16 dport);
69299+ __be16 sport, __be16 dport);
69300 extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69301- __be16 sport, __be16 dport);
69302+ __be16 sport, __be16 dport);
69303
69304 #endif /* _NET_SECURE_SEQ */
69305diff --git a/include/net/sock.h b/include/net/sock.h
69306index 9f96394..76fc9c7 100644
69307--- a/include/net/sock.h
69308+++ b/include/net/sock.h
69309@@ -272,7 +272,7 @@ struct sock {
69310 rwlock_t sk_callback_lock;
69311 int sk_err,
69312 sk_err_soft;
69313- atomic_t sk_drops;
69314+ atomic_unchecked_t sk_drops;
69315 unsigned short sk_ack_backlog;
69316 unsigned short sk_max_ack_backlog;
69317 __u32 sk_priority;
69318@@ -737,7 +737,7 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
69319 extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
69320 extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
69321 #else
69322-static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
69323+static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
69324 int inc)
69325 {
69326 }
69327diff --git a/include/net/tcp.h b/include/net/tcp.h
69328index 6cfe18b..dd21acb 100644
69329--- a/include/net/tcp.h
69330+++ b/include/net/tcp.h
69331@@ -1444,8 +1444,8 @@ enum tcp_seq_states {
69332 struct tcp_seq_afinfo {
69333 char *name;
69334 sa_family_t family;
69335- struct file_operations seq_fops;
69336- struct seq_operations seq_ops;
69337+ file_operations_no_const seq_fops;
69338+ seq_operations_no_const seq_ops;
69339 };
69340
69341 struct tcp_iter_state {
69342diff --git a/include/net/udp.h b/include/net/udp.h
69343index f98abd2..b4b042f 100644
69344--- a/include/net/udp.h
69345+++ b/include/net/udp.h
69346@@ -187,8 +187,8 @@ struct udp_seq_afinfo {
69347 char *name;
69348 sa_family_t family;
69349 struct udp_table *udp_table;
69350- struct file_operations seq_fops;
69351- struct seq_operations seq_ops;
69352+ file_operations_no_const seq_fops;
69353+ seq_operations_no_const seq_ops;
69354 };
69355
69356 struct udp_iter_state {
69357diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
69358index cbb822e..e9c1cbe 100644
69359--- a/include/rdma/iw_cm.h
69360+++ b/include/rdma/iw_cm.h
69361@@ -129,7 +129,7 @@ struct iw_cm_verbs {
69362 int backlog);
69363
69364 int (*destroy_listen)(struct iw_cm_id *cm_id);
69365-};
69366+} __no_const;
69367
69368 /**
69369 * iw_create_cm_id - Create an IW CM identifier.
69370diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
69371index 09a124b..caa8ca8 100644
69372--- a/include/scsi/libfc.h
69373+++ b/include/scsi/libfc.h
69374@@ -675,6 +675,7 @@ struct libfc_function_template {
69375 */
69376 void (*disc_stop_final) (struct fc_lport *);
69377 };
69378+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
69379
69380 /* information used by the discovery layer */
69381 struct fc_disc {
69382@@ -707,7 +708,7 @@ struct fc_lport {
69383 struct fc_disc disc;
69384
69385 /* Operational Information */
69386- struct libfc_function_template tt;
69387+ libfc_function_template_no_const tt;
69388 u8 link_up;
69389 u8 qfull;
69390 enum fc_lport_state state;
69391diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
69392index de8e180..f15e0d7 100644
69393--- a/include/scsi/scsi_device.h
69394+++ b/include/scsi/scsi_device.h
69395@@ -156,9 +156,9 @@ struct scsi_device {
69396 unsigned int max_device_blocked; /* what device_blocked counts down from */
69397 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
69398
69399- atomic_t iorequest_cnt;
69400- atomic_t iodone_cnt;
69401- atomic_t ioerr_cnt;
69402+ atomic_unchecked_t iorequest_cnt;
69403+ atomic_unchecked_t iodone_cnt;
69404+ atomic_unchecked_t ioerr_cnt;
69405
69406 struct device sdev_gendev,
69407 sdev_dev;
69408diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
69409index fc50bd6..81ba9cb 100644
69410--- a/include/scsi/scsi_transport_fc.h
69411+++ b/include/scsi/scsi_transport_fc.h
69412@@ -708,7 +708,7 @@ struct fc_function_template {
69413 unsigned long show_host_system_hostname:1;
69414
69415 unsigned long disable_target_scan:1;
69416-};
69417+} __do_const;
69418
69419
69420 /**
69421diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
69422index 3dae3f7..8440d6f 100644
69423--- a/include/sound/ac97_codec.h
69424+++ b/include/sound/ac97_codec.h
69425@@ -419,15 +419,15 @@
69426 struct snd_ac97;
69427
69428 struct snd_ac97_build_ops {
69429- int (*build_3d) (struct snd_ac97 *ac97);
69430- int (*build_specific) (struct snd_ac97 *ac97);
69431- int (*build_spdif) (struct snd_ac97 *ac97);
69432- int (*build_post_spdif) (struct snd_ac97 *ac97);
69433+ int (* const build_3d) (struct snd_ac97 *ac97);
69434+ int (* const build_specific) (struct snd_ac97 *ac97);
69435+ int (* const build_spdif) (struct snd_ac97 *ac97);
69436+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
69437 #ifdef CONFIG_PM
69438- void (*suspend) (struct snd_ac97 *ac97);
69439- void (*resume) (struct snd_ac97 *ac97);
69440+ void (* const suspend) (struct snd_ac97 *ac97);
69441+ void (* const resume) (struct snd_ac97 *ac97);
69442 #endif
69443- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69444+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69445 };
69446
69447 struct snd_ac97_bus_ops {
69448@@ -477,7 +477,7 @@ struct snd_ac97_template {
69449
69450 struct snd_ac97 {
69451 /* -- lowlevel (hardware) driver specific -- */
69452- struct snd_ac97_build_ops * build_ops;
69453+ const struct snd_ac97_build_ops * build_ops;
69454 void *private_data;
69455 void (*private_free) (struct snd_ac97 *ac97);
69456 /* --- */
69457diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
69458index 891cf1a..a94ba2b 100644
69459--- a/include/sound/ak4xxx-adda.h
69460+++ b/include/sound/ak4xxx-adda.h
69461@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
69462 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
69463 unsigned char val);
69464 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
69465-};
69466+} __no_const;
69467
69468 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
69469
69470diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
69471index 8c05e47..2b5df97 100644
69472--- a/include/sound/hwdep.h
69473+++ b/include/sound/hwdep.h
69474@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
69475 struct snd_hwdep_dsp_status *status);
69476 int (*dsp_load)(struct snd_hwdep *hw,
69477 struct snd_hwdep_dsp_image *image);
69478-};
69479+} __no_const;
69480
69481 struct snd_hwdep {
69482 struct snd_card *card;
69483diff --git a/include/sound/info.h b/include/sound/info.h
69484index 112e894..6fda5b5 100644
69485--- a/include/sound/info.h
69486+++ b/include/sound/info.h
69487@@ -44,7 +44,7 @@ struct snd_info_entry_text {
69488 struct snd_info_buffer *buffer);
69489 void (*write)(struct snd_info_entry *entry,
69490 struct snd_info_buffer *buffer);
69491-};
69492+} __no_const;
69493
69494 struct snd_info_entry_ops {
69495 int (*open)(struct snd_info_entry *entry,
69496diff --git a/include/sound/pcm.h b/include/sound/pcm.h
69497index de6d981..590a550 100644
69498--- a/include/sound/pcm.h
69499+++ b/include/sound/pcm.h
69500@@ -80,6 +80,7 @@ struct snd_pcm_ops {
69501 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
69502 int (*ack)(struct snd_pcm_substream *substream);
69503 };
69504+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
69505
69506 /*
69507 *
69508diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
69509index 736eac7..fe8a80f 100644
69510--- a/include/sound/sb16_csp.h
69511+++ b/include/sound/sb16_csp.h
69512@@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
69513 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
69514 int (*csp_stop) (struct snd_sb_csp * p);
69515 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
69516-};
69517+} __no_const;
69518
69519 /*
69520 * CSP private data
69521diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
69522index 444cd6b..3327cc5 100644
69523--- a/include/sound/ymfpci.h
69524+++ b/include/sound/ymfpci.h
69525@@ -358,7 +358,7 @@ struct snd_ymfpci {
69526 spinlock_t reg_lock;
69527 spinlock_t voice_lock;
69528 wait_queue_head_t interrupt_sleep;
69529- atomic_t interrupt_sleep_count;
69530+ atomic_unchecked_t interrupt_sleep_count;
69531 struct snd_info_entry *proc_entry;
69532 const struct firmware *dsp_microcode;
69533 const struct firmware *controller_microcode;
69534diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
69535index b89f9db..f097b38 100644
69536--- a/include/trace/events/irq.h
69537+++ b/include/trace/events/irq.h
69538@@ -34,7 +34,7 @@
69539 */
69540 TRACE_EVENT(irq_handler_entry,
69541
69542- TP_PROTO(int irq, struct irqaction *action),
69543+ TP_PROTO(int irq, const struct irqaction *action),
69544
69545 TP_ARGS(irq, action),
69546
69547@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
69548 */
69549 TRACE_EVENT(irq_handler_exit,
69550
69551- TP_PROTO(int irq, struct irqaction *action, int ret),
69552+ TP_PROTO(int irq, const struct irqaction *action, int ret),
69553
69554 TP_ARGS(irq, action, ret),
69555
69556@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
69557 */
69558 TRACE_EVENT(softirq_entry,
69559
69560- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69561+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69562
69563 TP_ARGS(h, vec),
69564
69565@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
69566 */
69567 TRACE_EVENT(softirq_exit,
69568
69569- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69570+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69571
69572 TP_ARGS(h, vec),
69573
69574diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
69575index 0993a22..32ba2fe 100644
69576--- a/include/video/uvesafb.h
69577+++ b/include/video/uvesafb.h
69578@@ -177,6 +177,7 @@ struct uvesafb_par {
69579 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
69580 u8 pmi_setpal; /* PMI for palette changes */
69581 u16 *pmi_base; /* protected mode interface location */
69582+ u8 *pmi_code; /* protected mode code location */
69583 void *pmi_start;
69584 void *pmi_pal;
69585 u8 *vbe_state_orig; /*
69586diff --git a/init/Kconfig b/init/Kconfig
69587index d72691b..3996e54 100644
69588--- a/init/Kconfig
69589+++ b/init/Kconfig
69590@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
69591
69592 config COMPAT_BRK
69593 bool "Disable heap randomization"
69594- default y
69595+ default n
69596 help
69597 Randomizing heap placement makes heap exploits harder, but it
69598 also breaks ancient binaries (including anything libc5 based).
69599diff --git a/init/do_mounts.c b/init/do_mounts.c
69600index bb008d0..4fa3933 100644
69601--- a/init/do_mounts.c
69602+++ b/init/do_mounts.c
69603@@ -216,11 +216,11 @@ static void __init get_fs_names(char *page)
69604
69605 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
69606 {
69607- int err = sys_mount(name, "/root", fs, flags, data);
69608+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
69609 if (err)
69610 return err;
69611
69612- sys_chdir("/root");
69613+ sys_chdir((__force const char __user *)"/root");
69614 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
69615 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
69616 current->fs->pwd.mnt->mnt_sb->s_type->name,
69617@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...)
69618 va_start(args, fmt);
69619 vsprintf(buf, fmt, args);
69620 va_end(args);
69621- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
69622+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
69623 if (fd >= 0) {
69624 sys_ioctl(fd, FDEJECT, 0);
69625 sys_close(fd);
69626 }
69627 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
69628- fd = sys_open("/dev/console", O_RDWR, 0);
69629+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
69630 if (fd >= 0) {
69631 sys_ioctl(fd, TCGETS, (long)&termios);
69632 termios.c_lflag &= ~ICANON;
69633 sys_ioctl(fd, TCSETSF, (long)&termios);
69634- sys_read(fd, &c, 1);
69635+ sys_read(fd, (char __user *)&c, 1);
69636 termios.c_lflag |= ICANON;
69637 sys_ioctl(fd, TCSETSF, (long)&termios);
69638 sys_close(fd);
69639@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
69640 mount_root();
69641 out:
69642 devtmpfs_mount("dev");
69643- sys_mount(".", "/", NULL, MS_MOVE, NULL);
69644- sys_chroot(".");
69645+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
69646+ sys_chroot((__force char __user *)".");
69647 }
69648diff --git a/init/do_mounts.h b/init/do_mounts.h
69649index f5b978a..69dbfe8 100644
69650--- a/init/do_mounts.h
69651+++ b/init/do_mounts.h
69652@@ -15,15 +15,15 @@ extern int root_mountflags;
69653
69654 static inline int create_dev(char *name, dev_t dev)
69655 {
69656- sys_unlink(name);
69657- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
69658+ sys_unlink((char __force_user *)name);
69659+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
69660 }
69661
69662 #if BITS_PER_LONG == 32
69663 static inline u32 bstat(char *name)
69664 {
69665 struct stat64 stat;
69666- if (sys_stat64(name, &stat) != 0)
69667+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
69668 return 0;
69669 if (!S_ISBLK(stat.st_mode))
69670 return 0;
69671@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
69672 static inline u32 bstat(char *name)
69673 {
69674 struct stat stat;
69675- if (sys_newstat(name, &stat) != 0)
69676+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
69677 return 0;
69678 if (!S_ISBLK(stat.st_mode))
69679 return 0;
69680diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
69681index 614241b..4da046b 100644
69682--- a/init/do_mounts_initrd.c
69683+++ b/init/do_mounts_initrd.c
69684@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shell)
69685 sys_close(old_fd);sys_close(root_fd);
69686 sys_close(0);sys_close(1);sys_close(2);
69687 sys_setsid();
69688- (void) sys_open("/dev/console",O_RDWR,0);
69689+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
69690 (void) sys_dup(0);
69691 (void) sys_dup(0);
69692 return kernel_execve(shell, argv, envp_init);
69693@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
69694 create_dev("/dev/root.old", Root_RAM0);
69695 /* mount initrd on rootfs' /root */
69696 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
69697- sys_mkdir("/old", 0700);
69698- root_fd = sys_open("/", 0, 0);
69699- old_fd = sys_open("/old", 0, 0);
69700+ sys_mkdir((const char __force_user *)"/old", 0700);
69701+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
69702+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
69703 /* move initrd over / and chdir/chroot in initrd root */
69704- sys_chdir("/root");
69705- sys_mount(".", "/", NULL, MS_MOVE, NULL);
69706- sys_chroot(".");
69707+ sys_chdir((const char __force_user *)"/root");
69708+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
69709+ sys_chroot((const char __force_user *)".");
69710
69711 /*
69712 * In case that a resume from disk is carried out by linuxrc or one of
69713@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
69714
69715 /* move initrd to rootfs' /old */
69716 sys_fchdir(old_fd);
69717- sys_mount("/", ".", NULL, MS_MOVE, NULL);
69718+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
69719 /* switch root and cwd back to / of rootfs */
69720 sys_fchdir(root_fd);
69721- sys_chroot(".");
69722+ sys_chroot((const char __force_user *)".");
69723 sys_close(old_fd);
69724 sys_close(root_fd);
69725
69726 if (new_decode_dev(real_root_dev) == Root_RAM0) {
69727- sys_chdir("/old");
69728+ sys_chdir((const char __force_user *)"/old");
69729 return;
69730 }
69731
69732@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
69733 mount_root();
69734
69735 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
69736- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
69737+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
69738 if (!error)
69739 printk("okay\n");
69740 else {
69741- int fd = sys_open("/dev/root.old", O_RDWR, 0);
69742+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
69743 if (error == -ENOENT)
69744 printk("/initrd does not exist. Ignored.\n");
69745 else
69746 printk("failed\n");
69747 printk(KERN_NOTICE "Unmounting old root\n");
69748- sys_umount("/old", MNT_DETACH);
69749+ sys_umount((char __force_user *)"/old", MNT_DETACH);
69750 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
69751 if (fd < 0) {
69752 error = fd;
69753@@ -119,11 +119,11 @@ int __init initrd_load(void)
69754 * mounted in the normal path.
69755 */
69756 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
69757- sys_unlink("/initrd.image");
69758+ sys_unlink((const char __force_user *)"/initrd.image");
69759 handle_initrd();
69760 return 1;
69761 }
69762 }
69763- sys_unlink("/initrd.image");
69764+ sys_unlink((const char __force_user *)"/initrd.image");
69765 return 0;
69766 }
69767diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
69768index 69aebbf..c0bf6a7 100644
69769--- a/init/do_mounts_md.c
69770+++ b/init/do_mounts_md.c
69771@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
69772 partitioned ? "_d" : "", minor,
69773 md_setup_args[ent].device_names);
69774
69775- fd = sys_open(name, 0, 0);
69776+ fd = sys_open((char __force_user *)name, 0, 0);
69777 if (fd < 0) {
69778 printk(KERN_ERR "md: open failed - cannot start "
69779 "array %s\n", name);
69780@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
69781 * array without it
69782 */
69783 sys_close(fd);
69784- fd = sys_open(name, 0, 0);
69785+ fd = sys_open((char __force_user *)name, 0, 0);
69786 sys_ioctl(fd, BLKRRPART, 0);
69787 }
69788 sys_close(fd);
69789@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
69790
69791 wait_for_device_probe();
69792
69793- fd = sys_open("/dev/md0", 0, 0);
69794+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
69795 if (fd >= 0) {
69796 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
69797 sys_close(fd);
69798diff --git a/init/initramfs.c b/init/initramfs.c
69799index 1fd59b8..a01b079 100644
69800--- a/init/initramfs.c
69801+++ b/init/initramfs.c
69802@@ -74,7 +74,7 @@ static void __init free_hash(void)
69803 }
69804 }
69805
69806-static long __init do_utime(char __user *filename, time_t mtime)
69807+static long __init do_utime(__force char __user *filename, time_t mtime)
69808 {
69809 struct timespec t[2];
69810
69811@@ -109,7 +109,7 @@ static void __init dir_utime(void)
69812 struct dir_entry *de, *tmp;
69813 list_for_each_entry_safe(de, tmp, &dir_list, list) {
69814 list_del(&de->list);
69815- do_utime(de->name, de->mtime);
69816+ do_utime((char __force_user *)de->name, de->mtime);
69817 kfree(de->name);
69818 kfree(de);
69819 }
69820@@ -271,7 +271,7 @@ static int __init maybe_link(void)
69821 if (nlink >= 2) {
69822 char *old = find_link(major, minor, ino, mode, collected);
69823 if (old)
69824- return (sys_link(old, collected) < 0) ? -1 : 1;
69825+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
69826 }
69827 return 0;
69828 }
69829@@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
69830 {
69831 struct stat st;
69832
69833- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
69834+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
69835 if (S_ISDIR(st.st_mode))
69836- sys_rmdir(path);
69837+ sys_rmdir((char __force_user *)path);
69838 else
69839- sys_unlink(path);
69840+ sys_unlink((char __force_user *)path);
69841 }
69842 }
69843
69844@@ -305,7 +305,7 @@ static int __init do_name(void)
69845 int openflags = O_WRONLY|O_CREAT;
69846 if (ml != 1)
69847 openflags |= O_TRUNC;
69848- wfd = sys_open(collected, openflags, mode);
69849+ wfd = sys_open((char __force_user *)collected, openflags, mode);
69850
69851 if (wfd >= 0) {
69852 sys_fchown(wfd, uid, gid);
69853@@ -317,17 +317,17 @@ static int __init do_name(void)
69854 }
69855 }
69856 } else if (S_ISDIR(mode)) {
69857- sys_mkdir(collected, mode);
69858- sys_chown(collected, uid, gid);
69859- sys_chmod(collected, mode);
69860+ sys_mkdir((char __force_user *)collected, mode);
69861+ sys_chown((char __force_user *)collected, uid, gid);
69862+ sys_chmod((char __force_user *)collected, mode);
69863 dir_add(collected, mtime);
69864 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
69865 S_ISFIFO(mode) || S_ISSOCK(mode)) {
69866 if (maybe_link() == 0) {
69867- sys_mknod(collected, mode, rdev);
69868- sys_chown(collected, uid, gid);
69869- sys_chmod(collected, mode);
69870- do_utime(collected, mtime);
69871+ sys_mknod((char __force_user *)collected, mode, rdev);
69872+ sys_chown((char __force_user *)collected, uid, gid);
69873+ sys_chmod((char __force_user *)collected, mode);
69874+ do_utime((char __force_user *)collected, mtime);
69875 }
69876 }
69877 return 0;
69878@@ -336,15 +336,15 @@ static int __init do_name(void)
69879 static int __init do_copy(void)
69880 {
69881 if (count >= body_len) {
69882- sys_write(wfd, victim, body_len);
69883+ sys_write(wfd, (char __force_user *)victim, body_len);
69884 sys_close(wfd);
69885- do_utime(vcollected, mtime);
69886+ do_utime((char __force_user *)vcollected, mtime);
69887 kfree(vcollected);
69888 eat(body_len);
69889 state = SkipIt;
69890 return 0;
69891 } else {
69892- sys_write(wfd, victim, count);
69893+ sys_write(wfd, (char __force_user *)victim, count);
69894 body_len -= count;
69895 eat(count);
69896 return 1;
69897@@ -355,9 +355,9 @@ static int __init do_symlink(void)
69898 {
69899 collected[N_ALIGN(name_len) + body_len] = '\0';
69900 clean_path(collected, 0);
69901- sys_symlink(collected + N_ALIGN(name_len), collected);
69902- sys_lchown(collected, uid, gid);
69903- do_utime(collected, mtime);
69904+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
69905+ sys_lchown((char __force_user *)collected, uid, gid);
69906+ do_utime((char __force_user *)collected, mtime);
69907 state = SkipIt;
69908 next_state = Reset;
69909 return 0;
69910diff --git a/init/main.c b/init/main.c
69911index 1eb4bd5..da8c6f5 100644
69912--- a/init/main.c
69913+++ b/init/main.c
69914@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void) { }
69915 #ifdef CONFIG_TC
69916 extern void tc_init(void);
69917 #endif
69918+extern void grsecurity_init(void);
69919
69920 enum system_states system_state __read_mostly;
69921 EXPORT_SYMBOL(system_state);
69922@@ -183,6 +184,49 @@ static int __init set_reset_devices(char *str)
69923
69924 __setup("reset_devices", set_reset_devices);
69925
69926+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69927+extern char pax_enter_kernel_user[];
69928+extern char pax_exit_kernel_user[];
69929+extern pgdval_t clone_pgd_mask;
69930+#endif
69931+
69932+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69933+static int __init setup_pax_nouderef(char *str)
69934+{
69935+#ifdef CONFIG_X86_32
69936+ unsigned int cpu;
69937+ struct desc_struct *gdt;
69938+
69939+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
69940+ gdt = get_cpu_gdt_table(cpu);
69941+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69942+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69943+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69944+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69945+ }
69946+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
69947+#else
69948+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
69949+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
69950+ clone_pgd_mask = ~(pgdval_t)0UL;
69951+#endif
69952+
69953+ return 0;
69954+}
69955+early_param("pax_nouderef", setup_pax_nouderef);
69956+#endif
69957+
69958+#ifdef CONFIG_PAX_SOFTMODE
69959+int pax_softmode;
69960+
69961+static int __init setup_pax_softmode(char *str)
69962+{
69963+ get_option(&str, &pax_softmode);
69964+ return 1;
69965+}
69966+__setup("pax_softmode=", setup_pax_softmode);
69967+#endif
69968+
69969 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69970 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69971 static const char *panic_later, *panic_param;
69972@@ -705,52 +749,53 @@ int initcall_debug;
69973 core_param(initcall_debug, initcall_debug, bool, 0644);
69974
69975 static char msgbuf[64];
69976-static struct boot_trace_call call;
69977-static struct boot_trace_ret ret;
69978+static struct boot_trace_call trace_call;
69979+static struct boot_trace_ret trace_ret;
69980
69981 int do_one_initcall(initcall_t fn)
69982 {
69983 int count = preempt_count();
69984 ktime_t calltime, delta, rettime;
69985+ const char *msg1 = "", *msg2 = "";
69986
69987 if (initcall_debug) {
69988- call.caller = task_pid_nr(current);
69989- printk("calling %pF @ %i\n", fn, call.caller);
69990+ trace_call.caller = task_pid_nr(current);
69991+ printk("calling %pF @ %i\n", fn, trace_call.caller);
69992 calltime = ktime_get();
69993- trace_boot_call(&call, fn);
69994+ trace_boot_call(&trace_call, fn);
69995 enable_boot_trace();
69996 }
69997
69998- ret.result = fn();
69999+ trace_ret.result = fn();
70000
70001 if (initcall_debug) {
70002 disable_boot_trace();
70003 rettime = ktime_get();
70004 delta = ktime_sub(rettime, calltime);
70005- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70006- trace_boot_ret(&ret, fn);
70007+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70008+ trace_boot_ret(&trace_ret, fn);
70009 printk("initcall %pF returned %d after %Ld usecs\n", fn,
70010- ret.result, ret.duration);
70011+ trace_ret.result, trace_ret.duration);
70012 }
70013
70014 msgbuf[0] = 0;
70015
70016- if (ret.result && ret.result != -ENODEV && initcall_debug)
70017- sprintf(msgbuf, "error code %d ", ret.result);
70018+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
70019+ sprintf(msgbuf, "error code %d ", trace_ret.result);
70020
70021 if (preempt_count() != count) {
70022- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
70023+ msg1 = " preemption imbalance";
70024 preempt_count() = count;
70025 }
70026 if (irqs_disabled()) {
70027- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
70028+ msg2 = " disabled interrupts";
70029 local_irq_enable();
70030 }
70031- if (msgbuf[0]) {
70032- printk("initcall %pF returned with %s\n", fn, msgbuf);
70033+ if (msgbuf[0] || *msg1 || *msg2) {
70034+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
70035 }
70036
70037- return ret.result;
70038+ return trace_ret.result;
70039 }
70040
70041
70042@@ -893,11 +938,13 @@ static int __init kernel_init(void * unused)
70043 if (!ramdisk_execute_command)
70044 ramdisk_execute_command = "/init";
70045
70046- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
70047+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
70048 ramdisk_execute_command = NULL;
70049 prepare_namespace();
70050 }
70051
70052+ grsecurity_init();
70053+
70054 /*
70055 * Ok, we have completed the initial bootup, and
70056 * we're essentially up and running. Get rid of the
70057diff --git a/init/noinitramfs.c b/init/noinitramfs.c
70058index f4c1a3a..96c19bd 100644
70059--- a/init/noinitramfs.c
70060+++ b/init/noinitramfs.c
70061@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
70062 {
70063 int err;
70064
70065- err = sys_mkdir("/dev", 0755);
70066+ err = sys_mkdir((const char __user *)"/dev", 0755);
70067 if (err < 0)
70068 goto out;
70069
70070@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
70071 if (err < 0)
70072 goto out;
70073
70074- err = sys_mkdir("/root", 0700);
70075+ err = sys_mkdir((const char __user *)"/root", 0700);
70076 if (err < 0)
70077 goto out;
70078
70079diff --git a/ipc/mqueue.c b/ipc/mqueue.c
70080index d01bc14..8df81db 100644
70081--- a/ipc/mqueue.c
70082+++ b/ipc/mqueue.c
70083@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
70084 mq_bytes = (mq_msg_tblsz +
70085 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
70086
70087+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
70088 spin_lock(&mq_lock);
70089 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
70090 u->mq_bytes + mq_bytes >
70091diff --git a/ipc/msg.c b/ipc/msg.c
70092index 779f762..4af9e36 100644
70093--- a/ipc/msg.c
70094+++ b/ipc/msg.c
70095@@ -310,18 +310,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
70096 return security_msg_queue_associate(msq, msgflg);
70097 }
70098
70099+static struct ipc_ops msg_ops = {
70100+ .getnew = newque,
70101+ .associate = msg_security,
70102+ .more_checks = NULL
70103+};
70104+
70105 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
70106 {
70107 struct ipc_namespace *ns;
70108- struct ipc_ops msg_ops;
70109 struct ipc_params msg_params;
70110
70111 ns = current->nsproxy->ipc_ns;
70112
70113- msg_ops.getnew = newque;
70114- msg_ops.associate = msg_security;
70115- msg_ops.more_checks = NULL;
70116-
70117 msg_params.key = key;
70118 msg_params.flg = msgflg;
70119
70120diff --git a/ipc/sem.c b/ipc/sem.c
70121index b781007..f738b04 100644
70122--- a/ipc/sem.c
70123+++ b/ipc/sem.c
70124@@ -309,10 +309,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
70125 return 0;
70126 }
70127
70128+static struct ipc_ops sem_ops = {
70129+ .getnew = newary,
70130+ .associate = sem_security,
70131+ .more_checks = sem_more_checks
70132+};
70133+
70134 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70135 {
70136 struct ipc_namespace *ns;
70137- struct ipc_ops sem_ops;
70138 struct ipc_params sem_params;
70139
70140 ns = current->nsproxy->ipc_ns;
70141@@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70142 if (nsems < 0 || nsems > ns->sc_semmsl)
70143 return -EINVAL;
70144
70145- sem_ops.getnew = newary;
70146- sem_ops.associate = sem_security;
70147- sem_ops.more_checks = sem_more_checks;
70148-
70149 sem_params.key = key;
70150 sem_params.flg = semflg;
70151 sem_params.u.nsems = nsems;
70152@@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
70153 ushort* sem_io = fast_sem_io;
70154 int nsems;
70155
70156+ pax_track_stack();
70157+
70158 sma = sem_lock_check(ns, semid);
70159 if (IS_ERR(sma))
70160 return PTR_ERR(sma);
70161@@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
70162 unsigned long jiffies_left = 0;
70163 struct ipc_namespace *ns;
70164
70165+ pax_track_stack();
70166+
70167 ns = current->nsproxy->ipc_ns;
70168
70169 if (nsops < 1 || semid < 0)
70170diff --git a/ipc/shm.c b/ipc/shm.c
70171index d30732c..7379456 100644
70172--- a/ipc/shm.c
70173+++ b/ipc/shm.c
70174@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
70175 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
70176 #endif
70177
70178+#ifdef CONFIG_GRKERNSEC
70179+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70180+ const time_t shm_createtime, const uid_t cuid,
70181+ const int shmid);
70182+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70183+ const time_t shm_createtime);
70184+#endif
70185+
70186 void shm_init_ns(struct ipc_namespace *ns)
70187 {
70188 ns->shm_ctlmax = SHMMAX;
70189@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
70190 shp->shm_lprid = 0;
70191 shp->shm_atim = shp->shm_dtim = 0;
70192 shp->shm_ctim = get_seconds();
70193+#ifdef CONFIG_GRKERNSEC
70194+ {
70195+ struct timespec timeval;
70196+ do_posix_clock_monotonic_gettime(&timeval);
70197+
70198+ shp->shm_createtime = timeval.tv_sec;
70199+ }
70200+#endif
70201 shp->shm_segsz = size;
70202 shp->shm_nattch = 0;
70203 shp->shm_file = file;
70204@@ -446,18 +462,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
70205 return 0;
70206 }
70207
70208+static struct ipc_ops shm_ops = {
70209+ .getnew = newseg,
70210+ .associate = shm_security,
70211+ .more_checks = shm_more_checks
70212+};
70213+
70214 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
70215 {
70216 struct ipc_namespace *ns;
70217- struct ipc_ops shm_ops;
70218 struct ipc_params shm_params;
70219
70220 ns = current->nsproxy->ipc_ns;
70221
70222- shm_ops.getnew = newseg;
70223- shm_ops.associate = shm_security;
70224- shm_ops.more_checks = shm_more_checks;
70225-
70226 shm_params.key = key;
70227 shm_params.flg = shmflg;
70228 shm_params.u.size = size;
70229@@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
70230 if (err)
70231 goto out_unlock;
70232
70233+#ifdef CONFIG_GRKERNSEC
70234+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
70235+ shp->shm_perm.cuid, shmid) ||
70236+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
70237+ err = -EACCES;
70238+ goto out_unlock;
70239+ }
70240+#endif
70241+
70242 path.dentry = dget(shp->shm_file->f_path.dentry);
70243 path.mnt = shp->shm_file->f_path.mnt;
70244 shp->shm_nattch++;
70245+#ifdef CONFIG_GRKERNSEC
70246+ shp->shm_lapid = current->pid;
70247+#endif
70248 size = i_size_read(path.dentry->d_inode);
70249 shm_unlock(shp);
70250
70251diff --git a/kernel/acct.c b/kernel/acct.c
70252index a6605ca..ca91111 100644
70253--- a/kernel/acct.c
70254+++ b/kernel/acct.c
70255@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
70256 */
70257 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
70258 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
70259- file->f_op->write(file, (char *)&ac,
70260+ file->f_op->write(file, (char __force_user *)&ac,
70261 sizeof(acct_t), &file->f_pos);
70262 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
70263 set_fs(fs);
70264diff --git a/kernel/audit.c b/kernel/audit.c
70265index 5feed23..513b02c 100644
70266--- a/kernel/audit.c
70267+++ b/kernel/audit.c
70268@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
70269 3) suppressed due to audit_rate_limit
70270 4) suppressed due to audit_backlog_limit
70271 */
70272-static atomic_t audit_lost = ATOMIC_INIT(0);
70273+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
70274
70275 /* The netlink socket. */
70276 static struct sock *audit_sock;
70277@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
70278 unsigned long now;
70279 int print;
70280
70281- atomic_inc(&audit_lost);
70282+ atomic_inc_unchecked(&audit_lost);
70283
70284 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
70285
70286@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
70287 printk(KERN_WARNING
70288 "audit: audit_lost=%d audit_rate_limit=%d "
70289 "audit_backlog_limit=%d\n",
70290- atomic_read(&audit_lost),
70291+ atomic_read_unchecked(&audit_lost),
70292 audit_rate_limit,
70293 audit_backlog_limit);
70294 audit_panic(message);
70295@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70296 status_set.pid = audit_pid;
70297 status_set.rate_limit = audit_rate_limit;
70298 status_set.backlog_limit = audit_backlog_limit;
70299- status_set.lost = atomic_read(&audit_lost);
70300+ status_set.lost = atomic_read_unchecked(&audit_lost);
70301 status_set.backlog = skb_queue_len(&audit_skb_queue);
70302 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
70303 &status_set, sizeof(status_set));
70304@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70305 spin_unlock_irq(&tsk->sighand->siglock);
70306 }
70307 read_unlock(&tasklist_lock);
70308- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
70309- &s, sizeof(s));
70310+
70311+ if (!err)
70312+ audit_send_reply(NETLINK_CB(skb).pid, seq,
70313+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
70314 break;
70315 }
70316 case AUDIT_TTY_SET: {
70317diff --git a/kernel/auditsc.c b/kernel/auditsc.c
70318index 267e484..f8e295a 100644
70319--- a/kernel/auditsc.c
70320+++ b/kernel/auditsc.c
70321@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
70322 }
70323
70324 /* global counter which is incremented every time something logs in */
70325-static atomic_t session_id = ATOMIC_INIT(0);
70326+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
70327
70328 /**
70329 * audit_set_loginuid - set a task's audit_context loginuid
70330@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
70331 */
70332 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
70333 {
70334- unsigned int sessionid = atomic_inc_return(&session_id);
70335+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
70336 struct audit_context *context = task->audit_context;
70337
70338 if (context && context->in_syscall) {
70339diff --git a/kernel/capability.c b/kernel/capability.c
70340index 8a944f5..db5001e 100644
70341--- a/kernel/capability.c
70342+++ b/kernel/capability.c
70343@@ -305,10 +305,26 @@ int capable(int cap)
70344 BUG();
70345 }
70346
70347- if (security_capable(cap) == 0) {
70348+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
70349 current->flags |= PF_SUPERPRIV;
70350 return 1;
70351 }
70352 return 0;
70353 }
70354+
70355+int capable_nolog(int cap)
70356+{
70357+ if (unlikely(!cap_valid(cap))) {
70358+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
70359+ BUG();
70360+ }
70361+
70362+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
70363+ current->flags |= PF_SUPERPRIV;
70364+ return 1;
70365+ }
70366+ return 0;
70367+}
70368+
70369 EXPORT_SYMBOL(capable);
70370+EXPORT_SYMBOL(capable_nolog);
70371diff --git a/kernel/cgroup.c b/kernel/cgroup.c
70372index 1fbcc74..7000012 100644
70373--- a/kernel/cgroup.c
70374+++ b/kernel/cgroup.c
70375@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
70376 struct hlist_head *hhead;
70377 struct cg_cgroup_link *link;
70378
70379+ pax_track_stack();
70380+
70381 /* First see if we already have a cgroup group that matches
70382 * the desired set */
70383 read_lock(&css_set_lock);
70384diff --git a/kernel/compat.c b/kernel/compat.c
70385index 8bc5578..186e44a 100644
70386--- a/kernel/compat.c
70387+++ b/kernel/compat.c
70388@@ -108,7 +108,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
70389 mm_segment_t oldfs;
70390 long ret;
70391
70392- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
70393+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
70394 oldfs = get_fs();
70395 set_fs(KERNEL_DS);
70396 ret = hrtimer_nanosleep_restart(restart);
70397@@ -140,7 +140,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
70398 oldfs = get_fs();
70399 set_fs(KERNEL_DS);
70400 ret = hrtimer_nanosleep(&tu,
70401- rmtp ? (struct timespec __user *)&rmt : NULL,
70402+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
70403 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
70404 set_fs(oldfs);
70405
70406@@ -247,7 +247,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
70407 mm_segment_t old_fs = get_fs();
70408
70409 set_fs(KERNEL_DS);
70410- ret = sys_sigpending((old_sigset_t __user *) &s);
70411+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
70412 set_fs(old_fs);
70413 if (ret == 0)
70414 ret = put_user(s, set);
70415@@ -266,8 +266,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
70416 old_fs = get_fs();
70417 set_fs(KERNEL_DS);
70418 ret = sys_sigprocmask(how,
70419- set ? (old_sigset_t __user *) &s : NULL,
70420- oset ? (old_sigset_t __user *) &s : NULL);
70421+ set ? (old_sigset_t __force_user *) &s : NULL,
70422+ oset ? (old_sigset_t __force_user *) &s : NULL);
70423 set_fs(old_fs);
70424 if (ret == 0)
70425 if (oset)
70426@@ -310,7 +310,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
70427 mm_segment_t old_fs = get_fs();
70428
70429 set_fs(KERNEL_DS);
70430- ret = sys_old_getrlimit(resource, &r);
70431+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
70432 set_fs(old_fs);
70433
70434 if (!ret) {
70435@@ -385,7 +385,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
70436 mm_segment_t old_fs = get_fs();
70437
70438 set_fs(KERNEL_DS);
70439- ret = sys_getrusage(who, (struct rusage __user *) &r);
70440+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
70441 set_fs(old_fs);
70442
70443 if (ret)
70444@@ -412,8 +412,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
70445 set_fs (KERNEL_DS);
70446 ret = sys_wait4(pid,
70447 (stat_addr ?
70448- (unsigned int __user *) &status : NULL),
70449- options, (struct rusage __user *) &r);
70450+ (unsigned int __force_user *) &status : NULL),
70451+ options, (struct rusage __force_user *) &r);
70452 set_fs (old_fs);
70453
70454 if (ret > 0) {
70455@@ -438,8 +438,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
70456 memset(&info, 0, sizeof(info));
70457
70458 set_fs(KERNEL_DS);
70459- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
70460- uru ? (struct rusage __user *)&ru : NULL);
70461+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
70462+ uru ? (struct rusage __force_user *)&ru : NULL);
70463 set_fs(old_fs);
70464
70465 if ((ret < 0) || (info.si_signo == 0))
70466@@ -569,8 +569,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
70467 oldfs = get_fs();
70468 set_fs(KERNEL_DS);
70469 err = sys_timer_settime(timer_id, flags,
70470- (struct itimerspec __user *) &newts,
70471- (struct itimerspec __user *) &oldts);
70472+ (struct itimerspec __force_user *) &newts,
70473+ (struct itimerspec __force_user *) &oldts);
70474 set_fs(oldfs);
70475 if (!err && old && put_compat_itimerspec(old, &oldts))
70476 return -EFAULT;
70477@@ -587,7 +587,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
70478 oldfs = get_fs();
70479 set_fs(KERNEL_DS);
70480 err = sys_timer_gettime(timer_id,
70481- (struct itimerspec __user *) &ts);
70482+ (struct itimerspec __force_user *) &ts);
70483 set_fs(oldfs);
70484 if (!err && put_compat_itimerspec(setting, &ts))
70485 return -EFAULT;
70486@@ -606,7 +606,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
70487 oldfs = get_fs();
70488 set_fs(KERNEL_DS);
70489 err = sys_clock_settime(which_clock,
70490- (struct timespec __user *) &ts);
70491+ (struct timespec __force_user *) &ts);
70492 set_fs(oldfs);
70493 return err;
70494 }
70495@@ -621,7 +621,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
70496 oldfs = get_fs();
70497 set_fs(KERNEL_DS);
70498 err = sys_clock_gettime(which_clock,
70499- (struct timespec __user *) &ts);
70500+ (struct timespec __force_user *) &ts);
70501 set_fs(oldfs);
70502 if (!err && put_compat_timespec(&ts, tp))
70503 return -EFAULT;
70504@@ -638,7 +638,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
70505 oldfs = get_fs();
70506 set_fs(KERNEL_DS);
70507 err = sys_clock_getres(which_clock,
70508- (struct timespec __user *) &ts);
70509+ (struct timespec __force_user *) &ts);
70510 set_fs(oldfs);
70511 if (!err && tp && put_compat_timespec(&ts, tp))
70512 return -EFAULT;
70513@@ -650,9 +650,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
70514 long err;
70515 mm_segment_t oldfs;
70516 struct timespec tu;
70517- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
70518+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
70519
70520- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
70521+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
70522 oldfs = get_fs();
70523 set_fs(KERNEL_DS);
70524 err = clock_nanosleep_restart(restart);
70525@@ -684,8 +684,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
70526 oldfs = get_fs();
70527 set_fs(KERNEL_DS);
70528 err = sys_clock_nanosleep(which_clock, flags,
70529- (struct timespec __user *) &in,
70530- (struct timespec __user *) &out);
70531+ (struct timespec __force_user *) &in,
70532+ (struct timespec __force_user *) &out);
70533 set_fs(oldfs);
70534
70535 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
70536diff --git a/kernel/configs.c b/kernel/configs.c
70537index abaee68..047facd 100644
70538--- a/kernel/configs.c
70539+++ b/kernel/configs.c
70540@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
70541 struct proc_dir_entry *entry;
70542
70543 /* create the current config file */
70544+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
70545+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
70546+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
70547+ &ikconfig_file_ops);
70548+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70549+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
70550+ &ikconfig_file_ops);
70551+#endif
70552+#else
70553 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
70554 &ikconfig_file_ops);
70555+#endif
70556+
70557 if (!entry)
70558 return -ENOMEM;
70559
70560diff --git a/kernel/cpu.c b/kernel/cpu.c
70561index 7e8b6ac..8921388 100644
70562--- a/kernel/cpu.c
70563+++ b/kernel/cpu.c
70564@@ -19,7 +19,7 @@
70565 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
70566 static DEFINE_MUTEX(cpu_add_remove_lock);
70567
70568-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
70569+static RAW_NOTIFIER_HEAD(cpu_chain);
70570
70571 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
70572 * Should always be manipulated under cpu_add_remove_lock
70573diff --git a/kernel/cred.c b/kernel/cred.c
70574index 0b5b5fc..419b86a 100644
70575--- a/kernel/cred.c
70576+++ b/kernel/cred.c
70577@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
70578 */
70579 void __put_cred(struct cred *cred)
70580 {
70581+ pax_track_stack();
70582+
70583 kdebug("__put_cred(%p{%d,%d})", cred,
70584 atomic_read(&cred->usage),
70585 read_cred_subscribers(cred));
70586@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
70587 {
70588 struct cred *cred;
70589
70590+ pax_track_stack();
70591+
70592 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
70593 atomic_read(&tsk->cred->usage),
70594 read_cred_subscribers(tsk->cred));
70595@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct task_struct *task)
70596 {
70597 const struct cred *cred;
70598
70599+ pax_track_stack();
70600+
70601 rcu_read_lock();
70602
70603 do {
70604@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
70605 {
70606 struct cred *new;
70607
70608+ pax_track_stack();
70609+
70610 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
70611 if (!new)
70612 return NULL;
70613@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
70614 const struct cred *old;
70615 struct cred *new;
70616
70617+ pax_track_stack();
70618+
70619 validate_process_creds();
70620
70621 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
70622@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
70623 struct thread_group_cred *tgcred = NULL;
70624 struct cred *new;
70625
70626+ pax_track_stack();
70627+
70628 #ifdef CONFIG_KEYS
70629 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
70630 if (!tgcred)
70631@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
70632 struct cred *new;
70633 int ret;
70634
70635+ pax_track_stack();
70636+
70637 mutex_init(&p->cred_guard_mutex);
70638
70639 if (
70640@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
70641 struct task_struct *task = current;
70642 const struct cred *old = task->real_cred;
70643
70644+ pax_track_stack();
70645+
70646 kdebug("commit_creds(%p{%d,%d})", new,
70647 atomic_read(&new->usage),
70648 read_cred_subscribers(new));
70649@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
70650
70651 get_cred(new); /* we will require a ref for the subj creds too */
70652
70653+ gr_set_role_label(task, new->uid, new->gid);
70654+
70655 /* dumpability changes */
70656 if (old->euid != new->euid ||
70657 old->egid != new->egid ||
70658@@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
70659 key_fsgid_changed(task);
70660
70661 /* do it
70662- * - What if a process setreuid()'s and this brings the
70663- * new uid over his NPROC rlimit? We can check this now
70664- * cheaply with the new uid cache, so if it matters
70665- * we should be checking for it. -DaveM
70666+ * RLIMIT_NPROC limits on user->processes have already been checked
70667+ * in set_user().
70668 */
70669 alter_cred_subscribers(new, 2);
70670 if (new->user != old->user)
70671@@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
70672 */
70673 void abort_creds(struct cred *new)
70674 {
70675+ pax_track_stack();
70676+
70677 kdebug("abort_creds(%p{%d,%d})", new,
70678 atomic_read(&new->usage),
70679 read_cred_subscribers(new));
70680@@ -629,6 +647,8 @@ const struct cred *override_creds(const struct cred *new)
70681 {
70682 const struct cred *old = current->cred;
70683
70684+ pax_track_stack();
70685+
70686 kdebug("override_creds(%p{%d,%d})", new,
70687 atomic_read(&new->usage),
70688 read_cred_subscribers(new));
70689@@ -658,6 +678,8 @@ void revert_creds(const struct cred *old)
70690 {
70691 const struct cred *override = current->cred;
70692
70693+ pax_track_stack();
70694+
70695 kdebug("revert_creds(%p{%d,%d})", old,
70696 atomic_read(&old->usage),
70697 read_cred_subscribers(old));
70698@@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
70699 const struct cred *old;
70700 struct cred *new;
70701
70702+ pax_track_stack();
70703+
70704 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
70705 if (!new)
70706 return NULL;
70707@@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
70708 */
70709 int set_security_override(struct cred *new, u32 secid)
70710 {
70711+ pax_track_stack();
70712+
70713 return security_kernel_act_as(new, secid);
70714 }
70715 EXPORT_SYMBOL(set_security_override);
70716@@ -777,6 +803,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
70717 u32 secid;
70718 int ret;
70719
70720+ pax_track_stack();
70721+
70722 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
70723 if (ret < 0)
70724 return ret;
70725diff --git a/kernel/exit.c b/kernel/exit.c
70726index 0f8fae3..9344a56 100644
70727--- a/kernel/exit.c
70728+++ b/kernel/exit.c
70729@@ -55,6 +55,10 @@
70730 #include <asm/pgtable.h>
70731 #include <asm/mmu_context.h>
70732
70733+#ifdef CONFIG_GRKERNSEC
70734+extern rwlock_t grsec_exec_file_lock;
70735+#endif
70736+
70737 static void exit_mm(struct task_struct * tsk);
70738
70739 static void __unhash_process(struct task_struct *p)
70740@@ -174,6 +178,10 @@ void release_task(struct task_struct * p)
70741 struct task_struct *leader;
70742 int zap_leader;
70743 repeat:
70744+#ifdef CONFIG_NET
70745+ gr_del_task_from_ip_table(p);
70746+#endif
70747+
70748 tracehook_prepare_release_task(p);
70749 /* don't need to get the RCU readlock here - the process is dead and
70750 * can't be modifying its own credentials */
70751@@ -397,7 +405,7 @@ int allow_signal(int sig)
70752 * know it'll be handled, so that they don't get converted to
70753 * SIGKILL or just silently dropped.
70754 */
70755- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70756+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70757 recalc_sigpending();
70758 spin_unlock_irq(&current->sighand->siglock);
70759 return 0;
70760@@ -433,6 +441,17 @@ void daemonize(const char *name, ...)
70761 vsnprintf(current->comm, sizeof(current->comm), name, args);
70762 va_end(args);
70763
70764+#ifdef CONFIG_GRKERNSEC
70765+ write_lock(&grsec_exec_file_lock);
70766+ if (current->exec_file) {
70767+ fput(current->exec_file);
70768+ current->exec_file = NULL;
70769+ }
70770+ write_unlock(&grsec_exec_file_lock);
70771+#endif
70772+
70773+ gr_set_kernel_label(current);
70774+
70775 /*
70776 * If we were started as result of loading a module, close all of the
70777 * user space pages. We don't need them, and if we didn't close them
70778@@ -897,17 +916,17 @@ NORET_TYPE void do_exit(long code)
70779 struct task_struct *tsk = current;
70780 int group_dead;
70781
70782- profile_task_exit(tsk);
70783-
70784- WARN_ON(atomic_read(&tsk->fs_excl));
70785-
70786+ /*
70787+ * Check this first since set_fs() below depends on
70788+ * current_thread_info(), which we better not access when we're in
70789+ * interrupt context. Other than that, we want to do the set_fs()
70790+ * as early as possible.
70791+ */
70792 if (unlikely(in_interrupt()))
70793 panic("Aiee, killing interrupt handler!");
70794- if (unlikely(!tsk->pid))
70795- panic("Attempted to kill the idle task!");
70796
70797 /*
70798- * If do_exit is called because this processes oopsed, it's possible
70799+ * If do_exit is called because this processes Oops'ed, it's possible
70800 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
70801 * continuing. Amongst other possible reasons, this is to prevent
70802 * mm_release()->clear_child_tid() from writing to a user-controlled
70803@@ -915,6 +934,13 @@ NORET_TYPE void do_exit(long code)
70804 */
70805 set_fs(USER_DS);
70806
70807+ profile_task_exit(tsk);
70808+
70809+ WARN_ON(atomic_read(&tsk->fs_excl));
70810+
70811+ if (unlikely(!tsk->pid))
70812+ panic("Attempted to kill the idle task!");
70813+
70814 tracehook_report_exit(&code);
70815
70816 validate_creds_for_do_exit(tsk);
70817@@ -973,6 +999,9 @@ NORET_TYPE void do_exit(long code)
70818 tsk->exit_code = code;
70819 taskstats_exit(tsk, group_dead);
70820
70821+ gr_acl_handle_psacct(tsk, code);
70822+ gr_acl_handle_exit();
70823+
70824 exit_mm(tsk);
70825
70826 if (group_dead)
70827@@ -1188,7 +1217,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
70828
70829 if (unlikely(wo->wo_flags & WNOWAIT)) {
70830 int exit_code = p->exit_code;
70831- int why, status;
70832+ int why;
70833
70834 get_task_struct(p);
70835 read_unlock(&tasklist_lock);
70836diff --git a/kernel/fork.c b/kernel/fork.c
70837index 4bde56f..29a9bab 100644
70838--- a/kernel/fork.c
70839+++ b/kernel/fork.c
70840@@ -253,7 +253,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70841 *stackend = STACK_END_MAGIC; /* for overflow detection */
70842
70843 #ifdef CONFIG_CC_STACKPROTECTOR
70844- tsk->stack_canary = get_random_int();
70845+ tsk->stack_canary = pax_get_random_long();
70846 #endif
70847
70848 /* One for us, one for whoever does the "release_task()" (usually parent) */
70849@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70850 mm->locked_vm = 0;
70851 mm->mmap = NULL;
70852 mm->mmap_cache = NULL;
70853- mm->free_area_cache = oldmm->mmap_base;
70854- mm->cached_hole_size = ~0UL;
70855+ mm->free_area_cache = oldmm->free_area_cache;
70856+ mm->cached_hole_size = oldmm->cached_hole_size;
70857 mm->map_count = 0;
70858 cpumask_clear(mm_cpumask(mm));
70859 mm->mm_rb = RB_ROOT;
70860@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70861 tmp->vm_flags &= ~VM_LOCKED;
70862 tmp->vm_mm = mm;
70863 tmp->vm_next = tmp->vm_prev = NULL;
70864+ tmp->vm_mirror = NULL;
70865 anon_vma_link(tmp);
70866 file = tmp->vm_file;
70867 if (file) {
70868@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70869 if (retval)
70870 goto out;
70871 }
70872+
70873+#ifdef CONFIG_PAX_SEGMEXEC
70874+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70875+ struct vm_area_struct *mpnt_m;
70876+
70877+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70878+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70879+
70880+ if (!mpnt->vm_mirror)
70881+ continue;
70882+
70883+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70884+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70885+ mpnt->vm_mirror = mpnt_m;
70886+ } else {
70887+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70888+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70889+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70890+ mpnt->vm_mirror->vm_mirror = mpnt;
70891+ }
70892+ }
70893+ BUG_ON(mpnt_m);
70894+ }
70895+#endif
70896+
70897 /* a new mm has just been created */
70898 arch_dup_mmap(oldmm, mm);
70899 retval = 0;
70900@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70901 write_unlock(&fs->lock);
70902 return -EAGAIN;
70903 }
70904- fs->users++;
70905+ atomic_inc(&fs->users);
70906 write_unlock(&fs->lock);
70907 return 0;
70908 }
70909 tsk->fs = copy_fs_struct(fs);
70910 if (!tsk->fs)
70911 return -ENOMEM;
70912+ gr_set_chroot_entries(tsk, &tsk->fs->root);
70913 return 0;
70914 }
70915
70916@@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70917 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70918 #endif
70919 retval = -EAGAIN;
70920+
70921+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70922+
70923 if (atomic_read(&p->real_cred->user->processes) >=
70924 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
70925- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70926- p->real_cred->user != INIT_USER)
70927+ if (p->real_cred->user != INIT_USER &&
70928+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
70929 goto bad_fork_free;
70930 }
70931+ current->flags &= ~PF_NPROC_EXCEEDED;
70932
70933 retval = copy_creds(p, clone_flags);
70934 if (retval < 0)
70935@@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70936 goto bad_fork_free_pid;
70937 }
70938
70939+ gr_copy_label(p);
70940+
70941 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
70942 /*
70943 * Clear TID on mm_release()?
70944@@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
70945 bad_fork_free:
70946 free_task(p);
70947 fork_out:
70948+ gr_log_forkfail(retval);
70949+
70950 return ERR_PTR(retval);
70951 }
70952
70953@@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
70954 if (clone_flags & CLONE_PARENT_SETTID)
70955 put_user(nr, parent_tidptr);
70956
70957+ gr_handle_brute_check();
70958+
70959 if (clone_flags & CLONE_VFORK) {
70960 p->vfork_done = &vfork;
70961 init_completion(&vfork);
70962@@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70963 return 0;
70964
70965 /* don't need lock here; in the worst case we'll do useless copy */
70966- if (fs->users == 1)
70967+ if (atomic_read(&fs->users) == 1)
70968 return 0;
70969
70970 *new_fsp = copy_fs_struct(fs);
70971@@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70972 fs = current->fs;
70973 write_lock(&fs->lock);
70974 current->fs = new_fs;
70975- if (--fs->users)
70976+ gr_set_chroot_entries(current, &current->fs->root);
70977+ if (atomic_dec_return(&fs->users))
70978 new_fs = NULL;
70979 else
70980 new_fs = fs;
70981diff --git a/kernel/futex.c b/kernel/futex.c
70982index fb98c9f..333faec 100644
70983--- a/kernel/futex.c
70984+++ b/kernel/futex.c
70985@@ -54,6 +54,7 @@
70986 #include <linux/mount.h>
70987 #include <linux/pagemap.h>
70988 #include <linux/syscalls.h>
70989+#include <linux/ptrace.h>
70990 #include <linux/signal.h>
70991 #include <linux/module.h>
70992 #include <linux/magic.h>
70993@@ -223,6 +224,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70994 struct page *page;
70995 int err, ro = 0;
70996
70997+#ifdef CONFIG_PAX_SEGMEXEC
70998+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70999+ return -EFAULT;
71000+#endif
71001+
71002 /*
71003 * The futex address must be "naturally" aligned.
71004 */
71005@@ -1819,6 +1825,8 @@ static int futex_wait(u32 __user *uaddr, int fshared,
71006 struct futex_q q;
71007 int ret;
71008
71009+ pax_track_stack();
71010+
71011 if (!bitset)
71012 return -EINVAL;
71013
71014@@ -1871,7 +1879,7 @@ retry:
71015
71016 restart = &current_thread_info()->restart_block;
71017 restart->fn = futex_wait_restart;
71018- restart->futex.uaddr = (u32 *)uaddr;
71019+ restart->futex.uaddr = uaddr;
71020 restart->futex.val = val;
71021 restart->futex.time = abs_time->tv64;
71022 restart->futex.bitset = bitset;
71023@@ -2233,6 +2241,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared,
71024 struct futex_q q;
71025 int res, ret;
71026
71027+ pax_track_stack();
71028+
71029 if (!bitset)
71030 return -EINVAL;
71031
71032@@ -2423,6 +2433,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
71033 if (!p)
71034 goto err_unlock;
71035 ret = -EPERM;
71036+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71037+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71038+ goto err_unlock;
71039+#endif
71040 pcred = __task_cred(p);
71041 if (cred->euid != pcred->euid &&
71042 cred->euid != pcred->uid &&
71043@@ -2489,7 +2503,7 @@ retry:
71044 */
71045 static inline int fetch_robust_entry(struct robust_list __user **entry,
71046 struct robust_list __user * __user *head,
71047- int *pi)
71048+ unsigned int *pi)
71049 {
71050 unsigned long uentry;
71051
71052@@ -2670,6 +2684,7 @@ static int __init futex_init(void)
71053 {
71054 u32 curval;
71055 int i;
71056+ mm_segment_t oldfs;
71057
71058 /*
71059 * This will fail and we want it. Some arch implementations do
71060@@ -2681,7 +2696,10 @@ static int __init futex_init(void)
71061 * implementation, the non functional ones will return
71062 * -ENOSYS.
71063 */
71064+ oldfs = get_fs();
71065+ set_fs(USER_DS);
71066 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
71067+ set_fs(oldfs);
71068 if (curval == -EFAULT)
71069 futex_cmpxchg_enabled = 1;
71070
71071diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
71072index 2357165..eb25501 100644
71073--- a/kernel/futex_compat.c
71074+++ b/kernel/futex_compat.c
71075@@ -10,6 +10,7 @@
71076 #include <linux/compat.h>
71077 #include <linux/nsproxy.h>
71078 #include <linux/futex.h>
71079+#include <linux/ptrace.h>
71080
71081 #include <asm/uaccess.h>
71082
71083@@ -135,7 +136,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71084 {
71085 struct compat_robust_list_head __user *head;
71086 unsigned long ret;
71087- const struct cred *cred = current_cred(), *pcred;
71088+ const struct cred *cred = current_cred();
71089+ const struct cred *pcred;
71090
71091 if (!futex_cmpxchg_enabled)
71092 return -ENOSYS;
71093@@ -151,6 +153,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71094 if (!p)
71095 goto err_unlock;
71096 ret = -EPERM;
71097+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71098+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71099+ goto err_unlock;
71100+#endif
71101 pcred = __task_cred(p);
71102 if (cred->euid != pcred->euid &&
71103 cred->euid != pcred->uid &&
71104diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
71105index 9b22d03..6295b62 100644
71106--- a/kernel/gcov/base.c
71107+++ b/kernel/gcov/base.c
71108@@ -102,11 +102,6 @@ void gcov_enable_events(void)
71109 }
71110
71111 #ifdef CONFIG_MODULES
71112-static inline int within(void *addr, void *start, unsigned long size)
71113-{
71114- return ((addr >= start) && (addr < start + size));
71115-}
71116-
71117 /* Update list and generate events when modules are unloaded. */
71118 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71119 void *data)
71120@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71121 prev = NULL;
71122 /* Remove entries located in module from linked list. */
71123 for (info = gcov_info_head; info; info = info->next) {
71124- if (within(info, mod->module_core, mod->core_size)) {
71125+ if (within_module_core_rw((unsigned long)info, mod)) {
71126 if (prev)
71127 prev->next = info->next;
71128 else
71129diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
71130index a6e9d00..a0da4f9 100644
71131--- a/kernel/hrtimer.c
71132+++ b/kernel/hrtimer.c
71133@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
71134 local_irq_restore(flags);
71135 }
71136
71137-static void run_hrtimer_softirq(struct softirq_action *h)
71138+static void run_hrtimer_softirq(void)
71139 {
71140 hrtimer_peek_ahead_timers();
71141 }
71142diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
71143index 8b6b8b6..6bc87df 100644
71144--- a/kernel/kallsyms.c
71145+++ b/kernel/kallsyms.c
71146@@ -11,6 +11,9 @@
71147 * Changed the compression method from stem compression to "table lookup"
71148 * compression (see scripts/kallsyms.c for a more complete description)
71149 */
71150+#ifdef CONFIG_GRKERNSEC_HIDESYM
71151+#define __INCLUDED_BY_HIDESYM 1
71152+#endif
71153 #include <linux/kallsyms.h>
71154 #include <linux/module.h>
71155 #include <linux/init.h>
71156@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
71157
71158 static inline int is_kernel_inittext(unsigned long addr)
71159 {
71160+ if (system_state != SYSTEM_BOOTING)
71161+ return 0;
71162+
71163 if (addr >= (unsigned long)_sinittext
71164 && addr <= (unsigned long)_einittext)
71165 return 1;
71166 return 0;
71167 }
71168
71169+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71170+#ifdef CONFIG_MODULES
71171+static inline int is_module_text(unsigned long addr)
71172+{
71173+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
71174+ return 1;
71175+
71176+ addr = ktla_ktva(addr);
71177+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
71178+}
71179+#else
71180+static inline int is_module_text(unsigned long addr)
71181+{
71182+ return 0;
71183+}
71184+#endif
71185+#endif
71186+
71187 static inline int is_kernel_text(unsigned long addr)
71188 {
71189 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
71190@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigned long addr)
71191
71192 static inline int is_kernel(unsigned long addr)
71193 {
71194+
71195+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71196+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
71197+ return 1;
71198+
71199+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
71200+#else
71201 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
71202+#endif
71203+
71204 return 1;
71205 return in_gate_area_no_task(addr);
71206 }
71207
71208 static int is_ksym_addr(unsigned long addr)
71209 {
71210+
71211+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71212+ if (is_module_text(addr))
71213+ return 0;
71214+#endif
71215+
71216 if (all_var)
71217 return is_kernel(addr);
71218
71219@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
71220
71221 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
71222 {
71223- iter->name[0] = '\0';
71224 iter->nameoff = get_symbol_offset(new_pos);
71225 iter->pos = new_pos;
71226 }
71227@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, void *p)
71228 {
71229 struct kallsym_iter *iter = m->private;
71230
71231+#ifdef CONFIG_GRKERNSEC_HIDESYM
71232+ if (current_uid())
71233+ return 0;
71234+#endif
71235+
71236 /* Some debugging symbols have no name. Ignore them. */
71237 if (!iter->name[0])
71238 return 0;
71239@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
71240 struct kallsym_iter *iter;
71241 int ret;
71242
71243- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
71244+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
71245 if (!iter)
71246 return -ENOMEM;
71247 reset_iter(iter, 0);
71248diff --git a/kernel/kexec.c b/kernel/kexec.c
71249index f336e21..9c1c20b 100644
71250--- a/kernel/kexec.c
71251+++ b/kernel/kexec.c
71252@@ -1028,7 +1028,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
71253 unsigned long flags)
71254 {
71255 struct compat_kexec_segment in;
71256- struct kexec_segment out, __user *ksegments;
71257+ struct kexec_segment out;
71258+ struct kexec_segment __user *ksegments;
71259 unsigned long i, result;
71260
71261 /* Don't allow clients that don't understand the native
71262diff --git a/kernel/kgdb.c b/kernel/kgdb.c
71263index 53dae4b..9ba3743 100644
71264--- a/kernel/kgdb.c
71265+++ b/kernel/kgdb.c
71266@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
71267 /* Guard for recursive entry */
71268 static int exception_level;
71269
71270-static struct kgdb_io *kgdb_io_ops;
71271+static const struct kgdb_io *kgdb_io_ops;
71272 static DEFINE_SPINLOCK(kgdb_registration_lock);
71273
71274 /* kgdb console driver is loaded */
71275@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1);
71276 */
71277 static atomic_t passive_cpu_wait[NR_CPUS];
71278 static atomic_t cpu_in_kgdb[NR_CPUS];
71279-atomic_t kgdb_setting_breakpoint;
71280+atomic_unchecked_t kgdb_setting_breakpoint;
71281
71282 struct task_struct *kgdb_usethread;
71283 struct task_struct *kgdb_contthread;
71284@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBYTES +
71285 sizeof(unsigned long)];
71286
71287 /* to keep track of the CPU which is doing the single stepping*/
71288-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71289+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71290
71291 /*
71292 * If you are debugging a problem where roundup (the collection of
71293@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
71294 return 0;
71295 if (kgdb_connected)
71296 return 1;
71297- if (atomic_read(&kgdb_setting_breakpoint))
71298+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
71299 return 1;
71300 if (print_wait)
71301 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
71302@@ -1426,8 +1426,8 @@ acquirelock:
71303 * instance of the exception handler wanted to come into the
71304 * debugger on a different CPU via a single step
71305 */
71306- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
71307- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
71308+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
71309+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
71310
71311 atomic_set(&kgdb_active, -1);
71312 touch_softlockup_watchdog();
71313@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void)
71314 *
71315 * Register it with the KGDB core.
71316 */
71317-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
71318+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
71319 {
71320 int err;
71321
71322@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_module);
71323 *
71324 * Unregister it with the KGDB core.
71325 */
71326-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
71327+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
71328 {
71329 BUG_ON(kgdb_connected);
71330
71331@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
71332 */
71333 void kgdb_breakpoint(void)
71334 {
71335- atomic_set(&kgdb_setting_breakpoint, 1);
71336+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
71337 wmb(); /* Sync point before breakpoint */
71338 arch_kgdb_breakpoint();
71339 wmb(); /* Sync point after breakpoint */
71340- atomic_set(&kgdb_setting_breakpoint, 0);
71341+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
71342 }
71343 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
71344
71345diff --git a/kernel/kmod.c b/kernel/kmod.c
71346index d206078..e27ba6a 100644
71347--- a/kernel/kmod.c
71348+++ b/kernel/kmod.c
71349@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
71350 * If module auto-loading support is disabled then this function
71351 * becomes a no-operation.
71352 */
71353-int __request_module(bool wait, const char *fmt, ...)
71354+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
71355 {
71356- va_list args;
71357 char module_name[MODULE_NAME_LEN];
71358 unsigned int max_modprobes;
71359 int ret;
71360- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
71361+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
71362 static char *envp[] = { "HOME=/",
71363 "TERM=linux",
71364 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
71365@@ -84,12 +83,24 @@ int __request_module(bool wait, const char *fmt, ...)
71366 if (ret)
71367 return ret;
71368
71369- va_start(args, fmt);
71370- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
71371- va_end(args);
71372+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
71373 if (ret >= MODULE_NAME_LEN)
71374 return -ENAMETOOLONG;
71375
71376+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71377+ if (!current_uid()) {
71378+ /* hack to workaround consolekit/udisks stupidity */
71379+ read_lock(&tasklist_lock);
71380+ if (!strcmp(current->comm, "mount") &&
71381+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
71382+ read_unlock(&tasklist_lock);
71383+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
71384+ return -EPERM;
71385+ }
71386+ read_unlock(&tasklist_lock);
71387+ }
71388+#endif
71389+
71390 /* If modprobe needs a service that is in a module, we get a recursive
71391 * loop. Limit the number of running kmod threads to max_threads/2 or
71392 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
71393@@ -123,6 +134,48 @@ int __request_module(bool wait, const char *fmt, ...)
71394 atomic_dec(&kmod_concurrent);
71395 return ret;
71396 }
71397+
71398+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
71399+{
71400+ va_list args;
71401+ int ret;
71402+
71403+ va_start(args, fmt);
71404+ ret = ____request_module(wait, module_param, fmt, args);
71405+ va_end(args);
71406+
71407+ return ret;
71408+}
71409+
71410+int __request_module(bool wait, const char *fmt, ...)
71411+{
71412+ va_list args;
71413+ int ret;
71414+
71415+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71416+ if (current_uid()) {
71417+ char module_param[MODULE_NAME_LEN];
71418+
71419+ memset(module_param, 0, sizeof(module_param));
71420+
71421+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
71422+
71423+ va_start(args, fmt);
71424+ ret = ____request_module(wait, module_param, fmt, args);
71425+ va_end(args);
71426+
71427+ return ret;
71428+ }
71429+#endif
71430+
71431+ va_start(args, fmt);
71432+ ret = ____request_module(wait, NULL, fmt, args);
71433+ va_end(args);
71434+
71435+ return ret;
71436+}
71437+
71438+
71439 EXPORT_SYMBOL(__request_module);
71440 #endif /* CONFIG_MODULES */
71441
71442@@ -228,7 +281,7 @@ static int wait_for_helper(void *data)
71443 *
71444 * Thus the __user pointer cast is valid here.
71445 */
71446- sys_wait4(pid, (int __user *)&ret, 0, NULL);
71447+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
71448
71449 /*
71450 * If ret is 0, either ____call_usermodehelper failed and the
71451diff --git a/kernel/kprobes.c b/kernel/kprobes.c
71452index 5240d75..5a6fb33 100644
71453--- a/kernel/kprobes.c
71454+++ b/kernel/kprobes.c
71455@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void)
71456 * kernel image and loaded module images reside. This is required
71457 * so x86_64 can correctly handle the %rip-relative fixups.
71458 */
71459- kip->insns = module_alloc(PAGE_SIZE);
71460+ kip->insns = module_alloc_exec(PAGE_SIZE);
71461 if (!kip->insns) {
71462 kfree(kip);
71463 return NULL;
71464@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
71465 */
71466 if (!list_is_singular(&kprobe_insn_pages)) {
71467 list_del(&kip->list);
71468- module_free(NULL, kip->insns);
71469+ module_free_exec(NULL, kip->insns);
71470 kfree(kip);
71471 }
71472 return 1;
71473@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
71474 {
71475 int i, err = 0;
71476 unsigned long offset = 0, size = 0;
71477- char *modname, namebuf[128];
71478+ char *modname, namebuf[KSYM_NAME_LEN];
71479 const char *symbol_name;
71480 void *addr;
71481 struct kprobe_blackpoint *kb;
71482@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
71483 const char *sym = NULL;
71484 unsigned int i = *(loff_t *) v;
71485 unsigned long offset = 0;
71486- char *modname, namebuf[128];
71487+ char *modname, namebuf[KSYM_NAME_LEN];
71488
71489 head = &kprobe_table[i];
71490 preempt_disable();
71491diff --git a/kernel/lockdep.c b/kernel/lockdep.c
71492index d86fe89..d12fc66 100644
71493--- a/kernel/lockdep.c
71494+++ b/kernel/lockdep.c
71495@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_trace = {
71496 /*
71497 * Various lockdep statistics:
71498 */
71499-atomic_t chain_lookup_hits;
71500-atomic_t chain_lookup_misses;
71501-atomic_t hardirqs_on_events;
71502-atomic_t hardirqs_off_events;
71503-atomic_t redundant_hardirqs_on;
71504-atomic_t redundant_hardirqs_off;
71505-atomic_t softirqs_on_events;
71506-atomic_t softirqs_off_events;
71507-atomic_t redundant_softirqs_on;
71508-atomic_t redundant_softirqs_off;
71509-atomic_t nr_unused_locks;
71510-atomic_t nr_cyclic_checks;
71511-atomic_t nr_find_usage_forwards_checks;
71512-atomic_t nr_find_usage_backwards_checks;
71513+atomic_unchecked_t chain_lookup_hits;
71514+atomic_unchecked_t chain_lookup_misses;
71515+atomic_unchecked_t hardirqs_on_events;
71516+atomic_unchecked_t hardirqs_off_events;
71517+atomic_unchecked_t redundant_hardirqs_on;
71518+atomic_unchecked_t redundant_hardirqs_off;
71519+atomic_unchecked_t softirqs_on_events;
71520+atomic_unchecked_t softirqs_off_events;
71521+atomic_unchecked_t redundant_softirqs_on;
71522+atomic_unchecked_t redundant_softirqs_off;
71523+atomic_unchecked_t nr_unused_locks;
71524+atomic_unchecked_t nr_cyclic_checks;
71525+atomic_unchecked_t nr_find_usage_forwards_checks;
71526+atomic_unchecked_t nr_find_usage_backwards_checks;
71527 #endif
71528
71529 /*
71530@@ -577,6 +577,10 @@ static int static_obj(void *obj)
71531 int i;
71532 #endif
71533
71534+#ifdef CONFIG_PAX_KERNEXEC
71535+ start = ktla_ktva(start);
71536+#endif
71537+
71538 /*
71539 * static variable?
71540 */
71541@@ -592,8 +596,7 @@ static int static_obj(void *obj)
71542 */
71543 for_each_possible_cpu(i) {
71544 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
71545- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
71546- + per_cpu_offset(i);
71547+ end = start + PERCPU_ENOUGH_ROOM;
71548
71549 if ((addr >= start) && (addr < end))
71550 return 1;
71551@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
71552 if (!static_obj(lock->key)) {
71553 debug_locks_off();
71554 printk("INFO: trying to register non-static key.\n");
71555+ printk("lock:%pS key:%pS.\n", lock, lock->key);
71556 printk("the code is fine but needs lockdep annotation.\n");
71557 printk("turning off the locking correctness validator.\n");
71558 dump_stack();
71559@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71560 if (!class)
71561 return 0;
71562 }
71563- debug_atomic_inc((atomic_t *)&class->ops);
71564+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
71565 if (very_verbose(class)) {
71566 printk("\nacquire class [%p] %s", class->key, class->name);
71567 if (class->name_version > 1)
71568diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h
71569index a2ee95a..092f0f2 100644
71570--- a/kernel/lockdep_internals.h
71571+++ b/kernel/lockdep_internals.h
71572@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_class *class)
71573 /*
71574 * Various lockdep statistics:
71575 */
71576-extern atomic_t chain_lookup_hits;
71577-extern atomic_t chain_lookup_misses;
71578-extern atomic_t hardirqs_on_events;
71579-extern atomic_t hardirqs_off_events;
71580-extern atomic_t redundant_hardirqs_on;
71581-extern atomic_t redundant_hardirqs_off;
71582-extern atomic_t softirqs_on_events;
71583-extern atomic_t softirqs_off_events;
71584-extern atomic_t redundant_softirqs_on;
71585-extern atomic_t redundant_softirqs_off;
71586-extern atomic_t nr_unused_locks;
71587-extern atomic_t nr_cyclic_checks;
71588-extern atomic_t nr_cyclic_check_recursions;
71589-extern atomic_t nr_find_usage_forwards_checks;
71590-extern atomic_t nr_find_usage_forwards_recursions;
71591-extern atomic_t nr_find_usage_backwards_checks;
71592-extern atomic_t nr_find_usage_backwards_recursions;
71593-# define debug_atomic_inc(ptr) atomic_inc(ptr)
71594-# define debug_atomic_dec(ptr) atomic_dec(ptr)
71595-# define debug_atomic_read(ptr) atomic_read(ptr)
71596+extern atomic_unchecked_t chain_lookup_hits;
71597+extern atomic_unchecked_t chain_lookup_misses;
71598+extern atomic_unchecked_t hardirqs_on_events;
71599+extern atomic_unchecked_t hardirqs_off_events;
71600+extern atomic_unchecked_t redundant_hardirqs_on;
71601+extern atomic_unchecked_t redundant_hardirqs_off;
71602+extern atomic_unchecked_t softirqs_on_events;
71603+extern atomic_unchecked_t softirqs_off_events;
71604+extern atomic_unchecked_t redundant_softirqs_on;
71605+extern atomic_unchecked_t redundant_softirqs_off;
71606+extern atomic_unchecked_t nr_unused_locks;
71607+extern atomic_unchecked_t nr_cyclic_checks;
71608+extern atomic_unchecked_t nr_cyclic_check_recursions;
71609+extern atomic_unchecked_t nr_find_usage_forwards_checks;
71610+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
71611+extern atomic_unchecked_t nr_find_usage_backwards_checks;
71612+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
71613+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
71614+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
71615+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
71616 #else
71617 # define debug_atomic_inc(ptr) do { } while (0)
71618 # define debug_atomic_dec(ptr) do { } while (0)
71619diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
71620index d4aba4f..02a353f 100644
71621--- a/kernel/lockdep_proc.c
71622+++ b/kernel/lockdep_proc.c
71623@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
71624
71625 static void print_name(struct seq_file *m, struct lock_class *class)
71626 {
71627- char str[128];
71628+ char str[KSYM_NAME_LEN];
71629 const char *name = class->name;
71630
71631 if (!name) {
71632diff --git a/kernel/module.c b/kernel/module.c
71633index 4b270e6..2226274 100644
71634--- a/kernel/module.c
71635+++ b/kernel/module.c
71636@@ -55,6 +55,7 @@
71637 #include <linux/async.h>
71638 #include <linux/percpu.h>
71639 #include <linux/kmemleak.h>
71640+#include <linux/grsecurity.h>
71641
71642 #define CREATE_TRACE_POINTS
71643 #include <trace/events/module.h>
71644@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
71645 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71646
71647 /* Bounds of module allocation, for speeding __module_address */
71648-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71649+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71650+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71651
71652 int register_module_notifier(struct notifier_block * nb)
71653 {
71654@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
71655 return true;
71656
71657 list_for_each_entry_rcu(mod, &modules, list) {
71658- struct symsearch arr[] = {
71659+ struct symsearch modarr[] = {
71660 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71661 NOT_GPL_ONLY, false },
71662 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71663@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
71664 #endif
71665 };
71666
71667- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71668+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71669 return true;
71670 }
71671 return false;
71672@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned long size, unsigned long align,
71673 void *ptr;
71674 int cpu;
71675
71676- if (align > PAGE_SIZE) {
71677+ if (align-1 >= PAGE_SIZE) {
71678 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71679 name, align, PAGE_SIZE);
71680 align = PAGE_SIZE;
71681@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
71682 * /sys/module/foo/sections stuff
71683 * J. Corbet <corbet@lwn.net>
71684 */
71685-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
71686+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71687
71688 static inline bool sect_empty(const Elf_Shdr *sect)
71689 {
71690@@ -1545,7 +1547,8 @@ static void free_module(struct module *mod)
71691 destroy_params(mod->kp, mod->num_kp);
71692
71693 /* This may be NULL, but that's OK */
71694- module_free(mod, mod->module_init);
71695+ module_free(mod, mod->module_init_rw);
71696+ module_free_exec(mod, mod->module_init_rx);
71697 kfree(mod->args);
71698 if (mod->percpu)
71699 percpu_modfree(mod->percpu);
71700@@ -1554,10 +1557,12 @@ static void free_module(struct module *mod)
71701 percpu_modfree(mod->refptr);
71702 #endif
71703 /* Free lock-classes: */
71704- lockdep_free_key_range(mod->module_core, mod->core_size);
71705+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71706+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71707
71708 /* Finally, free the core (containing the module structure) */
71709- module_free(mod, mod->module_core);
71710+ module_free_exec(mod, mod->module_core_rx);
71711+ module_free(mod, mod->module_core_rw);
71712
71713 #ifdef CONFIG_MPU
71714 update_protections(current->mm);
71715@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71716 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
71717 int ret = 0;
71718 const struct kernel_symbol *ksym;
71719+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71720+ int is_fs_load = 0;
71721+ int register_filesystem_found = 0;
71722+ char *p;
71723+
71724+ p = strstr(mod->args, "grsec_modharden_fs");
71725+
71726+ if (p) {
71727+ char *endptr = p + strlen("grsec_modharden_fs");
71728+ /* copy \0 as well */
71729+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71730+ is_fs_load = 1;
71731+ }
71732+#endif
71733+
71734
71735 for (i = 1; i < n; i++) {
71736+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71737+ const char *name = strtab + sym[i].st_name;
71738+
71739+ /* it's a real shame this will never get ripped and copied
71740+ upstream! ;(
71741+ */
71742+ if (is_fs_load && !strcmp(name, "register_filesystem"))
71743+ register_filesystem_found = 1;
71744+#endif
71745 switch (sym[i].st_shndx) {
71746 case SHN_COMMON:
71747 /* We compiled with -fno-common. These are not
71748@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71749 strtab + sym[i].st_name, mod);
71750 /* Ok if resolved. */
71751 if (ksym) {
71752+ pax_open_kernel();
71753 sym[i].st_value = ksym->value;
71754+ pax_close_kernel();
71755 break;
71756 }
71757
71758@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
71759 secbase = (unsigned long)mod->percpu;
71760 else
71761 secbase = sechdrs[sym[i].st_shndx].sh_addr;
71762+ pax_open_kernel();
71763 sym[i].st_value += secbase;
71764+ pax_close_kernel();
71765 break;
71766 }
71767 }
71768
71769+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71770+ if (is_fs_load && !register_filesystem_found) {
71771+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71772+ ret = -EPERM;
71773+ }
71774+#endif
71775+
71776 return ret;
71777 }
71778
71779@@ -1731,11 +1771,12 @@ static void layout_sections(struct module *mod,
71780 || s->sh_entsize != ~0UL
71781 || strstarts(secstrings + s->sh_name, ".init"))
71782 continue;
71783- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71784+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71785+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71786+ else
71787+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71788 DEBUGP("\t%s\n", secstrings + s->sh_name);
71789 }
71790- if (m == 0)
71791- mod->core_text_size = mod->core_size;
71792 }
71793
71794 DEBUGP("Init section allocation order:\n");
71795@@ -1748,12 +1789,13 @@ static void layout_sections(struct module *mod,
71796 || s->sh_entsize != ~0UL
71797 || !strstarts(secstrings + s->sh_name, ".init"))
71798 continue;
71799- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71800- | INIT_OFFSET_MASK);
71801+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71802+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71803+ else
71804+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71805+ s->sh_entsize |= INIT_OFFSET_MASK;
71806 DEBUGP("\t%s\n", secstrings + s->sh_name);
71807 }
71808- if (m == 0)
71809- mod->init_text_size = mod->init_size;
71810 }
71811 }
71812
71813@@ -1857,9 +1899,8 @@ static int is_exported(const char *name, unsigned long value,
71814
71815 /* As per nm */
71816 static char elf_type(const Elf_Sym *sym,
71817- Elf_Shdr *sechdrs,
71818- const char *secstrings,
71819- struct module *mod)
71820+ const Elf_Shdr *sechdrs,
71821+ const char *secstrings)
71822 {
71823 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
71824 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
71825@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struct module *mod,
71826
71827 /* Put symbol section at end of init part of module. */
71828 symsect->sh_flags |= SHF_ALLOC;
71829- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71830+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71831 symindex) | INIT_OFFSET_MASK;
71832 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
71833
71834@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struct module *mod,
71835 }
71836
71837 /* Append room for core symbols at end of core part. */
71838- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71839- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
71840+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71841+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
71842
71843 /* Put string table section at end of init part of module. */
71844 strsect->sh_flags |= SHF_ALLOC;
71845- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71846+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71847 strindex) | INIT_OFFSET_MASK;
71848 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
71849
71850 /* Append room for core symbols' strings at end of core part. */
71851- *pstroffs = mod->core_size;
71852+ *pstroffs = mod->core_size_rx;
71853 __set_bit(0, strmap);
71854- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
71855+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
71856
71857 return symoffs;
71858 }
71859@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *mod,
71860 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
71861 mod->strtab = (void *)sechdrs[strindex].sh_addr;
71862
71863+ pax_open_kernel();
71864+
71865 /* Set types up while we still have access to sections. */
71866 for (i = 0; i < mod->num_symtab; i++)
71867 mod->symtab[i].st_info
71868- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
71869+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
71870
71871- mod->core_symtab = dst = mod->module_core + symoffs;
71872+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
71873 src = mod->symtab;
71874 *dst = *src;
71875 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
71876@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *mod,
71877 }
71878 mod->core_num_syms = ndst;
71879
71880- mod->core_strtab = s = mod->module_core + stroffs;
71881+ mod->core_strtab = s = mod->module_core_rx + stroffs;
71882 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
71883 if (test_bit(i, strmap))
71884 *++s = mod->strtab[i];
71885+
71886+ pax_close_kernel();
71887 }
71888 #else
71889 static inline unsigned long layout_symtab(struct module *mod,
71890@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
71891 #endif
71892 }
71893
71894-static void *module_alloc_update_bounds(unsigned long size)
71895+static void *module_alloc_update_bounds_rw(unsigned long size)
71896 {
71897 void *ret = module_alloc(size);
71898
71899 if (ret) {
71900 /* Update module bounds. */
71901- if ((unsigned long)ret < module_addr_min)
71902- module_addr_min = (unsigned long)ret;
71903- if ((unsigned long)ret + size > module_addr_max)
71904- module_addr_max = (unsigned long)ret + size;
71905+ if ((unsigned long)ret < module_addr_min_rw)
71906+ module_addr_min_rw = (unsigned long)ret;
71907+ if ((unsigned long)ret + size > module_addr_max_rw)
71908+ module_addr_max_rw = (unsigned long)ret + size;
71909+ }
71910+ return ret;
71911+}
71912+
71913+static void *module_alloc_update_bounds_rx(unsigned long size)
71914+{
71915+ void *ret = module_alloc_exec(size);
71916+
71917+ if (ret) {
71918+ /* Update module bounds. */
71919+ if ((unsigned long)ret < module_addr_min_rx)
71920+ module_addr_min_rx = (unsigned long)ret;
71921+ if ((unsigned long)ret + size > module_addr_max_rx)
71922+ module_addr_max_rx = (unsigned long)ret + size;
71923 }
71924 return ret;
71925 }
71926@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
71927 unsigned int i;
71928
71929 /* only scan the sections containing data */
71930- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
71931- (unsigned long)mod->module_core,
71932+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
71933+ (unsigned long)mod->module_core_rw,
71934 sizeof(struct module), GFP_KERNEL);
71935
71936 for (i = 1; i < hdr->e_shnum; i++) {
71937@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
71938 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
71939 continue;
71940
71941- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
71942- (unsigned long)mod->module_core,
71943+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
71944+ (unsigned long)mod->module_core_rw,
71945 sechdrs[i].sh_size, GFP_KERNEL);
71946 }
71947 }
71948@@ -2097,7 +2156,7 @@ static noinline struct module *load_module(void __user *umod,
71949 Elf_Ehdr *hdr;
71950 Elf_Shdr *sechdrs;
71951 char *secstrings, *args, *modmagic, *strtab = NULL;
71952- char *staging;
71953+ char *staging, *license;
71954 unsigned int i;
71955 unsigned int symindex = 0;
71956 unsigned int strindex = 0;
71957@@ -2195,6 +2254,14 @@ static noinline struct module *load_module(void __user *umod,
71958 goto free_hdr;
71959 }
71960
71961+ license = get_modinfo(sechdrs, infoindex, "license");
71962+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71963+ if (!license || !license_is_gpl_compatible(license)) {
71964+ err -ENOEXEC;
71965+ goto free_hdr;
71966+ }
71967+#endif
71968+
71969 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
71970 /* This is allowed: modprobe --force will invalidate it. */
71971 if (!modmagic) {
71972@@ -2263,7 +2330,7 @@ static noinline struct module *load_module(void __user *umod,
71973 secstrings, &stroffs, strmap);
71974
71975 /* Do the allocs. */
71976- ptr = module_alloc_update_bounds(mod->core_size);
71977+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71978 /*
71979 * The pointer to this block is stored in the module structure
71980 * which is inside the block. Just mark it as not being a
71981@@ -2274,23 +2341,47 @@ static noinline struct module *load_module(void __user *umod,
71982 err = -ENOMEM;
71983 goto free_percpu;
71984 }
71985- memset(ptr, 0, mod->core_size);
71986- mod->module_core = ptr;
71987+ memset(ptr, 0, mod->core_size_rw);
71988+ mod->module_core_rw = ptr;
71989
71990- ptr = module_alloc_update_bounds(mod->init_size);
71991+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71992 /*
71993 * The pointer to this block is stored in the module structure
71994 * which is inside the block. This block doesn't need to be
71995 * scanned as it contains data and code that will be freed
71996 * after the module is initialized.
71997 */
71998- kmemleak_ignore(ptr);
71999- if (!ptr && mod->init_size) {
72000+ kmemleak_not_leak(ptr);
72001+ if (!ptr && mod->init_size_rw) {
72002 err = -ENOMEM;
72003- goto free_core;
72004+ goto free_core_rw;
72005 }
72006- memset(ptr, 0, mod->init_size);
72007- mod->module_init = ptr;
72008+ memset(ptr, 0, mod->init_size_rw);
72009+ mod->module_init_rw = ptr;
72010+
72011+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
72012+ kmemleak_not_leak(ptr);
72013+ if (!ptr) {
72014+ err = -ENOMEM;
72015+ goto free_init_rw;
72016+ }
72017+
72018+ pax_open_kernel();
72019+ memset(ptr, 0, mod->core_size_rx);
72020+ pax_close_kernel();
72021+ mod->module_core_rx = ptr;
72022+
72023+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
72024+ kmemleak_not_leak(ptr);
72025+ if (!ptr && mod->init_size_rx) {
72026+ err = -ENOMEM;
72027+ goto free_core_rx;
72028+ }
72029+
72030+ pax_open_kernel();
72031+ memset(ptr, 0, mod->init_size_rx);
72032+ pax_close_kernel();
72033+ mod->module_init_rx = ptr;
72034
72035 /* Transfer each section which specifies SHF_ALLOC */
72036 DEBUGP("final section addresses:\n");
72037@@ -2300,17 +2391,45 @@ static noinline struct module *load_module(void __user *umod,
72038 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
72039 continue;
72040
72041- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
72042- dest = mod->module_init
72043- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72044- else
72045- dest = mod->module_core + sechdrs[i].sh_entsize;
72046+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
72047+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72048+ dest = mod->module_init_rw
72049+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72050+ else
72051+ dest = mod->module_init_rx
72052+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72053+ } else {
72054+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72055+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
72056+ else
72057+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
72058+ }
72059
72060- if (sechdrs[i].sh_type != SHT_NOBITS)
72061- memcpy(dest, (void *)sechdrs[i].sh_addr,
72062- sechdrs[i].sh_size);
72063+ if (sechdrs[i].sh_type != SHT_NOBITS) {
72064+
72065+#ifdef CONFIG_PAX_KERNEXEC
72066+#ifdef CONFIG_X86_64
72067+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
72068+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
72069+#endif
72070+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
72071+ pax_open_kernel();
72072+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72073+ pax_close_kernel();
72074+ } else
72075+#endif
72076+
72077+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72078+ }
72079 /* Update sh_addr to point to copy in image. */
72080- sechdrs[i].sh_addr = (unsigned long)dest;
72081+
72082+#ifdef CONFIG_PAX_KERNEXEC
72083+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
72084+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
72085+ else
72086+#endif
72087+
72088+ sechdrs[i].sh_addr = (unsigned long)dest;
72089 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
72090 }
72091 /* Module has been moved. */
72092@@ -2322,7 +2441,7 @@ static noinline struct module *load_module(void __user *umod,
72093 mod->name);
72094 if (!mod->refptr) {
72095 err = -ENOMEM;
72096- goto free_init;
72097+ goto free_init_rx;
72098 }
72099 #endif
72100 /* Now we've moved module, initialize linked lists, etc. */
72101@@ -2334,7 +2453,7 @@ static noinline struct module *load_module(void __user *umod,
72102 goto free_unload;
72103
72104 /* Set up license info based on the info section */
72105- set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
72106+ set_license(mod, license);
72107
72108 /*
72109 * ndiswrapper is under GPL by itself, but loads proprietary modules.
72110@@ -2351,6 +2470,31 @@ static noinline struct module *load_module(void __user *umod,
72111 /* Set up MODINFO_ATTR fields */
72112 setup_modinfo(mod, sechdrs, infoindex);
72113
72114+ mod->args = args;
72115+
72116+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72117+ {
72118+ char *p, *p2;
72119+
72120+ if (strstr(mod->args, "grsec_modharden_netdev")) {
72121+ 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);
72122+ err = -EPERM;
72123+ goto cleanup;
72124+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
72125+ p += strlen("grsec_modharden_normal");
72126+ p2 = strstr(p, "_");
72127+ if (p2) {
72128+ *p2 = '\0';
72129+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
72130+ *p2 = '_';
72131+ }
72132+ err = -EPERM;
72133+ goto cleanup;
72134+ }
72135+ }
72136+#endif
72137+
72138+
72139 /* Fix up syms, so that st_value is a pointer to location. */
72140 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
72141 mod);
72142@@ -2431,8 +2575,8 @@ static noinline struct module *load_module(void __user *umod,
72143
72144 /* Now do relocations. */
72145 for (i = 1; i < hdr->e_shnum; i++) {
72146- const char *strtab = (char *)sechdrs[strindex].sh_addr;
72147 unsigned int info = sechdrs[i].sh_info;
72148+ strtab = (char *)sechdrs[strindex].sh_addr;
72149
72150 /* Not a valid relocation section? */
72151 if (info >= hdr->e_shnum)
72152@@ -2493,16 +2637,15 @@ static noinline struct module *load_module(void __user *umod,
72153 * Do it before processing of module parameters, so the module
72154 * can provide parameter accessor functions of its own.
72155 */
72156- if (mod->module_init)
72157- flush_icache_range((unsigned long)mod->module_init,
72158- (unsigned long)mod->module_init
72159- + mod->init_size);
72160- flush_icache_range((unsigned long)mod->module_core,
72161- (unsigned long)mod->module_core + mod->core_size);
72162+ if (mod->module_init_rx)
72163+ flush_icache_range((unsigned long)mod->module_init_rx,
72164+ (unsigned long)mod->module_init_rx
72165+ + mod->init_size_rx);
72166+ flush_icache_range((unsigned long)mod->module_core_rx,
72167+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
72168
72169 set_fs(old_fs);
72170
72171- mod->args = args;
72172 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
72173 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
72174 mod->name);
72175@@ -2546,12 +2689,16 @@ static noinline struct module *load_module(void __user *umod,
72176 free_unload:
72177 module_unload_free(mod);
72178 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
72179+ free_init_rx:
72180 percpu_modfree(mod->refptr);
72181- free_init:
72182 #endif
72183- module_free(mod, mod->module_init);
72184- free_core:
72185- module_free(mod, mod->module_core);
72186+ module_free_exec(mod, mod->module_init_rx);
72187+ free_core_rx:
72188+ module_free_exec(mod, mod->module_core_rx);
72189+ free_init_rw:
72190+ module_free(mod, mod->module_init_rw);
72191+ free_core_rw:
72192+ module_free(mod, mod->module_core_rw);
72193 /* mod will be freed with core. Don't access it beyond this line! */
72194 free_percpu:
72195 if (percpu)
72196@@ -2653,10 +2800,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
72197 mod->symtab = mod->core_symtab;
72198 mod->strtab = mod->core_strtab;
72199 #endif
72200- module_free(mod, mod->module_init);
72201- mod->module_init = NULL;
72202- mod->init_size = 0;
72203- mod->init_text_size = 0;
72204+ module_free(mod, mod->module_init_rw);
72205+ module_free_exec(mod, mod->module_init_rx);
72206+ mod->module_init_rw = NULL;
72207+ mod->module_init_rx = NULL;
72208+ mod->init_size_rw = 0;
72209+ mod->init_size_rx = 0;
72210 mutex_unlock(&module_mutex);
72211
72212 return 0;
72213@@ -2687,10 +2836,16 @@ static const char *get_ksymbol(struct module *mod,
72214 unsigned long nextval;
72215
72216 /* At worse, next value is at end of module */
72217- if (within_module_init(addr, mod))
72218- nextval = (unsigned long)mod->module_init+mod->init_text_size;
72219+ if (within_module_init_rx(addr, mod))
72220+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
72221+ else if (within_module_init_rw(addr, mod))
72222+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
72223+ else if (within_module_core_rx(addr, mod))
72224+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
72225+ else if (within_module_core_rw(addr, mod))
72226+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
72227 else
72228- nextval = (unsigned long)mod->module_core+mod->core_text_size;
72229+ return NULL;
72230
72231 /* Scan for closest preceeding symbol, and next symbol. (ELF
72232 starts real symbols at 1). */
72233@@ -2936,7 +3091,7 @@ static int m_show(struct seq_file *m, void *p)
72234 char buf[8];
72235
72236 seq_printf(m, "%s %u",
72237- mod->name, mod->init_size + mod->core_size);
72238+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
72239 print_unload_info(m, mod);
72240
72241 /* Informative for users. */
72242@@ -2945,7 +3100,7 @@ static int m_show(struct seq_file *m, void *p)
72243 mod->state == MODULE_STATE_COMING ? "Loading":
72244 "Live");
72245 /* Used by oprofile and other similar tools. */
72246- seq_printf(m, " 0x%p", mod->module_core);
72247+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
72248
72249 /* Taints info */
72250 if (mod->taints)
72251@@ -2981,7 +3136,17 @@ static const struct file_operations proc_modules_operations = {
72252
72253 static int __init proc_modules_init(void)
72254 {
72255+#ifndef CONFIG_GRKERNSEC_HIDESYM
72256+#ifdef CONFIG_GRKERNSEC_PROC_USER
72257+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72258+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72259+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
72260+#else
72261 proc_create("modules", 0, NULL, &proc_modules_operations);
72262+#endif
72263+#else
72264+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72265+#endif
72266 return 0;
72267 }
72268 module_init(proc_modules_init);
72269@@ -3040,12 +3205,12 @@ struct module *__module_address(unsigned long addr)
72270 {
72271 struct module *mod;
72272
72273- if (addr < module_addr_min || addr > module_addr_max)
72274+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
72275+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
72276 return NULL;
72277
72278 list_for_each_entry_rcu(mod, &modules, list)
72279- if (within_module_core(addr, mod)
72280- || within_module_init(addr, mod))
72281+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
72282 return mod;
72283 return NULL;
72284 }
72285@@ -3079,11 +3244,20 @@ bool is_module_text_address(unsigned long addr)
72286 */
72287 struct module *__module_text_address(unsigned long addr)
72288 {
72289- struct module *mod = __module_address(addr);
72290+ struct module *mod;
72291+
72292+#ifdef CONFIG_X86_32
72293+ addr = ktla_ktva(addr);
72294+#endif
72295+
72296+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
72297+ return NULL;
72298+
72299+ mod = __module_address(addr);
72300+
72301 if (mod) {
72302 /* Make sure it's within the text section. */
72303- if (!within(addr, mod->module_init, mod->init_text_size)
72304- && !within(addr, mod->module_core, mod->core_text_size))
72305+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
72306 mod = NULL;
72307 }
72308 return mod;
72309diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
72310index ec815a9..fe46e99 100644
72311--- a/kernel/mutex-debug.c
72312+++ b/kernel/mutex-debug.c
72313@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
72314 }
72315
72316 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72317- struct thread_info *ti)
72318+ struct task_struct *task)
72319 {
72320 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
72321
72322 /* Mark the current thread as blocked on the lock: */
72323- ti->task->blocked_on = waiter;
72324+ task->blocked_on = waiter;
72325 }
72326
72327 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72328- struct thread_info *ti)
72329+ struct task_struct *task)
72330 {
72331 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
72332- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
72333- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
72334- ti->task->blocked_on = NULL;
72335+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
72336+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
72337+ task->blocked_on = NULL;
72338
72339 list_del_init(&waiter->list);
72340 waiter->task = NULL;
72341@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lock)
72342 return;
72343
72344 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
72345- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
72346+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
72347 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
72348 mutex_clear_owner(lock);
72349 }
72350diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
72351index 6b2d735..372d3c4 100644
72352--- a/kernel/mutex-debug.h
72353+++ b/kernel/mutex-debug.h
72354@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
72355 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
72356 extern void debug_mutex_add_waiter(struct mutex *lock,
72357 struct mutex_waiter *waiter,
72358- struct thread_info *ti);
72359+ struct task_struct *task);
72360 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72361- struct thread_info *ti);
72362+ struct task_struct *task);
72363 extern void debug_mutex_unlock(struct mutex *lock);
72364 extern void debug_mutex_init(struct mutex *lock, const char *name,
72365 struct lock_class_key *key);
72366
72367 static inline void mutex_set_owner(struct mutex *lock)
72368 {
72369- lock->owner = current_thread_info();
72370+ lock->owner = current;
72371 }
72372
72373 static inline void mutex_clear_owner(struct mutex *lock)
72374diff --git a/kernel/mutex.c b/kernel/mutex.c
72375index f85644c..5ee9f77 100644
72376--- a/kernel/mutex.c
72377+++ b/kernel/mutex.c
72378@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72379 */
72380
72381 for (;;) {
72382- struct thread_info *owner;
72383+ struct task_struct *owner;
72384
72385 /*
72386 * If we own the BKL, then don't spin. The owner of
72387@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72388 spin_lock_mutex(&lock->wait_lock, flags);
72389
72390 debug_mutex_lock_common(lock, &waiter);
72391- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
72392+ debug_mutex_add_waiter(lock, &waiter, task);
72393
72394 /* add waiting tasks to the end of the waitqueue (FIFO): */
72395 list_add_tail(&waiter.list, &lock->wait_list);
72396@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72397 * TASK_UNINTERRUPTIBLE case.)
72398 */
72399 if (unlikely(signal_pending_state(state, task))) {
72400- mutex_remove_waiter(lock, &waiter,
72401- task_thread_info(task));
72402+ mutex_remove_waiter(lock, &waiter, task);
72403 mutex_release(&lock->dep_map, 1, ip);
72404 spin_unlock_mutex(&lock->wait_lock, flags);
72405
72406@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72407 done:
72408 lock_acquired(&lock->dep_map, ip);
72409 /* got the lock - rejoice! */
72410- mutex_remove_waiter(lock, &waiter, current_thread_info());
72411+ mutex_remove_waiter(lock, &waiter, task);
72412 mutex_set_owner(lock);
72413
72414 /* set it to 0 if there are no waiters left: */
72415diff --git a/kernel/mutex.h b/kernel/mutex.h
72416index 67578ca..4115fbf 100644
72417--- a/kernel/mutex.h
72418+++ b/kernel/mutex.h
72419@@ -19,7 +19,7 @@
72420 #ifdef CONFIG_SMP
72421 static inline void mutex_set_owner(struct mutex *lock)
72422 {
72423- lock->owner = current_thread_info();
72424+ lock->owner = current;
72425 }
72426
72427 static inline void mutex_clear_owner(struct mutex *lock)
72428diff --git a/kernel/panic.c b/kernel/panic.c
72429index 96b45d0..45c447a 100644
72430--- a/kernel/panic.c
72431+++ b/kernel/panic.c
72432@@ -352,7 +352,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
72433 const char *board;
72434
72435 printk(KERN_WARNING "------------[ cut here ]------------\n");
72436- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
72437+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
72438 board = dmi_get_system_info(DMI_PRODUCT_NAME);
72439 if (board)
72440 printk(KERN_WARNING "Hardware name: %s\n", board);
72441@@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
72442 */
72443 void __stack_chk_fail(void)
72444 {
72445- panic("stack-protector: Kernel stack is corrupted in: %p\n",
72446+ dump_stack();
72447+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
72448 __builtin_return_address(0));
72449 }
72450 EXPORT_SYMBOL(__stack_chk_fail);
72451diff --git a/kernel/params.c b/kernel/params.c
72452index d656c27..21e452c 100644
72453--- a/kernel/params.c
72454+++ b/kernel/params.c
72455@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
72456 return ret;
72457 }
72458
72459-static struct sysfs_ops module_sysfs_ops = {
72460+static const struct sysfs_ops module_sysfs_ops = {
72461 .show = module_attr_show,
72462 .store = module_attr_store,
72463 };
72464@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
72465 return 0;
72466 }
72467
72468-static struct kset_uevent_ops module_uevent_ops = {
72469+static const struct kset_uevent_ops module_uevent_ops = {
72470 .filter = uevent_filter,
72471 };
72472
72473diff --git a/kernel/perf_event.c b/kernel/perf_event.c
72474index 37ebc14..9c121d9 100644
72475--- a/kernel/perf_event.c
72476+++ b/kernel/perf_event.c
72477@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostly = 516; /* 'free' kb per user */
72478 */
72479 int sysctl_perf_event_sample_rate __read_mostly = 100000;
72480
72481-static atomic64_t perf_event_id;
72482+static atomic64_unchecked_t perf_event_id;
72483
72484 /*
72485 * Lock for (sysadmin-configurable) event reservations:
72486@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struct perf_event *event,
72487 * In order to keep per-task stats reliable we need to flip the event
72488 * values when we flip the contexts.
72489 */
72490- value = atomic64_read(&next_event->count);
72491- value = atomic64_xchg(&event->count, value);
72492- atomic64_set(&next_event->count, value);
72493+ value = atomic64_read_unchecked(&next_event->count);
72494+ value = atomic64_xchg_unchecked(&event->count, value);
72495+ atomic64_set_unchecked(&next_event->count, value);
72496
72497 swap(event->total_time_enabled, next_event->total_time_enabled);
72498 swap(event->total_time_running, next_event->total_time_running);
72499@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_event *event)
72500 update_event_times(event);
72501 }
72502
72503- return atomic64_read(&event->count);
72504+ return atomic64_read_unchecked(&event->count);
72505 }
72506
72507 /*
72508@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct perf_event *event,
72509 values[n++] = 1 + leader->nr_siblings;
72510 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72511 values[n++] = leader->total_time_enabled +
72512- atomic64_read(&leader->child_total_time_enabled);
72513+ atomic64_read_unchecked(&leader->child_total_time_enabled);
72514 }
72515 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72516 values[n++] = leader->total_time_running +
72517- atomic64_read(&leader->child_total_time_running);
72518+ atomic64_read_unchecked(&leader->child_total_time_running);
72519 }
72520
72521 size = n * sizeof(u64);
72522@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct perf_event *event,
72523 values[n++] = perf_event_read_value(event);
72524 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72525 values[n++] = event->total_time_enabled +
72526- atomic64_read(&event->child_total_time_enabled);
72527+ atomic64_read_unchecked(&event->child_total_time_enabled);
72528 }
72529 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72530 values[n++] = event->total_time_running +
72531- atomic64_read(&event->child_total_time_running);
72532+ atomic64_read_unchecked(&event->child_total_time_running);
72533 }
72534 if (read_format & PERF_FORMAT_ID)
72535 values[n++] = primary_event_id(event);
72536@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)
72537 static void perf_event_reset(struct perf_event *event)
72538 {
72539 (void)perf_event_read(event);
72540- atomic64_set(&event->count, 0);
72541+ atomic64_set_unchecked(&event->count, 0);
72542 perf_event_update_userpage(event);
72543 }
72544
72545@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct perf_event *event)
72546 ++userpg->lock;
72547 barrier();
72548 userpg->index = perf_event_index(event);
72549- userpg->offset = atomic64_read(&event->count);
72550+ userpg->offset = atomic64_read_unchecked(&event->count);
72551 if (event->state == PERF_EVENT_STATE_ACTIVE)
72552- userpg->offset -= atomic64_read(&event->hw.prev_count);
72553+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
72554
72555 userpg->time_enabled = event->total_time_enabled +
72556- atomic64_read(&event->child_total_time_enabled);
72557+ atomic64_read_unchecked(&event->child_total_time_enabled);
72558
72559 userpg->time_running = event->total_time_running +
72560- atomic64_read(&event->child_total_time_running);
72561+ atomic64_read_unchecked(&event->child_total_time_running);
72562
72563 barrier();
72564 ++userpg->lock;
72565@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct perf_output_handle *handle,
72566 u64 values[4];
72567 int n = 0;
72568
72569- values[n++] = atomic64_read(&event->count);
72570+ values[n++] = atomic64_read_unchecked(&event->count);
72571 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72572 values[n++] = event->total_time_enabled +
72573- atomic64_read(&event->child_total_time_enabled);
72574+ atomic64_read_unchecked(&event->child_total_time_enabled);
72575 }
72576 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72577 values[n++] = event->total_time_running +
72578- atomic64_read(&event->child_total_time_running);
72579+ atomic64_read_unchecked(&event->child_total_time_running);
72580 }
72581 if (read_format & PERF_FORMAT_ID)
72582 values[n++] = primary_event_id(event);
72583@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
72584 if (leader != event)
72585 leader->pmu->read(leader);
72586
72587- values[n++] = atomic64_read(&leader->count);
72588+ values[n++] = atomic64_read_unchecked(&leader->count);
72589 if (read_format & PERF_FORMAT_ID)
72590 values[n++] = primary_event_id(leader);
72591
72592@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
72593 if (sub != event)
72594 sub->pmu->read(sub);
72595
72596- values[n++] = atomic64_read(&sub->count);
72597+ values[n++] = atomic64_read_unchecked(&sub->count);
72598 if (read_format & PERF_FORMAT_ID)
72599 values[n++] = primary_event_id(sub);
72600
72601@@ -3525,12 +3525,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
72602 * need to add enough zero bytes after the string to handle
72603 * the 64bit alignment we do later.
72604 */
72605- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
72606+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
72607 if (!buf) {
72608 name = strncpy(tmp, "//enomem", sizeof(tmp));
72609 goto got_name;
72610 }
72611- name = d_path(&file->f_path, buf, PATH_MAX);
72612+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
72613 if (IS_ERR(name)) {
72614 name = strncpy(tmp, "//toolong", sizeof(tmp));
72615 goto got_name;
72616@@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
72617 {
72618 struct hw_perf_event *hwc = &event->hw;
72619
72620- atomic64_add(nr, &event->count);
72621+ atomic64_add_unchecked(nr, &event->count);
72622
72623 if (!hwc->sample_period)
72624 return;
72625@@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(struct perf_event *event)
72626 u64 now;
72627
72628 now = cpu_clock(cpu);
72629- prev = atomic64_read(&event->hw.prev_count);
72630- atomic64_set(&event->hw.prev_count, now);
72631- atomic64_add(now - prev, &event->count);
72632+ prev = atomic64_read_unchecked(&event->hw.prev_count);
72633+ atomic64_set_unchecked(&event->hw.prev_count, now);
72634+ atomic64_add_unchecked(now - prev, &event->count);
72635 }
72636
72637 static int cpu_clock_perf_event_enable(struct perf_event *event)
72638@@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(struct perf_event *event)
72639 struct hw_perf_event *hwc = &event->hw;
72640 int cpu = raw_smp_processor_id();
72641
72642- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
72643+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
72644 perf_swevent_start_hrtimer(event);
72645
72646 return 0;
72647@@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update(struct perf_event *event, u64 now)
72648 u64 prev;
72649 s64 delta;
72650
72651- prev = atomic64_xchg(&event->hw.prev_count, now);
72652+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
72653 delta = now - prev;
72654- atomic64_add(delta, &event->count);
72655+ atomic64_add_unchecked(delta, &event->count);
72656 }
72657
72658 static int task_clock_perf_event_enable(struct perf_event *event)
72659@@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(struct perf_event *event)
72660
72661 now = event->ctx->time;
72662
72663- atomic64_set(&hwc->prev_count, now);
72664+ atomic64_set_unchecked(&hwc->prev_count, now);
72665
72666 perf_swevent_start_hrtimer(event);
72667
72668@@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr *attr,
72669 event->parent = parent_event;
72670
72671 event->ns = get_pid_ns(current->nsproxy->pid_ns);
72672- event->id = atomic64_inc_return(&perf_event_id);
72673+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
72674
72675 event->state = PERF_EVENT_STATE_INACTIVE;
72676
72677@@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf_event *child_event,
72678 if (child_event->attr.inherit_stat)
72679 perf_event_read_event(child_event, child);
72680
72681- child_val = atomic64_read(&child_event->count);
72682+ child_val = atomic64_read_unchecked(&child_event->count);
72683
72684 /*
72685 * Add back the child's count to the parent's count:
72686 */
72687- atomic64_add(child_val, &parent_event->count);
72688- atomic64_add(child_event->total_time_enabled,
72689+ atomic64_add_unchecked(child_val, &parent_event->count);
72690+ atomic64_add_unchecked(child_event->total_time_enabled,
72691 &parent_event->child_total_time_enabled);
72692- atomic64_add(child_event->total_time_running,
72693+ atomic64_add_unchecked(child_event->total_time_running,
72694 &parent_event->child_total_time_running);
72695
72696 /*
72697diff --git a/kernel/pid.c b/kernel/pid.c
72698index fce7198..4f23a7e 100644
72699--- a/kernel/pid.c
72700+++ b/kernel/pid.c
72701@@ -33,6 +33,7 @@
72702 #include <linux/rculist.h>
72703 #include <linux/bootmem.h>
72704 #include <linux/hash.h>
72705+#include <linux/security.h>
72706 #include <linux/pid_namespace.h>
72707 #include <linux/init_task.h>
72708 #include <linux/syscalls.h>
72709@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
72710
72711 int pid_max = PID_MAX_DEFAULT;
72712
72713-#define RESERVED_PIDS 300
72714+#define RESERVED_PIDS 500
72715
72716 int pid_max_min = RESERVED_PIDS + 1;
72717 int pid_max_max = PID_MAX_LIMIT;
72718@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
72719 */
72720 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
72721 {
72722- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72723+ struct task_struct *task;
72724+
72725+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72726+
72727+ if (gr_pid_is_chrooted(task))
72728+ return NULL;
72729+
72730+ return task;
72731 }
72732
72733 struct task_struct *find_task_by_vpid(pid_t vnr)
72734@@ -391,6 +399,11 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
72735 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
72736 }
72737
72738+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
72739+{
72740+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
72741+}
72742+
72743 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
72744 {
72745 struct pid *pid;
72746diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
72747index 5c9dc22..d271117 100644
72748--- a/kernel/posix-cpu-timers.c
72749+++ b/kernel/posix-cpu-timers.c
72750@@ -6,6 +6,7 @@
72751 #include <linux/posix-timers.h>
72752 #include <linux/errno.h>
72753 #include <linux/math64.h>
72754+#include <linux/security.h>
72755 #include <asm/uaccess.h>
72756 #include <linux/kernel_stat.h>
72757 #include <trace/events/timer.h>
72758@@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
72759
72760 static __init int init_posix_cpu_timers(void)
72761 {
72762- struct k_clock process = {
72763+ static struct k_clock process = {
72764 .clock_getres = process_cpu_clock_getres,
72765 .clock_get = process_cpu_clock_get,
72766 .clock_set = do_posix_clock_nosettime,
72767@@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(void)
72768 .nsleep = process_cpu_nsleep,
72769 .nsleep_restart = process_cpu_nsleep_restart,
72770 };
72771- struct k_clock thread = {
72772+ static struct k_clock thread = {
72773 .clock_getres = thread_cpu_clock_getres,
72774 .clock_get = thread_cpu_clock_get,
72775 .clock_set = do_posix_clock_nosettime,
72776diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72777index 5e76d22..cf1baeb 100644
72778--- a/kernel/posix-timers.c
72779+++ b/kernel/posix-timers.c
72780@@ -42,6 +42,7 @@
72781 #include <linux/compiler.h>
72782 #include <linux/idr.h>
72783 #include <linux/posix-timers.h>
72784+#include <linux/grsecurity.h>
72785 #include <linux/syscalls.h>
72786 #include <linux/wait.h>
72787 #include <linux/workqueue.h>
72788@@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
72789 * which we beg off on and pass to do_sys_settimeofday().
72790 */
72791
72792-static struct k_clock posix_clocks[MAX_CLOCKS];
72793+static struct k_clock *posix_clocks[MAX_CLOCKS];
72794
72795 /*
72796 * These ones are defined below.
72797@@ -157,8 +158,8 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
72798 */
72799 #define CLOCK_DISPATCH(clock, call, arglist) \
72800 ((clock) < 0 ? posix_cpu_##call arglist : \
72801- (posix_clocks[clock].call != NULL \
72802- ? (*posix_clocks[clock].call) arglist : common_##call arglist))
72803+ (posix_clocks[clock]->call != NULL \
72804+ ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
72805
72806 /*
72807 * Default clock hook functions when the struct k_clock passed
72808@@ -172,7 +173,7 @@ static inline int common_clock_getres(const clockid_t which_clock,
72809 struct timespec *tp)
72810 {
72811 tp->tv_sec = 0;
72812- tp->tv_nsec = posix_clocks[which_clock].res;
72813+ tp->tv_nsec = posix_clocks[which_clock]->res;
72814 return 0;
72815 }
72816
72817@@ -217,9 +218,11 @@ static inline int invalid_clockid(const clockid_t which_clock)
72818 return 0;
72819 if ((unsigned) which_clock >= MAX_CLOCKS)
72820 return 1;
72821- if (posix_clocks[which_clock].clock_getres != NULL)
72822+ if (posix_clocks[which_clock] == NULL)
72823 return 0;
72824- if (posix_clocks[which_clock].res != 0)
72825+ if (posix_clocks[which_clock]->clock_getres != NULL)
72826+ return 0;
72827+ if (posix_clocks[which_clock]->res != 0)
72828 return 0;
72829 return 1;
72830 }
72831@@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
72832 */
72833 static __init int init_posix_timers(void)
72834 {
72835- struct k_clock clock_realtime = {
72836+ static struct k_clock clock_realtime = {
72837 .clock_getres = hrtimer_get_res,
72838 };
72839- struct k_clock clock_monotonic = {
72840+ static struct k_clock clock_monotonic = {
72841 .clock_getres = hrtimer_get_res,
72842 .clock_get = posix_ktime_get_ts,
72843 .clock_set = do_posix_clock_nosettime,
72844 };
72845- struct k_clock clock_monotonic_raw = {
72846+ static struct k_clock clock_monotonic_raw = {
72847 .clock_getres = hrtimer_get_res,
72848 .clock_get = posix_get_monotonic_raw,
72849 .clock_set = do_posix_clock_nosettime,
72850 .timer_create = no_timer_create,
72851 .nsleep = no_nsleep,
72852 };
72853- struct k_clock clock_realtime_coarse = {
72854+ static struct k_clock clock_realtime_coarse = {
72855 .clock_getres = posix_get_coarse_res,
72856 .clock_get = posix_get_realtime_coarse,
72857 .clock_set = do_posix_clock_nosettime,
72858 .timer_create = no_timer_create,
72859 .nsleep = no_nsleep,
72860 };
72861- struct k_clock clock_monotonic_coarse = {
72862+ static struct k_clock clock_monotonic_coarse = {
72863 .clock_getres = posix_get_coarse_res,
72864 .clock_get = posix_get_monotonic_coarse,
72865 .clock_set = do_posix_clock_nosettime,
72866@@ -296,6 +299,8 @@ static __init int init_posix_timers(void)
72867 .nsleep = no_nsleep,
72868 };
72869
72870+ pax_track_stack();
72871+
72872 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
72873 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
72874 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
72875@@ -484,7 +489,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
72876 return;
72877 }
72878
72879- posix_clocks[clock_id] = *new_clock;
72880+ posix_clocks[clock_id] = new_clock;
72881 }
72882 EXPORT_SYMBOL_GPL(register_posix_clock);
72883
72884@@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72885 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72886 return -EFAULT;
72887
72888+ /* only the CLOCK_REALTIME clock can be set, all other clocks
72889+ have their clock_set fptr set to a nosettime dummy function
72890+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72891+ call common_clock_set, which calls do_sys_settimeofday, which
72892+ we hook
72893+ */
72894+
72895 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
72896 }
72897
72898diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
72899index 04a9e90..bc355aa 100644
72900--- a/kernel/power/hibernate.c
72901+++ b/kernel/power/hibernate.c
72902@@ -48,14 +48,14 @@ enum {
72903
72904 static int hibernation_mode = HIBERNATION_SHUTDOWN;
72905
72906-static struct platform_hibernation_ops *hibernation_ops;
72907+static const struct platform_hibernation_ops *hibernation_ops;
72908
72909 /**
72910 * hibernation_set_ops - set the global hibernate operations
72911 * @ops: the hibernation operations to use in subsequent hibernation transitions
72912 */
72913
72914-void hibernation_set_ops(struct platform_hibernation_ops *ops)
72915+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
72916 {
72917 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
72918 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
72919diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
72920index e8b3370..484c2e4 100644
72921--- a/kernel/power/poweroff.c
72922+++ b/kernel/power/poweroff.c
72923@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
72924 .enable_mask = SYSRQ_ENABLE_BOOT,
72925 };
72926
72927-static int pm_sysrq_init(void)
72928+static int __init pm_sysrq_init(void)
72929 {
72930 register_sysrq_key('o', &sysrq_poweroff_op);
72931 return 0;
72932diff --git a/kernel/power/process.c b/kernel/power/process.c
72933index e7cd671..56d5f459 100644
72934--- a/kernel/power/process.c
72935+++ b/kernel/power/process.c
72936@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_only)
72937 struct timeval start, end;
72938 u64 elapsed_csecs64;
72939 unsigned int elapsed_csecs;
72940+ bool timedout = false;
72941
72942 do_gettimeofday(&start);
72943
72944 end_time = jiffies + TIMEOUT;
72945 do {
72946 todo = 0;
72947+ if (time_after(jiffies, end_time))
72948+ timedout = true;
72949 read_lock(&tasklist_lock);
72950 do_each_thread(g, p) {
72951 if (frozen(p) || !freezeable(p))
72952@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_only)
72953 * It is "frozen enough". If the task does wake
72954 * up, it will immediately call try_to_freeze.
72955 */
72956- if (!task_is_stopped_or_traced(p) &&
72957- !freezer_should_skip(p))
72958+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
72959 todo++;
72960+ if (timedout) {
72961+ printk(KERN_ERR "Task refusing to freeze:\n");
72962+ sched_show_task(p);
72963+ }
72964+ }
72965 } while_each_thread(g, p);
72966 read_unlock(&tasklist_lock);
72967 yield(); /* Yield is okay here */
72968- if (time_after(jiffies, end_time))
72969- break;
72970- } while (todo);
72971+ } while (todo && !timedout);
72972
72973 do_gettimeofday(&end);
72974 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
72975diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
72976index 40dd021..fb30ceb 100644
72977--- a/kernel/power/suspend.c
72978+++ b/kernel/power/suspend.c
72979@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_MAX] = {
72980 [PM_SUSPEND_MEM] = "mem",
72981 };
72982
72983-static struct platform_suspend_ops *suspend_ops;
72984+static const struct platform_suspend_ops *suspend_ops;
72985
72986 /**
72987 * suspend_set_ops - Set the global suspend method table.
72988 * @ops: Pointer to ops structure.
72989 */
72990-void suspend_set_ops(struct platform_suspend_ops *ops)
72991+void suspend_set_ops(const struct platform_suspend_ops *ops)
72992 {
72993 mutex_lock(&pm_mutex);
72994 suspend_ops = ops;
72995diff --git a/kernel/printk.c b/kernel/printk.c
72996index 4cade47..637e78a 100644
72997--- a/kernel/printk.c
72998+++ b/kernel/printk.c
72999@@ -278,6 +278,11 @@ int do_syslog(int type, char __user *buf, int len)
73000 char c;
73001 int error = 0;
73002
73003+#ifdef CONFIG_GRKERNSEC_DMESG
73004+ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
73005+ return -EPERM;
73006+#endif
73007+
73008 error = security_syslog(type);
73009 if (error)
73010 return error;
73011diff --git a/kernel/profile.c b/kernel/profile.c
73012index dfadc5b..7f59404 100644
73013--- a/kernel/profile.c
73014+++ b/kernel/profile.c
73015@@ -39,7 +39,7 @@ struct profile_hit {
73016 /* Oprofile timer tick hook */
73017 static int (*timer_hook)(struct pt_regs *) __read_mostly;
73018
73019-static atomic_t *prof_buffer;
73020+static atomic_unchecked_t *prof_buffer;
73021 static unsigned long prof_len, prof_shift;
73022
73023 int prof_on __read_mostly;
73024@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
73025 hits[i].pc = 0;
73026 continue;
73027 }
73028- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73029+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73030 hits[i].hits = hits[i].pc = 0;
73031 }
73032 }
73033@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73034 * Add the current hit(s) and flush the write-queue out
73035 * to the global buffer:
73036 */
73037- atomic_add(nr_hits, &prof_buffer[pc]);
73038+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
73039 for (i = 0; i < NR_PROFILE_HIT; ++i) {
73040- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73041+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73042 hits[i].pc = hits[i].hits = 0;
73043 }
73044 out:
73045@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73046 if (prof_on != type || !prof_buffer)
73047 return;
73048 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
73049- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73050+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73051 }
73052 #endif /* !CONFIG_SMP */
73053 EXPORT_SYMBOL_GPL(profile_hits);
73054@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
73055 return -EFAULT;
73056 buf++; p++; count--; read++;
73057 }
73058- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
73059+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
73060 if (copy_to_user(buf, (void *)pnt, count))
73061 return -EFAULT;
73062 read += count;
73063@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
73064 }
73065 #endif
73066 profile_discard_flip_buffers();
73067- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
73068+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
73069 return count;
73070 }
73071
73072diff --git a/kernel/ptrace.c b/kernel/ptrace.c
73073index 05625f6..733bf70 100644
73074--- a/kernel/ptrace.c
73075+++ b/kernel/ptrace.c
73076@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_struct *child, int kill)
73077 return ret;
73078 }
73079
73080-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73081+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
73082+ unsigned int log)
73083 {
73084 const struct cred *cred = current_cred(), *tcred;
73085
73086@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73087 cred->gid != tcred->egid ||
73088 cred->gid != tcred->sgid ||
73089 cred->gid != tcred->gid) &&
73090- !capable(CAP_SYS_PTRACE)) {
73091+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73092+ (log && !capable(CAP_SYS_PTRACE)))
73093+ ) {
73094 rcu_read_unlock();
73095 return -EPERM;
73096 }
73097@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73098 smp_rmb();
73099 if (task->mm)
73100 dumpable = get_dumpable(task->mm);
73101- if (!dumpable && !capable(CAP_SYS_PTRACE))
73102+ if (!dumpable &&
73103+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73104+ (log && !capable(CAP_SYS_PTRACE))))
73105 return -EPERM;
73106
73107 return security_ptrace_access_check(task, mode);
73108@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
73109 {
73110 int err;
73111 task_lock(task);
73112- err = __ptrace_may_access(task, mode);
73113+ err = __ptrace_may_access(task, mode, 0);
73114+ task_unlock(task);
73115+ return !err;
73116+}
73117+
73118+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
73119+{
73120+ int err;
73121+ task_lock(task);
73122+ err = __ptrace_may_access(task, mode, 1);
73123 task_unlock(task);
73124 return !err;
73125 }
73126@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *task)
73127 goto out;
73128
73129 task_lock(task);
73130- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
73131+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
73132 task_unlock(task);
73133 if (retval)
73134 goto unlock_creds;
73135@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *task)
73136 goto unlock_tasklist;
73137
73138 task->ptrace = PT_PTRACED;
73139- if (capable(CAP_SYS_PTRACE))
73140+ if (capable_nolog(CAP_SYS_PTRACE))
73141 task->ptrace |= PT_PTRACE_CAP;
73142
73143 __ptrace_link(task, current);
73144@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
73145 {
73146 int copied = 0;
73147
73148+ pax_track_stack();
73149+
73150 while (len > 0) {
73151 char buf[128];
73152 int this_len, retval;
73153@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
73154 {
73155 int copied = 0;
73156
73157+ pax_track_stack();
73158+
73159 while (len > 0) {
73160 char buf[128];
73161 int this_len, retval;
73162@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *child, long request,
73163 int ret = -EIO;
73164 siginfo_t siginfo;
73165
73166+ pax_track_stack();
73167+
73168 switch (request) {
73169 case PTRACE_PEEKTEXT:
73170 case PTRACE_PEEKDATA:
73171@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *child, long request,
73172 ret = ptrace_setoptions(child, data);
73173 break;
73174 case PTRACE_GETEVENTMSG:
73175- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
73176+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
73177 break;
73178
73179 case PTRACE_GETSIGINFO:
73180 ret = ptrace_getsiginfo(child, &siginfo);
73181 if (!ret)
73182- ret = copy_siginfo_to_user((siginfo_t __user *) data,
73183+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
73184 &siginfo);
73185 break;
73186
73187 case PTRACE_SETSIGINFO:
73188- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
73189+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
73190 sizeof siginfo))
73191 ret = -EFAULT;
73192 else
73193@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
73194 goto out;
73195 }
73196
73197+ if (gr_handle_ptrace(child, request)) {
73198+ ret = -EPERM;
73199+ goto out_put_task_struct;
73200+ }
73201+
73202 if (request == PTRACE_ATTACH) {
73203 ret = ptrace_attach(child);
73204 /*
73205 * Some architectures need to do book-keeping after
73206 * a ptrace attach.
73207 */
73208- if (!ret)
73209+ if (!ret) {
73210 arch_ptrace_attach(child);
73211+ gr_audit_ptrace(child);
73212+ }
73213 goto out_put_task_struct;
73214 }
73215
73216@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
73217 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
73218 if (copied != sizeof(tmp))
73219 return -EIO;
73220- return put_user(tmp, (unsigned long __user *)data);
73221+ return put_user(tmp, (__force unsigned long __user *)data);
73222 }
73223
73224 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
73225@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
73226 siginfo_t siginfo;
73227 int ret;
73228
73229+ pax_track_stack();
73230+
73231 switch (request) {
73232 case PTRACE_PEEKTEXT:
73233 case PTRACE_PEEKDATA:
73234@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73235 goto out;
73236 }
73237
73238+ if (gr_handle_ptrace(child, request)) {
73239+ ret = -EPERM;
73240+ goto out_put_task_struct;
73241+ }
73242+
73243 if (request == PTRACE_ATTACH) {
73244 ret = ptrace_attach(child);
73245 /*
73246 * Some architectures need to do book-keeping after
73247 * a ptrace attach.
73248 */
73249- if (!ret)
73250+ if (!ret) {
73251 arch_ptrace_attach(child);
73252+ gr_audit_ptrace(child);
73253+ }
73254 goto out_put_task_struct;
73255 }
73256
73257diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
73258index 697c0a0..2402696 100644
73259--- a/kernel/rcutorture.c
73260+++ b/kernel/rcutorture.c
73261@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
73262 { 0 };
73263 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
73264 { 0 };
73265-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73266-static atomic_t n_rcu_torture_alloc;
73267-static atomic_t n_rcu_torture_alloc_fail;
73268-static atomic_t n_rcu_torture_free;
73269-static atomic_t n_rcu_torture_mberror;
73270-static atomic_t n_rcu_torture_error;
73271+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73272+static atomic_unchecked_t n_rcu_torture_alloc;
73273+static atomic_unchecked_t n_rcu_torture_alloc_fail;
73274+static atomic_unchecked_t n_rcu_torture_free;
73275+static atomic_unchecked_t n_rcu_torture_mberror;
73276+static atomic_unchecked_t n_rcu_torture_error;
73277 static long n_rcu_torture_timers;
73278 static struct list_head rcu_torture_removed;
73279 static cpumask_var_t shuffle_tmp_mask;
73280@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
73281
73282 spin_lock_bh(&rcu_torture_lock);
73283 if (list_empty(&rcu_torture_freelist)) {
73284- atomic_inc(&n_rcu_torture_alloc_fail);
73285+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
73286 spin_unlock_bh(&rcu_torture_lock);
73287 return NULL;
73288 }
73289- atomic_inc(&n_rcu_torture_alloc);
73290+ atomic_inc_unchecked(&n_rcu_torture_alloc);
73291 p = rcu_torture_freelist.next;
73292 list_del_init(p);
73293 spin_unlock_bh(&rcu_torture_lock);
73294@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
73295 static void
73296 rcu_torture_free(struct rcu_torture *p)
73297 {
73298- atomic_inc(&n_rcu_torture_free);
73299+ atomic_inc_unchecked(&n_rcu_torture_free);
73300 spin_lock_bh(&rcu_torture_lock);
73301 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
73302 spin_unlock_bh(&rcu_torture_lock);
73303@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
73304 i = rp->rtort_pipe_count;
73305 if (i > RCU_TORTURE_PIPE_LEN)
73306 i = RCU_TORTURE_PIPE_LEN;
73307- atomic_inc(&rcu_torture_wcount[i]);
73308+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73309 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73310 rp->rtort_mbtest = 0;
73311 rcu_torture_free(rp);
73312@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
73313 i = rp->rtort_pipe_count;
73314 if (i > RCU_TORTURE_PIPE_LEN)
73315 i = RCU_TORTURE_PIPE_LEN;
73316- atomic_inc(&rcu_torture_wcount[i]);
73317+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73318 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73319 rp->rtort_mbtest = 0;
73320 list_del(&rp->rtort_free);
73321@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
73322 i = old_rp->rtort_pipe_count;
73323 if (i > RCU_TORTURE_PIPE_LEN)
73324 i = RCU_TORTURE_PIPE_LEN;
73325- atomic_inc(&rcu_torture_wcount[i]);
73326+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73327 old_rp->rtort_pipe_count++;
73328 cur_ops->deferred_free(old_rp);
73329 }
73330@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned long unused)
73331 return;
73332 }
73333 if (p->rtort_mbtest == 0)
73334- atomic_inc(&n_rcu_torture_mberror);
73335+ atomic_inc_unchecked(&n_rcu_torture_mberror);
73336 spin_lock(&rand_lock);
73337 cur_ops->read_delay(&rand);
73338 n_rcu_torture_timers++;
73339@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
73340 continue;
73341 }
73342 if (p->rtort_mbtest == 0)
73343- atomic_inc(&n_rcu_torture_mberror);
73344+ atomic_inc_unchecked(&n_rcu_torture_mberror);
73345 cur_ops->read_delay(&rand);
73346 preempt_disable();
73347 pipe_count = p->rtort_pipe_count;
73348@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
73349 rcu_torture_current,
73350 rcu_torture_current_version,
73351 list_empty(&rcu_torture_freelist),
73352- atomic_read(&n_rcu_torture_alloc),
73353- atomic_read(&n_rcu_torture_alloc_fail),
73354- atomic_read(&n_rcu_torture_free),
73355- atomic_read(&n_rcu_torture_mberror),
73356+ atomic_read_unchecked(&n_rcu_torture_alloc),
73357+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
73358+ atomic_read_unchecked(&n_rcu_torture_free),
73359+ atomic_read_unchecked(&n_rcu_torture_mberror),
73360 n_rcu_torture_timers);
73361- if (atomic_read(&n_rcu_torture_mberror) != 0)
73362+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
73363 cnt += sprintf(&page[cnt], " !!!");
73364 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
73365 if (i > 1) {
73366 cnt += sprintf(&page[cnt], "!!! ");
73367- atomic_inc(&n_rcu_torture_error);
73368+ atomic_inc_unchecked(&n_rcu_torture_error);
73369 WARN_ON_ONCE(1);
73370 }
73371 cnt += sprintf(&page[cnt], "Reader Pipe: ");
73372@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
73373 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
73374 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73375 cnt += sprintf(&page[cnt], " %d",
73376- atomic_read(&rcu_torture_wcount[i]));
73377+ atomic_read_unchecked(&rcu_torture_wcount[i]));
73378 }
73379 cnt += sprintf(&page[cnt], "\n");
73380 if (cur_ops->stats)
73381@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
73382
73383 if (cur_ops->cleanup)
73384 cur_ops->cleanup();
73385- if (atomic_read(&n_rcu_torture_error))
73386+ if (atomic_read_unchecked(&n_rcu_torture_error))
73387 rcu_torture_print_module_parms("End of test: FAILURE");
73388 else
73389 rcu_torture_print_module_parms("End of test: SUCCESS");
73390@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
73391
73392 rcu_torture_current = NULL;
73393 rcu_torture_current_version = 0;
73394- atomic_set(&n_rcu_torture_alloc, 0);
73395- atomic_set(&n_rcu_torture_alloc_fail, 0);
73396- atomic_set(&n_rcu_torture_free, 0);
73397- atomic_set(&n_rcu_torture_mberror, 0);
73398- atomic_set(&n_rcu_torture_error, 0);
73399+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
73400+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
73401+ atomic_set_unchecked(&n_rcu_torture_free, 0);
73402+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
73403+ atomic_set_unchecked(&n_rcu_torture_error, 0);
73404 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
73405- atomic_set(&rcu_torture_wcount[i], 0);
73406+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
73407 for_each_possible_cpu(cpu) {
73408 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73409 per_cpu(rcu_torture_count, cpu)[i] = 0;
73410diff --git a/kernel/rcutree.c b/kernel/rcutree.c
73411index 683c4f3..97f54c6 100644
73412--- a/kernel/rcutree.c
73413+++ b/kernel/rcutree.c
73414@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
73415 /*
73416 * Do softirq processing for the current CPU.
73417 */
73418-static void rcu_process_callbacks(struct softirq_action *unused)
73419+static void rcu_process_callbacks(void)
73420 {
73421 /*
73422 * Memory references from any prior RCU read-side critical sections
73423diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
73424index c03edf7..ac1b341 100644
73425--- a/kernel/rcutree_plugin.h
73426+++ b/kernel/rcutree_plugin.h
73427@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_switch(int cpu)
73428 */
73429 void __rcu_read_lock(void)
73430 {
73431- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
73432+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
73433 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
73434 }
73435 EXPORT_SYMBOL_GPL(__rcu_read_lock);
73436@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
73437 struct task_struct *t = current;
73438
73439 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
73440- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
73441+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
73442 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
73443 rcu_read_unlock_special(t);
73444 }
73445diff --git a/kernel/relay.c b/kernel/relay.c
73446index 760c262..a9fd241 100644
73447--- a/kernel/relay.c
73448+++ b/kernel/relay.c
73449@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct file *in,
73450 unsigned int flags,
73451 int *nonpad_ret)
73452 {
73453- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
73454+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
73455 struct rchan_buf *rbuf = in->private_data;
73456 unsigned int subbuf_size = rbuf->chan->subbuf_size;
73457 uint64_t pos = (uint64_t) *ppos;
73458@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct file *in,
73459 .ops = &relay_pipe_buf_ops,
73460 .spd_release = relay_page_release,
73461 };
73462+ ssize_t ret;
73463+
73464+ pax_track_stack();
73465
73466 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
73467 return 0;
73468diff --git a/kernel/resource.c b/kernel/resource.c
73469index fb11a58..4e61ae1 100644
73470--- a/kernel/resource.c
73471+++ b/kernel/resource.c
73472@@ -132,8 +132,18 @@ static const struct file_operations proc_iomem_operations = {
73473
73474 static int __init ioresources_init(void)
73475 {
73476+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73477+#ifdef CONFIG_GRKERNSEC_PROC_USER
73478+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
73479+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
73480+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73481+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
73482+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
73483+#endif
73484+#else
73485 proc_create("ioports", 0, NULL, &proc_ioports_operations);
73486 proc_create("iomem", 0, NULL, &proc_iomem_operations);
73487+#endif
73488 return 0;
73489 }
73490 __initcall(ioresources_init);
73491diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
73492index a56f629..1fc4989 100644
73493--- a/kernel/rtmutex-tester.c
73494+++ b/kernel/rtmutex-tester.c
73495@@ -21,7 +21,7 @@
73496 #define MAX_RT_TEST_MUTEXES 8
73497
73498 static spinlock_t rttest_lock;
73499-static atomic_t rttest_event;
73500+static atomic_unchecked_t rttest_event;
73501
73502 struct test_thread_data {
73503 int opcode;
73504@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73505
73506 case RTTEST_LOCKCONT:
73507 td->mutexes[td->opdata] = 1;
73508- td->event = atomic_add_return(1, &rttest_event);
73509+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73510 return 0;
73511
73512 case RTTEST_RESET:
73513@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73514 return 0;
73515
73516 case RTTEST_RESETEVENT:
73517- atomic_set(&rttest_event, 0);
73518+ atomic_set_unchecked(&rttest_event, 0);
73519 return 0;
73520
73521 default:
73522@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73523 return ret;
73524
73525 td->mutexes[id] = 1;
73526- td->event = atomic_add_return(1, &rttest_event);
73527+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73528 rt_mutex_lock(&mutexes[id]);
73529- td->event = atomic_add_return(1, &rttest_event);
73530+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73531 td->mutexes[id] = 4;
73532 return 0;
73533
73534@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73535 return ret;
73536
73537 td->mutexes[id] = 1;
73538- td->event = atomic_add_return(1, &rttest_event);
73539+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73540 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73541- td->event = atomic_add_return(1, &rttest_event);
73542+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73543 td->mutexes[id] = ret ? 0 : 4;
73544 return ret ? -EINTR : 0;
73545
73546@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73547 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73548 return ret;
73549
73550- td->event = atomic_add_return(1, &rttest_event);
73551+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73552 rt_mutex_unlock(&mutexes[id]);
73553- td->event = atomic_add_return(1, &rttest_event);
73554+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73555 td->mutexes[id] = 0;
73556 return 0;
73557
73558@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73559 break;
73560
73561 td->mutexes[dat] = 2;
73562- td->event = atomic_add_return(1, &rttest_event);
73563+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73564 break;
73565
73566 case RTTEST_LOCKBKL:
73567@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73568 return;
73569
73570 td->mutexes[dat] = 3;
73571- td->event = atomic_add_return(1, &rttest_event);
73572+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73573 break;
73574
73575 case RTTEST_LOCKNOWAIT:
73576@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73577 return;
73578
73579 td->mutexes[dat] = 1;
73580- td->event = atomic_add_return(1, &rttest_event);
73581+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73582 return;
73583
73584 case RTTEST_LOCKBKL:
73585diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
73586index 29bd4ba..8c5de90 100644
73587--- a/kernel/rtmutex.c
73588+++ b/kernel/rtmutex.c
73589@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
73590 */
73591 spin_lock_irqsave(&pendowner->pi_lock, flags);
73592
73593- WARN_ON(!pendowner->pi_blocked_on);
73594+ BUG_ON(!pendowner->pi_blocked_on);
73595 WARN_ON(pendowner->pi_blocked_on != waiter);
73596 WARN_ON(pendowner->pi_blocked_on->lock != lock);
73597
73598diff --git a/kernel/sched.c b/kernel/sched.c
73599index 0591df8..6e343c3 100644
73600--- a/kernel/sched.c
73601+++ b/kernel/sched.c
73602@@ -2764,9 +2764,10 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
73603 {
73604 unsigned long flags;
73605 struct rq *rq;
73606- int cpu = get_cpu();
73607
73608 #ifdef CONFIG_SMP
73609+ int cpu = get_cpu();
73610+
73611 rq = task_rq_lock(p, &flags);
73612 p->state = TASK_WAKING;
73613
73614@@ -5043,7 +5044,7 @@ out:
73615 * In CONFIG_NO_HZ case, the idle load balance owner will do the
73616 * rebalancing for all the cpus for whom scheduler ticks are stopped.
73617 */
73618-static void run_rebalance_domains(struct softirq_action *h)
73619+static void run_rebalance_domains(void)
73620 {
73621 int this_cpu = smp_processor_id();
73622 struct rq *this_rq = cpu_rq(this_cpu);
73623@@ -5700,6 +5701,8 @@ asmlinkage void __sched schedule(void)
73624 struct rq *rq;
73625 int cpu;
73626
73627+ pax_track_stack();
73628+
73629 need_resched:
73630 preempt_disable();
73631 cpu = smp_processor_id();
73632@@ -5770,7 +5773,7 @@ EXPORT_SYMBOL(schedule);
73633 * Look out! "owner" is an entirely speculative pointer
73634 * access and not reliable.
73635 */
73636-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73637+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
73638 {
73639 unsigned int cpu;
73640 struct rq *rq;
73641@@ -5784,10 +5787,10 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73642 * DEBUG_PAGEALLOC could have unmapped it if
73643 * the mutex owner just released it and exited.
73644 */
73645- if (probe_kernel_address(&owner->cpu, cpu))
73646+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
73647 return 0;
73648 #else
73649- cpu = owner->cpu;
73650+ cpu = task_thread_info(owner)->cpu;
73651 #endif
73652
73653 /*
73654@@ -5816,7 +5819,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
73655 /*
73656 * Is that owner really running on that cpu?
73657 */
73658- if (task_thread_info(rq->curr) != owner || need_resched())
73659+ if (rq->curr != owner || need_resched())
73660 return 0;
73661
73662 cpu_relax();
73663@@ -6359,6 +6362,8 @@ int can_nice(const struct task_struct *p, const int nice)
73664 /* convert nice value [19,-20] to rlimit style value [1,40] */
73665 int nice_rlim = 20 - nice;
73666
73667+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73668+
73669 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
73670 capable(CAP_SYS_NICE));
73671 }
73672@@ -6392,7 +6397,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73673 if (nice > 19)
73674 nice = 19;
73675
73676- if (increment < 0 && !can_nice(current, nice))
73677+ if (increment < 0 && (!can_nice(current, nice) ||
73678+ gr_handle_chroot_nice()))
73679 return -EPERM;
73680
73681 retval = security_task_setnice(current, nice);
73682@@ -8774,7 +8780,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
73683 long power;
73684 int weight;
73685
73686- WARN_ON(!sd || !sd->groups);
73687+ BUG_ON(!sd || !sd->groups);
73688
73689 if (cpu != group_first_cpu(sd->groups))
73690 return;
73691diff --git a/kernel/signal.c b/kernel/signal.c
73692index 2494827..cda80a0 100644
73693--- a/kernel/signal.c
73694+++ b/kernel/signal.c
73695@@ -41,12 +41,12 @@
73696
73697 static struct kmem_cache *sigqueue_cachep;
73698
73699-static void __user *sig_handler(struct task_struct *t, int sig)
73700+static __sighandler_t sig_handler(struct task_struct *t, int sig)
73701 {
73702 return t->sighand->action[sig - 1].sa.sa_handler;
73703 }
73704
73705-static int sig_handler_ignored(void __user *handler, int sig)
73706+static int sig_handler_ignored(__sighandler_t handler, int sig)
73707 {
73708 /* Is it explicitly or implicitly ignored? */
73709 return handler == SIG_IGN ||
73710@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73711 static int sig_task_ignored(struct task_struct *t, int sig,
73712 int from_ancestor_ns)
73713 {
73714- void __user *handler;
73715+ __sighandler_t handler;
73716
73717 handler = sig_handler(t, sig);
73718
73719@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
73720 */
73721 user = get_uid(__task_cred(t)->user);
73722 atomic_inc(&user->sigpending);
73723+
73724+ if (!override_rlimit)
73725+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73726 if (override_rlimit ||
73727 atomic_read(&user->sigpending) <=
73728 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
73729@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73730
73731 int unhandled_signal(struct task_struct *tsk, int sig)
73732 {
73733- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73734+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73735 if (is_global_init(tsk))
73736 return 1;
73737 if (handler != SIG_IGN && handler != SIG_DFL)
73738@@ -627,6 +630,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73739 }
73740 }
73741
73742+ /* allow glibc communication via tgkill to other threads in our
73743+ thread group */
73744+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73745+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73746+ && gr_handle_signal(t, sig))
73747+ return -EPERM;
73748+
73749 return security_task_kill(t, info, sig, 0);
73750 }
73751
73752@@ -968,7 +978,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73753 return send_signal(sig, info, p, 1);
73754 }
73755
73756-static int
73757+int
73758 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73759 {
73760 return send_signal(sig, info, t, 0);
73761@@ -1005,6 +1015,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73762 unsigned long int flags;
73763 int ret, blocked, ignored;
73764 struct k_sigaction *action;
73765+ int is_unhandled = 0;
73766
73767 spin_lock_irqsave(&t->sighand->siglock, flags);
73768 action = &t->sighand->action[sig-1];
73769@@ -1019,9 +1030,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73770 }
73771 if (action->sa.sa_handler == SIG_DFL)
73772 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73773+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73774+ is_unhandled = 1;
73775 ret = specific_send_sig_info(sig, info, t);
73776 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73777
73778+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
73779+ normal operation */
73780+ if (is_unhandled) {
73781+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73782+ gr_handle_crash(t, sig);
73783+ }
73784+
73785 return ret;
73786 }
73787
73788@@ -1081,8 +1101,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73789 {
73790 int ret = check_kill_permission(sig, info, p);
73791
73792- if (!ret && sig)
73793+ if (!ret && sig) {
73794 ret = do_send_sig_info(sig, info, p, true);
73795+ if (!ret)
73796+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73797+ }
73798
73799 return ret;
73800 }
73801@@ -1644,6 +1667,8 @@ void ptrace_notify(int exit_code)
73802 {
73803 siginfo_t info;
73804
73805+ pax_track_stack();
73806+
73807 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
73808
73809 memset(&info, 0, sizeof info);
73810@@ -2275,7 +2300,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73811 int error = -ESRCH;
73812
73813 rcu_read_lock();
73814- p = find_task_by_vpid(pid);
73815+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73816+ /* allow glibc communication via tgkill to other threads in our
73817+ thread group */
73818+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73819+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
73820+ p = find_task_by_vpid_unrestricted(pid);
73821+ else
73822+#endif
73823+ p = find_task_by_vpid(pid);
73824 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73825 error = check_kill_permission(sig, info, p);
73826 /*
73827diff --git a/kernel/smp.c b/kernel/smp.c
73828index aa9cff3..631a0de 100644
73829--- a/kernel/smp.c
73830+++ b/kernel/smp.c
73831@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void *), void *info, int wait)
73832 }
73833 EXPORT_SYMBOL(smp_call_function);
73834
73835-void ipi_call_lock(void)
73836+void ipi_call_lock(void) __acquires(call_function.lock)
73837 {
73838 spin_lock(&call_function.lock);
73839 }
73840
73841-void ipi_call_unlock(void)
73842+void ipi_call_unlock(void) __releases(call_function.lock)
73843 {
73844 spin_unlock(&call_function.lock);
73845 }
73846
73847-void ipi_call_lock_irq(void)
73848+void ipi_call_lock_irq(void) __acquires(call_function.lock)
73849 {
73850 spin_lock_irq(&call_function.lock);
73851 }
73852
73853-void ipi_call_unlock_irq(void)
73854+void ipi_call_unlock_irq(void) __releases(call_function.lock)
73855 {
73856 spin_unlock_irq(&call_function.lock);
73857 }
73858diff --git a/kernel/softirq.c b/kernel/softirq.c
73859index 04a0252..580c512 100644
73860--- a/kernel/softirq.c
73861+++ b/kernel/softirq.c
73862@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
73863
73864 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73865
73866-char *softirq_to_name[NR_SOFTIRQS] = {
73867+const char * const softirq_to_name[NR_SOFTIRQS] = {
73868 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73869 "TASKLET", "SCHED", "HRTIMER", "RCU"
73870 };
73871@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
73872
73873 asmlinkage void __do_softirq(void)
73874 {
73875- struct softirq_action *h;
73876+ const struct softirq_action *h;
73877 __u32 pending;
73878 int max_restart = MAX_SOFTIRQ_RESTART;
73879 int cpu;
73880@@ -233,7 +233,7 @@ restart:
73881 kstat_incr_softirqs_this_cpu(h - softirq_vec);
73882
73883 trace_softirq_entry(h, softirq_vec);
73884- h->action(h);
73885+ h->action();
73886 trace_softirq_exit(h, softirq_vec);
73887 if (unlikely(prev_count != preempt_count())) {
73888 printk(KERN_ERR "huh, entered softirq %td %s %p"
73889@@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
73890 local_irq_restore(flags);
73891 }
73892
73893-void open_softirq(int nr, void (*action)(struct softirq_action *))
73894+void open_softirq(int nr, void (*action)(void))
73895 {
73896- softirq_vec[nr].action = action;
73897+ pax_open_kernel();
73898+ *(void **)&softirq_vec[nr].action = action;
73899+ pax_close_kernel();
73900 }
73901
73902 /*
73903@@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73904
73905 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73906
73907-static void tasklet_action(struct softirq_action *a)
73908+static void tasklet_action(void)
73909 {
73910 struct tasklet_struct *list;
73911
73912@@ -454,7 +456,7 @@ static void tasklet_action(struct softirq_action *a)
73913 }
73914 }
73915
73916-static void tasklet_hi_action(struct softirq_action *a)
73917+static void tasklet_hi_action(void)
73918 {
73919 struct tasklet_struct *list;
73920
73921diff --git a/kernel/sys.c b/kernel/sys.c
73922index e9512b1..3c265de 100644
73923--- a/kernel/sys.c
73924+++ b/kernel/sys.c
73925@@ -133,6 +133,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73926 error = -EACCES;
73927 goto out;
73928 }
73929+
73930+ if (gr_handle_chroot_setpriority(p, niceval)) {
73931+ error = -EACCES;
73932+ goto out;
73933+ }
73934+
73935 no_nice = security_task_setnice(p, niceval);
73936 if (no_nice) {
73937 error = no_nice;
73938@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
73939 !(user = find_user(who)))
73940 goto out_unlock; /* No processes for this user */
73941
73942- do_each_thread(g, p)
73943+ do_each_thread(g, p) {
73944 if (__task_cred(p)->uid == who)
73945 error = set_one_prio(p, niceval, error);
73946- while_each_thread(g, p);
73947+ } while_each_thread(g, p);
73948 if (who != cred->uid)
73949 free_uid(user); /* For find_user() */
73950 break;
73951@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
73952 !(user = find_user(who)))
73953 goto out_unlock; /* No processes for this user */
73954
73955- do_each_thread(g, p)
73956+ do_each_thread(g, p) {
73957 if (__task_cred(p)->uid == who) {
73958 niceval = 20 - task_nice(p);
73959 if (niceval > retval)
73960 retval = niceval;
73961 }
73962- while_each_thread(g, p);
73963+ } while_each_thread(g, p);
73964 if (who != cred->uid)
73965 free_uid(user); /* for find_user() */
73966 break;
73967@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73968 goto error;
73969 }
73970
73971+ if (gr_check_group_change(new->gid, new->egid, -1))
73972+ goto error;
73973+
73974 if (rgid != (gid_t) -1 ||
73975 (egid != (gid_t) -1 && egid != old->gid))
73976 new->sgid = new->egid;
73977@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73978 goto error;
73979
73980 retval = -EPERM;
73981+
73982+ if (gr_check_group_change(gid, gid, gid))
73983+ goto error;
73984+
73985 if (capable(CAP_SETGID))
73986 new->gid = new->egid = new->sgid = new->fsgid = gid;
73987 else if (gid == old->gid || gid == old->sgid)
73988@@ -567,12 +580,19 @@ static int set_user(struct cred *new)
73989 if (!new_user)
73990 return -EAGAIN;
73991
73992+ /*
73993+ * We don't fail in case of NPROC limit excess here because too many
73994+ * poorly written programs don't check set*uid() return code, assuming
73995+ * it never fails if called by root. We may still enforce NPROC limit
73996+ * for programs doing set*uid()+execve() by harmlessly deferring the
73997+ * failure to the execve() stage.
73998+ */
73999 if (atomic_read(&new_user->processes) >=
74000 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
74001- new_user != INIT_USER) {
74002- free_uid(new_user);
74003- return -EAGAIN;
74004- }
74005+ new_user != INIT_USER)
74006+ current->flags |= PF_NPROC_EXCEEDED;
74007+ else
74008+ current->flags &= ~PF_NPROC_EXCEEDED;
74009
74010 free_uid(new->user);
74011 new->user = new_user;
74012@@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
74013 goto error;
74014 }
74015
74016+ if (gr_check_user_change(new->uid, new->euid, -1))
74017+ goto error;
74018+
74019 if (new->uid != old->uid) {
74020 retval = set_user(new);
74021 if (retval < 0)
74022@@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
74023 goto error;
74024
74025 retval = -EPERM;
74026+
74027+ if (gr_check_crash_uid(uid))
74028+ goto error;
74029+ if (gr_check_user_change(uid, uid, uid))
74030+ goto error;
74031+
74032 if (capable(CAP_SETUID)) {
74033 new->suid = new->uid = uid;
74034 if (uid != old->uid) {
74035@@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
74036 goto error;
74037 }
74038
74039+ if (gr_check_user_change(ruid, euid, -1))
74040+ goto error;
74041+
74042 if (ruid != (uid_t) -1) {
74043 new->uid = ruid;
74044 if (ruid != old->uid) {
74045@@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
74046 goto error;
74047 }
74048
74049+ if (gr_check_group_change(rgid, egid, -1))
74050+ goto error;
74051+
74052 if (rgid != (gid_t) -1)
74053 new->gid = rgid;
74054 if (egid != (gid_t) -1)
74055@@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
74056 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
74057 goto error;
74058
74059+ if (gr_check_user_change(-1, -1, uid))
74060+ goto error;
74061+
74062 if (uid == old->uid || uid == old->euid ||
74063 uid == old->suid || uid == old->fsuid ||
74064 capable(CAP_SETUID)) {
74065@@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
74066 if (gid == old->gid || gid == old->egid ||
74067 gid == old->sgid || gid == old->fsgid ||
74068 capable(CAP_SETGID)) {
74069+ if (gr_check_group_change(-1, -1, gid))
74070+ goto error;
74071+
74072 if (gid != old_fsgid) {
74073 new->fsgid = gid;
74074 goto change_okay;
74075@@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
74076 error = get_dumpable(me->mm);
74077 break;
74078 case PR_SET_DUMPABLE:
74079- if (arg2 < 0 || arg2 > 1) {
74080+ if (arg2 > 1) {
74081 error = -EINVAL;
74082 break;
74083 }
74084diff --git a/kernel/sysctl.c b/kernel/sysctl.c
74085index b8bd058..ab6a76be 100644
74086--- a/kernel/sysctl.c
74087+++ b/kernel/sysctl.c
74088@@ -63,6 +63,13 @@
74089 static int deprecated_sysctl_warning(struct __sysctl_args *args);
74090
74091 #if defined(CONFIG_SYSCTL)
74092+#include <linux/grsecurity.h>
74093+#include <linux/grinternal.h>
74094+
74095+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
74096+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
74097+ const int op);
74098+extern int gr_handle_chroot_sysctl(const int op);
74099
74100 /* External variables not in a header file. */
74101 extern int C_A_D;
74102@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
74103 static int proc_taint(struct ctl_table *table, int write,
74104 void __user *buffer, size_t *lenp, loff_t *ppos);
74105 #endif
74106+extern ctl_table grsecurity_table[];
74107
74108 static struct ctl_table root_table[];
74109 static struct ctl_table_root sysctl_table_root;
74110@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
74111 int sysctl_legacy_va_layout;
74112 #endif
74113
74114+#ifdef CONFIG_PAX_SOFTMODE
74115+static ctl_table pax_table[] = {
74116+ {
74117+ .ctl_name = CTL_UNNUMBERED,
74118+ .procname = "softmode",
74119+ .data = &pax_softmode,
74120+ .maxlen = sizeof(unsigned int),
74121+ .mode = 0600,
74122+ .proc_handler = &proc_dointvec,
74123+ },
74124+
74125+ { .ctl_name = 0 }
74126+};
74127+#endif
74128+
74129 extern int prove_locking;
74130 extern int lock_stat;
74131
74132@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
74133 #endif
74134
74135 static struct ctl_table kern_table[] = {
74136+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
74137+ {
74138+ .ctl_name = CTL_UNNUMBERED,
74139+ .procname = "grsecurity",
74140+ .mode = 0500,
74141+ .child = grsecurity_table,
74142+ },
74143+#endif
74144+
74145+#ifdef CONFIG_PAX_SOFTMODE
74146+ {
74147+ .ctl_name = CTL_UNNUMBERED,
74148+ .procname = "pax",
74149+ .mode = 0500,
74150+ .child = pax_table,
74151+ },
74152+#endif
74153+
74154 {
74155 .ctl_name = CTL_UNNUMBERED,
74156 .procname = "sched_child_runs_first",
74157@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
74158 .data = &modprobe_path,
74159 .maxlen = KMOD_PATH_LEN,
74160 .mode = 0644,
74161- .proc_handler = &proc_dostring,
74162- .strategy = &sysctl_string,
74163+ .proc_handler = &proc_dostring_modpriv,
74164+ .strategy = &sysctl_string_modpriv,
74165 },
74166 {
74167 .ctl_name = CTL_UNNUMBERED,
74168@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
74169 .mode = 0644,
74170 .proc_handler = &proc_dointvec
74171 },
74172+ {
74173+ .procname = "heap_stack_gap",
74174+ .data = &sysctl_heap_stack_gap,
74175+ .maxlen = sizeof(sysctl_heap_stack_gap),
74176+ .mode = 0644,
74177+ .proc_handler = proc_doulongvec_minmax,
74178+ },
74179 #else
74180 {
74181 .ctl_name = CTL_UNNUMBERED,
74182@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
74183 return 0;
74184 }
74185
74186+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
74187+
74188 static int parse_table(int __user *name, int nlen,
74189 void __user *oldval, size_t __user *oldlenp,
74190 void __user *newval, size_t newlen,
74191@@ -1821,7 +1871,7 @@ repeat:
74192 if (n == table->ctl_name) {
74193 int error;
74194 if (table->child) {
74195- if (sysctl_perm(root, table, MAY_EXEC))
74196+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
74197 return -EPERM;
74198 name++;
74199 nlen--;
74200@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
74201 int error;
74202 int mode;
74203
74204+ if (table->parent != NULL && table->parent->procname != NULL &&
74205+ table->procname != NULL &&
74206+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
74207+ return -EACCES;
74208+ if (gr_handle_chroot_sysctl(op))
74209+ return -EACCES;
74210+ error = gr_handle_sysctl(table, op);
74211+ if (error)
74212+ return error;
74213+
74214+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74215+ if (error)
74216+ return error;
74217+
74218+ if (root->permissions)
74219+ mode = root->permissions(root, current->nsproxy, table);
74220+ else
74221+ mode = table->mode;
74222+
74223+ return test_perm(mode, op);
74224+}
74225+
74226+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
74227+{
74228+ int error;
74229+ int mode;
74230+
74231 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74232 if (error)
74233 return error;
74234@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *table, int write,
74235 buffer, lenp, ppos);
74236 }
74237
74238+int proc_dostring_modpriv(struct ctl_table *table, int write,
74239+ void __user *buffer, size_t *lenp, loff_t *ppos)
74240+{
74241+ if (write && !capable(CAP_SYS_MODULE))
74242+ return -EPERM;
74243+
74244+ return _proc_do_string(table->data, table->maxlen, write,
74245+ buffer, lenp, ppos);
74246+}
74247+
74248
74249 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
74250 int *valp,
74251@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
74252 vleft = table->maxlen / sizeof(unsigned long);
74253 left = *lenp;
74254
74255- for (; left && vleft--; i++, min++, max++, first=0) {
74256+ for (; left && vleft--; i++, first=0) {
74257 if (write) {
74258 while (left) {
74259 char c;
74260@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *table, int write,
74261 return -ENOSYS;
74262 }
74263
74264+int proc_dostring_modpriv(struct ctl_table *table, int write,
74265+ void __user *buffer, size_t *lenp, loff_t *ppos)
74266+{
74267+ return -ENOSYS;
74268+}
74269+
74270 int proc_dointvec(struct ctl_table *table, int write,
74271 void __user *buffer, size_t *lenp, loff_t *ppos)
74272 {
74273@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *table,
74274 return 1;
74275 }
74276
74277+int sysctl_string_modpriv(struct ctl_table *table,
74278+ void __user *oldval, size_t __user *oldlenp,
74279+ void __user *newval, size_t newlen)
74280+{
74281+ if (newval && newlen && !capable(CAP_SYS_MODULE))
74282+ return -EPERM;
74283+
74284+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
74285+}
74286+
74287 /*
74288 * This function makes sure that all of the integers in the vector
74289 * are between the minimum and maximum values given in the arrays
74290@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *table,
74291 return -ENOSYS;
74292 }
74293
74294+int sysctl_string_modpriv(struct ctl_table *table,
74295+ void __user *oldval, size_t __user *oldlenp,
74296+ void __user *newval, size_t newlen)
74297+{
74298+ return -ENOSYS;
74299+}
74300+
74301 int sysctl_intvec(struct ctl_table *table,
74302 void __user *oldval, size_t __user *oldlenp,
74303 void __user *newval, size_t newlen)
74304@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
74305 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
74306 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
74307 EXPORT_SYMBOL(proc_dostring);
74308+EXPORT_SYMBOL(proc_dostring_modpriv);
74309 EXPORT_SYMBOL(proc_doulongvec_minmax);
74310 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
74311 EXPORT_SYMBOL(register_sysctl_table);
74312@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
74313 EXPORT_SYMBOL(sysctl_jiffies);
74314 EXPORT_SYMBOL(sysctl_ms_jiffies);
74315 EXPORT_SYMBOL(sysctl_string);
74316+EXPORT_SYMBOL(sysctl_string_modpriv);
74317 EXPORT_SYMBOL(sysctl_data);
74318 EXPORT_SYMBOL(unregister_sysctl_table);
74319diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
74320index 469193c..ea3ecb2 100644
74321--- a/kernel/sysctl_check.c
74322+++ b/kernel/sysctl_check.c
74323@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
74324 } else {
74325 if ((table->strategy == sysctl_data) ||
74326 (table->strategy == sysctl_string) ||
74327+ (table->strategy == sysctl_string_modpriv) ||
74328 (table->strategy == sysctl_intvec) ||
74329 (table->strategy == sysctl_jiffies) ||
74330 (table->strategy == sysctl_ms_jiffies) ||
74331 (table->proc_handler == proc_dostring) ||
74332+ (table->proc_handler == proc_dostring_modpriv) ||
74333 (table->proc_handler == proc_dointvec) ||
74334 (table->proc_handler == proc_dointvec_minmax) ||
74335 (table->proc_handler == proc_dointvec_jiffies) ||
74336diff --git a/kernel/taskstats.c b/kernel/taskstats.c
74337index a4ef542..798bcd7 100644
74338--- a/kernel/taskstats.c
74339+++ b/kernel/taskstats.c
74340@@ -26,9 +26,12 @@
74341 #include <linux/cgroup.h>
74342 #include <linux/fs.h>
74343 #include <linux/file.h>
74344+#include <linux/grsecurity.h>
74345 #include <net/genetlink.h>
74346 #include <asm/atomic.h>
74347
74348+extern int gr_is_taskstats_denied(int pid);
74349+
74350 /*
74351 * Maximum length of a cpumask that can be specified in
74352 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
74353@@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
74354 size_t size;
74355 cpumask_var_t mask;
74356
74357+ if (gr_is_taskstats_denied(current->pid))
74358+ return -EACCES;
74359+
74360 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
74361 return -ENOMEM;
74362
74363diff --git a/kernel/time.c b/kernel/time.c
74364index 33df60e..ca768bd 100644
74365--- a/kernel/time.c
74366+++ b/kernel/time.c
74367@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
74368 return error;
74369
74370 if (tz) {
74371+ /* we log in do_settimeofday called below, so don't log twice
74372+ */
74373+ if (!tv)
74374+ gr_log_timechange();
74375+
74376 /* SMP safe, global irq locking makes it work. */
74377 sys_tz = *tz;
74378 update_vsyscall_tz();
74379@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
74380 * Avoid unnecessary multiplications/divisions in the
74381 * two most common HZ cases:
74382 */
74383-unsigned int inline jiffies_to_msecs(const unsigned long j)
74384+inline unsigned int jiffies_to_msecs(const unsigned long j)
74385 {
74386 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
74387 return (MSEC_PER_SEC / HZ) * j;
74388@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
74389 }
74390 EXPORT_SYMBOL(jiffies_to_msecs);
74391
74392-unsigned int inline jiffies_to_usecs(const unsigned long j)
74393+inline unsigned int jiffies_to_usecs(const unsigned long j)
74394 {
74395 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
74396 return (USEC_PER_SEC / HZ) * j;
74397diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
74398index 57b953f..06f149f 100644
74399--- a/kernel/time/tick-broadcast.c
74400+++ b/kernel/time/tick-broadcast.c
74401@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
74402 * then clear the broadcast bit.
74403 */
74404 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
74405- int cpu = smp_processor_id();
74406+ cpu = smp_processor_id();
74407
74408 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
74409 tick_broadcast_clear_oneshot(cpu);
74410diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
74411index 4a71cff..ffb5548 100644
74412--- a/kernel/time/timekeeping.c
74413+++ b/kernel/time/timekeeping.c
74414@@ -14,6 +14,7 @@
74415 #include <linux/init.h>
74416 #include <linux/mm.h>
74417 #include <linux/sched.h>
74418+#include <linux/grsecurity.h>
74419 #include <linux/sysdev.h>
74420 #include <linux/clocksource.h>
74421 #include <linux/jiffies.h>
74422@@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
74423 */
74424 struct timespec ts = xtime;
74425 timespec_add_ns(&ts, nsec);
74426- ACCESS_ONCE(xtime_cache) = ts;
74427+ ACCESS_ONCE_RW(xtime_cache) = ts;
74428 }
74429
74430 /* must hold xtime_lock */
74431@@ -337,6 +338,8 @@ int do_settimeofday(struct timespec *tv)
74432 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
74433 return -EINVAL;
74434
74435+ gr_log_timechange();
74436+
74437 write_seqlock_irqsave(&xtime_lock, flags);
74438
74439 timekeeping_forward_now();
74440diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74441index 54c0dda..e9095d9 100644
74442--- a/kernel/time/timer_list.c
74443+++ b/kernel/time/timer_list.c
74444@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74445
74446 static void print_name_offset(struct seq_file *m, void *sym)
74447 {
74448+#ifdef CONFIG_GRKERNSEC_HIDESYM
74449+ SEQ_printf(m, "<%p>", NULL);
74450+#else
74451 char symname[KSYM_NAME_LEN];
74452
74453 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74454 SEQ_printf(m, "<%p>", sym);
74455 else
74456 SEQ_printf(m, "%s", symname);
74457+#endif
74458 }
74459
74460 static void
74461@@ -112,7 +116,11 @@ next_one:
74462 static void
74463 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
74464 {
74465+#ifdef CONFIG_GRKERNSEC_HIDESYM
74466+ SEQ_printf(m, " .base: %p\n", NULL);
74467+#else
74468 SEQ_printf(m, " .base: %p\n", base);
74469+#endif
74470 SEQ_printf(m, " .index: %d\n",
74471 base->index);
74472 SEQ_printf(m, " .resolution: %Lu nsecs\n",
74473@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs(void)
74474 {
74475 struct proc_dir_entry *pe;
74476
74477+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74478+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
74479+#else
74480 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
74481+#endif
74482 if (!pe)
74483 return -ENOMEM;
74484 return 0;
74485diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
74486index ee5681f..634089b 100644
74487--- a/kernel/time/timer_stats.c
74488+++ b/kernel/time/timer_stats.c
74489@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74490 static unsigned long nr_entries;
74491 static struct entry entries[MAX_ENTRIES];
74492
74493-static atomic_t overflow_count;
74494+static atomic_unchecked_t overflow_count;
74495
74496 /*
74497 * The entries are in a hash-table, for fast lookup:
74498@@ -140,7 +140,7 @@ static void reset_entries(void)
74499 nr_entries = 0;
74500 memset(entries, 0, sizeof(entries));
74501 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74502- atomic_set(&overflow_count, 0);
74503+ atomic_set_unchecked(&overflow_count, 0);
74504 }
74505
74506 static struct entry *alloc_entry(void)
74507@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74508 if (likely(entry))
74509 entry->count++;
74510 else
74511- atomic_inc(&overflow_count);
74512+ atomic_inc_unchecked(&overflow_count);
74513
74514 out_unlock:
74515 spin_unlock_irqrestore(lock, flags);
74516@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74517
74518 static void print_name_offset(struct seq_file *m, unsigned long addr)
74519 {
74520+#ifdef CONFIG_GRKERNSEC_HIDESYM
74521+ seq_printf(m, "<%p>", NULL);
74522+#else
74523 char symname[KSYM_NAME_LEN];
74524
74525 if (lookup_symbol_name(addr, symname) < 0)
74526 seq_printf(m, "<%p>", (void *)addr);
74527 else
74528 seq_printf(m, "%s", symname);
74529+#endif
74530 }
74531
74532 static int tstats_show(struct seq_file *m, void *v)
74533@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74534
74535 seq_puts(m, "Timer Stats Version: v0.2\n");
74536 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74537- if (atomic_read(&overflow_count))
74538+ if (atomic_read_unchecked(&overflow_count))
74539 seq_printf(m, "Overflow: %d entries\n",
74540- atomic_read(&overflow_count));
74541+ atomic_read_unchecked(&overflow_count));
74542
74543 for (i = 0; i < nr_entries; i++) {
74544 entry = entries + i;
74545@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(void)
74546 {
74547 struct proc_dir_entry *pe;
74548
74549+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74550+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74551+#else
74552 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74553+#endif
74554 if (!pe)
74555 return -ENOMEM;
74556 return 0;
74557diff --git a/kernel/timer.c b/kernel/timer.c
74558index cb3c1f1..8bf5526 100644
74559--- a/kernel/timer.c
74560+++ b/kernel/timer.c
74561@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
74562 /*
74563 * This function runs timers and the timer-tq in bottom half context.
74564 */
74565-static void run_timer_softirq(struct softirq_action *h)
74566+static void run_timer_softirq(void)
74567 {
74568 struct tvec_base *base = __get_cpu_var(tvec_bases);
74569
74570diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74571index d9d6206..f19467e 100644
74572--- a/kernel/trace/blktrace.c
74573+++ b/kernel/trace/blktrace.c
74574@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74575 struct blk_trace *bt = filp->private_data;
74576 char buf[16];
74577
74578- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74579+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74580
74581 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74582 }
74583@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74584 return 1;
74585
74586 bt = buf->chan->private_data;
74587- atomic_inc(&bt->dropped);
74588+ atomic_inc_unchecked(&bt->dropped);
74589 return 0;
74590 }
74591
74592@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74593
74594 bt->dir = dir;
74595 bt->dev = dev;
74596- atomic_set(&bt->dropped, 0);
74597+ atomic_set_unchecked(&bt->dropped, 0);
74598
74599 ret = -EIO;
74600 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74601diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74602index 4872937..c794d40 100644
74603--- a/kernel/trace/ftrace.c
74604+++ b/kernel/trace/ftrace.c
74605@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74606
74607 ip = rec->ip;
74608
74609+ ret = ftrace_arch_code_modify_prepare();
74610+ FTRACE_WARN_ON(ret);
74611+ if (ret)
74612+ return 0;
74613+
74614 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74615+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74616 if (ret) {
74617 ftrace_bug(ret, ip);
74618 rec->flags |= FTRACE_FL_FAILED;
74619- return 0;
74620 }
74621- return 1;
74622+ return ret ? 0 : 1;
74623 }
74624
74625 /*
74626diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74627index e749a05..19c6e94 100644
74628--- a/kernel/trace/ring_buffer.c
74629+++ b/kernel/trace/ring_buffer.c
74630@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(struct list_head *list)
74631 * the reader page). But if the next page is a header page,
74632 * its flags will be non zero.
74633 */
74634-static int inline
74635+static inline int
74636 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74637 struct buffer_page *page, struct list_head *list)
74638 {
74639diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74640index a2a2d1f..7f32b09 100644
74641--- a/kernel/trace/trace.c
74642+++ b/kernel/trace/trace.c
74643@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
74644 size_t rem;
74645 unsigned int i;
74646
74647+ pax_track_stack();
74648+
74649 /* copy the tracer to avoid using a global lock all around */
74650 mutex_lock(&trace_types_lock);
74651 if (unlikely(old_tracer != current_trace && current_trace)) {
74652@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
74653 int entries, size, i;
74654 size_t ret;
74655
74656+ pax_track_stack();
74657+
74658 if (*ppos & (PAGE_SIZE - 1)) {
74659 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
74660 return -EINVAL;
74661@@ -3816,10 +3820,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74662 };
74663 #endif
74664
74665-static struct dentry *d_tracer;
74666-
74667 struct dentry *tracing_init_dentry(void)
74668 {
74669+ static struct dentry *d_tracer;
74670 static int once;
74671
74672 if (d_tracer)
74673@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
74674 return d_tracer;
74675 }
74676
74677-static struct dentry *d_percpu;
74678-
74679 struct dentry *tracing_dentry_percpu(void)
74680 {
74681+ static struct dentry *d_percpu;
74682 static int once;
74683 struct dentry *d_tracer;
74684
74685diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74686index d128f65..f37b4af 100644
74687--- a/kernel/trace/trace_events.c
74688+++ b/kernel/trace/trace_events.c
74689@@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list);
74690 * Modules must own their file_operations to keep up with
74691 * reference counting.
74692 */
74693+
74694 struct ftrace_module_file_ops {
74695 struct list_head list;
74696 struct module *mod;
74697- struct file_operations id;
74698- struct file_operations enable;
74699- struct file_operations format;
74700- struct file_operations filter;
74701 };
74702
74703 static void remove_subsystem_dir(const char *name)
74704@@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod)
74705
74706 file_ops->mod = mod;
74707
74708- file_ops->id = ftrace_event_id_fops;
74709- file_ops->id.owner = mod;
74710-
74711- file_ops->enable = ftrace_enable_fops;
74712- file_ops->enable.owner = mod;
74713-
74714- file_ops->filter = ftrace_event_filter_fops;
74715- file_ops->filter.owner = mod;
74716-
74717- file_ops->format = ftrace_event_format_fops;
74718- file_ops->format.owner = mod;
74719+ pax_open_kernel();
74720+ *(void **)&mod->trace_id.owner = mod;
74721+ *(void **)&mod->trace_enable.owner = mod;
74722+ *(void **)&mod->trace_filter.owner = mod;
74723+ *(void **)&mod->trace_format.owner = mod;
74724+ pax_close_kernel();
74725
74726 list_add(&file_ops->list, &ftrace_module_file_list);
74727
74728@@ -1063,8 +1055,8 @@ static void trace_module_add_events(struct module *mod)
74729 call->mod = mod;
74730 list_add(&call->list, &ftrace_events);
74731 event_create_dir(call, d_events,
74732- &file_ops->id, &file_ops->enable,
74733- &file_ops->filter, &file_ops->format);
74734+ &mod->trace_id, &mod->trace_enable,
74735+ &mod->trace_filter, &mod->trace_format);
74736 }
74737 }
74738
74739diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74740index 0acd834..b800b56 100644
74741--- a/kernel/trace/trace_mmiotrace.c
74742+++ b/kernel/trace/trace_mmiotrace.c
74743@@ -23,7 +23,7 @@ struct header_iter {
74744 static struct trace_array *mmio_trace_array;
74745 static bool overrun_detected;
74746 static unsigned long prev_overruns;
74747-static atomic_t dropped_count;
74748+static atomic_unchecked_t dropped_count;
74749
74750 static void mmio_reset_data(struct trace_array *tr)
74751 {
74752@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iterator *iter)
74753
74754 static unsigned long count_overruns(struct trace_iterator *iter)
74755 {
74756- unsigned long cnt = atomic_xchg(&dropped_count, 0);
74757+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74758 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74759
74760 if (over > prev_overruns)
74761@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74762 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74763 sizeof(*entry), 0, pc);
74764 if (!event) {
74765- atomic_inc(&dropped_count);
74766+ atomic_inc_unchecked(&dropped_count);
74767 return;
74768 }
74769 entry = ring_buffer_event_data(event);
74770@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74771 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74772 sizeof(*entry), 0, pc);
74773 if (!event) {
74774- atomic_inc(&dropped_count);
74775+ atomic_inc_unchecked(&dropped_count);
74776 return;
74777 }
74778 entry = ring_buffer_event_data(event);
74779diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74780index b6c12c6..41fdc53 100644
74781--- a/kernel/trace/trace_output.c
74782+++ b/kernel/trace/trace_output.c
74783@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
74784 return 0;
74785 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74786 if (!IS_ERR(p)) {
74787- p = mangle_path(s->buffer + s->len, p, "\n");
74788+ p = mangle_path(s->buffer + s->len, p, "\n\\");
74789 if (p) {
74790 s->len = p - s->buffer;
74791 return 1;
74792diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74793index 8504ac7..ecf0adb 100644
74794--- a/kernel/trace/trace_stack.c
74795+++ b/kernel/trace/trace_stack.c
74796@@ -50,7 +50,7 @@ static inline void check_stack(void)
74797 return;
74798
74799 /* we do not handle interrupt stacks yet */
74800- if (!object_is_on_stack(&this_size))
74801+ if (!object_starts_on_stack(&this_size))
74802 return;
74803
74804 local_irq_save(flags);
74805diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
74806index 40cafb0..d5ead43 100644
74807--- a/kernel/trace/trace_workqueue.c
74808+++ b/kernel/trace/trace_workqueue.c
74809@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
74810 int cpu;
74811 pid_t pid;
74812 /* Can be inserted from interrupt or user context, need to be atomic */
74813- atomic_t inserted;
74814+ atomic_unchecked_t inserted;
74815 /*
74816 * Don't need to be atomic, works are serialized in a single workqueue thread
74817 * on a single CPU.
74818@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_struct *wq_thread,
74819 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
74820 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
74821 if (node->pid == wq_thread->pid) {
74822- atomic_inc(&node->inserted);
74823+ atomic_inc_unchecked(&node->inserted);
74824 goto found;
74825 }
74826 }
74827@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
74828 tsk = get_pid_task(pid, PIDTYPE_PID);
74829 if (tsk) {
74830 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
74831- atomic_read(&cws->inserted), cws->executed,
74832+ atomic_read_unchecked(&cws->inserted), cws->executed,
74833 tsk->comm);
74834 put_task_struct(tsk);
74835 }
74836diff --git a/kernel/user.c b/kernel/user.c
74837index 1b91701..8795237 100644
74838--- a/kernel/user.c
74839+++ b/kernel/user.c
74840@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
74841 spin_lock_irq(&uidhash_lock);
74842 up = uid_hash_find(uid, hashent);
74843 if (up) {
74844+ put_user_ns(ns);
74845 key_put(new->uid_keyring);
74846 key_put(new->session_keyring);
74847 kmem_cache_free(uid_cachep, new);
74848diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74849index 234ceb1..ad74049 100644
74850--- a/lib/Kconfig.debug
74851+++ b/lib/Kconfig.debug
74852@@ -905,7 +905,7 @@ config LATENCYTOP
74853 select STACKTRACE
74854 select SCHEDSTATS
74855 select SCHED_DEBUG
74856- depends on HAVE_LATENCYTOP_SUPPORT
74857+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
74858 help
74859 Enable this option if you want to use the LatencyTOP tool
74860 to find out which userspace is blocking on what kernel operations.
74861diff --git a/lib/bitmap.c b/lib/bitmap.c
74862index 7025658..8d14cab 100644
74863--- a/lib/bitmap.c
74864+++ b/lib/bitmap.c
74865@@ -341,7 +341,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74866 {
74867 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74868 u32 chunk;
74869- const char __user *ubuf = buf;
74870+ const char __user *ubuf = (const char __force_user *)buf;
74871
74872 bitmap_zero(maskp, nmaskbits);
74873
74874@@ -426,7 +426,7 @@ int bitmap_parse_user(const char __user *ubuf,
74875 {
74876 if (!access_ok(VERIFY_READ, ubuf, ulen))
74877 return -EFAULT;
74878- return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
74879+ return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
74880 }
74881 EXPORT_SYMBOL(bitmap_parse_user);
74882
74883diff --git a/lib/bug.c b/lib/bug.c
74884index 300e41a..2779eb0 100644
74885--- a/lib/bug.c
74886+++ b/lib/bug.c
74887@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74888 return BUG_TRAP_TYPE_NONE;
74889
74890 bug = find_bug(bugaddr);
74891+ if (!bug)
74892+ return BUG_TRAP_TYPE_NONE;
74893
74894 printk(KERN_EMERG "------------[ cut here ]------------\n");
74895
74896diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74897index 2b413db..e21d207 100644
74898--- a/lib/debugobjects.c
74899+++ b/lib/debugobjects.c
74900@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74901 if (limit > 4)
74902 return;
74903
74904- is_on_stack = object_is_on_stack(addr);
74905+ is_on_stack = object_starts_on_stack(addr);
74906 if (is_on_stack == onstack)
74907 return;
74908
74909diff --git a/lib/devres.c b/lib/devres.c
74910index 72c8909..7543868 100644
74911--- a/lib/devres.c
74912+++ b/lib/devres.c
74913@@ -80,7 +80,7 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
74914 {
74915 iounmap(addr);
74916 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74917- (void *)addr));
74918+ (void __force *)addr));
74919 }
74920 EXPORT_SYMBOL(devm_iounmap);
74921
74922@@ -140,7 +140,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74923 {
74924 ioport_unmap(addr);
74925 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74926- devm_ioport_map_match, (void *)addr));
74927+ devm_ioport_map_match, (void __force *)addr));
74928 }
74929 EXPORT_SYMBOL(devm_ioport_unmap);
74930
74931diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74932index 084e879..0674448 100644
74933--- a/lib/dma-debug.c
74934+++ b/lib/dma-debug.c
74935@@ -861,7 +861,7 @@ out:
74936
74937 static void check_for_stack(struct device *dev, void *addr)
74938 {
74939- if (object_is_on_stack(addr))
74940+ if (object_starts_on_stack(addr))
74941 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74942 "stack [addr=%p]\n", addr);
74943 }
74944diff --git a/lib/idr.c b/lib/idr.c
74945index eda7ba3..915dfae 100644
74946--- a/lib/idr.c
74947+++ b/lib/idr.c
74948@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
74949 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
74950
74951 /* if already at the top layer, we need to grow */
74952- if (id >= 1 << (idp->layers * IDR_BITS)) {
74953+ if (id >= (1 << (idp->layers * IDR_BITS))) {
74954 *starting_id = id;
74955 return IDR_NEED_TO_GROW;
74956 }
74957diff --git a/lib/inflate.c b/lib/inflate.c
74958index d102559..4215f31 100644
74959--- a/lib/inflate.c
74960+++ b/lib/inflate.c
74961@@ -266,7 +266,7 @@ static void free(void *where)
74962 malloc_ptr = free_mem_ptr;
74963 }
74964 #else
74965-#define malloc(a) kmalloc(a, GFP_KERNEL)
74966+#define malloc(a) kmalloc((a), GFP_KERNEL)
74967 #define free(a) kfree(a)
74968 #endif
74969
74970diff --git a/lib/kobject.c b/lib/kobject.c
74971index b512b74..8115eb1 100644
74972--- a/lib/kobject.c
74973+++ b/lib/kobject.c
74974@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
74975 return ret;
74976 }
74977
74978-struct sysfs_ops kobj_sysfs_ops = {
74979+const struct sysfs_ops kobj_sysfs_ops = {
74980 .show = kobj_attr_show,
74981 .store = kobj_attr_store,
74982 };
74983@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
74984 * If the kset was not able to be created, NULL will be returned.
74985 */
74986 static struct kset *kset_create(const char *name,
74987- struct kset_uevent_ops *uevent_ops,
74988+ const struct kset_uevent_ops *uevent_ops,
74989 struct kobject *parent_kobj)
74990 {
74991 struct kset *kset;
74992@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
74993 * If the kset was not able to be created, NULL will be returned.
74994 */
74995 struct kset *kset_create_and_add(const char *name,
74996- struct kset_uevent_ops *uevent_ops,
74997+ const struct kset_uevent_ops *uevent_ops,
74998 struct kobject *parent_kobj)
74999 {
75000 struct kset *kset;
75001diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
75002index 507b821..0bf8ed0 100644
75003--- a/lib/kobject_uevent.c
75004+++ b/lib/kobject_uevent.c
75005@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
75006 const char *subsystem;
75007 struct kobject *top_kobj;
75008 struct kset *kset;
75009- struct kset_uevent_ops *uevent_ops;
75010+ const struct kset_uevent_ops *uevent_ops;
75011 u64 seq;
75012 int i = 0;
75013 int retval = 0;
75014diff --git a/lib/kref.c b/lib/kref.c
75015index 9ecd6e8..12c94c1 100644
75016--- a/lib/kref.c
75017+++ b/lib/kref.c
75018@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
75019 */
75020 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
75021 {
75022- WARN_ON(release == NULL);
75023+ BUG_ON(release == NULL);
75024 WARN_ON(release == (void (*)(struct kref *))kfree);
75025
75026 if (atomic_dec_and_test(&kref->refcount)) {
75027diff --git a/lib/parser.c b/lib/parser.c
75028index b00d020..1b34325 100644
75029--- a/lib/parser.c
75030+++ b/lib/parser.c
75031@@ -126,7 +126,7 @@ static int match_number(substring_t *s, int *result, int base)
75032 char *buf;
75033 int ret;
75034
75035- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
75036+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
75037 if (!buf)
75038 return -ENOMEM;
75039 memcpy(buf, s->from, s->to - s->from);
75040diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75041index 92cdd99..a8149d7 100644
75042--- a/lib/radix-tree.c
75043+++ b/lib/radix-tree.c
75044@@ -81,7 +81,7 @@ struct radix_tree_preload {
75045 int nr;
75046 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
75047 };
75048-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75049+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75050
75051 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
75052 {
75053diff --git a/lib/random32.c b/lib/random32.c
75054index 217d5c4..45aba8a 100644
75055--- a/lib/random32.c
75056+++ b/lib/random32.c
75057@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *state)
75058 */
75059 static inline u32 __seed(u32 x, u32 m)
75060 {
75061- return (x < m) ? x + m : x;
75062+ return (x <= m) ? x + m + 1 : x;
75063 }
75064
75065 /**
75066diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75067index 33bed5e..1477e46 100644
75068--- a/lib/vsprintf.c
75069+++ b/lib/vsprintf.c
75070@@ -16,6 +16,9 @@
75071 * - scnprintf and vscnprintf
75072 */
75073
75074+#ifdef CONFIG_GRKERNSEC_HIDESYM
75075+#define __INCLUDED_BY_HIDESYM 1
75076+#endif
75077 #include <stdarg.h>
75078 #include <linux/module.h>
75079 #include <linux/types.h>
75080@@ -546,12 +549,12 @@ static char *number(char *buf, char *end, unsigned long long num,
75081 return buf;
75082 }
75083
75084-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
75085+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
75086 {
75087 int len, i;
75088
75089 if ((unsigned long)s < PAGE_SIZE)
75090- s = "<NULL>";
75091+ s = "(null)";
75092
75093 len = strnlen(s, spec.precision);
75094
75095@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, char *end, void *ptr,
75096 unsigned long value = (unsigned long) ptr;
75097 #ifdef CONFIG_KALLSYMS
75098 char sym[KSYM_SYMBOL_LEN];
75099- if (ext != 'f' && ext != 's')
75100+ if (ext != 'f' && ext != 's' && ext != 'a')
75101 sprint_symbol(sym, value);
75102 else
75103 kallsyms_lookup(value, NULL, NULL, NULL, sym);
75104@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
75105 * - 'f' For simple symbolic function names without offset
75106 * - 'S' For symbolic direct pointers with offset
75107 * - 's' For symbolic direct pointers without offset
75108+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75109+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75110 * - 'R' For a struct resource pointer, it prints the range of
75111 * addresses (not the name nor the flags)
75112 * - 'M' For a 6-byte MAC address, it prints the address in the
75113@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75114 struct printf_spec spec)
75115 {
75116 if (!ptr)
75117- return string(buf, end, "(null)", spec);
75118+ return string(buf, end, "(nil)", spec);
75119
75120 switch (*fmt) {
75121 case 'F':
75122@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75123 case 's':
75124 /* Fallthrough */
75125 case 'S':
75126+#ifdef CONFIG_GRKERNSEC_HIDESYM
75127+ break;
75128+#else
75129+ return symbol_string(buf, end, ptr, spec, *fmt);
75130+#endif
75131+ case 'a':
75132+ /* Fallthrough */
75133+ case 'A':
75134 return symbol_string(buf, end, ptr, spec, *fmt);
75135 case 'R':
75136 return resource_string(buf, end, ptr, spec);
75137@@ -1445,7 +1458,7 @@ do { \
75138 size_t len;
75139 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
75140 || (unsigned long)save_str < PAGE_SIZE)
75141- save_str = "<NULL>";
75142+ save_str = "(null)";
75143 len = strlen(save_str);
75144 if (str + len + 1 < end)
75145 memcpy(str, save_str, len + 1);
75146@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75147 typeof(type) value; \
75148 if (sizeof(type) == 8) { \
75149 args = PTR_ALIGN(args, sizeof(u32)); \
75150- *(u32 *)&value = *(u32 *)args; \
75151- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75152+ *(u32 *)&value = *(const u32 *)args; \
75153+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75154 } else { \
75155 args = PTR_ALIGN(args, sizeof(type)); \
75156- value = *(typeof(type) *)args; \
75157+ value = *(const typeof(type) *)args; \
75158 } \
75159 args += sizeof(type); \
75160 value; \
75161@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75162 const char *str_arg = args;
75163 size_t len = strlen(str_arg);
75164 args += len + 1;
75165- str = string(str, end, (char *)str_arg, spec);
75166+ str = string(str, end, str_arg, spec);
75167 break;
75168 }
75169
75170diff --git a/localversion-grsec b/localversion-grsec
75171new file mode 100644
75172index 0000000..7cd6065
75173--- /dev/null
75174+++ b/localversion-grsec
75175@@ -0,0 +1 @@
75176+-grsec
75177diff --git a/mm/Kconfig b/mm/Kconfig
75178index 2c19c0b..f3c3f83 100644
75179--- a/mm/Kconfig
75180+++ b/mm/Kconfig
75181@@ -228,7 +228,7 @@ config KSM
75182 config DEFAULT_MMAP_MIN_ADDR
75183 int "Low address space to protect from user allocation"
75184 depends on MMU
75185- default 4096
75186+ default 65536
75187 help
75188 This is the portion of low virtual memory which should be protected
75189 from userspace allocation. Keeping a user from writing to low pages
75190diff --git a/mm/backing-dev.c b/mm/backing-dev.c
75191index 67a33a5..094dcf1 100644
75192--- a/mm/backing-dev.c
75193+++ b/mm/backing-dev.c
75194@@ -272,7 +272,7 @@ static void bdi_task_init(struct backing_dev_info *bdi,
75195 list_add_tail_rcu(&wb->list, &bdi->wb_list);
75196 spin_unlock(&bdi->wb_lock);
75197
75198- tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
75199+ tsk->flags |= PF_SWAPWRITE;
75200 set_freezable();
75201
75202 /*
75203@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rcu_head *head)
75204 * Add the default flusher task that gets created for any bdi
75205 * that has dirty data pending writeout
75206 */
75207-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75208+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75209 {
75210 if (!bdi_cap_writeback_dirty(bdi))
75211 return;
75212diff --git a/mm/filemap.c b/mm/filemap.c
75213index 9e0826e..4ee8f13 100644
75214--- a/mm/filemap.c
75215+++ b/mm/filemap.c
75216@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75217 struct address_space *mapping = file->f_mapping;
75218
75219 if (!mapping->a_ops->readpage)
75220- return -ENOEXEC;
75221+ return -ENODEV;
75222 file_accessed(file);
75223 vma->vm_ops = &generic_file_vm_ops;
75224 vma->vm_flags |= VM_CAN_NONLINEAR;
75225@@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75226 *pos = i_size_read(inode);
75227
75228 if (limit != RLIM_INFINITY) {
75229+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75230 if (*pos >= limit) {
75231 send_sig(SIGXFSZ, current, 0);
75232 return -EFBIG;
75233diff --git a/mm/fremap.c b/mm/fremap.c
75234index b6ec85a..a24ac22 100644
75235--- a/mm/fremap.c
75236+++ b/mm/fremap.c
75237@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75238 retry:
75239 vma = find_vma(mm, start);
75240
75241+#ifdef CONFIG_PAX_SEGMEXEC
75242+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75243+ goto out;
75244+#endif
75245+
75246 /*
75247 * Make sure the vma is shared, that it supports prefaulting,
75248 * and that the remapped range is valid and fully within
75249@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75250 /*
75251 * drop PG_Mlocked flag for over-mapped range
75252 */
75253- unsigned int saved_flags = vma->vm_flags;
75254+ unsigned long saved_flags = vma->vm_flags;
75255 munlock_vma_pages_range(vma, start, start + size);
75256 vma->vm_flags = saved_flags;
75257 }
75258diff --git a/mm/highmem.c b/mm/highmem.c
75259index 9c1e627..5ca9447 100644
75260--- a/mm/highmem.c
75261+++ b/mm/highmem.c
75262@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
75263 * So no dangers, even with speculative execution.
75264 */
75265 page = pte_page(pkmap_page_table[i]);
75266+ pax_open_kernel();
75267 pte_clear(&init_mm, (unsigned long)page_address(page),
75268 &pkmap_page_table[i]);
75269-
75270+ pax_close_kernel();
75271 set_page_address(page, NULL);
75272 need_flush = 1;
75273 }
75274@@ -177,9 +178,11 @@ start:
75275 }
75276 }
75277 vaddr = PKMAP_ADDR(last_pkmap_nr);
75278+
75279+ pax_open_kernel();
75280 set_pte_at(&init_mm, vaddr,
75281 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75282-
75283+ pax_close_kernel();
75284 pkmap_count[last_pkmap_nr] = 1;
75285 set_page_address(page, (void *)vaddr);
75286
75287diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75288index 5e1e508..9f0ebad 100644
75289--- a/mm/hugetlb.c
75290+++ b/mm/hugetlb.c
75291@@ -1933,6 +1933,26 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75292 return 1;
75293 }
75294
75295+#ifdef CONFIG_PAX_SEGMEXEC
75296+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75297+{
75298+ struct mm_struct *mm = vma->vm_mm;
75299+ struct vm_area_struct *vma_m;
75300+ unsigned long address_m;
75301+ pte_t *ptep_m;
75302+
75303+ vma_m = pax_find_mirror_vma(vma);
75304+ if (!vma_m)
75305+ return;
75306+
75307+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75308+ address_m = address + SEGMEXEC_TASK_SIZE;
75309+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75310+ get_page(page_m);
75311+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75312+}
75313+#endif
75314+
75315 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
75316 unsigned long address, pte_t *ptep, pte_t pte,
75317 struct page *pagecache_page)
75318@@ -2004,6 +2024,11 @@ retry_avoidcopy:
75319 huge_ptep_clear_flush(vma, address, ptep);
75320 set_huge_pte_at(mm, address, ptep,
75321 make_huge_pte(vma, new_page, 1));
75322+
75323+#ifdef CONFIG_PAX_SEGMEXEC
75324+ pax_mirror_huge_pte(vma, address, new_page);
75325+#endif
75326+
75327 /* Make the old page be freed below */
75328 new_page = old_page;
75329 }
75330@@ -2135,6 +2160,10 @@ retry:
75331 && (vma->vm_flags & VM_SHARED)));
75332 set_huge_pte_at(mm, address, ptep, new_pte);
75333
75334+#ifdef CONFIG_PAX_SEGMEXEC
75335+ pax_mirror_huge_pte(vma, address, page);
75336+#endif
75337+
75338 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75339 /* Optimization, do the COW without a second fault */
75340 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75341@@ -2163,6 +2192,28 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75342 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75343 struct hstate *h = hstate_vma(vma);
75344
75345+#ifdef CONFIG_PAX_SEGMEXEC
75346+ struct vm_area_struct *vma_m;
75347+
75348+ vma_m = pax_find_mirror_vma(vma);
75349+ if (vma_m) {
75350+ unsigned long address_m;
75351+
75352+ if (vma->vm_start > vma_m->vm_start) {
75353+ address_m = address;
75354+ address -= SEGMEXEC_TASK_SIZE;
75355+ vma = vma_m;
75356+ h = hstate_vma(vma);
75357+ } else
75358+ address_m = address + SEGMEXEC_TASK_SIZE;
75359+
75360+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75361+ return VM_FAULT_OOM;
75362+ address_m &= HPAGE_MASK;
75363+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75364+ }
75365+#endif
75366+
75367 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75368 if (!ptep)
75369 return VM_FAULT_OOM;
75370diff --git a/mm/internal.h b/mm/internal.h
75371index f03e8e2..7354343 100644
75372--- a/mm/internal.h
75373+++ b/mm/internal.h
75374@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page *page);
75375 * in mm/page_alloc.c
75376 */
75377 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75378+extern void free_compound_page(struct page *page);
75379 extern void prep_compound_page(struct page *page, unsigned long order);
75380
75381
75382diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75383index c346660..b47382f 100644
75384--- a/mm/kmemleak.c
75385+++ b/mm/kmemleak.c
75386@@ -358,7 +358,7 @@ static void print_unreferenced(struct seq_file *seq,
75387
75388 for (i = 0; i < object->trace_len; i++) {
75389 void *ptr = (void *)object->trace[i];
75390- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75391+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
75392 }
75393 }
75394
75395diff --git a/mm/maccess.c b/mm/maccess.c
75396index 9073695..1127f348 100644
75397--- a/mm/maccess.c
75398+++ b/mm/maccess.c
75399@@ -14,7 +14,7 @@
75400 * Safely read from address @src to the buffer at @dst. If a kernel fault
75401 * happens, handle that and return -EFAULT.
75402 */
75403-long probe_kernel_read(void *dst, void *src, size_t size)
75404+long probe_kernel_read(void *dst, const void *src, size_t size)
75405 {
75406 long ret;
75407 mm_segment_t old_fs = get_fs();
75408@@ -22,7 +22,7 @@ long probe_kernel_read(void *dst, void *src, size_t size)
75409 set_fs(KERNEL_DS);
75410 pagefault_disable();
75411 ret = __copy_from_user_inatomic(dst,
75412- (__force const void __user *)src, size);
75413+ (const void __force_user *)src, size);
75414 pagefault_enable();
75415 set_fs(old_fs);
75416
75417@@ -39,14 +39,14 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
75418 * Safely write to address @dst from the buffer at @src. If a kernel fault
75419 * happens, handle that and return -EFAULT.
75420 */
75421-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
75422+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
75423 {
75424 long ret;
75425 mm_segment_t old_fs = get_fs();
75426
75427 set_fs(KERNEL_DS);
75428 pagefault_disable();
75429- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75430+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75431 pagefault_enable();
75432 set_fs(old_fs);
75433
75434diff --git a/mm/madvise.c b/mm/madvise.c
75435index 35b1479..499f7d4 100644
75436--- a/mm/madvise.c
75437+++ b/mm/madvise.c
75438@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75439 pgoff_t pgoff;
75440 unsigned long new_flags = vma->vm_flags;
75441
75442+#ifdef CONFIG_PAX_SEGMEXEC
75443+ struct vm_area_struct *vma_m;
75444+#endif
75445+
75446 switch (behavior) {
75447 case MADV_NORMAL:
75448 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75449@@ -103,6 +107,13 @@ success:
75450 /*
75451 * vm_flags is protected by the mmap_sem held in write mode.
75452 */
75453+
75454+#ifdef CONFIG_PAX_SEGMEXEC
75455+ vma_m = pax_find_mirror_vma(vma);
75456+ if (vma_m)
75457+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75458+#endif
75459+
75460 vma->vm_flags = new_flags;
75461
75462 out:
75463@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75464 struct vm_area_struct ** prev,
75465 unsigned long start, unsigned long end)
75466 {
75467+
75468+#ifdef CONFIG_PAX_SEGMEXEC
75469+ struct vm_area_struct *vma_m;
75470+#endif
75471+
75472 *prev = vma;
75473 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75474 return -EINVAL;
75475@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75476 zap_page_range(vma, start, end - start, &details);
75477 } else
75478 zap_page_range(vma, start, end - start, NULL);
75479+
75480+#ifdef CONFIG_PAX_SEGMEXEC
75481+ vma_m = pax_find_mirror_vma(vma);
75482+ if (vma_m) {
75483+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75484+ struct zap_details details = {
75485+ .nonlinear_vma = vma_m,
75486+ .last_index = ULONG_MAX,
75487+ };
75488+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75489+ } else
75490+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75491+ }
75492+#endif
75493+
75494 return 0;
75495 }
75496
75497@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75498 if (end < start)
75499 goto out;
75500
75501+#ifdef CONFIG_PAX_SEGMEXEC
75502+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75503+ if (end > SEGMEXEC_TASK_SIZE)
75504+ goto out;
75505+ } else
75506+#endif
75507+
75508+ if (end > TASK_SIZE)
75509+ goto out;
75510+
75511 error = 0;
75512 if (end == start)
75513 goto out;
75514diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75515index 8aeba53..b4a4198 100644
75516--- a/mm/memory-failure.c
75517+++ b/mm/memory-failure.c
75518@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75519
75520 int sysctl_memory_failure_recovery __read_mostly = 1;
75521
75522-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75523+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75524
75525 /*
75526 * Send all the processes who have the page mapped an ``action optional''
75527@@ -64,7 +64,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
75528 si.si_signo = SIGBUS;
75529 si.si_errno = 0;
75530 si.si_code = BUS_MCEERR_AO;
75531- si.si_addr = (void *)addr;
75532+ si.si_addr = (void __user *)addr;
75533 #ifdef __ARCH_SI_TRAPNO
75534 si.si_trapno = trapno;
75535 #endif
75536@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref)
75537 return 0;
75538 }
75539
75540- atomic_long_add(1, &mce_bad_pages);
75541+ atomic_long_add_unchecked(1, &mce_bad_pages);
75542
75543 /*
75544 * We need/can do nothing about count=0 pages.
75545diff --git a/mm/memory.c b/mm/memory.c
75546index 6c836d3..48f3264 100644
75547--- a/mm/memory.c
75548+++ b/mm/memory.c
75549@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75550 return;
75551
75552 pmd = pmd_offset(pud, start);
75553+
75554+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75555 pud_clear(pud);
75556 pmd_free_tlb(tlb, pmd, start);
75557+#endif
75558+
75559 }
75560
75561 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75562@@ -219,9 +223,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75563 if (end - 1 > ceiling - 1)
75564 return;
75565
75566+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75567 pud = pud_offset(pgd, start);
75568 pgd_clear(pgd);
75569 pud_free_tlb(tlb, pud, start);
75570+#endif
75571+
75572 }
75573
75574 /*
75575@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75576 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
75577 i = 0;
75578
75579- do {
75580+ while (nr_pages) {
75581 struct vm_area_struct *vma;
75582
75583- vma = find_extend_vma(mm, start);
75584+ vma = find_vma(mm, start);
75585 if (!vma && in_gate_area(tsk, start)) {
75586 unsigned long pg = start & PAGE_MASK;
75587 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
75588@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75589 continue;
75590 }
75591
75592- if (!vma ||
75593+ if (!vma || start < vma->vm_start ||
75594 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75595 !(vm_flags & vma->vm_flags))
75596 return i ? : -EFAULT;
75597@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75598 start += PAGE_SIZE;
75599 nr_pages--;
75600 } while (nr_pages && start < vma->vm_end);
75601- } while (nr_pages);
75602+ }
75603 return i;
75604 }
75605
75606@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75607 page_add_file_rmap(page);
75608 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75609
75610+#ifdef CONFIG_PAX_SEGMEXEC
75611+ pax_mirror_file_pte(vma, addr, page, ptl);
75612+#endif
75613+
75614 retval = 0;
75615 pte_unmap_unlock(pte, ptl);
75616 return retval;
75617@@ -1560,10 +1571,22 @@ out:
75618 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75619 struct page *page)
75620 {
75621+
75622+#ifdef CONFIG_PAX_SEGMEXEC
75623+ struct vm_area_struct *vma_m;
75624+#endif
75625+
75626 if (addr < vma->vm_start || addr >= vma->vm_end)
75627 return -EFAULT;
75628 if (!page_count(page))
75629 return -EINVAL;
75630+
75631+#ifdef CONFIG_PAX_SEGMEXEC
75632+ vma_m = pax_find_mirror_vma(vma);
75633+ if (vma_m)
75634+ vma_m->vm_flags |= VM_INSERTPAGE;
75635+#endif
75636+
75637 vma->vm_flags |= VM_INSERTPAGE;
75638 return insert_page(vma, addr, page, vma->vm_page_prot);
75639 }
75640@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75641 unsigned long pfn)
75642 {
75643 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75644+ BUG_ON(vma->vm_mirror);
75645
75646 if (addr < vma->vm_start || addr >= vma->vm_end)
75647 return -EFAULT;
75648@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75649 copy_user_highpage(dst, src, va, vma);
75650 }
75651
75652+#ifdef CONFIG_PAX_SEGMEXEC
75653+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75654+{
75655+ struct mm_struct *mm = vma->vm_mm;
75656+ spinlock_t *ptl;
75657+ pte_t *pte, entry;
75658+
75659+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75660+ entry = *pte;
75661+ if (!pte_present(entry)) {
75662+ if (!pte_none(entry)) {
75663+ BUG_ON(pte_file(entry));
75664+ free_swap_and_cache(pte_to_swp_entry(entry));
75665+ pte_clear_not_present_full(mm, address, pte, 0);
75666+ }
75667+ } else {
75668+ struct page *page;
75669+
75670+ flush_cache_page(vma, address, pte_pfn(entry));
75671+ entry = ptep_clear_flush(vma, address, pte);
75672+ BUG_ON(pte_dirty(entry));
75673+ page = vm_normal_page(vma, address, entry);
75674+ if (page) {
75675+ update_hiwater_rss(mm);
75676+ if (PageAnon(page))
75677+ dec_mm_counter(mm, anon_rss);
75678+ else
75679+ dec_mm_counter(mm, file_rss);
75680+ page_remove_rmap(page);
75681+ page_cache_release(page);
75682+ }
75683+ }
75684+ pte_unmap_unlock(pte, ptl);
75685+}
75686+
75687+/* PaX: if vma is mirrored, synchronize the mirror's PTE
75688+ *
75689+ * the ptl of the lower mapped page is held on entry and is not released on exit
75690+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75691+ */
75692+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75693+{
75694+ struct mm_struct *mm = vma->vm_mm;
75695+ unsigned long address_m;
75696+ spinlock_t *ptl_m;
75697+ struct vm_area_struct *vma_m;
75698+ pmd_t *pmd_m;
75699+ pte_t *pte_m, entry_m;
75700+
75701+ BUG_ON(!page_m || !PageAnon(page_m));
75702+
75703+ vma_m = pax_find_mirror_vma(vma);
75704+ if (!vma_m)
75705+ return;
75706+
75707+ BUG_ON(!PageLocked(page_m));
75708+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75709+ address_m = address + SEGMEXEC_TASK_SIZE;
75710+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75711+ pte_m = pte_offset_map_nested(pmd_m, address_m);
75712+ ptl_m = pte_lockptr(mm, pmd_m);
75713+ if (ptl != ptl_m) {
75714+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75715+ if (!pte_none(*pte_m))
75716+ goto out;
75717+ }
75718+
75719+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75720+ page_cache_get(page_m);
75721+ page_add_anon_rmap(page_m, vma_m, address_m);
75722+ inc_mm_counter(mm, anon_rss);
75723+ set_pte_at(mm, address_m, pte_m, entry_m);
75724+ update_mmu_cache(vma_m, address_m, entry_m);
75725+out:
75726+ if (ptl != ptl_m)
75727+ spin_unlock(ptl_m);
75728+ pte_unmap_nested(pte_m);
75729+ unlock_page(page_m);
75730+}
75731+
75732+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75733+{
75734+ struct mm_struct *mm = vma->vm_mm;
75735+ unsigned long address_m;
75736+ spinlock_t *ptl_m;
75737+ struct vm_area_struct *vma_m;
75738+ pmd_t *pmd_m;
75739+ pte_t *pte_m, entry_m;
75740+
75741+ BUG_ON(!page_m || PageAnon(page_m));
75742+
75743+ vma_m = pax_find_mirror_vma(vma);
75744+ if (!vma_m)
75745+ return;
75746+
75747+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75748+ address_m = address + SEGMEXEC_TASK_SIZE;
75749+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75750+ pte_m = pte_offset_map_nested(pmd_m, address_m);
75751+ ptl_m = pte_lockptr(mm, pmd_m);
75752+ if (ptl != ptl_m) {
75753+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75754+ if (!pte_none(*pte_m))
75755+ goto out;
75756+ }
75757+
75758+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75759+ page_cache_get(page_m);
75760+ page_add_file_rmap(page_m);
75761+ inc_mm_counter(mm, file_rss);
75762+ set_pte_at(mm, address_m, pte_m, entry_m);
75763+ update_mmu_cache(vma_m, address_m, entry_m);
75764+out:
75765+ if (ptl != ptl_m)
75766+ spin_unlock(ptl_m);
75767+ pte_unmap_nested(pte_m);
75768+}
75769+
75770+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75771+{
75772+ struct mm_struct *mm = vma->vm_mm;
75773+ unsigned long address_m;
75774+ spinlock_t *ptl_m;
75775+ struct vm_area_struct *vma_m;
75776+ pmd_t *pmd_m;
75777+ pte_t *pte_m, entry_m;
75778+
75779+ vma_m = pax_find_mirror_vma(vma);
75780+ if (!vma_m)
75781+ return;
75782+
75783+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75784+ address_m = address + SEGMEXEC_TASK_SIZE;
75785+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75786+ pte_m = pte_offset_map_nested(pmd_m, address_m);
75787+ ptl_m = pte_lockptr(mm, pmd_m);
75788+ if (ptl != ptl_m) {
75789+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75790+ if (!pte_none(*pte_m))
75791+ goto out;
75792+ }
75793+
75794+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75795+ set_pte_at(mm, address_m, pte_m, entry_m);
75796+out:
75797+ if (ptl != ptl_m)
75798+ spin_unlock(ptl_m);
75799+ pte_unmap_nested(pte_m);
75800+}
75801+
75802+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75803+{
75804+ struct page *page_m;
75805+ pte_t entry;
75806+
75807+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75808+ goto out;
75809+
75810+ entry = *pte;
75811+ page_m = vm_normal_page(vma, address, entry);
75812+ if (!page_m)
75813+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
75814+ else if (PageAnon(page_m)) {
75815+ if (pax_find_mirror_vma(vma)) {
75816+ pte_unmap_unlock(pte, ptl);
75817+ lock_page(page_m);
75818+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
75819+ if (pte_same(entry, *pte))
75820+ pax_mirror_anon_pte(vma, address, page_m, ptl);
75821+ else
75822+ unlock_page(page_m);
75823+ }
75824+ } else
75825+ pax_mirror_file_pte(vma, address, page_m, ptl);
75826+
75827+out:
75828+ pte_unmap_unlock(pte, ptl);
75829+}
75830+#endif
75831+
75832 /*
75833 * This routine handles present pages, when users try to write
75834 * to a shared page. It is done by copying the page to a new address
75835@@ -2156,6 +2360,12 @@ gotten:
75836 */
75837 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75838 if (likely(pte_same(*page_table, orig_pte))) {
75839+
75840+#ifdef CONFIG_PAX_SEGMEXEC
75841+ if (pax_find_mirror_vma(vma))
75842+ BUG_ON(!trylock_page(new_page));
75843+#endif
75844+
75845 if (old_page) {
75846 if (!PageAnon(old_page)) {
75847 dec_mm_counter(mm, file_rss);
75848@@ -2207,6 +2417,10 @@ gotten:
75849 page_remove_rmap(old_page);
75850 }
75851
75852+#ifdef CONFIG_PAX_SEGMEXEC
75853+ pax_mirror_anon_pte(vma, address, new_page, ptl);
75854+#endif
75855+
75856 /* Free the old page.. */
75857 new_page = old_page;
75858 ret |= VM_FAULT_WRITE;
75859@@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75860 swap_free(entry);
75861 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
75862 try_to_free_swap(page);
75863+
75864+#ifdef CONFIG_PAX_SEGMEXEC
75865+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
75866+#endif
75867+
75868 unlock_page(page);
75869
75870 if (flags & FAULT_FLAG_WRITE) {
75871@@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75872
75873 /* No need to invalidate - it was non-present before */
75874 update_mmu_cache(vma, address, pte);
75875+
75876+#ifdef CONFIG_PAX_SEGMEXEC
75877+ pax_mirror_anon_pte(vma, address, page, ptl);
75878+#endif
75879+
75880 unlock:
75881 pte_unmap_unlock(page_table, ptl);
75882 out:
75883@@ -2632,40 +2856,6 @@ out_release:
75884 }
75885
75886 /*
75887- * This is like a special single-page "expand_{down|up}wards()",
75888- * except we must first make sure that 'address{-|+}PAGE_SIZE'
75889- * doesn't hit another vma.
75890- */
75891-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
75892-{
75893- address &= PAGE_MASK;
75894- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
75895- struct vm_area_struct *prev = vma->vm_prev;
75896-
75897- /*
75898- * Is there a mapping abutting this one below?
75899- *
75900- * That's only ok if it's the same stack mapping
75901- * that has gotten split..
75902- */
75903- if (prev && prev->vm_end == address)
75904- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
75905-
75906- expand_stack(vma, address - PAGE_SIZE);
75907- }
75908- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
75909- struct vm_area_struct *next = vma->vm_next;
75910-
75911- /* As VM_GROWSDOWN but s/below/above/ */
75912- if (next && next->vm_start == address + PAGE_SIZE)
75913- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
75914-
75915- expand_upwards(vma, address + PAGE_SIZE);
75916- }
75917- return 0;
75918-}
75919-
75920-/*
75921 * We enter with non-exclusive mmap_sem (to exclude vma changes,
75922 * but allow concurrent faults), and pte mapped but not yet locked.
75923 * We return with mmap_sem still held, but pte unmapped and unlocked.
75924@@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75925 unsigned long address, pte_t *page_table, pmd_t *pmd,
75926 unsigned int flags)
75927 {
75928- struct page *page;
75929+ struct page *page = NULL;
75930 spinlock_t *ptl;
75931 pte_t entry;
75932
75933- pte_unmap(page_table);
75934-
75935- /* Check if we need to add a guard page to the stack */
75936- if (check_stack_guard_page(vma, address) < 0)
75937- return VM_FAULT_SIGBUS;
75938-
75939- /* Use the zero-page for reads */
75940 if (!(flags & FAULT_FLAG_WRITE)) {
75941 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
75942 vma->vm_page_prot));
75943- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75944+ ptl = pte_lockptr(mm, pmd);
75945+ spin_lock(ptl);
75946 if (!pte_none(*page_table))
75947 goto unlock;
75948 goto setpte;
75949 }
75950
75951 /* Allocate our own private page. */
75952+ pte_unmap(page_table);
75953+
75954 if (unlikely(anon_vma_prepare(vma)))
75955 goto oom;
75956 page = alloc_zeroed_user_highpage_movable(vma, address);
75957@@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75958 if (!pte_none(*page_table))
75959 goto release;
75960
75961+#ifdef CONFIG_PAX_SEGMEXEC
75962+ if (pax_find_mirror_vma(vma))
75963+ BUG_ON(!trylock_page(page));
75964+#endif
75965+
75966 inc_mm_counter(mm, anon_rss);
75967 page_add_new_anon_rmap(page, vma, address);
75968 setpte:
75969@@ -2720,6 +2911,12 @@ setpte:
75970
75971 /* No need to invalidate - it was non-present before */
75972 update_mmu_cache(vma, address, entry);
75973+
75974+#ifdef CONFIG_PAX_SEGMEXEC
75975+ if (page)
75976+ pax_mirror_anon_pte(vma, address, page, ptl);
75977+#endif
75978+
75979 unlock:
75980 pte_unmap_unlock(page_table, ptl);
75981 return 0;
75982@@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75983 */
75984 /* Only go through if we didn't race with anybody else... */
75985 if (likely(pte_same(*page_table, orig_pte))) {
75986+
75987+#ifdef CONFIG_PAX_SEGMEXEC
75988+ if (anon && pax_find_mirror_vma(vma))
75989+ BUG_ON(!trylock_page(page));
75990+#endif
75991+
75992 flush_icache_page(vma, page);
75993 entry = mk_pte(page, vma->vm_page_prot);
75994 if (flags & FAULT_FLAG_WRITE)
75995@@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75996
75997 /* no need to invalidate: a not-present page won't be cached */
75998 update_mmu_cache(vma, address, entry);
75999+
76000+#ifdef CONFIG_PAX_SEGMEXEC
76001+ if (anon)
76002+ pax_mirror_anon_pte(vma, address, page, ptl);
76003+ else
76004+ pax_mirror_file_pte(vma, address, page, ptl);
76005+#endif
76006+
76007 } else {
76008 if (charged)
76009 mem_cgroup_uncharge_page(page);
76010@@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struct mm_struct *mm,
76011 if (flags & FAULT_FLAG_WRITE)
76012 flush_tlb_page(vma, address);
76013 }
76014+
76015+#ifdef CONFIG_PAX_SEGMEXEC
76016+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76017+ return 0;
76018+#endif
76019+
76020 unlock:
76021 pte_unmap_unlock(pte, ptl);
76022 return 0;
76023@@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76024 pmd_t *pmd;
76025 pte_t *pte;
76026
76027+#ifdef CONFIG_PAX_SEGMEXEC
76028+ struct vm_area_struct *vma_m;
76029+#endif
76030+
76031 __set_current_state(TASK_RUNNING);
76032
76033 count_vm_event(PGFAULT);
76034@@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76035 if (unlikely(is_vm_hugetlb_page(vma)))
76036 return hugetlb_fault(mm, vma, address, flags);
76037
76038+#ifdef CONFIG_PAX_SEGMEXEC
76039+ vma_m = pax_find_mirror_vma(vma);
76040+ if (vma_m) {
76041+ unsigned long address_m;
76042+ pgd_t *pgd_m;
76043+ pud_t *pud_m;
76044+ pmd_t *pmd_m;
76045+
76046+ if (vma->vm_start > vma_m->vm_start) {
76047+ address_m = address;
76048+ address -= SEGMEXEC_TASK_SIZE;
76049+ vma = vma_m;
76050+ } else
76051+ address_m = address + SEGMEXEC_TASK_SIZE;
76052+
76053+ pgd_m = pgd_offset(mm, address_m);
76054+ pud_m = pud_alloc(mm, pgd_m, address_m);
76055+ if (!pud_m)
76056+ return VM_FAULT_OOM;
76057+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76058+ if (!pmd_m)
76059+ return VM_FAULT_OOM;
76060+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
76061+ return VM_FAULT_OOM;
76062+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76063+ }
76064+#endif
76065+
76066 pgd = pgd_offset(mm, address);
76067 pud = pud_alloc(mm, pgd, address);
76068 if (!pud)
76069@@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
76070 gate_vma.vm_start = FIXADDR_USER_START;
76071 gate_vma.vm_end = FIXADDR_USER_END;
76072 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76073- gate_vma.vm_page_prot = __P101;
76074+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76075 /*
76076 * Make sure the vDSO gets into every core dump.
76077 * Dumping its contents makes post-mortem fully interpretable later
76078diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76079index 3c6e3e2..ad9871c 100644
76080--- a/mm/mempolicy.c
76081+++ b/mm/mempolicy.c
76082@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76083 struct vm_area_struct *next;
76084 int err;
76085
76086+#ifdef CONFIG_PAX_SEGMEXEC
76087+ struct vm_area_struct *vma_m;
76088+#endif
76089+
76090 err = 0;
76091 for (; vma && vma->vm_start < end; vma = next) {
76092 next = vma->vm_next;
76093@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76094 err = policy_vma(vma, new);
76095 if (err)
76096 break;
76097+
76098+#ifdef CONFIG_PAX_SEGMEXEC
76099+ vma_m = pax_find_mirror_vma(vma);
76100+ if (vma_m) {
76101+ err = policy_vma(vma_m, new);
76102+ if (err)
76103+ break;
76104+ }
76105+#endif
76106+
76107 }
76108 return err;
76109 }
76110@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76111
76112 if (end < start)
76113 return -EINVAL;
76114+
76115+#ifdef CONFIG_PAX_SEGMEXEC
76116+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76117+ if (end > SEGMEXEC_TASK_SIZE)
76118+ return -EINVAL;
76119+ } else
76120+#endif
76121+
76122+ if (end > TASK_SIZE)
76123+ return -EINVAL;
76124+
76125 if (end == start)
76126 return 0;
76127
76128@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76129 if (!mm)
76130 return -EINVAL;
76131
76132+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76133+ if (mm != current->mm &&
76134+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76135+ err = -EPERM;
76136+ goto out;
76137+ }
76138+#endif
76139+
76140 /*
76141 * Check if this process has the right to modify the specified
76142 * process. The right exists if the process has administrative
76143@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76144 rcu_read_lock();
76145 tcred = __task_cred(task);
76146 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76147- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76148- !capable(CAP_SYS_NICE)) {
76149+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76150 rcu_read_unlock();
76151 err = -EPERM;
76152 goto out;
76153@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, void *v)
76154
76155 if (file) {
76156 seq_printf(m, " file=");
76157- seq_path(m, &file->f_path, "\n\t= ");
76158+ seq_path(m, &file->f_path, "\n\t\\= ");
76159 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
76160 seq_printf(m, " heap");
76161 } else if (vma->vm_start <= mm->start_stack &&
76162diff --git a/mm/migrate.c b/mm/migrate.c
76163index aaca868..2ebecdc 100644
76164--- a/mm/migrate.c
76165+++ b/mm/migrate.c
76166@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
76167 unsigned long chunk_start;
76168 int err;
76169
76170+ pax_track_stack();
76171+
76172 task_nodes = cpuset_mems_allowed(task);
76173
76174 err = -ENOMEM;
76175@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76176 if (!mm)
76177 return -EINVAL;
76178
76179+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76180+ if (mm != current->mm &&
76181+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76182+ err = -EPERM;
76183+ goto out;
76184+ }
76185+#endif
76186+
76187 /*
76188 * Check if this process has the right to modify the specified
76189 * process. The right exists if the process has administrative
76190@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76191 rcu_read_lock();
76192 tcred = __task_cred(task);
76193 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76194- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76195- !capable(CAP_SYS_NICE)) {
76196+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76197 rcu_read_unlock();
76198 err = -EPERM;
76199 goto out;
76200diff --git a/mm/mlock.c b/mm/mlock.c
76201index 2d846cf..98134d2 100644
76202--- a/mm/mlock.c
76203+++ b/mm/mlock.c
76204@@ -13,6 +13,7 @@
76205 #include <linux/pagemap.h>
76206 #include <linux/mempolicy.h>
76207 #include <linux/syscalls.h>
76208+#include <linux/security.h>
76209 #include <linux/sched.h>
76210 #include <linux/module.h>
76211 #include <linux/rmap.h>
76212@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
76213 }
76214 }
76215
76216-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
76217-{
76218- return (vma->vm_flags & VM_GROWSDOWN) &&
76219- (vma->vm_start == addr) &&
76220- !vma_stack_continue(vma->vm_prev, addr);
76221-}
76222-
76223 /**
76224 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
76225 * @vma: target vma
76226@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
76227 if (vma->vm_flags & VM_WRITE)
76228 gup_flags |= FOLL_WRITE;
76229
76230- /* We don't try to access the guard page of a stack vma */
76231- if (stack_guard_page(vma, start)) {
76232- addr += PAGE_SIZE;
76233- nr_pages--;
76234- }
76235-
76236 while (nr_pages > 0) {
76237 int i;
76238
76239@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76240 {
76241 unsigned long nstart, end, tmp;
76242 struct vm_area_struct * vma, * prev;
76243- int error;
76244+ int error = -EINVAL;
76245
76246 len = PAGE_ALIGN(len);
76247 end = start + len;
76248@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76249 return -EINVAL;
76250 if (end == start)
76251 return 0;
76252+ if (end > TASK_SIZE)
76253+ return -EINVAL;
76254+
76255 vma = find_vma_prev(current->mm, start, &prev);
76256 if (!vma || vma->vm_start > start)
76257 return -ENOMEM;
76258@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76259 for (nstart = start ; ; ) {
76260 unsigned int newflags;
76261
76262+#ifdef CONFIG_PAX_SEGMEXEC
76263+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76264+ break;
76265+#endif
76266+
76267 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76268
76269 newflags = vma->vm_flags | VM_LOCKED;
76270@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76271 lock_limit >>= PAGE_SHIFT;
76272
76273 /* check against resource limits */
76274+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76275 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76276 error = do_mlock(start, len, 1);
76277 up_write(&current->mm->mmap_sem);
76278@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
76279 static int do_mlockall(int flags)
76280 {
76281 struct vm_area_struct * vma, * prev = NULL;
76282- unsigned int def_flags = 0;
76283
76284 if (flags & MCL_FUTURE)
76285- def_flags = VM_LOCKED;
76286- current->mm->def_flags = def_flags;
76287+ current->mm->def_flags |= VM_LOCKED;
76288+ else
76289+ current->mm->def_flags &= ~VM_LOCKED;
76290 if (flags == MCL_FUTURE)
76291 goto out;
76292
76293 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76294- unsigned int newflags;
76295+ unsigned long newflags;
76296
76297+#ifdef CONFIG_PAX_SEGMEXEC
76298+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76299+ break;
76300+#endif
76301+
76302+ BUG_ON(vma->vm_end > TASK_SIZE);
76303 newflags = vma->vm_flags | VM_LOCKED;
76304 if (!(flags & MCL_CURRENT))
76305 newflags &= ~VM_LOCKED;
76306@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76307 lock_limit >>= PAGE_SHIFT;
76308
76309 ret = -ENOMEM;
76310+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76311 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76312 capable(CAP_IPC_LOCK))
76313 ret = do_mlockall(flags);
76314diff --git a/mm/mmap.c b/mm/mmap.c
76315index 4b80cbf..c5ce1df 100644
76316--- a/mm/mmap.c
76317+++ b/mm/mmap.c
76318@@ -45,6 +45,16 @@
76319 #define arch_rebalance_pgtables(addr, len) (addr)
76320 #endif
76321
76322+static inline void verify_mm_writelocked(struct mm_struct *mm)
76323+{
76324+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76325+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76326+ up_read(&mm->mmap_sem);
76327+ BUG();
76328+ }
76329+#endif
76330+}
76331+
76332 static void unmap_region(struct mm_struct *mm,
76333 struct vm_area_struct *vma, struct vm_area_struct *prev,
76334 unsigned long start, unsigned long end);
76335@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struct *mm,
76336 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76337 *
76338 */
76339-pgprot_t protection_map[16] = {
76340+pgprot_t protection_map[16] __read_only = {
76341 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76342 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76343 };
76344
76345 pgprot_t vm_get_page_prot(unsigned long vm_flags)
76346 {
76347- return __pgprot(pgprot_val(protection_map[vm_flags &
76348+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76349 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76350 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76351+
76352+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76353+ if (!nx_enabled &&
76354+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76355+ (vm_flags & (VM_READ | VM_WRITE)))
76356+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76357+#endif
76358+
76359+ return prot;
76360 }
76361 EXPORT_SYMBOL(vm_get_page_prot);
76362
76363 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76364 int sysctl_overcommit_ratio = 50; /* default is 50% */
76365 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76366+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76367 struct percpu_counter vm_committed_as;
76368
76369 /*
76370@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76371 struct vm_area_struct *next = vma->vm_next;
76372
76373 might_sleep();
76374+ BUG_ON(vma->vm_mirror);
76375 if (vma->vm_ops && vma->vm_ops->close)
76376 vma->vm_ops->close(vma);
76377 if (vma->vm_file) {
76378@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76379 * not page aligned -Ram Gupta
76380 */
76381 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
76382+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76383 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76384 (mm->end_data - mm->start_data) > rlim)
76385 goto out;
76386@@ -704,6 +726,12 @@ static int
76387 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76388 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76389 {
76390+
76391+#ifdef CONFIG_PAX_SEGMEXEC
76392+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76393+ return 0;
76394+#endif
76395+
76396 if (is_mergeable_vma(vma, file, vm_flags) &&
76397 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76398 if (vma->vm_pgoff == vm_pgoff)
76399@@ -723,6 +751,12 @@ static int
76400 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76401 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76402 {
76403+
76404+#ifdef CONFIG_PAX_SEGMEXEC
76405+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76406+ return 0;
76407+#endif
76408+
76409 if (is_mergeable_vma(vma, file, vm_flags) &&
76410 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76411 pgoff_t vm_pglen;
76412@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76413 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76414 struct vm_area_struct *prev, unsigned long addr,
76415 unsigned long end, unsigned long vm_flags,
76416- struct anon_vma *anon_vma, struct file *file,
76417+ struct anon_vma *anon_vma, struct file *file,
76418 pgoff_t pgoff, struct mempolicy *policy)
76419 {
76420 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76421 struct vm_area_struct *area, *next;
76422
76423+#ifdef CONFIG_PAX_SEGMEXEC
76424+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76425+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76426+
76427+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76428+#endif
76429+
76430 /*
76431 * We later require that vma->vm_flags == vm_flags,
76432 * so this tests vma->vm_flags & VM_SPECIAL, too.
76433@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76434 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76435 next = next->vm_next;
76436
76437+#ifdef CONFIG_PAX_SEGMEXEC
76438+ if (prev)
76439+ prev_m = pax_find_mirror_vma(prev);
76440+ if (area)
76441+ area_m = pax_find_mirror_vma(area);
76442+ if (next)
76443+ next_m = pax_find_mirror_vma(next);
76444+#endif
76445+
76446 /*
76447 * Can it merge with the predecessor?
76448 */
76449@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76450 /* cases 1, 6 */
76451 vma_adjust(prev, prev->vm_start,
76452 next->vm_end, prev->vm_pgoff, NULL);
76453- } else /* cases 2, 5, 7 */
76454+
76455+#ifdef CONFIG_PAX_SEGMEXEC
76456+ if (prev_m)
76457+ vma_adjust(prev_m, prev_m->vm_start,
76458+ next_m->vm_end, prev_m->vm_pgoff, NULL);
76459+#endif
76460+
76461+ } else { /* cases 2, 5, 7 */
76462 vma_adjust(prev, prev->vm_start,
76463 end, prev->vm_pgoff, NULL);
76464+
76465+#ifdef CONFIG_PAX_SEGMEXEC
76466+ if (prev_m)
76467+ vma_adjust(prev_m, prev_m->vm_start,
76468+ end_m, prev_m->vm_pgoff, NULL);
76469+#endif
76470+
76471+ }
76472 return prev;
76473 }
76474
76475@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76476 mpol_equal(policy, vma_policy(next)) &&
76477 can_vma_merge_before(next, vm_flags,
76478 anon_vma, file, pgoff+pglen)) {
76479- if (prev && addr < prev->vm_end) /* case 4 */
76480+ if (prev && addr < prev->vm_end) { /* case 4 */
76481 vma_adjust(prev, prev->vm_start,
76482 addr, prev->vm_pgoff, NULL);
76483- else /* cases 3, 8 */
76484+
76485+#ifdef CONFIG_PAX_SEGMEXEC
76486+ if (prev_m)
76487+ vma_adjust(prev_m, prev_m->vm_start,
76488+ addr_m, prev_m->vm_pgoff, NULL);
76489+#endif
76490+
76491+ } else { /* cases 3, 8 */
76492 vma_adjust(area, addr, next->vm_end,
76493 next->vm_pgoff - pglen, NULL);
76494+
76495+#ifdef CONFIG_PAX_SEGMEXEC
76496+ if (area_m)
76497+ vma_adjust(area_m, addr_m, next_m->vm_end,
76498+ next_m->vm_pgoff - pglen, NULL);
76499+#endif
76500+
76501+ }
76502 return area;
76503 }
76504
76505@@ -898,14 +978,11 @@ none:
76506 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76507 struct file *file, long pages)
76508 {
76509- const unsigned long stack_flags
76510- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76511-
76512 if (file) {
76513 mm->shared_vm += pages;
76514 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76515 mm->exec_vm += pages;
76516- } else if (flags & stack_flags)
76517+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76518 mm->stack_vm += pages;
76519 if (flags & (VM_RESERVED|VM_IO))
76520 mm->reserved_vm += pages;
76521@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76522 * (the exception is when the underlying filesystem is noexec
76523 * mounted, in which case we dont add PROT_EXEC.)
76524 */
76525- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76526+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76527 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76528 prot |= PROT_EXEC;
76529
76530@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76531 /* Obtain the address to map to. we verify (or select) it and ensure
76532 * that it represents a valid section of the address space.
76533 */
76534- addr = get_unmapped_area(file, addr, len, pgoff, flags);
76535+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76536 if (addr & ~PAGE_MASK)
76537 return addr;
76538
76539@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76540 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76541 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76542
76543+#ifdef CONFIG_PAX_MPROTECT
76544+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76545+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76546+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76547+ gr_log_rwxmmap(file);
76548+
76549+#ifdef CONFIG_PAX_EMUPLT
76550+ vm_flags &= ~VM_EXEC;
76551+#else
76552+ return -EPERM;
76553+#endif
76554+
76555+ }
76556+
76557+ if (!(vm_flags & VM_EXEC))
76558+ vm_flags &= ~VM_MAYEXEC;
76559+#else
76560+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76561+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76562+#endif
76563+ else
76564+ vm_flags &= ~VM_MAYWRITE;
76565+ }
76566+#endif
76567+
76568+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76569+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76570+ vm_flags &= ~VM_PAGEEXEC;
76571+#endif
76572+
76573 if (flags & MAP_LOCKED)
76574 if (!can_do_mlock())
76575 return -EPERM;
76576@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76577 locked += mm->locked_vm;
76578 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
76579 lock_limit >>= PAGE_SHIFT;
76580+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76581 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76582 return -EAGAIN;
76583 }
76584@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76585 if (error)
76586 return error;
76587
76588+ if (!gr_acl_handle_mmap(file, prot))
76589+ return -EACCES;
76590+
76591 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76592 }
76593 EXPORT_SYMBOL(do_mmap_pgoff);
76594@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
76595 */
76596 int vma_wants_writenotify(struct vm_area_struct *vma)
76597 {
76598- unsigned int vm_flags = vma->vm_flags;
76599+ unsigned long vm_flags = vma->vm_flags;
76600
76601 /* If it was private or non-writable, the write bit is already clear */
76602- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76603+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76604 return 0;
76605
76606 /* The backer wishes to know when pages are first written to? */
76607@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76608 unsigned long charged = 0;
76609 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76610
76611+#ifdef CONFIG_PAX_SEGMEXEC
76612+ struct vm_area_struct *vma_m = NULL;
76613+#endif
76614+
76615+ /*
76616+ * mm->mmap_sem is required to protect against another thread
76617+ * changing the mappings in case we sleep.
76618+ */
76619+ verify_mm_writelocked(mm);
76620+
76621 /* Clear old maps */
76622 error = -ENOMEM;
76623-munmap_back:
76624 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
76625 if (vma && vma->vm_start < addr + len) {
76626 if (do_munmap(mm, addr, len))
76627 return -ENOMEM;
76628- goto munmap_back;
76629+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
76630+ BUG_ON(vma && vma->vm_start < addr + len);
76631 }
76632
76633 /* Check against address space limit. */
76634@@ -1173,6 +1294,16 @@ munmap_back:
76635 goto unacct_error;
76636 }
76637
76638+#ifdef CONFIG_PAX_SEGMEXEC
76639+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76640+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76641+ if (!vma_m) {
76642+ error = -ENOMEM;
76643+ goto free_vma;
76644+ }
76645+ }
76646+#endif
76647+
76648 vma->vm_mm = mm;
76649 vma->vm_start = addr;
76650 vma->vm_end = addr + len;
76651@@ -1195,6 +1326,19 @@ munmap_back:
76652 error = file->f_op->mmap(file, vma);
76653 if (error)
76654 goto unmap_and_free_vma;
76655+
76656+#ifdef CONFIG_PAX_SEGMEXEC
76657+ if (vma_m && (vm_flags & VM_EXECUTABLE))
76658+ added_exe_file_vma(mm);
76659+#endif
76660+
76661+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76662+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76663+ vma->vm_flags |= VM_PAGEEXEC;
76664+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76665+ }
76666+#endif
76667+
76668 if (vm_flags & VM_EXECUTABLE)
76669 added_exe_file_vma(mm);
76670
76671@@ -1218,6 +1362,11 @@ munmap_back:
76672 vma_link(mm, vma, prev, rb_link, rb_parent);
76673 file = vma->vm_file;
76674
76675+#ifdef CONFIG_PAX_SEGMEXEC
76676+ if (vma_m)
76677+ pax_mirror_vma(vma_m, vma);
76678+#endif
76679+
76680 /* Once vma denies write, undo our temporary denial count */
76681 if (correct_wcount)
76682 atomic_inc(&inode->i_writecount);
76683@@ -1226,6 +1375,7 @@ out:
76684
76685 mm->total_vm += len >> PAGE_SHIFT;
76686 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76687+ track_exec_limit(mm, addr, addr + len, vm_flags);
76688 if (vm_flags & VM_LOCKED) {
76689 /*
76690 * makes pages present; downgrades, drops, reacquires mmap_sem
76691@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
76692 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76693 charged = 0;
76694 free_vma:
76695+
76696+#ifdef CONFIG_PAX_SEGMEXEC
76697+ if (vma_m)
76698+ kmem_cache_free(vm_area_cachep, vma_m);
76699+#endif
76700+
76701 kmem_cache_free(vm_area_cachep, vma);
76702 unacct_error:
76703 if (charged)
76704@@ -1255,6 +1411,44 @@ unacct_error:
76705 return error;
76706 }
76707
76708+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
76709+{
76710+ if (!vma) {
76711+#ifdef CONFIG_STACK_GROWSUP
76712+ if (addr > sysctl_heap_stack_gap)
76713+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76714+ else
76715+ vma = find_vma(current->mm, 0);
76716+ if (vma && (vma->vm_flags & VM_GROWSUP))
76717+ return false;
76718+#endif
76719+ return true;
76720+ }
76721+
76722+ if (addr + len > vma->vm_start)
76723+ return false;
76724+
76725+ if (vma->vm_flags & VM_GROWSDOWN)
76726+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76727+#ifdef CONFIG_STACK_GROWSUP
76728+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76729+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76730+#endif
76731+
76732+ return true;
76733+}
76734+
76735+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
76736+{
76737+ if (vma->vm_start < len)
76738+ return -ENOMEM;
76739+ if (!(vma->vm_flags & VM_GROWSDOWN))
76740+ return vma->vm_start - len;
76741+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
76742+ return vma->vm_start - len - sysctl_heap_stack_gap;
76743+ return -ENOMEM;
76744+}
76745+
76746 /* Get an address range which is currently unmapped.
76747 * For shmat() with addr=0.
76748 *
76749@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76750 if (flags & MAP_FIXED)
76751 return addr;
76752
76753+#ifdef CONFIG_PAX_RANDMMAP
76754+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76755+#endif
76756+
76757 if (addr) {
76758 addr = PAGE_ALIGN(addr);
76759- vma = find_vma(mm, addr);
76760- if (TASK_SIZE - len >= addr &&
76761- (!vma || addr + len <= vma->vm_start))
76762- return addr;
76763+ if (TASK_SIZE - len >= addr) {
76764+ vma = find_vma(mm, addr);
76765+ if (check_heap_stack_gap(vma, addr, len))
76766+ return addr;
76767+ }
76768 }
76769 if (len > mm->cached_hole_size) {
76770- start_addr = addr = mm->free_area_cache;
76771+ start_addr = addr = mm->free_area_cache;
76772 } else {
76773- start_addr = addr = TASK_UNMAPPED_BASE;
76774- mm->cached_hole_size = 0;
76775+ start_addr = addr = mm->mmap_base;
76776+ mm->cached_hole_size = 0;
76777 }
76778
76779 full_search:
76780@@ -1303,34 +1502,40 @@ full_search:
76781 * Start a new search - just in case we missed
76782 * some holes.
76783 */
76784- if (start_addr != TASK_UNMAPPED_BASE) {
76785- addr = TASK_UNMAPPED_BASE;
76786- start_addr = addr;
76787+ if (start_addr != mm->mmap_base) {
76788+ start_addr = addr = mm->mmap_base;
76789 mm->cached_hole_size = 0;
76790 goto full_search;
76791 }
76792 return -ENOMEM;
76793 }
76794- if (!vma || addr + len <= vma->vm_start) {
76795- /*
76796- * Remember the place where we stopped the search:
76797- */
76798- mm->free_area_cache = addr + len;
76799- return addr;
76800- }
76801+ if (check_heap_stack_gap(vma, addr, len))
76802+ break;
76803 if (addr + mm->cached_hole_size < vma->vm_start)
76804 mm->cached_hole_size = vma->vm_start - addr;
76805 addr = vma->vm_end;
76806 }
76807+
76808+ /*
76809+ * Remember the place where we stopped the search:
76810+ */
76811+ mm->free_area_cache = addr + len;
76812+ return addr;
76813 }
76814 #endif
76815
76816 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76817 {
76818+
76819+#ifdef CONFIG_PAX_SEGMEXEC
76820+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76821+ return;
76822+#endif
76823+
76824 /*
76825 * Is this a new hole at the lowest possible address?
76826 */
76827- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
76828+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
76829 mm->free_area_cache = addr;
76830 mm->cached_hole_size = ~0UL;
76831 }
76832@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76833 {
76834 struct vm_area_struct *vma;
76835 struct mm_struct *mm = current->mm;
76836- unsigned long addr = addr0;
76837+ unsigned long base = mm->mmap_base, addr = addr0;
76838
76839 /* requested length too big for entire address space */
76840 if (len > TASK_SIZE)
76841@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76842 if (flags & MAP_FIXED)
76843 return addr;
76844
76845+#ifdef CONFIG_PAX_RANDMMAP
76846+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76847+#endif
76848+
76849 /* requesting a specific address */
76850 if (addr) {
76851 addr = PAGE_ALIGN(addr);
76852- vma = find_vma(mm, addr);
76853- if (TASK_SIZE - len >= addr &&
76854- (!vma || addr + len <= vma->vm_start))
76855- return addr;
76856+ if (TASK_SIZE - len >= addr) {
76857+ vma = find_vma(mm, addr);
76858+ if (check_heap_stack_gap(vma, addr, len))
76859+ return addr;
76860+ }
76861 }
76862
76863 /* check if free_area_cache is useful for us */
76864@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76865 /* make sure it can fit in the remaining address space */
76866 if (addr > len) {
76867 vma = find_vma(mm, addr-len);
76868- if (!vma || addr <= vma->vm_start)
76869+ if (check_heap_stack_gap(vma, addr - len, len))
76870 /* remember the address as a hint for next time */
76871 return (mm->free_area_cache = addr-len);
76872 }
76873@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76874 * return with success:
76875 */
76876 vma = find_vma(mm, addr);
76877- if (!vma || addr+len <= vma->vm_start)
76878+ if (check_heap_stack_gap(vma, addr, len))
76879 /* remember the address as a hint for next time */
76880 return (mm->free_area_cache = addr);
76881
76882@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76883 mm->cached_hole_size = vma->vm_start - addr;
76884
76885 /* try just below the current vma->vm_start */
76886- addr = vma->vm_start-len;
76887- } while (len < vma->vm_start);
76888+ addr = skip_heap_stack_gap(vma, len);
76889+ } while (!IS_ERR_VALUE(addr));
76890
76891 bottomup:
76892 /*
76893@@ -1414,13 +1624,21 @@ bottomup:
76894 * can happen with large stack limits and large mmap()
76895 * allocations.
76896 */
76897+ mm->mmap_base = TASK_UNMAPPED_BASE;
76898+
76899+#ifdef CONFIG_PAX_RANDMMAP
76900+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76901+ mm->mmap_base += mm->delta_mmap;
76902+#endif
76903+
76904+ mm->free_area_cache = mm->mmap_base;
76905 mm->cached_hole_size = ~0UL;
76906- mm->free_area_cache = TASK_UNMAPPED_BASE;
76907 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
76908 /*
76909 * Restore the topdown base:
76910 */
76911- mm->free_area_cache = mm->mmap_base;
76912+ mm->mmap_base = base;
76913+ mm->free_area_cache = base;
76914 mm->cached_hole_size = ~0UL;
76915
76916 return addr;
76917@@ -1429,6 +1647,12 @@ bottomup:
76918
76919 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76920 {
76921+
76922+#ifdef CONFIG_PAX_SEGMEXEC
76923+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76924+ return;
76925+#endif
76926+
76927 /*
76928 * Is this a new hole at the highest possible address?
76929 */
76930@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76931 mm->free_area_cache = addr;
76932
76933 /* dont allow allocations above current base */
76934- if (mm->free_area_cache > mm->mmap_base)
76935+ if (mm->free_area_cache > mm->mmap_base) {
76936 mm->free_area_cache = mm->mmap_base;
76937+ mm->cached_hole_size = ~0UL;
76938+ }
76939 }
76940
76941 unsigned long
76942@@ -1545,6 +1771,27 @@ out:
76943 return prev ? prev->vm_next : vma;
76944 }
76945
76946+#ifdef CONFIG_PAX_SEGMEXEC
76947+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76948+{
76949+ struct vm_area_struct *vma_m;
76950+
76951+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76952+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76953+ BUG_ON(vma->vm_mirror);
76954+ return NULL;
76955+ }
76956+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76957+ vma_m = vma->vm_mirror;
76958+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76959+ BUG_ON(vma->vm_file != vma_m->vm_file);
76960+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76961+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
76962+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
76963+ return vma_m;
76964+}
76965+#endif
76966+
76967 /*
76968 * Verify that the stack growth is acceptable and
76969 * update accounting. This is shared with both the
76970@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76971 return -ENOMEM;
76972
76973 /* Stack limit test */
76974+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
76975 if (size > rlim[RLIMIT_STACK].rlim_cur)
76976 return -ENOMEM;
76977
76978@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76979 unsigned long limit;
76980 locked = mm->locked_vm + grow;
76981 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
76982+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76983 if (locked > limit && !capable(CAP_IPC_LOCK))
76984 return -ENOMEM;
76985 }
76986@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76987 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76988 * vma is the last one with address > vma->vm_end. Have to extend vma.
76989 */
76990+#ifndef CONFIG_IA64
76991+static
76992+#endif
76993 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76994 {
76995 int error;
76996+ bool locknext;
76997
76998 if (!(vma->vm_flags & VM_GROWSUP))
76999 return -EFAULT;
77000
77001+ /* Also guard against wrapping around to address 0. */
77002+ if (address < PAGE_ALIGN(address+1))
77003+ address = PAGE_ALIGN(address+1);
77004+ else
77005+ return -ENOMEM;
77006+
77007 /*
77008 * We must make sure the anon_vma is allocated
77009 * so that the anon_vma locking is not a noop.
77010 */
77011 if (unlikely(anon_vma_prepare(vma)))
77012 return -ENOMEM;
77013+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77014+ if (locknext && anon_vma_prepare(vma->vm_next))
77015+ return -ENOMEM;
77016 anon_vma_lock(vma);
77017+ if (locknext)
77018+ anon_vma_lock(vma->vm_next);
77019
77020 /*
77021 * vma->vm_start/vm_end cannot change under us because the caller
77022 * is required to hold the mmap_sem in read mode. We need the
77023- * anon_vma lock to serialize against concurrent expand_stacks.
77024- * Also guard against wrapping around to address 0.
77025+ * anon_vma locks to serialize against concurrent expand_stacks
77026+ * and expand_upwards.
77027 */
77028- if (address < PAGE_ALIGN(address+4))
77029- address = PAGE_ALIGN(address+4);
77030- else {
77031- anon_vma_unlock(vma);
77032- return -ENOMEM;
77033- }
77034 error = 0;
77035
77036 /* Somebody else might have raced and expanded it already */
77037- if (address > vma->vm_end) {
77038+ 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)
77039+ error = -ENOMEM;
77040+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77041 unsigned long size, grow;
77042
77043 size = address - vma->vm_start;
77044@@ -1643,6 +1903,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77045 vma->vm_end = address;
77046 }
77047 }
77048+ if (locknext)
77049+ anon_vma_unlock(vma->vm_next);
77050 anon_vma_unlock(vma);
77051 return error;
77052 }
77053@@ -1655,6 +1917,8 @@ static int expand_downwards(struct vm_area_struct *vma,
77054 unsigned long address)
77055 {
77056 int error;
77057+ bool lockprev = false;
77058+ struct vm_area_struct *prev;
77059
77060 /*
77061 * We must make sure the anon_vma is allocated
77062@@ -1668,6 +1932,15 @@ static int expand_downwards(struct vm_area_struct *vma,
77063 if (error)
77064 return error;
77065
77066+ prev = vma->vm_prev;
77067+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77068+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77069+#endif
77070+ if (lockprev && anon_vma_prepare(prev))
77071+ return -ENOMEM;
77072+ if (lockprev)
77073+ anon_vma_lock(prev);
77074+
77075 anon_vma_lock(vma);
77076
77077 /*
77078@@ -1677,9 +1950,17 @@ static int expand_downwards(struct vm_area_struct *vma,
77079 */
77080
77081 /* Somebody else might have raced and expanded it already */
77082- if (address < vma->vm_start) {
77083+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77084+ error = -ENOMEM;
77085+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77086 unsigned long size, grow;
77087
77088+#ifdef CONFIG_PAX_SEGMEXEC
77089+ struct vm_area_struct *vma_m;
77090+
77091+ vma_m = pax_find_mirror_vma(vma);
77092+#endif
77093+
77094 size = vma->vm_end - address;
77095 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77096
77097@@ -1689,10 +1970,22 @@ static int expand_downwards(struct vm_area_struct *vma,
77098 if (!error) {
77099 vma->vm_start = address;
77100 vma->vm_pgoff -= grow;
77101+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77102+
77103+#ifdef CONFIG_PAX_SEGMEXEC
77104+ if (vma_m) {
77105+ vma_m->vm_start -= grow << PAGE_SHIFT;
77106+ vma_m->vm_pgoff -= grow;
77107+ }
77108+#endif
77109+
77110+
77111 }
77112 }
77113 }
77114 anon_vma_unlock(vma);
77115+ if (lockprev)
77116+ anon_vma_unlock(prev);
77117 return error;
77118 }
77119
77120@@ -1768,6 +2061,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77121 do {
77122 long nrpages = vma_pages(vma);
77123
77124+#ifdef CONFIG_PAX_SEGMEXEC
77125+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77126+ vma = remove_vma(vma);
77127+ continue;
77128+ }
77129+#endif
77130+
77131 mm->total_vm -= nrpages;
77132 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77133 vma = remove_vma(vma);
77134@@ -1813,6 +2113,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77135 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77136 vma->vm_prev = NULL;
77137 do {
77138+
77139+#ifdef CONFIG_PAX_SEGMEXEC
77140+ if (vma->vm_mirror) {
77141+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77142+ vma->vm_mirror->vm_mirror = NULL;
77143+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77144+ vma->vm_mirror = NULL;
77145+ }
77146+#endif
77147+
77148 rb_erase(&vma->vm_rb, &mm->mm_rb);
77149 mm->map_count--;
77150 tail_vma = vma;
77151@@ -1840,10 +2150,25 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77152 struct mempolicy *pol;
77153 struct vm_area_struct *new;
77154
77155+#ifdef CONFIG_PAX_SEGMEXEC
77156+ struct vm_area_struct *vma_m, *new_m = NULL;
77157+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77158+#endif
77159+
77160 if (is_vm_hugetlb_page(vma) && (addr &
77161 ~(huge_page_mask(hstate_vma(vma)))))
77162 return -EINVAL;
77163
77164+#ifdef CONFIG_PAX_SEGMEXEC
77165+ vma_m = pax_find_mirror_vma(vma);
77166+
77167+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77168+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77169+ if (mm->map_count >= sysctl_max_map_count-1)
77170+ return -ENOMEM;
77171+ } else
77172+#endif
77173+
77174 if (mm->map_count >= sysctl_max_map_count)
77175 return -ENOMEM;
77176
77177@@ -1851,6 +2176,16 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77178 if (!new)
77179 return -ENOMEM;
77180
77181+#ifdef CONFIG_PAX_SEGMEXEC
77182+ if (vma_m) {
77183+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77184+ if (!new_m) {
77185+ kmem_cache_free(vm_area_cachep, new);
77186+ return -ENOMEM;
77187+ }
77188+ }
77189+#endif
77190+
77191 /* most fields are the same, copy all, and then fixup */
77192 *new = *vma;
77193
77194@@ -1861,8 +2196,29 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77195 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77196 }
77197
77198+#ifdef CONFIG_PAX_SEGMEXEC
77199+ if (vma_m) {
77200+ *new_m = *vma_m;
77201+ new_m->vm_mirror = new;
77202+ new->vm_mirror = new_m;
77203+
77204+ if (new_below)
77205+ new_m->vm_end = addr_m;
77206+ else {
77207+ new_m->vm_start = addr_m;
77208+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77209+ }
77210+ }
77211+#endif
77212+
77213 pol = mpol_dup(vma_policy(vma));
77214 if (IS_ERR(pol)) {
77215+
77216+#ifdef CONFIG_PAX_SEGMEXEC
77217+ if (new_m)
77218+ kmem_cache_free(vm_area_cachep, new_m);
77219+#endif
77220+
77221 kmem_cache_free(vm_area_cachep, new);
77222 return PTR_ERR(pol);
77223 }
77224@@ -1883,6 +2239,28 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77225 else
77226 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77227
77228+#ifdef CONFIG_PAX_SEGMEXEC
77229+ if (vma_m) {
77230+ mpol_get(pol);
77231+ vma_set_policy(new_m, pol);
77232+
77233+ if (new_m->vm_file) {
77234+ get_file(new_m->vm_file);
77235+ if (vma_m->vm_flags & VM_EXECUTABLE)
77236+ added_exe_file_vma(mm);
77237+ }
77238+
77239+ if (new_m->vm_ops && new_m->vm_ops->open)
77240+ new_m->vm_ops->open(new_m);
77241+
77242+ if (new_below)
77243+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77244+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77245+ else
77246+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77247+ }
77248+#endif
77249+
77250 return 0;
77251 }
77252
77253@@ -1891,11 +2269,30 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77254 * work. This now handles partial unmappings.
77255 * Jeremy Fitzhardinge <jeremy@goop.org>
77256 */
77257+#ifdef CONFIG_PAX_SEGMEXEC
77258 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77259 {
77260+ int ret = __do_munmap(mm, start, len);
77261+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77262+ return ret;
77263+
77264+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77265+}
77266+
77267+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77268+#else
77269+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77270+#endif
77271+{
77272 unsigned long end;
77273 struct vm_area_struct *vma, *prev, *last;
77274
77275+ /*
77276+ * mm->mmap_sem is required to protect against another thread
77277+ * changing the mappings in case we sleep.
77278+ */
77279+ verify_mm_writelocked(mm);
77280+
77281 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77282 return -EINVAL;
77283
77284@@ -1959,6 +2356,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77285 /* Fix up all other VM information */
77286 remove_vma_list(mm, vma);
77287
77288+ track_exec_limit(mm, start, end, 0UL);
77289+
77290 return 0;
77291 }
77292
77293@@ -1971,22 +2370,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77294
77295 profile_munmap(addr);
77296
77297+#ifdef CONFIG_PAX_SEGMEXEC
77298+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77299+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
77300+ return -EINVAL;
77301+#endif
77302+
77303 down_write(&mm->mmap_sem);
77304 ret = do_munmap(mm, addr, len);
77305 up_write(&mm->mmap_sem);
77306 return ret;
77307 }
77308
77309-static inline void verify_mm_writelocked(struct mm_struct *mm)
77310-{
77311-#ifdef CONFIG_DEBUG_VM
77312- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77313- WARN_ON(1);
77314- up_read(&mm->mmap_sem);
77315- }
77316-#endif
77317-}
77318-
77319 /*
77320 * this is really a simplified "do_mmap". it only handles
77321 * anonymous maps. eventually we may be able to do some
77322@@ -2000,6 +2395,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77323 struct rb_node ** rb_link, * rb_parent;
77324 pgoff_t pgoff = addr >> PAGE_SHIFT;
77325 int error;
77326+ unsigned long charged;
77327
77328 len = PAGE_ALIGN(len);
77329 if (!len)
77330@@ -2011,16 +2407,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77331
77332 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77333
77334+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77335+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77336+ flags &= ~VM_EXEC;
77337+
77338+#ifdef CONFIG_PAX_MPROTECT
77339+ if (mm->pax_flags & MF_PAX_MPROTECT)
77340+ flags &= ~VM_MAYEXEC;
77341+#endif
77342+
77343+ }
77344+#endif
77345+
77346 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77347 if (error & ~PAGE_MASK)
77348 return error;
77349
77350+ charged = len >> PAGE_SHIFT;
77351+
77352 /*
77353 * mlock MCL_FUTURE?
77354 */
77355 if (mm->def_flags & VM_LOCKED) {
77356 unsigned long locked, lock_limit;
77357- locked = len >> PAGE_SHIFT;
77358+ locked = charged;
77359 locked += mm->locked_vm;
77360 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
77361 lock_limit >>= PAGE_SHIFT;
77362@@ -2037,22 +2447,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77363 /*
77364 * Clear old maps. this also does some error checking for us
77365 */
77366- munmap_back:
77367 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77368 if (vma && vma->vm_start < addr + len) {
77369 if (do_munmap(mm, addr, len))
77370 return -ENOMEM;
77371- goto munmap_back;
77372+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77373+ BUG_ON(vma && vma->vm_start < addr + len);
77374 }
77375
77376 /* Check against address space limits *after* clearing old maps... */
77377- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77378+ if (!may_expand_vm(mm, charged))
77379 return -ENOMEM;
77380
77381 if (mm->map_count > sysctl_max_map_count)
77382 return -ENOMEM;
77383
77384- if (security_vm_enough_memory(len >> PAGE_SHIFT))
77385+ if (security_vm_enough_memory(charged))
77386 return -ENOMEM;
77387
77388 /* Can we just expand an old private anonymous mapping? */
77389@@ -2066,7 +2476,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77390 */
77391 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77392 if (!vma) {
77393- vm_unacct_memory(len >> PAGE_SHIFT);
77394+ vm_unacct_memory(charged);
77395 return -ENOMEM;
77396 }
77397
77398@@ -2078,11 +2488,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77399 vma->vm_page_prot = vm_get_page_prot(flags);
77400 vma_link(mm, vma, prev, rb_link, rb_parent);
77401 out:
77402- mm->total_vm += len >> PAGE_SHIFT;
77403+ mm->total_vm += charged;
77404 if (flags & VM_LOCKED) {
77405 if (!mlock_vma_pages_range(vma, addr, addr + len))
77406- mm->locked_vm += (len >> PAGE_SHIFT);
77407+ mm->locked_vm += charged;
77408 }
77409+ track_exec_limit(mm, addr, addr + len, flags);
77410 return addr;
77411 }
77412
77413@@ -2129,8 +2540,10 @@ void exit_mmap(struct mm_struct *mm)
77414 * Walk the list again, actually closing and freeing it,
77415 * with preemption enabled, without holding any MM locks.
77416 */
77417- while (vma)
77418+ while (vma) {
77419+ vma->vm_mirror = NULL;
77420 vma = remove_vma(vma);
77421+ }
77422
77423 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
77424 }
77425@@ -2144,6 +2557,10 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77426 struct vm_area_struct * __vma, * prev;
77427 struct rb_node ** rb_link, * rb_parent;
77428
77429+#ifdef CONFIG_PAX_SEGMEXEC
77430+ struct vm_area_struct *vma_m = NULL;
77431+#endif
77432+
77433 /*
77434 * The vm_pgoff of a purely anonymous vma should be irrelevant
77435 * until its first write fault, when page's anon_vma and index
77436@@ -2166,7 +2583,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77437 if ((vma->vm_flags & VM_ACCOUNT) &&
77438 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77439 return -ENOMEM;
77440+
77441+#ifdef CONFIG_PAX_SEGMEXEC
77442+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77443+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77444+ if (!vma_m)
77445+ return -ENOMEM;
77446+ }
77447+#endif
77448+
77449 vma_link(mm, vma, prev, rb_link, rb_parent);
77450+
77451+#ifdef CONFIG_PAX_SEGMEXEC
77452+ if (vma_m)
77453+ pax_mirror_vma(vma_m, vma);
77454+#endif
77455+
77456 return 0;
77457 }
77458
77459@@ -2184,6 +2616,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77460 struct rb_node **rb_link, *rb_parent;
77461 struct mempolicy *pol;
77462
77463+ BUG_ON(vma->vm_mirror);
77464+
77465 /*
77466 * If anonymous vma has not yet been faulted, update new pgoff
77467 * to match new location, to increase its chance of merging.
77468@@ -2227,6 +2661,35 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77469 return new_vma;
77470 }
77471
77472+#ifdef CONFIG_PAX_SEGMEXEC
77473+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77474+{
77475+ struct vm_area_struct *prev_m;
77476+ struct rb_node **rb_link_m, *rb_parent_m;
77477+ struct mempolicy *pol_m;
77478+
77479+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77480+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77481+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77482+ *vma_m = *vma;
77483+ pol_m = vma_policy(vma_m);
77484+ mpol_get(pol_m);
77485+ vma_set_policy(vma_m, pol_m);
77486+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77487+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77488+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77489+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77490+ if (vma_m->vm_file)
77491+ get_file(vma_m->vm_file);
77492+ if (vma_m->vm_ops && vma_m->vm_ops->open)
77493+ vma_m->vm_ops->open(vma_m);
77494+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
77495+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77496+ vma_m->vm_mirror = vma;
77497+ vma->vm_mirror = vma_m;
77498+}
77499+#endif
77500+
77501 /*
77502 * Return true if the calling process may expand its vm space by the passed
77503 * number of pages
77504@@ -2237,7 +2700,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77505 unsigned long lim;
77506
77507 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
77508-
77509+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77510 if (cur + npages > lim)
77511 return 0;
77512 return 1;
77513@@ -2307,6 +2770,22 @@ int install_special_mapping(struct mm_struct *mm,
77514 vma->vm_start = addr;
77515 vma->vm_end = addr + len;
77516
77517+#ifdef CONFIG_PAX_MPROTECT
77518+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77519+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77520+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77521+ return -EPERM;
77522+ if (!(vm_flags & VM_EXEC))
77523+ vm_flags &= ~VM_MAYEXEC;
77524+#else
77525+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77526+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77527+#endif
77528+ else
77529+ vm_flags &= ~VM_MAYWRITE;
77530+ }
77531+#endif
77532+
77533 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77534 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77535
77536diff --git a/mm/mprotect.c b/mm/mprotect.c
77537index 1737c7e..c7faeb4 100644
77538--- a/mm/mprotect.c
77539+++ b/mm/mprotect.c
77540@@ -24,10 +24,16 @@
77541 #include <linux/mmu_notifier.h>
77542 #include <linux/migrate.h>
77543 #include <linux/perf_event.h>
77544+
77545+#ifdef CONFIG_PAX_MPROTECT
77546+#include <linux/elf.h>
77547+#endif
77548+
77549 #include <asm/uaccess.h>
77550 #include <asm/pgtable.h>
77551 #include <asm/cacheflush.h>
77552 #include <asm/tlbflush.h>
77553+#include <asm/mmu_context.h>
77554
77555 #ifndef pgprot_modify
77556 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77557@@ -132,6 +138,48 @@ static void change_protection(struct vm_area_struct *vma,
77558 flush_tlb_range(vma, start, end);
77559 }
77560
77561+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77562+/* called while holding the mmap semaphor for writing except stack expansion */
77563+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77564+{
77565+ unsigned long oldlimit, newlimit = 0UL;
77566+
77567+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
77568+ return;
77569+
77570+ spin_lock(&mm->page_table_lock);
77571+ oldlimit = mm->context.user_cs_limit;
77572+ if ((prot & VM_EXEC) && oldlimit < end)
77573+ /* USER_CS limit moved up */
77574+ newlimit = end;
77575+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77576+ /* USER_CS limit moved down */
77577+ newlimit = start;
77578+
77579+ if (newlimit) {
77580+ mm->context.user_cs_limit = newlimit;
77581+
77582+#ifdef CONFIG_SMP
77583+ wmb();
77584+ cpus_clear(mm->context.cpu_user_cs_mask);
77585+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77586+#endif
77587+
77588+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77589+ }
77590+ spin_unlock(&mm->page_table_lock);
77591+ if (newlimit == end) {
77592+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
77593+
77594+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
77595+ if (is_vm_hugetlb_page(vma))
77596+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77597+ else
77598+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
77599+ }
77600+}
77601+#endif
77602+
77603 int
77604 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77605 unsigned long start, unsigned long end, unsigned long newflags)
77606@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77607 int error;
77608 int dirty_accountable = 0;
77609
77610+#ifdef CONFIG_PAX_SEGMEXEC
77611+ struct vm_area_struct *vma_m = NULL;
77612+ unsigned long start_m, end_m;
77613+
77614+ start_m = start + SEGMEXEC_TASK_SIZE;
77615+ end_m = end + SEGMEXEC_TASK_SIZE;
77616+#endif
77617+
77618 if (newflags == oldflags) {
77619 *pprev = vma;
77620 return 0;
77621 }
77622
77623+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77624+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77625+
77626+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77627+ return -ENOMEM;
77628+
77629+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77630+ return -ENOMEM;
77631+ }
77632+
77633 /*
77634 * If we make a private mapping writable we increase our commit;
77635 * but (without finer accounting) cannot reduce our commit if we
77636@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77637 }
77638 }
77639
77640+#ifdef CONFIG_PAX_SEGMEXEC
77641+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77642+ if (start != vma->vm_start) {
77643+ error = split_vma(mm, vma, start, 1);
77644+ if (error)
77645+ goto fail;
77646+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77647+ *pprev = (*pprev)->vm_next;
77648+ }
77649+
77650+ if (end != vma->vm_end) {
77651+ error = split_vma(mm, vma, end, 0);
77652+ if (error)
77653+ goto fail;
77654+ }
77655+
77656+ if (pax_find_mirror_vma(vma)) {
77657+ error = __do_munmap(mm, start_m, end_m - start_m);
77658+ if (error)
77659+ goto fail;
77660+ } else {
77661+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77662+ if (!vma_m) {
77663+ error = -ENOMEM;
77664+ goto fail;
77665+ }
77666+ vma->vm_flags = newflags;
77667+ pax_mirror_vma(vma_m, vma);
77668+ }
77669+ }
77670+#endif
77671+
77672 /*
77673 * First try to merge with previous and/or next vma.
77674 */
77675@@ -195,9 +293,21 @@ success:
77676 * vm_flags and vm_page_prot are protected by the mmap_sem
77677 * held in write mode.
77678 */
77679+
77680+#ifdef CONFIG_PAX_SEGMEXEC
77681+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77682+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77683+#endif
77684+
77685 vma->vm_flags = newflags;
77686+
77687+#ifdef CONFIG_PAX_MPROTECT
77688+ if (mm->binfmt && mm->binfmt->handle_mprotect)
77689+ mm->binfmt->handle_mprotect(vma, newflags);
77690+#endif
77691+
77692 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77693- vm_get_page_prot(newflags));
77694+ vm_get_page_prot(vma->vm_flags));
77695
77696 if (vma_wants_writenotify(vma)) {
77697 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77698@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77699 end = start + len;
77700 if (end <= start)
77701 return -ENOMEM;
77702+
77703+#ifdef CONFIG_PAX_SEGMEXEC
77704+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77705+ if (end > SEGMEXEC_TASK_SIZE)
77706+ return -EINVAL;
77707+ } else
77708+#endif
77709+
77710+ if (end > TASK_SIZE)
77711+ return -EINVAL;
77712+
77713 if (!arch_validate_prot(prot))
77714 return -EINVAL;
77715
77716@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77717 /*
77718 * Does the application expect PROT_READ to imply PROT_EXEC:
77719 */
77720- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77721+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77722 prot |= PROT_EXEC;
77723
77724 vm_flags = calc_vm_prot_bits(prot);
77725@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77726 if (start > vma->vm_start)
77727 prev = vma;
77728
77729+#ifdef CONFIG_PAX_MPROTECT
77730+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77731+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
77732+#endif
77733+
77734 for (nstart = start ; ; ) {
77735 unsigned long newflags;
77736
77737@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77738
77739 /* newflags >> 4 shift VM_MAY% in place of VM_% */
77740 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
77741+ if (prot & (PROT_WRITE | PROT_EXEC))
77742+ gr_log_rwxmprotect(vma->vm_file);
77743+
77744+ error = -EACCES;
77745+ goto out;
77746+ }
77747+
77748+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
77749 error = -EACCES;
77750 goto out;
77751 }
77752@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77753 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
77754 if (error)
77755 goto out;
77756+
77757+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
77758+
77759 nstart = tmp;
77760
77761 if (nstart < prev->vm_end)
77762diff --git a/mm/mremap.c b/mm/mremap.c
77763index 3e98d79..1706cec 100644
77764--- a/mm/mremap.c
77765+++ b/mm/mremap.c
77766@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
77767 continue;
77768 pte = ptep_clear_flush(vma, old_addr, old_pte);
77769 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
77770+
77771+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77772+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
77773+ pte = pte_exprotect(pte);
77774+#endif
77775+
77776 set_pte_at(mm, new_addr, new_pte, pte);
77777 }
77778
77779@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
77780 if (is_vm_hugetlb_page(vma))
77781 goto Einval;
77782
77783+#ifdef CONFIG_PAX_SEGMEXEC
77784+ if (pax_find_mirror_vma(vma))
77785+ goto Einval;
77786+#endif
77787+
77788 /* We can't remap across vm area boundaries */
77789 if (old_len > vma->vm_end - addr)
77790 goto Efault;
77791@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned long addr,
77792 unsigned long ret = -EINVAL;
77793 unsigned long charged = 0;
77794 unsigned long map_flags;
77795+ unsigned long pax_task_size = TASK_SIZE;
77796
77797 if (new_addr & ~PAGE_MASK)
77798 goto out;
77799
77800- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
77801+#ifdef CONFIG_PAX_SEGMEXEC
77802+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77803+ pax_task_size = SEGMEXEC_TASK_SIZE;
77804+#endif
77805+
77806+ pax_task_size -= PAGE_SIZE;
77807+
77808+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
77809 goto out;
77810
77811 /* Check if the location we're moving into overlaps the
77812 * old location at all, and fail if it does.
77813 */
77814- if ((new_addr <= addr) && (new_addr+new_len) > addr)
77815- goto out;
77816-
77817- if ((addr <= new_addr) && (addr+old_len) > new_addr)
77818+ if (addr + old_len > new_addr && new_addr + new_len > addr)
77819 goto out;
77820
77821 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
77822@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long addr,
77823 struct vm_area_struct *vma;
77824 unsigned long ret = -EINVAL;
77825 unsigned long charged = 0;
77826+ unsigned long pax_task_size = TASK_SIZE;
77827
77828 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
77829 goto out;
77830@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long addr,
77831 if (!new_len)
77832 goto out;
77833
77834+#ifdef CONFIG_PAX_SEGMEXEC
77835+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77836+ pax_task_size = SEGMEXEC_TASK_SIZE;
77837+#endif
77838+
77839+ pax_task_size -= PAGE_SIZE;
77840+
77841+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77842+ old_len > pax_task_size || addr > pax_task_size-old_len)
77843+ goto out;
77844+
77845 if (flags & MREMAP_FIXED) {
77846 if (flags & MREMAP_MAYMOVE)
77847 ret = mremap_to(addr, old_len, new_addr, new_len);
77848@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long addr,
77849 addr + new_len);
77850 }
77851 ret = addr;
77852+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77853 goto out;
77854 }
77855 }
77856@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long addr,
77857 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
77858 if (ret)
77859 goto out;
77860+
77861+ map_flags = vma->vm_flags;
77862 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77863+ if (!(ret & ~PAGE_MASK)) {
77864+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77865+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77866+ }
77867 }
77868 out:
77869 if (ret & ~PAGE_MASK)
77870diff --git a/mm/nommu.c b/mm/nommu.c
77871index 406e8d4..53970d3 100644
77872--- a/mm/nommu.c
77873+++ b/mm/nommu.c
77874@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77875 int sysctl_overcommit_ratio = 50; /* default is 50% */
77876 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77877 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77878-int heap_stack_gap = 0;
77879
77880 atomic_long_t mmap_pages_allocated;
77881
77882@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77883 EXPORT_SYMBOL(find_vma);
77884
77885 /*
77886- * find a VMA
77887- * - we don't extend stack VMAs under NOMMU conditions
77888- */
77889-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77890-{
77891- return find_vma(mm, addr);
77892-}
77893-
77894-/*
77895 * expand a stack to a given address
77896 * - not supported under NOMMU conditions
77897 */
77898diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77899index 3ecab7e..594a471 100644
77900--- a/mm/page_alloc.c
77901+++ b/mm/page_alloc.c
77902@@ -289,7 +289,7 @@ out:
77903 * This usage means that zero-order pages may not be compound.
77904 */
77905
77906-static void free_compound_page(struct page *page)
77907+void free_compound_page(struct page *page)
77908 {
77909 __free_pages_ok(page, compound_order(page));
77910 }
77911@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
77912 int bad = 0;
77913 int wasMlocked = __TestClearPageMlocked(page);
77914
77915+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77916+ unsigned long index = 1UL << order;
77917+#endif
77918+
77919 kmemcheck_free_shadow(page, order);
77920
77921 for (i = 0 ; i < (1 << order) ; ++i)
77922@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page *page, unsigned int order)
77923 debug_check_no_obj_freed(page_address(page),
77924 PAGE_SIZE << order);
77925 }
77926+
77927+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77928+ for (; index; --index)
77929+ sanitize_highpage(page + index - 1);
77930+#endif
77931+
77932 arch_free_page(page, order);
77933 kernel_map_pages(page, 1 << order, 0);
77934
77935@@ -702,8 +712,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77936 arch_alloc_page(page, order);
77937 kernel_map_pages(page, 1 << order, 1);
77938
77939+#ifndef CONFIG_PAX_MEMORY_SANITIZE
77940 if (gfp_flags & __GFP_ZERO)
77941 prep_zero_page(page, order, gfp_flags);
77942+#endif
77943
77944 if (order && (gfp_flags & __GFP_COMP))
77945 prep_compound_page(page, order);
77946@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct page *page, int cold)
77947 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
77948 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
77949 }
77950+
77951+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77952+ sanitize_highpage(page);
77953+#endif
77954+
77955 arch_free_page(page, 0);
77956 kernel_map_pages(page, 1, 0);
77957
77958@@ -2179,6 +2196,8 @@ void show_free_areas(void)
77959 int cpu;
77960 struct zone *zone;
77961
77962+ pax_track_stack();
77963+
77964 for_each_populated_zone(zone) {
77965 show_node(zone);
77966 printk("%s per-cpu:\n", zone->name);
77967@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct pglist_data *pgdat,
77968 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
77969 }
77970 #else
77971-static void inline setup_usemap(struct pglist_data *pgdat,
77972+static inline void setup_usemap(struct pglist_data *pgdat,
77973 struct zone *zone, unsigned long zonesize) {}
77974 #endif /* CONFIG_SPARSEMEM */
77975
77976diff --git a/mm/percpu.c b/mm/percpu.c
77977index c90614a..5f7b7b8 100644
77978--- a/mm/percpu.c
77979+++ b/mm/percpu.c
77980@@ -115,7 +115,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77981 static unsigned int pcpu_high_unit_cpu __read_mostly;
77982
77983 /* the address of the first chunk which starts with the kernel static area */
77984-void *pcpu_base_addr __read_mostly;
77985+void *pcpu_base_addr __read_only;
77986 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77987
77988 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77989diff --git a/mm/rmap.c b/mm/rmap.c
77990index dd43373..d848cd7 100644
77991--- a/mm/rmap.c
77992+++ b/mm/rmap.c
77993@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77994 /* page_table_lock to protect against threads */
77995 spin_lock(&mm->page_table_lock);
77996 if (likely(!vma->anon_vma)) {
77997+
77998+#ifdef CONFIG_PAX_SEGMEXEC
77999+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78000+
78001+ if (vma_m) {
78002+ BUG_ON(vma_m->anon_vma);
78003+ vma_m->anon_vma = anon_vma;
78004+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
78005+ }
78006+#endif
78007+
78008 vma->anon_vma = anon_vma;
78009 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
78010 allocated = NULL;
78011diff --git a/mm/shmem.c b/mm/shmem.c
78012index 3e0005b..1d659a8 100644
78013--- a/mm/shmem.c
78014+++ b/mm/shmem.c
78015@@ -31,7 +31,7 @@
78016 #include <linux/swap.h>
78017 #include <linux/ima.h>
78018
78019-static struct vfsmount *shm_mnt;
78020+struct vfsmount *shm_mnt;
78021
78022 #ifdef CONFIG_SHMEM
78023 /*
78024@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
78025 goto unlock;
78026 }
78027 entry = shmem_swp_entry(info, index, NULL);
78028+ if (!entry)
78029+ goto unlock;
78030 if (entry->val) {
78031 /*
78032 * The more uptodate page coming down from a stacked
78033@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
78034 struct vm_area_struct pvma;
78035 struct page *page;
78036
78037+ pax_track_stack();
78038+
78039 spol = mpol_cond_copy(&mpol,
78040 mpol_shared_policy_lookup(&info->policy, idx));
78041
78042@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
78043
78044 info = SHMEM_I(inode);
78045 inode->i_size = len-1;
78046- if (len <= (char *)inode - (char *)info) {
78047+ if (len <= (char *)inode - (char *)info && len <= 64) {
78048 /* do it inline */
78049 memcpy(info, symname, len);
78050 inode->i_op = &shmem_symlink_inline_operations;
78051@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78052 int err = -ENOMEM;
78053
78054 /* Round up to L1_CACHE_BYTES to resist false sharing */
78055- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78056- L1_CACHE_BYTES), GFP_KERNEL);
78057+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78058 if (!sbinfo)
78059 return -ENOMEM;
78060
78061diff --git a/mm/slab.c b/mm/slab.c
78062index c8d466a..909e01e 100644
78063--- a/mm/slab.c
78064+++ b/mm/slab.c
78065@@ -174,7 +174,7 @@
78066
78067 /* Legal flag mask for kmem_cache_create(). */
78068 #if DEBUG
78069-# define CREATE_MASK (SLAB_RED_ZONE | \
78070+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
78071 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
78072 SLAB_CACHE_DMA | \
78073 SLAB_STORE_USER | \
78074@@ -182,7 +182,7 @@
78075 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78076 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
78077 #else
78078-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
78079+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
78080 SLAB_CACHE_DMA | \
78081 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
78082 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78083@@ -308,7 +308,7 @@ struct kmem_list3 {
78084 * Need this for bootstrapping a per node allocator.
78085 */
78086 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78087-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78088+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78089 #define CACHE_CACHE 0
78090 #define SIZE_AC MAX_NUMNODES
78091 #define SIZE_L3 (2 * MAX_NUMNODES)
78092@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78093 if ((x)->max_freeable < i) \
78094 (x)->max_freeable = i; \
78095 } while (0)
78096-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78097-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78098-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78099-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78100+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78101+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78102+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78103+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78104 #else
78105 #define STATS_INC_ACTIVE(x) do { } while (0)
78106 #define STATS_DEC_ACTIVE(x) do { } while (0)
78107@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78108 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78109 */
78110 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78111- const struct slab *slab, void *obj)
78112+ const struct slab *slab, const void *obj)
78113 {
78114 u32 offset = (obj - slab->s_mem);
78115 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78116@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
78117 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
78118 sizes[INDEX_AC].cs_size,
78119 ARCH_KMALLOC_MINALIGN,
78120- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78121+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78122 NULL);
78123
78124 if (INDEX_AC != INDEX_L3) {
78125@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
78126 kmem_cache_create(names[INDEX_L3].name,
78127 sizes[INDEX_L3].cs_size,
78128 ARCH_KMALLOC_MINALIGN,
78129- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78130+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78131 NULL);
78132 }
78133
78134@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
78135 sizes->cs_cachep = kmem_cache_create(names->name,
78136 sizes->cs_size,
78137 ARCH_KMALLOC_MINALIGN,
78138- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78139+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78140 NULL);
78141 }
78142 #ifdef CONFIG_ZONE_DMA
78143@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, void *p)
78144 }
78145 /* cpu stats */
78146 {
78147- unsigned long allochit = atomic_read(&cachep->allochit);
78148- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78149- unsigned long freehit = atomic_read(&cachep->freehit);
78150- unsigned long freemiss = atomic_read(&cachep->freemiss);
78151+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78152+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78153+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78154+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78155
78156 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78157 allochit, allocmiss, freehit, freemiss);
78158@@ -4471,15 +4471,70 @@ static const struct file_operations proc_slabstats_operations = {
78159
78160 static int __init slab_proc_init(void)
78161 {
78162- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
78163+ mode_t gr_mode = S_IRUGO;
78164+
78165+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78166+ gr_mode = S_IRUSR;
78167+#endif
78168+
78169+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
78170 #ifdef CONFIG_DEBUG_SLAB_LEAK
78171- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78172+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
78173 #endif
78174 return 0;
78175 }
78176 module_init(slab_proc_init);
78177 #endif
78178
78179+void check_object_size(const void *ptr, unsigned long n, bool to)
78180+{
78181+
78182+#ifdef CONFIG_PAX_USERCOPY
78183+ struct page *page;
78184+ struct kmem_cache *cachep = NULL;
78185+ struct slab *slabp;
78186+ unsigned int objnr;
78187+ unsigned long offset;
78188+ const char *type;
78189+
78190+ if (!n)
78191+ return;
78192+
78193+ type = "<null>";
78194+ if (ZERO_OR_NULL_PTR(ptr))
78195+ goto report;
78196+
78197+ if (!virt_addr_valid(ptr))
78198+ return;
78199+
78200+ page = virt_to_head_page(ptr);
78201+
78202+ type = "<process stack>";
78203+ if (!PageSlab(page)) {
78204+ if (object_is_on_stack(ptr, n) == -1)
78205+ goto report;
78206+ return;
78207+ }
78208+
78209+ cachep = page_get_cache(page);
78210+ type = cachep->name;
78211+ if (!(cachep->flags & SLAB_USERCOPY))
78212+ goto report;
78213+
78214+ slabp = page_get_slab(page);
78215+ objnr = obj_to_index(cachep, slabp, ptr);
78216+ BUG_ON(objnr >= cachep->num);
78217+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78218+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
78219+ return;
78220+
78221+report:
78222+ pax_report_usercopy(ptr, n, to, type);
78223+#endif
78224+
78225+}
78226+EXPORT_SYMBOL(check_object_size);
78227+
78228 /**
78229 * ksize - get the actual amount of memory allocated for a given object
78230 * @objp: Pointer to the object
78231diff --git a/mm/slob.c b/mm/slob.c
78232index 837ebd6..4712174 100644
78233--- a/mm/slob.c
78234+++ b/mm/slob.c
78235@@ -29,7 +29,7 @@
78236 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
78237 * alloc_pages() directly, allocating compound pages so the page order
78238 * does not have to be separately tracked, and also stores the exact
78239- * allocation size in page->private so that it can be used to accurately
78240+ * allocation size in slob_page->size so that it can be used to accurately
78241 * provide ksize(). These objects are detected in kfree() because slob_page()
78242 * is false for them.
78243 *
78244@@ -58,6 +58,7 @@
78245 */
78246
78247 #include <linux/kernel.h>
78248+#include <linux/sched.h>
78249 #include <linux/slab.h>
78250 #include <linux/mm.h>
78251 #include <linux/swap.h> /* struct reclaim_state */
78252@@ -100,7 +101,8 @@ struct slob_page {
78253 unsigned long flags; /* mandatory */
78254 atomic_t _count; /* mandatory */
78255 slobidx_t units; /* free units left in page */
78256- unsigned long pad[2];
78257+ unsigned long pad[1];
78258+ unsigned long size; /* size when >=PAGE_SIZE */
78259 slob_t *free; /* first free slob_t in page */
78260 struct list_head list; /* linked list of free pages */
78261 };
78262@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
78263 */
78264 static inline int is_slob_page(struct slob_page *sp)
78265 {
78266- return PageSlab((struct page *)sp);
78267+ return PageSlab((struct page *)sp) && !sp->size;
78268 }
78269
78270 static inline void set_slob_page(struct slob_page *sp)
78271@@ -148,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
78272
78273 static inline struct slob_page *slob_page(const void *addr)
78274 {
78275- return (struct slob_page *)virt_to_page(addr);
78276+ return (struct slob_page *)virt_to_head_page(addr);
78277 }
78278
78279 /*
78280@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78281 /*
78282 * Return the size of a slob block.
78283 */
78284-static slobidx_t slob_units(slob_t *s)
78285+static slobidx_t slob_units(const slob_t *s)
78286 {
78287 if (s->units > 0)
78288 return s->units;
78289@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
78290 /*
78291 * Return the next free slob block pointer after this one.
78292 */
78293-static slob_t *slob_next(slob_t *s)
78294+static slob_t *slob_next(const slob_t *s)
78295 {
78296 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78297 slobidx_t next;
78298@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
78299 /*
78300 * Returns true if s is the last free block in its page.
78301 */
78302-static int slob_last(slob_t *s)
78303+static int slob_last(const slob_t *s)
78304 {
78305 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78306 }
78307@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78308 if (!page)
78309 return NULL;
78310
78311+ set_slob_page(page);
78312 return page_address(page);
78313 }
78314
78315@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78316 if (!b)
78317 return NULL;
78318 sp = slob_page(b);
78319- set_slob_page(sp);
78320
78321 spin_lock_irqsave(&slob_lock, flags);
78322 sp->units = SLOB_UNITS(PAGE_SIZE);
78323 sp->free = b;
78324+ sp->size = 0;
78325 INIT_LIST_HEAD(&sp->list);
78326 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78327 set_slob_page_free(sp, slob_list);
78328@@ -475,10 +478,9 @@ out:
78329 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
78330 #endif
78331
78332-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78333+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
78334 {
78335- unsigned int *m;
78336- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78337+ slob_t *m;
78338 void *ret;
78339
78340 lockdep_trace_alloc(gfp);
78341@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78342
78343 if (!m)
78344 return NULL;
78345- *m = size;
78346+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78347+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78348+ m[0].units = size;
78349+ m[1].units = align;
78350 ret = (void *)m + align;
78351
78352 trace_kmalloc_node(_RET_IP_, ret,
78353@@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78354
78355 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
78356 if (ret) {
78357- struct page *page;
78358- page = virt_to_page(ret);
78359- page->private = size;
78360+ struct slob_page *sp;
78361+ sp = slob_page(ret);
78362+ sp->size = size;
78363 }
78364
78365 trace_kmalloc_node(_RET_IP_, ret,
78366 size, PAGE_SIZE << order, gfp, node);
78367 }
78368
78369- kmemleak_alloc(ret, size, 1, gfp);
78370+ return ret;
78371+}
78372+
78373+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78374+{
78375+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78376+ void *ret = __kmalloc_node_align(size, gfp, node, align);
78377+
78378+ if (!ZERO_OR_NULL_PTR(ret))
78379+ kmemleak_alloc(ret, size, 1, gfp);
78380 return ret;
78381 }
78382 EXPORT_SYMBOL(__kmalloc_node);
78383@@ -528,13 +542,92 @@ void kfree(const void *block)
78384 sp = slob_page(block);
78385 if (is_slob_page(sp)) {
78386 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78387- unsigned int *m = (unsigned int *)(block - align);
78388- slob_free(m, *m + align);
78389- } else
78390+ slob_t *m = (slob_t *)(block - align);
78391+ slob_free(m, m[0].units + align);
78392+ } else {
78393+ clear_slob_page(sp);
78394+ free_slob_page(sp);
78395+ sp->size = 0;
78396 put_page(&sp->page);
78397+ }
78398 }
78399 EXPORT_SYMBOL(kfree);
78400
78401+void check_object_size(const void *ptr, unsigned long n, bool to)
78402+{
78403+
78404+#ifdef CONFIG_PAX_USERCOPY
78405+ struct slob_page *sp;
78406+ const slob_t *free;
78407+ const void *base;
78408+ unsigned long flags;
78409+ const char *type;
78410+
78411+ if (!n)
78412+ return;
78413+
78414+ type = "<null>";
78415+ if (ZERO_OR_NULL_PTR(ptr))
78416+ goto report;
78417+
78418+ if (!virt_addr_valid(ptr))
78419+ return;
78420+
78421+ type = "<process stack>";
78422+ sp = slob_page(ptr);
78423+ if (!PageSlab((struct page*)sp)) {
78424+ if (object_is_on_stack(ptr, n) == -1)
78425+ goto report;
78426+ return;
78427+ }
78428+
78429+ type = "<slob>";
78430+ if (sp->size) {
78431+ base = page_address(&sp->page);
78432+ if (base <= ptr && n <= sp->size - (ptr - base))
78433+ return;
78434+ goto report;
78435+ }
78436+
78437+ /* some tricky double walking to find the chunk */
78438+ spin_lock_irqsave(&slob_lock, flags);
78439+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78440+ free = sp->free;
78441+
78442+ while (!slob_last(free) && (void *)free <= ptr) {
78443+ base = free + slob_units(free);
78444+ free = slob_next(free);
78445+ }
78446+
78447+ while (base < (void *)free) {
78448+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78449+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
78450+ int offset;
78451+
78452+ if (ptr < base + align)
78453+ break;
78454+
78455+ offset = ptr - base - align;
78456+ if (offset >= m) {
78457+ base += size;
78458+ continue;
78459+ }
78460+
78461+ if (n > m - offset)
78462+ break;
78463+
78464+ spin_unlock_irqrestore(&slob_lock, flags);
78465+ return;
78466+ }
78467+
78468+ spin_unlock_irqrestore(&slob_lock, flags);
78469+report:
78470+ pax_report_usercopy(ptr, n, to, type);
78471+#endif
78472+
78473+}
78474+EXPORT_SYMBOL(check_object_size);
78475+
78476 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78477 size_t ksize(const void *block)
78478 {
78479@@ -547,10 +640,10 @@ size_t ksize(const void *block)
78480 sp = slob_page(block);
78481 if (is_slob_page(sp)) {
78482 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78483- unsigned int *m = (unsigned int *)(block - align);
78484- return SLOB_UNITS(*m) * SLOB_UNIT;
78485+ slob_t *m = (slob_t *)(block - align);
78486+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78487 } else
78488- return sp->page.private;
78489+ return sp->size;
78490 }
78491 EXPORT_SYMBOL(ksize);
78492
78493@@ -566,8 +659,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78494 {
78495 struct kmem_cache *c;
78496
78497+#ifdef CONFIG_PAX_USERCOPY
78498+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
78499+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
78500+#else
78501 c = slob_alloc(sizeof(struct kmem_cache),
78502 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
78503+#endif
78504
78505 if (c) {
78506 c->name = name;
78507@@ -605,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78508 {
78509 void *b;
78510
78511+#ifdef CONFIG_PAX_USERCOPY
78512+ b = __kmalloc_node_align(c->size, flags, node, c->align);
78513+#else
78514 if (c->size < PAGE_SIZE) {
78515 b = slob_alloc(c->size, flags, c->align, node);
78516 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
78517 SLOB_UNITS(c->size) * SLOB_UNIT,
78518 flags, node);
78519 } else {
78520+ struct slob_page *sp;
78521+
78522 b = slob_new_pages(flags, get_order(c->size), node);
78523+ sp = slob_page(b);
78524+ sp->size = c->size;
78525 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
78526 PAGE_SIZE << get_order(c->size),
78527 flags, node);
78528 }
78529+#endif
78530
78531 if (c->ctor)
78532 c->ctor(b);
78533@@ -627,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78534
78535 static void __kmem_cache_free(void *b, int size)
78536 {
78537- if (size < PAGE_SIZE)
78538+ struct slob_page *sp = slob_page(b);
78539+
78540+ if (is_slob_page(sp))
78541 slob_free(b, size);
78542- else
78543+ else {
78544+ clear_slob_page(sp);
78545+ free_slob_page(sp);
78546+ sp->size = 0;
78547 slob_free_pages(b, get_order(size));
78548+ }
78549 }
78550
78551 static void kmem_rcu_free(struct rcu_head *head)
78552@@ -643,18 +755,32 @@ static void kmem_rcu_free(struct rcu_head *head)
78553
78554 void kmem_cache_free(struct kmem_cache *c, void *b)
78555 {
78556+ int size = c->size;
78557+
78558+#ifdef CONFIG_PAX_USERCOPY
78559+ if (size + c->align < PAGE_SIZE) {
78560+ size += c->align;
78561+ b -= c->align;
78562+ }
78563+#endif
78564+
78565 kmemleak_free_recursive(b, c->flags);
78566 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78567 struct slob_rcu *slob_rcu;
78568- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78569+ slob_rcu = b + (size - sizeof(struct slob_rcu));
78570 INIT_RCU_HEAD(&slob_rcu->head);
78571- slob_rcu->size = c->size;
78572+ slob_rcu->size = size;
78573 call_rcu(&slob_rcu->head, kmem_rcu_free);
78574 } else {
78575- __kmem_cache_free(b, c->size);
78576+ __kmem_cache_free(b, size);
78577 }
78578
78579+#ifdef CONFIG_PAX_USERCOPY
78580+ trace_kfree(_RET_IP_, b);
78581+#else
78582 trace_kmem_cache_free(_RET_IP_, b);
78583+#endif
78584+
78585 }
78586 EXPORT_SYMBOL(kmem_cache_free);
78587
78588diff --git a/mm/slub.c b/mm/slub.c
78589index 4996fc7..87e01d0 100644
78590--- a/mm/slub.c
78591+++ b/mm/slub.c
78592@@ -201,7 +201,7 @@ struct track {
78593
78594 enum track_item { TRACK_ALLOC, TRACK_FREE };
78595
78596-#ifdef CONFIG_SLUB_DEBUG
78597+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78598 static int sysfs_slab_add(struct kmem_cache *);
78599 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78600 static void sysfs_slab_remove(struct kmem_cache *);
78601@@ -410,7 +410,7 @@ static void print_track(const char *s, struct track *t)
78602 if (!t->addr)
78603 return;
78604
78605- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78606+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78607 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78608 }
78609
78610@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
78611
78612 page = virt_to_head_page(x);
78613
78614+ BUG_ON(!PageSlab(page));
78615+
78616 slab_free(s, page, x, _RET_IP_);
78617
78618 trace_kmem_cache_free(_RET_IP_, x);
78619@@ -1937,7 +1939,7 @@ static int slub_min_objects;
78620 * Merge control. If this is set then no merging of slab caches will occur.
78621 * (Could be removed. This was introduced to pacify the merge skeptics.)
78622 */
78623-static int slub_nomerge;
78624+static int slub_nomerge = 1;
78625
78626 /*
78627 * Calculate the order of allocation given an slab object size.
78628@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
78629 * list to avoid pounding the page allocator excessively.
78630 */
78631 set_min_partial(s, ilog2(s->size));
78632- s->refcount = 1;
78633+ atomic_set(&s->refcount, 1);
78634 #ifdef CONFIG_NUMA
78635 s->remote_node_defrag_ratio = 1000;
78636 #endif
78637@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
78638 void kmem_cache_destroy(struct kmem_cache *s)
78639 {
78640 down_write(&slub_lock);
78641- s->refcount--;
78642- if (!s->refcount) {
78643+ if (atomic_dec_and_test(&s->refcount)) {
78644 list_del(&s->list);
78645 up_write(&slub_lock);
78646 if (kmem_cache_close(s)) {
78647@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(char *str)
78648 __setup("slub_nomerge", setup_slub_nomerge);
78649
78650 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
78651- const char *name, int size, gfp_t gfp_flags)
78652+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
78653 {
78654- unsigned int flags = 0;
78655-
78656 if (gfp_flags & SLUB_DMA)
78657- flags = SLAB_CACHE_DMA;
78658+ flags |= SLAB_CACHE_DMA;
78659
78660 /*
78661 * This function is called with IRQs disabled during early-boot on
78662@@ -2915,6 +2914,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78663 EXPORT_SYMBOL(__kmalloc_node);
78664 #endif
78665
78666+void check_object_size(const void *ptr, unsigned long n, bool to)
78667+{
78668+
78669+#ifdef CONFIG_PAX_USERCOPY
78670+ struct page *page;
78671+ struct kmem_cache *s = NULL;
78672+ unsigned long offset;
78673+ const char *type;
78674+
78675+ if (!n)
78676+ return;
78677+
78678+ type = "<null>";
78679+ if (ZERO_OR_NULL_PTR(ptr))
78680+ goto report;
78681+
78682+ if (!virt_addr_valid(ptr))
78683+ return;
78684+
78685+ page = get_object_page(ptr);
78686+
78687+ type = "<process stack>";
78688+ if (!page) {
78689+ if (object_is_on_stack(ptr, n) == -1)
78690+ goto report;
78691+ return;
78692+ }
78693+
78694+ s = page->slab;
78695+ type = s->name;
78696+ if (!(s->flags & SLAB_USERCOPY))
78697+ goto report;
78698+
78699+ offset = (ptr - page_address(page)) % s->size;
78700+ if (offset <= s->objsize && n <= s->objsize - offset)
78701+ return;
78702+
78703+report:
78704+ pax_report_usercopy(ptr, n, to, type);
78705+#endif
78706+
78707+}
78708+EXPORT_SYMBOL(check_object_size);
78709+
78710 size_t ksize(const void *object)
78711 {
78712 struct page *page;
78713@@ -3185,8 +3228,8 @@ void __init kmem_cache_init(void)
78714 * kmem_cache_open for slab_state == DOWN.
78715 */
78716 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
78717- sizeof(struct kmem_cache_node), GFP_NOWAIT);
78718- kmalloc_caches[0].refcount = -1;
78719+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
78720+ atomic_set(&kmalloc_caches[0].refcount, -1);
78721 caches++;
78722
78723 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
78724@@ -3198,18 +3241,18 @@ void __init kmem_cache_init(void)
78725 /* Caches that are not of the two-to-the-power-of size */
78726 if (KMALLOC_MIN_SIZE <= 32) {
78727 create_kmalloc_cache(&kmalloc_caches[1],
78728- "kmalloc-96", 96, GFP_NOWAIT);
78729+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
78730 caches++;
78731 }
78732 if (KMALLOC_MIN_SIZE <= 64) {
78733 create_kmalloc_cache(&kmalloc_caches[2],
78734- "kmalloc-192", 192, GFP_NOWAIT);
78735+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
78736 caches++;
78737 }
78738
78739 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78740 create_kmalloc_cache(&kmalloc_caches[i],
78741- "kmalloc", 1 << i, GFP_NOWAIT);
78742+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
78743 caches++;
78744 }
78745
78746@@ -3293,7 +3336,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78747 /*
78748 * We may have set a slab to be unmergeable during bootstrap.
78749 */
78750- if (s->refcount < 0)
78751+ if (atomic_read(&s->refcount) < 0)
78752 return 1;
78753
78754 return 0;
78755@@ -3353,7 +3396,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78756 if (s) {
78757 int cpu;
78758
78759- s->refcount++;
78760+ atomic_inc(&s->refcount);
78761 /*
78762 * Adjust the object sizes so that we clear
78763 * the complete object on kzalloc.
78764@@ -3372,7 +3415,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
78765
78766 if (sysfs_slab_alias(s, name)) {
78767 down_write(&slub_lock);
78768- s->refcount--;
78769+ atomic_dec(&s->refcount);
78770 up_write(&slub_lock);
78771 goto err;
78772 }
78773@@ -4101,7 +4144,7 @@ SLAB_ATTR_RO(ctor);
78774
78775 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78776 {
78777- return sprintf(buf, "%d\n", s->refcount - 1);
78778+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78779 }
78780 SLAB_ATTR_RO(aliases);
78781
78782@@ -4503,7 +4546,7 @@ static void kmem_cache_release(struct kobject *kobj)
78783 kfree(s);
78784 }
78785
78786-static struct sysfs_ops slab_sysfs_ops = {
78787+static const struct sysfs_ops slab_sysfs_ops = {
78788 .show = slab_attr_show,
78789 .store = slab_attr_store,
78790 };
78791@@ -4522,7 +4565,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
78792 return 0;
78793 }
78794
78795-static struct kset_uevent_ops slab_uevent_ops = {
78796+static const struct kset_uevent_ops slab_uevent_ops = {
78797 .filter = uevent_filter,
78798 };
78799
78800@@ -4564,6 +4607,7 @@ static char *create_unique_id(struct kmem_cache *s)
78801 return name;
78802 }
78803
78804+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78805 static int sysfs_slab_add(struct kmem_cache *s)
78806 {
78807 int err;
78808@@ -4619,6 +4663,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78809 kobject_del(&s->kobj);
78810 kobject_put(&s->kobj);
78811 }
78812+#endif
78813
78814 /*
78815 * Need to buffer aliases during bootup until sysfs becomes
78816@@ -4632,6 +4677,7 @@ struct saved_alias {
78817
78818 static struct saved_alias *alias_list;
78819
78820+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78821 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78822 {
78823 struct saved_alias *al;
78824@@ -4654,6 +4700,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78825 alias_list = al;
78826 return 0;
78827 }
78828+#endif
78829
78830 static int __init slab_sysfs_init(void)
78831 {
78832@@ -4785,7 +4832,13 @@ static const struct file_operations proc_slabinfo_operations = {
78833
78834 static int __init slab_proc_init(void)
78835 {
78836- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
78837+ mode_t gr_mode = S_IRUGO;
78838+
78839+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78840+ gr_mode = S_IRUSR;
78841+#endif
78842+
78843+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
78844 return 0;
78845 }
78846 module_init(slab_proc_init);
78847diff --git a/mm/swap.c b/mm/swap.c
78848index 308e57d..5de19c0 100644
78849--- a/mm/swap.c
78850+++ b/mm/swap.c
78851@@ -30,6 +30,7 @@
78852 #include <linux/notifier.h>
78853 #include <linux/backing-dev.h>
78854 #include <linux/memcontrol.h>
78855+#include <linux/hugetlb.h>
78856
78857 #include "internal.h"
78858
78859@@ -65,6 +66,8 @@ static void put_compound_page(struct page *page)
78860 compound_page_dtor *dtor;
78861
78862 dtor = get_compound_page_dtor(page);
78863+ if (!PageHuge(page))
78864+ BUG_ON(dtor != free_compound_page);
78865 (*dtor)(page);
78866 }
78867 }
78868diff --git a/mm/util.c b/mm/util.c
78869index e48b493..24a601d 100644
78870--- a/mm/util.c
78871+++ b/mm/util.c
78872@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
78873 void arch_pick_mmap_layout(struct mm_struct *mm)
78874 {
78875 mm->mmap_base = TASK_UNMAPPED_BASE;
78876+
78877+#ifdef CONFIG_PAX_RANDMMAP
78878+ if (mm->pax_flags & MF_PAX_RANDMMAP)
78879+ mm->mmap_base += mm->delta_mmap;
78880+#endif
78881+
78882 mm->get_unmapped_area = arch_get_unmapped_area;
78883 mm->unmap_area = arch_unmap_area;
78884 }
78885diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78886index f34ffd0..e60c44f 100644
78887--- a/mm/vmalloc.c
78888+++ b/mm/vmalloc.c
78889@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78890
78891 pte = pte_offset_kernel(pmd, addr);
78892 do {
78893- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78894- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78895+
78896+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78897+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78898+ BUG_ON(!pte_exec(*pte));
78899+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78900+ continue;
78901+ }
78902+#endif
78903+
78904+ {
78905+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78906+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78907+ }
78908 } while (pte++, addr += PAGE_SIZE, addr != end);
78909 }
78910
78911@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78912 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
78913 {
78914 pte_t *pte;
78915+ int ret = -ENOMEM;
78916
78917 /*
78918 * nr is a running index into the array which helps higher level
78919@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78920 pte = pte_alloc_kernel(pmd, addr);
78921 if (!pte)
78922 return -ENOMEM;
78923+
78924+ pax_open_kernel();
78925 do {
78926 struct page *page = pages[*nr];
78927
78928- if (WARN_ON(!pte_none(*pte)))
78929- return -EBUSY;
78930- if (WARN_ON(!page))
78931- return -ENOMEM;
78932+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78933+ if (!(pgprot_val(prot) & _PAGE_NX))
78934+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
78935+ else
78936+#endif
78937+
78938+ if (WARN_ON(!pte_none(*pte))) {
78939+ ret = -EBUSY;
78940+ goto out;
78941+ }
78942+ if (WARN_ON(!page)) {
78943+ ret = -ENOMEM;
78944+ goto out;
78945+ }
78946 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78947 (*nr)++;
78948 } while (pte++, addr += PAGE_SIZE, addr != end);
78949- return 0;
78950+ ret = 0;
78951+out:
78952+ pax_close_kernel();
78953+ return ret;
78954 }
78955
78956 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78957@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void *x)
78958 * and fall back on vmalloc() if that fails. Others
78959 * just put it in the vmalloc space.
78960 */
78961-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78962+#ifdef CONFIG_MODULES
78963+#ifdef MODULES_VADDR
78964 unsigned long addr = (unsigned long)x;
78965 if (addr >= MODULES_VADDR && addr < MODULES_END)
78966 return 1;
78967 #endif
78968+
78969+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78970+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78971+ return 1;
78972+#endif
78973+
78974+#endif
78975+
78976 return is_vmalloc_addr(x);
78977 }
78978
78979@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78980
78981 if (!pgd_none(*pgd)) {
78982 pud_t *pud = pud_offset(pgd, addr);
78983+#ifdef CONFIG_X86
78984+ if (!pud_large(*pud))
78985+#endif
78986 if (!pud_none(*pud)) {
78987 pmd_t *pmd = pmd_offset(pud, addr);
78988+#ifdef CONFIG_X86
78989+ if (!pmd_large(*pmd))
78990+#endif
78991 if (!pmd_none(*pmd)) {
78992 pte_t *ptep, pte;
78993
78994@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vmap_area *va)
78995 struct rb_node *tmp;
78996
78997 while (*p) {
78998- struct vmap_area *tmp;
78999+ struct vmap_area *varea;
79000
79001 parent = *p;
79002- tmp = rb_entry(parent, struct vmap_area, rb_node);
79003- if (va->va_start < tmp->va_end)
79004+ varea = rb_entry(parent, struct vmap_area, rb_node);
79005+ if (va->va_start < varea->va_end)
79006 p = &(*p)->rb_left;
79007- else if (va->va_end > tmp->va_start)
79008+ else if (va->va_end > varea->va_start)
79009 p = &(*p)->rb_right;
79010 else
79011 BUG();
79012@@ -1245,6 +1287,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79013 struct vm_struct *area;
79014
79015 BUG_ON(in_interrupt());
79016+
79017+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79018+ if (flags & VM_KERNEXEC) {
79019+ if (start != VMALLOC_START || end != VMALLOC_END)
79020+ return NULL;
79021+ start = (unsigned long)MODULES_EXEC_VADDR;
79022+ end = (unsigned long)MODULES_EXEC_END;
79023+ }
79024+#endif
79025+
79026 if (flags & VM_IOREMAP) {
79027 int bit = fls(size);
79028
79029@@ -1484,6 +1536,11 @@ void *vmap(struct page **pages, unsigned int count,
79030 if (count > totalram_pages)
79031 return NULL;
79032
79033+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79034+ if (!(pgprot_val(prot) & _PAGE_NX))
79035+ flags |= VM_KERNEXEC;
79036+#endif
79037+
79038 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79039 __builtin_return_address(0));
79040 if (!area)
79041@@ -1594,6 +1651,14 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79042 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79043 return NULL;
79044
79045+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79046+ if (!(pgprot_val(prot) & _PAGE_NX))
79047+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79048+ VMALLOC_START, VMALLOC_END, node,
79049+ gfp_mask, caller);
79050+ else
79051+#endif
79052+
79053 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79054 VMALLOC_START, VMALLOC_END, node,
79055 gfp_mask, caller);
79056@@ -1619,6 +1684,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79057 return addr;
79058 }
79059
79060+#undef __vmalloc
79061 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
79062 {
79063 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
79064@@ -1635,6 +1701,7 @@ EXPORT_SYMBOL(__vmalloc);
79065 * For tight control over page level allocator and protection flags
79066 * use __vmalloc() instead.
79067 */
79068+#undef vmalloc
79069 void *vmalloc(unsigned long size)
79070 {
79071 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79072@@ -1649,6 +1716,7 @@ EXPORT_SYMBOL(vmalloc);
79073 * The resulting memory area is zeroed so it can be mapped to userspace
79074 * without leaking data.
79075 */
79076+#undef vmalloc_user
79077 void *vmalloc_user(unsigned long size)
79078 {
79079 struct vm_struct *area;
79080@@ -1676,6 +1744,7 @@ EXPORT_SYMBOL(vmalloc_user);
79081 * For tight control over page level allocator and protection flags
79082 * use __vmalloc() instead.
79083 */
79084+#undef vmalloc_node
79085 void *vmalloc_node(unsigned long size, int node)
79086 {
79087 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79088@@ -1698,10 +1767,10 @@ EXPORT_SYMBOL(vmalloc_node);
79089 * For tight control over page level allocator and protection flags
79090 * use __vmalloc() instead.
79091 */
79092-
79093+#undef vmalloc_exec
79094 void *vmalloc_exec(unsigned long size)
79095 {
79096- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79097+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79098 -1, __builtin_return_address(0));
79099 }
79100
79101@@ -1720,6 +1789,7 @@ void *vmalloc_exec(unsigned long size)
79102 * Allocate enough 32bit PA addressable pages to cover @size from the
79103 * page level allocator and map them into contiguous kernel virtual space.
79104 */
79105+#undef vmalloc_32
79106 void *vmalloc_32(unsigned long size)
79107 {
79108 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
79109@@ -1734,6 +1804,7 @@ EXPORT_SYMBOL(vmalloc_32);
79110 * The resulting memory area is 32bit addressable and zeroed so it can be
79111 * mapped to userspace without leaking data.
79112 */
79113+#undef vmalloc_32_user
79114 void *vmalloc_32_user(unsigned long size)
79115 {
79116 struct vm_struct *area;
79117@@ -1998,6 +2069,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79118 unsigned long uaddr = vma->vm_start;
79119 unsigned long usize = vma->vm_end - vma->vm_start;
79120
79121+ BUG_ON(vma->vm_mirror);
79122+
79123 if ((PAGE_SIZE-1) & (unsigned long)addr)
79124 return -EINVAL;
79125
79126diff --git a/mm/vmstat.c b/mm/vmstat.c
79127index 42d76c6..5643dc4 100644
79128--- a/mm/vmstat.c
79129+++ b/mm/vmstat.c
79130@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
79131 *
79132 * vm_stat contains the global counters
79133 */
79134-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79135+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79136 EXPORT_SYMBOL(vm_stat);
79137
79138 #ifdef CONFIG_SMP
79139@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
79140 v = p->vm_stat_diff[i];
79141 p->vm_stat_diff[i] = 0;
79142 local_irq_restore(flags);
79143- atomic_long_add(v, &zone->vm_stat[i]);
79144+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79145 global_diff[i] += v;
79146 #ifdef CONFIG_NUMA
79147 /* 3 seconds idle till flush */
79148@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
79149
79150 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79151 if (global_diff[i])
79152- atomic_long_add(global_diff[i], &vm_stat[i]);
79153+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79154 }
79155
79156 #endif
79157@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
79158 start_cpu_timer(cpu);
79159 #endif
79160 #ifdef CONFIG_PROC_FS
79161- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79162- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79163- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79164- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79165+ {
79166+ mode_t gr_mode = S_IRUGO;
79167+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79168+ gr_mode = S_IRUSR;
79169+#endif
79170+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79171+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79172+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79173+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79174+#else
79175+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79176+#endif
79177+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79178+ }
79179 #endif
79180 return 0;
79181 }
79182diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79183index a29c5ab..6143f20 100644
79184--- a/net/8021q/vlan.c
79185+++ b/net/8021q/vlan.c
79186@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79187 err = -EPERM;
79188 if (!capable(CAP_NET_ADMIN))
79189 break;
79190- if ((args.u.name_type >= 0) &&
79191- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79192+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79193 struct vlan_net *vn;
79194
79195 vn = net_generic(net, vlan_net_id);
79196diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79197index a2d2984..f9eb711 100644
79198--- a/net/9p/trans_fd.c
79199+++ b/net/9p/trans_fd.c
79200@@ -419,7 +419,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79201 oldfs = get_fs();
79202 set_fs(get_ds());
79203 /* The cast to a user pointer is valid due to the set_fs() */
79204- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79205+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79206 set_fs(oldfs);
79207
79208 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79209diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79210index 02cc7e7..4514f1b 100644
79211--- a/net/atm/atm_misc.c
79212+++ b/net/atm/atm_misc.c
79213@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int truesize)
79214 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79215 return 1;
79216 atm_return(vcc,truesize);
79217- atomic_inc(&vcc->stats->rx_drop);
79218+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79219 return 0;
79220 }
79221
79222@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
79223 }
79224 }
79225 atm_return(vcc,guess);
79226- atomic_inc(&vcc->stats->rx_drop);
79227+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79228 return NULL;
79229 }
79230
79231@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafprm *tp)
79232
79233 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79234 {
79235-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79236+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79237 __SONET_ITEMS
79238 #undef __HANDLE_ITEM
79239 }
79240@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79241
79242 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79243 {
79244-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
79245+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79246 __SONET_ITEMS
79247 #undef __HANDLE_ITEM
79248 }
79249diff --git a/net/atm/lec.h b/net/atm/lec.h
79250index 9d14d19..5c145f3 100644
79251--- a/net/atm/lec.h
79252+++ b/net/atm/lec.h
79253@@ -48,7 +48,7 @@ struct lane2_ops {
79254 const u8 *tlvs, u32 sizeoftlvs);
79255 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79256 const u8 *tlvs, u32 sizeoftlvs);
79257-};
79258+} __no_const;
79259
79260 /*
79261 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79262diff --git a/net/atm/mpc.h b/net/atm/mpc.h
79263index 0919a88..a23d54e 100644
79264--- a/net/atm/mpc.h
79265+++ b/net/atm/mpc.h
79266@@ -33,7 +33,7 @@ struct mpoa_client {
79267 struct mpc_parameters parameters; /* parameters for this client */
79268
79269 const struct net_device_ops *old_ops;
79270- struct net_device_ops new_ops;
79271+ net_device_ops_no_const new_ops;
79272 };
79273
79274
79275diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
79276index 4504a4b..1733f1e 100644
79277--- a/net/atm/mpoa_caches.c
79278+++ b/net/atm/mpoa_caches.c
79279@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_client *client)
79280 struct timeval now;
79281 struct k_message msg;
79282
79283+ pax_track_stack();
79284+
79285 do_gettimeofday(&now);
79286
79287 write_lock_irq(&client->egress_lock);
79288diff --git a/net/atm/proc.c b/net/atm/proc.c
79289index ab8419a..aa91497 100644
79290--- a/net/atm/proc.c
79291+++ b/net/atm/proc.c
79292@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79293 const struct k_atm_aal_stats *stats)
79294 {
79295 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79296- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
79297- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
79298- atomic_read(&stats->rx_drop));
79299+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79300+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79301+ atomic_read_unchecked(&stats->rx_drop));
79302 }
79303
79304 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79305@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
79306 {
79307 struct sock *sk = sk_atm(vcc);
79308
79309+#ifdef CONFIG_GRKERNSEC_HIDESYM
79310+ seq_printf(seq, "%p ", NULL);
79311+#else
79312 seq_printf(seq, "%p ", vcc);
79313+#endif
79314+
79315 if (!vcc->dev)
79316 seq_printf(seq, "Unassigned ");
79317 else
79318@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
79319 {
79320 if (!vcc->dev)
79321 seq_printf(seq, sizeof(void *) == 4 ?
79322+#ifdef CONFIG_GRKERNSEC_HIDESYM
79323+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
79324+#else
79325 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
79326+#endif
79327 else
79328 seq_printf(seq, "%3d %3d %5d ",
79329 vcc->dev->number, vcc->vpi, vcc->vci);
79330diff --git a/net/atm/resources.c b/net/atm/resources.c
79331index 56b7322..c48b84e 100644
79332--- a/net/atm/resources.c
79333+++ b/net/atm/resources.c
79334@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *dev)
79335 static void copy_aal_stats(struct k_atm_aal_stats *from,
79336 struct atm_aal_stats *to)
79337 {
79338-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79339+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79340 __AAL_STAT_ITEMS
79341 #undef __HANDLE_ITEM
79342 }
79343@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79344 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79345 struct atm_aal_stats *to)
79346 {
79347-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79348+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79349 __AAL_STAT_ITEMS
79350 #undef __HANDLE_ITEM
79351 }
79352diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
79353index 8567d47..bba2292 100644
79354--- a/net/bridge/br_private.h
79355+++ b/net/bridge/br_private.h
79356@@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
79357
79358 #ifdef CONFIG_SYSFS
79359 /* br_sysfs_if.c */
79360-extern struct sysfs_ops brport_sysfs_ops;
79361+extern const struct sysfs_ops brport_sysfs_ops;
79362 extern int br_sysfs_addif(struct net_bridge_port *p);
79363
79364 /* br_sysfs_br.c */
79365diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
79366index 9a52ac5..c97538e 100644
79367--- a/net/bridge/br_stp_if.c
79368+++ b/net/bridge/br_stp_if.c
79369@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridge *br)
79370 char *envp[] = { NULL };
79371
79372 if (br->stp_enabled == BR_USER_STP) {
79373- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
79374+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
79375 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
79376 br->dev->name, r);
79377
79378diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
79379index 820643a..ce77fb3 100644
79380--- a/net/bridge/br_sysfs_if.c
79381+++ b/net/bridge/br_sysfs_if.c
79382@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobject * kobj,
79383 return ret;
79384 }
79385
79386-struct sysfs_ops brport_sysfs_ops = {
79387+const struct sysfs_ops brport_sysfs_ops = {
79388 .show = brport_show,
79389 .store = brport_store,
79390 };
79391diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79392index d73d47f..72df42a 100644
79393--- a/net/bridge/netfilter/ebtables.c
79394+++ b/net/bridge/netfilter/ebtables.c
79395@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
79396 unsigned int entries_size, nentries;
79397 char *entries;
79398
79399+ pax_track_stack();
79400+
79401 if (cmd == EBT_SO_GET_ENTRIES) {
79402 entries_size = t->private->entries_size;
79403 nentries = t->private->nentries;
79404diff --git a/net/can/bcm.c b/net/can/bcm.c
79405index 2ffd2e0..72a7486 100644
79406--- a/net/can/bcm.c
79407+++ b/net/can/bcm.c
79408@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file *m, void *v)
79409 struct bcm_sock *bo = bcm_sk(sk);
79410 struct bcm_op *op;
79411
79412+#ifdef CONFIG_GRKERNSEC_HIDESYM
79413+ seq_printf(m, ">>> socket %p", NULL);
79414+ seq_printf(m, " / sk %p", NULL);
79415+ seq_printf(m, " / bo %p", NULL);
79416+#else
79417 seq_printf(m, ">>> socket %p", sk->sk_socket);
79418 seq_printf(m, " / sk %p", sk);
79419 seq_printf(m, " / bo %p", bo);
79420+#endif
79421 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
79422 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
79423 seq_printf(m, " <<<\n");
79424diff --git a/net/compat.c b/net/compat.c
79425index 9559afc..ccd74e1 100644
79426--- a/net/compat.c
79427+++ b/net/compat.c
79428@@ -69,9 +69,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79429 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79430 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79431 return -EFAULT;
79432- kmsg->msg_name = compat_ptr(tmp1);
79433- kmsg->msg_iov = compat_ptr(tmp2);
79434- kmsg->msg_control = compat_ptr(tmp3);
79435+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79436+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79437+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79438 return 0;
79439 }
79440
79441@@ -94,7 +94,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79442 kern_msg->msg_name = NULL;
79443
79444 tot_len = iov_from_user_compat_to_kern(kern_iov,
79445- (struct compat_iovec __user *)kern_msg->msg_iov,
79446+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
79447 kern_msg->msg_iovlen);
79448 if (tot_len >= 0)
79449 kern_msg->msg_iov = kern_iov;
79450@@ -114,20 +114,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79451
79452 #define CMSG_COMPAT_FIRSTHDR(msg) \
79453 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79454- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79455+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79456 (struct compat_cmsghdr __user *)NULL)
79457
79458 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79459 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79460 (ucmlen) <= (unsigned long) \
79461 ((mhdr)->msg_controllen - \
79462- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79463+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79464
79465 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79466 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79467 {
79468 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79469- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79470+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79471 msg->msg_controllen)
79472 return NULL;
79473 return (struct compat_cmsghdr __user *)ptr;
79474@@ -219,7 +219,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79475 {
79476 struct compat_timeval ctv;
79477 struct compat_timespec cts[3];
79478- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79479+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79480 struct compat_cmsghdr cmhdr;
79481 int cmlen;
79482
79483@@ -271,7 +271,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79484
79485 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79486 {
79487- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79488+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79489 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79490 int fdnum = scm->fp->count;
79491 struct file **fp = scm->fp->fp;
79492@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79493 len = sizeof(ktime);
79494 old_fs = get_fs();
79495 set_fs(KERNEL_DS);
79496- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79497+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79498 set_fs(old_fs);
79499
79500 if (!err) {
79501@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79502 case MCAST_JOIN_GROUP:
79503 case MCAST_LEAVE_GROUP:
79504 {
79505- struct compat_group_req __user *gr32 = (void *)optval;
79506+ struct compat_group_req __user *gr32 = (void __user *)optval;
79507 struct group_req __user *kgr =
79508 compat_alloc_user_space(sizeof(struct group_req));
79509 u32 interface;
79510@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79511 case MCAST_BLOCK_SOURCE:
79512 case MCAST_UNBLOCK_SOURCE:
79513 {
79514- struct compat_group_source_req __user *gsr32 = (void *)optval;
79515+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79516 struct group_source_req __user *kgsr = compat_alloc_user_space(
79517 sizeof(struct group_source_req));
79518 u32 interface;
79519@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79520 }
79521 case MCAST_MSFILTER:
79522 {
79523- struct compat_group_filter __user *gf32 = (void *)optval;
79524+ struct compat_group_filter __user *gf32 = (void __user *)optval;
79525 struct group_filter __user *kgf;
79526 u32 interface, fmode, numsrc;
79527
79528diff --git a/net/core/dev.c b/net/core/dev.c
79529index 84a0705..575db4c 100644
79530--- a/net/core/dev.c
79531+++ b/net/core/dev.c
79532@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const char *name)
79533 if (no_module && capable(CAP_NET_ADMIN))
79534 no_module = request_module("netdev-%s", name);
79535 if (no_module && capable(CAP_SYS_MODULE)) {
79536+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79537+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
79538+#else
79539 if (!request_module("%s", name))
79540 pr_err("Loading kernel module for a network device "
79541 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
79542 "instead\n", name);
79543+#endif
79544 }
79545 }
79546 EXPORT_SYMBOL(dev_load);
79547@@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79548
79549 struct dev_gso_cb {
79550 void (*destructor)(struct sk_buff *skb);
79551-};
79552+} __no_const;
79553
79554 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79555
79556@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
79557 }
79558 EXPORT_SYMBOL(netif_rx_ni);
79559
79560-static void net_tx_action(struct softirq_action *h)
79561+static void net_tx_action(void)
79562 {
79563 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79564
79565@@ -2827,7 +2831,7 @@ void netif_napi_del(struct napi_struct *napi)
79566 EXPORT_SYMBOL(netif_napi_del);
79567
79568
79569-static void net_rx_action(struct softirq_action *h)
79570+static void net_rx_action(void)
79571 {
79572 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
79573 unsigned long time_limit = jiffies + 2;
79574diff --git a/net/core/flow.c b/net/core/flow.c
79575index 9601587..8c4824e 100644
79576--- a/net/core/flow.c
79577+++ b/net/core/flow.c
79578@@ -35,11 +35,11 @@ struct flow_cache_entry {
79579 atomic_t *object_ref;
79580 };
79581
79582-atomic_t flow_cache_genid = ATOMIC_INIT(0);
79583+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79584
79585 static u32 flow_hash_shift;
79586 #define flow_hash_size (1 << flow_hash_shift)
79587-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
79588+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
79589
79590 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
79591
79592@@ -52,7 +52,7 @@ struct flow_percpu_info {
79593 u32 hash_rnd;
79594 int count;
79595 };
79596-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
79597+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
79598
79599 #define flow_hash_rnd_recalc(cpu) \
79600 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
79601@@ -69,7 +69,7 @@ struct flow_flush_info {
79602 atomic_t cpuleft;
79603 struct completion completion;
79604 };
79605-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
79606+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
79607
79608 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
79609
79610@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir,
79611 if (fle->family == family &&
79612 fle->dir == dir &&
79613 flow_key_compare(key, &fle->key) == 0) {
79614- if (fle->genid == atomic_read(&flow_cache_genid)) {
79615+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
79616 void *ret = fle->object;
79617
79618 if (ret)
79619@@ -228,7 +228,7 @@ nocache:
79620 err = resolver(net, key, family, dir, &obj, &obj_ref);
79621
79622 if (fle && !err) {
79623- fle->genid = atomic_read(&flow_cache_genid);
79624+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
79625
79626 if (fle->object)
79627 atomic_dec(fle->object_ref);
79628@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(unsigned long data)
79629
79630 fle = flow_table(cpu)[i];
79631 for (; fle; fle = fle->next) {
79632- unsigned genid = atomic_read(&flow_cache_genid);
79633+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
79634
79635 if (!fle->object || fle->genid == genid)
79636 continue;
79637diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79638index d4fd895..ac9b1e6 100644
79639--- a/net/core/rtnetlink.c
79640+++ b/net/core/rtnetlink.c
79641@@ -57,7 +57,7 @@ struct rtnl_link
79642 {
79643 rtnl_doit_func doit;
79644 rtnl_dumpit_func dumpit;
79645-};
79646+} __no_const;
79647
79648 static DEFINE_MUTEX(rtnl_mutex);
79649
79650diff --git a/net/core/scm.c b/net/core/scm.c
79651index d98eafc..1a190a9 100644
79652--- a/net/core/scm.c
79653+++ b/net/core/scm.c
79654@@ -191,7 +191,7 @@ error:
79655 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79656 {
79657 struct cmsghdr __user *cm
79658- = (__force struct cmsghdr __user *)msg->msg_control;
79659+ = (struct cmsghdr __force_user *)msg->msg_control;
79660 struct cmsghdr cmhdr;
79661 int cmlen = CMSG_LEN(len);
79662 int err;
79663@@ -214,7 +214,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79664 err = -EFAULT;
79665 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79666 goto out;
79667- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79668+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79669 goto out;
79670 cmlen = CMSG_SPACE(len);
79671 if (msg->msg_controllen < cmlen)
79672@@ -229,7 +229,7 @@ out:
79673 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79674 {
79675 struct cmsghdr __user *cm
79676- = (__force struct cmsghdr __user*)msg->msg_control;
79677+ = (struct cmsghdr __force_user *)msg->msg_control;
79678
79679 int fdmax = 0;
79680 int fdnum = scm->fp->count;
79681@@ -249,7 +249,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79682 if (fdnum < fdmax)
79683 fdmax = fdnum;
79684
79685- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79686+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79687 i++, cmfptr++)
79688 {
79689 int new_fd;
79690diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
79691index 45329d7..626aaa6 100644
79692--- a/net/core/secure_seq.c
79693+++ b/net/core/secure_seq.c
79694@@ -57,7 +57,7 @@ __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
79695 EXPORT_SYMBOL(secure_tcpv6_sequence_number);
79696
79697 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
79698- __be16 dport)
79699+ __be16 dport)
79700 {
79701 u32 secret[MD5_MESSAGE_BYTES / 4];
79702 u32 hash[MD5_DIGEST_WORDS];
79703@@ -71,7 +71,6 @@ u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
79704 secret[i] = net_secret[i];
79705
79706 md5_transform(hash, secret);
79707-
79708 return hash[0];
79709 }
79710 #endif
79711diff --git a/net/core/skbuff.c b/net/core/skbuff.c
79712index a807f8c..65f906f 100644
79713--- a/net/core/skbuff.c
79714+++ b/net/core/skbuff.c
79715@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
79716 struct sk_buff *frag_iter;
79717 struct sock *sk = skb->sk;
79718
79719+ pax_track_stack();
79720+
79721 /*
79722 * __skb_splice_bits() only fails if the output has no room left,
79723 * so no point in going over the frag_list for the error case.
79724diff --git a/net/core/sock.c b/net/core/sock.c
79725index 6605e75..3acebda 100644
79726--- a/net/core/sock.c
79727+++ b/net/core/sock.c
79728@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79729 break;
79730
79731 case SO_PEERCRED:
79732+ {
79733+ struct ucred peercred;
79734 if (len > sizeof(sk->sk_peercred))
79735 len = sizeof(sk->sk_peercred);
79736- if (copy_to_user(optval, &sk->sk_peercred, len))
79737+ peercred = sk->sk_peercred;
79738+ if (copy_to_user(optval, &peercred, len))
79739 return -EFAULT;
79740 goto lenout;
79741+ }
79742
79743 case SO_PEERNAME:
79744 {
79745@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79746 */
79747 smp_wmb();
79748 atomic_set(&sk->sk_refcnt, 1);
79749- atomic_set(&sk->sk_drops, 0);
79750+ atomic_set_unchecked(&sk->sk_drops, 0);
79751 }
79752 EXPORT_SYMBOL(sock_init_data);
79753
79754diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79755index 2036568..c55883d 100644
79756--- a/net/decnet/sysctl_net_decnet.c
79757+++ b/net/decnet/sysctl_net_decnet.c
79758@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79759
79760 if (len > *lenp) len = *lenp;
79761
79762- if (copy_to_user(buffer, addr, len))
79763+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
79764 return -EFAULT;
79765
79766 *lenp = len;
79767@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79768
79769 if (len > *lenp) len = *lenp;
79770
79771- if (copy_to_user(buffer, devname, len))
79772+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
79773 return -EFAULT;
79774
79775 *lenp = len;
79776diff --git a/net/econet/Kconfig b/net/econet/Kconfig
79777index 39a2d29..f39c0fe 100644
79778--- a/net/econet/Kconfig
79779+++ b/net/econet/Kconfig
79780@@ -4,7 +4,7 @@
79781
79782 config ECONET
79783 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
79784- depends on EXPERIMENTAL && INET
79785+ depends on EXPERIMENTAL && INET && BROKEN
79786 ---help---
79787 Econet is a fairly old and slow networking protocol mainly used by
79788 Acorn computers to access file and print servers. It uses native
79789diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
79790index a413b1b..380849c 100644
79791--- a/net/ieee802154/dgram.c
79792+++ b/net/ieee802154/dgram.c
79793@@ -318,7 +318,7 @@ out:
79794 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
79795 {
79796 if (sock_queue_rcv_skb(sk, skb) < 0) {
79797- atomic_inc(&sk->sk_drops);
79798+ atomic_inc_unchecked(&sk->sk_drops);
79799 kfree_skb(skb);
79800 return NET_RX_DROP;
79801 }
79802diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
79803index 30e74ee..bfc6ee0 100644
79804--- a/net/ieee802154/raw.c
79805+++ b/net/ieee802154/raw.c
79806@@ -206,7 +206,7 @@ out:
79807 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79808 {
79809 if (sock_queue_rcv_skb(sk, skb) < 0) {
79810- atomic_inc(&sk->sk_drops);
79811+ atomic_inc_unchecked(&sk->sk_drops);
79812 kfree_skb(skb);
79813 return NET_RX_DROP;
79814 }
79815diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
79816index dba56d2..acee5d6 100644
79817--- a/net/ipv4/inet_diag.c
79818+++ b/net/ipv4/inet_diag.c
79819@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct sock *sk,
79820 r->idiag_retrans = 0;
79821
79822 r->id.idiag_if = sk->sk_bound_dev_if;
79823+#ifdef CONFIG_GRKERNSEC_HIDESYM
79824+ r->id.idiag_cookie[0] = 0;
79825+ r->id.idiag_cookie[1] = 0;
79826+#else
79827 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
79828 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79829+#endif
79830
79831 r->id.idiag_sport = inet->sport;
79832 r->id.idiag_dport = inet->dport;
79833@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
79834 r->idiag_family = tw->tw_family;
79835 r->idiag_retrans = 0;
79836 r->id.idiag_if = tw->tw_bound_dev_if;
79837+
79838+#ifdef CONFIG_GRKERNSEC_HIDESYM
79839+ r->id.idiag_cookie[0] = 0;
79840+ r->id.idiag_cookie[1] = 0;
79841+#else
79842 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
79843 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
79844+#endif
79845+
79846 r->id.idiag_sport = tw->tw_sport;
79847 r->id.idiag_dport = tw->tw_dport;
79848 r->id.idiag_src[0] = tw->tw_rcv_saddr;
79849@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
79850 if (sk == NULL)
79851 goto unlock;
79852
79853+#ifndef CONFIG_GRKERNSEC_HIDESYM
79854 err = -ESTALE;
79855 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
79856 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
79857 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
79858 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
79859 goto out;
79860+#endif
79861
79862 err = -ENOMEM;
79863 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
79864@@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
79865 r->idiag_retrans = req->retrans;
79866
79867 r->id.idiag_if = sk->sk_bound_dev_if;
79868+
79869+#ifdef CONFIG_GRKERNSEC_HIDESYM
79870+ r->id.idiag_cookie[0] = 0;
79871+ r->id.idiag_cookie[1] = 0;
79872+#else
79873 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
79874 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
79875+#endif
79876
79877 tmo = req->expires - jiffies;
79878 if (tmo < 0)
79879diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79880index d717267..56de7e7 100644
79881--- a/net/ipv4/inet_hashtables.c
79882+++ b/net/ipv4/inet_hashtables.c
79883@@ -18,12 +18,15 @@
79884 #include <linux/sched.h>
79885 #include <linux/slab.h>
79886 #include <linux/wait.h>
79887+#include <linux/security.h>
79888
79889 #include <net/inet_connection_sock.h>
79890 #include <net/inet_hashtables.h>
79891 #include <net/secure_seq.h>
79892 #include <net/ip.h>
79893
79894+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79895+
79896 /*
79897 * Allocate and initialize a new local port bind bucket.
79898 * The bindhash mutex for snum's hash chain must be held here.
79899@@ -491,6 +494,8 @@ ok:
79900 }
79901 spin_unlock(&head->lock);
79902
79903+ gr_update_task_in_ip_table(current, inet_sk(sk));
79904+
79905 if (tw) {
79906 inet_twsk_deschedule(tw, death_row);
79907 inet_twsk_put(tw);
79908diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79909index 13b229f..6956484 100644
79910--- a/net/ipv4/inetpeer.c
79911+++ b/net/ipv4/inetpeer.c
79912@@ -367,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
79913 struct inet_peer *p, *n;
79914 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
79915
79916+ pax_track_stack();
79917+
79918 /* Look up for the address quickly. */
79919 read_lock_bh(&peer_pool_lock);
79920 p = lookup(daddr, NULL);
79921@@ -390,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
79922 return NULL;
79923 n->v4daddr = daddr;
79924 atomic_set(&n->refcnt, 1);
79925- atomic_set(&n->rid, 0);
79926+ atomic_set_unchecked(&n->rid, 0);
79927 n->ip_id_count = secure_ip_id(daddr);
79928 n->tcp_ts_stamp = 0;
79929
79930diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79931index d3fe10b..feeafc9 100644
79932--- a/net/ipv4/ip_fragment.c
79933+++ b/net/ipv4/ip_fragment.c
79934@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79935 return 0;
79936
79937 start = qp->rid;
79938- end = atomic_inc_return(&peer->rid);
79939+ end = atomic_inc_return_unchecked(&peer->rid);
79940 qp->rid = end;
79941
79942 rc = qp->q.fragments && (end - start) > max;
79943diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79944index e982b5c..f079d75 100644
79945--- a/net/ipv4/ip_sockglue.c
79946+++ b/net/ipv4/ip_sockglue.c
79947@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79948 int val;
79949 int len;
79950
79951+ pax_track_stack();
79952+
79953 if (level != SOL_IP)
79954 return -EOPNOTSUPP;
79955
79956@@ -1173,7 +1175,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79957 if (sk->sk_type != SOCK_STREAM)
79958 return -ENOPROTOOPT;
79959
79960- msg.msg_control = optval;
79961+ msg.msg_control = (void __force_kernel *)optval;
79962 msg.msg_controllen = len;
79963 msg.msg_flags = 0;
79964
79965diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79966index f8d04c2..c1188f2 100644
79967--- a/net/ipv4/ipconfig.c
79968+++ b/net/ipv4/ipconfig.c
79969@@ -295,7 +295,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79970
79971 mm_segment_t oldfs = get_fs();
79972 set_fs(get_ds());
79973- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79974+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79975 set_fs(oldfs);
79976 return res;
79977 }
79978@@ -306,7 +306,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79979
79980 mm_segment_t oldfs = get_fs();
79981 set_fs(get_ds());
79982- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79983+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79984 set_fs(oldfs);
79985 return res;
79986 }
79987@@ -317,7 +317,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79988
79989 mm_segment_t oldfs = get_fs();
79990 set_fs(get_ds());
79991- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79992+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79993 set_fs(oldfs);
79994 return res;
79995 }
79996diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79997index c8b0cc3..4da5ae2 100644
79998--- a/net/ipv4/netfilter/arp_tables.c
79999+++ b/net/ipv4/netfilter/arp_tables.c
80000@@ -934,6 +934,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80001 private = &tmp;
80002 }
80003 #endif
80004+ memset(&info, 0, sizeof(info));
80005 info.valid_hooks = t->valid_hooks;
80006 memcpy(info.hook_entry, private->hook_entry,
80007 sizeof(info.hook_entry));
80008diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
80009index c156db2..e772975 100644
80010--- a/net/ipv4/netfilter/ip_queue.c
80011+++ b/net/ipv4/netfilter/ip_queue.c
80012@@ -286,6 +286,9 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80013
80014 if (v->data_len < sizeof(*user_iph))
80015 return 0;
80016+ if (v->data_len > 65535)
80017+ return -EMSGSIZE;
80018+
80019 diff = v->data_len - e->skb->len;
80020 if (diff < 0) {
80021 if (pskb_trim(e->skb, v->data_len))
80022@@ -409,7 +412,8 @@ ipq_dev_drop(int ifindex)
80023 static inline void
80024 __ipq_rcv_skb(struct sk_buff *skb)
80025 {
80026- int status, type, pid, flags, nlmsglen, skblen;
80027+ int status, type, pid, flags;
80028+ unsigned int nlmsglen, skblen;
80029 struct nlmsghdr *nlh;
80030
80031 skblen = skb->len;
80032diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80033index 0606db1..02e7e4c 100644
80034--- a/net/ipv4/netfilter/ip_tables.c
80035+++ b/net/ipv4/netfilter/ip_tables.c
80036@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80037 private = &tmp;
80038 }
80039 #endif
80040+ memset(&info, 0, sizeof(info));
80041 info.valid_hooks = t->valid_hooks;
80042 memcpy(info.hook_entry, private->hook_entry,
80043 sizeof(info.hook_entry));
80044diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80045index d9521f6..3c3eb25 100644
80046--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
80047+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80048@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
80049
80050 *len = 0;
80051
80052- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
80053+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
80054 if (*octets == NULL) {
80055 if (net_ratelimit())
80056 printk("OOM in bsalg (%d)\n", __LINE__);
80057diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80058index ab996f9..3da5f96 100644
80059--- a/net/ipv4/raw.c
80060+++ b/net/ipv4/raw.c
80061@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80062 /* Charge it to the socket. */
80063
80064 if (sock_queue_rcv_skb(sk, skb) < 0) {
80065- atomic_inc(&sk->sk_drops);
80066+ atomic_inc_unchecked(&sk->sk_drops);
80067 kfree_skb(skb);
80068 return NET_RX_DROP;
80069 }
80070@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80071 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80072 {
80073 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80074- atomic_inc(&sk->sk_drops);
80075+ atomic_inc_unchecked(&sk->sk_drops);
80076 kfree_skb(skb);
80077 return NET_RX_DROP;
80078 }
80079@@ -724,16 +724,23 @@ static int raw_init(struct sock *sk)
80080
80081 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80082 {
80083+ struct icmp_filter filter;
80084+
80085+ if (optlen < 0)
80086+ return -EINVAL;
80087 if (optlen > sizeof(struct icmp_filter))
80088 optlen = sizeof(struct icmp_filter);
80089- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80090+ if (copy_from_user(&filter, optval, optlen))
80091 return -EFAULT;
80092+ raw_sk(sk)->filter = filter;
80093+
80094 return 0;
80095 }
80096
80097 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80098 {
80099 int len, ret = -EFAULT;
80100+ struct icmp_filter filter;
80101
80102 if (get_user(len, optlen))
80103 goto out;
80104@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80105 if (len > sizeof(struct icmp_filter))
80106 len = sizeof(struct icmp_filter);
80107 ret = -EFAULT;
80108- if (put_user(len, optlen) ||
80109- copy_to_user(optval, &raw_sk(sk)->filter, len))
80110+ filter = raw_sk(sk)->filter;
80111+ if (put_user(len, optlen) || len > sizeof filter ||
80112+ copy_to_user(optval, &filter, len))
80113 goto out;
80114 ret = 0;
80115 out: return ret;
80116@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80117 sk_wmem_alloc_get(sp),
80118 sk_rmem_alloc_get(sp),
80119 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80120- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80121+ atomic_read(&sp->sk_refcnt),
80122+#ifdef CONFIG_GRKERNSEC_HIDESYM
80123+ NULL,
80124+#else
80125+ sp,
80126+#endif
80127+ atomic_read_unchecked(&sp->sk_drops));
80128 }
80129
80130 static int raw_seq_show(struct seq_file *seq, void *v)
80131diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80132index 58f141b..b759702 100644
80133--- a/net/ipv4/route.c
80134+++ b/net/ipv4/route.c
80135@@ -269,7 +269,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
80136
80137 static inline int rt_genid(struct net *net)
80138 {
80139- return atomic_read(&net->ipv4.rt_genid);
80140+ return atomic_read_unchecked(&net->ipv4.rt_genid);
80141 }
80142
80143 #ifdef CONFIG_PROC_FS
80144@@ -889,7 +889,7 @@ static void rt_cache_invalidate(struct net *net)
80145 unsigned char shuffle;
80146
80147 get_random_bytes(&shuffle, sizeof(shuffle));
80148- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
80149+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
80150 }
80151
80152 /*
80153@@ -3357,7 +3357,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80154
80155 static __net_init int rt_secret_timer_init(struct net *net)
80156 {
80157- atomic_set(&net->ipv4.rt_genid,
80158+ atomic_set_unchecked(&net->ipv4.rt_genid,
80159 (int) ((num_physpages ^ (num_physpages>>8)) ^
80160 (jiffies ^ (jiffies >> 7))));
80161
80162diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
80163index f095659..adc892a 100644
80164--- a/net/ipv4/tcp.c
80165+++ b/net/ipv4/tcp.c
80166@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
80167 int val;
80168 int err = 0;
80169
80170+ pax_track_stack();
80171+
80172 /* This is a string value all the others are int's */
80173 if (optname == TCP_CONGESTION) {
80174 char name[TCP_CA_NAME_MAX];
80175@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
80176 struct tcp_sock *tp = tcp_sk(sk);
80177 int val, len;
80178
80179+ pax_track_stack();
80180+
80181 if (get_user(len, optlen))
80182 return -EFAULT;
80183
80184diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80185index 6fc7961..33bad4a 100644
80186--- a/net/ipv4/tcp_ipv4.c
80187+++ b/net/ipv4/tcp_ipv4.c
80188@@ -85,6 +85,9 @@
80189 int sysctl_tcp_tw_reuse __read_mostly;
80190 int sysctl_tcp_low_latency __read_mostly;
80191
80192+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80193+extern int grsec_enable_blackhole;
80194+#endif
80195
80196 #ifdef CONFIG_TCP_MD5SIG
80197 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
80198@@ -1543,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80199 return 0;
80200
80201 reset:
80202+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80203+ if (!grsec_enable_blackhole)
80204+#endif
80205 tcp_v4_send_reset(rsk, skb);
80206 discard:
80207 kfree_skb(skb);
80208@@ -1604,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
80209 TCP_SKB_CB(skb)->sacked = 0;
80210
80211 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80212- if (!sk)
80213+ if (!sk) {
80214+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80215+ ret = 1;
80216+#endif
80217 goto no_tcp_socket;
80218+ }
80219
80220 process:
80221- if (sk->sk_state == TCP_TIME_WAIT)
80222+ if (sk->sk_state == TCP_TIME_WAIT) {
80223+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80224+ ret = 2;
80225+#endif
80226 goto do_time_wait;
80227+ }
80228
80229 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
80230 goto discard_and_relse;
80231@@ -1651,6 +1665,10 @@ no_tcp_socket:
80232 bad_packet:
80233 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80234 } else {
80235+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80236+ if (!grsec_enable_blackhole || (ret == 1 &&
80237+ (skb->dev->flags & IFF_LOOPBACK)))
80238+#endif
80239 tcp_v4_send_reset(NULL, skb);
80240 }
80241
80242@@ -2238,7 +2256,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
80243 0, /* non standard timer */
80244 0, /* open_requests have no inode */
80245 atomic_read(&sk->sk_refcnt),
80246+#ifdef CONFIG_GRKERNSEC_HIDESYM
80247+ NULL,
80248+#else
80249 req,
80250+#endif
80251 len);
80252 }
80253
80254@@ -2280,7 +2302,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
80255 sock_i_uid(sk),
80256 icsk->icsk_probes_out,
80257 sock_i_ino(sk),
80258- atomic_read(&sk->sk_refcnt), sk,
80259+ atomic_read(&sk->sk_refcnt),
80260+#ifdef CONFIG_GRKERNSEC_HIDESYM
80261+ NULL,
80262+#else
80263+ sk,
80264+#endif
80265 jiffies_to_clock_t(icsk->icsk_rto),
80266 jiffies_to_clock_t(icsk->icsk_ack.ato),
80267 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
80268@@ -2308,7 +2335,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
80269 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
80270 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
80271 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
80272- atomic_read(&tw->tw_refcnt), tw, len);
80273+ atomic_read(&tw->tw_refcnt),
80274+#ifdef CONFIG_GRKERNSEC_HIDESYM
80275+ NULL,
80276+#else
80277+ tw,
80278+#endif
80279+ len);
80280 }
80281
80282 #define TMPSZ 150
80283diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80284index 4c03598..e09a8e8 100644
80285--- a/net/ipv4/tcp_minisocks.c
80286+++ b/net/ipv4/tcp_minisocks.c
80287@@ -26,6 +26,10 @@
80288 #include <net/inet_common.h>
80289 #include <net/xfrm.h>
80290
80291+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80292+extern int grsec_enable_blackhole;
80293+#endif
80294+
80295 #ifdef CONFIG_SYSCTL
80296 #define SYNC_INIT 0 /* let the user enable it */
80297 #else
80298@@ -672,6 +676,10 @@ listen_overflow:
80299
80300 embryonic_reset:
80301 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
80302+
80303+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80304+ if (!grsec_enable_blackhole)
80305+#endif
80306 if (!(flg & TCP_FLAG_RST))
80307 req->rsk_ops->send_reset(sk, skb);
80308
80309diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
80310index af83bdf..ec91cb2 100644
80311--- a/net/ipv4/tcp_output.c
80312+++ b/net/ipv4/tcp_output.c
80313@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
80314 __u8 *md5_hash_location;
80315 int mss;
80316
80317+ pax_track_stack();
80318+
80319 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
80320 if (skb == NULL)
80321 return NULL;
80322diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80323index 59f5b5e..193860f 100644
80324--- a/net/ipv4/tcp_probe.c
80325+++ b/net/ipv4/tcp_probe.c
80326@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80327 if (cnt + width >= len)
80328 break;
80329
80330- if (copy_to_user(buf + cnt, tbuf, width))
80331+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80332 return -EFAULT;
80333 cnt += width;
80334 }
80335diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80336index 57d5501..a9ed13a 100644
80337--- a/net/ipv4/tcp_timer.c
80338+++ b/net/ipv4/tcp_timer.c
80339@@ -21,6 +21,10 @@
80340 #include <linux/module.h>
80341 #include <net/tcp.h>
80342
80343+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80344+extern int grsec_lastack_retries;
80345+#endif
80346+
80347 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80348 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80349 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80350@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock *sk)
80351 }
80352 }
80353
80354+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80355+ if ((sk->sk_state == TCP_LAST_ACK) &&
80356+ (grsec_lastack_retries > 0) &&
80357+ (grsec_lastack_retries < retry_until))
80358+ retry_until = grsec_lastack_retries;
80359+#endif
80360+
80361 if (retransmits_timed_out(sk, retry_until)) {
80362 /* Has it gone just too far? */
80363 tcp_write_err(sk);
80364diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80365index 0ac8833..58d8c43 100644
80366--- a/net/ipv4/udp.c
80367+++ b/net/ipv4/udp.c
80368@@ -86,6 +86,7 @@
80369 #include <linux/types.h>
80370 #include <linux/fcntl.h>
80371 #include <linux/module.h>
80372+#include <linux/security.h>
80373 #include <linux/socket.h>
80374 #include <linux/sockios.h>
80375 #include <linux/igmp.h>
80376@@ -106,6 +107,10 @@
80377 #include <net/xfrm.h>
80378 #include "udp_impl.h"
80379
80380+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80381+extern int grsec_enable_blackhole;
80382+#endif
80383+
80384 struct udp_table udp_table;
80385 EXPORT_SYMBOL(udp_table);
80386
80387@@ -371,6 +376,9 @@ found:
80388 return s;
80389 }
80390
80391+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80392+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80393+
80394 /*
80395 * This routine is called by the ICMP module when it gets some
80396 * sort of error condition. If err < 0 then the socket should
80397@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80398 dport = usin->sin_port;
80399 if (dport == 0)
80400 return -EINVAL;
80401+
80402+ err = gr_search_udp_sendmsg(sk, usin);
80403+ if (err)
80404+ return err;
80405 } else {
80406 if (sk->sk_state != TCP_ESTABLISHED)
80407 return -EDESTADDRREQ;
80408+
80409+ err = gr_search_udp_sendmsg(sk, NULL);
80410+ if (err)
80411+ return err;
80412+
80413 daddr = inet->daddr;
80414 dport = inet->dport;
80415 /* Open fast path for connected socket.
80416@@ -945,6 +962,10 @@ try_again:
80417 if (!skb)
80418 goto out;
80419
80420+ err = gr_search_udp_recvmsg(sk, skb);
80421+ if (err)
80422+ goto out_free;
80423+
80424 ulen = skb->len - sizeof(struct udphdr);
80425 copied = len;
80426 if (copied > ulen)
80427@@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80428 if (rc == -ENOMEM) {
80429 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80430 is_udplite);
80431- atomic_inc(&sk->sk_drops);
80432+ atomic_inc_unchecked(&sk->sk_drops);
80433 }
80434 goto drop;
80435 }
80436@@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80437 goto csum_error;
80438
80439 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80440+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80441+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80442+#endif
80443 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80444
80445 /*
80446@@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80447 sk_wmem_alloc_get(sp),
80448 sk_rmem_alloc_get(sp),
80449 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80450- atomic_read(&sp->sk_refcnt), sp,
80451- atomic_read(&sp->sk_drops), len);
80452+ atomic_read(&sp->sk_refcnt),
80453+#ifdef CONFIG_GRKERNSEC_HIDESYM
80454+ NULL,
80455+#else
80456+ sp,
80457+#endif
80458+ atomic_read_unchecked(&sp->sk_drops), len);
80459 }
80460
80461 int udp4_seq_show(struct seq_file *seq, void *v)
80462diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80463index 8ac3d09..fc58c5f 100644
80464--- a/net/ipv6/addrconf.c
80465+++ b/net/ipv6/addrconf.c
80466@@ -2053,7 +2053,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80467 p.iph.ihl = 5;
80468 p.iph.protocol = IPPROTO_IPV6;
80469 p.iph.ttl = 64;
80470- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80471+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80472
80473 if (ops->ndo_do_ioctl) {
80474 mm_segment_t oldfs = get_fs();
80475diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
80476index cc4797d..7cfdfcc 100644
80477--- a/net/ipv6/inet6_connection_sock.c
80478+++ b/net/ipv6/inet6_connection_sock.c
80479@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
80480 #ifdef CONFIG_XFRM
80481 {
80482 struct rt6_info *rt = (struct rt6_info *)dst;
80483- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
80484+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
80485 }
80486 #endif
80487 }
80488@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
80489 #ifdef CONFIG_XFRM
80490 if (dst) {
80491 struct rt6_info *rt = (struct rt6_info *)dst;
80492- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
80493+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
80494 sk->sk_dst_cache = NULL;
80495 dst_release(dst);
80496 dst = NULL;
80497diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
80498index 093e9b2..f72cddb 100644
80499--- a/net/ipv6/inet6_hashtables.c
80500+++ b/net/ipv6/inet6_hashtables.c
80501@@ -119,7 +119,7 @@ out:
80502 }
80503 EXPORT_SYMBOL(__inet6_lookup_established);
80504
80505-static int inline compute_score(struct sock *sk, struct net *net,
80506+static inline int compute_score(struct sock *sk, struct net *net,
80507 const unsigned short hnum,
80508 const struct in6_addr *daddr,
80509 const int dif)
80510diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80511index 4f7aaf6..f7acf45 100644
80512--- a/net/ipv6/ipv6_sockglue.c
80513+++ b/net/ipv6/ipv6_sockglue.c
80514@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
80515 int val, valbool;
80516 int retv = -ENOPROTOOPT;
80517
80518+ pax_track_stack();
80519+
80520 if (optval == NULL)
80521 val=0;
80522 else {
80523@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80524 int len;
80525 int val;
80526
80527+ pax_track_stack();
80528+
80529 if (ip6_mroute_opt(optname))
80530 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
80531
80532@@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80533 if (sk->sk_type != SOCK_STREAM)
80534 return -ENOPROTOOPT;
80535
80536- msg.msg_control = optval;
80537+ msg.msg_control = (void __force_kernel *)optval;
80538 msg.msg_controllen = len;
80539 msg.msg_flags = 0;
80540
80541diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
80542index 1cf3f0c..1d4376f 100644
80543--- a/net/ipv6/netfilter/ip6_queue.c
80544+++ b/net/ipv6/netfilter/ip6_queue.c
80545@@ -287,6 +287,9 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80546
80547 if (v->data_len < sizeof(*user_iph))
80548 return 0;
80549+ if (v->data_len > 65535)
80550+ return -EMSGSIZE;
80551+
80552 diff = v->data_len - e->skb->len;
80553 if (diff < 0) {
80554 if (pskb_trim(e->skb, v->data_len))
80555@@ -411,7 +414,8 @@ ipq_dev_drop(int ifindex)
80556 static inline void
80557 __ipq_rcv_skb(struct sk_buff *skb)
80558 {
80559- int status, type, pid, flags, nlmsglen, skblen;
80560+ int status, type, pid, flags;
80561+ unsigned int nlmsglen, skblen;
80562 struct nlmsghdr *nlh;
80563
80564 skblen = skb->len;
80565diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80566index 78b5a36..7f37433 100644
80567--- a/net/ipv6/netfilter/ip6_tables.c
80568+++ b/net/ipv6/netfilter/ip6_tables.c
80569@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80570 private = &tmp;
80571 }
80572 #endif
80573+ memset(&info, 0, sizeof(info));
80574 info.valid_hooks = t->valid_hooks;
80575 memcpy(info.hook_entry, private->hook_entry,
80576 sizeof(info.hook_entry));
80577diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80578index 4f24570..b813b34 100644
80579--- a/net/ipv6/raw.c
80580+++ b/net/ipv6/raw.c
80581@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
80582 {
80583 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
80584 skb_checksum_complete(skb)) {
80585- atomic_inc(&sk->sk_drops);
80586+ atomic_inc_unchecked(&sk->sk_drops);
80587 kfree_skb(skb);
80588 return NET_RX_DROP;
80589 }
80590
80591 /* Charge it to the socket. */
80592 if (sock_queue_rcv_skb(sk,skb)<0) {
80593- atomic_inc(&sk->sk_drops);
80594+ atomic_inc_unchecked(&sk->sk_drops);
80595 kfree_skb(skb);
80596 return NET_RX_DROP;
80597 }
80598@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80599 struct raw6_sock *rp = raw6_sk(sk);
80600
80601 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80602- atomic_inc(&sk->sk_drops);
80603+ atomic_inc_unchecked(&sk->sk_drops);
80604 kfree_skb(skb);
80605 return NET_RX_DROP;
80606 }
80607@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80608
80609 if (inet->hdrincl) {
80610 if (skb_checksum_complete(skb)) {
80611- atomic_inc(&sk->sk_drops);
80612+ atomic_inc_unchecked(&sk->sk_drops);
80613 kfree_skb(skb);
80614 return NET_RX_DROP;
80615 }
80616@@ -518,7 +518,7 @@ csum_copy_err:
80617 as some normal condition.
80618 */
80619 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
80620- atomic_inc(&sk->sk_drops);
80621+ atomic_inc_unchecked(&sk->sk_drops);
80622 goto out;
80623 }
80624
80625@@ -600,7 +600,7 @@ out:
80626 return err;
80627 }
80628
80629-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80630+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80631 struct flowi *fl, struct rt6_info *rt,
80632 unsigned int flags)
80633 {
80634@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
80635 u16 proto;
80636 int err;
80637
80638+ pax_track_stack();
80639+
80640 /* Rough check on arithmetic overflow,
80641 better check is made in ip6_append_data().
80642 */
80643@@ -916,12 +918,17 @@ do_confirm:
80644 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80645 char __user *optval, int optlen)
80646 {
80647+ struct icmp6_filter filter;
80648+
80649 switch (optname) {
80650 case ICMPV6_FILTER:
80651+ if (optlen < 0)
80652+ return -EINVAL;
80653 if (optlen > sizeof(struct icmp6_filter))
80654 optlen = sizeof(struct icmp6_filter);
80655- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80656+ if (copy_from_user(&filter, optval, optlen))
80657 return -EFAULT;
80658+ raw6_sk(sk)->filter = filter;
80659 return 0;
80660 default:
80661 return -ENOPROTOOPT;
80662@@ -934,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80663 char __user *optval, int __user *optlen)
80664 {
80665 int len;
80666+ struct icmp6_filter filter;
80667
80668 switch (optname) {
80669 case ICMPV6_FILTER:
80670@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80671 len = sizeof(struct icmp6_filter);
80672 if (put_user(len, optlen))
80673 return -EFAULT;
80674- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80675+ filter = raw6_sk(sk)->filter;
80676+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
80677 return -EFAULT;
80678 return 0;
80679 default:
80680@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80681 0, 0L, 0,
80682 sock_i_uid(sp), 0,
80683 sock_i_ino(sp),
80684- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80685+ atomic_read(&sp->sk_refcnt),
80686+#ifdef CONFIG_GRKERNSEC_HIDESYM
80687+ NULL,
80688+#else
80689+ sp,
80690+#endif
80691+ atomic_read_unchecked(&sp->sk_drops));
80692 }
80693
80694 static int raw6_seq_show(struct seq_file *seq, void *v)
80695diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80696index faae6df..d4430c1 100644
80697--- a/net/ipv6/tcp_ipv6.c
80698+++ b/net/ipv6/tcp_ipv6.c
80699@@ -89,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
80700 }
80701 #endif
80702
80703+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80704+extern int grsec_enable_blackhole;
80705+#endif
80706+
80707 static void tcp_v6_hash(struct sock *sk)
80708 {
80709 if (sk->sk_state != TCP_CLOSE) {
80710@@ -1579,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80711 return 0;
80712
80713 reset:
80714+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80715+ if (!grsec_enable_blackhole)
80716+#endif
80717 tcp_v6_send_reset(sk, skb);
80718 discard:
80719 if (opt_skb)
80720@@ -1656,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80721 TCP_SKB_CB(skb)->sacked = 0;
80722
80723 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80724- if (!sk)
80725+ if (!sk) {
80726+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80727+ ret = 1;
80728+#endif
80729 goto no_tcp_socket;
80730+ }
80731
80732 process:
80733- if (sk->sk_state == TCP_TIME_WAIT)
80734+ if (sk->sk_state == TCP_TIME_WAIT) {
80735+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80736+ ret = 2;
80737+#endif
80738 goto do_time_wait;
80739+ }
80740
80741 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
80742 goto discard_and_relse;
80743@@ -1701,6 +1716,10 @@ no_tcp_socket:
80744 bad_packet:
80745 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80746 } else {
80747+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80748+ if (!grsec_enable_blackhole || (ret == 1 &&
80749+ (skb->dev->flags & IFF_LOOPBACK)))
80750+#endif
80751 tcp_v6_send_reset(NULL, skb);
80752 }
80753
80754@@ -1916,7 +1935,13 @@ static void get_openreq6(struct seq_file *seq,
80755 uid,
80756 0, /* non standard timer */
80757 0, /* open_requests have no inode */
80758- 0, req);
80759+ 0,
80760+#ifdef CONFIG_GRKERNSEC_HIDESYM
80761+ NULL
80762+#else
80763+ req
80764+#endif
80765+ );
80766 }
80767
80768 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
80769@@ -1966,7 +1991,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
80770 sock_i_uid(sp),
80771 icsk->icsk_probes_out,
80772 sock_i_ino(sp),
80773- atomic_read(&sp->sk_refcnt), sp,
80774+ atomic_read(&sp->sk_refcnt),
80775+#ifdef CONFIG_GRKERNSEC_HIDESYM
80776+ NULL,
80777+#else
80778+ sp,
80779+#endif
80780 jiffies_to_clock_t(icsk->icsk_rto),
80781 jiffies_to_clock_t(icsk->icsk_ack.ato),
80782 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
80783@@ -2001,7 +2031,13 @@ static void get_timewait6_sock(struct seq_file *seq,
80784 dest->s6_addr32[2], dest->s6_addr32[3], destp,
80785 tw->tw_substate, 0, 0,
80786 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
80787- atomic_read(&tw->tw_refcnt), tw);
80788+ atomic_read(&tw->tw_refcnt),
80789+#ifdef CONFIG_GRKERNSEC_HIDESYM
80790+ NULL
80791+#else
80792+ tw
80793+#endif
80794+ );
80795 }
80796
80797 static int tcp6_seq_show(struct seq_file *seq, void *v)
80798diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80799index 9cc6289..052c521 100644
80800--- a/net/ipv6/udp.c
80801+++ b/net/ipv6/udp.c
80802@@ -49,6 +49,10 @@
80803 #include <linux/seq_file.h>
80804 #include "udp_impl.h"
80805
80806+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80807+extern int grsec_enable_blackhole;
80808+#endif
80809+
80810 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80811 {
80812 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80813@@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
80814 if (rc == -ENOMEM) {
80815 UDP6_INC_STATS_BH(sock_net(sk),
80816 UDP_MIB_RCVBUFERRORS, is_udplite);
80817- atomic_inc(&sk->sk_drops);
80818+ atomic_inc_unchecked(&sk->sk_drops);
80819 }
80820 goto drop;
80821 }
80822@@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80823 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
80824 proto == IPPROTO_UDPLITE);
80825
80826+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80827+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80828+#endif
80829 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
80830
80831 kfree_skb(skb);
80832@@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80833 0, 0L, 0,
80834 sock_i_uid(sp), 0,
80835 sock_i_ino(sp),
80836- atomic_read(&sp->sk_refcnt), sp,
80837- atomic_read(&sp->sk_drops));
80838+ atomic_read(&sp->sk_refcnt),
80839+#ifdef CONFIG_GRKERNSEC_HIDESYM
80840+ NULL,
80841+#else
80842+ sp,
80843+#endif
80844+ atomic_read_unchecked(&sp->sk_drops));
80845 }
80846
80847 int udp6_seq_show(struct seq_file *seq, void *v)
80848diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80849index 811984d..11f59b7 100644
80850--- a/net/irda/ircomm/ircomm_tty.c
80851+++ b/net/irda/ircomm/ircomm_tty.c
80852@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80853 add_wait_queue(&self->open_wait, &wait);
80854
80855 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80856- __FILE__,__LINE__, tty->driver->name, self->open_count );
80857+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
80858
80859 /* As far as I can see, we protect open_count - Jean II */
80860 spin_lock_irqsave(&self->spinlock, flags);
80861 if (!tty_hung_up_p(filp)) {
80862 extra_count = 1;
80863- self->open_count--;
80864+ local_dec(&self->open_count);
80865 }
80866 spin_unlock_irqrestore(&self->spinlock, flags);
80867- self->blocked_open++;
80868+ local_inc(&self->blocked_open);
80869
80870 while (1) {
80871 if (tty->termios->c_cflag & CBAUD) {
80872@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80873 }
80874
80875 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80876- __FILE__,__LINE__, tty->driver->name, self->open_count );
80877+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
80878
80879 schedule();
80880 }
80881@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80882 if (extra_count) {
80883 /* ++ is not atomic, so this should be protected - Jean II */
80884 spin_lock_irqsave(&self->spinlock, flags);
80885- self->open_count++;
80886+ local_inc(&self->open_count);
80887 spin_unlock_irqrestore(&self->spinlock, flags);
80888 }
80889- self->blocked_open--;
80890+ local_dec(&self->blocked_open);
80891
80892 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80893- __FILE__,__LINE__, tty->driver->name, self->open_count);
80894+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
80895
80896 if (!retval)
80897 self->flags |= ASYNC_NORMAL_ACTIVE;
80898@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80899 }
80900 /* ++ is not atomic, so this should be protected - Jean II */
80901 spin_lock_irqsave(&self->spinlock, flags);
80902- self->open_count++;
80903+ local_inc(&self->open_count);
80904
80905 tty->driver_data = self;
80906 self->tty = tty;
80907 spin_unlock_irqrestore(&self->spinlock, flags);
80908
80909 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80910- self->line, self->open_count);
80911+ self->line, local_read(&self->open_count));
80912
80913 /* Not really used by us, but lets do it anyway */
80914 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80915@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
80916 return;
80917 }
80918
80919- if ((tty->count == 1) && (self->open_count != 1)) {
80920+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
80921 /*
80922 * Uh, oh. tty->count is 1, which means that the tty
80923 * structure will be freed. state->count should always
80924@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
80925 */
80926 IRDA_DEBUG(0, "%s(), bad serial port count; "
80927 "tty->count is 1, state->count is %d\n", __func__ ,
80928- self->open_count);
80929- self->open_count = 1;
80930+ local_read(&self->open_count));
80931+ local_set(&self->open_count, 1);
80932 }
80933
80934- if (--self->open_count < 0) {
80935+ if (local_dec_return(&self->open_count) < 0) {
80936 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
80937- __func__, self->line, self->open_count);
80938- self->open_count = 0;
80939+ __func__, self->line, local_read(&self->open_count));
80940+ local_set(&self->open_count, 0);
80941 }
80942- if (self->open_count) {
80943+ if (local_read(&self->open_count)) {
80944 spin_unlock_irqrestore(&self->spinlock, flags);
80945
80946 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
80947@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
80948 tty->closing = 0;
80949 self->tty = NULL;
80950
80951- if (self->blocked_open) {
80952+ if (local_read(&self->blocked_open)) {
80953 if (self->close_delay)
80954 schedule_timeout_interruptible(self->close_delay);
80955 wake_up_interruptible(&self->open_wait);
80956@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80957 spin_lock_irqsave(&self->spinlock, flags);
80958 self->flags &= ~ASYNC_NORMAL_ACTIVE;
80959 self->tty = NULL;
80960- self->open_count = 0;
80961+ local_set(&self->open_count, 0);
80962 spin_unlock_irqrestore(&self->spinlock, flags);
80963
80964 wake_up_interruptible(&self->open_wait);
80965@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80966 seq_putc(m, '\n');
80967
80968 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80969- seq_printf(m, "Open count: %d\n", self->open_count);
80970+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
80971 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80972 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80973
80974diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80975index bada1b9..f325943 100644
80976--- a/net/iucv/af_iucv.c
80977+++ b/net/iucv/af_iucv.c
80978@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct sock *sk)
80979
80980 write_lock_bh(&iucv_sk_list.lock);
80981
80982- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80983+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80984 while (__iucv_get_sock_by_name(name)) {
80985 sprintf(name, "%08x",
80986- atomic_inc_return(&iucv_sk_list.autobind_name));
80987+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80988 }
80989
80990 write_unlock_bh(&iucv_sk_list.lock);
80991diff --git a/net/key/af_key.c b/net/key/af_key.c
80992index 4e98193..439b449 100644
80993--- a/net/key/af_key.c
80994+++ b/net/key/af_key.c
80995@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
80996 struct xfrm_migrate m[XFRM_MAX_DEPTH];
80997 struct xfrm_kmaddress k;
80998
80999+ pax_track_stack();
81000+
81001 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
81002 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
81003 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
81004@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
81005 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
81006 else
81007 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
81008+#ifdef CONFIG_GRKERNSEC_HIDESYM
81009+ NULL,
81010+#else
81011 s,
81012+#endif
81013 atomic_read(&s->sk_refcnt),
81014 sk_rmem_alloc_get(s),
81015 sk_wmem_alloc_get(s),
81016diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
81017index bda96d1..c038b72 100644
81018--- a/net/lapb/lapb_iface.c
81019+++ b/net/lapb/lapb_iface.c
81020@@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
81021 goto out;
81022
81023 lapb->dev = dev;
81024- lapb->callbacks = *callbacks;
81025+ lapb->callbacks = callbacks;
81026
81027 __lapb_insert_cb(lapb);
81028
81029@@ -379,32 +379,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
81030
81031 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
81032 {
81033- if (lapb->callbacks.connect_confirmation)
81034- lapb->callbacks.connect_confirmation(lapb->dev, reason);
81035+ if (lapb->callbacks->connect_confirmation)
81036+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
81037 }
81038
81039 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
81040 {
81041- if (lapb->callbacks.connect_indication)
81042- lapb->callbacks.connect_indication(lapb->dev, reason);
81043+ if (lapb->callbacks->connect_indication)
81044+ lapb->callbacks->connect_indication(lapb->dev, reason);
81045 }
81046
81047 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
81048 {
81049- if (lapb->callbacks.disconnect_confirmation)
81050- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
81051+ if (lapb->callbacks->disconnect_confirmation)
81052+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
81053 }
81054
81055 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
81056 {
81057- if (lapb->callbacks.disconnect_indication)
81058- lapb->callbacks.disconnect_indication(lapb->dev, reason);
81059+ if (lapb->callbacks->disconnect_indication)
81060+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
81061 }
81062
81063 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
81064 {
81065- if (lapb->callbacks.data_indication)
81066- return lapb->callbacks.data_indication(lapb->dev, skb);
81067+ if (lapb->callbacks->data_indication)
81068+ return lapb->callbacks->data_indication(lapb->dev, skb);
81069
81070 kfree_skb(skb);
81071 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
81072@@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
81073 {
81074 int used = 0;
81075
81076- if (lapb->callbacks.data_transmit) {
81077- lapb->callbacks.data_transmit(lapb->dev, skb);
81078+ if (lapb->callbacks->data_transmit) {
81079+ lapb->callbacks->data_transmit(lapb->dev, skb);
81080 used = 1;
81081 }
81082
81083diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81084index fe2d3f8..e57f683 100644
81085--- a/net/mac80211/cfg.c
81086+++ b/net/mac80211/cfg.c
81087@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
81088 return err;
81089 }
81090
81091-struct cfg80211_ops mac80211_config_ops = {
81092+const struct cfg80211_ops mac80211_config_ops = {
81093 .add_virtual_intf = ieee80211_add_iface,
81094 .del_virtual_intf = ieee80211_del_iface,
81095 .change_virtual_intf = ieee80211_change_iface,
81096diff --git a/net/mac80211/cfg.h b/net/mac80211/cfg.h
81097index 7d7879f..2d51f62 100644
81098--- a/net/mac80211/cfg.h
81099+++ b/net/mac80211/cfg.h
81100@@ -4,6 +4,6 @@
81101 #ifndef __CFG_H
81102 #define __CFG_H
81103
81104-extern struct cfg80211_ops mac80211_config_ops;
81105+extern const struct cfg80211_ops mac80211_config_ops;
81106
81107 #endif /* __CFG_H */
81108diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
81109index 99c7525..9cb4937 100644
81110--- a/net/mac80211/debugfs_key.c
81111+++ b/net/mac80211/debugfs_key.c
81112@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
81113 size_t count, loff_t *ppos)
81114 {
81115 struct ieee80211_key *key = file->private_data;
81116- int i, res, bufsize = 2 * key->conf.keylen + 2;
81117+ int i, bufsize = 2 * key->conf.keylen + 2;
81118 char *buf = kmalloc(bufsize, GFP_KERNEL);
81119 char *p = buf;
81120+ ssize_t res;
81121+
81122+ if (buf == NULL)
81123+ return -ENOMEM;
81124
81125 for (i = 0; i < key->conf.keylen; i++)
81126 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
81127diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
81128index 33a2e89..08650c8 100644
81129--- a/net/mac80211/debugfs_sta.c
81130+++ b/net/mac80211/debugfs_sta.c
81131@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
81132 int i;
81133 struct sta_info *sta = file->private_data;
81134
81135+ pax_track_stack();
81136+
81137 spin_lock_bh(&sta->lock);
81138 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
81139 sta->ampdu_mlme.dialog_token_allocator + 1);
81140diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81141index ca62bfe..6657a03 100644
81142--- a/net/mac80211/ieee80211_i.h
81143+++ b/net/mac80211/ieee80211_i.h
81144@@ -25,6 +25,7 @@
81145 #include <linux/etherdevice.h>
81146 #include <net/cfg80211.h>
81147 #include <net/mac80211.h>
81148+#include <asm/local.h>
81149 #include "key.h"
81150 #include "sta_info.h"
81151
81152@@ -635,7 +636,7 @@ struct ieee80211_local {
81153 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81154 spinlock_t queue_stop_reason_lock;
81155
81156- int open_count;
81157+ local_t open_count;
81158 int monitors, cooked_mntrs;
81159 /* number of interfaces with corresponding FIF_ flags */
81160 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
81161diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81162index 079c500..eb3c6d4 100644
81163--- a/net/mac80211/iface.c
81164+++ b/net/mac80211/iface.c
81165@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_device *dev)
81166 break;
81167 }
81168
81169- if (local->open_count == 0) {
81170+ if (local_read(&local->open_count) == 0) {
81171 res = drv_start(local);
81172 if (res)
81173 goto err_del_bss;
81174@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_device *dev)
81175 * Validate the MAC address for this device.
81176 */
81177 if (!is_valid_ether_addr(dev->dev_addr)) {
81178- if (!local->open_count)
81179+ if (!local_read(&local->open_count))
81180 drv_stop(local);
81181 return -EADDRNOTAVAIL;
81182 }
81183@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_device *dev)
81184
81185 hw_reconf_flags |= __ieee80211_recalc_idle(local);
81186
81187- local->open_count++;
81188+ local_inc(&local->open_count);
81189 if (hw_reconf_flags) {
81190 ieee80211_hw_config(local, hw_reconf_flags);
81191 /*
81192@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_device *dev)
81193 err_del_interface:
81194 drv_remove_interface(local, &conf);
81195 err_stop:
81196- if (!local->open_count)
81197+ if (!local_read(&local->open_count))
81198 drv_stop(local);
81199 err_del_bss:
81200 sdata->bss = NULL;
81201@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_device *dev)
81202 WARN_ON(!list_empty(&sdata->u.ap.vlans));
81203 }
81204
81205- local->open_count--;
81206+ local_dec(&local->open_count);
81207
81208 switch (sdata->vif.type) {
81209 case NL80211_IFTYPE_AP_VLAN:
81210@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_device *dev)
81211
81212 ieee80211_recalc_ps(local, -1);
81213
81214- if (local->open_count == 0) {
81215+ if (local_read(&local->open_count) == 0) {
81216 ieee80211_clear_tx_pending(local);
81217 ieee80211_stop_device(local);
81218
81219diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81220index 2dfe176..74e4388 100644
81221--- a/net/mac80211/main.c
81222+++ b/net/mac80211/main.c
81223@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81224 local->hw.conf.power_level = power;
81225 }
81226
81227- if (changed && local->open_count) {
81228+ if (changed && local_read(&local->open_count)) {
81229 ret = drv_config(local, changed);
81230 /*
81231 * Goal:
81232diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
81233index e67eea7..fcc227e 100644
81234--- a/net/mac80211/mlme.c
81235+++ b/net/mac80211/mlme.c
81236@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
81237 bool have_higher_than_11mbit = false, newsta = false;
81238 u16 ap_ht_cap_flags;
81239
81240+ pax_track_stack();
81241+
81242 /*
81243 * AssocResp and ReassocResp have identical structure, so process both
81244 * of them in this function.
81245diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81246index e535f1c..4d733d1 100644
81247--- a/net/mac80211/pm.c
81248+++ b/net/mac80211/pm.c
81249@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
81250 }
81251
81252 /* stop hardware - this must stop RX */
81253- if (local->open_count)
81254+ if (local_read(&local->open_count))
81255 ieee80211_stop_device(local);
81256
81257 local->suspended = true;
81258diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81259index b33efc4..0a2efb6 100644
81260--- a/net/mac80211/rate.c
81261+++ b/net/mac80211/rate.c
81262@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81263 struct rate_control_ref *ref, *old;
81264
81265 ASSERT_RTNL();
81266- if (local->open_count)
81267+ if (local_read(&local->open_count))
81268 return -EBUSY;
81269
81270 ref = rate_control_alloc(name, local);
81271diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
81272index b1d7904..57e4da7 100644
81273--- a/net/mac80211/tx.c
81274+++ b/net/mac80211/tx.c
81275@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
81276 return cpu_to_le16(dur);
81277 }
81278
81279-static int inline is_ieee80211_device(struct ieee80211_local *local,
81280+static inline int is_ieee80211_device(struct ieee80211_local *local,
81281 struct net_device *dev)
81282 {
81283 return local == wdev_priv(dev->ieee80211_ptr);
81284diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81285index 31b1085..48fb26d 100644
81286--- a/net/mac80211/util.c
81287+++ b/net/mac80211/util.c
81288@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81289 local->resuming = true;
81290
81291 /* restart hardware */
81292- if (local->open_count) {
81293+ if (local_read(&local->open_count)) {
81294 /*
81295 * Upon resume hardware can sometimes be goofy due to
81296 * various platform / driver / bus issues, so restarting
81297diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81298index 634d14a..b35a608 100644
81299--- a/net/netfilter/Kconfig
81300+++ b/net/netfilter/Kconfig
81301@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
81302
81303 To compile it as a module, choose M here. If unsure, say N.
81304
81305+config NETFILTER_XT_MATCH_GRADM
81306+ tristate '"gradm" match support'
81307+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81308+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81309+ ---help---
81310+ The gradm match allows to match on grsecurity RBAC being enabled.
81311+ It is useful when iptables rules are applied early on bootup to
81312+ prevent connections to the machine (except from a trusted host)
81313+ while the RBAC system is disabled.
81314+
81315 config NETFILTER_XT_MATCH_HASHLIMIT
81316 tristate '"hashlimit" match support'
81317 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81318diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81319index 49f62ee..a17b2c6 100644
81320--- a/net/netfilter/Makefile
81321+++ b/net/netfilter/Makefile
81322@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
81323 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
81324 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81325 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81326+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81327 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81328 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81329 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81330diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
81331index 3c7e427..724043c 100644
81332--- a/net/netfilter/ipvs/ip_vs_app.c
81333+++ b/net/netfilter/ipvs/ip_vs_app.c
81334@@ -564,7 +564,7 @@ static const struct file_operations ip_vs_app_fops = {
81335 .open = ip_vs_app_open,
81336 .read = seq_read,
81337 .llseek = seq_lseek,
81338- .release = seq_release,
81339+ .release = seq_release_net,
81340 };
81341 #endif
81342
81343diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81344index 95682e5..457dbac 100644
81345--- a/net/netfilter/ipvs/ip_vs_conn.c
81346+++ b/net/netfilter/ipvs/ip_vs_conn.c
81347@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81348 /* if the connection is not template and is created
81349 * by sync, preserve the activity flag.
81350 */
81351- cp->flags |= atomic_read(&dest->conn_flags) &
81352+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
81353 (~IP_VS_CONN_F_INACTIVE);
81354 else
81355- cp->flags |= atomic_read(&dest->conn_flags);
81356+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
81357 cp->dest = dest;
81358
81359 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
81360@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
81361 atomic_set(&cp->refcnt, 1);
81362
81363 atomic_set(&cp->n_control, 0);
81364- atomic_set(&cp->in_pkts, 0);
81365+ atomic_set_unchecked(&cp->in_pkts, 0);
81366
81367 atomic_inc(&ip_vs_conn_count);
81368 if (flags & IP_VS_CONN_F_NO_CPORT)
81369@@ -871,7 +871,7 @@ static const struct file_operations ip_vs_conn_fops = {
81370 .open = ip_vs_conn_open,
81371 .read = seq_read,
81372 .llseek = seq_lseek,
81373- .release = seq_release,
81374+ .release = seq_release_net,
81375 };
81376
81377 static const char *ip_vs_origin_name(unsigned flags)
81378@@ -934,7 +934,7 @@ static const struct file_operations ip_vs_conn_sync_fops = {
81379 .open = ip_vs_conn_sync_open,
81380 .read = seq_read,
81381 .llseek = seq_lseek,
81382- .release = seq_release,
81383+ .release = seq_release_net,
81384 };
81385
81386 #endif
81387@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81388
81389 /* Don't drop the entry if its number of incoming packets is not
81390 located in [0, 8] */
81391- i = atomic_read(&cp->in_pkts);
81392+ i = atomic_read_unchecked(&cp->in_pkts);
81393 if (i > 8 || i < 0) return 0;
81394
81395 if (!todrop_rate[i]) return 0;
81396diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81397index b95699f..5fee919 100644
81398--- a/net/netfilter/ipvs/ip_vs_core.c
81399+++ b/net/netfilter/ipvs/ip_vs_core.c
81400@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81401 ret = cp->packet_xmit(skb, cp, pp);
81402 /* do not touch skb anymore */
81403
81404- atomic_inc(&cp->in_pkts);
81405+ atomic_inc_unchecked(&cp->in_pkts);
81406 ip_vs_conn_put(cp);
81407 return ret;
81408 }
81409@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
81410 * Sync connection if it is about to close to
81411 * encorage the standby servers to update the connections timeout
81412 */
81413- pkts = atomic_add_return(1, &cp->in_pkts);
81414+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81415 if (af == AF_INET &&
81416 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
81417 (((cp->protocol != IPPROTO_TCP ||
81418diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81419index 02b2610..2d89424 100644
81420--- a/net/netfilter/ipvs/ip_vs_ctl.c
81421+++ b/net/netfilter/ipvs/ip_vs_ctl.c
81422@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc,
81423 ip_vs_rs_hash(dest);
81424 write_unlock_bh(&__ip_vs_rs_lock);
81425 }
81426- atomic_set(&dest->conn_flags, conn_flags);
81427+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
81428
81429 /* bind the service */
81430 if (!dest->svc) {
81431@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81432 " %-7s %-6d %-10d %-10d\n",
81433 &dest->addr.in6,
81434 ntohs(dest->port),
81435- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81436+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81437 atomic_read(&dest->weight),
81438 atomic_read(&dest->activeconns),
81439 atomic_read(&dest->inactconns));
81440@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81441 "%-7s %-6d %-10d %-10d\n",
81442 ntohl(dest->addr.ip),
81443 ntohs(dest->port),
81444- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81445+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81446 atomic_read(&dest->weight),
81447 atomic_read(&dest->activeconns),
81448 atomic_read(&dest->inactconns));
81449@@ -1927,7 +1927,7 @@ static const struct file_operations ip_vs_info_fops = {
81450 .open = ip_vs_info_open,
81451 .read = seq_read,
81452 .llseek = seq_lseek,
81453- .release = seq_release_private,
81454+ .release = seq_release_net,
81455 };
81456
81457 #endif
81458@@ -1976,7 +1976,7 @@ static const struct file_operations ip_vs_stats_fops = {
81459 .open = ip_vs_stats_seq_open,
81460 .read = seq_read,
81461 .llseek = seq_lseek,
81462- .release = single_release,
81463+ .release = single_release_net,
81464 };
81465
81466 #endif
81467@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip_vs_get_dests *get,
81468
81469 entry.addr = dest->addr.ip;
81470 entry.port = dest->port;
81471- entry.conn_flags = atomic_read(&dest->conn_flags);
81472+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81473 entry.weight = atomic_read(&dest->weight);
81474 entry.u_threshold = dest->u_threshold;
81475 entry.l_threshold = dest->l_threshold;
81476@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81477 unsigned char arg[128];
81478 int ret = 0;
81479
81480+ pax_track_stack();
81481+
81482 if (!capable(CAP_NET_ADMIN))
81483 return -EPERM;
81484
81485@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81486 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
81487
81488 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81489- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
81490+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
81491 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
81492 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
81493 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
81494diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81495index e177f0d..55e8581 100644
81496--- a/net/netfilter/ipvs/ip_vs_sync.c
81497+++ b/net/netfilter/ipvs/ip_vs_sync.c
81498@@ -438,7 +438,7 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
81499
81500 if (opt)
81501 memcpy(&cp->in_seq, opt, sizeof(*opt));
81502- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
81503+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
81504 cp->state = state;
81505 cp->old_state = cp->state;
81506 /*
81507diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81508index 30b3189..e2e4b55 100644
81509--- a/net/netfilter/ipvs/ip_vs_xmit.c
81510+++ b/net/netfilter/ipvs/ip_vs_xmit.c
81511@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81512 else
81513 rc = NF_ACCEPT;
81514 /* do not touch skb anymore */
81515- atomic_inc(&cp->in_pkts);
81516+ atomic_inc_unchecked(&cp->in_pkts);
81517 goto out;
81518 }
81519
81520@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81521 else
81522 rc = NF_ACCEPT;
81523 /* do not touch skb anymore */
81524- atomic_inc(&cp->in_pkts);
81525+ atomic_inc_unchecked(&cp->in_pkts);
81526 goto out;
81527 }
81528
81529diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
81530index d521718..d0fd7a1 100644
81531--- a/net/netfilter/nf_conntrack_netlink.c
81532+++ b/net/netfilter/nf_conntrack_netlink.c
81533@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
81534 static int
81535 ctnetlink_parse_tuple(const struct nlattr * const cda[],
81536 struct nf_conntrack_tuple *tuple,
81537- enum ctattr_tuple type, u_int8_t l3num)
81538+ enum ctattr_type type, u_int8_t l3num)
81539 {
81540 struct nlattr *tb[CTA_TUPLE_MAX+1];
81541 int err;
81542diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81543index f900dc3..5e45346 100644
81544--- a/net/netfilter/nfnetlink_log.c
81545+++ b/net/netfilter/nfnetlink_log.c
81546@@ -68,7 +68,7 @@ struct nfulnl_instance {
81547 };
81548
81549 static DEFINE_RWLOCK(instances_lock);
81550-static atomic_t global_seq;
81551+static atomic_unchecked_t global_seq;
81552
81553 #define INSTANCE_BUCKETS 16
81554 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81555@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81556 /* global sequence number */
81557 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
81558 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
81559- htonl(atomic_inc_return(&global_seq)));
81560+ htonl(atomic_inc_return_unchecked(&global_seq)));
81561
81562 if (data_len) {
81563 struct nlattr *nla;
81564diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81565new file mode 100644
81566index 0000000..b1bac76
81567--- /dev/null
81568+++ b/net/netfilter/xt_gradm.c
81569@@ -0,0 +1,51 @@
81570+/*
81571+ * gradm match for netfilter
81572